@overmvp/kumi 0.0.0-stage → 0.3.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 (319) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +67 -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 +387 -0
  13. package/builder/css-v1.test.mjs +361 -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 +127 -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 +435 -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 +2336 -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 +381 -0
  48. package/builder/src/native_ir.rs +65 -0
  49. package/builder/src/native_signal.rs +83 -0
  50. package/builder/src/numbers.lua +76 -0
  51. package/builder/src/project-front.mjs +3682 -0
  52. package/builder/src/records.lua +75 -0
  53. package/builder/src/routes.rs +124 -0
  54. package/builder/src/setup-store.lua +18 -0
  55. package/builder/src/signal-kernel.fingerprint +1 -0
  56. package/builder/src/strings.lua +103 -0
  57. package/builder/src/ts-lower.mjs +68 -0
  58. package/builder/src/wow-reads.lua +22 -0
  59. package/builder/src/wow_client.rs +253 -0
  60. package/builder/src/wow_types.rs +564 -0
  61. package/builder/style-modules.mjs +93 -0
  62. package/builder/style-states.mjs +100 -0
  63. package/builder/style-states.test.mjs +103 -0
  64. package/builder/vite-assets.mjs +53 -0
  65. package/builder/vite-project.mjs +10 -0
  66. package/config.ts +59 -0
  67. package/eslint.mjs +74 -0
  68. package/form/index.ts +526 -0
  69. package/form/package.json +13 -0
  70. package/motion/index.ts +2 -0
  71. package/motion/package.json +10 -0
  72. package/package.json +26 -4
  73. package/router/index.ts +50 -0
  74. package/router/navigation.ts +22 -0
  75. package/router/package.json +12 -0
  76. package/router/router-view.ts +134 -0
  77. package/router/routes.ts +64 -0
  78. package/scripts/addon-build.mjs +364 -0
  79. package/scripts/addon-project.mjs +78 -0
  80. package/scripts/kumi-cli.mjs +105 -0
  81. package/scripts/link-addons.mjs +61 -0
  82. package/src/bindings.ts +35 -0
  83. package/src/context.ts +15 -0
  84. package/src/css-tokens.ts +239 -0
  85. package/src/css-v1.ts +68 -0
  86. package/src/cvars.ts +91 -0
  87. package/src/element-node.ts +32 -0
  88. package/src/elements.ts +505 -0
  89. package/src/feature-scope.ts +82 -0
  90. package/src/flex-layout.ts +807 -0
  91. package/src/frame-scheduler.ts +336 -0
  92. package/src/grid-tracks.ts +165 -0
  93. package/src/image-imports.d.ts +24 -0
  94. package/src/images.ts +79 -0
  95. package/src/index.ts +29 -0
  96. package/src/jsx-dev-runtime.ts +2 -0
  97. package/src/jsx-runtime.ts +29 -0
  98. package/src/jsx.d.ts +12 -0
  99. package/src/keyed-list.ts +366 -0
  100. package/src/media-query.ts +144 -0
  101. package/src/module-ui.ts +147 -0
  102. package/src/module.ts +311 -0
  103. package/src/node-selectors.ts +114 -0
  104. package/src/owned-collections.ts +52 -0
  105. package/src/providers.ts +241 -0
  106. package/src/reactive-scope.ts +34 -0
  107. package/src/reactivity.ts +275 -0
  108. package/src/result.ts +64 -0
  109. package/src/runtime.ts +52 -0
  110. package/src/scheduler.ts +185 -0
  111. package/src/signal-kernel.ts +63 -0
  112. package/src/style-classes.ts +51 -0
  113. package/src/style-states.ts +134 -0
  114. package/src/style-variables.ts +53 -0
  115. package/src/text-children.ts +42 -0
  116. package/src/theme.ts +50 -0
  117. package/src/transition.ts +18 -0
  118. package/state/index.ts +9 -0
  119. package/state/package.json +12 -0
  120. package/state/setup-store-persistence.ts +206 -0
  121. package/state/setup-store-view.ts +10 -0
  122. package/state/setup-store.ts +342 -0
  123. package/state/store-bindings.ts +25 -0
  124. package/state/store.ts +84 -0
  125. package/styles/_layers.scss +14 -0
  126. package/templates/addon/.agents/skills/kumi-build-debug/SKILL.md +36 -0
  127. package/templates/addon/.agents/skills/kumi-feature/SKILL.md +50 -0
  128. package/templates/addon/.agents/skills/kumi-plugin/SKILL.md +36 -0
  129. package/templates/addon/.agents/skills/kumi-store/SKILL.md +47 -0
  130. package/templates/addon/.agents/skills/kumi-ui/SKILL.md +73 -0
  131. package/templates/addon/.agents/skills/kumi-wow-api/SKILL.md +30 -0
  132. package/templates/addon/.claude/skills/kumi-build-debug/SKILL.md +36 -0
  133. package/templates/addon/.claude/skills/kumi-feature/SKILL.md +50 -0
  134. package/templates/addon/.claude/skills/kumi-plugin/SKILL.md +36 -0
  135. package/templates/addon/.claude/skills/kumi-store/SKILL.md +47 -0
  136. package/templates/addon/.claude/skills/kumi-ui/SKILL.md +73 -0
  137. package/templates/addon/.claude/skills/kumi-wow-api/SKILL.md +30 -0
  138. package/templates/addon/AGENTS.md +34 -0
  139. package/templates/addon/Assets/Art/Corner10.tga +0 -0
  140. package/templates/addon/Assets/Art/Corner11.tga +0 -0
  141. package/templates/addon/Assets/Art/Corner12.tga +0 -0
  142. package/templates/addon/Assets/Art/Corner13.tga +0 -0
  143. package/templates/addon/Assets/Art/Corner14.tga +0 -0
  144. package/templates/addon/Assets/Art/Corner15.tga +0 -0
  145. package/templates/addon/Assets/Art/Corner16.tga +0 -0
  146. package/templates/addon/Assets/Art/Corner2.tga +0 -0
  147. package/templates/addon/Assets/Art/Corner3.tga +0 -0
  148. package/templates/addon/Assets/Art/Corner4.tga +0 -0
  149. package/templates/addon/Assets/Art/Corner5.tga +0 -0
  150. package/templates/addon/Assets/Art/Corner6.tga +0 -0
  151. package/templates/addon/Assets/Art/Corner7.tga +0 -0
  152. package/templates/addon/Assets/Art/Corner8.tga +0 -0
  153. package/templates/addon/Assets/Art/Corner9.tga +0 -0
  154. package/templates/addon/Assets/Art/Dot.tga +0 -0
  155. package/templates/addon/Assets/Art/Gear.tga +0 -0
  156. package/templates/addon/Assets/Art/Grip.tga +0 -0
  157. package/templates/addon/Assets/Art/Outline10.tga +0 -0
  158. package/templates/addon/Assets/Art/Outline12.tga +0 -0
  159. package/templates/addon/Assets/Art/Outline13.tga +0 -0
  160. package/templates/addon/Assets/Art/Outline14.tga +0 -0
  161. package/templates/addon/Assets/Art/Outline15.tga +0 -0
  162. package/templates/addon/Assets/Art/Outline2.tga +0 -0
  163. package/templates/addon/Assets/Art/Outline3.tga +0 -0
  164. package/templates/addon/Assets/Art/Outline5.tga +0 -0
  165. package/templates/addon/Assets/Art/Outline7.tga +0 -0
  166. package/templates/addon/Assets/Art/Outline9.tga +0 -0
  167. package/templates/addon/Assets/Art/Round11.tga +0 -0
  168. package/templates/addon/Assets/Art/Round11Border.tga +0 -0
  169. package/templates/addon/Assets/Art/Round4.tga +0 -0
  170. package/templates/addon/Assets/Art/Round4Border.tga +0 -0
  171. package/templates/addon/Assets/Art/Round6.tga +0 -0
  172. package/templates/addon/Assets/Art/Round6Border.tga +0 -0
  173. package/templates/addon/Assets/Art/Round8.tga +0 -0
  174. package/templates/addon/Assets/Art/Round8Border.tga +0 -0
  175. package/templates/addon/Assets/Art/Search.tga +0 -0
  176. package/templates/addon/CLAUDE.md +1 -0
  177. package/templates/addon/README.md +49 -0
  178. package/templates/addon/eslint.config.mjs +6 -0
  179. package/templates/addon/gitignore +9 -0
  180. package/templates/addon/kumi.config.ts +17 -0
  181. package/templates/addon/package.json +20 -0
  182. package/templates/addon/src/app/app.module.ts +18 -0
  183. package/templates/addon/src/app/commands.store.ts +11 -0
  184. package/templates/addon/src/app/layout/AppWindow.module.scss +92 -0
  185. package/templates/addon/src/app/layout/AppWindow.tsx +32 -0
  186. package/templates/addon/src/app/main.ts +5 -0
  187. package/templates/addon/src/app/routes/(window)/home/page.tsx +8 -0
  188. package/templates/addon/src/app/routes/(window)/plugins/page.tsx +38 -0
  189. package/templates/addon/src/app/routes/(window)/settings/page.tsx +8 -0
  190. package/templates/addon/src/app/theme.ts +6 -0
  191. package/templates/addon/src/modules/greeting/api/player.api.ts +29 -0
  192. package/templates/addon/src/modules/greeting/greeting.module.ts +18 -0
  193. package/templates/addon/src/modules/greeting/model/greeting.store.ts +81 -0
  194. package/templates/addon/src/modules/greeting/services/greeting.service.ts +38 -0
  195. package/templates/addon/src/modules/greeting/ui/Greeting.module.scss +105 -0
  196. package/templates/addon/src/modules/greeting/ui/GreetingCard.tsx +29 -0
  197. package/templates/addon/src/modules/greeting/widgets/GreetingHud.tsx +54 -0
  198. package/templates/addon/src/modules/greeting/widgets/GreetingOverview.tsx +18 -0
  199. package/templates/addon/src/modules/greeting/widgets/GreetingSettings.tsx +56 -0
  200. package/templates/addon/src/modules/playtime/api/clock.api.ts +6 -0
  201. package/templates/addon/src/modules/playtime/model/playtime.store.ts +19 -0
  202. package/templates/addon/src/modules/playtime/playtime.module.ts +18 -0
  203. package/templates/addon/src/modules/playtime/services/playtime.service.ts +18 -0
  204. package/templates/addon/src/modules/playtime/ui/Playtime.module.scss +25 -0
  205. package/templates/addon/src/modules/playtime/ui/PlaytimeBadge.tsx +10 -0
  206. package/templates/addon/src/modules/playtime/widgets/PlaytimePage.tsx +16 -0
  207. package/templates/addon/src/shared/api/native-art.ts +28 -0
  208. package/templates/addon/src/shared/assets/close.png +0 -0
  209. package/templates/addon/src/shared/lib/format.ts +20 -0
  210. package/templates/addon/src/shared/styles/_tokens.scss +12 -0
  211. package/templates/addon/src/shared/ui/Button.tsx +29 -0
  212. package/templates/addon/src/shared/ui/Choice.tsx +34 -0
  213. package/templates/addon/src/shared/ui/Controls.module.scss +93 -0
  214. package/templates/addon/src/shared/ui/Glyph.tsx +18 -0
  215. package/templates/addon/src/shared/ui/Slider.tsx +25 -0
  216. package/templates/addon/src/shared/ui/Toggle.tsx +29 -0
  217. package/templates/addon/src/shared/ui/focus-ref.ts +7 -0
  218. package/templates/addon/src/shared/ui/range-skin.tsx +15 -0
  219. package/templates/addon/tsconfig.json +63 -0
  220. package/translate/index.ts +14 -0
  221. package/translate/package.json +9 -0
  222. package/utils/colors.ts +76 -0
  223. package/utils/format.ts +37 -0
  224. package/utils/index.ts +4 -0
  225. package/utils/number.ts +17 -0
  226. package/utils/package.json +7 -0
  227. package/utils/text.ts +6 -0
  228. package/validate/index.ts +119 -0
  229. package/validate/package.json +9 -0
  230. package/wow/absolute-position.ts +142 -0
  231. package/wow/action-bar-layout.ts +108 -0
  232. package/wow/action-button.ts +219 -0
  233. package/wow/action-catalog.ts +98 -0
  234. package/wow/addon-manifest.ts +36 -0
  235. package/wow/animation.ts +428 -0
  236. package/wow/app-ui.ts +221 -0
  237. package/wow/aura-button.ts +76 -0
  238. package/wow/aura-container.ts +591 -0
  239. package/wow/aura-countdown.ts +201 -0
  240. package/wow/aura-slot.ts +153 -0
  241. package/wow/bar-shade.ts +93 -0
  242. package/wow/borrowed-slot.ts +216 -0
  243. package/wow/button-drag.ts +48 -0
  244. package/wow/cast-clock.ts +153 -0
  245. package/wow/cast-text.ts +83 -0
  246. package/wow/class-colors.ts +126 -0
  247. package/wow/clock.ts +7 -0
  248. package/wow/color-picker.ts +128 -0
  249. package/wow/commands.ts +17 -0
  250. package/wow/contained-frame.ts +128 -0
  251. package/wow/contract.ts +42 -0
  252. package/wow/cooldown-timing.ts +24 -0
  253. package/wow/css-box.ts +144 -0
  254. package/wow/css-color.ts +12 -0
  255. package/wow/css-style.ts +109 -0
  256. package/wow/css-surfaces.ts +603 -0
  257. package/wow/css-text.ts +399 -0
  258. package/wow/cursor.ts +45 -0
  259. package/wow/cvar-schema.ts +32 -0
  260. package/wow/cvars.ts +98 -0
  261. package/wow/dropdown-art.ts +39 -0
  262. package/wow/element-click.ts +20 -0
  263. package/wow/element-event-coordinator.ts +219 -0
  264. package/wow/element-events.ts +317 -0
  265. package/wow/event-dispatcher.ts +151 -0
  266. package/wow/events.ts +50 -0
  267. package/wow/font-cache.ts +92 -0
  268. package/wow/frame-access.ts +53 -0
  269. package/wow/frame-layer.ts +5 -0
  270. package/wow/frame-timing.ts +13 -0
  271. package/wow/frames.ts +236 -0
  272. package/wow/heal-prediction.ts +305 -0
  273. package/wow/hooks.ts +133 -0
  274. package/wow/image-layers.ts +55 -0
  275. package/wow/index.ts +111 -0
  276. package/wow/layout-view.ts +663 -0
  277. package/wow/locale-font.ts +15 -0
  278. package/wow/lua-string.ts +18 -0
  279. package/wow/lua-table.ts +18 -0
  280. package/wow/macro-book.ts +84 -0
  281. package/wow/map-position.ts +27 -0
  282. package/wow/media-query.ts +65 -0
  283. package/wow/module-events.ts +11 -0
  284. package/wow/native-hooks.ts +168 -0
  285. package/wow/native-placement.ts +88 -0
  286. package/wow/native.ts +153 -0
  287. package/wow/number-format.ts +8 -0
  288. package/wow/number-input.ts +10 -0
  289. package/wow/panel-host.ts +97 -0
  290. package/wow/pixel.ts +35 -0
  291. package/wow/plugins.ts +246 -0
  292. package/wow/protect.ts +48 -0
  293. package/wow/protected-layout.ts +133 -0
  294. package/wow/protected-view.ts +103 -0
  295. package/wow/range-art.ts +81 -0
  296. package/wow/readable-api.ts +120 -0
  297. package/wow/reparent-frame.ts +99 -0
  298. package/wow/rounded-texture.ts +183 -0
  299. package/wow/saved-variables.ts +109 -0
  300. package/wow/scroll-view.ts +64 -0
  301. package/wow/secret-ref.ts +14 -0
  302. package/wow/secure-bindings.ts +89 -0
  303. package/wow/secure-clicks.ts +432 -0
  304. package/wow/secure-snippet.ts +235 -0
  305. package/wow/secure-state.ts +130 -0
  306. package/wow/secure-target-visibility.ts +89 -0
  307. package/wow/secure-transaction.ts +331 -0
  308. package/wow/special-window.ts +269 -0
  309. package/wow/spell-cooldown.ts +36 -0
  310. package/wow/start-addon.ts +122 -0
  311. package/wow/state-paint.ts +256 -0
  312. package/wow/transition.ts +86 -0
  313. package/wow/unit-button.ts +39 -0
  314. package/wow/unit-cast.ts +92 -0
  315. package/wow/unit-health-text.ts +47 -0
  316. package/wow/view-nodes.ts +304 -0
  317. package/wow/view.ts +1864 -0
  318. package/wow/visible-frame-job.ts +34 -0
  319. package/wow/width-reserve.ts +108 -0
@@ -0,0 +1,63 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "lib": [
5
+ "ES2020"
6
+ ],
7
+ "module": "ESNext",
8
+ "moduleResolution": "Bundler",
9
+ "strict": true,
10
+ "noEmit": true,
11
+ "types": [],
12
+ "jsx": "react-jsx",
13
+ "paths": {
14
+ "@kumi/core": [
15
+ "./node_modules/__KUMI_PACKAGE__/src/index.ts"
16
+ ],
17
+ "@kumi/state": [
18
+ "./node_modules/__KUMI_PACKAGE__/state/index.ts"
19
+ ],
20
+ "@kumi/wow": [
21
+ "./node_modules/__KUMI_PACKAGE__/wow/index.ts"
22
+ ],
23
+ "@kumi/wow-generated": [
24
+ "./build/types/wow-api.d.ts"
25
+ ],
26
+ "@kumi/animation": [
27
+ "./node_modules/__KUMI_PACKAGE__/animation/index.ts"
28
+ ],
29
+ "@kumi/form": [
30
+ "./node_modules/__KUMI_PACKAGE__/form/index.ts"
31
+ ],
32
+ "@kumi/router": [
33
+ "./node_modules/__KUMI_PACKAGE__/router/index.ts"
34
+ ],
35
+ "@kumi/routes": [
36
+ "./build/routes/index.ts"
37
+ ],
38
+ "@kumi/routes/paths": [
39
+ "./build/routes/paths.ts"
40
+ ],
41
+ "@kumi/core/jsx-runtime": [
42
+ "./node_modules/__KUMI_PACKAGE__/src/jsx-runtime.ts"
43
+ ],
44
+ "@/*": [
45
+ "./src/*"
46
+ ],
47
+ "@kumi/styles/*": [
48
+ "./build/styles/*"
49
+ ]
50
+ },
51
+ "jsxImportSource": "@kumi/core",
52
+ "experimentalDecorators": true
53
+ },
54
+ "files": [
55
+ "node_modules/__KUMI_PACKAGE__/builder/native-lua.d.ts"
56
+ ],
57
+ "include": [
58
+ "src/**/*.ts",
59
+ "src/**/*.tsx",
60
+ "build/kumi/*.d.ts",
61
+ "kumi.config.ts"
62
+ ]
63
+ }
@@ -0,0 +1,14 @@
1
+ export type Translate = (this: void, key: string, ...values: (string | number)[]) => string;
2
+
3
+ const identity: Translate = key => key;
4
+ let translate = identity;
5
+
6
+ export function configureTranslation(resolve?: Translate): void {
7
+ translate = resolve ?? identity;
8
+ }
9
+
10
+ const t: Translate = (key, ...values) => translate(key, ...values);
11
+
12
+ export function useT(): Translate {
13
+ return t;
14
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "@kumi/translate",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "exports": {
7
+ ".": "./index.ts"
8
+ }
9
+ }
@@ -0,0 +1,76 @@
1
+ import type { OwnedReadonlyArray } from "../src/owned-collections";
2
+
3
+ /** Color channels in the range used by WoW and normalized CSS conversions. */
4
+ export type RGB = [red: number, green: number, blue: number];
5
+ export type RGBA = [...RGB, alpha: number];
6
+
7
+ export function isRGB(this: void, value: unknown): value is RGB {
8
+ if (typeof value !== "object" || value === null) return false;
9
+ const color = value as OwnedReadonlyArray<unknown>;
10
+ const red = color[0], green = color[1], blue = color[2];
11
+ return typeof red === "number" && Number.isFinite(red)
12
+ && typeof green === "number" && Number.isFinite(green)
13
+ && typeof blue === "number" && Number.isFinite(blue);
14
+ }
15
+
16
+ export function copyRGB(this: void, color: Readonly<RGB>): RGB {
17
+ return [color[0], color[1], color[2]];
18
+ }
19
+
20
+ export function mixRGB(this: void, from: Readonly<RGB>, to: Readonly<RGB>, share: number): RGB {
21
+ return [
22
+ from[0] + (to[0] - from[0]) * share,
23
+ from[1] + (to[1] - from[1]) * share,
24
+ from[2] + (to[2] - from[2]) * share,
25
+ ];
26
+ }
27
+
28
+ function linearChannel(value: number) {
29
+ return value <= 0.03928 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
30
+ }
31
+
32
+ function luminance(red: number, green: number, blue: number) {
33
+ return 0.2126 * linearChannel(red) + 0.7152 * linearChannel(green) + 0.0722 * linearChannel(blue);
34
+ }
35
+
36
+ /** Contrast ratio between two normalized sRGB colors. */
37
+ export function contrastRatio(this: void, r1: number, g1: number, b1: number, r2: number, g2: number, b2: number): number {
38
+ const left = luminance(r1, g1, b1);
39
+ const right = luminance(r2, g2, b2);
40
+ return (Math.max(left, right) + 0.05) / (Math.min(left, right) + 0.05);
41
+ }
42
+
43
+ export function colorContrast(this: void, first: Readonly<RGB>, second: Readonly<RGB>): number {
44
+ return contrastRatio(first[0], first[1], first[2], second[0], second[1], second[2]);
45
+ }
46
+
47
+ const hexDigits = "0123456789abcdef";
48
+
49
+ function toHexChannel(channel: number): string {
50
+ const normalized = Number.isFinite(channel) ? Math.max(0, Math.min(1, channel)) : 0;
51
+ const byte = Math.round(normalized * 255);
52
+ return hexDigits.charAt(Math.floor(byte / 16)) + hexDigits.charAt(byte % 16);
53
+ }
54
+
55
+ export function rgbToHex(this: void, color: Readonly<RGB>): string {
56
+ const [red, green, blue] = color;
57
+ return "#" + toHexChannel(red) + toHexChannel(green) + toHexChannel(blue);
58
+ }
59
+
60
+ export function rgbaToHex(this: void, red: number, green: number, blue: number, alpha: number): string {
61
+ const color = rgbToHex([red, green, blue]);
62
+ return alpha === 1 ? color : color + toHexChannel(alpha);
63
+ }
64
+
65
+ export function hexToRGB(this: void, value: string): RGB | undefined {
66
+ const hex = (value.startsWith("#") ? value.slice(1) : value).toLowerCase();
67
+ if (hex.length !== 6) return undefined;
68
+ const channels: RGB = [0, 0, 0];
69
+ for (let index = 0; index < 3; index++) {
70
+ const high = hexDigits.indexOf(hex.charAt(index * 2));
71
+ const low = hexDigits.indexOf(hex.charAt(index * 2 + 1));
72
+ if (high < 0 || low < 0) return undefined;
73
+ channels[index] = (high * 16 + low) / 255;
74
+ }
75
+ return channels;
76
+ }
@@ -0,0 +1,37 @@
1
+ /** Abbreviate a finite value using K, M, or B and preserve its sign. */
2
+ export function formatCompactAmount(this: void, value: number, decimals = 2): string {
3
+ if (!Number.isFinite(value)) return "-";
4
+ const absolute = Math.abs(value);
5
+ if (absolute >= 1e6) {
6
+ const digits = Number.isInteger(decimals) && decimals >= 0 && decimals <= 20 ? decimals : 2;
7
+ return absolute >= 1e9 ? (value / 1e9).toFixed(digits) + "B" : (value / 1e6).toFixed(digits) + "M";
8
+ }
9
+ if (absolute >= 1e3) return (value / 1e3).toFixed(1) + "K";
10
+ return String(Math.floor(value + 0.5));
11
+ }
12
+
13
+ export type DurationRounding = "nearest" | "up" | "down";
14
+
15
+ export function formatPercent(this: void, fraction: number, digits: number): string {
16
+ return (fraction * 100).toFixed(digits) + "%";
17
+ }
18
+
19
+ export function formatDuration(this: void, seconds: number, rounding: DurationRounding = "nearest"): string {
20
+ const duration = Number.isFinite(seconds) ? Math.max(0, seconds) : 0;
21
+ const whole = rounding === "up" ? Math.ceil(duration) : rounding === "down" ? Math.floor(duration) : Math.round(duration);
22
+ const remainder = whole % 60;
23
+ return `${Math.floor(whole / 60)}:${remainder < 10 ? "0" : ""}${remainder}`;
24
+ }
25
+
26
+ export function formatInteger(this: void, value: number, separator = ","): string {
27
+ let remaining = Math.abs(value);
28
+ if (remaining > 9_007_199_254_740_991 || !Number.isInteger(remaining)) return String(value);
29
+
30
+ let tail = "";
31
+ while (remaining >= 1000) {
32
+ const group = "00" + String(remaining % 1000);
33
+ tail = separator + group.slice(-3) + tail;
34
+ remaining = Math.floor(remaining / 1000);
35
+ }
36
+ return (value < 0 ? "-" : "") + String(remaining) + tail;
37
+ }
package/utils/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export { colorContrast, contrastRatio, copyRGB, hexToRGB, isRGB, mixRGB, rgbaToHex, rgbToHex, type RGB, type RGBA } from "./colors";
2
+ export { formatCompactAmount, formatDuration, formatInteger, formatPercent, type DurationRounding } from "./format";
3
+ export { clamp, fromPercent, isFiniteNumber, toPercent } from "./number";
4
+ export { replaceFirst } from "./text";
@@ -0,0 +1,17 @@
1
+ export function isFiniteNumber(this: void, value: unknown): value is number {
2
+ return typeof value === "number" && Number.isFinite(value);
3
+ }
4
+
5
+ export function clamp(this: void, value: number, minimum: number, maximum: number): number {
6
+ if (value < minimum) return minimum;
7
+ if (value > maximum) return maximum;
8
+ return value;
9
+ }
10
+
11
+ export function toPercent(this: void, fraction: number): number {
12
+ return Math.round(fraction * 100);
13
+ }
14
+
15
+ export function fromPercent(this: void, percent: number): number {
16
+ return percent / 100;
17
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "@kumi/utils",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "exports": "./index.ts"
7
+ }
package/utils/text.ts ADDED
@@ -0,0 +1,6 @@
1
+ export function replaceFirst(this: void, text: string, search: string, replacement: string): string {
2
+ if (search === "") return replacement + text;
3
+ const start = text.indexOf(search);
4
+ if (start < 0) return text;
5
+ return text.slice(0, start) + replacement + text.slice(start + search.length);
6
+ }
@@ -0,0 +1,119 @@
1
+ export interface ValidationIssue {
2
+ readonly path: readonly PropertyKey[];
3
+ readonly message: string;
4
+ }
5
+
6
+ export type ValidationResult<Value> =
7
+ | { readonly success: true; readonly data: Value }
8
+ | { readonly success: false; readonly error: { readonly issues: readonly ValidationIssue[] } };
9
+
10
+ type Path = readonly PropertyKey[];
11
+ type Read<Value> = (this: void, input: unknown, path: Path, issues: ValidationIssue[]) => Value | undefined;
12
+ type Check<Value> = (this: void, value: Value) => boolean;
13
+
14
+ export class Schema<Value> {
15
+ constructor(readonly read: Read<Value>) {}
16
+
17
+ safeParse(input: unknown): ValidationResult<Value> {
18
+ const issues: ValidationIssue[] = [];
19
+ const data = this.read(input, [], issues);
20
+ if (issues.length > 0) return { success: false, error: { issues } };
21
+ return { success: true, data: data as Value };
22
+ }
23
+
24
+ refine(check: Check<Value>, message: string): Schema<Value> {
25
+ const read = this.read;
26
+ return new Schema((input, path, issues) => {
27
+ const before = issues.length;
28
+ const value = read(input, path, issues);
29
+ if (issues.length === before && !check(value as Value)) issues.push({ path, message });
30
+ return value;
31
+ });
32
+ }
33
+ }
34
+
35
+ export type Infer<Input> = Input extends Schema<infer Value> ? Value : never;
36
+
37
+ function readType<Value>(guard: (this: void, input: unknown) => input is Value, message: string): Read<Value> {
38
+ return (input, path, issues) => {
39
+ if (guard(input)) return input;
40
+ issues.push({ path, message });
41
+ };
42
+ }
43
+
44
+ class StringSchema extends Schema<string> {
45
+ constructor(read: Read<string> = readType((value): value is string => typeof value === "string", "Expected a string")) {
46
+ super(read);
47
+ }
48
+
49
+ min(length: number, message = `Enter at least ${length} characters.`): StringSchema {
50
+ return new StringSchema(this.refine(value => value.length >= length, message).read);
51
+ }
52
+
53
+ trim(): StringSchema {
54
+ const read = this.read;
55
+ return new StringSchema((input, path, issues) => read(input, path, issues)?.trim());
56
+ }
57
+ }
58
+
59
+ class NumberSchema extends Schema<number> {
60
+ constructor(read: Read<number> = readType((value): value is number => typeof value === "number" && Number.isFinite(value),
61
+ "Expected a finite number")) {
62
+ super(read);
63
+ }
64
+
65
+ min(limit: number, message = `Must be at least ${limit}.`): NumberSchema {
66
+ return new NumberSchema(this.refine(value => value >= limit, message).read);
67
+ }
68
+
69
+ max(limit: number, message = `Must be at most ${limit}.`): NumberSchema {
70
+ return new NumberSchema(this.refine(value => value <= limit, message).read);
71
+ }
72
+
73
+ int(message = "Expected an integer"): NumberSchema {
74
+ return new NumberSchema(this.refine(value => Math.floor(value) === value, message).read);
75
+ }
76
+ }
77
+
78
+ function choices<const Values extends readonly [string, ...string[]]>(values: Values, message = "Invalid option"): Schema<Values[number]> {
79
+ return new Schema(readType((input): input is Values[number] => values.some(value => value === input), message));
80
+ }
81
+
82
+ function tuple<const Items extends readonly Schema<unknown>[]>(items: Items): Schema<{ [K in keyof Items]: Infer<Items[K]> }> {
83
+ type Output = { [K in keyof Items]: Infer<Items[K]> };
84
+ return new Schema((input, path, issues) => {
85
+ if (!Array.isArray(input) || input.length !== items.length) {
86
+ issues.push({ path, message: `Expected ${items.length} items` });
87
+ return;
88
+ }
89
+ return items.map((schema, index) => schema.read(input[index], [...path, index], issues)) as Output;
90
+ });
91
+ }
92
+
93
+ function object<Shape extends Record<string, Schema<unknown>>>(shape: Shape): Schema<{ [K in keyof Shape]: Infer<Shape[K]> }> {
94
+ type Output = { [K in keyof Shape]: Infer<Shape[K]> };
95
+ return new Schema((input, path, issues) => {
96
+ if (input === null || typeof input !== "object" || (Array.isArray(input) && input.length > 0)) {
97
+ issues.push({ path, message: "Expected an object" });
98
+ return;
99
+ }
100
+ const output: Record<string, unknown> = {};
101
+ for (const [key, schema] of Object.entries(shape)) {
102
+ output[key] = schema.read((input as Record<string, unknown>)[key], [...path, key], issues);
103
+ }
104
+ return output as Output;
105
+ });
106
+ }
107
+
108
+ const channel = new NumberSchema().min(0).max(1);
109
+
110
+ export const v = {
111
+ string: () => new StringSchema(),
112
+ number: () => new NumberSchema(),
113
+ boolean: () => new Schema(readType((input): input is boolean => typeof input === "boolean", "Expected a boolean")),
114
+ enum: choices,
115
+ tuple,
116
+ rgb: () => tuple([channel, channel, channel]),
117
+ rgba: () => tuple([channel, channel, channel, channel]),
118
+ object,
119
+ };
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "@kumi/validate",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "exports": {
7
+ ".": "./index.ts"
8
+ }
9
+ }
@@ -0,0 +1,142 @@
1
+ import type { Anchor, Binding, NativeStyle } from "../src/elements";
2
+ import type { ReadonlyRef } from "../src/reactivity";
3
+ import { fail, type Failure } from "../src/result";
4
+ import type { RuntimeScope } from "../src/runtime";
5
+ import { canAccessRegion } from "./frame-access";
6
+ import type { FontString, Frame, FrameParent } from "./frames";
7
+ import { readLayoutValue, validateLayoutParent } from "./layout-view";
8
+ import { isSecret, reveal } from "./native";
9
+
10
+ type Position = Pick<NativeStyle, "left" | "right" | "top" | "bottom" | "autoMargin">;
11
+ type Size = NativeStyle["width"];
12
+ type Region = Parameters<typeof validateLayoutParent>[0];
13
+
14
+ export interface NativeStartTarget {
15
+ kind: "text" | "button";
16
+ target: ReadonlyRef<Frame | undefined>;
17
+ }
18
+
19
+ export type NativeTextEndTarget = ReadonlyRef<FontString | undefined>;
20
+
21
+ export interface NativeEndTarget {
22
+ kind: "text" | "frame";
23
+ target: NativeTextEndTarget;
24
+ }
25
+
26
+ function finiteInset(value: number | undefined): boolean {
27
+ return value === undefined || Number.isFinite(value);
28
+ }
29
+
30
+ export function bindAbsolutePosition(this: void, region: Region, parent: FrameParent, scope: RuntimeScope, style: Position,
31
+ width: Size, height: Size, fullWidth?: boolean, offset?: Binding<number>, startAfter?: NativeStartTarget,
32
+ endBefore?: NativeEndTarget): Failure | undefined {
33
+ if (startAfter !== undefined && endBefore !== undefined) return fail("Absolute text supports one external anchor target");
34
+ let point: Anchor["point"] | undefined, opposite: Anchor["point"] | undefined;
35
+ let previousStart: Frame | undefined;
36
+ let previousEnd: FontString | undefined;
37
+ let needsRepair = false;
38
+ let x = 0, y = 0, oppositeX = 0, oppositeY = 0;
39
+ const observe = scope.watchEffect(() => {
40
+ const left = readLayoutValue(style.left);
41
+ const right = readLayoutValue(style.right);
42
+ const top = readLayoutValue(style.top);
43
+ const bottom = readLayoutValue(style.bottom);
44
+ const w = readLayoutValue(width);
45
+ const h = readLayoutValue(height);
46
+ const shift = readLayoutValue(offset);
47
+ const margins = readLayoutValue(style.autoMargin);
48
+ if (!margins.ok) return margins;
49
+ if (!left.ok) return left;
50
+ if (!right.ok) return right;
51
+ if (!top.ok) return top;
52
+ if (!bottom.ok) return bottom;
53
+ if (!w.ok) return w;
54
+ if (!h.ok) return h;
55
+ if (!shift.ok) return shift;
56
+ if (!finiteInset(left.value) || !finiteInset(right.value) || !finiteInset(top.value) || !finiteInset(bottom.value)) {
57
+ return fail("Invalid CSS absolute inset");
58
+ }
59
+ // Auto margins between two insets center the box on that axis (CSS `inset` + `margin: auto`), at its own size.
60
+ const auto = margins.value;
61
+ const centerX = fullWidth !== true && auto?.[1] === true && auto[3] === true && left.value !== undefined && right.value !== undefined;
62
+ const centerY = auto?.[0] === true && auto[2] === true && top.value !== undefined && bottom.value !== undefined;
63
+ const fillX = !centerX && (fullWidth === true || (w.value === undefined || w.value === "auto") && left.value !== undefined && right.value !== undefined);
64
+ const fillY = !centerY && (h.value === undefined || h.value === "auto") && top.value !== undefined && bottom.value !== undefined;
65
+ const side = centerX ? "" : fillX || left.value !== undefined || right.value === undefined ? "LEFT" : "RIGHT";
66
+ const edge = centerY ? "" : top.value !== undefined || bottom.value === undefined ? "TOP" : "BOTTOM";
67
+ // An explicit check: an empty string is truthy in Lua, so `|| "CENTER"` would pass "" to SetPoint.
68
+ const joined = `${edge}${side}`;
69
+ const next = (joined === "" ? "CENTER" : joined) as Anchor["point"];
70
+ const second = fillX || fillY ? `${fillY ? "BOTTOM" : edge}${fillX ? "RIGHT" : side}` as Anchor["point"] : undefined;
71
+ if (startAfter?.kind === "text" && (next !== "LEFT" || second !== "RIGHT")) {
72
+ return fail("A native text start target requires centered CSS text stretched between left and right insets");
73
+ }
74
+ if (startAfter?.kind === "button" && (second !== undefined || (next !== "LEFT" && next !== "TOPLEFT"))) {
75
+ return fail("A native button start target requires a single left or top-left CSS anchor");
76
+ }
77
+ const after = startAfter === undefined ? undefined : startAfter.target.value;
78
+ if (startAfter !== undefined && isSecret(after)) return fail("The native start target is unreadable");
79
+ const before = endBefore === undefined ? undefined : endBefore.target.value;
80
+ const frameEnd = endBefore?.kind === "frame";
81
+ if (endBefore?.kind === "text" && (next !== "LEFT" || second !== "RIGHT")) {
82
+ return fail("A native text end target requires centered CSS text with left and right insets");
83
+ }
84
+ if (frameEnd && (next !== "RIGHT" || second !== undefined)) {
85
+ return fail("A native frame end target requires a single centered CSS right anchor");
86
+ }
87
+ if (endBefore !== undefined && isSecret(before)) return fail("The native end target is unreadable");
88
+ const another = endBefore !== undefined && before === undefined ? undefined : second;
89
+ const moving = shift.value ?? 0;
90
+ const nextX = centerX ? ((left.value ?? 0) - (right.value ?? 0)) / 2 : side === "LEFT" ? left.value ?? 0 : -(right.value ?? 0);
91
+ const nextY = (centerY ? ((bottom.value ?? 0) - (top.value ?? 0)) / 2 : edge === "TOP" ? -(top.value ?? 0) : bottom.value ?? 0) + moving;
92
+ const anotherX = fillX ? -(right.value ?? 0) : nextX;
93
+ const anotherY = fillY ? (bottom.value ?? 0) + moving : nextY;
94
+ if (!needsRepair && point === next && opposite === another && x === nextX && y === nextY && oppositeX === anotherX && oppositeY === anotherY
95
+ && previousStart === after && previousEnd === before) return;
96
+ const permitted = validateLayoutParent(region, parent, "absolute");
97
+ if (!permitted.ok) return permitted;
98
+ const start = after === undefined ? permitted : validateLayoutParent(region, after);
99
+ if (!start.ok) return start;
100
+ if (before !== undefined) {
101
+ if (before === region || !canAccessRegion(before) || reveal(before.GetObjectType()) !== "FontString") {
102
+ return fail("Invalid native end target");
103
+ }
104
+ const targetParent = reveal(before.GetParent()) as FrameParent | undefined;
105
+ if (targetParent === undefined) return fail("The native end target has no readable parent");
106
+ const end = validateLayoutParent(before, targetParent);
107
+ if (!end.ok) return end;
108
+ }
109
+ if (endBefore === undefined) {
110
+ if (point !== undefined) region.ClearAllPoints();
111
+ const relative = after === undefined ? next : next === "TOPLEFT" ? "TOPRIGHT" : "RIGHT";
112
+ region.SetPoint(next, start.value, relative, nextX, nextY);
113
+ if (another !== undefined) region.SetPoint(another, permitted.value, another, anotherX, anotherY);
114
+ } else {
115
+ const firstTarget = frameEnd ? before : undefined;
116
+ const applied = scope.protect(() => {
117
+ if (point !== undefined || needsRepair) region.ClearAllPoints();
118
+ region.SetPoint(next, firstTarget ?? permitted.value, firstTarget === undefined ? next : "LEFT", nextX, nextY);
119
+ if (before !== undefined && another !== undefined) region.SetPoint(another, before, "LEFT", anotherX, anotherY);
120
+ });
121
+ if (!applied.ok) {
122
+ const restored = scope.protect(() => {
123
+ region.ClearAllPoints();
124
+ const previousFirst = frameEnd ? previousEnd : undefined;
125
+ if (point !== undefined) {
126
+ region.SetPoint(point, previousFirst ?? permitted.value, previousFirst === undefined ? point : "LEFT", x, y);
127
+ }
128
+ if (opposite !== undefined && previousEnd !== undefined) region.SetPoint(opposite, previousEnd, "LEFT", oppositeX, oppositeY);
129
+ });
130
+ needsRepair = !restored.ok;
131
+ const kind = frameEnd ? "frame" : "text";
132
+ return restored.ok ? applied : fail(applied.reason + ". Could not restore native " + kind + " anchors: " + restored.reason);
133
+ }
134
+ needsRepair = false;
135
+ }
136
+ point = next; opposite = another;
137
+ x = nextX; y = nextY; oppositeX = anotherX; oppositeY = anotherY;
138
+ previousStart = after;
139
+ previousEnd = before;
140
+ });
141
+ return observe.ok ? undefined : observe;
142
+ }
@@ -0,0 +1,108 @@
1
+ import type { Anchor } from "../src/elements";
2
+ import type { ReadonlyRef } from "../src/reactivity";
3
+ import { computed, computedResult } from "../src/reactive-scope";
4
+ import { ok } from "../src/result";
5
+ import { snapPixel } from "./pixel";
6
+
7
+ export interface ActionBarPosition {
8
+ readonly x: number;
9
+ readonly y: number;
10
+ }
11
+
12
+ export interface ActionBarLayoutOptions {
13
+ readonly count: ReadonlyRef<number>;
14
+ readonly slotSize: ReadonlyRef<number>;
15
+ readonly vertical: ReadonlyRef<boolean>;
16
+ readonly pixel: ReadonlyRef<number>;
17
+ readonly x: ReadonlyRef<number>;
18
+ readonly y: ReadonlyRef<number>;
19
+ readonly preview: ReadonlyRef<ActionBarPosition | undefined>;
20
+ readonly gap: number;
21
+ readonly padding: number;
22
+ readonly controlSize: number;
23
+ readonly controlGap: number;
24
+ readonly iconInsetPixels: number;
25
+ }
26
+
27
+ function measure(size: number, pixel: number, options: ActionBarLayoutOptions) {
28
+ const cell = snapPixel(size, pixel);
29
+ const step = cell + snapPixel(options.gap, pixel);
30
+ const control = snapPixel(options.controlSize, pixel);
31
+ const padding = snapPixel(options.padding, pixel);
32
+ const trayInset = control + snapPixel(options.controlGap, pixel);
33
+ const first = trayInset + padding;
34
+ const across = Math.max(cell, control) + 2 * padding;
35
+ return {
36
+ cell, step, first, control, trayInset, across,
37
+ cellCenter: snapPixel((across - cell) / 2, pixel),
38
+ controlCenter: snapPixel((across - control) / 2, pixel),
39
+ };
40
+ }
41
+
42
+ /** Bind an explicitly anchored strip of secure slots, a tray and two end controls. */
43
+ export function useActionBarLayout(this: void, options: ActionBarLayoutOptions) {
44
+ const { count, slotSize, vertical, pixel, preview, x, y } = options;
45
+ const geometry = computed(() => measure(slotSize.value, pixel.value, options));
46
+
47
+ function select<Value>(read: (this: void, value: ReturnType<typeof measure>) => Value) {
48
+ return computedResult(() => {
49
+ const size = geometry.value;
50
+ return size.ok ? ok(read(size.value)) : size;
51
+ });
52
+ }
53
+
54
+ function length(value: ReturnType<typeof measure>) {
55
+ const slots = count.value;
56
+ return 2 * value.first + (slots > 0 ? value.cell + (slots - 1) * value.step : 0);
57
+ }
58
+
59
+ const anchor = computed<Anchor>(() => {
60
+ const current = preview.value;
61
+ return { point: "BOTTOM", x: snapPixel(current?.x ?? x.value, pixel.value), y: snapPixel(current?.y ?? y.value, pixel.value) };
62
+ });
63
+ const control = select(value => value.control);
64
+ const cell = select(value => value.cell);
65
+ const icon = select(value => value.cell - 2 * options.iconInsetPixels * pixel.value);
66
+
67
+ return {
68
+ bar: {
69
+ anchor,
70
+ width: select(value => vertical.value ? value.across : length(value)),
71
+ height: select(value => vertical.value ? length(value) : value.across),
72
+ },
73
+ start: {
74
+ width: control, height: control,
75
+ anchor: select((value): Anchor => vertical.value
76
+ ? { point: "TOPLEFT", x: value.controlCenter }
77
+ : { point: "TOPLEFT", y: -value.controlCenter }),
78
+ },
79
+ end: {
80
+ width: control, height: control,
81
+ anchor: select((value): Anchor => vertical.value
82
+ ? { point: "BOTTOMLEFT", x: value.controlCenter }
83
+ : { point: "TOPRIGHT", y: -value.controlCenter }),
84
+ },
85
+ tray: {
86
+ width: select(value => vertical.value ? value.across : length(value) - 2 * value.trayInset),
87
+ height: select(value => vertical.value ? length(value) - 2 * value.trayInset : value.across),
88
+ anchor: select((value): Anchor => vertical.value
89
+ ? { point: "TOPLEFT", y: -value.trayInset }
90
+ : { point: "TOPLEFT", x: value.trayInset }),
91
+ },
92
+ iconSize: icon,
93
+ cellSize: cell,
94
+ slot(this: void, index: number) {
95
+ return {
96
+ width: cell,
97
+ height: cell,
98
+ shown: computed(() => index < count.value),
99
+ anchor: select((value): Anchor => {
100
+ const offset = value.first + index * value.step;
101
+ return vertical.value
102
+ ? { point: "TOPLEFT", x: value.cellCenter, y: -offset }
103
+ : { point: "TOPLEFT", x: offset, y: -value.cellCenter };
104
+ }),
105
+ };
106
+ },
107
+ };
108
+ }