@dooboostore/simple-web-component 1.0.43 → 1.0.45

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.
Files changed (146) hide show
  1. package/README.md +312 -63
  2. package/dist/cjs/SwcAppEngine.js +3 -1
  3. package/dist/cjs/SwcAppEngine.js.map +2 -2
  4. package/dist/cjs/decorators/addEventListener.js.map +2 -2
  5. package/dist/cjs/decorators/applyAttribute.js +66 -43
  6. package/dist/cjs/decorators/applyAttribute.js.map +2 -2
  7. package/dist/cjs/decorators/applyClass.js +110 -43
  8. package/dist/cjs/decorators/applyClass.js.map +3 -3
  9. package/dist/cjs/decorators/applyNode.js +200 -112
  10. package/dist/cjs/decorators/applyNode.js.map +2 -2
  11. package/dist/cjs/decorators/applyProperty.js +49 -45
  12. package/dist/cjs/decorators/applyProperty.js.map +2 -2
  13. package/dist/cjs/decorators/applyStyle.js +92 -37
  14. package/dist/cjs/decorators/applyStyle.js.map +3 -3
  15. package/dist/cjs/decorators/{changedAttributeThis.js → changedAttribute.js} +6 -6
  16. package/dist/cjs/decorators/changedAttribute.js.map +7 -0
  17. package/dist/cjs/decorators/elementDefine.js +81 -31
  18. package/dist/cjs/decorators/elementDefine.js.map +3 -3
  19. package/dist/cjs/decorators/emitCustomEvent.js +80 -52
  20. package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
  21. package/dist/cjs/decorators/index.js +1 -1
  22. package/dist/cjs/decorators/index.js.map +2 -2
  23. package/dist/cjs/decorators/publishSwcAppMessage.js +5 -5
  24. package/dist/cjs/decorators/publishSwcAppMessage.js.map +3 -3
  25. package/dist/cjs/decorators/query.js +133 -147
  26. package/dist/cjs/decorators/query.js.map +3 -3
  27. package/dist/cjs/decorators/queryAll.js +143 -132
  28. package/dist/cjs/decorators/queryAll.js.map +3 -3
  29. package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js +2 -0
  30. package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js.map +2 -2
  31. package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js +2 -0
  32. package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
  33. package/dist/cjs/elements/SwcAppMixin.js +17 -2
  34. package/dist/cjs/elements/SwcAppMixin.js.map +2 -2
  35. package/dist/cjs/examples/RxJSOperatorsExample.js +285 -0
  36. package/dist/cjs/examples/RxJSOperatorsExample.js.map +7 -0
  37. package/dist/cjs/index.js +1 -0
  38. package/dist/cjs/index.js.map +2 -2
  39. package/dist/cjs/router/ElementRouter.js +4 -0
  40. package/dist/cjs/router/ElementRouter.js.map +2 -2
  41. package/dist/cjs/types/window.d.js.map +1 -1
  42. package/dist/esm/SwcAppEngine.js +3 -1
  43. package/dist/esm/SwcAppEngine.js.map +2 -2
  44. package/dist/esm/decorators/addEventListener.js.map +2 -2
  45. package/dist/esm/decorators/applyAttribute.js +66 -43
  46. package/dist/esm/decorators/applyAttribute.js.map +2 -2
  47. package/dist/esm/decorators/applyClass.js +110 -43
  48. package/dist/esm/decorators/applyClass.js.map +3 -3
  49. package/dist/esm/decorators/applyNode.js +200 -112
  50. package/dist/esm/decorators/applyNode.js.map +2 -2
  51. package/dist/esm/decorators/applyProperty.js +49 -45
  52. package/dist/esm/decorators/applyProperty.js.map +2 -2
  53. package/dist/esm/decorators/applyStyle.js +92 -37
  54. package/dist/esm/decorators/applyStyle.js.map +3 -3
  55. package/dist/esm/decorators/{changedAttributeThis.js → changedAttribute.js} +3 -3
  56. package/dist/esm/decorators/changedAttribute.js.map +7 -0
  57. package/dist/esm/decorators/elementDefine.js +79 -29
  58. package/dist/esm/decorators/elementDefine.js.map +2 -2
  59. package/dist/esm/decorators/emitCustomEvent.js +80 -52
  60. package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
  61. package/dist/esm/decorators/index.js +1 -1
  62. package/dist/esm/decorators/index.js.map +1 -1
  63. package/dist/esm/decorators/publishSwcAppMessage.js +5 -5
  64. package/dist/esm/decorators/publishSwcAppMessage.js.map +3 -3
  65. package/dist/esm/decorators/query.js +133 -147
  66. package/dist/esm/decorators/query.js.map +3 -3
  67. package/dist/esm/decorators/queryAll.js +143 -132
  68. package/dist/esm/decorators/queryAll.js.map +3 -3
  69. package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js +2 -0
  70. package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js.map +2 -2
  71. package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js +2 -0
  72. package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
  73. package/dist/esm/elements/SwcAppMixin.js +18 -3
  74. package/dist/esm/elements/SwcAppMixin.js.map +2 -2
  75. package/dist/esm/examples/RxJSOperatorsExample.js +266 -0
  76. package/dist/esm/examples/RxJSOperatorsExample.js.map +7 -0
  77. package/dist/esm/index.js +1 -0
  78. package/dist/esm/index.js.map +2 -2
  79. package/dist/esm/router/ElementRouter.js +4 -0
  80. package/dist/esm/router/ElementRouter.js.map +2 -2
  81. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +1118 -633
  82. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
  83. package/dist/types/SwcAppEngine.d.ts.map +1 -1
  84. package/dist/types/decorators/addEventListener.d.ts +19 -15
  85. package/dist/types/decorators/addEventListener.d.ts.map +1 -1
  86. package/dist/types/decorators/applyAttribute.d.ts +45 -26
  87. package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
  88. package/dist/types/decorators/applyClass.d.ts +19 -38
  89. package/dist/types/decorators/applyClass.d.ts.map +1 -1
  90. package/dist/types/decorators/applyNode.d.ts +175 -32
  91. package/dist/types/decorators/applyNode.d.ts.map +1 -1
  92. package/dist/types/decorators/applyProperty.d.ts +38 -25
  93. package/dist/types/decorators/applyProperty.d.ts.map +1 -1
  94. package/dist/types/decorators/applyStyle.d.ts +10 -9
  95. package/dist/types/decorators/applyStyle.d.ts.map +1 -1
  96. package/dist/types/decorators/{changedAttributeThis.d.ts → changedAttribute.d.ts} +2 -2
  97. package/dist/types/decorators/changedAttribute.d.ts.map +1 -0
  98. package/dist/types/decorators/elementDefine.d.ts.map +1 -1
  99. package/dist/types/decorators/emitCustomEvent.d.ts +6 -12
  100. package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
  101. package/dist/types/decorators/index.d.ts +1 -1
  102. package/dist/types/decorators/index.d.ts.map +1 -1
  103. package/dist/types/decorators/publishSwcAppMessage.d.ts +1 -1
  104. package/dist/types/decorators/publishSwcAppMessage.d.ts.map +1 -1
  105. package/dist/types/decorators/query.d.ts +16 -29
  106. package/dist/types/decorators/query.d.ts.map +1 -1
  107. package/dist/types/decorators/queryAll.d.ts +16 -23
  108. package/dist/types/decorators/queryAll.d.ts.map +1 -1
  109. package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts +1 -0
  110. package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts.map +1 -1
  111. package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts +2 -0
  112. package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts.map +1 -1
  113. package/dist/types/elements/SwcAppMixin.d.ts +4 -4
  114. package/dist/types/elements/SwcAppMixin.d.ts.map +1 -1
  115. package/dist/types/examples/RxJSOperatorsExample.d.ts +94 -0
  116. package/dist/types/examples/RxJSOperatorsExample.d.ts.map +1 -0
  117. package/dist/types/index.d.ts +1 -0
  118. package/dist/types/index.d.ts.map +1 -1
  119. package/dist/types/router/ElementRouter.d.ts.map +1 -1
  120. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +1118 -633
  121. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
  122. package/package.json +1 -1
  123. package/src/SwcAppEngine.ts +3 -1
  124. package/src/decorators/addEventListener.ts +31 -25
  125. package/src/decorators/applyAttribute.ts +164 -86
  126. package/src/decorators/applyClass.ts +161 -41
  127. package/src/decorators/applyNode.ts +408 -108
  128. package/src/decorators/applyProperty.ts +100 -89
  129. package/src/decorators/applyStyle.ts +131 -37
  130. package/src/decorators/{changedAttributeThis.ts → changedAttribute.ts} +1 -1
  131. package/src/decorators/elementDefine.ts +96 -30
  132. package/src/decorators/emitCustomEvent.ts +92 -60
  133. package/src/decorators/index.ts +1 -1
  134. package/src/decorators/publishSwcAppMessage.ts +1 -1
  135. package/src/decorators/query.ts +155 -162
  136. package/src/decorators/queryAll.ts +157 -139
  137. package/src/decorators/subscribeSwcAppMessageWhileConnected.ts +1 -0
  138. package/src/decorators/subscribeSwcAppRouteChangeWhileConnected.ts +3 -1
  139. package/src/elements/SwcAppMixin.ts +43 -24
  140. package/src/examples/RxJSOperatorsExample.ts +279 -0
  141. package/src/index.ts +2 -0
  142. package/src/router/ElementRouter.ts +4 -0
  143. package/src/types/window.d.ts +3 -0
  144. package/dist/cjs/decorators/changedAttributeThis.js.map +0 -7
  145. package/dist/esm/decorators/changedAttributeThis.js.map +0 -7
  146. package/dist/types/decorators/changedAttributeThis.d.ts.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dooboostore/simple-web-component",
3
- "version": "1.0.43",
3
+ "version": "1.0.45",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.js",
@@ -78,7 +78,9 @@ export class SwcAppEngine {
78
78
 
79
79
  if (this._config.onStartedLazyDefineComponent) {
80
80
  // console.log('-------->', this._config.onStartedLazyDefineComponent)
81
- await Promise.all(this._config.onStartedLazyDefineComponent.map(it => it(this._config.window)))
81
+ await Promise.all(this._config.onStartedLazyDefineComponent.map(it => {
82
+ it(this._config.window);
83
+ }))
82
84
  }
83
85
  if (this._config.onEngineStarted) {
84
86
  await this._config.onEngineStarted(this.simpleApplication, this.host as unknown as SwcAppInterface);
@@ -1,7 +1,7 @@
1
1
  import { ReflectUtils } from '@dooboostore/core';
2
2
  import { SpecialSelector, SwcQueryOptions, HelperHostSet } from '../types';
3
3
 
4
- export interface AddEventListenerBaseOptions extends EventListenerOptions {
4
+ export interface AddEventListenerBaseOptions<TEvent extends Event = Event> extends EventListenerOptions {
5
5
  capture?: boolean;
6
6
  once?: boolean;
7
7
  passive?: boolean;
@@ -11,27 +11,33 @@ export interface AddEventListenerBaseOptions extends EventListenerOptions {
11
11
  // removeOnDisconnected?: boolean;
12
12
  delegate?: boolean;
13
13
  filter?: (target: Event | CustomEvent, meta:{currentThis: any, helper: HelperHostSet}) => boolean;
14
+ // RxJS operator options
15
+ debounceTime?: number;
16
+ throttleTime?: number;
17
+ distinctUntilChanged?: boolean | ((prev: TEvent, curr: TEvent) => boolean);
14
18
  }
15
19
 
16
- export interface AddEventListenerMetadata {
20
+ export type EventListenerSelector = string | ((currentThis: any, helper: HelperHostSet) => NodeList | Element | Element[] | null);
21
+
22
+ export interface AddEventListenerMetadata<TEvent extends Event = Event> {
17
23
  propertyKey: string | symbol;
18
- selector: string;
24
+ selector: EventListenerSelector;
19
25
  type: string;
20
- options: AddEventListenerBaseOptions & SwcQueryOptions & { delegate?: boolean };
26
+ options: AddEventListenerBaseOptions<TEvent> & SwcQueryOptions & { delegate?: boolean };
21
27
  }
22
28
 
23
29
  export const ADD_EVENT_LISTENER_METADATA_KEY = Symbol.for('simple-web-component:add-event-listener');
24
30
 
25
- export function addEventListener(target: SpecialSelector, type: string, options?: AddEventListenerBaseOptions): MethodDecorator;
26
- export function addEventListener(selector: string, type: string, options?: AddEventListenerBaseOptions & SwcQueryOptions & { delegate?: boolean }): MethodDecorator;
31
+ export function addEventListener<TEvent extends Event = Event>(target: SpecialSelector, type: string, options?: AddEventListenerBaseOptions<TEvent>): MethodDecorator;
32
+ export function addEventListener<TEvent extends Event = Event>(selector: EventListenerSelector, type: string, options?: AddEventListenerBaseOptions<TEvent> & SwcQueryOptions & { delegate?: boolean }): MethodDecorator;
27
33
  /**
28
34
  * @addEventListener decorator to bind events to elements.
29
35
  */
30
- export function addEventListener(selectorOrTarget: string, type: string, options: any = {}): MethodDecorator {
36
+ export function addEventListener<TEvent extends Event = Event>(selectorOrTarget: EventListenerSelector, type: string, options: any = {}): MethodDecorator {
31
37
  return (targetObj: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {
32
38
  const constructor = targetObj.constructor;
33
39
 
34
- let listeners = ReflectUtils.getMetadata<AddEventListenerMetadata[]>(ADD_EVENT_LISTENER_METADATA_KEY, constructor);
40
+ let listeners = ReflectUtils.getMetadata<AddEventListenerMetadata<TEvent>[]>(ADD_EVENT_LISTENER_METADATA_KEY, constructor);
35
41
  if (!listeners) {
36
42
  listeners = [];
37
43
  ReflectUtils.defineMetadata(ADD_EVENT_LISTENER_METADATA_KEY, listeners, constructor);
@@ -42,18 +48,18 @@ export function addEventListener(selectorOrTarget: string, type: string, options
42
48
  }
43
49
 
44
50
 
45
- export function addEventListenerDelegateLightDom(selector: string, type: string, options?: Omit<AddEventListenerBaseOptions, 'delegate'>): MethodDecorator {
46
- return addEventListener(selector, type, {...options??{}, root:'light', delegate: true});
51
+ export function addEventListenerDelegateLightDom<TEvent extends Event = Event>(selector: EventListenerSelector, type: string, options?: Omit<AddEventListenerBaseOptions<TEvent>, 'delegate'>): MethodDecorator {
52
+ return addEventListener<TEvent>(selector, type, {...options??{}, root:'light', delegate: true});
47
53
  }
48
54
 
49
- export function addEventListenerDelegateShadowDom(selector: string, type: string, options?: Omit<AddEventListenerBaseOptions, 'delegate'>): MethodDecorator {
50
- return addEventListener(selector, type, {...options??{}, root:'shadow', delegate: true});
55
+ export function addEventListenerDelegateShadowDom<TEvent extends Event = Event>(selector: EventListenerSelector, type: string, options?: Omit<AddEventListenerBaseOptions<TEvent>, 'delegate'>): MethodDecorator {
56
+ return addEventListener<TEvent>(selector, type, {...options??{}, root:'shadow', delegate: true});
51
57
  }
52
- export function addEventListenerDelegateAllDom(selector: string, type: string, options?: Omit<AddEventListenerBaseOptions, 'delegate'>): MethodDecorator {
53
- return addEventListener(selector, type, {...options??{}, root:'all', delegate: true});
58
+ export function addEventListenerDelegateAllDom<TEvent extends Event = Event>(selector: EventListenerSelector, type: string, options?: Omit<AddEventListenerBaseOptions<TEvent>, 'delegate'>): MethodDecorator {
59
+ return addEventListener<TEvent>(selector, type, {...options??{}, root:'all', delegate: true});
54
60
  }
55
- export function addEventListenerDelegate(selector: string, type: string, options?: Omit<AddEventListenerBaseOptions, 'delegate'>): MethodDecorator {
56
- return addEventListener(selector, type, {...options??{}, root:'auto', delegate: true});
61
+ export function addEventListenerDelegate<TEvent extends Event = Event>(selector: EventListenerSelector, type: string, options?: Omit<AddEventListenerBaseOptions<TEvent>, 'delegate'>): MethodDecorator {
62
+ return addEventListener<TEvent>(selector, type, {...options??{}, root:'auto', delegate: true});
57
63
  }
58
64
 
59
65
  /**
@@ -66,25 +72,25 @@ export const eventDelegateLightDom = addEventListenerDelegateLightDom;
66
72
  export const eventDelegateShadowDom = addEventListenerDelegateShadowDom;
67
73
  export const eventDelegateAllDom = addEventListenerDelegateAllDom;
68
74
  export const eventDelegate = addEventListenerDelegate;
69
- export function addEventListenerThis(type: string, options?: AddEventListenerBaseOptions & SwcQueryOptions): MethodDecorator {
70
- return addEventListener('$this', type, options);
75
+ export function addEventListenerThis<TEvent extends Event = Event>(type: string, options?: AddEventListenerBaseOptions<TEvent> & SwcQueryOptions): MethodDecorator {
76
+ return addEventListener<TEvent>('$this', type, options);
71
77
  }
72
78
 
73
79
  /**
74
80
  * @addEventListenerAppHost decorator - simplified version of @addEventListener for $appHost selector
75
81
  */
76
- export function addEventListenerAppHost(type: string, options?: AddEventListenerBaseOptions & SwcQueryOptions): MethodDecorator {
77
- return addEventListener('$appHost', type, options);
82
+ export function addEventListenerAppHost<TEvent extends Event = Event>(type: string, options?: AddEventListenerBaseOptions<TEvent> & SwcQueryOptions): MethodDecorator {
83
+ return addEventListener<TEvent>('$appHost', type, options);
78
84
  }
79
85
 
80
- export function addEventListenerWindow(type: string, options?: AddEventListenerBaseOptions & SwcQueryOptions): MethodDecorator {
81
- return addEventListener('$window', type, options);
86
+ export function addEventListenerWindow<TEvent extends Event = Event>(type: string, options?: AddEventListenerBaseOptions<TEvent> & SwcQueryOptions): MethodDecorator {
87
+ return addEventListener<TEvent>('$window', type, options);
82
88
  }
83
- export function addEventListenerDocument(type: string, options?: AddEventListenerBaseOptions & SwcQueryOptions): MethodDecorator {
84
- return addEventListener('$document', type, options);
89
+ export function addEventListenerDocument<TEvent extends Event = Event>(type: string, options?: AddEventListenerBaseOptions<TEvent> & SwcQueryOptions): MethodDecorator {
90
+ return addEventListener<TEvent>('$document', type, options);
85
91
  }
86
92
 
87
- export const getAddEventListenerMetadata = (target: any): AddEventListenerMetadata[] | undefined => {
93
+ export const getAddEventListenerMetadata = (target: any): AddEventListenerMetadata<Event>[] | undefined => {
88
94
  const constructor = target instanceof Function ? target : target.constructor;
89
95
  return ReflectUtils.getMetadata(ADD_EVENT_LISTENER_METADATA_KEY, constructor);
90
96
  };
@@ -40,9 +40,11 @@ export interface AttributeOptions extends SwcQueryOptions {
40
40
  valueKey?: symbol | string;
41
41
  }
42
42
 
43
+ export type AttributeSelector = string | ((currentThis: any, helper: HelperHostSet) => NodeList | Element | Element[] | null);
44
+
43
45
  export interface AttributeMetadata {
44
46
  propertyKey: string | symbol;
45
- selector: string;
47
+ selector: AttributeSelector;
46
48
  targetAttributeName: string;
47
49
  options: AttributeOptions;
48
50
  type: 'property' | 'method';
@@ -54,6 +56,36 @@ export const ATTRIBUTE_METADATA_KEY = Symbol.for('simple-web-component:attribute
54
56
  // Utilities
55
57
  // ============================================
56
58
 
59
+ /**
60
+ * Determine if a string is a CSS selector or an attribute name
61
+ *
62
+ * CSS selectors typically:
63
+ * - Start with: #, ., [, :, >, +, ~
64
+ * - Contain special chars: >, +, ~, :, [, ]
65
+ * - Are special keywords: $this, $host, $parentHost, etc.
66
+ *
67
+ * Attribute names are typically:
68
+ * - kebab-case (lowercase with hyphens)
69
+ * - No special selector syntax
70
+ *
71
+ * @param str - String to check
72
+ * @returns true if it's a CSS selector, false if it's an attribute name
73
+ */
74
+ const isCssSelector = (str: string): boolean => {
75
+ if (!str) return false;
76
+
77
+ // Special keywords
78
+ if (str.startsWith('$')) return true;
79
+
80
+ // CSS selector syntax
81
+ if (/^[#.\[\:>+~]/.test(str)) return true;
82
+
83
+ // Contains CSS combinator or pseudo-selector syntax
84
+ if (/[>+~:\[\]]/.test(str)) return true;
85
+
86
+ return false;
87
+ };
88
+
57
89
  const convertValue = (val: string | null, type: any): any => {
58
90
  if (val === null || val === undefined) return val;
59
91
  if (type === Number) return Number(val);
@@ -63,7 +95,7 @@ const convertValue = (val: string | null, type: any): any => {
63
95
 
64
96
  export {convertValue};
65
97
 
66
- export const getAttributeValue = (inst: any, attrName: string, options?: AttributeOptions & { selector?: string }): any => {
98
+ export const getAttributeValue = (inst: any, attrName: string, options?: AttributeOptions & { selector?: AttributeSelector }): any => {
67
99
  const conf = getElementConfig(inst);
68
100
  const currentWin = inst._resolveWindow?.(conf) || ((typeof window !== 'undefined' ? window : undefined) as any);
69
101
 
@@ -101,15 +133,42 @@ export const getAttributeValue = (inst: any, attrName: string, options?: Attribu
101
133
 
102
134
  /**
103
135
  * Resolve target elements based on selector and options
104
- * Handles special selectors ($this, $host, etc.) and CSS selectors
136
+ * Handles special selectors ($this, $host, etc.), CSS selectors, and function-based selectors
105
137
  * Returns HTMLElement[] for attribute operations
106
138
  */
107
- export const resolveAttributeTargets = (inst: any, selector: string, options: AttributeOptions): HTMLElement[] => {
139
+ export const resolveAttributeTargets = (inst: any, selector: AttributeSelector, options: AttributeOptions): HTMLElement[] => {
108
140
  const conf = getElementConfig(inst);
109
141
  const currentWin = conf.window;
110
142
  const r = options.root || 'auto';
111
143
  const results: HTMLElement[] = [];
112
144
 
145
+ // Resolve selector if it's a function
146
+ let resolvedSelector: string | Element | NodeList | Element[] | null = selector as any;
147
+ if (typeof selector === 'function') {
148
+ const hostSet = SwcUtils.getHelperAndHostSet(currentWin, inst);
149
+ resolvedSelector = selector(inst, hostSet);
150
+ }
151
+
152
+ // If selector function returned elements directly, use them
153
+ if (resolvedSelector instanceof currentWin.Element) {
154
+ results.push(resolvedSelector as HTMLElement);
155
+ return results;
156
+ }
157
+ if (resolvedSelector instanceof currentWin.NodeList) {
158
+ results.push(...(Array.from(resolvedSelector) as HTMLElement[]));
159
+ return results;
160
+ }
161
+ if (Array.isArray(resolvedSelector)) {
162
+ results.push(...(resolvedSelector as HTMLElement[]));
163
+ return results;
164
+ }
165
+ if (resolvedSelector === null) {
166
+ return results;
167
+ }
168
+
169
+ // Handle string selector
170
+ const stringSelector = resolvedSelector as string;
171
+
113
172
  const applyRoot = (target: any) => {
114
173
  if (!target) return;
115
174
  if (r === 'auto') {
@@ -120,33 +179,33 @@ export const resolveAttributeTargets = (inst: any, selector: string, options: At
120
179
  }
121
180
  };
122
181
 
123
- if (selector === '$this' || !selector) {
182
+ if (stringSelector === '$this' || !stringSelector) {
124
183
  applyRoot(inst);
125
184
  } else {
126
185
  const hostSet = SwcUtils.getHostSet(inst);
127
- if (selector === '$host') applyRoot(hostSet.$host);
128
- else if (selector === '$parentHost') applyRoot(hostSet.$parentHost);
129
- else if (selector === '$appHost') applyRoot(hostSet.$appHost as any);
130
- else if (selector === '$firstHost') applyRoot(hostSet.$firstHost);
131
- else if (selector === '$lastHost') applyRoot(hostSet.$lastHost);
132
- else if (selector === '$firstAppHost') applyRoot(hostSet.$firstAppHost as any);
133
- else if (selector === '$lastAppHost') applyRoot(hostSet.$lastAppHost as any);
134
- else if (selector === '$hosts') hostSet.$hosts.forEach(applyRoot);
135
- else if (selector === '$appHosts') hostSet.$appHosts.forEach(applyRoot);
186
+ if (stringSelector === '$host') applyRoot(hostSet.$host);
187
+ else if (stringSelector === '$parentHost') applyRoot(hostSet.$parentHost);
188
+ else if (stringSelector === '$appHost') applyRoot(hostSet.$appHost as any);
189
+ else if (stringSelector === '$firstHost') applyRoot(hostSet.$firstHost);
190
+ else if (stringSelector === '$lastHost') applyRoot(hostSet.$lastHost);
191
+ else if (stringSelector === '$firstAppHost') applyRoot(hostSet.$firstAppHost as any);
192
+ else if (stringSelector === '$lastAppHost') applyRoot(hostSet.$lastAppHost as any);
193
+ else if (stringSelector === '$hosts') hostSet.$hosts.forEach(applyRoot);
194
+ else if (stringSelector === '$appHosts') hostSet.$appHosts.forEach(applyRoot);
136
195
  else {
137
196
  if (r === 'shadow') {
138
- const found = inst.shadowRoot?.querySelectorAll(selector);
197
+ const found = inst.shadowRoot?.querySelectorAll(stringSelector);
139
198
  if (found) results.push(...found);
140
199
  } else if (r === 'light') {
141
- const found = inst.querySelectorAll(selector);
200
+ const found = inst.querySelectorAll(stringSelector);
142
201
  if (found) results.push(...found);
143
202
  } else if (r === 'all') {
144
- const sMatch = inst.shadowRoot?.querySelectorAll(selector);
145
- const lMatch = inst.querySelectorAll(selector);
203
+ const sMatch = inst.shadowRoot?.querySelectorAll(stringSelector);
204
+ const lMatch = inst.querySelectorAll(stringSelector);
146
205
  if (sMatch) results.push(...sMatch);
147
206
  if (lMatch) results.push(...lMatch);
148
207
  } else {
149
- const found = (inst.shadowRoot || inst).querySelectorAll(selector);
208
+ const found = (inst.shadowRoot || inst).querySelectorAll(stringSelector);
150
209
  if (found) results.push(...found);
151
210
  }
152
211
  }
@@ -161,11 +220,12 @@ export const resolveAttributeTargets = (inst: any, selector: string, options: At
161
220
  * - @applyAttribute('selector', 'attrName') - Set attribute with explicit name
162
221
  * - @applyAttribute('selector') - Use property name as attribute name
163
222
  * - @applyAttribute('selector', { name: 'attrName' }) - Set attribute via options
223
+ * - @applyAttribute((this, helper) => 'selector', 'attrName') - Function-based selector
164
224
  * - Return null to remove attribute
165
225
  */
166
- export function applyAttribute(selector: string, targetAttributeName: string, options?: AttributeOptions): MethodDecorator & PropertyDecorator;
167
- export function applyAttribute(selector: string, options?: AttributeOptions): MethodDecorator & PropertyDecorator;
168
- export function applyAttribute(selector: string, targetAttributeNameOrOptions?: string | AttributeOptions, options?: AttributeOptions): MethodDecorator & PropertyDecorator {
226
+ export function applyAttribute(selector: AttributeSelector, targetAttributeName: string, options?: AttributeOptions): MethodDecorator & PropertyDecorator;
227
+ export function applyAttribute(selector: AttributeSelector, options?: AttributeOptions): MethodDecorator & PropertyDecorator;
228
+ export function applyAttribute(selector: AttributeSelector, targetAttributeNameOrOptions?: string | AttributeOptions, options?: AttributeOptions): MethodDecorator & PropertyDecorator {
169
229
  return (target: Object, propertyKey: string | symbol, descriptor?: PropertyDescriptor) => {
170
230
  // ensureInit(target as any);
171
231
 
@@ -198,7 +258,7 @@ export function applyAttribute(selector: string, targetAttributeNameOrOptions?:
198
258
  }
199
259
  metaList.push({
200
260
  propertyKey,
201
- selector,
261
+ selector: selector as AttributeSelector,
202
262
  targetAttributeName,
203
263
  options: finalOptions,
204
264
  type: metaType
@@ -307,77 +367,95 @@ export function applyAttribute(selector: string, targetAttributeNameOrOptions?:
307
367
  // ============================================
308
368
 
309
369
  /**
310
- * @attribute - Alias for @applyAttribute
311
- */
312
- export function attribute(selector: string, targetAttributeName: string, options?: AttributeOptions): MethodDecorator & PropertyDecorator;
313
- export function attribute(selector: string, options?: AttributeOptions): MethodDecorator & PropertyDecorator;
314
- export function attribute(selector: string, targetAttributeNameOrOptions?: string | AttributeOptions, options?: AttributeOptions): MethodDecorator & PropertyDecorator {
315
- return applyAttribute(selector, targetAttributeNameOrOptions as any, options);
316
- }
317
-
318
- /**
319
- * @attributeThis - Apply attribute on $this element
320
- * Can be used as: @attributeThis or @attributeThis('attrName') or @attributeThis({ name: 'attrName' })
370
+ * @attribute - Field decorator for binding element attributes (read/write)
371
+ *
372
+ * Intelligently distinguishes between attribute names and CSS selectors:
373
+ *
374
+ * Usage patterns:
375
+ * - @attribute('product-id') - Attribute name on $this (auto-detected)
376
+ * - @attribute('#user', 'product-id') - Attribute name on selector
377
+ * - @attribute('product-id', options) - Attribute name on $this with options
378
+ * - @attribute('#user', 'product-id', options) - Attribute name on selector with options
379
+ * - @attribute((this, helper) => 'selector', 'product-id') - Function-based selector
380
+ * - @attribute - Bare decorator (uses property name as attribute on $this)
381
+ *
382
+ * Note: This decorator is for FIELDS ONLY. For methods, use @setAttribute.
321
383
  */
322
- export function attributeThis(target: Object, propertyKey: string | symbol): void;
323
- export function attributeThis(targetAttributeName: string, options?: AttributeOptions): MethodDecorator & PropertyDecorator;
324
- export function attributeThis(options?: AttributeOptions): MethodDecorator & PropertyDecorator;
325
- export function attributeThis(targetOrOptions?: any, propertyKeyOrOptions?: any, descriptor?: PropertyDescriptor): any {
326
- // Direct decorator usage: @attributeThis
327
- if (typeof targetOrOptions === 'object' && targetOrOptions !== null && !Array.isArray(targetOrOptions) &&
328
- typeof propertyKeyOrOptions === 'string' || typeof propertyKeyOrOptions === 'symbol') {
329
- // Called as @attributeThis (target, propertyKey)
330
- return applyAttribute('$this', undefined as any, {})(targetOrOptions, propertyKeyOrOptions, descriptor);
384
+ export function attribute(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor | void;
385
+ export function attribute(attributeName: string, options?: AttributeOptions): PropertyDecorator;
386
+ export function attribute(selector: AttributeSelector, attributeName: string, options?: AttributeOptions): PropertyDecorator;
387
+ export function attribute(selectorOrAttributeOrTarget?: AttributeSelector | Object, attributeNameOrOptions?: any, optionsOrDescriptor?: any): any {
388
+ // Bare decorator: @attribute
389
+ if (optionsOrDescriptor !== undefined && (typeof attributeNameOrOptions === 'string' || typeof attributeNameOrOptions === 'symbol')) {
390
+ return applyAttribute('$this', undefined as any, {})(selectorOrAttributeOrTarget as Object, attributeNameOrOptions, optionsOrDescriptor as PropertyDescriptor);
331
391
  }
332
-
333
- // Called with parameters
334
- if (typeof targetOrOptions === 'string') {
335
- // @attributeThis('attrName', options?)
336
- return applyAttribute('$this', targetOrOptions, propertyKeyOrOptions);
337
- } else if (targetOrOptions && typeof targetOrOptions === 'object') {
338
- // @attributeThis({ name: 'attrName' })
339
- return applyAttribute('$this', undefined as any, targetOrOptions);
340
- } else {
341
- // @attributeThis() or @attributeThis
342
- return applyAttribute('$this', undefined as any, {});
392
+
393
+ // With string as first parameter
394
+ if (typeof selectorOrAttributeOrTarget === 'string') {
395
+ // Check if first parameter is a CSS selector or attribute name
396
+ const isSelector = isCssSelector(selectorOrAttributeOrTarget);
397
+
398
+ if (isSelector) {
399
+ // First param is a selector: @attribute('#user', 'product-id', options?)
400
+ return applyAttribute(selectorOrAttributeOrTarget, attributeNameOrOptions as any, optionsOrDescriptor as AttributeOptions);
401
+ } else {
402
+ // First param is an attribute name: @attribute('product-id', options?)
403
+ // Treat as attribute name on $this
404
+ const options = (typeof attributeNameOrOptions === 'object' && attributeNameOrOptions !== null)
405
+ ? attributeNameOrOptions
406
+ : {};
407
+ return applyAttribute('$this', selectorOrAttributeOrTarget, options);
408
+ }
343
409
  }
410
+
411
+ // Without selector (defaults to $this with options)
412
+ return applyAttribute('$this', undefined as any, selectorOrAttributeOrTarget as AttributeOptions);
344
413
  }
345
414
 
346
415
  /**
347
- * @setAttribute - Alias for @applyAttribute (method-decorator semantics)
416
+ * @setAttribute - Method decorator for setting element attributes from method return value
417
+ *
418
+ * Intelligently distinguishes between attribute names and CSS selectors:
419
+ *
420
+ * Usage patterns:
421
+ * - @setAttribute('data-id') - Attribute name on $this (auto-detected)
422
+ * - @setAttribute('#user', 'data-id') - Attribute name on selector
423
+ * - @setAttribute('data-id', options) - Attribute name on $this with options
424
+ * - @setAttribute('#user', 'data-id', options) - Attribute name on selector with options
425
+ * - @setAttribute((this, helper) => 'selector', 'data-id') - Function-based selector
426
+ * - @setAttribute - Bare decorator (uses method name as attribute on $this)
427
+ *
428
+ * Note: This decorator is for METHODS ONLY. For fields, use @attribute.
429
+ *
430
+ * Example:
431
+ * @setAttribute('data-status')
432
+ * updateStatus() {
433
+ * return 'active';
434
+ * }
348
435
  */
349
- export function setAttribute(selector: string, targetAttributeName: string, options?: AttributeOptions): MethodDecorator;
350
- export function setAttribute(selector: string, options?: AttributeOptions): MethodDecorator;
351
- export function setAttribute(selector: string, targetAttributeNameOrOptions?: string | AttributeOptions, options?: AttributeOptions): MethodDecorator {
352
- return applyAttribute(selector, targetAttributeNameOrOptions as any, options) as MethodDecorator;
353
- }
354
-
355
- /**
356
- * @setAttributeThis - Set attribute on $this element
357
- * Can be used as: @setAttributeThis or @setAttributeThis('attrName') or @setAttributeThis({ name: 'attrName' })
358
- */
359
- export function setAttributeThis(target: Object, propertyKey: string | symbol): void;
360
- export function setAttributeThis(targetAttributeName: string, options?: AttributeOptions): MethodDecorator;
361
- export function setAttributeThis(options?: AttributeOptions): MethodDecorator;
362
- export function setAttributeThis(targetOrOptions?: any, propertyKeyOrOptions?: any, descriptor?: PropertyDescriptor): any {
363
- // Direct decorator usage: @setAttributeThis
364
- if (typeof targetOrOptions === 'object' && targetOrOptions !== null && !Array.isArray(targetOrOptions) &&
365
- (typeof propertyKeyOrOptions === 'string' || typeof propertyKeyOrOptions === 'symbol')) {
366
- // Called as @setAttributeThis (target, propertyKey)
367
- return applyAttribute('$this', undefined as any, {})(targetOrOptions, propertyKeyOrOptions, descriptor);
368
- }
369
-
370
- // Called with parameters
371
- if (typeof targetOrOptions === 'string') {
372
- // @setAttributeThis('attrName', options?)
373
- return applyAttribute('$this', targetOrOptions, propertyKeyOrOptions) as MethodDecorator;
374
- } else if (targetOrOptions && typeof targetOrOptions === 'object') {
375
- // @setAttributeThis({ name: 'attrName' })
376
- return applyAttribute('$this', undefined as any, targetOrOptions) as MethodDecorator;
377
- } else {
378
- // @setAttributeThis() or @setAttributeThis
379
- return applyAttribute('$this', undefined as any, {}) as MethodDecorator;
436
+ export function setAttribute(selector: AttributeSelector, attributeName: string, options?: AttributeOptions): MethodDecorator;
437
+ export function setAttribute(attributeName: string, options?: AttributeOptions): MethodDecorator;
438
+ export function setAttribute(selectorOrAttributeOrOptions?: AttributeSelector | AttributeOptions, attributeNameOrOptions?: any, optionsOrUndefined?: AttributeOptions): MethodDecorator {
439
+ // With string as first parameter
440
+ if (typeof selectorOrAttributeOrOptions === 'string') {
441
+ // Check if first parameter is a CSS selector or attribute name
442
+ const isSelector = isCssSelector(selectorOrAttributeOrOptions);
443
+
444
+ if (isSelector) {
445
+ // First param is a selector: @setAttribute('#user', 'data-id', options?)
446
+ return applyAttribute(selectorOrAttributeOrOptions, attributeNameOrOptions as any, optionsOrUndefined as AttributeOptions) as MethodDecorator;
447
+ } else {
448
+ // First param is an attribute name: @setAttribute('data-id', options?)
449
+ // Treat as attribute name on $this
450
+ const options = (typeof attributeNameOrOptions === 'object' && attributeNameOrOptions !== null)
451
+ ? attributeNameOrOptions
452
+ : {};
453
+ return applyAttribute('$this', selectorOrAttributeOrOptions, options) as MethodDecorator;
454
+ }
380
455
  }
456
+
457
+ // Without selector (defaults to $this with options)
458
+ return applyAttribute('$this', undefined as any, selectorOrAttributeOrOptions as AttributeOptions) as MethodDecorator;
381
459
  }
382
460
 
383
461
  // ============================================