@dooboostore/simple-web-component 1.0.49 → 1.0.50
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 +72 -0
- package/dist/cjs/decorators/addEventListener.js +1994 -9
- package/dist/cjs/decorators/addEventListener.js.map +2 -2
- package/dist/cjs/decorators/applyAttribute.js +10 -4
- package/dist/cjs/decorators/applyAttribute.js.map +2 -2
- package/dist/cjs/decorators/applyClass.js +10 -4
- package/dist/cjs/decorators/applyClass.js.map +2 -2
- package/dist/cjs/decorators/applyNode.js +10 -4
- package/dist/cjs/decorators/applyNode.js.map +2 -2
- package/dist/cjs/decorators/applyProperty.js +14 -8
- package/dist/cjs/decorators/applyProperty.js.map +2 -2
- package/dist/cjs/decorators/applySlot.js +6 -5
- package/dist/cjs/decorators/applySlot.js.map +2 -2
- package/dist/cjs/decorators/applyStyle.js +10 -4
- package/dist/cjs/decorators/applyStyle.js.map +2 -2
- package/dist/cjs/decorators/changedAttribute.js +22 -13
- package/dist/cjs/decorators/changedAttribute.js.map +2 -2
- package/dist/cjs/decorators/elementDefine.js +18 -3
- package/dist/cjs/decorators/elementDefine.js.map +2 -2
- package/dist/cjs/decorators/eventMedia.js +84 -0
- package/dist/cjs/decorators/eventMedia.js.map +7 -0
- package/dist/cjs/decorators/index.js +3 -0
- package/dist/cjs/decorators/index.js.map +2 -2
- package/dist/cjs/decorators/intersectionObserver.js +46 -55
- package/dist/cjs/decorators/intersectionObserver.js.map +2 -2
- package/dist/cjs/decorators/mutationObserver.js +46 -55
- package/dist/cjs/decorators/mutationObserver.js.map +2 -2
- package/dist/cjs/decorators/parameter.js +73 -0
- package/dist/cjs/decorators/parameter.js.map +7 -0
- package/dist/cjs/decorators/requestAnimationFrame.js +124 -0
- package/dist/cjs/decorators/requestAnimationFrame.js.map +7 -0
- package/dist/cjs/decorators/resizeObserver.js +46 -55
- package/dist/cjs/decorators/resizeObserver.js.map +2 -2
- package/dist/cjs/decorators/setInterval.js +46 -14
- package/dist/cjs/decorators/setInterval.js.map +2 -2
- package/dist/cjs/decorators/setTimeout.js +49 -14
- package/dist/cjs/decorators/setTimeout.js.map +2 -2
- package/dist/cjs/elements/SwcAppMixin.js +19 -3
- package/dist/cjs/elements/SwcAppMixin.js.map +2 -2
- package/dist/cjs/types/window.d.js.map +1 -1
- package/dist/esm/decorators/addEventListener.js +1994 -9
- package/dist/esm/decorators/addEventListener.js.map +2 -2
- package/dist/esm/decorators/applyAttribute.js +10 -4
- package/dist/esm/decorators/applyAttribute.js.map +2 -2
- package/dist/esm/decorators/applyClass.js +10 -4
- package/dist/esm/decorators/applyClass.js.map +2 -2
- package/dist/esm/decorators/applyNode.js +10 -4
- package/dist/esm/decorators/applyNode.js.map +2 -2
- package/dist/esm/decorators/applyProperty.js +14 -8
- package/dist/esm/decorators/applyProperty.js.map +2 -2
- package/dist/esm/decorators/applySlot.js +6 -5
- package/dist/esm/decorators/applySlot.js.map +2 -2
- package/dist/esm/decorators/applyStyle.js +10 -4
- package/dist/esm/decorators/applyStyle.js.map +2 -2
- package/dist/esm/decorators/changedAttribute.js +22 -13
- package/dist/esm/decorators/changedAttribute.js.map +2 -2
- package/dist/esm/decorators/elementDefine.js +18 -3
- package/dist/esm/decorators/elementDefine.js.map +2 -2
- package/dist/esm/decorators/eventMedia.js +66 -0
- package/dist/esm/decorators/eventMedia.js.map +7 -0
- package/dist/esm/decorators/index.js +3 -0
- package/dist/esm/decorators/index.js.map +2 -2
- package/dist/esm/decorators/intersectionObserver.js +46 -55
- package/dist/esm/decorators/intersectionObserver.js.map +2 -2
- package/dist/esm/decorators/mutationObserver.js +46 -55
- package/dist/esm/decorators/mutationObserver.js.map +2 -2
- package/dist/esm/decorators/parameter.js +54 -0
- package/dist/esm/decorators/parameter.js.map +7 -0
- package/dist/esm/decorators/requestAnimationFrame.js +105 -0
- package/dist/esm/decorators/requestAnimationFrame.js.map +7 -0
- package/dist/esm/decorators/resizeObserver.js +46 -55
- package/dist/esm/decorators/resizeObserver.js.map +2 -2
- package/dist/esm/decorators/setInterval.js +46 -15
- package/dist/esm/decorators/setInterval.js.map +2 -2
- package/dist/esm/decorators/setTimeout.js +49 -15
- package/dist/esm/decorators/setTimeout.js.map +2 -2
- package/dist/esm/elements/SwcAppMixin.js +20 -4
- package/dist/esm/elements/SwcAppMixin.js.map +2 -2
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +2813 -571
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/decorators/addEventListener.d.ts +962 -0
- package/dist/types/decorators/addEventListener.d.ts.map +1 -1
- package/dist/types/decorators/applyAttribute.d.ts +2 -0
- package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
- package/dist/types/decorators/applyClass.d.ts +2 -0
- package/dist/types/decorators/applyClass.d.ts.map +1 -1
- package/dist/types/decorators/applyNode.d.ts +2 -0
- package/dist/types/decorators/applyNode.d.ts.map +1 -1
- package/dist/types/decorators/applyProperty.d.ts +4 -0
- 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 -0
- package/dist/types/decorators/applyStyle.d.ts.map +1 -1
- package/dist/types/decorators/changedAttribute.d.ts +1 -3
- package/dist/types/decorators/changedAttribute.d.ts.map +1 -1
- package/dist/types/decorators/elementDefine.d.ts.map +1 -1
- package/dist/types/decorators/eventMedia.d.ts +25 -0
- package/dist/types/decorators/eventMedia.d.ts.map +1 -0
- package/dist/types/decorators/index.d.ts +3 -0
- package/dist/types/decorators/index.d.ts.map +1 -1
- package/dist/types/decorators/intersectionObserver.d.ts +9 -0
- package/dist/types/decorators/intersectionObserver.d.ts.map +1 -1
- package/dist/types/decorators/mutationObserver.d.ts +10 -1
- package/dist/types/decorators/mutationObserver.d.ts.map +1 -1
- package/dist/types/decorators/parameter.d.ts +35 -0
- package/dist/types/decorators/parameter.d.ts.map +1 -0
- 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 +9 -0
- package/dist/types/decorators/resizeObserver.d.ts.map +1 -1
- package/dist/types/decorators/setInterval.d.ts +17 -5
- package/dist/types/decorators/setInterval.d.ts.map +1 -1
- package/dist/types/decorators/setTimeout.d.ts +17 -5
- package/dist/types/decorators/setTimeout.d.ts.map +1 -1
- package/dist/types/elements/SwcAppMixin.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +2813 -571
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +3 -3
- package/src/decorators/addEventListener.ts +1060 -8
- package/src/decorators/applyAttribute.ts +14 -4
- package/src/decorators/applyClass.ts +14 -4
- package/src/decorators/applyNode.ts +14 -4
- package/src/decorators/applyProperty.ts +28 -8
- package/src/decorators/applySlot.ts +6 -5
- package/src/decorators/applyStyle.ts +14 -4
- package/src/decorators/changedAttribute.ts +30 -15
- package/src/decorators/elementDefine.ts +32 -5
- package/src/decorators/eventMedia.ts +78 -0
- package/src/decorators/index.ts +3 -0
- package/src/decorators/intersectionObserver.ts +77 -61
- package/src/decorators/mutationObserver.ts +78 -61
- package/src/decorators/parameter.ts +81 -0
- package/src/decorators/requestAnimationFrame.ts +158 -0
- package/src/decorators/resizeObserver.ts +76 -60
- package/src/decorators/setInterval.ts +71 -15
- package/src/decorators/setTimeout.ts +74 -15
- package/src/elements/SwcAppMixin.ts +20 -5
- package/src/types/window.d.ts +2 -18
- package/dist/cjs/examples/RxJSOperatorsExample.js +0 -285
- package/dist/cjs/examples/RxJSOperatorsExample.js.map +0 -7
- package/dist/esm/examples/RxJSOperatorsExample.js +0 -266
- package/dist/esm/examples/RxJSOperatorsExample.js.map +0 -7
- package/dist/types/examples/RxJSOperatorsExample.d.ts +0 -94
- package/dist/types/examples/RxJSOperatorsExample.d.ts.map +0 -1
- package/src/examples/RxJSOperatorsExample.ts +0 -279
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/decorators/intersectionObserver.ts"],
|
|
4
|
-
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core';\nimport { SpecialSelector, SwcQueryOptions, SwcFnSelector, SwcSelector, HelperHostSet } from '../types';\n\n// \uACF5\uD1B5 \uC635\uC158 \u2014 IntersectionObserverInit + filter/removeObserver. root\u00B7delegate \uC81C\uC678.\n// \uC8FC\uC758: \uB370\uCF54\uB808\uC774\uD130\uC758 root(light/shadow/all/auto) \uB294 \uC140\uB809\uD130 \uC2A4\uCF54\uD504 \uC120\uD0DD\uC6A9\uC774\uB2E4.\n// IntersectionObserver \uC758 \uC2A4\uD06C\uB864 \uCEE8\uD14C\uC774\uB108 root \uB294 intersectionRoot \uB85C \uC9C0\uC815\uD55C\uB2E4.\nexport interface IntersectionObserverBaseOptions extends Omit<IntersectionObserverInit, 'root'> {\n /** IntersectionObserver \uC758 \uC2A4\uD06C\uB864 \uCEE8\uD14C\uC774\uB108 (viewport \uB300\uC2E0). \uB370\uCF54\uB808\uC774\uD130 root \uC640 \uD63C\uB3D9 \uC8FC\uC758. */\n intersectionRoot?: Element | Document;\n filter?: (matchedEls: HTMLElement[], meta: { currentThis: any, helper: HelperHostSet }) => boolean;\n removeObserver?: (target: Element, optionValue: IntersectionObserverQueryOptions) => void;\n}\n\n// \uBB38\uC790\uC5F4 \uC140\uB809\uD130 \uC804\uC6A9 \u2014 root\u00B7delegate \uD5C8\uC6A9\nexport type IntersectionObserverQueryOptions = IntersectionObserverBaseOptions & SwcQueryOptions & { delegate?: boolean };\n// \uD568\uC218 \uC140\uB809\uD130 \uC804\uC6A9 \u2014 root\u00B7delegate \uAE08\uC9C0\nexport type IntersectionObserverNonQueryOptions = IntersectionObserverBaseOptions;\n// \uB0B4\uBD80 \uC800\uC7A5/\uD574\uC11D\uC6A9\nexport type IntersectionObserverOptions = IntersectionObserverQueryOptions;\n\n// \uC140\uB809\uD130 \uC885\uB958\uC5D0 \uB530\uB77C \uC635\uC158 \uD0C0\uC785 \uBD84\uAE30\nexport type IntersectionObserverOptionsOf<S extends SwcSelector> = S extends string ? IntersectionObserverQueryOptions : IntersectionObserverNonQueryOptions;\n\nexport interface IntersectionObserverMetadata {\n propertyKey: string | symbol;\n selector: SwcSelector;\n options: IntersectionObserverOptions;\n}\n\nexport const INTERSECTION_OBSERVER_METADATA_KEY = Symbol.for('simple-web-component:intersection-observer');\n\nexport function intersectionObserver(target: SpecialSelector, options?: IntersectionObserverQueryOptions): MethodDecorator;\nexport function intersectionObserver(selector: string, options?: IntersectionObserverQueryOptions): MethodDecorator;\nexport function intersectionObserver(selector: SwcFnSelector, options?: IntersectionObserverNonQueryOptions): MethodDecorator;\nexport function intersectionObserver(options?: IntersectionObserverQueryOptions): MethodDecorator;\n/**\n * @intersectionObserver decorator to observe element intersection changes.\n *\n * IntersectionObserver \uB294 \uC0DD\uC131 \uC2DC\uC810\uC5D0 \uC635\uC158(threshold/rootMargin/root)\uC774 \uACE0\uC815\uB418\uBBC0\uB85C,\n * \uC635\uC158\uBCC4\uB85C \uADF8\uB8F9\uC744 \uB9CC\uB4E4\uC5B4 observer \uB97C \uC0DD\uC131\uD55C\uB2E4. \uAC19\uC740 \uC635\uC158 \uADF8\uB8F9 \uC548\uC5D0\uC11C delegate \uB3D9\uC801 \uCD94\uC801\uC774 \uAC00\uB2A5\uD558\uB2E4.\n */\nexport function intersectionObserver(selectorOrOptions?: SwcSelector | IntersectionObserverOptions, maybeOptions?: IntersectionObserverOptions): MethodDecorator {\n return (targetObj: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n let selector: SwcSelector = '$this';\n let options: IntersectionObserverOptions = {};\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<IntersectionObserverMetadata[]>(INTERSECTION_OBSERVER_METADATA_KEY, constructor);\n if (!observers) {\n observers = [];\n ReflectUtils.defineMetadata(INTERSECTION_OBSERVER_METADATA_KEY, observers, constructor);\n }\n\n observers.push({ propertyKey, selector, options });\n };\n}\n\nexport function intersectionObserverThis(options?: IntersectionObserverQueryOptions): MethodDecorator {\n return intersectionObserver('$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 intersectionObserverDelegateLight(selector: string, options?: Omit<IntersectionObserverQueryOptions, 'delegate'>): MethodDecorator;\nexport function intersectionObserverDelegateLight(options?: Omit<IntersectionObserverQueryOptions, 'delegate'>): MethodDecorator;\nexport function intersectionObserverDelegateLight(selectorOrOptions?: string | Omit<IntersectionObserverQueryOptions, 'delegate'>, maybeOptions?: Omit<IntersectionObserverQueryOptions, 'delegate'>): MethodDecorator {\n if (typeof selectorOrOptions === 'string' || typeof selectorOrOptions === 'function') {\n return intersectionObserver(selectorOrOptions as any, {...maybeOptions ?? {}, root: 'light', delegate: true});\n }\n return intersectionObserver({...selectorOrOptions ?? {}, root: 'light', delegate: true});\n}\n\nexport function intersectionObserverDelegateShadow(selector: string, options?: Omit<IntersectionObserverQueryOptions, 'delegate'>): MethodDecorator;\nexport function intersectionObserverDelegateShadow(options?: Omit<IntersectionObserverQueryOptions, 'delegate'>): MethodDecorator;\nexport function intersectionObserverDelegateShadow(selectorOrOptions?: string | Omit<IntersectionObserverQueryOptions, 'delegate'>, maybeOptions?: Omit<IntersectionObserverQueryOptions, 'delegate'>): MethodDecorator {\n if (typeof selectorOrOptions === 'string' || typeof selectorOrOptions === 'function') {\n return intersectionObserver(selectorOrOptions as any, {...maybeOptions ?? {}, root: 'shadow', delegate: true});\n }\n return intersectionObserver({...selectorOrOptions ?? {}, root: 'shadow', delegate: true});\n}\n\nexport function intersectionObserverDelegateAll(selector: string, options?: Omit<IntersectionObserverQueryOptions, 'delegate'>): MethodDecorator;\nexport function intersectionObserverDelegateAll(options?: Omit<IntersectionObserverQueryOptions, 'delegate'>): MethodDecorator;\nexport function intersectionObserverDelegateAll(selectorOrOptions?: string | Omit<IntersectionObserverQueryOptions, 'delegate'>, maybeOptions?: Omit<IntersectionObserverQueryOptions, 'delegate'>): MethodDecorator {\n if (typeof selectorOrOptions === 'string' || typeof selectorOrOptions === 'function') {\n return intersectionObserver(selectorOrOptions as any, {...maybeOptions ?? {}, root: 'all', delegate: true});\n }\n return intersectionObserver({...selectorOrOptions ?? {}, root: 'all', delegate: true});\n}\n\nexport function intersectionObserverDelegate(selector: string, options?: Omit<IntersectionObserverQueryOptions, 'delegate'>): MethodDecorator;\nexport function intersectionObserverDelegate(options?: Omit<IntersectionObserverQueryOptions, 'delegate'>): MethodDecorator;\nexport function intersectionObserverDelegate(selectorOrOptions?: string | Omit<IntersectionObserverQueryOptions, 'delegate'>, maybeOptions?: Omit<IntersectionObserverQueryOptions, 'delegate'>): MethodDecorator {\n if (typeof selectorOrOptions === 'string' || typeof selectorOrOptions === 'function') {\n return intersectionObserver(selectorOrOptions as any, {...maybeOptions ?? {}, root: 'auto', delegate: true});\n }\n return intersectionObserver({...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 intersectionObserverLight(selector: string, options?: IntersectionObserverQueryOptions): MethodDecorator;\nexport function intersectionObserverLight(options?: IntersectionObserverQueryOptions): MethodDecorator;\nexport function intersectionObserverLight(selectorOrOptions?: string | IntersectionObserverQueryOptions, maybeOptions?: IntersectionObserverQueryOptions): MethodDecorator {\n if (typeof selectorOrOptions === 'string' || typeof selectorOrOptions === 'function') {\n return intersectionObserver(selectorOrOptions as any, {...maybeOptions ?? {}, root: 'light'});\n }\n return intersectionObserver({...selectorOrOptions ?? {}, root: 'light'});\n}\n\nexport function intersectionObserverShadow(selector: string, options?: IntersectionObserverQueryOptions): MethodDecorator;\nexport function intersectionObserverShadow(options?: IntersectionObserverQueryOptions): MethodDecorator;\nexport function intersectionObserverShadow(selectorOrOptions?: string | IntersectionObserverQueryOptions, maybeOptions?: IntersectionObserverQueryOptions): MethodDecorator {\n if (typeof selectorOrOptions === 'string' || typeof selectorOrOptions === 'function') {\n return intersectionObserver(selectorOrOptions as any, {...maybeOptions ?? {}, root: 'shadow'});\n }\n return intersectionObserver({...selectorOrOptions ?? {}, root: 'shadow'});\n}\n\nexport function intersectionObserverAll(selector: string, options?: IntersectionObserverQueryOptions): MethodDecorator;\nexport function intersectionObserverAll(options?: IntersectionObserverQueryOptions): MethodDecorator;\nexport function intersectionObserverAll(selectorOrOptions?: string | IntersectionObserverQueryOptions, maybeOptions?: IntersectionObserverQueryOptions): MethodDecorator {\n if (typeof selectorOrOptions === 'string' || typeof selectorOrOptions === 'function') {\n return intersectionObserver(selectorOrOptions as any, {...maybeOptions ?? {}, root: 'all'});\n }\n return intersectionObserver({...selectorOrOptions ?? {}, root: 'all'});\n}\n\nexport function getIntersectionObserverMetadata(target: any): IntersectionObserverMetadata[] | undefined {\n const constructor = target instanceof Function ? target : target.constructor;\n return ReflectUtils.getMetadata(INTERSECTION_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// IntersectionObserverLifeCycler\n// observer \uB97C \uC9C1\uC811 \uC0DD\uC131\uD558\uC9C0 \uC54A\uACE0 \uC635\uC158 \uADF8\uB8F9 \uBC30\uC5F4(IntersectionObserverSet)\uC744 \uBC18\uD658\uD55C\uB2E4.\n// elementDefine \uC774 \uADF8\uB8F9\uBCC4\uB85C observer \uB97C \uC0DD\uC131\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, IntersectionObserverSet, IntersectionObserverGroup, IntersectionObserverSetEntry } from '../types';\nimport { SwcUtils } from '../utils/Utils';\n\nexport class IntersectionObserverLifeCycler 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 = getIntersectionObserverMetadata(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 IntersectionObserver \uCF5C\uBC31 \u2500\u2500\n const buildCallback = (metas: IntersectionObserverMetadata[]): IntersectionObserverSetEntry['callback'] => {\n return (entries, obs) => {\n for (const m of metas) {\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\n // \u2500\u2500 \uC635\uC158\uBCC4 \uADF8\uB8F9\uD551: \uAC19\uC740 observer \uC635\uC158(threshold/rootMargin/intersectionRoot)\uB07C\uB9AC \uBB36\uB294\uB2E4 \u2500\u2500\n // delegate:true \uD56D\uBAA9\uC740 \uB3D9\uC801 \uCD94\uC801\uC6A9 \uC140\uB809\uD130 \uBB38\uC790\uC5F4\uB85C \uC120\uC5B8\uB41C\uB2E4.\n const groups = new Map<string, { options: IntersectionObserverInit; metas: IntersectionObserverMetadata[] }>();\n for (const m of allMeta) {\n const obsOptions: IntersectionObserverInit = {\n root: m.options.intersectionRoot ?? null,\n rootMargin: m.options.rootMargin,\n threshold: m.options.threshold,\n };\n const key = JSON.stringify([obsOptions.root, obsOptions.rootMargin, obsOptions.threshold]);\n if (!groups.has(key)) groups.set(key, { options: obsOptions, metas: [] });\n groups.get(key)!.metas.push(m);\n }\n\n const intersectionObserverSet: IntersectionObserverSet = [];\n for (const [, group] of groups) {\n const callback = buildCallback(group.metas);\n const observeTargets: IntersectionObserverGroup['observeTargets'] = [];\n\n for (const m of group.metas) {\n if (m.options.delegate && typeof m.selector === 'string') {\n observeTargets.push({ target: m.selector, delegate: true, delegateRoot: m.options.root, 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) observeTargets.push({ target: el, callback });\n }\n\n intersectionObserverSet.push({ options: group.options, observeTargets });\n }\n\n return { intersectionObserverSet };\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}"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA6B;
|
|
4
|
+
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core';\nimport { SpecialSelector, SwcQueryOptions, SwcFnSelector, SwcSelector, HelperHostSet } from '../types';\n\n// \uACF5\uD1B5 \uC635\uC158 \u2014 IntersectionObserverInit + filter/removeObserver. root\u00B7delegate \uC81C\uC678.\n// \uC8FC\uC758: \uB370\uCF54\uB808\uC774\uD130\uC758 root(light/shadow/all/auto) \uB294 \uC140\uB809\uD130 \uC2A4\uCF54\uD504 \uC120\uD0DD\uC6A9\uC774\uB2E4.\n// IntersectionObserver \uC758 \uC2A4\uD06C\uB864 \uCEE8\uD14C\uC774\uB108 root \uB294 intersectionRoot \uB85C \uC9C0\uC815\uD55C\uB2E4.\nexport interface IntersectionObserverBaseOptions extends Omit<IntersectionObserverInit, 'root'> {\n /** IntersectionObserver \uC758 \uC2A4\uD06C\uB864 \uCEE8\uD14C\uC774\uB108 (viewport \uB300\uC2E0). \uB370\uCF54\uB808\uC774\uD130 root \uC640 \uD63C\uB3D9 \uC8FC\uC758. */\n intersectionRoot?: Element | Document;\n filter?: (matchedEls: HTMLElement[], meta: { currentThis: any, helper: HelperHostSet }) => boolean;\n removeObserver?: (target: Element, optionValue: IntersectionObserverQueryOptions) => void;\n}\n\n// \uBB38\uC790\uC5F4 \uC140\uB809\uD130 \uC804\uC6A9 \u2014 root\u00B7delegate \uD5C8\uC6A9\nexport type IntersectionObserverQueryOptions = IntersectionObserverBaseOptions & SwcQueryOptions & { delegate?: boolean };\n// \uD568\uC218 \uC140\uB809\uD130 \uC804\uC6A9 \u2014 root\u00B7delegate \uAE08\uC9C0\nexport type IntersectionObserverNonQueryOptions = IntersectionObserverBaseOptions;\n// \uB0B4\uBD80 \uC800\uC7A5/\uD574\uC11D\uC6A9\nexport type IntersectionObserverOptions = IntersectionObserverQueryOptions;\n\n// \uC140\uB809\uD130 \uC885\uB958\uC5D0 \uB530\uB77C \uC635\uC158 \uD0C0\uC785 \uBD84\uAE30\nexport type IntersectionObserverOptionsOf<S extends SwcSelector> = S extends string ? IntersectionObserverQueryOptions : IntersectionObserverNonQueryOptions;\n\nexport interface IntersectionObserverMetadata {\n propertyKey: string | symbol;\n selector: SwcSelector;\n options: IntersectionObserverOptions;\n}\n\nexport const INTERSECTION_OBSERVER_METADATA_KEY = Symbol.for('simple-web-component:intersection-observer');\n\nconst applyIntersectionObserver = (selector: SwcSelector, options: IntersectionObserverOptions, targetObj: Object, propertyKey: string | symbol): void => {\n const constructor = targetObj.constructor;\n let observers = ReflectUtils.getMetadata<IntersectionObserverMetadata[]>(INTERSECTION_OBSERVER_METADATA_KEY, constructor);\n if (!observers) {\n observers = [];\n ReflectUtils.defineMetadata(INTERSECTION_OBSERVER_METADATA_KEY, observers, constructor);\n }\n observers.push({ propertyKey, selector, options });\n};\n\nconst resolveIntersectionObserverArgs = (\n selectorOrOptions: SwcSelector | IntersectionObserverOptions | undefined,\n maybeOptions: IntersectionObserverOptions | undefined,\n extra: Partial<IntersectionObserverOptions>\n): { selector: SwcSelector; options: IntersectionObserverOptions } => {\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()/@decorator(...)) \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 dispatchIntersectionObserver = (\n selectorOrOptionsOrTarget: SwcSelector | IntersectionObserverOptions | Object | undefined,\n maybeOptionsOrPropertyKey: IntersectionObserverOptions | string | symbol | undefined,\n descriptor: PropertyDescriptor | undefined,\n extra: Partial<IntersectionObserverOptions>\n): MethodDecorator | void => {\n if ((typeof maybeOptionsOrPropertyKey === 'string' || typeof maybeOptionsOrPropertyKey === 'symbol') && descriptor !== undefined) {\n // \uC635\uC158 \uC5C6\uC774: @decorator\n applyIntersectionObserver('$this', { ...extra }, selectorOrOptionsOrTarget as Object, maybeOptionsOrPropertyKey);\n return;\n }\n // \uC635\uC158\uACFC \uD568\uAED8: @decorator() / @decorator(selector, options) / @decorator(options)\n const { selector, options } = resolveIntersectionObserverArgs(\n selectorOrOptionsOrTarget as SwcSelector | IntersectionObserverOptions | undefined,\n maybeOptionsOrPropertyKey as IntersectionObserverOptions | undefined,\n extra\n );\n return (targetObj: Object, propertyKey: string | symbol) => {\n applyIntersectionObserver(selector, options, targetObj, propertyKey);\n };\n};\n\nexport function intersectionObserver(target: SpecialSelector, options?: IntersectionObserverQueryOptions): MethodDecorator;\nexport function intersectionObserver(selector: string, options?: IntersectionObserverQueryOptions): MethodDecorator;\nexport function intersectionObserver(selector: SwcFnSelector, options?: IntersectionObserverNonQueryOptions): MethodDecorator;\nexport function intersectionObserver(options?: IntersectionObserverQueryOptions): MethodDecorator;\nexport function intersectionObserver(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\n/**\n * @intersectionObserver decorator to observe element intersection changes.\n *\n * IntersectionObserver \uB294 \uC0DD\uC131 \uC2DC\uC810\uC5D0 \uC635\uC158(threshold/rootMargin/root)\uC774 \uACE0\uC815\uB418\uBBC0\uB85C,\n * \uC635\uC158\uBCC4\uB85C \uADF8\uB8F9\uC744 \uB9CC\uB4E4\uC5B4 observer \uB97C \uC0DD\uC131\uD55C\uB2E4. \uAC19\uC740 \uC635\uC158 \uADF8\uB8F9 \uC548\uC5D0\uC11C delegate \uB3D9\uC801 \uCD94\uC801\uC774 \uAC00\uB2A5\uD558\uB2E4.\n * \uC635\uC158 \uC5C6\uC774 `@intersectionObserver` \uADF8\uB300\uB85C \uBD99\uC5EC\uB3C4 \uB418\uACE0, `@intersectionObserver(...)`\uCC98\uB7FC \uC140\uB809\uD130/\uC635\uC158\uC744 \uC904 \uC218\uB3C4 \uC788\uB2E4.\n */\nexport function intersectionObserver(selectorOrOptionsOrTarget?: SwcSelector | IntersectionObserverOptions | Object, maybeOptionsOrPropertyKey?: IntersectionObserverOptions | string | symbol, descriptor?: PropertyDescriptor): MethodDecorator | void {\n return dispatchIntersectionObserver(selectorOrOptionsOrTarget, maybeOptionsOrPropertyKey, descriptor, {});\n}\n\nexport function intersectionObserverThis(options?: IntersectionObserverQueryOptions): MethodDecorator;\nexport function intersectionObserverThis(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function intersectionObserverThis(optionsOrTarget?: IntersectionObserverQueryOptions | Object, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): MethodDecorator | void {\n return dispatchIntersectionObserver(optionsOrTarget, propertyKey, descriptor, {});\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 intersectionObserverDelegateLight(selector: string, options?: Omit<IntersectionObserverQueryOptions, 'delegate'>): MethodDecorator;\nexport function intersectionObserverDelegateLight(options?: Omit<IntersectionObserverQueryOptions, 'delegate'>): MethodDecorator;\nexport function intersectionObserverDelegateLight(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function intersectionObserverDelegateLight(selectorOrOptionsOrTarget?: string | Omit<IntersectionObserverQueryOptions, 'delegate'> | Object, maybeOptionsOrPropertyKey?: Omit<IntersectionObserverQueryOptions, 'delegate'> | string | symbol, descriptor?: PropertyDescriptor): MethodDecorator | void {\n return dispatchIntersectionObserver(selectorOrOptionsOrTarget as any, maybeOptionsOrPropertyKey as any, descriptor, { root: 'light', delegate: true });\n}\n\nexport function intersectionObserverDelegateShadow(selector: string, options?: Omit<IntersectionObserverQueryOptions, 'delegate'>): MethodDecorator;\nexport function intersectionObserverDelegateShadow(options?: Omit<IntersectionObserverQueryOptions, 'delegate'>): MethodDecorator;\nexport function intersectionObserverDelegateShadow(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function intersectionObserverDelegateShadow(selectorOrOptionsOrTarget?: string | Omit<IntersectionObserverQueryOptions, 'delegate'> | Object, maybeOptionsOrPropertyKey?: Omit<IntersectionObserverQueryOptions, 'delegate'> | string | symbol, descriptor?: PropertyDescriptor): MethodDecorator | void {\n return dispatchIntersectionObserver(selectorOrOptionsOrTarget as any, maybeOptionsOrPropertyKey as any, descriptor, { root: 'shadow', delegate: true });\n}\n\nexport function intersectionObserverDelegateAll(selector: string, options?: Omit<IntersectionObserverQueryOptions, 'delegate'>): MethodDecorator;\nexport function intersectionObserverDelegateAll(options?: Omit<IntersectionObserverQueryOptions, 'delegate'>): MethodDecorator;\nexport function intersectionObserverDelegateAll(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function intersectionObserverDelegateAll(selectorOrOptionsOrTarget?: string | Omit<IntersectionObserverQueryOptions, 'delegate'> | Object, maybeOptionsOrPropertyKey?: Omit<IntersectionObserverQueryOptions, 'delegate'> | string | symbol, descriptor?: PropertyDescriptor): MethodDecorator | void {\n return dispatchIntersectionObserver(selectorOrOptionsOrTarget as any, maybeOptionsOrPropertyKey as any, descriptor, { root: 'all', delegate: true });\n}\n\nexport function intersectionObserverDelegate(selector: string, options?: Omit<IntersectionObserverQueryOptions, 'delegate'>): MethodDecorator;\nexport function intersectionObserverDelegate(options?: Omit<IntersectionObserverQueryOptions, 'delegate'>): MethodDecorator;\nexport function intersectionObserverDelegate(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function intersectionObserverDelegate(selectorOrOptionsOrTarget?: string | Omit<IntersectionObserverQueryOptions, 'delegate'> | Object, maybeOptionsOrPropertyKey?: Omit<IntersectionObserverQueryOptions, 'delegate'> | string | symbol, descriptor?: PropertyDescriptor): MethodDecorator | void {\n return dispatchIntersectionObserver(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 intersectionObserverLight(selector: string, options?: IntersectionObserverQueryOptions): MethodDecorator;\nexport function intersectionObserverLight(options?: IntersectionObserverQueryOptions): MethodDecorator;\nexport function intersectionObserverLight(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function intersectionObserverLight(selectorOrOptionsOrTarget?: string | IntersectionObserverQueryOptions | Object, maybeOptionsOrPropertyKey?: IntersectionObserverQueryOptions | string | symbol, descriptor?: PropertyDescriptor): MethodDecorator | void {\n return dispatchIntersectionObserver(selectorOrOptionsOrTarget as any, maybeOptionsOrPropertyKey as any, descriptor, { root: 'light' });\n}\n\nexport function intersectionObserverShadow(selector: string, options?: IntersectionObserverQueryOptions): MethodDecorator;\nexport function intersectionObserverShadow(options?: IntersectionObserverQueryOptions): MethodDecorator;\nexport function intersectionObserverShadow(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function intersectionObserverShadow(selectorOrOptionsOrTarget?: string | IntersectionObserverQueryOptions | Object, maybeOptionsOrPropertyKey?: IntersectionObserverQueryOptions | string | symbol, descriptor?: PropertyDescriptor): MethodDecorator | void {\n return dispatchIntersectionObserver(selectorOrOptionsOrTarget as any, maybeOptionsOrPropertyKey as any, descriptor, { root: 'shadow' });\n}\n\nexport function intersectionObserverAll(selector: string, options?: IntersectionObserverQueryOptions): MethodDecorator;\nexport function intersectionObserverAll(options?: IntersectionObserverQueryOptions): MethodDecorator;\nexport function intersectionObserverAll(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function intersectionObserverAll(selectorOrOptionsOrTarget?: string | IntersectionObserverQueryOptions | Object, maybeOptionsOrPropertyKey?: IntersectionObserverQueryOptions | string | symbol, descriptor?: PropertyDescriptor): MethodDecorator | void {\n return dispatchIntersectionObserver(selectorOrOptionsOrTarget as any, maybeOptionsOrPropertyKey as any, descriptor, { root: 'all' });\n}\n\nexport function getIntersectionObserverMetadata(target: any): IntersectionObserverMetadata[] | undefined {\n const constructor = target instanceof Function ? target : target.constructor;\n return ReflectUtils.getMetadata(INTERSECTION_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// IntersectionObserverLifeCycler\n// observer \uB97C \uC9C1\uC811 \uC0DD\uC131\uD558\uC9C0 \uC54A\uACE0 \uC635\uC158 \uADF8\uB8F9 \uBC30\uC5F4(IntersectionObserverSet)\uC744 \uBC18\uD658\uD55C\uB2E4.\n// elementDefine \uC774 \uADF8\uB8F9\uBCC4\uB85C observer \uB97C \uC0DD\uC131\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, IntersectionObserverSet, IntersectionObserverGroup, IntersectionObserverSetEntry } from '../types';\nimport { SwcUtils } from '../utils/Utils';\n\nexport class IntersectionObserverLifeCycler 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 = getIntersectionObserverMetadata(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 IntersectionObserver \uCF5C\uBC31 \u2500\u2500\n const buildCallback = (metas: IntersectionObserverMetadata[]): IntersectionObserverSetEntry['callback'] => {\n return (entries, obs) => {\n for (const m of metas) {\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\n // \u2500\u2500 \uC635\uC158\uBCC4 \uADF8\uB8F9\uD551: \uAC19\uC740 observer \uC635\uC158(threshold/rootMargin/intersectionRoot)\uB07C\uB9AC \uBB36\uB294\uB2E4 \u2500\u2500\n // delegate:true \uD56D\uBAA9\uC740 \uB3D9\uC801 \uCD94\uC801\uC6A9 \uC140\uB809\uD130 \uBB38\uC790\uC5F4\uB85C \uC120\uC5B8\uB41C\uB2E4.\n const groups = new Map<string, { options: IntersectionObserverInit; metas: IntersectionObserverMetadata[] }>();\n for (const m of allMeta) {\n const obsOptions: IntersectionObserverInit = {\n root: m.options.intersectionRoot ?? null,\n rootMargin: m.options.rootMargin,\n threshold: m.options.threshold,\n };\n const key = JSON.stringify([obsOptions.root, obsOptions.rootMargin, obsOptions.threshold]);\n if (!groups.has(key)) groups.set(key, { options: obsOptions, metas: [] });\n groups.get(key)!.metas.push(m);\n }\n\n const intersectionObserverSet: IntersectionObserverSet = [];\n for (const [, group] of groups) {\n const callback = buildCallback(group.metas);\n const observeTargets: IntersectionObserverGroup['observeTargets'] = [];\n\n for (const m of group.metas) {\n if (m.options.delegate && typeof m.selector === 'string') {\n observeTargets.push({ target: m.selector, delegate: true, delegateRoot: m.options.root, 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) observeTargets.push({ target: el, callback });\n }\n\n intersectionObserverSet.push({ options: group.options, observeTargets });\n }\n\n return { intersectionObserverSet };\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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA6B;AAoK7B,mBAAyB;AAvIlB,MAAM,qCAAqC,OAAO,IAAI,4CAA4C;AAEzG,MAAM,4BAA4B,CAAC,UAAuB,SAAsC,WAAmB,gBAAuC;AACxJ,QAAM,cAAc,UAAU;AAC9B,MAAI,YAAY,yBAAa,YAA4C,oCAAoC,WAAW;AACxH,MAAI,CAAC,WAAW;AACd,gBAAY,CAAC;AACb,6BAAa,eAAe,oCAAoC,WAAW,WAAW;AAAA,EACxF;AACA,YAAU,KAAK,EAAE,aAAa,UAAU,QAAQ,CAAC;AACnD;AAEA,MAAM,kCAAkC,CACtC,mBACA,cACA,UACoE;AACpE,MAAI,OAAO,sBAAsB,YAAY,OAAO,sBAAsB,YAAY;AACpF,WAAO,EAAE,UAAU,mBAAmB,SAAS,EAAE,GAAI,gBAAgB,CA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ACxE;AAEA,8BAAwB,KAAK,EAAE,SAAS,MAAM,SAAS,eAAe,CAAC;AAAA,IACzE;AAEA,WAAO,EAAE,wBAAwB;AAAA,EACnC;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
|
}
|
|
@@ -36,70 +36,61 @@ module.exports = __toCommonJS(mutationObserver_exports);
|
|
|
36
36
|
var import_core = require("@dooboostore/core");
|
|
37
37
|
var import_Utils = require("../utils/Utils");
|
|
38
38
|
const MUTATION_OBSERVER_METADATA_KEY = Symbol.for("simple-web-component:mutation-observer");
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
39
|
+
const applyMutationObserver = (selector, options, targetObj, propertyKey) => {
|
|
40
|
+
const constructor = targetObj.constructor;
|
|
41
|
+
let observers = import_core.ReflectUtils.getMetadata(MUTATION_OBSERVER_METADATA_KEY, constructor);
|
|
42
|
+
if (!observers) {
|
|
43
|
+
observers = [];
|
|
44
|
+
import_core.ReflectUtils.defineMetadata(MUTATION_OBSERVER_METADATA_KEY, observers, constructor);
|
|
45
|
+
}
|
|
46
|
+
observers.push({ propertyKey, selector, options });
|
|
47
|
+
};
|
|
48
|
+
const resolveMutationObserverArgs = (selectorOrOptions, maybeOptions, extra) => {
|
|
49
|
+
if (typeof selectorOrOptions === "string" || typeof selectorOrOptions === "function") {
|
|
50
|
+
return { selector: selectorOrOptions, options: { ...maybeOptions ?? {}, ...extra } };
|
|
51
|
+
}
|
|
52
|
+
return { selector: "$this", options: { ...selectorOrOptions ?? {}, ...extra } };
|
|
53
|
+
};
|
|
54
|
+
const dispatchMutationObserver = (selectorOrOptionsOrTarget, maybeOptionsOrPropertyKey, descriptor, extra) => {
|
|
55
|
+
if ((typeof maybeOptionsOrPropertyKey === "string" || typeof maybeOptionsOrPropertyKey === "symbol") && descriptor !== void 0) {
|
|
56
|
+
applyMutationObserver("$this", { ...extra }, selectorOrOptionsOrTarget, maybeOptionsOrPropertyKey);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const { selector, options } = resolveMutationObserverArgs(
|
|
60
|
+
selectorOrOptionsOrTarget,
|
|
61
|
+
maybeOptionsOrPropertyKey,
|
|
62
|
+
extra
|
|
63
|
+
);
|
|
64
|
+
return (targetObj, propertyKey) => {
|
|
65
|
+
applyMutationObserver(selector, options, targetObj, propertyKey);
|
|
57
66
|
};
|
|
67
|
+
};
|
|
68
|
+
function mutationObserver(selectorOrOptionsOrTarget, maybeOptionsOrPropertyKey, descriptor) {
|
|
69
|
+
return dispatchMutationObserver(selectorOrOptionsOrTarget, maybeOptionsOrPropertyKey, descriptor, {});
|
|
58
70
|
}
|
|
59
|
-
function mutationObserverThis(
|
|
60
|
-
return
|
|
71
|
+
function mutationObserverThis(optionsOrTarget, propertyKey, descriptor) {
|
|
72
|
+
return dispatchMutationObserver(optionsOrTarget, propertyKey, descriptor, {});
|
|
61
73
|
}
|
|
62
|
-
function mutationObserverDelegateLight(
|
|
63
|
-
|
|
64
|
-
return mutationObserver(selectorOrOptions, { ...maybeOptions ?? {}, root: "light", delegate: true });
|
|
65
|
-
}
|
|
66
|
-
return mutationObserver({ ...selectorOrOptions ?? {}, root: "light", delegate: true });
|
|
74
|
+
function mutationObserverDelegateLight(selectorOrOptionsOrTarget, maybeOptionsOrPropertyKey, descriptor) {
|
|
75
|
+
return dispatchMutationObserver(selectorOrOptionsOrTarget, maybeOptionsOrPropertyKey, descriptor, { root: "light", delegate: true });
|
|
67
76
|
}
|
|
68
|
-
function mutationObserverDelegateShadow(
|
|
69
|
-
|
|
70
|
-
return mutationObserver(selectorOrOptions, { ...maybeOptions ?? {}, root: "shadow", delegate: true });
|
|
71
|
-
}
|
|
72
|
-
return mutationObserver({ ...selectorOrOptions ?? {}, root: "shadow", delegate: true });
|
|
77
|
+
function mutationObserverDelegateShadow(selectorOrOptionsOrTarget, maybeOptionsOrPropertyKey, descriptor) {
|
|
78
|
+
return dispatchMutationObserver(selectorOrOptionsOrTarget, maybeOptionsOrPropertyKey, descriptor, { root: "shadow", delegate: true });
|
|
73
79
|
}
|
|
74
|
-
function mutationObserverDelegateAll(
|
|
75
|
-
|
|
76
|
-
return mutationObserver(selectorOrOptions, { ...maybeOptions ?? {}, root: "all", delegate: true });
|
|
77
|
-
}
|
|
78
|
-
return mutationObserver({ ...selectorOrOptions ?? {}, root: "all", delegate: true });
|
|
80
|
+
function mutationObserverDelegateAll(selectorOrOptionsOrTarget, maybeOptionsOrPropertyKey, descriptor) {
|
|
81
|
+
return dispatchMutationObserver(selectorOrOptionsOrTarget, maybeOptionsOrPropertyKey, descriptor, { root: "all", delegate: true });
|
|
79
82
|
}
|
|
80
|
-
function mutationObserverDelegate(
|
|
81
|
-
|
|
82
|
-
return mutationObserver(selectorOrOptions, { ...maybeOptions ?? {}, root: "auto", delegate: true });
|
|
83
|
-
}
|
|
84
|
-
return mutationObserver({ ...selectorOrOptions ?? {}, root: "auto", delegate: true });
|
|
83
|
+
function mutationObserverDelegate(selectorOrOptionsOrTarget, maybeOptionsOrPropertyKey, descriptor) {
|
|
84
|
+
return dispatchMutationObserver(selectorOrOptionsOrTarget, maybeOptionsOrPropertyKey, descriptor, { root: "auto", delegate: true });
|
|
85
85
|
}
|
|
86
|
-
function mutationObserverLight(
|
|
87
|
-
|
|
88
|
-
return mutationObserver(selectorOrOptions, { ...maybeOptions ?? {}, root: "light" });
|
|
89
|
-
}
|
|
90
|
-
return mutationObserver({ ...selectorOrOptions ?? {}, root: "light" });
|
|
86
|
+
function mutationObserverLight(selectorOrOptionsOrTarget, maybeOptionsOrPropertyKey, descriptor) {
|
|
87
|
+
return dispatchMutationObserver(selectorOrOptionsOrTarget, maybeOptionsOrPropertyKey, descriptor, { root: "light" });
|
|
91
88
|
}
|
|
92
|
-
function mutationObserverShadow(
|
|
93
|
-
|
|
94
|
-
return mutationObserver(selectorOrOptions, { ...maybeOptions ?? {}, root: "shadow" });
|
|
95
|
-
}
|
|
96
|
-
return mutationObserver({ ...selectorOrOptions ?? {}, root: "shadow" });
|
|
89
|
+
function mutationObserverShadow(selectorOrOptionsOrTarget, maybeOptionsOrPropertyKey, descriptor) {
|
|
90
|
+
return dispatchMutationObserver(selectorOrOptionsOrTarget, maybeOptionsOrPropertyKey, descriptor, { root: "shadow" });
|
|
97
91
|
}
|
|
98
|
-
function mutationObserverAll(
|
|
99
|
-
|
|
100
|
-
return mutationObserver(selectorOrOptions, { ...maybeOptions ?? {}, root: "all" });
|
|
101
|
-
}
|
|
102
|
-
return mutationObserver({ ...selectorOrOptions ?? {}, root: "all" });
|
|
92
|
+
function mutationObserverAll(selectorOrOptionsOrTarget, maybeOptionsOrPropertyKey, descriptor) {
|
|
93
|
+
return dispatchMutationObserver(selectorOrOptionsOrTarget, maybeOptionsOrPropertyKey, descriptor, { root: "all" });
|
|
103
94
|
}
|
|
104
95
|
function getMutationObserverMetadata(target) {
|
|
105
96
|
const constructor = target instanceof Function ? target : target.constructor;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/decorators/mutationObserver.ts"],
|
|
4
|
-
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core';\nimport { SpecialSelector, SwcQueryOptions, SwcSelector, SwcFnSelector, HelperHostSet } from '../types';\n\n// \uACF5\uD1B5 \uC635\uC158 \u2014 root\u00B7delegate \uC5C6\uC74C (MutationObserverInit + filter/removeObserver)\nexport interface MutationObserverBaseOptions extends MutationObserverInit {\n filter?: (matchedEls: HTMLElement[], meta: { currentThis: any, helper: HelperHostSet }) => boolean;\n // observer \uD574\uC81C(disconnected) \uC2DC \uD638\uCD9C\uB418\uB294 \uCF5C\uBC31. \uCCAB \uBC88\uC9F8 \uC778\uC790\uB294 observe\uB41C target element, \uB450 \uBC88\uC9F8\uB294 \uC0AC\uC6A9\uC790 \uC635\uC158 \uAC1D\uCCB4.\n removeObserver?: (target: Element, optionValue: MutationObserverQueryOptions) => void;\n}\n\n// \uBB38\uC790\uC5F4 \uC140\uB809\uD130 \uC804\uC6A9 \u2014 root\u00B7delegate \uD5C8\uC6A9 (\uC140\uB809\uD130\uB85C \uD0D0\uC0C9/\uB378\uB9AC\uAC8C\uC774\uC158)\nexport type MutationObserverQueryOptions = MutationObserverBaseOptions & SwcQueryOptions & { delegate?: boolean };\n// \uD568\uC218 \uC140\uB809\uD130 \uC804\uC6A9 \u2014 root\u00B7delegate \uAE08\uC9C0 (\uC774\uBBF8 \uC694\uC18C\uB97C \uC9C1\uC811 \uBC18\uD658)\nexport type MutationObserverNonQueryOptions = MutationObserverBaseOptions;\n\n// \uC140\uB809\uD130 \uC885\uB958\uC5D0 \uB530\uB77C \uC635\uC158 \uD0C0\uC785 \uBD84\uAE30\nexport type MutationObserverOptionsOf<S extends SwcSelector> = S extends string ? MutationObserverQueryOptions : MutationObserverNonQueryOptions;\n\nexport interface MutationObserverMetadata {\n propertyKey: string | symbol;\n selector: SwcSelector;\n options: MutationObserverQueryOptions;\n}\n\nexport const MUTATION_OBSERVER_METADATA_KEY = Symbol.for('simple-web-component:mutation-observer');\n\nexport function mutationObserver(target: SpecialSelector, options?: MutationObserverQueryOptions): MethodDecorator;\nexport function mutationObserver(selector: string, options?: MutationObserverQueryOptions): MethodDecorator;\nexport function mutationObserver(selector: SwcFnSelector, options?: MutationObserverNonQueryOptions): MethodDecorator;\nexport function mutationObserver(options?: MutationObserverQueryOptions): MethodDecorator;\n/**\n * @mutationObserver decorator to observe DOM mutations.\n */\nexport function mutationObserver(selectorOrOptions?: SwcSelector | MutationObserverQueryOptions, maybeOptions?: MutationObserverQueryOptions): MethodDecorator {\n return (targetObj: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n let selector: SwcSelector = '$this';\n let options: MutationObserverQueryOptions = {};\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<MutationObserverMetadata[]>(MUTATION_OBSERVER_METADATA_KEY, constructor);\n if (!observers) {\n observers = [];\n ReflectUtils.defineMetadata(MUTATION_OBSERVER_METADATA_KEY, observers, constructor);\n }\n\n observers.push({ propertyKey, selector, options });\n };\n}\n\nexport function mutationObserverThis<TEvent extends Event = Event>(options?: MutationObserverQueryOptions): MethodDecorator {\n return mutationObserver('$this', options);\n}\n\n// \u2500\u2500\u2500 root\uBCC4 delegate \uD5EC\uD37C (addEventListener\uC640 \uB3D9\uC77C \uD328\uD134) \u2500\u2500\u2500\n\nexport function mutationObserverDelegateLight(selector: string, options?: MutationObserverBaseOptions): MethodDecorator;\nexport function mutationObserverDelegateLight(options?: MutationObserverBaseOptions): MethodDecorator;\nexport function mutationObserverDelegateLight(selectorOrOptions?: string | Omit<MutationObserverQueryOptions, 'root'>, maybeOptions?: Omit<MutationObserverQueryOptions, 'root'>): MethodDecorator {\n if (typeof selectorOrOptions === 'string' || typeof selectorOrOptions === 'function') {\n return mutationObserver(selectorOrOptions, {...maybeOptions ?? {}, root: 'light', delegate: true});\n }\n return mutationObserver({...selectorOrOptions ?? {}, root: 'light', delegate: true});\n}\n\nexport function mutationObserverDelegateShadow(selector: string, options?: MutationObserverBaseOptions): MethodDecorator;\nexport function mutationObserverDelegateShadow(options?: MutationObserverBaseOptions): MethodDecorator;\nexport function mutationObserverDelegateShadow(selectorOrOptions?: string | Omit<MutationObserverQueryOptions, 'root'>, maybeOptions?: Omit<MutationObserverQueryOptions, 'root'>): MethodDecorator {\n if (typeof selectorOrOptions === 'string' || typeof selectorOrOptions === 'function') {\n return mutationObserver(selectorOrOptions, {...maybeOptions ?? {}, root: 'shadow', delegate: true});\n }\n return mutationObserver({...selectorOrOptions ?? {}, root: 'shadow', delegate: true});\n}\n\nexport function mutationObserverDelegateAll(selector: string, options?: MutationObserverBaseOptions): MethodDecorator;\nexport function mutationObserverDelegateAll(options?: MutationObserverBaseOptions): MethodDecorator;\nexport function mutationObserverDelegateAll(selectorOrOptions?: string | Omit<MutationObserverQueryOptions, 'root'>, maybeOptions?: Omit<MutationObserverQueryOptions, 'root'>): MethodDecorator {\n if (typeof selectorOrOptions === 'string' || typeof selectorOrOptions === 'function') {\n return mutationObserver(selectorOrOptions, {...maybeOptions ?? {}, root: 'all', delegate: true});\n }\n return mutationObserver({...selectorOrOptions ?? {}, root: 'all', delegate: true});\n}\n\nexport function mutationObserverDelegate(selector: string, options?: MutationObserverBaseOptions): MethodDecorator;\nexport function mutationObserverDelegate(options?: MutationObserverBaseOptions): MethodDecorator;\nexport function mutationObserverDelegate(selectorOrOptions?: string | Omit<MutationObserverQueryOptions, 'root'>, maybeOptions?: Omit<MutationObserverQueryOptions, 'root'>): MethodDecorator {\n if (typeof selectorOrOptions === 'string' || typeof selectorOrOptions === 'function') {\n return mutationObserver(selectorOrOptions, {...maybeOptions ?? {}, root: 'auto', delegate: true});\n }\n return mutationObserver({...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 mutationObserverLight(selector: string, options?: Omit<MutationObserverQueryOptions, 'root'>): MethodDecorator;\nexport function mutationObserverLight(options?: Omit<MutationObserverQueryOptions, 'root'>): MethodDecorator;\nexport function mutationObserverLight(selectorOrOptions?: string | Omit<MutationObserverQueryOptions, 'root'>, maybeOptions?: Omit<MutationObserverQueryOptions, 'root'>): MethodDecorator {\n if (typeof selectorOrOptions === 'string' || typeof selectorOrOptions === 'function') {\n return mutationObserver(selectorOrOptions, {...maybeOptions ?? {}, root: 'light'});\n }\n return mutationObserver({...selectorOrOptions ?? {}, root: 'light'});\n}\n\nexport function mutationObserverShadow(selector: string, options?: Omit<MutationObserverQueryOptions, 'root'>): MethodDecorator;\nexport function mutationObserverShadow(options?: Omit<MutationObserverQueryOptions, 'root'>): MethodDecorator;\nexport function mutationObserverShadow(selectorOrOptions?: string | Omit<MutationObserverQueryOptions, 'root'>, maybeOptions?: Omit<MutationObserverQueryOptions, 'root'>): MethodDecorator {\n if (typeof selectorOrOptions === 'string' || typeof selectorOrOptions === 'function') {\n return mutationObserver(selectorOrOptions, {...maybeOptions ?? {}, root: 'shadow'});\n }\n return mutationObserver({...selectorOrOptions ?? {}, root: 'shadow'});\n}\n\nexport function mutationObserverAll(selector: string, options?: Omit<MutationObserverQueryOptions, 'root'>): MethodDecorator;\nexport function mutationObserverAll(options?: Omit<MutationObserverQueryOptions, 'root'>): MethodDecorator;\nexport function mutationObserverAll(selectorOrOptions?: string | Omit<MutationObserverQueryOptions, 'root'>, maybeOptions?: Omit<MutationObserverQueryOptions, 'root'>): MethodDecorator {\n if (typeof selectorOrOptions === 'string' || typeof selectorOrOptions === 'function') {\n return mutationObserver(selectorOrOptions, {...maybeOptions ?? {}, root: 'all'});\n }\n return mutationObserver({...selectorOrOptions ?? {}, root: 'all'});\n}\n\nexport function getMutationObserverMetadata(target: any): MutationObserverMetadata[] | undefined {\n const constructor = target instanceof Function ? target : target.constructor;\n return ReflectUtils.getMetadata(MUTATION_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// MutationObserverLifeCycler\n// observer \uB97C \uC9C1\uC811 \uC0DD\uC131\uD558\uC9C0 \uC54A\uACE0 OnConnectedResult \uB97C \uBC18\uD658\uD55C\uB2E4.\n// elementDefine \uC774 \uC218\uC9D1\uB41C MutationObserverSet \uC73C\uB85C observer \uB97C \uC0DD\uC131\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, MutationObserverSet, MutationObserverSetEntry, ObserverObserveTarget, OnConnectedResult } from '../types';\nimport { SwcUtils } from '../utils/Utils';\n\nexport class MutationObserverLifeCycler 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 = getMutationObserverMetadata(inst) ?? [];\n // \uCC98\uB9AC\uD560 \uBA54\uD0C0\uAC00 \uC5C6\uC73C\uBA74 observer \uBD88\uD544\uC694\n if (allMeta.length === 0) return;\n\n // \u2500\u2500 shadow / light \uB8E8\uD2B8\uBCC4 \uBD84\uB958 \u2500\u2500\n const shadowMetas = allMeta.filter(m => {\n const r = m.options.root || 'auto';\n return inst.shadowRoot && (r === 'shadow' || r === 'all' || r === 'auto');\n });\n const lightMetas = allMeta.filter(m => {\n const r = m.options.root || 'auto';\n return r === 'light' || r === 'all' || (!inst.shadowRoot && r === 'auto');\n });\n // \u2500\u2500 MutationObserverSet \uC0DD\uC131 \uD5EC\uD37C (\uB8E8\uD2B8\uBCC4) \u2500\u2500\n const buildSet = (\n root: HTMLElement | ShadowRoot,\n metas: MutationObserverMetadata[],\n ): { callback: MutationObserverSetEntry['callback']; observeTargets: ObserverObserveTarget<MutationObserverInit>[] } | null => {\n if (metas.length === 0) return null;\n\n const initFrom = (o: MutationObserverBaseOptions): MutationObserverInit => {\n const init: MutationObserverInit = {\n childList: o.childList, attributes: o.attributes, characterData: o.characterData,\n subtree: o.subtree, attributeFilter: o.attributeFilter,\n attributeOldValue: o.attributeOldValue, characterDataOldValue: o.characterDataOldValue,\n };\n if (!init.childList && !init.attributes && !init.characterData) init.childList = true;\n return init;\n };\n\n const fnObservedSets = new Map<MutationObserverMetadata, WeakSet<Element>>();\n\n const callback = (mutations: MutationRecord[], obs: MutationObserver) => {\n // \u2500\u2500 MutationObserver \uBA54\uD0C0 \uCF5C\uBC31 \u2500\u2500\n for (const meta of metas) {\n const { selector, options } = meta;\n let matchedEls: HTMLElement[] = [];\n\n const typeMatches = (m: MutationRecord): boolean => {\n const has = !!(options.childList || options.attributes || options.characterData);\n if (m.type === 'childList') return has ? !!options.childList : true;\n if (m.type === 'attributes') return !!options.attributes;\n if (m.type === 'characterData') return !!options.characterData;\n return true;\n };\n\n const collect = (matchesSel: (n: any) => boolean) =>\n mutations.flatMap(m => {\n if (!typeMatches(m)) return [];\n const els: HTMLElement[] = [];\n if (matchesSel(m.target)) els.push(m.target as HTMLElement);\n Array.from(m.addedNodes || []).filter(matchesSel).forEach(n => els.push(n as HTMLElement));\n Array.from(m.removedNodes || []).filter(matchesSel).forEach(n => els.push(n as HTMLElement));\n return els;\n });\n\n if (options.delegate && typeof selector === 'string') {\n const isThis = selector === '$this' || selector === '';\n matchedEls = collect(n => {\n if (!n || n.nodeType !== 1) return false;\n if (isThis) return true;\n const el = n as HTMLElement;\n return el.matches?.(selector) || !!el.closest?.(selector);\n });\n } else if (typeof selector === 'string') {\n const isThis = selector === '$this' || selector === '';\n matchedEls = collect(n => {\n if (!n || n.nodeType !== 1) return false;\n if (isThis) return true;\n return (n as HTMLElement).matches?.(selector);\n });\n } else if (typeof selector === 'function') {\n const set = fnObservedSets.get(meta);\n matchedEls = mutations.filter(m => typeMatches(m))\n .map(m => m.target as HTMLElement)\n .filter(t => t && t.nodeType === 1 && (set ? set.has(t) : false));\n } else {\n matchedEls = mutations.filter(m => typeMatches(m))\n .map(m => m.target as HTMLElement)\n .filter(t => t && t.nodeType === 1);\n }\n\n if (matchedEls.length === 0) continue;\n if (options.filter) {\n if (!options.filter(matchedEls, { currentThis: inst, helper: helperHostSet })) continue;\n }\n const hostSet = SwcUtils.getHostSet(inst);\n inst[meta.propertyKey](matchedEls, mutations, obs, { ...hostSet, $root: root });\n }\n\n };\n\n // \u2500\u2500 observe \uB300\uC0C1 \uBAA9\uB85D \uAD6C\uC131 \u2500\u2500\n const observeTargets: ObserverObserveTarget<MutationObserverInit>[] = [];\n\n // delegate \uC788\uC73C\uBA74 \uB8E8\uD2B8 \uC804\uCCB4 subtree observe\n if (metas.some(m => m.options.delegate)) {\n observeTargets.push({ target: root, options: { childList: true, subtree: true } });\n }\n\n // non-delegate: \uC140\uB809\uD130 \uB9E4\uCE6D \uC694\uC18C \uC9C1\uC811 observe\n for (const m of metas.filter(m => !m.options.delegate)) {\n const { selector, options } = m;\n const mInit = initFrom(options);\n if (typeof selector === 'string') {\n if (selector === '$this' || selector === '') {\n observeTargets.push({ target: root, options: mInit });\n } else {\n root.querySelectorAll(selector).forEach(el => observeTargets.push({ target: el as Element, options: mInit }));\n }\n } else if (typeof selector === 'function') {\n const res = (selector as any)(inst, helperHostSet);\n let targets: HTMLElement[] = [];\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 const set = new WeakSet<Element>();\n for (const el of targets) { set.add(el); observeTargets.push({ target: el, options: mInit }); }\n fnObservedSets.set(m, set);\n }\n }\n\n // removeObserver \uCF5C\uBC31 \uC218\uC9D1\n for (const m of metas) {\n if (m.options.removeObserver) removeObserverCallbacks.push({ fn: m.options.removeObserver, target: root, opts: m.options });\n }\n\n return { callback, observeTargets };\n };\n\n const shadowSet = inst.shadowRoot ? buildSet(inst.shadowRoot, shadowMetas) : null;\n const lightSet = buildSet(inst as any, lightMetas);\n\n // \uB450 \uB8E8\uD2B8\uC758 observe \uB300\uC0C1 + \uCF5C\uBC31\uC744 \uC5D4\uD2B8\uB9AC \uBC30\uC5F4(MutationObserverSet)\uB85C \uBCD1\uD569\n // \uAC19\uC740 \uB8E8\uD2B8\uC758 \uC5EC\uB7EC \uB300\uC0C1\uC740 \uAC19\uC740 callback \uC744 \uACF5\uC720\uD55C\uB2E4.\n const mutationObserverSet: MutationObserverSet = [\n ...(shadowSet?.observeTargets ?? []).map(t => ({ ...t, callback: shadowSet!.callback })),\n ...(lightSet?.observeTargets ?? []).map(t => ({ ...t, callback: lightSet!.callback })),\n ];\n if (mutationObserverSet.length === 0) return;\n\n return { mutationObserverSet };\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}"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA6B;
|
|
4
|
+
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core';\nimport { SpecialSelector, SwcQueryOptions, SwcSelector, SwcFnSelector, HelperHostSet } from '../types';\n\n// \uACF5\uD1B5 \uC635\uC158 \u2014 root\u00B7delegate \uC5C6\uC74C (MutationObserverInit + filter/removeObserver)\nexport interface MutationObserverBaseOptions extends MutationObserverInit {\n filter?: (matchedEls: HTMLElement[], meta: { currentThis: any, helper: HelperHostSet }) => boolean;\n // observer \uD574\uC81C(disconnected) \uC2DC \uD638\uCD9C\uB418\uB294 \uCF5C\uBC31. \uCCAB \uBC88\uC9F8 \uC778\uC790\uB294 observe\uB41C target element, \uB450 \uBC88\uC9F8\uB294 \uC0AC\uC6A9\uC790 \uC635\uC158 \uAC1D\uCCB4.\n removeObserver?: (target: Element, optionValue: MutationObserverQueryOptions) => void;\n}\n\n// \uBB38\uC790\uC5F4 \uC140\uB809\uD130 \uC804\uC6A9 \u2014 root\u00B7delegate \uD5C8\uC6A9 (\uC140\uB809\uD130\uB85C \uD0D0\uC0C9/\uB378\uB9AC\uAC8C\uC774\uC158)\nexport type MutationObserverQueryOptions = MutationObserverBaseOptions & SwcQueryOptions & { delegate?: boolean };\n// \uD568\uC218 \uC140\uB809\uD130 \uC804\uC6A9 \u2014 root\u00B7delegate \uAE08\uC9C0 (\uC774\uBBF8 \uC694\uC18C\uB97C \uC9C1\uC811 \uBC18\uD658)\nexport type MutationObserverNonQueryOptions = MutationObserverBaseOptions;\n\n// \uC140\uB809\uD130 \uC885\uB958\uC5D0 \uB530\uB77C \uC635\uC158 \uD0C0\uC785 \uBD84\uAE30\nexport type MutationObserverOptionsOf<S extends SwcSelector> = S extends string ? MutationObserverQueryOptions : MutationObserverNonQueryOptions;\n\nexport interface MutationObserverMetadata {\n propertyKey: string | symbol;\n selector: SwcSelector;\n options: MutationObserverQueryOptions;\n}\n\nexport const MUTATION_OBSERVER_METADATA_KEY = Symbol.for('simple-web-component:mutation-observer');\n\nconst applyMutationObserver = (selector: SwcSelector, options: MutationObserverQueryOptions, targetObj: Object, propertyKey: string | symbol): void => {\n const constructor = targetObj.constructor;\n let observers = ReflectUtils.getMetadata<MutationObserverMetadata[]>(MUTATION_OBSERVER_METADATA_KEY, constructor);\n if (!observers) {\n observers = [];\n ReflectUtils.defineMetadata(MUTATION_OBSERVER_METADATA_KEY, observers, constructor);\n }\n observers.push({ propertyKey, selector, options });\n};\n\nconst resolveMutationObserverArgs = (\n selectorOrOptions: SwcSelector | MutationObserverQueryOptions | undefined,\n maybeOptions: MutationObserverQueryOptions | undefined,\n extra: Partial<MutationObserverQueryOptions>\n): { selector: SwcSelector; options: MutationObserverQueryOptions } => {\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 * selectorOrOptionsOrTarget/maybeOptionsOrPropertyKey/descriptor\uC744 \uBC1B\uC544 bare(@decorator)\uC640\n * factory(@decorator()/@decorator(...)) \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 dispatchMutationObserver = (\n selectorOrOptionsOrTarget: SwcSelector | MutationObserverQueryOptions | Object | undefined,\n maybeOptionsOrPropertyKey: MutationObserverQueryOptions | string | symbol | undefined,\n descriptor: PropertyDescriptor | undefined,\n extra: Partial<MutationObserverQueryOptions>\n): MethodDecorator | void => {\n if ((typeof maybeOptionsOrPropertyKey === 'string' || typeof maybeOptionsOrPropertyKey === 'symbol') && descriptor !== undefined) {\n // \uC635\uC158 \uC5C6\uC774: @decorator\n applyMutationObserver('$this', { ...extra }, selectorOrOptionsOrTarget as Object, maybeOptionsOrPropertyKey);\n return;\n }\n // \uC635\uC158\uACFC \uD568\uAED8: @decorator() / @decorator(selector, options) / @decorator(options)\n const { selector, options } = resolveMutationObserverArgs(\n selectorOrOptionsOrTarget as SwcSelector | MutationObserverQueryOptions | undefined,\n maybeOptionsOrPropertyKey as MutationObserverQueryOptions | undefined,\n extra\n );\n return (targetObj: Object, propertyKey: string | symbol) => {\n applyMutationObserver(selector, options, targetObj, propertyKey);\n };\n};\n\nexport function mutationObserver(target: SpecialSelector, options?: MutationObserverQueryOptions): MethodDecorator;\nexport function mutationObserver(selector: string, options?: MutationObserverQueryOptions): MethodDecorator;\nexport function mutationObserver(selector: SwcFnSelector, options?: MutationObserverNonQueryOptions): MethodDecorator;\nexport function mutationObserver(options?: MutationObserverQueryOptions): MethodDecorator;\nexport function mutationObserver(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\n/**\n * @mutationObserver decorator to observe DOM mutations.\n * \uC635\uC158 \uC5C6\uC774 `@mutationObserver` \uADF8\uB300\uB85C \uBD99\uC5EC\uB3C4 \uB418\uACE0, `@mutationObserver(...)`\uCC98\uB7FC \uC140\uB809\uD130/\uC635\uC158\uC744 \uC904 \uC218\uB3C4 \uC788\uB2E4.\n */\nexport function mutationObserver(selectorOrOptionsOrTarget?: SwcSelector | MutationObserverQueryOptions | Object, maybeOptionsOrPropertyKey?: MutationObserverQueryOptions | string | symbol, descriptor?: PropertyDescriptor): MethodDecorator | void {\n return dispatchMutationObserver(selectorOrOptionsOrTarget, maybeOptionsOrPropertyKey, descriptor, {});\n}\n\nexport function mutationObserverThis(options?: MutationObserverQueryOptions): MethodDecorator;\nexport function mutationObserverThis(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function mutationObserverThis(optionsOrTarget?: MutationObserverQueryOptions | Object, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): MethodDecorator | void {\n return dispatchMutationObserver(optionsOrTarget, propertyKey, descriptor, {});\n}\n\n// \u2500\u2500\u2500 root\uBCC4 delegate \uD5EC\uD37C (addEventListener\uC640 \uB3D9\uC77C \uD328\uD134) \u2500\u2500\u2500\n\nexport function mutationObserverDelegateLight(selector: string, options?: MutationObserverBaseOptions): MethodDecorator;\nexport function mutationObserverDelegateLight(options?: MutationObserverBaseOptions): MethodDecorator;\nexport function mutationObserverDelegateLight(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function mutationObserverDelegateLight(selectorOrOptionsOrTarget?: string | Omit<MutationObserverQueryOptions, 'root'> | Object, maybeOptionsOrPropertyKey?: Omit<MutationObserverQueryOptions, 'root'> | string | symbol, descriptor?: PropertyDescriptor): MethodDecorator | void {\n return dispatchMutationObserver(selectorOrOptionsOrTarget as any, maybeOptionsOrPropertyKey as any, descriptor, { root: 'light', delegate: true });\n}\n\nexport function mutationObserverDelegateShadow(selector: string, options?: MutationObserverBaseOptions): MethodDecorator;\nexport function mutationObserverDelegateShadow(options?: MutationObserverBaseOptions): MethodDecorator;\nexport function mutationObserverDelegateShadow(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function mutationObserverDelegateShadow(selectorOrOptionsOrTarget?: string | Omit<MutationObserverQueryOptions, 'root'> | Object, maybeOptionsOrPropertyKey?: Omit<MutationObserverQueryOptions, 'root'> | string | symbol, descriptor?: PropertyDescriptor): MethodDecorator | void {\n return dispatchMutationObserver(selectorOrOptionsOrTarget as any, maybeOptionsOrPropertyKey as any, descriptor, { root: 'shadow', delegate: true });\n}\n\nexport function mutationObserverDelegateAll(selector: string, options?: MutationObserverBaseOptions): MethodDecorator;\nexport function mutationObserverDelegateAll(options?: MutationObserverBaseOptions): MethodDecorator;\nexport function mutationObserverDelegateAll(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function mutationObserverDelegateAll(selectorOrOptionsOrTarget?: string | Omit<MutationObserverQueryOptions, 'root'> | Object, maybeOptionsOrPropertyKey?: Omit<MutationObserverQueryOptions, 'root'> | string | symbol, descriptor?: PropertyDescriptor): MethodDecorator | void {\n return dispatchMutationObserver(selectorOrOptionsOrTarget as any, maybeOptionsOrPropertyKey as any, descriptor, { root: 'all', delegate: true });\n}\n\nexport function mutationObserverDelegate(selector: string, options?: MutationObserverBaseOptions): MethodDecorator;\nexport function mutationObserverDelegate(options?: MutationObserverBaseOptions): MethodDecorator;\nexport function mutationObserverDelegate(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function mutationObserverDelegate(selectorOrOptionsOrTarget?: string | Omit<MutationObserverQueryOptions, 'root'> | Object, maybeOptionsOrPropertyKey?: Omit<MutationObserverQueryOptions, 'root'> | string | symbol, descriptor?: PropertyDescriptor): MethodDecorator | void {\n return dispatchMutationObserver(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 mutationObserverLight(selector: string, options?: Omit<MutationObserverQueryOptions, 'root'>): MethodDecorator;\nexport function mutationObserverLight(options?: Omit<MutationObserverQueryOptions, 'root'>): MethodDecorator;\nexport function mutationObserverLight(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function mutationObserverLight(selectorOrOptionsOrTarget?: string | Omit<MutationObserverQueryOptions, 'root'> | Object, maybeOptionsOrPropertyKey?: Omit<MutationObserverQueryOptions, 'root'> | string | symbol, descriptor?: PropertyDescriptor): MethodDecorator | void {\n return dispatchMutationObserver(selectorOrOptionsOrTarget as any, maybeOptionsOrPropertyKey as any, descriptor, { root: 'light' });\n}\n\nexport function mutationObserverShadow(selector: string, options?: Omit<MutationObserverQueryOptions, 'root'>): MethodDecorator;\nexport function mutationObserverShadow(options?: Omit<MutationObserverQueryOptions, 'root'>): MethodDecorator;\nexport function mutationObserverShadow(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function mutationObserverShadow(selectorOrOptionsOrTarget?: string | Omit<MutationObserverQueryOptions, 'root'> | Object, maybeOptionsOrPropertyKey?: Omit<MutationObserverQueryOptions, 'root'> | string | symbol, descriptor?: PropertyDescriptor): MethodDecorator | void {\n return dispatchMutationObserver(selectorOrOptionsOrTarget as any, maybeOptionsOrPropertyKey as any, descriptor, { root: 'shadow' });\n}\n\nexport function mutationObserverAll(selector: string, options?: Omit<MutationObserverQueryOptions, 'root'>): MethodDecorator;\nexport function mutationObserverAll(options?: Omit<MutationObserverQueryOptions, 'root'>): MethodDecorator;\nexport function mutationObserverAll(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void;\nexport function mutationObserverAll(selectorOrOptionsOrTarget?: string | Omit<MutationObserverQueryOptions, 'root'> | Object, maybeOptionsOrPropertyKey?: Omit<MutationObserverQueryOptions, 'root'> | string | symbol, descriptor?: PropertyDescriptor): MethodDecorator | void {\n return dispatchMutationObserver(selectorOrOptionsOrTarget as any, maybeOptionsOrPropertyKey as any, descriptor, { root: 'all' });\n}\n\nexport function getMutationObserverMetadata(target: any): MutationObserverMetadata[] | undefined {\n const constructor = target instanceof Function ? target : target.constructor;\n return ReflectUtils.getMetadata(MUTATION_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// MutationObserverLifeCycler\n// observer \uB97C \uC9C1\uC811 \uC0DD\uC131\uD558\uC9C0 \uC54A\uACE0 OnConnectedResult \uB97C \uBC18\uD658\uD55C\uB2E4.\n// elementDefine \uC774 \uC218\uC9D1\uB41C MutationObserverSet \uC73C\uB85C observer \uB97C \uC0DD\uC131\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, MutationObserverSet, MutationObserverSetEntry, ObserverObserveTarget, OnConnectedResult } from '../types';\nimport { SwcUtils } from '../utils/Utils';\n\nexport class MutationObserverLifeCycler 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 = getMutationObserverMetadata(inst) ?? [];\n // \uCC98\uB9AC\uD560 \uBA54\uD0C0\uAC00 \uC5C6\uC73C\uBA74 observer \uBD88\uD544\uC694\n if (allMeta.length === 0) return;\n\n // \u2500\u2500 shadow / light \uB8E8\uD2B8\uBCC4 \uBD84\uB958 \u2500\u2500\n const shadowMetas = allMeta.filter(m => {\n const r = m.options.root || 'auto';\n return inst.shadowRoot && (r === 'shadow' || r === 'all' || r === 'auto');\n });\n const lightMetas = allMeta.filter(m => {\n const r = m.options.root || 'auto';\n return r === 'light' || r === 'all' || (!inst.shadowRoot && r === 'auto');\n });\n // \u2500\u2500 MutationObserverSet \uC0DD\uC131 \uD5EC\uD37C (\uB8E8\uD2B8\uBCC4) \u2500\u2500\n const buildSet = (\n root: HTMLElement | ShadowRoot,\n metas: MutationObserverMetadata[],\n ): { callback: MutationObserverSetEntry['callback']; observeTargets: ObserverObserveTarget<MutationObserverInit>[] } | null => {\n if (metas.length === 0) return null;\n\n const initFrom = (o: MutationObserverBaseOptions): MutationObserverInit => {\n const init: MutationObserverInit = {\n childList: o.childList, attributes: o.attributes, characterData: o.characterData,\n subtree: o.subtree, attributeFilter: o.attributeFilter,\n attributeOldValue: o.attributeOldValue, characterDataOldValue: o.characterDataOldValue,\n };\n if (!init.childList && !init.attributes && !init.characterData) init.childList = true;\n return init;\n };\n\n const fnObservedSets = new Map<MutationObserverMetadata, WeakSet<Element>>();\n\n const callback = (mutations: MutationRecord[], obs: MutationObserver) => {\n // \u2500\u2500 MutationObserver \uBA54\uD0C0 \uCF5C\uBC31 \u2500\u2500\n for (const meta of metas) {\n const { selector, options } = meta;\n let matchedEls: HTMLElement[] = [];\n\n const typeMatches = (m: MutationRecord): boolean => {\n const has = !!(options.childList || options.attributes || options.characterData);\n if (m.type === 'childList') return has ? !!options.childList : true;\n if (m.type === 'attributes') return !!options.attributes;\n if (m.type === 'characterData') return !!options.characterData;\n return true;\n };\n\n const collect = (matchesSel: (n: any) => boolean) =>\n mutations.flatMap(m => {\n if (!typeMatches(m)) return [];\n const els: HTMLElement[] = [];\n if (matchesSel(m.target)) els.push(m.target as HTMLElement);\n Array.from(m.addedNodes || []).filter(matchesSel).forEach(n => els.push(n as HTMLElement));\n Array.from(m.removedNodes || []).filter(matchesSel).forEach(n => els.push(n as HTMLElement));\n return els;\n });\n\n if (options.delegate && typeof selector === 'string') {\n const isThis = selector === '$this' || selector === '';\n matchedEls = collect(n => {\n if (!n || n.nodeType !== 1) return false;\n if (isThis) return true;\n const el = n as HTMLElement;\n return el.matches?.(selector) || !!el.closest?.(selector);\n });\n } else if (typeof selector === 'string') {\n const isThis = selector === '$this' || selector === '';\n matchedEls = collect(n => {\n if (!n || n.nodeType !== 1) return false;\n if (isThis) return true;\n return (n as HTMLElement).matches?.(selector);\n });\n } else if (typeof selector === 'function') {\n const set = fnObservedSets.get(meta);\n matchedEls = mutations.filter(m => typeMatches(m))\n .map(m => m.target as HTMLElement)\n .filter(t => t && t.nodeType === 1 && (set ? set.has(t) : false));\n } else {\n matchedEls = mutations.filter(m => typeMatches(m))\n .map(m => m.target as HTMLElement)\n .filter(t => t && t.nodeType === 1);\n }\n\n if (matchedEls.length === 0) continue;\n if (options.filter) {\n if (!options.filter(matchedEls, { currentThis: inst, helper: helperHostSet })) continue;\n }\n const hostSet = SwcUtils.getHostSet(inst);\n inst[meta.propertyKey](matchedEls, mutations, obs, { ...hostSet, $root: root });\n }\n\n };\n\n // \u2500\u2500 observe \uB300\uC0C1 \uBAA9\uB85D \uAD6C\uC131 \u2500\u2500\n const observeTargets: ObserverObserveTarget<MutationObserverInit>[] = [];\n\n // delegate \uC788\uC73C\uBA74 \uB8E8\uD2B8 \uC804\uCCB4 subtree observe\n if (metas.some(m => m.options.delegate)) {\n observeTargets.push({ target: root, options: { childList: true, subtree: true } });\n }\n\n // non-delegate: \uC140\uB809\uD130 \uB9E4\uCE6D \uC694\uC18C \uC9C1\uC811 observe\n for (const m of metas.filter(m => !m.options.delegate)) {\n const { selector, options } = m;\n const mInit = initFrom(options);\n if (typeof selector === 'string') {\n if (selector === '$this' || selector === '') {\n observeTargets.push({ target: root, options: mInit });\n } else {\n root.querySelectorAll(selector).forEach(el => observeTargets.push({ target: el as Element, options: mInit }));\n }\n } else if (typeof selector === 'function') {\n const res = (selector as any)(inst, helperHostSet);\n let targets: HTMLElement[] = [];\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 const set = new WeakSet<Element>();\n for (const el of targets) { set.add(el); observeTargets.push({ target: el, options: mInit }); }\n fnObservedSets.set(m, set);\n }\n }\n\n // removeObserver \uCF5C\uBC31 \uC218\uC9D1\n for (const m of metas) {\n if (m.options.removeObserver) removeObserverCallbacks.push({ fn: m.options.removeObserver, target: root, opts: m.options });\n }\n\n return { callback, observeTargets };\n };\n\n const shadowSet = inst.shadowRoot ? buildSet(inst.shadowRoot, shadowMetas) : null;\n const lightSet = buildSet(inst as any, lightMetas);\n\n // \uB450 \uB8E8\uD2B8\uC758 observe \uB300\uC0C1 + \uCF5C\uBC31\uC744 \uC5D4\uD2B8\uB9AC \uBC30\uC5F4(MutationObserverSet)\uB85C \uBCD1\uD569\n // \uAC19\uC740 \uB8E8\uD2B8\uC758 \uC5EC\uB7EC \uB300\uC0C1\uC740 \uAC19\uC740 callback \uC744 \uACF5\uC720\uD55C\uB2E4.\n const mutationObserverSet: MutationObserverSet = [\n ...(shadowSet?.observeTargets ?? []).map(t => ({ ...t, callback: shadowSet!.callback })),\n ...(lightSet?.observeTargets ?? []).map(t => ({ ...t, callback: lightSet!.callback })),\n ];\n if (mutationObserverSet.length === 0) return;\n\n return { mutationObserverSet };\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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA6B;AA6J7B,mBAAyB;AArIlB,MAAM,iCAAiC,OAAO,IAAI,wCAAwC;AAEjG,MAAM,wBAAwB,CAAC,UAAuB,SAAuC,WAAmB,gBAAuC;AACrJ,QAAM,cAAc,UAAU;AAC9B,MAAI,YAAY,yBAAa,YAAwC,gCAAgC,WAAW;AAChH,MAAI,CAAC,WAAW;AACd,gBAAY,CAAC;AACb,6BAAa,eAAe,gCAAgC,WAAW,WAAW;AAAA,EACpF;AACA,YAAU,KAAK,EAAE,aAAa,UAAU,QAAQ,CAAC;AACnD;AAEA,MAAM,8BAA8B,CAClC,mBACA,cACA,UACqE;AACrE,MAAI,OAAO,sBAAsB,YAAY,OAAO,sBAAsB,YAAY;AACpF,WAAO,EAAE,UAAU,mBAAmB,SAAS,EAAE,GAAI,gBAAgB,CAAC,GAAI,GAAG,MAAM,EAAE;AAAA,EACvF;AACA,SAAO,EAAE,UAAU,SAAS,SAAS,EAAE,GAAI,qBAAqB,CAAC,GAAI,GAAG,MAAM,EAAE;AAClF;AAOA,MAAM,2BAA2B,CAC/B,2BACA,2BACA,YACA,UAC2B;AAC3B,OAAK,OAAO,8BAA8B,YAAY,OAAO,8BAA8B,aAAa,eAAe,QAAW;AAEhI,0BAAsB,SAAS,EAAE,GAAG,MAAM,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AM,EAAE,GAAG,GAAG,UAAU,SAAU,SAAS,EAAE;AAAA,IACxF;AACA,QAAI,oBAAoB,WAAW,EAAG;AAEtC,WAAO,EAAE,oBAAoB;AAAA,EAC/B;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": ["m"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,73 @@
|
|
|
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 parameter_exports = {};
|
|
19
|
+
__export(parameter_exports, {
|
|
20
|
+
appMessage: () => appMessage,
|
|
21
|
+
buildSwcParameterArgs: () => buildSwcParameterArgs,
|
|
22
|
+
eventObject: () => eventObject,
|
|
23
|
+
getParameterMetadata: () => getParameterMetadata,
|
|
24
|
+
helperHostSet: () => helperHostSet,
|
|
25
|
+
helperSet: () => helperSet,
|
|
26
|
+
hostSet: () => hostSet,
|
|
27
|
+
matchedElement: () => matchedElement,
|
|
28
|
+
routerEvent: () => routerEvent
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(parameter_exports);
|
|
31
|
+
var import_core = require("@dooboostore/core");
|
|
32
|
+
const SWC_PARAMETER_METADATA_KEY = Symbol.for("simple-web-component:parameter");
|
|
33
|
+
const registerParam = (kind, target, propertyKey, parameterIndex) => {
|
|
34
|
+
if (!propertyKey) return;
|
|
35
|
+
const constructor = target.constructor;
|
|
36
|
+
const saves = import_core.ReflectUtils.getOwnMetadata(SWC_PARAMETER_METADATA_KEY, constructor, propertyKey) ?? [];
|
|
37
|
+
saves.push({ index: parameterIndex, kind });
|
|
38
|
+
import_core.ReflectUtils.defineMetadata(SWC_PARAMETER_METADATA_KEY, saves, constructor, propertyKey);
|
|
39
|
+
};
|
|
40
|
+
function eventObject(target, propertyKey, parameterIndex) {
|
|
41
|
+
registerParam("event", target, propertyKey, parameterIndex);
|
|
42
|
+
}
|
|
43
|
+
function matchedElement(target, propertyKey, parameterIndex) {
|
|
44
|
+
registerParam("matched", target, propertyKey, parameterIndex);
|
|
45
|
+
}
|
|
46
|
+
function hostSet(target, propertyKey, parameterIndex) {
|
|
47
|
+
registerParam("hostSet", target, propertyKey, parameterIndex);
|
|
48
|
+
}
|
|
49
|
+
function helperHostSet(target, propertyKey, parameterIndex) {
|
|
50
|
+
registerParam("helperHostSet", target, propertyKey, parameterIndex);
|
|
51
|
+
}
|
|
52
|
+
function helperSet(target, propertyKey, parameterIndex) {
|
|
53
|
+
registerParam("helperSet", target, propertyKey, parameterIndex);
|
|
54
|
+
}
|
|
55
|
+
function routerEvent(target, propertyKey, parameterIndex) {
|
|
56
|
+
registerParam("routerEvent", target, propertyKey, parameterIndex);
|
|
57
|
+
}
|
|
58
|
+
function appMessage(target, propertyKey, parameterIndex) {
|
|
59
|
+
registerParam("appMessage", target, propertyKey, parameterIndex);
|
|
60
|
+
}
|
|
61
|
+
const getParameterMetadata = (target, propertyKey) => {
|
|
62
|
+
const constructor = target instanceof Function ? target : target.constructor;
|
|
63
|
+
return import_core.ReflectUtils.getMetadata(SWC_PARAMETER_METADATA_KEY, constructor, propertyKey) ?? [];
|
|
64
|
+
};
|
|
65
|
+
const buildSwcParameterArgs = (target, propertyKey, kindValues, legacyArgs) => {
|
|
66
|
+
const saves = getParameterMetadata(target, propertyKey);
|
|
67
|
+
if (saves.length === 0) return legacyArgs;
|
|
68
|
+
const maxIndex = Math.max(...saves.map((s) => s.index));
|
|
69
|
+
const args = new Array(maxIndex + 1);
|
|
70
|
+
for (const s of saves) args[s.index] = kindValues[s.kind];
|
|
71
|
+
return args;
|
|
72
|
+
};
|
|
73
|
+
//# sourceMappingURL=parameter.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/decorators/parameter.ts"],
|
|
4
|
+
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core';\n\n/**\n * @eventObject/@matchedElement/@hostSet/@helperHostSet/@helperSet/@routerEvent/@appMessage \u2014\n * @addEventListener/lifecycle/subscribeSwcAppRouteChangeWhileConnected/subscribeSwcAppMessageWhileConnected\n * \uACC4\uC5F4 \uD578\uB4E4\uB7EC\uC758 \uD30C\uB77C\uBBF8\uD130\uB97C \uC21C\uC11C \uBB34\uAD00\uD558\uAC8C \uC120\uC5B8\uD560 \uC218 \uC788\uAC8C \uD574\uC8FC\uB294 \uD30C\uB77C\uBBF8\uD130 \uB370\uCF54\uB808\uC774\uD130.\n * @dooboostore/simple-boot\uC758 @Inject\uC640 \uB3D9\uC77C\uD55C \uC778\uB371\uC2A4 \uAE30\uBC18 \uBA54\uD0C0\uB370\uC774\uD130 \uD328\uD134\uC744 \uB530\uB978\uB2E4:\n * \uB370\uCF54\uB808\uC774\uD130\uAC00 \uC2E4\uD589\uB418\uB294 \uC21C\uC11C\uAC00 \uC544\uB2C8\uB77C \uC2E4\uC81C parameterIndex\uB85C \uC2AC\uB86F\uC744 \uB9E4\uCE6D\uD558\uBBC0\uB85C,\n * \uC0AC\uC6A9\uC790\uAC00 \uD30C\uB77C\uBBF8\uD130 \uC120\uC5B8 \uC21C\uC11C\uB97C \uC790\uC720\uB86D\uAC8C \uBC14\uAFD4\uB3C4 \uB41C\uB2E4.\n */\nexport type SwcParamKind = 'event' | 'matched' | 'hostSet' | 'helperHostSet' | 'helperSet' | 'routerEvent' | 'appMessage';\n\nconst SWC_PARAMETER_METADATA_KEY = Symbol.for('simple-web-component:parameter');\n\ntype SaveParamConfig = { index: number; kind: SwcParamKind };\n\nconst registerParam = (kind: SwcParamKind, target: Object, propertyKey: string | symbol | undefined, parameterIndex: number) => {\n if (!propertyKey) return;\n const constructor = target.constructor;\n const saves = (ReflectUtils.getOwnMetadata(SWC_PARAMETER_METADATA_KEY, constructor, propertyKey) ?? []) as SaveParamConfig[];\n saves.push({ index: parameterIndex, kind });\n ReflectUtils.defineMetadata(SWC_PARAMETER_METADATA_KEY, saves, constructor, propertyKey);\n};\n\n/** \uC774\uBCA4\uD2B8 \uD578\uB4E4\uB7EC\uC758 \uC6D0\uBCF8 Event \uAC1D\uCCB4\uB97C \uC8FC\uC785\uD55C\uB2E4. */\nexport function eventObject(target: Object, propertyKey: string | symbol, parameterIndex: number): void {\n registerParam('event', target, propertyKey, parameterIndex);\n}\n\n/** delegate\uB85C \uB9E4\uCE6D\uB41C \uC2E4\uC81C \uC5D8\uB9AC\uBA3C\uD2B8($matchedElement)\uB97C \uC8FC\uC785\uD55C\uB2E4. */\nexport function matchedElement(target: Object, propertyKey: string | symbol, parameterIndex: number): void {\n registerParam('matched', target, propertyKey, parameterIndex);\n}\n\n/** HostSet(\uD638\uC2A4\uD2B8 \uD2B8\uB9AC \uC815\uBCF4 \u2014 $host/$hosts/$firstHost/$appHost \uB4F1)\uC744 \uC8FC\uC785\uD55C\uB2E4. */\nexport function hostSet(target: Object, propertyKey: string | symbol, parameterIndex: number): void {\n registerParam('hostSet', target, propertyKey, parameterIndex);\n}\n\n/** HelperHostSet(HelperSet + HostSet + $this \uC804\uCCB4 \uBB36\uC74C)\uC744 \uC8FC\uC785\uD55C\uB2E4. */\nexport function helperHostSet(target: Object, propertyKey: string | symbol, parameterIndex: number): void {\n registerParam('helperHostSet', target, propertyKey, parameterIndex);\n}\n\n/** HelperSet($d/$w/$q/$qa/$qi \uB4F1 \uC21C\uC218 DOM/window \uD5EC\uD37C, \uD638\uC2A4\uD2B8 \uD2B8\uB9AC \uC815\uBCF4 \uC5C6\uC74C)\uC744 \uC8FC\uC785\uD55C\uB2E4. */\nexport function helperSet(target: Object, propertyKey: string | symbol, parameterIndex: number): void {\n registerParam('helperSet', target, propertyKey, parameterIndex);\n}\n\n/** @subscribeSwcAppRouteChangeWhileConnected \uD578\uB4E4\uB7EC\uC758 \uB77C\uC6B0\uD2B8 \uBCC0\uACBD \uC774\uBCA4\uD2B8({...RouterEventType, pathData})\uB97C \uC8FC\uC785\uD55C\uB2E4. */\nexport function routerEvent(target: Object, propertyKey: string | symbol, parameterIndex: number): void {\n registerParam('routerEvent', target, propertyKey, parameterIndex);\n}\n\n/** @subscribeSwcAppMessageWhileConnected \uD578\uB4E4\uB7EC\uC758 SwcAppMessage \uD398\uC774\uB85C\uB4DC\uB97C \uC8FC\uC785\uD55C\uB2E4. */\nexport function appMessage(target: Object, propertyKey: string | symbol, parameterIndex: number): void {\n registerParam('appMessage', target, propertyKey, parameterIndex);\n}\n\nexport const getParameterMetadata = (target: any, propertyKey: string | symbol): SaveParamConfig[] => {\n const constructor = target instanceof Function ? target : target.constructor;\n return ReflectUtils.getMetadata(SWC_PARAMETER_METADATA_KEY, constructor, propertyKey) ?? [];\n};\n\n/**\n * \uC704 \uD30C\uB77C\uBBF8\uD130 \uB370\uCF54\uB808\uC774\uD130 \uBA54\uD0C0\uB370\uC774\uD130\uAC00 \uD558\uB098\uB77C\uB3C4 \uC788\uC73C\uBA74 kind\uBCC4 \uAC12\uC744 index \uC21C\uC11C\uC5D0 \uB9DE\uAC8C\n * \uBC30\uC5F4\uB85C \uC870\uB9BD\uD558\uACE0, \uD558\uB098\uB3C4 \uC5C6\uC73C\uBA74 \uAE30\uC874 \uC704\uCE58 \uC778\uC790(legacyArgs)\uB97C \uADF8\uB300\uB85C \uBC18\uD658\uD55C\uB2E4 \u2014 \uC644\uC804 \uD558\uC704\uD638\uD658.\n */\nexport const buildSwcParameterArgs = (\n target: any,\n propertyKey: string | symbol,\n kindValues: Partial<Record<SwcParamKind, any>>,\n legacyArgs: any[]\n): any[] => {\n const saves = getParameterMetadata(target, propertyKey);\n if (saves.length === 0) return legacyArgs;\n const maxIndex = Math.max(...saves.map(s => s.index));\n const args: any[] = new Array(maxIndex + 1);\n for (const s of saves) args[s.index] = kindValues[s.kind];\n return args;\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA6B;AAY7B,MAAM,6BAA6B,OAAO,IAAI,gCAAgC;AAI9E,MAAM,gBAAgB,CAAC,MAAoB,QAAgB,aAA0C,mBAA2B;AAC9H,MAAI,CAAC,YAAa;AAClB,QAAM,cAAc,OAAO;AAC3B,QAAM,QAAS,yBAAa,eAAe,4BAA4B,aAAa,WAAW,KAAK,CAAC;AACrG,QAAM,KAAK,EAAE,OAAO,gBAAgB,KAAK,CAAC;AAC1C,2BAAa,eAAe,4BAA4B,OAAO,aAAa,WAAW;AACzF;AAGO,SAAS,YAAY,QAAgB,aAA8B,gBAA8B;AACtG,gBAAc,SAAS,QAAQ,aAAa,cAAc;AAC5D;AAGO,SAAS,eAAe,QAAgB,aAA8B,gBAA8B;AACzG,gBAAc,WAAW,QAAQ,aAAa,cAAc;AAC9D;AAGO,SAAS,QAAQ,QAAgB,aAA8B,gBAA8B;AAClG,gBAAc,WAAW,QAAQ,aAAa,cAAc;AAC9D;AAGO,SAAS,cAAc,QAAgB,aAA8B,gBAA8B;AACxG,gBAAc,iBAAiB,QAAQ,aAAa,cAAc;AACpE;AAGO,SAAS,UAAU,QAAgB,aAA8B,gBAA8B;AACpG,gBAAc,aAAa,QAAQ,aAAa,cAAc;AAChE;AAGO,SAAS,YAAY,QAAgB,aAA8B,gBAA8B;AACtG,gBAAc,eAAe,QAAQ,aAAa,cAAc;AAClE;AAGO,SAAS,WAAW,QAAgB,aAA8B,gBAA8B;AACrG,gBAAc,cAAc,QAAQ,aAAa,cAAc;AACjE;AAEO,MAAM,uBAAuB,CAAC,QAAa,gBAAoD;AACpG,QAAM,cAAc,kBAAkB,WAAW,SAAS,OAAO;AACjE,SAAO,yBAAa,YAAY,4BAA4B,aAAa,WAAW,KAAK,CAAC;AAC5F;AAMO,MAAM,wBAAwB,CACnC,QACA,aACA,YACA,eACU;AACV,QAAM,QAAQ,qBAAqB,QAAQ,WAAW;AACtD,MAAI,MAAM,WAAW,EAAG,QAAO;AAC/B,QAAM,WAAW,KAAK,IAAI,GAAG,MAAM,IAAI,OAAK,EAAE,KAAK,CAAC;AACpD,QAAM,OAAc,IAAI,MAAM,WAAW,CAAC;AAC1C,aAAW,KAAK,MAAO,MAAK,EAAE,KAAK,IAAI,WAAW,EAAE,IAAI;AACxD,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
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 requestAnimationFrame_exports = {};
|
|
19
|
+
__export(requestAnimationFrame_exports, {
|
|
20
|
+
REQUEST_ANIMATION_FRAME_METADATA_KEY: () => REQUEST_ANIMATION_FRAME_METADATA_KEY,
|
|
21
|
+
RequestAnimationFrameLifeCycler: () => RequestAnimationFrameLifeCycler,
|
|
22
|
+
findAllRequestAnimationFrameMetadata: () => findAllRequestAnimationFrameMetadata,
|
|
23
|
+
requestAnimationFrame: () => requestAnimationFrame
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(requestAnimationFrame_exports);
|
|
26
|
+
var import_core = require("@dooboostore/core");
|
|
27
|
+
var import_elementDefine = require("./elementDefine");
|
|
28
|
+
var import_Utils = require("../utils/Utils");
|
|
29
|
+
const REQUEST_ANIMATION_FRAME_METADATA_KEY = Symbol.for("simple-web-component:request-animation-frame");
|
|
30
|
+
const activeMap = /* @__PURE__ */ new WeakMap();
|
|
31
|
+
const getActiveEntries = (inst) => {
|
|
32
|
+
let entries = activeMap.get(inst);
|
|
33
|
+
if (!entries) {
|
|
34
|
+
entries = [];
|
|
35
|
+
activeMap.set(inst, entries);
|
|
36
|
+
}
|
|
37
|
+
return entries;
|
|
38
|
+
};
|
|
39
|
+
const startFrameLoop = (win, entries, frameFn) => {
|
|
40
|
+
let currentId = 0;
|
|
41
|
+
const step = (timestamp, prevValue) => {
|
|
42
|
+
const idx = entries.indexOf(currentId);
|
|
43
|
+
if (idx >= 0) entries.splice(idx, 1);
|
|
44
|
+
let result;
|
|
45
|
+
try {
|
|
46
|
+
result = frameFn(timestamp, prevValue);
|
|
47
|
+
} catch (e) {
|
|
48
|
+
console.error("[SWC] requestAnimationFrame callback error:", e);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (result === void 0 || result === null) return;
|
|
52
|
+
currentId = win.requestAnimationFrame((ts) => step(ts, result));
|
|
53
|
+
entries.push(currentId);
|
|
54
|
+
};
|
|
55
|
+
currentId = win.requestAnimationFrame((ts) => step(ts, void 0));
|
|
56
|
+
entries.push(currentId);
|
|
57
|
+
return currentId;
|
|
58
|
+
};
|
|
59
|
+
const applyRequestAnimationFrame = (options, target, propertyKey, descriptor) => {
|
|
60
|
+
const constructor = target.constructor;
|
|
61
|
+
const normalizedOptions = { ...options, type: options.type ?? "returnValue" };
|
|
62
|
+
let metaList = import_core.ReflectUtils.getOwnMetadata(REQUEST_ANIMATION_FRAME_METADATA_KEY, constructor);
|
|
63
|
+
if (!metaList) {
|
|
64
|
+
metaList = [];
|
|
65
|
+
import_core.ReflectUtils.defineMetadata(REQUEST_ANIMATION_FRAME_METADATA_KEY, metaList, constructor);
|
|
66
|
+
}
|
|
67
|
+
metaList.push({ propertyKey, options: normalizedOptions });
|
|
68
|
+
if (normalizedOptions.type === "onConnected" || !descriptor) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const original = descriptor.value;
|
|
72
|
+
descriptor.value = function(...args) {
|
|
73
|
+
const res = original.apply(this, args);
|
|
74
|
+
const vk = normalizedOptions.valueKey ?? REQUEST_ANIMATION_FRAME_METADATA_KEY;
|
|
75
|
+
const frameFn = typeof res === "function" ? res : res && typeof res === "object" && typeof res[vk] === "function" ? res[vk] : void 0;
|
|
76
|
+
if (frameFn) {
|
|
77
|
+
(0, import_elementDefine.ensureInit)(this);
|
|
78
|
+
const conf = (0, import_elementDefine.getElementConfig)(this);
|
|
79
|
+
const win = this._resolveWindow?.(conf) || (typeof window !== "undefined" ? window : void 0);
|
|
80
|
+
const id = startFrameLoop(win, getActiveEntries(this), frameFn);
|
|
81
|
+
normalizedOptions.created?.(import_Utils.SwcUtils.getHelperAndHostSet(win, this), id);
|
|
82
|
+
}
|
|
83
|
+
return res;
|
|
84
|
+
};
|
|
85
|
+
return descriptor;
|
|
86
|
+
};
|
|
87
|
+
function requestAnimationFrame(optionsOrTarget, propertyKey, descriptor) {
|
|
88
|
+
if (propertyKey !== void 0) {
|
|
89
|
+
applyRequestAnimationFrame({}, optionsOrTarget, propertyKey, descriptor);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
return (target, propertyKey2, descriptor2) => {
|
|
93
|
+
return applyRequestAnimationFrame(optionsOrTarget ?? {}, target, propertyKey2, descriptor2);
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
const findAllRequestAnimationFrameMetadata = (target) => {
|
|
97
|
+
const constructor = target instanceof Function ? target : target.constructor;
|
|
98
|
+
return (import_core.ReflectUtils.findAllMetadata(REQUEST_ANIMATION_FRAME_METADATA_KEY, constructor) || []).flat();
|
|
99
|
+
};
|
|
100
|
+
class RequestAnimationFrameLifeCycler {
|
|
101
|
+
onConnected(helperHostSet) {
|
|
102
|
+
const inst = helperHostSet.$this;
|
|
103
|
+
activeMap.delete(inst);
|
|
104
|
+
const entries = getActiveEntries(inst);
|
|
105
|
+
for (const meta of findAllRequestAnimationFrameMetadata(inst)) {
|
|
106
|
+
if (meta.options.type !== "onConnected") continue;
|
|
107
|
+
const frameFn = (timestamp, prevValue) => inst[meta.propertyKey](timestamp, prevValue);
|
|
108
|
+
const id = startFrameLoop(helperHostSet.$w, entries, frameFn);
|
|
109
|
+
meta.options.created?.(helperHostSet, id);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
onDisconnected(helperHostSet) {
|
|
113
|
+
const inst = helperHostSet.$this;
|
|
114
|
+
for (const id of activeMap.get(inst) ?? []) {
|
|
115
|
+
try {
|
|
116
|
+
helperHostSet.$w.cancelAnimationFrame(id);
|
|
117
|
+
} catch (e) {
|
|
118
|
+
console.error("[SWC] cancelAnimationFrame error:", e);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
activeMap.delete(inst);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=requestAnimationFrame.js.map
|