@dooboostore/simple-web-component 1.0.30 → 1.0.32
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 +220 -1
- package/dist/cjs/decorators/applyStyle.js +1 -1
- package/dist/cjs/decorators/applyStyle.js.map +2 -2
- package/dist/cjs/decorators/attribute.js +17 -1
- package/dist/cjs/decorators/attribute.js.map +2 -2
- package/dist/cjs/decorators/elementDefine.js +29 -12
- package/dist/cjs/decorators/elementDefine.js.map +3 -3
- package/dist/cjs/elements/SwcAppEngine.js +3 -3
- package/dist/cjs/elements/SwcAppEngine.js.map +2 -2
- package/dist/cjs/elements/SwcAppMixin.js +1 -8
- package/dist/cjs/elements/SwcAppMixin.js.map +2 -2
- package/dist/cjs/elements/SwcAsync.js +71 -78
- package/dist/cjs/elements/SwcAsync.js.map +2 -2
- package/dist/cjs/elements/SwcChoose.js +66 -81
- package/dist/cjs/elements/SwcChoose.js.map +2 -2
- package/dist/cjs/elements/SwcIf.js +52 -96
- package/dist/cjs/elements/SwcIf.js.map +2 -2
- package/dist/cjs/elements/SwcLoop.js +60 -103
- package/dist/cjs/elements/SwcLoop.js.map +2 -2
- package/dist/cjs/elements/SwcSubTemplates.js +0 -27
- package/dist/cjs/elements/SwcSubTemplates.js.map +2 -2
- package/dist/cjs/elements/register.js +314 -343
- package/dist/cjs/elements/register.js.map +2 -2
- package/dist/cjs/router/ElementRouter.js +1 -8
- package/dist/cjs/router/ElementRouter.js.map +2 -2
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/utils/Utils.js +31 -24
- package/dist/cjs/utils/Utils.js.map +2 -2
- package/dist/esm/decorators/applyStyle.js +1 -1
- package/dist/esm/decorators/applyStyle.js.map +2 -2
- package/dist/esm/decorators/attribute.js +18 -2
- package/dist/esm/decorators/attribute.js.map +2 -2
- package/dist/esm/decorators/elementDefine.js +27 -10
- package/dist/esm/decorators/elementDefine.js.map +3 -3
- package/dist/esm/elements/SwcAppEngine.js +3 -3
- package/dist/esm/elements/SwcAppEngine.js.map +2 -2
- package/dist/esm/elements/SwcAppMixin.js +1 -8
- package/dist/esm/elements/SwcAppMixin.js.map +2 -2
- package/dist/esm/elements/SwcAsync.js +72 -60
- package/dist/esm/elements/SwcAsync.js.map +2 -2
- package/dist/esm/elements/SwcChoose.js +67 -63
- package/dist/esm/elements/SwcChoose.js.map +2 -2
- package/dist/esm/elements/SwcIf.js +53 -78
- package/dist/esm/elements/SwcIf.js.map +2 -2
- package/dist/esm/elements/SwcLoop.js +61 -85
- package/dist/esm/elements/SwcLoop.js.map +2 -2
- package/dist/esm/elements/SwcSubTemplates.js +0 -8
- package/dist/esm/elements/SwcSubTemplates.js.map +2 -2
- package/dist/esm/elements/register.js +246 -275
- package/dist/esm/elements/register.js.map +2 -2
- package/dist/esm/router/ElementRouter.js +1 -8
- package/dist/esm/router/ElementRouter.js.map +2 -2
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils/Utils.js +31 -24
- package/dist/esm/utils/Utils.js.map +2 -2
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +2223 -2009
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/decorators/attribute.d.ts.map +1 -1
- package/dist/types/decorators/elementDefine.d.ts.map +1 -1
- package/dist/types/elements/SwcAppMixin.d.ts.map +1 -1
- package/dist/types/elements/SwcAsync.d.ts +1 -11
- package/dist/types/elements/SwcAsync.d.ts.map +1 -1
- package/dist/types/elements/SwcChoose.d.ts +1 -13
- package/dist/types/elements/SwcChoose.d.ts.map +1 -1
- package/dist/types/elements/SwcIf.d.ts +1 -13
- package/dist/types/elements/SwcIf.d.ts.map +1 -1
- package/dist/types/elements/SwcLoop.d.ts +1 -13
- package/dist/types/elements/SwcLoop.d.ts.map +1 -1
- package/dist/types/elements/SwcSubTemplates.d.ts +6 -6
- package/dist/types/elements/SwcSubTemplates.d.ts.map +1 -1
- package/dist/types/elements/register.d.ts.map +1 -1
- package/dist/types/router/ElementRouter.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 +10 -0
- package/dist/types/utils/Utils.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +2223 -2009
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +3 -3
- package/src/decorators/applyStyle.ts +1 -1
- package/src/decorators/attribute.ts +35 -30
- package/src/decorators/elementDefine.ts +32 -10
- package/src/elements/SwcAppEngine.ts +3 -3
- package/src/elements/SwcAppMixin.ts +6 -27
- package/src/elements/SwcAsync.ts +75 -57
- package/src/elements/SwcChoose.ts +69 -77
- package/src/elements/SwcIf.ts +50 -75
- package/src/elements/SwcLoop.ts +56 -82
- package/src/elements/SwcSubTemplates.ts +6 -6
- package/src/elements/register.ts +234 -285
- package/src/router/ElementRouter.ts +1 -12
- package/src/types.ts +9 -2
- package/src/utils/Utils.ts +48 -37
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/elements/SwcAppMixin.ts"],
|
|
4
|
-
"sourcesContent": ["import { SwcAppEngine, SwcAttributeConfigType, SwcConfigType } from './SwcAppEngine';\nimport { SwcAppInterface } from '../types';\nimport { SwcUtils } from '../utils/Utils';\nimport { FunctionUtils, Subscription } from '@dooboostore/core';\nimport { Router, RouterEventType } from '@dooboostore/core-web';\nimport { ON_CONNECTED_SWC_APP_METADATA_KEY, findAllLifecycleMetadata } from '../decorators/lifecycles';\nimport { getSubscribeSwcAppRouteChangeMetadata } from '../decorators/subscribeSwcAppRouteChange';\n\nexport function SwcAppMixin<T extends { new (...args: any[]): HTMLElement }>(Base: T) {\n //@ts-ignore\n return class extends Base implements SwcAppInterface {\n __swc_engine = new SwcAppEngine(this as any);\n _swc_connected_instance = new Set<any>();\n _routerSubscription?: Subscription;\n _lastRouterEvent?: RouterEventType;\n\n /*\n 사파리 is 일경우\n <script src=\"https://unpkg.com/@ungap/custom-elements\"></script>\n 이걸사용하는데 is 대응하는거다 그런데 이때 처리되는 순서가 크롬이나 표준에서는 부모부터 만들어지고 자식들이 만들어지는데\n 저 polyfill에서는 자식부터 만들어지고 부모가 만들어진다 is일때 아 .. 이문제때문에 자식이 _connected_safari 에 강제로 자기자식넣어준다\n */\n _connected_safari = [];\n get simpleApplication() {\n return this.__swc_engine.simpleApplication;\n }\n get router() {\n return this.__swc_engine.router;\n }\n\n
|
|
5
|
-
"mappings": "AAAA,SAAS,oBAA2D;AAEpE,SAAS,gBAAgB;AACzB,SAAS,qBAAmC;AAE5C,SAAS,mCAAmC,gCAAgC;AAC5E,SAAS,6CAA6C;AAEhD,SAAU,YAA6D,MAAO;AAElF,SAAO,cAAc,KAAI;IAAlB,cAAA;;AACL,WAAA,eAAe,IAAI,aAAa,IAAW;AAC3C,WAAA,0BAA0B,oBAAI,IAAG;AAUjC,WAAA,oBAAoB,CAAA;
|
|
4
|
+
"sourcesContent": ["import { SwcAppEngine, SwcAttributeConfigType, SwcConfigType } from './SwcAppEngine';\nimport { SwcAppInterface } from '../types';\nimport { SwcUtils } from '../utils/Utils';\nimport { FunctionUtils, Subscription } from '@dooboostore/core';\nimport { Router, RouterEventType } from '@dooboostore/core-web';\nimport { ON_CONNECTED_SWC_APP_METADATA_KEY, findAllLifecycleMetadata } from '../decorators/lifecycles';\nimport { getSubscribeSwcAppRouteChangeMetadata } from '../decorators/subscribeSwcAppRouteChange';\n\nexport function SwcAppMixin<T extends { new (...args: any[]): HTMLElement }>(Base: T) {\n //@ts-ignore\n return class extends Base implements SwcAppInterface {\n __swc_engine = new SwcAppEngine(this as any);\n _swc_connected_instance = new Set<any>();\n _routerSubscription?: Subscription;\n _lastRouterEvent?: RouterEventType;\n\n /*\n 사파리 is 일경우\n <script src=\"https://unpkg.com/@ungap/custom-elements\"></script>\n 이걸사용하는데 is 대응하는거다 그런데 이때 처리되는 순서가 크롬이나 표준에서는 부모부터 만들어지고 자식들이 만들어지는데\n 저 polyfill에서는 자식부터 만들어지고 부모가 만들어진다 is일때 아 .. 이문제때문에 자식이 _connected_safari 에 강제로 자기자식넣어준다\n */\n _connected_safari = [];\n get simpleApplication() {\n return this.__swc_engine.simpleApplication;\n }\n get router() {\n return this.__swc_engine.router;\n }\n\n _invokeRouteChangeSubscribers(instance: any, re: RouterEventType) {\n const routeChangeSubscribers = getSubscribeSwcAppRouteChangeMetadata(instance);\n if (routeChangeSubscribers && Array.isArray(routeChangeSubscribers)) {\n routeChangeSubscribers.forEach((metadata: any) => {\n const methodName = metadata.propertyKey || metadata;\n const pathPattern = metadata.pathPattern;\n const filter = metadata.filter;\n\n // Path pattern matching (support both string and array)\n let pathMatched = false;\n let pathData: any = null;\n\n if (!pathPattern) {\n // pathPattern이 없으면 모든 경로 매칭 (와일드카드)\n pathMatched = true;\n pathData = {};\n } else if (Array.isArray(pathPattern)) {\n // 배열: 하나라도 매칭되면 OK\n for (const pattern of pathPattern) {\n const data = SwcUtils.parsePathPattern(pattern, re.path || '/');\n if (data !== null) {\n pathMatched = true;\n pathData = data;\n break;\n }\n }\n } else {\n // 문자열\n pathData = SwcUtils.parsePathPattern(pathPattern, re.path || '/');\n pathMatched = pathData !== null;\n }\n\n // Filter validation\n const filterPassed = !filter || filter(this.router!);\n\n // Invoke method if conditions pass\n if (pathMatched && filterPassed) {\n instance[methodName]?.({...re, pathData: pathData});\n }\n });\n }\n }\n\n _connected(instance: any) {\n // console.log('appmixin--> connected', this, instance);\n if (instance) {\n this._swc_connected_instance.add(instance);\n if (this.simpleApplication) {\n this._invokeOnConnectedSwcAppStarted(instance);\n // Notify current route subscribers immediately after connection\n if (this.router && this._lastRouterEvent) {\n this._invokeRouteChangeSubscribers(instance, this._lastRouterEvent);\n }\n }\n }\n }\n\n _disconnected(instance: any) {\n if (instance) {\n this._swc_connected_instance.delete(instance);\n }\n }\n\n _handleRouteChange(route: RouterEventType) {\n if (route.triggerPoint === 'end') {\n // Iterate through all connected component instances\n this._swc_connected_instance.forEach((instance: any) => {\n this._invokeRouteChangeSubscribers(instance, route);\n });\n }\n\n // Save last router event\n this._lastRouterEvent = route;\n }\n\n async connect(config?: SwcAttributeConfigType) {\n const swcConfig = {\n routeType: 'element',\n window: config.window,\n ...config\n } as SwcConfigType;\n\n const mode = config?.connectMode || 'direct';\n\n if (mode === 'direct') {\n await this.__swc_engine.connect(swcConfig);\n this.setAttribute('swc-connect-mode', 'direct');\n } else if (mode === 'swap' && !this.parentNode) {\n await this.__swc_engine.connect(swcConfig);\n this.setAttribute('swc-connect-mode', 'direct');\n\n const clonedApp = this.cloneNode(true) as any;\n clonedApp.style.display = 'none';\n this.parentNode.insertBefore(clonedApp, this.nextSibling);\n\n try {\n await clonedApp.connect({ ...(config || {}), connectMode: 'direct' });\n if (this.parentNode) {\n this.parentNode.removeChild(this);\n }\n clonedApp.setAttribute('swc-connect-mode', 'swap');\n clonedApp.style.display = '';\n } catch (e) {\n if (clonedApp.parentNode) {\n clonedApp.parentNode.removeChild(clonedApp);\n }\n throw e;\n }\n }\n\n // 사파리일떄 예외이다 is 일때 polyfill되는데 이떄 부모부터 만들어지는게 아니라 자식부터 만들어진다 그래서 부모가 만들어질때 자식들이 이미 만들어져있어서 부모가 자식들을 등록해주는 형태로 강제로 등록해준다\n this._connected_safari.forEach((instance: any) => {\n this._swc_connected_instance.add(instance);\n });\n // Invoke @onConnectedSwcApp lifecycle methods on all connected component instances\n // const hostSet = SwcUtils.getHostSet(this as any);\n this._swc_connected_instance.forEach((instance: any) => {\n this._invokeOnConnectedSwcAppStarted(instance);\n });\n\n\n // Subscribe to router changes after connect\n if (!this._routerSubscription && this.router) {\n this._routerSubscription = this.router.observable.subscribe((route: RouterEventType) => {\n //@ts-ignore\n // console.log('Route changed:', route, this._swcId);\n this._handleRouteChange(route);\n });\n // Navigate to initial path if specified\n const config = this.__swc_engine.config;\n // if (config?.path) {\n // this.router.go(config.path);\n // }\n }\n }\n\n _invokeOnConnectedSwcAppStarted(instance: any) {\n const startedMethods = findAllLifecycleMetadata(instance, ON_CONNECTED_SWC_APP_METADATA_KEY);\n if (startedMethods) {\n for (const m of startedMethods) {\n instance._invokeLifecycleMethod(m);\n }\n }\n }\n\n connectedCallback() {\n // @ts-ignore\n if (super.connectedCallback) super.connectedCallback();\n\n const configStr = this.getAttribute('swc-get-application-config');\n const win = this.ownerDocument?.defaultView || window;\n if (configStr && win) {\n try {\n // console.log('vvvvvvvvvvvvvvvv->>>>', SwcUtils.findNearestSwcHost(this.host), SwcUtils.getHostSet(this.host))\n const userConfig = FunctionUtils.executeReturn({\n script: configStr,\n context: this,\n args: SwcUtils.getHelperAndHostSet(win, this)\n });\n this.connect(userConfig);\n } catch (e) {\n console.error('[SWC-APP-ENGINE] Script execution failed:', e);\n }\n }\n\n this.__swc_engine?.config?.onConnected?.(this);\n }\n\n disconnectedCallback() {\n // @ts-ignore\n if (super.disconnectedCallback) super.disconnectedCallback();\n this._routerSubscription?.unsubscribe();\n this._routerSubscription = undefined;\n this._lastRouterEvent = undefined;\n this.__swc_engine.disconnect();\n this.__swc_engine?.config?.onDisconnected?.(this);\n }\n\n async routing(path: string) {\n await this.router?.go(path);\n }\n\n back(): void {\n this.router?.back();\n }\n\n forward(): void {\n this.router?.forward();\n }\n\n reload(): void {\n this.router?.reload();\n }\n };\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,oBAA2D;AAEpE,SAAS,gBAAgB;AACzB,SAAS,qBAAmC;AAE5C,SAAS,mCAAmC,gCAAgC;AAC5E,SAAS,6CAA6C;AAEhD,SAAU,YAA6D,MAAO;AAElF,SAAO,cAAc,KAAI;IAAlB,cAAA;;AACL,WAAA,eAAe,IAAI,aAAa,IAAW;AAC3C,WAAA,0BAA0B,oBAAI,IAAG;AAUjC,WAAA,oBAAoB,CAAA;IAyMtB;IAxME,IAAI,oBAAiB;AACnB,aAAO,KAAK,aAAa;IAC3B;IACA,IAAI,SAAM;AACR,aAAO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BAAW,KAAK,gBAAgB;AAC9B,mBAAS,uBAAuB,CAAC;QACnC;MACF;IACF;IAEA,oBAAiB;AAEf,UAAI,MAAM;AAAmB,cAAM,kBAAiB;AAEpD,YAAM,YAAY,KAAK,aAAa,4BAA4B;AAChE,YAAM,MAAM,KAAK,eAAe,eAAe;AAC/C,UAAI,aAAa,KAAK;AACpB,YAAI;AAEF,gBAAM,aAAa,cAAc,cAAc;YAC7C,QAAQ;YACR,SAAS;YACT,MAAM,SAAS,oBAAoB,KAAK,IAAI;WAC7C;AACD,eAAK,QAAQ,UAAU;QACzB,SAAS,GAAG;AACV,kBAAQ,MAAM,6CAA6C,CAAC;QAC9D;MACF;AAEA,WAAK,cAAc,QAAQ,cAAc,IAAI;IAC/C;IAEA,uBAAoB;AAElB,UAAI,MAAM;AAAsB,cAAM,qBAAoB;AAC1D,WAAK,qBAAqB,YAAW;AACrC,WAAK,sBAAsB;AAC3B,WAAK,mBAAmB;AACxB,WAAK,aAAa,WAAU;AAC5B,WAAK,cAAc,QAAQ,iBAAiB,IAAI;IAClD;IAEA,MAAM,QAAQ,MAAY;AACxB,YAAM,KAAK,QAAQ,GAAG,IAAI;IAC5B;IAEA,OAAI;AACF,WAAK,QAAQ,KAAI;IACnB;IAEA,UAAO;AACL,WAAK,QAAQ,QAAO;IACtB;IAEA,SAAM;AACJ,WAAK,QAAQ,OAAM;IACrB;;AAEJ;",
|
|
6
6
|
"names": ["config"]
|
|
7
7
|
}
|
|
@@ -9,99 +9,111 @@ var __metadata = function(k, v) {
|
|
|
9
9
|
};
|
|
10
10
|
import { changedAttributeHost } from "../decorators/changedAttributeHost.js";
|
|
11
11
|
import { SwcUtils } from "../utils/Utils.js";
|
|
12
|
-
import { FunctionUtils } from "@dooboostore/core";
|
|
12
|
+
import { FunctionUtils, ActionExpression } from "@dooboostore/core";
|
|
13
|
+
import { ConvertUtils } from "@dooboostore/core-web";
|
|
14
|
+
import { attributeHost } from "../decorators/index.js";
|
|
13
15
|
class SwcAsync extends HTMLTemplateElement {
|
|
14
16
|
constructor() {
|
|
15
17
|
super(...arguments);
|
|
16
18
|
this._nodes = [];
|
|
17
|
-
this._value = null;
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (!portalScript)
|
|
22
|
-
return this.parentElement;
|
|
23
|
-
const win = this.ownerDocument?.defaultView || window;
|
|
24
|
-
const res = FunctionUtils.executeReturn({
|
|
25
|
-
script: portalScript,
|
|
26
|
-
context: this,
|
|
27
|
-
args: SwcUtils.getHelperAndHostSet(win, this)
|
|
28
|
-
});
|
|
29
|
-
if (res instanceof HTMLElement)
|
|
30
|
-
return res;
|
|
31
|
-
if (typeof res === "string")
|
|
32
|
-
return win.document.querySelector(res);
|
|
33
|
-
return this.parentElement;
|
|
20
|
+
get value() {
|
|
21
|
+
return this._value;
|
|
34
22
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
23
|
+
set value(nv) {
|
|
24
|
+
this.executeAsync(nv);
|
|
25
|
+
}
|
|
26
|
+
setValue(valueAttr) {
|
|
27
|
+
this.executeAsync(this._value);
|
|
40
28
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
29
|
+
setReplaceWrap() {
|
|
30
|
+
this.executeAsync(this._value);
|
|
31
|
+
}
|
|
32
|
+
executeAsync(result = this._value) {
|
|
33
|
+
if (result === void 0 || result === null) {
|
|
34
|
+
this.refresh("default");
|
|
45
35
|
return;
|
|
46
36
|
}
|
|
47
|
-
const win = this.ownerDocument?.defaultView || window;
|
|
48
|
-
const result = FunctionUtils.executeReturn({ script, context: this, args: SwcUtils.getHelperAndHostSet(win, this) });
|
|
49
37
|
if (result instanceof Promise) {
|
|
50
|
-
this.
|
|
38
|
+
this.refresh("loading");
|
|
51
39
|
result.then((v) => {
|
|
52
|
-
this.
|
|
53
|
-
this.
|
|
54
|
-
}).catch((e) =>
|
|
40
|
+
this.resultValue = v;
|
|
41
|
+
this.refresh("success");
|
|
42
|
+
}).catch((e) => {
|
|
43
|
+
console.error("[SWC-ASYNC] Promise rejected:", e);
|
|
44
|
+
this.resultValue = e;
|
|
45
|
+
this.refresh("error");
|
|
46
|
+
});
|
|
55
47
|
} else {
|
|
56
|
-
this.
|
|
57
|
-
this.
|
|
48
|
+
this.resultValue = result;
|
|
49
|
+
this.refresh("success");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
replaceExpressions(html, groupArgs, context, wrap) {
|
|
53
|
+
const config = wrap ? { wrapExpression: wrap } : void 0;
|
|
54
|
+
const ae = new ActionExpression(html, config);
|
|
55
|
+
const filterOptions = wrap ? { type: "replace", wrap } : "replace";
|
|
56
|
+
const win = this.ownerDocument?.defaultView || window;
|
|
57
|
+
for (const expr of ae.getExpressions(filterOptions)) {
|
|
58
|
+
try {
|
|
59
|
+
const value = FunctionUtils.executeReturn({
|
|
60
|
+
script: ConvertUtils.decodeHtmlEntity(expr.script, win.document),
|
|
61
|
+
context,
|
|
62
|
+
args: groupArgs
|
|
63
|
+
});
|
|
64
|
+
ae.replace(expr, String(value));
|
|
65
|
+
} catch (e) {
|
|
66
|
+
console.error(`[SWC] Failed to execute ${expr.original}:`, e);
|
|
67
|
+
}
|
|
58
68
|
}
|
|
69
|
+
return ae.getUnprocessedTemplate();
|
|
59
70
|
}
|
|
60
|
-
|
|
71
|
+
refresh(state = "default") {
|
|
72
|
+
console.log("rrrrrrrrrrrrrrrrr", state);
|
|
61
73
|
this.cleanup();
|
|
62
|
-
const portal = this.
|
|
74
|
+
const portal = this.parentElement;
|
|
63
75
|
if (!portal)
|
|
64
76
|
return;
|
|
65
77
|
const win = this.ownerDocument?.defaultView || window;
|
|
66
78
|
const helperSet = SwcUtils.getHelperAndHostSet(win, this);
|
|
67
79
|
const t = this.content.querySelector(`template[is="swc-${state}"]`);
|
|
68
80
|
if (t) {
|
|
69
|
-
|
|
70
|
-
this.
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
});
|
|
78
|
-
this._executeCloneCallback("on-clone-nodes", groupArgs);
|
|
79
|
-
if (portal === this.parentElement) {
|
|
80
|
-
portal.insertBefore(clone, this.nextSibling);
|
|
81
|
-
} else {
|
|
82
|
-
portal.appendChild(clone);
|
|
83
|
-
}
|
|
81
|
+
let htmlString = t.innerHTML;
|
|
82
|
+
const groupArgs = { ...helperSet, $value: this._value, $state: state };
|
|
83
|
+
htmlString = this.replaceExpressions(htmlString, groupArgs, this, this._replaceWrap);
|
|
84
|
+
const temp = this.ownerDocument?.createElement("template") || document.createElement("template");
|
|
85
|
+
temp.innerHTML = htmlString;
|
|
86
|
+
const content = temp.content;
|
|
87
|
+
this._nodes = Array.from(content.childNodes);
|
|
88
|
+
portal.insertBefore(content, this.nextSibling);
|
|
84
89
|
}
|
|
85
90
|
}
|
|
86
91
|
cleanup() {
|
|
87
92
|
this._nodes.forEach((n) => n.parentElement?.removeChild(n));
|
|
88
93
|
this._nodes = [];
|
|
89
94
|
}
|
|
90
|
-
connectedCallback() {
|
|
91
|
-
console.log("[SwcAsync] connectedCallback called");
|
|
92
|
-
this.refresh();
|
|
93
|
-
}
|
|
94
95
|
disconnectedCallback() {
|
|
95
96
|
this.cleanup();
|
|
96
97
|
}
|
|
97
98
|
}
|
|
98
99
|
__decorate([
|
|
99
|
-
|
|
100
|
+
attributeHost("value"),
|
|
101
|
+
__metadata("design:type", Object)
|
|
102
|
+
], SwcAsync.prototype, "_value", void 0);
|
|
103
|
+
__decorate([
|
|
104
|
+
attributeHost("replace-wrap"),
|
|
105
|
+
__metadata("design:type", String)
|
|
106
|
+
], SwcAsync.prototype, "_replaceWrap", void 0);
|
|
107
|
+
__decorate([
|
|
108
|
+
changedAttributeHost("value"),
|
|
109
|
+
__metadata("design:type", Function),
|
|
110
|
+
__metadata("design:paramtypes", [String]),
|
|
111
|
+
__metadata("design:returntype", void 0)
|
|
112
|
+
], SwcAsync.prototype, "setValue", null);
|
|
113
|
+
__decorate([
|
|
114
|
+
changedAttributeHost("replace-wrap"),
|
|
100
115
|
__metadata("design:type", Function),
|
|
101
116
|
__metadata("design:paramtypes", []),
|
|
102
117
|
__metadata("design:returntype", void 0)
|
|
103
|
-
], SwcAsync.prototype, "
|
|
104
|
-
export {
|
|
105
|
-
SwcAsync
|
|
106
|
-
};
|
|
118
|
+
], SwcAsync.prototype, "setReplaceWrap", null);
|
|
107
119
|
//# sourceMappingURL=SwcAsync.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/elements/SwcAsync.ts"],
|
|
4
|
-
"sourcesContent": ["import { changedAttributeHost } from '../decorators/changedAttributeHost';\nimport { SwcUtils } from '../utils/Utils';\nimport { FunctionUtils } from '@dooboostore/core';\
|
|
5
|
-
"mappings": ";;;;;;;;;AAAA,SAAS,4BAA4B;AACrC,SAAS,gBAAgB;AACzB,SAAS,qBAAqB;
|
|
4
|
+
"sourcesContent": ["import { changedAttributeHost } from '../decorators/changedAttributeHost';\nimport { SwcUtils } from '../utils/Utils';\nimport { FunctionUtils, ActionExpression } from '@dooboostore/core';\nimport { ConvertUtils } from '@dooboostore/core-web';\nimport { attributeHost } from '../decorators';\n\nclass SwcAsync extends HTMLTemplateElement {\n @attributeHost('value')\n _value: any;\n\n @attributeHost('replace-wrap')\n _replaceWrap: string | null;\n\n resultValue?: any;\n\n get value(): boolean {\n return this._value;\n }\n\n set value(nv: any) {\n this.executeAsync(nv);\n }\n\n private _nodes: Node[] = [];\n\n @changedAttributeHost('value')\n private setValue(valueAttr?: string | null) {\n this.executeAsync(this._value);\n }\n\n @changedAttributeHost('replace-wrap')\n private setReplaceWrap() {\n this.executeAsync(this._value);\n }\n\n private executeAsync(result: any = this._value) {\n if (result === undefined || result === null) {\n this.refresh('default');\n return;\n }\n\n if (result instanceof Promise) {\n this.refresh('loading');\n result\n .then(v => {\n this.resultValue = v;\n this.refresh('success');\n })\n .catch(e => {\n console.error('[SWC-ASYNC] Promise rejected:', e);\n this.resultValue = e;\n this.refresh('error');\n });\n } else {\n this.resultValue = result;\n this.refresh('success');\n }\n }\n\n private replaceExpressions(html: string, groupArgs: any, context: any, wrap?: string | null): string {\n const config = wrap ? { wrapExpression: wrap } : undefined;\n const ae = new ActionExpression(html, config);\n const filterOptions = wrap ? { type: 'replace' as const, wrap } : 'replace';\n const win = this.ownerDocument?.defaultView || window;\n\n // @ts-ignore\n for (const expr of ae.getExpressions(filterOptions)) {\n try {\n const value = FunctionUtils.executeReturn({\n script: ConvertUtils.decodeHtmlEntity(expr.script, win.document),\n context,\n args: groupArgs\n });\n ae.replace(expr, String(value));\n } catch (e) {\n console.error(`[SWC] Failed to execute ${expr.original}:`, e);\n }\n }\n return ae.getUnprocessedTemplate();\n }\n\n refresh(state: string = 'default') {\n console.log('rrrrrrrrrrrrrrrrr', state);\n this.cleanup();\n const portal = this.parentElement;\n if (!portal) return;\n\n const win = this.ownerDocument?.defaultView || window;\n const helperSet = SwcUtils.getHelperAndHostSet(win, this);\n\n const t = this.content.querySelector(`template[is=\"swc-${state}\"]`) as HTMLTemplateElement;\n if (t) {\n let htmlString = t.innerHTML;\n const groupArgs = { ...helperSet, $value: this._value, $state: state };\n\n htmlString = this.replaceExpressions(htmlString, groupArgs, this, this._replaceWrap);\n\n const temp = this.ownerDocument?.createElement('template') || document.createElement('template');\n temp.innerHTML = htmlString;\n const content = temp.content;\n\n this._nodes = Array.from(content.childNodes);\n portal.insertBefore(content, this.nextSibling);\n }\n }\n\n private cleanup() {\n this._nodes.forEach(n => n.parentElement?.removeChild(n));\n this._nodes = [];\n }\n\n disconnectedCallback() {\n this.cleanup();\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;AAAA,SAAS,4BAA4B;AACrC,SAAS,gBAAgB;AACzB,SAAS,eAAe,wBAAwB;AAChD,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;AAE9B,M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EAEA,QAAQ,QAAgB,WAAS;AAC/B,YAAQ,IAAI,qBAAqB,KAAK;AACtC,SAAK,QAAO;AACZ,UAAM,SAAS,KAAK;AACpB,QAAI,CAAC;AAAQ;AAEb,UAAM,MAAM,KAAK,eAAe,eAAe;AAC/C,UAAM,YAAY,SAAS,oBAAoB,KAAK,IAAI;AAExD,UAAM,IAAI,KAAK,QAAQ,cAAc,oBAAoB,KAAK,IAAI;AAClE,QAAI,GAAG;AACL,UAAI,aAAa,EAAE;AACnB,YAAM,YAAY,EAAE,GAAG,WAAW,QAAQ,KAAK,QAAQ,QAAQ,MAAK;AAEpE,mBAAa,KAAK,mBAAmB,YAAY,WAAW,MAAM,KAAK,YAAY;AAEnF,YAAM,OAAO,KAAK,eAAe,cAAc,UAAU,KAAK,SAAS,cAAc,UAAU;AAC/F,WAAK,YAAY;AACjB,YAAM,UAAU,KAAK;AAErB,WAAK,SAAS,MAAM,KAAK,QAAQ,UAAU;AAC3C,aAAO,aAAa,SAAS,KAAK,WAAW;IAC/C;EACF;EAEQ,UAAO;AACb,SAAK,OAAO,QAAQ,OAAK,EAAE,eAAe,YAAY,CAAC,CAAC;AACxD,SAAK,SAAS,CAAA;EAChB;EAEA,uBAAoB;AAClB,SAAK,QAAO;EACd;;AAzGA,WAAA;EADC,cAAc,OAAO;;;AAItB,WAAA;EADC,cAAc,cAAc;;;AAgBrB,WAAA;EADP,qBAAqB,OAAO;;;;;AAMrB,WAAA;EADP,qBAAqB,cAAc;;;;;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -9,61 +9,71 @@ var __metadata = function(k, v) {
|
|
|
9
9
|
};
|
|
10
10
|
import { changedAttributeHost } from "../decorators/changedAttributeHost.js";
|
|
11
11
|
import { SwcUtils } from "../utils/Utils.js";
|
|
12
|
-
import { FunctionUtils } from "@dooboostore/core";
|
|
12
|
+
import { FunctionUtils, ActionExpression } from "@dooboostore/core";
|
|
13
|
+
import { ConvertUtils } from "@dooboostore/core-web";
|
|
14
|
+
import { attributeHost } from "../decorators/index.js";
|
|
13
15
|
class SwcChoose extends HTMLTemplateElement {
|
|
14
16
|
constructor() {
|
|
15
17
|
super(...arguments);
|
|
16
18
|
this._nodes = [];
|
|
17
|
-
this._value = null;
|
|
18
19
|
this._previousTemplate = null;
|
|
19
20
|
}
|
|
20
21
|
get value() {
|
|
21
22
|
return this._value;
|
|
22
23
|
}
|
|
23
24
|
set value(nv) {
|
|
24
|
-
this.
|
|
25
|
-
this.render();
|
|
25
|
+
this.refresh(nv);
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
if (!script)
|
|
30
|
-
return;
|
|
31
|
-
FunctionUtils.execute({ script, context: this, args });
|
|
27
|
+
setValue() {
|
|
28
|
+
this.refresh();
|
|
32
29
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
30
|
+
setReplaceWrap(replaceWrapAttr) {
|
|
31
|
+
this.refresh();
|
|
32
|
+
}
|
|
33
|
+
replaceExpressions(html, groupArgs, context, wrap) {
|
|
34
|
+
const config = wrap ? { wrapExpression: wrap } : void 0;
|
|
35
|
+
const ae = new ActionExpression(html, config);
|
|
36
|
+
const filterOptions = wrap ? { type: "replace", wrap } : "replace";
|
|
37
|
+
const win = this.ownerDocument?.defaultView || window;
|
|
38
|
+
for (const expr of ae.getExpressions(filterOptions)) {
|
|
39
|
+
try {
|
|
40
|
+
const value = FunctionUtils.executeReturn({
|
|
41
|
+
script: ConvertUtils.decodeHtmlEntity(expr.script, win.document),
|
|
42
|
+
context,
|
|
43
|
+
args: groupArgs
|
|
44
|
+
});
|
|
45
|
+
ae.replace(expr, String(value));
|
|
46
|
+
} catch (e) {
|
|
47
|
+
console.error(`[SWC] Failed to execute ${expr.original}:`, e);
|
|
48
|
+
}
|
|
46
49
|
}
|
|
50
|
+
return ae.getUnprocessedTemplate();
|
|
47
51
|
}
|
|
48
|
-
|
|
52
|
+
refresh(value = this._value) {
|
|
53
|
+
const portal = this.parentElement;
|
|
54
|
+
if (!portal)
|
|
55
|
+
return;
|
|
49
56
|
const win = this.ownerDocument?.defaultView || window;
|
|
50
57
|
const helperSet = SwcUtils.getHelperAndHostSet(win, this);
|
|
58
|
+
const groupArgs = { ...helperSet, $value: value };
|
|
51
59
|
const templates = Array.from(this.content.querySelectorAll("template"));
|
|
52
60
|
let selected = null;
|
|
53
61
|
for (const t of templates) {
|
|
54
62
|
if (t.getAttribute("is") === "swc-when") {
|
|
63
|
+
const attrVal = t.getAttribute("value") || "";
|
|
55
64
|
let matches = false;
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
65
|
+
const ae = new ActionExpression(attrVal);
|
|
66
|
+
const expr = ae.getFirstExpression("replace");
|
|
67
|
+
if (expr) {
|
|
68
|
+
const decodedScript = ConvertUtils.decodeHtmlEntity(expr.script, win.document);
|
|
59
69
|
const result = FunctionUtils.executeReturn({
|
|
60
|
-
script,
|
|
70
|
+
script: decodedScript,
|
|
61
71
|
context: t,
|
|
62
|
-
args:
|
|
72
|
+
args: groupArgs
|
|
63
73
|
});
|
|
64
|
-
matches = result
|
|
74
|
+
matches = !!result;
|
|
65
75
|
} else {
|
|
66
|
-
matches = String(
|
|
76
|
+
matches = String(attrVal) === String(value);
|
|
67
77
|
}
|
|
68
78
|
if (matches) {
|
|
69
79
|
selected = t;
|
|
@@ -72,57 +82,51 @@ class SwcChoose extends HTMLTemplateElement {
|
|
|
72
82
|
}
|
|
73
83
|
}
|
|
74
84
|
const target = selected || this.content.querySelector('template[is="swc-otherwise"]');
|
|
75
|
-
const
|
|
76
|
-
const
|
|
77
|
-
|
|
85
|
+
const skipValue = target?.getAttribute?.("skip-if-same");
|
|
86
|
+
const skipValue2 = this._previousTemplate?.getAttribute?.("skip-if-same");
|
|
87
|
+
const hasSkipIfSame = target?.hasAttribute?.("skip-if-same");
|
|
88
|
+
const isSame = this._previousTemplate === target;
|
|
89
|
+
if (hasSkipIfSame && isSame) {
|
|
78
90
|
return;
|
|
79
91
|
}
|
|
80
92
|
this.cleanup();
|
|
81
93
|
this._previousTemplate = target;
|
|
82
94
|
if (target) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
Array.from(n.attributes).forEach((attr) => {
|
|
91
|
-
const value = attr.value || "";
|
|
92
|
-
if (value.startsWith("{{") && value.endsWith("}}")) {
|
|
93
|
-
const script = value.slice(2, -2).trim();
|
|
94
|
-
const result = FunctionUtils.executeReturn({
|
|
95
|
-
script,
|
|
96
|
-
context: n,
|
|
97
|
-
args: { ...groupArgs, $value: this._value }
|
|
98
|
-
});
|
|
99
|
-
n.setAttribute(attr.name, String(result));
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
this._executeCloneCallback("on-clone-nodes", groupArgs);
|
|
105
|
-
this.parentElement?.insertBefore(clone, this.nextSibling);
|
|
95
|
+
let htmlString = target.innerHTML;
|
|
96
|
+
htmlString = this.replaceExpressions(htmlString, groupArgs, this, this._replaceWrap);
|
|
97
|
+
const result = this.ownerDocument?.createElement("template") || document.createElement("template");
|
|
98
|
+
result.innerHTML = htmlString;
|
|
99
|
+
const processedFragment = result.content;
|
|
100
|
+
this._nodes = Array.from(processedFragment.childNodes);
|
|
101
|
+
portal.insertBefore(processedFragment, this.nextSibling);
|
|
106
102
|
}
|
|
107
103
|
}
|
|
108
104
|
cleanup() {
|
|
109
105
|
this._nodes.forEach((n) => n.parentElement?.removeChild(n));
|
|
110
106
|
this._nodes = [];
|
|
111
107
|
}
|
|
112
|
-
connectedCallback() {
|
|
113
|
-
this.refresh();
|
|
114
|
-
}
|
|
115
108
|
disconnectedCallback() {
|
|
116
109
|
this.cleanup();
|
|
117
110
|
}
|
|
118
111
|
}
|
|
112
|
+
__decorate([
|
|
113
|
+
attributeHost("value"),
|
|
114
|
+
__metadata("design:type", Object)
|
|
115
|
+
], SwcChoose.prototype, "_value", void 0);
|
|
116
|
+
__decorate([
|
|
117
|
+
attributeHost("replace-wrap"),
|
|
118
|
+
__metadata("design:type", String)
|
|
119
|
+
], SwcChoose.prototype, "_replaceWrap", void 0);
|
|
119
120
|
__decorate([
|
|
120
121
|
changedAttributeHost("value"),
|
|
121
122
|
__metadata("design:type", Function),
|
|
123
|
+
__metadata("design:paramtypes", []),
|
|
124
|
+
__metadata("design:returntype", void 0)
|
|
125
|
+
], SwcChoose.prototype, "setValue", null);
|
|
126
|
+
__decorate([
|
|
127
|
+
changedAttributeHost("replace-wrap"),
|
|
128
|
+
__metadata("design:type", Function),
|
|
122
129
|
__metadata("design:paramtypes", [String]),
|
|
123
130
|
__metadata("design:returntype", void 0)
|
|
124
|
-
], SwcChoose.prototype, "
|
|
125
|
-
export {
|
|
126
|
-
SwcChoose
|
|
127
|
-
};
|
|
131
|
+
], SwcChoose.prototype, "setReplaceWrap", null);
|
|
128
132
|
//# sourceMappingURL=SwcChoose.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/elements/SwcChoose.ts"],
|
|
4
|
-
"sourcesContent": ["import { changedAttributeHost } from '../decorators/changedAttributeHost';\nimport { SwcUtils } from '../utils/Utils';\nimport { FunctionUtils } from '@dooboostore/core';\n\
|
|
5
|
-
"mappings": ";;;;;;;;;AAAA,SAAS,4BAA4B;AACrC,SAAS,gBAAgB;AACzB,SAAS,qBAAqB;
|
|
4
|
+
"sourcesContent": ["import { changedAttributeHost } from '../decorators/changedAttributeHost';\nimport { SwcUtils } from '../utils/Utils';\nimport { FunctionUtils, ActionExpression } from '@dooboostore/core';\nimport { ConvertUtils } from '@dooboostore/core-web';\nimport { SwcChooseInterface } from '../types';\nimport { attributeHost } from '../decorators';\n\nclass SwcChoose extends HTMLTemplateElement implements SwcChooseInterface {\n @attributeHost('value')\n _value: any;\n\n @attributeHost('replace-wrap')\n _replaceWrap: string | null;\n\n private _nodes: Node[] = [];\n private _previousTemplate: HTMLTemplateElement | null = null;\n\n get value(): any {\n return this._value;\n }\n\n set value(nv: any) {\n this.refresh(nv);\n }\n\n @changedAttributeHost('value')\n private setValue() {\n this.refresh();\n }\n\n @changedAttributeHost('replace-wrap')\n private setReplaceWrap(replaceWrapAttr?: string | null) {\n this.refresh();\n }\n\n private replaceExpressions(html: string, groupArgs: any, context: any, wrap?: string | null): string {\n const config = wrap ? { wrapExpression: wrap } : undefined;\n const ae = new ActionExpression(html, config);\n const filterOptions = wrap ? { type: 'replace' as const, wrap } : 'replace';\n const win = this.ownerDocument?.defaultView || window;\n\n // @ts-ignore\n for (const expr of ae.getExpressions(filterOptions)) {\n try {\n const value = FunctionUtils.executeReturn({\n script: ConvertUtils.decodeHtmlEntity(expr.script, win.document),\n context,\n args: groupArgs\n });\n ae.replace(expr, String(value));\n } catch (e) {\n console.error(`[SWC] Failed to execute ${expr.original}:`, e);\n }\n }\n return ae.getUnprocessedTemplate();\n }\n\n refresh(value = this._value) {\n const portal = this.parentElement;\n if (!portal) return;\n\n const win = this.ownerDocument?.defaultView || window;\n const helperSet = SwcUtils.getHelperAndHostSet(win, this);\n const groupArgs = { ...helperSet, $value: value };\n\n const templates = Array.from(this.content.querySelectorAll('template'));\n let selected: HTMLTemplateElement | null = null;\n\n for (const t of templates) {\n if (t.getAttribute('is') === 'swc-when') {\n const attrVal = t.getAttribute('value') || '';\n let matches = false;\n\n // Use ActionExpression to parse and extract script from value attribute\n const ae = new ActionExpression(attrVal);\n const expr = ae.getFirstExpression('replace');\n\n if (expr) {\n const decodedScript = ConvertUtils.decodeHtmlEntity(expr.script, win.document);\n const result = FunctionUtils.executeReturn({\n script: decodedScript,\n context: t,\n args: groupArgs\n });\n matches = !!result;\n } else {\n matches = String(attrVal) === String(value);\n }\n\n if (matches) {\n selected = t;\n break;\n }\n }\n }\n\n const target = selected || (this.content.querySelector('template[is=\"swc-otherwise\"]') as HTMLTemplateElement);\n\n const skipValue = target?.getAttribute?.('skip-if-same');\n const skipValue2 = this._previousTemplate?.getAttribute?.('skip-if-same');\n const hasSkipIfSame = target?.hasAttribute?.('skip-if-same');\n const isSame = this._previousTemplate === target;\n // console.log('---rrrr---', this._previousTemplate, target, hasSkipIfSame, isSame, skipValue, skipValue2);\n if (hasSkipIfSame && isSame) {\n return;\n }\n\n this.cleanup();\n this._previousTemplate = target;\n\n if (target) {\n let htmlString = target.innerHTML;\n htmlString = this.replaceExpressions(htmlString, groupArgs, this, this._replaceWrap);\n\n const result = this.ownerDocument?.createElement('template') || document.createElement('template');\n result.innerHTML = htmlString;\n const processedFragment = result.content;\n\n this._nodes = Array.from(processedFragment.childNodes);\n portal.insertBefore(processedFragment, this.nextSibling);\n }\n }\n\n private cleanup() {\n this._nodes.forEach(n => n.parentElement?.removeChild(n));\n this._nodes = [];\n }\n\n disconnectedCallback() {\n this.cleanup();\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;AAAA,SAAS,4BAA4B;AACrC,SAAS,gBAAgB;AACzB,SAAS,eAAe,wBAAwB;AAChD,SAAS,oBAAoB;AAE7B,SAAS,qBAAqB;AAE9B,MAAM,kBAAkB,oBAAmB;EAA3C,cAAA;;AAOU,SAAA,SAAiB,CAAA;AACjB,SAAA,oBAAgD;EAoH1D;EAlHE,IAAI,QAAK;AACP,WAAO,KAAK;EACd;EAEA,IAAI,MAAM,IAAO;AACf,SAAK,QAAQ,EAAE;EACjB;EAGQ,WAAQ;AACd,SAAK,QAAO;EACd;EAGQ,eAAe,iBAA+B;AACpD,SAAK,QAAO;EACd;EAEQ,mBAAmB,MAAc,WAAgB,SAAc,MAAoB;AACzF,UAAM,SAAS,OAAO,EAAE,gBAAgB,KAAI,IAAK;AACjD,UAAM,KAAK,IAAI,iBAAiB,MAAM,MAAM;AAC5C,UA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