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.
- package/Events.js +28 -26
- package/Events.ts +34 -30
- package/MountObserver.js +235 -520
- package/MountObserver.ts +281 -542
- package/README.md +149 -56
- package/attrCoordinates.js +93 -0
- package/attrCoordinates.ts +122 -0
- package/constants.js +6 -0
- package/constants.ts +7 -0
- package/index.js +3 -0
- package/index.ts +19 -0
- package/loadImports.js +47 -0
- package/loadImports.ts +56 -0
- package/package.json +8 -115
- package/playwright.config.ts +0 -1
- package/types.d.ts +86 -0
- package/whereAttr.js +174 -0
- package/whereAttr.ts +221 -0
- package/LICENSE +0 -21
- package/Newish.js +0 -145
- package/Newish.ts +0 -169
- package/ObsAttr.js +0 -18
- package/ObsAttr.ts +0 -18
- package/RootMutObs.js +0 -49
- package/RootMutObs.ts +0 -58
- package/Synthesizer.js +0 -125
- package/Synthesizer.ts +0 -130
- package/bindish.js +0 -15
- package/bindish.ts +0 -22
- package/compose.js +0 -148
- package/compose.ts +0 -164
- package/doCleanup.js +0 -31
- package/doCleanup.ts +0 -34
- package/getWhereAttrSelector.js +0 -83
- package/getWhereAttrSelector.ts +0 -92
- package/preloadContent.js +0 -44
- package/preloadContent.ts +0 -47
- package/readAttrs.ts +0 -60
- package/refid/README.md +0 -259
- package/refid/arr.js +0 -4
- package/refid/arr.ts +0 -4
- package/refid/camelToKebab.js +0 -4
- package/refid/camelToKebab.ts +0 -4
- package/refid/genIds.js +0 -190
- package/refid/genIds.ts +0 -177
- package/refid/getAdjRefs.js +0 -38
- package/refid/getAdjRefs.ts +0 -38
- package/refid/getContext.js +0 -13
- package/refid/getContext.ts +0 -14
- package/refid/getCount.js +0 -8
- package/refid/getCount.ts +0 -8
- package/refid/getIsh.js +0 -35
- package/refid/getIsh.ts +0 -37
- package/refid/hostish.js +0 -18
- package/refid/hostish.ts +0 -20
- package/refid/ism.js +0 -78
- package/refid/ism.ts +0 -81
- package/refid/itemprops.js +0 -60
- package/refid/itemprops.ts +0 -67
- package/refid/joinMatching.js +0 -56
- package/refid/joinMatching.ts +0 -54
- package/refid/nudge.js +0 -23
- package/refid/nudge.ts +0 -23
- package/refid/regIsh.js +0 -27
- package/refid/regIsh.ts +0 -31
- package/refid/secretKeys.js +0 -5
- package/refid/secretKeys.ts +0 -5
- package/refid/splitRefs.js +0 -6
- package/refid/splitRefs.ts +0 -6
- package/refid/stdVal.js +0 -15
- package/refid/stdVal.ts +0 -15
- package/refid/via.js +0 -114
- package/refid/via.ts +0 -113
- package/slotkin/affine.js +0 -39
- package/slotkin/affine.ts +0 -46
- package/slotkin/beKindred.js +0 -45
- package/slotkin/beKindred.ts +0 -55
- package/slotkin/getBreadth.js +0 -19
- package/slotkin/getBreadth.ts +0 -21
- package/slotkin/getFrag.js +0 -22
- package/slotkin/getFrag.ts +0 -21
- package/slotkin/toQuery.js +0 -12
- package/slotkin/toQuery.ts +0 -13
- package/slotkin/wrap.js +0 -13
- package/slotkin/wrap.ts +0 -18
- package/ts-refs/LICENSE +0 -21
- package/ts-refs/README.md +0 -18
- package/ts-refs/be-a-beacon/types.d.ts +0 -22
- package/ts-refs/be-alit/types.d.ts +0 -1
- package/ts-refs/be-based/types.d.ts +0 -32
- package/ts-refs/be-bound/types.d.ts +0 -65
- package/ts-refs/be-buttoned-up/types.d.ts +0 -21
- package/ts-refs/be-calculating/types.d.ts +0 -57
- package/ts-refs/be-clonable/types.d.ts +0 -28
- package/ts-refs/be-committed/types.d.ts +0 -26
- package/ts-refs/be-consoling/types.d.ts +0 -25
- package/ts-refs/be-counted/types.d.ts +0 -88
- package/ts-refs/be-delible/types.d.ts +0 -26
- package/ts-refs/be-directive/types.d.ts +0 -43
- package/ts-refs/be-dispatching/types.d.ts +0 -41
- package/ts-refs/be-elevating/types.d.ts +0 -55
- package/ts-refs/be-enhanced/types.d.ts +0 -32
- package/ts-refs/be-enhancing/types.d.ts +0 -31
- package/ts-refs/be-evanescent/types.d.ts +0 -20
- package/ts-refs/be-eventing/types.d.ts +0 -27
- package/ts-refs/be-exportable/types.d.ts +0 -26
- package/ts-refs/be-fetching/types.d.ts +0 -73
- package/ts-refs/be-flashy/types.d.ts +0 -27
- package/ts-refs/be-formalizing/types.d.ts +0 -29
- package/ts-refs/be-formidable/types.d.ts +0 -64
- package/ts-refs/be-giddy/types.d.ts +0 -26
- package/ts-refs/be-gingerly/types.d.ts +0 -19
- package/ts-refs/be-gone/types.d.ts +0 -24
- package/ts-refs/be-hashing-out/types.d.ts +0 -22
- package/ts-refs/be-hive/types.d.ts +0 -18
- package/ts-refs/be-imbued/types.d.ts +0 -30
- package/ts-refs/be-included/types.d.ts +0 -20
- package/ts-refs/be-inclusive/types.d.ts +0 -30
- package/ts-refs/be-intersectional/types.d.ts +0 -37
- package/ts-refs/be-intl/types.d.ts +0 -28
- package/ts-refs/be-invoking/types.d.ts +0 -28
- package/ts-refs/be-joining/types.d.ts +0 -26
- package/ts-refs/be-kvetching/types.d.ts +0 -24
- package/ts-refs/be-lazy/types.d.ts +0 -29
- package/ts-refs/be-literate/types.d.ts +0 -29
- package/ts-refs/be-mediating/types.d.ts +0 -34
- package/ts-refs/be-methodical/types.d.ts +0 -20
- package/ts-refs/be-modding/types.d.ts +0 -18
- package/ts-refs/be-observant/types.d.ts +0 -27
- package/ts-refs/be-observing/types.d.ts +0 -84
- package/ts-refs/be-parsed/types.d.ts +0 -19
- package/ts-refs/be-parsing/types.d.ts +0 -37
- package/ts-refs/be-persistent/types.d.ts +0 -66
- package/ts-refs/be-propagating/types.d.ts +0 -26
- package/ts-refs/be-reformable/types.d.ts +0 -48
- package/ts-refs/be-render-neutral/types.d.ts +0 -31
- package/ts-refs/be-scoped/types.d.ts +0 -24
- package/ts-refs/be-sharing/types.d.ts +0 -17
- package/ts-refs/be-switched/types.d.ts +0 -155
- package/ts-refs/be-typed/types.d.ts +0 -36
- package/ts-refs/be-value-added/types.d.ts +0 -34
- package/ts-refs/be-valued/types.d.ts +0 -22
- package/ts-refs/be-written/types.d.ts +0 -59
- package/ts-refs/css-charts/types.d.ts +0 -38
- package/ts-refs/css-echarts/types.d.ts +0 -13
- package/ts-refs/data-props/types.d.ts +0 -27
- package/ts-refs/do-inc/types.d.ts +0 -28
- package/ts-refs/do-invoke/types.d.ts +0 -28
- package/ts-refs/do-toggle/types.d.ts +0 -27
- package/ts-refs/em-bower/types.d.ts +0 -18
- package/ts-refs/fetch-for/types.d.ts +0 -37
- package/ts-refs/folder-picker/types.d.ts +0 -43
- package/ts-refs/for-fetch/doc.d.ts +0 -98
- package/ts-refs/for-fetch/types.d.ts +0 -83
- package/ts-refs/mount-observer/types.d.ts +0 -248
- package/ts-refs/mt-si/types.d.ts +0 -21
- package/ts-refs/per-each/types.d.ts +0 -51
- package/ts-refs/soak-up/types.d.ts +0 -36
- package/ts-refs/trans-render/XV/types.d.ts +0 -69
- package/ts-refs/trans-render/asmr/types.d.ts +0 -138
- package/ts-refs/trans-render/be/types.d.ts +0 -190
- package/ts-refs/trans-render/dss/types.d.ts +0 -57
- package/ts-refs/trans-render/froop/types.d.ts +0 -416
- package/ts-refs/trans-render/funions/types.d.ts +0 -12
- package/ts-refs/trans-render/lib/mixins/types.d.ts +0 -42
- package/ts-refs/trans-render/lib/prs/types.d.ts +0 -40
- package/ts-refs/trans-render/lib/types.d.ts +0 -489
- package/ts-refs/trans-render/types.d.ts +0 -583
- package/ts-refs/wc-info/SimpleWCInfo.d.ts +0 -15
- package/ts-refs/when-resolved/types.d.ts +0 -30
- package/ts-refs/xp-as/types.d.ts +0 -20
- package/ts-refs/xtal-element/types.d.ts +0 -43
- package/ts-refs/xtal-frappe-chart/types.d.ts +0 -193
- package/upShadowSearch.js +0 -25
- package/upShadowSearch.ts +0 -23
- package/waitForEvent.js +0 -12
- package/waitForEvent.ts +0 -13
- package/waitForIsh.js +0 -21
- 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
|
-
}
|