cotomy 0.3.9 → 0.3.11
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 +3 -0
- package/dist/browser/cotomy.js +12 -0
- 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 +12 -0
- package/dist/esm/view.js.map +1 -1
- package/dist/types/view.d.ts +3 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -48,6 +48,7 @@ The View layer provides thin wrappers around DOM elements and window events.
|
|
|
48
48
|
- `CotomyElement.byId(id, type?)`
|
|
49
49
|
- `CotomyElement.empty(type?)` — Creates a hidden placeholder element
|
|
50
50
|
- Identity & matching
|
|
51
|
+
- `instanceId: string | null | undefined` — Public getter backed by `data-cotomy-instance`
|
|
51
52
|
- `id: string | null | undefined`
|
|
52
53
|
- `generateId(prefix = "__cotomy_elem__"): this`
|
|
53
54
|
- `is(selector: string): boolean` — Parent-aware matching helper
|
|
@@ -75,6 +76,7 @@ The View layer provides thin wrappers around DOM elements and window events.
|
|
|
75
76
|
- `append(child): this` / `prepend(child): this` / `appendAll(children): this`
|
|
76
77
|
- `insertBefore(sibling): this` / `insertAfter(sibling): this`
|
|
77
78
|
- `appendTo(target): this` / `prependTo(target): this`
|
|
79
|
+
- `comesBefore(target): boolean` / `comesAfter(target): boolean` — Checks DOM order (returns `false` for the same element or disconnected nodes)
|
|
78
80
|
- `clone(type?): CotomyElement` - Returns a deep-cloned element, optionally typed, and reassigns new `data-cotomy-instance`/`data-cotomy-scopeid` values (and strips `data-cotomy-moving`). Cloning an invalidated element (`data-cotomy-invalidated`) throws.
|
|
79
81
|
- `clear(): this` — Removes all descendants and text
|
|
80
82
|
- `remove(): void` — Explicitly non-chainable after removal
|
|
@@ -130,6 +132,7 @@ npx vitest run tests/view.spec.ts -t "assigns fresh scope ids when cloning, incl
|
|
|
130
132
|
npx vitest run tests/view.spec.ts -t "regenerates instance ids and lifecycle hooks when cloning"
|
|
131
133
|
npx vitest run tests/view.spec.ts -t "strips moving flags when cloning"
|
|
132
134
|
npx vitest run tests/view.spec.ts -t "throws when cloning an invalidated element"
|
|
135
|
+
npx vitest run tests/view.spec.ts -t "compares document order with comesBefore/comesAfter"
|
|
133
136
|
```
|
|
134
137
|
|
|
135
138
|
The first command ensures `[scope]` expands to `[data-cotomy-scopeid="..."]` in injected styles, the second confirms that cloning reassigns new `data-cotomy-scopeid` attributes to the cloned tree, the third verifies fresh `data-cotomy-instance` values and lifecycle hooks, and the last two cover stripping transit flags and rejecting invalidated nodes during cloning.
|
package/dist/browser/cotomy.js
CHANGED
|
@@ -1283,6 +1283,18 @@ class CotomyElement {
|
|
|
1283
1283
|
get isRightViewport() {
|
|
1284
1284
|
return this.element.getBoundingClientRect().left > window.innerWidth;
|
|
1285
1285
|
}
|
|
1286
|
+
comesBefore(target) {
|
|
1287
|
+
const pos = this.element.compareDocumentPosition(target.element);
|
|
1288
|
+
if (pos & Node.DOCUMENT_POSITION_DISCONNECTED)
|
|
1289
|
+
return false;
|
|
1290
|
+
return (pos & Node.DOCUMENT_POSITION_FOLLOWING) !== 0;
|
|
1291
|
+
}
|
|
1292
|
+
comesAfter(target) {
|
|
1293
|
+
const pos = this.element.compareDocumentPosition(target.element);
|
|
1294
|
+
if (pos & Node.DOCUMENT_POSITION_DISCONNECTED)
|
|
1295
|
+
return false;
|
|
1296
|
+
return (pos & Node.DOCUMENT_POSITION_PRECEDING) !== 0;
|
|
1297
|
+
}
|
|
1286
1298
|
hasAttribute(name) {
|
|
1287
1299
|
return this.element.hasAttribute(name);
|
|
1288
1300
|
}
|