@overmvp/kumi 0.1.0 → 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 (201) hide show
  1. package/README.md +59 -6
  2. package/animation/index.ts +4 -0
  3. package/animation/motion-policy.ts +20 -0
  4. package/animation/slide.ts +61 -0
  5. package/animation/spring.ts +75 -0
  6. package/animation/staggered-reveal.ts +34 -0
  7. package/builder/css-gradients.mjs +74 -0
  8. package/builder/css-mask-assets.mjs +52 -0
  9. package/builder/css-mask-assets.test.mjs +31 -0
  10. package/builder/css-v1.mjs +127 -23
  11. package/builder/css-v1.test.mjs +82 -2
  12. package/builder/link-addon-package.mjs +47 -6
  13. package/builder/module-declarations.test.mjs +9 -18
  14. package/builder/native-kernels.mjs +1 -1
  15. package/builder/src/compiler.rs +205 -8
  16. package/builder/src/lua_upvalues.rs +641 -0
  17. package/builder/src/main.rs +20 -5
  18. package/builder/src/native_ir.rs +1 -1
  19. package/builder/src/native_signal.rs +46 -10
  20. package/builder/src/numbers.lua +14 -0
  21. package/builder/src/project-front.mjs +385 -34
  22. package/builder/src/routes.rs +11 -14
  23. package/builder/src/setup-store.lua +18 -0
  24. package/builder/src/signal-kernel.fingerprint +1 -1
  25. package/builder/src/ts-lower.mjs +2 -2
  26. package/builder/src/wow-reads.lua +22 -0
  27. package/builder/style-modules.mjs +111 -0
  28. package/builder/style-modules.test.mjs +24 -0
  29. package/builder/style-states.mjs +6 -4
  30. package/config.ts +56 -14
  31. package/eslint.mjs +74 -0
  32. package/form/index.ts +15 -11
  33. package/package.json +11 -7
  34. package/router/index.ts +10 -2
  35. package/router/link.tsx +32 -0
  36. package/router/navigation.ts +22 -0
  37. package/router/router-view.ts +134 -0
  38. package/scripts/addon-build.mjs +377 -0
  39. package/scripts/addon-project.mjs +89 -0
  40. package/scripts/kumi-cli.mjs +52 -17
  41. package/scripts/link-addons.mjs +12 -2
  42. package/src/bindings.ts +12 -6
  43. package/src/context.ts +31 -7
  44. package/src/css-tokens.ts +27 -13
  45. package/src/css-v1.ts +13 -0
  46. package/src/elements.ts +35 -0
  47. package/src/flex-layout.ts +26 -5
  48. package/src/frame-scheduler.ts +6 -2
  49. package/src/index.ts +2 -1
  50. package/src/jsx-runtime.ts +8 -1
  51. package/src/keyed-list.ts +17 -11
  52. package/src/module-ui.ts +163 -0
  53. package/src/module.ts +51 -8
  54. package/src/owned-collections.ts +8 -0
  55. package/src/providers.ts +7 -1
  56. package/src/reactive-scope.ts +3 -3
  57. package/src/reactivity.ts +42 -8
  58. package/src/result.ts +6 -0
  59. package/src/signal-kernel.ts +35 -2
  60. package/src/style-classes.ts +22 -1
  61. package/src/style-states.ts +13 -6
  62. package/state/index.ts +6 -0
  63. package/state/setup-store-persistence.ts +206 -0
  64. package/state/setup-store-view.ts +10 -0
  65. package/state/setup-store.ts +342 -0
  66. package/state/store.ts +2 -0
  67. package/templates/addon/.agents/skills/kumi-build-debug/SKILL.md +36 -0
  68. package/templates/addon/.agents/skills/kumi-feature/SKILL.md +50 -0
  69. package/templates/addon/.agents/skills/kumi-plugin/SKILL.md +36 -0
  70. package/templates/addon/.agents/skills/kumi-store/SKILL.md +47 -0
  71. package/templates/addon/.agents/skills/kumi-ui/SKILL.md +73 -0
  72. package/templates/addon/.agents/skills/kumi-wow-api/SKILL.md +30 -0
  73. package/templates/addon/.claude/skills/kumi-build-debug/SKILL.md +36 -0
  74. package/templates/addon/.claude/skills/kumi-feature/SKILL.md +50 -0
  75. package/templates/addon/.claude/skills/kumi-plugin/SKILL.md +36 -0
  76. package/templates/addon/.claude/skills/kumi-store/SKILL.md +47 -0
  77. package/templates/addon/.claude/skills/kumi-ui/SKILL.md +73 -0
  78. package/templates/addon/.claude/skills/kumi-wow-api/SKILL.md +30 -0
  79. package/templates/addon/AGENTS.md +34 -0
  80. package/templates/addon/Assets/Art/Corner10.tga +0 -0
  81. package/templates/addon/Assets/Art/Corner11.tga +0 -0
  82. package/templates/addon/Assets/Art/Corner12.tga +0 -0
  83. package/templates/addon/Assets/Art/Corner13.tga +0 -0
  84. package/templates/addon/Assets/Art/Corner14.tga +0 -0
  85. package/templates/addon/Assets/Art/Corner15.tga +0 -0
  86. package/templates/addon/Assets/Art/Corner16.tga +0 -0
  87. package/templates/addon/Assets/Art/Corner2.tga +0 -0
  88. package/templates/addon/Assets/Art/Corner3.tga +0 -0
  89. package/templates/addon/Assets/Art/Corner4.tga +0 -0
  90. package/templates/addon/Assets/Art/Corner5.tga +0 -0
  91. package/templates/addon/Assets/Art/Corner6.tga +0 -0
  92. package/templates/addon/Assets/Art/Corner7.tga +0 -0
  93. package/templates/addon/Assets/Art/Corner8.tga +0 -0
  94. package/templates/addon/Assets/Art/Corner9.tga +0 -0
  95. package/templates/addon/Assets/Art/Dot.tga +0 -0
  96. package/templates/addon/Assets/Art/Gear.tga +0 -0
  97. package/templates/addon/Assets/Art/Grip.tga +0 -0
  98. package/templates/addon/Assets/Art/Outline10.tga +0 -0
  99. package/templates/addon/Assets/Art/Outline12.tga +0 -0
  100. package/templates/addon/Assets/Art/Outline13.tga +0 -0
  101. package/templates/addon/Assets/Art/Outline14.tga +0 -0
  102. package/templates/addon/Assets/Art/Outline15.tga +0 -0
  103. package/templates/addon/Assets/Art/Outline2.tga +0 -0
  104. package/templates/addon/Assets/Art/Outline3.tga +0 -0
  105. package/templates/addon/Assets/Art/Outline5.tga +0 -0
  106. package/templates/addon/Assets/Art/Outline7.tga +0 -0
  107. package/templates/addon/Assets/Art/Outline9.tga +0 -0
  108. package/templates/addon/Assets/Art/Round11.tga +0 -0
  109. package/templates/addon/Assets/Art/Round11Border.tga +0 -0
  110. package/templates/addon/Assets/Art/Round4.tga +0 -0
  111. package/templates/addon/Assets/Art/Round4Border.tga +0 -0
  112. package/templates/addon/Assets/Art/Round6.tga +0 -0
  113. package/templates/addon/Assets/Art/Round6Border.tga +0 -0
  114. package/templates/addon/Assets/Art/Round8.tga +0 -0
  115. package/templates/addon/Assets/Art/Round8Border.tga +0 -0
  116. package/templates/addon/Assets/Art/Search.tga +0 -0
  117. package/templates/addon/CLAUDE.md +1 -0
  118. package/templates/addon/README.md +42 -7
  119. package/templates/addon/eslint.config.mjs +3 -9
  120. package/templates/addon/gitignore +1 -0
  121. package/templates/addon/kumi.config.ts +17 -0
  122. package/templates/addon/package.json +4 -5
  123. package/templates/addon/src/app/app.module.ts +18 -0
  124. package/templates/addon/src/app/commands.store.ts +11 -0
  125. package/templates/addon/src/app/layout/AppWindow.module.css +90 -0
  126. package/templates/addon/src/app/layout/AppWindow.tsx +32 -0
  127. package/templates/addon/src/app/main.ts +5 -0
  128. package/templates/addon/src/app/routes/(window)/home/page.tsx +8 -0
  129. package/templates/addon/src/app/routes/(window)/plugins/page.tsx +38 -0
  130. package/templates/addon/src/app/routes/(window)/settings/page.tsx +8 -0
  131. package/templates/addon/src/app/theme.ts +6 -0
  132. package/templates/addon/src/modules/greeting/api/player.api.ts +29 -0
  133. package/templates/addon/src/modules/greeting/greeting.module.ts +18 -0
  134. package/templates/addon/src/modules/greeting/model/greeting.store.ts +81 -0
  135. package/templates/addon/src/modules/greeting/services/greeting.service.ts +38 -0
  136. package/templates/addon/src/modules/greeting/ui/Greeting.module.css +103 -0
  137. package/templates/addon/src/modules/greeting/ui/GreetingCard.tsx +29 -0
  138. package/templates/addon/src/modules/greeting/widgets/GreetingHud.tsx +54 -0
  139. package/templates/addon/src/modules/greeting/widgets/GreetingOverview.tsx +18 -0
  140. package/templates/addon/src/modules/greeting/widgets/GreetingSettings.tsx +56 -0
  141. package/templates/addon/src/modules/playtime/api/clock.api.ts +6 -0
  142. package/templates/addon/src/modules/playtime/model/playtime.store.ts +19 -0
  143. package/templates/addon/src/modules/playtime/playtime.module.ts +18 -0
  144. package/templates/addon/src/modules/playtime/services/playtime.service.ts +18 -0
  145. package/templates/addon/src/modules/playtime/ui/Playtime.module.css +23 -0
  146. package/templates/addon/src/modules/playtime/ui/PlaytimeBadge.tsx +10 -0
  147. package/templates/addon/src/modules/playtime/widgets/PlaytimePage.tsx +16 -0
  148. package/templates/addon/src/shared/api/native-art.ts +28 -0
  149. package/templates/addon/src/shared/assets/close.png +0 -0
  150. package/templates/addon/src/shared/lib/format.ts +20 -0
  151. package/templates/addon/src/shared/styles/tokens.css +13 -0
  152. package/templates/addon/src/shared/ui/Button.tsx +29 -0
  153. package/templates/addon/src/shared/ui/Choice.tsx +34 -0
  154. package/templates/addon/src/shared/ui/Controls.module.css +91 -0
  155. package/templates/addon/src/shared/ui/Glyph.tsx +18 -0
  156. package/templates/addon/src/shared/ui/Slider.tsx +25 -0
  157. package/templates/addon/src/shared/ui/Toggle.tsx +29 -0
  158. package/templates/addon/src/shared/ui/focus-ref.ts +7 -0
  159. package/templates/addon/src/shared/ui/range-skin.tsx +15 -0
  160. package/templates/addon/tsconfig.json +49 -10
  161. package/wow/action-bar-layout.ts +108 -0
  162. package/wow/action-button.ts +244 -0
  163. package/wow/action-catalog.ts +98 -0
  164. package/wow/addon-manifest.ts +38 -0
  165. package/wow/animation.ts +3 -14
  166. package/wow/app-ui.ts +230 -0
  167. package/wow/cooldown-timing.ts +24 -0
  168. package/wow/css-background-image.ts +75 -0
  169. package/wow/css-box.ts +46 -10
  170. package/wow/css-image-mask.ts +32 -0
  171. package/wow/css-surfaces.ts +295 -43
  172. package/wow/cursor.ts +45 -0
  173. package/wow/element-events.ts +33 -13
  174. package/wow/frame-access.ts +23 -1
  175. package/wow/frame-timing.ts +13 -0
  176. package/wow/heal-prediction.ts +2 -4
  177. package/wow/hooks.ts +133 -0
  178. package/wow/index.ts +19 -4
  179. package/wow/layout-view.ts +44 -23
  180. package/wow/locale-font.ts +15 -0
  181. package/wow/module-replacements.ts +103 -0
  182. package/wow/native.ts +18 -0
  183. package/wow/panel-host.ts +97 -0
  184. package/wow/pixel.ts +35 -0
  185. package/wow/plugins.ts +246 -0
  186. package/wow/pointer-click.ts +35 -0
  187. package/wow/protect.ts +27 -3
  188. package/wow/protected-view.ts +139 -0
  189. package/wow/range-art.ts +7 -0
  190. package/wow/readable-api.ts +120 -0
  191. package/wow/rounded-texture.ts +38 -6
  192. package/wow/saved-variables.ts +67 -18
  193. package/wow/spell-cooldown.ts +36 -0
  194. package/wow/start-addon.ts +31 -8
  195. package/wow/state-paint.ts +5 -14
  196. package/wow/texture-fill.ts +10 -0
  197. package/wow/unit-cast.ts +6 -4
  198. package/wow/view.ts +458 -228
  199. package/templates/addon/__ADDON_NAME__.toc +0 -4
  200. package/templates/addon/scripts/build.mjs +0 -25
  201. package/templates/addon/src/app/main.tsx +0 -13
@@ -1,4 +1,5 @@
1
- import { parseStateDeclaration, parseStyleColor, supportsStateProperty } from "./style-states.mjs";
1
+ import { parseLinearGradient, parseMaskGradient } from "./css-gradients.mjs";
2
+ import { parseStateDeclaration, parseStyleColor, parseTexturePath, supportsStateProperty } from "./style-states.mjs";
2
3
 
3
4
  // These are the radii with shipped fill and outline textures.
4
5
  export const cssRadii = Object.freeze([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12]);
@@ -8,12 +9,15 @@ const sides = ["top", "right", "bottom", "left"];
8
9
  const sidesByProperty = new Map(sides.flatMap((side, index) => [
9
10
  ["margin-" + side, ["margin", index]], [side, [side]], ["border-" + side, ["border", side]],
10
11
  ]));
11
- const ordered = new Set(["margin", "border", "inset", ...sidesByProperty.keys()]);
12
+ // Longhand border parts: `border-width`, `border-color` and their per-side forms.
13
+ const borderParts = new Map([["border-width", ["width"]], ["border-color", ["color"]],
14
+ ...sides.flatMap(side => [["border-" + side + "-width", ["width", side]], ["border-" + side + "-color", ["color", side]]])]);
15
+ const ordered = new Set(["margin", "border", "inset", "border-style", ...borderParts.keys(), ...sidesByProperty.keys()]);
12
16
  const decimal = String.raw`(?:\d+(?:\.\d+)?|\.\d+)`;
13
17
  const unitlessNumber = new RegExp(`^[+-]?${decimal}$`);
14
18
  const pixels = new RegExp(`^[+-]?${decimal}px$`);
15
- const variable = String.raw`var\(\s*(--[a-z][\w-]*)\s*\)`;
16
- const reference = new RegExp(`^${variable}$`);
19
+ const variable = String.raw`var\(\s*(--[\w-]+)\s*\)`;
20
+ const reference = /^var\(\s*(--[\w-]+)\s*(?:,\s*([\s\S]+))?\)$/u;
17
21
  const arithmetic = new RegExp(`^calc\\(\\s*${variable}\\s+([+-])\\s+(${decimal})(px)?\\s*\\)$`);
18
22
 
19
23
  function numberIn(value, unit) {
@@ -39,12 +43,19 @@ const positiveLength = numeric("positiveLength", "px", value => value > 0);
39
43
  const percent = new RegExp(`^${decimal}%$`);
40
44
  // A size is auto, a length, or a percentage of the parent's content box (kept as "50%" for the layout solver).
41
45
  const size = { ...length, kind: "size", parse: value => value === "auto" || percent.test(value) ? value : length.parse(value) };
46
+ const width = { ...size, parse: value => ["fit-content", "min-content", "max-content"].includes(value) ? value : size.parse(value) };
42
47
  const number = numeric("number", "", value => value >= 0);
43
48
  const integer = numeric("integer", "", Number.isInteger);
44
49
  const opacity = numeric("opacity", "", value => value >= 0 && value <= 1);
45
50
  const columns = Array.from({ length: 10 }, (_, index) => index + 1);
46
51
  const columnCount = numeric("integer", "", value => columns.includes(value), columns);
47
52
  const color = { kind: "color", parse: parseStyleColor };
53
+ const gradientColor = { kind: "color", parse: value => {
54
+ if (value === "transparent") return "#00000000";
55
+ if (value === "black") return "#000000";
56
+ if (value === "white") return "#ffffff";
57
+ return parseStyleColor(value);
58
+ } };
48
59
  const image = {
49
60
  kind: "backgroundImage",
50
61
  parse(value) {
@@ -61,7 +72,7 @@ const scalarProperties = {
61
72
  "background-image": ["backgroundImage", image],
62
73
  opacity: ["opacity", opacity],
63
74
  position: ["position", keywords("static", "relative", "absolute")],
64
- width: ["width", size],
75
+ width: ["width", width],
65
76
  height: ["height", size],
66
77
  "min-width": ["minWidth", length],
67
78
  "max-width": ["maxWidth", length],
@@ -114,13 +125,29 @@ function pieces(source) {
114
125
  return words;
115
126
  }
116
127
 
117
- function tokenValue(tokens, name) {
118
- if (!tokens.has(name)) throw new Error(`Unknown token ${name}`);
119
- return tokens.get(name).trim();
128
+ function resolveToken(tokens, name, fallback, chain) {
129
+ const raw = chain.has(name) ? undefined : tokens.get(name)?.trim();
130
+ if (raw !== undefined) {
131
+ const alias = reference.exec(raw);
132
+ if (!alias) return raw;
133
+ chain.add(name);
134
+ const value = resolveToken(tokens, alias[1], alias[2], chain);
135
+ chain.delete(name);
136
+ if (value !== undefined) return value;
137
+ }
138
+ if (fallback === undefined) return;
139
+ const alias = reference.exec(fallback.trim());
140
+ return alias ? resolveToken(tokens, alias[1], alias[2], chain) : fallback.trim();
141
+ }
142
+
143
+ function tokenValue(tokens, name, fallback) {
144
+ const value = resolveToken(tokens, name, fallback, new Set());
145
+ if (value === undefined) throw new Error(`Unknown token ${name} or unresolved reference`);
146
+ return value;
120
147
  }
121
148
 
122
149
  function bind(input, spec, tokens) {
123
- const token = reference.exec(input)?.[1];
150
+ const [, token, fallback] = reference.exec(input) ?? [];
124
151
  const calc = arithmetic.exec(input);
125
152
  if (calc) {
126
153
  const [, name, operation, amount, unit = ""] = calc;
@@ -131,11 +158,13 @@ function bind(input, spec, tokens) {
131
158
  const add = Number(amount) * (operation === "+" ? 1 : -1);
132
159
  const value = base + add;
133
160
  if (!Number.isFinite(value) || !spec.accepts(value)) return;
134
- return { value, token: name, kind: spec.kind, add, values: spec.values };
161
+ return { value, token: name, source: raw, kind: spec.kind, add, values: spec.values };
135
162
  }
136
- const value = spec.parse(token === undefined ? input : tokenValue(tokens, token));
163
+ const source = token === undefined ? input : tokenValue(tokens, token, fallback);
164
+ const value = spec.parse(source);
137
165
  if (value === undefined) return;
138
- return token === undefined || spec.kind === undefined ? { value } : { value, token, kind: spec.kind, values: spec.values };
166
+ return token === undefined || spec.kind === undefined ? { value }
167
+ : { value, token, source, fallbackExpression: fallback?.trim(), kind: spec.kind, values: spec.values };
139
168
  }
140
169
 
141
170
  function rectangle(values) {
@@ -178,20 +207,25 @@ function readShadow(source, read) {
178
207
  }
179
208
 
180
209
  function compound(source, kind, parse, keys, tokens) {
181
- const token = reference.exec(source)?.[1];
210
+ const [, token, fallback] = reference.exec(source) ?? [];
182
211
  if (token === undefined) return parse(source, (input, spec) => bind(input, spec, tokens));
183
- const value = parse(tokenValue(tokens, token), (input, spec) => spec.parse(input));
212
+ const resolved = tokenValue(tokens, token, fallback);
213
+ const value = parse(resolved, (input, spec) => spec.parse(input));
184
214
  if (value === undefined) return;
185
- return Object.fromEntries(keys.map(part => [part, { value: value[part], token, kind, part }]));
215
+ return Object.fromEntries(keys.map(part => [part, {
216
+ value: value[part], token, source: resolved, fallbackExpression: fallback?.trim(), kind, part,
217
+ }]));
186
218
  }
187
219
 
188
220
  function compileInsets(source, property, spec, tokens) {
189
- const token = reference.exec(source)?.[1];
221
+ const [, token, fallback] = reference.exec(source) ?? [];
190
222
  if (token === undefined) return readInsets(source, input => bind(input, spec, tokens));
191
- const values = readInsets(tokenValue(tokens, token), input => spec.parse(input));
223
+ const resolved = tokenValue(tokens, token, fallback);
224
+ const values = readInsets(resolved, input => spec.parse(input));
192
225
  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 }));
226
+ const binding = { token, source: resolved, fallbackExpression: fallback?.trim(), kind: property === "padding" ? "padding" : "margin" };
227
+ if (property === "padding" && values.length === 1) return [{ ...binding, value: values[0] }];
228
+ return rectangle(values).map((value, part) => ({ ...binding, value, part }));
195
229
  }
196
230
 
197
231
  function declarationError(declaration, message) {
@@ -217,17 +251,35 @@ export function compileCssDeclarations(declarations, {
217
251
  const key = path[index];
218
252
  parent = parent[key] ??= typeof path[index + 1] === "number" ? [] : {};
219
253
  }
220
- const { value, token, kind, add, part, values } = resolved;
254
+ const { value, token, source, fallbackExpression, kind, add, part, values } = resolved;
221
255
  parent[path.at(-1)] = value;
222
256
  const key = JSON.stringify(path);
223
257
  if (live && token !== undefined) {
224
- recipes.set(key, { path, token, kind, fallback: value, source: tokenValue(tokens, token),
258
+ recipes.set(key, { path, token, kind, fallback: value, source,
259
+ ...(fallbackExpression === undefined ? {} : { fallbackExpression }),
225
260
  ...(add === undefined ? {} : { add }), ...(part === undefined ? {} : { part }),
226
261
  ...(values === undefined ? {} : { values }) });
227
262
  } else recipes.delete(key);
228
263
  }
229
264
 
230
265
  function declare(property, source) {
266
+ if (property === "mask-image") {
267
+ const value = parseTexturePath(source) ?? parseMaskGradient(source, input => gradientColor.parse(input));
268
+ if (value === undefined) return false;
269
+ write(["maskImage"], { value });
270
+ return true;
271
+ }
272
+ if (property === "background-image" && source.startsWith("linear-gradient(")) {
273
+ const value = parseLinearGradient(source, input => {
274
+ const stop = bind(input, gradientColor, tokens);
275
+ if (stop === undefined) return;
276
+ if (stop.token === undefined) return stop.value;
277
+ return `var(${stop.token}, ${stop.fallbackExpression ?? stop.value})`;
278
+ });
279
+ if (value === undefined) return false;
280
+ write(["backgroundImage"], { value });
281
+ return true;
282
+ }
231
283
  if (state && property === "border-color") {
232
284
  const resolved = bind(source, color, tokens);
233
285
  if (resolved === undefined) return false;
@@ -235,6 +287,29 @@ export function compileCssDeclarations(declarations, {
235
287
  return true;
236
288
  }
237
289
  const side = sidesByProperty.get(property);
290
+ if ((property === "border" || side?.[0] === "border") && /^(none|0|0px)$/u.test(source)
291
+ || property === "border-style" && source === "none") {
292
+ // No border: zero widths need no color, and they replace a border from an earlier class.
293
+ for (const edge of side ? [side[1]] : sides) {
294
+ write(["border", edge, "width"], { value: 0 }, false);
295
+ if (output.border[edge].color !== undefined) delete output.border[edge].color;
296
+ recipes.delete(JSON.stringify(["border", edge, "color"]));
297
+ }
298
+ return true;
299
+ }
300
+ if (property === "border-style") return source === "solid";
301
+ const part = borderParts.get(property);
302
+ if (part !== undefined) {
303
+ const [field, edge] = part;
304
+ const spec = field === "width" ? length : color;
305
+ const words = edge === undefined ? pieces(source) : [source];
306
+ if (words.length < 1 || words.length > 4) return false;
307
+ const values = words.map(word => bind(word, spec, tokens));
308
+ if (values.some(value => value === undefined)) return false;
309
+ if (edge !== undefined) write(["border", edge, field], values[0]);
310
+ else rectangle(values).forEach((value, index) => write(["border", sides[index], field], value));
311
+ return true;
312
+ }
238
313
  if (property === "border" || side?.[0] === "border") {
239
314
  const fields = compound(source, "border", readBorder, ["width", "color"], tokens);
240
315
  if (fields === undefined) return false;
@@ -302,14 +377,18 @@ export function compileCssDeclarations(declarations, {
302
377
  const [key, spec] = entry;
303
378
  const resolved = bind(source, spec, tokens);
304
379
  if (resolved === undefined) return false;
305
- const { value, token } = resolved;
306
- if ((key === "color" || key === "backgroundColor") && token !== undefined) write([key], { value: `var(${token}, ${value})` });
380
+ const { value, token, fallbackExpression } = resolved;
381
+ if ((key === "color" || key === "backgroundColor") && token !== undefined) {
382
+ write([key], { value: `var(${token}, ${fallbackExpression ?? value})` });
383
+ }
307
384
  else write([key], resolved, key !== "overflow");
308
385
  return true;
309
386
  }
310
387
 
388
+ let borderDeclaration;
311
389
  for (const declaration of declarations) {
312
390
  const { prop } = declaration;
391
+ if (prop.startsWith("border") && prop !== "border-radius") borderDeclaration = declaration;
313
392
  try {
314
393
  if (state && !supportsStateProperty(prop)) throw new Error(`Unsupported property ${prop} in a style state`);
315
394
  if (reactive && prop === "overflow") throw new Error("Overflow is fixed at mount");
@@ -329,6 +408,31 @@ export function compileCssDeclarations(declarations, {
329
408
  throw declarationError(bounds.get(`max-${axis}`), `min-${axis} (${min}px) exceeds max-${axis} (${max}px)`);
330
409
  }
331
410
  }
411
+ const border = output.border;
412
+ if (border !== undefined && !state) {
413
+ for (const side of sides) {
414
+ const edge = border[side];
415
+ if (edge === undefined) continue;
416
+ if (edge.width === undefined) {
417
+ throw declarationError(borderDeclaration, `border-${side}-color needs a width in the same rule. Use the border shorthand or add border-width`);
418
+ }
419
+ if (edge.width > 0 && edge.color === undefined) {
420
+ throw declarationError(borderDeclaration, `border-${side}-width needs a color in the same rule. Use the border shorthand or add border-color`);
421
+ }
422
+ }
423
+ }
424
+ const top = border?.top;
425
+ if (top?.width > 0 && sides.every(side => {
426
+ const edge = border[side];
427
+ return edge?.width === top.width && edge.color === top.color
428
+ && !recipes.has(JSON.stringify(["border", side, "width"]))
429
+ && !recipes.has(JSON.stringify(["border", side, "color"]));
430
+ })) {
431
+ const { width, color: literal } = top;
432
+ const rgba = [1, 3, 5].map(offset => Number.parseInt(literal.slice(offset, offset + 2), 16) / 255);
433
+ rgba.push(literal.length === 9 ? Number.parseInt(literal.slice(7, 9), 16) / 255 : 1);
434
+ output.borderPaint = { width, literal, rgba };
435
+ }
332
436
  if (recipes.size > 0) output.styleTokens = [...recipes.values()];
333
437
  return output;
334
438
  }
@@ -51,6 +51,16 @@ test("validates minimum and maximum width and height, including reversed ranges"
51
51
  ]), /^SyntaxError: panel\.css:7 min-height .* exceeds max-height/);
52
52
  });
53
53
 
54
+ test("accepts intrinsic widths alongside limits and CSS variable fallbacks", () => {
55
+ for (const width of ["fit-content", "min-content", "max-content"]) {
56
+ assert.deepEqual(compile([["width", width], ["min-width", "64px"], ["max-width", "200px"]]), {
57
+ width, minWidth: 64, maxWidth: 200,
58
+ });
59
+ }
60
+ assert.equal(single("width", "var(--control-width, fit-content)").width, "fit-content");
61
+ assert.deepEqual(single("width", "104px"), { width: 104 });
62
+ });
63
+
54
64
  test("compiles absolute position, inset shorthand and the individual bounds in declaration order", () => {
55
65
  assert.deepEqual(compile([
56
66
  ["position", "absolute"], ["left", "9px"], ["inset", "1px -2px 3px"], ["top", "0"], ["left", "4px"],
@@ -84,6 +94,46 @@ test("compiles width and color for each border without losing declaration order"
84
94
  ]) assert.throws(() => single("border", value), /Invalid value for border/, value);
85
95
  });
86
96
 
97
+ test("compiles border-width, border-color and their per-side forms", () => {
98
+ const line = { width: 1, color: "#405168" };
99
+ assert.deepEqual(compile([["border", "1px solid #405168"], ["border-width", "0 0 2px"]]), {
100
+ border: { top: { width: 0, color: "#405168" }, right: { width: 0, color: "#405168" },
101
+ bottom: { width: 2, color: "#405168" }, left: { width: 0, color: "#405168" } },
102
+ });
103
+ assert.deepEqual(compile([["border-width", "1px"], ["border-color", "#405168"]]).border, { top: line, right: line, bottom: line, left: line });
104
+ assert.deepEqual(compile([["border", "1px solid #405168"], ["border-top-width", "3px"], ["border-left-color", "#efbf68"]]).border, {
105
+ top: { width: 3, color: "#405168" }, right: line, bottom: line, left: { width: 1, color: "#efbf68" },
106
+ });
107
+ assert.deepEqual(compile([["border-width", "1px 2px"], ["border-color", "#111111 #222222 #333333 #444444"]]).border, {
108
+ top: { width: 1, color: "#111111" }, right: { width: 2, color: "#222222" },
109
+ bottom: { width: 1, color: "#333333" }, left: { width: 2, color: "#444444" },
110
+ });
111
+ const none = { top: { width: 0 }, right: { width: 0 }, bottom: { width: 0 }, left: { width: 0 } };
112
+ for (const [property, value] of [["border", "none"], ["border", "0"], ["border-width", "0"], ["border-style", "none"]]) {
113
+ assert.deepEqual(single(property, value).border, none, property + ": " + value);
114
+ }
115
+ assert.deepEqual(compile([["border", "1px solid #405168"], ["border", "none"]]).border, none);
116
+ assert.equal(single("border-style", "solid").border, undefined);
117
+ assert.throws(() => single("border-width", "2px"), /border-top-width needs a color/);
118
+ assert.throws(() => single("border-color", "#405168"), /border-top-color needs a width/);
119
+ assert.throws(() => single("border-width", "1px 2px 3px 4px 5px"), /Invalid value for border-width/);
120
+ assert.throws(() => single("border-style", "dashed"), /Invalid value for border-style/);
121
+ });
122
+
123
+ test("prepares uniform literal border paint from the final ordered declarations", () => {
124
+ const border = ["border", "1px solid rgba(64, 128, 255, 0.5)"];
125
+ const dynamic = ["border-left", "var(--edge)"];
126
+ const options = { tokens: new Map([["--edge", "1px #4080ff80"]]) };
127
+ const plan = { width: 1, literal: "#4080ff80", rgba: [64 / 255, 128 / 255, 1, 128 / 255] };
128
+
129
+ assert.deepEqual(compile([border, ["border-radius", "6px"]]).borderPaint, plan);
130
+ assert.deepEqual(compile([dynamic, border], options).borderPaint, plan);
131
+ assert.equal(compile([border, dynamic], options).borderPaint, undefined);
132
+ assert.equal(compile([border, ["border-top", "2px #4080ff80"]]).borderPaint, undefined);
133
+ assert.equal(compile([border, ["border-top", "1px #ffffff"]]).borderPaint, undefined);
134
+ assert.equal(single("border", "0 #ffffff").borderPaint, undefined);
135
+ });
136
+
87
137
  test("validates exact registered radii and permits an explicit host registry", () => {
88
138
  assert.deepEqual(cssRadii, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12]);
89
139
  for (const radius of cssRadii) assert.deepEqual(single("border-radius", radius + "px"), { borderRadius: radius });
@@ -109,11 +159,41 @@ test("accepts a single quoted local URL or atlas using the same grammar in base
109
159
  'url("textures/../tab.tga")', 'url("textures/%2e%2e/tab.tga")', 'url("textures\\..\\tab.tga")',
110
160
  'url("textures//tab.tga")', 'url("tab.tga?query")', 'url("tab.tga#fragment")', 'url("tab.tga"), atlas(other)',
111
161
  'url("tab.tga") center', 'url("")', "url(tab.tga)", "atlas()", 'atlas("x/y")', 'atlas("x y")',
112
- "linear-gradient(#123456, #ffffff)", "none",
162
+ "linear-gradient(45deg, #123456, #ffffff)", "none",
113
163
  ]) assert.throws(() => single("background-image", value, { state }), /Invalid value for background-image/, value);
114
164
  }
115
165
  });
116
166
 
167
+ test("compiles cardinal background gradients with live color stop variables", () => {
168
+ const tokens = new Map([["--ink", "#a10020"]]);
169
+ for (const state of [false, true]) {
170
+ assert.deepEqual(single("background-image", "linear-gradient(to right, var(--ink), rgba(0, 0, 0, 0))", { state, tokens }), {
171
+ backgroundImage: { gradient: { axis: "HORIZONTAL", min: "var(--ink, #a10020)", max: "#00000000" } },
172
+ });
173
+ }
174
+ assert.deepEqual(single("background-image", "linear-gradient(black, white)"), {
175
+ backgroundImage: { gradient: { axis: "VERTICAL", min: "#ffffff", max: "#000000" } },
176
+ });
177
+ for (const source of ["linear-gradient(black)", "linear-gradient(black, white, black)",
178
+ "linear-gradient(black 25%, white)", "linear-gradient(var(--missing), white)"]) {
179
+ assert.throws(() => single("background-image", source), /Invalid value for|Unknown token/);
180
+ }
181
+ });
182
+
183
+ test("compiles static alpha masks with CSS percentage stop placement", () => {
184
+ assert.deepEqual(single("mask-image", 'url("Assets/Art/Moon.tga")'), { maskImage: { path: "Assets/Art/Moon.tga" } });
185
+ assert.deepEqual(single("mask-image", "linear-gradient(to bottom, transparent, black 22%, white, black 86%, transparent)"), {
186
+ maskImage: { gradient: { axis: "VERTICAL", reverse: true, stops: [
187
+ { position: 0, alpha: 0 }, { position: 0.22, alpha: 255 }, { position: 0.54, alpha: 255 },
188
+ { position: 0.86, alpha: 255 }, { position: 1, alpha: 0 },
189
+ ] } },
190
+ });
191
+ for (const source of ['url("../outside.tga")', "linear-gradient(black 120%, white)", "linear-gradient(black)", "atlas(Moon)"]) {
192
+ assert.throws(() => single("mask-image", source), /Invalid value for mask-image/);
193
+ }
194
+ assert.throws(() => single("mask-image", 'url("Moon.tga")', { state: true }), /Unsupported property mask-image/);
195
+ });
196
+
117
197
  test("validates typography properties and registered font weights", () => {
118
198
  assert.deepEqual(compile([
119
199
  ["font-size", "13.5px"], ["font-weight", "600"], ["text-align", "center"],
@@ -272,7 +352,7 @@ test("checks typed token defaults and restricted calc operands and results", ()
272
352
  ["width", "calc(var(--space) * 2px)"], ["width", "calc(var(--space) + var(--space))"],
273
353
  ["width", "calc(var(--space) + 2px - 2px)"], ["width", "calc(var(--space)+2px)"],
274
354
  ["width", "calc(2px + var(--space))"], ["width", "calc(calc(var(--space) + 2px) + 2px)"],
275
- ["width", "var(--space, 5px)"], ["width", "var(--space)px"], ["color", "calc(var(--ink) + 2)"],
355
+ ["width", "var(--missing, #123456)"], ["width", "var(--space)px"], ["color", "calc(var(--ink) + 2)"],
276
356
  ["border-radius", "calc(var(--round) + 0px)"], ["opacity", "calc(var(--number) + .75)"],
277
357
  ]) assert.throws(() => single(prop, value, options), /Invalid value for/, prop + " " + value);
278
358
  for (const [prop, value] of [
@@ -30,6 +30,18 @@ function readFragment(path, packet) {
30
30
  return { header, prelude, footer, modules };
31
31
  }
32
32
 
33
+ // Fragment keys use the Rust backend's Lua string encoding.
34
+ function moduleKeyLiteral(key) {
35
+ let literal = '"';
36
+ for (const character of key) {
37
+ const code = character.codePointAt(0);
38
+ if (code < 32 || code === 127) literal += "\\" + String(code).padStart(3, "0");
39
+ else if (character === '"' || character === "\\") literal += "\\" + character;
40
+ else literal += character;
41
+ }
42
+ return literal + '"';
43
+ }
44
+
33
45
  async function publish(path, parts, check) {
34
46
  const source = Buffer.concat(parts.map(part => typeof part === "string" ? Buffer.from(part) : part));
35
47
  if (check) {
@@ -39,13 +51,16 @@ async function publish(path, parts, check) {
39
51
  }
40
52
 
41
53
  /** Link opaque Rust codegen fragments. The entry order is fixed by the package manifest. */
42
- export async function linkAddonPackage(entries, output, check = false) {
54
+ export async function linkAddonPackage(entries, output, check = false, autoStamp) {
43
55
  if (!entries.length) throw new Error("A native package requires at least one entry");
44
56
  const chunks = [];
45
57
  const candidates = new Map();
46
58
  let prelude;
47
- for (const { fragment, lua } of entries) {
48
- const chunk = readFragment(fragment, await readFile(fragment));
59
+ const digest = autoStamp === undefined ? undefined : createHash("sha256");
60
+ for (const { fragment, lua, lazyModule, ownedFolder, name, pluginId } of entries) {
61
+ const packet = await readFile(fragment);
62
+ digest?.update(packet);
63
+ const chunk = readFragment(fragment, packet);
49
64
  prelude ??= chunk.prelude;
50
65
  if (!prelude.equals(chunk.prelude)) throw new Error(`Mixed native package build stamps: ${fragment}`);
51
66
  for (const module of chunk.modules) {
@@ -61,11 +76,37 @@ export async function linkAddonPackage(entries, output, check = false) {
61
76
  }
62
77
  module.shared = other;
63
78
  }
64
- chunks.push({ lua, ...chunk });
79
+ chunks.push({ lua, lazyModule, ownedFolder, name, pluginId, ...chunk });
80
+ }
81
+ for (const owner of chunks) {
82
+ if (owner.lazyModule === undefined) continue;
83
+ const key = moduleKeyLiteral(owner.lazyModule);
84
+ if (!owner.modules.some(module => module.key === key)) {
85
+ throw new Error("Missing plugin module " + owner.lazyModule + " in " + (owner.name ?? owner.lua));
86
+ }
87
+ // Every file in a plugin's folder belongs to that plugin. Another chunk must not bundle any of them.
88
+ const folder = owner.ownedFolder === undefined ? undefined : moduleKeyLiteral(owner.ownedFolder).slice(0, -1);
89
+ for (const other of chunks) {
90
+ if (other === owner) continue;
91
+ const leaked = other.modules.find(module => module.key === key || folder !== undefined && module.key.startsWith(folder));
92
+ if (leaked === undefined) continue;
93
+ const file = leaked.key.slice(1, -1).replace(/^addon\//u, "");
94
+ const plugin = owner.pluginId === undefined ? owner.lazyModule : "plugin " + owner.pluginId;
95
+ throw new Error(file + " belongs to " + plugin + ", but " + (other.name ?? other.lua) + " imports it. "
96
+ + "Use `import type` for the plugin's types, or move shared code into a core module.");
97
+ }
98
+ }
99
+ const stamp = digest?.digest("hex");
100
+ function stampHeader(header) {
101
+ if (stamp === undefined) return header;
102
+ const source = header.toString();
103
+ const before = "local nativeBuild = " + JSON.stringify(autoStamp) + "\n";
104
+ if (!source.includes(before)) throw new Error("The native linked header is missing its build stamp");
105
+ return source.replace(before, "local nativeBuild = " + JSON.stringify(stamp) + "\n");
65
106
  }
66
107
  let shared = 0;
67
108
  let duplicateBytes = 0;
68
- const pool = [prelude];
109
+ const pool = [stampHeader(prelude)];
69
110
  for (const candidate of candidates.values()) {
70
111
  if (candidate.count < 2) continue;
71
112
  candidate.slot = ++shared;
@@ -75,7 +116,7 @@ export async function linkAddonPackage(entries, output, check = false) {
75
116
  pool.push("nativeRegistry.definitions = definitions\n");
76
117
  let bytes = await publish(output, pool, check);
77
118
  for (const chunk of chunks) {
78
- const parts = [chunk.header];
119
+ const parts = [stampHeader(chunk.header)];
79
120
  for (const { prefix, shared, factory, suffix } of chunk.modules) {
80
121
  parts.push(prefix, shared.slot ? `nativeDefinitions[${shared.slot}]` : factory, suffix);
81
122
  }
@@ -342,7 +342,7 @@ class Service {
342
342
  assert.throws(() => foreign.transform("fixture.ts"), /Declare this class provider next to the module/);
343
343
  });
344
344
 
345
- test("emits the same Lua 5.1 class and provider as the manual constructor descriptor", () => {
345
+ test("lowers a decorated class to the manual constructor descriptor", () => {
346
346
  const body = `
347
347
  class Store { key = "ready"; }
348
348
 
@@ -360,23 +360,14 @@ export class Service {
360
360
  + 'exports: { service: Service } } as const;\nexport const Fixture = __kumiDefineModule(metadata);\n';
361
361
  const original = fixture({ "fixture.ts": decorated });
362
362
  const lowered = original.transform("fixture.ts");
363
- const { Transpiler } = load("typescript-to-lua");
364
- function lua(source) {
365
- const emitted = fixture({ "fixture.ts": source }, false, {
366
- luaTarget: "5.1", luaLibImport: "require-minimal", noImplicitSelf: true, noResolvePaths: ["@kumi/core"],
367
- });
368
- const result = new Transpiler().emit({ program: emitted.program, writeFile: (name, data) => emitted.output.set(name, data) });
369
- const diagnostics = [...ts.getPreEmitDiagnostics(emitted.program), ...result.diagnostics];
370
- assert.equal(diagnostics.map(item => ts.flattenDiagnosticMessageText(item.messageText, "\n")).join("\n"), "");
371
- assert.equal(result.emitSkipped, false);
372
- const unit = [...emitted.output].find(([name]) => name.replaceAll("\\", "/").split("/").pop() === "fixture.lua");
373
- assert.ok(unit, "Expected fixture.lua in " + [...emitted.output.keys()].join(", "));
374
- return unit[1];
375
- }
376
- const output = lua(lowered);
377
- assert.equal(output, lua(manual));
378
- assert.match(output, /function Service\.prototype\.read\(self\)/);
379
- assert.match(output, /inject\s*=\s*\{\s*Store,\s*moduleScope\s*\}/);
363
+ // The decorated class lowers to the same provider descriptor a manual module declares.
364
+ const compact = source => source.replace(/\s+/gu, " ");
365
+ const loweredProviders = compact(lowered).match(/providers: \[Store, \{[^\]]*\]/u)?.[0];
366
+ const manualProviders = compact(manual).match(/providers: \[Store, \{[^\]]*\]/u)?.[0];
367
+ assert.ok(loweredProviders, "Expected lowered providers in " + lowered);
368
+ assert.equal(loweredProviders.replace(/\s*,?\s*\}\s*$/u, "}"), manualProviders?.replace(/\s*,?\s*\}\s*$/u, "}"));
369
+ assert.match(compact(lowered), /inject: \[Store, moduleScope\]/);
370
+ assert.match(lowered, /__kumiDefineModule\(metadata\)/);
380
371
  });
381
372
 
382
373
  test("lowers feature hooks with the child scope and keeps module hooks separate", () => {
@@ -20,7 +20,7 @@ export async function prepareSignalKernel({ ts, program, sdkRoot, output, pack }
20
20
  await rm(join(scratch, "signal.lua"), { force: true });
21
21
  await rmdir(scratch);
22
22
  }
23
- if (!lua.startsWith(`-- kumi-native-1 / SignalFactoryV1 / ${lowered.source}\n`)) {
23
+ if (!lua.startsWith(`-- kumi-native-1 / SignalFactoryV3 / ${lowered.source}\n`)) {
24
24
  throw new Error("Signal emitter returned a mismatched native module");
25
25
  }
26
26
  let replaced = false;