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/Newish.ts DELETED
@@ -1,169 +0,0 @@
1
- import { BindishOptions, HasIsh, Ishcycle } from './ts-refs/mount-observer/types.js';
2
-
3
- export {waitForEvent} from './waitForEvent.js';
4
- import {ObsAttr} from './ObsAttr.js';
5
- import {splitRefs} from './refid/splitRefs.js';
6
- import {getIsh} from './refid/getIsh.js';
7
- import {arr} from './refid/secretKeys.js';
8
- export const attached = Symbol.for('xyyspnstnU+CDrNVa0VnxA');
9
- export class Newish implements EventListenerObject {
10
- queue: Array<any> = [];
11
- isResolved = false;
12
- #ce: Ishcycle | undefined;
13
- #ref: WeakRef<Element>;
14
-
15
- #options: BindishOptions;
16
- #args: [enhancedElement: Element, target: Node, itemscope: string] | undefined;
17
- constructor(
18
- enhancedElement: Element,
19
- target: Node,
20
- itemscope: string,
21
- options?: BindishOptions
22
- ){
23
- this.#args = [enhancedElement, target, itemscope];
24
- this.#options = options || {assigner: Object.assign};
25
- this.#ref = new WeakRef(enhancedElement);
26
- }
27
- async handleEvent() {
28
- const enhancedElement = this.#ref.deref();
29
- if(!enhancedElement) return;
30
- await this.#attachItemrefs(enhancedElement);
31
- }
32
-
33
- async do(){
34
- const [enhancedElement, target, itemscope] = this.#args!;
35
- this.#args = undefined;
36
- if((<any>enhancedElement)[attached] === true) return;
37
- (<any>enhancedElement)[attached] = true;
38
- const options = this.#options;
39
- const {initPropVals, ctr} = options;
40
- let ce: Ishcycle;
41
- if(ctr === undefined){
42
- const foundCtr = await getIsh(enhancedElement.isConnected ? enhancedElement :target, itemscope)! as any;
43
-
44
- const initPropVals = (<any>enhancedElement)['ish'];
45
-
46
- const resolvedConstructor = foundCtr.constructor.name === 'AsyncFunction' ? await foundCtr() : foundCtr;
47
- const isInstance = initPropVals instanceof resolvedConstructor
48
- ce = isInstance ? initPropVals : new resolvedConstructor() as Ishcycle;
49
- if(initPropVals !== undefined && !isInstance) this.queue.push(initPropVals);
50
- }else{
51
- ce = new (ctr as any)();
52
- if(initPropVals !== undefined) this.queue.push(initPropVals);
53
- }
54
- // if('tbd' in ce && typeof ce['tbd'] === 'function'){
55
- // await ce['tbd'](ce, enhancedElement, this.#options);
56
- // }
57
-
58
- this.#ce = ce;
59
- const self = this;
60
- Object.defineProperty(enhancedElement, 'ish', {
61
- get(){
62
- return self.#ce;
63
- },
64
- set(nv: any){
65
- if(self.#ce === nv) return;
66
- self.queue.push(nv);
67
- self.#assignGingerly(false);
68
- },
69
- enumerable: true,
70
- configurable: true,
71
- });
72
- await this.#assignGingerly(true);
73
- if('<mount>' in ce && typeof ce['<mount>'] === 'function'){
74
- await ce['<mount>'](ce, enhancedElement as HasIsh & Element, this.#options)
75
- }
76
- //attach any itemref references
77
- await this.#attachItemrefs(enhancedElement);
78
- const et = ObsAttr(enhancedElement, 'itemref');
79
- et.addEventListener('attr-changed', this);
80
- this.isResolved = true;
81
- return ce;
82
- }
83
-
84
-
85
-
86
- #alreadyAttached = new WeakSet<Element>;
87
-
88
- async #attachItemrefs(enhancedElement: Element){
89
- //TODO: watch for already attached itemrefs to be removed and remove them from the set
90
- // and call outOfScopeCallback on them
91
- if('<inScope>' in (<any>this.#ce) && enhancedElement.hasAttribute('itemref')){
92
- await import('./refid/via.js');
93
- const itemref = (<any>enhancedElement).via.itemref
94
- const refs = itemref.children as Element[];
95
- for(const ref of refs){
96
- if(this.#alreadyAttached.has(ref)) continue;
97
- (<any>this.#ce)['<inScope>'](this.#ce, ref, this.#options);
98
- }
99
- itemref.addEventListener('change', this);
100
-
101
- }
102
-
103
- }
104
-
105
- async #assignGingerly(fromDo: boolean){
106
- const actions = new Set<Action>();
107
- if(fromDo){
108
- actions.add('attached');
109
- }
110
- let ce = this.#ce!;
111
- if(ce === undefined){
112
- throw 500;
113
- }
114
- let foundArray = false;
115
- const hasArrFilter = 'arr=>' in ce && typeof ce['arr=>'] === 'function';
116
- const ref = this.#ref.deref();
117
- while(this.queue.length > 0 ){
118
- const fi = this.queue.shift();
119
- //TODO: Provide support for a virtual slice of a very large list
120
- //TODO: Maybe should check if iterable rather than an array?
121
- if(Array.isArray(fi)){
122
- foundArray = true;
123
- let filtered = fi as any | undefined;
124
- if(hasArrFilter){
125
- filtered = await (ce['arr=>']!)(ce, fi, ref! as HasIsh & Element, this.#options);
126
- }
127
- (<any>ce)[arr] = filtered;
128
- actions.add('ishListAssigned');
129
- }else{
130
- let {assigner} = this.#options;
131
- if(assigner === undefined){
132
- assigner = Object.assign;
133
- }
134
- await assigner!(ce, fi);
135
- actions.add('ishAssigned');
136
- }
137
-
138
- }
139
- if(fromDo && !foundArray && hasArrFilter){
140
- const filtered = await (ce['arr=>']!)(ce, undefined, ref! as HasIsh & Element, this.#options);
141
- if(filtered !== undefined){
142
- (<any>ce)[arr] = filtered;
143
- actions.add('ishListAssigned');
144
- }
145
- }
146
-
147
- if(ref){
148
- ref.dispatchEvent(new IshEvent(Array.from(actions)));
149
- }
150
- }
151
-
152
- }
153
-
154
- type Action =
155
- | 'attached'
156
- | 'ishAssigned'
157
- | 'ishListAssigned'
158
-
159
- interface IIshEvent{
160
- actions: Array<Action>;
161
- }
162
-
163
- export class IshEvent extends Event implements IIshEvent{
164
- static eventName = 'ish';
165
-
166
- constructor(public actions: Array<Action>){
167
- super(IshEvent.eventName);
168
- }
169
- }
package/ObsAttr.js DELETED
@@ -1,18 +0,0 @@
1
- export function ObsAttr(element, attr) {
2
- const eventTarget = new EventTarget();
3
- const obs = new MutationObserver((mutations) => {
4
- eventTarget.dispatchEvent(new Event('attr-changed'));
5
- // for(const mutation of mutations){
6
- // if(mutation.type === 'attributes' && mutation.attributeName === attr){
7
- // obs.disconnect();
8
- // eventTarget.dispatchEvent(new Event('obsAttr'));
9
- // break;
10
- // }
11
- // }
12
- });
13
- obs.observe(element, {
14
- attributes: true,
15
- attributeFilter: [attr],
16
- });
17
- return eventTarget;
18
- }
package/ObsAttr.ts DELETED
@@ -1,18 +0,0 @@
1
- export function ObsAttr(element: Element, attr: string): EventTarget{
2
- const eventTarget = new EventTarget();
3
- const obs = new MutationObserver((mutations) => {
4
- eventTarget.dispatchEvent(new Event('attr-changed'));
5
- // for(const mutation of mutations){
6
- // if(mutation.type === 'attributes' && mutation.attributeName === attr){
7
- // obs.disconnect();
8
- // eventTarget.dispatchEvent(new Event('obsAttr'));
9
- // break;
10
- // }
11
- // }
12
- });
13
- obs.observe(element, {
14
- attributes: true,
15
- attributeFilter: [attr],
16
- });
17
- return eventTarget;
18
- }
package/RootMutObs.js DELETED
@@ -1,49 +0,0 @@
1
- export class RootMutObs extends EventTarget {
2
- #idleTimeout; //TODO: make this configurable
3
- #idlePointer = 0;
4
- constructor(rootNode, options) {
5
- super();
6
- this.#idleTimeout = options?.idleTimeout ?? 30;
7
- this.#mutationObserver = new MutationObserver(mutationRecords => {
8
- this.dispatchEvent(new MutationEvent(mutationRecords));
9
- this.#triggerIsIdle();
10
- });
11
- this.#mutationObserver.observe(rootNode, {
12
- subtree: true,
13
- childList: true,
14
- attributes: true,
15
- attributeOldValue: true,
16
- });
17
- this.#triggerIsIdle();
18
- }
19
- #isIdle = false;
20
- get isIdle() {
21
- return this.#isIdle;
22
- }
23
- #triggerIsIdle() {
24
- this.#isIdle = false;
25
- clearTimeout(this.#idlePointer);
26
- this.#idlePointer = setTimeout(() => {
27
- this.#isIdle = true;
28
- this.dispatchEvent(new Event('is-idle'));
29
- }, this.#idleTimeout);
30
- }
31
- #mutationObserver;
32
- disconnect() {
33
- this.#mutationObserver.disconnect();
34
- }
35
- }
36
- // https://github.com/webcomponents-cg/community-protocols/issues/12#issuecomment-872415080
37
- /**
38
- * The `mutation-event` event represents something that happened.
39
- * We can document it here.
40
- */
41
- export class MutationEvent extends Event {
42
- mutationRecords;
43
- static eventName = 'mutation-event';
44
- constructor(mutationRecords) {
45
- // Since these are hard-coded, dispatchers can't get them wrong
46
- super(MutationEvent.eventName);
47
- this.mutationRecords = mutationRecords;
48
- }
49
- }
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
- }