cotomy 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -37,7 +37,9 @@ The View layer provides thin wrappers around DOM elements and window events.
37
37
  - `new CotomyElement({ tagname, text?, css? })`
38
38
  - Scoped CSS
39
39
  - `scopeId: string` - Returns the value stored in the element's `data-cotomy-scopeid` attribute
40
- - `[scope]` placeholder in provided CSS is replaced by `[data-cotomy-scopeid="..."]`
40
+ - `[root]` placeholder in provided CSS is replaced by `[data-cotomy-scopeid="..."]`
41
+ - `[scope]` is deprecated and will be removed in a future release (use `[root]` instead)
42
+ - If neither `[root]` nor `[scope]` is present, `[root]` is treated as if it were prefixed automatically
41
43
  - Scoped CSS text is kept on the instance; if the `<style id="css-${scopeId}">` is missing when the element is attached, it will be re-generated automatically
42
44
  - `stylable: boolean` - False for tags like `script`, `style`, `link`, `meta`
43
45
  - Static helpers
@@ -119,8 +121,8 @@ import { CotomyElement } from "cotomy";
119
121
  const panel = new CotomyElement({
120
122
  html: `<div class="panel"><button class="ok">OK</button></div>`,
121
123
  css: `
122
- [scope] .panel { padding: 8px; }
123
- [scope] .ok { color: green; }
124
+ [root] .panel { padding: 8px; }
125
+ [root] .ok { color: green; }
124
126
  `,
125
127
  });
126
128
 
@@ -143,7 +145,7 @@ npm test -- --run tests/view.spec.ts -t "throws when cloning an invalidated elem
143
145
  npm test -- --run tests/view.spec.ts -t "compares document order with comesBefore/comesAfter"
144
146
  ```
145
147
 
146
- 普段は `npm test` で全体を実行できます。上記のコマンドでは `[scope]` 展開、スコープID共有のクローン挙動、インスタンス単位のイベント隔離、クローン後のスコープCSS再生成、移動フラグの除去、無効化要素のクローン拒否、DOM順序判定などをピンポイントで確認できます。
148
+ 普段は `npm test` で全体を実行できます。上記のコマンドでは `[root]/[scope]` 展開、スコープID共有のクローン挙動、インスタンス単位のイベント隔離、クローン後のスコープCSS再生成、移動フラグの除去、無効化要素のクローン拒否、DOM順序判定などをピンポイントで確認できます。
147
149
 
148
150
  ### CotomyMetaElement
149
151
 
@@ -306,10 +308,10 @@ By passing HTML and CSS strings to the constructor, it is possible to generate E
306
308
  </div>
307
309
  `,
308
310
  css: /* css */`
309
- [scope] {
311
+ [root] {
310
312
  display: block;
311
313
  }
312
- [scope] > p {
314
+ [root] > p {
313
315
  text-align: center;
314
316
  }
315
317
  `
@@ -1008,7 +1008,9 @@ class CotomyElement {
1008
1008
  const cssid = this.scopedCssElementId;
1009
1009
  CotomyElement.find(`#${cssid}`).forEach(e => e.remove());
1010
1010
  const element = document.createElement("style");
1011
- const writeCss = css.replace(/\[scope\]/g, `[data-cotomy-scopeid="${this.scopeId}"]`);
1011
+ const hasScopeOrRoot = /\[(?:scope|root)\]/.test(css);
1012
+ const normalizedCss = hasScopeOrRoot ? css : `[root] ${css}`;
1013
+ const writeCss = normalizedCss.replace(/\[(?:scope|root)\]/g, `[data-cotomy-scopeid="${this.scopeId}"]`);
1012
1014
  const node = document.createTextNode(writeCss);
1013
1015
  element.appendChild(node);
1014
1016
  element.id = cssid;