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
package/refid/genIds.ts DELETED
@@ -1,177 +0,0 @@
1
- import {nudge} from './nudge.js';
2
- import {getCount} from './getCount.js';
3
-
4
- const attrMap = {
5
- '@': 'name',
6
- '|': 'itemprop',
7
- };
8
-
9
- const scopeMatches = '[itemscope],fieldset';
10
-
11
- export function inScope(scopeFragment: DocumentFragment | Element, el: Element){
12
- const closest = el.closest(scopeMatches);//TODO account for itemref?
13
- if(closest === null) return true;
14
- if(scopeFragment === closest) return true;
15
- if(scopeFragment.contains(closest)) return false;
16
- return true;
17
- }
18
-
19
- export function genIds(enhancedElement: Element){
20
- // const {parentElement} = enhancedElement;
21
- // if(parentElement === null) throw 404;
22
- const scopeFragment = (enhancedElement.closest(scopeMatches) || enhancedElement.getRootNode()) as DocumentFragment | Element;
23
-
24
- //first find all elements with attribute #
25
- const hashTest = '[\\#]';
26
- const hashIds = Array.from(scopeFragment.querySelectorAll(hashTest)).filter(x => inScope(scopeFragment, x));
27
- if(scopeFragment instanceof Element && scopeFragment.matches(hashTest)) hashIds.push(scopeFragment);
28
- const uniqueCheck = new Set();
29
- for(const hi of hashIds){
30
- if(!(hi instanceof HTMLElement)) continue;
31
- const idName = hi.getAttribute('itemscope') || hi.localName;
32
- if(uniqueCheck.has(idName)) throw 500;
33
- uniqueCheck.add(idName);
34
- let sideEffects = '';
35
- const hashValue = hi.getAttribute('#');
36
- if(hashValue){
37
- sideEffects = `${hashValue} `;
38
- }
39
- hi.dataset.id = `{{${sideEffects}${idName}}}`;
40
- hi.removeAttribute('#');
41
- }
42
-
43
- //now find all elements with attribute @
44
- const nameTest = '[name]:not([name=""])[\\@]';
45
- const names = Array.from(scopeFragment.querySelectorAll(nameTest)).filter(x => inScope(scopeFragment, x));
46
- if(scopeFragment instanceof Element && scopeFragment.matches(nameTest)) names.push(scopeFragment);
47
- for(const nameEl of names){
48
- if(!(nameEl instanceof HTMLElement)) continue;
49
- const val = nameEl.getAttribute('name');
50
- if(uniqueCheck.has(val)) throw 500;
51
- uniqueCheck.add(val);
52
- let sideEffects = '';
53
- const nameValue = nameEl.getAttribute('@');
54
- if(nameValue){
55
- sideEffects = `${nameValue} `;
56
- }
57
- nameEl.dataset.id = `{{${sideEffects}${val}}}`;
58
- nameEl.removeAttribute('@');
59
- }
60
-
61
- //now find all elements with attribute |
62
- const itemScopeTest = '[itemprop]:not([itemprop=""])[\\|]';
63
- const itemprops = Array.from(scopeFragment.querySelectorAll(itemScopeTest)).filter(x => inScope(scopeFragment, x));
64
- if(scopeFragment instanceof Element && scopeFragment.matches(itemScopeTest)) itemprops.push(scopeFragment);
65
- for(const itempropEl of itemprops){
66
- if(!(itempropEl instanceof HTMLElement)) continue;
67
- const val = itempropEl.getAttribute('itemprop');
68
- if(uniqueCheck.has(val)) throw 500;
69
- uniqueCheck.add(val);
70
- let sideEffects = '';
71
- const nameValue = itempropEl.getAttribute('|');
72
- if(nameValue){
73
- sideEffects = `${nameValue} `;
74
- }
75
- itempropEl.dataset.id = `{{${sideEffects}${val}}}`;
76
- itempropEl.removeAttribute('|');
77
- }
78
- const dataIdTest = '[data-id^="{{"][data-id$="}}"]';
79
- const dataIds = Array.from(scopeFragment.querySelectorAll(dataIdTest)).filter(x => inScope(scopeFragment, x));
80
- if(scopeFragment instanceof Element && scopeFragment.matches(dataIdTest)) dataIds.push(scopeFragment);
81
- const ids: Array<string> = [];
82
- for(const di of dataIds){
83
- if(!(di instanceof HTMLElement)) continue;
84
- const unparsedID = di.dataset.id;
85
- const inner = unparsedID?.substring(2, unparsedID.length - 2);
86
- if(!inner) continue;
87
- const split = inner.split(' ');
88
- const id = split.length === 2 ? split[1] : split[0];
89
- if(ids.includes(id)) throw 500;
90
- ids.push(id);
91
- }
92
- if(ids.length === 0) return;
93
-
94
- const allChildren = Array.from(scopeFragment.querySelectorAll('*')).filter(x => inScope(scopeFragment, x));
95
- if(scopeFragment instanceof Element) allChildren.push(scopeFragment);
96
-
97
- const idLookup: {[key: string]: string} = {};
98
- const base = 'gid';
99
- for(const child of allChildren){
100
- const attrs = child.attributes;
101
- for(const attr of attrs){
102
- const {name, value} = attr;
103
- if(!name.startsWith('data-')) continue;
104
- if(name === 'data-id'){
105
- if(!value.startsWith('{{') || !value.endsWith('}}')) continue;
106
- const inner = value.substring(2, value.length - 2);
107
- const split = inner.split(' ');
108
- const id = split.length === 2 ? split[1] : split[0];
109
- if(!(id in idLookup)){
110
- idLookup[id] = `${base}-${getCount(base)}`;
111
- }
112
- if(split.length === 2){
113
- const sideEffects = split[0];
114
- for(const char of sideEffects){
115
- switch(char){
116
- case '@':
117
- case '|':
118
- child.setAttribute(attrMap[char], id);
119
- break;
120
- case '%':
121
- child.part.add(id);
122
- break;
123
- case '.':
124
- child.classList.add(id);
125
- break;
126
-
127
- }
128
- }
129
- }
130
- child.id = idLookup[id];
131
- child.setAttribute('data-id', id);
132
- }else{
133
- let newValue = value;
134
- for(const id of ids){
135
- const token = `{{${id}}}`;
136
- if(!newValue.includes(token)) continue;
137
- if(!(id in idLookup)){
138
- idLookup[id] = `${base}-${getCount(base)}`;
139
- }
140
- newValue = newValue.replaceAll(token, idLookup[id]);
141
-
142
- }
143
- if(newValue === value) continue;
144
- child.setAttribute(name.substring(5), newValue);
145
- child.removeAttribute(name);
146
- }
147
-
148
- }
149
- for(const attr of attrs){
150
- const {name, value} = attr;
151
- if(!name.startsWith('defer-')) continue;
152
- const nameWithoutDefer = name.substring(6);
153
- const attrWithoutDefer = child.getAttributeNode(nameWithoutDefer);
154
- if(attrWithoutDefer === null) continue;
155
- const valueWithoutDefer = attrWithoutDefer.value;
156
-
157
- let newValue = valueWithoutDefer;
158
- let changeMade = false;
159
- for(const id of ids){
160
- const token = `{{${id}}}`;
161
- if(!newValue.includes(token)) continue;
162
- if(!(id in idLookup)){
163
- idLookup[id] = `${base}-${getCount(base)}`;
164
- }
165
- newValue = newValue.replaceAll(token, idLookup[id]);
166
- changeMade = true;
167
-
168
- }
169
- //child.setAttribute(nameWithoutDefer, newValue);
170
- if(changeMade) attrWithoutDefer.value = newValue;
171
- nudge(child, name);
172
- }
173
- }
174
- if(scopeFragment instanceof Element && 'disabled' in scopeFragment){
175
- nudge(scopeFragment);
176
- }
177
- }
@@ -1,38 +0,0 @@
1
- import { splitRefs } from './splitRefs.js';
2
- export function getAdjRefs(node) {
3
- const returnArr = [node];
4
- if (node.nodeType === node.COMMENT_NODE) {
5
- const openText = node.data.split(' ')[0];
6
- const closedText = `/${openText}`;
7
- let ns = node.nextSibling;
8
- while (ns) {
9
- returnArr.push(ns);
10
- if (node.nodeType === node.COMMENT_NODE && node.data === closedText) {
11
- return returnArr;
12
- }
13
- ns = ns.nextSibling;
14
- }
15
- }
16
- else {
17
- const el = node;
18
- const itemref = el.getAttribute('itemref');
19
- if (itemref === null)
20
- return returnArr;
21
- const itemrefList = splitRefs(itemref); // itemref.split(' ').map((id) => id.trim()).filter((id) => id.length > 0);
22
- if (itemrefList.length === 0)
23
- return returnArr;
24
- let ns = el.nextSibling;
25
- while (ns !== null) {
26
- if (ns instanceof Element) {
27
- if (ns.id && itemrefList.includes(ns.id)) {
28
- returnArr.push(ns);
29
- }
30
- }
31
- else {
32
- return returnArr;
33
- }
34
- ns = ns.nextSibling;
35
- }
36
- }
37
- return returnArr;
38
- }
@@ -1,38 +0,0 @@
1
- import { splitRefs } from './splitRefs.js';
2
- export function getAdjRefs(node: Node){
3
- const returnArr: Array<Node> = [node];
4
- if(node.nodeType === node.COMMENT_NODE){
5
- const openText = (node as Comment).data.split(' ')[0];
6
- const closedText = `/${openText}`;
7
- let ns = node.nextSibling;
8
- while(ns){
9
- returnArr.push(ns);
10
- if(node.nodeType === node.COMMENT_NODE && (node as Comment).data === closedText){
11
- return returnArr;
12
- }
13
- ns = ns.nextSibling;
14
- }
15
- }else{
16
- const el = node as Element;
17
- const itemref = el.getAttribute('itemref');
18
- if(itemref === null) return returnArr;
19
- const itemrefList = splitRefs(itemref);// itemref.split(' ').map((id) => id.trim()).filter((id) => id.length > 0);
20
- if(itemrefList.length === 0) return returnArr;
21
- let ns = el.nextSibling;
22
- while(ns !== null){
23
- if(ns instanceof Element){
24
- if(ns.id && itemrefList.includes(ns.id)){
25
- returnArr.push(ns);
26
- }
27
- }else{
28
- return returnArr;
29
- }
30
- ns = ns.nextSibling;
31
- }
32
-
33
- }
34
-
35
- return returnArr;
36
- }
37
-
38
-
@@ -1,13 +0,0 @@
1
- import './hostish.js';
2
- export function getContext(el, ctr) {
3
- let hostish = el.hostish(false);
4
- while (hostish && !(hostish instanceof ctr)) {
5
- if ('hostish' in hostish) {
6
- hostish = hostish.hostish();
7
- }
8
- else {
9
- return null;
10
- }
11
- }
12
- return hostish;
13
- }
@@ -1,14 +0,0 @@
1
- import './hostish.js';
2
-
3
- export function getContext<T extends Object>(el: Element, ctr: {new(): T}){
4
- let hostish = (<any>el).hostish(false);
5
- while(hostish && !(hostish instanceof ctr)){
6
- if('hostish' in hostish){
7
- hostish = hostish.hostish();
8
- }else{
9
- return null;
10
- }
11
-
12
- }
13
- return hostish;
14
- }
package/refid/getCount.js DELETED
@@ -1,8 +0,0 @@
1
- const ttGuid = '0j9qIjjR+UWYLrZ3FskVig';
2
- export function getCount(baseID) {
3
- const key = Symbol.for(ttGuid + baseID);
4
- let returnCnt = window[key] || 0;
5
- const nextCnt = returnCnt + 1;
6
- window[key] = nextCnt;
7
- return returnCnt;
8
- }
package/refid/getCount.ts DELETED
@@ -1,8 +0,0 @@
1
- const ttGuid = '0j9qIjjR+UWYLrZ3FskVig'
2
- export function getCount(baseID: string){
3
- const key = Symbol.for(ttGuid + baseID);
4
- let returnCnt = (<any>window)[key] || 0;
5
- const nextCnt = returnCnt + 1;
6
- (<any>window)[key] = nextCnt;
7
- return returnCnt;
8
- }
package/refid/getIsh.js DELETED
@@ -1,35 +0,0 @@
1
- import { sym, guid } from './regIsh.js';
2
- export async function getIsh(scope, name) {
3
- let test = scope;
4
- while (true) {
5
- const map = test[sym];
6
- if (map !== undefined) {
7
- if (map.has(name)) {
8
- return map.get(name);
9
- }
10
- }
11
- if (test === document) {
12
- return await watch(scope, name);
13
- }
14
- if (test instanceof ShadowRoot) {
15
- test = test.host;
16
- continue;
17
- }
18
- let newTest = test.parentElement;
19
- if (newTest) {
20
- test = newTest;
21
- continue;
22
- }
23
- const lastTest = test;
24
- test = test.getRootNode();
25
- if (test === lastTest) {
26
- return await watch(scope, name);
27
- }
28
- ;
29
- }
30
- }
31
- async function watch(scope, name) {
32
- const { waitForEvent } = await import('../waitForEvent.js');
33
- await waitForEvent(document, guid);
34
- return await getIsh(scope, name);
35
- }
package/refid/getIsh.ts DELETED
@@ -1,37 +0,0 @@
1
- import {sym, guid} from './regIsh.js';
2
- import {IshCtr} from '../ts-refs/mount-observer/types.js';
3
- export async function getIsh(scope: Element | ShadowRoot | Document | Node, name: string): Promise<IshCtr>{
4
- let test = scope as any;
5
-
6
- while(true){
7
- const map = test[sym] as Map<string, IshCtr>;
8
- if(map !== undefined){
9
- if(map.has(name)){
10
- return map.get(name)!;
11
- }
12
- }
13
- if(test === document){
14
- return await watch(scope, name);
15
- }
16
- if(test instanceof ShadowRoot){
17
- test = test.host;
18
- continue;
19
- }
20
- let newTest = test.parentElement;
21
- if(newTest){
22
- test = newTest;
23
- continue;
24
- }
25
- const lastTest = test;
26
- test = test.getRootNode();
27
- if(test === lastTest) {
28
- return await watch(scope, name);
29
- };
30
- }
31
- }
32
-
33
- async function watch(scope: Element | ShadowRoot | Document | Node, name: string){
34
- const {waitForEvent} = await import('../waitForEvent.js');
35
- await waitForEvent(document, guid);
36
- return await getIsh(scope, name);
37
- }
package/refid/hostish.js DELETED
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Element.prototype.hostish = async function (checkSelf = true) {
3
- const from = checkSelf ? this : this.hasAttribute('itemscope') ? this.parentElement : this;
4
- const closest = from?.closest('[itemscope]');
5
- if (closest === null || closest === undefined)
6
- return this.getRootNode().host;
7
- const { localName } = closest;
8
- const itemScopeAttr = closest.getAttribute('itemscope');
9
- if (itemScopeAttr) {
10
- const { waitForIsh } = await import('mount-observer/waitForIsh.js');
11
- return await waitForIsh(closest);
12
- }
13
- if (localName.includes('-')) {
14
- await customElements.whenDefined(localName);
15
- return closest;
16
- }
17
- return this.getRootNode().host;
18
- };
package/refid/hostish.ts DELETED
@@ -1,20 +0,0 @@
1
- interface Element{
2
- hostish(): Promise<any>
3
- }
4
- Element.prototype.hostish = async function(checkSelf = true){
5
- const from = checkSelf ? this : this.hasAttribute('itemscope') ? this.parentElement : this;
6
- const closest = from?.closest('[itemscope]') as HTMLElement;
7
- if(closest === null || closest === undefined) return (<any>this.getRootNode()).host;
8
- const {localName} = closest;
9
- const itemScopeAttr = closest.getAttribute('itemscope');
10
- if(itemScopeAttr){
11
- const {waitForIsh} = await import('mount-observer/waitForIsh.js');
12
- return await waitForIsh(closest);
13
- }
14
- if(localName.includes('-')){
15
- await customElements.whenDefined(localName);
16
- return closest;
17
- }
18
-
19
- return (<any>this.getRootNode()).host;
20
- }
package/refid/ism.js DELETED
@@ -1,78 +0,0 @@
1
- import { upShadowSearch } from '../upShadowSearch.js';
2
- import { stdVal } from './stdVal.js';
3
- Object.defineProperty(HTMLElement.prototype, 'ism', {
4
- get() {
5
- const el = this;
6
- if (!el.hasAttribute('itemscope'))
7
- return;
8
- return parse(el);
9
- }
10
- });
11
- const parsedItempropMaps = new WeakMap();
12
- export function parse(el, scope = {}, scopedLists = {}) {
13
- const itemprop = el.getAttribute('itemprop');
14
- if (itemprop) {
15
- scope[itemprop] = stdVal(el); //TODO full logic
16
- }
17
- const itempropmap = el.getAttribute('itempropmap');
18
- if (itempropmap) {
19
- //const el = document.getElementById(itempropmap);
20
- const jsonEl = upShadowSearch(el, itempropmap);
21
- if (!jsonEl)
22
- throw 500;
23
- if (!parsedItempropMaps.has(jsonEl)) {
24
- parsedItempropMaps.set(jsonEl, JSON.parse(jsonEl.innerHTML));
25
- }
26
- const parsed = /** @type {ItemPropMap} */ (parsedItempropMaps.get(jsonEl));
27
- for (const key in parsed) {
28
- const attr = el.getAttribute(key);
29
- if (attr === null)
30
- continue;
31
- const rhs = parsed[key];
32
- switch (typeof rhs) {
33
- case 'string':
34
- scope[rhs] = attr;
35
- break;
36
- case 'object':
37
- const { instanceOf, mapsTo } = rhs;
38
- switch (instanceOf) {
39
- case 'Number':
40
- case Number:
41
- scope[mapsTo] = Number(attr);
42
- break;
43
- case 'Object':
44
- case Object:
45
- case 'Boolean':
46
- case Boolean:
47
- scope[mapsTo] = JSON.parse(attr);
48
- break;
49
- }
50
- }
51
- }
52
- }
53
- const children = Array.from(el.children);
54
- let itemscopeMapToPass = scopedLists;
55
- for (const child of children) {
56
- if (!(child instanceof HTMLElement))
57
- continue;
58
- const childHasItemScopeAttr = child.hasAttribute('itemscope');
59
- const objToPass = childHasItemScopeAttr ? {} : scope;
60
- if (childHasItemScopeAttr) {
61
- itemscopeMapToPass = {};
62
- }
63
- parse(child, objToPass, itemscopeMapToPass);
64
- const isItemScopeAndChildHasBothItempropAndItemscope = scopedLists && child.hasAttribute('itemprop') && child.hasAttribute('itemscope');
65
- if (isItemScopeAndChildHasBothItempropAndItemscope) {
66
- const itemprops = child.getAttribute('itemprop').split(" ").filter(x => x);
67
- for (const itemprop of itemprops) {
68
- if (!scopedLists[itemprop])
69
- scopedLists[itemprop] = [];
70
- scopedLists[itemprop].push(objToPass);
71
- }
72
- }
73
- }
74
- return {
75
- scope,
76
- scopedLists
77
- };
78
- }
package/refid/ism.ts DELETED
@@ -1,81 +0,0 @@
1
- import {upShadowSearch} from '../upShadowSearch.js';
2
- import {stdVal} from './stdVal.js';
3
-
4
- Object.defineProperty(HTMLElement.prototype, 'ism', {
5
- get(){
6
- const el = this as HTMLElement;
7
- if(!el.hasAttribute('itemscope')) return;
8
- return parse(el);
9
- }
10
- });
11
-
12
- type ScopedLists = {[key: string] : any[]}
13
-
14
- const parsedItempropMaps = new WeakMap<HTMLScriptElement, any>();
15
-
16
- export function parse(el: HTMLElement, scope: any = {}, scopedLists: ScopedLists = {}){
17
- const itemprop = el.getAttribute('itemprop');
18
- if(itemprop){
19
- scope[itemprop] = stdVal(el); //TODO full logic
20
- }
21
- const itempropmap = el.getAttribute('itempropmap');
22
- if(itempropmap){
23
- //const el = document.getElementById(itempropmap);
24
- const jsonEl = upShadowSearch(el, itempropmap)
25
- if(!jsonEl) throw 500;
26
- if(!parsedItempropMaps.has(jsonEl)){
27
- parsedItempropMaps.set(jsonEl, JSON.parse(jsonEl.innerHTML));
28
- }
29
- const parsed =/** @type {ItemPropMap} */ (parsedItempropMaps.get(jsonEl));
30
- for(const key in parsed){
31
- const attr = el.getAttribute(key);
32
- if(attr === null) continue;
33
- const rhs = parsed[key];
34
- switch(typeof rhs){
35
- case 'string':
36
- scope[rhs] = attr;
37
- break;
38
- case 'object':
39
- const {instanceOf, mapsTo} = rhs;
40
- switch(instanceOf){
41
- case 'Number':
42
- case Number:
43
- scope[mapsTo] = Number(attr);
44
- break;
45
- case 'Object':
46
- case Object:
47
- case 'Boolean':
48
- case Boolean:
49
- scope[mapsTo] = JSON.parse(attr);
50
- break;
51
-
52
-
53
- }
54
- }
55
- }
56
-
57
- }
58
- const children = Array.from(el.children);
59
- let itemscopeMapToPass = scopedLists;
60
- for(const child of children){
61
- if(!(child instanceof HTMLElement)) continue;
62
- const childHasItemScopeAttr = child.hasAttribute('itemscope')
63
- const objToPass = childHasItemScopeAttr ? {} : scope;
64
- if(childHasItemScopeAttr) {
65
- itemscopeMapToPass = {};
66
- }
67
- parse(child, objToPass, itemscopeMapToPass);
68
- const isItemScopeAndChildHasBothItempropAndItemscope = scopedLists && child.hasAttribute('itemprop') && child.hasAttribute('itemscope');
69
- if(isItemScopeAndChildHasBothItempropAndItemscope){
70
- const itemprops = child.getAttribute('itemprop')!.split(" ").filter(x => x);
71
- for(const itemprop of itemprops){
72
- if(!scopedLists![itemprop]) scopedLists![itemprop] = [];
73
- scopedLists![itemprop].push(objToPass);
74
- }
75
- }
76
- }
77
- return {
78
- scope,
79
- scopedLists
80
- };
81
- }
@@ -1,60 +0,0 @@
1
- "use strict";
2
- function getFirst(element, prop) {
3
- for (const child of element.children) {
4
- const itemprop = child.getAttribute('itemprop');
5
- if (itemprop === prop) {
6
- return child;
7
- }
8
- if (!child.hasAttribute('itemscope')) {
9
- const found = getFirst(child, prop);
10
- if (found)
11
- return found;
12
- }
13
- }
14
- return null;
15
- }
16
- const proxies = new WeakMap();
17
- const refLookup = new WeakMap();
18
- Object.defineProperty(Element.prototype, 'itemprops', {
19
- get() {
20
- if (!proxies.has(this)) {
21
- const handler = {
22
- get(target, prop) {
23
- let lookup;
24
- if (refLookup.has(target)) {
25
- lookup = refLookup.get(target);
26
- }
27
- else {
28
- lookup = new Map();
29
- refLookup.set(target, lookup);
30
- }
31
- if (lookup.has(prop)) {
32
- return lookup.get(prop);
33
- }
34
- else {
35
- const propManager = new ItempropManager(target, prop);
36
- lookup.set(prop, propManager);
37
- return propManager;
38
- }
39
- },
40
- };
41
- proxies.set(this, new Proxy(this, handler));
42
- }
43
- return proxies.get(this);
44
- }
45
- });
46
- class ItempropManager extends EventTarget {
47
- #el;
48
- #prop;
49
- constructor(el, prop) {
50
- super();
51
- this.#el = new WeakRef(el);
52
- this.#prop = prop;
53
- }
54
- get first() {
55
- const el = this.#el.deref();
56
- if (el === undefined)
57
- return null;
58
- return getFirst(el, this.#prop);
59
- }
60
- }