@dooboostore/simple-web-component 1.0.15 → 1.0.17
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/README.md +275 -91
- package/dist/cjs/decorators/addEventListener.js +2 -3
- package/dist/cjs/decorators/addEventListener.js.map +2 -2
- package/dist/cjs/decorators/elementDefine.js +161 -34
- package/dist/cjs/decorators/elementDefine.js.map +3 -3
- package/dist/cjs/decorators/emitCustomEvent.js +2 -14
- package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
- package/dist/cjs/decorators/query.js +47 -36
- package/dist/cjs/decorators/query.js.map +2 -2
- package/dist/cjs/decorators/queryAll.js +42 -36
- package/dist/cjs/decorators/queryAll.js.map +2 -2
- package/dist/cjs/elements/SwcAppEngine.js +2 -1
- package/dist/cjs/elements/SwcAppEngine.js.map +2 -2
- package/dist/cjs/elements/SwcAsync.js +188 -0
- package/dist/cjs/elements/SwcAsync.js.map +7 -0
- package/dist/cjs/elements/SwcChoose.js +155 -0
- package/dist/cjs/elements/SwcChoose.js.map +7 -0
- package/dist/cjs/elements/SwcIf.js +167 -0
- package/dist/cjs/elements/SwcIf.js.map +7 -0
- package/dist/cjs/elements/SwcLoop.js +246 -0
- package/dist/cjs/elements/SwcLoop.js.map +7 -0
- package/dist/cjs/elements/SwcSubTemplates.js +65 -0
- package/dist/cjs/elements/SwcSubTemplates.js.map +7 -0
- package/dist/cjs/elements/index.js +7 -0
- package/dist/cjs/elements/index.js.map +2 -2
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/types.js +1 -0
- package/dist/cjs/types.js.map +2 -2
- package/dist/cjs/utils/Utils.js +92 -162
- package/dist/cjs/utils/Utils.js.map +3 -3
- package/dist/esm/decorators/addEventListener.js +2 -3
- package/dist/esm/decorators/addEventListener.js.map +2 -2
- package/dist/esm/decorators/elementDefine.js +161 -34
- package/dist/esm/decorators/elementDefine.js.map +3 -3
- package/dist/esm/decorators/emitCustomEvent.js +2 -14
- package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
- package/dist/esm/decorators/query.js +47 -36
- package/dist/esm/decorators/query.js.map +2 -2
- package/dist/esm/decorators/queryAll.js +42 -36
- package/dist/esm/decorators/queryAll.js.map +2 -2
- package/dist/esm/elements/SwcAppEngine.js +2 -1
- package/dist/esm/elements/SwcAppEngine.js.map +2 -2
- package/dist/esm/elements/SwcAsync.js +169 -0
- package/dist/esm/elements/SwcAsync.js.map +7 -0
- package/dist/esm/elements/SwcChoose.js +136 -0
- package/dist/esm/elements/SwcChoose.js.map +7 -0
- package/dist/esm/elements/SwcIf.js +148 -0
- package/dist/esm/elements/SwcIf.js.map +7 -0
- package/dist/esm/elements/SwcLoop.js +227 -0
- package/dist/esm/elements/SwcLoop.js.map +7 -0
- package/dist/esm/elements/SwcSubTemplates.js +46 -0
- package/dist/esm/elements/SwcSubTemplates.js.map +7 -0
- package/dist/esm/elements/index.js +7 -0
- package/dist/esm/elements/index.js.map +2 -2
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types.js +1 -0
- package/dist/esm/types.js.map +2 -2
- package/dist/esm/utils/Utils.js +92 -162
- package/dist/esm/utils/Utils.js.map +3 -3
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +1150 -326
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/decorators/addEventListener.d.ts +10 -4
- package/dist/types/decorators/addEventListener.d.ts.map +1 -1
- package/dist/types/decorators/elementDefine.d.ts.map +1 -1
- package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
- package/dist/types/decorators/query.d.ts +4 -5
- package/dist/types/decorators/query.d.ts.map +1 -1
- package/dist/types/decorators/queryAll.d.ts +4 -5
- package/dist/types/decorators/queryAll.d.ts.map +1 -1
- package/dist/types/elements/SwcAppEngine.d.ts.map +1 -1
- package/dist/types/elements/SwcAsync.d.ts +16 -0
- package/dist/types/elements/SwcAsync.d.ts.map +1 -0
- package/dist/types/elements/SwcChoose.d.ts +13 -0
- package/dist/types/elements/SwcChoose.d.ts.map +1 -0
- package/dist/types/elements/SwcIf.d.ts +15 -0
- package/dist/types/elements/SwcIf.d.ts.map +1 -0
- package/dist/types/elements/SwcLoop.d.ts +20 -0
- package/dist/types/elements/SwcLoop.d.ts.map +1 -0
- package/dist/types/elements/SwcSubTemplates.d.ts +13 -0
- package/dist/types/elements/SwcSubTemplates.d.ts.map +1 -0
- package/dist/types/elements/index.d.ts +7 -0
- package/dist/types/elements/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types.d.ts +11 -1
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils/Utils.d.ts +19 -21
- package/dist/types/utils/Utils.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +1150 -326
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +10 -3
- package/src/decorators/addEventListener.ts +11 -7
- package/src/decorators/elementDefine.ts +165 -39
- package/src/decorators/emitCustomEvent.ts +5 -21
- package/src/decorators/query.ts +46 -41
- package/src/decorators/queryAll.ts +45 -41
- package/src/elements/SwcAppEngine.ts +2 -1
- package/src/elements/SwcAsync.ts +163 -0
- package/src/elements/SwcChoose.ts +127 -0
- package/src/elements/SwcIf.ts +134 -0
- package/src/elements/SwcLoop.ts +215 -0
- package/src/elements/SwcSubTemplates.ts +19 -0
- package/src/elements/index.ts +8 -3
- package/src/index.ts +1 -1
- package/src/types.ts +15 -5
- package/src/utils/Utils.ts +111 -197
package/dist/esm/utils/Utils.js
CHANGED
|
@@ -1,181 +1,111 @@
|
|
|
1
|
+
import { getElementConfig } from "../decorators/elementDefine.js";
|
|
1
2
|
const SWC_NOT_FOUND = Symbol("SWC_NOT_FOUND");
|
|
2
|
-
|
|
3
|
-
|
|
3
|
+
var SwcUtils;
|
|
4
|
+
((SwcUtils2) => {
|
|
5
|
+
SwcUtils2.getHelperSet = (win) => {
|
|
6
|
+
const doc = win.document;
|
|
7
|
+
return {
|
|
8
|
+
$d: doc,
|
|
9
|
+
$w: win,
|
|
10
|
+
$q: (sel, root) => (root ?? doc).querySelector(sel),
|
|
11
|
+
$qa: (sel, root) => Array.from((root ?? doc).querySelectorAll(sel)),
|
|
12
|
+
$qi: (id, root) => (root ?? doc).getElementById(id)
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
SwcUtils2.getHelperAndHostSet = (win, el) => {
|
|
16
|
+
const helperSet = (0, SwcUtils2.getHelperSet)(win);
|
|
17
|
+
const hostSet = (0, SwcUtils2.getHostSet)(el);
|
|
18
|
+
return {
|
|
19
|
+
...helperSet,
|
|
20
|
+
...hostSet
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
SwcUtils2.getValueByPath = (obj, path, rootName) => {
|
|
4
24
|
if (!obj || !path) return SWC_NOT_FOUND;
|
|
5
25
|
const parts = path.split(".");
|
|
6
|
-
|
|
7
|
-
const subParts = parts.slice(1);
|
|
8
|
-
let subResult = obj;
|
|
9
|
-
for (const part of subParts) {
|
|
10
|
-
if (subResult === null || typeof subResult !== "object" || !(part in subResult)) return SWC_NOT_FOUND;
|
|
11
|
-
subResult = subResult[part];
|
|
12
|
-
}
|
|
13
|
-
return subResult;
|
|
14
|
-
}
|
|
15
|
-
let result = obj;
|
|
26
|
+
let current = obj;
|
|
16
27
|
for (const part of parts) {
|
|
17
|
-
if (
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
result = result[part];
|
|
21
|
-
}
|
|
22
|
-
if (result !== obj && !(result instanceof HTMLElement)) {
|
|
23
|
-
return result;
|
|
24
|
-
}
|
|
25
|
-
return SWC_NOT_FOUND;
|
|
26
|
-
}
|
|
27
|
-
static evalExpression(expr, context) {
|
|
28
|
-
try {
|
|
29
|
-
const keys = Object.keys(context);
|
|
30
|
-
const values = Object.values(context);
|
|
31
|
-
return new Function(...keys, `return (${expr})`).apply(null, values);
|
|
32
|
-
} catch {
|
|
33
|
-
return SWC_NOT_FOUND;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
static applyData(node, data, options) {
|
|
37
|
-
const { asKey, asIndexKey, index, hostContext } = options;
|
|
38
|
-
const context = {};
|
|
39
|
-
if (index !== void 0) {
|
|
40
|
-
context[asIndexKey] = index;
|
|
28
|
+
if (current === null || current === void 0) return SWC_NOT_FOUND;
|
|
29
|
+
current = current[part];
|
|
41
30
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
31
|
+
return current;
|
|
32
|
+
};
|
|
33
|
+
SwcUtils2.findNearestSwcHost = (el) => {
|
|
34
|
+
if (el.__swc_host) return el.__swc_host;
|
|
35
|
+
let current = el.parentElement || el.getRootNode?.()?.host;
|
|
36
|
+
while (current && current !== document && current !== window) {
|
|
37
|
+
if (current.__swc_host) return current.__swc_host;
|
|
38
|
+
if (getElementConfig(current)) return current;
|
|
39
|
+
current = current.parentElement || current.getRootNode?.()?.host;
|
|
45
40
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const simpleVal = SwcUtils.getValueByPath(data, expr, asKey);
|
|
50
|
-
if (simpleVal !== SWC_NOT_FOUND && typeof simpleVal !== "symbol") {
|
|
51
|
-
return simpleVal === null || simpleVal === void 0 ? "" : String(simpleVal);
|
|
52
|
-
}
|
|
53
|
-
const exprVal = SwcUtils.evalExpression(expr, fullContext);
|
|
54
|
-
if (exprVal !== SWC_NOT_FOUND && typeof exprVal !== "symbol") {
|
|
55
|
-
return exprVal === null || exprVal === void 0 ? "" : String(exprVal);
|
|
56
|
-
}
|
|
57
|
-
return match;
|
|
58
|
-
};
|
|
59
|
-
const walk = (n) => {
|
|
60
|
-
if (n.nodeType === Node.TEXT_NODE) {
|
|
61
|
-
if (!n._original) n._original = n.textContent;
|
|
62
|
-
let text = n._original;
|
|
63
|
-
text = text.replace(/{{(.*?)}}/g, (match, path) => {
|
|
64
|
-
return resolveExpr(path, match);
|
|
65
|
-
});
|
|
66
|
-
if (n.textContent !== text) n.textContent = text;
|
|
67
|
-
} else if (n.nodeType === Node.ELEMENT_NODE) {
|
|
68
|
-
const el = n;
|
|
69
|
-
Array.from(el.attributes).forEach((a) => {
|
|
70
|
-
if (!a._original) a._original = a.value;
|
|
71
|
-
let val = a._original;
|
|
72
|
-
val = val.replace(/{{(.*?)}}/g, (match, path) => {
|
|
73
|
-
return resolveExpr(path, match);
|
|
74
|
-
});
|
|
75
|
-
if (a.value !== val) a.value = val;
|
|
76
|
-
});
|
|
77
|
-
el.childNodes.forEach(walk);
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
walk(node);
|
|
81
|
-
}
|
|
82
|
-
static createReactiveProxy(target, onChange, onIndexChange) {
|
|
83
|
-
const makeRecursiveProxy = (obj) => {
|
|
84
|
-
if (typeof obj !== "object" || obj === null || obj instanceof Node) return obj;
|
|
85
|
-
if (obj.__swc_is_proxy) return obj;
|
|
86
|
-
const IS_PROXY_KEY = "__swc_is_proxy";
|
|
87
|
-
const proxy = new Proxy(obj, {
|
|
88
|
-
get: (t, prop) => {
|
|
89
|
-
if (prop === IS_PROXY_KEY) return true;
|
|
90
|
-
if (typeof prop === "symbol") return t[prop];
|
|
91
|
-
return t[prop];
|
|
92
|
-
},
|
|
93
|
-
set: (t, prop, val) => {
|
|
94
|
-
if (prop === IS_PROXY_KEY) return true;
|
|
95
|
-
if (typeof prop === "symbol") {
|
|
96
|
-
t[prop] = val;
|
|
97
|
-
return true;
|
|
98
|
-
}
|
|
99
|
-
const oldVal = t[prop];
|
|
100
|
-
if (oldVal === val) return true;
|
|
101
|
-
t[prop] = makeRecursiveProxy(val);
|
|
102
|
-
const isIndex = !isNaN(Number(prop)) && Array.isArray(t);
|
|
103
|
-
if (isIndex && onIndexChange) {
|
|
104
|
-
onIndexChange(Number(prop), val);
|
|
105
|
-
} else {
|
|
106
|
-
onChange();
|
|
107
|
-
}
|
|
108
|
-
return true;
|
|
109
|
-
},
|
|
110
|
-
deleteProperty: (t, prop) => {
|
|
111
|
-
delete t[prop];
|
|
112
|
-
onChange();
|
|
113
|
-
return true;
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
return proxy;
|
|
117
|
-
};
|
|
118
|
-
return makeRecursiveProxy(target);
|
|
119
|
-
}
|
|
120
|
-
static findNearestSwcHost(el) {
|
|
121
|
-
const hosts = this.findAllSwcHosts(el);
|
|
122
|
-
return hosts.length > 0 ? hosts[hosts.length - 1] : null;
|
|
123
|
-
}
|
|
124
|
-
static findAllSwcHosts(el) {
|
|
41
|
+
return void 0;
|
|
42
|
+
};
|
|
43
|
+
SwcUtils2.findAllSwcHosts = (el) => {
|
|
125
44
|
const hosts = [];
|
|
126
|
-
let
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
curr = curr.parentElement || curr?.getRootNode()?.host;
|
|
45
|
+
let current = (0, SwcUtils2.findNearestSwcHost)(el);
|
|
46
|
+
while (current) {
|
|
47
|
+
hosts.push(current);
|
|
48
|
+
current = (0, SwcUtils2.findNearestSwcHost)(current);
|
|
131
49
|
}
|
|
132
50
|
return hosts.reverse();
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
static getAppHosts(el) {
|
|
146
|
-
const hosts = this.getHosts(el);
|
|
51
|
+
};
|
|
52
|
+
SwcUtils2.getHosts = (el) => {
|
|
53
|
+
const ancestors = (0, SwcUtils2.findAllSwcHosts)(el);
|
|
54
|
+
if (getElementConfig(el)) return [...ancestors, el];
|
|
55
|
+
return ancestors;
|
|
56
|
+
};
|
|
57
|
+
SwcUtils2.getHost = (el) => {
|
|
58
|
+
if (getElementConfig(el)) return el;
|
|
59
|
+
return (0, SwcUtils2.findNearestSwcHost)(el);
|
|
60
|
+
};
|
|
61
|
+
SwcUtils2.getAppHosts = (el) => {
|
|
62
|
+
const hosts = (0, SwcUtils2.getHosts)(el);
|
|
147
63
|
return hosts.filter((host) => host.tagName.toLowerCase() === "swc-app" || host.getAttribute("is")?.startsWith("swc-app-"));
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
const appHosts =
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
const $
|
|
64
|
+
};
|
|
65
|
+
SwcUtils2.getAppHost = (el) => {
|
|
66
|
+
const appHosts = (0, SwcUtils2.getAppHosts)(el);
|
|
67
|
+
const appHostsWithoutSelf = appHosts.filter((h) => h !== el);
|
|
68
|
+
return appHostsWithoutSelf.length > 0 ? appHostsWithoutSelf[appHostsWithoutSelf.length - 1] : void 0;
|
|
69
|
+
};
|
|
70
|
+
SwcUtils2.getHostSet = (el) => {
|
|
71
|
+
const isSwc = !!getElementConfig(el);
|
|
72
|
+
const ancestors = (0, SwcUtils2.findAllSwcHosts)(el);
|
|
73
|
+
let $host;
|
|
74
|
+
let $parentHost;
|
|
75
|
+
if (isSwc) {
|
|
76
|
+
$host = el;
|
|
77
|
+
$parentHost = ancestors.length > 0 ? ancestors[ancestors.length - 1] : null;
|
|
78
|
+
} else {
|
|
79
|
+
$host = ancestors.length > 0 ? ancestors[ancestors.length - 1] : el;
|
|
80
|
+
$parentHost = ancestors.length > 1 ? ancestors[ancestors.length - 2] : null;
|
|
81
|
+
}
|
|
82
|
+
const $hosts = isSwc ? [...ancestors, el] : ancestors;
|
|
83
|
+
const $firstHost = $hosts.length > 0 ? $hosts[0] : null;
|
|
84
|
+
const loopContext = {};
|
|
85
|
+
let curr = el;
|
|
86
|
+
while (curr && curr !== document.documentElement) {
|
|
87
|
+
if (curr.__swc_loop_context) {
|
|
88
|
+
Object.assign(loopContext, curr.__swc_loop_context);
|
|
89
|
+
}
|
|
90
|
+
curr = curr.parentElement || curr.getRootNode().host;
|
|
91
|
+
}
|
|
92
|
+
const $appHosts = $hosts.filter((h) => h.tagName.toLowerCase() === "swc-app" || h.getAttribute("is")?.startsWith("swc-app-"));
|
|
93
|
+
const $appHost = $appHosts.length > 0 ? $appHosts[$appHosts.length - 1] === el ? $appHosts.length > 1 ? $appHosts[$appHosts.length - 2] : null : $appHosts[$appHosts.length - 1] : null;
|
|
94
|
+
const $firstAppHost = $appHosts.length > 0 ? $appHosts[0] : null;
|
|
167
95
|
return {
|
|
168
|
-
$host
|
|
96
|
+
$host,
|
|
97
|
+
$parentHost,
|
|
169
98
|
$hosts,
|
|
170
99
|
$firstHost,
|
|
171
|
-
$lastHost,
|
|
172
|
-
$appHost
|
|
100
|
+
$lastHost: $parentHost,
|
|
101
|
+
$appHost,
|
|
173
102
|
$appHosts,
|
|
174
103
|
$firstAppHost,
|
|
175
|
-
$lastAppHost
|
|
104
|
+
$lastAppHost: $appHost,
|
|
105
|
+
...loopContext
|
|
176
106
|
};
|
|
177
|
-
}
|
|
178
|
-
}
|
|
107
|
+
};
|
|
108
|
+
})(SwcUtils || (SwcUtils = {}));
|
|
179
109
|
export {
|
|
180
110
|
SWC_NOT_FOUND,
|
|
181
111
|
SwcUtils
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/utils/Utils.ts"],
|
|
4
|
-
"sourcesContent": ["import {HostSet,
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": []
|
|
4
|
+
"sourcesContent": ["import { SwcAppInterface, HostSet, HelperSet, HelperHostSet } from '../types';\nimport { getElementConfig } from '../decorators/elementDefine';\n\nexport const SWC_NOT_FOUND = Symbol('SWC_NOT_FOUND');\n\nexport namespace SwcUtils {\n export const getHelperSet = (win: Window): HelperSet => {\n const doc: Document = win.document;\n return {\n $d: doc,\n $w: win,\n $q: (sel: string, root?: Element | Document | ShadowRoot) => (root ?? doc).querySelector(sel),\n $qa: (sel: string, root?: Element | Document | ShadowRoot) => Array.from((root ?? doc).querySelectorAll(sel)) as HTMLElement[],\n $qi: (id: string, root?: Document | ShadowRoot) => (root ?? doc).getElementById(id) as HTMLElement\n } as const;\n };\n\n export const getHelperAndHostSet = (win: Window, el: HTMLElement): HelperHostSet => {\n const helperSet = getHelperSet(win);\n const hostSet = getHostSet(el);\n return {\n ...helperSet,\n ...hostSet\n };\n };\n\n export const getValueByPath = (obj: any, path: string, rootName: string) => {\n if (!obj || !path) return SWC_NOT_FOUND;\n\n const parts = path.split('.');\n let current = obj;\n\n for (const part of parts) {\n if (current === null || current === undefined) return SWC_NOT_FOUND;\n current = current[part];\n }\n return current;\n };\n\n /**\n * Finds the nearest logical SWC host for an element.\n * Checks __swc_host property first, then climbs the DOM tree.\n */\n export const findNearestSwcHost = (el: HTMLElement | Node): HTMLElement | undefined => {\n if ((el as any).__swc_host) return (el as any).__swc_host;\n\n let current: any = el.parentElement || (el.getRootNode?.() as any)?.host;\n while (current && current !== document && current !== window) {\n if (current.__swc_host) return current.__swc_host;\n if (getElementConfig(current)) return current as HTMLElement;\n current = current.parentElement || (current.getRootNode?.() as any)?.host;\n }\n return undefined;\n };\n\n /**\n * Returns all SWC ancestors (excluding self) in [root, ..., parent] order.\n */\n export const findAllSwcHosts = (el: HTMLElement | Node): HTMLElement[] => {\n const hosts: HTMLElement[] = [];\n let current = findNearestSwcHost(el);\n while (current) {\n hosts.push(current);\n // To find the next ancestor, we must start searching from the PARENT of the found host\n current = findNearestSwcHost(current);\n }\n return hosts.reverse();\n };\n\n export const getHosts = (el: HTMLElement): HTMLElement[] => {\n const ancestors = findAllSwcHosts(el);\n if (getElementConfig(el)) return [...ancestors, el];\n return ancestors;\n };\n\n export const getHost = (el: HTMLElement): HTMLElement | undefined => {\n if (getElementConfig(el)) return el;\n return findNearestSwcHost(el);\n };\n\n export const getAppHosts = (el: HTMLElement): SwcAppInterface[] => {\n const hosts = getHosts(el);\n return hosts.filter(host => host.tagName.toLowerCase() === 'swc-app' || host.getAttribute('is')?.startsWith('swc-app-')) as SwcAppInterface[];\n };\n\n export const getAppHost = (el: HTMLElement): SwcAppInterface | undefined => {\n const appHosts = getAppHosts(el);\n const appHostsWithoutSelf = appHosts.filter(h => h !== el);\n return appHostsWithoutSelf.length > 0 ? appHostsWithoutSelf[appHostsWithoutSelf.length - 1] : undefined;\n };\n\n export const getHostSet = (el: HTMLElement): HostSet => {\n const isSwc = !!getElementConfig(el);\n const ancestors = findAllSwcHosts(el); // [root, ..., parent]\n\n let $host: HTMLElement;\n let $parentHost: HTMLElement | null;\n\n if (isSwc) {\n $host = el;\n $parentHost = ancestors.length > 0 ? ancestors[ancestors.length - 1] : null;\n } else {\n $host = ancestors.length > 0 ? ancestors[ancestors.length - 1] : el;\n $parentHost = ancestors.length > 1 ? ancestors[ancestors.length - 2] : null;\n }\n\n const $hosts = isSwc ? [...ancestors, el] : ancestors;\n const $firstHost = $hosts.length > 0 ? $hosts[0] : null;\n\n // Collect loop contexts\n const loopContext: Record<string, any> = {};\n let curr: any = el;\n while (curr && curr !== document.documentElement) {\n if (curr.__swc_loop_context) {\n Object.assign(loopContext, curr.__swc_loop_context);\n }\n curr = curr.parentElement || (curr.getRootNode() as any).host;\n }\n\n const $appHosts = $hosts.filter(h => h.tagName.toLowerCase() === 'swc-app' || h.getAttribute('is')?.startsWith('swc-app-')) as SwcAppInterface[];\n const $appHost = $appHosts.length > 0 ? ($appHosts[$appHosts.length - 1] === el ? ($appHosts.length > 1 ? $appHosts[$appHosts.length - 2] : null) : $appHosts[$appHosts.length - 1]) : null;\n const $firstAppHost = $appHosts.length > 0 ? $appHosts[0] : null;\n\n return {\n $host,\n $parentHost,\n $hosts,\n $firstHost,\n $lastHost: $parentHost,\n $appHost,\n $appHosts,\n $firstAppHost,\n $lastAppHost: $appHost,\n ...loopContext\n } as any;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