mount-observer 0.0.111 → 0.1.0

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 (179) hide show
  1. package/Events.js +28 -26
  2. package/Events.ts +34 -30
  3. package/MountObserver.js +235 -520
  4. package/MountObserver.ts +281 -542
  5. package/README.md +149 -56
  6. package/attrCoordinates.js +93 -0
  7. package/attrCoordinates.ts +122 -0
  8. package/constants.js +6 -0
  9. package/constants.ts +7 -0
  10. package/index.js +3 -0
  11. package/index.ts +19 -0
  12. package/loadImports.js +47 -0
  13. package/loadImports.ts +56 -0
  14. package/package.json +8 -115
  15. package/playwright.config.ts +0 -1
  16. package/types.d.ts +86 -0
  17. package/whereAttr.js +174 -0
  18. package/whereAttr.ts +221 -0
  19. package/LICENSE +0 -21
  20. package/Newish.js +0 -145
  21. package/Newish.ts +0 -169
  22. package/ObsAttr.js +0 -18
  23. package/ObsAttr.ts +0 -18
  24. package/RootMutObs.js +0 -49
  25. package/RootMutObs.ts +0 -58
  26. package/Synthesizer.js +0 -125
  27. package/Synthesizer.ts +0 -130
  28. package/bindish.js +0 -15
  29. package/bindish.ts +0 -22
  30. package/compose.js +0 -148
  31. package/compose.ts +0 -164
  32. package/doCleanup.js +0 -31
  33. package/doCleanup.ts +0 -34
  34. package/getWhereAttrSelector.js +0 -83
  35. package/getWhereAttrSelector.ts +0 -92
  36. package/preloadContent.js +0 -44
  37. package/preloadContent.ts +0 -47
  38. package/readAttrs.ts +0 -60
  39. package/refid/README.md +0 -259
  40. package/refid/arr.js +0 -4
  41. package/refid/arr.ts +0 -4
  42. package/refid/camelToKebab.js +0 -4
  43. package/refid/camelToKebab.ts +0 -4
  44. package/refid/genIds.js +0 -190
  45. package/refid/genIds.ts +0 -177
  46. package/refid/getAdjRefs.js +0 -38
  47. package/refid/getAdjRefs.ts +0 -38
  48. package/refid/getContext.js +0 -13
  49. package/refid/getContext.ts +0 -14
  50. package/refid/getCount.js +0 -8
  51. package/refid/getCount.ts +0 -8
  52. package/refid/getIsh.js +0 -35
  53. package/refid/getIsh.ts +0 -37
  54. package/refid/hostish.js +0 -18
  55. package/refid/hostish.ts +0 -20
  56. package/refid/ism.js +0 -78
  57. package/refid/ism.ts +0 -81
  58. package/refid/itemprops.js +0 -60
  59. package/refid/itemprops.ts +0 -67
  60. package/refid/joinMatching.js +0 -56
  61. package/refid/joinMatching.ts +0 -54
  62. package/refid/nudge.js +0 -23
  63. package/refid/nudge.ts +0 -23
  64. package/refid/regIsh.js +0 -27
  65. package/refid/regIsh.ts +0 -31
  66. package/refid/secretKeys.js +0 -5
  67. package/refid/secretKeys.ts +0 -5
  68. package/refid/splitRefs.js +0 -6
  69. package/refid/splitRefs.ts +0 -6
  70. package/refid/stdVal.js +0 -15
  71. package/refid/stdVal.ts +0 -15
  72. package/refid/via.js +0 -114
  73. package/refid/via.ts +0 -113
  74. package/slotkin/affine.js +0 -39
  75. package/slotkin/affine.ts +0 -46
  76. package/slotkin/beKindred.js +0 -45
  77. package/slotkin/beKindred.ts +0 -55
  78. package/slotkin/getBreadth.js +0 -19
  79. package/slotkin/getBreadth.ts +0 -21
  80. package/slotkin/getFrag.js +0 -22
  81. package/slotkin/getFrag.ts +0 -21
  82. package/slotkin/toQuery.js +0 -12
  83. package/slotkin/toQuery.ts +0 -13
  84. package/slotkin/wrap.js +0 -13
  85. package/slotkin/wrap.ts +0 -18
  86. package/ts-refs/LICENSE +0 -21
  87. package/ts-refs/README.md +0 -18
  88. package/ts-refs/be-a-beacon/types.d.ts +0 -22
  89. package/ts-refs/be-alit/types.d.ts +0 -1
  90. package/ts-refs/be-based/types.d.ts +0 -32
  91. package/ts-refs/be-bound/types.d.ts +0 -65
  92. package/ts-refs/be-buttoned-up/types.d.ts +0 -21
  93. package/ts-refs/be-calculating/types.d.ts +0 -57
  94. package/ts-refs/be-clonable/types.d.ts +0 -28
  95. package/ts-refs/be-committed/types.d.ts +0 -26
  96. package/ts-refs/be-consoling/types.d.ts +0 -25
  97. package/ts-refs/be-counted/types.d.ts +0 -88
  98. package/ts-refs/be-delible/types.d.ts +0 -26
  99. package/ts-refs/be-directive/types.d.ts +0 -43
  100. package/ts-refs/be-dispatching/types.d.ts +0 -41
  101. package/ts-refs/be-elevating/types.d.ts +0 -55
  102. package/ts-refs/be-enhanced/types.d.ts +0 -32
  103. package/ts-refs/be-enhancing/types.d.ts +0 -31
  104. package/ts-refs/be-evanescent/types.d.ts +0 -20
  105. package/ts-refs/be-eventing/types.d.ts +0 -27
  106. package/ts-refs/be-exportable/types.d.ts +0 -26
  107. package/ts-refs/be-fetching/types.d.ts +0 -73
  108. package/ts-refs/be-flashy/types.d.ts +0 -27
  109. package/ts-refs/be-formalizing/types.d.ts +0 -29
  110. package/ts-refs/be-formidable/types.d.ts +0 -64
  111. package/ts-refs/be-giddy/types.d.ts +0 -26
  112. package/ts-refs/be-gingerly/types.d.ts +0 -19
  113. package/ts-refs/be-gone/types.d.ts +0 -24
  114. package/ts-refs/be-hashing-out/types.d.ts +0 -22
  115. package/ts-refs/be-hive/types.d.ts +0 -18
  116. package/ts-refs/be-imbued/types.d.ts +0 -30
  117. package/ts-refs/be-included/types.d.ts +0 -20
  118. package/ts-refs/be-inclusive/types.d.ts +0 -30
  119. package/ts-refs/be-intersectional/types.d.ts +0 -37
  120. package/ts-refs/be-intl/types.d.ts +0 -28
  121. package/ts-refs/be-invoking/types.d.ts +0 -28
  122. package/ts-refs/be-joining/types.d.ts +0 -26
  123. package/ts-refs/be-kvetching/types.d.ts +0 -24
  124. package/ts-refs/be-lazy/types.d.ts +0 -29
  125. package/ts-refs/be-literate/types.d.ts +0 -29
  126. package/ts-refs/be-mediating/types.d.ts +0 -34
  127. package/ts-refs/be-methodical/types.d.ts +0 -20
  128. package/ts-refs/be-modding/types.d.ts +0 -18
  129. package/ts-refs/be-observant/types.d.ts +0 -27
  130. package/ts-refs/be-observing/types.d.ts +0 -84
  131. package/ts-refs/be-parsed/types.d.ts +0 -19
  132. package/ts-refs/be-parsing/types.d.ts +0 -37
  133. package/ts-refs/be-persistent/types.d.ts +0 -66
  134. package/ts-refs/be-propagating/types.d.ts +0 -26
  135. package/ts-refs/be-reformable/types.d.ts +0 -48
  136. package/ts-refs/be-render-neutral/types.d.ts +0 -31
  137. package/ts-refs/be-scoped/types.d.ts +0 -24
  138. package/ts-refs/be-sharing/types.d.ts +0 -17
  139. package/ts-refs/be-switched/types.d.ts +0 -155
  140. package/ts-refs/be-typed/types.d.ts +0 -36
  141. package/ts-refs/be-value-added/types.d.ts +0 -34
  142. package/ts-refs/be-valued/types.d.ts +0 -22
  143. package/ts-refs/be-written/types.d.ts +0 -59
  144. package/ts-refs/css-charts/types.d.ts +0 -38
  145. package/ts-refs/css-echarts/types.d.ts +0 -13
  146. package/ts-refs/data-props/types.d.ts +0 -27
  147. package/ts-refs/do-inc/types.d.ts +0 -28
  148. package/ts-refs/do-invoke/types.d.ts +0 -28
  149. package/ts-refs/do-toggle/types.d.ts +0 -27
  150. package/ts-refs/em-bower/types.d.ts +0 -18
  151. package/ts-refs/fetch-for/types.d.ts +0 -37
  152. package/ts-refs/folder-picker/types.d.ts +0 -43
  153. package/ts-refs/for-fetch/doc.d.ts +0 -98
  154. package/ts-refs/for-fetch/types.d.ts +0 -83
  155. package/ts-refs/mount-observer/types.d.ts +0 -248
  156. package/ts-refs/mt-si/types.d.ts +0 -21
  157. package/ts-refs/per-each/types.d.ts +0 -51
  158. package/ts-refs/soak-up/types.d.ts +0 -36
  159. package/ts-refs/trans-render/XV/types.d.ts +0 -69
  160. package/ts-refs/trans-render/asmr/types.d.ts +0 -138
  161. package/ts-refs/trans-render/be/types.d.ts +0 -190
  162. package/ts-refs/trans-render/dss/types.d.ts +0 -57
  163. package/ts-refs/trans-render/froop/types.d.ts +0 -416
  164. package/ts-refs/trans-render/funions/types.d.ts +0 -12
  165. package/ts-refs/trans-render/lib/mixins/types.d.ts +0 -42
  166. package/ts-refs/trans-render/lib/prs/types.d.ts +0 -40
  167. package/ts-refs/trans-render/lib/types.d.ts +0 -489
  168. package/ts-refs/trans-render/types.d.ts +0 -583
  169. package/ts-refs/wc-info/SimpleWCInfo.d.ts +0 -15
  170. package/ts-refs/when-resolved/types.d.ts +0 -30
  171. package/ts-refs/xp-as/types.d.ts +0 -20
  172. package/ts-refs/xtal-element/types.d.ts +0 -43
  173. package/ts-refs/xtal-frappe-chart/types.d.ts +0 -193
  174. package/upShadowSearch.js +0 -25
  175. package/upShadowSearch.ts +0 -23
  176. package/waitForEvent.js +0 -12
  177. package/waitForEvent.ts +0 -13
  178. package/waitForIsh.js +0 -21
  179. package/waitForIsh.ts +0 -20
package/RootMutObs.ts DELETED
@@ -1,58 +0,0 @@
1
- import {mutationEventName, AddMutationEventListener, MountInit} from './ts-refs/mount-observer/types';
2
-
3
- export class RootMutObs extends EventTarget{
4
- #idleTimeout: number; //TODO: make this configurable
5
- #idlePointer = 0;
6
- constructor(rootNode: Node, options: MountInit ){
7
- super();
8
- this.#idleTimeout = options?.idleTimeout ?? 30;
9
- this.#mutationObserver = new MutationObserver(mutationRecords => {
10
- this.dispatchEvent(new MutationEvent(mutationRecords));
11
- this.#triggerIsIdle();
12
- });
13
- this.#mutationObserver.observe(rootNode, {
14
- subtree: true,
15
- childList: true,
16
- attributes: true,
17
- attributeOldValue: true,
18
- });
19
- this.#triggerIsIdle();
20
- }
21
- #isIdle = false;
22
- get isIdle(){
23
- return this.#isIdle;
24
- }
25
- #triggerIsIdle(){
26
- this.#isIdle = false;
27
- clearTimeout(this.#idlePointer);
28
- this.#idlePointer = setTimeout(()=>{
29
- this.#isIdle = true;
30
- this.dispatchEvent(new Event('is-idle'));
31
- }, this.#idleTimeout)
32
- }
33
- #mutationObserver: MutationObserver;
34
- disconnect(){
35
- this.#mutationObserver.disconnect();
36
- }
37
- }
38
-
39
-
40
-
41
- // https://github.com/webcomponents-cg/community-protocols/issues/12#issuecomment-872415080
42
-
43
- /**
44
- * The `mutation-event` event represents something that happened.
45
- * We can document it here.
46
- */
47
- export class MutationEvent extends Event implements MutationEvent {
48
- static eventName: mutationEventName = 'mutation-event';
49
-
50
- constructor(public mutationRecords: Array<MutationRecord>) {
51
- // Since these are hard-coded, dispatchers can't get them wrong
52
- super(MutationEvent.eventName);
53
- }
54
- }
55
-
56
-
57
-
58
-
package/Synthesizer.js DELETED
@@ -1,125 +0,0 @@
1
- import { MountObserver } from './MountObserver.js';
2
- export class Synthesizer extends HTMLElement {
3
- #mutationObserver;
4
- mountObserverElements = [];
5
- mutationCallback(mutationList) {
6
- for (const mutation of mutationList) {
7
- const { addedNodes } = mutation;
8
- for (const node of addedNodes) {
9
- if (!(node instanceof HTMLScriptElement) || node.type !== 'mountobserver')
10
- continue;
11
- const mose = node;
12
- this.mountObserverElements.push(mose);
13
- this.activate(mose);
14
- const e = new SynthesizeEvent(mose);
15
- this.dispatchEvent(e);
16
- }
17
- }
18
- }
19
- connectedCallback() {
20
- this.hidden = true;
21
- const init = {
22
- childList: true
23
- };
24
- this.querySelectorAll('script[type="mountobserver"]').forEach(s => {
25
- const mose = s;
26
- this.mountObserverElements.push(mose);
27
- this.activate(mose);
28
- });
29
- this.#mutationObserver = new MutationObserver(this.mutationCallback.bind(this));
30
- this.#mutationObserver.observe(this, init);
31
- this.inherit();
32
- }
33
- checkIfAllowed(mose) {
34
- if (this.hasAttribute('passthrough'))
35
- return false;
36
- const { id } = mose;
37
- if (this.hasAttribute('include')) {
38
- const split = this.getAttribute('include').split(' ');
39
- if (!split.includes(id))
40
- return false;
41
- }
42
- if (this.hasAttribute('exclude')) {
43
- const split = this.getAttribute('exclude').split(' ');
44
- if (split.includes(id))
45
- return false;
46
- }
47
- return true;
48
- }
49
- activate(mose) {
50
- if (!this.checkIfAllowed(mose))
51
- return;
52
- mose.dispatchEvent(new LoadEvent());
53
- const { init, do: d } = mose;
54
- const mi = {
55
- do: d,
56
- ...init
57
- };
58
- const mo = new MountObserver(mi);
59
- mose.observer = mo;
60
- mo.observe(this.getRootNode());
61
- }
62
- import(mose) {
63
- const { init, do: d, id, synConfig } = mose;
64
- const se = document.createElement('script');
65
- se.type = 'mountobserver';
66
- se.init = { ...init };
67
- se.id = id;
68
- se.do = { ...d };
69
- se.synConfig = { ...synConfig };
70
- this.appendChild(se);
71
- }
72
- inherit() {
73
- const rn = this.getRootNode();
74
- const host = rn.host;
75
- if (!host)
76
- return;
77
- const parentShadowRealm = host.getRootNode();
78
- const { localName } = this;
79
- let parentScopeSynthesizer = parentShadowRealm.querySelector(localName);
80
- if (parentScopeSynthesizer === null) {
81
- parentScopeSynthesizer = document.createElement(localName);
82
- if (parentShadowRealm === document) {
83
- document.head.appendChild(parentScopeSynthesizer);
84
- }
85
- else {
86
- parentShadowRealm.appendChild(parentScopeSynthesizer);
87
- }
88
- }
89
- ;
90
- const { mountObserverElements } = parentScopeSynthesizer;
91
- for (const moe of mountObserverElements) {
92
- this.import(moe);
93
- }
94
- parentScopeSynthesizer.addEventListener(SynthesizeEvent.eventName, e => {
95
- this.import(e.mountObserverElement);
96
- });
97
- }
98
- disconnectedCallback() {
99
- if (this.#mutationObserver !== undefined) {
100
- this.#mutationObserver.disconnect();
101
- }
102
- for (const mose of this.mountObserverElements) {
103
- mose.observer.disconnect(this.getRootNode());
104
- }
105
- }
106
- }
107
- // https://github.com/webcomponents-cg/community-protocols/issues/12#issuecomment-872415080
108
- /**
109
- * The `mutation-event` event represents something that happened.
110
- * We can document it here.
111
- */
112
- export class SynthesizeEvent extends Event {
113
- mountObserverElement;
114
- static eventName = 'synthesize';
115
- constructor(mountObserverElement) {
116
- super(SynthesizeEvent.eventName);
117
- this.mountObserverElement = mountObserverElement;
118
- }
119
- }
120
- export class LoadEvent extends Event {
121
- static eventName = 'load';
122
- constructor() {
123
- super(LoadEvent.eventName);
124
- }
125
- }
package/Synthesizer.ts DELETED
@@ -1,130 +0,0 @@
1
- import {MountInit, MOSE} from './ts-refs/mount-observer/types';
2
- import {MountObserver} from './MountObserver.js';
3
-
4
- export abstract class Synthesizer extends HTMLElement{
5
- #mutationObserver: MutationObserver | undefined;
6
-
7
- mountObserverElements: Array<MOSE> = [];
8
-
9
- mutationCallback(mutationList: Array<MutationRecord>){
10
- for (const mutation of mutationList) {
11
- const {addedNodes} = mutation;
12
- for(const node of addedNodes){
13
- if(!(node instanceof HTMLScriptElement) || node.type !== 'mountobserver') continue;
14
- const mose = node as MOSE;
15
- this.mountObserverElements.push(mose);
16
- this.activate(mose);
17
- const e = new SynthesizeEvent(mose);
18
- this.dispatchEvent(e);
19
- }
20
-
21
- }
22
- }
23
-
24
- connectedCallback(){
25
- this.hidden = true;
26
- const init: MutationObserverInit = {
27
- childList: true
28
- };
29
- this.querySelectorAll('script[type="mountobserver"]').forEach(s => {
30
- const mose = s as MOSE;
31
- this.mountObserverElements.push(mose);
32
- this.activate(mose);
33
- });
34
- this.#mutationObserver = new MutationObserver(this.mutationCallback.bind(this));
35
- this.#mutationObserver.observe(this, init);
36
- this.inherit();
37
- }
38
-
39
- checkIfAllowed(mose: MOSE){
40
- if(this.hasAttribute('passthrough')) return false;
41
- const {id} = mose;
42
- if(this.hasAttribute('include')){
43
- const split = this.getAttribute('include')!.split(' ');
44
- if(!split.includes(id)) return false;
45
- }
46
- if(this.hasAttribute('exclude')){
47
- const split = this.getAttribute('exclude')!.split(' ');
48
- if(split.includes(id)) return false;
49
- }
50
- return true;
51
- }
52
-
53
- activate(mose: MOSE){
54
- if(!this.checkIfAllowed(mose)) return;
55
- mose.dispatchEvent(new LoadEvent());
56
- const {init, do: d} = mose;
57
- const mi: MountInit = {
58
- do: d,
59
- ...init
60
- };
61
- const mo = new MountObserver(mi);
62
- mose.observer = mo;
63
- mo.observe(this.getRootNode());
64
- }
65
-
66
- import(mose: MOSE){
67
- const {init, do: d, id, synConfig} = mose;
68
- const se = document.createElement('script') as MOSE;
69
- se.type='mountobserver';
70
- se.init = {...init};
71
- se.id = id;
72
- se.do = {...d};
73
- se.synConfig = {...synConfig};
74
- this.appendChild(se);
75
- }
76
-
77
- inherit(){
78
- const rn = this.getRootNode();
79
- const host = (<any>rn).host;
80
- if(!host) return;
81
- const parentShadowRealm = host.getRootNode();
82
- const {localName} = this;
83
- let parentScopeSynthesizer = parentShadowRealm.querySelector(localName) as Synthesizer;
84
- if(parentScopeSynthesizer === null) {
85
- parentScopeSynthesizer = document.createElement(localName) as Synthesizer;
86
- if(parentShadowRealm === document) {
87
- document.head.appendChild(parentScopeSynthesizer);
88
- }else{
89
- parentShadowRealm.appendChild(parentScopeSynthesizer);
90
- }
91
- };
92
- const {mountObserverElements} = parentScopeSynthesizer;
93
- for(const moe of mountObserverElements){
94
- this.import(moe);
95
- }
96
- parentScopeSynthesizer.addEventListener(SynthesizeEvent.eventName, e => {
97
- this.import((e as SynthesizeEvent).mountObserverElement)
98
- })
99
-
100
- }
101
- disconnectedCallback(){
102
- if(this.#mutationObserver !== undefined){
103
- this.#mutationObserver.disconnect();
104
- }
105
- for(const mose of this.mountObserverElements){
106
- mose.observer.disconnect(this.getRootNode());
107
- }
108
- }
109
- }
110
-
111
- // https://github.com/webcomponents-cg/community-protocols/issues/12#issuecomment-872415080
112
- /**
113
- * The `mutation-event` event represents something that happened.
114
- * We can document it here.
115
- */
116
- export class SynthesizeEvent extends Event{
117
- static eventName = 'synthesize';
118
-
119
- constructor(public mountObserverElement: MOSE) {
120
- super(SynthesizeEvent.eventName);
121
- }
122
- }
123
-
124
- export class LoadEvent extends Event {
125
- static eventName = 'load';
126
-
127
- constructor(){
128
- super(LoadEvent.eventName);
129
- }
130
- }
package/bindish.js DELETED
@@ -1,15 +0,0 @@
1
- export const itemscopeQry = '[itemscope]:not([itemscope=""])';
2
- export async function bindish(fragment, target, options) {
3
- const scopes = Array.from(fragment.querySelectorAll(`${itemscopeQry}`));
4
- await bindishIt(scopes, target, options);
5
- }
6
- export async function bindishIt(scopes, target, options) {
7
- for (const scope of scopes) {
8
- const itemscope = scope.getAttribute('itemscope');
9
- if (itemscope && !(scope.ish instanceof HTMLElement)) {
10
- const { Newish } = await import('./Newish.js');
11
- const newIsh = new Newish(scope, target, itemscope, options);
12
- await newIsh.do();
13
- }
14
- }
15
- }
package/bindish.ts DELETED
@@ -1,22 +0,0 @@
1
- import { Assigner, BindishOptions } from './ts-refs/mount-observer/types.js';
2
-
3
- export const itemscopeQry = '[itemscope]:not([itemscope=""])';
4
- export async function bindish(
5
- fragment: DocumentFragment,
6
- target: Node,
7
- options?: BindishOptions
8
- ){
9
- const scopes = Array.from(fragment.querySelectorAll(`${itemscopeQry}`));
10
- await bindishIt(scopes, target, options);
11
- }
12
-
13
- export async function bindishIt(scopes: Array<Element>, target: Node, options?: BindishOptions){
14
- for(const scope of scopes){
15
- const itemscope = scope.getAttribute('itemscope');
16
- if(itemscope && !((<any>scope).ish instanceof HTMLElement)){
17
- const {Newish} = await import('./Newish.js');
18
- const newIsh = new Newish(scope, target, itemscope, options);
19
- await newIsh.do()
20
- }
21
- }
22
- }
package/compose.js DELETED
@@ -1,148 +0,0 @@
1
- import { wasItemReffed } from './MountObserver.js';
2
- //import {prep} from './slotkin/affine.js';
3
- //goal: deprecate this key, in favor of comments
4
- export const childRefsKey = Symbol.for('Wr0WPVh84k+O93miuENdMA');
5
- export const cloneKey = Symbol.for('LD97VKZYc02CQv23DT/6fQ');
6
- const autogenKey = Symbol.for('YpP5EP0i1UKcBBBH9tsm0w');
7
- //const wrapped = Symbol.for('50tzQZt95ECXUtHF7a40og');
8
- export async function compose(self, el, level, refName, refType) {
9
- const src = el.getAttribute('src');
10
- if (src === null)
11
- return;
12
- el.removeAttribute('src');
13
- //const templID = src!.substring(1);
14
- //const refType = src![0];
15
- const fragment = self.objNde?.deref();
16
- if (fragment === undefined)
17
- return;
18
- const templ = await self.findByID(refName, fragment, refType);
19
- if (!(templ instanceof HTMLTemplateElement))
20
- throw 404;
21
- if (refType === '#') {
22
- (await import('./slotkin/wrap.js')).wrap(templ, refName);
23
- }
24
- const clone = templ.content.cloneNode(true);
25
- const dataLd = el.dataset.ld;
26
- const wasReffed = templ[wasItemReffed];
27
- if (wasReffed || dataLd) {
28
- const firstElement = clone.firstElementChild;
29
- if (wasReffed) {
30
- let ns = firstElement.nextElementSibling;
31
- const ids = [];
32
- let count = window[autogenKey];
33
- if (count === undefined) {
34
- count = 0;
35
- }
36
- else {
37
- count++;
38
- }
39
- window[autogenKey] = count;
40
- while (ns !== null) {
41
- const id = ns.id = `mount-observer-${count}`;
42
- ids.push(id);
43
- ns = ns.nextElementSibling;
44
- }
45
- firstElement.setAttribute('itemref', ids.join(' '));
46
- }
47
- if (dataLd) {
48
- const parsed = JSON.parse(dataLd);
49
- let type = parsed['@type'];
50
- const itemscopeAttr = firstElement.getAttribute('itemscope');
51
- if (type && !itemscopeAttr) {
52
- firstElement.setAttribute('itemscope', type);
53
- }
54
- firstElement['ish'] = parsed;
55
- delete el.dataset.ld;
56
- }
57
- }
58
- if (el.content.childElementCount > 0) {
59
- const { affine } = await import('./slotkin/affine.js');
60
- const children = Array.from(el.content.children);
61
- for (const child of children) {
62
- //TODO support clean up
63
- const mo = affine(clone, child);
64
- }
65
- }
66
- await self.composeFragment(clone, level + 1);
67
- // if (false) {
68
- // const shadowRootModeOnLoad = el.getAttribute('shadowRootModeOnLoad') as null | ShadowRootMode;
69
- // if (shadowRootModeOnLoad === null && level === 0) {
70
- // const slotMap = el.getAttribute('slotmap');
71
- // let map = slotMap === null ? undefined : JSON.parse(slotMap);
72
- // const slots = clone.querySelectorAll('[slot]');
73
- // for (const slot of slots) {
74
- // if (map !== undefined) {
75
- // const slotName = slot.slot;
76
- // for (const key in map) {
77
- // if (slot.matches(key)) {
78
- // const targetAttSymbols = map[key] as string;
79
- // for (const sym of targetAttSymbols) {
80
- // switch (sym) {
81
- // case '|':
82
- // slot.setAttribute('itemprop', slotName);
83
- // break;
84
- // case '$':
85
- // slot.setAttribute('itemscope', '');
86
- // slot.setAttribute('itemprop', slotName);
87
- // break;
88
- // case '@':
89
- // slot.setAttribute('name', slotName);
90
- // break;
91
- // case '.':
92
- // slot.classList.add(slotName);
93
- // break;
94
- // case '%':
95
- // slot.part.add(slotName);
96
- // break;
97
- // }
98
- // }
99
- // }
100
- // }
101
- // }
102
- // slot.removeAttribute('slot');
103
- // }
104
- // el.dispatchEvent(new LoadEvent(clone));
105
- // }
106
- // }
107
- if (level === 0) {
108
- const refs = [];
109
- for (const child of clone.children) {
110
- refs.push(new WeakRef(child));
111
- }
112
- el[childRefsKey] = refs;
113
- }
114
- //if template has itemscope attribute, assume want to do some data binding before instantiating into
115
- //DOM fragment.
116
- let cloneStashed = false;
117
- if (el.hasAttribute('itemscope')) {
118
- el[cloneKey] = clone;
119
- cloneStashed = true;
120
- }
121
- else {
122
- // if (false /*shadowRootModeOnLoad !== null */) {
123
- // const parent = el.parentElement;
124
- // if (parent === null) throw 404;
125
- // if (parent.shadowRoot === null) parent.attachShadow({ mode: shadowRootModeOnLoad });
126
- // parent.shadowRoot?.append(clone);
127
- // } else {
128
- el.after(clone);
129
- //}
130
- }
131
- //moving the code down here broke be-inclusive Example2.html (but maybe it caused something else to work, so will need to revisit)
132
- //check to make sure the progresive loading of css-charts works as before.
133
- // if(level === 0){
134
- // el.dispatchEvent(new LoadEvent(clone));
135
- // }
136
- if (!cloneStashed) {
137
- if (level !== 0 || el.attributes.length === 0)
138
- el.remove();
139
- }
140
- }
141
- export class LoadEvent extends Event {
142
- clone;
143
- static eventName = 'load';
144
- constructor(clone) {
145
- super(LoadEvent.eventName);
146
- this.clone = clone;
147
- }
148
- }
package/compose.ts DELETED
@@ -1,164 +0,0 @@
1
- import { ILoadEvent, loadEventName, RefType } from './ts-refs/mount-observer/types';
2
- import { MountObserver, inclTemplQry, wasItemReffed } from './MountObserver.js';
3
- //import {prep} from './slotkin/affine.js';
4
-
5
- //goal: deprecate this key, in favor of comments
6
- export const childRefsKey = Symbol.for('Wr0WPVh84k+O93miuENdMA');
7
- export const cloneKey = Symbol.for('LD97VKZYc02CQv23DT/6fQ');
8
- const autogenKey = Symbol.for('YpP5EP0i1UKcBBBH9tsm0w');
9
- //const wrapped = Symbol.for('50tzQZt95ECXUtHF7a40og');
10
- export async function compose(
11
- self: MountObserver,
12
- el: HTMLTemplateElement,
13
- level: number,
14
- refName: string,
15
- refType: RefType,
16
- ) {
17
- const src = el.getAttribute('src'); if (src === null) return;
18
- el.removeAttribute('src');
19
- //const templID = src!.substring(1);
20
- //const refType = src![0];
21
- const fragment = self.objNde?.deref() as DocumentFragment;
22
- if (fragment === undefined) return;
23
- const templ = await self.findByID(refName, fragment, refType);
24
- if (!(templ instanceof HTMLTemplateElement)) throw 404;
25
- if (refType === '#') {
26
- (await import('./slotkin/wrap.js')).wrap(templ, refName);
27
- }
28
-
29
- const clone = templ.content.cloneNode(true) as DocumentFragment;
30
- const dataLd = el.dataset.ld;
31
- const wasReffed = (<any>templ)[wasItemReffed];
32
- if (wasReffed || dataLd) {
33
- const firstElement = clone.firstElementChild!;
34
- if (wasReffed) {
35
- let ns = firstElement.nextElementSibling;
36
- const ids = [];
37
- let count = (<any>window)[autogenKey];
38
- if (count === undefined) {
39
- count = 0;
40
- } else {
41
- count++;
42
- }
43
- (<any>window)[autogenKey] = count;
44
- while (ns !== null) {
45
- const id = ns.id = `mount-observer-${count}`;
46
- ids.push(id);
47
- ns = ns.nextElementSibling;
48
- }
49
- firstElement.setAttribute('itemref', ids.join(' '));
50
- }
51
-
52
- if (dataLd) {
53
- const parsed = JSON.parse(dataLd);
54
- let type = parsed['@type'];
55
- const itemscopeAttr = firstElement.getAttribute('itemscope');
56
- if (type && !itemscopeAttr) {
57
- firstElement.setAttribute('itemscope', type);
58
- }
59
- (<any>firstElement)['ish'] = parsed;
60
- delete el.dataset.ld;
61
- }
62
-
63
- }
64
- if (el.content.childElementCount > 0) {
65
- const { affine } = await import('./slotkin/affine.js');
66
- const children = Array.from(el.content.children);
67
- for (const child of children) {
68
- //TODO support clean up
69
- const mo = affine(clone, child);
70
-
71
- }
72
-
73
- }
74
-
75
-
76
- await self.composeFragment(clone, level + 1);
77
- // if (false) {
78
- // const shadowRootModeOnLoad = el.getAttribute('shadowRootModeOnLoad') as null | ShadowRootMode;
79
- // if (shadowRootModeOnLoad === null && level === 0) {
80
-
81
- // const slotMap = el.getAttribute('slotmap');
82
- // let map = slotMap === null ? undefined : JSON.parse(slotMap);
83
- // const slots = clone.querySelectorAll('[slot]');
84
- // for (const slot of slots) {
85
- // if (map !== undefined) {
86
- // const slotName = slot.slot;
87
- // for (const key in map) {
88
- // if (slot.matches(key)) {
89
- // const targetAttSymbols = map[key] as string;
90
- // for (const sym of targetAttSymbols) {
91
- // switch (sym) {
92
- // case '|':
93
- // slot.setAttribute('itemprop', slotName);
94
- // break;
95
- // case '$':
96
- // slot.setAttribute('itemscope', '');
97
- // slot.setAttribute('itemprop', slotName);
98
- // break;
99
- // case '@':
100
- // slot.setAttribute('name', slotName);
101
- // break;
102
- // case '.':
103
- // slot.classList.add(slotName);
104
- // break;
105
- // case '%':
106
- // slot.part.add(slotName);
107
- // break;
108
- // }
109
- // }
110
- // }
111
- // }
112
- // }
113
- // slot.removeAttribute('slot');
114
- // }
115
- // el.dispatchEvent(new LoadEvent(clone));
116
- // }
117
- // }
118
-
119
- if (level === 0) {
120
- const refs: Array<WeakRef<Element>> = [];
121
- for (const child of clone.children) {
122
- refs.push(new WeakRef(child));
123
- }
124
- (<any>el)[childRefsKey] = refs;
125
-
126
- }
127
- //if template has itemscope attribute, assume want to do some data binding before instantiating into
128
- //DOM fragment.
129
- let cloneStashed = false;
130
- if (el.hasAttribute('itemscope')) {
131
- (<any>el)[cloneKey] = clone;
132
- cloneStashed = true;
133
- } else {
134
- // if (false /*shadowRootModeOnLoad !== null */) {
135
- // const parent = el.parentElement;
136
- // if (parent === null) throw 404;
137
- // if (parent.shadowRoot === null) parent.attachShadow({ mode: shadowRootModeOnLoad });
138
- // parent.shadowRoot?.append(clone);
139
- // } else {
140
- el.after(clone);
141
- //}
142
- }
143
- //moving the code down here broke be-inclusive Example2.html (but maybe it caused something else to work, so will need to revisit)
144
- //check to make sure the progresive loading of css-charts works as before.
145
- // if(level === 0){
146
- // el.dispatchEvent(new LoadEvent(clone));
147
- // }
148
-
149
- if (!cloneStashed) {
150
- if (level !== 0 || el.attributes.length === 0) el.remove();
151
- }
152
-
153
- }
154
-
155
- export class LoadEvent extends Event implements ILoadEvent {
156
- static eventName: loadEventName = 'load';
157
- constructor(public clone: DocumentFragment) {
158
- super(LoadEvent.eventName);
159
- }
160
- }
161
-
162
- interface HTMLElementEventMap {
163
- 'load': LoadEvent,
164
- }