@overmvp/kumi 0.0.0-stage → 0.1.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 (205) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +14 -2
  3. package/animation/color-transition.ts +196 -0
  4. package/animation/cycle.ts +151 -0
  5. package/animation/ease.ts +29 -0
  6. package/animation/index.ts +13 -0
  7. package/animation/package.json +12 -0
  8. package/animation/presets.ts +376 -0
  9. package/animation/spec.ts +197 -0
  10. package/builder/Cargo.lock +192 -0
  11. package/builder/Cargo.toml +7 -0
  12. package/builder/css-v1.mjs +334 -0
  13. package/builder/css-v1.test.mjs +321 -0
  14. package/builder/generated-output.mjs +61 -0
  15. package/builder/generated-output.test.mjs +132 -0
  16. package/builder/jsx-form.mjs +93 -0
  17. package/builder/jsx-form.test.mjs +48 -0
  18. package/builder/jsx-lists.mjs +209 -0
  19. package/builder/link-addon-package.mjs +86 -0
  20. package/builder/lua-assets.mjs +74 -0
  21. package/builder/lua-builtin-values.mjs +57 -0
  22. package/builder/lua-builtin-values.test.mjs +155 -0
  23. package/builder/lua-loop-closures.mjs +183 -0
  24. package/builder/lua-loop-closures.test.mjs +89 -0
  25. package/builder/lua-truthiness.mjs +61 -0
  26. package/builder/lua-truthiness.test.mjs +113 -0
  27. package/builder/module-declarations.mjs +594 -0
  28. package/builder/module-declarations.test.mjs +444 -0
  29. package/builder/native-kernels.mjs +60 -0
  30. package/builder/native-lua.d.ts +57 -0
  31. package/builder/native-routes.mjs +51 -0
  32. package/builder/no-static-ref-read.mjs +93 -0
  33. package/builder/no-static-ref-read.test.mjs +181 -0
  34. package/builder/secure-snippet.mjs +317 -0
  35. package/builder/secure-snippet.test.mjs +101 -0
  36. package/builder/shared-lua-runtime.mjs +150 -0
  37. package/builder/src/addon-link.lua +29 -0
  38. package/builder/src/arrays.lua +260 -0
  39. package/builder/src/assets.rs +177 -0
  40. package/builder/src/classes.lua +75 -0
  41. package/builder/src/collections.lua +190 -0
  42. package/builder/src/compiler.rs +2164 -0
  43. package/builder/src/config.rs +42 -0
  44. package/builder/src/entries.rs +166 -0
  45. package/builder/src/errors.lua +15 -0
  46. package/builder/src/lua_data.rs +231 -0
  47. package/builder/src/main.rs +367 -0
  48. package/builder/src/native_ir.rs +65 -0
  49. package/builder/src/native_signal.rs +47 -0
  50. package/builder/src/numbers.lua +62 -0
  51. package/builder/src/project-front.mjs +3331 -0
  52. package/builder/src/records.lua +75 -0
  53. package/builder/src/routes.rs +127 -0
  54. package/builder/src/signal-kernel.fingerprint +1 -0
  55. package/builder/src/strings.lua +103 -0
  56. package/builder/src/ts-lower.mjs +68 -0
  57. package/builder/src/wow_client.rs +253 -0
  58. package/builder/src/wow_types.rs +564 -0
  59. package/builder/style-states.mjs +100 -0
  60. package/builder/style-states.test.mjs +103 -0
  61. package/builder/vite-assets.mjs +53 -0
  62. package/builder/vite-project.mjs +10 -0
  63. package/config.ts +17 -0
  64. package/form/index.ts +522 -0
  65. package/form/package.json +13 -0
  66. package/motion/index.ts +2 -0
  67. package/motion/package.json +10 -0
  68. package/package.json +22 -4
  69. package/router/index.ts +43 -0
  70. package/router/package.json +12 -0
  71. package/router/routes.ts +64 -0
  72. package/scripts/kumi-cli.mjs +70 -0
  73. package/scripts/link-addons.mjs +51 -0
  74. package/src/bindings.ts +35 -0
  75. package/src/context.ts +15 -0
  76. package/src/css-tokens.ts +234 -0
  77. package/src/css-v1.ts +58 -0
  78. package/src/cvars.ts +91 -0
  79. package/src/element-node.ts +32 -0
  80. package/src/elements.ts +479 -0
  81. package/src/feature-scope.ts +82 -0
  82. package/src/flex-layout.ts +807 -0
  83. package/src/frame-scheduler.ts +334 -0
  84. package/src/grid-tracks.ts +165 -0
  85. package/src/image-imports.d.ts +24 -0
  86. package/src/images.ts +79 -0
  87. package/src/index.ts +28 -0
  88. package/src/jsx-dev-runtime.ts +2 -0
  89. package/src/jsx-runtime.ts +22 -0
  90. package/src/jsx.d.ts +12 -0
  91. package/src/keyed-list.ts +363 -0
  92. package/src/media-query.ts +144 -0
  93. package/src/module.ts +277 -0
  94. package/src/node-selectors.ts +114 -0
  95. package/src/owned-collections.ts +44 -0
  96. package/src/providers.ts +235 -0
  97. package/src/reactive-scope.ts +34 -0
  98. package/src/reactivity.ts +254 -0
  99. package/src/result.ts +58 -0
  100. package/src/runtime.ts +52 -0
  101. package/src/scheduler.ts +185 -0
  102. package/src/signal-kernel.ts +30 -0
  103. package/src/style-classes.ts +51 -0
  104. package/src/style-states.ts +134 -0
  105. package/src/style-variables.ts +53 -0
  106. package/src/text-children.ts +42 -0
  107. package/src/theme.ts +50 -0
  108. package/src/transition.ts +18 -0
  109. package/state/index.ts +3 -0
  110. package/state/package.json +12 -0
  111. package/state/store-bindings.ts +25 -0
  112. package/state/store.ts +82 -0
  113. package/styles/_layers.scss +14 -0
  114. package/templates/addon/README.md +14 -0
  115. package/templates/addon/__ADDON_NAME__.toc +4 -0
  116. package/templates/addon/eslint.config.mjs +12 -0
  117. package/templates/addon/gitignore +8 -0
  118. package/templates/addon/package.json +21 -0
  119. package/templates/addon/scripts/build.mjs +25 -0
  120. package/templates/addon/src/app/main.tsx +13 -0
  121. package/templates/addon/tsconfig.json +24 -0
  122. package/translate/index.ts +14 -0
  123. package/translate/package.json +9 -0
  124. package/utils/colors.ts +76 -0
  125. package/utils/format.ts +37 -0
  126. package/utils/index.ts +4 -0
  127. package/utils/number.ts +17 -0
  128. package/utils/package.json +7 -0
  129. package/utils/text.ts +6 -0
  130. package/validate/index.ts +119 -0
  131. package/validate/package.json +9 -0
  132. package/wow/absolute-position.ts +142 -0
  133. package/wow/animation.ts +428 -0
  134. package/wow/aura-button.ts +76 -0
  135. package/wow/aura-container.ts +591 -0
  136. package/wow/aura-countdown.ts +201 -0
  137. package/wow/aura-slot.ts +153 -0
  138. package/wow/bar-shade.ts +93 -0
  139. package/wow/borrowed-slot.ts +216 -0
  140. package/wow/button-drag.ts +48 -0
  141. package/wow/cast-clock.ts +153 -0
  142. package/wow/cast-text.ts +83 -0
  143. package/wow/class-colors.ts +126 -0
  144. package/wow/clock.ts +7 -0
  145. package/wow/color-picker.ts +128 -0
  146. package/wow/commands.ts +17 -0
  147. package/wow/contained-frame.ts +128 -0
  148. package/wow/contract.ts +42 -0
  149. package/wow/css-box.ts +110 -0
  150. package/wow/css-color.ts +12 -0
  151. package/wow/css-style.ts +109 -0
  152. package/wow/css-surfaces.ts +398 -0
  153. package/wow/css-text.ts +399 -0
  154. package/wow/cvar-schema.ts +32 -0
  155. package/wow/cvars.ts +98 -0
  156. package/wow/dropdown-art.ts +39 -0
  157. package/wow/element-click.ts +20 -0
  158. package/wow/element-event-coordinator.ts +219 -0
  159. package/wow/element-events.ts +317 -0
  160. package/wow/event-dispatcher.ts +151 -0
  161. package/wow/events.ts +50 -0
  162. package/wow/font-cache.ts +92 -0
  163. package/wow/frame-access.ts +31 -0
  164. package/wow/frame-layer.ts +5 -0
  165. package/wow/frames.ts +236 -0
  166. package/wow/heal-prediction.ts +305 -0
  167. package/wow/image-layers.ts +55 -0
  168. package/wow/index.ts +97 -0
  169. package/wow/layout-view.ts +651 -0
  170. package/wow/lua-string.ts +18 -0
  171. package/wow/lua-table.ts +18 -0
  172. package/wow/macro-book.ts +84 -0
  173. package/wow/map-position.ts +27 -0
  174. package/wow/media-query.ts +65 -0
  175. package/wow/module-events.ts +11 -0
  176. package/wow/native-hooks.ts +168 -0
  177. package/wow/native-placement.ts +88 -0
  178. package/wow/native.ts +135 -0
  179. package/wow/number-format.ts +8 -0
  180. package/wow/number-input.ts +10 -0
  181. package/wow/protect.ts +24 -0
  182. package/wow/protected-layout.ts +133 -0
  183. package/wow/range-art.ts +74 -0
  184. package/wow/reparent-frame.ts +99 -0
  185. package/wow/rounded-texture.ts +156 -0
  186. package/wow/saved-variables.ts +60 -0
  187. package/wow/scroll-view.ts +64 -0
  188. package/wow/secret-ref.ts +14 -0
  189. package/wow/secure-bindings.ts +89 -0
  190. package/wow/secure-clicks.ts +432 -0
  191. package/wow/secure-snippet.ts +235 -0
  192. package/wow/secure-state.ts +130 -0
  193. package/wow/secure-target-visibility.ts +89 -0
  194. package/wow/secure-transaction.ts +331 -0
  195. package/wow/special-window.ts +269 -0
  196. package/wow/start-addon.ts +99 -0
  197. package/wow/state-paint.ts +256 -0
  198. package/wow/transition.ts +86 -0
  199. package/wow/unit-button.ts +39 -0
  200. package/wow/unit-cast.ts +92 -0
  201. package/wow/unit-health-text.ts +47 -0
  202. package/wow/view-nodes.ts +304 -0
  203. package/wow/view.ts +1746 -0
  204. package/wow/visible-frame-job.ts +34 -0
  205. package/wow/width-reserve.ts +108 -0
@@ -0,0 +1,192 @@
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 4
4
+
5
+ [[package]]
6
+ name = "adler2"
7
+ version = "2.0.1"
8
+ source = "registry+https://github.com/rust-lang/crates.io-index"
9
+ checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
10
+
11
+ [[package]]
12
+ name = "autocfg"
13
+ version = "1.5.1"
14
+ source = "registry+https://github.com/rust-lang/crates.io-index"
15
+ checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
16
+
17
+ [[package]]
18
+ name = "bitflags"
19
+ version = "2.13.2"
20
+ source = "registry+https://github.com/rust-lang/crates.io-index"
21
+ checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06"
22
+
23
+ [[package]]
24
+ name = "bytemuck"
25
+ version = "1.25.2"
26
+ source = "registry+https://github.com/rust-lang/crates.io-index"
27
+ checksum = "95832e849adfb21180ccb6826a99da14e5d266ae5c2e668e1602cf234f153797"
28
+
29
+ [[package]]
30
+ name = "byteorder-lite"
31
+ version = "0.1.0"
32
+ source = "registry+https://github.com/rust-lang/crates.io-index"
33
+ checksum = "8f1fe948ff07f4bd06c30984e69f5b4899c516a3ef74f34df92a2df2ab535495"
34
+
35
+ [[package]]
36
+ name = "cfg-if"
37
+ version = "1.0.5"
38
+ source = "registry+https://github.com/rust-lang/crates.io-index"
39
+ checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"
40
+
41
+ [[package]]
42
+ name = "crc32fast"
43
+ version = "1.5.5"
44
+ source = "registry+https://github.com/rust-lang/crates.io-index"
45
+ checksum = "2b929dd2a135771f40afabd1073f85eed59c800b7c61901e5c254270497dad64"
46
+ dependencies = [
47
+ "cfg-if",
48
+ ]
49
+
50
+ [[package]]
51
+ name = "fdeflate"
52
+ version = "0.3.7"
53
+ source = "registry+https://github.com/rust-lang/crates.io-index"
54
+ checksum = "1e6853b52649d4ac5c0bd02320cddc5ba956bdb407c4b75a2c6b75bf51500f8c"
55
+ dependencies = [
56
+ "simd-adler32",
57
+ ]
58
+
59
+ [[package]]
60
+ name = "flate2"
61
+ version = "1.1.11"
62
+ source = "registry+https://github.com/rust-lang/crates.io-index"
63
+ checksum = "626d4928326b646e70f65ed36fc7cf9f206bdb68a0019ee7c6b4709da4e084c4"
64
+ dependencies = [
65
+ "crc32fast",
66
+ "miniz_oxide 0.9.1",
67
+ "zlib-rs",
68
+ ]
69
+
70
+ [[package]]
71
+ name = "image"
72
+ version = "0.25.10"
73
+ source = "registry+https://github.com/rust-lang/crates.io-index"
74
+ checksum = "85ab80394333c02fe689eaf900ab500fbd0c2213da414687ebf995a65d5a6104"
75
+ dependencies = [
76
+ "bytemuck",
77
+ "byteorder-lite",
78
+ "image-webp",
79
+ "moxcms",
80
+ "num-traits",
81
+ "png",
82
+ "zune-core",
83
+ "zune-jpeg",
84
+ ]
85
+
86
+ [[package]]
87
+ name = "image-webp"
88
+ version = "0.2.4"
89
+ source = "registry+https://github.com/rust-lang/crates.io-index"
90
+ checksum = "525e9ff3e1a4be2fbea1fdf0e98686a6d98b4d8f937e1bf7402245af1909e8c3"
91
+ dependencies = [
92
+ "byteorder-lite",
93
+ "quick-error",
94
+ ]
95
+
96
+ [[package]]
97
+ name = "kumi-pack"
98
+ version = "0.1.0"
99
+ dependencies = [
100
+ "image",
101
+ ]
102
+
103
+ [[package]]
104
+ name = "miniz_oxide"
105
+ version = "0.8.9"
106
+ source = "registry+https://github.com/rust-lang/crates.io-index"
107
+ checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316"
108
+ dependencies = [
109
+ "adler2",
110
+ "simd-adler32",
111
+ ]
112
+
113
+ [[package]]
114
+ name = "miniz_oxide"
115
+ version = "0.9.1"
116
+ source = "registry+https://github.com/rust-lang/crates.io-index"
117
+ checksum = "b63fbc4a50860e98e7b2aa7804ded1db5cbc3aff9193adaff57a6931bf7c4b4c"
118
+ dependencies = [
119
+ "adler2",
120
+ "simd-adler32",
121
+ ]
122
+
123
+ [[package]]
124
+ name = "moxcms"
125
+ version = "0.8.1"
126
+ source = "registry+https://github.com/rust-lang/crates.io-index"
127
+ checksum = "bb85c154ba489f01b25c0d36ae69a87e4a1c73a72631fc6c0eb6dde34a73e44b"
128
+ dependencies = [
129
+ "num-traits",
130
+ "pxfm",
131
+ ]
132
+
133
+ [[package]]
134
+ name = "num-traits"
135
+ version = "0.2.19"
136
+ source = "registry+https://github.com/rust-lang/crates.io-index"
137
+ checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
138
+ dependencies = [
139
+ "autocfg",
140
+ ]
141
+
142
+ [[package]]
143
+ name = "png"
144
+ version = "0.18.1"
145
+ source = "registry+https://github.com/rust-lang/crates.io-index"
146
+ checksum = "60769b8b31b2a9f263dae2776c37b1b28ae246943cf719eb6946a1db05128a61"
147
+ dependencies = [
148
+ "bitflags",
149
+ "crc32fast",
150
+ "fdeflate",
151
+ "flate2",
152
+ "miniz_oxide 0.8.9",
153
+ ]
154
+
155
+ [[package]]
156
+ name = "pxfm"
157
+ version = "0.1.30"
158
+ source = "registry+https://github.com/rust-lang/crates.io-index"
159
+ checksum = "d55d956fa96f5ec02be2e13af0e20391a5aa83d6a074e3ad368959d0fab299ea"
160
+
161
+ [[package]]
162
+ name = "quick-error"
163
+ version = "2.0.1"
164
+ source = "registry+https://github.com/rust-lang/crates.io-index"
165
+ checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3"
166
+
167
+ [[package]]
168
+ name = "simd-adler32"
169
+ version = "0.3.10"
170
+ source = "registry+https://github.com/rust-lang/crates.io-index"
171
+ checksum = "3a219298ac11a56ea9a6d2120044824d6f01aeb034955e7af7bc16858527deea"
172
+
173
+ [[package]]
174
+ name = "zlib-rs"
175
+ version = "0.6.8"
176
+ source = "registry+https://github.com/rust-lang/crates.io-index"
177
+ checksum = "b268e58e7c693d7c271f93ffc4ba3b380412554231c85bf61ca7af91042a4112"
178
+
179
+ [[package]]
180
+ name = "zune-core"
181
+ version = "0.5.3"
182
+ source = "registry+https://github.com/rust-lang/crates.io-index"
183
+ checksum = "d56377fd46368984a170bc5aac5567e52ca5da874caa60bea39fcbca78fb658b"
184
+
185
+ [[package]]
186
+ name = "zune-jpeg"
187
+ version = "0.5.15"
188
+ source = "registry+https://github.com/rust-lang/crates.io-index"
189
+ checksum = "27bc9d5b815bc103f142aa054f561d9187d191692ec7c2d1e2b4737f8dbd7296"
190
+ dependencies = [
191
+ "zune-core",
192
+ ]
@@ -0,0 +1,7 @@
1
+ [package]
2
+ name = "kumi-pack"
3
+ version = "0.1.0"
4
+ edition = "2021"
5
+
6
+ [dependencies]
7
+ image = { version = "0.25", default-features = false, features = ["jpeg", "png", "tga", "webp"] }
@@ -0,0 +1,334 @@
1
+ import { parseStateDeclaration, parseStyleColor, supportsStateProperty } from "./style-states.mjs";
2
+
3
+ // These are the radii with shipped fill and outline textures.
4
+ export const cssRadii = Object.freeze([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12]);
5
+ export const cssFontWeights = Object.freeze([400, 600, 700]);
6
+
7
+ const sides = ["top", "right", "bottom", "left"];
8
+ const sidesByProperty = new Map(sides.flatMap((side, index) => [
9
+ ["margin-" + side, ["margin", index]], [side, [side]], ["border-" + side, ["border", side]],
10
+ ]));
11
+ const ordered = new Set(["margin", "border", "inset", ...sidesByProperty.keys()]);
12
+ const decimal = String.raw`(?:\d+(?:\.\d+)?|\.\d+)`;
13
+ const unitlessNumber = new RegExp(`^[+-]?${decimal}$`);
14
+ const pixels = new RegExp(`^[+-]?${decimal}px$`);
15
+ const variable = String.raw`var\(\s*(--[a-z][\w-]*)\s*\)`;
16
+ const reference = new RegExp(`^${variable}$`);
17
+ const arithmetic = new RegExp(`^calc\\(\\s*${variable}\\s+([+-])\\s+(${decimal})(px)?\\s*\\)$`);
18
+
19
+ function numberIn(value, unit) {
20
+ const length = unit === "px" && pixels.test(value);
21
+ if (!length && !unitlessNumber.test(value)) return;
22
+ const number = Number(length ? value.slice(0, -2) : value);
23
+ if (Number.isFinite(number) && (unit === "" || length || number === 0)) return number;
24
+ }
25
+
26
+ function numeric(kind, unit, accepts, values, alias) {
27
+ return {
28
+ kind, unit, values, accepts,
29
+ parse(value) {
30
+ const number = alias?.(value) ?? numberIn(value, unit);
31
+ if (number !== undefined && accepts(number)) return number;
32
+ },
33
+ };
34
+ }
35
+
36
+ const length = numeric("length", "px", value => value >= 0);
37
+ const signedLength = numeric("signedLength", "px", () => true);
38
+ const positiveLength = numeric("positiveLength", "px", value => value > 0);
39
+ const percent = new RegExp(`^${decimal}%$`);
40
+ // A size is auto, a length, or a percentage of the parent's content box (kept as "50%" for the layout solver).
41
+ const size = { ...length, kind: "size", parse: value => value === "auto" || percent.test(value) ? value : length.parse(value) };
42
+ const number = numeric("number", "", value => value >= 0);
43
+ const integer = numeric("integer", "", Number.isInteger);
44
+ const opacity = numeric("opacity", "", value => value >= 0 && value <= 1);
45
+ const columns = Array.from({ length: 10 }, (_, index) => index + 1);
46
+ const columnCount = numeric("integer", "", value => columns.includes(value), columns);
47
+ const color = { kind: "color", parse: parseStyleColor };
48
+ const image = {
49
+ kind: "backgroundImage",
50
+ parse(value) {
51
+ try { return parseStateDeclaration("background-image", value)[1]; }
52
+ catch { return undefined; }
53
+ },
54
+ };
55
+
56
+ const keywords = (...values) => ({ kind: "enum", values, parse: value => values.includes(value) ? value : undefined });
57
+ const alignment = ["flex-start", "center", "flex-end", "stretch"];
58
+ const scalarProperties = {
59
+ color: ["color", color],
60
+ "background-color": ["backgroundColor", color],
61
+ "background-image": ["backgroundImage", image],
62
+ opacity: ["opacity", opacity],
63
+ position: ["position", keywords("static", "relative", "absolute")],
64
+ width: ["width", size],
65
+ height: ["height", size],
66
+ "min-width": ["minWidth", length],
67
+ "max-width": ["maxWidth", length],
68
+ "min-height": ["minHeight", length],
69
+ "max-height": ["maxHeight", length],
70
+ "font-size": ["fontSize", positiveLength],
71
+ "text-align": ["textAlign", keywords("left", "center", "right")],
72
+ "text-transform": ["textTransform", keywords("none", "uppercase", "lowercase", "capitalize")],
73
+ "text-overflow": ["textOverflow", keywords("ellipsis")],
74
+ "white-space": ["whiteSpace", keywords("nowrap")],
75
+ display: ["display", keywords("block", "inline", "inline-block", "flex", "grid", "none")],
76
+ overflow: ["overflow", keywords("hidden", "scroll")],
77
+ gap: ["gap", length],
78
+ columns: ["columns", columnCount],
79
+ "max-scale": ["maxScale", number],
80
+ "z-index": ["zIndex", integer],
81
+ "flex-direction": ["flexDirection", keywords("row", "column")],
82
+ "flex-wrap": ["flexWrap", keywords("nowrap", "wrap")],
83
+ "justify-content": ["justifyContent", keywords("flex-start", "center", "flex-end", "space-between")],
84
+ "align-items": ["alignItems", keywords(...alignment, "start", "end")],
85
+ "align-self": ["alignSelf", keywords("auto", ...alignment)],
86
+ "flex-grow": ["flexGrow", number],
87
+ "flex-shrink": ["flexShrink", number],
88
+ "flex-basis": ["flexBasis", size],
89
+ "row-gap": ["rowGap", length],
90
+ "column-gap": ["columnGap", length],
91
+ "justify-items": ["justifyItems", keywords("start", "center", "end", "stretch")],
92
+ };
93
+
94
+ function pieces(source) {
95
+ const words = [];
96
+ let start = 0;
97
+ let quote;
98
+ let depth = 0;
99
+ for (let index = 0; index < source.length; index++) {
100
+ const char = source[index];
101
+ if (quote !== undefined) {
102
+ if (char === quote) quote = undefined;
103
+ } else if (char === '"' || char === "'") quote = char;
104
+ else if (char === "(") depth++;
105
+ else if (char === ")") {
106
+ if (--depth < 0) return [];
107
+ } else if (depth === 0 && /\s/.test(char)) {
108
+ if (index > start) words.push(source.slice(start, index));
109
+ start = index + 1;
110
+ }
111
+ }
112
+ if (depth !== 0 || quote !== undefined) return [];
113
+ if (source.length > start) words.push(source.slice(start));
114
+ return words;
115
+ }
116
+
117
+ function tokenValue(tokens, name) {
118
+ if (!tokens.has(name)) throw new Error(`Unknown token ${name}`);
119
+ return tokens.get(name).trim();
120
+ }
121
+
122
+ function bind(input, spec, tokens) {
123
+ const token = reference.exec(input)?.[1];
124
+ const calc = arithmetic.exec(input);
125
+ if (calc) {
126
+ const [, name, operation, amount, unit = ""] = calc;
127
+ const raw = tokenValue(tokens, name);
128
+ if (spec.unit === undefined || unit !== spec.unit) return;
129
+ const base = numberIn(raw, unit);
130
+ if (base === undefined) return;
131
+ const add = Number(amount) * (operation === "+" ? 1 : -1);
132
+ const value = base + add;
133
+ if (!Number.isFinite(value) || !spec.accepts(value)) return;
134
+ return { value, token: name, kind: spec.kind, add, values: spec.values };
135
+ }
136
+ const value = spec.parse(token === undefined ? input : tokenValue(tokens, token));
137
+ if (value === undefined) return;
138
+ return token === undefined || spec.kind === undefined ? { value } : { value, token, kind: spec.kind, values: spec.values };
139
+ }
140
+
141
+ function rectangle(values) {
142
+ const [top, right = top, bottom = top, left = right] = values;
143
+ return [top, right, bottom, left];
144
+ }
145
+
146
+ function readInsets(source, read) {
147
+ const words = pieces(source);
148
+ if (words.length < 1 || words.length > 4) return;
149
+ const resolved = words.map(read);
150
+ if (resolved.every(value => value !== undefined)) return resolved;
151
+ }
152
+
153
+ function readBorder(source, read) {
154
+ const words = pieces(source);
155
+ if (words.length < 2 || words.length > 3) return;
156
+ let width;
157
+ let paint;
158
+ let solid = false;
159
+ for (const word of words) {
160
+ if (width === undefined && (width = read(word, length)) !== undefined) continue;
161
+ if (paint === undefined && (paint = read(word, color)) !== undefined) continue;
162
+ if (!solid && read(word, solidKeyword) !== undefined) { solid = true; continue; }
163
+ return;
164
+ }
165
+ if (width !== undefined && paint !== undefined) return { width, color: paint };
166
+ }
167
+
168
+ const solidKeyword = keywords("solid");
169
+
170
+ function readShadow(source, read) {
171
+ const words = pieces(source);
172
+ if (words.length !== 3) return;
173
+ const colorLast = read(words[2], color);
174
+ const paint = colorLast ?? read(words[0], color);
175
+ const x = read(words[colorLast === undefined ? 1 : 0], signedLength);
176
+ const y = read(words[colorLast === undefined ? 2 : 1], signedLength);
177
+ if (paint !== undefined && x !== undefined && y !== undefined) return { x, y, color: paint };
178
+ }
179
+
180
+ function compound(source, kind, parse, keys, tokens) {
181
+ const token = reference.exec(source)?.[1];
182
+ if (token === undefined) return parse(source, (input, spec) => bind(input, spec, tokens));
183
+ const value = parse(tokenValue(tokens, token), (input, spec) => spec.parse(input));
184
+ if (value === undefined) return;
185
+ return Object.fromEntries(keys.map(part => [part, { value: value[part], token, kind, part }]));
186
+ }
187
+
188
+ function compileInsets(source, property, spec, tokens) {
189
+ const token = reference.exec(source)?.[1];
190
+ if (token === undefined) return readInsets(source, input => bind(input, spec, tokens));
191
+ const values = readInsets(tokenValue(tokens, token), input => spec.parse(input));
192
+ if (values === undefined) return;
193
+ if (property === "padding" && values.length === 1) return [{ value: values[0], token, kind: "padding" }];
194
+ return rectangle(values).map((value, part) => ({ value, token, kind: property === "padding" ? "padding" : "margin", part }));
195
+ }
196
+
197
+ function declarationError(declaration, message) {
198
+ return typeof declaration.error === "function" ? declaration.error(message) : new Error(message);
199
+ }
200
+
201
+ const weightAlias = value => value === "normal" ? 400 : value === "bold" ? 700 : undefined;
202
+
203
+ /** Compile PostCSS-style ordered {prop, value, error?} records to one native style or state paint. */
204
+ export function compileCssDeclarations(declarations, {
205
+ tokens = new Map(), legacyProperties = {}, radii = cssRadii, fontWeights = cssFontWeights, state = false, reactive = false,
206
+ } = {}) {
207
+ const allowedRadii = [...radii];
208
+ const allowedWeights = [...fontWeights];
209
+ const bounds = new Map();
210
+ const recipes = new Map();
211
+ const seen = new Set();
212
+ const output = {};
213
+
214
+ function write(path, resolved, live = true) {
215
+ let parent = output;
216
+ for (let index = 0; index < path.length - 1; index++) {
217
+ const key = path[index];
218
+ parent = parent[key] ??= typeof path[index + 1] === "number" ? [] : {};
219
+ }
220
+ const { value, token, kind, add, part, values } = resolved;
221
+ parent[path.at(-1)] = value;
222
+ const key = JSON.stringify(path);
223
+ if (live && token !== undefined) {
224
+ recipes.set(key, { path, token, kind, fallback: value, source: tokenValue(tokens, token),
225
+ ...(add === undefined ? {} : { add }), ...(part === undefined ? {} : { part }),
226
+ ...(values === undefined ? {} : { values }) });
227
+ } else recipes.delete(key);
228
+ }
229
+
230
+ function declare(property, source) {
231
+ if (state && property === "border-color") {
232
+ const resolved = bind(source, color, tokens);
233
+ if (resolved === undefined) return false;
234
+ write(["borderColor"], resolved);
235
+ return true;
236
+ }
237
+ const side = sidesByProperty.get(property);
238
+ if (property === "border" || side?.[0] === "border") {
239
+ const fields = compound(source, "border", readBorder, ["width", "color"], tokens);
240
+ if (fields === undefined) return false;
241
+ for (const edge of side ? [side[1]] : sides) {
242
+ write(["border", edge, "width"], fields.width);
243
+ write(["border", edge, "color"], fields.color);
244
+ }
245
+ return true;
246
+ }
247
+ if (property === "text-shadow") {
248
+ const fields = compound(source, "textShadow", readShadow, ["x", "y", "color"], tokens);
249
+ if (fields === undefined) return false;
250
+ for (const field of ["x", "y", "color"]) write(["textShadow", field], fields[field]);
251
+ return true;
252
+ }
253
+ if ((property === "margin" || side?.[0] === "margin") && /(^|\s)auto(\s|$)/.test(source.trim())) {
254
+ // `auto` margins: the numeric sides stay margins, the auto ones are flags that center an absolute box.
255
+ const words = source.trim().split(/\s+/);
256
+ if (side?.[0] === "margin" ? words.length !== 1 : words.length < 1 || words.length > 4) return false;
257
+ const flags = output.autoMargin ? [...output.autoMargin] : [false, false, false, false];
258
+ const parts = side?.[0] === "margin" ? [[side[1], words[0]]] : rectangle(words).map((word, index) => [index, word]);
259
+ for (const [index, word] of parts) {
260
+ if (word === "auto") {
261
+ flags[index] = true;
262
+ continue;
263
+ }
264
+ const resolved = bind(word, signedLength, tokens);
265
+ if (resolved === undefined) return false;
266
+ flags[index] = false;
267
+ output.margin ??= [0, 0, 0, 0];
268
+ write(["margin", index], resolved);
269
+ }
270
+ write(["autoMargin"], { value: flags }, false);
271
+ return true;
272
+ }
273
+ if (property === "margin" || property === "padding" || property === "inset") {
274
+ const values = compileInsets(source, property, property === "padding" ? length : signedLength, tokens);
275
+ if (values === undefined) return false;
276
+ if (property === "padding") {
277
+ if (values.length === 1) write(["padding"], values[0]);
278
+ else values.forEach((value, index) => write(["padding", index], value));
279
+ } else rectangle(values).forEach((value, index) => write(property === "inset" ? [sides[index]] : ["margin", index], value));
280
+ return true;
281
+ }
282
+ if (side) {
283
+ const resolved = bind(source, signedLength, tokens);
284
+ if (resolved === undefined) return false;
285
+ if (side[0] === "margin") output.margin ??= [0, 0, 0, 0];
286
+ write(side, resolved);
287
+ return true;
288
+ }
289
+
290
+ let entry;
291
+ if (property === "border-radius") {
292
+ entry = ["borderRadius", numeric("radius", "px", value => allowedRadii.includes(value), allowedRadii)];
293
+ } else if (property === "font-weight") {
294
+ entry = ["fontWeight", numeric("fontWeight", "", value => allowedWeights.includes(value), allowedWeights, weightAlias)];
295
+ } else if (Object.hasOwn(scalarProperties, property)) entry = scalarProperties[property];
296
+ else if (Object.hasOwn(legacyProperties, property)) {
297
+ const [key, parse] = legacyProperties[property];
298
+ const kind = property === "grid-column" ? "gridColumn" : property.startsWith("grid-template-") ? "gridTracks" : undefined;
299
+ entry = [key, { kind, parse }];
300
+ }
301
+ if (!entry) throw new Error(`Unsupported property ${property}`);
302
+ const [key, spec] = entry;
303
+ const resolved = bind(source, spec, tokens);
304
+ if (resolved === undefined) return false;
305
+ const { value, token } = resolved;
306
+ if ((key === "color" || key === "backgroundColor") && token !== undefined) write([key], { value: `var(${token}, ${value})` });
307
+ else write([key], resolved, key !== "overflow");
308
+ return true;
309
+ }
310
+
311
+ for (const declaration of declarations) {
312
+ const { prop } = declaration;
313
+ try {
314
+ if (state && !supportsStateProperty(prop)) throw new Error(`Unsupported property ${prop} in a style state`);
315
+ if (reactive && prop === "overflow") throw new Error("Overflow is fixed at mount");
316
+ if (seen.has(prop) && !ordered.has(prop)) throw new Error(`Duplicate property ${prop}`);
317
+ if (!declare(prop, declaration.value.trim())) {
318
+ const hint = prop === "border-radius" ? ` (allowed radii: ${allowedRadii.map(value => `${value}px`).join(", ")})`
319
+ : prop === "font-weight" ? ` (allowed weights: ${allowedWeights.join(", ")})` : "";
320
+ throw new Error(`Invalid value for ${prop}: ${declaration.value}${hint}`);
321
+ }
322
+ } catch (error) { throw declarationError(declaration, error.message); }
323
+ seen.add(prop);
324
+ if (/^(min|max)-(width|height)$/.test(prop)) bounds.set(prop, declaration);
325
+ }
326
+
327
+ for (const [axis, min, max] of [["width", output.minWidth, output.maxWidth], ["height", output.minHeight, output.maxHeight]]) {
328
+ if (min !== undefined && max !== undefined && min > max) {
329
+ throw declarationError(bounds.get(`max-${axis}`), `min-${axis} (${min}px) exceeds max-${axis} (${max}px)`);
330
+ }
331
+ }
332
+ if (recipes.size > 0) output.styleTokens = [...recipes.values()];
333
+ return output;
334
+ }