@dooboostore/simple-web-component 1.0.23 → 1.0.25

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 (149) hide show
  1. package/README.md +64 -3212
  2. package/dist/cjs/decorators/addEventListener.js +1 -1
  3. package/dist/cjs/decorators/addEventListener.js.map +2 -2
  4. package/dist/cjs/decorators/applyAttribute.js +148 -0
  5. package/dist/cjs/decorators/applyAttribute.js.map +7 -0
  6. package/dist/cjs/decorators/applyClass.js +164 -0
  7. package/dist/cjs/decorators/applyClass.js.map +7 -0
  8. package/dist/cjs/decorators/applyNode.js +97 -109
  9. package/dist/cjs/decorators/applyNode.js.map +2 -2
  10. package/dist/cjs/decorators/applyStyle.js +135 -0
  11. package/dist/cjs/decorators/applyStyle.js.map +7 -0
  12. package/dist/cjs/decorators/attribute.js +24 -11
  13. package/dist/cjs/decorators/attribute.js.map +2 -2
  14. package/dist/cjs/decorators/changedAttributeHost.js +1 -1
  15. package/dist/cjs/decorators/changedAttributeHost.js.map +2 -2
  16. package/dist/cjs/decorators/elementDefine.js +14 -23
  17. package/dist/cjs/decorators/elementDefine.js.map +2 -2
  18. package/dist/cjs/decorators/emitCustomEvent.js +5 -2
  19. package/dist/cjs/decorators/emitCustomEvent.js.map +2 -2
  20. package/dist/cjs/decorators/index.js +3 -3
  21. package/dist/cjs/decorators/index.js.map +2 -2
  22. package/dist/cjs/decorators/lifecycles.js +9 -9
  23. package/dist/cjs/decorators/lifecycles.js.map +2 -2
  24. package/dist/cjs/decorators/query.js +78 -3
  25. package/dist/cjs/decorators/query.js.map +2 -2
  26. package/dist/cjs/decorators/queryAll.js +78 -3
  27. package/dist/cjs/decorators/queryAll.js.map +2 -2
  28. package/dist/cjs/elements/SwcAppEngine.js +19 -4
  29. package/dist/cjs/elements/SwcAppEngine.js.map +2 -2
  30. package/dist/cjs/elements/SwcAppMixin.js +2 -0
  31. package/dist/cjs/elements/SwcAppMixin.js.map +2 -2
  32. package/dist/cjs/index.js +4 -4
  33. package/dist/cjs/index.js.map +2 -2
  34. package/dist/cjs/utils/Utils.js +141 -2
  35. package/dist/cjs/utils/Utils.js.map +2 -2
  36. package/dist/esm/decorators/addEventListener.js +1 -1
  37. package/dist/esm/decorators/addEventListener.js.map +2 -2
  38. package/dist/esm/decorators/applyAttribute.js +129 -0
  39. package/dist/esm/decorators/applyAttribute.js.map +7 -0
  40. package/dist/esm/decorators/applyClass.js +145 -0
  41. package/dist/esm/decorators/applyClass.js.map +7 -0
  42. package/dist/esm/decorators/applyNode.js +97 -109
  43. package/dist/esm/decorators/applyNode.js.map +2 -2
  44. package/dist/esm/decorators/applyStyle.js +116 -0
  45. package/dist/esm/decorators/applyStyle.js.map +7 -0
  46. package/dist/esm/decorators/attribute.js +24 -11
  47. package/dist/esm/decorators/attribute.js.map +2 -2
  48. package/dist/esm/decorators/changedAttributeHost.js +1 -1
  49. package/dist/esm/decorators/changedAttributeHost.js.map +2 -2
  50. package/dist/esm/decorators/elementDefine.js +14 -23
  51. package/dist/esm/decorators/elementDefine.js.map +2 -2
  52. package/dist/esm/decorators/emitCustomEvent.js +5 -2
  53. package/dist/esm/decorators/emitCustomEvent.js.map +2 -2
  54. package/dist/esm/decorators/index.js +3 -3
  55. package/dist/esm/decorators/index.js.map +1 -1
  56. package/dist/esm/decorators/lifecycles.js +9 -9
  57. package/dist/esm/decorators/lifecycles.js.map +2 -2
  58. package/dist/esm/decorators/query.js +78 -3
  59. package/dist/esm/decorators/query.js.map +2 -2
  60. package/dist/esm/decorators/queryAll.js +78 -3
  61. package/dist/esm/decorators/queryAll.js.map +2 -2
  62. package/dist/esm/elements/SwcAppEngine.js +19 -4
  63. package/dist/esm/elements/SwcAppEngine.js.map +2 -2
  64. package/dist/esm/elements/SwcAppMixin.js +2 -0
  65. package/dist/esm/elements/SwcAppMixin.js.map +2 -2
  66. package/dist/esm/index.js +4 -4
  67. package/dist/esm/index.js.map +2 -2
  68. package/dist/esm/utils/Utils.js +141 -2
  69. package/dist/esm/utils/Utils.js.map +2 -2
  70. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js +3191 -506
  71. package/dist/esm-bundle/dooboostore-simple-web-component.esm.js.map +4 -4
  72. package/dist/types/decorators/addEventListener.d.ts.map +1 -1
  73. package/dist/types/decorators/applyAttribute.d.ts +22 -0
  74. package/dist/types/decorators/applyAttribute.d.ts.map +1 -0
  75. package/dist/types/decorators/applyClass.d.ts +65 -0
  76. package/dist/types/decorators/applyClass.d.ts.map +1 -0
  77. package/dist/types/decorators/applyNode.d.ts +18 -104
  78. package/dist/types/decorators/applyNode.d.ts.map +1 -1
  79. package/dist/types/decorators/applyStyle.d.ts +21 -0
  80. package/dist/types/decorators/applyStyle.d.ts.map +1 -0
  81. package/dist/types/decorators/attribute.d.ts +12 -14
  82. package/dist/types/decorators/attribute.d.ts.map +1 -1
  83. package/dist/types/decorators/changedAttributeHost.d.ts.map +1 -1
  84. package/dist/types/decorators/elementDefine.d.ts.map +1 -1
  85. package/dist/types/decorators/emitCustomEvent.d.ts +1 -1
  86. package/dist/types/decorators/emitCustomEvent.d.ts.map +1 -1
  87. package/dist/types/decorators/index.d.ts +3 -3
  88. package/dist/types/decorators/index.d.ts.map +1 -1
  89. package/dist/types/decorators/lifecycles.d.ts.map +1 -1
  90. package/dist/types/decorators/query.d.ts +68 -4
  91. package/dist/types/decorators/query.d.ts.map +1 -1
  92. package/dist/types/decorators/queryAll.d.ts +70 -1
  93. package/dist/types/decorators/queryAll.d.ts.map +1 -1
  94. package/dist/types/elements/SwcAppEngine.d.ts +7 -0
  95. package/dist/types/elements/SwcAppEngine.d.ts.map +1 -1
  96. package/dist/types/elements/SwcAppMixin.d.ts +1 -1
  97. package/dist/types/elements/SwcAppMixin.d.ts.map +1 -1
  98. package/dist/types/index.d.ts +1 -2
  99. package/dist/types/index.d.ts.map +1 -1
  100. package/dist/types/utils/Utils.d.ts +49 -0
  101. package/dist/types/utils/Utils.d.ts.map +1 -1
  102. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js +3191 -506
  103. package/dist/umd-bundle/dooboostore-simple-web-component.umd.js.map +4 -4
  104. package/package.json +3 -3
  105. package/src/decorators/addEventListener.ts +1 -1
  106. package/src/decorators/applyAttribute.ts +147 -0
  107. package/src/decorators/applyClass.ts +158 -0
  108. package/src/decorators/applyNode.ts +126 -225
  109. package/src/decorators/applyStyle.ts +128 -0
  110. package/src/decorators/attribute.ts +42 -43
  111. package/src/decorators/changedAttributeHost.ts +2 -2
  112. package/src/decorators/elementDefine.ts +18 -39
  113. package/src/decorators/emitCustomEvent.ts +6 -3
  114. package/src/decorators/index.ts +3 -3
  115. package/src/decorators/lifecycles.ts +9 -11
  116. package/src/decorators/query.ts +148 -6
  117. package/src/decorators/queryAll.ts +149 -3
  118. package/src/elements/SwcAppEngine.ts +32 -4
  119. package/src/elements/SwcAppMixin.ts +2 -0
  120. package/src/index.ts +6 -6
  121. package/src/utils/Utils.ts +146 -1
  122. package/dist/cjs/decorators/classList.js +0 -134
  123. package/dist/cjs/decorators/classList.js.map +0 -7
  124. package/dist/cjs/decorators/setAttribute.js +0 -111
  125. package/dist/cjs/decorators/setAttribute.js.map +0 -7
  126. package/dist/cjs/decorators/style.js +0 -114
  127. package/dist/cjs/decorators/style.js.map +0 -7
  128. package/dist/cjs/utils/TemplateUtils.js +0 -109
  129. package/dist/cjs/utils/TemplateUtils.js.map +0 -7
  130. package/dist/esm/decorators/classList.js +0 -115
  131. package/dist/esm/decorators/classList.js.map +0 -7
  132. package/dist/esm/decorators/setAttribute.js +0 -92
  133. package/dist/esm/decorators/setAttribute.js.map +0 -7
  134. package/dist/esm/decorators/style.js +0 -95
  135. package/dist/esm/decorators/style.js.map +0 -7
  136. package/dist/esm/utils/TemplateUtils.js +0 -90
  137. package/dist/esm/utils/TemplateUtils.js.map +0 -7
  138. package/dist/types/decorators/classList.d.ts +0 -61
  139. package/dist/types/decorators/classList.d.ts.map +0 -1
  140. package/dist/types/decorators/setAttribute.d.ts +0 -23
  141. package/dist/types/decorators/setAttribute.d.ts.map +0 -1
  142. package/dist/types/decorators/style.d.ts +0 -49
  143. package/dist/types/decorators/style.d.ts.map +0 -1
  144. package/dist/types/utils/TemplateUtils.d.ts +0 -59
  145. package/dist/types/utils/TemplateUtils.d.ts.map +0 -1
  146. package/src/decorators/classList.ts +0 -172
  147. package/src/decorators/setAttribute.ts +0 -113
  148. package/src/decorators/style.ts +0 -140
  149. package/src/utils/TemplateUtils.ts +0 -92
@@ -18,11 +18,150 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
18
18
  var Utils_exports = {};
19
19
  __export(Utils_exports, {
20
20
  SWC_NOT_FOUND: () => SWC_NOT_FOUND,
21
- SwcUtils: () => SwcUtils
21
+ SwcUtils: () => SwcUtils,
22
+ commentNode: () => commentNode,
23
+ createElement: () => createElement,
24
+ htmlAElement: () => htmlAElement,
25
+ htmlArticleElement: () => htmlArticleElement,
26
+ htmlButtonElement: () => htmlButtonElement,
27
+ htmlDivElement: () => htmlDivElement,
28
+ htmlFragment: () => htmlFragment,
29
+ htmlHeadingElement: () => htmlHeadingElement,
30
+ htmlLiElement: () => htmlLiElement,
31
+ htmlPElement: () => htmlPElement,
32
+ htmlSectionElement: () => htmlSectionElement,
33
+ htmlSpanElement: () => htmlSpanElement,
34
+ htmlUlElement: () => htmlUlElement,
35
+ textNode: () => textNode
22
36
  });
23
37
  module.exports = __toCommonJS(Utils_exports);
24
38
  var import_decorators = require("../decorators");
25
- const SWC_NOT_FOUND = Symbol("SWC_NOT_FOUND");
39
+ const SWC_NOT_FOUND = Symbol.for("simple-web-component:not-found");
40
+ const htmlFragment = (html, doc) => {
41
+ const d = doc || (typeof document !== "undefined" ? document : void 0);
42
+ if (!d) throw new Error("Document is not available");
43
+ const template = d.createElement("template");
44
+ template.innerHTML = html.trim();
45
+ return template.content;
46
+ };
47
+ const textNode = (text, doc) => {
48
+ const d = doc || (typeof document !== "undefined" ? document : void 0);
49
+ if (!d) throw new Error("Document is not available");
50
+ return d.createTextNode(text !== void 0 && text !== null ? String(text) : "");
51
+ };
52
+ const commentNode = (comment, doc) => {
53
+ const d = doc || (typeof document !== "undefined" ? document : void 0);
54
+ if (!d) throw new Error("Document is not available");
55
+ return d.createComment(comment !== void 0 && comment !== null ? String(comment) : "");
56
+ };
57
+ const createElement = (tagName, options) => {
58
+ const d = options?.doc || (typeof document !== "undefined" ? document : void 0);
59
+ if (!d) throw new Error("Document is not available");
60
+ const el = d.createElement(tagName);
61
+ if (options?.html) el.innerHTML = options.html;
62
+ if (options?.attrs) {
63
+ Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));
64
+ }
65
+ return el;
66
+ };
67
+ const htmlDivElement = (html, options) => {
68
+ const d = options?.doc || (typeof document !== "undefined" ? document : void 0);
69
+ if (!d) throw new Error("Document is not available");
70
+ const el = d.createElement("div");
71
+ el.innerHTML = html.trim();
72
+ if (options?.attrs) {
73
+ Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));
74
+ }
75
+ return el;
76
+ };
77
+ const htmlSpanElement = (html, options) => {
78
+ const d = options?.doc || (typeof document !== "undefined" ? document : void 0);
79
+ if (!d) throw new Error("Document is not available");
80
+ const el = d.createElement("span");
81
+ el.innerHTML = html.trim();
82
+ if (options?.attrs) {
83
+ Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));
84
+ }
85
+ return el;
86
+ };
87
+ const htmlButtonElement = (html, options) => {
88
+ const d = options?.doc || (typeof document !== "undefined" ? document : void 0);
89
+ if (!d) throw new Error("Document is not available");
90
+ const el = d.createElement("button");
91
+ el.innerHTML = html.trim();
92
+ if (options?.attrs) {
93
+ Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));
94
+ }
95
+ return el;
96
+ };
97
+ const htmlUlElement = (options) => {
98
+ const d = options?.doc || (typeof document !== "undefined" ? document : void 0);
99
+ if (!d) throw new Error("Document is not available");
100
+ const el = d.createElement("ul");
101
+ if (options?.attrs) {
102
+ Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));
103
+ }
104
+ return el;
105
+ };
106
+ const htmlLiElement = (html, options) => {
107
+ const d = options?.doc || (typeof document !== "undefined" ? document : void 0);
108
+ if (!d) throw new Error("Document is not available");
109
+ const el = d.createElement("li");
110
+ el.innerHTML = html.trim();
111
+ if (options?.attrs) {
112
+ Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));
113
+ }
114
+ return el;
115
+ };
116
+ const htmlAElement = (html, options) => {
117
+ const d = options?.doc || (typeof document !== "undefined" ? document : void 0);
118
+ if (!d) throw new Error("Document is not available");
119
+ const el = d.createElement("a");
120
+ el.innerHTML = html.trim();
121
+ if (options?.href) el.href = options.href;
122
+ if (options?.attrs) {
123
+ Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));
124
+ }
125
+ return el;
126
+ };
127
+ const htmlPElement = (html, options) => {
128
+ const d = options?.doc || (typeof document !== "undefined" ? document : void 0);
129
+ if (!d) throw new Error("Document is not available");
130
+ const el = d.createElement("p");
131
+ el.innerHTML = html.trim();
132
+ if (options?.attrs) {
133
+ Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));
134
+ }
135
+ return el;
136
+ };
137
+ const htmlHeadingElement = (level, html, options) => {
138
+ const d = options?.doc || (typeof document !== "undefined" ? document : void 0);
139
+ if (!d) throw new Error("Document is not available");
140
+ const el = d.createElement(`h${level}`);
141
+ el.innerHTML = html.trim();
142
+ if (options?.attrs) {
143
+ Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));
144
+ }
145
+ return el;
146
+ };
147
+ const htmlSectionElement = (options) => {
148
+ const d = options?.doc || (typeof document !== "undefined" ? document : void 0);
149
+ if (!d) throw new Error("Document is not available");
150
+ const el = d.createElement("section");
151
+ if (options?.attrs) {
152
+ Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));
153
+ }
154
+ return el;
155
+ };
156
+ const htmlArticleElement = (options) => {
157
+ const d = options?.doc || (typeof document !== "undefined" ? document : void 0);
158
+ if (!d) throw new Error("Document is not available");
159
+ const el = d.createElement("article");
160
+ if (options?.attrs) {
161
+ Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));
162
+ }
163
+ return el;
164
+ };
26
165
  var SwcUtils;
27
166
  ((SwcUtils2) => {
28
167
  SwcUtils2.getHelperSet = (win) => {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/utils/Utils.ts"],
4
- "sourcesContent": ["import { SwcAppInterface, HostSet, HelperSet, HelperHostSet } from '../types';\nimport {getElementConfig} from \"../decorators\";\n\nexport const SWC_NOT_FOUND = Symbol('SWC_NOT_FOUND');\n\nexport namespace SwcUtils {\n export const getHelperSet = (win: Window): HelperSet => {\n const doc: Document = win.document;\n return {\n $d: doc,\n $w: win,\n $q: (sel: string, root?: Element | Document | ShadowRoot) => (root ?? doc).querySelector(sel),\n $qa: (sel: string, root?: Element | Document | ShadowRoot) => Array.from((root ?? doc).querySelectorAll(sel)) as HTMLElement[],\n $qi: (id: string, root?: Document | ShadowRoot) => (root ?? doc).getElementById(id) as HTMLElement\n } as const;\n };\n\n export const getHelperAndHostSet = (win: Window, el: HTMLElement): HelperHostSet => {\n const helperSet = getHelperSet(win);\n const hostSet = getHostSet(el);\n return {\n ...helperSet,\n ...hostSet\n };\n };\n\n export const getValueByPath = (obj: any, path: string, rootName: string) => {\n if (!obj || !path) return SWC_NOT_FOUND;\n\n const parts = path.split('.');\n let current = obj;\n\n for (const part of parts) {\n if (current === null || current === undefined) return SWC_NOT_FOUND;\n current = current[part];\n }\n return current;\n };\n\n /**\n * Finds the nearest logical SWC host for an element.\n * Checks __swc_host property first, then climbs the DOM tree.\n */\n export const findNearestSwcHost = (el: HTMLElement | Node): HTMLElement | undefined => {\n if ((el as any).__swc_host) return (el as any).__swc_host;\n\n let current: any = el.parentElement || (el.getRootNode?.() as any)?.host;\n const doc = el.ownerDocument;\n const win = doc?.defaultView || ((typeof window !== 'undefined' ? window : undefined) as any);\n while (current && current !== doc && current !== win) {\n if (current.__swc_host) return current.__swc_host;\n if (getElementConfig(current)) return current as HTMLElement;\n current = current.parentElement || (current.getRootNode?.() as any)?.host;\n }\n return undefined;\n };\n\n /**\n * Returns all SWC ancestors (excluding self) in [root, ..., parent] order.\n */\n export const findAllSwcHosts = (el: HTMLElement | Node): HTMLElement[] => {\n const hosts: HTMLElement[] = [];\n let current = findNearestSwcHost(el);\n while (current) {\n hosts.push(current);\n // To find the next ancestor, we must start searching from the PARENT of the found host\n current = findNearestSwcHost(current);\n }\n return hosts.reverse();\n };\n\n export const getHosts = (el: HTMLElement): HTMLElement[] => {\n const ancestors = findAllSwcHosts(el);\n if (getElementConfig(el)) return [...ancestors, el];\n return ancestors;\n };\n\n export const getHost = (el: HTMLElement): HTMLElement | undefined => {\n if (getElementConfig(el)) return el;\n return findNearestSwcHost(el);\n };\n\n export const getAppHosts = (el: HTMLElement): SwcAppInterface[] => {\n const hosts = getHosts(el);\n return hosts.filter(host => host.tagName.toLowerCase() === 'swc-app' || host.getAttribute('is')?.startsWith('swc-app-')) as SwcAppInterface[];\n };\n\n export const getAppHost = (el: HTMLElement): SwcAppInterface | undefined => {\n const appHosts = getAppHosts(el);\n const appHostsWithoutSelf = appHosts.filter(h => h !== el);\n return appHostsWithoutSelf.length > 0 ? appHostsWithoutSelf[appHostsWithoutSelf.length - 1] : undefined;\n };\n\n export const getHostSet = (el: HTMLElement): HostSet => {\n const isSwc = !!getElementConfig(el);\n const ancestors = findAllSwcHosts(el); // [root, ..., parent]\n\n let $host: HTMLElement;\n let $parentHost: HTMLElement | null;\n\n if (isSwc) {\n $host = el;\n $parentHost = ancestors.length > 0 ? ancestors[ancestors.length - 1] : null;\n } else {\n $host = ancestors.length > 0 ? ancestors[ancestors.length - 1] : el;\n $parentHost = ancestors.length > 1 ? ancestors[ancestors.length - 2] : null;\n }\n\n const $hosts = isSwc ? [...ancestors, el] : ancestors;\n const $firstHost = $hosts.length > 0 ? $hosts[0] : null;\n\n // Collect loop contexts\n const loopContext: Record<string, any> = {};\n let curr: any = el;\n const rootEl = el.ownerDocument?.documentElement;\n while (curr && curr !== rootEl) {\n if (curr.__swc_loop_context) {\n Object.assign(loopContext, curr.__swc_loop_context);\n }\n curr = curr.parentElement || (curr.getRootNode() as any).host;\n }\n\n const $appHosts = $hosts.filter(h => h.tagName.toLowerCase() === 'swc-app' || h.getAttribute('is')?.startsWith('swc-app-')) as SwcAppInterface[];\n const $appHost = $appHosts.length > 0 ? ($appHosts[$appHosts.length - 1] === el ? ($appHosts.length > 1 ? $appHosts[$appHosts.length - 2] : null) : $appHosts[$appHosts.length - 1]) : null;\n const $firstAppHost = $appHosts.length > 0 ? $appHosts[0] : null;\n\n return {\n $host,\n $parentHost,\n $hosts,\n $firstHost,\n $lastHost: $parentHost,\n $appHost,\n $appHosts,\n $firstAppHost,\n $lastAppHost: $appHost,\n ...loopContext\n } as any;\n };\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,wBAA+B;AAExB,MAAM,gBAAgB,OAAO,eAAe;AAE5C,IAAU;AAAA,CAAV,CAAUA,cAAV;AACE,EAAMA,UAAA,eAAe,CAAC,QAA2B;AACtD,UAAM,MAAgB,IAAI;AAC1B,WAAO;AAAA,MACL,IAAI;AAAA,MACJ,IAAI;AAAA,MACJ,IAAI,CAAC,KAAa,UAA4C,QAAQ,KAAK,cAAc,GAAG;AAAA,MAC5F,KAAK,CAAC,KAAa,SAA2C,MAAM,MAAM,QAAQ,KAAK,iBAAiB,GAAG,CAAC;AAAA,MAC5G,KAAK,CAAC,IAAY,UAAkC,QAAQ,KAAK,eAAe,EAAE;AAAA,IACpF;AAAA,EACF;AAEO,EAAMA,UAAA,sBAAsB,CAAC,KAAa,OAAmC;AAClF,UAAM,gBAAYA,UAAA,cAAa,GA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A,IAC3D;AAEA,UAAM,YAAY,OAAO,OAAO,OAAK,EAAE,QAAQ,YAAY,MAAM,aAAa,EAAE,aAAa,IAAI,GAAG,WAAW,UAAU,CAAC;AAC1H,UAAM,WAAW,UAAU,SAAS,IAAK,UAAU,UAAU,SAAS,CAAC,MAAM,KAAM,UAAU,SAAS,IAAI,UAAU,UAAU,SAAS,CAAC,IAAI,OAAQ,UAAU,UAAU,SAAS,CAAC,IAAK;AACvL,UAAM,gBAAgB,UAAU,SAAS,IAAI,UAAU,CAAC,IAAI;AAE5D,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,WAAW;AAAA,MACX;AAAA,MACA;AAAA,MACA;AAAA,MACA,cAAc;AAAA,MACd,GAAG;AAAA,IACL;AAAA,EACF;AAAA,GArIe;",
4
+ "sourcesContent": ["import { SwcAppInterface, HostSet, HelperSet, HelperHostSet } from '../types';\nimport {getElementConfig} from \"../decorators\";\n\nexport const SWC_NOT_FOUND = Symbol.for('simple-web-component:not-found');\n\n// DOM Creation Utilities\nexport const htmlFragment = (html: string, doc?: Document): DocumentFragment => {\n const d = doc || (typeof document !== 'undefined' ? document : undefined);\n if (!d) throw new Error('Document is not available');\n const template = d.createElement('template');\n template.innerHTML = html.trim();\n return template.content;\n};\n\nexport const textNode = (text: string | any, doc?: Document): Text => {\n const d = doc || (typeof document !== 'undefined' ? document : undefined);\n if (!d) throw new Error('Document is not available');\n return d.createTextNode(text !== undefined && text !== null ? String(text) : '');\n};\n\nexport const commentNode = (comment: string | any, doc?: Document): Comment => {\n const d = doc || (typeof document !== 'undefined' ? document : undefined);\n if (!d) throw new Error('Document is not available');\n return d.createComment(comment !== undefined && comment !== null ? String(comment) : '');\n};\n\nexport const createElement = <T extends HTMLElement>(\n tagName: string,\n options?: { html?: string; attrs?: Record<string, any>; doc?: Document }\n): T => {\n const d = options?.doc || (typeof document !== 'undefined' ? document : undefined);\n if (!d) throw new Error('Document is not available');\n const el = d.createElement(tagName) as T;\n if (options?.html) el.innerHTML = options.html;\n if (options?.attrs) {\n Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));\n }\n return el;\n};\n\n// Element factory functions\nexport const htmlDivElement = (html: string, options?: { doc?: Document; attrs?: Record<string, any> }): HTMLDivElement => {\n const d = options?.doc || (typeof document !== 'undefined' ? document : undefined);\n if (!d) throw new Error('Document is not available');\n const el = d.createElement('div') as HTMLDivElement;\n el.innerHTML = html.trim();\n if (options?.attrs) {\n Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));\n }\n return el;\n};\n\nexport const htmlSpanElement = (html: string, options?: { doc?: Document; attrs?: Record<string, any> }): HTMLSpanElement => {\n const d = options?.doc || (typeof document !== 'undefined' ? document : undefined);\n if (!d) throw new Error('Document is not available');\n const el = d.createElement('span') as HTMLSpanElement;\n el.innerHTML = html.trim();\n if (options?.attrs) {\n Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));\n }\n return el;\n};\n\nexport const htmlButtonElement = (html: string, options?: { doc?: Document; attrs?: Record<string, any> }): HTMLButtonElement => {\n const d = options?.doc || (typeof document !== 'undefined' ? document : undefined);\n if (!d) throw new Error('Document is not available');\n const el = d.createElement('button') as HTMLButtonElement;\n el.innerHTML = html.trim();\n if (options?.attrs) {\n Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));\n }\n return el;\n};\n\nexport const htmlUlElement = (options?: { doc?: Document; attrs?: Record<string, any> }): HTMLUListElement => {\n const d = options?.doc || (typeof document !== 'undefined' ? document : undefined);\n if (!d) throw new Error('Document is not available');\n const el = d.createElement('ul') as HTMLUListElement;\n if (options?.attrs) {\n Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));\n }\n return el;\n};\n\nexport const htmlLiElement = (html: string, options?: { doc?: Document; attrs?: Record<string, any> }): HTMLLIElement => {\n const d = options?.doc || (typeof document !== 'undefined' ? document : undefined);\n if (!d) throw new Error('Document is not available');\n const el = d.createElement('li') as HTMLLIElement;\n el.innerHTML = html.trim();\n if (options?.attrs) {\n Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));\n }\n return el;\n};\n\nexport const htmlAElement = (html: string, options?: { href?: string; doc?: Document; attrs?: Record<string, any> }): HTMLAnchorElement => {\n const d = options?.doc || (typeof document !== 'undefined' ? document : undefined);\n if (!d) throw new Error('Document is not available');\n const el = d.createElement('a') as HTMLAnchorElement;\n el.innerHTML = html.trim();\n if (options?.href) el.href = options.href;\n if (options?.attrs) {\n Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));\n }\n return el;\n};\n\nexport const htmlPElement = (html: string, options?: { doc?: Document; attrs?: Record<string, any> }): HTMLParagraphElement => {\n const d = options?.doc || (typeof document !== 'undefined' ? document : undefined);\n if (!d) throw new Error('Document is not available');\n const el = d.createElement('p') as HTMLParagraphElement;\n el.innerHTML = html.trim();\n if (options?.attrs) {\n Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));\n }\n return el;\n};\n\nexport const htmlHeadingElement = (level: 1 | 2 | 3 | 4 | 5 | 6, html: string, options?: { doc?: Document; attrs?: Record<string, any> }): HTMLHeadingElement => {\n const d = options?.doc || (typeof document !== 'undefined' ? document : undefined);\n if (!d) throw new Error('Document is not available');\n const el = d.createElement(`h${level}`) as HTMLHeadingElement;\n el.innerHTML = html.trim();\n if (options?.attrs) {\n Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));\n }\n return el;\n};\n\nexport const htmlSectionElement = (options?: { doc?: Document; attrs?: Record<string, any> }): HTMLElement => {\n const d = options?.doc || (typeof document !== 'undefined' ? document : undefined);\n if (!d) throw new Error('Document is not available');\n const el = d.createElement('section');\n if (options?.attrs) {\n Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));\n }\n return el;\n};\n\nexport const htmlArticleElement = (options?: { doc?: Document; attrs?: Record<string, any> }): HTMLElement => {\n const d = options?.doc || (typeof document !== 'undefined' ? document : undefined);\n if (!d) throw new Error('Document is not available');\n const el = d.createElement('article');\n if (options?.attrs) {\n Object.entries(options.attrs).forEach(([k, v]) => el.setAttribute(k, String(v)));\n }\n return el;\n};\n\nexport namespace SwcUtils {\n export const getHelperSet = (win: Window): HelperSet => {\n const doc: Document = win.document;\n return {\n $d: doc,\n $w: win,\n $q: (sel: string, root?: Element | Document | ShadowRoot) => (root ?? doc).querySelector(sel),\n $qa: (sel: string, root?: Element | Document | ShadowRoot) => Array.from((root ?? doc).querySelectorAll(sel)) as HTMLElement[],\n $qi: (id: string, root?: Document | ShadowRoot) => (root ?? doc).getElementById(id) as HTMLElement\n } as const;\n };\n\n export const getHelperAndHostSet = (win: Window, el: HTMLElement): HelperHostSet => {\n const helperSet = getHelperSet(win);\n const hostSet = getHostSet(el);\n return {\n ...helperSet,\n ...hostSet\n };\n };\n\n export const getValueByPath = (obj: any, path: string, rootName: string) => {\n if (!obj || !path) return SWC_NOT_FOUND;\n\n const parts = path.split('.');\n let current = obj;\n\n for (const part of parts) {\n if (current === null || current === undefined) return SWC_NOT_FOUND;\n current = current[part];\n }\n return current;\n };\n\n /**\n * Finds the nearest logical SWC host for an element.\n * Checks __swc_host property first, then climbs the DOM tree.\n */\n export const findNearestSwcHost = (el: HTMLElement | Node): HTMLElement | undefined => {\n if ((el as any).__swc_host) return (el as any).__swc_host;\n // if ((el as any).__swc_proto_setup) return (el as any).__swc_proto_setup;\n\n let current: any = el.parentElement || (el.getRootNode?.() as any)?.host;\n const doc = el.ownerDocument;\n const win = doc?.defaultView || ((typeof window !== 'undefined' ? window : undefined) as any);\n while (current && current !== doc && current !== win) {\n if (current.__swc_host) return current.__swc_host;\n if (getElementConfig(current)) return current as HTMLElement;\n current = current.parentElement || (current.getRootNode?.() as any)?.host;\n }\n return undefined;\n };\n\n /**\n * Returns all SWC ancestors (excluding self) in [root, ..., parent] order.\n */\n export const findAllSwcHosts = (el: HTMLElement | Node): HTMLElement[] => {\n const hosts: HTMLElement[] = [];\n let current = findNearestSwcHost(el);\n while (current) {\n hosts.push(current);\n // To find the next ancestor, we must start searching from the PARENT of the found host\n current = findNearestSwcHost(current);\n }\n return hosts.reverse();\n };\n\n export const getHosts = (el: HTMLElement): HTMLElement[] => {\n const ancestors = findAllSwcHosts(el);\n if (getElementConfig(el)) return [...ancestors, el];\n return ancestors;\n };\n\n export const getHost = (el: HTMLElement): HTMLElement | undefined => {\n if (getElementConfig(el)) return el;\n return findNearestSwcHost(el);\n };\n\n export const getAppHosts = (el: HTMLElement): SwcAppInterface[] => {\n const hosts = getHosts(el);\n return hosts.filter(host => host.tagName.toLowerCase() === 'swc-app' || host.getAttribute('is')?.startsWith('swc-app-')) as SwcAppInterface[];\n };\n\n export const getAppHost = (el: HTMLElement): SwcAppInterface | undefined => {\n const appHosts = getAppHosts(el);\n const appHostsWithoutSelf = appHosts.filter(h => h !== el);\n return appHostsWithoutSelf.length > 0 ? appHostsWithoutSelf[appHostsWithoutSelf.length - 1] : undefined;\n };\n\n export const getHostSet = (el: HTMLElement): HostSet => {\n const isSwc = !!getElementConfig(el);\n const ancestors = findAllSwcHosts(el); // [root, ..., parent]\n\n let $host: HTMLElement;\n let $parentHost: HTMLElement | null;\n\n if (isSwc) {\n $host = el;\n $parentHost = ancestors.length > 0 ? ancestors[ancestors.length - 1] : null;\n } else {\n $host = ancestors.length > 0 ? ancestors[ancestors.length - 1] : el;\n $parentHost = ancestors.length > 1 ? ancestors[ancestors.length - 2] : null;\n }\n\n const $hosts = isSwc ? [...ancestors, el] : ancestors;\n const $firstHost = $hosts.length > 0 ? $hosts[0] : null;\n\n // Collect loop contexts\n const loopContext: Record<string, any> = {};\n let curr: any = el;\n const rootEl = el.ownerDocument?.documentElement;\n while (curr && curr !== rootEl) {\n if (curr.__swc_loop_context) {\n Object.assign(loopContext, curr.__swc_loop_context);\n }\n curr = curr.parentElement || (curr.getRootNode() as any).host;\n }\n\n const $appHosts = $hosts.filter(h => h.tagName.toLowerCase() === 'swc-app' || h.getAttribute('is')?.startsWith('swc-app-')) as SwcAppInterface[];\n const $appHost = $appHosts.length > 0 ? ($appHosts[$appHosts.length - 1] === el ? ($appHosts.length > 1 ? $appHosts[$appHosts.length - 2] : null) : $appHosts[$appHosts.length - 1]) : null;\n const $firstAppHost = $appHosts.length > 0 ? $appHosts[0] : null;\n\n return {\n $host,\n $parentHost,\n $hosts,\n $firstHost,\n $lastHost: $parentHost,\n $appHost,\n $appHosts,\n $firstAppHost,\n $lastAppHost: $appHost,\n ...loopContext\n } as any;\n };\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,wBAA+B;AAExB,MAAM,gBAAgB,OAAO,IAAI,gCAAgC;AAGjE,MAAM,eAAe,CAAC,MAAc,QAAqC;AAC9E,QAAM,IAAI,QAAQ,OAAO,aAAa,cAAc,WAAW;AAC/D,MAAI,CAAC,EAAG,OAAM,IAAI,MAAM,2BAA2B;AACnD,QAAM,WAAW,EAAE,cAAc,UAAU;AAC3C,WAAS,YAAY,KAAK,KAAK;AAC/B,SAAO,SAAS;AAClB;AAEO,MAAM,WAAW,CAAC,MAAoB,QAAyB;AACpE,QAAM,IAAI,QAAQ,OAAO,aAAa,cAAc,WAAW;AAC/D,MAAI,CAAC,EAAG,OAAM,IAAI,MAAM,2BAA2B;AACnD,SAAO,EAAE,eAAe,SAAS,UAAa,SAAS,OAAO,OAAO,IAAI,IAAI,EAAE;AACjF;AAEO,MAAM,cAAc,CAAC,SAAuB,QAA4B;AAC7E,QAAM,IAAI,QAAQ,OAAO,aAAa,cAAc,WAAW;AAC/D,MAAI,CAAC,EAAG,OAAM,IAAI,MAAM,2BAA2B;AACnD,SAAO,EAAE,cAAc,YAAY,UAAa,YAAY,OAAO,OAAO,OAAO,IAAI,EAAE;AACzF;AAEO,MAA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SAAS,IAAI,UAAU,CAAC,IAAI;AAE5D,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,WAAW;AAAA,MACX;AAAA,MACA;AAAA,MACA;AAAA,MACA,cAAc;AAAA,MACd,GAAG;AAAA,IACL;AAAA,EACF;AAAA,GAtIe;",
6
6
  "names": ["SwcUtils"]
7
7
  }
@@ -1,5 +1,5 @@
1
1
  import { ReflectUtils } from "@dooboostore/core";
2
- const ADD_EVENT_LISTENER_METADATA_KEY = Symbol("simple-web-component:add-event-listener");
2
+ const ADD_EVENT_LISTENER_METADATA_KEY = Symbol.for("simple-web-component:add-event-listener");
3
3
  function addEventListener(selectorOrTarget, type, options = {}) {
4
4
  return (targetObj, propertyKey, descriptor) => {
5
5
  const constructor = targetObj.constructor;
@@ -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 } 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}\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('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"],
5
- "mappings": "AAAA,SAAS,oBAAoB;AAqBtB,MAAM,kCAAkC,OAAO,yCAAyC;AAOxF,SAAS,iBAAiB,kBAA0B,MAAc,UAAe,CAAC,GAAoB;AAC3G,SAAO,CAAC,WAAmB,aAA8B,eAAmC;AAC1F,UAAM,cAAc,UAAU;AAE9B,QAAI,YAAY,aAAa,YAAwC,iCAAiC,WAAW;AACjH,QAAI,CAAC,WAAW;AACd,kBAAY,CAAC;AACb,mBAAa,eAAe,iCAAiC,WAAW,WAAW;AAAA,IACrF;AAEA,cAAU,KAAK,EAAE,aAAa,UAAU,kBAAkB,MAAM,QAAQ,CAAC;AAAA,EAC3E;AACF;AAEO,MAAM,8BAA8B,CAAC,WAAwD;AAClG,QAAM,cAAc,kBAAkB,WAAW,SAAS,OAAO;AACjE,SAAO,aAAa,YAAY,iCAAiC,WAAW;AAC9E;AAOO,SAAS,qBAAqB,MAAc,SAA0E;AAC3H,SAAO,iBAAiB,SAAS,MAAM,OAAO;AAChD;",
4
+ "sourcesContent": ["import { ReflectUtils } from '@dooboostore/core';\nimport { SpecialSelector, SwcQueryOptions } 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}\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"],
5
+ "mappings": "AAAA,SAAS,oBAAoB;AAqBtB,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,aAAa,YAAwC,iCAAiC,WAAW;AACjH,QAAI,CAAC,WAAW;AACd,kBAAY,CAAC;AACb,mBAAa,eAAe,iCAAiC,WAAW,WAAW;AAAA,IACrF;AAEA,cAAU,KAAK,EAAE,aAAa,UAAU,kBAAkB,MAAM,QAAQ,CAAC;AAAA,EAC3E;AACF;AAEO,MAAM,8BAA8B,CAAC,WAAwD;AAClG,QAAM,cAAc,kBAAkB,WAAW,SAAS,OAAO;AACjE,SAAO,aAAa,YAAY,iCAAiC,WAAW;AAC9E;AAOO,SAAS,qBAAqB,MAAc,SAA0E;AAC3H,SAAO,iBAAiB,SAAS,MAAM,OAAO;AAChD;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,129 @@
1
+ import { ReflectUtils } from "@dooboostore/core";
2
+ import { ensureInit } from "./elementDefine.js";
3
+ import { SwcUtils } from "../utils/Utils.js";
4
+ const ATTRIBUTE_APPLY_METADATA_KEY = Symbol.for("simple-web-component:attribute-apply");
5
+ function createAttributeDecorator(action) {
6
+ return (selector, nameOrOptions, options = {}) => {
7
+ return (target, propertyKey, descriptor) => {
8
+ const constructor = target.constructor;
9
+ let metaList = ReflectUtils.getOwnMetadata(ATTRIBUTE_APPLY_METADATA_KEY, constructor);
10
+ if (!metaList) {
11
+ metaList = /* @__PURE__ */ new Map();
12
+ ReflectUtils.defineMetadata(ATTRIBUTE_APPLY_METADATA_KEY, metaList, constructor);
13
+ }
14
+ let attributeName = typeof nameOrOptions === "string" ? nameOrOptions : void 0;
15
+ let finalOptions = options;
16
+ if (typeof nameOrOptions === "object" && nameOrOptions !== null) {
17
+ finalOptions = nameOrOptions;
18
+ }
19
+ metaList.set(propertyKey, {
20
+ propertyKey,
21
+ selector,
22
+ action,
23
+ options: { ...finalOptions, name: attributeName }
24
+ });
25
+ const original = descriptor.value;
26
+ descriptor.value = async function(...args) {
27
+ ensureInit(this);
28
+ const res = await original.apply(this, args);
29
+ if (res !== void 0) {
30
+ const win = this.ownerDocument?.defaultView || window;
31
+ const host = this;
32
+ const hostSet = { ...SwcUtils.getHelperAndHostSet(win, host), $this: this };
33
+ const r = finalOptions.root || "auto";
34
+ const targetEls = [];
35
+ const applyRoot = (t) => {
36
+ if (!t || !(t instanceof win.HTMLElement)) return;
37
+ targetEls.push(t);
38
+ };
39
+ if (selector === ":parentHost") applyRoot(hostSet.$parentHost);
40
+ else if (selector === ":appHost") applyRoot(hostSet.$appHost);
41
+ else if (selector === ":firstHost") applyRoot(hostSet.$firstHost);
42
+ else if (selector === ":lastHost") applyRoot(hostSet.$lastHost);
43
+ else if (selector === ":firstAppHost") applyRoot(hostSet.$firstAppHost);
44
+ else if (selector === ":lastAppHost") applyRoot(hostSet.$lastAppHost);
45
+ else if (selector === ":hosts") hostSet.$hosts.forEach(applyRoot);
46
+ else if (selector === ":appHosts") hostSet.$appHosts.forEach(applyRoot);
47
+ else if (selector === ":host" || !selector) applyRoot(host);
48
+ else {
49
+ const targetRoot = r === "auto" ? host.shadowRoot || host : r === "shadow" ? host.shadowRoot : host;
50
+ if (targetRoot) {
51
+ const found = targetRoot.querySelectorAll(selector);
52
+ if (found) targetEls.push(...Array.from(found));
53
+ }
54
+ }
55
+ targetEls.forEach((targetEl) => {
56
+ const resolvedRes = typeof res === "function" ? res(targetEl, hostSet) : res;
57
+ if (action === "set" || action === "update") {
58
+ if (attributeName) {
59
+ if (resolvedRes === null || resolvedRes === void 0 || resolvedRes === false) {
60
+ targetEl.removeAttribute(attributeName);
61
+ } else {
62
+ targetEl.setAttribute(attributeName, resolvedRes === true ? "" : String(resolvedRes));
63
+ }
64
+ } else if (typeof resolvedRes === "object" && resolvedRes !== null && !Array.isArray(resolvedRes)) {
65
+ Object.entries(resolvedRes).forEach(([attr, val]) => {
66
+ const finalVal = typeof val === "function" ? val(targetEl, hostSet) : val;
67
+ if (finalVal === null || finalVal === void 0 || finalVal === false) {
68
+ targetEl.removeAttribute(attr);
69
+ } else {
70
+ targetEl.setAttribute(attr, finalVal === true ? "" : String(finalVal));
71
+ }
72
+ });
73
+ }
74
+ } else if (action === "remove") {
75
+ if (attributeName) {
76
+ targetEl.removeAttribute(attributeName);
77
+ } else if (typeof resolvedRes === "object" && resolvedRes !== null && !Array.isArray(resolvedRes)) {
78
+ Object.entries(resolvedRes).forEach(([attr, val]) => {
79
+ const shouldRemove = typeof val === "function" ? val(targetEl, hostSet) : !!val;
80
+ if (shouldRemove) targetEl.removeAttribute(attr);
81
+ });
82
+ } else {
83
+ const attrs = Array.isArray(resolvedRes) ? resolvedRes : [resolvedRes];
84
+ attrs.forEach((a) => targetEl.removeAttribute(String(a)));
85
+ }
86
+ }
87
+ });
88
+ }
89
+ return res;
90
+ };
91
+ return descriptor;
92
+ };
93
+ };
94
+ }
95
+ function applyAttribute(selector, action = "update", options = {}) {
96
+ return createAttributeDecorator(action)(selector, options);
97
+ }
98
+ const setAttribute = (selector, nameOrOptions, options = {}) => createAttributeDecorator("set")(selector, nameOrOptions, options);
99
+ const updateAttribute = (selector, nameOrOptions, options = {}) => createAttributeDecorator("update")(selector, nameOrOptions, options);
100
+ const removeAttribute = (selector, nameOrOptions, options = {}) => createAttributeDecorator("remove")(selector, nameOrOptions, options);
101
+ function applyAttributeHost(action = "update", options = {}) {
102
+ return createAttributeDecorator(action)(":host", options);
103
+ }
104
+ const setAttributeHost = (nameOrOptions, options = {}) => createAttributeDecorator("set")(":host", nameOrOptions, options);
105
+ const updateAttributeHost = (nameOrOptions, options = {}) => createAttributeDecorator("update")(":host", nameOrOptions, options);
106
+ const removeAttributeHost = (nameOrOptions, options = {}) => createAttributeDecorator("remove")(":host", nameOrOptions, options);
107
+ const findAllAttributeApplyMetadata = (target) => {
108
+ const result = /* @__PURE__ */ new Map();
109
+ const maps = ReflectUtils.findAllMetadata(ATTRIBUTE_APPLY_METADATA_KEY, target);
110
+ maps.forEach((map) => {
111
+ if (map instanceof Map) {
112
+ map.forEach((v, k) => result.set(k, v));
113
+ }
114
+ });
115
+ return result;
116
+ };
117
+ export {
118
+ ATTRIBUTE_APPLY_METADATA_KEY,
119
+ applyAttribute,
120
+ applyAttributeHost,
121
+ findAllAttributeApplyMetadata,
122
+ removeAttribute,
123
+ removeAttributeHost,
124
+ setAttribute,
125
+ setAttributeHost,
126
+ updateAttribute,
127
+ updateAttributeHost
128
+ };
129
+ //# sourceMappingURL=applyAttribute.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 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,SAAS,oBAAoB;AAC7B,SAAS,kBAAkB;AAC3B,SAAS,gBAAgB;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,aAAa,eAAe,8BAA8B,WAAW;AACpF,UAAI,CAAC,UAAU;AACb,mBAAW,oBAAI,IAA6C;AAC5D,qBAAa,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,kBAAmB,MAAa;AACjD,mBAAW,IAAI;AACf,cAAM,MAAM,M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zI,SAAO,yBAAyB,MAAM,EAAE,UAAU,OAAO;AAC3D;AAEO,MAAM,eAAe,CAAC,UAAkB,eAAgD,UAAiC,CAAC,MAAM,yBAAyB,KAAK,EAAE,UAAU,eAAe,OAAO;AAChM,MAAM,kBAAkB,CAAC,UAAkB,eAAgD,UAAiC,CAAC,MAAM,yBAAyB,QAAQ,EAAE,UAAU,eAAe,OAAO;AACtM,MAAM,kBAAkB,CAAC,UAAkB,eAAgD,UAAiC,CAAC,MAAM,yBAAyB,QAAQ,EAAE,UAAU,eAAe,OAAO;AAGtM,SAAS,mBAAmB,SAA0B,UAAU,UAAiC,CAAC,GAAoB;AAC3H,SAAO,yBAAyB,MAAM,EAAE,SAAS,OAAO;AAC1D;AACO,MAAM,mBAAmB,CAAC,eAA+C,UAAiC,CAAC,MAAM,yBAAyB,KAAK,EAAE,SAAS,eAAe,OAAO;AAChL,MAAM,sBAAsB,CAAC,eAA+C,UAAiC,CAAC,MAAM,yBAAyB,QAAQ,EAAE,SAAS,eAAe,OAAO;AACtL,MAAM,sBAAsB,CAAC,eAAgD,UAAiC,CAAC,MAAM,yBAAyB,QAAQ,EAAE,SAAS,eAAe,OAAO;AAEvL,MAAM,gCAAgC,CAAC,WAA8D;AAC1G,QAAM,SAAS,oBAAI,IAA6C;AAChE,QAAM,OAAO,aAAa,gBAA8D,8BAA8B,MAAM;AAC5H,OAAK,QAAQ,SAAO;AAClB,QAAI,eAAe,KAAK;AACtB,UAAI,QAAQ,CAAC,GAAG,MAAM,OAAO,IAAI,GAAG,CAAC,CAAC;AAAA,IACxC;AAAA,EACF,CAAC;AACD,SAAO;AACT;",
6
+ "names": []
7
+ }
@@ -0,0 +1,145 @@
1
+ import { ReflectUtils } from "@dooboostore/core";
2
+ import { ensureInit } from "./elementDefine.js";
3
+ import { SwcUtils } from "../utils/Utils.js";
4
+ const CLASS_METADATA_KEY = Symbol.for("simple-web-component:class");
5
+ function createClassDecorator(action) {
6
+ return (selector, classMapOrOptions, options = {}) => {
7
+ return (target, propertyKey, descriptor) => {
8
+ const constructor = target.constructor;
9
+ let metaList = ReflectUtils.getOwnMetadata(CLASS_METADATA_KEY, constructor);
10
+ if (!metaList) {
11
+ metaList = /* @__PURE__ */ new Map();
12
+ ReflectUtils.defineMetadata(CLASS_METADATA_KEY, metaList, constructor);
13
+ }
14
+ let classMap = void 0;
15
+ let finalOptions = options;
16
+ if (typeof classMapOrOptions === "string" || typeof classMapOrOptions === "object" && classMapOrOptions !== null && !("root" in classMapOrOptions)) {
17
+ classMap = classMapOrOptions;
18
+ } else if (typeof classMapOrOptions === "object" && classMapOrOptions !== null && "root" in classMapOrOptions) {
19
+ finalOptions = classMapOrOptions;
20
+ }
21
+ metaList.set(propertyKey, { propertyKey, selector, action, options: finalOptions });
22
+ const original = descriptor.value;
23
+ descriptor.value = async function(...args) {
24
+ ensureInit(this);
25
+ const res = await original.apply(this, args);
26
+ if (res !== void 0) {
27
+ const win = this.ownerDocument?.defaultView || window;
28
+ const host = this;
29
+ const hostSet = { ...SwcUtils.getHelperAndHostSet(win, host), $this: this };
30
+ const r = finalOptions.root || "auto";
31
+ const targetEls = [];
32
+ const applyRoot = (t) => {
33
+ if (!t || !(t instanceof win.HTMLElement)) return;
34
+ targetEls.push(t);
35
+ };
36
+ if (selector === ":parentHost") applyRoot(hostSet.$parentHost);
37
+ else if (selector === ":appHost") applyRoot(hostSet.$appHost);
38
+ else if (selector === ":firstHost") applyRoot(hostSet.$firstHost);
39
+ else if (selector === ":lastHost") applyRoot(hostSet.$lastHost);
40
+ else if (selector === ":firstAppHost") applyRoot(hostSet.$firstAppHost);
41
+ else if (selector === ":lastAppHost") applyRoot(hostSet.$lastAppHost);
42
+ else if (selector === ":hosts") hostSet.$hosts.forEach(applyRoot);
43
+ else if (selector === ":appHosts") hostSet.$appHosts.forEach(applyRoot);
44
+ else if (selector === ":host" || !selector) applyRoot(host);
45
+ else {
46
+ const targetRoot = r === "auto" ? host.shadowRoot || host : r === "shadow" ? host.shadowRoot : host;
47
+ if (targetRoot) {
48
+ const found = targetRoot.querySelectorAll(selector);
49
+ if (found) targetEls.push(...Array.from(found));
50
+ }
51
+ }
52
+ targetEls.forEach((targetEl) => {
53
+ const resolvedRes = typeof res === "function" ? res(targetEl, hostSet) : res;
54
+ if (action === "set") {
55
+ let classes = "";
56
+ if (classMap && typeof classMap === "string") {
57
+ classes = resolvedRes ? classMap : "";
58
+ } else if (typeof resolvedRes === "object" && resolvedRes !== null && !Array.isArray(resolvedRes)) {
59
+ classes = Object.entries(resolvedRes).filter(([_, force]) => typeof force === "function" ? force(targetEl, hostSet) : !!force).map(([cls]) => cls).join(" ");
60
+ } else {
61
+ classes = Array.isArray(resolvedRes) ? resolvedRes.join(" ") : String(resolvedRes);
62
+ }
63
+ targetEl.className = classes;
64
+ } else if (action === "update" || action === "toggle") {
65
+ if (classMap && typeof classMap === "string") {
66
+ targetEl.classList.toggle(classMap, !!resolvedRes);
67
+ } else if (typeof resolvedRes === "object" && resolvedRes !== null && !Array.isArray(resolvedRes)) {
68
+ Object.entries(resolvedRes).forEach(([cls, force]) => {
69
+ const isActive = typeof force === "function" ? force(targetEl, hostSet) : !!force;
70
+ targetEl.classList.toggle(cls, isActive);
71
+ });
72
+ } else {
73
+ const classes = Array.isArray(resolvedRes) ? resolvedRes.map(String) : [String(resolvedRes)];
74
+ if (action === "update") targetEl.classList.add(...classes);
75
+ else classes.forEach((c) => targetEl.classList.toggle(c));
76
+ }
77
+ } else if (action === "add" || action === "remove") {
78
+ if (classMap && typeof classMap === "string" && !!resolvedRes) {
79
+ if (action === "add") targetEl.classList.add(classMap);
80
+ else targetEl.classList.remove(classMap);
81
+ } else if (typeof resolvedRes === "object" && resolvedRes !== null && !Array.isArray(resolvedRes)) {
82
+ Object.entries(resolvedRes).forEach(([cls, force]) => {
83
+ const shouldExecute = typeof force === "function" ? force(targetEl, hostSet) : !!force;
84
+ if (shouldExecute) {
85
+ if (action === "add") targetEl.classList.add(cls);
86
+ else targetEl.classList.remove(cls);
87
+ }
88
+ });
89
+ } else {
90
+ const classes = Array.isArray(resolvedRes) ? resolvedRes.map(String) : [String(resolvedRes)];
91
+ if (action === "add") targetEl.classList.add(...classes);
92
+ else targetEl.classList.remove(...classes);
93
+ }
94
+ }
95
+ });
96
+ }
97
+ return res;
98
+ };
99
+ return descriptor;
100
+ };
101
+ };
102
+ }
103
+ function applyClass(selector, action = "update", options = {}) {
104
+ return createClassDecorator(action)(selector, options);
105
+ }
106
+ const setClass = (selector, classMapOrOptions, options = {}) => createClassDecorator("set")(selector, classMapOrOptions, options);
107
+ const updateClass = (selector, classMapOrOptions, options = {}) => createClassDecorator("update")(selector, classMapOrOptions, options);
108
+ const addClass = (selector, classMapOrOptions, options = {}) => createClassDecorator("add")(selector, classMapOrOptions, options);
109
+ const removeClass = (selector, classMapOrOptions, options = {}) => createClassDecorator("remove")(selector, classMapOrOptions, options);
110
+ const toggleClass = (selector, classMapOrOptions, options = {}) => createClassDecorator("toggle")(selector, classMapOrOptions, options);
111
+ function applyClassHost(action = "update", options = {}) {
112
+ return createClassDecorator(action)(":host", options);
113
+ }
114
+ const setClassHost = (classMapOrOptions, options = {}) => createClassDecorator("set")(":host", classMapOrOptions, options);
115
+ const updateClassHost = (classMapOrOptions, options = {}) => createClassDecorator("update")(":host", classMapOrOptions, options);
116
+ const addClassHost = (classMapOrOptions, options = {}) => createClassDecorator("add")(":host", classMapOrOptions, options);
117
+ const removeClassHost = (classMapOrOptions, options = {}) => createClassDecorator("remove")(":host", classMapOrOptions, options);
118
+ const toggleClassHost = (classMapOrOptions, options = {}) => createClassDecorator("toggle")(":host", classMapOrOptions, options);
119
+ const findAllClassMetadata = (target) => {
120
+ const result = /* @__PURE__ */ new Map();
121
+ const maps = ReflectUtils.findAllMetadata(CLASS_METADATA_KEY, target);
122
+ maps.forEach((map) => {
123
+ if (map instanceof Map) {
124
+ map.forEach((v, k) => result.set(k, v));
125
+ }
126
+ });
127
+ return result;
128
+ };
129
+ export {
130
+ CLASS_METADATA_KEY,
131
+ addClass,
132
+ addClassHost,
133
+ applyClass,
134
+ applyClassHost,
135
+ findAllClassMetadata,
136
+ removeClass,
137
+ removeClassHost,
138
+ setClass,
139
+ setClassHost,
140
+ toggleClass,
141
+ toggleClassHost,
142
+ updateClass,
143
+ updateClassHost
144
+ };
145
+ //# sourceMappingURL=applyClass.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/decorators/applyClass.ts"],
4
+ "sourcesContent": ["import { ReflectUtils } from '@dooboostore/core';\nimport { ensureInit } from './elementDefine';\nimport { SwcUtils } from '../utils/Utils';\nimport { SwcQueryOptions, HelperHostSet } from '../types';\n\nexport const CLASS_METADATA_KEY = Symbol.for('simple-web-component:class');\n\nexport type ClassAction = 'set' | 'update' | 'add' | 'remove' | 'toggle';\n\nexport interface ClassApplyOptions extends SwcQueryOptions {}\n\nexport interface ClassApplyMetadata {\n propertyKey: string | symbol;\n selector: string;\n action: ClassAction;\n options: ClassApplyOptions;\n}\n\nfunction createClassDecorator(action: ClassAction) {\n return (selector: string, classMapOrOptions?: string | { [className: string]: (el: HTMLElement, value: any, helper: HelperHostSet & { $this: any }) => boolean } | ClassApplyOptions, options: ClassApplyOptions = {}): MethodDecorator => {\n return (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n const constructor = target.constructor;\n let metaList = ReflectUtils.getOwnMetadata(CLASS_METADATA_KEY, constructor) as Map<string | symbol, ClassApplyMetadata>;\n if (!metaList) {\n metaList = new Map<string | symbol, ClassApplyMetadata>();\n ReflectUtils.defineMetadata(CLASS_METADATA_KEY, metaList, constructor);\n }\n\n let classMap: any = undefined;\n let finalOptions = options;\n\n if (typeof classMapOrOptions === 'string' || (typeof classMapOrOptions === 'object' && classMapOrOptions !== null && !('root' in classMapOrOptions))) {\n classMap = classMapOrOptions;\n } else if (typeof classMapOrOptions === 'object' && classMapOrOptions !== null && 'root' in classMapOrOptions) {\n finalOptions = classMapOrOptions as ClassApplyOptions;\n }\n\n metaList.set(propertyKey, { propertyKey, selector, action, options: finalOptions });\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') {\n let classes = '';\n if (classMap && typeof classMap === 'string') {\n classes = resolvedRes ? classMap : '';\n } else if (typeof resolvedRes === 'object' && resolvedRes !== null && !Array.isArray(resolvedRes)) {\n classes = Object.entries(resolvedRes as any)\n .filter(([_, force]) => typeof force === 'function' ? force(targetEl, hostSet) : !!force)\n .map(([cls]) => cls)\n .join(' ');\n } else {\n classes = Array.isArray(resolvedRes) ? (resolvedRes as any[]).join(' ') : String(resolvedRes);\n }\n targetEl.className = classes;\n } else if (action === 'update' || action === 'toggle') {\n if (classMap && typeof classMap === 'string') {\n targetEl.classList.toggle(classMap, !!resolvedRes);\n } else if (typeof resolvedRes === 'object' && resolvedRes !== null && !Array.isArray(resolvedRes)) {\n Object.entries(resolvedRes as any).forEach(([cls, force]) => {\n const isActive = typeof force === 'function' ? force(targetEl, hostSet) : !!force;\n targetEl.classList.toggle(cls, isActive);\n });\n } else {\n const classes = Array.isArray(resolvedRes) ? (resolvedRes as any[]).map(String) : [String(resolvedRes)];\n if (action === 'update') targetEl.classList.add(...classes);\n else classes.forEach(c => targetEl.classList.toggle(c));\n }\n } else if (action === 'add' || action === 'remove') {\n if (classMap && typeof classMap === 'string' && !!resolvedRes) {\n if (action === 'add') targetEl.classList.add(classMap);\n else targetEl.classList.remove(classMap);\n } else if (typeof resolvedRes === 'object' && resolvedRes !== null && !Array.isArray(resolvedRes)) {\n Object.entries(resolvedRes as any).forEach(([cls, force]) => {\n const shouldExecute = typeof force === 'function' ? force(targetEl, hostSet) : !!force;\n if (shouldExecute) {\n if (action === 'add') targetEl.classList.add(cls);\n else targetEl.classList.remove(cls);\n }\n });\n } else {\n const classes = Array.isArray(resolvedRes) ? (resolvedRes as any[]).map(String) : [String(resolvedRes)];\n if (action === 'add') targetEl.classList.add(...classes);\n else targetEl.classList.remove(...classes);\n }\n }\n });\n }\n return res;\n };\n return descriptor;\n };\n };\n}\n\nexport function applyClass(selector: string, action: ClassAction = 'update', options: ClassApplyOptions = {}): MethodDecorator {\n return createClassDecorator(action)(selector, options);\n}\n\nexport const setClass = (selector: string, classMapOrOptions?: string | { [className: string]: (el: HTMLElement, value: any, helper: HelperHostSet & { $this: any }) => boolean } | ClassApplyOptions, options: ClassApplyOptions = {}) => createClassDecorator('set')(selector, classMapOrOptions, options);\nexport const updateClass = (selector: string, classMapOrOptions?: string | { [className: string]: (el: HTMLElement, value: any, helper: HelperHostSet & { $this: any }) => boolean } | ClassApplyOptions, options: ClassApplyOptions = {}) => createClassDecorator('update')(selector, classMapOrOptions, options);\nexport const addClass = (selector: string, classMapOrOptions?: string | { [className: string]: (el: HTMLElement, value: any, helper: HelperHostSet & { $this: any }) => boolean } | ClassApplyOptions, options: ClassApplyOptions = {}) => createClassDecorator('add')(selector, classMapOrOptions, options);\nexport const removeClass = (selector: string, classMapOrOptions?: string | { [className: string]: (el: HTMLElement, value: any, helper: HelperHostSet & { $this: any }) => boolean } | ClassApplyOptions, options: ClassApplyOptions = {}) => createClassDecorator('remove')(selector, classMapOrOptions, options);\nexport const toggleClass = (selector: string, classMapOrOptions?: string | { [className: string]: (el: HTMLElement, value: any, helper: HelperHostSet & { $this: any }) => boolean } | ClassApplyOptions, options: ClassApplyOptions = {}) => createClassDecorator('toggle')(selector, classMapOrOptions, options);\n\n// Host versions\nexport function applyClassHost(action: ClassAction = 'update', options: ClassApplyOptions = {}): MethodDecorator {\n return createClassDecorator(action)(':host', options);\n}\nexport const setClassHost = (classMapOrOptions?: string | { [className: string]: (el: HTMLElement, value: any, helper: HelperHostSet & { $this: any }) => boolean } | ClassApplyOptions, options: ClassApplyOptions = {}) => createClassDecorator('set')(':host', classMapOrOptions, options);\nexport const updateClassHost = (classMapOrOptions?: string | { [className: string]: (el: HTMLElement, value: any, helper: HelperHostSet & { $this: any }) => boolean } | ClassApplyOptions, options: ClassApplyOptions = {}) => createClassDecorator('update')(':host', classMapOrOptions, options);\nexport const addClassHost = (classMapOrOptions?: string | { [className: string]: (el: HTMLElement, value: any, helper: HelperHostSet & { $this: any }) => boolean } | ClassApplyOptions, options: ClassApplyOptions = {}) => createClassDecorator('add')(':host', classMapOrOptions, options);\nexport const removeClassHost = (classMapOrOptions?: string | { [className: string]: (el: HTMLElement, value: any, helper: HelperHostSet & { $this: any }) => boolean } | ClassApplyOptions, options: ClassApplyOptions = {}) => createClassDecorator('remove')(':host', classMapOrOptions, options);\nexport const toggleClassHost = (classMapOrOptions?: string | { [className: string]: (el: HTMLElement, value: any, helper: HelperHostSet & { $this: any }) => boolean } | ClassApplyOptions, options: ClassApplyOptions = {}) => createClassDecorator('toggle')(':host', classMapOrOptions, options);\n\nexport const findAllClassMetadata = (target: any): Map<string | symbol, ClassApplyMetadata> => {\n const result = new Map<string | symbol, ClassApplyMetadata>();\n const maps = ReflectUtils.findAllMetadata<Map<string | symbol, ClassApplyMetadata>>(CLASS_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,SAAS,oBAAoB;AAC7B,SAAS,kBAAkB;AAC3B,SAAS,gBAAgB;AAGlB,MAAM,qBAAqB,OAAO,IAAI,4BAA4B;AAazE,SAAS,qBAAqB,QAAqB;AACjD,SAAO,CAAC,UAAkB,mBAA4J,UAA6B,CAAC,MAAuB;AACzO,WAAO,CAAC,QAAgB,aAA8B,eAAmC;AACvF,YAAM,cAAc,OAAO;AAC3B,UAAI,WAAW,aAAa,eAAe,oBAAoB,WAAW;AAC1E,UAAI,CAAC,UAAU;AACb,mBAAW,oBAAI,IAAyC;AACxD,qBAAa,eAAe,oBAAoB,UAAU,WAAW;AAAA,MACvE;AAEA,UAAI,WAAgB;AACpB,UAAI,eAAe;AAEnB,UAAI,OAAO,sBAAsB,YAAa,OAAO,sBAAsB,YAAY,sBAAsB,QAAQ,EAAE,UAAU,oBAAqB;AAClJ,mBAAW;AAAA,MACf,WAAW,OAAO,sBAAsB,YAAY,sBAAsB,QAAQ,UAAU,mBAAmB;AAC3G,uBAAe;AAAA,MACnB;AAEA,eAAS,IAAI,aAAa,EAAE,aAAa,UAAU,QAAQ,SAAS,aAAa,CAAC;AAElF,YAAM,WAAW,WAAW;AAC5B,iBAAW,QAAQ,kBAAmB,MAAa;AACjD,mBAAW,IAAI;AACf,cAAM,MAAM,MAAO,SAAiB,MAAM,MAAM,IAAI;AACpD,YAAI,QAAQ,QAAW;AACrB,gBAAM,MAAO,KAAa,eAAe,eAAe;AACxD,gBAAM,OAAO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