@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,659 @@
1
+ /**
2
+ * Tests for SolidJS-compatible API utilities
3
+ */
4
+ import { describe, test, expect, beforeEach, afterEach } from "vitest";
5
+ import {
6
+ createSignal,
7
+ createRenderEffect,
8
+ createMemo,
9
+ createRoot,
10
+ on,
11
+ mergeProps,
12
+ splitProps,
13
+ Provider,
14
+ Index,
15
+ Switch,
16
+ Match,
17
+ Portal,
18
+ portalToBody,
19
+ portalToSelector,
20
+ createContext,
21
+ useContext,
22
+ createElement,
23
+ text,
24
+ mount,
25
+ For,
26
+ } from "../src/index";
27
+
28
+ // MoonBit AttrValue constructors
29
+ const AttrValue = {
30
+ Static: (value: string) => ({ $tag: 0, _0: value }),
31
+ Dynamic: (getter: () => string) => ({ $tag: 1, _0: getter }),
32
+ };
33
+
34
+ function attr(name: string, value: unknown) {
35
+ return { _0: name, _1: value };
36
+ }
37
+
38
+ describe("on() utility", () => {
39
+ test("on tracks single dependency", () => {
40
+ const results: [number, number | undefined][] = [];
41
+
42
+ createRoot((dispose) => {
43
+ const [count, setCount] = createSignal(0);
44
+
45
+ createRenderEffect(
46
+ on(count, (value, prev) => {
47
+ results.push([value, prev]);
48
+ })
49
+ );
50
+
51
+ setCount(1);
52
+ setCount(2);
53
+ dispose();
54
+ });
55
+
56
+ expect(results).toEqual([
57
+ [0, undefined],
58
+ [1, 0],
59
+ [2, 1],
60
+ ]);
61
+ });
62
+
63
+ test("on tracks multiple dependencies", () => {
64
+ const results: [[number, string], [number, string] | undefined][] = [];
65
+
66
+ createRoot((dispose) => {
67
+ const [a, setA] = createSignal(1);
68
+ const [b, setB] = createSignal("x");
69
+
70
+ createRenderEffect(
71
+ on([a, b], (values, prev) => {
72
+ results.push([values as [number, string], prev as [number, string] | undefined]);
73
+ })
74
+ );
75
+
76
+ setA(2);
77
+ setB("y");
78
+ dispose();
79
+ });
80
+
81
+ expect(results).toEqual([
82
+ [[1, "x"], undefined],
83
+ [[2, "x"], [1, "x"]],
84
+ [[2, "y"], [2, "x"]],
85
+ ]);
86
+ });
87
+
88
+ test("on with defer option skips initial run", () => {
89
+ const results: number[] = [];
90
+
91
+ createRoot((dispose) => {
92
+ const [count, setCount] = createSignal(0);
93
+
94
+ createRenderEffect(
95
+ on(
96
+ count,
97
+ (value) => {
98
+ results.push(value);
99
+ },
100
+ { defer: true }
101
+ )
102
+ );
103
+
104
+ // Initial run should be skipped
105
+ expect(results).toEqual([]);
106
+
107
+ setCount(1);
108
+ expect(results).toEqual([1]);
109
+
110
+ setCount(2);
111
+ expect(results).toEqual([1, 2]);
112
+
113
+ dispose();
114
+ });
115
+ });
116
+ });
117
+
118
+ describe("mergeProps()", () => {
119
+ test("merges simple props", () => {
120
+ const a = { foo: 1, bar: 2 };
121
+ const b = { bar: 3, baz: 4 };
122
+ const result = mergeProps(a, b);
123
+
124
+ expect(result).toEqual({ foo: 1, bar: 3, baz: 4 });
125
+ });
126
+
127
+ test("merges event handlers", () => {
128
+ const calls: string[] = [];
129
+ const a = { onClick: () => calls.push("a") };
130
+ const b = { onClick: () => calls.push("b") };
131
+ const result = mergeProps(a, b) as { onClick: () => void };
132
+
133
+ result.onClick();
134
+ expect(calls).toEqual(["a", "b"]);
135
+ });
136
+
137
+ test("merges ref callbacks", () => {
138
+ const refs: string[] = [];
139
+ const a = { ref: (el: string) => refs.push(`a:${el}`) };
140
+ const b = { ref: (el: string) => refs.push(`b:${el}`) };
141
+ const result = mergeProps(a, b) as { ref: (el: string) => void };
142
+
143
+ result.ref("element");
144
+ expect(refs).toEqual(["a:element", "b:element"]);
145
+ });
146
+
147
+ test("merges class names", () => {
148
+ const a = { class: "foo" };
149
+ const b = { class: "bar" };
150
+ const result = mergeProps(a, b);
151
+
152
+ expect(result.class).toBe("foo bar");
153
+ });
154
+
155
+ test("merges className", () => {
156
+ const a = { className: "foo" };
157
+ const b = { className: "bar" };
158
+ const result = mergeProps(a, b);
159
+
160
+ expect(result.className).toBe("foo bar");
161
+ });
162
+
163
+ test("merges style objects", () => {
164
+ const a = { style: { color: "red", margin: "10px" } } as const;
165
+ const b = { style: { color: "blue", padding: "5px" } } as const;
166
+ const result = mergeProps<{ style: Record<string, string> }>(a as any, b as any);
167
+
168
+ expect(result.style).toEqual({ color: "blue", margin: "10px", padding: "5px" });
169
+ });
170
+
171
+ test("handles undefined sources", () => {
172
+ const a = { foo: 1 };
173
+ const result = mergeProps<{ foo?: number; bar?: number }>(undefined, a, undefined, { bar: 2 });
174
+
175
+ expect(result).toEqual({ foo: 1, bar: 2 });
176
+ });
177
+ });
178
+
179
+ describe("splitProps()", () => {
180
+ test("splits props into specified groups", () => {
181
+ const props = { a: 1, b: 2, c: 3, d: 4 };
182
+ const [ab, cd] = splitProps(props, ["a", "b"]);
183
+
184
+ expect(ab).toEqual({ a: 1, b: 2 });
185
+ expect(cd).toEqual({ c: 3, d: 4 });
186
+ });
187
+
188
+ test("splits props into multiple groups", () => {
189
+ const props = { a: 1, b: 2, c: 3, d: 4, e: 5 };
190
+ const [group1, group2, rest] = splitProps(props, ["a", "b"], ["c"]);
191
+
192
+ expect(group1).toEqual({ a: 1, b: 2 });
193
+ expect(group2).toEqual({ c: 3 });
194
+ expect(rest).toEqual({ d: 4, e: 5 });
195
+ });
196
+
197
+ test("handles missing keys", () => {
198
+ const props = { a: 1, b: 2 };
199
+ const [group, rest] = splitProps(props, ["a", "c"] as (keyof typeof props)[]);
200
+
201
+ expect(group).toEqual({ a: 1 });
202
+ expect(rest).toEqual({ b: 2 });
203
+ });
204
+ });
205
+
206
+ describe("Provider component", () => {
207
+ let container: HTMLElement;
208
+
209
+ beforeEach(() => {
210
+ container = document.createElement("div");
211
+ document.body.appendChild(container);
212
+ });
213
+
214
+ test("Provider provides context value", () => {
215
+ const themeCtx = createContext("light");
216
+ let capturedTheme = "";
217
+
218
+ const Child = () => {
219
+ capturedTheme = useContext(themeCtx);
220
+ return text(capturedTheme);
221
+ };
222
+
223
+ Provider({
224
+ context: themeCtx,
225
+ value: "dark",
226
+ children: () => {
227
+ mount(container, Child());
228
+ return text("");
229
+ },
230
+ });
231
+
232
+ expect(capturedTheme).toBe("dark");
233
+ });
234
+
235
+ test("Provider works with function children", () => {
236
+ const countCtx = createContext(0);
237
+ let capturedCount = -1;
238
+
239
+ Provider({
240
+ context: countCtx,
241
+ value: 42,
242
+ children: () => {
243
+ capturedCount = useContext(countCtx);
244
+ return text(String(capturedCount));
245
+ },
246
+ });
247
+
248
+ expect(capturedCount).toBe(42);
249
+ });
250
+ });
251
+
252
+ describe("Index component", () => {
253
+ let container: HTMLElement;
254
+
255
+ beforeEach(() => {
256
+ container = document.createElement("div");
257
+ document.body.appendChild(container);
258
+ });
259
+
260
+ test("Index renders list with item getters", () => {
261
+ const [items] = createSignal(["a", "b", "c"]);
262
+
263
+ const node = Index({
264
+ each: items,
265
+ children: (itemGetter, index) =>
266
+ createElement(
267
+ "span",
268
+ [attr("data-index", AttrValue.Static(String(index)))],
269
+ [text(itemGetter())]
270
+ ),
271
+ });
272
+
273
+ mount(container, node);
274
+
275
+ const spans = container.querySelectorAll("span");
276
+ expect(spans.length).toBe(3);
277
+ expect(spans[0].textContent).toBe("a");
278
+ expect(spans[1].textContent).toBe("b");
279
+ expect(spans[2].textContent).toBe("c");
280
+ });
281
+
282
+ test("Index provides working item getter", () => {
283
+ const values: string[] = [];
284
+ const [items] = createSignal(["x", "y"]);
285
+
286
+ Index({
287
+ each: items,
288
+ children: (itemGetter, _index) => {
289
+ values.push(itemGetter());
290
+ return text(itemGetter());
291
+ },
292
+ });
293
+
294
+ expect(values).toEqual(["x", "y"]);
295
+ });
296
+ });
297
+
298
+ describe("Switch/Match components", () => {
299
+ let container: HTMLElement;
300
+
301
+ beforeEach(() => {
302
+ container = document.createElement("div");
303
+ document.body.appendChild(container);
304
+ });
305
+
306
+ afterEach(() => {
307
+ container.remove();
308
+ });
309
+
310
+ test("Switch renders first truthy Match", () => {
311
+ const [value, setValue] = createSignal("a");
312
+
313
+ let rendered = "";
314
+ createRoot((dispose) => {
315
+ const result = Switch({
316
+ fallback: text("none"),
317
+ children: [
318
+ Match({
319
+ when: () => value() === "a",
320
+ children: text("matched-a"),
321
+ }),
322
+ Match({
323
+ when: () => value() === "b",
324
+ children: text("matched-b"),
325
+ }),
326
+ ],
327
+ });
328
+
329
+ // result should be the matched content
330
+ rendered = result ? "has-result" : "no-result";
331
+ dispose();
332
+ });
333
+
334
+ expect(rendered).toBe("has-result");
335
+ });
336
+
337
+ test("Switch updates DOM when signal changes", () => {
338
+ const [value, setValue] = createSignal("a");
339
+
340
+ createRoot((dispose) => {
341
+ const node = Switch({
342
+ fallback: text("fallback"),
343
+ children: [
344
+ Match({
345
+ when: () => value() === "a",
346
+ children: text("A"),
347
+ }),
348
+ Match({
349
+ when: () => value() === "b",
350
+ children: text("B"),
351
+ }),
352
+ ],
353
+ });
354
+
355
+ mount(container, node);
356
+ expect(container.textContent).toBe("A");
357
+
358
+ setValue("b");
359
+ expect(container.textContent).toBe("B");
360
+
361
+ setValue("c");
362
+ expect(container.textContent).toBe("fallback");
363
+
364
+ setValue("a");
365
+ expect(container.textContent).toBe("A");
366
+
367
+ dispose();
368
+ });
369
+ });
370
+
371
+ test("Switch returns fallback when no match", () => {
372
+ const [value] = createSignal("c");
373
+
374
+ const result = Switch({
375
+ fallback: text("fallback"),
376
+ children: [
377
+ Match({
378
+ when: () => value() === "a",
379
+ children: text("a"),
380
+ }),
381
+ Match({
382
+ when: () => value() === "b",
383
+ children: text("b"),
384
+ }),
385
+ ],
386
+ });
387
+
388
+ // Result should be fallback text node
389
+ expect(result).toBeDefined();
390
+ });
391
+
392
+ test("Match with function children receives value", () => {
393
+ const [user, setUser] = createSignal<{ name: string } | null>(null);
394
+ let receivedName = "";
395
+
396
+ createRoot((dispose) => {
397
+ const match = Match({
398
+ when: user,
399
+ children: (u: { name: string }) => {
400
+ receivedName = u.name;
401
+ return text(u.name);
402
+ },
403
+ });
404
+
405
+ // First, user is null, so match.when() should be false
406
+ expect(match.when()).toBe(false);
407
+
408
+ setUser({ name: "Alice" });
409
+ expect(match.when()).toBe(true);
410
+
411
+ // Call children with the value
412
+ if (match.when() && typeof match.children === "function") {
413
+ match.children();
414
+ expect(receivedName).toBe("Alice");
415
+ }
416
+
417
+ dispose();
418
+ });
419
+ });
420
+ });
421
+
422
+ describe("SolidJS API compatibility", () => {
423
+ test("createSignal returns tuple [getter, setter]", () => {
424
+ const [count, setCount] = createSignal(0);
425
+
426
+ expect(typeof count).toBe("function");
427
+ expect(typeof setCount).toBe("function");
428
+ expect(count()).toBe(0);
429
+
430
+ setCount(5);
431
+ expect(count()).toBe(5);
432
+
433
+ setCount((c) => c + 1);
434
+ expect(count()).toBe(6);
435
+ });
436
+
437
+ test("createMemo returns accessor", () => {
438
+ const [count, setCount] = createSignal(2);
439
+ const doubled = createMemo(() => count() * 2);
440
+
441
+ expect(typeof doubled).toBe("function");
442
+ expect(doubled()).toBe(4);
443
+
444
+ setCount(5);
445
+ expect(doubled()).toBe(10);
446
+ });
447
+
448
+ test("createRenderEffect tracks dependencies automatically", () => {
449
+ const values: number[] = [];
450
+
451
+ createRoot((dispose) => {
452
+ const [count, setCount] = createSignal(0);
453
+
454
+ createRenderEffect(() => {
455
+ values.push(count());
456
+ });
457
+
458
+ setCount(1);
459
+ setCount(2);
460
+ dispose();
461
+ });
462
+
463
+ expect(values).toEqual([0, 1, 2]);
464
+ });
465
+ });
466
+
467
+ describe("Portal component", () => {
468
+ let container: HTMLElement;
469
+ let portalTarget: HTMLElement;
470
+
471
+ beforeEach(() => {
472
+ container = document.createElement("div");
473
+ container.id = "test-container";
474
+ document.body.appendChild(container);
475
+
476
+ portalTarget = document.createElement("div");
477
+ portalTarget.id = "portal-target";
478
+ document.body.appendChild(portalTarget);
479
+ });
480
+
481
+ afterEach(() => {
482
+ container.remove();
483
+ portalTarget.remove();
484
+ });
485
+
486
+ test("Portal renders children to body by default", () => {
487
+ const placeholder = Portal({
488
+ children: () => createElement("div", [attr("id", AttrValue.Static("portal-content"))], [text("Portal content")]),
489
+ });
490
+
491
+ // Placeholder should be returned
492
+ expect(placeholder).toBeDefined();
493
+
494
+ // Content should be in body
495
+ const rendered = document.getElementById("portal-content");
496
+ expect(rendered).not.toBeNull();
497
+ expect(rendered?.textContent).toBe("Portal content");
498
+
499
+ // Clean up
500
+ rendered?.remove();
501
+ });
502
+
503
+ test("Portal renders to selector mount target", () => {
504
+ Portal({
505
+ mount: "#portal-target",
506
+ children: () => createElement("div", [attr("id", AttrValue.Static("selector-portal"))], [text("Selector portal")]),
507
+ });
508
+
509
+ // Content should be in the portal target
510
+ const rendered = portalTarget.querySelector("#selector-portal");
511
+ expect(rendered).not.toBeNull();
512
+ expect(rendered?.textContent).toBe("Selector portal");
513
+ });
514
+
515
+ test("portalToBody low-level API works", () => {
516
+ const content = createElement("div", [attr("id", AttrValue.Static("low-level-portal"))], [text("Low level")]);
517
+
518
+ portalToBody([content]);
519
+
520
+ const rendered = document.getElementById("low-level-portal");
521
+ expect(rendered).not.toBeNull();
522
+ expect(rendered?.textContent).toBe("Low level");
523
+
524
+ rendered?.remove();
525
+ });
526
+
527
+ test("portalToSelector low-level API works", () => {
528
+ const content = createElement("div", [attr("class", AttrValue.Static("selector-content"))], [text("Selector content")]);
529
+
530
+ portalToSelector("#portal-target", [content]);
531
+
532
+ const rendered = portalTarget.querySelector(".selector-content");
533
+ expect(rendered).not.toBeNull();
534
+ expect(rendered?.textContent).toBe("Selector content");
535
+ });
536
+
537
+ test("Portal accepts function children", () => {
538
+ const content = () => createElement("span", [attr("id", AttrValue.Static("func-portal"))], [text("Function child")]);
539
+
540
+ Portal({
541
+ children: content,
542
+ });
543
+
544
+ const rendered = document.getElementById("func-portal");
545
+ expect(rendered).not.toBeNull();
546
+ expect(rendered?.textContent).toBe("Function child");
547
+
548
+ rendered?.remove();
549
+ });
550
+ });
551
+
552
+ describe("Switch/Match component", () => {
553
+ let container: HTMLElement;
554
+
555
+ beforeEach(() => {
556
+ container = document.createElement("div");
557
+ document.body.appendChild(container);
558
+ });
559
+
560
+ afterEach(() => {
561
+ container.remove();
562
+ });
563
+
564
+ test("Switch with single Match renders correctly", () => {
565
+ createRoot((dispose) => {
566
+ const [value, setValue] = createSignal(true);
567
+
568
+ const node = Switch({
569
+ children: Match({
570
+ when: value,
571
+ children: createElement("div", [], [text("Match 1")]),
572
+ }),
573
+ });
574
+
575
+ mount(container, node);
576
+ expect(container.textContent).toContain("Match 1");
577
+ dispose();
578
+ });
579
+ });
580
+
581
+ test("Switch with single Match and fallback", () => {
582
+ createRoot((dispose) => {
583
+ const [value, setValue] = createSignal(false);
584
+
585
+ const node = Switch({
586
+ fallback: createElement("div", [], [text("Fallback")]),
587
+ children: Match({
588
+ when: value,
589
+ children: createElement("div", [], [text("Match 1")]),
590
+ }),
591
+ });
592
+
593
+ mount(container, node);
594
+ expect(container.textContent).toContain("Fallback");
595
+
596
+ // Trigger update
597
+ setValue(true);
598
+ expect(container.textContent).toContain("Match 1");
599
+ dispose();
600
+ });
601
+ });
602
+
603
+ test("Switch with multiple Match components", () => {
604
+ createRoot((dispose) => {
605
+ const [value, setValue] = createSignal(1);
606
+
607
+ const node = Switch({
608
+ fallback: createElement("div", [], [text("Fallback")]),
609
+ children: [
610
+ Match({
611
+ when: () => value() === 1,
612
+ children: createElement("div", [], [text("First")]),
613
+ }),
614
+ Match({
615
+ when: () => value() === 2,
616
+ children: createElement("div", [], [text("Second")]),
617
+ }),
618
+ ],
619
+ });
620
+
621
+ mount(container, node);
622
+ expect(container.textContent).toContain("First");
623
+
624
+ setValue(2);
625
+ expect(container.textContent).toContain("Second");
626
+
627
+ setValue(3);
628
+ expect(container.textContent).toContain("Fallback");
629
+ dispose();
630
+ });
631
+ });
632
+
633
+ test("Switch with accessor condition in Match", () => {
634
+ createRoot((dispose) => {
635
+ const [count, setCount] = createSignal(0);
636
+
637
+ const node = Switch({
638
+ fallback: createElement("div", [], [text("Default")]),
639
+ children: Match({
640
+ when: () => count() % 3 === 0 && count() > 0,
641
+ children: createElement("div", [], [text("Bang!")]),
642
+ }),
643
+ });
644
+
645
+ mount(container, node);
646
+ expect(container.textContent).toContain("Default");
647
+
648
+ setCount(3);
649
+ expect(container.textContent).toContain("Bang!");
650
+
651
+ setCount(4);
652
+ expect(container.textContent).toContain("Default");
653
+
654
+ setCount(6);
655
+ expect(container.textContent).toContain("Bang!");
656
+ dispose();
657
+ });
658
+ });
659
+ });
@@ -0,0 +1,64 @@
1
+ import { bench, describe } from "vitest";
2
+
3
+ // Generate HTML for list items
4
+ function generateListHTML(count: number): string {
5
+ let html = "<ul>";
6
+ for (let i = 0; i < count; i++) {
7
+ html += `<li>Item ${i}</li>`;
8
+ }
9
+ html += "</ul>";
10
+ return html;
11
+ }
12
+
13
+ // Generate DOM using createElement (like render_vnode_to_dom)
14
+ function createListDOM(count: number): Node {
15
+ const ul = document.createElement("ul");
16
+ for (let i = 0; i < count; i++) {
17
+ const li = document.createElement("li");
18
+ li.textContent = `Item ${i}`;
19
+ ul.appendChild(li);
20
+ }
21
+ return ul;
22
+ }
23
+
24
+ describe("Static Content: innerHTML vs createElement (Real Browser)", () => {
25
+ const html100 = generateListHTML(100);
26
+ const html500 = generateListHTML(500);
27
+ const html1000 = generateListHTML(1000);
28
+
29
+ describe("100 items", () => {
30
+ bench("createElement (render_vnode_to_dom style)", () => {
31
+ const container = document.createElement("div");
32
+ container.appendChild(createListDOM(100));
33
+ });
34
+
35
+ bench("innerHTML (inject_static style)", () => {
36
+ const container = document.createElement("div");
37
+ container.innerHTML = html100;
38
+ });
39
+ });
40
+
41
+ describe("500 items", () => {
42
+ bench("createElement (render_vnode_to_dom style)", () => {
43
+ const container = document.createElement("div");
44
+ container.appendChild(createListDOM(500));
45
+ });
46
+
47
+ bench("innerHTML (inject_static style)", () => {
48
+ const container = document.createElement("div");
49
+ container.innerHTML = html500;
50
+ });
51
+ });
52
+
53
+ describe("1000 items", () => {
54
+ bench("createElement (render_vnode_to_dom style)", () => {
55
+ const container = document.createElement("div");
56
+ container.appendChild(createListDOM(1000));
57
+ });
58
+
59
+ bench("innerHTML (inject_static style)", () => {
60
+ const container = document.createElement("div");
61
+ container.innerHTML = html1000;
62
+ });
63
+ });
64
+ });