@dooboostore/simple-web-component 1.0.33 → 1.0.35

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 (150) hide show
  1. package/README.md +23 -30
  2. package/dist/cjs/decorators/addEventListener.js.map +1 -1
  3. package/dist/cjs/decorators/applyAttribute.js +67 -57
  4. package/dist/cjs/decorators/applyAttribute.js.map +2 -2
  5. package/dist/cjs/decorators/applyClass.js +80 -70
  6. package/dist/cjs/decorators/applyClass.js.map +2 -2
  7. package/dist/cjs/decorators/applyNode.js +5 -8
  8. package/dist/cjs/decorators/applyNode.js.map +2 -2
  9. package/dist/cjs/decorators/applyStyle.js +66 -56
  10. package/dist/cjs/decorators/applyStyle.js.map +2 -2
  11. package/dist/cjs/decorators/attribute.js +35 -29
  12. package/dist/cjs/decorators/attribute.js.map +2 -2
  13. package/dist/cjs/decorators/changedAttributeHost.js +32 -12
  14. package/dist/cjs/decorators/changedAttributeHost.js.map +2 -2
  15. package/dist/cjs/decorators/elementDefine.js +238 -180
  16. package/dist/cjs/decorators/elementDefine.js.map +2 -2
  17. package/dist/cjs/decorators/emitCustomEvent.js +67 -48
  18. package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
  19. package/dist/cjs/decorators/lifecycles.js +15 -17
  20. package/dist/cjs/decorators/lifecycles.js.map +2 -2
  21. package/dist/cjs/decorators/setProperty.js +50 -39
  22. package/dist/cjs/decorators/setProperty.js.map +2 -2
  23. package/dist/cjs/decorators/subscribeSwcAppMessageWhileConnected.js.map +1 -1
  24. package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js +2 -2
  25. package/dist/cjs/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
  26. package/dist/cjs/elements/SwcAppEngine.js +14 -8
  27. package/dist/cjs/elements/SwcAppEngine.js.map +3 -3
  28. package/dist/cjs/elements/SwcAppMixin.js +154 -81
  29. package/dist/cjs/elements/SwcAppMixin.js.map +2 -2
  30. package/dist/cjs/elements/SwcAsync.js +28 -18
  31. package/dist/cjs/elements/SwcAsync.js.map +2 -2
  32. package/dist/cjs/elements/SwcChoose.js +68 -45
  33. package/dist/cjs/elements/SwcChoose.js.map +2 -2
  34. package/dist/cjs/elements/SwcIf.js +52 -30
  35. package/dist/cjs/elements/SwcIf.js.map +2 -2
  36. package/dist/cjs/elements/SwcLoop.js +109 -35
  37. package/dist/cjs/elements/SwcLoop.js.map +2 -2
  38. package/dist/cjs/elements/register.js +263 -131
  39. package/dist/cjs/elements/register.js.map +2 -2
  40. package/dist/cjs/router/ElementRouter.js +4 -2
  41. package/dist/cjs/router/ElementRouter.js.map +1 -1
  42. package/dist/cjs/types.js.map +1 -1
  43. package/dist/cjs/utils/Utils.js +25 -7
  44. package/dist/cjs/utils/Utils.js.map +2 -2
  45. package/dist/esm/decorators/addEventListener.js.map +1 -1
  46. package/dist/esm/decorators/applyAttribute.js +67 -57
  47. package/dist/esm/decorators/applyAttribute.js.map +2 -2
  48. package/dist/esm/decorators/applyClass.js +80 -70
  49. package/dist/esm/decorators/applyClass.js.map +2 -2
  50. package/dist/esm/decorators/applyNode.js +5 -8
  51. package/dist/esm/decorators/applyNode.js.map +2 -2
  52. package/dist/esm/decorators/applyStyle.js +66 -56
  53. package/dist/esm/decorators/applyStyle.js.map +2 -2
  54. package/dist/esm/decorators/attribute.js +35 -29
  55. package/dist/esm/decorators/attribute.js.map +2 -2
  56. package/dist/esm/decorators/changedAttributeHost.js +32 -12
  57. package/dist/esm/decorators/changedAttributeHost.js.map +2 -2
  58. package/dist/esm/decorators/elementDefine.js +240 -182
  59. package/dist/esm/decorators/elementDefine.js.map +2 -2
  60. package/dist/esm/decorators/emitCustomEvent.js +67 -48
  61. package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
  62. package/dist/esm/decorators/lifecycles.js +15 -17
  63. package/dist/esm/decorators/lifecycles.js.map +2 -2
  64. package/dist/esm/decorators/setProperty.js +50 -39
  65. package/dist/esm/decorators/setProperty.js.map +2 -2
  66. package/dist/esm/decorators/subscribeSwcAppMessageWhileConnected.js.map +1 -1
  67. package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js +2 -2
  68. package/dist/esm/decorators/subscribeSwcAppRouteChangeWhileConnected.js.map +2 -2
  69. package/dist/esm/elements/SwcAppEngine.js +14 -7
  70. package/dist/esm/elements/SwcAppEngine.js.map +2 -2
  71. package/dist/esm/elements/SwcAppMixin.js +156 -82
  72. package/dist/esm/elements/SwcAppMixin.js.map +2 -2
  73. package/dist/esm/elements/SwcAsync.js +28 -18
  74. package/dist/esm/elements/SwcAsync.js.map +2 -2
  75. package/dist/esm/elements/SwcChoose.js +69 -46
  76. package/dist/esm/elements/SwcChoose.js.map +2 -2
  77. package/dist/esm/elements/SwcIf.js +53 -31
  78. package/dist/esm/elements/SwcIf.js.map +2 -2
  79. package/dist/esm/elements/SwcLoop.js +110 -36
  80. package/dist/esm/elements/SwcLoop.js.map +2 -2
  81. package/dist/esm/elements/register.js +264 -132
  82. package/dist/esm/elements/register.js.map +2 -2
  83. package/dist/esm/router/ElementRouter.js +5 -2
  84. package/dist/esm/router/ElementRouter.js.map +1 -1
  85. package/dist/esm/types.js.map +1 -1
  86. package/dist/esm/utils/Utils.js +25 -7
  87. package/dist/esm/utils/Utils.js.map +2 -2
  88. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +728 -595
  89. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
  90. package/dist/types/decorators/addEventListener.d.ts +4 -1
  91. package/dist/types/decorators/addEventListener.d.ts.map +1 -1
  92. package/dist/types/decorators/applyAttribute.d.ts +5 -1
  93. package/dist/types/decorators/applyAttribute.d.ts.map +1 -1
  94. package/dist/types/decorators/applyClass.d.ts +4 -0
  95. package/dist/types/decorators/applyClass.d.ts.map +1 -1
  96. package/dist/types/decorators/applyNode.d.ts +5 -1
  97. package/dist/types/decorators/applyNode.d.ts.map +1 -1
  98. package/dist/types/decorators/applyStyle.d.ts +5 -1
  99. package/dist/types/decorators/applyStyle.d.ts.map +1 -1
  100. package/dist/types/decorators/attribute.d.ts +5 -0
  101. package/dist/types/decorators/attribute.d.ts.map +1 -1
  102. package/dist/types/decorators/changedAttributeHost.d.ts +14 -3
  103. package/dist/types/decorators/changedAttributeHost.d.ts.map +1 -1
  104. package/dist/types/decorators/elementDefine.d.ts +1 -1
  105. package/dist/types/decorators/elementDefine.d.ts.map +1 -1
  106. package/dist/types/decorators/emitCustomEvent.d.ts +15 -7
  107. package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
  108. package/dist/types/decorators/lifecycles.d.ts +10 -7
  109. package/dist/types/decorators/lifecycles.d.ts.map +1 -1
  110. package/dist/types/decorators/setProperty.d.ts +5 -1
  111. package/dist/types/decorators/setProperty.d.ts.map +1 -1
  112. package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts +2 -2
  113. package/dist/types/decorators/subscribeSwcAppMessageWhileConnected.d.ts.map +1 -1
  114. package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts +5 -6
  115. package/dist/types/decorators/subscribeSwcAppRouteChangeWhileConnected.d.ts.map +1 -1
  116. package/dist/types/elements/SwcAppEngine.d.ts +9 -3
  117. package/dist/types/elements/SwcAppEngine.d.ts.map +1 -1
  118. package/dist/types/elements/SwcAppMixin.d.ts +12 -7
  119. package/dist/types/elements/SwcAppMixin.d.ts.map +1 -1
  120. package/dist/types/elements/register.d.ts.map +1 -1
  121. package/dist/types/types.d.ts +1 -0
  122. package/dist/types/types.d.ts.map +1 -1
  123. package/dist/types/utils/Utils.d.ts +4 -1
  124. package/dist/types/utils/Utils.d.ts.map +1 -1
  125. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +728 -595
  126. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
  127. package/package.json +5 -5
  128. package/src/decorators/addEventListener.ts +1 -1
  129. package/src/decorators/applyAttribute.ts +74 -61
  130. package/src/decorators/applyClass.ts +91 -77
  131. package/src/decorators/applyNode.ts +16 -13
  132. package/src/decorators/applyStyle.ts +75 -61
  133. package/src/decorators/attribute.ts +55 -43
  134. package/src/decorators/changedAttributeHost.ts +49 -15
  135. package/src/decorators/elementDefine.ts +401 -340
  136. package/src/decorators/emitCustomEvent.ts +92 -62
  137. package/src/decorators/lifecycles.ts +11 -10
  138. package/src/decorators/setProperty.ts +58 -44
  139. package/src/decorators/subscribeSwcAppMessageWhileConnected.ts +2 -2
  140. package/src/decorators/subscribeSwcAppRouteChangeWhileConnected.ts +11 -11
  141. package/src/elements/SwcAppEngine.ts +19 -13
  142. package/src/elements/SwcAppMixin.ts +214 -102
  143. package/src/elements/SwcAsync.ts +28 -17
  144. package/src/elements/SwcChoose.ts +94 -36
  145. package/src/elements/SwcIf.ts +59 -22
  146. package/src/elements/SwcLoop.ts +140 -27
  147. package/src/elements/register.ts +319 -100
  148. package/src/types.ts +1 -0
  149. package/src/utils/Utils.ts +38 -10
  150. package/tsconfig.json +2 -2
package/README.md CHANGED
@@ -239,7 +239,7 @@ onDisconnected() {
239
239
  }
240
240
 
241
241
 
242
- @onConnectedSwcApp
242
+ @onConnectedBefore
243
243
  onAppReady(router: Router) {
244
244
  // Called after SwcApp.connect() completes on all already-connected components
245
245
  // Full DI support available through hostSet
@@ -300,18 +300,15 @@ class StatusDisplay extends HTMLElement {
300
300
  render() {
301
301
  return `
302
302
  <template id="status-template" is="swc-choose">
303
- <!-- Pending State: Using {{ }} for condition -->
304
- <template is="swc-when" value="{{ $value === 'pending' }}">
303
+ <template is="swc-when" test="$value === 'pending'">
305
304
  <div style="color: orange;">⏳ Processing...</div>
306
305
  </template>
307
306
 
308
- <!-- Success State: Using {{ }} for condition -->
309
- <template is="swc-when" value="{{ $value === 'success' }}">
307
+ <template is="swc-when" test="$value === 'success'">
310
308
  <div style="color: green;">✓ Completed</div>
311
309
  </template>
312
310
 
313
- <!-- Error State: Using {{ }} for condition -->
314
- <template is="swc-when" value="{{ $value === 'error' }}">
311
+ <template is="swc-when" test="$value === 'error'">
315
312
  <div style="color: red;">✗ Failed</div>
316
313
  </template>
317
314
 
@@ -326,7 +323,6 @@ class StatusDisplay extends HTMLElement {
326
323
  ```
327
324
 
328
325
  **Expression Features:**
329
- - `{{ }} braces` for dynamic condition evaluation
330
326
  - `$value` contains the value passed to `swc-choose`
331
327
  - `skip-if-same` attribute prevents re-render when same template selected
332
328
  - **Attribute substitution with `{{= }}`**: `attribute-name="{{= expression }}"` automatically evaluated
@@ -334,7 +330,7 @@ class StatusDisplay extends HTMLElement {
334
330
  **Attribute Substitution Example ({{= }} usage):**
335
331
  ```html
336
332
  <template is="swc-choose">
337
- <template is="swc-when" value="{{ $value?.type === 'user' }}">
333
+ <template is="swc-when" test="$value?.type === 'user'">
338
334
  <user-card
339
335
  data-username="{{= $value?.name }}"
340
336
  data-email="{{= $value?.email }}"
@@ -342,7 +338,7 @@ class StatusDisplay extends HTMLElement {
342
338
  ></user-card>
343
339
  </template>
344
340
 
345
- <template is="swc-when" value="{{ $value?.type === 'product' }}">
341
+ <template is="swc-when" value="$value?.type === 'product'">
346
342
  <product-card
347
343
  data-product-name="{{= $value?.title }}"
348
344
  data-price="{{= $value?.price }}"
@@ -499,7 +495,7 @@ class ProductList extends HTMLElement {
499
495
  <div style="margin: 10px; padding: 10px; border: 1px solid #ddd;">
500
496
  <!-- Using {{ }} for template content rendering -->
501
497
  <h3>{{ $item.name }}</h3>
502
- <p>Price: ${{ $item.price }}</p>
498
+ <p>Price: {{ $item.price }}</p>
503
499
  <p>ID: {{ $item.id }} (Index: {{ $index }})</p>
504
500
 
505
501
  <!-- Using {{= }} for dynamic attribute substitution -->
@@ -512,7 +508,7 @@ class ProductList extends HTMLElement {
512
508
 
513
509
  <!-- Computed expressions with {{= }} -->
514
510
  <button data-id="{{= $item.id }}" data-price="{{= $item.price }}">
515
- Add to Cart - \${{= $item.price }}
511
+ Add to Cart - {{ $item.price }}
516
512
  </button>
517
513
  </div>
518
514
 
@@ -561,7 +557,7 @@ class ProductList extends HTMLElement {
561
557
  </template>
562
558
  ```
563
559
 
564
- **Advanced: replace-wrap for Custom Expression Syntax**
560
+ **Advanced: replace-wrap-start replace-wrap-end for Custom Expression Syntax**
565
561
 
566
562
  Override default `{{ }}` and `{{= }}` syntax with custom wrappers:
567
563
 
@@ -574,10 +570,10 @@ class CustomLoop extends HTMLElement {
574
570
  render() {
575
571
  return `
576
572
  <!-- Using custom wrapper syntax [(= ... )] instead of {{= ... }} -->
577
- <template id="items" is="swc-loop" replace-wrap="[(= )]" value="[(= $host.items )]">
573
+ <template id="items" is="swc-loop" replace-wrap-start="[(" replace-wrap-end=")]" value="{{= $host.items }}">
578
574
  <div>
579
- <p>Name: [(= $item.name )]</p>
580
- <button data-id="[(= $item.id )]">Click me</button>
575
+ <p>Name: [( $item.name )]</p>
576
+ <button data-id="[( $item.id )]">Click me</button>
581
577
  </div>
582
578
  </template>
583
579
  `;
@@ -586,10 +582,8 @@ class CustomLoop extends HTMLElement {
586
582
  ```
587
583
 
588
584
  **replace-wrap attribute options:**
589
- - Change expression wrapper from default `{{= }}` to custom pattern
590
- - Useful when `{{ }}` conflicts with template engines like EJS or Mustache
585
+ - Change expression wrapper from default `{#{ }#}` to custom pattern
591
586
  - Supported on: `SwcLoop`, `SwcChoose`, `SwcIf`, `SwcAsync`, `register()` directives
592
- - Example patterns: `[(= )]`, `{[= ]}`, `<%= %>` (after escaping)
593
587
 
594
588
  ---
595
589
 
@@ -621,23 +615,22 @@ class RootRouter extends HTMLElement {
621
615
  render() {
622
616
  return `
623
617
  <template id="router" is="swc-choose">
624
- <!-- Home Page: Using {{ }} for condition -->
625
- <template is="swc-when" value="{{ ['', '/'].includes($value?.path) }}">
618
+ <template is="swc-when" test="['', '/'].includes($value?.path)">
626
619
  <home-page/>
627
620
  </template>
628
621
 
629
622
  <!-- Users List Page -->
630
- <template is="swc-when" value="{{ $value?.path === '/users' }}">
623
+ <template is="swc-when" test="$value?.path === '/users'">
631
624
  <users-list-page/>
632
625
  </template>
633
626
 
634
627
  <!-- User Detail Page: Using {{= }} for dynamic attributes from route params -->
635
- <template is="swc-when" value="{{ $value?.path.startsWith('/users/') }}">
628
+ <template is="swc-when" test="$value?.path.startsWith('/users/')">
636
629
  <user-detail-page user-id="{{= $value?.pathData?.id }}"></user-detail-page>
637
630
  </template>
638
631
 
639
632
  <!-- Product Detail Page: Using {{= }} for dynamic route parameters -->
640
- <template is="swc-when" value="{{ $value?.path.startsWith('/products/') }}">
633
+ <template is="swc-when" test="$value?.path.startsWith('/products/')">
641
634
  <product-detail-page product-id="{{= $value?.pathData?.id }}"></product-detail-page>
642
635
  </template>
643
636
 
@@ -900,17 +893,17 @@ const rootRouterFactory = (w: Window) => {
900
893
  return `
901
894
  <template id="router" is="swc-choose">
902
895
  <!-- Home Page -->
903
- <template is="swc-when" value="{{ ['', '/'].includes($value?.path) }}">
896
+ <template is="swc-when" test="['', '/'].includes($value?.path)">
904
897
  <home-page/>
905
898
  </template>
906
899
 
907
900
  <!-- Users List -->
908
- <template is="swc-when" value="{{ $value?.path === '/users' }}">
901
+ <template is="swc-when" test="$value?.path === '/users'">
909
902
  <users-list-page/>
910
903
  </template>
911
904
 
912
905
  <!-- User Detail -->
913
- <template is="swc-when" value="{{ $value?.path.startsWith('/users/') }}">
906
+ <template is="swc-when" test="$value?.path.startsWith('/users/')">
914
907
  <user-detail-page user-id="{{$value?.pathData?.id}}"/>
915
908
  </template>
916
909
 
@@ -965,7 +958,7 @@ export default HomePage;
965
958
 
966
959
  ```typescript
967
960
  // pages/UsersListPage.ts
968
- import { elementDefine, onConnectedInnerHtml, onConnectedSwcApp } from '@dooboostore/simple-web-component';
961
+ import { elementDefine, onConnectedInnerHtml, onConnectedBefore } from '@dooboostore/simple-web-component';
969
962
  import { Inject } from '@dooboostore/simple-boot';
970
963
  import { UserService } from '../services/UserService';
971
964
 
@@ -978,7 +971,7 @@ const UsersListPage = (w: Window) => {
978
971
  class UsersListPage extends w.HTMLElement {
979
972
  private users: any[] = [];
980
973
 
981
- @onConnectedSwcApp
974
+ @onConnectedBefore
982
975
  onconstructor(@Inject({ symbol: UserService.SYMBOL }) userService: UserService) {
983
976
  this.users = userService.getAllUsers();
984
977
  }
@@ -1173,7 +1166,7 @@ src/
1173
1166
  6. `<root-router>` becomes active with `@subscribeSwcAppRouteChangeWhileConnected` + `swc-choose` template
1174
1167
  7. Route changes automatically trigger `swc-choose` re-evaluation and template re-rendering
1175
1168
  8. Template attributes like `user-id="{{$value?.pathData?.id}}"` are dynamically populated with route params
1176
- 9. All components have access to injected services via `@onInitialize` or `@onConnectedSwcApp`
1169
+ 9. All components have access to injected services via `@onInitialize`
1177
1170
 
1178
1171
 
1179
1172
  ---
@@ -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 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, helper: HelperHostSet) => boolean;\n}\n\nexport interface AddEventListenerMetadata {\n propertyKey: string | symbol;\n selector: string;\n type: string;\n options: AddEventListenerBaseOptions & SwcQueryOptions & { delegate?: boolean };\n}\n\nexport const ADD_EVENT_LISTENER_METADATA_KEY = Symbol.for('simple-web-component:add-event-listener');\n\nexport function addEventListener(target: SpecialSelector, type: string, options?: AddEventListenerBaseOptions): MethodDecorator;\nexport function addEventListener(selector: string, type: string, options?: AddEventListenerBaseOptions & SwcQueryOptions & { delegate?: boolean }): MethodDecorator;\n/**\n * @addEventListener decorator to bind events to elements.\n */\nexport function addEventListener(selectorOrTarget: string, 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[]>(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\nexport const getAddEventListenerMetadata = (target: any): AddEventListenerMetadata[] | undefined => {\n const constructor = target instanceof Function ? target : target.constructor;\n return ReflectUtils.getMetadata(ADD_EVENT_LISTENER_METADATA_KEY, constructor);\n};\n\n/**\n * @addEventListenerHost decorator - simplified version of @addEventListener for :host selector\n * Usage: @addEventListenerHost('click')\n * Usage: @addEventListenerHost('click', { stopPropagation: true })\n */\nexport function addEventListenerHost(type: string, options?: AddEventListenerBaseOptions & SwcQueryOptions): MethodDecorator {\n return addEventListener(':host', type, options);\n}\n\n/**\n * @addEventListenerAppHost decorator - simplified version of @addEventListener for :appHost selector\n * Usage: @addEventListenerAppHost('click')\n * Usage: @addEventListenerAppHost('click', { stopPropagation: true })\n */\nexport function addEventListenerAppHost(type: string, options?: AddEventListenerBaseOptions & SwcQueryOptions): MethodDecorator {\n return addEventListener(':appHost', type, options);\n}\n"],
4
+ "sourcesContent": ["import { ReflectUtils } from '@dooboostore/core';\nimport { SpecialSelector, SwcQueryOptions, HelperHostSet } from '../types';\n\nexport interface AddEventListenerBaseOptions 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}\n\nexport interface AddEventListenerMetadata {\n propertyKey: string | symbol;\n selector: string;\n type: string;\n options: AddEventListenerBaseOptions & SwcQueryOptions & { delegate?: boolean };\n}\n\nexport const ADD_EVENT_LISTENER_METADATA_KEY = Symbol.for('simple-web-component:add-event-listener');\n\nexport function addEventListener(target: SpecialSelector, type: string, options?: AddEventListenerBaseOptions): MethodDecorator;\nexport function addEventListener(selector: string, type: string, options?: AddEventListenerBaseOptions & SwcQueryOptions & { delegate?: boolean }): MethodDecorator;\n/**\n * @addEventListener decorator to bind events to elements.\n */\nexport function addEventListener(selectorOrTarget: string, 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[]>(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\nexport const getAddEventListenerMetadata = (target: any): AddEventListenerMetadata[] | undefined => {\n const constructor = target instanceof Function ? target : target.constructor;\n return ReflectUtils.getMetadata(ADD_EVENT_LISTENER_METADATA_KEY, constructor);\n};\n\n/**\n * @addEventListenerHost decorator - simplified version of @addEventListener for :host selector\n * Usage: @addEventListenerHost('click')\n * Usage: @addEventListenerHost('click', { stopPropagation: true })\n */\nexport function addEventListenerHost(type: string, options?: AddEventListenerBaseOptions & SwcQueryOptions): MethodDecorator {\n return addEventListener(':host', type, options);\n}\n\n/**\n * @addEventListenerAppHost decorator - simplified version of @addEventListener for :appHost selector\n * Usage: @addEventListenerAppHost('click')\n * Usage: @addEventListenerAppHost('click', { stopPropagation: true })\n */\nexport function addEventListenerAppHost(type: string, options?: AddEventListenerBaseOptions & SwcQueryOptions): MethodDecorator {\n return addEventListener(':appHost', type, options);\n}\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA6B;AAsBtB,MAAM,kCAAkC,OAAO,IAAI,yCAAyC;AAO5F,SAAS,iBAAiB,kBAA0B,MAAc,UAAe,CAAC,GAAoB;AAC3G,SAAO,CAAC,WAAmB,aAA8B,eAAmC;AAC1F,UAAM,cAAc,UAAU;AAE9B,QAAI,YAAY,yBAAa,YAAwC,iCAAiC,WAAW;AACjH,QAAI,CAAC,WAAW;AACd,kBAAY,CAAC;AACb,+BAAa,eAAe,iCAAiC,WAAW,WAAW;AAAA,IACrF;AAEA,cAAU,KAAK,EAAE,aAAa,UAAU,kBAAkB,MAAM,QAAQ,CAAC;AAAA,EAC3E;AACF;AAEO,MAAM,8BAA8B,CAAC,WAAwD;AAClG,QAAM,cAAc,kBAAkB,WAAW,SAAS,OAAO;AACjE,SAAO,yBAAa,YAAY,iCAAiC,WAAW;AAC9E;AAOO,SAAS,qBAAqB,MAAc,SAA0E;AAC3H,SAAO,iBAAiB,SAAS,MAAM,OAAO;AAChD;AAOO,SAAS,wBAAwB,MAAc,SAA0E;AAC9H,SAAO,iBAAiB,YAAY,MAAM,OAAO;AACnD;",
6
6
  "names": []
7
7
  }
@@ -54,70 +54,80 @@ function createAttributeDecorator(action) {
54
54
  options: { ...finalOptions, name: attributeName }
55
55
  });
56
56
  const original = descriptor.value;
57
- descriptor.value = async function(...args) {
57
+ descriptor.value = function(...args) {
58
58
  (0, import_elementDefine.ensureInit)(this);
59
- const res = await original.apply(this, args);
60
- if (res !== void 0) {
61
- const win = this.ownerDocument?.defaultView || window;
62
- const host = this;
63
- const hostSet = { ...import_Utils.SwcUtils.getHelperAndHostSet(win, host), $this: this };
64
- const r = finalOptions.root || "auto";
65
- const targetEls = [];
66
- const applyRoot = (t) => {
67
- if (!t || !(t instanceof win.HTMLElement)) return;
68
- targetEls.push(t);
69
- };
70
- if (selector === ":parentHost") applyRoot(hostSet.$parentHost);
71
- else if (selector === ":appHost") applyRoot(hostSet.$appHost);
72
- else if (selector === ":firstHost") applyRoot(hostSet.$firstHost);
73
- else if (selector === ":lastHost") applyRoot(hostSet.$lastHost);
74
- else if (selector === ":firstAppHost") applyRoot(hostSet.$firstAppHost);
75
- else if (selector === ":lastAppHost") applyRoot(hostSet.$lastAppHost);
76
- else if (selector === ":hosts") hostSet.$hosts.forEach(applyRoot);
77
- else if (selector === ":appHosts") hostSet.$appHosts.forEach(applyRoot);
78
- else if (selector === ":host" || !selector) applyRoot(host);
79
- else {
80
- const targetRoot = r === "auto" ? host.shadowRoot || host : r === "shadow" ? host.shadowRoot : host;
81
- if (targetRoot) {
82
- const found = targetRoot.querySelectorAll(selector);
83
- if (found) targetEls.push(...Array.from(found));
59
+ const res = original.apply(this, args);
60
+ const handleResult = (resolvedValue) => {
61
+ if (resolvedValue !== void 0) {
62
+ const win = this.ownerDocument?.defaultView || window;
63
+ const host = this;
64
+ const hostSet = { ...import_Utils.SwcUtils.getHelperAndHostSet(win, host), $this: this };
65
+ const r = finalOptions.root || "auto";
66
+ const targetEls = [];
67
+ const applyRoot = (t) => {
68
+ if (!t || !(t instanceof win.HTMLElement)) return;
69
+ targetEls.push(t);
70
+ };
71
+ if (selector === ":parentHost") applyRoot(hostSet.$parentHost);
72
+ else if (selector === ":appHost") applyRoot(hostSet.$appHost);
73
+ else if (selector === ":firstHost") applyRoot(hostSet.$firstHost);
74
+ else if (selector === ":lastHost") applyRoot(hostSet.$lastHost);
75
+ else if (selector === ":firstAppHost") applyRoot(hostSet.$firstAppHost);
76
+ else if (selector === ":lastAppHost") applyRoot(hostSet.$lastAppHost);
77
+ else if (selector === ":hosts") hostSet.$hosts.forEach(applyRoot);
78
+ else if (selector === ":appHosts") hostSet.$appHosts.forEach(applyRoot);
79
+ else if (selector === ":host" || !selector) applyRoot(host);
80
+ else {
81
+ const targetRoot = r === "auto" ? host.shadowRoot || host : r === "shadow" ? host.shadowRoot : host;
82
+ if (targetRoot) {
83
+ const found = targetRoot.querySelectorAll(selector);
84
+ if (found) targetEls.push(...Array.from(found));
85
+ }
84
86
  }
85
- }
86
- targetEls.forEach((targetEl) => {
87
- const resolvedRes = typeof res === "function" ? res(targetEl, hostSet) : res;
88
- if (action === "set" || action === "update") {
89
- if (attributeName) {
90
- if (resolvedRes === null || resolvedRes === void 0 || resolvedRes === false) {
87
+ targetEls.forEach((targetEl) => {
88
+ if (finalOptions.filter && !finalOptions.filter(targetEl, resolvedValue, { currentThis: this, helper: hostSet })) {
89
+ return;
90
+ }
91
+ const resolvedRes = typeof resolvedValue === "function" ? resolvedValue(targetEl, hostSet) : resolvedValue;
92
+ if (action === "set" || action === "update") {
93
+ if (attributeName) {
94
+ if (resolvedRes === null || resolvedRes === void 0 || resolvedRes === false) {
95
+ targetEl.removeAttribute(attributeName);
96
+ } else {
97
+ targetEl.setAttribute(attributeName, resolvedRes === true ? "" : String(resolvedRes));
98
+ }
99
+ } else if (typeof resolvedRes === "object" && resolvedRes !== null && !Array.isArray(resolvedRes)) {
100
+ Object.entries(resolvedRes).forEach(([attr, val]) => {
101
+ const finalVal = typeof val === "function" ? val(targetEl, hostSet) : val;
102
+ if (finalVal === null || finalVal === void 0 || finalVal === false) {
103
+ targetEl.removeAttribute(attr);
104
+ } else {
105
+ targetEl.setAttribute(attr, finalVal === true ? "" : String(finalVal));
106
+ }
107
+ });
108
+ }
109
+ } else if (action === "remove") {
110
+ if (attributeName) {
91
111
  targetEl.removeAttribute(attributeName);
112
+ } else if (typeof resolvedRes === "object" && resolvedRes !== null && !Array.isArray(resolvedRes)) {
113
+ Object.entries(resolvedRes).forEach(([attr, val]) => {
114
+ const shouldRemove = typeof val === "function" ? val(targetEl, hostSet) : !!val;
115
+ if (shouldRemove) targetEl.removeAttribute(attr);
116
+ });
92
117
  } else {
93
- targetEl.setAttribute(attributeName, resolvedRes === true ? "" : String(resolvedRes));
118
+ const attrs = Array.isArray(resolvedRes) ? resolvedRes : [resolvedRes];
119
+ attrs.forEach((a) => targetEl.removeAttribute(String(a)));
94
120
  }
95
- } else if (typeof resolvedRes === "object" && resolvedRes !== null && !Array.isArray(resolvedRes)) {
96
- Object.entries(resolvedRes).forEach(([attr, val]) => {
97
- const finalVal = typeof val === "function" ? val(targetEl, hostSet) : val;
98
- if (finalVal === null || finalVal === void 0 || finalVal === false) {
99
- targetEl.removeAttribute(attr);
100
- } else {
101
- targetEl.setAttribute(attr, finalVal === true ? "" : String(finalVal));
102
- }
103
- });
104
- }
105
- } else if (action === "remove") {
106
- if (attributeName) {
107
- targetEl.removeAttribute(attributeName);
108
- } else if (typeof resolvedRes === "object" && resolvedRes !== null && !Array.isArray(resolvedRes)) {
109
- Object.entries(resolvedRes).forEach(([attr, val]) => {
110
- const shouldRemove = typeof val === "function" ? val(targetEl, hostSet) : !!val;
111
- if (shouldRemove) targetEl.removeAttribute(attr);
112
- });
113
- } else {
114
- const attrs = Array.isArray(resolvedRes) ? resolvedRes : [resolvedRes];
115
- attrs.forEach((a) => targetEl.removeAttribute(String(a)));
116
121
  }
117
- }
118
- });
122
+ });
123
+ }
124
+ return resolvedValue;
125
+ };
126
+ if (res instanceof Promise) {
127
+ return res.then(handleResult);
128
+ } else {
129
+ return handleResult(res);
119
130
  }
120
- return res;
121
131
  };
122
132
  return descriptor;
123
133
  };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/decorators/applyAttribute.ts"],
4
- "sourcesContent": ["import { ReflectUtils } from '@dooboostore/core';\nimport { ensureInit } from './elementDefine';\nimport { SwcUtils } from '../utils/Utils';\nimport { SwcQueryOptions, HelperHostSet } from '../types';\n\nexport type AttributeAction = 'set' | 'update' | 'remove';\n\nexport interface AttributeApplyOptions extends SwcQueryOptions {\n name?: string;\n}\n\nexport interface AttributeApplyMetadata {\n propertyKey: string | symbol;\n selector: string;\n action: AttributeAction;\n options: AttributeApplyOptions;\n}\n\nexport const ATTRIBUTE_APPLY_METADATA_KEY = Symbol.for('simple-web-component:attribute-apply');\n\nfunction createAttributeDecorator(action: AttributeAction) {\n return (selector: string, nameOrOptions?: string | AttributeApplyOptions, options: AttributeApplyOptions = {}): MethodDecorator => {\n return (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n const constructor = target.constructor;\n let metaList = ReflectUtils.getOwnMetadata(ATTRIBUTE_APPLY_METADATA_KEY, constructor) as Map<string | symbol, AttributeApplyMetadata>;\n if (!metaList) {\n metaList = new Map<string | symbol, AttributeApplyMetadata>();\n ReflectUtils.defineMetadata(ATTRIBUTE_APPLY_METADATA_KEY, metaList, constructor);\n }\n\n let attributeName = typeof nameOrOptions === 'string' ? nameOrOptions : undefined;\n let finalOptions = options;\n \n if (typeof nameOrOptions === 'object' && nameOrOptions !== null) {\n finalOptions = nameOrOptions as AttributeApplyOptions;\n }\n\n metaList.set(propertyKey, { \n propertyKey, \n selector, \n action, \n options: { ...finalOptions, name: attributeName } \n });\n\n const original = descriptor.value;\n descriptor.value = async function (...args: any[]) {\n ensureInit(this);\n const res = await (original as any).apply(this, args);\n if (res !== undefined) {\n const win = (this as any).ownerDocument?.defaultView || window;\n const host = this as unknown as HTMLElement;\n const hostSet = { ...SwcUtils.getHelperAndHostSet(win, host), $this: this };\n const r = finalOptions.root || 'auto';\n const targetEls: HTMLElement[] = [];\n\n const applyRoot = (t: any) => {\n if (!t || !(t instanceof win.HTMLElement)) return;\n targetEls.push(t);\n };\n\n if (selector === ':parentHost') applyRoot(hostSet.$parentHost);\n else if (selector === ':appHost') applyRoot(hostSet.$appHost);\n else if (selector === ':firstHost') applyRoot(hostSet.$firstHost);\n else if (selector === ':lastHost') applyRoot(hostSet.$lastHost);\n else if (selector === ':firstAppHost') applyRoot(hostSet.$firstAppHost);\n else if (selector === ':lastAppHost') applyRoot(hostSet.$lastAppHost);\n else if (selector === ':hosts') hostSet.$hosts.forEach(applyRoot);\n else if (selector === ':appHosts') hostSet.$appHosts.forEach(applyRoot);\n else if (selector === ':host' || !selector) applyRoot(host);\n else {\n const targetRoot = r === 'auto' ? (host.shadowRoot || host) : (r === 'shadow' ? host.shadowRoot : host);\n if (targetRoot) {\n const found = targetRoot.querySelectorAll(selector);\n if (found) targetEls.push(...(Array.from(found) as HTMLElement[]));\n }\n }\n\n targetEls.forEach(targetEl => {\n const resolvedRes = typeof res === 'function' ? (res as any)(targetEl, hostSet) : res;\n\n if (action === 'set' || action === 'update') {\n if (attributeName) {\n // Case: @setAttribute(selector, 'name')\n if (resolvedRes === null || resolvedRes === undefined || resolvedRes === false) {\n targetEl.removeAttribute(attributeName);\n } else {\n targetEl.setAttribute(attributeName, resolvedRes === true ? '' : String(resolvedRes));\n }\n } else if (typeof resolvedRes === 'object' && resolvedRes !== null && !Array.isArray(resolvedRes)) {\n // Case: @applyAttribute(selector) with Object return\n Object.entries(resolvedRes as any).forEach(([attr, val]) => {\n const finalVal = typeof val === 'function' ? val(targetEl, hostSet) : val;\n if (finalVal === null || finalVal === undefined || finalVal === false) {\n targetEl.removeAttribute(attr);\n } else {\n targetEl.setAttribute(attr, finalVal === true ? '' : String(finalVal));\n }\n });\n }\n } else if (action === 'remove') {\n if (attributeName) {\n targetEl.removeAttribute(attributeName);\n } else if (typeof resolvedRes === 'object' && resolvedRes !== null && !Array.isArray(resolvedRes)) {\n Object.entries(resolvedRes as any).forEach(([attr, val]) => {\n const shouldRemove = typeof val === 'function' ? val(targetEl, hostSet) : !!val;\n if (shouldRemove) targetEl.removeAttribute(attr);\n });\n } else {\n const attrs = Array.isArray(resolvedRes) ? resolvedRes : [resolvedRes];\n attrs.forEach(a => targetEl.removeAttribute(String(a)));\n }\n }\n });\n }\n return res;\n };\n return descriptor;\n };\n };\n}\n\nexport function applyAttribute(selector: string, action: AttributeAction = 'update', options: AttributeApplyOptions = {}): MethodDecorator {\n return createAttributeDecorator(action)(selector, options);\n}\n\nexport const setAttribute = (selector: string, nameOrOptions?: string | AttributeApplyOptions, options: AttributeApplyOptions = {}) => createAttributeDecorator('set')(selector, nameOrOptions, options);\nexport const updateAttribute = (selector: string, nameOrOptions?: string | AttributeApplyOptions, options: AttributeApplyOptions = {}) => createAttributeDecorator('update')(selector, nameOrOptions, options);\nexport const removeAttribute = (selector: string, nameOrOptions?: string | AttributeApplyOptions, options: AttributeApplyOptions = {}) => createAttributeDecorator('remove')(selector, nameOrOptions, options);\n\n// Host versions\nexport function applyAttributeHost(action: AttributeAction = 'update', options: AttributeApplyOptions = {}): MethodDecorator {\n return createAttributeDecorator(action)(':host', options);\n}\nexport const setAttributeHost = (nameOrOptions: string | AttributeApplyOptions, options: AttributeApplyOptions = {}) => createAttributeDecorator('set')(':host', nameOrOptions, options);\nexport const updateAttributeHost = (nameOrOptions: string | AttributeApplyOptions, options: AttributeApplyOptions = {}) => createAttributeDecorator('update')(':host', nameOrOptions, options);\nexport const removeAttributeHost = (nameOrOptions?: string | AttributeApplyOptions, options: AttributeApplyOptions = {}) => createAttributeDecorator('remove')(':host', nameOrOptions, options);\n\nexport const findAllAttributeApplyMetadata = (target: any): Map<string | symbol, AttributeApplyMetadata> => {\n const result = new Map<string | symbol, AttributeApplyMetadata>();\n const maps = ReflectUtils.findAllMetadata<Map<string | symbol, AttributeApplyMetadata>>(ATTRIBUTE_APPLY_METADATA_KEY, target);\n maps.forEach(map => {\n if (map instanceof Map) {\n map.forEach((v, k) => result.set(k, v));\n }\n });\n return result;\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA6B;AAC7B,2BAA2B;AAC3B,mBAAyB;AAgBlB,MAAM,+BAA+B,OAAO,IAAI,sCAAsC;AAE7F,SAAS,yBAAyB,QAAyB;AACzD,SAAO,CAAC,UAAkB,eAAgD,UAAiC,CAAC,MAAuB;AACjI,WAAO,CAAC,QAAgB,aAA8B,eAAmC;AACvF,YAAM,cAAc,OAAO;AAC3B,UAAI,WAAW,yBAAa,eAAe,8BAA8B,WAAW;AACpF,UAAI,CAAC,UAAU;AACb,mBAAW,oBAAI,IAA6C;AAC5D,iCAAa,eAAe,8BAA8B,UAAU,WAAW;AAAA,MACjF;AAEA,UA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QAAI,eAAe,KAAK;AACtB,UAAI,QAAQ,CAAC,GAAG,MAAM,OAAO,IAAI,GAAG,CAAC,CAAC;AAAA,IACxC;AAAA,EACF,CAAC;AACD,SAAO;AACT;",
4
+ "sourcesContent": ["import { ReflectUtils } from '@dooboostore/core';\nimport { ensureInit } from './elementDefine';\nimport { SwcUtils } from '../utils/Utils';\nimport { SwcQueryOptions, HelperHostSet } from '../types';\n\nexport type AttributeAction = 'set' | 'update' | 'remove';\n\nexport interface AttributeApplyOptions extends SwcQueryOptions {\n name?: string;\n filter?: (target: HTMLElement, value: any, meta: {currentThis: any, helper: HelperHostSet}) => boolean;\n}\n\nexport interface AttributeApplyMetadata {\n propertyKey: string | symbol;\n selector: string;\n action: AttributeAction;\n options: AttributeApplyOptions;\n}\n\nexport const ATTRIBUTE_APPLY_METADATA_KEY = Symbol.for('simple-web-component:attribute-apply');\n\nfunction createAttributeDecorator(action: AttributeAction) {\n return (selector: string, nameOrOptions?: string | AttributeApplyOptions, options: AttributeApplyOptions = {}): MethodDecorator => {\n return (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n const constructor = target.constructor;\n let metaList = ReflectUtils.getOwnMetadata(ATTRIBUTE_APPLY_METADATA_KEY, constructor) as Map<string | symbol, AttributeApplyMetadata>;\n if (!metaList) {\n metaList = new Map<string | symbol, AttributeApplyMetadata>();\n ReflectUtils.defineMetadata(ATTRIBUTE_APPLY_METADATA_KEY, metaList, constructor);\n }\n\n let attributeName = typeof nameOrOptions === 'string' ? nameOrOptions : undefined;\n let finalOptions = options;\n \n if (typeof nameOrOptions === 'object' && nameOrOptions !== null) {\n finalOptions = nameOrOptions as AttributeApplyOptions;\n }\n\n metaList.set(propertyKey, { \n propertyKey, \n selector, \n action, \n options: { ...finalOptions, name: attributeName } \n });\n\n const original = descriptor.value;\n descriptor.value = function (...args: any[]) {\n ensureInit(this);\n const res = (original as any).apply(this, args);\n\n const handleResult = (resolvedValue: any) => {\n if (resolvedValue !== undefined) {\n const win = (this as any).ownerDocument?.defaultView || window;\n const host = this as unknown as HTMLElement;\n const hostSet = { ...SwcUtils.getHelperAndHostSet(win, host), $this: this };\n const r = finalOptions.root || 'auto';\n const targetEls: HTMLElement[] = [];\n\n const applyRoot = (t: any) => {\n if (!t || !(t instanceof win.HTMLElement)) return;\n targetEls.push(t);\n };\n\n if (selector === ':parentHost') applyRoot(hostSet.$parentHost);\n else if (selector === ':appHost') applyRoot(hostSet.$appHost);\n else if (selector === ':firstHost') applyRoot(hostSet.$firstHost);\n else if (selector === ':lastHost') applyRoot(hostSet.$lastHost);\n else if (selector === ':firstAppHost') applyRoot(hostSet.$firstAppHost);\n else if (selector === ':lastAppHost') applyRoot(hostSet.$lastAppHost);\n else if (selector === ':hosts') hostSet.$hosts.forEach(applyRoot);\n else if (selector === ':appHosts') hostSet.$appHosts.forEach(applyRoot);\n else if (selector === ':host' || !selector) applyRoot(host);\n else {\n const targetRoot = r === 'auto' ? (host.shadowRoot || host) : (r === 'shadow' ? host.shadowRoot : host);\n if (targetRoot) {\n const found = targetRoot.querySelectorAll(selector);\n if (found) targetEls.push(...(Array.from(found) as HTMLElement[]));\n }\n }\n\n targetEls.forEach(targetEl => {\n if (finalOptions.filter && !finalOptions.filter(targetEl, resolvedValue, {currentThis: this, helper: hostSet})) {\n return;\n }\n const resolvedRes = typeof resolvedValue === 'function' ? (resolvedValue as any)(targetEl, hostSet) : resolvedValue;\n\n if (action === 'set' || action === 'update') {\n if (attributeName) {\n // Case: @setAttribute(selector, 'name')\n if (resolvedRes === null || resolvedRes === undefined || resolvedRes === false) {\n targetEl.removeAttribute(attributeName);\n } else {\n targetEl.setAttribute(attributeName, resolvedRes === true ? '' : String(resolvedRes));\n }\n } else if (typeof resolvedRes === 'object' && resolvedRes !== null && !Array.isArray(resolvedRes)) {\n // Case: @applyAttribute(selector) with Object return\n Object.entries(resolvedRes as any).forEach(([attr, val]) => {\n const finalVal = typeof val === 'function' ? val(targetEl, hostSet) : val;\n if (finalVal === null || finalVal === undefined || finalVal === false) {\n targetEl.removeAttribute(attr);\n } else {\n targetEl.setAttribute(attr, finalVal === true ? '' : String(finalVal));\n }\n });\n }\n } else if (action === 'remove') {\n if (attributeName) {\n targetEl.removeAttribute(attributeName);\n } else if (typeof resolvedRes === 'object' && resolvedRes !== null && !Array.isArray(resolvedRes)) {\n Object.entries(resolvedRes as any).forEach(([attr, val]) => {\n const shouldRemove = typeof val === 'function' ? val(targetEl, hostSet) : !!val;\n if (shouldRemove) targetEl.removeAttribute(attr);\n });\n } else {\n const attrs = Array.isArray(resolvedRes) ? resolvedRes : [resolvedRes];\n attrs.forEach(a => targetEl.removeAttribute(String(a)));\n }\n }\n });\n }\n return resolvedValue;\n };\n\n if (res instanceof Promise) {\n return res.then(handleResult);\n } else {\n return handleResult(res);\n }\n };\n return descriptor;\n };\n };\n}\n\nexport function applyAttribute(selector: string, action: AttributeAction = 'update', options: AttributeApplyOptions = {}): MethodDecorator {\n return createAttributeDecorator(action)(selector, options);\n}\n\nexport const setAttribute = (selector: string, nameOrOptions?: string | AttributeApplyOptions, options: AttributeApplyOptions = {}) => createAttributeDecorator('set')(selector, nameOrOptions, options);\nexport const updateAttribute = (selector: string, nameOrOptions?: string | AttributeApplyOptions, options: AttributeApplyOptions = {}) => createAttributeDecorator('update')(selector, nameOrOptions, options);\nexport const removeAttribute = (selector: string, nameOrOptions?: string | AttributeApplyOptions, options: AttributeApplyOptions = {}) => createAttributeDecorator('remove')(selector, nameOrOptions, options);\n\n// Host versions\nexport function applyAttributeHost(action: AttributeAction = 'update', options: AttributeApplyOptions = {}): MethodDecorator {\n return createAttributeDecorator(action)(':host', options);\n}\nexport const setAttributeHost = (nameOrOptions: string | AttributeApplyOptions, options: AttributeApplyOptions = {}) => createAttributeDecorator('set')(':host', nameOrOptions, options);\nexport const updateAttributeHost = (nameOrOptions: string | AttributeApplyOptions, options: AttributeApplyOptions = {}) => createAttributeDecorator('update')(':host', nameOrOptions, options);\nexport const removeAttributeHost = (nameOrOptions?: string | AttributeApplyOptions, options: AttributeApplyOptions = {}) => createAttributeDecorator('remove')(':host', nameOrOptions, options);\n\nexport const findAllAttributeApplyMetadata = (target: any): Map<string | symbol, AttributeApplyMetadata> => {\n const result = new Map<string | symbol, AttributeApplyMetadata>();\n const maps = ReflectUtils.findAllMetadata<Map<string | symbol, AttributeApplyMetadata>>(ATTRIBUTE_APPLY_METADATA_KEY, target);\n maps.forEach(map => {\n if (map instanceof Map) {\n map.forEach((v, k) => result.set(k, v));\n }\n });\n return result;\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA6B;AAC7B,2BAA2B;AAC3B,mBAAyB;AAiBlB,MAAM,+BAA+B,OAAO,IAAI,sCAAsC;AAE7F,SAAS,yBAAyB,QAAyB;AACzD,SAAO,CAAC,UAAkB,eAAgD,UAAiC,CAAC,MAAuB;AACjI,WAAO,CAAC,QAAgB,aAA8B,eAAmC;AACvF,YAAM,cAAc,OAAO;AAC3B,UAAI,WAAW,yBAAa,eAAe,8BAA8B,WAAW;AACpF,UAAI,CAAC,UAAU;AACb,mBAAW,oBAAI,IAA6C;AAC5D,iCAAa,eAAe,8BAA8B,UAAU,WAAW;AAAA,MACjF;AAEA,UAAI,gBAAgB,OAAO,kBAAkB,WAAW,gBAAgB;AACxE,UAAI,eAAe;AAEnB,UAAI,OAAO,kBAAkB,YAAY,kBAAkB,MAAM;AAC7D,uBAAe;AAAA,MACnB;AAEA,eAAS,IAAI,aAAa;AAAA,QACxB;AAAA,QACA;AAAA,QACA;AAAA,QACA,SAAS,EAAE,GAAG,cAAc,MAAM,cAAc;AAAA,MAClD,CAAC;AAED,YAAM,WAAW,WAAW;AAC5B,iBAAW,QAAQ,YAAa,MAAa;AAC3C,6CAAW,IAAI;AACf,cAAM,MAAO,SAAiB,MAAM,MAAM,IAAI;AAE9C,cAAM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F,CAAC;AACD,SAAO;AACT;",
6
6
  "names": []
7
7
  }
@@ -55,81 +55,91 @@ function createClassDecorator(action) {
55
55
  }
56
56
  metaList.set(propertyKey, { propertyKey, selector, action, options: finalOptions });
57
57
  const original = descriptor.value;
58
- descriptor.value = async function(...args) {
58
+ descriptor.value = function(...args) {
59
59
  (0, import_elementDefine.ensureInit)(this);
60
- const res = await original.apply(this, args);
61
- if (res !== void 0) {
62
- const win = this.ownerDocument?.defaultView || window;
63
- const host = this;
64
- const hostSet = { ...import_Utils.SwcUtils.getHelperAndHostSet(win, host), $this: this };
65
- const r = finalOptions.root || "auto";
66
- const targetEls = [];
67
- const applyRoot = (t) => {
68
- if (!t || !(t instanceof win.HTMLElement)) return;
69
- targetEls.push(t);
70
- };
71
- if (selector === ":parentHost") applyRoot(hostSet.$parentHost);
72
- else if (selector === ":appHost") applyRoot(hostSet.$appHost);
73
- else if (selector === ":firstHost") applyRoot(hostSet.$firstHost);
74
- else if (selector === ":lastHost") applyRoot(hostSet.$lastHost);
75
- else if (selector === ":firstAppHost") applyRoot(hostSet.$firstAppHost);
76
- else if (selector === ":lastAppHost") applyRoot(hostSet.$lastAppHost);
77
- else if (selector === ":hosts") hostSet.$hosts.forEach(applyRoot);
78
- else if (selector === ":appHosts") hostSet.$appHosts.forEach(applyRoot);
79
- else if (selector === ":host" || !selector) applyRoot(host);
80
- else {
81
- const targetRoot = r === "auto" ? host.shadowRoot || host : r === "shadow" ? host.shadowRoot : host;
82
- if (targetRoot) {
83
- const found = targetRoot.querySelectorAll(selector);
84
- if (found) targetEls.push(...Array.from(found));
85
- }
86
- }
87
- targetEls.forEach((targetEl) => {
88
- const resolvedRes = typeof res === "function" ? res(targetEl, hostSet) : res;
89
- if (action === "set") {
90
- let classes = "";
91
- if (classMap && typeof classMap === "string") {
92
- classes = resolvedRes ? classMap : "";
93
- } else if (typeof resolvedRes === "object" && resolvedRes !== null && !Array.isArray(resolvedRes)) {
94
- classes = Object.entries(resolvedRes).filter(([_, force]) => typeof force === "function" ? force(targetEl, hostSet) : !!force).map(([cls]) => cls).join(" ");
95
- } else {
96
- classes = Array.isArray(resolvedRes) ? resolvedRes.join(" ") : String(resolvedRes);
60
+ const res = original.apply(this, args);
61
+ const handleResult = (resolvedValue) => {
62
+ if (resolvedValue !== void 0) {
63
+ const win = this.ownerDocument?.defaultView || window;
64
+ const host = this;
65
+ const hostSet = { ...import_Utils.SwcUtils.getHelperAndHostSet(win, host), $this: this };
66
+ const r = finalOptions.root || "auto";
67
+ const targetEls = [];
68
+ const applyRoot = (t) => {
69
+ if (!t || !(t instanceof win.HTMLElement)) return;
70
+ targetEls.push(t);
71
+ };
72
+ if (selector === ":parentHost") applyRoot(hostSet.$parentHost);
73
+ else if (selector === ":appHost") applyRoot(hostSet.$appHost);
74
+ else if (selector === ":firstHost") applyRoot(hostSet.$firstHost);
75
+ else if (selector === ":lastHost") applyRoot(hostSet.$lastHost);
76
+ else if (selector === ":firstAppHost") applyRoot(hostSet.$firstAppHost);
77
+ else if (selector === ":lastAppHost") applyRoot(hostSet.$lastAppHost);
78
+ else if (selector === ":hosts") hostSet.$hosts.forEach(applyRoot);
79
+ else if (selector === ":appHosts") hostSet.$appHosts.forEach(applyRoot);
80
+ else if (selector === ":host" || !selector) applyRoot(host);
81
+ else {
82
+ const targetRoot = r === "auto" ? host.shadowRoot || host : r === "shadow" ? host.shadowRoot : host;
83
+ if (targetRoot) {
84
+ const found = targetRoot.querySelectorAll(selector);
85
+ if (found) targetEls.push(...Array.from(found));
97
86
  }
98
- targetEl.className = classes;
99
- } else if (action === "update" || action === "toggle") {
100
- if (classMap && typeof classMap === "string") {
101
- targetEl.classList.toggle(classMap, !!resolvedRes);
102
- } else if (typeof resolvedRes === "object" && resolvedRes !== null && !Array.isArray(resolvedRes)) {
103
- Object.entries(resolvedRes).forEach(([cls, force]) => {
104
- const isActive = typeof force === "function" ? force(targetEl, hostSet) : !!force;
105
- targetEl.classList.toggle(cls, isActive);
106
- });
107
- } else {
108
- const classes = Array.isArray(resolvedRes) ? resolvedRes.map(String) : [String(resolvedRes)];
109
- if (action === "update") targetEl.classList.add(...classes);
110
- else classes.forEach((c) => targetEl.classList.toggle(c));
87
+ }
88
+ targetEls.forEach((targetEl) => {
89
+ if (finalOptions.filter && !finalOptions.filter(targetEl, resolvedValue, { currentThis: this, helper: hostSet })) {
90
+ return;
111
91
  }
112
- } else if (action === "add" || action === "remove") {
113
- if (classMap && typeof classMap === "string" && !!resolvedRes) {
114
- if (action === "add") targetEl.classList.add(classMap);
115
- else targetEl.classList.remove(classMap);
116
- } else if (typeof resolvedRes === "object" && resolvedRes !== null && !Array.isArray(resolvedRes)) {
117
- Object.entries(resolvedRes).forEach(([cls, force]) => {
118
- const shouldExecute = typeof force === "function" ? force(targetEl, hostSet) : !!force;
119
- if (shouldExecute) {
120
- if (action === "add") targetEl.classList.add(cls);
121
- else targetEl.classList.remove(cls);
122
- }
123
- });
124
- } else {
125
- const classes = Array.isArray(resolvedRes) ? resolvedRes.map(String) : [String(resolvedRes)];
126
- if (action === "add") targetEl.classList.add(...classes);
127
- else targetEl.classList.remove(...classes);
92
+ const resolvedRes = typeof resolvedValue === "function" ? resolvedValue(targetEl, hostSet) : resolvedValue;
93
+ if (action === "set") {
94
+ let classes = "";
95
+ if (classMap && typeof classMap === "string") {
96
+ classes = resolvedRes ? classMap : "";
97
+ } else if (typeof resolvedRes === "object" && resolvedRes !== null && !Array.isArray(resolvedRes)) {
98
+ classes = Object.entries(resolvedRes).filter(([_, force]) => typeof force === "function" ? force(targetEl, hostSet) : !!force).map(([cls]) => cls).join(" ");
99
+ } else {
100
+ classes = Array.isArray(resolvedRes) ? resolvedRes.join(" ") : String(resolvedRes);
101
+ }
102
+ targetEl.className = classes;
103
+ } else if (action === "update" || action === "toggle") {
104
+ if (classMap && typeof classMap === "string") {
105
+ targetEl.classList.toggle(classMap, !!resolvedRes);
106
+ } else if (typeof resolvedRes === "object" && resolvedRes !== null && !Array.isArray(resolvedRes)) {
107
+ Object.entries(resolvedRes).forEach(([cls, force]) => {
108
+ const isActive = typeof force === "function" ? force(targetEl, hostSet) : !!force;
109
+ targetEl.classList.toggle(cls, isActive);
110
+ });
111
+ } else {
112
+ const classes = Array.isArray(resolvedRes) ? resolvedRes.map(String) : [String(resolvedRes)];
113
+ if (action === "update") targetEl.classList.add(...classes);
114
+ else classes.forEach((c) => targetEl.classList.toggle(c));
115
+ }
116
+ } else if (action === "add" || action === "remove") {
117
+ if (classMap && typeof classMap === "string" && !!resolvedRes) {
118
+ if (action === "add") targetEl.classList.add(classMap);
119
+ else targetEl.classList.remove(classMap);
120
+ } else if (typeof resolvedRes === "object" && resolvedRes !== null && !Array.isArray(resolvedRes)) {
121
+ Object.entries(resolvedRes).forEach(([cls, force]) => {
122
+ const shouldExecute = typeof force === "function" ? force(targetEl, hostSet) : !!force;
123
+ if (shouldExecute) {
124
+ if (action === "add") targetEl.classList.add(cls);
125
+ else targetEl.classList.remove(cls);
126
+ }
127
+ });
128
+ } else {
129
+ const classes = Array.isArray(resolvedRes) ? resolvedRes.map(String) : [String(resolvedRes)];
130
+ if (action === "add") targetEl.classList.add(...classes);
131
+ else targetEl.classList.remove(...classes);
132
+ }
128
133
  }
129
- }
130
- });
134
+ });
135
+ }
136
+ return resolvedValue;
137
+ };
138
+ if (res instanceof Promise) {
139
+ return res.then(handleResult);
140
+ } else {
141
+ return handleResult(res);
131
142
  }
132
- return res;
133
143
  };
134
144
  return descriptor;
135
145
  };