# ShadyCSS
ShadyCSS provides a library to simulate ShadowDOM style encapsulation (ScopingShim), a shim for the proposed CSS mixin `@apply` syntax (ApplyShim), and a library to integrate document-level stylesheets with both of the former libraries (CustomStyleInterface).
## Requirements
ShadyCSS requires support for the `<template>` element, ShadowDOM, MutationObserver, Promise, and Object.assign
## Loading
ShadyCSS can be used by loading the ScopingShim, ApplyShim, CustomStyleInterface, or any combination of those.
The most-supported loading order is:
1. ScopingShim
1. ApplyShim
1. CustomStyleInterface
All libraries will expose an object on `window` named `ShadyCSS` with the following interface:
```js
ShadyCSS = {
prepareTemplate(templateElement, elementName, elementExtension){},
styleElement(element){},
styleSubtree(element, overrideProperties){},
styleDocument(overrideProperties){},
getComputedStyleValue(element, propertyName){
return // style value for property name on element
},
nativeCss: Boolean,
nativeShadow: Boolean
}
```
## About ScopingShim
ScopingShim provides simulated ShadyDOM style encapsulation, and a shim for CSS Custom Properties.
ScopingShim works by rewriting style contents and transforming selectors to enforce scoping.
Additionally, if CSS Custom Properties is not detected, ScopingShim will replace CSS Custom Property usage with realized values.
### Example:
Here's an example of a custom element when Scoping Shim is not needed.
```html
<my-element>
<!-- shadow-root -->
<style>
:host {
display: block;
}
#container slot::slotted(*) {
color: gray;
}
#foo {
color: black;
}
</style>
<div id="foo">Shadow</div>
<div id="container">
<slot>
<!-- span distributed here -->
</slot>
</div>
<!-- /shadow-root -->
<span>Light</span>
</my-element>
```
becomes:
```html
<style scope="my-element">
my-element {
display: block;
}
#container.my-element > * {
color: gray;
}
#foo.my-element {
color: black;
}
</style>
<my-element>
<div id="foo">Shadow</div>
<div id="container">
<span>Light</span>
</div>
</my-element>
```
## About ApplyShim
ApplyShim provides a shim for the `@apply` syntax proposed at https://tabatkins.github.io/specs/css-apply-rule/, which expands the definition CSS Custom Properties to include objects that can be applied as a block.
This is done by transforming the block definition into a set of CSS Custom Properties, and replacing uses of `@apply` with consumption of those custom properties.
### Status:
The `@apply` proposal has been abandoned in favor of the ::part/::theme [Shadow Parts spec](https://tabatkins.github.io/specs/css-shadow-parts/). Therefore, the ApplyShim library is deprecated and provided only for backwards compatibility. Support going forward will be limited to critical bug fixes.
### Known Issues:
* Mixin properties cannot be modified at runtime.
* Nested mixins are not supported.
* Shorthand properties are not expanded and may conflict with more explicit properties. Whenever shorthand notations are used in conjunction with their expanded forms in `@apply`, depending in the order of usage of the mixins, properties can be overridden. This means that using both `background-color: green;` and `background: red;` in two separate CSS selectors
can result in `background-color: transparent` in the selector that `background: red;` is specified.
```css
#nonexistent {
--my-mixin: {
background: red;
}
}
```
with an element style definition of
```css
:host {
display: block;
background-color: green;
@apply(--my-mixin);
}
```
results in the background being `transparent`, as an empty `background` definition replaces
the `@apply` definition.
For this reason, we recommend avoiding shorthand properties.
### Example:
Here we define a block called `--mixin` at the document level, and apply that block to `my-element` somewhere in the page.
```css
html {
--mixin: {
border: 2px solid black;
background-color: green;
}
}
my-element {
border: 1px dotted orange;
@apply --mixin;
}
```
becomes:
```css
html {
--mixin_-_border: 2px solid black;
--mixin_-_background-color: green;
}
my-element {
border: var(--mixin_-_border, 1px dotted orange);
background-color: var(--mixin_-_background-color);
}
```
## About CustomStyleInterface
CustomStyleInterface provides API to process `<style>` elements that are not inside of
ShadowRoots, and simulate upper-boundary style scoping for ShadyDOM.
To add document-level styles to ShadyCSS, one can call `CustomStyleInterface.addCustomStyle(styleElement)` or `CustomStyleInterface.addCustomStyle({getStyle: () => styleElement})`
An example usage of the document-level styling api can be found in `examples/document-style-lib.js`, and another example that uses a custom element wrapper can be found in `examples/custom-style-element.js`
### Example:
```html
<style class="document-style">
html {
--content-color: brown;
}
</style>
<my-element>This text will be brown!</my-element>
<script>
CustomStyleInterface.addCustomStyle(document.querySelector('style.document-style'));
</script>
```
Another example with a wrapper `<custom-style>` element
```html
<custom-style>
<style>
html {
--content-color: brown;
}
</style>
</custom-style>
<script>
class CustomStyle extends HTMLElement {
constructor() {
CustomStyleInterface.addCustomStyle(this);
}
getStyle() {
return this.querySelector('style');
}
}
</script>
<my-element>This this text will be brown!</my-element>
```
Another example with a function that produces style elements
```html
<my-element>This this text will be brown!</my-element>
<script>
CustomStyleInterface.addCustomStyle({
getStyle() {
const s = document.createElement('style');
s.textContent = 'html{ --content-color: brown }';
return s;
}
});
</script>
```
## Usage
To use ShadyCSS:
1. First, call `ShadyCSS.prepareTemplate(template, name)` on a
`<template>` element that will be imported into a `shadowRoot`.
2. When the element instance is connected, call `ShadyCSS.styleElement(element)`
3. Create and stamp the element's shadowRoot
4. Whenever dynamic updates are required, call `ShadyCSS.styleSubtree(element)`.
5. If a styling change is made that may affect the whole document, call
`ShadyCSS.styleDocument()`.
The following example uses ShadyCSS and ShadyDOM to define a custom element.
```html
<template id="myElementTemplate">
<style>
:host {
display: block;
padding: 8px;
}
#content {
background-color: var(--content-color);
}
.slot-container ::slotted(*) {
border: 1px solid steelblue;
margin: 4px;
}
</style>
<div id="content">Content</div>
<div class="slot-container">
<slot></slot>
</div>
</template>
<script>
// Use polyfill only in browsers that lack native Shadow DOM.
window.ShadyCSS && ShadyCSS.prepareTemplate(myElementTemplate, 'my-element');
class MyElement extends HTMLElement {
connectedCallback() {
window.ShadyCSS && ShadyCSS.styleElement(this);
if (!this.shadowRoot) {
this.attachShadow({mode: 'open'});
this.shadowRoot.appendChild(
document.importNode(myElementTemplate.content, true));
}
}
}
customElements.define('my-element', MyElement);
</script>
```
## Type Extension elements
ShadyCSS can also be used with type extension elements by supplying the base
element name to `prepareTemplate` as a third argument.
### Example
```html
<template id="myElementTemplate">
<style>
:host {
display: block;
padding: 8px;
}
#content {
background-color: var(--content-color);
}
.slot-container ::slotted(*) {
border: 1px solid steelblue;
margin: 4px;
}
</style>
<div id="content">Content</div>
<div class="slot-container">
<slot></slot>
</div>
</template>
<script>
windo
platform-tools2.zip
需积分: 0 48 浏览量
更新于2023-07-14
收藏 19.42MB ZIP 举报
平台工具包platform-tools是Android开发不可或缺的一部分,它包含了Android系统开发者所需要的各种命令行工具,用于进行设备管理和应用程序的调试工作。platform-tools2.zip文件很可能是Android SDK中的一个更新版本,包含了一系列升级后的平台工具。
在Android开发过程中,platform-tools扮演着至关重要的角色,主要包含以下几个核心工具:
1. **ADB (Android Debug Bridge)**:ADB是一个多功能的命令行工具,用于连接计算机和运行Android操作系统的设备或模拟器。通过ADB,开发者可以进行设备管理、安装应用、运行shell命令、传输文件以及进行远程调试。
2. **Fastboot**:这是一个用于在设备启动模式下进行低级别系统修改的工具,比如更新分区映像、擦除分区或解锁设备的Bootloader。
3. **systrace**:该工具用于性能分析和系统追踪,可以帮助开发者了解应用程序的运行情况,优化性能,找出瓶颈。
4. **Hprof-conv**:这个工具用于转换和压缩Android应用程序的内存快照文件(.hprof格式),便于内存分析和泄漏检测。
5. **Tracer for OpenGL ES**:这是一个图形性能分析工具,可以记录和分析OpenGL ES的调用,帮助开发者优化图形渲染性能。
6. **monkey**:Monkey是一个自动化测试工具,能够向设备发送随机用户事件流,如触摸屏点击、键盘输入等,以测试应用的稳定性和健壮性。
7. **apkanalyzer**:这是Android Studio新增的一个工具,用于分析APK的各个方面,如大小、依赖关系、权限等,有助于优化应用的发布和性能。
8. **dexdump**:它能显示Dalvik虚拟机的.dex文件的内部结构,对于理解APK的组成和优化APK大小非常有用。
9. **zipalign**:这个工具用于对APK进行对齐处理,确保所有数据都以4字节的边界对齐,以提高运行时的效率。
10. **aapt**:Android Asset Packaging Tool,用于处理应用资源,包括编译、打包和验证资源文件,生成.R类文件供代码使用。
在使用platform-tools时,开发者通常会将其路径添加到系统的PATH环境变量中,以便于在任何目录下都能直接使用这些工具。随着Android系统的不断更新,platform-tools也会定期推出新版本,增加新的功能或改进现有工具的性能,以适应开发者的需求。
在解压并安装platform-tools2后,开发者可以通过命令行来使用这些工具,例如通过adb命令连接设备,或者使用fastboot来解锁Bootloader进行系统更新。了解并熟练掌握这些工具的使用方法,将极大地提升Android开发和调试的效率。
2302_79129700
- 粉丝: 0
- 资源: 1
最新资源
- S7-200SMART多段插补库(含使用说明+示例程序).rar
- 毕业设计-基于SSM协同过滤音乐推荐管理系统全部资料+详细文档+高分项目+源码.zip
- 毕业设计-基于SSM小区物业管理系统全部资料+详细文档+高分项目+源码.zip
- 毕业设计-基于SSM网上医院预约挂号系统全部资料+详细文档+高分项目+源码.zip
- 毕业设计-基于SSM学生毕业设计-论文选题系统全部资料+详细文档+高分项目+源码.zip
- 毕业设计-基于SSM学而优奖学金评定管理系统全部资料+详细文档+高分项目+源码.zip
- 毕业设计-基于thinkphp6.0+mysql+bootstrap4的疫情防控系统全部资料+详细文档+高分项目+源码.zip
- 3-各地区-不同行业-就业、失业、工资144个指标(1990-2021年).zip
- MATLAB代码:计及源-荷双重不确定性的电厂 微网日前随机优化调度 关键词:电厂 微网 随机优化 随机调度 源-荷双重不确定性 电厂调度 参考文档:Virtual power plant
- rds.zip
- common.zip
- 毕业设计-基于VUe+Element的人事管理系统全部资料+详细文档+高分项目+源码.zip
- 毕业设计-基于Structs+Hibernate+Spring+mahout+bootstrap+mysql 实现的网上书店前后台系统全部资料+详细文档+高分项
- 毕业设计-基于vue+Python在线考试系统前端全部资料+详细文档+高分项目+源码.zip
- 毕业设计-基于vue2的在线答题系统前端全部资料+详细文档+高分项目+源码.zip
- 毕业设计-基于VUE+PHP的高校校友信息管理系统毕业设计-全部资料+详细文档+高分项目+源码.zip