@miurajs/miura-render 0.0.0 → 0.1.1

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 (262) hide show
  1. package/dist/index.d.ts +14 -0
  2. package/dist/index.d.ts.map +1 -0
  3. package/dist/index.js +13 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/src/binding-manager/binding-manager.d.ts +30 -0
  6. package/dist/src/binding-manager/binding-manager.d.ts.map +1 -0
  7. package/dist/src/binding-manager/binding-manager.js +245 -0
  8. package/dist/src/binding-manager/binding-manager.js.map +1 -0
  9. package/dist/src/binding-manager/binding-type.d.ts +24 -0
  10. package/dist/src/binding-manager/binding-type.d.ts.map +1 -0
  11. package/dist/src/binding-manager/binding-type.js +25 -0
  12. package/dist/src/binding-manager/binding-type.js.map +1 -0
  13. package/dist/src/binding-manager/bindings/async-binding.d.ts +23 -0
  14. package/dist/src/binding-manager/bindings/async-binding.d.ts.map +1 -0
  15. package/dist/src/binding-manager/bindings/async-binding.js +67 -0
  16. package/dist/src/binding-manager/bindings/async-binding.js.map +1 -0
  17. package/dist/src/binding-manager/bindings/attribute-binding.d.ts +41 -0
  18. package/dist/src/binding-manager/bindings/attribute-binding.d.ts.map +1 -0
  19. package/dist/src/binding-manager/bindings/attribute-binding.js +79 -0
  20. package/dist/src/binding-manager/bindings/attribute-binding.js.map +1 -0
  21. package/dist/src/binding-manager/bindings/bind-binding.d.ts +30 -0
  22. package/dist/src/binding-manager/bindings/bind-binding.d.ts.map +1 -0
  23. package/dist/src/binding-manager/bindings/bind-binding.js +81 -0
  24. package/dist/src/binding-manager/bindings/bind-binding.js.map +1 -0
  25. package/dist/src/binding-manager/bindings/binding.d.ts +6 -0
  26. package/dist/src/binding-manager/bindings/binding.d.ts.map +1 -0
  27. package/dist/src/binding-manager/bindings/binding.js +2 -0
  28. package/dist/src/binding-manager/bindings/binding.js.map +1 -0
  29. package/dist/src/binding-manager/bindings/boolean-binding.d.ts +18 -0
  30. package/dist/src/binding-manager/bindings/boolean-binding.d.ts.map +1 -0
  31. package/dist/src/binding-manager/bindings/boolean-binding.js +65 -0
  32. package/dist/src/binding-manager/bindings/boolean-binding.js.map +1 -0
  33. package/dist/src/binding-manager/bindings/class-binding.d.ts +10 -0
  34. package/dist/src/binding-manager/bindings/class-binding.d.ts.map +1 -0
  35. package/dist/src/binding-manager/bindings/class-binding.js +68 -0
  36. package/dist/src/binding-manager/bindings/class-binding.js.map +1 -0
  37. package/dist/src/binding-manager/bindings/directive-binding.d.ts +15 -0
  38. package/dist/src/binding-manager/bindings/directive-binding.d.ts.map +1 -0
  39. package/dist/src/binding-manager/bindings/directive-binding.js +70 -0
  40. package/dist/src/binding-manager/bindings/directive-binding.js.map +1 -0
  41. package/dist/src/binding-manager/bindings/event-binding.d.ts +14 -0
  42. package/dist/src/binding-manager/bindings/event-binding.d.ts.map +1 -0
  43. package/dist/src/binding-manager/bindings/event-binding.js +73 -0
  44. package/dist/src/binding-manager/bindings/event-binding.js.map +1 -0
  45. package/dist/src/binding-manager/bindings/node-binding.d.ts +36 -0
  46. package/dist/src/binding-manager/bindings/node-binding.d.ts.map +1 -0
  47. package/dist/src/binding-manager/bindings/node-binding.js +235 -0
  48. package/dist/src/binding-manager/bindings/node-binding.js.map +1 -0
  49. package/dist/src/binding-manager/bindings/object-class-binding.d.ts +16 -0
  50. package/dist/src/binding-manager/bindings/object-class-binding.d.ts.map +1 -0
  51. package/dist/src/binding-manager/bindings/object-class-binding.js +42 -0
  52. package/dist/src/binding-manager/bindings/object-class-binding.js.map +1 -0
  53. package/dist/src/binding-manager/bindings/object-style-binding.d.ts +16 -0
  54. package/dist/src/binding-manager/bindings/object-style-binding.d.ts.map +1 -0
  55. package/dist/src/binding-manager/bindings/object-style-binding.js +38 -0
  56. package/dist/src/binding-manager/bindings/object-style-binding.js.map +1 -0
  57. package/dist/src/binding-manager/bindings/property-binding.d.ts +12 -0
  58. package/dist/src/binding-manager/bindings/property-binding.d.ts.map +1 -0
  59. package/dist/src/binding-manager/bindings/property-binding.js +44 -0
  60. package/dist/src/binding-manager/bindings/property-binding.js.map +1 -0
  61. package/dist/src/binding-manager/bindings/reference-binding.d.ts +14 -0
  62. package/dist/src/binding-manager/bindings/reference-binding.d.ts.map +1 -0
  63. package/dist/src/binding-manager/bindings/reference-binding.js +44 -0
  64. package/dist/src/binding-manager/bindings/reference-binding.js.map +1 -0
  65. package/dist/src/binding-manager/bindings/spread-binding.d.ts +16 -0
  66. package/dist/src/binding-manager/bindings/spread-binding.d.ts.map +1 -0
  67. package/dist/src/binding-manager/bindings/spread-binding.js +40 -0
  68. package/dist/src/binding-manager/bindings/spread-binding.js.map +1 -0
  69. package/dist/src/binding-manager/bindings/style-binding.d.ts +10 -0
  70. package/dist/src/binding-manager/bindings/style-binding.d.ts.map +1 -0
  71. package/dist/src/binding-manager/bindings/style-binding.js +44 -0
  72. package/dist/src/binding-manager/bindings/style-binding.js.map +1 -0
  73. package/dist/src/compiler/code-factory.d.ts +45 -0
  74. package/dist/src/compiler/code-factory.d.ts.map +1 -0
  75. package/dist/src/compiler/code-factory.js +211 -0
  76. package/dist/src/compiler/code-factory.js.map +1 -0
  77. package/dist/src/compiler/compiler.d.ts +77 -0
  78. package/dist/src/compiler/compiler.d.ts.map +1 -0
  79. package/dist/src/compiler/compiler.js +77 -0
  80. package/dist/src/compiler/compiler.js.map +1 -0
  81. package/dist/src/compiler/constants.d.ts +5 -0
  82. package/dist/src/compiler/constants.d.ts.map +1 -0
  83. package/dist/src/compiler/constants.js +9 -0
  84. package/dist/src/compiler/constants.js.map +1 -0
  85. package/dist/src/css-result.d.ts +27 -0
  86. package/dist/src/css-result.d.ts.map +1 -0
  87. package/dist/src/css-result.js +56 -0
  88. package/dist/src/css-result.js.map +1 -0
  89. package/dist/src/css.d.ts +26 -0
  90. package/dist/src/css.d.ts.map +1 -0
  91. package/dist/src/css.js +62 -0
  92. package/dist/src/css.js.map +1 -0
  93. package/dist/src/directives/animate.directive.d.ts +42 -0
  94. package/dist/src/directives/animate.directive.d.ts.map +1 -0
  95. package/dist/src/directives/animate.directive.js +349 -0
  96. package/dist/src/directives/animate.directive.js.map +1 -0
  97. package/dist/src/directives/await.d.ts +68 -0
  98. package/dist/src/directives/await.d.ts.map +1 -0
  99. package/dist/src/directives/await.js +70 -0
  100. package/dist/src/directives/await.js.map +1 -0
  101. package/dist/src/directives/choose.d.ts +28 -0
  102. package/dist/src/directives/choose.d.ts.map +1 -0
  103. package/dist/src/directives/choose.js +30 -0
  104. package/dist/src/directives/choose.js.map +1 -0
  105. package/dist/src/directives/decorator-example.d.ts +8 -0
  106. package/dist/src/directives/decorator-example.d.ts.map +1 -0
  107. package/dist/src/directives/decorator-example.js +32 -0
  108. package/dist/src/directives/decorator-example.js.map +1 -0
  109. package/dist/src/directives/decorators.d.ts +3 -0
  110. package/dist/src/directives/decorators.d.ts.map +1 -0
  111. package/dist/src/directives/decorators.js +17 -0
  112. package/dist/src/directives/decorators.js.map +1 -0
  113. package/dist/src/directives/directive-manager.d.ts +26 -0
  114. package/dist/src/directives/directive-manager.d.ts.map +1 -0
  115. package/dist/src/directives/directive-manager.js +114 -0
  116. package/dist/src/directives/directive-manager.js.map +1 -0
  117. package/dist/src/directives/directive.d.ts +38 -0
  118. package/dist/src/directives/directive.d.ts.map +1 -0
  119. package/dist/src/directives/directive.js +18 -0
  120. package/dist/src/directives/directive.js.map +1 -0
  121. package/dist/src/directives/focus.directive.d.ts +16 -0
  122. package/dist/src/directives/focus.directive.d.ts.map +1 -0
  123. package/dist/src/directives/focus.directive.js +29 -0
  124. package/dist/src/directives/focus.directive.js.map +1 -0
  125. package/dist/src/directives/gesture.directive.d.ts +58 -0
  126. package/dist/src/directives/gesture.directive.d.ts.map +1 -0
  127. package/dist/src/directives/gesture.directive.js +331 -0
  128. package/dist/src/directives/gesture.directive.js.map +1 -0
  129. package/dist/src/directives/index.d.ts +34 -0
  130. package/dist/src/directives/index.d.ts.map +1 -0
  131. package/dist/src/directives/index.js +35 -0
  132. package/dist/src/directives/index.js.map +1 -0
  133. package/dist/src/directives/intersection.directive.d.ts +18 -0
  134. package/dist/src/directives/intersection.directive.d.ts.map +1 -0
  135. package/dist/src/directives/intersection.directive.js +50 -0
  136. package/dist/src/directives/intersection.directive.js.map +1 -0
  137. package/dist/src/directives/keyed-diff.d.ts +30 -0
  138. package/dist/src/directives/keyed-diff.d.ts.map +1 -0
  139. package/dist/src/directives/keyed-diff.js +185 -0
  140. package/dist/src/directives/keyed-diff.js.map +1 -0
  141. package/dist/src/directives/lazy-setup.d.ts +3 -0
  142. package/dist/src/directives/lazy-setup.d.ts.map +1 -0
  143. package/dist/src/directives/lazy-setup.js +55 -0
  144. package/dist/src/directives/lazy-setup.js.map +1 -0
  145. package/dist/src/directives/lazy.directive.d.ts +19 -0
  146. package/dist/src/directives/lazy.directive.d.ts.map +1 -0
  147. package/dist/src/directives/lazy.directive.js +73 -0
  148. package/dist/src/directives/lazy.directive.js.map +1 -0
  149. package/dist/src/directives/media.directive.d.ts +31 -0
  150. package/dist/src/directives/media.directive.d.ts.map +1 -0
  151. package/dist/src/directives/media.directive.js +105 -0
  152. package/dist/src/directives/media.directive.js.map +1 -0
  153. package/dist/src/directives/mutation.directive.d.ts +11 -0
  154. package/dist/src/directives/mutation.directive.d.ts.map +1 -0
  155. package/dist/src/directives/mutation.directive.js +56 -0
  156. package/dist/src/directives/mutation.directive.js.map +1 -0
  157. package/dist/src/directives/repeat.d.ts +50 -0
  158. package/dist/src/directives/repeat.d.ts.map +1 -0
  159. package/dist/src/directives/repeat.js +47 -0
  160. package/dist/src/directives/repeat.js.map +1 -0
  161. package/dist/src/directives/resize.directive.d.ts +14 -0
  162. package/dist/src/directives/resize.directive.d.ts.map +1 -0
  163. package/dist/src/directives/resize.directive.js +81 -0
  164. package/dist/src/directives/resize.directive.js.map +1 -0
  165. package/dist/src/directives/setup.d.ts +9 -0
  166. package/dist/src/directives/setup.d.ts.map +1 -0
  167. package/dist/src/directives/setup.js +9 -0
  168. package/dist/src/directives/setup.js.map +1 -0
  169. package/dist/src/directives/structural/async.directive.d.ts +39 -0
  170. package/dist/src/directives/structural/async.directive.d.ts.map +1 -0
  171. package/dist/src/directives/structural/async.directive.js +115 -0
  172. package/dist/src/directives/structural/async.directive.js.map +1 -0
  173. package/dist/src/directives/structural/for.directive.d.ts +37 -0
  174. package/dist/src/directives/structural/for.directive.d.ts.map +1 -0
  175. package/dist/src/directives/structural/for.directive.js +209 -0
  176. package/dist/src/directives/structural/for.directive.js.map +1 -0
  177. package/dist/src/directives/structural/if.directive.d.ts +54 -0
  178. package/dist/src/directives/structural/if.directive.d.ts.map +1 -0
  179. package/dist/src/directives/structural/if.directive.js +210 -0
  180. package/dist/src/directives/structural/if.directive.js.map +1 -0
  181. package/dist/src/directives/structural/structural.directive.d.ts +11 -0
  182. package/dist/src/directives/structural/structural.directive.d.ts.map +1 -0
  183. package/dist/src/directives/structural/structural.directive.js +29 -0
  184. package/dist/src/directives/structural/structural.directive.js.map +1 -0
  185. package/dist/src/directives/structural/switch.directive.d.ts +12 -0
  186. package/dist/src/directives/structural/switch.directive.d.ts.map +1 -0
  187. package/dist/src/directives/structural/switch.directive.js +69 -0
  188. package/dist/src/directives/structural/switch.directive.js.map +1 -0
  189. package/dist/src/directives/structural/virtual-scroll.directive.d.ts +50 -0
  190. package/dist/src/directives/structural/virtual-scroll.directive.d.ts.map +1 -0
  191. package/dist/src/directives/structural/virtual-scroll.directive.js +165 -0
  192. package/dist/src/directives/structural/virtual-scroll.directive.js.map +1 -0
  193. package/dist/src/directives/utils.d.ts +61 -0
  194. package/dist/src/directives/utils.d.ts.map +1 -0
  195. package/dist/src/directives/utils.js +121 -0
  196. package/dist/src/directives/utils.js.map +1 -0
  197. package/dist/src/directives/validate.directive.d.ts +41 -0
  198. package/dist/src/directives/validate.directive.d.ts.map +1 -0
  199. package/dist/src/directives/validate.directive.js +161 -0
  200. package/dist/src/directives/validate.directive.js.map +1 -0
  201. package/dist/src/directives/virtual-scroll.d.ts +91 -0
  202. package/dist/src/directives/virtual-scroll.d.ts.map +1 -0
  203. package/dist/src/directives/virtual-scroll.js +78 -0
  204. package/dist/src/directives/virtual-scroll.js.map +1 -0
  205. package/dist/src/directives/when.d.ts +24 -0
  206. package/dist/src/directives/when.d.ts.map +1 -0
  207. package/dist/src/directives/when.js +25 -0
  208. package/dist/src/directives/when.js.map +1 -0
  209. package/dist/src/html.d.ts +23 -0
  210. package/dist/src/html.d.ts.map +1 -0
  211. package/dist/src/html.js +37 -0
  212. package/dist/src/html.js.map +1 -0
  213. package/dist/src/modifiers/capture-modifier.d.ts +6 -0
  214. package/dist/src/modifiers/capture-modifier.d.ts.map +1 -0
  215. package/dist/src/modifiers/capture-modifier.js +14 -0
  216. package/dist/src/modifiers/capture-modifier.js.map +1 -0
  217. package/dist/src/modifiers/event-modifiers.d.ts +38 -0
  218. package/dist/src/modifiers/event-modifiers.d.ts.map +1 -0
  219. package/dist/src/modifiers/event-modifiers.js +90 -0
  220. package/dist/src/modifiers/event-modifiers.js.map +1 -0
  221. package/dist/src/modifiers/key-modifiers.d.ts +8 -0
  222. package/dist/src/modifiers/key-modifiers.d.ts.map +1 -0
  223. package/dist/src/modifiers/key-modifiers.js +29 -0
  224. package/dist/src/modifiers/key-modifiers.js.map +1 -0
  225. package/dist/src/modifiers/mouse-modifiers.d.ts +8 -0
  226. package/dist/src/modifiers/mouse-modifiers.d.ts.map +1 -0
  227. package/dist/src/modifiers/mouse-modifiers.js +15 -0
  228. package/dist/src/modifiers/mouse-modifiers.js.map +1 -0
  229. package/dist/src/modifiers/once-modifier.d.ts +6 -0
  230. package/dist/src/modifiers/once-modifier.d.ts.map +1 -0
  231. package/dist/src/modifiers/once-modifier.js +11 -0
  232. package/dist/src/modifiers/once-modifier.js.map +1 -0
  233. package/dist/src/modifiers/passive-modifier.d.ts +6 -0
  234. package/dist/src/modifiers/passive-modifier.d.ts.map +1 -0
  235. package/dist/src/modifiers/passive-modifier.js +14 -0
  236. package/dist/src/modifiers/passive-modifier.js.map +1 -0
  237. package/dist/src/processor/parser.d.ts +74 -0
  238. package/dist/src/processor/parser.d.ts.map +1 -0
  239. package/dist/src/processor/parser.js +345 -0
  240. package/dist/src/processor/parser.js.map +1 -0
  241. package/dist/src/processor/processor.d.ts +68 -0
  242. package/dist/src/processor/processor.d.ts.map +1 -0
  243. package/dist/src/processor/processor.js +138 -0
  244. package/dist/src/processor/processor.js.map +1 -0
  245. package/dist/src/processor/template-result.d.ts +74 -0
  246. package/dist/src/processor/template-result.d.ts.map +1 -0
  247. package/dist/src/processor/template-result.js +53 -0
  248. package/dist/src/processor/template-result.js.map +1 -0
  249. package/dist/src/processor/types.d.ts +16 -0
  250. package/dist/src/processor/types.d.ts.map +1 -0
  251. package/dist/src/processor/types.js +13 -0
  252. package/dist/src/processor/types.js.map +1 -0
  253. package/dist/src/utils/debug.d.ts +7 -0
  254. package/dist/src/utils/debug.d.ts.map +1 -0
  255. package/dist/src/utils/debug.js +7 -0
  256. package/dist/src/utils/debug.js.map +1 -0
  257. package/dist/src/utils/performance.d.ts +50 -0
  258. package/dist/src/utils/performance.d.ts.map +1 -0
  259. package/dist/src/utils/performance.js +51 -0
  260. package/dist/src/utils/performance.js.map +1 -0
  261. package/dist/tsconfig.tsbuildinfo +1 -0
  262. package/package.json +8 -10
@@ -0,0 +1,45 @@
1
+ import type { TemplateBinding } from '../processor/parser';
2
+ /** Runtime ref slot stored in the generated refs array */
3
+ interface RefSlot {
4
+ /** For Node bindings: the start comment node */
5
+ startComment?: Comment;
6
+ /** For Node bindings: the end comment node */
7
+ endComment?: Comment;
8
+ /** For attribute / element bindings: the host element */
9
+ el?: Element;
10
+ /** Previous value — used to skip no-op updates */
11
+ prev?: unknown;
12
+ /** Bound event listener (for cleanup) */
13
+ listener?: EventListener;
14
+ }
15
+ /**
16
+ * CodeFactory — generates optimised render/update JavaScript from a parsed
17
+ * miura template.
18
+ *
19
+ * The generated functions use a `refs` array whose slots are populated once
20
+ * (by `collectRefs()`) and then reused on every subsequent update call,
21
+ * avoiding repeated DOM tree walks.
22
+ */
23
+ export declare class CodeFactory {
24
+ private readonly _html;
25
+ constructor(html: string);
26
+ /**
27
+ * Generate the render function for the template.
28
+ * The returned function creates the DOM, collects refs, applies initial
29
+ * values, and returns `{ fragment, refs }`.
30
+ */
31
+ generateRenderFunction(bindings: TemplateBinding[], count: number): CompiledRenderFn;
32
+ /**
33
+ * Generate the update function for the template.
34
+ * Requires the `refs` array produced by the render function.
35
+ */
36
+ generateUpdateFunction(bindings: TemplateBinding[]): CompiledUpdateFn;
37
+ get html(): string;
38
+ }
39
+ export type CompiledRenderFn = (html: string, values: unknown[]) => {
40
+ fragment: DocumentFragment;
41
+ refs: RefSlot[];
42
+ };
43
+ export type CompiledUpdateFn = (refs: RefSlot[], values: unknown[]) => void;
44
+ export {};
45
+ //# sourceMappingURL=code-factory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code-factory.d.ts","sourceRoot":"","sources":["../../../src/compiler/code-factory.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAE3D,0DAA0D;AAC1D,UAAU,OAAO;IACb,gDAAgD;IAChD,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,8CAA8C;IAC9C,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,yDAAyD;IACzD,EAAE,CAAC,EAAE,OAAO,CAAC;IACb,kDAAkD;IAClD,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,yCAAyC;IACzC,QAAQ,CAAC,EAAE,aAAa,CAAC;CAC5B;AAiLD;;;;;;;GAOG;AACH,qBAAa,WAAW;IACpB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;gBAEnB,IAAI,EAAE,MAAM;IAIxB;;;;OAIG;IACH,sBAAsB,CAAC,QAAQ,EAAE,eAAe,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,gBAAgB;IAoBpF;;;OAGG;IACH,sBAAsB,CAAC,QAAQ,EAAE,eAAe,EAAE,GAAG,gBAAgB;IAerE,IAAI,IAAI,IAAI,MAAM,CAAuB;CAC5C;AAID,MAAM,MAAM,gBAAgB,GAAG,CAC3B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,OAAO,EAAE,KAChB;IAAE,QAAQ,EAAE,gBAAgB,CAAC;IAAC,IAAI,EAAE,OAAO,EAAE,CAAA;CAAE,CAAC;AAErD,MAAM,MAAM,gBAAgB,GAAG,CAC3B,IAAI,EAAE,OAAO,EAAE,EACf,MAAM,EAAE,OAAO,EAAE,KAChB,IAAI,CAAC"}
@@ -0,0 +1,211 @@
1
+ import { BindingType } from '../processor/template-result';
2
+ // ── Shared runtime helper code injected into every generated function ─────────
3
+ const HELPERS = /* js */ `
4
+ const MARKER = 'binding:';
5
+
6
+ /** Collect all binding refs from a cloned fragment (run once per render). */
7
+ function collectRefs(frag, count) {
8
+ const refs = new Array(count);
9
+ const walker = document.createTreeWalker(
10
+ frag,
11
+ 0x1 | 0x80, // SHOW_ELEMENT | SHOW_COMMENT
12
+ null
13
+ );
14
+ let node = walker.nextNode();
15
+ while (node) {
16
+ if (node.nodeType === 8) {
17
+ const text = node.textContent || '';
18
+ if (text.startsWith(MARKER)) {
19
+ const idx = +text.slice(MARKER.length);
20
+ if (!isNaN(idx)) {
21
+ refs[idx] = refs[idx] || {};
22
+ refs[idx].startComment = node;
23
+ }
24
+ } else if (text.startsWith('/binding:')) {
25
+ const idx = +text.slice(9);
26
+ if (!isNaN(idx) && refs[idx]) {
27
+ refs[idx].endComment = node;
28
+ }
29
+ }
30
+ } else if (node.nodeType === 1) {
31
+ for (const attr of Array.from(node.attributes)) {
32
+ if (attr.value.startsWith(MARKER)) {
33
+ const idx = +attr.value.slice(MARKER.length);
34
+ if (!isNaN(idx)) {
35
+ refs[idx] = refs[idx] || {};
36
+ refs[idx].el = node;
37
+ node.removeAttribute(attr.name);
38
+ }
39
+ }
40
+ }
41
+ }
42
+ node = walker.nextNode();
43
+ }
44
+ return refs;
45
+ }
46
+
47
+ /** Update a single Node binding (replaces nodes between comment markers). */
48
+ function setNodeBinding(ref, value) {
49
+ if (ref.prev === value) return;
50
+ ref.prev = value;
51
+ const start = ref.startComment;
52
+ const end = ref.endComment;
53
+ if (!start || !end || !start.parentNode) return;
54
+ const parent = start.parentNode;
55
+ // Remove existing content between markers
56
+ let cur = start.nextSibling;
57
+ while (cur && cur !== end) {
58
+ const next = cur.nextSibling;
59
+ parent.removeChild(cur);
60
+ cur = next;
61
+ }
62
+ if (value == null || value === '') return;
63
+ if (value instanceof DocumentFragment || value instanceof Node) {
64
+ parent.insertBefore(value, end);
65
+ } else {
66
+ parent.insertBefore(document.createTextNode(String(value)), end);
67
+ }
68
+ }
69
+
70
+ /** Toggle classes from an object map { className: boolean }. */
71
+ function setObjectClass(el, prev, next) {
72
+ if (prev) Object.keys(prev).forEach(k => { if (!next[k]) el.classList.remove(k); });
73
+ Object.entries(next).forEach(([k, v]) => { v ? el.classList.add(k) : el.classList.remove(k); });
74
+ }
75
+
76
+ /** Apply a style object map { property: value }. */
77
+ function setObjectStyle(el, next) {
78
+ Object.entries(next).forEach(([k, v]) => { el.style[k] = v == null ? '' : String(v); });
79
+ }
80
+ `;
81
+ // ── Per-binding update code generation ───────────────────────────────────────
82
+ /**
83
+ * Strip the binding-syntax prefix character(s) from a raw attribute name.
84
+ * `b.name` is stored as the raw attribute name (e.g. `.value`, `?disabled`,
85
+ * `&model`, `~data`) so that the JIT path can use it verbatim. The AOT path
86
+ * generates JS property accesses and must use the clean identifier instead.
87
+ */
88
+ function _stripPrefix(name) {
89
+ if (!name)
90
+ return '';
91
+ // Handle 3-char spread prefix first, then single-char prefixes
92
+ return name.replace(/^(\.\.\.|[.?&~:#@])/, '');
93
+ }
94
+ function _updateCode(b, ri) {
95
+ const r = `refs[${ri}]`;
96
+ const v = `values[${b.index}]`;
97
+ switch (b.type) {
98
+ case BindingType.Node:
99
+ // Handled externally via NodeBinding instances — skip in generated code.
100
+ return `/* node binding ${ri}: managed by caller */`;
101
+ case BindingType.Property: {
102
+ const prop = _stripPrefix(b.name);
103
+ return `if (${r}.prev !== ${v}) { ${r}.prev = ${v}; ${r}.el.${prop} = ${v}; }`;
104
+ }
105
+ case BindingType.Boolean: {
106
+ const attr = JSON.stringify(_stripPrefix(b.name));
107
+ return `if (${r}.prev !== ${v}) { ${r}.prev = ${v}; ${v} ? ${r}.el.setAttribute(${attr}, '') : ${r}.el.removeAttribute(${attr}); }`;
108
+ }
109
+ case BindingType.Class: {
110
+ return `if (${r}.prev !== ${v}) { ${r}.prev = ${v}; ${r}.el.className = ${v}; }`;
111
+ }
112
+ case BindingType.Style:
113
+ return `if (${r}.prev !== ${v}) { ${r}.prev = ${v}; ${r}.el.style.cssText = ${v}; }`;
114
+ case BindingType.Attribute: {
115
+ const attrName = JSON.stringify(b.name);
116
+ return `if (${r}.prev !== ${v}) { ${r}.prev = ${v}; ${r}.el.setAttribute(${attrName}, ${v} == null ? '' : String(${v})); }`;
117
+ }
118
+ case BindingType.Event:
119
+ // Events set once at render time — skip on update
120
+ return `/* event: ${b.name} — set at render */`;
121
+ case BindingType.ObjectClass:
122
+ return `{ const _next = ${v}||{}; setObjectClass(${r}.el, ${r}.prev, _next); ${r}.prev = _next; }`;
123
+ case BindingType.ObjectStyle:
124
+ return `if (${r}.prev !== ${v}) { ${r}.prev = ${v}; setObjectStyle(${r}.el, ${v}||{}); }`;
125
+ case BindingType.Spread:
126
+ return `if (${r}.prev !== ${v}) { ${r}.prev = ${v}; Object.assign(${r}.el, ${v}||{}); }`;
127
+ case BindingType.Async: {
128
+ const asyncProp = _stripPrefix(b.name);
129
+ return `if (${r}.prev !== ${v}) { ${r}.prev = ${v}; Promise.resolve(${v}).then(rv => { ${r}.el.${asyncProp} = rv; }); }`;
130
+ }
131
+ case BindingType.Bind: {
132
+ const propName = JSON.stringify(_stripPrefix(b.name));
133
+ return `if (${r}.prev !== ${v}) { ${r}.prev = ${v}; ${r}.el[${propName}] = ${v}; }`;
134
+ }
135
+ case BindingType.Reference:
136
+ return `if (${v} && typeof ${v} === 'object') { ${v}.value = ${r}.el; }`;
137
+ case BindingType.Directive:
138
+ return `/* directive handled at runtime */`;
139
+ default:
140
+ return `setNodeBinding(${r}, ${v});`;
141
+ }
142
+ }
143
+ function _renderEventCode(b, ri) {
144
+ const r = `refs[${ri}]`;
145
+ const v = `values[${b.index}]`;
146
+ const evt = JSON.stringify(b.name);
147
+ const once = (b.modifiers ?? []).includes('once') ? ', { once: true }' : '';
148
+ const pass = (b.modifiers ?? []).includes('passive') ? ' | passive' : '';
149
+ return `
150
+ if (${r}.listener) ${r}.el.removeEventListener(${evt}, ${r}.listener${pass ? ', {passive:true}' : ''});
151
+ ${r}.listener = ${v};
152
+ if (${v}) ${r}.el.addEventListener(${evt}, ${v}${once});
153
+ `;
154
+ }
155
+ // ── Public API ────────────────────────────────────────────────────────────────
156
+ /**
157
+ * CodeFactory — generates optimised render/update JavaScript from a parsed
158
+ * miura template.
159
+ *
160
+ * The generated functions use a `refs` array whose slots are populated once
161
+ * (by `collectRefs()`) and then reused on every subsequent update call,
162
+ * avoiding repeated DOM tree walks.
163
+ */
164
+ export class CodeFactory {
165
+ _html;
166
+ constructor(html) {
167
+ this._html = html;
168
+ }
169
+ /**
170
+ * Generate the render function for the template.
171
+ * The returned function creates the DOM, collects refs, applies initial
172
+ * values, and returns `{ fragment, refs }`.
173
+ */
174
+ generateRenderFunction(bindings, count) {
175
+ const updateLines = bindings.map((b, ri) => {
176
+ if (b.type === BindingType.Event)
177
+ return _renderEventCode(b, ri);
178
+ return _updateCode(b, ri);
179
+ }).join('\n');
180
+ const src = /* js */ `
181
+ ${HELPERS}
182
+ const _tpl = document.createElement('template');
183
+ _tpl.innerHTML = html;
184
+ const fragment = _tpl.content.cloneNode(true);
185
+ const refs = collectRefs(fragment, ${count});
186
+ ${updateLines}
187
+ return { fragment, refs };
188
+ `;
189
+ // eslint-disable-next-line no-new-func
190
+ return new Function('html', 'values', src);
191
+ }
192
+ /**
193
+ * Generate the update function for the template.
194
+ * Requires the `refs` array produced by the render function.
195
+ */
196
+ generateUpdateFunction(bindings) {
197
+ const lines = bindings.map((b, ri) => {
198
+ if (b.type === BindingType.Event)
199
+ return _renderEventCode(b, ri);
200
+ return _updateCode(b, ri);
201
+ }).join('\n');
202
+ const src = /* js */ `
203
+ ${HELPERS}
204
+ ${lines}
205
+ `;
206
+ // eslint-disable-next-line no-new-func
207
+ return new Function('refs', 'values', src);
208
+ }
209
+ get html() { return this._html; }
210
+ }
211
+ //# sourceMappingURL=code-factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code-factory.js","sourceRoot":"","sources":["../../../src/compiler/code-factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAiB3D,iFAAiF;AAEjF,MAAM,OAAO,GAAG,QAAQ,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6EvB,CAAC;AAEF,gFAAgF;AAEhF;;;;;GAKG;AACH,SAAS,YAAY,CAAC,IAAwB;IAC1C,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,CAAC;IACrB,+DAA+D;IAC/D,OAAO,IAAI,CAAC,OAAO,CAAC,qBAAqB,EAAE,EAAE,CAAC,CAAC;AACnD,CAAC;AAED,SAAS,WAAW,CAAC,CAAkB,EAAE,EAAU;IAC/C,MAAM,CAAC,GAAG,QAAQ,EAAE,GAAG,CAAC;IACxB,MAAM,CAAC,GAAG,UAAU,CAAC,CAAC,KAAK,GAAG,CAAC;IAE/B,QAAQ,CAAC,CAAC,IAAI,EAAE,CAAC;QACb,KAAK,WAAW,CAAC,IAAI;YACjB,yEAAyE;YACzE,OAAO,mBAAmB,EAAE,wBAAwB,CAAC;QAEzD,KAAK,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC;YAC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AAG,CAAqB,CAAC;IACnE,CAAC;IAED;;;OAGG;IACH,sBAAsB,CAAC,QAA2B;QAC9C,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE;YACjC,IAAI,CAAC,CAAC,IAAI,KAAK,WAAW,CAAC,KAAK;gBAAE,OAAO,gBAAgB,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YACjE,OAAO,WAAW,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAC9B,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEd,MAAM,GAAG,GAAG,QAAQ,CAAA;cACd,OAAO;cACP,KAAK;SACV,CAAC;QAEF,uCAAuC;QACvC,OAAO,IAAI,QAAQ,CAAC,MAAM,EAAE,QAAQ,EAAE,GAAG,CAAqB,CAAC;IACnE,CAAC;IAED,IAAI,IAAI,KAAa,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;CAC5C"}
@@ -0,0 +1,77 @@
1
+ import { TemplateResult } from '../processor/template-result';
2
+ /**
3
+ * A compiled template — owns the generated render/update functions and
4
+ * a `refs` cache (populated on first render, reused on subsequent updates).
5
+ */
6
+ export interface CompiledTemplate {
7
+ /** HTML string for the template (passed to the generated render fn). */
8
+ readonly html: string;
9
+ /**
10
+ * Ref indices (into the `refs` array) that correspond to Node bindings.
11
+ * The caller (MiuraElement AOT path) manages real NodeBinding instances
12
+ * for these indices — the generated update function skips them.
13
+ */
14
+ readonly nodeBindingIndices: readonly number[];
15
+ /**
16
+ * Directive binding descriptors: ref index + directive name (without `#`).
17
+ * The caller creates real DirectiveBinding instances for these so that
18
+ * structural directives (#if, #for, #switch …) work in AOT mode.
19
+ */
20
+ readonly directiveBindingInfos: readonly {
21
+ refIndex: number;
22
+ name: string;
23
+ }[];
24
+ /**
25
+ * Create the DOM fragment and collect element refs.
26
+ * Called once per element instance (on connect / initial render).
27
+ * Returns `{ fragment, refs }` — store `refs` and pass it to `update()`.
28
+ */
29
+ render(values: unknown[]): {
30
+ fragment: DocumentFragment;
31
+ refs: unknown[];
32
+ };
33
+ /**
34
+ * Apply new values to cached element refs.
35
+ * Called on every subsequent update — zero DOM queries.
36
+ * Node bindings (nodeBindingIndices) are intentionally skipped here;
37
+ * the caller updates them via NodeBinding.setValue().
38
+ */
39
+ update(refs: unknown[], values: unknown[]): void;
40
+ }
41
+ /**
42
+ * TemplateCompiler — compiles a TemplateResult into optimised render/update
43
+ * functions using CodeFactory.
44
+ *
45
+ * Templates with the same `strings` reference share a single compiled entry
46
+ * (WeakMap-cached), so compilation happens only once per unique template
47
+ * shape regardless of how many component instances use it.
48
+ *
49
+ * ── Usage ─────────────────────────────────────────────────────────────────────
50
+ *
51
+ * const compiler = new TemplateCompiler();
52
+ *
53
+ * // First call — parses + compiles
54
+ * const compiled = compiler.compile(result);
55
+ *
56
+ * // On first render
57
+ * const { fragment, refs } = compiled.render(result.values);
58
+ * shadowRoot.appendChild(fragment);
59
+ *
60
+ * // On subsequent updates
61
+ * compiled.update(refs, newResult.values);
62
+ */
63
+ export declare class TemplateCompiler {
64
+ private readonly _parseCache;
65
+ private readonly _compileCache;
66
+ private readonly _parser;
67
+ /**
68
+ * Compile a TemplateResult into a reusable CompiledTemplate.
69
+ * Results are cached by `strings` reference — identical tagged template
70
+ * literals always return the same compiled object.
71
+ */
72
+ compile(result: TemplateResult): CompiledTemplate;
73
+ /** Clear both caches (e.g. in tests or hot-module replacement). */
74
+ clearCache(): void;
75
+ private _getOrParse;
76
+ }
77
+ //# sourceMappingURL=compiler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../../../src/compiler/compiler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAe,MAAM,8BAA8B,CAAC;AAI3E;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC7B,wEAAwE;IACxE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;;;OAIG;IACH,QAAQ,CAAC,kBAAkB,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/C;;;;OAIG;IACH,QAAQ,CAAC,qBAAqB,EAAE,SAAS;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC9E;;;;OAIG;IACH,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG;QAAE,QAAQ,EAAE,gBAAgB,CAAC;QAAC,IAAI,EAAE,OAAO,EAAE,CAAA;KAAE,CAAC;IAC3E;;;;;OAKG;IACH,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;CACpD;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,gBAAgB;IACzB,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAwD;IACpF,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAyD;IACvF,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAwB;IAEhD;;;;OAIG;IACH,OAAO,CAAC,MAAM,EAAE,cAAc,GAAG,gBAAgB;IAiCjD,mEAAmE;IACnE,UAAU,IAAI,IAAI;IAMlB,OAAO,CAAC,WAAW;CAQtB"}
@@ -0,0 +1,77 @@
1
+ import { BindingType } from '../processor/template-result';
2
+ import { TemplateParser } from '../processor/parser';
3
+ import { CodeFactory } from './code-factory';
4
+ /**
5
+ * TemplateCompiler — compiles a TemplateResult into optimised render/update
6
+ * functions using CodeFactory.
7
+ *
8
+ * Templates with the same `strings` reference share a single compiled entry
9
+ * (WeakMap-cached), so compilation happens only once per unique template
10
+ * shape regardless of how many component instances use it.
11
+ *
12
+ * ── Usage ─────────────────────────────────────────────────────────────────────
13
+ *
14
+ * const compiler = new TemplateCompiler();
15
+ *
16
+ * // First call — parses + compiles
17
+ * const compiled = compiler.compile(result);
18
+ *
19
+ * // On first render
20
+ * const { fragment, refs } = compiled.render(result.values);
21
+ * shadowRoot.appendChild(fragment);
22
+ *
23
+ * // On subsequent updates
24
+ * compiled.update(refs, newResult.values);
25
+ */
26
+ export class TemplateCompiler {
27
+ _parseCache = new WeakMap();
28
+ _compileCache = new WeakMap();
29
+ _parser = new TemplateParser();
30
+ /**
31
+ * Compile a TemplateResult into a reusable CompiledTemplate.
32
+ * Results are cached by `strings` reference — identical tagged template
33
+ * literals always return the same compiled object.
34
+ */
35
+ compile(result) {
36
+ const cached = this._compileCache.get(result.strings);
37
+ if (cached)
38
+ return cached;
39
+ const parsed = this._getOrParse(result);
40
+ const factory = new CodeFactory(parsed.html);
41
+ const count = parsed.bindings.length;
42
+ const renderFn = factory.generateRenderFunction(parsed.bindings, count);
43
+ const updateFn = factory.generateUpdateFunction(parsed.bindings);
44
+ const nodeBindingIndices = parsed.bindings
45
+ .map((b, i) => b.type === BindingType.Node ? i : -1)
46
+ .filter(i => i !== -1);
47
+ const directiveBindingInfos = parsed.bindings
48
+ .map((b, i) => b.type === BindingType.Directive
49
+ ? { refIndex: i, name: (b.name ?? '').replace(/^#/, '') }
50
+ : null)
51
+ .filter((x) => x !== null);
52
+ const compiled = {
53
+ html: parsed.html,
54
+ nodeBindingIndices,
55
+ directiveBindingInfos,
56
+ render(values) { return renderFn(parsed.html, values); },
57
+ update(refs, values) { updateFn(refs, values); },
58
+ };
59
+ this._compileCache.set(result.strings, compiled);
60
+ return compiled;
61
+ }
62
+ /** Clear both caches (e.g. in tests or hot-module replacement). */
63
+ clearCache() {
64
+ // WeakMaps self-clean — re-assign to drop all entries
65
+ this._parseCache = new WeakMap();
66
+ this._compileCache = new WeakMap();
67
+ }
68
+ _getOrParse(result) {
69
+ let parsed = this._parseCache.get(result.strings);
70
+ if (!parsed) {
71
+ parsed = this._parser.parse(result.strings);
72
+ this._parseCache.set(result.strings, parsed);
73
+ }
74
+ return parsed;
75
+ }
76
+ }
77
+ //# sourceMappingURL=compiler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file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,CAAC,OAAO,CAAC,CAAC;YAC5C,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACjD,CAAC;QACD,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ"}
@@ -0,0 +1,5 @@
1
+ export declare const MARKER_PREFIX = "<!--";
2
+ export declare const MARKER_SUFFIX = "-->";
3
+ export declare function createMarker(index: number): string;
4
+ export declare function createMarkerSelector(index: number): string;
5
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/compiler/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,SAAS,CAAC;AACpC,eAAO,MAAM,aAAa,QAAQ,CAAC;AAEnC,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAElD;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE1D"}
@@ -0,0 +1,9 @@
1
+ export const MARKER_PREFIX = '<!--';
2
+ export const MARKER_SUFFIX = '-->';
3
+ export function createMarker(index) {
4
+ return `${MARKER_PREFIX}${index}${MARKER_SUFFIX}`;
5
+ }
6
+ export function createMarkerSelector(index) {
7
+ return `*:has(+ comment:contains("${index}"))`;
8
+ }
9
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/compiler/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC;AACpC,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,CAAC;AAEnC,MAAM,UAAU,YAAY,CAAC,KAAa;IACxC,OAAO,GAAG,aAAa,GAAG,KAAK,GAAG,aAAa,EAAE,CAAC;AACpD,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,KAAa;IAChD,OAAO,6BAA6B,KAAK,KAAK,CAAC;AACjD,CAAC"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Represents a processed CSS result that can be applied to a component.
3
+ * This class handles the actual CSS text and provides methods to apply it to elements.
4
+ */
5
+ export declare class CSSResult {
6
+ private cssText;
7
+ private styleSheet;
8
+ private adoptedStyleSheets;
9
+ constructor(cssText: string);
10
+ /**
11
+ * Gets the CSS text content
12
+ */
13
+ toString(): string;
14
+ /**
15
+ * Gets or creates a CSSStyleSheet for this CSS result
16
+ */
17
+ private getStyleSheet;
18
+ /**
19
+ * Applies the styles to a given shadow root
20
+ */
21
+ applyTo(shadowRoot: ShadowRoot): void;
22
+ /**
23
+ * Removes the styles from a given shadow root
24
+ */
25
+ removeFrom(shadowRoot: ShadowRoot): void;
26
+ }
27
+ //# sourceMappingURL=css-result.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"css-result.d.ts","sourceRoot":"","sources":["../../src/css-result.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,qBAAa,SAAS;IAIN,OAAO,CAAC,OAAO;IAH3B,OAAO,CAAC,UAAU,CAA8B;IAChD,OAAO,CAAC,kBAAkB,CAA4C;gBAElD,OAAO,EAAE,MAAM;IAEnC;;OAEG;IACH,QAAQ,IAAI,MAAM;IAIlB;;OAEG;IACH,OAAO,CAAC,aAAa;IAQrB;;OAEG;IACH,OAAO,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI;IAUrC;;OAEG;IACH,UAAU,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI;CAY3C"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Represents a processed CSS result that can be applied to a component.
3
+ * This class handles the actual CSS text and provides methods to apply it to elements.
4
+ */
5
+ export class CSSResult {
6
+ cssText;
7
+ styleSheet = null;
8
+ adoptedStyleSheets = new WeakMap();
9
+ constructor(cssText) {
10
+ this.cssText = cssText;
11
+ }
12
+ /**
13
+ * Gets the CSS text content
14
+ */
15
+ toString() {
16
+ return this.cssText;
17
+ }
18
+ /**
19
+ * Gets or creates a CSSStyleSheet for this CSS result
20
+ */
21
+ getStyleSheet() {
22
+ if (!this.styleSheet) {
23
+ this.styleSheet = new CSSStyleSheet();
24
+ this.styleSheet.replaceSync(this.cssText);
25
+ }
26
+ return this.styleSheet;
27
+ }
28
+ /**
29
+ * Applies the styles to a given shadow root
30
+ */
31
+ applyTo(shadowRoot) {
32
+ if (!this.adoptedStyleSheets.has(shadowRoot)) {
33
+ const sheet = this.getStyleSheet();
34
+ const sheets = Array.from(shadowRoot.adoptedStyleSheets);
35
+ sheets.push(sheet);
36
+ shadowRoot.adoptedStyleSheets = sheets;
37
+ this.adoptedStyleSheets.set(shadowRoot, sheet);
38
+ }
39
+ }
40
+ /**
41
+ * Removes the styles from a given shadow root
42
+ */
43
+ removeFrom(shadowRoot) {
44
+ const sheet = this.adoptedStyleSheets.get(shadowRoot);
45
+ if (sheet) {
46
+ const sheets = Array.from(shadowRoot.adoptedStyleSheets);
47
+ const index = sheets.indexOf(sheet);
48
+ if (index > -1) {
49
+ sheets.splice(index, 1);
50
+ shadowRoot.adoptedStyleSheets = sheets;
51
+ }
52
+ this.adoptedStyleSheets.delete(shadowRoot);
53
+ }
54
+ }
55
+ }
56
+ //# sourceMappingURL=css-result.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"css-result.js","sourceRoot":"","sources":["../../src/css-result.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,OAAO,SAAS;IAIE;IAHZ,UAAU,GAAyB,IAAI,CAAC;IACxC,kBAAkB,GAAG,IAAI,OAAO,EAA6B,CAAC;IAEtE,YAAoB,OAAe;QAAf,YAAO,GAAP,OAAO,CAAQ;IAAG,CAAC;IAEvC;;OAEG;IACH,QAAQ;QACJ,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;IAED;;OAEG;IACK,aAAa;QACjB,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACnB,IAAI,CAAC,UAAU,GAAG,IAAI,aAAa,EAAE,CAAC;YACtC,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC9C,CAAC;QACD,OAAO,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,OAAO,CAAC,UAAsB;QAC1B,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC;YAC3C,MAAM,KAAK,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;YACnC,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,kBAAkB,CAAC,CAAC;YACzD,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACnB,UAAU,CAAC,kBAAkB,GAAG,MAAM,CAAC;YACvC,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;QACnD,CAAC;IACL,CAAC;IAED;;OAEG;IACH,UAAU,CAAC,UAAsB;QAC7B,MAAM,KAAK,GAAG,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QACtD,IAAI,KAAK,EAAE,CAAC;YACR,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,kBAAkB,CAAC,CAAC;YACzD,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YACpC,IAAI,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC;gBACb,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;gBACxB,UAAU,CAAC,kBAAkB,GAAG,MAAM,CAAC;YAC3C,CAAC;YACD,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QAC/C,CAAC;IACL,CAAC;CACJ"}
@@ -0,0 +1,26 @@
1
+ import { CSSResult } from './css-result';
2
+ /**
3
+ * Get performance metrics for css function
4
+ */
5
+ export declare function getCssMetrics(): {
6
+ callCount: number;
7
+ totalTime: number;
8
+ cacheHits: number;
9
+ cacheMisses: number;
10
+ };
11
+ /**
12
+ * Reset performance metrics for css function
13
+ */
14
+ export declare function resetCssMetrics(): void;
15
+ /**
16
+ * Clear CSS cache to free memory
17
+ */
18
+ export declare function clearCssCache(): void;
19
+ /**
20
+ * A template literal tag that creates a CSSResult with the given CSS string.
21
+ * @param strings - The static strings from the template literal
22
+ * @param values - The interpolated values from the template literal
23
+ * @returns A CSSResult containing the processed CSS
24
+ */
25
+ export declare function css(strings: TemplateStringsArray, ...values: unknown[]): CSSResult;
26
+ //# sourceMappingURL=css.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"css.d.ts","sourceRoot":"","sources":["../../src/css.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAiBzC;;GAEG;AACH,wBAAgB,aAAa;;;;;EAE5B;AAED;;GAEG;AACH,wBAAgB,eAAe,SAK9B;AAED;;GAEG;AACH,wBAAgB,aAAa,SAE5B;AAED;;;;;GAKG;AACH,wBAAgB,GAAG,CAAC,OAAO,EAAE,oBAAoB,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,SAAS,CAuBlF"}
@@ -0,0 +1,62 @@
1
+ import { CSSResult } from './css-result';
2
+ /**
3
+ * Performance tracking for css function
4
+ */
5
+ const cssMetrics = {
6
+ callCount: 0,
7
+ totalTime: 0,
8
+ cacheHits: 0,
9
+ cacheMisses: 0
10
+ };
11
+ /**
12
+ * CSS cache for repeated styles
13
+ */
14
+ const cssCache = new Map();
15
+ /**
16
+ * Get performance metrics for css function
17
+ */
18
+ export function getCssMetrics() {
19
+ return { ...cssMetrics };
20
+ }
21
+ /**
22
+ * Reset performance metrics for css function
23
+ */
24
+ export function resetCssMetrics() {
25
+ cssMetrics.callCount = 0;
26
+ cssMetrics.totalTime = 0;
27
+ cssMetrics.cacheHits = 0;
28
+ cssMetrics.cacheMisses = 0;
29
+ }
30
+ /**
31
+ * Clear CSS cache to free memory
32
+ */
33
+ export function clearCssCache() {
34
+ cssCache.clear();
35
+ }
36
+ /**
37
+ * A template literal tag that creates a CSSResult with the given CSS string.
38
+ * @param strings - The static strings from the template literal
39
+ * @param values - The interpolated values from the template literal
40
+ * @returns A CSSResult containing the processed CSS
41
+ */
42
+ export function css(strings, ...values) {
43
+ const startTime = performance.now();
44
+ cssMetrics.callCount++;
45
+ const cssText = strings.reduce((result, string, i) => {
46
+ const value = values[i];
47
+ return result + string + (i < values.length ? String(value) : '');
48
+ }, '');
49
+ // Check cache for identical CSS
50
+ const cached = cssCache.get(cssText);
51
+ if (cached) {
52
+ cssMetrics.cacheHits++;
53
+ cssMetrics.totalTime = performance.now() - startTime;
54
+ return cached;
55
+ }
56
+ cssMetrics.cacheMisses++;
57
+ const result = new CSSResult(cssText);
58
+ cssCache.set(cssText, result);
59
+ cssMetrics.totalTime = performance.now() - startTime;
60
+ return result;
61
+ }
62
+ //# sourceMappingURL=css.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"css.js","sourceRoot":"","sources":["../../src/css.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC;;GAEG;AACH,MAAM,UAAU,GAAG;IACjB,SAAS,EAAE,CAAC;IACZ,SAAS,EAAE,CAAC;IACZ,SAAS,EAAE,CAAC;IACZ,WAAW,EAAE,CAAC;CACf,CAAC;AAEF;;GAEG;AACH,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAqB,CAAC;AAE9C;;GAEG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO,EAAE,GAAG,UAAU,EAAE,CAAC;AAC3B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe;IAC7B,UAAU,CAAC,SAAS,GAAG,CAAC,CAAC;IACzB,UAAU,CAAC,SAAS,GAAG,CAAC,CAAC;IACzB,UAAU,CAAC,SAAS,GAAG,CAAC,CAAC;IACzB,UAAU,CAAC,WAAW,G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