@dooboostore/simple-web-component 1.0.23 → 1.0.24

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 (78) hide show
  1. package/README.md +238 -44
  2. package/dist/cjs/decorators/applyNode.js +129 -34
  3. package/dist/cjs/decorators/applyNode.js.map +2 -2
  4. package/dist/cjs/decorators/attribute.js +21 -2
  5. package/dist/cjs/decorators/attribute.js.map +2 -2
  6. package/dist/cjs/decorators/changedAttributeHost.js.map +2 -2
  7. package/dist/cjs/decorators/classList.js +60 -17
  8. package/dist/cjs/decorators/classList.js.map +2 -2
  9. package/dist/cjs/decorators/query.js +77 -2
  10. package/dist/cjs/decorators/query.js.map +2 -2
  11. package/dist/cjs/decorators/queryAll.js +77 -2
  12. package/dist/cjs/decorators/queryAll.js.map +2 -2
  13. package/dist/cjs/decorators/setAttribute.js +4 -4
  14. package/dist/cjs/decorators/setAttribute.js.map +2 -2
  15. package/dist/cjs/decorators/style.js +46 -15
  16. package/dist/cjs/decorators/style.js.map +2 -2
  17. package/dist/cjs/index.js +4 -4
  18. package/dist/cjs/index.js.map +2 -2
  19. package/dist/cjs/utils/Utils.js +140 -1
  20. package/dist/cjs/utils/Utils.js.map +2 -2
  21. package/dist/esm/decorators/applyNode.js +129 -34
  22. package/dist/esm/decorators/applyNode.js.map +2 -2
  23. package/dist/esm/decorators/attribute.js +21 -2
  24. package/dist/esm/decorators/attribute.js.map +2 -2
  25. package/dist/esm/decorators/changedAttributeHost.js.map +2 -2
  26. package/dist/esm/decorators/classList.js +60 -17
  27. package/dist/esm/decorators/classList.js.map +2 -2
  28. package/dist/esm/decorators/query.js +77 -2
  29. package/dist/esm/decorators/query.js.map +2 -2
  30. package/dist/esm/decorators/queryAll.js +77 -2
  31. package/dist/esm/decorators/queryAll.js.map +2 -2
  32. package/dist/esm/decorators/setAttribute.js +4 -4
  33. package/dist/esm/decorators/setAttribute.js.map +2 -2
  34. package/dist/esm/decorators/style.js +46 -15
  35. package/dist/esm/decorators/style.js.map +2 -2
  36. package/dist/esm/index.js +4 -4
  37. package/dist/esm/index.js.map +2 -2
  38. package/dist/esm/utils/Utils.js +140 -1
  39. package/dist/esm/utils/Utils.js.map +2 -2
  40. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +542 -155
  41. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
  42. package/dist/types/decorators/applyNode.d.ts +49 -27
  43. package/dist/types/decorators/applyNode.d.ts.map +1 -1
  44. package/dist/types/decorators/attribute.d.ts +11 -4
  45. package/dist/types/decorators/attribute.d.ts.map +1 -1
  46. package/dist/types/decorators/classList.d.ts +15 -5
  47. package/dist/types/decorators/classList.d.ts.map +1 -1
  48. package/dist/types/decorators/query.d.ts +68 -4
  49. package/dist/types/decorators/query.d.ts.map +1 -1
  50. package/dist/types/decorators/queryAll.d.ts +70 -1
  51. package/dist/types/decorators/queryAll.d.ts.map +1 -1
  52. package/dist/types/decorators/setAttribute.d.ts.map +1 -1
  53. package/dist/types/decorators/style.d.ts +17 -8
  54. package/dist/types/decorators/style.d.ts.map +1 -1
  55. package/dist/types/index.d.ts +1 -2
  56. package/dist/types/index.d.ts.map +1 -1
  57. package/dist/types/utils/Utils.d.ts +49 -0
  58. package/dist/types/utils/Utils.d.ts.map +1 -1
  59. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +542 -155
  60. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
  61. package/package.json +3 -3
  62. package/src/decorators/applyNode.ts +179 -60
  63. package/src/decorators/attribute.ts +43 -10
  64. package/src/decorators/changedAttributeHost.ts +1 -1
  65. package/src/decorators/classList.ts +79 -17
  66. package/src/decorators/query.ts +147 -5
  67. package/src/decorators/queryAll.ts +148 -2
  68. package/src/decorators/setAttribute.ts +6 -5
  69. package/src/decorators/style.ts +67 -22
  70. package/src/index.ts +6 -6
  71. package/src/utils/Utils.ts +144 -0
  72. package/dist/cjs/utils/TemplateUtils.js +0 -109
  73. package/dist/cjs/utils/TemplateUtils.js.map +0 -7
  74. package/dist/esm/utils/TemplateUtils.js +0 -90
  75. package/dist/esm/utils/TemplateUtils.js.map +0 -7
  76. package/dist/types/utils/TemplateUtils.d.ts +0 -59
  77. package/dist/types/utils/TemplateUtils.d.ts.map +0 -1
  78. package/src/utils/TemplateUtils.ts +0 -92
@@ -108,10 +108,152 @@ export const getQueryMetadata = (target: any): QueryMetadata[] | undefined => {
108
108
  };
109
109
 
110
110
  /**
111
- * @hostQuery decorator - simplified version of @query for :host selector
112
- * Usage: @hostQuery()
113
- * Usage: @hostQuery({ root: 'shadow' })
111
+ * @queryHost decorator - simplified version of @query for :host selector
112
+ * Usage: @queryHost testzzs: HTMLElement | undefined;
113
+ * Usage: @queryHost() testzzs: HTMLElement | undefined;
114
+ * Usage: @queryHost({ root: 'shadow' }) testzzs: HTMLElement | undefined;
114
115
  */
115
- export function queryHost(options?: SwcQueryOptions): PropertyDecorator {
116
- return query(':host', options);
116
+ export function queryHost(target: Object, propertyKey: string | symbol): void;
117
+ export function queryHost(): PropertyDecorator;
118
+ export function queryHost(options: SwcQueryOptions): PropertyDecorator;
119
+ export function queryHost(targetOrOptions?: any, propertyKey?: string | symbol): any {
120
+ // Direct decorator usage: @queryHost (no parentheses)
121
+ if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
122
+ return query(':host', {})(targetOrOptions, propertyKey);
123
+ }
124
+
125
+ // @queryHost() or @queryHost(options)
126
+ if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
127
+ return query(':host', targetOrOptions as SwcQueryOptions);
128
+ } else {
129
+ return query(':host', {});
130
+ }
131
+ }
132
+
133
+ /**
134
+ * @host - Alias for @queryHost decorator
135
+ * Usage: @host element: HTMLElement | undefined;
136
+ * Usage: @host() element: HTMLElement | undefined;
137
+ * Usage: @host({ root: 'shadow' }) element: HTMLElement | undefined;
138
+ */
139
+ export const host = queryHost;
140
+
141
+ /**
142
+ * @parentHost - Query :parentHost (Direct parent SWC component)
143
+ * Usage: @parentHost parent: HTMLElement | undefined;
144
+ * Usage: @parentHost() parent: HTMLElement | undefined;
145
+ * Usage: @parentHost({ root: 'shadow' }) parent: HTMLElement | undefined;
146
+ */
147
+ export function parentHost(target: Object, propertyKey: string | symbol): void;
148
+ export function parentHost(): PropertyDecorator;
149
+ export function parentHost(options: SwcQueryOptions): PropertyDecorator;
150
+ export function parentHost(targetOrOptions?: any, propertyKey?: string | symbol): any {
151
+ if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
152
+ return query(':parentHost', {})(targetOrOptions, propertyKey);
153
+ }
154
+ if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
155
+ return query(':parentHost', targetOrOptions as SwcQueryOptions);
156
+ } else {
157
+ return query(':parentHost', {});
158
+ }
159
+ }
160
+
161
+ /**
162
+ * @appHost - Query :appHost (Nearest <swc-app>)
163
+ * Usage: @appHost app: SwcAppInterface | undefined;
164
+ * Usage: @appHost() app: SwcAppInterface | undefined;
165
+ * Usage: @appHost({ root: 'shadow' }) app: SwcAppInterface | undefined;
166
+ */
167
+ export function appHost(target: Object, propertyKey: string | symbol): void;
168
+ export function appHost(): PropertyDecorator;
169
+ export function appHost(options: SwcQueryOptions): PropertyDecorator;
170
+ export function appHost(targetOrOptions?: any, propertyKey?: string | symbol): any {
171
+ if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
172
+ return query(':appHost', {})(targetOrOptions, propertyKey);
173
+ }
174
+ if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
175
+ return query(':appHost', targetOrOptions as SwcQueryOptions);
176
+ } else {
177
+ return query(':appHost', {});
178
+ }
179
+ }
180
+
181
+ /**
182
+ * @firstHost - Query :firstHost (First component in hierarchy)
183
+ * Usage: @firstHost first: HTMLElement | undefined;
184
+ * Usage: @firstHost() first: HTMLElement | undefined;
185
+ * Usage: @firstHost({ root: 'shadow' }) first: HTMLElement | undefined;
186
+ */
187
+ export function firstHost(target: Object, propertyKey: string | symbol): void;
188
+ export function firstHost(): PropertyDecorator;
189
+ export function firstHost(options: SwcQueryOptions): PropertyDecorator;
190
+ export function firstHost(targetOrOptions?: any, propertyKey?: string | symbol): any {
191
+ if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
192
+ return query(':firstHost', {})(targetOrOptions, propertyKey);
193
+ }
194
+ if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
195
+ return query(':firstHost', targetOrOptions as SwcQueryOptions);
196
+ } else {
197
+ return query(':firstHost', {});
198
+ }
199
+ }
200
+
201
+ /**
202
+ * @lastHost - Query :lastHost (Last component in hierarchy)
203
+ * Usage: @lastHost last: HTMLElement | undefined;
204
+ * Usage: @lastHost() last: HTMLElement | undefined;
205
+ * Usage: @lastHost({ root: 'shadow' }) last: HTMLElement | undefined;
206
+ */
207
+ export function lastHost(target: Object, propertyKey: string | symbol): void;
208
+ export function lastHost(): PropertyDecorator;
209
+ export function lastHost(options: SwcQueryOptions): PropertyDecorator;
210
+ export function lastHost(targetOrOptions?: any, propertyKey?: string | symbol): any {
211
+ if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
212
+ return query(':lastHost', {})(targetOrOptions, propertyKey);
213
+ }
214
+ if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
215
+ return query(':lastHost', targetOrOptions as SwcQueryOptions);
216
+ } else {
217
+ return query(':lastHost', {});
218
+ }
219
+ }
220
+
221
+ /**
222
+ * @firstAppHost - Query :firstAppHost (First <swc-app> in hierarchy)
223
+ * Usage: @firstAppHost app: SwcAppInterface | undefined;
224
+ * Usage: @firstAppHost() app: SwcAppInterface | undefined;
225
+ * Usage: @firstAppHost({ root: 'shadow' }) app: SwcAppInterface | undefined;
226
+ */
227
+ export function firstAppHost(target: Object, propertyKey: string | symbol): void;
228
+ export function firstAppHost(): PropertyDecorator;
229
+ export function firstAppHost(options: SwcQueryOptions): PropertyDecorator;
230
+ export function firstAppHost(targetOrOptions?: any, propertyKey?: string | symbol): any {
231
+ if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
232
+ return query(':firstAppHost', {})(targetOrOptions, propertyKey);
233
+ }
234
+ if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
235
+ return query(':firstAppHost', targetOrOptions as SwcQueryOptions);
236
+ } else {
237
+ return query(':firstAppHost', {});
238
+ }
239
+ }
240
+
241
+ /**
242
+ * @lastAppHost - Query :lastAppHost (Last <swc-app> in hierarchy)
243
+ * Usage: @lastAppHost app: SwcAppInterface | undefined;
244
+ * Usage: @lastAppHost() app: SwcAppInterface | undefined;
245
+ * Usage: @lastAppHost({ root: 'shadow' }) app: SwcAppInterface | undefined;
246
+ */
247
+ export function lastAppHost(target: Object, propertyKey: string | symbol): void;
248
+ export function lastAppHost(): PropertyDecorator;
249
+ export function lastAppHost(options: SwcQueryOptions): PropertyDecorator;
250
+ export function lastAppHost(targetOrOptions?: any, propertyKey?: string | symbol): any {
251
+ if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
252
+ return query(':lastAppHost', {})(targetOrOptions, propertyKey);
253
+ }
254
+ if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
255
+ return query(':lastAppHost', targetOrOptions as SwcQueryOptions);
256
+ } else {
257
+ return query(':lastAppHost', {});
258
+ }
117
259
  }
@@ -113,6 +113,152 @@ export const getQueryAllMetadata = (target: any): QueryAllMetadata[] | undefined
113
113
  * Usage: @hostQueryAll()
114
114
  * Usage: @hostQueryAll({ root: 'shadow' })
115
115
  */
116
- export function queryAllHost(options?: SwcQueryOptions): PropertyDecorator {
117
- return queryAll(':host', options);
116
+ /**
117
+ * @queryAllHost decorator - simplified version of @queryAll for :host selector
118
+ * Usage: @queryAllHost items: HTMLElement[];
119
+ * Usage: @queryAllHost() items: HTMLElement[];
120
+ * Usage: @queryAllHost({ root: 'shadow' }) items: HTMLElement[];
121
+ */
122
+ export function queryAllHost(target: Object, propertyKey: string | symbol): void;
123
+ export function queryAllHost(): PropertyDecorator;
124
+ export function queryAllHost(options: SwcQueryOptions): PropertyDecorator;
125
+ export function queryAllHost(targetOrOptions?: any, propertyKey?: string | symbol): any {
126
+ // Direct decorator usage: @queryAllHost (no parentheses)
127
+ if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
128
+ return queryAll(':host', {})(targetOrOptions, propertyKey);
129
+ }
130
+
131
+ // @queryAllHost() or @queryAllHost(options)
132
+ if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
133
+ return queryAll(':host', targetOrOptions as SwcQueryOptions);
134
+ } else {
135
+ return queryAll(':host', {});
136
+ }
137
+ }
138
+
139
+ /**
140
+ * @allHost - Alias for @queryAllHost decorator
141
+ * Usage: @allHost items: HTMLElement[];
142
+ * Usage: @allHost() items: HTMLElement[];
143
+ * Usage: @allHost({ root: 'shadow' }) items: HTMLElement[];
144
+ */
145
+ export const allHost = queryAllHost;
146
+ /**
147
+ * @allParentHost - Query all :parentHost (All parent SWC components)
148
+ * Usage: @allParentHost parents: HTMLElement[];
149
+ * Usage: @allParentHost() parents: HTMLElement[];
150
+ * Usage: @allParentHost({ root: 'shadow' }) parents: HTMLElement[];
151
+ */
152
+ export function allParentHost(target: Object, propertyKey: string | symbol): void;
153
+ export function allParentHost(): PropertyDecorator;
154
+ export function allParentHost(options: SwcQueryOptions): PropertyDecorator;
155
+ export function allParentHost(targetOrOptions?: any, propertyKey?: string | symbol): any {
156
+ if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
157
+ return queryAll(':parentHost', {})(targetOrOptions, propertyKey);
158
+ }
159
+ if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
160
+ return queryAll(':parentHost', targetOrOptions as SwcQueryOptions);
161
+ } else {
162
+ return queryAll(':parentHost', {});
163
+ }
164
+ }
165
+
166
+ /**
167
+ * @allAppHost - Query all :appHost (All <swc-app> instances)
168
+ * Usage: @allAppHost apps: SwcAppInterface[];
169
+ * Usage: @allAppHost() apps: SwcAppInterface[];
170
+ * Usage: @allAppHost({ root: 'shadow' }) apps: SwcAppInterface[];
171
+ */
172
+ export function allAppHost(target: Object, propertyKey: string | symbol): void;
173
+ export function allAppHost(): PropertyDecorator;
174
+ export function allAppHost(options: SwcQueryOptions): PropertyDecorator;
175
+ export function allAppHost(targetOrOptions?: any, propertyKey?: string | symbol): any {
176
+ if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
177
+ return queryAll(':appHost', {})(targetOrOptions, propertyKey);
178
+ }
179
+ if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
180
+ return queryAll(':appHost', targetOrOptions as SwcQueryOptions);
181
+ } else {
182
+ return queryAll(':appHost', {});
183
+ }
184
+ }
185
+
186
+ /**
187
+ * @allFirstHost - Query all :firstHost (All first components in hierarchy)
188
+ * Usage: @allFirstHost firsts: HTMLElement[];
189
+ * Usage: @allFirstHost() firsts: HTMLElement[];
190
+ * Usage: @allFirstHost({ root: 'shadow' }) firsts: HTMLElement[];
191
+ */
192
+ export function allFirstHost(target: Object, propertyKey: string | symbol): void;
193
+ export function allFirstHost(): PropertyDecorator;
194
+ export function allFirstHost(options: SwcQueryOptions): PropertyDecorator;
195
+ export function allFirstHost(targetOrOptions?: any, propertyKey?: string | symbol): any {
196
+ if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
197
+ return queryAll(':firstHost', {})(targetOrOptions, propertyKey);
198
+ }
199
+ if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
200
+ return queryAll(':firstHost', targetOrOptions as SwcQueryOptions);
201
+ } else {
202
+ return queryAll(':firstHost', {});
203
+ }
204
+ }
205
+
206
+ /**
207
+ * @allLastHost - Query all :lastHost (All last components in hierarchy)
208
+ * Usage: @allLastHost lasts: HTMLElement[];
209
+ * Usage: @allLastHost() lasts: HTMLElement[];
210
+ * Usage: @allLastHost({ root: 'shadow' }) lasts: HTMLElement[];
211
+ */
212
+ export function allLastHost(target: Object, propertyKey: string | symbol): void;
213
+ export function allLastHost(): PropertyDecorator;
214
+ export function allLastHost(options: SwcQueryOptions): PropertyDecorator;
215
+ export function allLastHost(targetOrOptions?: any, propertyKey?: string | symbol): any {
216
+ if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
217
+ return queryAll(':lastHost', {})(targetOrOptions, propertyKey);
218
+ }
219
+ if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
220
+ return queryAll(':lastHost', targetOrOptions as SwcQueryOptions);
221
+ } else {
222
+ return queryAll(':lastHost', {});
223
+ }
118
224
  }
225
+
226
+ /**
227
+ * @allFirstAppHost - Query all :firstAppHost (All first <swc-app> in hierarchy)
228
+ * Usage: @allFirstAppHost apps: SwcAppInterface[];
229
+ * Usage: @allFirstAppHost() apps: SwcAppInterface[];
230
+ * Usage: @allFirstAppHost({ root: 'shadow' }) apps: SwcAppInterface[];
231
+ */
232
+ export function allFirstAppHost(target: Object, propertyKey: string | symbol): void;
233
+ export function allFirstAppHost(): PropertyDecorator;
234
+ export function allFirstAppHost(options: SwcQueryOptions): PropertyDecorator;
235
+ export function allFirstAppHost(targetOrOptions?: any, propertyKey?: string | symbol): any {
236
+ if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
237
+ return queryAll(':firstAppHost', {})(targetOrOptions, propertyKey);
238
+ }
239
+ if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
240
+ return queryAll(':firstAppHost', targetOrOptions as SwcQueryOptions);
241
+ } else {
242
+ return queryAll(':firstAppHost', {});
243
+ }
244
+ }
245
+
246
+ /**
247
+ * @allLastAppHost - Query all :lastAppHost (All last <swc-app> in hierarchy)
248
+ * Usage: @allLastAppHost apps: SwcAppInterface[];
249
+ * Usage: @allLastAppHost() apps: SwcAppInterface[];
250
+ * Usage: @allLastAppHost({ root: 'shadow' }) apps: SwcAppInterface[];
251
+ */
252
+ export function allLastAppHost(target: Object, propertyKey: string | symbol): void;
253
+ export function allLastAppHost(): PropertyDecorator;
254
+ export function allLastAppHost(options: SwcQueryOptions): PropertyDecorator;
255
+ export function allLastAppHost(targetOrOptions?: any, propertyKey?: string | symbol): any {
256
+ if (propertyKey !== undefined && (typeof propertyKey === 'string' || typeof propertyKey === 'symbol')) {
257
+ return queryAll(':lastAppHost', {})(targetOrOptions, propertyKey);
258
+ }
259
+ if (typeof targetOrOptions === 'object' && targetOrOptions !== null) {
260
+ return queryAll(':lastAppHost', targetOrOptions as SwcQueryOptions);
261
+ } else {
262
+ return queryAll(':lastAppHost', {});
263
+ }
264
+ }
@@ -44,11 +44,12 @@ export function setAttribute(selector: string, name: string, options: SwcQueryOp
44
44
  const applyRoot = (t: any) => {
45
45
  if (!t) return;
46
46
  if (r === 'auto') {
47
- targetEls.push((t as any).shadowRoot || t);
48
- return;
47
+ // Attributes belong to the ELEMENT, not the ShadowRoot.
48
+ targetEls.push(t);
49
+ } else {
50
+ if (r === 'light' || r === 'all') targetEls.push(t);
51
+ if ((r === 'shadow' || r === 'all') && (t as any).shadowRoot) targetEls.push((t as any).shadowRoot);
49
52
  }
50
- if (r === 'light' || r === 'all') targetEls.push(t);
51
- if ((r === 'shadow' || r === 'all') && (t as any).shadowRoot) targetEls.push((t as any).shadowRoot);
52
53
  };
53
54
 
54
55
  if (selector === ':window') targetEls.push(currentWin);
@@ -81,7 +82,7 @@ export function setAttribute(selector: string, name: string, options: SwcQueryOp
81
82
  if (!targetEl || typeof (targetEl as any).setAttribute !== 'function') return;
82
83
  if (res === null) (targetEl as any).removeAttribute(name);
83
84
  else (targetEl as any).setAttribute(name, String(res));
84
- })
85
+ });
85
86
  }
86
87
  return res;
87
88
  };
@@ -5,8 +5,7 @@ import { SwcQueryOptions } from '../types';
5
5
 
6
6
  export type StyleAction = 'set' | 'update' | 'remove';
7
7
 
8
- export interface StyleOptions extends SwcQueryOptions {
9
- }
8
+ export interface StyleOptions extends SwcQueryOptions {}
10
9
 
11
10
  export interface StyleMetadata {
12
11
  propertyKey: string | symbol;
@@ -37,28 +36,44 @@ function createStyleDecorator(action: StyleAction) {
37
36
  const hostSet = SwcUtils.getHostSet(this as any);
38
37
  const targetEls: HTMLElement[] = [];
39
38
 
40
- if (selector === ':host' || !selector) {
41
- targetEls.push(this as any);
42
- } else if (selector === ':parentHost') {
43
- if (hostSet.$parentHost) targetEls.push(hostSet.$parentHost);
44
- } else if (selector === ':appHost') {
45
- if (hostSet.$appHost) targetEls.push(hostSet.$appHost);
46
- } else {
39
+ const applyRoot = (t: any) => {
40
+ if (!t || !(t instanceof HTMLElement)) return;
41
+ if (r === 'auto') {
42
+ // Styles belong to the ELEMENT, not the ShadowRoot.
43
+ targetEls.push(t);
44
+ } else {
45
+ if (r === 'light' || r === 'all') targetEls.push(t);
46
+ if ((r === 'shadow' || r === 'all') && t.shadowRoot) {
47
+ // ShadowRoot doesn't have a style property, so we skip it.
48
+ }
49
+ }
50
+ };
51
+
52
+ if (selector === ':parentHost') applyRoot(hostSet.$parentHost);
53
+ else if (selector === ':appHost') applyRoot(hostSet.$appHost);
54
+ else if (selector === ':firstHost') applyRoot(hostSet.$firstHost);
55
+ else if (selector === ':lastHost') applyRoot(hostSet.$lastHost);
56
+ else if (selector === ':firstAppHost') applyRoot(hostSet.$firstAppHost);
57
+ else if (selector === ':lastAppHost') applyRoot(hostSet.$lastAppHost);
58
+ else if (selector === ':hosts') hostSet.$hosts.forEach(applyRoot);
59
+ else if (selector === ':appHosts') hostSet.$appHosts.forEach(applyRoot);
60
+ else if (selector === ':host' || !selector) applyRoot(this);
61
+ else {
47
62
  if (r === 'shadow') {
48
63
  const found = this.shadowRoot?.querySelectorAll(selector);
49
- if (found) targetEls.push(...found);
64
+ if (found) targetEls.push(...(Array.from(found) as HTMLElement[]));
50
65
  } else if (r === 'light') {
51
66
  const found = (this as any).querySelectorAll(selector);
52
- if (found) targetEls.push(...found);
67
+ if (found) targetEls.push(...(Array.from(found) as HTMLElement[]));
53
68
  } else if (r === 'all') {
54
69
  const sFound = this.shadowRoot?.querySelectorAll(selector);
55
70
  const lFound = (this as any).querySelectorAll(selector);
56
- if (sFound) targetEls.push(...sFound);
57
- if (lFound) targetEls.push(...lFound);
71
+ if (sFound) targetEls.push(...(Array.from(sFound) as HTMLElement[]));
72
+ if (lFound) targetEls.push(...(Array.from(lFound) as HTMLElement[]));
58
73
  } else {
59
74
  // auto
60
75
  const found = (this.shadowRoot || (this as any)).querySelectorAll(selector);
61
- if (found) targetEls.push(...found);
76
+ if (found) targetEls.push(...(Array.from(found) as HTMLElement[]));
62
77
  }
63
78
  }
64
79
 
@@ -95,10 +110,20 @@ export const setStyle = (selector: string, options: StyleOptions = {}) => create
95
110
 
96
111
  /**
97
112
  * @setStyleHost decorator - simplified version of @setStyle for :host selector.
98
- * Usage: @setStyleHost getStyles() { return { color: 'red', display: 'block' }; }
99
- * Usage: @setStyleHost({ root: 'shadow' }) getStyles() { return { color: 'red' }; }
113
+ * Usage: @setStyleHost setHostStyle() { return { color: 'red' }; }
114
+ * Usage: @setStyleHost() setHostStyle() { return { color: 'red' }; }
115
+ * Usage: @setStyleHost({ ... }) setHostStyle() { return { color: 'red' }; }
100
116
  */
101
- export const setStyleHost = (options: StyleOptions = {}) => createStyleDecorator('set')(':host', options);
117
+ export function setStyleHost(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): any;
118
+ export function setStyleHost(): MethodDecorator;
119
+ export function setStyleHost(options: StyleOptions): MethodDecorator;
120
+ export function setStyleHost(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
121
+ if (propertyKey !== undefined) {
122
+ const decorator = createStyleDecorator('set')(':host', {});
123
+ return decorator(targetOrOptions, propertyKey, descriptor);
124
+ }
125
+ return createStyleDecorator('set')(':host', (targetOrOptions as StyleOptions) || {});
126
+ }
102
127
 
103
128
  /**
104
129
  * @updateStyle decorator to surgically update styles on a target element (merges with existing styles).
@@ -110,9 +135,19 @@ export const updateStyle = (selector: string, options: StyleOptions = {}) => cre
110
135
  /**
111
136
  * @updateStyleHost decorator - simplified version of @updateStyle for :host selector.
112
137
  * Usage: @updateStyleHost updateStyles() { return { color: 'blue' }; }
113
- * Usage: @updateStyleHost({ root: 'shadow' }) updateStyles() { return { color: 'blue' }; }
138
+ * Usage: @updateStyleHost() updateStyles() { return { color: 'blue' }; }
139
+ * Usage: @updateStyleHost({ ... }) updateStyles() { return { color: 'blue' }; }
114
140
  */
115
- export const updateStyleHost = (options: StyleOptions = {}) => createStyleDecorator('update')(':host', options);
141
+ export function updateStyleHost(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): any;
142
+ export function updateStyleHost(): MethodDecorator;
143
+ export function updateStyleHost(options: StyleOptions): MethodDecorator;
144
+ export function updateStyleHost(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
145
+ if (propertyKey !== undefined) {
146
+ const decorator = createStyleDecorator('update')(':host', {});
147
+ return decorator(targetOrOptions, propertyKey, descriptor);
148
+ }
149
+ return createStyleDecorator('update')(':host', (targetOrOptions as StyleOptions) || {});
150
+ }
116
151
 
117
152
  /**
118
153
  * @removeStyle decorator to surgically remove styles from a target element.
@@ -123,10 +158,20 @@ export const removeStyle = (selector: string, options: StyleOptions = {}) => cre
123
158
 
124
159
  /**
125
160
  * @removeStyleHost decorator - simplified version of @removeStyle for :host selector.
126
- * Usage: @removeStyleHost clearStyles() { return ['color', 'display']; }
127
- * Usage: @removeStyleHost({ root: 'shadow' }) clearStyles() { return ['color']; }
161
+ * Usage: @removeStyleHost clearStyles() { return ['color']; }
162
+ * Usage: @removeStyleHost() clearStyles() { return ['color']; }
163
+ * Usage: @removeStyleHost({ ... }) clearStyles() { return ['color']; }
128
164
  */
129
- export const removeStyleHost = (options: StyleOptions = {}) => createStyleDecorator('remove')(':host', options);
165
+ export function removeStyleHost(target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): any;
166
+ export function removeStyleHost(): MethodDecorator;
167
+ export function removeStyleHost(options: StyleOptions): MethodDecorator;
168
+ export function removeStyleHost(targetOrOptions?: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor): any {
169
+ if (propertyKey !== undefined) {
170
+ const decorator = createStyleDecorator('remove')(':host', {});
171
+ return decorator(targetOrOptions, propertyKey, descriptor);
172
+ }
173
+ return createStyleDecorator('remove')(':host', (targetOrOptions as StyleOptions) || {});
174
+ }
130
175
 
131
176
  export const findAllStyleMetadata = (target: any): Map<string | symbol, StyleMetadata> => {
132
177
  const result = new Map<string | symbol, StyleMetadata>();
package/src/index.ts CHANGED
@@ -10,18 +10,18 @@ export * from './types';
10
10
 
11
11
  // Utilities
12
12
  export * from './utils/Utils';
13
- export * from './utils/TemplateUtils';
14
13
 
15
14
  // Config
16
15
  export * from './config/config';
17
16
 
18
17
  // Registration Factory
19
- export default (w: Window, other?: ((w: Window) => ConstructorType<any>)[]): ConstructorType<any>[] => {
18
+ export default (w: Window, other?: (((w: Window) => ConstructorType<any>) | any) []) => {
20
19
  registerAllElements(w);
21
20
  const r = other?.map(fn => {
22
- const a = fn(w);
23
- // console.log('l', fn, a)
24
- return a;
21
+ if (typeof fn === 'function') {
22
+ const a = fn(w);
23
+ } else {
24
+ }
25
25
  });
26
- return r??[];
26
+ // return r??[];
27
27
  };
@@ -3,6 +3,150 @@ import {getElementConfig} from "../decorators";
3
3
 
4
4
  export const SWC_NOT_FOUND = Symbol('SWC_NOT_FOUND');
5
5
 
6
+ // DOM Creation Utilities
7
+ export const htmlFragment = (html: string, doc?: Document): DocumentFragment => {
8
+ const d = doc || (typeof document !== 'undefined' ? document : undefined);
9
+ if (!d) throw new Error('Document is not available');
10
+ const template = d.createElement('template');
11
+ template.innerHTML = html.trim();
12
+ return template.content;
13
+ };
14
+
15
+ export const textNode = (text: string | any, doc?: Document): Text => {
16
+ const d = doc || (typeof document !== 'undefined' ? document : undefined);
17
+ if (!d) throw new Error('Document is not available');
18
+ return d.createTextNode(text !== undefined && text !== null ? String(text) : '');
19
+ };
20
+
21
+ export const commentNode = (comment: string | any, doc?: Document): Comment => {
22
+ const d = doc || (typeof document !== 'undefined' ? document : undefined);
23
+ if (!d) throw new Error('Document is not available');
24
+ return d.createComment(comment !== undefined && comment !== null ? String(comment) : '');
25
+ };
26
+
27
+ export const createElement = <T extends HTMLElement>(
28
+ tagName: string,
29
+ options?: { html?: string; attrs?: Record<string, any>; doc?: Document }
30
+ ): T => {
31
+ const d = options?.doc || (typeof document !== 'undefined' ? document : undefined);
32
+ if (!d) throw new Error('Document is not available');
33
+ const el = d.createElement(tagName) as T;
34
+ if (options?.html) el.innerHTML = options.html;
35
+ if (options?.attrs) {
36
+ Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));
37
+ }
38
+ return el;
39
+ };
40
+
41
+ // Element factory functions
42
+ export const htmlDivElement = (html: string, options?: { doc?: Document; attrs?: Record<string, any> }): HTMLDivElement => {
43
+ const d = options?.doc || (typeof document !== 'undefined' ? document : undefined);
44
+ if (!d) throw new Error('Document is not available');
45
+ const el = d.createElement('div') as HTMLDivElement;
46
+ el.innerHTML = html.trim();
47
+ if (options?.attrs) {
48
+ Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));
49
+ }
50
+ return el;
51
+ };
52
+
53
+ export const htmlSpanElement = (html: string, options?: { doc?: Document; attrs?: Record<string, any> }): HTMLSpanElement => {
54
+ const d = options?.doc || (typeof document !== 'undefined' ? document : undefined);
55
+ if (!d) throw new Error('Document is not available');
56
+ const el = d.createElement('span') as HTMLSpanElement;
57
+ el.innerHTML = html.trim();
58
+ if (options?.attrs) {
59
+ Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));
60
+ }
61
+ return el;
62
+ };
63
+
64
+ export const htmlButtonElement = (html: string, options?: { doc?: Document; attrs?: Record<string, any> }): HTMLButtonElement => {
65
+ const d = options?.doc || (typeof document !== 'undefined' ? document : undefined);
66
+ if (!d) throw new Error('Document is not available');
67
+ const el = d.createElement('button') as HTMLButtonElement;
68
+ el.innerHTML = html.trim();
69
+ if (options?.attrs) {
70
+ Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));
71
+ }
72
+ return el;
73
+ };
74
+
75
+ export const htmlUlElement = (options?: { doc?: Document; attrs?: Record<string, any> }): HTMLUListElement => {
76
+ const d = options?.doc || (typeof document !== 'undefined' ? document : undefined);
77
+ if (!d) throw new Error('Document is not available');
78
+ const el = d.createElement('ul') as HTMLUListElement;
79
+ if (options?.attrs) {
80
+ Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));
81
+ }
82
+ return el;
83
+ };
84
+
85
+ export const htmlLiElement = (html: string, options?: { doc?: Document; attrs?: Record<string, any> }): HTMLLIElement => {
86
+ const d = options?.doc || (typeof document !== 'undefined' ? document : undefined);
87
+ if (!d) throw new Error('Document is not available');
88
+ const el = d.createElement('li') as HTMLLIElement;
89
+ el.innerHTML = html.trim();
90
+ if (options?.attrs) {
91
+ Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));
92
+ }
93
+ return el;
94
+ };
95
+
96
+ export const htmlAElement = (html: string, options?: { href?: string; doc?: Document; attrs?: Record<string, any> }): HTMLAnchorElement => {
97
+ const d = options?.doc || (typeof document !== 'undefined' ? document : undefined);
98
+ if (!d) throw new Error('Document is not available');
99
+ const el = d.createElement('a') as HTMLAnchorElement;
100
+ el.innerHTML = html.trim();
101
+ if (options?.href) el.href = options.href;
102
+ if (options?.attrs) {
103
+ Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));
104
+ }
105
+ return el;
106
+ };
107
+
108
+ export const htmlPElement = (html: string, options?: { doc?: Document; attrs?: Record<string, any> }): HTMLParagraphElement => {
109
+ const d = options?.doc || (typeof document !== 'undefined' ? document : undefined);
110
+ if (!d) throw new Error('Document is not available');
111
+ const el = d.createElement('p') as HTMLParagraphElement;
112
+ el.innerHTML = html.trim();
113
+ if (options?.attrs) {
114
+ Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));
115
+ }
116
+ return el;
117
+ };
118
+
119
+ export const htmlHeadingElement = (level: 1 | 2 | 3 | 4 | 5 | 6, html: string, options?: { doc?: Document; attrs?: Record<string, any> }): HTMLHeadingElement => {
120
+ const d = options?.doc || (typeof document !== 'undefined' ? document : undefined);
121
+ if (!d) throw new Error('Document is not available');
122
+ const el = d.createElement(`h${level}`) as HTMLHeadingElement;
123
+ el.innerHTML = html.trim();
124
+ if (options?.attrs) {
125
+ Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));
126
+ }
127
+ return el;
128
+ };
129
+
130
+ export const htmlSectionElement = (options?: { doc?: Document; attrs?: Record<string, any> }): HTMLElement => {
131
+ const d = options?.doc || (typeof document !== 'undefined' ? document : undefined);
132
+ if (!d) throw new Error('Document is not available');
133
+ const el = d.createElement('section');
134
+ if (options?.attrs) {
135
+ Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));
136
+ }
137
+ return el;
138
+ };
139
+
140
+ export const htmlArticleElement = (options?: { doc?: Document; attrs?: Record<string, any> }): HTMLElement => {
141
+ const d = options?.doc || (typeof document !== 'undefined' ? document : undefined);
142
+ if (!d) throw new Error('Document is not available');
143
+ const el = d.createElement('article');
144
+ if (options?.attrs) {
145
+ Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));
146
+ }
147
+ return el;
148
+ };
149
+
6
150
  export namespace SwcUtils {
7
151
  export const getHelperSet = (win: Window): HelperSet => {
8
152
  const doc: Document = win.document;