@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
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { ReflectUtils } from "@dooboostore/core";
|
|
2
|
+
import { ensureInit } from "./elementDefine.js";
|
|
3
|
+
import { SwcUtils } from "../utils/Utils.js";
|
|
4
|
+
const REQUEST_ANIMATION_FRAME_METADATA_KEY = Symbol.for("simple-web-component:request-animation-frame");
|
|
5
|
+
const getActiveEntries = (inst) => inst.__swc_requestAnimationFrameIds ?? (inst.__swc_requestAnimationFrameIds = []);
|
|
6
|
+
const startFrameLoop = (win, entries, frameFn) => {
|
|
7
|
+
let currentId = 0;
|
|
8
|
+
const step = (timestamp, prevValue) => {
|
|
9
|
+
const idx = entries.indexOf(currentId);
|
|
10
|
+
if (idx >= 0) entries.splice(idx, 1);
|
|
11
|
+
let result;
|
|
12
|
+
try {
|
|
13
|
+
result = frameFn(timestamp, prevValue);
|
|
14
|
+
} catch (e) {
|
|
15
|
+
console.error("[SWC] requestAnimationFrame callback error:", e);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (result === void 0 || result === null) return;
|
|
19
|
+
currentId = win.requestAnimationFrame((ts) => step(ts, result));
|
|
20
|
+
entries.push(currentId);
|
|
21
|
+
};
|
|
22
|
+
currentId = win.requestAnimationFrame((ts) => step(ts, void 0));
|
|
23
|
+
entries.push(currentId);
|
|
24
|
+
return currentId;
|
|
25
|
+
};
|
|
26
|
+
const applyRequestAnimationFrame = (options, target, propertyKey, descriptor) => {
|
|
27
|
+
const constructor = target.constructor;
|
|
28
|
+
const normalizedOptions = { ...options, type: options.type ?? "returnValue" };
|
|
29
|
+
let metaList = ReflectUtils.getOwnMetadata(REQUEST_ANIMATION_FRAME_METADATA_KEY, constructor);
|
|
30
|
+
if (!metaList) {
|
|
31
|
+
metaList = [];
|
|
32
|
+
ReflectUtils.defineMetadata(REQUEST_ANIMATION_FRAME_METADATA_KEY, metaList, constructor);
|
|
33
|
+
}
|
|
34
|
+
metaList.push({ propertyKey, options: normalizedOptions });
|
|
35
|
+
if (normalizedOptions.type === "onConnected" || !descriptor) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const original = descriptor.value;
|
|
39
|
+
descriptor.value = function(...args) {
|
|
40
|
+
const res = original.apply(this, args);
|
|
41
|
+
const vk = normalizedOptions.valueKey ?? REQUEST_ANIMATION_FRAME_METADATA_KEY;
|
|
42
|
+
const frameFn = typeof res === "function" ? res : res && typeof res === "object" && typeof res[vk] === "function" ? res[vk] : void 0;
|
|
43
|
+
if (frameFn) {
|
|
44
|
+
ensureInit(this);
|
|
45
|
+
const win = SwcUtils.resolveWindow(this);
|
|
46
|
+
const id = startFrameLoop(win, getActiveEntries(this), frameFn);
|
|
47
|
+
normalizedOptions.created?.(SwcUtils.getHelperAndHostSet(this), id);
|
|
48
|
+
}
|
|
49
|
+
return res;
|
|
50
|
+
};
|
|
51
|
+
return descriptor;
|
|
52
|
+
};
|
|
53
|
+
function requestAnimationFrame(optionsOrTarget, propertyKey, descriptor) {
|
|
54
|
+
if (propertyKey !== void 0) {
|
|
55
|
+
applyRequestAnimationFrame({}, optionsOrTarget, propertyKey, descriptor);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
return (target, propertyKey2, descriptor2) => {
|
|
59
|
+
return applyRequestAnimationFrame(optionsOrTarget ?? {}, target, propertyKey2, descriptor2);
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
const findAllRequestAnimationFrameMetadata = (target) => {
|
|
63
|
+
const constructor = typeof target === "function" ? target : target.constructor;
|
|
64
|
+
return (ReflectUtils.findAllMetadata(REQUEST_ANIMATION_FRAME_METADATA_KEY, constructor) || []).flat();
|
|
65
|
+
};
|
|
66
|
+
class RequestAnimationFrameLifeCycler {
|
|
67
|
+
onConnected(helperHostSet) {
|
|
68
|
+
const inst = helperHostSet.$this;
|
|
69
|
+
inst.__swc_requestAnimationFrameIds = [];
|
|
70
|
+
const entries = getActiveEntries(inst);
|
|
71
|
+
for (const meta of findAllRequestAnimationFrameMetadata(inst)) {
|
|
72
|
+
if (meta.options.type !== "onConnected") continue;
|
|
73
|
+
const frameFn = (timestamp, prevValue) => inst[meta.propertyKey](timestamp, prevValue);
|
|
74
|
+
const id = startFrameLoop(helperHostSet.$w, entries, frameFn);
|
|
75
|
+
meta.options.created?.(helperHostSet, id);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
onDisconnected(helperHostSet) {
|
|
79
|
+
const inst = helperHostSet.$this;
|
|
80
|
+
for (const id of inst.__swc_requestAnimationFrameIds ?? []) {
|
|
81
|
+
try {
|
|
82
|
+
helperHostSet.$w.cancelAnimationFrame(id);
|
|
83
|
+
} catch (e) {
|
|
84
|
+
console.error("[SWC] cancelAnimationFrame error:", e);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
inst.__swc_requestAnimationFrameIds = [];
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
export {
|
|
91
|
+
REQUEST_ANIMATION_FRAME_METADATA_KEY,
|
|
92
|
+
RequestAnimationFrameLifeCycler,
|
|
93
|
+
findAllRequestAnimationFrameMetadata,
|
|
94
|
+
requestAnimationFrame
|
|
95
|
+
};
|
|
96
|
+
//# sourceMappingURL=requestAnimationFrame.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/decorators/requestAnimationFrame.ts"],
|
|
4
|
+
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core';\nimport { ensureInit } from './elementDefine';\nimport { SwcUtils } from '../utils/Utils';\nimport { ElementDefineLifeCycler, HelperHostSet } from '../types';\n\nexport const REQUEST_ANIMATION_FRAME_METADATA_KEY = Symbol.for('simple-web-component:request-animation-frame');\n\nexport type RequestAnimationFrameType = 'onConnected' | 'returnValue';\n\nexport interface RequestAnimationFrameOptions {\n /**\n * 'onConnected' - connect \uC2DC \uC790\uB3D9\uC73C\uB85C \uB8E8\uD504 \uC2DC\uC791 (\uB9E4 \uD504\uB808\uC784 \uB370\uCF54\uB808\uC774\uD2B8\uB41C \uBA54\uC11C\uB4DC\uB97C \uC9C1\uC811 \uD638\uCD9C), disconnect \uC2DC \uC790\uB3D9 \uC815\uB9AC.\n * 'returnValue'(\uAE30\uBCF8\uAC12) - \uC790\uB3D9 \uC2DC\uC791 \uC5C6\uC74C. \uAC1C\uBC1C\uC790\uAC00 \uC774 \uBA54\uC11C\uB4DC\uB97C \uC9C1\uC811 \uD638\uCD9C\uD574\uC57C \uC2DC\uC791\uB418\uACE0,\n * \uADF8 \uD638\uCD9C\uC758 \uB9AC\uD134\uAC12(\uB610\uB294 valueKey\uB85C \uBF51\uC740 \uAC12)\uC774 \uC2E4\uC81C\uB85C \uB9E4 \uD504\uB808\uC784 \uD638\uCD9C\uB420 \uD568\uC218\uAC00 \uB41C\uB2E4.\n */\n type?: RequestAnimationFrameType;\n /** \uB8E8\uD504 \uC2DC\uC791 \uC9C1\uD6C4 1\uD68C \uD638\uCD9C (\uB514\uBC84\uAE45/\uB85C\uAE45\uC6A9). id\uB294 \uCCAB requestAnimationFrame \uBC18\uD658\uAC12 - cleanup\uC740 \uC790\uB3D9\uC73C\uB85C \uCC98\uB9AC\uB418\uBBC0\uB85C \uC9C1\uC811 \uCDE8\uC18C\uD560 \uD544\uC694 \uC5C6\uC74C. */\n created?: (set: HelperHostSet, id: number) => void;\n /**\n * type:'returnValue' \uC804\uC6A9 - \uB9AC\uD134\uAC12\uC774 \uD568\uC218\uBA74 \uADF8 \uC790\uCCB4\uB97C, \uAC1D\uCCB4\uBA74 \uC774 \uD0A4\uC758 \uAC12\uC774 \uD568\uC218\uC77C \uB54C \uADF8 \uAC12\uC744\n * \"\uB9E4 \uD504\uB808\uC784 \uD638\uCD9C\uB420 \uD568\uC218\"\uB85C \uC0AC\uC6A9\uD55C\uB2E4. \uC548 \uC8FC\uBA74 REQUEST_ANIMATION_FRAME_METADATA_KEY\uB85C \uD3F4\uBC31\uD55C\uB2E4 -\n * applyAttribute.ts/applyNode.ts\uC758 valueKey\uC640 \uB3D9\uC77C\uD55C \uCEE8\uBCA4\uC158.\n */\n valueKey?: symbol | string;\n}\n\nexport interface RequestAnimationFrameMetadata {\n propertyKey: string | symbol;\n options: RequestAnimationFrameOptions;\n}\n\n/**\n * \uD504\uB808\uC784 \uCF5C\uBC31 \uC2DC\uADF8\uB2C8\uCC98.\n * - timestamp: \uC774\uBC88 \uD504\uB808\uC784\uC758 \uC2DC\uAC01 (requestAnimationFrame\uC774 \uB118\uACA8\uC8FC\uB294 \uAC12)\n * - prevValue: \uC9C1\uC804 \uD638\uCD9C\uC774 \uB9AC\uD134\uD55C \uAC12 (\uCCAB \uD638\uCD9C\uC5D0\uC11C\uB294 undefined)\n * \uB9AC\uD134\uAC12\uC774 undefined/null\uC774\uBA74 \uB2E4\uC74C \uD504\uB808\uC784\uC744 \uC608\uC57D\uD558\uC9C0 \uC54A\uACE0 \uB8E8\uD504\uAC00 \uBA48\uCD98\uB2E4 (\uAC1C\uBC1C\uC790\uAC00 \uC885\uB8CC\uB97C \uC81C\uC5B4).\n * undefined/null\uC774 \uC544\uB2CC \uAC12\uC744 \uB9AC\uD134\uD558\uBA74 \uADF8 \uAC12 \uADF8\uB300\uB85C \uB2E4\uC74C \uD638\uCD9C\uC758 prevValue\uB85C \uC804\uB2EC\uB41C\uB2E4.\n */\nexport type FrameCallback = (timestamp: number, prevValue?: any) => any;\n\nconst getActiveEntries = (inst: any): number[] => (inst.__swc_requestAnimationFrameIds ??= []);\n\nconst startFrameLoop = (win: Window, entries: number[], frameFn: FrameCallback): number => {\n let currentId = 0;\n const step = (timestamp: number, prevValue?: any) => {\n const idx = entries.indexOf(currentId);\n if (idx >= 0) entries.splice(idx, 1);\n let result: any;\n try {\n result = frameFn(timestamp, prevValue);\n } catch (e) {\n console.error('[SWC] requestAnimationFrame callback error:', e);\n return;\n }\n if (result === undefined || result === null) return; // \uAC1C\uBC1C\uC790\uAC00 \uC885\uB8CC\uB97C \uC2E0\uD638\uD568 - \uB2E4\uC74C \uD504\uB808\uC784 \uC608\uC57D \uC548 \uD568\n currentId = win.requestAnimationFrame(ts => step(ts, result));\n entries.push(currentId);\n };\n currentId = win.requestAnimationFrame(ts => step(ts, undefined));\n entries.push(currentId);\n return currentId;\n};\n\nconst applyRequestAnimationFrame = (options: RequestAnimationFrameOptions, target: Object, propertyKey: string | symbol, descriptor?: PropertyDescriptor): PropertyDescriptor | void => {\n const constructor = target.constructor;\n const normalizedOptions: RequestAnimationFrameOptions = { ...options, type: options.type ?? 'returnValue' };\n\n let metaList = ReflectUtils.getOwnMetadata(REQUEST_ANIMATION_FRAME_METADATA_KEY, constructor) as RequestAnimationFrameMetadata[];\n if (!metaList) {\n metaList = [];\n ReflectUtils.defineMetadata(REQUEST_ANIMATION_FRAME_METADATA_KEY, metaList, constructor);\n }\n metaList.push({ propertyKey, options: normalizedOptions });\n\n if (normalizedOptions.type === 'onConnected' || !descriptor) {\n return; // LifeCycler\uAC00 connect/disconnect\uB97C \uC804\uB2F4 - wrapping \uBD88\uD544\uC694\n }\n\n const original = descriptor.value;\n descriptor.value = function (this: any, ...args: any[]) {\n const res = original.apply(this, args);\n // valueKey\uB97C \uC548 \uC8FC\uBA74 \uC774 \uB370\uCF54\uB808\uC774\uD130 \uC804\uC6A9 METADATA_KEY\uB85C \uD3F4\uBC31 (applyAttribute.ts/applyNode.ts\uC640 \uB3D9\uC77C\uD55C \uCEE8\uBCA4\uC158)\n const vk = normalizedOptions.valueKey ?? REQUEST_ANIMATION_FRAME_METADATA_KEY;\n const frameFn: FrameCallback | undefined =\n typeof res === 'function' ? res : res && typeof res === 'object' && typeof res[vk] === 'function' ? res[vk] : undefined;\n\n if (frameFn) {\n ensureInit(this);\n const win = SwcUtils.resolveWindow(this);\n const id = startFrameLoop(win, getActiveEntries(this), frameFn);\n normalizedOptions.created?.(SwcUtils.getHelperAndHostSet(this), id);\n }\n return res;\n };\n return descriptor;\n};\n\n/**\n * type:'onConnected' - connect \uC2DC \uC790\uB3D9\uC73C\uB85C \uB9E4 \uD504\uB808\uC784 \uB8E8\uD504\uB97C \uC2DC\uC791\uD558\uACE0, disconnect \uC2DC \uC790\uB3D9\uC73C\uB85C cancelAnimationFrame \uD55C\uB2E4.\n * type:'returnValue'(\uAE30\uBCF8\uAC12) - \uBA54\uC11C\uB4DC\uB97C \uAC10\uC2F8\uC9C0 \uC54A\uB294 \uB300\uC2E0, \uD638\uCD9C\uB420 \uB54C\uB9C8\uB2E4(\uAC1C\uBC1C\uC790\uAC00 \uC9C1\uC811 \uD638\uCD9C) \uC6D0\uBCF8 \uB85C\uC9C1\uC744\n * \uADF8\uB300\uB85C \uC2E4\uD589\uD558\uACE0 \uB9AC\uD134\uAC12(\uB610\uB294 valueKey\uB85C \uBF51\uC740 \uAC12)\uC774 \uD568\uC218\uBA74 \uADF8 \uD568\uC218\uB97C \uB9E4 \uD504\uB808\uC784 \uD638\uCD9C\uB418\uB294 \uB8E8\uD504\uB85C \uB4F1\uB85D\uD55C\uB2E4.\n * \uC6D0\uBCF8 \uB9AC\uD134\uAC12\uC740 \uADF8\uB300\uB85C \uD1B5\uACFC\uC2DC\uD0A4\uBBC0\uB85C \uB2E4\uB978 \uB370\uCF54\uB808\uC774\uD130\uC640 \uAC19\uC740 \uBA54\uC11C\uB4DC\uC5D0 \uC2A4\uD0DD\uD574\uB3C4 \uC21C\uC11C\uC5D0 \uC0C1\uAD00\uC5C6\uC774 \uC548\uC804\uD558\uB2E4.\n *\n * \uC635\uC158 \uC5C6\uC774 `@requestAnimationFrame` \uADF8\uB300\uB85C \uBD99\uC5EC\uB3C4 \uB418\uACE0, `@requestAnimationFrame({...})`\uCC98\uB7FC \uC635\uC158\uC744 \uC904 \uC218\uB3C4 \uC788\uB2E4.\n */\nexport function requestAnimationFrame(options: RequestAnimationFrameOptions): MethodDecorator;\nexport function requestAnimationFrame(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function requestAnimationFrame(optionsOrTarget?: RequestAnimationFrameOptions | Object, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): MethodDecorator | void {\n if (propertyKey !== undefined) {\n // \uC635\uC158 \uC5C6\uC774: @requestAnimationFrame\n applyRequestAnimationFrame({}, optionsOrTarget as Object, propertyKey, descriptor);\n return;\n }\n // \uC635\uC158\uACFC \uD568\uAED8: @requestAnimationFrame({...})\n return (target: Object, propertyKey: string | symbol, descriptor?: PropertyDescriptor) => {\n return applyRequestAnimationFrame((optionsOrTarget as RequestAnimationFrameOptions) ?? {}, target, propertyKey, descriptor);\n };\n}\n\nexport const findAllRequestAnimationFrameMetadata = (target: any): RequestAnimationFrameMetadata[] => {\n const constructor = typeof target === 'function' ? target : target.constructor;\n return (ReflectUtils.findAllMetadata<RequestAnimationFrameMetadata[]>(REQUEST_ANIMATION_FRAME_METADATA_KEY, constructor) || []).flat();\n};\n\nexport class RequestAnimationFrameLifeCycler implements ElementDefineLifeCycler {\n onConnected(helperHostSet: HelperHostSet): void {\n const inst = helperHostSet.$this;\n inst.__swc_requestAnimationFrameIds = []; // \uC7AC\uC5F0\uACB0 \uB300\uBE44 \uB9AC\uC14B\n const entries = getActiveEntries(inst);\n for (const meta of findAllRequestAnimationFrameMetadata(inst)) {\n if (meta.options.type !== 'onConnected') continue; // returnValue \uD0C0\uC785\uC740 \uC218\uB3D9 \uD638\uCD9C\uC744 \uAE30\uB2E4\uB9BC\n const frameFn: FrameCallback = (timestamp, prevValue) => inst[meta.propertyKey](timestamp, prevValue);\n const id = startFrameLoop(helperHostSet.$w, entries, frameFn);\n meta.options.created?.(helperHostSet, id);\n }\n }\n\n onDisconnected(helperHostSet: HelperHostSet): void {\n const inst = helperHostSet.$this;\n for (const id of inst.__swc_requestAnimationFrameIds ?? []) {\n try {\n helperHostSet.$w.cancelAnimationFrame(id);\n } catch (e) {\n console.error('[SWC] cancelAnimationFr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E;AAAA,IAC1C;AAAA,EACF;AAAA,EAEA,eAAe,eAAoC;AACjD,UAAM,OAAO,cAAc;AAC3B,eAAW,MAAM,KAAK,kCAAkC,CAAC,GAAG;AAC1D,UAAI;AACF,sBAAc,GAAG,qBAAqB,EAAE;AAAA,MAC1C,SAAS,GAAG;AACV,gBAAQ,MAAM,qCAAqC,CAAC;AAAA,MACtD;AAAA,IACF;AACA,SAAK,iCAAiC,CAAC;AAAA,EACzC;AACF;",
|
|
6
|
+
"names": ["propertyKey", "descriptor"]
|
|
7
|
+
}
|
|
@@ -2,92 +2,83 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
4
|
import { ReflectUtils } from "@dooboostore/core";
|
|
5
|
+
import { buildSwcParameterArgs } from "./parameter.js";
|
|
5
6
|
const RESIZE_OBSERVER_METADATA_KEY = Symbol.for("simple-web-component:resize-observer");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
options = maybeOptions ?? {};
|
|
13
|
-
} else {
|
|
14
|
-
selector = "$this";
|
|
15
|
-
options = selectorOrOptions ?? {};
|
|
16
|
-
}
|
|
17
|
-
const constructor = targetObj.constructor;
|
|
18
|
-
let observers = ReflectUtils.getMetadata(RESIZE_OBSERVER_METADATA_KEY, constructor);
|
|
19
|
-
if (!observers) {
|
|
20
|
-
observers = [];
|
|
21
|
-
ReflectUtils.defineMetadata(RESIZE_OBSERVER_METADATA_KEY, observers, constructor);
|
|
22
|
-
}
|
|
23
|
-
observers.push({ propertyKey, selector, options });
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
function resizeObserverThis(options) {
|
|
27
|
-
return resizeObserver("$this", options);
|
|
28
|
-
}
|
|
29
|
-
function resizeObserverDelegateLight(selectorOrOptions, maybeOptions) {
|
|
30
|
-
if (typeof selectorOrOptions === "string" || typeof selectorOrOptions === "function") {
|
|
31
|
-
return resizeObserver(selectorOrOptions, { ...maybeOptions ?? {}, root: "light", delegate: true });
|
|
7
|
+
const applyResizeObserver = (selector, options, targetObj, propertyKey) => {
|
|
8
|
+
const constructor = targetObj.constructor;
|
|
9
|
+
let observers = ReflectUtils.getOwnMetadata(RESIZE_OBSERVER_METADATA_KEY, constructor);
|
|
10
|
+
if (!observers) {
|
|
11
|
+
observers = [];
|
|
12
|
+
ReflectUtils.defineMetadata(RESIZE_OBSERVER_METADATA_KEY, observers, constructor);
|
|
32
13
|
}
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
14
|
+
observers.push({ propertyKey, selector, options });
|
|
15
|
+
};
|
|
16
|
+
const resolveResizeObserverArgs = (selectorOrOptions, maybeOptions, extra) => {
|
|
36
17
|
if (typeof selectorOrOptions === "string" || typeof selectorOrOptions === "function") {
|
|
37
|
-
return
|
|
18
|
+
return { selector: selectorOrOptions, options: { ...maybeOptions ?? {}, ...extra } };
|
|
38
19
|
}
|
|
39
|
-
return
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (typeof
|
|
43
|
-
|
|
20
|
+
return { selector: "$this", options: { ...selectorOrOptions ?? {}, ...extra } };
|
|
21
|
+
};
|
|
22
|
+
const dispatchResizeObserver = (selectorOrOptionsOrTarget, maybeOptionsOrPropertyKey, descriptor, extra) => {
|
|
23
|
+
if ((typeof maybeOptionsOrPropertyKey === "string" || typeof maybeOptionsOrPropertyKey === "symbol") && descriptor !== void 0) {
|
|
24
|
+
applyResizeObserver("$this", { ...extra }, selectorOrOptionsOrTarget, maybeOptionsOrPropertyKey);
|
|
25
|
+
return;
|
|
44
26
|
}
|
|
45
|
-
|
|
27
|
+
const { selector, options } = resolveResizeObserverArgs(
|
|
28
|
+
selectorOrOptionsOrTarget,
|
|
29
|
+
maybeOptionsOrPropertyKey,
|
|
30
|
+
extra
|
|
31
|
+
);
|
|
32
|
+
return (targetObj, propertyKey) => {
|
|
33
|
+
applyResizeObserver(selector, options, targetObj, propertyKey);
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
function resizeObserver(selectorOrOptionsOrTarget, maybeOptionsOrPropertyKey, descriptor) {
|
|
37
|
+
return dispatchResizeObserver(selectorOrOptionsOrTarget, maybeOptionsOrPropertyKey, descriptor, {});
|
|
46
38
|
}
|
|
47
|
-
function
|
|
48
|
-
|
|
49
|
-
return resizeObserver(selectorOrOptions, { ...maybeOptions ?? {}, root: "auto", delegate: true });
|
|
50
|
-
}
|
|
51
|
-
return resizeObserver({ ...selectorOrOptions ?? {}, root: "auto", delegate: true });
|
|
39
|
+
function resizeObserverDelegateLight(selectorOrOptionsOrTarget, maybeOptionsOrPropertyKey, descriptor) {
|
|
40
|
+
return dispatchResizeObserver(selectorOrOptionsOrTarget, maybeOptionsOrPropertyKey, descriptor, { root: "light", delegate: true });
|
|
52
41
|
}
|
|
53
|
-
function
|
|
54
|
-
|
|
55
|
-
return resizeObserver(selectorOrOptions, { ...maybeOptions ?? {}, root: "light" });
|
|
56
|
-
}
|
|
57
|
-
return resizeObserver({ ...selectorOrOptions ?? {}, root: "light" });
|
|
42
|
+
function resizeObserverDelegateShadow(selectorOrOptionsOrTarget, maybeOptionsOrPropertyKey, descriptor) {
|
|
43
|
+
return dispatchResizeObserver(selectorOrOptionsOrTarget, maybeOptionsOrPropertyKey, descriptor, { root: "shadow", delegate: true });
|
|
58
44
|
}
|
|
59
|
-
function
|
|
60
|
-
|
|
61
|
-
return resizeObserver(selectorOrOptions, { ...maybeOptions ?? {}, root: "shadow" });
|
|
62
|
-
}
|
|
63
|
-
return resizeObserver({ ...selectorOrOptions ?? {}, root: "shadow" });
|
|
45
|
+
function resizeObserverDelegateAll(selectorOrOptionsOrTarget, maybeOptionsOrPropertyKey, descriptor) {
|
|
46
|
+
return dispatchResizeObserver(selectorOrOptionsOrTarget, maybeOptionsOrPropertyKey, descriptor, { root: "all", delegate: true });
|
|
64
47
|
}
|
|
65
|
-
function
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return
|
|
48
|
+
function resizeObserverDelegate(selectorOrOptionsOrTarget, maybeOptionsOrPropertyKey, descriptor) {
|
|
49
|
+
return dispatchResizeObserver(selectorOrOptionsOrTarget, maybeOptionsOrPropertyKey, descriptor, { root: "auto", delegate: true });
|
|
50
|
+
}
|
|
51
|
+
function resizeObserverLight(selectorOrOptionsOrTarget, maybeOptionsOrPropertyKey, descriptor) {
|
|
52
|
+
return dispatchResizeObserver(selectorOrOptionsOrTarget, maybeOptionsOrPropertyKey, descriptor, { root: "light" });
|
|
53
|
+
}
|
|
54
|
+
function resizeObserverShadow(selectorOrOptionsOrTarget, maybeOptionsOrPropertyKey, descriptor) {
|
|
55
|
+
return dispatchResizeObserver(selectorOrOptionsOrTarget, maybeOptionsOrPropertyKey, descriptor, { root: "shadow" });
|
|
56
|
+
}
|
|
57
|
+
function resizeObserverAll(selectorOrOptionsOrTarget, maybeOptionsOrPropertyKey, descriptor) {
|
|
58
|
+
return dispatchResizeObserver(selectorOrOptionsOrTarget, maybeOptionsOrPropertyKey, descriptor, { root: "all" });
|
|
70
59
|
}
|
|
71
60
|
function getResizeObserverMetadata(target) {
|
|
72
|
-
const constructor = target
|
|
73
|
-
return ReflectUtils.
|
|
61
|
+
const constructor = typeof target === "function" ? target : target.constructor;
|
|
62
|
+
return ReflectUtils.findAllMetadata(RESIZE_OBSERVER_METADATA_KEY, constructor).flat();
|
|
74
63
|
}
|
|
64
|
+
import { inObserverScope } from "../types/index.js";
|
|
75
65
|
import { SwcUtils } from "../utils/Utils.js";
|
|
76
66
|
class ResizeObserverLifeCycler {
|
|
77
67
|
constructor() {
|
|
78
68
|
__publicField(this, "removeObserverCallbacksMap", /* @__PURE__ */ new WeakMap());
|
|
79
69
|
}
|
|
80
|
-
onConnected(helperHostSet) {
|
|
70
|
+
onConnected(helperHostSet, _set, scope) {
|
|
81
71
|
const inst = helperHostSet.$this;
|
|
82
72
|
const currentWin = helperHostSet.$w;
|
|
83
|
-
const removeObserverCallbacks = [];
|
|
73
|
+
const removeObserverCallbacks = scope === "rest" && this.removeObserverCallbacksMap.get(inst) || [];
|
|
84
74
|
this.removeObserverCallbacksMap.set(inst, removeObserverCallbacks);
|
|
85
|
-
const allMeta = getResizeObserverMetadata(inst) ?? [];
|
|
75
|
+
const allMeta = (getResizeObserverMetadata(inst) ?? []).filter((m) => inObserverScope(m, scope));
|
|
86
76
|
if (allMeta.length === 0) return;
|
|
87
77
|
const root = inst.shadowRoot || inst;
|
|
88
78
|
for (const m of allMeta) {
|
|
89
79
|
if (m.options.removeObserver) removeObserverCallbacks.push({ fn: m.options.removeObserver, target: root, opts: m.options });
|
|
90
80
|
}
|
|
81
|
+
const metaTargets = /* @__PURE__ */ new Map();
|
|
91
82
|
const callback = (entries, obs) => {
|
|
92
83
|
for (const m of allMeta) {
|
|
93
84
|
let matchedEls;
|
|
@@ -99,14 +90,38 @@ class ResizeObserverLifeCycler {
|
|
|
99
90
|
return el.matches?.(m.selector) || !!el.closest?.(m.selector);
|
|
100
91
|
});
|
|
101
92
|
} else {
|
|
102
|
-
|
|
93
|
+
const set = metaTargets.get(m);
|
|
94
|
+
matchedEls = entries.map((e) => e.target).filter((t) => t && t.nodeType === 1 && !!set?.has(t));
|
|
103
95
|
}
|
|
104
96
|
if (matchedEls.length === 0) continue;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
97
|
+
const opts = m.options;
|
|
98
|
+
void (async () => {
|
|
99
|
+
const helper = SwcUtils.getHelperAndHostSet(inst);
|
|
100
|
+
if (opts.filter && !await opts.filter(matchedEls, { currentThis: inst, helper })) return;
|
|
101
|
+
const hostSet = SwcUtils.getHostSet(inst);
|
|
102
|
+
const helperSet = SwcUtils.getHelperSet(helperHostSet.$w);
|
|
103
|
+
const legacyArgs = [matchedEls, entries.filter((e) => matchedEls.includes(e.target)), obs, { ...hostSet, $root: root }];
|
|
104
|
+
const buildArgs = (beforeReturn) => buildSwcParameterArgs(inst, m.propertyKey, {
|
|
105
|
+
hostSet,
|
|
106
|
+
helperHostSet: helper,
|
|
107
|
+
helperSet,
|
|
108
|
+
resizeObserverBeforeReturn: beforeReturn
|
|
109
|
+
}, [...legacyArgs, beforeReturn]);
|
|
110
|
+
let args = buildArgs(void 0);
|
|
111
|
+
if (opts.before) {
|
|
112
|
+
const br = await opts.before(matchedEls, { currentThis: inst, helper });
|
|
113
|
+
args = buildArgs(br);
|
|
114
|
+
}
|
|
115
|
+
let result, error;
|
|
116
|
+
try {
|
|
117
|
+
result = await inst[m.propertyKey](...args);
|
|
118
|
+
} catch (e) {
|
|
119
|
+
error = e;
|
|
120
|
+
} finally {
|
|
121
|
+
if (opts.finally) await opts.finally(matchedEls, { currentThis: inst, helper }, { args, result, error });
|
|
122
|
+
}
|
|
123
|
+
if (error) throw error;
|
|
124
|
+
})().catch((e) => console.error("[SWC] resizeObserver handler error:", e));
|
|
110
125
|
}
|
|
111
126
|
};
|
|
112
127
|
const resizeObserverSet = [];
|
|
@@ -140,6 +155,7 @@ class ResizeObserverLifeCycler {
|
|
|
140
155
|
}
|
|
141
156
|
}
|
|
142
157
|
}
|
|
158
|
+
metaTargets.set(m, new WeakSet(targets));
|
|
143
159
|
for (const el of targets) resizeObserverSet.push({ target: el, options: m.options.box ? { box: m.options.box } : void 0, callback });
|
|
144
160
|
}
|
|
145
161
|
return { resizeObserverSet };
|
|
@@ -167,7 +183,6 @@ export {
|
|
|
167
183
|
resizeObserverDelegateLight,
|
|
168
184
|
resizeObserverDelegateShadow,
|
|
169
185
|
resizeObserverLight,
|
|
170
|
-
resizeObserverShadow
|
|
171
|
-
resizeObserverThis
|
|
186
|
+
resizeObserverShadow
|
|
172
187
|
};
|
|
173
188
|
//# sourceMappingURL=resizeObserver.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/decorators/resizeObserver.ts"],
|
|
4
|
-
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core';\nimport { SpecialSelector, SwcQueryOptions, SwcFnSelector, SwcSelector, HelperHostSet } from '../types';\n\n// \uACF5\uD1B5 \uC635\uC158 \u2014 root\u00B7delegate \uC5C6\uC74C\nexport interface ResizeObserverBaseOptions {\n box?: 'content-box' | 'border-box' | 'device-pixel-content-box';\n filter?: (matchedEls: HTMLElement[], meta: { currentThis: any, helper: HelperHostSet }) => boolean;\n removeObserver?: (target: Element, optionValue: ResizeObserverOptions) => void;\n}\n\n// \uBB38\uC790\uC5F4 \uC140\uB809\uD130 \uC804\uC6A9 \u2014 root\u00B7delegate \uD5C8\uC6A9\nexport type ResizeObserverQueryOptions = ResizeObserverBaseOptions & SwcQueryOptions & { delegate?: boolean };\n// \uD568\uC218 \uC140\uB809\uD130 \uC804\uC6A9 \u2014 root\u00B7delegate \uAE08\uC9C0\nexport type ResizeObserverNonQueryOptions = ResizeObserverBaseOptions;\n// \uB0B4\uBD80 \uC800\uC7A5/\uD574\uC11D\uC6A9\nexport type ResizeObserverOptions = ResizeObserverQueryOptions;\n\n// \uC140\uB809\uD130 \uC885\uB958\uC5D0 \uB530\uB77C \uC635\uC158 \uD0C0\uC785 \uBD84\uAE30\nexport type ResizeObserverOptionsOf<S extends SwcSelector> = S extends string ? ResizeObserverQueryOptions : ResizeObserverNonQueryOptions;\n\nexport interface ResizeObserverMetadata {\n propertyKey: string | symbol;\n selector: SwcSelector;\n options: ResizeObserverOptions;\n}\n\nexport const RESIZE_OBSERVER_METADATA_KEY = Symbol.for('simple-web-component:resize-observer');\n\nexport function resizeObserver(target: SpecialSelector, options?: ResizeObserverQueryOptions): MethodDecorator;\nexport function resizeObserver(selector: string, options?: ResizeObserverQueryOptions): MethodDecorator;\nexport function resizeObserver(selector: SwcFnSelector, options?: ResizeObserverNonQueryOptions): MethodDecorator;\nexport function resizeObserver(options?: ResizeObserverQueryOptions): MethodDecorator;\n/**\n * @resizeObserver decorator to observe element size changes.\n */\nexport function resizeObserver(selectorOrOptions?: SwcSelector | ResizeObserverOptions, maybeOptions?: ResizeObserverOptions): MethodDecorator {\n return (targetObj: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n let selector: SwcSelector = '$this';\n let options: ResizeObserverOptions = {};\n\n if (typeof selectorOrOptions === 'string' || typeof selectorOrOptions === 'function') {\n selector = selectorOrOptions;\n options = maybeOptions ?? {};\n } else {\n selector = '$this';\n options = selectorOrOptions ?? {};\n }\n\n const constructor = targetObj.constructor;\n\n let observers = ReflectUtils.getMetadata<ResizeObserverMetadata[]>(RESIZE_OBSERVER_METADATA_KEY, constructor);\n if (!observers) {\n observers = [];\n ReflectUtils.defineMetadata(RESIZE_OBSERVER_METADATA_KEY, observers, constructor);\n }\n\n observers.push({ propertyKey, selector, options });\n };\n}\n\nexport function resizeObserverThis(options?: ResizeObserverQueryOptions): MethodDecorator {\n return resizeObserver('$this', options);\n}\n\n// \u2500\u2500\u2500 root\uBCC4 delegate \uD5EC\uD37C (root \uC8FC\uC785 \u2192 \uBB38\uC790\uC5F4 \uC140\uB809\uD130 \uC804\uC6A9) \u2500\u2500\u2500\n\nexport function resizeObserverDelegateLight(selector: string, options?: Omit<ResizeObserverQueryOptions, 'delegate'>): MethodDecorator;\nexport function resizeObserverDelegateLight(options?: Omit<ResizeObserverQueryOptions, 'delegate'>): MethodDecorator;\nexport function resizeObserverDelegateLight(selectorOrOptions?: string | Omit<ResizeObserverQueryOptions, 'delegate'>, maybeOptions?: Omit<ResizeObserverQueryOptions, 'delegate'>): MethodDecorator {\n if (typeof selectorOrOptions === 'string' || typeof selectorOrOptions === 'function') {\n return resizeObserver(selectorOrOptions as any, {...maybeOptions ?? {}, root: 'light', delegate: true});\n }\n return resizeObserver({...selectorOrOptions ?? {}, root: 'light', delegate: true});\n}\n\nexport function resizeObserverDelegateShadow(selector: string, options?: Omit<ResizeObserverQueryOptions, 'delegate'>): MethodDecorator;\nexport function resizeObserverDelegateShadow(options?: Omit<ResizeObserverQueryOptions, 'delegate'>): MethodDecorator;\nexport function resizeObserverDelegateShadow(selectorOrOptions?: string | Omit<ResizeObserverQueryOptions, 'delegate'>, maybeOptions?: Omit<ResizeObserverQueryOptions, 'delegate'>): MethodDecorator {\n if (typeof selectorOrOptions === 'string' || typeof selectorOrOptions === 'function') {\n return resizeObserver(selectorOrOptions as any, {...maybeOptions ?? {}, root: 'shadow', delegate: true});\n }\n return resizeObserver({...selectorOrOptions ?? {}, root: 'shadow', delegate: true});\n}\n\nexport function resizeObserverDelegateAll(selector: string, options?: Omit<ResizeObserverQueryOptions, 'delegate'>): MethodDecorator;\nexport function resizeObserverDelegateAll(options?: Omit<ResizeObserverQueryOptions, 'delegate'>): MethodDecorator;\nexport function resizeObserverDelegateAll(selectorOrOptions?: string | Omit<ResizeObserverQueryOptions, 'delegate'>, maybeOptions?: Omit<ResizeObserverQueryOptions, 'delegate'>): MethodDecorator {\n if (typeof selectorOrOptions === 'string' || typeof selectorOrOptions === 'function') {\n return resizeObserver(selectorOrOptions as any, {...maybeOptions ?? {}, root: 'all', delegate: true});\n }\n return resizeObserver({...selectorOrOptions ?? {}, root: 'all', delegate: true});\n}\n\nexport function resizeObserverDelegate(selector: string, options?: Omit<ResizeObserverQueryOptions, 'delegate'>): MethodDecorator;\nexport function resizeObserverDelegate(options?: Omit<ResizeObserverQueryOptions, 'delegate'>): MethodDecorator;\nexport function resizeObserverDelegate(selectorOrOptions?: string | Omit<ResizeObserverQueryOptions, 'delegate'>, maybeOptions?: Omit<ResizeObserverQueryOptions, 'delegate'>): MethodDecorator {\n if (typeof selectorOrOptions === 'string' || typeof selectorOrOptions === 'function') {\n return resizeObserver(selectorOrOptions as any, {...maybeOptions ?? {}, root: 'auto', delegate: true});\n }\n return resizeObserver({...selectorOrOptions ?? {}, root: 'auto', delegate: true});\n}\n\n// \u2500\u2500\u2500 root\uBCC4 \uC77C\uBC18 \uD5EC\uD37C (delegate \uC5C6\uC774, \uC140\uB809\uD130 \uC0DD\uB7B5 \uC2DC $this) \u2500\u2500\u2500\n\nexport function resizeObserverLight(selector: string, options?: ResizeObserverQueryOptions): MethodDecorator;\nexport function resizeObserverLight(options?: ResizeObserverQueryOptions): MethodDecorator;\nexport function resizeObserverLight(selectorOrOptions?: string | ResizeObserverQueryOptions, maybeOptions?: ResizeObserverQueryOptions): MethodDecorator {\n if (typeof selectorOrOptions === 'string' || typeof selectorOrOptions === 'function') {\n return resizeObserver(selectorOrOptions as any, {...maybeOptions ?? {}, root: 'light'});\n }\n return resizeObserver({...selectorOrOptions ?? {}, root: 'light'});\n}\n\nexport function resizeObserverShadow(selector: string, options?: ResizeObserverQueryOptions): MethodDecorator;\nexport function resizeObserverShadow(options?: ResizeObserverQueryOptions): MethodDecorator;\nexport function resizeObserverShadow(selectorOrOptions?: string | ResizeObserverQueryOptions, maybeOptions?: ResizeObserverQueryOptions): MethodDecorator {\n if (typeof selectorOrOptions === 'string' || typeof selectorOrOptions === 'function') {\n return resizeObserver(selectorOrOptions as any, {...maybeOptions ?? {}, root: 'shadow'});\n }\n return resizeObserver({...selectorOrOptions ?? {}, root: 'shadow'});\n}\n\nexport function resizeObserverAll(selector: string, options?: ResizeObserverQueryOptions): MethodDecorator;\nexport function resizeObserverAll(options?: ResizeObserverQueryOptions): MethodDecorator;\nexport function resizeObserverAll(selectorOrOptions?: string | ResizeObserverQueryOptions, maybeOptions?: ResizeObserverQueryOptions): MethodDecorator {\n if (typeof selectorOrOptions === 'string' || typeof selectorOrOptions === 'function') {\n return resizeObserver(selectorOrOptions as any, {...maybeOptions ?? {}, root: 'all'});\n }\n return resizeObserver({...selectorOrOptions ?? {}, root: 'all'});\n}\n\nexport function getResizeObserverMetadata(target: any): ResizeObserverMetadata[] | undefined {\n const constructor = target instanceof Function ? target : target.constructor;\n return ReflectUtils.getMetadata(RESIZE_OBSERVER_METADATA_KEY, constructor);\n}\n\n// \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n// ResizeObserverLifeCycler\n// observer \uB97C \uC9C1\uC811 \uC0DD\uC131\uD558\uC9C0 \uC54A\uACE0 OnConnectedResult \uB97C \uBC18\uD658\uD55C\uB2E4.\n// elementDefine \uC774 \uC218\uC9D1\uB41C ResizeObserverSet \uC73C\uB85C observer \uB97C \uC0DD\uC131\uD558\uACE0,\n// observe/unobserve \uD568\uC218\uB97C \uC8FC\uC785\uD574 MutationObserver delegate \uCD94\uC801\uC774 \uC0AC\uC6A9\uD560 \uC218 \uC788\uAC8C \uD55C\uB2E4.\n// \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\nimport { ElementDefineLifeCycler, OnConnectedResult, ResizeObserverSet, ResizeObserverSetEntry } from '../types';\nimport { SwcUtils } from '../utils/Utils';\n\nexport class ResizeObserverLifeCycler implements ElementDefineLifeCycler {\n private readonly removeObserverCallbacksMap = new WeakMap<Element, Array<{ fn: (target: Element, opts: unknown) => void; target: any; opts: unknown }>>();\n\n onConnected(helperHostSet: HelperHostSet): OnConnectedResult | void {\n const inst = helperHostSet.$this;\n const currentWin = helperHostSet.$w;\n\n const removeObserverCallbacks: Array<{ fn: (target: Element, opts: unknown) => void; target: any; opts: unknown }> = [];\n this.removeObserverCallbacksMap.set(inst, removeObserverCallbacks);\n\n const allMeta = getResizeObserverMetadata(inst) ?? [];\n if (allMeta.length === 0) return;\n\n const root: HTMLElement | ShadowRoot = inst.shadowRoot || inst;\n\n // removeObserver \uCF5C\uBC31 \uC218\uC9D1\n for (const m of allMeta) {\n if (m.options.removeObserver) removeObserverCallbacks.push({ fn: m.options.removeObserver, target: root, opts: m.options });\n }\n\n // \u2500\u2500 ResizeObserver \uCF5C\uBC31 \u2500\u2500\n const callback: ResizeObserverSetEntry['callback'] = (entries, obs) => {\n for (const m of allMeta) {\n let matchedEls: HTMLElement[];\n if (m.options.delegate && typeof m.selector === 'string') {\n const isThis = m.selector === '$this' || m.selector === '';\n matchedEls = entries.map(e => e.target as HTMLElement).filter(el => {\n if (!el || el.nodeType !== 1) return false;\n if (isThis) return true;\n return el.matches?.(m.selector as string) || !!el.closest?.(m.selector as string);\n });\n } else {\n matchedEls = entries.map(e => e.target as HTMLElement).filter(t => t && t.nodeType === 1);\n }\n if (matchedEls.length === 0) continue;\n if (m.options.filter) {\n if (!m.options.filter(matchedEls, { currentThis: inst, helper: helperHostSet })) continue;\n }\n const hostSet = SwcUtils.getHostSet(inst);\n inst[m.propertyKey](matchedEls, entries, obs, { ...hostSet, $root: root });\n }\n };\n\n // \u2500\u2500 observe \uB300\uC0C1 \uBAA9\uB85D \uAD6C\uC131 \u2500\u2500\n // - non-delegate: \uC2E4\uC81C \uC694\uC18C\uB97C \uCD08\uAE30 observe\n // - delegate: \uB3D9\uC801 \uCD94\uC801\uC6A9 \uC140\uB809\uD130 \uBB38\uC790\uC5F4\uB85C \uC120\uC5B8 (elementDefine \uC758 MutationObserver \uCF5C\uBC31\uC774 observe/unobserve)\n // \uBAA8\uB4E0 \uB300\uC0C1\uC740 \uC774 \uB8E8\uD2B8\uC758 callback \uC744 \uACF5\uC720\uD55C\uB2E4.\n const resizeObserverSet: ResizeObserverSet = [];\n for (const m of allMeta) {\n if (m.options.delegate && typeof m.selector === 'string') {\n resizeObserverSet.push({ target: m.selector, delegate: true, delegateRoot: m.options.root, options: m.options.box ? { box: m.options.box } : undefined, callback });\n continue;\n }\n let targets: HTMLElement[] = [];\n\n if (typeof m.selector === 'function') {\n const res = (m.selector as any)(inst, helperHostSet);\n if (res instanceof currentWin.HTMLElement) targets = [res as HTMLElement];\n else if (res instanceof currentWin.NodeList) targets = Array.from(res as NodeList).filter((e: any) => e instanceof currentWin.HTMLElement) as HTMLElement[];\n else if (Array.isArray(res)) targets = res.filter((e: any) => e instanceof currentWin.HTMLElement) as HTMLElement[];\n } else if (typeof m.selector === 'string') {\n if (m.selector === '$this' || m.selector === '') {\n targets = [inst as HTMLElement];\n } else {\n const r: any = m.options.root || 'auto';\n const scopes: any[] = [];\n if (r === 'auto') scopes.push(inst.shadowRoot || inst);\n else if (r === 'light') scopes.push(inst);\n else if (r === 'shadow' && inst.shadowRoot) scopes.push(inst.shadowRoot);\n else if (r === 'all') { scopes.push(inst); if (inst.shadowRoot) scopes.push(inst.shadowRoot); }\n for (const s of scopes) {\n const found = s?.querySelectorAll?.(m.selector as string) as NodeListOf<HTMLElement> | undefined;\n if (found?.length) targets.push(...Array.from(found));\n }\n }\n }\n for (const el of targets) resizeObserverSet.push({ target: el, options: m.options.box ? { box: m.options.box } : undefined, callback });\n }\n\n return { resizeObserverSet };\n }\n\n onDisconnected(helperHostSet: HelperHostSet): void {\n const inst = helperHostSet.$this;\n for (const cb of this.removeObserverCallbacksMap.get(inst) ?? []) {\n try { cb.fn(cb.target, cb.opts); } catch (e) { console.error('[SWC] removeObserver error:', e); }\n }\n this.removeObserverCallbacksMap.delete(inst);\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;AAAA,SAAS,oBAAoB;
|
|
4
|
+
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core';\nimport { SpecialSelector, SwcQueryOptions, SwcFnSelector, SwcSelector, HelperHostSet } from '../types';\nimport { buildSwcParameterArgs } from './parameter';\n\n// \uACF5\uD1B5 \uC635\uC158 \u2014 root\u00B7delegate \uC5C6\uC74C\nexport interface ResizeObserverBaseOptions {\n box?: 'content-box' | 'border-box' | 'device-pixel-content-box';\n /** \uB9E4\uCE6D \uC2DC \uD578\uB4E4\uB7EC \uC2E4\uD589 \uC5EC\uBD80 \uAC8C\uC774\uD2B8. Promise<boolean>\uB3C4 \uB418\uC5B4 async \uD310\uC815 \uAC00\uB2A5. false\uBA74 \uC2A4\uD0B5. */\n filter?: (matchedEls: HTMLElement[], meta: { currentThis: any, helper: HelperHostSet }) => boolean | Promise<boolean>;\n /** filter \uD1B5\uACFC \uD6C4 \uD578\uB4E4\uB7EC \uC9C1\uC804 \uD6C5. await\uB418\uACE0, \uB9AC\uD134\uAC12\uC740 @resizeObserverBeforeReturn \uC73C\uB85C \uD578\uB4E4\uB7EC\uC5D0 \uC8FC\uC785\uB41C\uB2E4. */\n before?: (matchedEls: HTMLElement[], meta: { currentThis: any, helper: HelperHostSet }) => any | Promise<any>;\n /** \uD578\uB4E4\uB7EC\uAC00 \uC131\uACF5/\uC2E4\uD328\uD574\uB3C4 \uD56D\uC0C1 \uC2E4\uD589\uB418\uB294 \uC815\uB9AC \uD6C5. ctx\uB85C \uC778\uC790/\uACB0\uACFC/\uC5D0\uB7EC\uB97C \uBC1B\uB294\uB2E4. \uC5D0\uB7EC\uB294 \uB85C\uAE45\uB428. */\n finally?: (matchedEls: HTMLElement[], meta: { currentThis: any, helper: HelperHostSet }, ctx: { args: any[]; result?: any; error?: any }) => any | Promise<any>;\n removeObserver?: (target: Element, optionValue: ResizeObserverOptions) => void;\n}\n\n// \uBB38\uC790\uC5F4 \uC140\uB809\uD130 \uC804\uC6A9 \u2014 root\u00B7delegate \uD5C8\uC6A9\nexport type ResizeObserverQueryOptions = ResizeObserverBaseOptions & SwcQueryOptions & { delegate?: boolean };\n// \uD568\uC218 \uC140\uB809\uD130 \uC804\uC6A9 \u2014 root\u00B7delegate \uAE08\uC9C0\nexport type ResizeObserverNonQueryOptions = ResizeObserverBaseOptions;\n// \uB0B4\uBD80 \uC800\uC7A5/\uD574\uC11D\uC6A9\nexport type ResizeObserverOptions = ResizeObserverQueryOptions;\n\n// \uC140\uB809\uD130 \uC885\uB958\uC5D0 \uB530\uB77C \uC635\uC158 \uD0C0\uC785 \uBD84\uAE30\nexport type ResizeObserverOptionsOf<S extends SwcSelector> = S extends string ? ResizeObserverQueryOptions : ResizeObserverNonQueryOptions;\n\nexport interface ResizeObserverMetadata {\n propertyKey: string | symbol;\n selector: SwcSelector;\n options: ResizeObserverOptions;\n}\n\nexport const RESIZE_OBSERVER_METADATA_KEY = Symbol.for('simple-web-component:resize-observer');\n\nconst applyResizeObserver = (selector: SwcSelector, options: ResizeObserverOptions, targetObj: Object, propertyKey: string | symbol): void => {\n const constructor = targetObj.constructor;\n let observers = ReflectUtils.getOwnMetadata(RESIZE_OBSERVER_METADATA_KEY, constructor) as ResizeObserverMetadata[] | undefined;\n if (!observers) {\n observers = [];\n ReflectUtils.defineMetadata(RESIZE_OBSERVER_METADATA_KEY, observers, constructor);\n }\n observers.push({ propertyKey, selector, options });\n};\n\nconst resolveResizeObserverArgs = (\n selectorOrOptions: SwcSelector | ResizeObserverOptions | undefined,\n maybeOptions: ResizeObserverOptions | undefined,\n extra: Partial<ResizeObserverOptions>\n): { selector: SwcSelector; options: ResizeObserverOptions } => {\n if (typeof selectorOrOptions === 'string' || typeof selectorOrOptions === 'function') {\n return { selector: selectorOrOptions, options: { ...(maybeOptions ?? {}), ...extra } };\n }\n return { selector: '$this', options: { ...(selectorOrOptions ?? {}), ...extra } };\n};\n\n/**\n * bare(@decorator)\uC640 factory(@decorator(...), \uBE48 \uAD04\uD638\uB294 \uD0C0\uC785\uC5D0\uC11C \uB9C9\uC74C) \uD638\uCD9C\uC744 \uBAA8\uB450 \uCC98\uB9AC\uD558\uB294 \uACF5\uD1B5 \uB514\uC2A4\uD328\uCC98.\n * extra\uB294 Light/Shadow/All/Delegate \uBCC0\uD615\uC774 \uAC15\uC81C\uB85C \uB367\uC50C\uC6B0\uB294 \uC635\uC158(root, delegate \uB4F1)\uC774\uB2E4.\n */\nconst dispatchResizeObserver = (\n selectorOrOptionsOrTarget: SwcSelector | ResizeObserverOptions | Object | undefined,\n maybeOptionsOrPropertyKey: ResizeObserverOptions | string | symbol | undefined,\n descriptor: PropertyDescriptor | undefined,\n extra: Partial<ResizeObserverOptions>\n): MethodDecorator | void => {\n if ((typeof maybeOptionsOrPropertyKey === 'string' || typeof maybeOptionsOrPropertyKey === 'symbol') && descriptor !== undefined) {\n // \uC635\uC158 \uC5C6\uC774: @decorator\n applyResizeObserver('$this', { ...extra }, selectorOrOptionsOrTarget as Object, maybeOptionsOrPropertyKey);\n return;\n }\n // \uC635\uC158\uACFC \uD568\uAED8: @decorator(selector, options) / @decorator(options)\n const { selector, options } = resolveResizeObserverArgs(\n selectorOrOptionsOrTarget as SwcSelector | ResizeObserverOptions | undefined,\n maybeOptionsOrPropertyKey as ResizeObserverOptions | undefined,\n extra\n );\n return (targetObj: Object, propertyKey: string | symbol) => {\n applyResizeObserver(selector, options, targetObj, propertyKey);\n };\n};\n\nexport function resizeObserver(target: SpecialSelector, options?: ResizeObserverQueryOptions): MethodDecorator;\nexport function resizeObserver(selector: string, options?: ResizeObserverQueryOptions): MethodDecorator;\nexport function resizeObserver(selector: SwcFnSelector, options?: ResizeObserverNonQueryOptions): MethodDecorator;\nexport function resizeObserver(options: ResizeObserverQueryOptions): MethodDecorator;\nexport function resizeObserver(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\n/**\n * @resizeObserver decorator to observe element size changes.\n * \uC635\uC158 \uC5C6\uC774 `@resizeObserver` \uADF8\uB300\uB85C \uBD99\uC5EC\uB3C4 \uB418\uACE0, `@resizeObserver(...)`\uCC98\uB7FC \uC140\uB809\uD130/\uC635\uC158\uC744 \uC904 \uC218\uB3C4 \uC788\uB2E4.\n */\nexport function resizeObserver(selectorOrOptionsOrTarget?: SwcSelector | ResizeObserverOptions | Object, maybeOptionsOrPropertyKey?: ResizeObserverOptions | string | symbol, descriptor?: PropertyDescriptor): MethodDecorator | void {\n return dispatchResizeObserver(selectorOrOptionsOrTarget, maybeOptionsOrPropertyKey, descriptor, {});\n}\n\n\n// \u2500\u2500\u2500 root\uBCC4 delegate \uD5EC\uD37C (root \uC8FC\uC785 \u2192 \uBB38\uC790\uC5F4 \uC140\uB809\uD130 \uC804\uC6A9) \u2500\u2500\u2500\n\nexport function resizeObserverDelegateLight(selector: string, options?: Omit<ResizeObserverQueryOptions, 'delegate'>): MethodDecorator;\nexport function resizeObserverDelegateLight(options: Omit<ResizeObserverQueryOptions, 'delegate'>): MethodDecorator;\nexport function resizeObserverDelegateLight(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function resizeObserverDelegateLight(selectorOrOptionsOrTarget?: string | Omit<ResizeObserverQueryOptions, 'delegate'> | Object, maybeOptionsOrPropertyKey?: Omit<ResizeObserverQueryOptions, 'delegate'> | string | symbol, descriptor?: PropertyDescriptor): MethodDecorator | void {\n return dispatchResizeObserver(selectorOrOptionsOrTarget as any, maybeOptionsOrPropertyKey as any, descriptor, { root: 'light', delegate: true });\n}\n\nexport function resizeObserverDelegateShadow(selector: string, options?: Omit<ResizeObserverQueryOptions, 'delegate'>): MethodDecorator;\nexport function resizeObserverDelegateShadow(options: Omit<ResizeObserverQueryOptions, 'delegate'>): MethodDecorator;\nexport function resizeObserverDelegateShadow(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function resizeObserverDelegateShadow(selectorOrOptionsOrTarget?: string | Omit<ResizeObserverQueryOptions, 'delegate'> | Object, maybeOptionsOrPropertyKey?: Omit<ResizeObserverQueryOptions, 'delegate'> | string | symbol, descriptor?: PropertyDescriptor): MethodDecorator | void {\n return dispatchResizeObserver(selectorOrOptionsOrTarget as any, maybeOptionsOrPropertyKey as any, descriptor, { root: 'shadow', delegate: true });\n}\n\nexport function resizeObserverDelegateAll(selector: string, options?: Omit<ResizeObserverQueryOptions, 'delegate'>): MethodDecorator;\nexport function resizeObserverDelegateAll(options: Omit<ResizeObserverQueryOptions, 'delegate'>): MethodDecorator;\nexport function resizeObserverDelegateAll(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function resizeObserverDelegateAll(selectorOrOptionsOrTarget?: string | Omit<ResizeObserverQueryOptions, 'delegate'> | Object, maybeOptionsOrPropertyKey?: Omit<ResizeObserverQueryOptions, 'delegate'> | string | symbol, descriptor?: PropertyDescriptor): MethodDecorator | void {\n return dispatchResizeObserver(selectorOrOptionsOrTarget as any, maybeOptionsOrPropertyKey as any, descriptor, { root: 'all', delegate: true });\n}\n\nexport function resizeObserverDelegate(selector: string, options?: Omit<ResizeObserverQueryOptions, 'delegate'>): MethodDecorator;\nexport function resizeObserverDelegate(options: Omit<ResizeObserverQueryOptions, 'delegate'>): MethodDecorator;\nexport function resizeObserverDelegate(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function resizeObserverDelegate(selectorOrOptionsOrTarget?: string | Omit<ResizeObserverQueryOptions, 'delegate'> | Object, maybeOptionsOrPropertyKey?: Omit<ResizeObserverQueryOptions, 'delegate'> | string | symbol, descriptor?: PropertyDescriptor): MethodDecorator | void {\n return dispatchResizeObserver(selectorOrOptionsOrTarget as any, maybeOptionsOrPropertyKey as any, descriptor, { root: 'auto', delegate: true });\n}\n\n// \u2500\u2500\u2500 root\uBCC4 \uC77C\uBC18 \uD5EC\uD37C (delegate \uC5C6\uC774, \uC140\uB809\uD130 \uC0DD\uB7B5 \uC2DC $this) \u2500\u2500\u2500\n\nexport function resizeObserverLight(selector: string, options?: ResizeObserverQueryOptions): MethodDecorator;\nexport function resizeObserverLight(options: ResizeObserverQueryOptions): MethodDecorator;\nexport function resizeObserverLight(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function resizeObserverLight(selectorOrOptionsOrTarget?: string | ResizeObserverQueryOptions | Object, maybeOptionsOrPropertyKey?: ResizeObserverQueryOptions | string | symbol, descriptor?: PropertyDescriptor): MethodDecorator | void {\n return dispatchResizeObserver(selectorOrOptionsOrTarget as any, maybeOptionsOrPropertyKey as any, descriptor, { root: 'light' });\n}\n\nexport function resizeObserverShadow(selector: string, options?: ResizeObserverQueryOptions): MethodDecorator;\nexport function resizeObserverShadow(options: ResizeObserverQueryOptions): MethodDecorator;\nexport function resizeObserverShadow(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function resizeObserverShadow(selectorOrOptionsOrTarget?: string | ResizeObserverQueryOptions | Object, maybeOptionsOrPropertyKey?: ResizeObserverQueryOptions | string | symbol, descriptor?: PropertyDescriptor): MethodDecorator | void {\n return dispatchResizeObserver(selectorOrOptionsOrTarget as any, maybeOptionsOrPropertyKey as any, descriptor, { root: 'shadow' });\n}\n\nexport function resizeObserverAll(selector: string, options?: ResizeObserverQueryOptions): MethodDecorator;\nexport function resizeObserverAll(options: ResizeObserverQueryOptions): MethodDecorator;\nexport function resizeObserverAll(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function resizeObserverAll(selectorOrOptionsOrTarget?: string | ResizeObserverQueryOptions | Object, maybeOptionsOrPropertyKey?: ResizeObserverQueryOptions | string | symbol, descriptor?: PropertyDescriptor): MethodDecorator | void {\n return dispatchResizeObserver(selectorOrOptionsOrTarget as any, maybeOptionsOrPropertyKey as any, descriptor, { root: 'all' });\n}\n\nexport function getResizeObserverMetadata(target: any): ResizeObserverMetadata[] | undefined {\n const constructor = typeof target === 'function' ? target : target.constructor;\n return ReflectUtils.findAllMetadata<any[]>(RESIZE_OBSERVER_METADATA_KEY, constructor).flat();\n}\n\n// \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n// ResizeObserverLifeCycler\n// observer \uB97C \uC9C1\uC811 \uC0DD\uC131\uD558\uC9C0 \uC54A\uACE0 OnConnectedResult \uB97C \uBC18\uD658\uD55C\uB2E4.\n// elementDefine \uC774 \uC218\uC9D1\uB41C ResizeObserverSet \uC73C\uB85C observer \uB97C \uC0DD\uC131\uD558\uACE0,\n// observe/unobserve \uD568\uC218\uB97C \uC8FC\uC785\uD574 MutationObserver delegate \uCD94\uC801\uC774 \uC0AC\uC6A9\uD560 \uC218 \uC788\uAC8C \uD55C\uB2E4.\n// \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\nimport { ElementDefineLifeCycler, inObserverScope, ObserverScope, OnConnectedResult, ResizeObserverSet, ResizeObserverSetEntry } from '../types';\nimport { SwcUtils } from '../utils/Utils';\n\nexport class ResizeObserverLifeCycler implements ElementDefineLifeCycler {\n private readonly removeObserverCallbacksMap = new WeakMap<Element, Array<{ fn: (target: Element, opts: unknown) => void; target: any; opts: unknown }>>();\n\n onConnected(helperHostSet: HelperHostSet, _set?: ResizeObserverSet, scope?: ObserverScope): OnConnectedResult | void {\n const inst = helperHostSet.$this;\n const currentWin = helperHostSet.$w;\n\n // 'rest' \uB294 \uAC19\uC740 connect \uC758 'self' \uB4A4\uC5D0 \uC624\uBBC0\uB85C \uC774\uC5B4 \uBD99\uC774\uACE0, \uADF8 \uC678(\uC0C8 connect)\uB294 \uC0C8\uB85C \uC2DC\uC791\uD55C\uB2E4.\n const removeObserverCallbacks = (scope === 'rest' && this.removeObserverCallbacksMap.get(inst)) || [];\n this.removeObserverCallbacksMap.set(inst, removeObserverCallbacks);\n\n const allMeta = (getResizeObserverMetadata(inst) ?? []).filter(m => inObserverScope(m, scope));\n if (allMeta.length === 0) return;\n\n const root: HTMLElement | ShadowRoot = inst.shadowRoot || inst;\n\n // removeObserver \uCF5C\uBC31 \uC218\uC9D1\n for (const m of allMeta) {\n if (m.options.removeObserver) removeObserverCallbacks.push({ fn: m.options.removeObserver, target: root, opts: m.options });\n }\n\n // non-delegate \uBA54\uD0C0\uBCC4 observe \uB300\uC0C1 \u2014 \uCF5C\uBC31\uC740 \uBAA8\uB4E0 \uBA54\uD0C0\uAC00 \uACF5\uC720\uD558\uBBC0\uB85C, \uC5D4\uD2B8\uB9AC\uB97C \uC790\uAE30 \uB300\uC0C1\uC5D0\uB9CC \uBC30\uB2EC\uD55C\uB2E4.\n const metaTargets = new Map<typeof allMeta[number], WeakSet<Element>>();\n\n // \u2500\u2500 ResizeObserver \uCF5C\uBC31 \u2500\u2500\n const callback: ResizeObserverSetEntry['callback'] = (entries, obs) => {\n for (const m of allMeta) {\n let matchedEls: HTMLElement[];\n if (m.options.delegate && typeof m.selector === 'string') {\n const isThis = m.selector === '$this' || m.selector === '';\n matchedEls = entries.map(e => e.target as HTMLElement).filter(el => {\n if (!el || el.nodeType !== 1) return false;\n if (isThis) return true;\n return el.matches?.(m.selector as string) || !!el.closest?.(m.selector as string);\n });\n } else {\n const set = metaTargets.get(m);\n matchedEls = entries.map(e => e.target as HTMLElement).filter(t => t && t.nodeType === 1 && !!set?.has(t));\n }\n if (matchedEls.length === 0) continue;\n const opts = m.options;\n void (async () => {\n const helper = SwcUtils.getHelperAndHostSet(inst);\n if (opts.filter && !(await opts.filter(matchedEls, { currentThis: inst, helper }))) return;\n const hostSet = SwcUtils.getHostSet(inst);\n const helperSet = SwcUtils.getHelperSet(helperHostSet.$w);\n // entries \uB3C4 \uC774 \uBA54\uC11C\uB4DC \uB300\uC0C1 \uAC83\uB9CC (\uC635\uC800\uBC84\uB294 \uACF5\uC720\uB77C \uBC30\uCE58\uC5D0 \uB2E4\uB978 \uB300\uC0C1 \uC5D4\uD2B8\uB9AC\uAC00 \uC11E\uC778\uB2E4)\n const legacyArgs = [matchedEls, entries.filter(e => matchedEls.includes(e.target as HTMLElement)), obs, { ...hostSet, $root: root }];\n const buildArgs = (beforeReturn: any) => buildSwcParameterArgs(inst, m.propertyKey, {\n hostSet, helperHostSet: helper, helperSet, resizeObserverBeforeReturn: beforeReturn\n }, [...legacyArgs, beforeReturn]);\n let args = buildArgs(undefined);\n if (opts.before) { const br = await opts.before(matchedEls, { currentThis: inst, helper }); args = buildArgs(br); }\n let result: any, error: any;\n try { result = await inst[m.propertyKey](...args); }\n catch (e) { error = e; }\n finally { if (opts.finally) await opts.finally(matchedEls, { currentThis: inst, helper }, { args, result, error }); }\n if (error) throw error;\n })().catch(e => console.error('[SWC] resizeObserver handler error:', e));\n }\n };\n\n // \u2500\u2500 observe \uB300\uC0C1 \uBAA9\uB85D \uAD6C\uC131 \u2500\u2500\n // - non-delegate: \uC2E4\uC81C \uC694\uC18C\uB97C \uCD08\uAE30 observe\n // - delegate: \uB3D9\uC801 \uCD94\uC801\uC6A9 \uC140\uB809\uD130 \uBB38\uC790\uC5F4\uB85C \uC120\uC5B8 (elementDefine \uC758 MutationObserver \uCF5C\uBC31\uC774 observe/unobserve)\n // \uBAA8\uB4E0 \uB300\uC0C1\uC740 \uC774 \uB8E8\uD2B8\uC758 callback \uC744 \uACF5\uC720\uD55C\uB2E4.\n const resizeObserverSet: ResizeObserverSet = [];\n for (const m of allMeta) {\n if (m.options.delegate && typeof m.selector === 'string') {\n resizeObserverSet.push({ target: m.selector, delegate: true, delegateRoot: m.options.root, options: m.options.box ? { box: m.options.box } : undefined, callback });\n continue;\n }\n let targets: HTMLElement[] = [];\n\n if (typeof m.selector === 'function') {\n const res = (m.selector as any)(inst, helperHostSet);\n if (res instanceof currentWin.HTMLElement) targets = [res as HTMLElement];\n else if (res instanceof currentWin.NodeList) targets = Array.from(res as NodeList).filter((e: any) => e instanceof currentWin.HTMLElement) as HTMLElement[];\n else if (Array.isArray(res)) targets = res.filter((e: any) => e instanceof currentWin.HTMLElement) as HTMLElement[];\n } else if (typeof m.selector === 'string') {\n if (m.selector === '$this' || m.selector === '') {\n targets = [inst as HTMLElement];\n } else {\n const r: any = m.options.root || 'auto';\n const scopes: any[] = [];\n if (r === 'auto') scopes.push(inst.shadowRoot || inst);\n else if (r === 'light') scopes.push(inst);\n else if (r === 'shadow' && inst.shadowRoot) scopes.push(inst.shadowRoot);\n else if (r === 'all') { scopes.push(inst); if (inst.shadowRoot) scopes.push(inst.shadowRoot); }\n for (const s of scopes) {\n const found = s?.querySelectorAll?.(m.selector as string) as NodeListOf<HTMLElement> | undefined;\n if (found?.length) targets.push(...Array.from(found));\n }\n }\n }\n metaTargets.set(m, new WeakSet(targets));\n for (const el of targets) resizeObserverSet.push({ target: el, options: m.options.box ? { box: m.options.box } : undefined, callback });\n }\n\n return { resizeObserverSet };\n }\n\n onDisconnected(helperHostSet: HelperHostSet): void {\n const inst = helperHostSet.$this;\n for (const cb of this.removeObserverCallbacksMap.get(inst) ?? []) {\n try { cb.fn(cb.target, cb.opts); } catch (e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BAAkB;AAAA,EAC7B;AAAA,EAEA,eAAe,eAAoC;AACjD,UAAM,OAAO,cAAc;AAC3B,eAAW,MAAM,KAAK,2BAA2B,IAAI,IAAI,KAAK,CAAC,GAAG;AAChE,UAAI;AAAE,WAAG,GAAG,GAAG,QAAQ,GAAG,IAAI;AAAA,MAAG,SAAS,GAAG;AAAE,gBAAQ,MAAM,+BAA+B,CAAC;AAAA,MAAG;AAAA,IAClG;AACA,SAAK,2BAA2B,OAAO,IAAI;AAAA,EAC7C;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,58 +1,100 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
1
|
import { ReflectUtils } from "@dooboostore/core";
|
|
2
|
+
import { ensureInit } from "./elementDefine.js";
|
|
3
|
+
import { SwcUtils } from "../utils/Utils.js";
|
|
4
|
+
import { buildSwcParameterArgs } from "./parameter.js";
|
|
5
5
|
const SET_INTERVAL_METADATA_KEY = Symbol.for("simple-web-component:set-interval");
|
|
6
|
+
const getActiveEntries = (inst) => inst.__swc_intervalIds ?? (inst.__swc_intervalIds = []);
|
|
6
7
|
function setInterval(interval, options = {}) {
|
|
7
|
-
return (target, propertyKey) => {
|
|
8
|
+
return (target, propertyKey, descriptor) => {
|
|
8
9
|
const constructor = target.constructor;
|
|
10
|
+
const normalizedOptions = { ...options, type: options.type ?? "returnValue" };
|
|
9
11
|
let metaList = ReflectUtils.getOwnMetadata(SET_INTERVAL_METADATA_KEY, constructor);
|
|
10
12
|
if (!metaList) {
|
|
11
13
|
metaList = [];
|
|
12
14
|
ReflectUtils.defineMetadata(SET_INTERVAL_METADATA_KEY, metaList, constructor);
|
|
13
15
|
}
|
|
14
|
-
metaList.push({ propertyKey, interval, options });
|
|
16
|
+
metaList.push({ propertyKey, interval, options: normalizedOptions });
|
|
17
|
+
if (normalizedOptions.type === "onConnected" || !descriptor) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const original = descriptor.value;
|
|
21
|
+
descriptor.value = function(...args) {
|
|
22
|
+
const res = original.apply(this, args);
|
|
23
|
+
const vk = normalizedOptions.valueKey ?? SET_INTERVAL_METADATA_KEY;
|
|
24
|
+
const tickFn = typeof res === "function" ? res : res && typeof res === "object" && typeof res[vk] === "function" ? res[vk] : void 0;
|
|
25
|
+
if (tickFn) {
|
|
26
|
+
ensureInit(this);
|
|
27
|
+
const win = SwcUtils.resolveWindow(this);
|
|
28
|
+
const id = win.setInterval(() => {
|
|
29
|
+
try {
|
|
30
|
+
tickFn(id);
|
|
31
|
+
} catch (e) {
|
|
32
|
+
console.error("[SWC] setInterval tick error:", e);
|
|
33
|
+
}
|
|
34
|
+
}, interval);
|
|
35
|
+
normalizedOptions.created?.(SwcUtils.getHelperAndHostSet(this), id);
|
|
36
|
+
getActiveEntries(this).push(id);
|
|
37
|
+
}
|
|
38
|
+
return res;
|
|
39
|
+
};
|
|
40
|
+
return descriptor;
|
|
15
41
|
};
|
|
16
42
|
}
|
|
17
43
|
const findAllSetIntervalMetadata = (target) => {
|
|
18
|
-
const constructor = target
|
|
44
|
+
const constructor = typeof target === "function" ? target : target.constructor;
|
|
19
45
|
return (ReflectUtils.findAllMetadata(SET_INTERVAL_METADATA_KEY, constructor) || []).flat();
|
|
20
46
|
};
|
|
21
47
|
class SetIntervalLifeCycler {
|
|
22
|
-
constructor() {
|
|
23
|
-
__publicField(this, "activeMap", /* @__PURE__ */ new WeakMap());
|
|
24
|
-
}
|
|
25
48
|
onConnected(helperHostSet) {
|
|
26
49
|
const inst = helperHostSet.$this;
|
|
27
|
-
|
|
50
|
+
inst.__swc_intervalIds = [];
|
|
28
51
|
for (const meta of findAllSetIntervalMetadata(inst)) {
|
|
52
|
+
if (meta.options.type !== "onConnected") continue;
|
|
29
53
|
const id = helperHostSet.$w.setInterval(() => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
54
|
+
void (async () => {
|
|
55
|
+
const helper = SwcUtils.getHelperAndHostSet(inst);
|
|
56
|
+
if (meta.options.filter && !await meta.options.filter(helper)) return;
|
|
57
|
+
const paramArgs = meta.options.parameter?.(helperHostSet) ?? [];
|
|
58
|
+
const hostSet = SwcUtils.getHostSet(inst);
|
|
59
|
+
const helperSet = SwcUtils.getHelperSet(helperHostSet.$w);
|
|
60
|
+
const buildArgs = (beforeReturn) => buildSwcParameterArgs(inst, meta.propertyKey, {
|
|
61
|
+
hostSet,
|
|
62
|
+
helperHostSet: helper,
|
|
63
|
+
helperSet,
|
|
64
|
+
setIntervalBeforeReturn: beforeReturn
|
|
65
|
+
}, [...paramArgs, beforeReturn]);
|
|
66
|
+
let args = buildArgs(void 0);
|
|
67
|
+
if (meta.options.before) {
|
|
68
|
+
const br = await meta.options.before(helper);
|
|
69
|
+
args = buildArgs(br);
|
|
70
|
+
}
|
|
71
|
+
let result, error;
|
|
72
|
+
try {
|
|
73
|
+
result = await inst[meta.propertyKey](...args);
|
|
74
|
+
const vk = meta.options.valueKey ?? SET_INTERVAL_METADATA_KEY;
|
|
75
|
+
if (result && typeof result === "object" && typeof result[vk] === "function") result[vk](id);
|
|
76
|
+
} catch (e) {
|
|
77
|
+
error = e;
|
|
78
|
+
} finally {
|
|
79
|
+
if (meta.options.finally) await meta.options.finally(helper, { args, result, error });
|
|
36
80
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
81
|
+
if (error) console.error("[SWC] setInterval tick error:", error);
|
|
82
|
+
})().catch((e) => console.error("[SWC] setInterval tick error:", e));
|
|
40
83
|
}, meta.interval);
|
|
41
84
|
meta.options.created?.(helperHostSet, id);
|
|
42
|
-
|
|
85
|
+
getActiveEntries(inst).push(id);
|
|
43
86
|
}
|
|
44
|
-
this.activeMap.set(inst, ids);
|
|
45
87
|
}
|
|
46
88
|
onDisconnected(helperHostSet) {
|
|
47
89
|
const inst = helperHostSet.$this;
|
|
48
|
-
for (const id of
|
|
90
|
+
for (const id of inst.__swc_intervalIds ?? []) {
|
|
49
91
|
try {
|
|
50
92
|
helperHostSet.$w.clearInterval(id);
|
|
51
93
|
} catch (e) {
|
|
52
94
|
console.error("[SWC] clearInterval error:", e);
|
|
53
95
|
}
|
|
54
96
|
}
|
|
55
|
-
|
|
97
|
+
inst.__swc_intervalIds = [];
|
|
56
98
|
}
|
|
57
99
|
}
|
|
58
100
|
export {
|