mount-observer 0.0.112 → 0.1.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.
Files changed (181) hide show
  1. package/Events.js +62 -26
  2. package/Events.ts +52 -30
  3. package/MountObserver.js +285 -514
  4. package/MountObserver.ts +362 -538
  5. package/README.md +149 -56
  6. package/SharedMutationObserver.js +70 -0
  7. package/SharedMutationObserver.ts +96 -0
  8. package/attrCoordinates.js +93 -0
  9. package/attrCoordinates.ts +122 -0
  10. package/index.js +3 -0
  11. package/index.ts +22 -0
  12. package/loadImports.js +47 -0
  13. package/loadImports.ts +56 -0
  14. package/mediaQuery.js +86 -0
  15. package/mediaQuery.ts +113 -0
  16. package/package.json +11 -119
  17. package/playwright.config.ts +0 -1
  18. package/types.d.ts +104 -0
  19. package/whereAttr.js +174 -0
  20. package/whereAttr.ts +221 -0
  21. package/LICENSE +0 -21
  22. package/Newish.js +0 -145
  23. package/Newish.ts +0 -169
  24. package/ObsAttr.js +0 -18
  25. package/ObsAttr.ts +0 -18
  26. package/RootMutObs.js +0 -49
  27. package/RootMutObs.ts +0 -58
  28. package/Synthesizer.js +0 -125
  29. package/Synthesizer.ts +0 -130
  30. package/bindish.js +0 -15
  31. package/bindish.ts +0 -22
  32. package/compose.js +0 -148
  33. package/compose.ts +0 -164
  34. package/doCleanup.js +0 -31
  35. package/doCleanup.ts +0 -34
  36. package/getWhereAttrSelector.js +0 -83
  37. package/getWhereAttrSelector.ts +0 -92
  38. package/preloadContent.js +0 -44
  39. package/preloadContent.ts +0 -47
  40. package/readAttrs.ts +0 -60
  41. package/refid/README.md +0 -259
  42. package/refid/arr.js +0 -4
  43. package/refid/arr.ts +0 -4
  44. package/refid/camelToKebab.js +0 -4
  45. package/refid/camelToKebab.ts +0 -4
  46. package/refid/genIds.js +0 -190
  47. package/refid/genIds.ts +0 -177
  48. package/refid/getAdjRefs.js +0 -38
  49. package/refid/getAdjRefs.ts +0 -38
  50. package/refid/getContext.js +0 -13
  51. package/refid/getContext.ts +0 -14
  52. package/refid/getCount.js +0 -8
  53. package/refid/getCount.ts +0 -8
  54. package/refid/getIsh.js +0 -35
  55. package/refid/getIsh.ts +0 -37
  56. package/refid/hostish.js +0 -18
  57. package/refid/hostish.ts +0 -20
  58. package/refid/ism.js +0 -78
  59. package/refid/ism.ts +0 -81
  60. package/refid/itemprops.js +0 -60
  61. package/refid/itemprops.ts +0 -67
  62. package/refid/joinMatching.js +0 -56
  63. package/refid/joinMatching.ts +0 -54
  64. package/refid/nudge.js +0 -23
  65. package/refid/nudge.ts +0 -23
  66. package/refid/regIsh.js +0 -27
  67. package/refid/regIsh.ts +0 -31
  68. package/refid/secretKeys.js +0 -5
  69. package/refid/secretKeys.ts +0 -5
  70. package/refid/splitRefs.js +0 -6
  71. package/refid/splitRefs.ts +0 -6
  72. package/refid/stdVal.js +0 -15
  73. package/refid/stdVal.ts +0 -15
  74. package/refid/via.js +0 -114
  75. package/refid/via.ts +0 -113
  76. package/slotkin/affine.js +0 -39
  77. package/slotkin/affine.ts +0 -46
  78. package/slotkin/beKindred.js +0 -45
  79. package/slotkin/beKindred.ts +0 -55
  80. package/slotkin/getBreadth.js +0 -19
  81. package/slotkin/getBreadth.ts +0 -21
  82. package/slotkin/getFrag.js +0 -22
  83. package/slotkin/getFrag.ts +0 -21
  84. package/slotkin/toQuery.js +0 -12
  85. package/slotkin/toQuery.ts +0 -13
  86. package/slotkin/wrap.js +0 -13
  87. package/slotkin/wrap.ts +0 -18
  88. package/ts-refs/LICENSE +0 -21
  89. package/ts-refs/README.md +0 -18
  90. package/ts-refs/be-a-beacon/types.d.ts +0 -22
  91. package/ts-refs/be-alit/types.d.ts +0 -1
  92. package/ts-refs/be-based/types.d.ts +0 -32
  93. package/ts-refs/be-bound/types.d.ts +0 -65
  94. package/ts-refs/be-buttoned-up/types.d.ts +0 -21
  95. package/ts-refs/be-calculating/types.d.ts +0 -57
  96. package/ts-refs/be-clonable/types.d.ts +0 -28
  97. package/ts-refs/be-committed/types.d.ts +0 -26
  98. package/ts-refs/be-consoling/types.d.ts +0 -25
  99. package/ts-refs/be-counted/types.d.ts +0 -88
  100. package/ts-refs/be-delible/types.d.ts +0 -26
  101. package/ts-refs/be-directive/types.d.ts +0 -43
  102. package/ts-refs/be-dispatching/types.d.ts +0 -41
  103. package/ts-refs/be-elevating/types.d.ts +0 -55
  104. package/ts-refs/be-enhanced/types.d.ts +0 -32
  105. package/ts-refs/be-enhancing/types.d.ts +0 -31
  106. package/ts-refs/be-evanescent/types.d.ts +0 -20
  107. package/ts-refs/be-eventing/types.d.ts +0 -27
  108. package/ts-refs/be-exportable/types.d.ts +0 -26
  109. package/ts-refs/be-fetching/types.d.ts +0 -73
  110. package/ts-refs/be-flashy/types.d.ts +0 -27
  111. package/ts-refs/be-formalizing/types.d.ts +0 -29
  112. package/ts-refs/be-formidable/types.d.ts +0 -64
  113. package/ts-refs/be-giddy/types.d.ts +0 -26
  114. package/ts-refs/be-gingerly/types.d.ts +0 -19
  115. package/ts-refs/be-gone/types.d.ts +0 -24
  116. package/ts-refs/be-hashing-out/types.d.ts +0 -22
  117. package/ts-refs/be-hive/types.d.ts +0 -18
  118. package/ts-refs/be-imbued/types.d.ts +0 -30
  119. package/ts-refs/be-included/types.d.ts +0 -20
  120. package/ts-refs/be-inclusive/types.d.ts +0 -30
  121. package/ts-refs/be-intersectional/types.d.ts +0 -37
  122. package/ts-refs/be-intl/types.d.ts +0 -28
  123. package/ts-refs/be-invoking/types.d.ts +0 -28
  124. package/ts-refs/be-joining/types.d.ts +0 -26
  125. package/ts-refs/be-kvetching/types.d.ts +0 -24
  126. package/ts-refs/be-lazy/types.d.ts +0 -29
  127. package/ts-refs/be-literate/types.d.ts +0 -29
  128. package/ts-refs/be-mediating/types.d.ts +0 -34
  129. package/ts-refs/be-methodical/types.d.ts +0 -20
  130. package/ts-refs/be-modding/types.d.ts +0 -18
  131. package/ts-refs/be-observant/types.d.ts +0 -27
  132. package/ts-refs/be-observing/types.d.ts +0 -84
  133. package/ts-refs/be-parsed/types.d.ts +0 -19
  134. package/ts-refs/be-parsing/types.d.ts +0 -37
  135. package/ts-refs/be-persistent/types.d.ts +0 -66
  136. package/ts-refs/be-propagating/types.d.ts +0 -26
  137. package/ts-refs/be-reformable/types.d.ts +0 -48
  138. package/ts-refs/be-render-neutral/types.d.ts +0 -31
  139. package/ts-refs/be-scoped/types.d.ts +0 -24
  140. package/ts-refs/be-sharing/types.d.ts +0 -17
  141. package/ts-refs/be-switched/types.d.ts +0 -155
  142. package/ts-refs/be-typed/types.d.ts +0 -36
  143. package/ts-refs/be-value-added/types.d.ts +0 -34
  144. package/ts-refs/be-valued/types.d.ts +0 -22
  145. package/ts-refs/be-written/types.d.ts +0 -59
  146. package/ts-refs/css-charts/types.d.ts +0 -38
  147. package/ts-refs/css-echarts/types.d.ts +0 -13
  148. package/ts-refs/data-props/types.d.ts +0 -27
  149. package/ts-refs/do-inc/types.d.ts +0 -28
  150. package/ts-refs/do-invoke/types.d.ts +0 -28
  151. package/ts-refs/do-toggle/types.d.ts +0 -27
  152. package/ts-refs/em-bower/types.d.ts +0 -24
  153. package/ts-refs/fetch-for/types.d.ts +0 -37
  154. package/ts-refs/folder-picker/types.d.ts +0 -43
  155. package/ts-refs/for-fetch/doc.d.ts +0 -98
  156. package/ts-refs/for-fetch/types.d.ts +0 -83
  157. package/ts-refs/mount-observer/types.d.ts +0 -248
  158. package/ts-refs/mt-si/types.d.ts +0 -21
  159. package/ts-refs/per-each/types.d.ts +0 -51
  160. package/ts-refs/soak-up/types.d.ts +0 -36
  161. package/ts-refs/trans-render/XV/types.d.ts +0 -69
  162. package/ts-refs/trans-render/asmr/types.d.ts +0 -138
  163. package/ts-refs/trans-render/be/types.d.ts +0 -198
  164. package/ts-refs/trans-render/dss/types.d.ts +0 -57
  165. package/ts-refs/trans-render/froop/types.d.ts +0 -416
  166. package/ts-refs/trans-render/funions/types.d.ts +0 -12
  167. package/ts-refs/trans-render/lib/mixins/types.d.ts +0 -42
  168. package/ts-refs/trans-render/lib/prs/types.d.ts +0 -40
  169. package/ts-refs/trans-render/lib/types.d.ts +0 -489
  170. package/ts-refs/trans-render/types.d.ts +0 -583
  171. package/ts-refs/wc-info/SimpleWCInfo.d.ts +0 -15
  172. package/ts-refs/when-resolved/types.d.ts +0 -30
  173. package/ts-refs/xp-as/types.d.ts +0 -20
  174. package/ts-refs/xtal-element/types.d.ts +0 -43
  175. package/ts-refs/xtal-frappe-chart/types.d.ts +0 -193
  176. package/upShadowSearch.js +0 -25
  177. package/upShadowSearch.ts +0 -23
  178. package/waitForEvent.js +0 -12
  179. package/waitForEvent.ts +0 -13
  180. package/waitForIsh.js +0 -21
  181. package/waitForIsh.ts +0 -20
@@ -1,67 +0,0 @@
1
- function getFirst(element: Element, prop: string): Element | null {
2
- for(const child of element.children){
3
- const itemprop = child.getAttribute('itemprop');
4
- if(itemprop === prop){
5
- return child;
6
- }
7
- if(!child.hasAttribute('itemscope')){
8
- const found = getFirst(child, prop);
9
- if(found) return found;
10
- }
11
- }
12
- return null;
13
- }
14
- const proxies = new WeakMap<Element, ProxyConstructor>();
15
- const refLookup = new WeakMap<Element, PropManagerLookup>();
16
- Object.defineProperty(Element.prototype, 'itemprops', {
17
-
18
- get(){
19
- if(!proxies.has(this)){
20
- const handler = {
21
- get(target: Element, prop: string) {
22
- let lookup: PropManagerLookup;
23
- if(refLookup.has(target)){
24
- lookup = refLookup.get(target)!;
25
- }else{
26
- lookup = new Map<Prop, ItempropManager>();
27
- refLookup.set(target, lookup);
28
- }
29
- if(lookup.has(prop)){
30
- return lookup.get(prop);
31
- }else{
32
- const propManager = new ItempropManager(target, prop as string);
33
- lookup.set(prop, propManager);
34
- return propManager;
35
- }
36
- },
37
-
38
- };
39
- proxies.set(this, new Proxy(this, handler));
40
- }
41
-
42
-
43
- return proxies.get(this);
44
- }
45
- });
46
-
47
- type Prop = string;
48
-
49
- type PropManagerLookup = Map<Prop, ItempropManager>;
50
-
51
- class ItempropManager extends EventTarget {
52
- #el: WeakRef<Element>;
53
- #prop: Prop;
54
- constructor(el: Element, prop: Prop){
55
- super();
56
- this.#el = new WeakRef(el);
57
- this.#prop = prop;
58
- }
59
-
60
- get first(){
61
- const el = this.#el.deref();
62
- if(el === undefined) return null;
63
- return getFirst(el, this.#prop);
64
- }
65
-
66
- }
67
-
@@ -1,56 +0,0 @@
1
- import { camelToKebab } from './camelToKebab.js';
2
- const proxies = new WeakMap();
3
- Object.defineProperty(Element.prototype, 'joinMatching', {
4
- get() {
5
- if (!proxies.has(this)) {
6
- const handler = {
7
- get(target, prop) {
8
- const jm = new JoinMatching(target, prop);
9
- return jm;
10
- },
11
- };
12
- proxies.set(this, new Proxy(this, handler));
13
- }
14
- return proxies.get(this);
15
- },
16
- });
17
- export class JoinMatching {
18
- #proxy;
19
- elRef;
20
- attr;
21
- constructor(el, prop) {
22
- this.elRef = new WeakRef(el);
23
- this.attr = camelToKebab(prop);
24
- }
25
- get fromClosest() {
26
- const handler = {
27
- get(self, closestQry) {
28
- const { elRef, attr } = self;
29
- const el = elRef.deref();
30
- if (el === undefined)
31
- return [];
32
- const attrVal = el.getAttribute(attr);
33
- const tryClosestQry = camelToKebab(closestQry);
34
- let closest = el.closest(tryClosestQry);
35
- if (closest === null)
36
- closest = el.closest(closestQry);
37
- if (closest === null)
38
- throw 404;
39
- return Array.from(closest.querySelectorAll(`[${attr}="${attrVal}"]`));
40
- //console.log({self, closestQry, prop, el});
41
- }
42
- };
43
- return new Proxy(this, handler);
44
- }
45
- get fromParent() {
46
- const { elRef, attr } = this;
47
- const el = elRef.deref();
48
- if (el === undefined)
49
- return [];
50
- const { parentElement } = el;
51
- if (parentElement === null)
52
- return [];
53
- const attrVal = el.getAttribute(attr);
54
- return Array.from(parentElement.querySelectorAll(`[${attr}="${attrVal}"]`));
55
- }
56
- }
@@ -1,54 +0,0 @@
1
- import {camelToKebab} from './camelToKebab.js';
2
- const proxies = new WeakMap<Element, ProxyConstructor>();
3
- Object.defineProperty(Element.prototype, 'joinMatching', {
4
- get(){
5
- if(!proxies.has(this)){
6
- const handler = {
7
- get(target: Element, prop: string) {
8
- const jm = new JoinMatching(target, prop);
9
- return jm;
10
- },
11
- }
12
- proxies.set(this, new Proxy(this, handler));
13
- }
14
- return proxies.get(this);
15
- },
16
- });
17
-
18
- export class JoinMatching {
19
- #proxy: ProxyConstructor | undefined;
20
- elRef: WeakRef<Element>;
21
- attr: string;
22
- constructor(el: Element, prop: string){
23
- this.elRef = new WeakRef(el);
24
- this.attr = camelToKebab(prop);
25
- }
26
-
27
- get fromClosest(){
28
- const handler = {
29
- get(self: JoinMatching, closestQry: string){
30
- const {elRef, attr} = self;
31
- const el = elRef.deref();
32
- if(el === undefined) return [];
33
- const attrVal = el.getAttribute(attr);
34
- const tryClosestQry = camelToKebab(closestQry);
35
- let closest = el.closest(tryClosestQry);
36
- if(closest === null) closest = el.closest(closestQry);
37
- if(closest === null) throw 404;
38
- return Array.from(closest.querySelectorAll(`[${attr}="${attrVal}"]`))
39
- //console.log({self, closestQry, prop, el});
40
- }
41
- }
42
- return new Proxy(this, handler);
43
- }
44
-
45
- get fromParent(){
46
- const {elRef, attr} = this;
47
- const el = elRef.deref();
48
- if(el === undefined) return [];
49
- const {parentElement} = el;
50
- if(parentElement === null) return [];
51
- const attrVal = el.getAttribute(attr);
52
- return Array.from(parentElement.querySelectorAll(`[${attr}="${attrVal}"]`));
53
- }
54
- }
package/refid/nudge.js DELETED
@@ -1,23 +0,0 @@
1
- import { arr } from './arr.js';
2
- /**
3
- * Decrement "disabled" counter, remove when reaches 0
4
- * @param el
5
- * Optional select the attribute or attributes to remove or decrement
6
- * @param attr
7
- */
8
- export function nudge(el, attr = 'disabled') {
9
- const attrs = arr(attr);
10
- for (const attr of attrs) {
11
- const da = el.getAttribute(attr);
12
- if (da !== null) {
13
- if (da.length === 0 || da === "1") {
14
- el.removeAttribute(attr);
15
- if (attr === 'disabled')
16
- el.disabled = false;
17
- }
18
- else {
19
- el.setAttribute(attr, (parseInt(da) - 1).toString());
20
- }
21
- }
22
- }
23
- }
package/refid/nudge.ts DELETED
@@ -1,23 +0,0 @@
1
- import {arr} from './arr.js';
2
- /**
3
- * Decrement "disabled" counter, remove when reaches 0
4
- * @param el
5
- * Optional select the attribute or attributes to remove or decrement
6
- * @param attr
7
- */
8
- export function nudge(el: Element, attr: string | Array<string> = 'disabled') { //TODO: Share with be-observant
9
- const attrs = arr(attr);
10
- for(const attr of attrs){
11
- const da = el.getAttribute(attr);
12
- if (da !== null) {
13
- if (da.length === 0 || da === "1") {
14
- el.removeAttribute(attr);
15
- if(attr === 'disabled') (<any>el).disabled = false;
16
- }
17
- else {
18
- el.setAttribute(attr, (parseInt(da) - 1).toString());
19
- }
20
- }
21
- }
22
-
23
- }
package/refid/regIsh.js DELETED
@@ -1,27 +0,0 @@
1
- export const guid = 'La8Cx9vHsUOd03WomqdnPw';
2
- export const sym = Symbol.for(guid);
3
- import { arr } from './secretKeys.js';
4
- export function regIsh(scope, name, ctr) {
5
- let map = scope[sym];
6
- if (map === undefined) {
7
- map = new Map();
8
- scope[sym] = map;
9
- }
10
- if (map.has(name)) {
11
- throw 403;
12
- }
13
- map.set(name, ctr);
14
- ctr.prototype[Symbol.iterator] = function () {
15
- var index = -1;
16
- var data = this[arr];
17
- return {
18
- next: function () {
19
- return {
20
- value: data === undefined ? undefined : data[++index],
21
- done: data === undefined || !(index in data)
22
- };
23
- }
24
- };
25
- };
26
- document.dispatchEvent(new Event(guid));
27
- }
package/refid/regIsh.ts DELETED
@@ -1,31 +0,0 @@
1
- import {IshCtr} from '../ts-refs/mount-observer/types';
2
- export const guid = 'La8Cx9vHsUOd03WomqdnPw'
3
- export const sym = Symbol.for(guid);
4
- import {arr} from './secretKeys.js';
5
-
6
- export function regIsh(scope: Element | ShadowRoot | Document, name: string, ctr:IshCtr){
7
- let map = (<any>scope)[sym] as Map<string, IshCtr>;
8
- if(map === undefined){
9
- map = new Map<string, IshCtr>();
10
- (<any>scope)[sym] = map;
11
- }
12
- if(map.has(name)){
13
- throw 403;
14
- }
15
- map.set(name, ctr);
16
- ctr.prototype[Symbol.iterator] = function() {
17
- var index = -1;
18
- var data = this[arr];
19
-
20
- return {
21
- next: function() {
22
- return {
23
- value: data === undefined ? undefined : data[++index],
24
- done: data === undefined || !(index in data)
25
- }
26
- }
27
- };
28
- };
29
-
30
- document.dispatchEvent(new Event(guid));
31
- }
@@ -1,5 +0,0 @@
1
- //using Symbol.for, which is easily hackaable, because if two different entry points
2
- //come from different versions of mount-observer, things could get out of sync.
3
- //Not an issue if this was built into the browser, but it is an issue for a custom a library.
4
- //Do not make this file exportable, it is only for internal use.
5
- export const arr = Symbol.for('MHtiI353KU+aKBDlz/jR+A');
@@ -1,5 +0,0 @@
1
- //using Symbol.for, which is easily hackaable, because if two different entry points
2
- //come from different versions of mount-observer, things could get out of sync.
3
- //Not an issue if this was built into the browser, but it is an issue for a custom a library.
4
- //Do not make this file exportable, it is only for internal use.
5
- export const arr = Symbol.for('MHtiI353KU+aKBDlz/jR+A');
@@ -1,6 +0,0 @@
1
- export function splitRefs(refs) {
2
- return refs
3
- .split(' ')
4
- .map(s => s.trim())
5
- .filter(s => !!s);
6
- }
@@ -1,6 +0,0 @@
1
- export function splitRefs(refs: string){
2
- return refs
3
- .split(' ')
4
- .map(s => s.trim())
5
- .filter(s => !!s);
6
- }
package/refid/stdVal.js DELETED
@@ -1,15 +0,0 @@
1
- export function stdVal(el) {
2
- const { localName } = el;
3
- switch (localName) {
4
- case 'form':
5
- throw 'NI';
6
- case 'input':
7
- throw 'NI';
8
- case 'a':
9
- return el.href;
10
- case 'data':
11
- return JSON.parse(el.value);
12
- default:
13
- return el.textContent;
14
- }
15
- }
package/refid/stdVal.ts DELETED
@@ -1,15 +0,0 @@
1
- export function stdVal(el: Element){
2
- const {localName} = el;
3
- switch(localName){
4
- case 'form':
5
- throw 'NI';
6
- case 'input':
7
- throw 'NI';
8
- case 'a':
9
- return (el as HTMLAnchorElement).href;
10
- case 'data':
11
- return JSON.parse((el as HTMLDataElement).value);
12
- default:
13
- return el.textContent;
14
- }
15
- }
package/refid/via.js DELETED
@@ -1,114 +0,0 @@
1
- import { splitRefs } from './splitRefs.js';
2
- import { MountObserver } from '../MountObserver.js';
3
- import { camelToKebab } from './camelToKebab.js';
4
- const proxies = new WeakMap();
5
- const refLookup = new WeakMap();
6
- Object.defineProperty(Element.prototype, 'via', {
7
- get() {
8
- if (!proxies.has(this)) {
9
- const handler = {
10
- get(target, prop) {
11
- let lookup;
12
- if (refLookup.has(target)) {
13
- lookup = refLookup.get(target);
14
- }
15
- else {
16
- lookup = new Map();
17
- refLookup.set(target, lookup);
18
- }
19
- if (lookup.has(prop)) {
20
- return lookup.get(prop);
21
- }
22
- else {
23
- const refManager = new RefManager(target, prop);
24
- lookup.set(prop, refManager);
25
- return refManager;
26
- }
27
- //return Reflect.get(target, prop);
28
- },
29
- };
30
- proxies.set(this, new Proxy(this, handler));
31
- }
32
- return proxies.get(this);
33
- }
34
- });
35
- class RefManager extends EventTarget {
36
- #el;
37
- #children;
38
- #attr;
39
- #lastAttrVal = '';
40
- //#parents: Array<WeakRef<Element>> | undefined;
41
- constructor(el, prop) {
42
- super();
43
- this.#attr = camelToKebab(prop);
44
- this.#el = new WeakRef(el);
45
- }
46
- get children() {
47
- const el = this.#el.deref();
48
- if (el === undefined)
49
- return [];
50
- const attr = el.getAttribute(this.#attr);
51
- if (this.#children === undefined || attr !== this.#lastAttrVal) {
52
- if (!attr)
53
- return [];
54
- this.#lastAttrVal = attr;
55
- const refIds = splitRefs(attr);
56
- const qry = refIds.map(id => `#${id}`).join(',');
57
- const rn = el.getRootNode();
58
- const refsArr = Array.from(rn.querySelectorAll(qry));
59
- const refs = new Map();
60
- for (const ref of refsArr) {
61
- refs.set(ref.id, new WeakRef(ref));
62
- }
63
- this.#children = refs;
64
- const mo = new MountObserver({
65
- on: qry,
66
- do: {
67
- mount: (el) => {
68
- const id = el.id;
69
- if (id && !this.#children?.has(id)) {
70
- this.#children?.set(id, new WeakRef(el));
71
- this.dispatchEvent(new ChangeEvent([el], []));
72
- }
73
- },
74
- dismount: (el) => {
75
- const id = el.id;
76
- if (id && this.#children?.has(id)) {
77
- this.#children?.delete(id);
78
- this.dispatchEvent(new ChangeEvent([], [el]));
79
- }
80
- }
81
- }
82
- });
83
- mo.observe(rn);
84
- this.dispatchEvent(new ChangeEvent((refsArr), []));
85
- }
86
- return Array.from(this.#children?.values().map(ref => ref.deref()).filter(el => el !== undefined)) || [];
87
- }
88
- get parents() {
89
- //for now, hold off on caching parents until a use case arises
90
- //if(this.#parents === undefined){
91
- const el = this.#el.deref();
92
- if (el === undefined)
93
- return [];
94
- if (el.id === '')
95
- return [];
96
- const rn = el.getRootNode();
97
- const qry = `[${this.#attr}~="${el.id}"]`;
98
- const parents = Array.from(rn.querySelectorAll(qry));
99
- //this.#parents = parents.map(parent => new WeakRef(parent));
100
- return parents;
101
- //}
102
- //return this.#parents.map(ref => ref.deref()).filter(el => el !== undefined) || [];
103
- }
104
- }
105
- export class ChangeEvent extends Event {
106
- addedChildren;
107
- removedChildren;
108
- static eventName = 'change';
109
- constructor(addedChildren, removedChildren) {
110
- super(ChangeEvent.eventName);
111
- this.addedChildren = addedChildren;
112
- this.removedChildren = removedChildren;
113
- }
114
- }
package/refid/via.ts DELETED
@@ -1,113 +0,0 @@
1
- import {splitRefs} from './splitRefs.js';
2
- import {MountObserver} from '../MountObserver.js';
3
- import {camelToKebab} from './camelToKebab.js';
4
- const proxies = new WeakMap<Element, ProxyConstructor>();
5
- const refLookup = new WeakMap<Element, RefLookup>();
6
- Object.defineProperty(Element.prototype, 'via', {
7
- get(){
8
- if(!proxies.has(this)){
9
- const handler = {
10
- get(target: Element, prop: string) {
11
- let lookup: RefLookup;
12
- if(refLookup.has(target)){
13
- lookup = refLookup.get(target)!;
14
- }else{
15
- lookup = new Map<attr, RefManager>();
16
- refLookup.set(target, lookup);
17
- }
18
- if(lookup.has(prop)){
19
- return lookup.get(prop);
20
- }else{
21
- const refManager = new RefManager(target, prop as string);
22
- lookup.set(prop, refManager);
23
- return refManager;
24
- }
25
- //return Reflect.get(target, prop);
26
- },
27
-
28
- };
29
- proxies.set(this, new Proxy(this, handler));
30
- }
31
- return proxies.get(this);
32
- }
33
- });
34
-
35
- type attr = string;
36
-
37
- type RefLookup = Map<attr, RefManager>;
38
-
39
- class RefManager extends EventTarget {
40
- #el: WeakRef<Element>;
41
- #children: Map<string, WeakRef<Element>> | undefined;
42
- #attr: string;
43
- #lastAttrVal: string = '';
44
- //#parents: Array<WeakRef<Element>> | undefined;
45
- constructor(el: Element, prop: string){
46
- super();
47
- this.#attr = camelToKebab(prop);
48
- this.#el = new WeakRef(el);
49
- }
50
- get children(){
51
- const el = this.#el.deref();
52
- if(el === undefined) return [];
53
- const attr = el.getAttribute(this.#attr);
54
- if(this.#children === undefined || attr !== this.#lastAttrVal){
55
- if(!attr) return [];
56
- this.#lastAttrVal = attr;
57
- const refIds = splitRefs(attr);
58
- const qry = refIds.map(id => `#${id}`).join(',');
59
- const rn = el.getRootNode() as DocumentFragment;
60
- const refsArr = Array.from(rn.querySelectorAll(qry));
61
- const refs = new Map<string, WeakRef<Element>>();
62
- for(const ref of refsArr){
63
- refs.set(ref.id, new WeakRef(ref));
64
- }
65
- this.#children = refs;
66
- const mo = new MountObserver({
67
- on: qry,
68
- do: {
69
- mount: (el) => {
70
- const id = el.id;
71
- if(id && !this.#children?.has(id)){
72
- this.#children?.set(id, new WeakRef(el));
73
- this.dispatchEvent(new ChangeEvent([el], []));
74
- }
75
- },
76
- dismount: (el) => {
77
- const id = el.id;
78
- if(id && this.#children?.has(id)){
79
- this.#children?.delete(id);
80
- this.dispatchEvent(new ChangeEvent([], [el]));
81
- }
82
- }
83
- }
84
- });
85
- mo.observe(rn);
86
- this.dispatchEvent(new ChangeEvent((refsArr), []));
87
- }
88
- return Array.from(this.#children?.values().map(ref => ref.deref()).filter(el => el !== undefined)) || [];
89
- }
90
-
91
- get parents(){
92
- //for now, hold off on caching parents until a use case arises
93
- //if(this.#parents === undefined){
94
- const el = this.#el.deref();
95
- if(el === undefined) return [];
96
- if(el.id === '') return [];
97
- const rn = el.getRootNode() as DocumentFragment;
98
- const qry = `[${this.#attr}~="${el.id}"]`;
99
- const parents = Array.from(rn.querySelectorAll(qry));
100
- //this.#parents = parents.map(parent => new WeakRef(parent));
101
- return parents;
102
- //}
103
- //return this.#parents.map(ref => ref.deref()).filter(el => el !== undefined) || [];
104
-
105
- }
106
- }
107
-
108
- export class ChangeEvent extends Event {
109
- static eventName = 'change';
110
- constructor(public addedChildren: Array<Element>, public removedChildren: Array<Element>){
111
- super(ChangeEvent.eventName);
112
- }
113
- }
package/slotkin/affine.js DELETED
@@ -1,39 +0,0 @@
1
- import { toQuery } from './toQuery.js';
2
- import { splitRefs } from '../refid/splitRefs.js';
3
- export function affine(fragment, el) {
4
- const qry = toQuery(el);
5
- const { elFragment, map } = prep(el);
6
- const matches = Array.from(fragment.querySelectorAll(qry));
7
- for (const match of matches) {
8
- clone(match, elFragment, map);
9
- }
10
- }
11
- export function prep(el) {
12
- const elFragment = new DocumentFragment();
13
- const clone = el.cloneNode(true);
14
- for (const child of clone.childNodes) {
15
- elFragment.appendChild(child);
16
- }
17
- const insertAttrs = el.getAttribute('-i');
18
- let map = null;
19
- if (insertAttrs !== null) {
20
- const attrs = splitRefs(insertAttrs);
21
- map = {};
22
- for (const attr of attrs) {
23
- map[attr] = el.getAttribute(attr);
24
- }
25
- }
26
- return {
27
- elFragment, map
28
- };
29
- }
30
- export function clone(matchingElement, elFragment, map) {
31
- const fragmentClone = elFragment.cloneNode(true);
32
- matchingElement.replaceChildren(fragmentClone);
33
- if (map !== null) {
34
- for (const key in map) {
35
- const value = map[key];
36
- matchingElement.setAttribute(key, value);
37
- }
38
- }
39
- }
package/slotkin/affine.ts DELETED
@@ -1,46 +0,0 @@
1
- import {toQuery} from './toQuery.js';
2
- import {splitRefs} from '../refid/splitRefs.js';
3
-
4
- export function affine(fragment: DocumentFragment | Element,
5
- el: Element){
6
- const qry = toQuery(el);
7
- const {elFragment, map} = prep(el);
8
- const matches = Array.from(fragment.querySelectorAll(qry));
9
- for(const match of matches){
10
- clone(match, elFragment, map);
11
- }
12
- }
13
-
14
- export function prep(el: Element){
15
- const elFragment = new DocumentFragment();
16
- const clone = el.cloneNode(true);
17
- for(const child of clone.childNodes){
18
- elFragment.appendChild(child);
19
- }
20
- const insertAttrs = el.getAttribute('-i');
21
- let map: {[key: string]: string} | null = null;
22
- if(insertAttrs !== null){
23
- const attrs = splitRefs(insertAttrs);
24
- map = {};
25
- for(const attr of attrs){
26
- map[attr] = el.getAttribute(attr)!;
27
- }
28
- }
29
- return {
30
- elFragment, map
31
- }
32
- }
33
-
34
- export function clone(
35
- matchingElement: Element,
36
- elFragment: DocumentFragment,
37
- map: {[key: string]: string} | null){
38
- const fragmentClone = elFragment.cloneNode(true) as DocumentFragment;
39
- matchingElement.replaceChildren(fragmentClone);
40
- if(map !== null){
41
- for(const key in map){
42
- const value = map[key]!;
43
- matchingElement.setAttribute(key, value);
44
- }
45
- }
46
- }