@dooboostore/simple-web-component 1.0.47 → 1.0.49
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 +223 -27
- package/dist/cjs/config/config.js +1 -1
- package/dist/cjs/config/config.js.map +2 -2
- package/dist/cjs/decorators/addEventListener.js +412 -16
- package/dist/cjs/decorators/addEventListener.js.map +3 -3
- package/dist/cjs/decorators/applyAttribute.js +25 -0
- package/dist/cjs/decorators/applyAttribute.js.map +2 -2
- package/dist/cjs/decorators/applyClass.js +49 -18
- package/dist/cjs/decorators/applyClass.js.map +3 -3
- package/dist/cjs/decorators/applyNode.js +67 -1
- package/dist/cjs/decorators/applyNode.js.map +3 -3
- package/dist/cjs/decorators/applyProperty.js +101 -3
- package/dist/cjs/decorators/applyProperty.js.map +2 -2
- package/dist/cjs/decorators/applyStyle.js +36 -5
- package/dist/cjs/decorators/applyStyle.js.map +2 -2
- package/dist/cjs/decorators/changedAttribute.js +39 -0
- package/dist/cjs/decorators/changedAttribute.js.map +2 -2
- package/dist/cjs/decorators/elementDefine.js +244 -225
- package/dist/cjs/decorators/elementDefine.js.map +3 -3
- package/dist/cjs/decorators/emitCustomEvent.js +55 -0
- package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
- package/dist/cjs/decorators/index.js +5 -1
- package/dist/cjs/decorators/index.js.map +2 -2
- package/dist/cjs/decorators/intersectionObserver.js +209 -0
- package/dist/cjs/decorators/intersectionObserver.js.map +7 -0
- package/dist/cjs/decorators/mutationObserver.js +244 -0
- package/dist/cjs/decorators/mutationObserver.js.map +7 -0
- package/dist/cjs/decorators/query.js +129 -102
- package/dist/cjs/decorators/query.js.map +2 -2
- package/dist/cjs/decorators/resizeObserver.js +191 -0
- package/dist/cjs/decorators/resizeObserver.js.map +7 -0
- package/dist/cjs/decorators/setInterval.js +82 -0
- package/dist/cjs/decorators/setInterval.js.map +7 -0
- package/dist/cjs/decorators/setTimeout.js +82 -0
- package/dist/cjs/decorators/setTimeout.js.map +7 -0
- package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js +9 -0
- package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js.map +2 -2
- package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js +9 -0
- package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
- package/dist/cjs/examples/RxJSOperatorsExample.js +285 -0
- package/dist/cjs/examples/RxJSOperatorsExample.js.map +7 -0
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/esm/config/config.js +1 -1
- package/dist/esm/config/config.js.map +2 -2
- package/dist/esm/decorators/addEventListener.js +413 -16
- package/dist/esm/decorators/addEventListener.js.map +3 -3
- package/dist/esm/decorators/applyAttribute.js +25 -0
- package/dist/esm/decorators/applyAttribute.js.map +2 -2
- package/dist/esm/decorators/applyClass.js +49 -18
- package/dist/esm/decorators/applyClass.js.map +3 -3
- package/dist/esm/decorators/applyNode.js +67 -1
- package/dist/esm/decorators/applyNode.js.map +3 -3
- package/dist/esm/decorators/applyProperty.js +101 -3
- package/dist/esm/decorators/applyProperty.js.map +2 -2
- package/dist/esm/decorators/applyStyle.js +36 -5
- package/dist/esm/decorators/applyStyle.js.map +2 -2
- package/dist/esm/decorators/changedAttribute.js +40 -0
- package/dist/esm/decorators/changedAttribute.js.map +2 -2
- package/dist/esm/decorators/elementDefine.js +249 -230
- package/dist/esm/decorators/elementDefine.js.map +3 -3
- package/dist/esm/decorators/emitCustomEvent.js +55 -0
- package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
- package/dist/esm/decorators/index.js +5 -1
- package/dist/esm/decorators/index.js.map +2 -2
- package/dist/esm/decorators/intersectionObserver.js +191 -0
- package/dist/esm/decorators/intersectionObserver.js.map +7 -0
- package/dist/esm/decorators/mutationObserver.js +226 -0
- package/dist/esm/decorators/mutationObserver.js.map +7 -0
- package/dist/esm/decorators/query.js +129 -102
- package/dist/esm/decorators/query.js.map +2 -2
- package/dist/esm/decorators/resizeObserver.js +173 -0
- package/dist/esm/decorators/resizeObserver.js.map +7 -0
- package/dist/esm/decorators/setInterval.js +64 -0
- package/dist/esm/decorators/setInterval.js.map +7 -0
- package/dist/esm/decorators/setTimeout.js +64 -0
- package/dist/esm/decorators/setTimeout.js.map +7 -0
- package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js +9 -0
- package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js.map +2 -2
- package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js +9 -0
- package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
- package/dist/esm/examples/RxJSOperatorsExample.js +266 -0
- package/dist/esm/examples/RxJSOperatorsExample.js.map +7 -0
- package/dist/esm/types/index.js.map +1 -1
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +2413 -889
- package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
- package/dist/types/config/config.d.ts.map +1 -1
- package/dist/types/decorators/addEventListener.d.ts +93 -23
- package/dist/types/decorators/addEventListener.d.ts.map +1 -1
- package/dist/types/decorators/applyAttribute.d.ts +22 -34
- package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
- package/dist/types/decorators/applyClass.d.ts +34 -34
- package/dist/types/decorators/applyClass.d.ts.map +1 -1
- package/dist/types/decorators/applyNode.d.ts +30 -20
- package/dist/types/decorators/applyNode.d.ts.map +1 -1
- package/dist/types/decorators/applyProperty.d.ts +57 -34
- package/dist/types/decorators/applyProperty.d.ts.map +1 -1
- package/dist/types/decorators/applyStyle.d.ts +25 -12
- package/dist/types/decorators/applyStyle.d.ts.map +1 -1
- package/dist/types/decorators/changedAttribute.d.ts +11 -0
- package/dist/types/decorators/changedAttribute.d.ts.map +1 -1
- package/dist/types/decorators/elementDefine.d.ts.map +1 -1
- package/dist/types/decorators/emitCustomEvent.d.ts +28 -4
- package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
- package/dist/types/decorators/index.d.ts +5 -1
- package/dist/types/decorators/index.d.ts.map +1 -1
- package/dist/types/decorators/intersectionObserver.d.ts +49 -0
- package/dist/types/decorators/intersectionObserver.d.ts.map +1 -0
- package/dist/types/decorators/mutationObserver.d.ts +46 -0
- package/dist/types/decorators/mutationObserver.d.ts.map +1 -0
- package/dist/types/decorators/query.d.ts +63 -8
- package/dist/types/decorators/query.d.ts.map +1 -1
- package/dist/types/decorators/resizeObserver.d.ts +48 -0
- package/dist/types/decorators/resizeObserver.d.ts.map +1 -0
- package/dist/types/decorators/setInterval.d.ts +29 -0
- package/dist/types/decorators/setInterval.d.ts.map +1 -0
- package/dist/types/decorators/setTimeout.d.ts +29 -0
- package/dist/types/decorators/setTimeout.d.ts.map +1 -0
- package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts +7 -1
- package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts.map +1 -1
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts +6 -0
- package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts.map +1 -1
- package/dist/types/examples/RxJSOperatorsExample.d.ts +94 -0
- package/dist/types/examples/RxJSOperatorsExample.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +104 -0
- package/dist/types/types/index.d.ts.map +1 -1
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +2413 -889
- package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
- package/package.json +8 -6
- package/src/config/config.ts +1 -1
- package/src/decorators/addEventListener.ts +426 -23
- package/src/decorators/applyAttribute.ts +50 -36
- package/src/decorators/applyClass.ts +76 -26
- package/src/decorators/applyNode.ts +114 -36
- package/src/decorators/applyProperty.ts +152 -40
- package/src/decorators/applyStyle.ts +64 -17
- package/src/decorators/changedAttribute.ts +46 -0
- package/src/decorators/elementDefine.ts +301 -317
- package/src/decorators/emitCustomEvent.ts +73 -5
- package/src/decorators/index.ts +5 -1
- package/src/decorators/intersectionObserver.ts +259 -0
- package/src/decorators/mutationObserver.ts +304 -0
- package/src/decorators/query.ts +182 -117
- package/src/decorators/resizeObserver.ts +235 -0
- package/src/decorators/setInterval.ts +80 -0
- package/src/decorators/setTimeout.ts +80 -0
- package/src/decorators/subscribeSwcAppMessageWhileConnected.ts +17 -0
- package/src/decorators/subscribeSwcAppRouteChangeWhileConnected.ts +19 -0
- package/src/examples/RxJSOperatorsExample.ts +279 -0
- package/src/types/index.ts +141 -0
- package/dist/cjs/decorators/queryAll.js +0 -181
- package/dist/cjs/decorators/queryAll.js.map +0 -7
- package/dist/cjs/elements/tt/SwcAppMixin.js +0 -1
- package/dist/cjs/elements/tt/SwcAppMixin.js.map +0 -7
- package/dist/cjs/elements/tt/SwcAsync.js +0 -1
- package/dist/cjs/elements/tt/SwcAsync.js.map +0 -7
- package/dist/cjs/elements/tt/SwcAsyncTemplate.js +0 -1
- package/dist/cjs/elements/tt/SwcAsyncTemplate.js.map +0 -7
- package/dist/cjs/elements/tt/SwcChoose.js +0 -1
- package/dist/cjs/elements/tt/SwcChoose.js.map +0 -7
- package/dist/cjs/elements/tt/SwcChooseTemplate.js +0 -1
- package/dist/cjs/elements/tt/SwcChooseTemplate.js.map +0 -7
- package/dist/cjs/elements/tt/SwcIf.js +0 -1
- package/dist/cjs/elements/tt/SwcIf.js.map +0 -7
- package/dist/cjs/elements/tt/SwcIfTemplate.js +0 -1
- package/dist/cjs/elements/tt/SwcIfTemplate.js.map +0 -7
- package/dist/cjs/elements/tt/SwcLoop.js +0 -1
- package/dist/cjs/elements/tt/SwcLoop.js.map +0 -7
- package/dist/cjs/elements/tt/SwcLoopTemplate.js +0 -1
- package/dist/cjs/elements/tt/SwcLoopTemplate.js.map +0 -7
- package/dist/cjs/elements/tt/SwcSubTemplates.js +0 -1
- package/dist/cjs/elements/tt/SwcSubTemplates.js.map +0 -7
- package/dist/cjs/elements/tt/register.js +0 -1
- package/dist/cjs/elements/tt/register.js.map +0 -7
- package/dist/esm/decorators/queryAll.js +0 -162
- package/dist/esm/decorators/queryAll.js.map +0 -7
- package/dist/esm/elements/tt/SwcAppMixin.js +0 -1
- package/dist/esm/elements/tt/SwcAppMixin.js.map +0 -7
- package/dist/esm/elements/tt/SwcAsync.js +0 -1
- package/dist/esm/elements/tt/SwcAsync.js.map +0 -7
- package/dist/esm/elements/tt/SwcAsyncTemplate.js +0 -1
- package/dist/esm/elements/tt/SwcAsyncTemplate.js.map +0 -7
- package/dist/esm/elements/tt/SwcChoose.js +0 -1
- package/dist/esm/elements/tt/SwcChoose.js.map +0 -7
- package/dist/esm/elements/tt/SwcChooseTemplate.js +0 -1
- package/dist/esm/elements/tt/SwcChooseTemplate.js.map +0 -7
- package/dist/esm/elements/tt/SwcIf.js +0 -1
- package/dist/esm/elements/tt/SwcIf.js.map +0 -7
- package/dist/esm/elements/tt/SwcIfTemplate.js +0 -1
- package/dist/esm/elements/tt/SwcIfTemplate.js.map +0 -7
- package/dist/esm/elements/tt/SwcLoop.js +0 -1
- package/dist/esm/elements/tt/SwcLoop.js.map +0 -7
- package/dist/esm/elements/tt/SwcLoopTemplate.js +0 -1
- package/dist/esm/elements/tt/SwcLoopTemplate.js.map +0 -7
- package/dist/esm/elements/tt/SwcSubTemplates.js +0 -1
- package/dist/esm/elements/tt/SwcSubTemplates.js.map +0 -7
- package/dist/esm/elements/tt/register.js +0 -1
- package/dist/esm/elements/tt/register.js.map +0 -7
- package/dist/types/decorators/queryAll.d.ts +0 -22
- package/dist/types/decorators/queryAll.d.ts.map +0 -1
- package/dist/types/elements/tt/SwcAppMixin.d.ts +0 -1
- package/dist/types/elements/tt/SwcAppMixin.d.ts.map +0 -1
- package/dist/types/elements/tt/SwcAsync.d.ts +0 -1
- package/dist/types/elements/tt/SwcAsync.d.ts.map +0 -1
- package/dist/types/elements/tt/SwcAsyncTemplate.d.ts +0 -1
- package/dist/types/elements/tt/SwcAsyncTemplate.d.ts.map +0 -1
- package/dist/types/elements/tt/SwcChoose.d.ts +0 -1
- package/dist/types/elements/tt/SwcChoose.d.ts.map +0 -1
- package/dist/types/elements/tt/SwcChooseTemplate.d.ts +0 -1
- package/dist/types/elements/tt/SwcChooseTemplate.d.ts.map +0 -1
- package/dist/types/elements/tt/SwcIf.d.ts +0 -1
- package/dist/types/elements/tt/SwcIf.d.ts.map +0 -1
- package/dist/types/elements/tt/SwcIfTemplate.d.ts +0 -1
- package/dist/types/elements/tt/SwcIfTemplate.d.ts.map +0 -1
- package/dist/types/elements/tt/SwcLoop.d.ts +0 -1
- package/dist/types/elements/tt/SwcLoop.d.ts.map +0 -1
- package/dist/types/elements/tt/SwcLoopTemplate.d.ts +0 -1
- package/dist/types/elements/tt/SwcLoopTemplate.d.ts.map +0 -1
- package/dist/types/elements/tt/SwcSubTemplates.d.ts +0 -1
- package/dist/types/elements/tt/SwcSubTemplates.d.ts.map +0 -1
- package/dist/types/elements/tt/register.d.ts +0 -1
- package/dist/types/elements/tt/register.d.ts.map +0 -1
- package/src/decorators/queryAll.ts +0 -186
- package/src/elements/tt/SwcAppMixin.ts +0 -13
- package/src/elements/tt/SwcAsync.ts +0 -139
- package/src/elements/tt/SwcAsyncTemplate.ts +0 -126
- package/src/elements/tt/SwcChoose.ts +0 -182
- package/src/elements/tt/SwcChooseTemplate.ts +0 -229
- package/src/elements/tt/SwcIf.ts +0 -145
- package/src/elements/tt/SwcIfTemplate.ts +0 -158
- package/src/elements/tt/SwcLoop.ts +0 -222
- package/src/elements/tt/SwcLoopTemplate.ts +0 -255
- package/src/elements/tt/SwcSubTemplates.ts +0 -6
- package/src/elements/tt/register.ts +0 -720
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/decorators/addEventListener.ts"],
|
|
4
|
-
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core';\nimport { SpecialSelector, SwcQueryOptions, HelperHostSet } from '../types';\n\nexport interface AddEventListenerBaseOptions<TEvent extends Event = Event> extends EventListenerOptions {\n capture?: boolean;\n once?: boolean;\n passive?: boolean;\n stopPropagation?: boolean;\n stopImmediatePropagation?: boolean;\n preventDefault?: boolean;\n // removeOnDisconnected?: boolean;\n delegate?: boolean;\n filter?: (target: Event | CustomEvent, meta:{currentThis: any, helper: HelperHostSet}) => boolean;\n // RxJS operator options\n debounceTime?: number;\n throttleTime?: number;\n distinctUntilChanged?: boolean | ((prev: TEvent, curr: TEvent) => boolean);\n}\n\nexport type EventListenerSelector = string | ((currentThis: any, helper: HelperHostSet) => NodeList | Element | Element[] | null);\n\nexport interface AddEventListenerMetadata<TEvent extends Event = Event> {\n propertyKey: string | symbol;\n selector: EventListenerSelector;\n type: string;\n options: AddEventListenerBaseOptions<TEvent> & SwcQueryOptions & { delegate?: boolean };\n}\n\nexport const ADD_EVENT_LISTENER_METADATA_KEY = Symbol.for('simple-web-component:add-event-listener');\n\nexport function addEventListener<TEvent extends Event = Event>(target: SpecialSelector, type: string, options?: AddEventListenerBaseOptions<TEvent>): MethodDecorator;\nexport function addEventListener<TEvent extends Event = Event>(selector: EventListenerSelector, type: string, options?: AddEventListenerBaseOptions<TEvent> & SwcQueryOptions & { delegate?: boolean }): MethodDecorator;\n/**\n * @addEventListener decorator to bind events to elements.\n */\nexport function addEventListener<TEvent extends Event = Event>(selectorOrTarget: EventListenerSelector, type: string, options: any = {}): MethodDecorator {\n return (targetObj: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n const constructor = targetObj.constructor;\n\n let listeners = ReflectUtils.getMetadata<AddEventListenerMetadata<TEvent>[]>(ADD_EVENT_LISTENER_METADATA_KEY, constructor);\n if (!listeners) {\n listeners = [];\n ReflectUtils.defineMetadata(ADD_EVENT_LISTENER_METADATA_KEY, listeners, constructor);\n }\n\n listeners.push({ propertyKey, selector: selectorOrTarget, type, options });\n };\n}\n\n\nexport function addEventListenerDelegateLightDom<TEvent extends Event = Event>(selector: EventListenerSelector, type: string, options?: Omit<AddEventListenerBaseOptions<TEvent>, 'delegate'>): MethodDecorator {\n return addEventListener<TEvent>(selector, type, {...options??{}, root:'light', delegate: true});\n}\n\nexport function addEventListenerDelegateShadowDom<TEvent extends Event = Event>(selector: EventListenerSelector, type: string, options?: Omit<AddEventListenerBaseOptions<TEvent>, 'delegate'>): MethodDecorator {\n return addEventListener<TEvent>(selector, type, {...options??{}, root:'shadow', delegate: true});\n}\nexport function addEventListenerDelegateAllDom<TEvent extends Event = Event>(selector: EventListenerSelector, type: string, options?: Omit<AddEventListenerBaseOptions<TEvent>, 'delegate'>): MethodDecorator {\n return addEventListener<TEvent>(selector, type, {...options??{}, root:'all', delegate: true});\n}\nexport function addEventListenerDelegate<TEvent extends Event = Event>(selector: EventListenerSelector, type: string, options?: Omit<AddEventListenerBaseOptions<TEvent>, 'delegate'>): MethodDecorator {\n return addEventListener<TEvent>(selector, type, {...options??{}, root:'auto', delegate: true});\n}\n\n/**\n * @addEventListenerThis decorator - simplified version of @addEventListener for $this selector\n */\n\n// --- Aliases: event... ---\nexport const event = addEventListener;\nexport const eventDelegateLightDom = addEventListenerDelegateLightDom;\nexport const eventDelegateShadowDom = addEventListenerDelegateShadowDom;\nexport const eventDelegateAllDom = addEventListenerDelegateAllDom;\nexport const eventDelegate = addEventListenerDelegate;\nexport function addEventListenerThis<TEvent extends Event = Event>(type: string, options?: AddEventListenerBaseOptions<TEvent> & SwcQueryOptions): MethodDecorator {\n return addEventListener<TEvent>('$this', type, options);\n}\n\n/**\n * @addEventListenerAppHost decorator - simplified version of @addEventListener for $appHost selector\n */\nexport function addEventListenerAppHost<TEvent extends Event = Event>(type: string, options?: AddEventListenerBaseOptions<TEvent> & SwcQueryOptions): MethodDecorator {\n return addEventListener<TEvent>('$appHost', type, options);\n}\n\nexport function addEventListenerWindow<TEvent extends Event = Event>(type: string, options?: AddEventListenerBaseOptions<TEvent> & SwcQueryOptions): MethodDecorator {\n return addEventListener<TEvent>('$window', type, options);\n}\nexport function addEventListenerDocument<TEvent extends Event = Event>(type: string, options?: AddEventListenerBaseOptions<TEvent> & SwcQueryOptions): MethodDecorator {\n return addEventListener<TEvent>('$document', type, options);\n}\n\nexport const getAddEventListenerMetadata = (target: any): AddEventListenerMetadata<Event>[] | undefined => {\n const constructor = target instanceof Function ? target : target.constructor;\n return ReflectUtils.getMetadata(ADD_EVENT_LISTENER_METADATA_KEY, constructor);\n};\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,oBAAoB;AA4BtB,MAAM,kCAAkC,OAAO,IAAI,yCAAyC;AAO5F,SAAS,iBAA+C,kBAAyC,MAAc,UAAe,CAAC,GAAoB;AACxJ,SAAO,CAAC,WAAmB,aAA8B,eAAmC;AAC1F,UAAM,cAAc,UAAU;AAE9B,QAAI,YAAY,aAAa,YAAgD,iCAAiC,WAAW;AACzH,QAAI,CAAC,WAAW;AACd,kBAAY,CAAC;AACb,mBAAa,eAAe,iCAAiC,WAAW,WAAW;AAAA,IACrF;AAEA,cAAU,KAAK,EAAE,aAAa,UAAU,kBAAkB,MAAM,QAAQ,CAAC;AAAA,EAC3E;AACF;AAGO,SAAS,iCAA+D,UAAiC,MAAc,SAAkF;AAC9M,SAAO,iBAAyB,UAAU,MAAM,EAAC,GAAG,WAAS,CAAC,GAAG,MAAK,SAAS,UAAU,KAAI,CAAC;AAChG;AAEO,SAAS,kCAAgE,UAAiC,MAAc,SAAkF;AAC/M,SAAO,iBAAyB,UAAU,MAAM,EAAC,GAAG,WAAS,CAAC,GAAG,MAAK,UAAU,UAAU,KAAI,CAAC;AACjG;AACO,SAAS,+BAA6D,UAAiC,MAAc,SAAkF;AAC5M,SAAO,iBAAyB,UAAU,MAAM,EAAC,GAAG,WAAS,CAAC,GAAG,MAAK,OAAO,UAAU,KAAI,CAAC;AAC9F;AACO,SAAS,yBAAuD,UAAiC,MAAc,SAAkF;AACtM,SAAO,iBAAyB,UAAU,MAAM,EAAC,GAAG,WAAS,CAAC,GAAG,MAAK,QAAQ,UAAU,KAAI,CAAC;AAC/F;AAOO,MAAM,QAAQ;AACd,MAAM,wBAAwB;AAC9B,MAAM,yBAAyB;AAC/B,MAAM,sBAAsB;AAC5B,MAAM,gBAAgB;AACtB,SAAS,qBAAmD,MAAc,SAAkF;AACjK,SAAO,iBAAyB,SAAS,MAAM,OAAO;AACxD;AAKO,SAAS,wBAAsD,MAAc,SAAkF;AACpK,SAAO,iBAAyB,YAAY,MAAM,OAAO;AAC3D;AAEO,SAAS,uBAAqD,MAAc,SAAkF;AACnK,SAAO,iBAAyB,WAAW,MAAM,OAAO;AAC1D;AACO,SAAS,yBAAuD,MAAc,SAAkF;AACrK,SAAO,iBAAyB,aAAa,MAAM,OAAO;AAC5D;AAEO,MAAM,8BAA8B,CAAC,WAA+D;AACzG,QAAM,cAAc,kBAAkB,WAAW,SAAS,OAAO;AACjE,SAAO,aAAa,YAAY,iCAAiC,WAAW;AAC9E;",
|
|
6
|
-
"names": []
|
|
4
|
+
"sourcesContent": ["import { ReflectUtils } from '@dooboostore/core';\nimport { SpecialSelector, SwcQueryOptions, HelperHostSet, SwcFnSelector, SwcSelector } from '../types';\n\nexport interface AddEventListenerBaseOptions<TEvent extends Event = Event> extends EventListenerOptions {\n capture?: boolean;\n once?: boolean;\n passive?: boolean;\n stopPropagation?: boolean;\n stopImmediatePropagation?: boolean;\n preventDefault?: boolean;\n // removeOnDisconnected?: boolean;\n // delegate\uB294 \uBB38\uC790\uC5F4 \uC140\uB809\uD130 \uC804\uC6A9 \u2192 AddEventListenerQueryOptions\uC5D0\uB9CC \uC874\uC7AC\n filter?: (target: Event | CustomEvent, meta:{currentThis: any, helper: HelperHostSet}) => boolean;\n // \uB9AC\uC2A4\uB108 \uC81C\uAC70(disconnected \uB610\uB294 unmount) \uC2DC \uD638\uCD9C\uB418\uB294 \uCF5C\uBC31. \uCCAB \uBC88\uC9F8 \uC778\uC790\uB294 \uBC14\uC778\uB529\uB41C \uD0C0\uAC9F element, \uB450 \uBC88\uC9F8\uB294 \uC774 \uC635\uC158\uC774 \uC18D\uD55C \uC804\uCCB4 \uC635\uC158 \uAC1D\uCCB4(Base + SwcQuery + delegate).\n removeListener?: (target: Element, optionValue: AddEventListenerQueryOptions<TEvent>) => void;\n // RxJS operator options\n debounceTime?: number;\n throttleTime?: number;\n distinctUntilChanged?: boolean | ((prev: TEvent, curr: TEvent) => boolean);\n}\n\nexport type EventListenerFnSelector = SwcFnSelector;\nexport type EventListenerSelector = SwcSelector;\n\nexport interface AddEventListenerMetadata<TEvent extends Event = Event> {\n propertyKey: string | symbol;\n selector: EventListenerSelector;\n type: string;\n options: AddEventListenerQueryOptions<TEvent>;\n}\n\nexport const ADD_EVENT_LISTENER_METADATA_KEY = Symbol.for('simple-web-component:add-event-listener');\n\n// root + delegate \uD5C8\uC6A9 \u2014 \uBB38\uC790\uC5F4 \uC140\uB809\uD130\uB294 \uCEF4\uD3EC\uB10C\uD2B8 DOM \uD2B8\uB9AC \uC548\uC5D0\uC11C \uD0D0\uC0C9/\uB378\uB9AC\uAC8C\uC774\uC158\uD558\uBBC0\uB85C \uC758\uBBF8 \uC788\uC74C\nexport type AddEventListenerQueryOptions<TEvent extends Event = Event> = AddEventListenerBaseOptions<TEvent> & SwcQueryOptions & { delegate?: boolean | 'this' | 'mutation' };\n// root\u00B7delegate \uBE44\uD5C8\uC6A9 \u2014 \uD568\uC218 \uC140\uB809\uD130\uB294 \uC774\uBBF8 \uC694\uC18C\uB97C \uC9C1\uC811 \uBC18\uD658\uD558\uBBC0\uB85C root\u00B7delegate\uAC00 \uBB34\uC758\uBBF8\uD568\nexport type AddEventListenerNonQueryOptions<TEvent extends Event = Event> = AddEventListenerBaseOptions<TEvent>;\n\n// \uC140\uB809\uD130 \uC885\uB958\uC5D0 \uB530\uB77C \uC635\uC158 \uD0C0\uC785\uC744 \uBD84\uAE30\nexport type AddEventListenerOptionsOf<S extends EventListenerSelector, TEvent extends Event = Event> =\n S extends string ? AddEventListenerQueryOptions<TEvent> : AddEventListenerNonQueryOptions<TEvent>;\n\nexport function addEventListener<TEvent extends Event = Event>(target: SpecialSelector, type: string, options?: AddEventListenerQueryOptions<TEvent>): MethodDecorator;\nexport function addEventListener<TEvent extends Event = Event>(selector: string, type: string, options?: AddEventListenerQueryOptions<TEvent>): MethodDecorator;\nexport function addEventListener<TEvent extends Event = Event>(selector: string, type: string[], options?: AddEventListenerQueryOptions<TEvent>): MethodDecorator;\nexport function addEventListener<TEvent extends Event = Event>(selector: EventListenerFnSelector, type: string, options?: AddEventListenerNonQueryOptions<TEvent>): MethodDecorator;\n/**\n * @addEventListener(type, options?) \u2014 \uC140\uB809\uD130 \uC0DD\uB7B5 \uC2DC $this(\uCEF4\uD3EC\uB10C\uD2B8 \uC790\uC2E0)\uB85C \uBC14\uC778\uB529\n */\nexport function addEventListener<TEvent extends Event = Event>(type: string, options?: AddEventListenerQueryOptions<TEvent>): MethodDecorator;\nexport function addEventListener<TEvent extends Event = Event>(type: string[], options?: AddEventListenerQueryOptions<TEvent>): MethodDecorator;\n/**\n * @addEventListener decorator to bind events to elements.\n */\nexport function addEventListener<TEvent extends Event = Event>(selectorOrType: EventListenerSelector | string | string[], typeOrOptions?: string | string[] | AddEventListenerQueryOptions<TEvent>, maybeOptions?: AddEventListenerQueryOptions<TEvent>): MethodDecorator {\n return (targetObj: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n let selector: EventListenerSelector;\n let types: string[];\n let opts: any = {};\n\n if (typeof typeOrOptions === 'string' || Array.isArray(typeOrOptions)) {\n // (selector, type|[types][, options]) form \u2014 \uAE30\uC874 \uD638\uD658\n selector = selectorOrType as EventListenerSelector;\n types = Array.isArray(typeOrOptions) ? typeOrOptions : [typeOrOptions];\n opts = maybeOptions ?? {};\n } else {\n // (type|[types][, options]) form \u2014 selector \uAE30\uBCF8\uAC12 $this\n selector = '$this';\n if (Array.isArray(selectorOrType)) types = selectorOrType;\n else types = [selectorOrType as string];\n opts = typeOrOptions ?? {};\n }\n\n const constructor = targetObj.constructor;\n\n let listeners = ReflectUtils.getMetadata<AddEventListenerMetadata<TEvent>[]>(ADD_EVENT_LISTENER_METADATA_KEY, constructor);\n if (!listeners) {\n listeners = [];\n ReflectUtils.defineMetadata(ADD_EVENT_LISTENER_METADATA_KEY, listeners, constructor);\n }\n\n for (const type of types) listeners.push({ propertyKey, selector, type, options: opts });\n };\n}\n\n\nexport function addEventListenerDelegateLight<TEvent extends Event = Event>(selector: string, type: string, options?: Omit<AddEventListenerQueryOptions<TEvent>, 'delegate'>): MethodDecorator {\n return addEventListener<TEvent>(selector, type, {...options??{}, root:'light', delegate: true});\n}\n\nexport function addEventListenerDelegateShadow<TEvent extends Event = Event>(selector: string, type: string, options?: Omit<AddEventListenerQueryOptions<TEvent>, 'delegate'>): MethodDecorator {\n return addEventListener<TEvent>(selector, type, {...options??{}, root:'shadow', delegate: true});\n}\nexport function addEventListenerDelegateAll<TEvent extends Event = Event>(selector: string, type: string, options?: Omit<AddEventListenerQueryOptions<TEvent>, 'delegate'>): MethodDecorator {\n return addEventListener<TEvent>(selector, type, {...options??{}, root:'all', delegate: true});\n}\nexport function addEventListenerDelegate<TEvent extends Event = Event>(selector: string, type: string, options?: Omit<AddEventListenerQueryOptions<TEvent>, 'delegate'>): MethodDecorator {\n return addEventListener<TEvent>(selector, type, {...options??{}, root:'auto', delegate: true});\n}\n\nexport function addEventListenerMutationLight<TEvent extends Event = Event>(selector: string, type: string, options?: Omit<AddEventListenerQueryOptions<TEvent>, 'delegate'>): MethodDecorator {\n return addEventListener<TEvent>(selector, type, {...options??{}, root:'light', delegate: 'mutation'});\n}\n\nexport function addEventListenerMutationShadow<TEvent extends Event = Event>(selector: string, type: string, options?: Omit<AddEventListenerQueryOptions<TEvent>, 'delegate'>): MethodDecorator {\n return addEventListener<TEvent>(selector, type, {...options??{}, root:'shadow', delegate: 'mutation'});\n}\n\nexport function addEventListenerMutationAll<TEvent extends Event = Event>(selector: string, type: string, options?: Omit<AddEventListenerQueryOptions<TEvent>, 'delegate'>): MethodDecorator {\n return addEventListener<TEvent>(selector, type, {...options??{}, root:'all', delegate: 'mutation'});\n}\n\nexport function addEventListenerMutation<TEvent extends Event = Event>(selector: string, type: string, options?: Omit<AddEventListenerQueryOptions<TEvent>, 'delegate'>): MethodDecorator {\n return addEventListener<TEvent>(selector, type, {...options??{}, root:'auto', delegate: 'mutation'});\n}\n\n// \u2500\u2500\u2500 root\uBCC4 \uC77C\uBC18 \uD5EC\uD37C (delegate \uC5C6\uC74C, \uBB38\uC790\uC5F4 \uC140\uB809\uD130 \uC804\uC6A9) \u2500\u2500\u2500\n\nexport function addEventListenerLight<TEvent extends Event = Event>(selector: string, type: string, options?: AddEventListenerQueryOptions<TEvent>): MethodDecorator {\n return addEventListener<TEvent>(selector, type, {...options??{}, root:'light'});\n}\n\nexport function addEventListenerShadow<TEvent extends Event = Event>(selector: string, type: string, options?: AddEventListenerQueryOptions<TEvent>): MethodDecorator {\n return addEventListener<TEvent>(selector, type, {...options??{}, root:'shadow'});\n}\n\nexport function addEventListenerAll<TEvent extends Event = Event>(selector: string, type: string, options?: AddEventListenerQueryOptions<TEvent>): MethodDecorator {\n return addEventListener<TEvent>(selector, type, {...options??{}, root:'all'});\n}\n\n/**\n * @addEventListenerThis decorator - simplified version of @addEventListener for $this selector\n */\nexport function addEventListenerThis<TEvent extends Event = Event>(type: string, options?: AddEventListenerQueryOptions<TEvent>): MethodDecorator {\n return addEventListener<TEvent>('$this', type, options);\n}\n\n/**\n * @addEventListenerAppHost decorator - simplified version of @addEventListener for $appHost selector\n */\nexport function addEventListenerAppHost<TEvent extends Event = Event>(type: string, options?: AddEventListenerQueryOptions<TEvent>): MethodDecorator {\n return addEventListener<TEvent>('$appHost', type, options);\n}\n\nexport function addEventListenerWindow<TEvent extends Event = Event>(type: string, options?: AddEventListenerQueryOptions<TEvent>): MethodDecorator {\n return addEventListener<TEvent>('$window', type, options);\n}\nexport function addEventListenerDocument<TEvent extends Event = Event>(type: string, options?: AddEventListenerQueryOptions<TEvent>): MethodDecorator {\n return addEventListener<TEvent>('$document', type, options);\n}\n\n// --- Aliases: event... ---\nexport const event = addEventListener;\nexport const eventDelegateLight = addEventListenerDelegateLight;\nexport const eventDelegateShadow = addEventListenerDelegateShadow;\nexport const eventDelegateAll = addEventListenerDelegateAll;\nexport const eventDelegate = addEventListenerDelegate;\nexport const eventMutationLight = addEventListenerMutationLight;\nexport const eventMutationShadow = addEventListenerMutationShadow;\nexport const eventMutationAll = addEventListenerMutationAll;\nexport const eventMutation = addEventListenerMutation;\nexport const eventLight = addEventListenerLight;\nexport const eventShadow = addEventListenerShadow;\nexport const eventAll = addEventListenerAll;\nexport const eventAppHost = addEventListenerAppHost;\nexport const eventWindow = addEventListenerWindow;\nexport const eventDocument = addEventListenerDocument;\nexport const eventThis = addEventListenerThis;\n\nexport const getAddEventListenerMetadata = (target: any): AddEventListenerMetadata<Event>[] | undefined => {\n const constructor = target instanceof Function ? target : target.constructor;\n return ReflectUtils.getMetadata(ADD_EVENT_LISTENER_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// EventListenerLifeCycler\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, MutationObserverSetEntry, OnConnectedResult } from '../types';\nimport { Subject } from '@dooboostore/core';\nimport { debounceTime, distinctUntilChanged, throttleTime } from '@dooboostore/core/message/operators';\nimport { SwcUtils } from '../utils/Utils';\n\nexport interface BoundListenerEntry {\n target: EventTarget;\n type: string;\n handler: EventListener;\n options: AddEventListenerOptions;\n onRemoves?: Array<{ fn: (target: EventTarget, optionValue: unknown) => void; opts: unknown }>;\n subscription?: { unsubscribe: () => void };\n meta?: AddEventListenerMetadata<Event>;\n}\n\nexport class EventListenerLifeCycler implements ElementDefineLifeCycler {\n /** \uC778\uC2A4\uD134\uC2A4\uBCC4 boundListeners \uC0C1\uD0DC (\uC2DC\uD074\uB7EC\uB294 elementDefine \uC2DC 1\uD68C \uC0DD\uC131\uB418\uC5B4 \uACF5\uC720\uB418\uBBC0\uB85C) */\n private readonly boundListenersMap = new WeakMap<Element, BoundListenerEntry[]>();\n /** \uC778\uC2A4\uD134\uC2A4\uBCC4 delegate:'mutation' \uBC14\uC778\uB529 \uCD94\uC801 WeakSet \u2014 MutationObserverLifeCycler \uC5D0\uC11C \uCC38\uC870 */\n private readonly eventBoundSetsMap = new WeakMap<Element, Map<AddEventListenerMetadata, WeakSet<Element>>>();\n\n // \u2500\u2500 \uC678\uBD80(MutationObserverLifeCycler)\uC5D0\uC11C \uC9C1\uC811 \uC0AC\uC6A9\uD558\uB294 \uACF5\uAC1C \uD5EC\uD37C \u2500\u2500\n\n /** \uC778\uC2A4\uD134\uC2A4\uBCC4 boundListeners \uB97C \uBC18\uD658\uD55C\uB2E4 (\uC5C6\uC73C\uBA74 \uC0DD\uC131). */\n getBoundListeners(inst: Element): BoundListenerEntry[] {\n let list = this.boundListenersMap.get(inst);\n if (!list) { list = []; this.boundListenersMap.set(inst, list); }\n return list;\n }\n\n /** \uC778\uC2A4\uD134\uC2A4\uBCC4 eventBoundSets \uB97C \uBC18\uD658\uD55C\uB2E4 (\uC5C6\uC73C\uBA74 \uC0DD\uC131). */\n getEventBoundSets(inst: Element): Map<AddEventListenerMetadata, WeakSet<Element>> {\n let map = this.eventBoundSetsMap.get(inst);\n if (!map) { map = new Map(); this.eventBoundSetsMap.set(inst, map); }\n return map;\n }\n\n /**\n * target \uC5D0 meta \uC774\uBCA4\uD2B8\uB97C \uC9C1\uC811 \uBC14\uC778\uB529\uD55C\uB2E4.\n * delegate:'mutation' \uCD08\uAE30/\uB3D9\uC801 \uBC14\uC778\uB529\uC5D0\uC11C \uD638\uCD9C\uB41C\uB2E4.\n */\n bindDirect(helperHostSet: HelperHostSet, target: EventTarget, meta: AddEventListenerMetadata): void {\n const inst = helperHostSet.$this;\n const currentWin = helperHostSet.$w;\n const { type, options } = meta;\n const opts = { capture: options.capture, once: options.once, passive: options.passive };\n\n const handler = async (event: Event) => {\n if (options.filter) {\n const helper = SwcUtils.getHelperAndHostSet(currentWin, target as HTMLElement);\n if (!options.filter(event, { currentThis: inst, helper })) return;\n }\n if (options.stopPropagation) event.stopPropagation();\n if (options.stopImmediatePropagation) event.stopImmediatePropagation();\n if (options.preventDefault) event.preventDefault();\n const currentHostSet = SwcUtils.getHostSet(inst);\n await inst[meta.propertyKey](event, { currentHostSet, $matchedElement: event.currentTarget }, { event, ...currentHostSet, $el: target, $root: target });\n };\n\n const eventSubject = new Subject<Event>();\n let eventStream: any = eventSubject;\n if (options.debounceTime && options.debounceTime > 0)\n eventStream = eventStream.pipe(debounceTime(options.debounceTime));\n if (options.throttleTime && options.throttleTime > 0)\n eventStream = eventStream.pipe(throttleTime(options.throttleTime));\n if (options.distinctUntilChanged !== undefined && options.distinctUntilChanged !== false) {\n eventStream = typeof options.distinctUntilChanged === 'function'\n ? eventStream.pipe(distinctUntilChanged(options.distinctUntilChanged))\n : eventStream.pipe(distinctUntilChanged());\n }\n\n const subscription = eventStream.subscribe({\n next: (e: Event) => handler(e).catch((err: any) => console.error('Event handler error:', err)),\n error: (err: any) => console.error('Event stream error:', err),\n });\n\n const wrappedHandler = (event: Event) => eventSubject.next(event);\n target.addEventListener(type, wrappedHandler, opts);\n\n const onRemoves: Array<{ fn: any; opts: any }> =\n options.removeListener ? [{ fn: options.removeListener, opts: options }] : [];\n this.getBoundListeners(inst).push({ target, type, handler: wrappedHandler, options: opts, subscription, onRemoves, meta });\n }\n\n /** target + meta \uC870\uD569 \uB9AC\uC2A4\uB108\uB97C \uC81C\uAC70\uD55C\uB2E4. MutationObserver \uCD94\uC801 \uC694\uC18C \uC81C\uAC70 \uC2DC \uD638\uCD9C. */\n unbindDirect(helperHostSet: HelperHostSet, target: EventTarget, meta: AddEventListenerMetadata): void {\n const inst = helperHostSet.$this;\n const list = this.getBoundListeners(inst);\n for (let i = list.length - 1; i >= 0; i--) {\n const l = list[i];\n if (l.target === target && l.type === meta.type && l.meta === meta) {\n try { l.target.removeEventListener(l.type, l.handler, l.options); l.subscription?.unsubscribe?.(); }\n catch (e) { console.error('[SWC] unbindDirect error:', e); }\n for (const r of l.onRemoves ?? []) {\n try { r.fn(l.target, r.opts); } catch (e) { console.error('[SWC] unbindDirect removeListener error:', e); }\n }\n list.splice(i, 1);\n }\n }\n }\n\n /**\n * \uBA54\uD0C0\uB370\uC774\uD130 \uBAA9\uB85D\uC744 delegate / mutationDelegate / nonDelegate \uB85C \uBD84\uB958\uD55C\uB2E4.\n * MutationObserverLifeCycler \uC5D0\uC11C mutationDelegate \uBAA9\uB85D\uC744 \uAEBC\uB0BC \uB54C \uC0AC\uC6A9\uD55C\uB2E4.\n */\n classifyListeners(metaList: AddEventListenerMetadata[]): {\n delegateListeners: AddEventListenerMetadata[];\n mutationDelegateListeners: AddEventListenerMetadata[];\n nonDelegateListeners: AddEventListenerMetadata[];\n } {\n const isSpecial = (sel: any) =>\n ['$window', '$document', '$host', '$appHost', '$firstHost', '$lastHost',\n '$firstAppHost', '$lastAppHost', '$hosts', '$appHosts', '$this', ''].includes(sel);\n\n const delegateListeners: AddEventListenerMetadata[] = [];\n const mutationDelegateListeners: AddEventListenerMetadata[] = [];\n const nonDelegateListeners: AddEventListenerMetadata[] = [];\n\n for (const meta of metaList) {\n const isStr = typeof meta.selector === 'string';\n const mode = meta.options.delegate;\n if (mode && isStr && !isSpecial(meta.selector)) {\n mode === 'mutation' ? mutationDelegateListeners.push(meta) : delegateListeners.push(meta);\n } else {\n nonDelegateListeners.push(meta);\n }\n }\n return { delegateListeners, mutationDelegateListeners, nonDelegateListeners };\n }\n\n // \u2500\u2500 ElementDefineLifeCycler \uAD6C\uD604 \u2500\u2500\n\n onConnected(helperHostSet: HelperHostSet): OnConnectedResult | void {\n const inst = helperHostSet.$this;\n const currentWin = helperHostSet.$w;\n\n this.boundListenersMap.delete(inst);\n this.eventBoundSetsMap.delete(inst);\n\n const allMeta = getAddEventListenerMetadata(inst) ?? [];\n const { delegateListeners, nonDelegateListeners, mutationDelegateListeners } = this.classifyListeners(allMeta);\n\n // \u2500\u2500 delegate \uB9AC\uC2A4\uB108: type+root \uD0A4\uB85C \uADF8\uB8F9\uD551 \u2192 unified handler \u2500\u2500\n const groups = new Map<string, AddEventListenerMetadata[]>();\n for (const meta of delegateListeners) {\n const key = `${meta.type}:${meta.options.root || 'auto'}`;\n if (!groups.has(key)) groups.set(key, []);\n groups.get(key)!.push(meta);\n }\n\n groups.forEach((metaList, key) => {\n const ci = key.indexOf(':');\n const type = key.slice(0, ci);\n const r = key.slice(ci + 1);\n const opts = { capture: metaList[0].options.capture, once: metaList[0].options.once, passive: metaList[0].options.passive };\n\n const roots: (HTMLElement | ShadowRoot)[] = [];\n if (r === 'auto') roots.push(inst.shadowRoot || inst);\n else if (r === 'light') roots.push(inst);\n else if (r === 'shadow' && inst.shadowRoot) roots.push(inst.shadowRoot);\n else if (r === 'all') { roots.push(inst); if (inst.shadowRoot) roots.push(inst.shadowRoot); }\n\n for (const br of roots) {\n const sorted = [...metaList].sort((a, b) => (b.options.stopPropagation ? 1 : 0) - (a.options.stopPropagation ? 1 : 0));\n const handler = async (event: Event) => {\n for (const m of sorted) {\n const matchedEl = (event.target as HTMLElement)?.closest(m.selector as string);\n console.log('[DBG][delegate] type=', event.type, '| evtTarget=', (event.target as any)?.tagName, '| sel=', m.selector, '| matchedEl=', matchedEl?.className || matchedEl?.tagName, '| brContains=', (br as any).contains?.(matchedEl), '| brTag=', (br as any).tagName || (br as any).constructor?.name);\n if (matchedEl && (br as any).contains(matchedEl)) {\n if (m.options.filter) {\n const helper = SwcUtils.getHelperAndHostSet(currentWin, matchedEl as HTMLElement);\n if (!m.options.filter(event, { currentThis: inst, helper })) continue;\n }\n if (m.options.stopPropagation) event.stopPropagation();\n if (m.options.stopImmediatePropagation) event.stopImmediatePropagation();\n if (m.options.preventDefault) event.preventDefault();\n const hs = SwcUtils.getHostSet(inst);\n await inst[m.propertyKey](event, { ...hs, $matchedElement: matchedEl }, { event, ...hs, $el: matchedEl, $root: br });\n if ((event as any).cancelBubble) break;\n }\n }\n };\n br.addEventListener(type, handler, opts);\n if (type === 'click') {\n console.log('[DBG][eventCycler] bound click on br=', (br as any).tagName || (br as any).constructor?.name, '| inst=', (inst as any).tagName || (inst as any).constructor?.name, '| isSame=', br === inst);\n }\n const onRemoves: Array<{ fn: any; opts: any }> = sorted.filter(m => m.options.removeListener).map(m => ({ fn: m.options.removeListener, opts: m.options }));\n this.getBoundListeners(inst).push({ target: br, type, handler, options: opts, onRemoves });\n }\n });\n\n // \u2500\u2500 non-delegate \uB9AC\uC2A4\uB108: \uB300\uC0C1 \uC694\uC18C \uC9C1\uC811 \uD0D0\uC0C9 \u2192 bindDirect \u2500\u2500\n for (const meta of nonDelegateListeners) {\n const { selector, options } = meta;\n const r = options.root || 'auto';\n const bindTargets: EventTarget[] = [];\n\n let resolvedSel: string | null = null;\n if (typeof selector === 'function') {\n const result = selector(inst, helperHostSet);\n if (typeof result === 'string') resolvedSel = result;\n else if (result instanceof currentWin.Element) bindTargets.push(result as EventTarget);\n else if (result instanceof currentWin.NodeList) bindTargets.push(...(Array.from(result) as EventTarget[]));\n else if (Array.isArray(result)) bindTargets.push(...(result as EventTarget[]));\n } else {\n resolvedSel = selector;\n }\n\n const applyRoot = (t: any) => {\n if (!t) return;\n if (r === 'auto') bindTargets.push(t.shadowRoot || t);\n else { if (r === 'light' || r === 'all') bindTargets.push(t); if ((r === 'shadow' || r === 'all') && t.shadowRoot) bindTargets.push(t.shadowRoot); }\n };\n\n if (resolvedSel) {\n if (resolvedSel === '$window') bindTargets.push(currentWin);\n else if (resolvedSel === '$document') bindTargets.push(currentWin.document);\n else if (resolvedSel === '$host') applyRoot(helperHostSet.$host);\n else if (resolvedSel === '$parentHost') applyRoot(helperHostSet.$parentHost);\n else if (resolvedSel === '$appHost') applyRoot(helperHostSet.$appHost);\n else if (resolvedSel === '$firstHost') applyRoot(helperHostSet.$firstHost);\n else if (resolvedSel === '$lastHost') applyRoot(helperHostSet.$lastHost);\n else if (resolvedSel === '$firstAppHost') applyRoot(helperHostSet.$firstAppHost);\n else if (resolvedSel === '$lastAppHost') applyRoot(helperHostSet.$lastAppHost);\n else if (resolvedSel === '$hosts') helperHostSet.$hosts.forEach(applyRoot);\n else if (resolvedSel === '$appHosts') helperHostSet.$appHosts.forEach(applyRoot);\n else if (resolvedSel === '$this' || !resolvedSel) applyRoot(inst);\n else {\n const searchRoots: (HTMLElement | ShadowRoot)[] = [];\n if (r === 'auto') searchRoots.push(inst.shadowRoot || inst);\n else if (r === 'light') searchRoots.push(inst);\n else if (r === 'shadow' && inst.shadowRoot) searchRoots.push(inst.shadowRoot);\n else if (r === 'all') { searchRoots.push(inst); if (inst.shadowRoot) searchRoots.push(inst.shadowRoot); }\n for (const sr of searchRoots) sr.querySelectorAll(resolvedSel).forEach(el => bindTargets.push(el));\n }\n }\n\n for (const t of bindTargets) this.bindDirect(helperHostSet, t, meta);\n }\n\n // \u2500\u2500 delegate:'mutation' \uB9AC\uC2A4\uB108: MutationObserver \uB85C \uCD94\uAC00/\uC81C\uAC70\uB41C \uC694\uC18C\uB97C \uCD94\uC801\uD574 \uC9C1\uC811 \uBC14\uC778\uB529/\uD574\uC81C \u2500\u2500\n // \uC774\uBCA4\uD2B8 \uB9AC\uC2A4\uB108\uC758 \uCC45\uC784\uC774\uBBC0\uB85C EventListenerLifeCycler \uAC00 \uC9C1\uC811 \uCC98\uB9AC\uD558\uACE0,\n // mutationObserverSet \uC744 \uBC18\uD658\uD574 elementDefine \uC774 \uD558\uB098\uC758 MutationObserver \uB85C \uC0DD\uC131\uD558\uAC8C \uD55C\uB2E4.\n if (mutationDelegateListeners.length > 0) {\n const shadowEventDelegates = mutationDelegateListeners.filter(m => {\n const r = m.options.root || 'auto';\n return inst.shadowRoot && (r === 'shadow' || r === 'all' || r === 'auto');\n });\n const lightEventDelegates = mutationDelegateListeners.filter(m => {\n const r = m.options.root || 'auto';\n return r === 'light' || r === 'all' || (!inst.shadowRoot && r === 'auto');\n });\n\n const buildMutationEntry = (\n root: HTMLElement | ShadowRoot,\n eventDelegates: AddEventListenerMetadata[],\n ): MutationObserverSetEntry | null => {\n if (eventDelegates.length === 0) return null;\n const boundSets = this.getEventBoundSets(inst);\n\n const callback = (mutations: MutationRecord[], obs: MutationObserver) => {\n for (const m of eventDelegates) {\n let boundSet = boundSets.get(m);\n if (!boundSet) { boundSet = new WeakSet<Element>(); boundSets.set(m, boundSet); }\n\n const isThis = m.selector === '$this' || m.selector === '';\n const matchesSel = (n: any) => {\n if (!n || n.nodeType !== 1) return false;\n if (isThis) return true;\n return typeof m.selector === 'string' && (n as HTMLElement).matches?.(m.selector);\n };\n const bindEl = (el: Element) => { if (!boundSet!.has(el)) { this.bindDirect(helperHostSet, el, m); boundSet!.add(el); } };\n const unbindEl = (el: Element) => { if (boundSet!.has(el)) { this.unbindDirect(helperHostSet, el, m); boundSet!.delete(el); } };\n\n for (const mut of mutations) {\n Array.from(mut.addedNodes || []).forEach(n => { if (n.nodeType !== 1) return; if (matchesSel(n)) bindEl(n as Element); else if (!isThis && typeof m.selector === 'string') (n as Element).querySelectorAll?.(m.selector).forEach(bindEl); });\n Array.from(mut.removedNodes || []).forEach(n => { if (n.nodeType !== 1) return; const el = n as Element; if (matchesSel(el)) unbindEl(el); else if (!isThis && typeof m.selector === 'string') el.querySelectorAll?.(m.selector).forEach(unbindEl); });\n }\n }\n };\n\n // delegate:'mutation' \uCD08\uAE30 \uBC14\uC778\uB529 (connected \uC2DC \uC774\uBBF8 \uC874\uC7AC\uD558\uB294 \uC694\uC18C)\n for (const m of eventDelegates) {\n let boundSet = boundSets.get(m);\n if (!boundSet) { boundSet = new WeakSet<Element>(); boundSets.set(m, boundSet); }\n if (typeof m.selector !== 'string') continue;\n if (m.selector === '$this' || m.selector === '') {\n this.bindDirect(helperHostSet, root as EventTarget, m);\n boundSet.add(root as Element);\n } else {\n root.querySelectorAll(m.selector).forEach(el => {\n if (!boundSet!.has(el)) { this.bindDirect(helperHostSet, el, m); boundSet!.add(el); }\n });\n }\n }\n\n return { target: root, options: { childList: true, subtree: true }, callback };\n };\n\n const shadowEntry = inst.shadowRoot ? buildMutationEntry(inst.shadowRoot, shadowEventDelegates) : null;\n const lightEntry = buildMutationEntry(inst as any, lightEventDelegates);\n const mutationObserverSet: MutationObserverSetEntry[] = [shadowEntry, lightEntry].filter(Boolean) as MutationObserverSetEntry[];\n if (mutationObserverSet.length > 0) return { mutationObserverSet };\n }\n\n return undefined;\n }\n\n onDisconnected(helperHostSet: HelperHostSet): void {\n const inst = helperHostSet.$this;\n const list = this.boundListenersMap.get(inst) ?? [];\n for (const l of list) {\n try { l.target.removeEventListener(l.type, l.handler, l.options); l.subscription?.unsubscribe?.(); }\n catch (e) { console.error('[SWC] EventListenerLifeCycler cleanup error:', e); }\n for (const r of l.onRemoves ?? []) {\n try { r.fn(l.target, r.opts); } catch (e) { console.error('[SWC] removeListener error:', e); }\n }\n }\n this.boundListenersMap.delete(inst);\n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IAAI,CAAC;AAAG,yBAAU,IAAI,EAAE;AAAA,cAAG;AAAA,YACtF,CAAC;AAAA,UACH;AAAA,QACF;AAEA,eAAO,EAAE,QAAQ,MAAM,SAAS,EAAE,WAAW,MAAM,SAAS,KAAK,GAAG,SAAS;AAAA,MAC/E;AAEA,YAAM,cAAc,KAAK,aAAa,mBAAmB,KAAK,YAAY,oBAAoB,IAAI;AAClG,YAAM,aAAa,mBAAmB,MAAa,mBAAmB;AACtE,YAAM,sBAAkD,CAAC,aAAa,UAAU,EAAE,OAAO,OAAO;AAChG,UAAI,oBAAoB,SAAS,EAAG,QAAO,EAAE,oBAAoB;AAAA,IACnE;AAEA,WAAO;AAAA,EACT;AAAA,EAEA,eAAe,eAAoC;AACjD,UAAM,OAAO,cAAc;AAC3B,UAAM,OAAO,KAAK,kBAAkB,IAAI,IAAI,KAAK,CAAC;AAClD,eAAW,KAAK,MAAM;AACpB,UAAI;AAAE,UAAE,OAAO,oBAAoB,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO;AAAG,UAAE,cAAc,cAAc;AAAA,MAAG,SAC5F,GAAG;AAAE,gBAAQ,MAAM,gDAAgD,CAAC;AAAA,MAAG;AAC9E,iBAAW,KAAK,EAAE,aAAa,CAAC,GAAG;AACjC,YAAI;AAAE,YAAE,GAAG,EAAE,QAAQ,EAAE,IAAI;AAAA,QAAG,SAAS,GAAG;AAAE,kBAAQ,MAAM,+BAA+B,CAAC;AAAA,QAAG;AAAA,MAC/F;AAAA,IACF;AACA,SAAK,kBAAkB,OAAO,IAAI;AAClC,SAAK,kBAAkB,OAAO,IAAI;AAAA,EACpC;AACF;",
|
|
6
|
+
"names": ["event"]
|
|
7
7
|
}
|
|
@@ -217,6 +217,9 @@ function attribute(selectorOrAttributeOrTarget, attributeNameOrOptions, optionsO
|
|
|
217
217
|
return applyAttribute("$this", void 0, selectorOrAttributeOrTarget);
|
|
218
218
|
}
|
|
219
219
|
function setAttribute(selectorOrAttributeOrOptions, attributeNameOrOptions, optionsOrUndefined) {
|
|
220
|
+
if (typeof selectorOrAttributeOrOptions === "function") {
|
|
221
|
+
return applyAttribute(selectorOrAttributeOrOptions, attributeNameOrOptions, optionsOrUndefined);
|
|
222
|
+
}
|
|
220
223
|
if (typeof selectorOrAttributeOrOptions === "string") {
|
|
221
224
|
const isSelector = isCssSelector(selectorOrAttributeOrOptions);
|
|
222
225
|
if (isSelector) {
|
|
@@ -239,10 +242,32 @@ const findAllAttributeApplyMetadata = (target) => {
|
|
|
239
242
|
});
|
|
240
243
|
return result;
|
|
241
244
|
};
|
|
245
|
+
const attr = applyAttribute;
|
|
246
|
+
function attrThis(targetAttributeName, options) {
|
|
247
|
+
return applyAttribute("$this", targetAttributeName, options);
|
|
248
|
+
}
|
|
249
|
+
function attrAppHost(targetAttributeName, options) {
|
|
250
|
+
return applyAttribute("$appHost", targetAttributeName, options);
|
|
251
|
+
}
|
|
252
|
+
function attrLight(selector, targetAttributeName, options) {
|
|
253
|
+
return applyAttribute(selector, targetAttributeName, { ...options ?? {}, root: "light" });
|
|
254
|
+
}
|
|
255
|
+
function attrShadow(selector, targetAttributeName, options) {
|
|
256
|
+
return applyAttribute(selector, targetAttributeName, { ...options ?? {}, root: "shadow" });
|
|
257
|
+
}
|
|
258
|
+
function attrAll(selector, targetAttributeName, options) {
|
|
259
|
+
return applyAttribute(selector, targetAttributeName, { ...options ?? {}, root: "all" });
|
|
260
|
+
}
|
|
242
261
|
var applyAttribute_default = applyAttribute;
|
|
243
262
|
export {
|
|
244
263
|
ATTRIBUTE_METADATA_KEY,
|
|
245
264
|
applyAttribute,
|
|
265
|
+
attr,
|
|
266
|
+
attrAll,
|
|
267
|
+
attrAppHost,
|
|
268
|
+
attrLight,
|
|
269
|
+
attrShadow,
|
|
270
|
+
attrThis,
|
|
246
271
|
attribute,
|
|
247
272
|
convertValue,
|
|
248
273
|
applyAttribute_default as default,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/decorators/applyAttribute.ts"],
|
|
4
|
-
"sourcesContent": ["import {ReflectUtils, FunctionUtils, ActionExpression} from '@dooboostore/core';\nimport {ensureInit, getElementConfig} from './elementDefine';\nimport {SwcUtils} from '../utils/Utils';\nimport {SwcQueryOptions, HelperHostSet} from '../types';\nimport {ConvertUtils} from '@dooboostore/core-web';\n\n// ============================================\n// Types & Interfaces\n// ============================================\n\nexport interface AttributeOptions extends SwcQueryOptions {\n name?: string;\n type?: typeof Number | typeof Boolean | typeof String;\n filter?: (target: HTMLElement, value: any, meta: { currentThis: any, helper: HelperHostSet }) => boolean;\n /**\n * Custom key to extract value from return object.\n * If not provided, uses ATTRIBUTE_METADATA_KEY by default.\n * Useful when multiple @setAttribute decorators are on the same method.\n * \n * Example:\n * @setAttribute('selector1', { valueKey: 'attr1' })\n * @setAttribute('selector2', { valueKey: 'attr2' })\n * myMethod() {\n * return {\n * attr1: 'value1',\n * attr2: 'value2'\n * };\n * }\n * \n * Or with symbols:\n * @setAttribute('selector1', { valueKey: Symbol.for('attr1') })\n * @setAttribute('selector2', { valueKey: Symbol.for('attr2') })\n * myMethod() {\n * return {\n * [Symbol.for('attr1')]: 'value1',\n * [Symbol.for('attr2')]: 'value2'\n * };\n * }\n */\n valueKey?: symbol | string;\n}\n\nexport type AttributeSelector = string | ((currentThis: any, helper: HelperHostSet) => NodeList | Element | Element[] | null);\n\nexport interface AttributeMetadata {\n propertyKey: string | symbol;\n selector: AttributeSelector;\n targetAttributeName: string;\n options: AttributeOptions;\n type: 'property' | 'method';\n}\n\nexport const ATTRIBUTE_METADATA_KEY = Symbol.for('simple-web-component:attribute');\n\n// ============================================\n// Utilities\n// ============================================\n\n/**\n * Determine if a string is a CSS selector or an attribute name\n * \n * CSS selectors typically:\n * - Start with: #, ., [, :, >, +, ~\n * - Contain special chars: >, +, ~, :, [, ]\n * - Are special keywords: $this, $host, $parentHost, etc.\n * \n * Attribute names are typically:\n * - kebab-case (lowercase with hyphens)\n * - No special selector syntax\n * \n * @param str - String to check\n * @returns true if it's a CSS selector, false if it's an attribute name\n */\nconst isCssSelector = (str: string): boolean => {\n if (!str) return false;\n \n // Special keywords\n if (str.startsWith('$')) return true;\n \n // CSS selector syntax\n if (/^[#.\\[\\:>+~]/.test(str)) return true;\n \n // Contains CSS combinator or pseudo-selector syntax\n if (/[>+~:\\[\\]]/.test(str)) return true;\n \n return false;\n};\n\nconst convertValue = (val: string | null, type: any): any => {\n if (val === null || val === undefined) return val;\n if (type === Number) return Number(val);\n if (type === Boolean) return val === 'false' || val === '0' ? false : true;\n return val;\n};\n\nexport {convertValue};\n\nexport const getAttributeValue = (inst: any, attrName: string, options?: AttributeOptions & { selector?: AttributeSelector }): any => {\n const conf = getElementConfig(inst);\n const currentWin = inst._resolveWindow?.(conf) || ((typeof window !== 'undefined' ? window : undefined) as any);\n\n // If selector is not provided, use inst itself\n const targets = options?.selector ? resolveAttributeTargets(inst, options.selector, options) : [inst];\n\n const primaryTarget = targets[0];\n\n if (primaryTarget && typeof (primaryTarget as any).hasAttribute === 'function' && (primaryTarget as any).hasAttribute(attrName)) {\n let domVal = (primaryTarget as any).getAttribute(attrName);\n\n // \uD45C\uD604\uC2DD \uCCB4\uD06C\n const ae = new ActionExpression(domVal);\n const expr = ae.getFirstExpression('callReturn');\n if (expr) {\n try {\n const result = FunctionUtils.executeReturn({\n script: ConvertUtils.decodeHtmlEntity(expr.script, currentWin.document),\n context: inst,\n args: SwcUtils.getHelperAndHostSet(currentWin, inst)\n });\n return convertValue(result, options?.type);\n } catch (err) {\n console.error(`[SWC] Failed to execute directive {{= ${expr.script} }}:`, err);\n return convertValue(domVal, options?.type);\n }\n }\n\n return convertValue(domVal, options?.type);\n }\n\n // If no target found, return null\n return null;\n};\n\n/**\n * Resolve target elements based on selector and options\n * Handles special selectors ($this, $host, etc.), CSS selectors, and function-based selectors\n * Returns HTMLElement[] for attribute operations\n */\nexport const resolveAttributeTargets = (inst: any, selector: AttributeSelector, options: AttributeOptions): HTMLElement[] => {\n const conf = getElementConfig(inst);\n const currentWin = conf.window;\n const r = options.root || 'auto';\n const results: HTMLElement[] = [];\n\n // Resolve selector if it's a function\n let resolvedSelector: string | Element | NodeList | Element[] | null = selector as any;\n if (typeof selector === 'function') {\n const hostSet = SwcUtils.getHelperAndHostSet(currentWin, inst);\n resolvedSelector = selector(inst, hostSet);\n }\n\n // If selector function returned elements directly, use them\n if (resolvedSelector instanceof currentWin.Element) {\n results.push(resolvedSelector as HTMLElement);\n return results;\n }\n if (resolvedSelector instanceof currentWin.NodeList) {\n results.push(...(Array.from(resolvedSelector) as HTMLElement[]));\n return results;\n }\n if (Array.isArray(resolvedSelector)) {\n results.push(...(resolvedSelector as HTMLElement[]));\n return results;\n }\n if (resolvedSelector === null) {\n return results;\n }\n\n // Handle string selector\n const stringSelector = resolvedSelector as string;\n\n const applyRoot = (target: any) => {\n if (!target) return;\n if (r === 'auto') {\n results.push(target);\n } else {\n if (r === 'light' || r === 'all') results.push(target);\n if ((r === 'shadow' || r === 'all') && target.shadowRoot) results.push(target.shadowRoot);\n }\n };\n\n if (stringSelector === '$this' || !stringSelector) {\n applyRoot(inst);\n } else {\n const hostSet = SwcUtils.getHostSet(inst);\n if (stringSelector === '$host') applyRoot(hostSet.$host);\n else if (stringSelector === '$parentHost') applyRoot(hostSet.$parentHost);\n else if (stringSelector === '$appHost') applyRoot(hostSet.$appHost as any);\n else if (stringSelector === '$firstHost') applyRoot(hostSet.$firstHost);\n else if (stringSelector === '$lastHost') applyRoot(hostSet.$lastHost);\n else if (stringSelector === '$firstAppHost') applyRoot(hostSet.$firstAppHost as any);\n else if (stringSelector === '$lastAppHost') applyRoot(hostSet.$lastAppHost as any);\n else if (stringSelector === '$hosts') hostSet.$hosts.forEach(applyRoot);\n else if (stringSelector === '$appHosts') hostSet.$appHosts.forEach(applyRoot);\n else {\n if (r === 'shadow') {\n const found = inst.shadowRoot?.querySelectorAll(stringSelector);\n if (found) results.push(...found);\n } else if (r === 'light') {\n const found = inst.querySelectorAll(stringSelector);\n if (found) results.push(...found);\n } else if (r === 'all') {\n const sMatch = inst.shadowRoot?.querySelectorAll(stringSelector);\n const lMatch = inst.querySelectorAll(stringSelector);\n if (sMatch) results.push(...sMatch);\n if (lMatch) results.push(...lMatch);\n } else {\n const found = (inst.shadowRoot || inst).querySelectorAll(stringSelector);\n if (found) results.push(...found);\n }\n }\n }\n return results;\n};\n\n/**\n * @applyAttribute decorator - set/get element attributes\n *\n * Usage:\n * - @applyAttribute('selector', 'attrName') - Set attribute with explicit name\n * - @applyAttribute('selector') - Use property name as attribute name\n * - @applyAttribute('selector', { name: 'attrName' }) - Set attribute via options\n * - @applyAttribute((this, helper) => 'selector', 'attrName') - Function-based selector\n * - Return null to remove attribute\n */\nexport function applyAttribute(selector: AttributeSelector, targetAttributeName: string, options?: AttributeOptions): MethodDecorator & PropertyDecorator;\nexport function applyAttribute(selector: AttributeSelector, options?: AttributeOptions): MethodDecorator & PropertyDecorator;\nexport function applyAttribute(selector: AttributeSelector, targetAttributeNameOrOptions?: string | AttributeOptions, options?: AttributeOptions): MethodDecorator & PropertyDecorator {\n return (target: Object, propertyKey: string | symbol, descriptor?: PropertyDescriptor) => {\n // ensureInit(target as any);\n\n const constructor = target.constructor;\n const designType = (Reflect as any).getMetadata('design:type', target, propertyKey);\n const metaType: 'property' | 'method' = descriptor && typeof descriptor.value === 'function' ? 'method' : 'property';\n\n // Parse arguments\n let finalOptions: AttributeOptions = {};\n let targetAttributeName: string;\n\n if (typeof targetAttributeNameOrOptions === 'string') {\n // applyAttribute('selector', 'attrName', options?)\n targetAttributeName = targetAttributeNameOrOptions;\n finalOptions = options || {};\n } else if (targetAttributeNameOrOptions) {\n // applyAttribute('selector', options)\n finalOptions = targetAttributeNameOrOptions;\n targetAttributeName = finalOptions.name || String(propertyKey);\n } else {\n // applyAttribute('selector')\n targetAttributeName = String(propertyKey);\n }\n\n // Store metadata\n let metaList = ReflectUtils.getOwnMetadata(ATTRIBUTE_METADATA_KEY, constructor) as AttributeMetadata[];\n if (!metaList) {\n metaList = [];\n ReflectUtils.defineMetadata(ATTRIBUTE_METADATA_KEY, metaList, constructor);\n }\n metaList.push({\n propertyKey,\n selector: selector as AttributeSelector,\n targetAttributeName,\n options: finalOptions,\n type: metaType\n });\n\n // Helper: Apply resolved value to targets\n const applyValueToTargets = (inst: any, resolvedValue: any) => {\n const conf = getElementConfig(inst);\n const currentWin = conf.window;\n const targetEls = resolveAttributeTargets(inst, selector, finalOptions);\n const hostSet = SwcUtils.getHelperAndHostSet(currentWin, inst);\n\n targetEls.forEach(targetEl => {\n // Apply filter if provided\n if (finalOptions.filter && !finalOptions.filter(targetEl, resolvedValue, {currentThis: inst, helper: hostSet})) {\n return;\n }\n\n if (resolvedValue === null) {\n // Remove attribute if value is null\n targetEl.removeAttribute(targetAttributeName);\n } else if (resolvedValue !== undefined) {\n // Set attribute\n targetEl.setAttribute(targetAttributeName, resolvedValue === true ? '' : String(resolvedValue));\n }\n });\n\n return resolvedValue;\n };\n\n // Method decorator: wrap method to apply its return value to attributes\n if (descriptor && typeof descriptor.value === 'function') {\n const original = descriptor.value;\n descriptor.value = function (...args: any[]) {\n ensureInit(this);\n const res = (original as any).apply(this, args);\n\n /**\n * Extract value for this decorator from method return value\n * \n * If return value is an object with this decorator's key,\n * use that value. Otherwise use the entire return value.\n * \n * Uses valueKey from options if provided, otherwise uses ATTRIBUTE_METADATA_KEY.\n * \n * Example:\n * @setAttribute('selector1', { valueKey: 'attr1' })\n * @setAttribute('selector2', { valueKey: 'attr2' })\n * myMethod() {\n * return {\n * attr1: 'attribute-value1',\n * attr2: 'attribute-value2'\n * };\n * }\n * \n * First decorator will use 'attribute-value1', second will use 'attribute-value2'\n */\n const extractValue = (v: any) => {\n const keyToUse = finalOptions.valueKey ?? ATTRIBUTE_METADATA_KEY;\n if (v && typeof v === 'object' && keyToUse in v) {\n return v[keyToUse];\n }\n return v;\n };\n\n if (res instanceof Promise) {\n return res.then((v: any) => {\n const extracted = extractValue(v);\n applyValueToTargets(this, extracted);\n return v;\n });\n } else {\n const extracted = extractValue(res);\n applyValueToTargets(this, extracted);\n return res;\n }\n };\n return;\n }\n\n // Property decorator: define getter/setter to proxy to element attributes\n Object.defineProperty(target, propertyKey, {\n configurable: true,\n enumerable: true,\n get(this: any) {\n ensureInit(this);\n const mergedOptions = {...finalOptions, selector, type: finalOptions.type || designType};\n return getAttributeValue(this, targetAttributeName, mergedOptions);\n },\n set(this: any, value: any) {\n ensureInit(this);\n\n if (value instanceof Promise) {\n value.then((v: any) => applyValueToTargets(this, v)).catch(() => { /* swallow */\n });\n } else {\n applyValueToTargets(this, value);\n }\n }\n });\n };\n}\n\n// ============================================\n// Convenience Aliases\n// ============================================\n\n/**\n * @attribute - Field decorator for binding element attributes (read/write)\n * \n * Intelligently distinguishes between attribute names and CSS selectors:\n * \n * Usage patterns:\n * - @attribute('product-id') - Attribute name on $this (auto-detected)\n * - @attribute('#user', 'product-id') - Attribute name on selector\n * - @attribute('product-id', options) - Attribute name on $this with options\n * - @attribute('#user', 'product-id', options) - Attribute name on selector with options\n * - @attribute((this, helper) => 'selector', 'product-id') - Function-based selector\n * - @attribute - Bare decorator (uses property name as attribute on $this)\n * \n * Note: This decorator is for FIELDS ONLY. For methods, use @setAttribute.\n */\nexport function attribute(target: Object, propertyKey: string | symbol): void;\nexport function attribute(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;\nexport function attribute(attributeName: string, options?: AttributeOptions): PropertyDecorator;\nexport function attribute(selector: AttributeSelector, attributeName: string, options?: AttributeOptions): PropertyDecorator;\nexport function attribute(selectorOrAttributeOrTarget?: AttributeSelector | Object, attributeNameOrOptions?: any, optionsOrDescriptor?: any): any {\n // Bare decorator: @attribute\n if (optionsOrDescriptor !== undefined && (typeof attributeNameOrOptions === 'string' || typeof attributeNameOrOptions === 'symbol')) {\n return applyAttribute('$this', undefined as any, {})(selectorOrAttributeOrTarget as Object, attributeNameOrOptions, optionsOrDescriptor as PropertyDescriptor);\n }\n \n // With string as first parameter\n if (typeof selectorOrAttributeOrTarget === 'string') {\n // Check if first parameter is a CSS selector or attribute name\n const isSelector = isCssSelector(selectorOrAttributeOrTarget);\n \n if (isSelector) {\n // First param is a selector: @attribute('#user', 'product-id', options?)\n return applyAttribute(selectorOrAttributeOrTarget, attributeNameOrOptions as any, optionsOrDescriptor as AttributeOptions);\n } else {\n // First param is an attribute name: @attribute('product-id', options?)\n // Treat as attribute name on $this\n const options = (typeof attributeNameOrOptions === 'object' && attributeNameOrOptions !== null) \n ? attributeNameOrOptions \n : {};\n return applyAttribute('$this', selectorOrAttributeOrTarget, options);\n }\n }\n \n // Without selector (defaults to $this with options)\n return applyAttribute('$this', undefined as any, selectorOrAttributeOrTarget as AttributeOptions);\n}\n\n/**\n * @setAttribute - Method decorator for setting element attributes from method return value\n * \n * Intelligently distinguishes between attribute names and CSS selectors:\n * \n * Usage patterns:\n * - @setAttribute('data-id') - Attribute name on $this (auto-detected)\n * - @setAttribute('#user', 'data-id') - Attribute name on selector\n * - @setAttribute('data-id', options) - Attribute name on $this with options\n * - @setAttribute('#user', 'data-id', options) - Attribute name on selector with options\n * - @setAttribute((this, helper) => 'selector', 'data-id') - Function-based selector\n * - @setAttribute - Bare decorator (uses method name as attribute on $this)\n * \n * Note: This decorator is for METHODS ONLY. For fields, use @attribute.\n * \n * Example:\n * @setAttribute('data-status')\n * updateStatus() {\n * return 'active';\n * }\n */\nexport function setAttribute(selector: AttributeSelector, attributeName: string, options?: AttributeOptions): MethodDecorator;\nexport function setAttribute(attributeName: string, options?: AttributeOptions): MethodDecorator;\nexport function setAttribute(selectorOrAttributeOrOptions?: AttributeSelector | AttributeOptions, attributeNameOrOptions?: any, optionsOrUndefined?: AttributeOptions): MethodDecorator {\n // With string as first parameter\n if (typeof selectorOrAttributeOrOptions === 'string') {\n // Check if first parameter is a CSS selector or attribute name\n const isSelector = isCssSelector(selectorOrAttributeOrOptions);\n \n if (isSelector) {\n // First param is a selector: @setAttribute('#user', 'data-id', options?)\n return applyAttribute(selectorOrAttributeOrOptions, attributeNameOrOptions as any, optionsOrUndefined as AttributeOptions) as MethodDecorator;\n } else {\n // First param is an attribute name: @setAttribute('data-id', options?)\n // Treat as attribute name on $this\n const options = (typeof attributeNameOrOptions === 'object' && attributeNameOrOptions !== null) \n ? attributeNameOrOptions \n : {};\n return applyAttribute('$this', selectorOrAttributeOrOptions, options) as MethodDecorator;\n }\n }\n \n // Without selector (defaults to $this with options)\n return applyAttribute('$this', undefined as any, selectorOrAttributeOrOptions as AttributeOptions) as MethodDecorator;\n}\n\n// ============================================\n// Metadata Helpers\n// ============================================\n\nexport const findAllAttributeMetadata = (target: any): AttributeMetadata[] => {\n const actualTarget = target instanceof Function ? target : target.constructor;\n return ReflectUtils.findAllMetadata<AttributeMetadata[]>(ATTRIBUTE_METADATA_KEY, actualTarget).flat();\n};\n\n// Backward compatibility alias\nexport const findAllAttributeApplyMetadata = (target: any): Map<string | symbol, AttributeMetadata> => {\n const result = new Map<string | symbol, AttributeMetadata>();\n findAllAttributeMetadata(target).forEach(meta => {\n result.set(meta.propertyKey, meta);\n });\n return result;\n};\n\n\nexport default applyAttribute;\n"],
|
|
5
|
-
"mappings": "AAAA,SAAQ,cAAc,eAAe,wBAAuB;AAC5D,SAAQ,YAAY,wBAAuB;AAC3C,SAAQ,gBAAe;AAEvB,SAAQ,oBAAmB;
|
|
4
|
+
"sourcesContent": ["import {ReflectUtils, FunctionUtils, ActionExpression} from '@dooboostore/core';\nimport {ensureInit, getElementConfig} from './elementDefine';\nimport {SwcUtils} from '../utils/Utils';\nimport {SwcQueryOptions, HelperHostSet, SwcFnSelector, SwcSelector} from '../types';\nimport {ConvertUtils} from '@dooboostore/core-web';\n\n// ============================================\n// Types & Interfaces\n// ============================================\n\n// \uACF5\uD1B5 \uC635\uC158 \u2014 root \uC5C6\uC74C\nexport interface AttributeBaseOptions {\n name?: string;\n type?: typeof Number | typeof Boolean | typeof String;\n filter?: (target: HTMLElement, value: any, meta: { currentThis: any, helper: HelperHostSet }) => boolean;\n valueKey?: symbol | string;\n}\n\n// \uBB38\uC790\uC5F4 \uC140\uB809\uD130 \uC804\uC6A9 \u2014 root \uD5C8\uC6A9 (\uCEF4\uD3EC\uB10C\uD2B8 DOM \uD2B8\uB9AC \uC548\uC5D0\uC11C \uD0D0\uC0C9)\nexport type AttributeQueryOptions = AttributeBaseOptions & SwcQueryOptions;\n// \uD568\uC218 \uC140\uB809\uD130 \uC804\uC6A9 \u2014 root \uAE08\uC9C0 (\uC774\uBBF8 \uC694\uC18C\uB97C \uC9C1\uC811 \uBC18\uD658)\nexport type AttributeNonQueryOptions = AttributeBaseOptions;\n// \uB0B4\uBD80 \uC800\uC7A5/\uD574\uC11D\uC6A9 \u2014 root optional\uC774\uB77C \uB450 \uC885\uB958 \uBAA8\uB450 \uC800\uC7A5 \uAC00\uB2A5\nexport type AttributeOptions = AttributeQueryOptions;\n\nexport type AttributeFnSelector = SwcFnSelector;\nexport type AttributeSelector = SwcSelector;\n\n// \uC140\uB809\uD130 \uC885\uB958\uC5D0 \uB530\uB77C \uC635\uC158 \uD0C0\uC785 \uBD84\uAE30\nexport type AttributeOptionsOf<S extends AttributeSelector> = S extends string ? AttributeQueryOptions : AttributeNonQueryOptions;\n\nexport interface AttributeMetadata {\n propertyKey: string | symbol;\n selector: AttributeSelector;\n targetAttributeName: string;\n options: AttributeOptions;\n type: 'property' | 'method';\n}\n\nexport const ATTRIBUTE_METADATA_KEY = Symbol.for('simple-web-component:attribute');\n\n// ============================================\n// Utilities\n// ============================================\n\n/**\n * Determine if a string is a CSS selector or an attribute name\n * \n * CSS selectors typically:\n * - Start with: #, ., [, :, >, +, ~\n * - Contain special chars: >, +, ~, :, [, ]\n * - Are special keywords: $this, $host, $parentHost, etc.\n * \n * Attribute names are typically:\n * - kebab-case (lowercase with hyphens)\n * - No special selector syntax\n * \n * @param str - String to check\n * @returns true if it's a CSS selector, false if it's an attribute name\n */\nconst isCssSelector = (str: string): boolean => {\n if (!str) return false;\n \n // Special keywords\n if (str.startsWith('$')) return true;\n \n // CSS selector syntax\n if (/^[#.\\[\\:>+~]/.test(str)) return true;\n \n // Contains CSS combinator or pseudo-selector syntax\n if (/[>+~:\\[\\]]/.test(str)) return true;\n \n return false;\n};\n\nconst convertValue = (val: string | null, type: any): any => {\n if (val === null || val === undefined) return val;\n if (type === Number) return Number(val);\n if (type === Boolean) return val === 'false' || val === '0' ? false : true;\n return val;\n};\n\nexport {convertValue};\n\nexport const getAttributeValue = (inst: any, attrName: string, options?: AttributeOptions & { selector?: AttributeSelector }): any => {\n const conf = getElementConfig(inst);\n const currentWin = inst._resolveWindow?.(conf) || ((typeof window !== 'undefined' ? window : undefined) as any);\n\n // If selector is not provided, use inst itself\n const targets = options?.selector ? resolveAttributeTargets(inst, options.selector, options) : [inst];\n\n const primaryTarget = targets[0];\n\n if (primaryTarget && typeof (primaryTarget as any).hasAttribute === 'function' && (primaryTarget as any).hasAttribute(attrName)) {\n let domVal = (primaryTarget as any).getAttribute(attrName);\n\n // \uD45C\uD604\uC2DD \uCCB4\uD06C\n const ae = new ActionExpression(domVal);\n const expr = ae.getFirstExpression('callReturn');\n if (expr) {\n try {\n const result = FunctionUtils.executeReturn({\n script: ConvertUtils.decodeHtmlEntity(expr.script, currentWin.document),\n context: inst,\n args: SwcUtils.getHelperAndHostSet(currentWin, inst)\n });\n return convertValue(result, options?.type);\n } catch (err) {\n console.error(`[SWC] Failed to execute directive {{= ${expr.script} }}:`, err);\n return convertValue(domVal, options?.type);\n }\n }\n\n return convertValue(domVal, options?.type);\n }\n\n // If no target found, return null\n return null;\n};\n\n/**\n * Resolve target elements based on selector and options\n * Handles special selectors ($this, $host, etc.), CSS selectors, and function-based selectors\n * Returns HTMLElement[] for attribute operations\n */\nexport const resolveAttributeTargets = (inst: any, selector: AttributeSelector, options: AttributeOptions): HTMLElement[] => {\n const conf = getElementConfig(inst);\n const currentWin = conf.window;\n const r = options.root || 'auto';\n const results: HTMLElement[] = [];\n\n // Resolve selector if it's a function\n let resolvedSelector: string | Node | Element | NodeList | Element[] | null = selector as any;\n if (typeof selector === 'function') {\n const hostSet = SwcUtils.getHelperAndHostSet(currentWin, inst);\n resolvedSelector = selector(inst, hostSet);\n }\n\n // If selector function returned elements directly, use them\n if (resolvedSelector instanceof currentWin.Element) {\n results.push(resolvedSelector as HTMLElement);\n return results;\n }\n if (resolvedSelector instanceof currentWin.NodeList) {\n results.push(...(Array.from(resolvedSelector) as HTMLElement[]));\n return results;\n }\n if (Array.isArray(resolvedSelector)) {\n results.push(...(resolvedSelector as HTMLElement[]));\n return results;\n }\n if (resolvedSelector === null) {\n return results;\n }\n\n // Handle string selector\n const stringSelector = resolvedSelector as string;\n\n const applyRoot = (target: any) => {\n if (!target) return;\n if (r === 'auto') {\n results.push(target);\n } else {\n if (r === 'light' || r === 'all') results.push(target);\n if ((r === 'shadow' || r === 'all') && target.shadowRoot) results.push(target.shadowRoot);\n }\n };\n\n if (stringSelector === '$this' || !stringSelector) {\n applyRoot(inst);\n } else {\n const hostSet = SwcUtils.getHostSet(inst);\n if (stringSelector === '$host') applyRoot(hostSet.$host);\n else if (stringSelector === '$parentHost') applyRoot(hostSet.$parentHost);\n else if (stringSelector === '$appHost') applyRoot(hostSet.$appHost as any);\n else if (stringSelector === '$firstHost') applyRoot(hostSet.$firstHost);\n else if (stringSelector === '$lastHost') applyRoot(hostSet.$lastHost);\n else if (stringSelector === '$firstAppHost') applyRoot(hostSet.$firstAppHost as any);\n else if (stringSelector === '$lastAppHost') applyRoot(hostSet.$lastAppHost as any);\n else if (stringSelector === '$hosts') hostSet.$hosts.forEach(applyRoot);\n else if (stringSelector === '$appHosts') hostSet.$appHosts.forEach(applyRoot);\n else {\n if (r === 'shadow') {\n const found = inst.shadowRoot?.querySelectorAll(stringSelector);\n if (found) results.push(...found);\n } else if (r === 'light') {\n const found = inst.querySelectorAll(stringSelector);\n if (found) results.push(...found);\n } else if (r === 'all') {\n const sMatch = inst.shadowRoot?.querySelectorAll(stringSelector);\n const lMatch = inst.querySelectorAll(stringSelector);\n if (sMatch) results.push(...sMatch);\n if (lMatch) results.push(...lMatch);\n } else {\n const found = (inst.shadowRoot || inst).querySelectorAll(stringSelector);\n if (found) results.push(...found);\n }\n }\n }\n return results;\n};\n\n/**\n * @applyAttribute decorator - set/get element attributes\n *\n * Usage:\n * - @applyAttribute('selector', 'attrName') - Set attribute with explicit name\n * - @applyAttribute('selector') - Use property name as attribute name\n * - @applyAttribute('selector', { name: 'attrName' }) - Set attribute via options\n * - @applyAttribute((this, helper) => 'selector', 'attrName') - Function-based selector\n * - Return null to remove attribute\n */\nexport function applyAttribute<S extends AttributeSelector>(selector: S, targetAttributeName: string, options?: AttributeOptionsOf<S>): MethodDecorator & PropertyDecorator;\nexport function applyAttribute<S extends AttributeSelector>(selector: S, options?: AttributeOptionsOf<S>): MethodDecorator & PropertyDecorator;\nexport function applyAttribute(selector: AttributeSelector, targetAttributeNameOrOptions?: string | AttributeOptions, options?: AttributeOptions): MethodDecorator {\n return (target: Object, propertyKey: string | symbol, descriptor?: PropertyDescriptor) => {\n // ensureInit(target as any);\n\n const constructor = target.constructor;\n const designType = (Reflect as any).getMetadata('design:type', target, propertyKey);\n const metaType: 'property' | 'method' = descriptor && typeof descriptor.value === 'function' ? 'method' : 'property';\n\n // Parse arguments\n let finalOptions: AttributeOptions = {};\n let targetAttributeName: string;\n\n if (typeof targetAttributeNameOrOptions === 'string') {\n // applyAttribute('selector', 'attrName', options?)\n targetAttributeName = targetAttributeNameOrOptions;\n finalOptions = options || {};\n } else if (targetAttributeNameOrOptions) {\n // applyAttribute('selector', options)\n finalOptions = targetAttributeNameOrOptions;\n targetAttributeName = finalOptions.name || String(propertyKey);\n } else {\n // applyAttribute('selector')\n targetAttributeName = String(propertyKey);\n }\n\n // Store metadata\n let metaList = ReflectUtils.getOwnMetadata(ATTRIBUTE_METADATA_KEY, constructor) as AttributeMetadata[];\n if (!metaList) {\n metaList = [];\n ReflectUtils.defineMetadata(ATTRIBUTE_METADATA_KEY, metaList, constructor);\n }\n metaList.push({\n propertyKey,\n selector: selector as AttributeSelector,\n targetAttributeName,\n options: finalOptions,\n type: metaType\n });\n\n // Helper: Apply resolved value to targets\n const applyValueToTargets = (inst: any, resolvedValue: any) => {\n const conf = getElementConfig(inst);\n const currentWin = conf.window;\n const targetEls = resolveAttributeTargets(inst, selector, finalOptions);\n const hostSet = SwcUtils.getHelperAndHostSet(currentWin, inst);\n\n targetEls.forEach(targetEl => {\n // Apply filter if provided\n if (finalOptions.filter && !finalOptions.filter(targetEl, resolvedValue, {currentThis: inst, helper: hostSet})) {\n return;\n }\n\n if (resolvedValue === null) {\n // Remove attribute if value is null\n targetEl.removeAttribute(targetAttributeName);\n } else if (resolvedValue !== undefined) {\n // Set attribute\n targetEl.setAttribute(targetAttributeName, resolvedValue === true ? '' : String(resolvedValue));\n }\n });\n\n return resolvedValue;\n };\n\n // Method decorator: wrap method to apply its return value to attributes\n if (descriptor && typeof descriptor.value === 'function') {\n const original = descriptor.value;\n descriptor.value = function (...args: any[]) {\n ensureInit(this);\n const res = (original as any).apply(this, args);\n\n /**\n * Extract value for this decorator from method return value\n * \n * If return value is an object with this decorator's key,\n * use that value. Otherwise use the entire return value.\n * \n * Uses valueKey from options if provided, otherwise uses ATTRIBUTE_METADATA_KEY.\n * \n * Example:\n * @setAttribute('selector1', { valueKey: 'attr1' })\n * @setAttribute('selector2', { valueKey: 'attr2' })\n * myMethod() {\n * return {\n * attr1: 'attribute-value1',\n * attr2: 'attribute-value2'\n * };\n * }\n * \n * First decorator will use 'attribute-value1', second will use 'attribute-value2'\n */\n const extractValue = (v: any) => {\n const keyToUse = finalOptions.valueKey ?? ATTRIBUTE_METADATA_KEY;\n if (v && typeof v === 'object' && keyToUse in v) {\n return v[keyToUse];\n }\n return v;\n };\n\n if (res instanceof Promise) {\n return res.then((v: any) => {\n const extracted = extractValue(v);\n applyValueToTargets(this, extracted);\n return v;\n });\n } else {\n const extracted = extractValue(res);\n applyValueToTargets(this, extracted);\n return res;\n }\n };\n return;\n }\n\n // Property decorator: define getter/setter to proxy to element attributes\n Object.defineProperty(target, propertyKey, {\n configurable: true,\n enumerable: true,\n get(this: any) {\n ensureInit(this);\n const mergedOptions = {...finalOptions, selector, type: finalOptions.type || designType};\n return getAttributeValue(this, targetAttributeName, mergedOptions);\n },\n set(this: any, value: any) {\n ensureInit(this);\n\n if (value instanceof Promise) {\n value.then((v: any) => applyValueToTargets(this, v)).catch(() => { /* swallow */\n });\n } else {\n applyValueToTargets(this, value);\n }\n }\n });\n };\n}\n\n// ============================================\n// Convenience Aliases\n// ============================================\n\n/**\n * @attribute - Field decorator for binding element attributes (read/write)\n * \n * Intelligently distinguishes between attribute names and CSS selectors:\n * \n * Usage patterns:\n * - @attribute('product-id') - Attribute name on $this (auto-detected)\n * - @attribute('#user', 'product-id') - Attribute name on selector\n * - @attribute('product-id', options) - Attribute name on $this with options\n * - @attribute('#user', 'product-id', options) - Attribute name on selector with options\n * - @attribute((this, helper) => 'selector', 'product-id') - Function-based selector\n * - @attribute - Bare decorator (uses property name as attribute on $this)\n * \n * Note: This decorator is for FIELDS ONLY. For methods, use @setAttribute.\n */\nexport function attribute(target: Object, propertyKey: string | symbol): void;\nexport function attribute(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;\nexport function attribute(attributeName: string, options?: AttributeQueryOptions): PropertyDecorator;\nexport function attribute(selector: string, attributeName: string, options?: AttributeQueryOptions): PropertyDecorator;\nexport function attribute(selector: AttributeFnSelector, attributeName: string, options?: AttributeNonQueryOptions): PropertyDecorator;\nexport function attribute(selectorOrAttributeOrTarget?: AttributeSelector | Object, attributeNameOrOptions?: any, optionsOrDescriptor?: any): any {\n // Bare decorator: @attribute\n if (optionsOrDescriptor !== undefined && (typeof attributeNameOrOptions === 'string' || typeof attributeNameOrOptions === 'symbol')) {\n return applyAttribute('$this', undefined as any, {})(selectorOrAttributeOrTarget as Object, attributeNameOrOptions, optionsOrDescriptor as PropertyDescriptor);\n }\n \n // With string as first parameter\n if (typeof selectorOrAttributeOrTarget === 'string') {\n // Check if first parameter is a CSS selector or attribute name\n const isSelector = isCssSelector(selectorOrAttributeOrTarget);\n \n if (isSelector) {\n // First param is a selector: @attribute('#user', 'product-id', options?)\n return applyAttribute(selectorOrAttributeOrTarget, attributeNameOrOptions as any, optionsOrDescriptor as AttributeOptions);\n } else {\n // First param is an attribute name: @attribute('product-id', options?)\n // Treat as attribute name on $this\n const options = (typeof attributeNameOrOptions === 'object' && attributeNameOrOptions !== null) \n ? attributeNameOrOptions \n : {};\n return applyAttribute('$this', selectorOrAttributeOrTarget, options);\n }\n }\n \n // Without selector (defaults to $this with options)\n return applyAttribute('$this', undefined as any, selectorOrAttributeOrTarget as AttributeOptions);\n}\n\n/**\n * @setAttribute - Method decorator for setting element attributes from method return value\n * \n * Intelligently distinguishes between attribute names and CSS selectors:\n * \n * Usage patterns:\n * - @setAttribute('data-id') - Attribute name on $this (auto-detected)\n * - @setAttribute('#user', 'data-id') - Attribute name on selector\n * - @setAttribute('data-id', options) - Attribute name on $this with options\n * - @setAttribute('#user', 'data-id', options) - Attribute name on selector with options\n * - @setAttribute((this, helper) => 'selector', 'data-id') - Function-based selector\n * - @setAttribute - Bare decorator (uses method name as attribute on $this)\n * \n * Note: This decorator is for METHODS ONLY. For fields, use @attribute.\n * \n * Example:\n * @setAttribute('data-status')\n * updateStatus() {\n * return 'active';\n * }\n */\nexport function setAttribute(selector: string, attributeName: string, options?: AttributeQueryOptions): MethodDecorator;\nexport function setAttribute(selector: AttributeFnSelector, attributeName: string, options?: AttributeNonQueryOptions): MethodDecorator;\nexport function setAttribute(attributeName: string, options?: AttributeQueryOptions): MethodDecorator;\nexport function setAttribute(selectorOrAttributeOrOptions?: AttributeSelector | AttributeOptions, attributeNameOrOptions?: any, optionsOrUndefined?: AttributeOptions): MethodDecorator {\n // Function selector: @setAttribute((c, helper) => ..., 'attr', options?)\n if (typeof selectorOrAttributeOrOptions === 'function') {\n return applyAttribute(selectorOrAttributeOrOptions as AttributeSelector, attributeNameOrOptions as any, optionsOrUndefined as AttributeOptions) as MethodDecorator;\n }\n // With string as first parameter\n if (typeof selectorOrAttributeOrOptions === 'string') {\n // Check if first parameter is a CSS selector or attribute name\n const isSelector = isCssSelector(selectorOrAttributeOrOptions);\n \n if (isSelector) {\n // First param is a selector: @setAttribute('#user', 'data-id', options?)\n return applyAttribute(selectorOrAttributeOrOptions, attributeNameOrOptions as any, optionsOrUndefined as AttributeOptions) as MethodDecorator;\n } else {\n // First param is an attribute name: @setAttribute('data-id', options?)\n // Treat as attribute name on $this\n const options = (typeof attributeNameOrOptions === 'object' && attributeNameOrOptions !== null) \n ? attributeNameOrOptions \n : {};\n return applyAttribute('$this', selectorOrAttributeOrOptions, options) as MethodDecorator;\n }\n }\n \n // Without selector (defaults to $this with options)\n return applyAttribute('$this', undefined as any, selectorOrAttributeOrOptions as AttributeOptions) as MethodDecorator;\n}\n\n// ============================================\n// Metadata Helpers\n// ============================================\n\nexport const findAllAttributeMetadata = (target: any): AttributeMetadata[] => {\n const actualTarget = target instanceof Function ? target : target.constructor;\n return ReflectUtils.findAllMetadata<AttributeMetadata[]>(ATTRIBUTE_METADATA_KEY, actualTarget).flat();\n};\n\n// Backward compatibility alias\nexport const findAllAttributeApplyMetadata = (target: any): Map<string | symbol, AttributeMetadata> => {\n const result = new Map<string | symbol, AttributeMetadata>();\n findAllAttributeMetadata(target).forEach(meta => {\n result.set(meta.propertyKey, meta);\n });\n return result;\n};\n\n// \u2500\u2500\u2500 Aliases \u2500\u2500\u2500\n// attribute(\uD544\uB4DC) / setAttribute(\uBA54\uC11C\uB4DC)\uC640 \uAD6C\uBD84\uB418\uB294 \uC77C\uBC18 \uB370\uCF54\uB808\uC774\uD130 \uB2E8\uCD95\uBA85\nexport const attr = applyAttribute;\n\n// \u2500\u2500\u2500 \uD3B8\uC758 \uD5EC\uD37C (selector/root \uC0DD\uB7B5) \u2500\u2500\u2500\n\nexport function attrThis(targetAttributeName?: string, options?: AttributeQueryOptions): MethodDecorator {\n return applyAttribute('$this', targetAttributeName, options);\n}\nexport function attrAppHost(targetAttributeName?: string, options?: AttributeQueryOptions): MethodDecorator {\n return applyAttribute('$appHost', targetAttributeName, options);\n}\nexport function attrLight(selector: string, targetAttributeName?: string, options?: Omit<AttributeQueryOptions, 'root'>): MethodDecorator {\n return applyAttribute(selector, targetAttributeName, {...options ?? {}, root: 'light'});\n}\nexport function attrShadow(selector: string, targetAttributeName?: string, options?: Omit<AttributeQueryOptions, 'root'>): MethodDecorator {\n return applyAttribute(selector, targetAttributeName, {...options ?? {}, root: 'shadow'});\n}\nexport function attrAll(selector: string, targetAttributeName?: string, options?: Omit<AttributeQueryOptions, 'root'>): MethodDecorator {\n return applyAttribute(selector, targetAttributeName, {...options ?? {}, root: 'all'});\n}\n\nexport default applyAttribute;\n"],
|
|
5
|
+
"mappings": "AAAA,SAAQ,cAAc,eAAe,wBAAuB;AAC5D,SAAQ,YAAY,wBAAuB;AAC3C,SAAQ,gBAAe;AAEvB,SAAQ,oBAAmB;AAmCpB,MAAM,yBAAyB,OAAO,IAAI,gCAAgC;AAqBjF,MAAM,gBAAgB,CAAC,QAAyB;AAC9C,MAAI,CAAC,IAAK,QAAO;AAGjB,MAAI,IAAI,WAAW,GAAG,EAAG,QAAO;AAGhC,MAAI,eAAe,KAAK,GAAG,EAAG,QAAO;AAGrC,MAAI,aAAa,KAAK,GAAG,EAAG,QAAO;AAEnC,SAAO;AACT;AAEA,MAAM,eAAe,CAAC,KAAoB,SAAmB;AAC3D,MAAI,QAAQ,QAAQ,QAAQ,OAAW,QAAO;AAC9C,MAAI,SAAS,OAAQ,QAAO,OAAO,GAAG;AACtC,MAAI,SAAS,QAAS,QAAO,QAAQ,WAAW,QAAQ,MAAM,QAAQ;AACtE,SAAO;AACT;AAIO,MAAM,oBAAoB,CAAC,MAAW,UAAkB,YAAuE;AACp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CAAC;AACL,aAAO,eAAe,SAAS,8BAA8B,OAAO;AAAA,IACtE;AAAA,EACF;AAGA,SAAO,eAAe,SAAS,QAAkB,4BAAgD;AACnG;AAMO,MAAM,2BAA2B,CAAC,WAAqC;AAC5E,QAAM,eAAe,kBAAkB,WAAW,SAAS,OAAO;AAClE,SAAO,aAAa,gBAAqC,wBAAwB,YAAY,EAAE,KAAK;AACtG;AAGO,MAAM,gCAAgC,CAAC,WAAyD;AACrG,QAAM,SAAS,oBAAI,IAAwC;AAC3D,2BAAyB,MAAM,EAAE,QAAQ,UAAQ;AAC/C,WAAO,IAAI,KAAK,aAAa,IAAI;AAAA,EACnC,CAAC;AACD,SAAO;AACT;AAIO,MAAM,OAAO;AAIb,SAAS,SAAS,qBAA8B,SAAkD;AACvG,SAAO,eAAe,SAAS,qBAAqB,OAAO;AAC7D;AACO,SAAS,YAAY,qBAA8B,SAAkD;AAC1G,SAAO,eAAe,YAAY,qBAAqB,OAAO;AAChE;AACO,SAAS,UAAU,UAAkB,qBAA8B,SAAgE;AACxI,SAAO,eAAe,UAAU,qBAAqB,EAAC,GAAG,WAAW,CAAC,GAAG,MAAM,QAAO,CAAC;AACxF;AACO,SAAS,WAAW,UAAkB,qBAA8B,SAAgE;AACzI,SAAO,eAAe,UAAU,qBAAqB,EAAC,GAAG,WAAW,CAAC,GAAG,MAAM,SAAQ,CAAC;AACzF;AACO,SAAS,QAAQ,UAAkB,qBAA8B,SAAgE;AACtI,SAAO,eAAe,UAAU,qBAAqB,EAAC,GAAG,WAAW,CAAC,GAAG,MAAM,MAAK,CAAC;AACtF;AAEA,IAAO,yBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -18,6 +18,9 @@ const resolveSelector = (selector, inst, win) => {
|
|
|
18
18
|
if (result === null) {
|
|
19
19
|
return [];
|
|
20
20
|
}
|
|
21
|
+
if (result instanceof win.Node) {
|
|
22
|
+
return [];
|
|
23
|
+
}
|
|
21
24
|
return result;
|
|
22
25
|
}
|
|
23
26
|
return selector;
|
|
@@ -99,7 +102,7 @@ function createClassDecorator(action) {
|
|
|
99
102
|
if (classMap && typeof classMap === "string") {
|
|
100
103
|
classes = resolvedRes ? classMap : "";
|
|
101
104
|
} else if (typeof resolvedRes === "object" && resolvedRes !== null && !Array.isArray(resolvedRes)) {
|
|
102
|
-
classes = Object.entries(resolvedRes).filter(([_, force]) => typeof force === "function" ? force(targetEl, hostSet) : !!force).map(([
|
|
105
|
+
classes = Object.entries(resolvedRes).filter(([_, force]) => typeof force === "function" ? force(targetEl, hostSet) : !!force).map(([cls2]) => cls2).join(" ");
|
|
103
106
|
} else {
|
|
104
107
|
classes = Array.isArray(resolvedRes) ? resolvedRes.join(" ") : String(resolvedRes);
|
|
105
108
|
}
|
|
@@ -108,9 +111,9 @@ function createClassDecorator(action) {
|
|
|
108
111
|
if (classMap && typeof classMap === "string") {
|
|
109
112
|
targetEl.classList.toggle(classMap, !!resolvedRes);
|
|
110
113
|
} else if (typeof resolvedRes === "object" && resolvedRes !== null && !Array.isArray(resolvedRes)) {
|
|
111
|
-
Object.entries(resolvedRes).forEach(([
|
|
114
|
+
Object.entries(resolvedRes).forEach(([cls2, force]) => {
|
|
112
115
|
const isActive = typeof force === "function" ? force(targetEl, hostSet) : !!force;
|
|
113
|
-
targetEl.classList.toggle(
|
|
116
|
+
targetEl.classList.toggle(cls2, isActive);
|
|
114
117
|
});
|
|
115
118
|
} else {
|
|
116
119
|
const classes = Array.isArray(resolvedRes) ? resolvedRes.map(String) : [String(resolvedRes)];
|
|
@@ -122,11 +125,11 @@ function createClassDecorator(action) {
|
|
|
122
125
|
if (action === "add") targetEl.classList.add(classMap);
|
|
123
126
|
else targetEl.classList.remove(classMap);
|
|
124
127
|
} else if (typeof resolvedRes === "object" && resolvedRes !== null && !Array.isArray(resolvedRes)) {
|
|
125
|
-
Object.entries(resolvedRes).forEach(([
|
|
128
|
+
Object.entries(resolvedRes).forEach(([cls2, force]) => {
|
|
126
129
|
const shouldExecute = typeof force === "function" ? force(targetEl, hostSet) : !!force;
|
|
127
130
|
if (shouldExecute) {
|
|
128
|
-
if (action === "add") targetEl.classList.add(
|
|
129
|
-
else targetEl.classList.remove(
|
|
131
|
+
if (action === "add") targetEl.classList.add(cls2);
|
|
132
|
+
else targetEl.classList.remove(cls2);
|
|
130
133
|
}
|
|
131
134
|
});
|
|
132
135
|
} else {
|
|
@@ -150,10 +153,10 @@ function createClassDecorator(action) {
|
|
|
150
153
|
};
|
|
151
154
|
}
|
|
152
155
|
function applyClass(selectorOrTarget, actionOrPropertyKey, optionsOrDescriptor) {
|
|
153
|
-
if (optionsOrDescriptor !== void 0 && (typeof actionOrPropertyKey === "string" || typeof actionOrPropertyKey === "symbol")) {
|
|
156
|
+
if (optionsOrDescriptor !== void 0 && typeof selectorOrTarget !== "string" && typeof selectorOrTarget !== "function" && (typeof actionOrPropertyKey === "string" || typeof actionOrPropertyKey === "symbol")) {
|
|
154
157
|
return createClassDecorator("update")("$this", {})(selectorOrTarget, actionOrPropertyKey, optionsOrDescriptor);
|
|
155
158
|
}
|
|
156
|
-
if (typeof selectorOrTarget === "string") {
|
|
159
|
+
if (typeof selectorOrTarget === "string" || typeof selectorOrTarget === "function") {
|
|
157
160
|
const action2 = typeof actionOrPropertyKey === "string" ? actionOrPropertyKey : "update";
|
|
158
161
|
const options2 = typeof actionOrPropertyKey === "object" ? actionOrPropertyKey : optionsOrDescriptor;
|
|
159
162
|
return createClassDecorator(action2)(selectorOrTarget, options2);
|
|
@@ -163,50 +166,72 @@ function applyClass(selectorOrTarget, actionOrPropertyKey, optionsOrDescriptor)
|
|
|
163
166
|
return createClassDecorator(action)("$this", options);
|
|
164
167
|
}
|
|
165
168
|
function setClass(selectorOrTarget, classMapOrOptionsOrPropertyKey, optionsOrDescriptor) {
|
|
166
|
-
if (optionsOrDescriptor !== void 0 && (typeof classMapOrOptionsOrPropertyKey === "string" || typeof classMapOrOptionsOrPropertyKey === "symbol")) {
|
|
169
|
+
if (optionsOrDescriptor !== void 0 && typeof selectorOrTarget !== "string" && typeof selectorOrTarget !== "function" && (typeof classMapOrOptionsOrPropertyKey === "string" || typeof classMapOrOptionsOrPropertyKey === "symbol")) {
|
|
167
170
|
return createClassDecorator("set")("$this", {})(selectorOrTarget, classMapOrOptionsOrPropertyKey, optionsOrDescriptor);
|
|
168
171
|
}
|
|
169
|
-
if (typeof selectorOrTarget === "string") {
|
|
172
|
+
if (typeof selectorOrTarget === "string" || typeof selectorOrTarget === "function") {
|
|
170
173
|
return createClassDecorator("set")(selectorOrTarget, classMapOrOptionsOrPropertyKey, optionsOrDescriptor);
|
|
171
174
|
}
|
|
172
175
|
return createClassDecorator("set")("$this", selectorOrTarget);
|
|
173
176
|
}
|
|
174
177
|
function updateClass(selectorOrTarget, classMapOrOptionsOrPropertyKey, optionsOrDescriptor) {
|
|
175
|
-
if (optionsOrDescriptor !== void 0 && (typeof classMapOrOptionsOrPropertyKey === "string" || typeof classMapOrOptionsOrPropertyKey === "symbol")) {
|
|
178
|
+
if (optionsOrDescriptor !== void 0 && typeof selectorOrTarget !== "string" && typeof selectorOrTarget !== "function" && (typeof classMapOrOptionsOrPropertyKey === "string" || typeof classMapOrOptionsOrPropertyKey === "symbol")) {
|
|
176
179
|
return createClassDecorator("update")("$this", {})(selectorOrTarget, classMapOrOptionsOrPropertyKey, optionsOrDescriptor);
|
|
177
180
|
}
|
|
178
|
-
if (typeof selectorOrTarget === "string") {
|
|
181
|
+
if (typeof selectorOrTarget === "string" || typeof selectorOrTarget === "function") {
|
|
179
182
|
return createClassDecorator("update")(selectorOrTarget, classMapOrOptionsOrPropertyKey, optionsOrDescriptor);
|
|
180
183
|
}
|
|
181
184
|
return createClassDecorator("update")("$this", selectorOrTarget);
|
|
182
185
|
}
|
|
183
186
|
function addClass(selectorOrTarget, classMapOrOptionsOrPropertyKey, optionsOrDescriptor) {
|
|
184
|
-
if (optionsOrDescriptor !== void 0 && (typeof classMapOrOptionsOrPropertyKey === "string" || typeof classMapOrOptionsOrPropertyKey === "symbol")) {
|
|
187
|
+
if (optionsOrDescriptor !== void 0 && typeof selectorOrTarget !== "string" && typeof selectorOrTarget !== "function" && (typeof classMapOrOptionsOrPropertyKey === "string" || typeof classMapOrOptionsOrPropertyKey === "symbol")) {
|
|
185
188
|
return createClassDecorator("add")("$this", {})(selectorOrTarget, classMapOrOptionsOrPropertyKey, optionsOrDescriptor);
|
|
186
189
|
}
|
|
187
|
-
if (typeof selectorOrTarget === "string") {
|
|
190
|
+
if (typeof selectorOrTarget === "string" || typeof selectorOrTarget === "function") {
|
|
188
191
|
return createClassDecorator("add")(selectorOrTarget, classMapOrOptionsOrPropertyKey, optionsOrDescriptor);
|
|
189
192
|
}
|
|
190
193
|
return createClassDecorator("add")("$this", selectorOrTarget);
|
|
191
194
|
}
|
|
192
195
|
function removeClass(selectorOrTarget, classMapOrOptionsOrPropertyKey, optionsOrDescriptor) {
|
|
193
|
-
if (optionsOrDescriptor !== void 0 && (typeof classMapOrOptionsOrPropertyKey === "string" || typeof classMapOrOptionsOrPropertyKey === "symbol")) {
|
|
196
|
+
if (optionsOrDescriptor !== void 0 && typeof selectorOrTarget !== "string" && typeof selectorOrTarget !== "function" && (typeof classMapOrOptionsOrPropertyKey === "string" || typeof classMapOrOptionsOrPropertyKey === "symbol")) {
|
|
194
197
|
return createClassDecorator("remove")("$this", {})(selectorOrTarget, classMapOrOptionsOrPropertyKey, optionsOrDescriptor);
|
|
195
198
|
}
|
|
196
|
-
if (typeof selectorOrTarget === "string") {
|
|
199
|
+
if (typeof selectorOrTarget === "string" || typeof selectorOrTarget === "function") {
|
|
197
200
|
return createClassDecorator("remove")(selectorOrTarget, classMapOrOptionsOrPropertyKey, optionsOrDescriptor);
|
|
198
201
|
}
|
|
199
202
|
return createClassDecorator("remove")("$this", selectorOrTarget);
|
|
200
203
|
}
|
|
201
204
|
function toggleClass(selectorOrTarget, classMapOrOptionsOrPropertyKey, optionsOrDescriptor) {
|
|
202
|
-
if (optionsOrDescriptor !== void 0 && (typeof classMapOrOptionsOrPropertyKey === "string" || typeof classMapOrOptionsOrPropertyKey === "symbol")) {
|
|
205
|
+
if (optionsOrDescriptor !== void 0 && typeof selectorOrTarget !== "string" && typeof selectorOrTarget !== "function" && (typeof classMapOrOptionsOrPropertyKey === "string" || typeof classMapOrOptionsOrPropertyKey === "symbol")) {
|
|
203
206
|
return createClassDecorator("toggle")("$this", {})(selectorOrTarget, classMapOrOptionsOrPropertyKey, optionsOrDescriptor);
|
|
204
207
|
}
|
|
205
|
-
if (typeof selectorOrTarget === "string") {
|
|
208
|
+
if (typeof selectorOrTarget === "string" || typeof selectorOrTarget === "function") {
|
|
206
209
|
return createClassDecorator("toggle")(selectorOrTarget, classMapOrOptionsOrPropertyKey, optionsOrDescriptor);
|
|
207
210
|
}
|
|
208
211
|
return createClassDecorator("toggle")("$this", selectorOrTarget);
|
|
209
212
|
}
|
|
213
|
+
const cls = applyClass;
|
|
214
|
+
function clsThis(action, options) {
|
|
215
|
+
return applyClass("$this", action, options);
|
|
216
|
+
}
|
|
217
|
+
function clsAppHost(action, options) {
|
|
218
|
+
return applyClass("$appHost", action, options);
|
|
219
|
+
}
|
|
220
|
+
function clsLight(selector, actionOrOptions, options) {
|
|
221
|
+
const action = typeof actionOrOptions === "string" ? actionOrOptions : void 0;
|
|
222
|
+
const opts = typeof actionOrOptions === "object" ? actionOrOptions : options;
|
|
223
|
+
return applyClass(selector, action, { ...opts ?? {}, root: "light" });
|
|
224
|
+
}
|
|
225
|
+
function clsShadow(selector, actionOrOptions, options) {
|
|
226
|
+
const action = typeof actionOrOptions === "string" ? actionOrOptions : void 0;
|
|
227
|
+
const opts = typeof actionOrOptions === "object" ? actionOrOptions : options;
|
|
228
|
+
return applyClass(selector, action, { ...opts ?? {}, root: "shadow" });
|
|
229
|
+
}
|
|
230
|
+
function clsAll(selector, actionOrOptions, options) {
|
|
231
|
+
const action = typeof actionOrOptions === "string" ? actionOrOptions : void 0;
|
|
232
|
+
const opts = typeof actionOrOptions === "object" ? actionOrOptions : options;
|
|
233
|
+
return applyClass(selector, action, { ...opts ?? {}, root: "all" });
|
|
234
|
+
}
|
|
210
235
|
const findAllClassMetadata = (target) => {
|
|
211
236
|
const result = /* @__PURE__ */ new Map();
|
|
212
237
|
const maps = ReflectUtils.findAllMetadata(CLASS_METADATA_KEY, target);
|
|
@@ -221,6 +246,12 @@ export {
|
|
|
221
246
|
CLASS_METADATA_KEY,
|
|
222
247
|
addClass,
|
|
223
248
|
applyClass,
|
|
249
|
+
cls,
|
|
250
|
+
clsAll,
|
|
251
|
+
clsAppHost,
|
|
252
|
+
clsLight,
|
|
253
|
+
clsShadow,
|
|
254
|
+
clsThis,
|
|
224
255
|
findAllClassMetadata,
|
|
225
256
|
removeClass,
|
|
226
257
|
setClass,
|