cotomy 0.4.0 → 0.4.2
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 +11 -9
- package/dist/browser/cotomy.js +22 -13
- package/dist/browser/cotomy.js.map +1 -1
- package/dist/browser/cotomy.min.js +1 -1
- package/dist/browser/cotomy.min.js.map +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/view.js +22 -13
- package/dist/esm/view.js.map +1 -1
- package/dist/types/view.d.ts +25 -6
- package/package.json +1 -1
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
|
-
- `[
|
|
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
|
|
@@ -74,8 +76,8 @@ The View layer provides thin wrappers around DOM elements and window events.
|
|
|
74
76
|
- `lastChild(selector = "*", type?)`
|
|
75
77
|
- `closest(selector, type?)`
|
|
76
78
|
- `find(selector, type?)` / `first(selector = "*", type?)` / `last(selector = "*", type?)` / `contains(selector)`
|
|
77
|
-
- `append(child): this` / `prepend(child): this` / `appendAll(children): this`
|
|
78
|
-
- `insertBefore(sibling): this` / `insertAfter(sibling): this`
|
|
79
|
+
- `append(child): this` / `prepend(child): this` / `appendAll(children): this` — accepts `CotomyElement`, HTML string, or `{ html, css? }`
|
|
80
|
+
- `insertBefore(sibling): this` / `insertAfter(sibling): this` — accepts `CotomyElement`, HTML string, or `{ html, css? }`
|
|
79
81
|
- `appendTo(target): this` / `prependTo(target): this`
|
|
80
82
|
- `comesBefore(target): boolean` / `comesAfter(target): boolean` — Checks DOM order (returns `false` for the same element or disconnected nodes)
|
|
81
83
|
- `clone(type?): CotomyElement` - Returns a deep-cloned element, optionally typed, and reassigns a new `data-cotomy-instance` while preserving the `data-cotomy-scopeid` for scoped CSS sharing (strips `data-cotomy-moving`). Cloning an invalidated element (`data-cotomy-invalidated`) throws.
|
|
@@ -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
|
-
[
|
|
123
|
-
[
|
|
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
|
|
|
@@ -158,7 +160,7 @@ npm test -- --run tests/view.spec.ts -t "compares document order with comesBefor
|
|
|
158
160
|
- `initialize(): this`
|
|
159
161
|
- DOM helpers
|
|
160
162
|
- `body: CotomyElement`
|
|
161
|
-
- `append(element: CotomyElement): this`
|
|
163
|
+
- `append(element: CotomyElement | string | { html: string, css?: string }): this`
|
|
162
164
|
- `scrollTo(target, options?: CotomyScrollOptions | Partial<CotomyScrollOptions>): this` — Scrolls to reveal a target (`selector | CotomyElement | HTMLElement`)
|
|
163
165
|
- `moveNext(focused: CotomyElement, shift = false)` — Move focus to next/previous focusable
|
|
164
166
|
- Window events
|
|
@@ -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
|
-
[
|
|
311
|
+
[root] {
|
|
310
312
|
display: block;
|
|
311
313
|
}
|
|
312
|
-
[
|
|
314
|
+
[root] > p {
|
|
313
315
|
text-align: center;
|
|
314
316
|
}
|
|
315
317
|
`
|
package/dist/browser/cotomy.js
CHANGED
|
@@ -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
|
|
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;
|
|
@@ -1614,18 +1616,23 @@ class CotomyElement {
|
|
|
1614
1616
|
target.trigger("cotomy:transitend");
|
|
1615
1617
|
}
|
|
1616
1618
|
}
|
|
1619
|
+
static toElement(target) {
|
|
1620
|
+
return target instanceof CotomyElement ? target : new CotomyElement(target);
|
|
1621
|
+
}
|
|
1617
1622
|
prepend(prepend) {
|
|
1618
|
-
CotomyElement.
|
|
1619
|
-
|
|
1623
|
+
const e = CotomyElement.toElement(prepend);
|
|
1624
|
+
CotomyElement.runWithMoveEvents(e, () => {
|
|
1625
|
+
this.element.prepend(e.element);
|
|
1620
1626
|
});
|
|
1621
|
-
|
|
1627
|
+
e.ensureScopedCss();
|
|
1622
1628
|
return this;
|
|
1623
1629
|
}
|
|
1624
1630
|
append(target) {
|
|
1625
|
-
CotomyElement.
|
|
1626
|
-
|
|
1631
|
+
const e = CotomyElement.toElement(target);
|
|
1632
|
+
CotomyElement.runWithMoveEvents(e, () => {
|
|
1633
|
+
this.element.append(e.element);
|
|
1627
1634
|
});
|
|
1628
|
-
|
|
1635
|
+
e.ensureScopedCss();
|
|
1629
1636
|
return this;
|
|
1630
1637
|
}
|
|
1631
1638
|
appendAll(targets) {
|
|
@@ -1633,17 +1640,19 @@ class CotomyElement {
|
|
|
1633
1640
|
return this;
|
|
1634
1641
|
}
|
|
1635
1642
|
insertBefore(append) {
|
|
1636
|
-
CotomyElement.
|
|
1637
|
-
|
|
1643
|
+
const e = CotomyElement.toElement(append);
|
|
1644
|
+
CotomyElement.runWithMoveEvents(e, () => {
|
|
1645
|
+
this.element.before(e.element);
|
|
1638
1646
|
});
|
|
1639
|
-
|
|
1647
|
+
e.ensureScopedCss();
|
|
1640
1648
|
return this;
|
|
1641
1649
|
}
|
|
1642
1650
|
insertAfter(append) {
|
|
1643
|
-
CotomyElement.
|
|
1644
|
-
|
|
1651
|
+
const e = CotomyElement.toElement(append);
|
|
1652
|
+
CotomyElement.runWithMoveEvents(e, () => {
|
|
1653
|
+
this.element.after(e.element);
|
|
1645
1654
|
});
|
|
1646
|
-
|
|
1655
|
+
e.ensureScopedCss();
|
|
1647
1656
|
return this;
|
|
1648
1657
|
}
|
|
1649
1658
|
appendTo(target) {
|