@dooboostore/simple-web-component 1.0.49 → 1.0.51
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 +790 -337
- package/dist/cjs/SwcAppEngine.js.map +2 -2
- package/dist/cjs/decorators/addEventListener.js +1925 -22
- package/dist/cjs/decorators/addEventListener.js.map +2 -2
- package/dist/cjs/decorators/applyAttribute.js +41 -47
- package/dist/cjs/decorators/applyAttribute.js.map +2 -2
- package/dist/cjs/decorators/applyClass.js +14 -11
- package/dist/cjs/decorators/applyClass.js.map +2 -2
- package/dist/cjs/decorators/applyNode.js +19 -21
- package/dist/cjs/decorators/applyNode.js.map +2 -2
- package/dist/cjs/decorators/applyProperty.js +24 -48
- package/dist/cjs/decorators/applyProperty.js.map +2 -2
- package/dist/cjs/decorators/applySlot.js +9 -8
- package/dist/cjs/decorators/applySlot.js.map +2 -2
- package/dist/cjs/decorators/applyStyle.js +14 -11
- package/dist/cjs/decorators/applyStyle.js.map +2 -2
- package/dist/cjs/decorators/around.js +124 -0
- package/dist/cjs/decorators/around.js.map +7 -0
- package/dist/cjs/decorators/changedAttribute.js +61 -24
- package/dist/cjs/decorators/changedAttribute.js.map +2 -2
- package/dist/cjs/decorators/elementDefine.js +240 -196
- package/dist/cjs/decorators/elementDefine.js.map +3 -3
- package/dist/cjs/decorators/emitCustomEvent.js +14 -12
- package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
- package/dist/cjs/decorators/eventMedia.js +112 -0
- package/dist/cjs/decorators/eventMedia.js.map +7 -0
- package/dist/cjs/decorators/fetch.js +278 -0
- package/dist/cjs/decorators/fetch.js.map +7 -0
- package/dist/cjs/decorators/index.js +8 -2
- package/dist/cjs/decorators/index.js.map +2 -2
- package/dist/cjs/decorators/intersectionObserver.js +76 -65
- package/dist/cjs/decorators/intersectionObserver.js.map +2 -2
- package/dist/cjs/decorators/lifecycles.js +11 -11
- package/dist/cjs/decorators/lifecycles.js.map +2 -2
- package/dist/cjs/decorators/mutationObserver.js +97 -90
- package/dist/cjs/decorators/mutationObserver.js.map +3 -3
- package/dist/cjs/decorators/parameter.js +156 -0
- package/dist/cjs/decorators/parameter.js.map +7 -0
- package/dist/cjs/decorators/publishSwcAppMessage.js +2 -2
- package/dist/cjs/decorators/publishSwcAppMessage.js.map +2 -2
- package/dist/cjs/decorators/query.js +11 -5
- package/dist/cjs/decorators/query.js.map +2 -2
- package/dist/cjs/decorators/requestAnimationFrame.js +115 -0
- package/dist/cjs/decorators/requestAnimationFrame.js.map +7 -0
- package/dist/cjs/decorators/resizeObserver.js +84 -69
- package/dist/cjs/decorators/resizeObserver.js.map +3 -3
- package/dist/cjs/decorators/setInterval.js +65 -22
- package/dist/cjs/decorators/setInterval.js.map +2 -2
- package/dist/cjs/decorators/setTimeout.js +68 -22
- package/dist/cjs/decorators/setTimeout.js.map +2 -2
- package/dist/cjs/decorators/state.js +13 -10
- package/dist/cjs/decorators/state.js.map +2 -2
- package/dist/cjs/decorators/{subscribeSwcAppMessageWhileConnected.js → subscribeSwcAppMessage.js} +20 -21
- package/dist/cjs/decorators/subscribeSwcAppMessage.js.map +7 -0
- package/dist/cjs/decorators/{subscribeSwcAppRouteChangeWhileConnected.js → subscribeSwcAppRouteChange.js} +23 -19
- package/dist/cjs/decorators/subscribeSwcAppRouteChange.js.map +7 -0
- package/dist/cjs/decorators/swcAppRoute.js +149 -0
- package/dist/cjs/decorators/swcAppRoute.js.map +7 -0
- package/dist/cjs/elements/SwcApp.js +70 -0
- package/dist/cjs/elements/SwcApp.js.map +2 -2
- package/dist/cjs/elements/SwcAppMixin.js +256 -67
- package/dist/cjs/elements/SwcAppMixin.js.map +3 -3
- package/dist/cjs/types/index.js +5 -1
- package/dist/cjs/types/index.js.map +2 -2
- package/dist/cjs/types/window.d.js.map +1 -1
- package/dist/cjs/utils/Utils.js +36 -15
- package/dist/cjs/utils/Utils.js.map +2 -2
- package/dist/esm/SwcAppEngine.js.map +2 -2
- package/dist/esm/decorators/addEventListener.js +1925 -22
- package/dist/esm/decorators/addEventListener.js.map +2 -2
- package/dist/esm/decorators/applyAttribute.js +41 -47
- package/dist/esm/decorators/applyAttribute.js.map +2 -2
- package/dist/esm/decorators/applyClass.js +14 -11
- package/dist/esm/decorators/applyClass.js.map +2 -2
- package/dist/esm/decorators/applyNode.js +20 -22
- package/dist/esm/decorators/applyNode.js.map +2 -2
- package/dist/esm/decorators/applyProperty.js +24 -48
- package/dist/esm/decorators/applyProperty.js.map +2 -2
- package/dist/esm/decorators/applySlot.js +9 -8
- package/dist/esm/decorators/applySlot.js.map +2 -2
- package/dist/esm/decorators/applyStyle.js +14 -11
- package/dist/esm/decorators/applyStyle.js.map +2 -2
- package/dist/esm/decorators/around.js +105 -0
- package/dist/esm/decorators/around.js.map +7 -0
- package/dist/esm/decorators/changedAttribute.js +61 -24
- package/dist/esm/decorators/changedAttribute.js.map +2 -2
- package/dist/esm/decorators/elementDefine.js +238 -194
- package/dist/esm/decorators/elementDefine.js.map +3 -3
- package/dist/esm/decorators/emitCustomEvent.js +15 -13
- package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
- package/dist/esm/decorators/eventMedia.js +94 -0
- package/dist/esm/decorators/eventMedia.js.map +7 -0
- package/dist/esm/decorators/fetch.js +259 -0
- package/dist/esm/decorators/fetch.js.map +7 -0
- package/dist/esm/decorators/index.js +8 -2
- package/dist/esm/decorators/index.js.map +2 -2
- package/dist/esm/decorators/intersectionObserver.js +76 -65
- package/dist/esm/decorators/intersectionObserver.js.map +2 -2
- package/dist/esm/decorators/lifecycles.js +11 -11
- package/dist/esm/decorators/lifecycles.js.map +2 -2
- package/dist/esm/decorators/mutationObserver.js +97 -90
- package/dist/esm/decorators/mutationObserver.js.map +3 -3
- package/dist/esm/decorators/parameter.js +137 -0
- package/dist/esm/decorators/parameter.js.map +7 -0
- package/dist/esm/decorators/publishSwcAppMessage.js +2 -2
- package/dist/esm/decorators/publishSwcAppMessage.js.map +2 -2
- package/dist/esm/decorators/query.js +11 -5
- package/dist/esm/decorators/query.js.map +2 -2
- package/dist/esm/decorators/requestAnimationFrame.js +96 -0
- package/dist/esm/decorators/requestAnimationFrame.js.map +7 -0
- package/dist/esm/decorators/resizeObserver.js +84 -69
- package/dist/esm/decorators/resizeObserver.js.map +2 -2
- package/dist/esm/decorators/setInterval.js +65 -23
- package/dist/esm/decorators/setInterval.js.map +2 -2
- package/dist/esm/decorators/setTimeout.js +68 -23
- package/dist/esm/decorators/setTimeout.js.map +2 -2
- package/dist/esm/decorators/state.js +13 -10
- package/dist/esm/decorators/state.js.map +2 -2
- package/dist/esm/decorators/subscribeSwcAppMessage.js +53 -0
- package/dist/esm/decorators/subscribeSwcAppMessage.js.map +7 -0
- package/dist/esm/decorators/{subscribeSwcAppRouteChangeWhileConnected.js → subscribeSwcAppRouteChange.js} +20 -16
- package/dist/esm/decorators/subscribeSwcAppRouteChange.js.map +7 -0
- package/dist/esm/decorators/swcAppRoute.js +130 -0
- package/dist/esm/decorators/swcAppRoute.js.map +7 -0
- package/dist/esm/elements/SwcApp.js +70 -0
- package/dist/esm/elements/SwcApp.js.map +2 -2
- package/dist/esm/elements/SwcAppMixin.js +258 -69
- package/dist/esm/elements/SwcAppMixin.js.map +3 -3
- package/dist/esm/types/index.js +5 -1
- package/dist/esm/types/index.js.map +2 -2
- package/dist/esm/utils/Utils.js +36 -15
- package/dist/esm/utils/Utils.js.map +2 -2
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +4395 -1266
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/SwcAppEngine.d.ts +1 -0
- package/dist/types/SwcAppEngine.d.ts.map +1 -1
- package/dist/types/decorators/addEventListener.d.ts +936 -11
- package/dist/types/decorators/addEventListener.d.ts.map +1 -1
- package/dist/types/decorators/applyAttribute.d.ts +27 -37
- package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
- package/dist/types/decorators/applyClass.d.ts +2 -2
- package/dist/types/decorators/applyClass.d.ts.map +1 -1
- package/dist/types/decorators/applyNode.d.ts +16 -16
- package/dist/types/decorators/applyNode.d.ts.map +1 -1
- package/dist/types/decorators/applyProperty.d.ts +28 -44
- package/dist/types/decorators/applyProperty.d.ts.map +1 -1
- package/dist/types/decorators/applySlot.d.ts.map +1 -1
- package/dist/types/decorators/applyStyle.d.ts +2 -2
- package/dist/types/decorators/applyStyle.d.ts.map +1 -1
- package/dist/types/decorators/around.d.ts +87 -0
- package/dist/types/decorators/around.d.ts.map +1 -0
- package/dist/types/decorators/changedAttribute.d.ts +22 -4
- package/dist/types/decorators/changedAttribute.d.ts.map +1 -1
- package/dist/types/decorators/elementDefine.d.ts.map +1 -1
- package/dist/types/decorators/emitCustomEvent.d.ts +0 -1
- package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
- package/dist/types/decorators/eventMedia.d.ts +48 -0
- package/dist/types/decorators/eventMedia.d.ts.map +1 -0
- package/dist/types/decorators/fetch.d.ts +139 -0
- package/dist/types/decorators/fetch.d.ts.map +1 -0
- package/dist/types/decorators/index.d.ts +8 -2
- package/dist/types/decorators/index.d.ts.map +1 -1
- package/dist/types/decorators/intersectionObserver.d.ts +32 -10
- package/dist/types/decorators/intersectionObserver.d.ts.map +1 -1
- package/dist/types/decorators/lifecycles.d.ts +8 -7
- package/dist/types/decorators/lifecycles.d.ts.map +1 -1
- package/dist/types/decorators/mutationObserver.d.ts +34 -12
- package/dist/types/decorators/mutationObserver.d.ts.map +1 -1
- package/dist/types/decorators/parameter.d.ts +113 -0
- package/dist/types/decorators/parameter.d.ts.map +1 -0
- package/dist/types/decorators/publishSwcAppMessage.d.ts +0 -1
- package/dist/types/decorators/publishSwcAppMessage.d.ts.map +1 -1
- package/dist/types/decorators/query.d.ts +7 -7
- package/dist/types/decorators/query.d.ts.map +1 -1
- package/dist/types/decorators/requestAnimationFrame.d.ts +47 -0
- package/dist/types/decorators/requestAnimationFrame.d.ts.map +1 -0
- package/dist/types/decorators/resizeObserver.d.ts +34 -12
- package/dist/types/decorators/resizeObserver.d.ts.map +1 -1
- package/dist/types/decorators/setInterval.d.ts +27 -5
- package/dist/types/decorators/setInterval.d.ts.map +1 -1
- package/dist/types/decorators/setTimeout.d.ts +27 -5
- package/dist/types/decorators/setTimeout.d.ts.map +1 -1
- package/dist/types/decorators/state.d.ts.map +1 -1
- package/dist/types/decorators/subscribeSwcAppMessage.d.ts +44 -0
- package/dist/types/decorators/subscribeSwcAppMessage.d.ts.map +1 -0
- package/dist/types/decorators/subscribeSwcAppRouteChange.d.ts +60 -0
- package/dist/types/decorators/subscribeSwcAppRouteChange.d.ts.map +1 -0
- package/dist/types/decorators/swcAppRoute.d.ts +94 -0
- package/dist/types/decorators/swcAppRoute.d.ts.map +1 -0
- package/dist/types/elements/SwcApp.d.ts.map +1 -1
- package/dist/types/elements/SwcAppMixin.d.ts +423 -388
- package/dist/types/elements/SwcAppMixin.d.ts.map +1 -1
- package/dist/types/types/index.d.ts +43 -4
- package/dist/types/types/index.d.ts.map +1 -1
- package/dist/types/utils/Utils.d.ts +15 -5
- package/dist/types/utils/Utils.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +4395 -1266
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +8 -6
- package/src/SwcAppEngine.ts +1 -0
- package/src/decorators/addEventListener.ts +1086 -28
- package/src/decorators/applyAttribute.ts +82 -134
- package/src/decorators/applyClass.ts +14 -10
- package/src/decorators/applyNode.ts +39 -37
- package/src/decorators/applyProperty.ts +72 -100
- package/src/decorators/applySlot.ts +9 -8
- package/src/decorators/applyStyle.ts +14 -10
- package/src/decorators/around.ts +196 -0
- package/src/decorators/changedAttribute.ts +65 -26
- package/src/decorators/elementDefine.ts +298 -220
- package/src/decorators/emitCustomEvent.ts +17 -13
- package/src/decorators/eventMedia.ts +119 -0
- package/src/decorators/fetch.ts +454 -0
- package/src/decorators/index.ts +8 -2
- package/src/decorators/intersectionObserver.ts +108 -78
- package/src/decorators/lifecycles.ts +24 -22
- package/src/decorators/mutationObserver.ts +140 -104
- package/src/decorators/parameter.ts +212 -0
- package/src/decorators/publishSwcAppMessage.ts +3 -4
- package/src/decorators/query.ts +22 -14
- package/src/decorators/requestAnimationFrame.ts +149 -0
- package/src/decorators/resizeObserver.ts +119 -82
- package/src/decorators/setInterval.ts +90 -23
- package/src/decorators/setTimeout.ts +93 -23
- package/src/decorators/state.ts +19 -13
- package/src/decorators/subscribeSwcAppMessage.ts +106 -0
- package/src/decorators/subscribeSwcAppRouteChange.ts +131 -0
- package/src/decorators/swcAppRoute.ts +231 -0
- package/src/elements/SwcApp.ts +40 -10
- package/src/elements/SwcAppMixin.ts +329 -85
- package/src/types/index.ts +38 -5
- package/src/types/window.d.ts +2 -18
- package/src/utils/Utils.ts +50 -18
- package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js.map +0 -7
- package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +0 -7
- package/dist/cjs/examples/RxJSOperatorsExample.js +0 -285
- package/dist/cjs/examples/RxJSOperatorsExample.js.map +0 -7
- package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js +0 -54
- package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js.map +0 -7
- package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +0 -7
- package/dist/esm/examples/RxJSOperatorsExample.js +0 -266
- package/dist/esm/examples/RxJSOperatorsExample.js.map +0 -7
- package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts +0 -23
- package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts.map +0 -1
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts +0 -31
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts.map +0 -1
- package/dist/types/examples/RxJSOperatorsExample.d.ts +0 -94
- package/dist/types/examples/RxJSOperatorsExample.d.ts.map +0 -1
- package/src/decorators/subscribeSwcAppMessageWhileConnected.ts +0 -91
- package/src/decorators/subscribeSwcAppRouteChangeWhileConnected.ts +0 -107
- package/src/examples/RxJSOperatorsExample.ts +0 -279
|
@@ -37,8 +37,8 @@ var import_elementDefine = require("./elementDefine");
|
|
|
37
37
|
var import_Utils = require("../utils/Utils");
|
|
38
38
|
var import_core_web = require("@dooboostore/core-web");
|
|
39
39
|
const APPLY_SLOT_METADATA_KEY = Symbol.for("simple-web-component:apply-slot");
|
|
40
|
-
const applyToDom = (swcId, id, pos, nodes) => {
|
|
41
|
-
const nodeSlot = new import_core_web.NodeSlot(
|
|
40
|
+
const applyToDom = (host, swcId, id, pos, nodes) => {
|
|
41
|
+
const nodeSlot = new import_core_web.NodeSlot(host, swcId);
|
|
42
42
|
if (pos === "replaceChildrenText" || pos === "replaceChildren" || pos === "replaceChildrenHtml") {
|
|
43
43
|
nodeSlot.replaceChildren(id, ...nodes);
|
|
44
44
|
} else if (pos === "appendHtml" || pos === "append" || pos === "appendText") {
|
|
@@ -62,11 +62,12 @@ function applySlot(targetId, opt) {
|
|
|
62
62
|
const original = descriptor.value;
|
|
63
63
|
descriptor.value = function(...args) {
|
|
64
64
|
(0, import_elementDefine.ensureInit)(this);
|
|
65
|
+
const host = this;
|
|
65
66
|
const conf = (0, import_elementDefine.getElementConfig)(this);
|
|
66
67
|
const currentWin = conf.window;
|
|
67
68
|
const swcId = this._swcId;
|
|
68
69
|
const currentDoc = currentWin.document;
|
|
69
|
-
const hostSet = import_Utils.SwcUtils.getHelperAndHostSet(
|
|
70
|
+
const hostSet = import_Utils.SwcUtils.getHelperAndHostSet(this);
|
|
70
71
|
const pos = options.position;
|
|
71
72
|
const resToNodes = (res2) => {
|
|
72
73
|
const nodes = [];
|
|
@@ -87,7 +88,7 @@ function applySlot(targetId, opt) {
|
|
|
87
88
|
const res2 = options.fallback.call(this, hostSet);
|
|
88
89
|
const nodes = resToNodes(res2);
|
|
89
90
|
fallbackNodes.push(...nodes);
|
|
90
|
-
applyToDom(swcId, targetId, options.position, nodes);
|
|
91
|
+
applyToDom(host, swcId, targetId, options.position, nodes);
|
|
91
92
|
}
|
|
92
93
|
const extractValue = (v) => {
|
|
93
94
|
const keyToUse = options.valueKey ?? APPLY_SLOT_METADATA_KEY;
|
|
@@ -102,12 +103,12 @@ function applySlot(targetId, opt) {
|
|
|
102
103
|
const extracted = extractValue(asyncRes);
|
|
103
104
|
const nodes = resToNodes(extracted);
|
|
104
105
|
fallbackNodes.forEach((it) => it.remove());
|
|
105
|
-
applyToDom(swcId, targetId, options.position, nodes);
|
|
106
|
+
applyToDom(host, swcId, targetId, options.position, nodes);
|
|
106
107
|
});
|
|
107
108
|
} else {
|
|
108
109
|
const extracted = extractValue(res);
|
|
109
110
|
const nodes = resToNodes(extracted);
|
|
110
|
-
applyToDom(swcId, targetId, options.position, nodes);
|
|
111
|
+
applyToDom(host, swcId, targetId, options.position, nodes);
|
|
111
112
|
}
|
|
112
113
|
};
|
|
113
114
|
};
|
|
@@ -143,7 +144,7 @@ function replaceChildrenTextSlot(targetId) {
|
|
|
143
144
|
return applySlot(targetId, { position: "replaceChildrenText" });
|
|
144
145
|
}
|
|
145
146
|
const findAllApplySlotMetadata = (target) => {
|
|
146
|
-
const constructor = target
|
|
147
|
-
return import_core.ReflectUtils.
|
|
147
|
+
const constructor = typeof target === "function" ? target : target.constructor;
|
|
148
|
+
return import_core.ReflectUtils.findAllMetadata(APPLY_SLOT_METADATA_KEY, constructor).flat();
|
|
148
149
|
};
|
|
149
150
|
//# sourceMappingURL=applySlot.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/decorators/applySlot.ts"],
|
|
4
|
-
"sourcesContent": ["import {OptionalType, ReflectUtils} from '@dooboostore/core';\nimport {ensureInit, getElementConfig} from './elementDefine';\nimport {SwcUtils} from \"../utils/Utils\";\nimport {NodeSlot} from \"@dooboostore/core-web\";\nimport {HelperHostSet} from \"../types\";\n/*\n<!-- beforebegin -->\n<p> <-- it's me\n <!-- afterbegin -->\n foo\n <!-- beforeend -->\n</p>\n<!-- afterend -->\n */\nexport type ApplySlotPosition = 'prepend' | 'prependHtml' | 'prependText' | 'append' | 'appendHtml' | 'appendText' | 'replaceChildren' | 'replaceChildrenHtml' | 'replaceChildrenText' | 'clear';\n\nexport interface ApplySlotOptions {\n position: ApplySlotPosition;\n fallback?: (helper: HelperHostSet) => string | Node;\n /**\n * Custom key to extract value from return object.\n * If not provided, uses APPLY_SLOT_METADATA_KEY by default.\n * Useful when multiple @applySlot decorators are on the same method.\n */\n valueKey?: symbol | string;\n}\n\nexport interface ApplySlotMetadata {\n propertyKey: string | symbol;\n targetId: string;\n // type: 'method' | 'property';\n options: ApplySlotOptions;\n}\n\nexport const APPLY_SLOT_METADATA_KEY = Symbol.for('simple-web-component:apply-slot');\n\n// const normalizeNodes = (res: any, doc: Document): Node[] => {\n// const items = Array.isArray(res) ? res : [res];\n// return items.map(it => {\n// if (it instanceof Node) return it;\n// return doc.createTextNode(it !== undefined && it !== null ? String(it) : '');\n// });\n// };\n\n// const applyToDom = (targetEl: any, res: any, pos: ApplyNodePosition, win: Window) => {\n// if (!targetEl) return;\n//\n// const doc = win.document;\n//\n// if (pos === 'innerHtml') {\n// targetEl.innerHTML = res !== undefined && res !== null ? String(res) : '';\n// return;\n// }\n//\n// if (pos === 'innerText') {\n// if (targetEl.innerText !== undefined) {\n// targetEl.innerText = res !== undefined && res !== null ? String(res) : '';\n// }\n// return;\n// }\n//\n// const isShadowRoot = targetEl instanceof win.ShadowRoot;\n// const nodes = normalizeNodes(res, doc);\n// if (pos === 'replace') {\n// if (!isShadowRoot) targetEl.replaceWith(...nodes);\n// } else if (pos === 'replaceChildren') {\n// targetEl.replaceChildren(...nodes);\n// } else {\n// if (pos === 'beforeEnd') targetEl.append(...nodes);\n// else if (pos === 'afterBegin') targetEl.prepend(...nodes);\n// else if (pos === 'beforeBegin' && !isShadowRoot) targetEl.before(...nodes);\n// else if (pos === 'afterEnd' && !isShadowRoot) targetEl.after(...nodes);\n// }\n// };\n\nconst applyToDom = (swcId: string, id: string, pos: ApplySlotPosition, nodes: Node[]) => {\n const nodeSlot = new NodeSlot(
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAyC;AACzC,2BAA2C;AAC3C,mBAAuB;AACvB,sBAAuB;AA+BhB,MAAM,0BAA0B,OAAO,IAAI,iCAAiC;AAyCnF,MAAM,aAAa,CAAC,OAAe,IAAY,KAAwB,UAAkB;
|
|
4
|
+
"sourcesContent": ["import {OptionalType, ReflectUtils} from '@dooboostore/core';\nimport {ensureInit, getElementConfig} from './elementDefine';\nimport {SwcUtils} from \"../utils/Utils\";\nimport {NodeSlot} from \"@dooboostore/core-web\";\nimport {HelperHostSet} from \"../types\";\n/*\n<!-- beforebegin -->\n<p> <-- it's me\n <!-- afterbegin -->\n foo\n <!-- beforeend -->\n</p>\n<!-- afterend -->\n */\nexport type ApplySlotPosition = 'prepend' | 'prependHtml' | 'prependText' | 'append' | 'appendHtml' | 'appendText' | 'replaceChildren' | 'replaceChildrenHtml' | 'replaceChildrenText' | 'clear';\n\nexport interface ApplySlotOptions {\n position: ApplySlotPosition;\n fallback?: (helper: HelperHostSet) => string | Node;\n /**\n * Custom key to extract value from return object.\n * If not provided, uses APPLY_SLOT_METADATA_KEY by default.\n * Useful when multiple @applySlot decorators are on the same method.\n */\n valueKey?: symbol | string;\n}\n\nexport interface ApplySlotMetadata {\n propertyKey: string | symbol;\n targetId: string;\n // type: 'method' | 'property';\n options: ApplySlotOptions;\n}\n\nexport const APPLY_SLOT_METADATA_KEY = Symbol.for('simple-web-component:apply-slot');\n\n// const normalizeNodes = (res: any, doc: Document): Node[] => {\n// const items = Array.isArray(res) ? res : [res];\n// return items.map(it => {\n// if (it instanceof Node) return it;\n// return doc.createTextNode(it !== undefined && it !== null ? String(it) : '');\n// });\n// };\n\n// const applyToDom = (targetEl: any, res: any, pos: ApplyNodePosition, win: Window) => {\n// if (!targetEl) return;\n//\n// const doc = win.document;\n//\n// if (pos === 'innerHtml') {\n// targetEl.innerHTML = res !== undefined && res !== null ? String(res) : '';\n// return;\n// }\n//\n// if (pos === 'innerText') {\n// if (targetEl.innerText !== undefined) {\n// targetEl.innerText = res !== undefined && res !== null ? String(res) : '';\n// }\n// return;\n// }\n//\n// const isShadowRoot = targetEl instanceof win.ShadowRoot;\n// const nodes = normalizeNodes(res, doc);\n// if (pos === 'replace') {\n// if (!isShadowRoot) targetEl.replaceWith(...nodes);\n// } else if (pos === 'replaceChildren') {\n// targetEl.replaceChildren(...nodes);\n// } else {\n// if (pos === 'beforeEnd') targetEl.append(...nodes);\n// else if (pos === 'afterBegin') targetEl.prepend(...nodes);\n// else if (pos === 'beforeBegin' && !isShadowRoot) targetEl.before(...nodes);\n// else if (pos === 'afterEnd' && !isShadowRoot) targetEl.after(...nodes);\n// }\n// };\n\nconst applyToDom = (host: HTMLElement, swcId: string, id: string, pos: ApplySlotPosition, nodes: Node[]) => {\n const nodeSlot = new NodeSlot(host, swcId);\n if (pos === 'replaceChildrenText' || pos === 'replaceChildren' || pos === 'replaceChildrenHtml') {\n nodeSlot.replaceChildren(id, ...nodes);\n } else if (pos === 'appendHtml' || pos === 'append' || pos === 'appendText') {\n nodeSlot.append(id, ...nodes);\n } else if (pos === 'prependHtml' || pos === 'prepend' || pos === 'prependText') {\n nodeSlot.prepend(id, ...nodes);\n } else if (pos === 'clear') {\n nodeSlot.clear(id);\n }\n}\n\n/**\n * @applyNode decorator to surgically add/replace nodes to a target element.\n */\nexport function applySlot(targetId: string, opt: OptionalType<ApplySlotOptions, 'position'>): MethodDecorator {\n return (targetObj: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<any>) => {\n\n\n const options: ApplySlotOptions = {position: 'replaceChildren', ...opt};\n\n\n const constructor = targetObj.constructor;\n let metaList = ReflectUtils.getOwnMetadata(APPLY_SLOT_METADATA_KEY, constructor) as ApplySlotMetadata[];\n if (!metaList) {\n metaList = []\n ReflectUtils.defineMetadata(APPLY_SLOT_METADATA_KEY, metaList, constructor);\n }\n metaList.push({propertyKey, targetId, options});\n\n\n const original = descriptor.value;\n descriptor.value = function (...args: any[]) {\n ensureInit(this);\n\n const host = this;\n const conf = getElementConfig(this);\n const currentWin = conf.window;\n const swcId = this._swcId;\n const currentDoc = currentWin.document;\n const hostSet = SwcUtils.getHelperAndHostSet(this);\n const pos = options.position;\n\n const resToNodes = (res: string | Node) => {\n const nodes: Node[] = [];\n\n if (typeof res === 'string' && (pos === 'replaceChildrenHtml' || pos === 'appendHtml' || pos === 'prependHtml')) {\n const t = currentWin.document.createElement('template');\n t.innerHTML = res;\n nodes.push(...Array.from(t.content.childNodes));\n } else if (typeof res === 'string' && (pos === 'replaceChildrenText' || pos === 'prependText' || pos === 'appendText')) {\n nodes.push(currentWin.document.createTextNode(res));\n } else if (typeof res === 'object') {\n nodes.push(res);\n }\n SwcUtils.projectProcessHtml(swcId, nodes, currentDoc);\n return nodes;\n }\n\n const fallbackNodes: Node[] = [];\n if (options.fallback) {\n const res: string | Node = options.fallback.call(this, hostSet);\n const nodes: Node[] = resToNodes(res);\n fallbackNodes.push(...nodes);\n applyToDom(host, swcId, targetId, options.position, nodes);\n }\n\n /**\n * Extract value for this decorator from method return value\n * \n * If return value is an object with this decorator's key,\n * use that value. Otherwise use the entire return value.\n * \n * Uses valueKey from options if provided, otherwise uses APPLY_SLOT_METADATA_KEY.\n */\n const extractValue = (v: any) => {\n const keyToUse = options.valueKey ?? APPLY_SLOT_METADATA_KEY;\n if (v && typeof v === 'object' && keyToUse in v) {\n return v[keyToUse];\n }\n return v;\n };\n\n let res = original.apply(this, args);\n if (res instanceof Promise) {\n return res.then(asyncRes => {\n const extracted = extractValue(asyncRes);\n const nodes = resToNodes(extracted)\n fallbackNodes.forEach((it: any) => it.remove());\n applyToDom(host, swcId, targetId, options.position, nodes);\n })\n } else {\n const extracted = extractValue(res);\n const nodes: Node[] = resToNodes(extracted);\n applyToDom(host, swcId, targetId, options.position, nodes);\n }\n };\n };\n}\n\nexport function clearSlot(targetId: string): MethodDecorator {\n return applySlot(targetId, {position: 'clear'});\n}\n\nexport function prependHtmlSlot(targetId: string): MethodDecorator {\n return applySlot(targetId, {position: 'prependHtml'});\n}\n\nexport function prependSlot(targetId: string): MethodDecorator {\n return applySlot(targetId, {position: 'prepend'});\n}\n\nexport function prependTextSlot(targetId: string): MethodDecorator {\n return applySlot(targetId, {position: 'prependText'});\n}\n\nexport function appendHtmlSlot(targetId: string): MethodDecorator {\n return applySlot(targetId, {position: 'appendHtml'});\n}\n\nexport function appendTextSlot(targetId: string): MethodDecorator {\n return applySlot(targetId, {position: 'appendText'});\n}\n\nexport function appendSlot(targetId: string): MethodDecorator {\n return applySlot(targetId, {position: 'append'});\n}\n\nexport function replaceChildrenHtmlSlot(targetId: string): MethodDecorator {\n return applySlot(targetId, {position: 'replaceChildrenHtml'});\n}\n\nexport function replaceChildrenSlot(targetId: string): MethodDecorator {\n return applySlot(targetId, {position: 'replaceChildren'});\n}\n\nexport function replaceChildrenTextSlot(targetId: string): MethodDecorator {\n return applySlot(targetId, {position: 'replaceChildrenText'});\n}\n\n// export const findAllApplySlotMetadata = (target: any): Map<string | symbol, ApplySlotMetadata> => {\nexport const findAllApplySlotMetadata = (target: any): ApplySlotMetadata[] => {\n const constructor = typeof target === 'function' ? target : target.constructor;\n return ReflectUtils.findAllMetadata<any[]>(APPLY_SLOT_METADATA_KEY, constructor).flat();\n};"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAyC;AACzC,2BAA2C;AAC3C,mBAAuB;AACvB,sBAAuB;AA+B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,UAAU,KAAK;AAAA,MAC3D;AAAA,IACF;AAAA,EACF;AACF;AAEO,SAAS,UAAU,UAAmC;AAC3D,SAAO,UAAU,UAAU,EAAC,UAAU,QAAO,CAAC;AAChD;AAEO,SAAS,gBAAgB,UAAmC;AACjE,SAAO,UAAU,UAAU,EAAC,UAAU,cAAa,CAAC;AACtD;AAEO,SAAS,YAAY,UAAmC;AAC7D,SAAO,UAAU,UAAU,EAAC,UAAU,UAAS,CAAC;AAClD;AAEO,SAAS,gBAAgB,UAAmC;AACjE,SAAO,UAAU,UAAU,EAAC,UAAU,cAAa,CAAC;AACtD;AAEO,SAAS,eAAe,UAAmC;AAChE,SAAO,UAAU,UAAU,EAAC,UAAU,aAAY,CAAC;AACrD;AAEO,SAAS,eAAe,UAAmC;AAChE,SAAO,UAAU,UAAU,EAAC,UAAU,aAAY,CAAC;AACrD;AAEO,SAAS,WAAW,UAAmC;AAC5D,SAAO,UAAU,UAAU,EAAC,UAAU,SAAQ,CAAC;AACjD;AAEO,SAAS,wBAAwB,UAAmC;AACzE,SAAO,UAAU,UAAU,EAAC,UAAU,sBAAqB,CAAC;AAC9D;AAEO,SAAS,oBAAoB,UAAmC;AACrE,SAAO,UAAU,UAAU,EAAC,UAAU,kBAAiB,CAAC;AAC1D;AAEO,SAAS,wBAAwB,UAAmC;AACzE,SAAO,UAAU,UAAU,EAAC,UAAU,sBAAqB,CAAC;AAC9D;AAGO,MAAM,2BAA2B,CAAC,WAAqC;AAC5E,QAAM,cAAc,OAAO,WAAW,aAAa,SAAS,OAAO;AACnE,SAAO,yBAAa,gBAAuB,yBAAyB,WAAW,EAAE,KAAK;AACxF;",
|
|
6
6
|
"names": ["res"]
|
|
7
7
|
}
|
|
@@ -27,7 +27,6 @@ __export(applyStyle_exports, {
|
|
|
27
27
|
styleAppHost: () => styleAppHost,
|
|
28
28
|
styleLight: () => styleLight,
|
|
29
29
|
styleShadow: () => styleShadow,
|
|
30
|
-
styleThis: () => styleThis,
|
|
31
30
|
updateStyle: () => updateStyle
|
|
32
31
|
});
|
|
33
32
|
module.exports = __toCommonJS(applyStyle_exports);
|
|
@@ -37,7 +36,7 @@ var import_Utils = require("../utils/Utils");
|
|
|
37
36
|
const STYLE_METADATA_KEY = Symbol.for("simple-web-component:style");
|
|
38
37
|
const resolveSelector = (selector, inst, win) => {
|
|
39
38
|
if (typeof selector === "function") {
|
|
40
|
-
const hostSet = import_Utils.SwcUtils.getHelperAndHostSet(
|
|
39
|
+
const hostSet = import_Utils.SwcUtils.getHelperAndHostSet(inst);
|
|
41
40
|
const result = selector(inst, hostSet);
|
|
42
41
|
if (result instanceof win.Element) {
|
|
43
42
|
return [result];
|
|
@@ -66,7 +65,7 @@ const getTargetElements = (selector, inst, win, root) => {
|
|
|
66
65
|
const stringSelector = resolved;
|
|
67
66
|
const targetEls = [];
|
|
68
67
|
const host = inst;
|
|
69
|
-
const hostSet = import_Utils.SwcUtils.getHelperAndHostSet(
|
|
68
|
+
const hostSet = import_Utils.SwcUtils.getHelperAndHostSet(inst);
|
|
70
69
|
const applyRoot = (t) => {
|
|
71
70
|
if (!t || !(t instanceof win.HTMLElement)) return;
|
|
72
71
|
targetEls.push(t);
|
|
@@ -115,7 +114,7 @@ function createStyleDecorator(action) {
|
|
|
115
114
|
if (resolvedValue !== void 0) {
|
|
116
115
|
const win = this.ownerDocument?.defaultView || window;
|
|
117
116
|
const host = this;
|
|
118
|
-
const hostSet = { ...import_Utils.SwcUtils.getHelperAndHostSet(
|
|
117
|
+
const hostSet = { ...import_Utils.SwcUtils.getHelperAndHostSet(host), $this: this };
|
|
119
118
|
const r = options.root || "auto";
|
|
120
119
|
const targetEls = getTargetElements(selector, this, win, r);
|
|
121
120
|
targetEls.forEach((targetEl) => {
|
|
@@ -155,9 +154,13 @@ function createStyleDecorator(action) {
|
|
|
155
154
|
return resolvedValue;
|
|
156
155
|
};
|
|
157
156
|
if (res instanceof Promise) {
|
|
158
|
-
return res.then((v) =>
|
|
157
|
+
return res.then((v) => {
|
|
158
|
+
handleResult(extractValue(v));
|
|
159
|
+
return v;
|
|
160
|
+
});
|
|
159
161
|
} else {
|
|
160
|
-
|
|
162
|
+
handleResult(extractValue(res));
|
|
163
|
+
return res;
|
|
161
164
|
}
|
|
162
165
|
};
|
|
163
166
|
return descriptor;
|
|
@@ -205,11 +208,11 @@ function removeStyle(selectorOrTarget, optionsOrPropertyKey, descriptor) {
|
|
|
205
208
|
return createStyleDecorator("remove")("$this", selectorOrTarget);
|
|
206
209
|
}
|
|
207
210
|
const style = applyStyle;
|
|
208
|
-
function
|
|
209
|
-
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
return applyStyle("$appHost",
|
|
211
|
+
function styleAppHost(actionOrTarget, optionsOrPropertyKey, descriptor) {
|
|
212
|
+
if ((typeof optionsOrPropertyKey === "string" || typeof optionsOrPropertyKey === "symbol") && descriptor !== void 0) {
|
|
213
|
+
return applyStyle("$appHost", void 0, {})(actionOrTarget, optionsOrPropertyKey, descriptor);
|
|
214
|
+
}
|
|
215
|
+
return applyStyle("$appHost", actionOrTarget, optionsOrPropertyKey);
|
|
213
216
|
}
|
|
214
217
|
function styleLight(selector, actionOrOptions, options) {
|
|
215
218
|
const action = typeof actionOrOptions === "string" ? actionOrOptions : void 0;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/decorators/applyStyle.ts"],
|
|
4
|
-
"sourcesContent": ["import {ReflectUtils} from '@dooboostore/core';\nimport {ensureInit} from './elementDefine';\nimport {SwcUtils} from '../utils/Utils';\nimport { SpecialSelector, SwcQueryOptions, SwcFnSelector, SwcSelector, HelperHostSet } from '../types';\n\nexport type StyleAction = 'set' | 'update' | 'remove';\n\n// \uACF5\uD1B5 \uC635\uC158 \u2014 root \uC5C6\uC74C\nexport interface StyleBaseOptions {\n filter?: (target: HTMLElement, value: any, meta: {currentThis: any, helper: HelperHostSet}) => boolean;\n valueKey?: symbol | string;\n}\n\n// \uBB38\uC790\uC5F4 \uC140\uB809\uD130 \uC804\uC6A9 \u2014 root \uD5C8\uC6A9\nexport type StyleQueryOptions = StyleBaseOptions & SwcQueryOptions;\n// \uD568\uC218 \uC140\uB809\uD130 \uC804\uC6A9 \u2014 root \uAE08\uC9C0\nexport type StyleNonQueryOptions = StyleBaseOptions;\n// \uB0B4\uBD80 \uC800\uC7A5/\uD574\uC11D\uC6A9\nexport type StyleApplyOptions = StyleQueryOptions;\n\nexport type StyleFnSelector = SwcFnSelector;\nexport type StyleSelector = SwcSelector;\n\n// \uC140\uB809\uD130 \uC885\uB958\uC5D0 \uB530\uB77C \uC635\uC158 \uD0C0\uC785 \uBD84\uAE30\nexport type StyleOptionsOf<S extends StyleSelector> = S extends string ? StyleQueryOptions : StyleNonQueryOptions;\n\nexport interface StyleApplyMetadata {\n propertyKey: string | symbol;\n selector: StyleSelector;\n action: StyleAction;\n options: StyleApplyOptions;\n}\n\nexport const STYLE_METADATA_KEY = Symbol.for('simple-web-component:style');\n\n/**\n * Resolve selector to string or elements\n * Handles function-based selectors and returns elements if applicable\n */\nconst resolveSelector = (selector: StyleSelector, inst: any, win: Window): string | HTMLElement[] => {\n if (typeof selector === 'function') {\n const hostSet = SwcUtils.getHelperAndHostSet(win, inst);\n const result = selector(inst, hostSet);\n \n if (result instanceof win.Element) {\n return [result as HTMLElement];\n }\n if (result instanceof win.NodeList) {\n return Array.from(result) as HTMLElement[];\n }\n if (Array.isArray(result)) {\n return result as HTMLElement[];\n }\n if (result === null) {\n return [];\n }\n if (result instanceof win.Node) {\n return [];\n }\n return result as string;\n }\n return selector as string;\n};\n\n/**\n * Get target elements from selector\n */\nconst getTargetElements = (selector: StyleSelector, inst: any, win: Window, root: string): HTMLElement[] => {\n const resolved = resolveSelector(selector, inst, win);\n \n if (Array.isArray(resolved)) {\n return resolved;\n }\n\n const stringSelector = resolved as string;\n const targetEls: HTMLElement[] = [];\n const host = inst as unknown as HTMLElement;\n const hostSet = SwcUtils.getHelperAndHostSet(win, inst);\n\n const applyRoot = (t: any) => {\n if (!t || !(t instanceof win.HTMLElement)) return;\n targetEls.push(t);\n };\n\n if (stringSelector === '$this' || !stringSelector) applyRoot(host);\n else if (stringSelector === '$host') applyRoot(hostSet.$host);\n else if (stringSelector === '$parentHost') applyRoot(hostSet.$parentHost);\n else if (stringSelector === '$appHost') applyRoot(hostSet.$appHost);\n else if (stringSelector === '$firstHost') applyRoot(hostSet.$firstHost);\n else if (stringSelector === '$lastHost') applyRoot(hostSet.$lastHost);\n else if (stringSelector === '$firstAppHost') applyRoot(hostSet.$firstAppHost);\n else if (stringSelector === '$lastAppHost') applyRoot(hostSet.$lastAppHost);\n else if (stringSelector === '$hosts') hostSet.$hosts.forEach(applyRoot);\n else if (stringSelector === '$appHosts') hostSet.$appHosts.forEach(applyRoot);\n else {\n const targetRoot = root === 'auto' ? (host.shadowRoot || host) : (root === 'shadow' ? host.shadowRoot : host);\n if (targetRoot) {\n const found = targetRoot.querySelectorAll(stringSelector);\n if (found) targetEls.push(...(Array.from(found) as HTMLElement[]));\n }\n }\n\n return targetEls;\n};\n\nfunction createStyleDecorator(action: StyleAction) {\n return (selector: StyleSelector, options: StyleApplyOptions = {}): MethodDecorator => {\n return (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n const constructor = target.constructor;\n let metaList = ReflectUtils.getOwnMetadata(STYLE_METADATA_KEY, constructor) as Map<string | symbol, StyleApplyMetadata>;\n if (!metaList) {\n metaList = new Map<string | symbol, StyleApplyMetadata>();\n ReflectUtils.defineMetadata(STYLE_METADATA_KEY, metaList, constructor);\n }\n metaList.set(propertyKey, { propertyKey, selector, action, options });\n\n const original = descriptor.value;\n descriptor.value = function (...args: any[]) {\n ensureInit(this);\n const res = (original as any).apply(this, args);\n\n /**\n * Extract value for this decorator from method return value\n * \n * If return value is an object with this decorator's key,\n * use that value. Otherwise use the entire return value.\n * \n * Uses valueKey from options if provided, otherwise uses STYLE_METADATA_KEY.\n */\n const extractValue = (v: any) => {\n const keyToUse = options.valueKey ?? STYLE_METADATA_KEY;\n if (v && typeof v === 'object' && keyToUse in v) {\n return v[keyToUse];\n }\n return v;\n };\n\n const handleResult = (resolvedValue: any) => {\n if (resolvedValue !== undefined) {\n const win = (this as any).ownerDocument?.defaultView || window;\n const host = this as unknown as HTMLElement;\n const hostSet = { ...SwcUtils.getHelperAndHostSet(win, host), $this: this };\n const r = options.root || 'auto';\n const targetEls = getTargetElements(selector, this, win, r);\n\n targetEls.forEach(targetEl => {\n if (options.filter && !options.filter(targetEl, resolvedValue, {currentThis: this, helper: hostSet})) {\n return;\n }\n const resolvedRes = typeof resolvedValue === 'function' ? (resolvedValue as any)(targetEl, hostSet) : resolvedValue;\n\n if (action === 'set' || action === 'update') {\n if (action === 'set') targetEl.style.cssText = '';\n \n if (typeof resolvedRes === 'object' && resolvedRes !== null && !Array.isArray(resolvedRes)) {\n Object.entries(resolvedRes as any).forEach(([prop, val]) => {\n const finalVal = typeof val === 'function' ? val(targetEl, hostSet) : val;\n if (finalVal === null || finalVal === undefined) {\n targetEl.style.removeProperty(prop);\n } else {\n targetEl.style[prop as any] = String(finalVal);\n }\n });\n } else if (typeof resolvedRes === 'string') {\n targetEl.style.cssText = resolvedRes;\n }\n } else if (action === 'remove') {\n if (typeof resolvedRes === 'object' && resolvedRes !== null && !Array.isArray(resolvedRes)) {\n Object.entries(resolvedRes as any).forEach(([prop, val]) => {\n const shouldRemove = typeof val === 'function' ? val(targetEl, hostSet) : !!val;\n if (shouldRemove) {\n targetEl.style.removeProperty(prop);\n }\n });\n } else {\n const props = Array.isArray(resolvedRes) ? resolvedRes : [resolvedRes];\n props.forEach(p => targetEl.style.removeProperty(String(p)));\n }\n }\n });\n }\n return resolvedValue;\n };\n\n if (res instanceof Promise) {\n return res.then((v: any) => handleResult(extractValue(v)));\n } else {\n return handleResult(extractValue(res));\n }\n };\n return descriptor;\n };\n };\n}\n\nexport function applyStyle(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;\nexport function applyStyle(selector: string, action?: StyleAction, options?: StyleQueryOptions): MethodDecorator;\nexport function applyStyle(selector: StyleFnSelector, action?: StyleAction, options?: StyleNonQueryOptions): MethodDecorator;\nexport function applyStyle(selectorOrTarget?: any, actionOrPropertyKey?: any, optionsOrDescriptor?: any): any {\n // Bare decorator: @applyStyle\n if (optionsOrDescriptor !== undefined && typeof selectorOrTarget !== 'string' && typeof selectorOrTarget !== 'function' && (typeof actionOrPropertyKey === 'string' || typeof actionOrPropertyKey === 'symbol')) {\n return createStyleDecorator('update')('$this', {})(selectorOrTarget as Object, actionOrPropertyKey, optionsOrDescriptor as PropertyDescriptor);\n }\n // With selector\n if (typeof selectorOrTarget === 'string' || typeof selectorOrTarget === 'function') {\n const action = (typeof actionOrPropertyKey === 'string' ? actionOrPropertyKey : 'update') as StyleAction;\n const options = (typeof actionOrPropertyKey === 'object' ? actionOrPropertyKey : optionsOrDescriptor) as StyleApplyOptions | undefined;\n return createStyleDecorator(action)(selectorOrTarget, options);\n }\n // Without selector (defaults to $this)\n const action = (typeof selectorOrTarget === 'string' ? selectorOrTarget : 'update') as StyleAction;\n const options = (typeof selectorOrTarget === 'object' ? selectorOrTarget : actionOrPropertyKey) as StyleApplyOptions | undefined;\n return createStyleDecorator(action)('$this', options);\n}\n\nexport function setStyle(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;\nexport function setStyle(selector: string, options?: StyleQueryOptions): MethodDecorator;\nexport function setStyle(selector: StyleFnSelector, options?: StyleNonQueryOptions): MethodDecorator;\nexport function setStyle(selectorOrTarget?: any, optionsOrPropertyKey?: any, descriptor?: any): any {\n // Bare decorator: @setStyle\n if (descriptor !== undefined && (typeof optionsOrPropertyKey === 'string' || typeof optionsOrPropertyKey === 'symbol')) {\n return createStyleDecorator('set')('$this', {})(selectorOrTarget as Object, optionsOrPropertyKey, descriptor as PropertyDescriptor);\n }\n // With selector\n if (typeof selectorOrTarget === 'string' || typeof selectorOrTarget === 'function') {\n return createStyleDecorator('set')(selectorOrTarget, optionsOrPropertyKey as StyleApplyOptions);\n }\n // Without selector (defaults to $this)\n return createStyleDecorator('set')('$this', selectorOrTarget as StyleApplyOptions);\n}\n\nexport function updateStyle(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;\nexport function updateStyle(selector: string, options?: StyleQueryOptions): MethodDecorator;\nexport function updateStyle(selector: StyleFnSelector, options?: StyleNonQueryOptions): MethodDecorator;\nexport function updateStyle(selectorOrTarget?: any, optionsOrPropertyKey?: any, descriptor?: any): any {\n // Bare decorator: @updateStyle\n if (descriptor !== undefined && (typeof optionsOrPropertyKey === 'string' || typeof optionsOrPropertyKey === 'symbol')) {\n return createStyleDecorator('update')('$this', {})(selectorOrTarget as Object, optionsOrPropertyKey, descriptor as PropertyDescriptor);\n }\n // With selector\n if (typeof selectorOrTarget === 'string' || typeof selectorOrTarget === 'function') {\n return createStyleDecorator('update')(selectorOrTarget, optionsOrPropertyKey as StyleApplyOptions);\n }\n // Without selector (defaults to $this)\n return createStyleDecorator('update')('$this', selectorOrTarget as StyleApplyOptions);\n}\n\nexport function removeStyle(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;\nexport function removeStyle(selector: string, options?: StyleQueryOptions): MethodDecorator;\nexport function removeStyle(selector: StyleFnSelector, options?: StyleNonQueryOptions): MethodDecorator;\nexport function removeStyle(selectorOrTarget?: any, optionsOrPropertyKey?: any, descriptor?: any): any {\n // Bare decorator: @removeStyle\n if (descriptor !== undefined && (typeof optionsOrPropertyKey === 'string' || typeof optionsOrPropertyKey === 'symbol')) {\n return createStyleDecorator('remove')('$this', {})(selectorOrTarget as Object, optionsOrPropertyKey, descriptor as PropertyDescriptor);\n }\n // With selector\n if (typeof selectorOrTarget === 'string' || typeof selectorOrTarget === 'function') {\n return createStyleDecorator('remove')(selectorOrTarget, optionsOrPropertyKey as StyleApplyOptions);\n }\n // Without selector (defaults to $this)\n return createStyleDecorator('remove')('$this', selectorOrTarget as StyleApplyOptions);\n}\n\n// \u2500\u2500\u2500 Aliases \u2500\u2500\u2500\nexport const style = applyStyle;\n\n// \u2500\u2500\u2500 \uD3B8\uC758 \uD5EC\uD37C (selector/root \uC0DD\uB7B5) \u2500\u2500\u2500\n\nexport function styleThis(action?: StyleAction, options?: StyleQueryOptions): MethodDecorator {\n return applyStyle('$this', action, options);\n}\nexport function styleAppHost(action?: StyleAction, options?: StyleQueryOptions): MethodDecorator {\n return applyStyle('$appHost', action, options);\n}\nexport function styleLight(selector: string, action?: StyleAction, options?: Omit<StyleQueryOptions, 'root'>): MethodDecorator;\nexport function styleLight(selector: string, options?: Omit<StyleQueryOptions, 'root'>): MethodDecorator;\nexport function styleLight(selector: string, actionOrOptions?: StyleAction | Omit<StyleQueryOptions, 'root'>, options?: Omit<StyleQueryOptions, 'root'>): MethodDecorator {\n const action = (typeof actionOrOptions === 'string' ? actionOrOptions : undefined) as StyleAction | undefined;\n const opts = (typeof actionOrOptions === 'object' ? actionOrOptions : options) as Omit<StyleQueryOptions, 'root'> | undefined;\n return applyStyle(selector, action, {...opts ?? {}, root: 'light'});\n}\nexport function styleShadow(selector: string, action?: StyleAction, options?: Omit<StyleQueryOptions, 'root'>): MethodDecorator;\nexport function styleShadow(selector: string, options?: Omit<StyleQueryOptions, 'root'>): MethodDecorator;\nexport function styleShadow(selector: string, actionOrOptions?: StyleAction | Omit<StyleQueryOptions, 'root'>, options?: Omit<StyleQueryOptions, 'root'>): MethodDecorator {\n const action = (typeof actionOrOptions === 'string' ? actionOrOptions : undefined) as StyleAction | undefined;\n const opts = (typeof actionOrOptions === 'object' ? actionOrOptions : options) as Omit<StyleQueryOptions, 'root'> | undefined;\n return applyStyle(selector, action, {...opts ?? {}, root: 'shadow'});\n}\nexport function styleAll(selector: string, action?: StyleAction, options?: Omit<StyleQueryOptions, 'root'>): MethodDecorator;\nexport function styleAll(selector: string, options?: Omit<StyleQueryOptions, 'root'>): MethodDecorator;\nexport function styleAll(selector: string, actionOrOptions?: StyleAction | Omit<StyleQueryOptions, 'root'>, options?: Omit<StyleQueryOptions, 'root'>): MethodDecorator {\n const action = (typeof actionOrOptions === 'string' ? actionOrOptions : undefined) as StyleAction | undefined;\n const opts = (typeof actionOrOptions === 'object' ? actionOrOptions : options) as Omit<StyleQueryOptions, 'root'> | undefined;\n return applyStyle(selector, action, {...opts ?? {}, root: 'all'});\n}\n\nexport const findAllStyleMetadata = (target: any): Map<string | symbol, StyleApplyMetadata> => {\n const result = new Map<string | symbol, StyleApplyMetadata>();\n const maps = ReflectUtils.findAllMetadata<Map<string | symbol, StyleApplyMetadata>>(STYLE_METADATA_KEY, target);\n maps.forEach(map => {\n if (map instanceof Map) {\n map.forEach((v, k) => result.set(k, v));\n }\n });\n return result;\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA
|
|
4
|
+
"sourcesContent": ["import {ReflectUtils} from '@dooboostore/core';\nimport {ensureInit} from './elementDefine';\nimport {SwcUtils} from '../utils/Utils';\nimport { SpecialSelector, SwcQueryOptions, SwcFnSelector, SwcSelector, HelperHostSet } from '../types';\n\nexport type StyleAction = 'set' | 'update' | 'remove';\n\n// \uACF5\uD1B5 \uC635\uC158 \u2014 root \uC5C6\uC74C\nexport interface StyleBaseOptions {\n filter?: (target: HTMLElement, value: any, meta: {currentThis: any, helper: HelperHostSet}) => boolean;\n valueKey?: symbol | string;\n}\n\n// \uBB38\uC790\uC5F4 \uC140\uB809\uD130 \uC804\uC6A9 \u2014 root \uD5C8\uC6A9\nexport type StyleQueryOptions = StyleBaseOptions & SwcQueryOptions;\n// \uD568\uC218 \uC140\uB809\uD130 \uC804\uC6A9 \u2014 root \uAE08\uC9C0\nexport type StyleNonQueryOptions = StyleBaseOptions;\n// \uB0B4\uBD80 \uC800\uC7A5/\uD574\uC11D\uC6A9\nexport type StyleApplyOptions = StyleQueryOptions;\n\nexport type StyleFnSelector = SwcFnSelector;\nexport type StyleSelector = SwcSelector;\n\n// \uC140\uB809\uD130 \uC885\uB958\uC5D0 \uB530\uB77C \uC635\uC158 \uD0C0\uC785 \uBD84\uAE30\nexport type StyleOptionsOf<S extends StyleSelector> = S extends string ? StyleQueryOptions : StyleNonQueryOptions;\n\nexport interface StyleApplyMetadata {\n propertyKey: string | symbol;\n selector: StyleSelector;\n action: StyleAction;\n options: StyleApplyOptions;\n}\n\nexport const STYLE_METADATA_KEY = Symbol.for('simple-web-component:style');\n\n/**\n * Resolve selector to string or elements\n * Handles function-based selectors and returns elements if applicable\n */\nconst resolveSelector = (selector: StyleSelector, inst: any, win: Window): string | HTMLElement[] => {\n if (typeof selector === 'function') {\n const hostSet = SwcUtils.getHelperAndHostSet(inst);\n const result = selector(inst, hostSet);\n \n if (result instanceof win.Element) {\n return [result as HTMLElement];\n }\n if (result instanceof win.NodeList) {\n return Array.from(result) as HTMLElement[];\n }\n if (Array.isArray(result)) {\n return result as HTMLElement[];\n }\n if (result === null) {\n return [];\n }\n if (result instanceof win.Node) {\n return [];\n }\n return result as string;\n }\n return selector as string;\n};\n\n/**\n * Get target elements from selector\n */\nconst getTargetElements = (selector: StyleSelector, inst: any, win: Window, root: string): HTMLElement[] => {\n const resolved = resolveSelector(selector, inst, win);\n \n if (Array.isArray(resolved)) {\n return resolved;\n }\n\n const stringSelector = resolved as string;\n const targetEls: HTMLElement[] = [];\n const host = inst as unknown as HTMLElement;\n const hostSet = SwcUtils.getHelperAndHostSet(inst);\n\n const applyRoot = (t: any) => {\n if (!t || !(t instanceof win.HTMLElement)) return;\n targetEls.push(t);\n };\n\n if (stringSelector === '$this' || !stringSelector) applyRoot(host);\n else if (stringSelector === '$host') applyRoot(hostSet.$host);\n else if (stringSelector === '$parentHost') applyRoot(hostSet.$parentHost);\n else if (stringSelector === '$appHost') applyRoot(hostSet.$appHost);\n else if (stringSelector === '$firstHost') applyRoot(hostSet.$firstHost);\n else if (stringSelector === '$lastHost') applyRoot(hostSet.$lastHost);\n else if (stringSelector === '$firstAppHost') applyRoot(hostSet.$firstAppHost);\n else if (stringSelector === '$lastAppHost') applyRoot(hostSet.$lastAppHost);\n else if (stringSelector === '$hosts') hostSet.$hosts.forEach(applyRoot);\n else if (stringSelector === '$appHosts') hostSet.$appHosts.forEach(applyRoot);\n else {\n const targetRoot = root === 'auto' ? (host.shadowRoot || host) : (root === 'shadow' ? host.shadowRoot : host);\n if (targetRoot) {\n const found = targetRoot.querySelectorAll(stringSelector);\n if (found) targetEls.push(...(Array.from(found) as HTMLElement[]));\n }\n }\n\n return targetEls;\n};\n\nfunction createStyleDecorator(action: StyleAction) {\n return (selector: StyleSelector, options: StyleApplyOptions = {}): MethodDecorator => {\n return (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n const constructor = target.constructor;\n let metaList = ReflectUtils.getOwnMetadata(STYLE_METADATA_KEY, constructor) as Map<string | symbol, StyleApplyMetadata>;\n if (!metaList) {\n metaList = new Map<string | symbol, StyleApplyMetadata>();\n ReflectUtils.defineMetadata(STYLE_METADATA_KEY, metaList, constructor);\n }\n metaList.set(propertyKey, { propertyKey, selector, action, options });\n\n const original = descriptor.value;\n descriptor.value = function (...args: any[]) {\n ensureInit(this);\n const res = (original as any).apply(this, args);\n\n /**\n * Extract value for this decorator from method return value\n * \n * If return value is an object with this decorator's key,\n * use that value. Otherwise use the entire return value.\n * \n * Uses valueKey from options if provided, otherwise uses STYLE_METADATA_KEY.\n */\n const extractValue = (v: any) => {\n const keyToUse = options.valueKey ?? STYLE_METADATA_KEY;\n if (v && typeof v === 'object' && keyToUse in v) {\n return v[keyToUse];\n }\n return v;\n };\n\n const handleResult = (resolvedValue: any) => {\n if (resolvedValue !== undefined) {\n const win = (this as any).ownerDocument?.defaultView || window;\n const host = this as unknown as HTMLElement;\n const hostSet = { ...SwcUtils.getHelperAndHostSet(host), $this: this };\n const r = options.root || 'auto';\n const targetEls = getTargetElements(selector, this, win, r);\n\n targetEls.forEach(targetEl => {\n if (options.filter && !options.filter(targetEl, resolvedValue, {currentThis: this, helper: hostSet})) {\n return;\n }\n const resolvedRes = typeof resolvedValue === 'function' ? (resolvedValue as any)(targetEl, hostSet) : resolvedValue;\n\n if (action === 'set' || action === 'update') {\n if (action === 'set') targetEl.style.cssText = '';\n \n if (typeof resolvedRes === 'object' && resolvedRes !== null && !Array.isArray(resolvedRes)) {\n Object.entries(resolvedRes as any).forEach(([prop, val]) => {\n const finalVal = typeof val === 'function' ? val(targetEl, hostSet) : val;\n if (finalVal === null || finalVal === undefined) {\n targetEl.style.removeProperty(prop);\n } else {\n targetEl.style[prop as any] = String(finalVal);\n }\n });\n } else if (typeof resolvedRes === 'string') {\n targetEl.style.cssText = resolvedRes;\n }\n } else if (action === 'remove') {\n if (typeof resolvedRes === 'object' && resolvedRes !== null && !Array.isArray(resolvedRes)) {\n Object.entries(resolvedRes as any).forEach(([prop, val]) => {\n const shouldRemove = typeof val === 'function' ? val(targetEl, hostSet) : !!val;\n if (shouldRemove) {\n targetEl.style.removeProperty(prop);\n }\n });\n } else {\n const props = Array.isArray(resolvedRes) ? resolvedRes : [resolvedRes];\n props.forEach(p => targetEl.style.removeProperty(String(p)));\n }\n }\n });\n }\n return resolvedValue;\n };\n\n if (res instanceof Promise) {\n // \uC790\uAE30 \uBAAB(valueKey)\uB9CC \uC801\uC6A9\uD558\uACE0 \uC6D0\uB798 \uBC18\uD658\uAC12\uC740 \uADF8\uB300\uB85C \uC704\uB85C \uB118\uAE34\uB2E4 \u2014 \uC704\uC5D0 \uC313\uC778 \uB2E4\uB978 \uC544\uC6C3\uD48B\uB3C4 \uC790\uAE30 \uD0A4\uB97C \uCC3E\uAC8C\n return res.then((v: any) => { handleResult(extractValue(v)); return v; });\n } else {\n handleResult(extractValue(res));\n return res;\n }\n };\n return descriptor;\n };\n };\n}\n\nexport function applyStyle(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;\nexport function applyStyle(selector: string, action?: StyleAction, options?: StyleQueryOptions): MethodDecorator;\nexport function applyStyle(selector: StyleFnSelector, action?: StyleAction, options?: StyleNonQueryOptions): MethodDecorator;\nexport function applyStyle(selectorOrTarget?: any, actionOrPropertyKey?: any, optionsOrDescriptor?: any): any {\n // Bare decorator: @applyStyle\n if (optionsOrDescriptor !== undefined && typeof selectorOrTarget !== 'string' && typeof selectorOrTarget !== 'function' && (typeof actionOrPropertyKey === 'string' || typeof actionOrPropertyKey === 'symbol')) {\n return createStyleDecorator('update')('$this', {})(selectorOrTarget as Object, actionOrPropertyKey, optionsOrDescriptor as PropertyDescriptor);\n }\n // With selector\n if (typeof selectorOrTarget === 'string' || typeof selectorOrTarget === 'function') {\n const action = (typeof actionOrPropertyKey === 'string' ? actionOrPropertyKey : 'update') as StyleAction;\n const options = (typeof actionOrPropertyKey === 'object' ? actionOrPropertyKey : optionsOrDescriptor) as StyleApplyOptions | undefined;\n return createStyleDecorator(action)(selectorOrTarget, options);\n }\n // Without selector (defaults to $this)\n const action = (typeof selectorOrTarget === 'string' ? selectorOrTarget : 'update') as StyleAction;\n const options = (typeof selectorOrTarget === 'object' ? selectorOrTarget : actionOrPropertyKey) as StyleApplyOptions | undefined;\n return createStyleDecorator(action)('$this', options);\n}\n\nexport function setStyle(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;\nexport function setStyle(selector: string, options?: StyleQueryOptions): MethodDecorator;\nexport function setStyle(selector: StyleFnSelector, options?: StyleNonQueryOptions): MethodDecorator;\nexport function setStyle(selectorOrTarget?: any, optionsOrPropertyKey?: any, descriptor?: any): any {\n // Bare decorator: @setStyle\n if (descriptor !== undefined && (typeof optionsOrPropertyKey === 'string' || typeof optionsOrPropertyKey === 'symbol')) {\n return createStyleDecorator('set')('$this', {})(selectorOrTarget as Object, optionsOrPropertyKey, descriptor as PropertyDescriptor);\n }\n // With selector\n if (typeof selectorOrTarget === 'string' || typeof selectorOrTarget === 'function') {\n return createStyleDecorator('set')(selectorOrTarget, optionsOrPropertyKey as StyleApplyOptions);\n }\n // Without selector (defaults to $this)\n return createStyleDecorator('set')('$this', selectorOrTarget as StyleApplyOptions);\n}\n\nexport function updateStyle(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;\nexport function updateStyle(selector: string, options?: StyleQueryOptions): MethodDecorator;\nexport function updateStyle(selector: StyleFnSelector, options?: StyleNonQueryOptions): MethodDecorator;\nexport function updateStyle(selectorOrTarget?: any, optionsOrPropertyKey?: any, descriptor?: any): any {\n // Bare decorator: @updateStyle\n if (descriptor !== undefined && (typeof optionsOrPropertyKey === 'string' || typeof optionsOrPropertyKey === 'symbol')) {\n return createStyleDecorator('update')('$this', {})(selectorOrTarget as Object, optionsOrPropertyKey, descriptor as PropertyDescriptor);\n }\n // With selector\n if (typeof selectorOrTarget === 'string' || typeof selectorOrTarget === 'function') {\n return createStyleDecorator('update')(selectorOrTarget, optionsOrPropertyKey as StyleApplyOptions);\n }\n // Without selector (defaults to $this)\n return createStyleDecorator('update')('$this', selectorOrTarget as StyleApplyOptions);\n}\n\nexport function removeStyle(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;\nexport function removeStyle(selector: string, options?: StyleQueryOptions): MethodDecorator;\nexport function removeStyle(selector: StyleFnSelector, options?: StyleNonQueryOptions): MethodDecorator;\nexport function removeStyle(selectorOrTarget?: any, optionsOrPropertyKey?: any, descriptor?: any): any {\n // Bare decorator: @removeStyle\n if (descriptor !== undefined && (typeof optionsOrPropertyKey === 'string' || typeof optionsOrPropertyKey === 'symbol')) {\n return createStyleDecorator('remove')('$this', {})(selectorOrTarget as Object, optionsOrPropertyKey, descriptor as PropertyDescriptor);\n }\n // With selector\n if (typeof selectorOrTarget === 'string' || typeof selectorOrTarget === 'function') {\n return createStyleDecorator('remove')(selectorOrTarget, optionsOrPropertyKey as StyleApplyOptions);\n }\n // Without selector (defaults to $this)\n return createStyleDecorator('remove')('$this', selectorOrTarget as StyleApplyOptions);\n}\n\n// \u2500\u2500\u2500 Aliases \u2500\u2500\u2500\nexport const style = applyStyle;\n\n// \u2500\u2500\u2500 \uD3B8\uC758 \uD5EC\uD37C (selector/root \uC0DD\uB7B5) \u2500\u2500\u2500\n\nexport function styleAppHost(action: StyleAction, options?: StyleQueryOptions): MethodDecorator;\nexport function styleAppHost(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;\nexport function styleAppHost(actionOrTarget?: StyleAction | Object, optionsOrPropertyKey?: StyleQueryOptions | string | symbol, descriptor?: PropertyDescriptor): any {\n if ((typeof optionsOrPropertyKey === 'string' || typeof optionsOrPropertyKey === 'symbol') && descriptor !== undefined) {\n return (applyStyle('$appHost', undefined as any, {}) as any)(actionOrTarget, optionsOrPropertyKey, descriptor);\n }\n return applyStyle('$appHost', actionOrTarget as any, optionsOrPropertyKey as StyleQueryOptions);\n}\nexport function styleLight(selector: string, action?: StyleAction, options?: Omit<StyleQueryOptions, 'root'>): MethodDecorator;\nexport function styleLight(selector: string, options?: Omit<StyleQueryOptions, 'root'>): MethodDecorator;\nexport function styleLight(selector: string, actionOrOptions?: StyleAction | Omit<StyleQueryOptions, 'root'>, options?: Omit<StyleQueryOptions, 'root'>): MethodDecorator {\n const action = (typeof actionOrOptions === 'string' ? actionOrOptions : undefined) as StyleAction | undefined;\n const opts = (typeof actionOrOptions === 'object' ? actionOrOptions : options) as Omit<StyleQueryOptions, 'root'> | undefined;\n return applyStyle(selector, action, {...opts ?? {}, root: 'light'});\n}\nexport function styleShadow(selector: string, action?: StyleAction, options?: Omit<StyleQueryOptions, 'root'>): MethodDecorator;\nexport function styleShadow(selector: string, options?: Omit<StyleQueryOptions, 'root'>): MethodDecorator;\nexport function styleShadow(selector: string, actionOrOptions?: StyleAction | Omit<StyleQueryOptions, 'root'>, options?: Omit<StyleQueryOptions, 'root'>): MethodDecorator {\n const action = (typeof actionOrOptions === 'string' ? actionOrOptions : undefined) as StyleAction | undefined;\n const opts = (typeof actionOrOptions === 'object' ? actionOrOptions : options) as Omit<StyleQueryOptions, 'root'> | undefined;\n return applyStyle(selector, action, {...opts ?? {}, root: 'shadow'});\n}\nexport function styleAll(selector: string, action?: StyleAction, options?: Omit<StyleQueryOptions, 'root'>): MethodDecorator;\nexport function styleAll(selector: string, options?: Omit<StyleQueryOptions, 'root'>): MethodDecorator;\nexport function styleAll(selector: string, actionOrOptions?: StyleAction | Omit<StyleQueryOptions, 'root'>, options?: Omit<StyleQueryOptions, 'root'>): MethodDecorator {\n const action = (typeof actionOrOptions === 'string' ? actionOrOptions : undefined) as StyleAction | undefined;\n const opts = (typeof actionOrOptions === 'object' ? actionOrOptions : options) as Omit<StyleQueryOptions, 'root'> | undefined;\n return applyStyle(selector, action, {...opts ?? {}, root: 'all'});\n}\n\nexport const findAllStyleMetadata = (target: any): Map<string | symbol, StyleApplyMetadata> => {\n const result = new Map<string | symbol, StyleApplyMetadata>();\n const maps = ReflectUtils.findAllMetadata<Map<string | symbol, StyleApplyMetadata>>(STYLE_METADATA_KEY, target);\n maps.forEach(map => {\n if (map instanceof Map) {\n map.forEach((v, k) => result.set(k, v));\n }\n });\n return result;\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA2B;AAC3B,2BAAyB;AACzB,mBAAuB;AA+BhB,MAAM,qBAAqB,OAAO,IAAI,4BAA4B;AAMzE,MAAM,kBAAkB,CAAC,UAAyB,MAAW,QAAwC;AACnG,MAAI,OAAO,aAAa,YAAY;AAClC,UAAM,UAAU,sBAAS,oBAAoB,IAAI;AACjD,UAAM,SAAS,SAAS,MAAM,OAAO;AAErC,QAAI,kBAAkB,IAAI,SAAS;AACjC,aAAO,CAAC,MAAqB;A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,oBAAoB,WAAW,kBAAkB;AACxE,QAAM,OAAQ,OAAO,oBAAoB,WAAW,kBAAkB;AACtE,SAAO,WAAW,UAAU,QAAQ,EAAC,GAAG,QAAQ,CAAC,GAAG,MAAM,SAAQ,CAAC;AACrE;AAGO,SAAS,SAAS,UAAkB,iBAAiE,SAA4D;AACtK,QAAM,SAAU,OAAO,oBAAoB,WAAW,kBAAkB;AACxE,QAAM,OAAQ,OAAO,oBAAoB,WAAW,kBAAkB;AACtE,SAAO,WAAW,UAAU,QAAQ,EAAC,GAAG,QAAQ,CAAC,GAAG,MAAM,MAAK,CAAC;AAClE;AAEO,MAAM,uBAAuB,CAAC,WAA0D;AAC7F,QAAM,SAAS,oBAAI,IAAyC;AAC5D,QAAM,OAAO,yBAAa,gBAA0D,oBAAoB,MAAM;AAC9G,OAAK,QAAQ,SAAO;AAClB,QAAI,eAAe,KAAK;AACtB,UAAI,QAAQ,CAAC,GAAG,MAAM,OAAO,IAAI,GAAG,CAAC,CAAC;AAAA,IACxC;AAAA,EACF,CAAC;AACD,SAAO;AACT;",
|
|
6
6
|
"names": ["action", "options"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var around_exports = {};
|
|
19
|
+
__export(around_exports, {
|
|
20
|
+
AROUND_METADATA_KEY: () => AROUND_METADATA_KEY,
|
|
21
|
+
around: () => around,
|
|
22
|
+
findAllAroundMetadata: () => findAllAroundMetadata
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(around_exports);
|
|
25
|
+
var import_core = require("@dooboostore/core");
|
|
26
|
+
var import_elementDefine = require("./elementDefine");
|
|
27
|
+
var import_Utils = require("../utils/Utils");
|
|
28
|
+
const AROUND_METADATA_KEY = Symbol.for("simple-web-component:around");
|
|
29
|
+
const resolveHelperHostSet = (inst) => {
|
|
30
|
+
try {
|
|
31
|
+
(0, import_elementDefine.ensureInit)(inst);
|
|
32
|
+
return import_Utils.SwcUtils.getHelperAndHostSet(inst);
|
|
33
|
+
} catch {
|
|
34
|
+
return { $this: inst };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
function around(options = {}) {
|
|
38
|
+
return (target, propertyKey, descriptor) => {
|
|
39
|
+
if (descriptor && typeof descriptor.value === "function") {
|
|
40
|
+
const original = descriptor.value;
|
|
41
|
+
const runAfter = function(hhs, res) {
|
|
42
|
+
if (!options.after) return res;
|
|
43
|
+
const run = (v) => options.after.call(this, hhs, v);
|
|
44
|
+
return res && typeof res.then === "function" ? res.then(run) : run(res);
|
|
45
|
+
};
|
|
46
|
+
descriptor.value = function(...args) {
|
|
47
|
+
const hhs = resolveHelperHostSet(this);
|
|
48
|
+
const self = this;
|
|
49
|
+
const callOriginal = (finalArgs) => runAfter.call(self, hhs, original.apply(self, finalArgs));
|
|
50
|
+
const runBody = () => {
|
|
51
|
+
if (options.before) {
|
|
52
|
+
const mapped = options.before.call(self, hhs, args);
|
|
53
|
+
if (mapped && typeof mapped.then === "function") {
|
|
54
|
+
return mapped.then((m) => {
|
|
55
|
+
if (Array.isArray(m)) return callOriginal(m);
|
|
56
|
+
if (m !== void 0) return callOriginal([m]);
|
|
57
|
+
return callOriginal(args);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
if (Array.isArray(mapped)) return callOriginal(mapped);
|
|
61
|
+
if (mapped !== void 0) return callOriginal([mapped]);
|
|
62
|
+
}
|
|
63
|
+
return callOriginal(args);
|
|
64
|
+
};
|
|
65
|
+
if (!options.finally) return runBody();
|
|
66
|
+
const afterFin = (settle, ctx) => {
|
|
67
|
+
const f = options.finally.call(self, hhs, ctx);
|
|
68
|
+
return f && typeof f.then === "function" ? f.then(settle) : settle();
|
|
69
|
+
};
|
|
70
|
+
let out;
|
|
71
|
+
try {
|
|
72
|
+
out = runBody();
|
|
73
|
+
} catch (e) {
|
|
74
|
+
return afterFin(() => {
|
|
75
|
+
throw e;
|
|
76
|
+
}, { args, error: e });
|
|
77
|
+
}
|
|
78
|
+
if (out && typeof out.then === "function") {
|
|
79
|
+
return out.then(
|
|
80
|
+
(v) => afterFin(() => v, { args, result: v }),
|
|
81
|
+
(e) => afterFin(() => {
|
|
82
|
+
throw e;
|
|
83
|
+
}, { args, error: e })
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
return afterFin(() => out, { args, result: out });
|
|
87
|
+
};
|
|
88
|
+
return descriptor;
|
|
89
|
+
}
|
|
90
|
+
const constructor = target.constructor;
|
|
91
|
+
let aroundList = import_core.ReflectUtils.getOwnMetadata(AROUND_METADATA_KEY, constructor);
|
|
92
|
+
if (!aroundList) {
|
|
93
|
+
aroundList = [];
|
|
94
|
+
import_core.ReflectUtils.defineMetadata(AROUND_METADATA_KEY, aroundList, constructor);
|
|
95
|
+
}
|
|
96
|
+
aroundList.push({ propertyKey });
|
|
97
|
+
const storageKey = Symbol(`around:${String(propertyKey)}`);
|
|
98
|
+
const getFn = options.get;
|
|
99
|
+
const setFn = options.set;
|
|
100
|
+
Object.defineProperty(target, propertyKey, {
|
|
101
|
+
get() {
|
|
102
|
+
const own = Object.getOwnPropertyDescriptor(this, propertyKey);
|
|
103
|
+
if (own && "value" in own) {
|
|
104
|
+
delete this[propertyKey];
|
|
105
|
+
this[storageKey] = setFn ? setFn.call(this, resolveHelperHostSet(this), own.value) : own.value;
|
|
106
|
+
}
|
|
107
|
+
const raw = this[storageKey];
|
|
108
|
+
if (!getFn) return raw;
|
|
109
|
+
const mapped = getFn.call(this, resolveHelperHostSet(this), raw);
|
|
110
|
+
return mapped === void 0 ? raw : mapped;
|
|
111
|
+
},
|
|
112
|
+
set(value) {
|
|
113
|
+
this[storageKey] = setFn ? setFn.call(this, resolveHelperHostSet(this), value) : value;
|
|
114
|
+
},
|
|
115
|
+
enumerable: true,
|
|
116
|
+
configurable: true
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
const findAllAroundMetadata = (target) => {
|
|
121
|
+
const constructor = typeof target === "function" ? target : target.constructor;
|
|
122
|
+
return import_core.ReflectUtils.findAllMetadata(AROUND_METADATA_KEY, constructor).flat();
|
|
123
|
+
};
|
|
124
|
+
//# sourceMappingURL=around.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/decorators/around.ts"],
|
|
4
|
+
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core';\nimport { ensureInit } from './elementDefine';\nimport { SwcUtils } from '../utils/Utils';\nimport { HelperHostSet } from '../types';\n\nexport const AROUND_METADATA_KEY = Symbol.for('simple-web-component:around');\n\nexport interface AroundMetadata {\n propertyKey: string | symbol;\n}\n\nexport interface AroundPropertyOptions<Value = any> {\n /**\n * get\uD560 \uB54C (helperHostSet, \uC800\uC7A5\uB41C \uAC12)\uC744 \uBC1B\uC544 \uC2E4\uC81C\uB85C \uC77D\uB294 \uCABD\uC5D0 \uB3CC\uB824\uC904 \uAC12\uC744 \uB9AC\uD134\uD55C\uB2E4.\n * undefined \uB9AC\uD134\uC774\uBA74 \uC800\uC7A5\uAC12 \uADF8\uB300\uB85C \uD1B5\uACFC. \uC548 \uC8FC\uBA74 \uADF8\uB300\uB85C \uD1B5\uACFC.\n */\n get?: (helperHostSet: HelperHostSet, stored: Value) => Value | void;\n /**\n * set\uD560 \uB54C (helperHostSet, \uB300\uC785\uB418\uB294 \uAC12)\uC744 \uBC1B\uC544 \uC2E4\uC81C\uB85C \uC800\uC7A5\uD560 \uAC12\uC744 \uB9AC\uD134\uD55C\uB2E4.\n * \uC548 \uC8FC\uBA74 \uADF8\uB300\uB85C \uD1B5\uACFC.\n */\n set?: (helperHostSet: HelperHostSet, incoming: Value) => Value | void;\n}\nexport interface AroundOptions<Args extends any[] = any[], Return = any> {\n /**\n * \uC6D0\uBCF8 \uC2E4\uD589 \uC804\uC5D0, (helperHostSet, \uD638\uCD9C\uC790\uAC00 \uB118\uAE34 \uC778\uC790 \uBC30\uC5F4)\uC744 \uBC1B\uC544\n * \uC2E4\uC81C\uB85C \uC6D0\uBCF8\uC5D0 \uB118\uAE38 \uC778\uC790 \uBC30\uC5F4\uC744 \uB9AC\uD134\uD55C\uB2E4. undefined \uB9AC\uD134\uC774\uBA74 \uC778\uC790 \uADF8\uB300\uB85C \uD1B5\uACFC.\n * \uC6D0\uBCF8\uC774 Promise\uB97C \uB9AC\uD134\uD558\uBA74 before\uB3C4 Promise\uB97C \uB9AC\uD134\uD560 \uC218 \uC788\uB2E4 \u2014\n * resolve\uB41C \uAC12\uC73C\uB85C \uC6D0\uBCF8\uC774 \uD638\uCD9C\uB41C\uB2E4 (\uC774 \uACBD\uC6B0 \uB798\uD37C\uB3C4 Promise \uBC18\uD658).\n * \uC6D0\uBCF8\uC774 sync\uBA74 before\uB3C4 sync\uC5EC\uC57C \uD55C\uB2E4 (async\uB97C \uB2EC\uBA74 \uD638\uCD9C \uCE21\uC774 \uBAA8\uB974\uB294 Promise\uAC00 \uC0C8\uC5B4\uB098\uAC10).\n * \uC548 \uC8FC\uBA74 \uADF8\uB300\uB85C \uD1B5\uACFC.\n *\n * \uC81C\uB124\uB9AD \uC0DD\uB7B5 \uC2DC(Return=any) \uC591\uCABD \uB2E4 \uD5C8\uC6A9\uC774\uB77C \uB290\uC2A8\uD558\uAC8C \uB3D9\uC791\uD558\uACE0,\n * `@around<[number], number>`\uCC98\uB7FC \uBA85\uC2DC\uD558\uBA74 \uC704 \uADDC\uCE59\uC774 \uAC80\uC0AC\uB41C\uB2E4.\n */\n before?: (helperHostSet: HelperHostSet, args: Args) => Return extends Promise<any> ? Args | void | Promise<Args | void> : Args | void;\n /**\n * \uC6D0\uBCF8 \uC2E4\uD589 \uD6C4\uC5D0, (helperHostSet, \uB9AC\uD134\uAC12)\uC744 \uBC1B\uC544 \uC2E4\uC81C\uB85C \uD638\uCD9C\uC790\uC5D0\uAC8C\n * \uB3CC\uB824\uC904 \uAC12\uC744 \uB9AC\uD134\uD55C\uB2E4.\n * \uC6D0\uBCF8\uC774 Promise\uB97C \uB9AC\uD134\uD558\uBA74 resolve\uB41C \uAC12(Awaited<Return>)\uC744 \uB118\uACA8\uBC1B\uACE0,\n * after\uC758 \uB9AC\uD134\uAC12\uC774 \uADF8\uB300\uB85C \uCD5C\uC885 Promise\uC758 resolve \uAC12\uC774 \uB41C\uB2E4.\n * after\uAC00 Promise\uB97C \uB9AC\uD134\uD574\uB3C4 \uB41C\uB2E4 \u2014 resolve\uB41C \uAC12\uC774 \uCD5C\uC885\uAC12\uC774 \uB41C\uB2E4.\n * \uC548 \uC8FC\uBA74 \uADF8\uB300\uB85C \uD1B5\uACFC.\n *\n * \uC81C\uB124\uB9AD\uC744 \uBA85\uC2DC\uD558\uBA74 \uD6C5 \uC785\uCD9C\uB825\uC774 \uAC80\uC0AC\uB41C\uB2E4:\n * `@around<[string], Promise<string>>({ after: (h, r) => ... })`\n * (r\uC740 string\uC73C\uB85C \uCD94\uB860). \uC0DD\uB7B5\uD558\uBA74 any\uB85C \uB290\uC2A8\uD558\uAC8C \uB3D9\uC791\uD55C\uB2E4.\n * \uB2E8, legacy \uB370\uCF54\uB808\uC774\uD130 \uD55C\uACC4\uC0C1 \uB798\uD551\uB41C \uBA54\uC11C\uB4DC\uC758 \uAC89\uBCF4\uAE30 \uC2DC\uADF8\uB2C8\uCC98\uB294 \uC548 \uBC14\uB00C\uBBC0\uB85C\n * async \uD6C5\uC744 \uB2E8 sync \uBA54\uC11C\uB4DC\uB294 \uD638\uCD9C \uCE21\uC5D0\uC11C Promise\uB85C \uCDE8\uAE09\uD574\uC57C \uD55C\uB2E4.\n */\n after?: (helperHostSet: HelperHostSet, result: Awaited<Return>) => Return | Promise<Awaited<Return>>;\n /**\n * before/\uC6D0\uBCF8/after \uC2E4\uD589\uC774 \uB05D\uB098\uBA74 \uC131\uACF5\u00B7\uC2E4\uD328\uC640 \uBB34\uAD00\uD558\uAC8C \uD56D\uC0C1 \uC2E4\uD589\uB418\uB294 \uC815\uB9AC \uD6C5 (try/finally\uC758 finally).\n * \uB450 \uBC88\uC9F8 \uC778\uC790\uB85C \uCEE8\uD14D\uC2A4\uD2B8\uB97C \uBC1B\uB294\uB2E4:\n * - args: \uD638\uCD9C\uC790\uAC00 \uB118\uAE34 \uC6D0\uBCF8 \uC778\uC790 \uBC30\uC5F4(before \uAC00\uACF5 \uC804)\n * - result: \uC131\uACF5 \uC2DC \uCD5C\uC885 \uB9AC\uD134\uAC12(after \uC801\uC6A9 \uD6C4). \uC2E4\uD328 \uC2DC \uC5C6\uC74C.\n * - error: throw/reject \uC2DC \uADF8 \uC5D0\uB7EC. \uC131\uACF5 \uC2DC \uC5C6\uC74C.\n * \uC5D0\uB7EC\uB97C \uC0BC\uD0A4\uC9C0 \uC54A\uB294\uB2E4 \u2014 finally\uB97C \uBA3C\uC800 \uB3CC\uB9B0 \uB4A4 \uC6D0\uB798 \uC5D0\uB7EC/\uB9AC\uD134\uAC12\uC774 \uADF8\uB300\uB85C \uC804\uD30C\uB41C\uB2E4.\n * sync \uC6D0\uBCF8 + sync finally\uBA74 sync\uB85C \uC720\uC9C0\uB418\uC9C0\uB9CC, finally\uAC00 Promise\uB97C \uB9AC\uD134\uD558\uBA74\n * \uB798\uD37C\uB294 Promise\uB97C \uBC18\uD658\uD55C\uB2E4(async before/after\uC640 \uB3D9\uC77C \uADDC\uCE59).\n */\n finally?: (helperHostSet: HelperHostSet, ctx: { args: Args; result?: Awaited<Return>; error?: any }) => void | Promise<void>;\n}\n\n/** \uC778\uC2A4\uD134\uC2A4\uC5D0\uC11C HelperHostSet\uC744 \uD574\uC11D\uD55C\uB2E4 \u2014 \uC2E4\uD328(SSR/\uBBF8\uCD08\uAE30\uD654)\uD558\uBA74 \uCD5C\uC18C \uD3F4\uBC31\uC744 \uB3CC\uB824\uC900\uB2E4. */\nconst resolveHelperHostSet = (inst: any): HelperHostSet => {\n try {\n ensureInit(inst);\n return SwcUtils.getHelperAndHostSet(inst);\n } catch {\n return { $this: inst } as HelperHostSet;\n }\n};\n\n/**\n * \uBA54\uC11C\uB4DC\uC5D0 \uAC78\uBA74 \uD638\uCD9C\uC744 \uAC10\uC2F8\uC11C \uD638\uCD9C \uC804(\uC778\uC790 \uAC00\uACF5)/\uD6C4(\uB9AC\uD134\uAC12 \uAC00\uACF5) \uD6C5\uC744 \uAC74\uB2E4 - AOP\uC758 \"around advice\".\n *\n * @around({\n * before: (h, args: [number, string]) => [args[0], args[1].toUpperCase()],\n * after: (h, r: string) => r + '!'\n * })\n * greet(a: number, b: string) { return `${a}:${b}`; }\n *\n * \uD504\uB85C\uD37C\uD2F0(\uD544\uB4DC)\uC5D0 \uAC78\uBA74 get/set\uC744 \uAC00\uB85C\uCC48\uB2E4 - get\uC740 get, set\uC740 set\uC774 \uD638\uCD9C\uB41C\uB2E4.\n * (\uD504\uB85C\uD37C\uD2F0 \uACBD\uB85C\uC5D0\uC11C\uB294 \uAC12\uC774 \uBC30\uC5F4\uC774 \uC544\uB2C8\uB77C \uB2E8\uC77C\uAC12\uC73C\uB85C \uB118\uC5B4\uAC04\uB2E4)\n * \uD544\uB4DC \uC774\uB2C8\uC15C\uB77C\uC774\uC800(`wow = 'x'`)\uAC00 \uC788\uC5B4\uB3C4 \uB41C\uB2E4 \u2014 ensureInit\uC774 state\uCC98\uB7FC\n * \uCD08\uAE30\uAC12\uC744 \uC0B4\uB824 setter \uACBD\uC720\uB85C \uC815\uB9AC\uD558\uBBC0\uB85C \uCD08\uAE30\uAC12\uC5D0\uB3C4 set()\uC774 \uC801\uC6A9\uB41C\uB2E4.\n * (\uB2E8, custom element\uAC00 \uC544\uB2CC \uC77C\uBC18 \uD074\uB798\uC2A4\uC5D0\uC11C\uB294 ensureInit\uC774 \uC548 \uB3CC\uBBC0\uB85C\n * `declare` + \uC0DD\uC131\uC790 \uB300\uC785\uC73C\uB85C \uC4F8 \uAC83)\n *\n * @around({\n * get: (h, stored: string) => stored?.toUpperCase(),\n * set: (h, incoming: string) => incoming?.trim()\n * })\n * wow: string = ' hi ';\n */\nexport function around<Args extends any[] = any[], Return = any>(options: AroundOptions<NoInfer<Args>, NoInfer<Return>>): MethodDecorator;\nexport function around<Value = any>(options: AroundPropertyOptions<NoInfer<Value>>): PropertyDecorator;\nexport function around(options: any = {}): MethodDecorator & PropertyDecorator {\n return ((target: Object, propertyKey: string | symbol, descriptor?: PropertyDescriptor) => {\n // \uBA54\uC11C\uB4DC: descriptor.value\uAC00 \uC2E4\uC81C \uD568\uC218\uC77C \uB54C\uB9CC (\uC774\uBBF8 \uC815\uC758\uB41C \uC811\uADFC\uC790\uB97C \uAC10\uC2F8\uB294 \uAC74 \uC9C0\uC6D0 \uBC94\uC704 \uBC16)\n if (descriptor && typeof descriptor.value === 'function') {\n const original = descriptor.value;\n const runAfter = function (this: any, hhs: HelperHostSet, res: any) {\n if (!options.after) return res;\n const run = (v: any) => (options.after as any).call(this, hhs, v);\n // after\uAC00 Promise\uB97C \uB9AC\uD134\uD558\uBA74 resolve\uB41C \uAC12\uC774 \uCD5C\uC885\uAC12\uC774 \uB41C\uB2E4 (then \uD50C\uB798\uD2B8\uB2DD).\n return res && typeof res.then === 'function' ? res.then(run) : run(res);\n };\n descriptor.value = function (this: any, ...args: any[]) {\n const hhs = resolveHelperHostSet(this);\n const self = this;\n const callOriginal = (finalArgs: any[]) => runAfter.call(self, hhs, original.apply(self, finalArgs));\n const runBody = () => {\n if (options.before) {\n const mapped = (options.before as any).call(self, hhs, args);\n if (mapped && typeof mapped.then === 'function') {\n // async before \u2014 resolve\uB41C \uC778\uC790\uB85C \uC6D0\uBCF8 \uD638\uCD9C, \uB798\uD37C\uB294 Promise \uBC18\uD658.\n // (sync \uC6D0\uBCF8 + sync \uD6C5\uC77C \uB54C\uB9CC sync \uBC18\uD658\uC774 \uC720\uC9C0\uB41C\uB2E4)\n return mapped.then((m: any) => {\n if (Array.isArray(m)) return callOriginal(m);\n if (m !== undefined) return callOriginal([m]);\n return callOriginal(args);\n });\n }\n if (Array.isArray(mapped)) return callOriginal(mapped);\n if (mapped !== undefined) return callOriginal([mapped]);\n }\n return callOriginal(args);\n };\n if (!options.finally) return runBody();\n // sync/async \uD22C\uBA85\uC131\uC744 \uC9C0\uD0A4\uB294 try/finally \u2014 \uC5D0\uB7EC\uB294 \uC0BC\uD0A4\uC9C0 \uC54A\uACE0 finally \uD6C4 \uC804\uD30C.\n const afterFin = (settle: () => any, ctx: { args: any[]; result?: any; error?: any }) => {\n const f = (options.finally as any).call(self, hhs, ctx);\n return f && typeof f.then === 'function' ? f.then(settle) : settle();\n };\n let out: any;\n try {\n out = runBody();\n } catch (e) {\n return afterFin(() => { throw e; }, { args, error: e });\n }\n if (out && typeof out.then === 'function') {\n return out.then(\n (v: any) => afterFin(() => v, { args, result: v }),\n (e: any) => afterFin(() => { throw e; }, { args, error: e })\n );\n }\n return afterFin(() => out, { args, result: out });\n };\n return descriptor;\n }\n\n // \uD504\uB85C\uD37C\uD2F0: ensureInit\uC5D0\uC11C own property\uB97C \uC815\uB9AC\uD560 \uC218 \uC788\uB3C4\uB85D \uBA54\uD0C0\uB370\uC774\uD130 \uB4F1\uB85D (state.ts\uC640 \uB3D9\uC77C \uD328\uD134).\n // \uD544\uB4DC \uC774\uB2C8\uC15C\uB77C\uC774\uC800\uAC00 \uC788\uC73C\uBA74 own property\uAC00 accessor\uB97C \uAC00\uB9AC\uBBC0\uB85C getter\uAC00 \uC601\uC6D0\uD788 \uC548 \uBD88\uB9BC \u2014\n // getter \uC548\uC758 \uC790\uCCB4\uC774\uC8FC\uB294 \uB9C8\uC9C0\uB9C9 \uC548\uC804\uB9DD\uC77C \uBFD0, \uC2E4\uC9C8\uC801\uC778 \uC0B4\uB9BC\uC740 ensureInit\uC774 \uD55C\uB2E4.\n const constructor = (target as any).constructor;\n let aroundList = ReflectUtils.getOwnMetadata(AROUND_METADATA_KEY, constructor) as AroundMetadata[] | undefined;\n if (!aroundList) {\n aroundList = [];\n ReflectUtils.defineMetadata(AROUND_METADATA_KEY, aroundList, constructor);\n }\n aroundList.push({ propertyKey });\n\n // target\uC740 prototype\uC774\uB77C \uC5EC\uAE30 \uAC12\uC744 \uC9C1\uC811 \uB450\uBA74 \uBAA8\uB4E0 \uC778\uC2A4\uD134\uC2A4\uAC00 \uACF5\uC720\uD574\uBC84\uB9B0\uB2E4.\n // \uC778\uC2A4\uD134\uC2A4\uBCC4\uB85C \uB530\uB85C \uC800\uC7A5\uB418\uB3C4\uB85D \uC778\uC2A4\uD134\uC2A4 \uC804\uC6A9 Symbol \uC2AC\uB86F(this[storageKey])\uC5D0 \uC2E4\uC81C \uAC12\uC744 \uB454\uB2E4.\n const storageKey = Symbol(`around:${String(propertyKey)}`);\n const getFn = (options as AroundPropertyOptions).get as unknown as ((hhs: HelperHostSet, value: any) => any) | undefined;\n const setFn = (options as AroundPropertyOptions).set as unknown as ((hhs: HelperHostSet, value: any) => any) | undefined;\n Object.defineProperty(target, propertyKey, {\n get(this: any) {\n // \uC548\uC804\uB9DD: \uB204\uAD70\uAC00 plain delete\uB85C own\uC744 \uAC77\uC5B4\uB0B8 \uB4A4\uB77C\uBA74 \uC5EC\uAE30\uC11C \uC2AC\uB86F\uC73C\uB85C \uD68C\uC218\uD55C\uB2E4.\n // (\uC815\uC0C1 \uACBD\uB85C\uC5D0\uC11C\uB294 ensureInit\uC774 \uC774\uBBF8 setter \uACBD\uC720\uB85C \uC815\uB9AC\uD588\uC73C\uBBC0\uB85C own\uC774 \uC5C6\uC74C)\n const own = Object.getOwnPropertyDescriptor(this, propertyKey);\n if (own && 'value' in own) {\n delete this[propertyKey];\n this[storageKey] = setFn ? setFn.call(this, resolveHelperHostSet(this), own.value) : own.value;\n }\n const raw = this[storageKey];\n if (!getFn) return raw;\n const mapped = getFn.call(this, resolveHelperHostSet(this), raw);\n return mapped === undefined ? raw : mapped;\n },\n set(this: any, value: any) {\n this[storageKey] = setFn ? setFn.call(this, resolveHelperHostSet(this), value) : value;\n },\n enumerable: true,\n configurable: true\n });\n }) as MethodDecorator & PropertyDecorator;\n}\n\nexport const findAllAroundMetadata = (target: any): AroundMetadata[] => {\n const constructor = typeof target === 'function' ? target : target.constructor;\n return ReflectUtils.findAllMetadata<any[]>(AROUND_METADATA_KEY, constructor).flat();\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA6B;AAC7B,2BAA2B;AAC3B,mBAAyB;AAGlB,MAAM,sBAAsB,OAAO,IAAI,6BAA6B;AA4D3E,MAAM,uBAAuB,CAAC,SAA6B;AACzD,MAAI;AACF,yCAAW,IAAI;AACf,WAAO,sBAAS,oBAAoB,IAAI;AAAA,EAC1C,QAAQ;AACN,WAAO,EAAE,OAAO,KAAK;AAAA,EACvB;AACF;AA0BO,SAAS,OAAO,UAAe,CAAC,GAAwC;AAC7E,SAAQ,CAAC,QAAgB,aAA8B,eAAoC;AAEzF,QAAI,cAAc,OAAO,WAAW,UAAU,YAAY;AACxD,YAAM,WAAW,WAAW;AAC5B,YAAM,WAAW,SAAqB,KA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I;AAAA,MACnF;AAAA,MACA,YAAY;AAAA,MACZ,cAAc;AAAA,IAChB,CAAC;AAAA,EACH;AACF;AAEO,MAAM,wBAAwB,CAAC,WAAkC;AACtE,QAAM,cAAc,OAAO,WAAW,aAAa,SAAS,OAAO;AACnE,SAAO,yBAAa,gBAAuB,qBAAqB,WAAW,EAAE,KAAK;AACpF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -29,35 +29,40 @@ __export(changedAttribute_exports, {
|
|
|
29
29
|
module.exports = __toCommonJS(changedAttribute_exports);
|
|
30
30
|
var import_core = require("@dooboostore/core");
|
|
31
31
|
var import_applyAttribute = require("./applyAttribute");
|
|
32
|
+
var import_Utils = require("../utils/Utils");
|
|
33
|
+
var import_parameter = require("./parameter");
|
|
32
34
|
const ON_ATTRIBUTE_CHANGED_METADATA_KEY = Symbol.for("simple-web-component:on-attribute-changed");
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (
|
|
37
|
-
|
|
35
|
+
const applyChangedAttribute = (attributeName, options, target, propertyKey) => {
|
|
36
|
+
const constructor = target.constructor;
|
|
37
|
+
let metaList = import_core.ReflectUtils.getOwnMetadata(ON_ATTRIBUTE_CHANGED_METADATA_KEY, constructor);
|
|
38
|
+
if (!metaList) {
|
|
39
|
+
metaList = [];
|
|
40
|
+
import_core.ReflectUtils.defineMetadata(ON_ATTRIBUTE_CHANGED_METADATA_KEY, metaList, constructor);
|
|
41
|
+
}
|
|
42
|
+
const name = attributeName || String(propertyKey);
|
|
43
|
+
metaList.push({
|
|
44
|
+
attributeName: name,
|
|
45
|
+
propertyKey,
|
|
46
|
+
options
|
|
47
|
+
});
|
|
38
48
|
};
|
|
39
|
-
function changedAttribute(
|
|
49
|
+
function changedAttribute(attributeNameOrTarget, optionsOrPropertyKey, descriptor) {
|
|
50
|
+
if ((typeof optionsOrPropertyKey === "string" || typeof optionsOrPropertyKey === "symbol") && descriptor !== void 0) {
|
|
51
|
+
applyChangedAttribute(void 0, {}, attributeNameOrTarget, optionsOrPropertyKey);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const attributeName = attributeNameOrTarget;
|
|
55
|
+
const options = optionsOrPropertyKey ?? {};
|
|
40
56
|
return (target, propertyKey) => {
|
|
41
|
-
|
|
42
|
-
let metaList = import_core.ReflectUtils.getOwnMetadata(ON_ATTRIBUTE_CHANGED_METADATA_KEY, constructor);
|
|
43
|
-
if (!metaList) {
|
|
44
|
-
metaList = [];
|
|
45
|
-
import_core.ReflectUtils.defineMetadata(ON_ATTRIBUTE_CHANGED_METADATA_KEY, metaList, constructor);
|
|
46
|
-
}
|
|
47
|
-
const name = attributeName || String(propertyKey);
|
|
48
|
-
metaList.push({
|
|
49
|
-
attributeName: name,
|
|
50
|
-
propertyKey,
|
|
51
|
-
options
|
|
52
|
-
});
|
|
57
|
+
applyChangedAttribute(attributeName, options, target, propertyKey);
|
|
53
58
|
};
|
|
54
59
|
}
|
|
55
60
|
const getChangedAttributeMetadata = (target) => {
|
|
56
|
-
const constructor = target
|
|
57
|
-
return import_core.ReflectUtils.
|
|
61
|
+
const constructor = typeof target === "function" ? target : target.constructor;
|
|
62
|
+
return import_core.ReflectUtils.findAllMetadata(ON_ATTRIBUTE_CHANGED_METADATA_KEY, constructor).flat();
|
|
58
63
|
};
|
|
59
64
|
const findAllAttributeChangedMetadata = (target) => {
|
|
60
|
-
const constructor = target
|
|
65
|
+
const constructor = typeof target === "function" ? target : target.constructor;
|
|
61
66
|
const metaList = import_core.ReflectUtils.findAllMetadata(ON_ATTRIBUTE_CHANGED_METADATA_KEY, constructor) || [];
|
|
62
67
|
const result = /* @__PURE__ */ new Map();
|
|
63
68
|
metaList.forEach((meta) => {
|
|
@@ -71,7 +76,7 @@ const findAllAttributeChangedMetadata = (target) => {
|
|
|
71
76
|
return result;
|
|
72
77
|
};
|
|
73
78
|
const convertAttributeValue = (val, type) => {
|
|
74
|
-
return convertValue(val, type);
|
|
79
|
+
return (0, import_applyAttribute.convertValue)(val, type);
|
|
75
80
|
};
|
|
76
81
|
class ChangedAttributeLifeCycler {
|
|
77
82
|
constructor() {
|
|
@@ -92,7 +97,7 @@ class ChangedAttributeLifeCycler {
|
|
|
92
97
|
for (const meta of metaList) {
|
|
93
98
|
if (meta.options.while === "connected") {
|
|
94
99
|
const val = (0, import_applyAttribute.getAttributeValue)(inst, name, { type: meta.options.type });
|
|
95
|
-
if (val !== null)
|
|
100
|
+
if (val !== null) this.runChanged(helperHostSet, meta, val, null, name);
|
|
96
101
|
}
|
|
97
102
|
}
|
|
98
103
|
}
|
|
@@ -104,8 +109,40 @@ class ChangedAttributeLifeCycler {
|
|
|
104
109
|
if (!metaList) return;
|
|
105
110
|
for (const meta of metaList) {
|
|
106
111
|
if (meta.options.while === "connected" && !inst.__swc_connected) continue;
|
|
107
|
-
|
|
112
|
+
this.runChanged(helperHostSet, meta, convertAttributeValue(newVal, meta.options.type), old, name);
|
|
108
113
|
}
|
|
109
114
|
}
|
|
115
|
+
// filter(async)/before/finally + @changedAttributeBeforeReturn 주입. fire-and-forget.
|
|
116
|
+
runChanged(helperHostSet, meta, value, old, name) {
|
|
117
|
+
const inst = helperHostSet.$this;
|
|
118
|
+
const opts = meta.options;
|
|
119
|
+
void (async () => {
|
|
120
|
+
const helper = import_Utils.SwcUtils.getHelperAndHostSet(inst);
|
|
121
|
+
if (opts.filter && !await opts.filter(value, { currentThis: inst, helper })) return;
|
|
122
|
+
const hostSet = import_Utils.SwcUtils.getHostSet(inst);
|
|
123
|
+
const helperSet = import_Utils.SwcUtils.getHelperSet(helperHostSet.$w);
|
|
124
|
+
const legacyArgs = [value, old, name, helper];
|
|
125
|
+
const buildArgs = (beforeReturn) => (0, import_parameter.buildSwcParameterArgs)(inst, meta.propertyKey, {
|
|
126
|
+
hostSet,
|
|
127
|
+
helperHostSet: helper,
|
|
128
|
+
helperSet,
|
|
129
|
+
changedAttributeBeforeReturn: beforeReturn
|
|
130
|
+
}, [...legacyArgs, beforeReturn]);
|
|
131
|
+
let args = buildArgs(void 0);
|
|
132
|
+
if (opts.before) {
|
|
133
|
+
const br = await opts.before(value, { currentThis: inst, helper });
|
|
134
|
+
args = buildArgs(br);
|
|
135
|
+
}
|
|
136
|
+
let result, error;
|
|
137
|
+
try {
|
|
138
|
+
result = await inst[meta.propertyKey](...args);
|
|
139
|
+
} catch (e) {
|
|
140
|
+
error = e;
|
|
141
|
+
} finally {
|
|
142
|
+
if (opts.finally) await opts.finally(value, { currentThis: inst, helper }, { args, result, error });
|
|
143
|
+
}
|
|
144
|
+
if (error) throw error;
|
|
145
|
+
})().catch((e) => console.error("[SWC] changedAttribute handler error:", e));
|
|
146
|
+
}
|
|
110
147
|
}
|
|
111
148
|
//# sourceMappingURL=changedAttribute.js.map
|