@luna_ui/luna 0.3.4 → 0.4.0

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 (182) hide show
  1. package/dist/cli.mjs +1264 -27
  2. package/dist/css/index.d.ts +194 -0
  3. package/dist/css/index.js +721 -0
  4. package/dist/css/runtime.d.ts +92 -0
  5. package/dist/css/runtime.js +179 -0
  6. package/dist/{index-CyEkcO3_.d.ts → index-CDWzWF-h.d.ts} +2 -2
  7. package/dist/index.d.ts +1 -1
  8. package/dist/index.js +1 -1
  9. package/dist/jsx-dev-runtime.js +1 -1
  10. package/dist/jsx-runtime.d.ts +1 -1
  11. package/dist/jsx-runtime.js +1 -1
  12. package/dist/src-DEjrAhrg.js +1 -0
  13. package/dist/vite-plugin.d.ts +122 -0
  14. package/dist/vite-plugin.js +1518 -0
  15. package/package.json +16 -2
  16. package/src/css/extract.ts +798 -0
  17. package/src/css/index.ts +10 -0
  18. package/src/css/inject.ts +205 -0
  19. package/src/css/inline.ts +182 -0
  20. package/src/css/minify.ts +70 -0
  21. package/src/css/optimizer.ts +6 -0
  22. package/src/css/runtime.ts +344 -0
  23. package/src/css-optimizer/README.md +353 -0
  24. package/src/css-optimizer/cooccurrence.ts +100 -0
  25. package/src/css-optimizer/core.ts +263 -0
  26. package/src/css-optimizer/extractors.ts +243 -0
  27. package/src/css-optimizer/hash.ts +54 -0
  28. package/src/css-optimizer/index.ts +129 -0
  29. package/src/css-optimizer/merge.ts +109 -0
  30. package/src/css-optimizer/moonbit-analyzer.ts +210 -0
  31. package/src/css-optimizer/parser.ts +120 -0
  32. package/src/css-optimizer/pattern.ts +171 -0
  33. package/src/css-optimizer/transformers.ts +301 -0
  34. package/src/css-optimizer/types.ts +128 -0
  35. package/src/event-utils.ts +227 -0
  36. package/src/hydration/createHydrator.ts +62 -0
  37. package/src/hydration/delegate.ts +62 -0
  38. package/src/hydration/drag.ts +214 -0
  39. package/src/hydration/index.ts +12 -0
  40. package/src/hydration/keyboard.ts +64 -0
  41. package/src/hydration/toggle.ts +101 -0
  42. package/src/index.ts +890 -0
  43. package/src/jsx-dev-runtime.ts +2 -0
  44. package/src/jsx-runtime.ts +398 -0
  45. package/src/vite-plugin.ts +718 -0
  46. package/tests/__screenshots__/context.test.ts/Context-API-context-with-reactive-effects-context-value-accessible-in-effect-1.png +0 -0
  47. package/tests/__screenshots__/dom.test.ts/DOM-API-For-component--SolidJS-style--For-updates-when-signal-changes-1.png +0 -0
  48. package/tests/__screenshots__/dom.test.ts/DOM-API-Show-component--SolidJS-style--Show-accepts-children-as-function-1.png +0 -0
  49. package/tests/__screenshots__/dom.test.ts/DOM-API-Show-component--SolidJS-style--Show-toggles-visibility-1.png +0 -0
  50. package/tests/__screenshots__/dom.test.ts/DOM-API-createElement-createElement-with-dynamic-attribute-1.png +0 -0
  51. package/tests/__screenshots__/dom.test.ts/DOM-API-createElement-createElement-with-dynamic-style-1.png +0 -0
  52. package/tests/__screenshots__/dom.test.ts/DOM-API-createElementNs--SVG-support--createElementNs-with-dynamic-attribute-1.png +0 -0
  53. package/tests/__screenshots__/dom.test.ts/DOM-API-effect-with-DOM-effect-tracks-signal-changes-1.png +0 -0
  54. package/tests/__screenshots__/dom.test.ts/DOM-API-forEach--list-rendering--forEach-handles-clear-to-empty-1.png +0 -0
  55. package/tests/__screenshots__/dom.test.ts/DOM-API-forEach--list-rendering--forEach-handles-empty-array-1.png +0 -0
  56. package/tests/__screenshots__/dom.test.ts/DOM-API-forEach--list-rendering--forEach-removes-items-1.png +0 -0
  57. package/tests/__screenshots__/dom.test.ts/DOM-API-forEach--list-rendering--forEach-renders-initial-list-1.png +0 -0
  58. package/tests/__screenshots__/dom.test.ts/DOM-API-forEach--list-rendering--forEach-updates-when-items-change-1.png +0 -0
  59. package/tests/__screenshots__/dom.test.ts/DOM-API-forEach-with-SVG-elements-forEach-handles-empty-to-non-empty-transition-in-SVG-1.png +0 -0
  60. package/tests/__screenshots__/dom.test.ts/DOM-API-forEach-with-SVG-elements-forEach-handles-reordering-in-SVG-1.png +0 -0
  61. package/tests/__screenshots__/dom.test.ts/DOM-API-forEach-with-SVG-elements-forEach-updates-SVG-elements-when-signal-changes-1.png +0 -0
  62. package/tests/__screenshots__/dom.test.ts/DOM-API-forEach-with-SVG-elements-forEach-with-nested-SVG-groups-1.png +0 -0
  63. package/tests/__screenshots__/dom.test.ts/DOM-API-ref-callback--JSX-style--ref-callback-with-nested-elements-1.png +0 -0
  64. package/tests/__screenshots__/dom.test.ts/DOM-API-show--conditional-rendering--show-creates-a-node-1.png +0 -0
  65. package/tests/__screenshots__/dom.test.ts/DOM-API-show--conditional-rendering--show-with-false-condition-creates-placeholder-1.png +0 -0
  66. package/tests/__screenshots__/dom.test.ts/DOM-API-text-nodes-textDyn-creates-reactive-text-node-1.png +0 -0
  67. package/tests/__screenshots__/integration.test.ts/Integration--Nested-Components-with-Context-Complex-nested-scenario-forEach-renders-correctly-without-show--initial-items--1.png +0 -0
  68. package/tests/__screenshots__/integration.test.ts/Integration--Nested-Components-with-Context-Complex-nested-scenario-forEach-with-context-renders-correctly-without-show-1.png +0 -0
  69. package/tests/__screenshots__/integration.test.ts/Integration--Nested-Components-with-Context-Complex-nested-scenario-nested-components-with-context--forEach--and-show-1.png +0 -0
  70. package/tests/__screenshots__/integration.test.ts/Integration--Nested-Components-with-Context-Complex-nested-scenario-show-and-forEach-inherit-context-from-Owner--fixed--1.png +0 -0
  71. package/tests/__screenshots__/integration.test.ts/Integration--Nested-Components-with-Context-Complex-nested-scenario-show-and-forEach-work-together--context-uses-default--1.png +0 -0
  72. package/tests/__screenshots__/integration.test.ts/Integration--Nested-Components-with-Context-Context---ForEach-integration-forEach-items-can-access-context-1.png +0 -0
  73. package/tests/__screenshots__/integration.test.ts/Integration--Nested-Components-with-Context-ForEach-with-reactive-updates-forEach-renders-initial-list-1.png +0 -0
  74. package/tests/__screenshots__/integration.test.ts/Integration--Nested-Components-with-Context-ForEach-with-reactive-updates-forEach-updates-when-signal-changes-1.png +0 -0
  75. package/tests/__screenshots__/integration.test.ts/Integration--Nested-Components-with-Context-ForEach-with-reactive-updates-forEach-with-object-items-1.png +0 -0
  76. package/tests/__screenshots__/integration.test.ts/Integration--Nested-Components-with-Context-Show--conditional-rendering--show-hides-when-condition-is-false-1.png +0 -0
  77. package/tests/__screenshots__/integration.test.ts/Integration--Nested-Components-with-Context-Show--conditional-rendering--show-renders-when-condition-is-true-1.png +0 -0
  78. package/tests/__screenshots__/integration.test.ts/Integration--Nested-Components-with-Context-Show--conditional-rendering--show-toggles-from-false-to-true-1.png +0 -0
  79. package/tests/__screenshots__/integration.test.ts/Integration--Nested-Components-with-Context-Show--conditional-rendering--show-toggles-reactively-1.png +0 -0
  80. package/tests/__screenshots__/lifecycle.test.ts/onCleanup-in-Component-Body--Solid-js-style--event-listener-pattern--Solid-js-docs-example--1.png +0 -0
  81. package/tests/__screenshots__/lifecycle.test.ts/onCleanup-in-Component-Body--Solid-js-style--multiple-cleanups-in-component-body--LIFO-order--1.png +0 -0
  82. package/tests/__screenshots__/lifecycle.test.ts/onCleanup-in-Component-Body--Solid-js-style--onCleanup-in-component-body-runs-on-unmount-1.png +0 -0
  83. package/tests/__screenshots__/lifecycle.test.ts/onCleanup-in-Component-Body--Solid-js-style--onCleanup-works-with-For-loop-items--component-body-style--1.png +0 -0
  84. package/tests/__screenshots__/lifecycle.test.ts/onCleanup-in-Component-Body--Solid-js-style--timer-cleanup-pattern--Solid-js-style--1.png +0 -0
  85. package/tests/__screenshots__/lifecycle.test.ts/onCleanup-in-Effects-effect-cleanup-runs-before-re-run-1.png +0 -0
  86. package/tests/__screenshots__/preact-signals-comparison.test.ts/Bulk-Updates-large-list-update-1.png +0 -0
  87. package/tests/__screenshots__/preact-signals-comparison.test.ts/Bulk-Updates-nested-batch-operations-1.png +0 -0
  88. package/tests/__screenshots__/preact-signals-comparison.test.ts/Bulk-Updates-rapid-sequential-updates-1.png +0 -0
  89. package/tests/__screenshots__/preact-signals-comparison.test.ts/DOM-Rendering-Comparison---Conditional-Show-component---visible-1.png +0 -0
  90. package/tests/__screenshots__/preact-signals-comparison.test.ts/DOM-Rendering-Comparison---Conditional-show-hide-element---visible-1.png +0 -0
  91. package/tests/__screenshots__/preact-signals-comparison.test.ts/DOM-Rendering-Comparison---Fragments-fragment-with-list-1.png +0 -0
  92. package/tests/__screenshots__/preact-signals-comparison.test.ts/DOM-Rendering-Comparison---Fragments-nested-fragments-1.png +0 -0
  93. package/tests/__screenshots__/preact-signals-comparison.test.ts/DOM-Rendering-Comparison---Fragments-simple-fragment-1.png +0 -0
  94. package/tests/__screenshots__/preact-signals-comparison.test.ts/DOM-Rendering-Comparison---Reactive-Updates-conditional-toggle-updates-1.png +0 -0
  95. package/tests/__screenshots__/preact-signals-comparison.test.ts/DOM-Rendering-Comparison---Reactive-Updates-list-addition-updates-match-1.png +0 -0
  96. package/tests/__screenshots__/preact-signals-comparison.test.ts/DOM-Rendering-Comparison---Reactive-Updates-list-removal-updates-match-1.png +0 -0
  97. package/tests/__screenshots__/preact-signals-comparison.test.ts/DOM-Rendering-Comparison---Reactive-Updates-text-updates-match-1.png +0 -0
  98. package/tests/__screenshots__/preact-signals-comparison.test.ts/Dynamic-Attributes-Comparison-dynamic-className-updates-1.png +0 -0
  99. package/tests/__screenshots__/preact-signals-comparison.test.ts/Dynamic-Attributes-Comparison-dynamic-style-updates-1.png +0 -0
  100. package/tests/__screenshots__/preact-signals-comparison.test.ts/Dynamic-Attributes-Comparison-multiple-dynamic-attributes-1.png +0 -0
  101. package/tests/__screenshots__/preact-signals-comparison.test.ts/Edge-Cases-deeply-nested-conditionals-1.png +0 -0
  102. package/tests/__screenshots__/preact-signals-comparison.test.ts/Edge-Cases-list-transitions-from-empty-to-populated-1.png +0 -0
  103. package/tests/__screenshots__/preact-signals-comparison.test.ts/Edge-Cases-list-transitions-from-populated-to-empty-1.png +0 -0
  104. package/tests/__screenshots__/preact-signals-comparison.test.ts/Effect-Cleanup-Comparison-nested-effects-cleanup-order-1.png +0 -0
  105. package/tests/__screenshots__/preact-signals-comparison.test.ts/Effect-Cleanup-Comparison-nested-effects-with-inner-signal-change-1.png +0 -0
  106. package/tests/__screenshots__/preact-signals-comparison.test.ts/Effect-Cleanup-Comparison-onCleanup-is-called-when-effect-re-runs-1.png +0 -0
  107. package/tests/__screenshots__/preact-signals-comparison.test.ts/Effect-Cleanup-Comparison-onCleanup-with-resource-simulation-1.png +0 -0
  108. package/tests/__screenshots__/preact-signals-comparison.test.ts/Fragment-Comparison-with-Preact-Fragment-with-multiple-children--no-wrapper--1.png +0 -0
  109. package/tests/__screenshots__/preact-signals-comparison.test.ts/Fragment-Comparison-with-Preact-Fragment-with-no-children-1.png +0 -0
  110. package/tests/__screenshots__/preact-signals-comparison.test.ts/Fragment-Comparison-with-Preact-fragment-with-list-1.png +0 -0
  111. package/tests/__screenshots__/preact-signals-comparison.test.ts/Fragment-Comparison-with-Preact-nested-Fragments-work-correctly-1.png +0 -0
  112. package/tests/__screenshots__/preact-signals-comparison.test.ts/List-Reordering-complex-reordering-with-additions-and-removals-1.png +0 -0
  113. package/tests/__screenshots__/preact-signals-comparison.test.ts/List-Reordering-insert-in-middle-1.png +0 -0
  114. package/tests/__screenshots__/preact-signals-comparison.test.ts/List-Reordering-remove-from-middle-1.png +0 -0
  115. package/tests/__screenshots__/preact-signals-comparison.test.ts/List-Reordering-reverse-list-order-1.png +0 -0
  116. package/tests/__screenshots__/preact-signals-comparison.test.ts/List-Reordering-shuffle-list-1.png +0 -0
  117. package/tests/__screenshots__/preact-signals-comparison.test.ts/Luna-Conditional-Rendering-Show-component-renders-when-condition-is-true-1.png +0 -0
  118. package/tests/__screenshots__/preact-signals-comparison.test.ts/Luna-Conditional-Rendering-show-renders-content-when-initially-true-1.png +0 -0
  119. package/tests/__screenshots__/preact-signals-comparison.test.ts/Luna-Conditional-Rendering-show-toggles-visibility-dynamically-1.png +0 -0
  120. package/tests/__screenshots__/preact-signals-comparison.test.ts/Memo-Dependency-Chain-conditional-memo-dependencies-1.png +0 -0
  121. package/tests/__screenshots__/preact-signals-comparison.test.ts/Signal-Behavior-Comparison-basic-signal-get-set-produces-same-values-1.png +0 -0
  122. package/tests/__screenshots__/preact-signals-comparison.test.ts/Signal-Behavior-Comparison-batch-updates-produce-same-final-values-1.png +0 -0
  123. package/tests/__screenshots__/preact-signals-comparison.test.ts/Untrack-and-Peek-Behavior-peek-reads-value-without-tracking-1.png +0 -0
  124. package/tests/__screenshots__/preact-signals-comparison.test.ts/Untrack-and-Peek-Behavior-selective-tracking-with-untrack-1.png +0 -0
  125. package/tests/__screenshots__/preact-signals-comparison.test.ts/Untrack-and-Peek-Behavior-untrack-prevents-dependency-tracking-1.png +0 -0
  126. package/tests/__screenshots__/resource.test.ts/Resource-API--SolidJS-style--reactivity-accessor-is-reactive-1.png +0 -0
  127. package/tests/__screenshots__/resource.test.ts/Resource-API-AsyncState-helpers-stateError-returns-empty-string-for-non-failure-1.png +0 -0
  128. package/tests/__screenshots__/resource.test.ts/Resource-API-AsyncState-helpers-stateError-returns-undefined-for-non-failure-1.png +0 -0
  129. package/tests/__screenshots__/resource.test.ts/Resource-API-AsyncState-helpers-stateIsFailure-and-stateError-1.png +0 -0
  130. package/tests/__screenshots__/resource.test.ts/Resource-API-AsyncState-helpers-stateIsPending-1.png +0 -0
  131. package/tests/__screenshots__/resource.test.ts/Resource-API-AsyncState-helpers-stateIsSuccess-and-stateValue-1.png +0 -0
  132. package/tests/__screenshots__/resource.test.ts/Resource-API-AsyncState-helpers-stateValue-returns-undefined-for-non-success-1.png +0 -0
  133. package/tests/__screenshots__/resource.test.ts/Resource-API-createDeferred-reject-transitions-to-failure-1.png +0 -0
  134. package/tests/__screenshots__/resource.test.ts/Resource-API-createDeferred-resolve-transitions-to-success-1.png +0 -0
  135. package/tests/__screenshots__/resource.test.ts/Resource-API-createDeferred-returns-resource--resolve--and-reject-functions-1.png +0 -0
  136. package/tests/__screenshots__/resource.test.ts/Resource-API-createDeferred-starts-in-pending-state-1.png +0 -0
  137. package/tests/__screenshots__/resource.test.ts/Resource-API-createResource-async-resolve-works-1.png +0 -0
  138. package/tests/__screenshots__/resource.test.ts/Resource-API-createResource-starts-in-pending-state-1.png +0 -0
  139. package/tests/__screenshots__/resource.test.ts/Resource-API-createResource-transitions-to-failure-on-reject-1.png +0 -0
  140. package/tests/__screenshots__/resource.test.ts/Resource-API-createResource-transitions-to-success-on-resolve-1.png +0 -0
  141. package/tests/__screenshots__/resource.test.ts/Resource-API-integration-with-Promise-can-wrap-fetch-like-async-operations-1.png +0 -0
  142. package/tests/__screenshots__/resource.test.ts/Resource-API-integration-with-Promise-works-with-setTimeout-simulation-1.png +0 -0
  143. package/tests/__screenshots__/resource.test.ts/Resource-API-resourceGet-vs-resourcePeek-resourceGet-tracks-dependencies-1.png +0 -0
  144. package/tests/__screenshots__/resource.test.ts/Resource-API-resourceGet-vs-resourcePeek-resourcePeek-does-not-track-dependencies-1.png +0 -0
  145. package/tests/__screenshots__/resource.test.ts/Resource-API-resourceRefetch-refetch-resets-to-pending-and-re-runs-fetcher-1.png +0 -0
  146. package/tests/__screenshots__/solidjs-api.test.ts/Portal-component-Portal-renders-children-to-body-by-default-1.png +0 -0
  147. package/tests/__screenshots__/solidjs-api.test.ts/Portal-component-Portal-renders-to-selector-mount-target-1.png +0 -0
  148. package/tests/__screenshots__/solidjs-api.test.ts/SolidJS-API-compatibility-createEffect-tracks-dependencies-automatically-1.png +0 -0
  149. package/tests/__screenshots__/solidjs-api.test.ts/Switch-Match-component-Switch-with-accessor-condition-in-Match-1.png +0 -0
  150. package/tests/__screenshots__/solidjs-api.test.ts/Switch-Match-component-Switch-with-multiple-Match-components-1.png +0 -0
  151. package/tests/__screenshots__/solidjs-api.test.ts/Switch-Match-component-Switch-with-single-Match-and-fallback-1.png +0 -0
  152. package/tests/__screenshots__/solidjs-api.test.ts/Switch-Match-components-Switch-updates-DOM-when-signal-changes-1.png +0 -0
  153. package/tests/__screenshots__/solidjs-api.test.ts/on---utility-on-tracks-multiple-dependencies-1.png +0 -0
  154. package/tests/__screenshots__/solidjs-api.test.ts/on---utility-on-tracks-single-dependency-1.png +0 -0
  155. package/tests/__screenshots__/solidjs-api.test.ts/on---utility-on-with-defer-option-skips-initial-run-1.png +0 -0
  156. package/tests/__screenshots__/store.test.ts/createStore-Arrays-array-updates-work-1.png +0 -0
  157. package/tests/__screenshots__/store.test.ts/createStore-Reactivity-only-triggers-when-accessed-property-changes-1.png +0 -0
  158. package/tests/__screenshots__/store.test.ts/createStore-Reactivity-parent-path-change-notifies-child-accessors-1.png +0 -0
  159. package/tests/__screenshots__/store.test.ts/createStore-Reactivity-tracks-nested-property-access-1.png +0 -0
  160. package/tests/__screenshots__/store.test.ts/createStore-Reactivity-tracks-property-access-in-effects-1.png +0 -0
  161. package/tests/context.test.ts +118 -0
  162. package/tests/css-optimizer-extractors.test.ts +264 -0
  163. package/tests/css-optimizer-integration.test.ts +566 -0
  164. package/tests/css-optimizer-transformers.test.ts +301 -0
  165. package/tests/css-optimizer.test.ts +646 -0
  166. package/tests/css-runtime.bench.ts +442 -0
  167. package/tests/css-runtime.test.ts +342 -0
  168. package/tests/dom.test.ts +872 -0
  169. package/tests/integration.test.ts +405 -0
  170. package/tests/issue-5-for-infinite-loop.test.ts +516 -0
  171. package/tests/jsx-runtime.test.tsx +393 -0
  172. package/tests/lifecycle.test.ts +833 -0
  173. package/tests/move-before.bench.ts +304 -0
  174. package/tests/preact-signals-comparison.test.ts +1608 -0
  175. package/tests/resource.test.ts +160 -0
  176. package/tests/router.test.ts +117 -0
  177. package/tests/show-initial-mount-leak.test.tsx +182 -0
  178. package/tests/solidjs-api.test.ts +659 -0
  179. package/tests/static-perf.bench.ts +64 -0
  180. package/tests/store.test.ts +263 -0
  181. package/tests/tsx-syntax.test.tsx +404 -0
  182. package/dist/src-BDdxGwvq.js +0 -1
@@ -0,0 +1,304 @@
1
+ /**
2
+ * DOM operation benchmark tests
3
+ * Run with: pnpm test:browser
4
+ */
5
+
6
+ import { describe, test, expect, beforeEach, afterEach } from "vitest";
7
+
8
+ // Extend Element interface for moveBefore (Chrome 133+)
9
+ declare global {
10
+ interface Element {
11
+ moveBefore(node: Node, child: Node | null): Node;
12
+ }
13
+ }
14
+
15
+ // Benchmark helper (silent - no console output)
16
+ function bench(name: string, fn: () => void, iterations = 1000, warmup = 100) {
17
+ // Warmup
18
+ for (let i = 0; i < warmup; i++) {
19
+ fn();
20
+ }
21
+
22
+ // Actual run
23
+ const start = performance.now();
24
+ for (let i = 0; i < iterations; i++) {
25
+ fn();
26
+ }
27
+ const elapsed = performance.now() - start;
28
+ const perOp = elapsed / iterations;
29
+
30
+ return { name, elapsed, perOp };
31
+ }
32
+
33
+ describe("moveBefore API", () => {
34
+ let container: HTMLDivElement;
35
+
36
+ beforeEach(() => {
37
+ container = document.createElement("div");
38
+ document.body.appendChild(container);
39
+ });
40
+
41
+ afterEach(() => {
42
+ container.remove();
43
+ });
44
+
45
+ test("moveBefore preserves element reference", () => {
46
+ const ul = document.createElement("ul");
47
+ const li1 = document.createElement("li");
48
+ const li2 = document.createElement("li");
49
+ li1.textContent = "Item 1";
50
+ li2.textContent = "Item 2";
51
+ ul.appendChild(li1);
52
+ ul.appendChild(li2);
53
+ container.appendChild(ul);
54
+
55
+ // Store reference
56
+ const originalLi1 = li1;
57
+
58
+ // Move li1 to end
59
+ ul.moveBefore(li1, null);
60
+
61
+ // Verify it's the same element
62
+ expect(ul.lastChild).toBe(originalLi1);
63
+ expect(ul.children[1]).toBe(originalLi1);
64
+ });
65
+
66
+ test("insertBefore also preserves element reference", () => {
67
+ const ul = document.createElement("ul");
68
+ const li1 = document.createElement("li");
69
+ const li2 = document.createElement("li");
70
+ li1.textContent = "Item 1";
71
+ li2.textContent = "Item 2";
72
+ ul.appendChild(li1);
73
+ ul.appendChild(li2);
74
+ container.appendChild(ul);
75
+
76
+ // Store reference
77
+ const originalLi1 = li1;
78
+
79
+ // Move li1 to end using insertBefore
80
+ ul.insertBefore(li1, null);
81
+
82
+ // Verify it's the same element
83
+ expect(ul.lastChild).toBe(originalLi1);
84
+ });
85
+ });
86
+
87
+ describe("moveBefore vs insertBefore benchmark", () => {
88
+ let container: HTMLDivElement;
89
+
90
+ beforeEach(() => {
91
+ container = document.createElement("div");
92
+ document.body.appendChild(container);
93
+ });
94
+
95
+ afterEach(() => {
96
+ container.remove();
97
+ });
98
+
99
+ const setupList = (count: number): HTMLUListElement => {
100
+ const ul = document.createElement("ul");
101
+ for (let i = 0; i < count; i++) {
102
+ const li = document.createElement("li");
103
+ li.textContent = `Item ${i}`;
104
+ ul.appendChild(li);
105
+ }
106
+ container.appendChild(ul);
107
+ return ul;
108
+ };
109
+
110
+ test("benchmark: single element move", () => {
111
+ const results: { name: string; perOp: number }[] = [];
112
+
113
+ results.push(
114
+ bench("insertBefore_single", () => {
115
+ const ul = setupList(10);
116
+ const first = ul.firstChild!;
117
+ ul.insertBefore(first, null);
118
+ ul.remove();
119
+ })
120
+ );
121
+
122
+ results.push(
123
+ bench("moveBefore_single", () => {
124
+ const ul = setupList(10);
125
+ const first = ul.firstChild!;
126
+ ul.moveBefore(first, null);
127
+ ul.remove();
128
+ })
129
+ );
130
+
131
+ expect(results.length).toBe(2);
132
+ });
133
+
134
+ test("benchmark: shuffle 10 elements", () => {
135
+ const results: { name: string; perOp: number }[] = [];
136
+
137
+ results.push(
138
+ bench("insertBefore_shuffle_10", () => {
139
+ const ul = setupList(10);
140
+ const children = Array.from(ul.children);
141
+ for (let i = children.length - 1; i >= 0; i--) {
142
+ ul.insertBefore(children[i], ul.firstChild);
143
+ }
144
+ ul.remove();
145
+ })
146
+ );
147
+
148
+ results.push(
149
+ bench("moveBefore_shuffle_10", () => {
150
+ const ul = setupList(10);
151
+ const children = Array.from(ul.children);
152
+ for (let i = children.length - 1; i >= 0; i--) {
153
+ ul.moveBefore(children[i], ul.firstChild);
154
+ }
155
+ ul.remove();
156
+ })
157
+ );
158
+
159
+ expect(results.length).toBe(2);
160
+ });
161
+
162
+ test("benchmark: shuffle 50 elements", () => {
163
+ const results: { name: string; perOp: number }[] = [];
164
+
165
+ results.push(
166
+ bench(
167
+ "insertBefore_shuffle_50",
168
+ () => {
169
+ const ul = setupList(50);
170
+ const children = Array.from(ul.children);
171
+ for (let i = children.length - 1; i >= 0; i--) {
172
+ ul.insertBefore(children[i], ul.firstChild);
173
+ }
174
+ ul.remove();
175
+ },
176
+ 500
177
+ )
178
+ );
179
+
180
+ results.push(
181
+ bench(
182
+ "moveBefore_shuffle_50",
183
+ () => {
184
+ const ul = setupList(50);
185
+ const children = Array.from(ul.children);
186
+ for (let i = children.length - 1; i >= 0; i--) {
187
+ ul.moveBefore(children[i], ul.firstChild);
188
+ }
189
+ ul.remove();
190
+ },
191
+ 500
192
+ )
193
+ );
194
+
195
+ expect(results.length).toBe(2);
196
+ });
197
+
198
+ test("moveBefore preserves iframe state", async () => {
199
+ // Create container with iframe
200
+ const wrapper = document.createElement("div");
201
+ const section1 = document.createElement("section");
202
+ const section2 = document.createElement("section");
203
+ const iframe = document.createElement("iframe");
204
+ iframe.srcdoc = "<html><body>Test content</body></html>";
205
+
206
+ wrapper.appendChild(section1);
207
+ wrapper.appendChild(section2);
208
+ section1.appendChild(iframe);
209
+ container.appendChild(wrapper);
210
+
211
+ // Wait for iframe to load
212
+ await new Promise((resolve) => {
213
+ iframe.onload = resolve;
214
+ setTimeout(resolve, 100); // Fallback timeout
215
+ });
216
+
217
+ // Get iframe content before move
218
+ const contentBefore = iframe.contentDocument?.body?.textContent;
219
+
220
+ // Move iframe to section2 using moveBefore
221
+ section2.moveBefore(iframe, null);
222
+
223
+ // Check iframe content after move
224
+ const contentAfter = iframe.contentDocument?.body?.textContent;
225
+
226
+ // moveBefore should preserve iframe state
227
+ expect(iframe.parentElement).toBe(section2);
228
+ expect(contentAfter).toBe(contentBefore);
229
+ });
230
+ });
231
+
232
+ describe("DOM operation microbenchmarks", () => {
233
+ let container: HTMLDivElement;
234
+
235
+ beforeEach(() => {
236
+ container = document.createElement("div");
237
+ document.body.appendChild(container);
238
+ });
239
+
240
+ afterEach(() => {
241
+ container.remove();
242
+ });
243
+
244
+ test("benchmark: createElement", () => {
245
+ const result = bench("createElement_div", () => {
246
+ document.createElement("div");
247
+ }, 10000);
248
+ expect(result.perOp).toBeLessThan(1);
249
+ });
250
+
251
+ test("benchmark: appendChild", () => {
252
+ const result = bench("appendChild", () => {
253
+ const div = document.createElement("div");
254
+ container.appendChild(div);
255
+ div.remove();
256
+ }, 5000);
257
+ expect(result.perOp).toBeLessThan(1);
258
+ });
259
+
260
+ test("benchmark: textContent assignment", () => {
261
+ const div = document.createElement("div");
262
+ container.appendChild(div);
263
+
264
+ const result = bench("textContent_set", () => {
265
+ div.textContent = "Hello World";
266
+ }, 10000);
267
+
268
+ expect(result.perOp).toBeLessThan(1);
269
+ });
270
+
271
+ test("benchmark: innerHTML clear", () => {
272
+ const result = bench("innerHTML_clear", () => {
273
+ const div = document.createElement("div");
274
+ div.innerHTML = "<span>test</span><span>test2</span>";
275
+ container.appendChild(div);
276
+ div.innerHTML = "";
277
+ div.remove();
278
+ }, 5000);
279
+ expect(result.perOp).toBeLessThan(1);
280
+ });
281
+
282
+ test("benchmark: setAttribute", () => {
283
+ const div = document.createElement("div");
284
+ container.appendChild(div);
285
+
286
+ const result = bench("setAttribute", () => {
287
+ div.setAttribute("class", "test-class");
288
+ }, 10000);
289
+
290
+ expect(result.perOp).toBeLessThan(1);
291
+ });
292
+
293
+ test("benchmark: classList.add", () => {
294
+ const div = document.createElement("div");
295
+ container.appendChild(div);
296
+
297
+ const result = bench("classList_add", () => {
298
+ div.classList.add("test-class");
299
+ div.classList.remove("test-class");
300
+ }, 10000);
301
+
302
+ expect(result.perOp).toBeLessThan(1);
303
+ });
304
+ });