@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.
- package/LICENSE +21 -0
- package/README.md +67 -2
- package/animation/color-transition.ts +196 -0
- package/animation/cycle.ts +151 -0
- package/animation/ease.ts +29 -0
- package/animation/index.ts +13 -0
- package/animation/package.json +12 -0
- package/animation/presets.ts +376 -0
- package/animation/spec.ts +197 -0
- package/builder/Cargo.lock +192 -0
- package/builder/Cargo.toml +7 -0
- package/builder/css-v1.mjs +387 -0
- package/builder/css-v1.test.mjs +361 -0
- package/builder/generated-output.mjs +61 -0
- package/builder/generated-output.test.mjs +132 -0
- package/builder/jsx-form.mjs +93 -0
- package/builder/jsx-form.test.mjs +48 -0
- package/builder/jsx-lists.mjs +209 -0
- package/builder/link-addon-package.mjs +127 -0
- package/builder/lua-assets.mjs +74 -0
- package/builder/lua-builtin-values.mjs +57 -0
- package/builder/lua-builtin-values.test.mjs +155 -0
- package/builder/lua-loop-closures.mjs +183 -0
- package/builder/lua-loop-closures.test.mjs +89 -0
- package/builder/lua-truthiness.mjs +61 -0
- package/builder/lua-truthiness.test.mjs +113 -0
- package/builder/module-declarations.mjs +594 -0
- package/builder/module-declarations.test.mjs +435 -0
- package/builder/native-kernels.mjs +60 -0
- package/builder/native-lua.d.ts +57 -0
- package/builder/native-routes.mjs +51 -0
- package/builder/no-static-ref-read.mjs +93 -0
- package/builder/no-static-ref-read.test.mjs +181 -0
- package/builder/secure-snippet.mjs +317 -0
- package/builder/secure-snippet.test.mjs +101 -0
- package/builder/shared-lua-runtime.mjs +150 -0
- package/builder/src/addon-link.lua +29 -0
- package/builder/src/arrays.lua +260 -0
- package/builder/src/assets.rs +177 -0
- package/builder/src/classes.lua +75 -0
- package/builder/src/collections.lua +190 -0
- package/builder/src/compiler.rs +2336 -0
- package/builder/src/config.rs +42 -0
- package/builder/src/entries.rs +166 -0
- package/builder/src/errors.lua +15 -0
- package/builder/src/lua_data.rs +231 -0
- package/builder/src/main.rs +381 -0
- package/builder/src/native_ir.rs +65 -0
- package/builder/src/native_signal.rs +83 -0
- package/builder/src/numbers.lua +76 -0
- package/builder/src/project-front.mjs +3682 -0
- package/builder/src/records.lua +75 -0
- package/builder/src/routes.rs +124 -0
- package/builder/src/setup-store.lua +18 -0
- package/builder/src/signal-kernel.fingerprint +1 -0
- package/builder/src/strings.lua +103 -0
- package/builder/src/ts-lower.mjs +68 -0
- package/builder/src/wow-reads.lua +22 -0
- package/builder/src/wow_client.rs +253 -0
- package/builder/src/wow_types.rs +564 -0
- package/builder/style-modules.mjs +93 -0
- package/builder/style-states.mjs +100 -0
- package/builder/style-states.test.mjs +103 -0
- package/builder/vite-assets.mjs +53 -0
- package/builder/vite-project.mjs +10 -0
- package/config.ts +59 -0
- package/eslint.mjs +74 -0
- package/form/index.ts +526 -0
- package/form/package.json +13 -0
- package/motion/index.ts +2 -0
- package/motion/package.json +10 -0
- package/package.json +26 -4
- package/router/index.ts +50 -0
- package/router/navigation.ts +22 -0
- package/router/package.json +12 -0
- package/router/router-view.ts +134 -0
- package/router/routes.ts +64 -0
- package/scripts/addon-build.mjs +364 -0
- package/scripts/addon-project.mjs +78 -0
- package/scripts/kumi-cli.mjs +105 -0
- package/scripts/link-addons.mjs +61 -0
- package/src/bindings.ts +35 -0
- package/src/context.ts +15 -0
- package/src/css-tokens.ts +239 -0
- package/src/css-v1.ts +68 -0
- package/src/cvars.ts +91 -0
- package/src/element-node.ts +32 -0
- package/src/elements.ts +505 -0
- package/src/feature-scope.ts +82 -0
- package/src/flex-layout.ts +807 -0
- package/src/frame-scheduler.ts +336 -0
- package/src/grid-tracks.ts +165 -0
- package/src/image-imports.d.ts +24 -0
- package/src/images.ts +79 -0
- package/src/index.ts +29 -0
- package/src/jsx-dev-runtime.ts +2 -0
- package/src/jsx-runtime.ts +29 -0
- package/src/jsx.d.ts +12 -0
- package/src/keyed-list.ts +366 -0
- package/src/media-query.ts +144 -0
- package/src/module-ui.ts +147 -0
- package/src/module.ts +311 -0
- package/src/node-selectors.ts +114 -0
- package/src/owned-collections.ts +52 -0
- package/src/providers.ts +241 -0
- package/src/reactive-scope.ts +34 -0
- package/src/reactivity.ts +275 -0
- package/src/result.ts +64 -0
- package/src/runtime.ts +52 -0
- package/src/scheduler.ts +185 -0
- package/src/signal-kernel.ts +63 -0
- package/src/style-classes.ts +51 -0
- package/src/style-states.ts +134 -0
- package/src/style-variables.ts +53 -0
- package/src/text-children.ts +42 -0
- package/src/theme.ts +50 -0
- package/src/transition.ts +18 -0
- package/state/index.ts +9 -0
- package/state/package.json +12 -0
- package/state/setup-store-persistence.ts +206 -0
- package/state/setup-store-view.ts +10 -0
- package/state/setup-store.ts +342 -0
- package/state/store-bindings.ts +25 -0
- package/state/store.ts +84 -0
- package/styles/_layers.scss +14 -0
- package/templates/addon/.agents/skills/kumi-build-debug/SKILL.md +36 -0
- package/templates/addon/.agents/skills/kumi-feature/SKILL.md +50 -0
- package/templates/addon/.agents/skills/kumi-plugin/SKILL.md +36 -0
- package/templates/addon/.agents/skills/kumi-store/SKILL.md +47 -0
- package/templates/addon/.agents/skills/kumi-ui/SKILL.md +73 -0
- package/templates/addon/.agents/skills/kumi-wow-api/SKILL.md +30 -0
- package/templates/addon/.claude/skills/kumi-build-debug/SKILL.md +36 -0
- package/templates/addon/.claude/skills/kumi-feature/SKILL.md +50 -0
- package/templates/addon/.claude/skills/kumi-plugin/SKILL.md +36 -0
- package/templates/addon/.claude/skills/kumi-store/SKILL.md +47 -0
- package/templates/addon/.claude/skills/kumi-ui/SKILL.md +73 -0
- package/templates/addon/.claude/skills/kumi-wow-api/SKILL.md +30 -0
- package/templates/addon/AGENTS.md +34 -0
- package/templates/addon/Assets/Art/Corner10.tga +0 -0
- package/templates/addon/Assets/Art/Corner11.tga +0 -0
- package/templates/addon/Assets/Art/Corner12.tga +0 -0
- package/templates/addon/Assets/Art/Corner13.tga +0 -0
- package/templates/addon/Assets/Art/Corner14.tga +0 -0
- package/templates/addon/Assets/Art/Corner15.tga +0 -0
- package/templates/addon/Assets/Art/Corner16.tga +0 -0
- package/templates/addon/Assets/Art/Corner2.tga +0 -0
- package/templates/addon/Assets/Art/Corner3.tga +0 -0
- package/templates/addon/Assets/Art/Corner4.tga +0 -0
- package/templates/addon/Assets/Art/Corner5.tga +0 -0
- package/templates/addon/Assets/Art/Corner6.tga +0 -0
- package/templates/addon/Assets/Art/Corner7.tga +0 -0
- package/templates/addon/Assets/Art/Corner8.tga +0 -0
- package/templates/addon/Assets/Art/Corner9.tga +0 -0
- package/templates/addon/Assets/Art/Dot.tga +0 -0
- package/templates/addon/Assets/Art/Gear.tga +0 -0
- package/templates/addon/Assets/Art/Grip.tga +0 -0
- package/templates/addon/Assets/Art/Outline10.tga +0 -0
- package/templates/addon/Assets/Art/Outline12.tga +0 -0
- package/templates/addon/Assets/Art/Outline13.tga +0 -0
- package/templates/addon/Assets/Art/Outline14.tga +0 -0
- package/templates/addon/Assets/Art/Outline15.tga +0 -0
- package/templates/addon/Assets/Art/Outline2.tga +0 -0
- package/templates/addon/Assets/Art/Outline3.tga +0 -0
- package/templates/addon/Assets/Art/Outline5.tga +0 -0
- package/templates/addon/Assets/Art/Outline7.tga +0 -0
- package/templates/addon/Assets/Art/Outline9.tga +0 -0
- package/templates/addon/Assets/Art/Round11.tga +0 -0
- package/templates/addon/Assets/Art/Round11Border.tga +0 -0
- package/templates/addon/Assets/Art/Round4.tga +0 -0
- package/templates/addon/Assets/Art/Round4Border.tga +0 -0
- package/templates/addon/Assets/Art/Round6.tga +0 -0
- package/templates/addon/Assets/Art/Round6Border.tga +0 -0
- package/templates/addon/Assets/Art/Round8.tga +0 -0
- package/templates/addon/Assets/Art/Round8Border.tga +0 -0
- package/templates/addon/Assets/Art/Search.tga +0 -0
- package/templates/addon/CLAUDE.md +1 -0
- package/templates/addon/README.md +49 -0
- package/templates/addon/eslint.config.mjs +6 -0
- package/templates/addon/gitignore +9 -0
- package/templates/addon/kumi.config.ts +17 -0
- package/templates/addon/package.json +20 -0
- package/templates/addon/src/app/app.module.ts +18 -0
- package/templates/addon/src/app/commands.store.ts +11 -0
- package/templates/addon/src/app/layout/AppWindow.module.scss +92 -0
- package/templates/addon/src/app/layout/AppWindow.tsx +32 -0
- package/templates/addon/src/app/main.ts +5 -0
- package/templates/addon/src/app/routes/(window)/home/page.tsx +8 -0
- package/templates/addon/src/app/routes/(window)/plugins/page.tsx +38 -0
- package/templates/addon/src/app/routes/(window)/settings/page.tsx +8 -0
- package/templates/addon/src/app/theme.ts +6 -0
- package/templates/addon/src/modules/greeting/api/player.api.ts +29 -0
- package/templates/addon/src/modules/greeting/greeting.module.ts +18 -0
- package/templates/addon/src/modules/greeting/model/greeting.store.ts +81 -0
- package/templates/addon/src/modules/greeting/services/greeting.service.ts +38 -0
- package/templates/addon/src/modules/greeting/ui/Greeting.module.scss +105 -0
- package/templates/addon/src/modules/greeting/ui/GreetingCard.tsx +29 -0
- package/templates/addon/src/modules/greeting/widgets/GreetingHud.tsx +54 -0
- package/templates/addon/src/modules/greeting/widgets/GreetingOverview.tsx +18 -0
- package/templates/addon/src/modules/greeting/widgets/GreetingSettings.tsx +56 -0
- package/templates/addon/src/modules/playtime/api/clock.api.ts +6 -0
- package/templates/addon/src/modules/playtime/model/playtime.store.ts +19 -0
- package/templates/addon/src/modules/playtime/playtime.module.ts +18 -0
- package/templates/addon/src/modules/playtime/services/playtime.service.ts +18 -0
- package/templates/addon/src/modules/playtime/ui/Playtime.module.scss +25 -0
- package/templates/addon/src/modules/playtime/ui/PlaytimeBadge.tsx +10 -0
- package/templates/addon/src/modules/playtime/widgets/PlaytimePage.tsx +16 -0
- package/templates/addon/src/shared/api/native-art.ts +28 -0
- package/templates/addon/src/shared/assets/close.png +0 -0
- package/templates/addon/src/shared/lib/format.ts +20 -0
- package/templates/addon/src/shared/styles/_tokens.scss +12 -0
- package/templates/addon/src/shared/ui/Button.tsx +29 -0
- package/templates/addon/src/shared/ui/Choice.tsx +34 -0
- package/templates/addon/src/shared/ui/Controls.module.scss +93 -0
- package/templates/addon/src/shared/ui/Glyph.tsx +18 -0
- package/templates/addon/src/shared/ui/Slider.tsx +25 -0
- package/templates/addon/src/shared/ui/Toggle.tsx +29 -0
- package/templates/addon/src/shared/ui/focus-ref.ts +7 -0
- package/templates/addon/src/shared/ui/range-skin.tsx +15 -0
- package/templates/addon/tsconfig.json +63 -0
- package/translate/index.ts +14 -0
- package/translate/package.json +9 -0
- package/utils/colors.ts +76 -0
- package/utils/format.ts +37 -0
- package/utils/index.ts +4 -0
- package/utils/number.ts +17 -0
- package/utils/package.json +7 -0
- package/utils/text.ts +6 -0
- package/validate/index.ts +119 -0
- package/validate/package.json +9 -0
- package/wow/absolute-position.ts +142 -0
- package/wow/action-bar-layout.ts +108 -0
- package/wow/action-button.ts +219 -0
- package/wow/action-catalog.ts +98 -0
- package/wow/addon-manifest.ts +36 -0
- package/wow/animation.ts +428 -0
- package/wow/app-ui.ts +221 -0
- package/wow/aura-button.ts +76 -0
- package/wow/aura-container.ts +591 -0
- package/wow/aura-countdown.ts +201 -0
- package/wow/aura-slot.ts +153 -0
- package/wow/bar-shade.ts +93 -0
- package/wow/borrowed-slot.ts +216 -0
- package/wow/button-drag.ts +48 -0
- package/wow/cast-clock.ts +153 -0
- package/wow/cast-text.ts +83 -0
- package/wow/class-colors.ts +126 -0
- package/wow/clock.ts +7 -0
- package/wow/color-picker.ts +128 -0
- package/wow/commands.ts +17 -0
- package/wow/contained-frame.ts +128 -0
- package/wow/contract.ts +42 -0
- package/wow/cooldown-timing.ts +24 -0
- package/wow/css-box.ts +144 -0
- package/wow/css-color.ts +12 -0
- package/wow/css-style.ts +109 -0
- package/wow/css-surfaces.ts +603 -0
- package/wow/css-text.ts +399 -0
- package/wow/cursor.ts +45 -0
- package/wow/cvar-schema.ts +32 -0
- package/wow/cvars.ts +98 -0
- package/wow/dropdown-art.ts +39 -0
- package/wow/element-click.ts +20 -0
- package/wow/element-event-coordinator.ts +219 -0
- package/wow/element-events.ts +317 -0
- package/wow/event-dispatcher.ts +151 -0
- package/wow/events.ts +50 -0
- package/wow/font-cache.ts +92 -0
- package/wow/frame-access.ts +53 -0
- package/wow/frame-layer.ts +5 -0
- package/wow/frame-timing.ts +13 -0
- package/wow/frames.ts +236 -0
- package/wow/heal-prediction.ts +305 -0
- package/wow/hooks.ts +133 -0
- package/wow/image-layers.ts +55 -0
- package/wow/index.ts +111 -0
- package/wow/layout-view.ts +663 -0
- package/wow/locale-font.ts +15 -0
- package/wow/lua-string.ts +18 -0
- package/wow/lua-table.ts +18 -0
- package/wow/macro-book.ts +84 -0
- package/wow/map-position.ts +27 -0
- package/wow/media-query.ts +65 -0
- package/wow/module-events.ts +11 -0
- package/wow/native-hooks.ts +168 -0
- package/wow/native-placement.ts +88 -0
- package/wow/native.ts +153 -0
- package/wow/number-format.ts +8 -0
- package/wow/number-input.ts +10 -0
- package/wow/panel-host.ts +97 -0
- package/wow/pixel.ts +35 -0
- package/wow/plugins.ts +246 -0
- package/wow/protect.ts +48 -0
- package/wow/protected-layout.ts +133 -0
- package/wow/protected-view.ts +103 -0
- package/wow/range-art.ts +81 -0
- package/wow/readable-api.ts +120 -0
- package/wow/reparent-frame.ts +99 -0
- package/wow/rounded-texture.ts +183 -0
- package/wow/saved-variables.ts +109 -0
- package/wow/scroll-view.ts +64 -0
- package/wow/secret-ref.ts +14 -0
- package/wow/secure-bindings.ts +89 -0
- package/wow/secure-clicks.ts +432 -0
- package/wow/secure-snippet.ts +235 -0
- package/wow/secure-state.ts +130 -0
- package/wow/secure-target-visibility.ts +89 -0
- package/wow/secure-transaction.ts +331 -0
- package/wow/special-window.ts +269 -0
- package/wow/spell-cooldown.ts +36 -0
- package/wow/start-addon.ts +122 -0
- package/wow/state-paint.ts +256 -0
- package/wow/transition.ts +86 -0
- package/wow/unit-button.ts +39 -0
- package/wow/unit-cast.ts +92 -0
- package/wow/unit-health-text.ts +47 -0
- package/wow/view-nodes.ts +304 -0
- package/wow/view.ts +1864 -0
- package/wow/visible-frame-job.ts +34 -0
- package/wow/width-reserve.ts +108 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
const localClass = /^\.([a-z][a-zA-Z0-9]*)$/;
|
|
2
|
+
const styleStates = new Set(["hover", "active", "focus", "disabled", "checked"]);
|
|
3
|
+
const hexColor = /^#[0-9a-f]{6}(?:[0-9a-f]{2})?$/i;
|
|
4
|
+
const rgbaColor = /^rgba\(\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)\s*,\s*(\d*\.?\d+)\s*\)$/i;
|
|
5
|
+
const opacity = /^(?:0(?:\.\d+)?|1(?:\.0+)?)$/;
|
|
6
|
+
const tokenReference = /^var\((--[a-z][\w-]*)\)$/;
|
|
7
|
+
const textureUrl = /^url\(\s*(["'])([^"']+)\1\s*\)$/;
|
|
8
|
+
const textureAtlas = /^atlas\(\s*(?:([\w-]+)|(["'])([\w-]+)\2)\s*\)$/;
|
|
9
|
+
const pathSegment = /^[\w-](?:[\w. -]*[\w-])?$/;
|
|
10
|
+
|
|
11
|
+
export function parseLocalStyleSelector(selector) {
|
|
12
|
+
const [base, ...when] = selector.split(":");
|
|
13
|
+
const match = localClass.exec(base);
|
|
14
|
+
if (!match) throw new Error("Expected a single local class in camelCase");
|
|
15
|
+
|
|
16
|
+
const seen = new Set();
|
|
17
|
+
for (const state of when) {
|
|
18
|
+
if (!styleStates.has(state)) throw new Error(`Unsupported style state :${state}`);
|
|
19
|
+
if (seen.has(state)) throw new Error(`Duplicate style state :${state}`);
|
|
20
|
+
seen.add(state);
|
|
21
|
+
}
|
|
22
|
+
return { name: match[1], when };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function parseBackgroundImage(value) {
|
|
26
|
+
const atlas = textureAtlas.exec(value);
|
|
27
|
+
if (atlas) return { atlas: atlas[1] ?? atlas[3] };
|
|
28
|
+
|
|
29
|
+
const path = textureUrl.exec(value)?.[2];
|
|
30
|
+
if (path === undefined) return;
|
|
31
|
+
const relative = path.startsWith("./") ? path.slice(2) : path;
|
|
32
|
+
if (relative.split("/").every(segment => pathSegment.test(segment))) return { path };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function parseStyleColor(value) {
|
|
36
|
+
if (hexColor.test(value)) return value;
|
|
37
|
+
const rgba = rgbaColor.exec(value);
|
|
38
|
+
if (!rgba) return;
|
|
39
|
+
const [red, green, blue, alpha] = rgba.slice(1).map(Number);
|
|
40
|
+
if (red > 255 || green > 255 || blue > 255 || alpha > 1) return;
|
|
41
|
+
const bytes = alpha === 1 ? [red, green, blue] : [red, green, blue, alpha * 255];
|
|
42
|
+
return "#" + bytes.map(channel => Math.round(channel).toString(16).padStart(2, "0")).join("");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function stateOpacity(value) {
|
|
46
|
+
if (opacity.test(value)) return Number(value);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const stateProperties = {
|
|
50
|
+
color: ["color", parseStyleColor],
|
|
51
|
+
"background-color": ["backgroundColor", parseStyleColor],
|
|
52
|
+
"border-color": ["borderColor", parseStyleColor],
|
|
53
|
+
opacity: ["opacity", stateOpacity],
|
|
54
|
+
"background-image": ["backgroundImage", parseBackgroundImage],
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export function supportsStateProperty(property) {
|
|
58
|
+
return Object.hasOwn(stateProperties, property);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function parseStateDeclaration(property, input, tokens) {
|
|
62
|
+
if (!supportsStateProperty(property)) {
|
|
63
|
+
throw new Error(`Unsupported property ${property} in a style state`);
|
|
64
|
+
}
|
|
65
|
+
const [key, parse] = stateProperties[property];
|
|
66
|
+
const token = tokenReference.exec(input)?.[1];
|
|
67
|
+
if (token && !tokens?.has(token)) throw new Error(`Unknown token ${token}`);
|
|
68
|
+
|
|
69
|
+
const value = parse(token ? tokens.get(token) : input);
|
|
70
|
+
if (value === undefined) throw new Error(`Invalid value for ${property}: ${input}`);
|
|
71
|
+
return [key, token && parse === parseStyleColor ? `var(${token}, ${value})` : value];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// A stable sort preserves declaration order when specificity and disabled match.
|
|
75
|
+
export function compareStyleStates(left, right) {
|
|
76
|
+
return left.when.length - right.when.length
|
|
77
|
+
|| Number(left.when.includes("disabled")) - Number(right.when.includes("disabled"));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function parseMediaQuery(condition, breakpoints) {
|
|
81
|
+
if (/^\(\s*prefers-reduced-motion\s*:\s*reduce\s*\)$/.test(condition)) return { reducedMotion: true };
|
|
82
|
+
const width = /^\(\s*(min|max)-width\s*:\s*(\d+)px\s*\)$/.exec(condition);
|
|
83
|
+
if (width === null) throw new Error(`Unsupported media query ${condition}`);
|
|
84
|
+
const breakpoint = breakpoints.get(Number(width[2]));
|
|
85
|
+
if (breakpoint === undefined) throw new Error(`Undefined media breakpoint ${width[2]}px`);
|
|
86
|
+
return width[1] === "min" ? { minWidth: breakpoint } : { maxWidth: breakpoint };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const mediaProperties = new Set([
|
|
90
|
+
"color", "background-color", "opacity", "display", "width", "height", "min-width", "min-height", "max-width", "max-height",
|
|
91
|
+
"top", "right", "bottom", "left", "padding", "margin", "gap", "row-gap", "column-gap", "flex-grow", "flex-shrink",
|
|
92
|
+
"flex-basis", "flex-direction", "justify-content", "align-items", "align-self", "justify-items", "grid-template-columns",
|
|
93
|
+
"grid-template-rows", "grid-column",
|
|
94
|
+
]);
|
|
95
|
+
|
|
96
|
+
export function assertMediaProperties(declarations) {
|
|
97
|
+
for (const declaration of declarations) {
|
|
98
|
+
if (!mediaProperties.has(declaration.prop)) throw declaration.error(`Unsupported property ${declaration.prop} in a media query`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { test } from "node:test";
|
|
3
|
+
import { compareStyleStates, parseLocalStyleSelector, parseMediaQuery, parseStateDeclaration } from "./style-states.mjs";
|
|
4
|
+
|
|
5
|
+
test("resolves media widths to known breakpoint names at build time", () => {
|
|
6
|
+
const widths = new Map([[0, "base"], [530, "compact"], [760, "narrow"]]);
|
|
7
|
+
assert.deepEqual(parseMediaQuery("(min-width: 530px)", widths), { minWidth: "compact" });
|
|
8
|
+
assert.deepEqual(parseMediaQuery("(max-width: 760px)", widths), { maxWidth: "narrow" });
|
|
9
|
+
assert.deepEqual(parseMediaQuery("(prefers-reduced-motion: reduce)", widths), { reducedMotion: true });
|
|
10
|
+
assert.throws(() => parseMediaQuery("(max-width: 640px)", widths), /Undefined media breakpoint/);
|
|
11
|
+
assert.throws(() => parseMediaQuery("(orientation: landscape)", widths), /Unsupported media query/);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
test("reads the existing base syntax and single or combined state selectors", () => {
|
|
15
|
+
assert.deepEqual(parseLocalStyleSelector(".tabItem1"), { name: "tabItem1", when: [] });
|
|
16
|
+
for (const state of ["hover", "active", "focus", "disabled", "checked"]) {
|
|
17
|
+
assert.deepEqual(parseLocalStyleSelector(`.tab:${state}`), { name: "tab", when: [state] });
|
|
18
|
+
}
|
|
19
|
+
assert.deepEqual(parseLocalStyleSelector(".tab:checked:hover"), { name: "tab", when: ["checked", "hover"] });
|
|
20
|
+
assert.deepEqual(parseLocalStyleSelector(".tab:active:focus:disabled"), {
|
|
21
|
+
name: "tab", when: ["active", "focus", "disabled"],
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test("rejects duplicate and unsupported states and selector shapes", () => {
|
|
26
|
+
assert.throws(() => parseLocalStyleSelector(".tab:hover:checked:hover"), /Duplicate style state :hover/);
|
|
27
|
+
assert.throws(() => parseLocalStyleSelector(".tab:selected"), /Unsupported style state :selected/);
|
|
28
|
+
for (const selector of [
|
|
29
|
+
".Tab:hover", ".tab-item:hover", "#tab:hover", "tab:hover", ".tab:hover:",
|
|
30
|
+
".tab::before", ".tab:not(:checked)", ".tab:has(.child)", ".tab:nth-child(2)",
|
|
31
|
+
".tab:hover, .other:active", ".tab .child:hover", ".tab:hover .child", ".tab:hover + .other",
|
|
32
|
+
".tab:hover > .other", ".tab:hover[part=x]", ".tab:hover.other", ".tab :hover",
|
|
33
|
+
]) {
|
|
34
|
+
assert.throws(() => parseLocalStyleSelector(selector), { name: "Error" }, selector);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test("parses state paint in the native style format and resolves typed tokens", () => {
|
|
39
|
+
const tokens = new Map([["--bright", "#aBC102"], ["--dim", "0.5"], ["--tab-art", "atlas(tab-active)"]]);
|
|
40
|
+
assert.deepEqual(parseStateDeclaration("color", "#aBC102"), ["color", "#aBC102"]);
|
|
41
|
+
assert.deepEqual(parseStateDeclaration("background-color", "#123456"), ["backgroundColor", "#123456"]);
|
|
42
|
+
assert.deepEqual(parseStateDeclaration("border-color", "#aBC102"), ["borderColor", "#aBC102"]);
|
|
43
|
+
assert.deepEqual(parseStateDeclaration("color", "var(--bright)", tokens), ["color", "var(--bright, #aBC102)"]);
|
|
44
|
+
assert.deepEqual(parseStateDeclaration("background-color", "var(--bright)", tokens), [
|
|
45
|
+
"backgroundColor", "var(--bright, #aBC102)",
|
|
46
|
+
]);
|
|
47
|
+
assert.deepEqual(parseStateDeclaration("border-color", "var(--bright)", tokens), ["borderColor", "var(--bright, #aBC102)"]);
|
|
48
|
+
assert.deepEqual(parseStateDeclaration("opacity", "0"), ["opacity", 0]);
|
|
49
|
+
assert.deepEqual(parseStateDeclaration("opacity", "1.000"), ["opacity", 1]);
|
|
50
|
+
assert.deepEqual(parseStateDeclaration("opacity", "var(--dim)", tokens), ["opacity", 0.5]);
|
|
51
|
+
assert.deepEqual(parseStateDeclaration("background-image", "var(--tab-art)", tokens), [
|
|
52
|
+
"backgroundImage", { atlas: "tab-active" },
|
|
53
|
+
]);
|
|
54
|
+
|
|
55
|
+
for (const property of ["width", "padding", "gap", "position", "display", "font-size", "z-index", "__proto__"]) {
|
|
56
|
+
assert.throws(() => parseStateDeclaration(property, "0"), /Unsupported property .* in a style state/);
|
|
57
|
+
}
|
|
58
|
+
assert.throws(() => parseStateDeclaration("color", "var(--missing)", tokens), /Unknown token --missing/);
|
|
59
|
+
assert.throws(() => parseStateDeclaration("color", "var(--dim)", tokens), /Invalid value for color/);
|
|
60
|
+
assert.throws(() => parseStateDeclaration("opacity", "var(--bright)", tokens), /Invalid value for opacity/);
|
|
61
|
+
assert.throws(() => parseStateDeclaration("color", "red"), /Invalid value for color/);
|
|
62
|
+
for (const value of ["1.001", "-0.1", "50%", "Infinity"]) {
|
|
63
|
+
assert.throws(() => parseStateDeclaration("opacity", value), /Invalid value for opacity/);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test("allows a single local texture path or atlas", () => {
|
|
68
|
+
assert.deepEqual(parseStateDeclaration("background-image", 'url("Interface/AddOns/Kumi/Textures/Tab Active.tga")'), [
|
|
69
|
+
"backgroundImage", { path: "Interface/AddOns/Kumi/Textures/Tab Active.tga" },
|
|
70
|
+
]);
|
|
71
|
+
assert.deepEqual(parseStateDeclaration("background-image", "url( './textures/tab.blp' )"), [
|
|
72
|
+
"backgroundImage", { path: "./textures/tab.blp" },
|
|
73
|
+
]);
|
|
74
|
+
assert.deepEqual(parseStateDeclaration("background-image", "atlas(UI-Panel_Active)"), [
|
|
75
|
+
"backgroundImage", { atlas: "UI-Panel_Active" },
|
|
76
|
+
]);
|
|
77
|
+
assert.deepEqual(parseStateDeclaration("background-image", 'atlas("UI-Panel_Active")'), [
|
|
78
|
+
"backgroundImage", { atlas: "UI-Panel_Active" },
|
|
79
|
+
]);
|
|
80
|
+
|
|
81
|
+
for (const value of [
|
|
82
|
+
'url("https://example.com/tab.tga")', 'url("//example.com/tab.tga")', 'url("data:image/png;base64,ABC")',
|
|
83
|
+
'url("file:///tab.tga")', 'url("C:/tab.tga")', 'url("/tab.tga")', 'url("../tab.tga")',
|
|
84
|
+
'url("textures/../tab.tga")', 'url("textures/%2e%2e/tab.tga")', 'url("textures\\..\\tab.tga")',
|
|
85
|
+
'url("textures//tab.tga")', 'url("tab.tga?query")', 'url("tab.tga#fragment")',
|
|
86
|
+
'url("tab.tga"), url("other.tga")', 'url("tab.tga") center', 'url("")', "url(tab.tga)",
|
|
87
|
+
'atlas("x/y")', 'atlas("x y")', "atlas()", "linear-gradient(#123456, #ffffff)", "none",
|
|
88
|
+
]) {
|
|
89
|
+
assert.throws(() => parseStateDeclaration("background-image", value), /Invalid value for background-image/, value);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test("orders by specificity, disabled tiebreak, then source", () => {
|
|
94
|
+
const selectors = [
|
|
95
|
+
".tab:focus:checked", ".tab:checked:disabled", ".tab:disabled", ".tab:hover",
|
|
96
|
+
".tab:active", ".tab:disabled:hover", ".tab:checked:hover", ".tab:hover:checked", ".tab",
|
|
97
|
+
];
|
|
98
|
+
const variants = selectors.map(selector => ({ ...parseLocalStyleSelector(selector), selector, paint: {} }));
|
|
99
|
+
assert.deepEqual(variants.sort(compareStyleStates).map(({ selector }) => selector), [
|
|
100
|
+
".tab", ".tab:hover", ".tab:active", ".tab:disabled", ".tab:focus:checked",
|
|
101
|
+
".tab:checked:hover", ".tab:hover:checked", ".tab:checked:disabled", ".tab:disabled:hover",
|
|
102
|
+
]);
|
|
103
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { readFile } from "node:fs/promises";
|
|
4
|
+
import { resolve } from "node:path";
|
|
5
|
+
import { promisify } from "node:util";
|
|
6
|
+
|
|
7
|
+
const imageExtension = /\.(?:png|jpe?g|webp|tga)$/;
|
|
8
|
+
const prefix = "\0kumi-image:";
|
|
9
|
+
const tgaQuery = "?kumi-tga";
|
|
10
|
+
const run = promisify(execFile);
|
|
11
|
+
|
|
12
|
+
export function viteImageAssets({ pack, cacheDir } = {}) {
|
|
13
|
+
return {
|
|
14
|
+
name: "kumi-image-assets",
|
|
15
|
+
enforce: "pre",
|
|
16
|
+
async resolveId(source, importer) {
|
|
17
|
+
if (!importer || !imageExtension.test(source) || !/^\.\.?\//.test(source)) return;
|
|
18
|
+
if (source.endsWith(".tga")) {
|
|
19
|
+
const resolved = await this.resolve(source, importer, { skipSelf: true });
|
|
20
|
+
if (resolved) return resolved.id + tgaQuery;
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const resolved = await this.resolve(source + "?url", importer, { skipSelf: true });
|
|
24
|
+
if (resolved) return prefix + resolved.id;
|
|
25
|
+
},
|
|
26
|
+
async load(id) {
|
|
27
|
+
if (id.endsWith(tgaQuery)) {
|
|
28
|
+
if (!pack || !cacheDir) throw new Error("Set pack and cacheDir in viteImageAssets to preview TGA images");
|
|
29
|
+
const file = id.slice(0, -tgaQuery.length);
|
|
30
|
+
this.addWatchFile(file);
|
|
31
|
+
const source = await readFile(file);
|
|
32
|
+
const hash = createHash("sha256").update(source).digest("hex");
|
|
33
|
+
const png = resolve(cacheDir, hash + ".png");
|
|
34
|
+
let data;
|
|
35
|
+
try {
|
|
36
|
+
data = await readFile(png);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
if (error.code !== "ENOENT") throw error;
|
|
39
|
+
const conversion = run(pack, ["image", "-", "--image-input-tga", "--image-output", png], { windowsHide: true });
|
|
40
|
+
conversion.child.stdin.on("error", () => {});
|
|
41
|
+
conversion.child.stdin.end(source);
|
|
42
|
+
await conversion;
|
|
43
|
+
data = await readFile(png);
|
|
44
|
+
}
|
|
45
|
+
const image = { path: "data:image/png;base64," + data.toString("base64"),
|
|
46
|
+
width: data.readUInt32BE(16), height: data.readUInt32BE(20) };
|
|
47
|
+
return `export default ${JSON.stringify(image)};`;
|
|
48
|
+
}
|
|
49
|
+
if (!id.startsWith(prefix)) return;
|
|
50
|
+
return `import path from ${JSON.stringify(id.slice(prefix.length))}; export default { path };`;
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
|
|
3
|
+
export function viteProjectAliases({ root, source = "src" } = {}) {
|
|
4
|
+
return {
|
|
5
|
+
name: "kumi-project-aliases",
|
|
6
|
+
config(config) {
|
|
7
|
+
return { resolve: { alias: { "@": resolve(root ?? config.root ?? process.cwd(), source) } } };
|
|
8
|
+
},
|
|
9
|
+
};
|
|
10
|
+
}
|
package/config.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for `kumi.config.ts`. Write the config as a plain object:
|
|
3
|
+
*
|
|
4
|
+
* ```ts
|
|
5
|
+
* import type { KumiConfig } from "@overmvp/kumi/config";
|
|
6
|
+
*
|
|
7
|
+
* export default {
|
|
8
|
+
* addon: { name: "MyAddon", title: "My Addon", savedVariables: "MyAddonDB" },
|
|
9
|
+
* } satisfies KumiConfig;
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export interface KumiConfig {
|
|
13
|
+
/** The main addon. Kumi writes its TOC from these fields. */
|
|
14
|
+
readonly addon: AddonConfig;
|
|
15
|
+
/**
|
|
16
|
+
* Optional parts that players turn on or off in the addon list, keyed by plugin ID
|
|
17
|
+
* (lowercase letters, digits and dashes). Each plugin is built as its own addon folder, `<name>_<id>`.
|
|
18
|
+
*/
|
|
19
|
+
readonly plugins?: Readonly<Record<string, PluginConfig>>;
|
|
20
|
+
/** Whether turning a plugin on or off applies to the current character or to every character. Defaults to `"account"`. */
|
|
21
|
+
readonly pluginState?: "account" | "character";
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface AddonConfig {
|
|
25
|
+
/** Folder and TOC name: a letter followed by letters, digits, `_` or `-`. */
|
|
26
|
+
readonly name: string;
|
|
27
|
+
/** The title shown in the addon list. */
|
|
28
|
+
readonly title: string;
|
|
29
|
+
readonly notes?: string;
|
|
30
|
+
readonly author?: string;
|
|
31
|
+
readonly version?: string;
|
|
32
|
+
/** A texture inside the addon folder, such as `Assets/Art/Icon.tga`. Plugins reuse it. */
|
|
33
|
+
readonly icon?: string;
|
|
34
|
+
/** Interface numbers per client. `kumi build --target` picks one. Kumi has defaults for both clients. */
|
|
35
|
+
readonly interface?: { readonly retail?: number | readonly number[]; readonly forever?: number | readonly number[] };
|
|
36
|
+
/** Account-wide SavedVariables global. Persisted stores save under their ID here unless they pass a storage. */
|
|
37
|
+
readonly savedVariables?: string;
|
|
38
|
+
/** Per-character SavedVariables global. */
|
|
39
|
+
readonly savedVariablesPerCharacter?: string;
|
|
40
|
+
/** Addons that load before this one when they are installed. */
|
|
41
|
+
readonly optionalDependencies?: readonly string[];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface PluginConfig {
|
|
45
|
+
/** The plugin's module file under `src`, for example `src/modules/history/history.module.ts`. */
|
|
46
|
+
readonly module: string;
|
|
47
|
+
/** The name of the exported `@Module` class. Needed only when the file exports more than one module. */
|
|
48
|
+
readonly export?: string;
|
|
49
|
+
/** The plugin's name in the addon list and in `usePlugins()`. */
|
|
50
|
+
readonly title: string;
|
|
51
|
+
readonly notes?: string;
|
|
52
|
+
/**
|
|
53
|
+
* `"startup"` (default): WoW loads the plugin with the addon while it is enabled.
|
|
54
|
+
* `"demand"`: the plugin loads the first time the addon calls `load()` for it.
|
|
55
|
+
*/
|
|
56
|
+
readonly load?: "startup" | "demand";
|
|
57
|
+
/** Whether the plugin starts enabled on a fresh install. Defaults to `true`. */
|
|
58
|
+
readonly enabled?: boolean;
|
|
59
|
+
}
|
package/eslint.mjs
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// Kumi's project rules: the layer order inside a feature, public module APIs and the WoW boundary.
|
|
2
|
+
//
|
|
3
|
+
// import ts from "@typescript-eslint/eslint-plugin";
|
|
4
|
+
// import parser from "@typescript-eslint/parser";
|
|
5
|
+
// import { kumiRules } from "<kumi package>/eslint.mjs";
|
|
6
|
+
// export default kumiRules({ parser, plugin: ts });
|
|
7
|
+
import { readFileSync } from "node:fs";
|
|
8
|
+
|
|
9
|
+
const sdkPackage = JSON.parse(readFileSync(new URL("./package.json", import.meta.url), "utf8")).name;
|
|
10
|
+
|
|
11
|
+
const NATIVE_NAMES = ["api", "readableApi", "rawField", "setRawField", "createFrame", "reveal", "isSecret", "savedVariablesStorage"];
|
|
12
|
+
const GAME_GLOBALS = ["_G", "CreateFrame", "UIParent", "GameTooltip", "InCombatLockdown", "GetTime", "GetMoney", "GetCursorInfo",
|
|
13
|
+
"ClearCursor", "C_Container", "C_Item", "C_Spell", "C_SpellBook", "C_ToyBox", "C_AddOns", "C_Timer", "SlashCmdList", "geterrorhandler"];
|
|
14
|
+
|
|
15
|
+
const messages = {
|
|
16
|
+
deep: "Import Kumi through its @kumi/* paths. Deep package imports skip the project's rules.",
|
|
17
|
+
native: "Call WoW in the feature's api/ layer. Other layers use the api functions, services or hooks.",
|
|
18
|
+
module: "Use another feature through its <feature>.module.ts file, its public API.",
|
|
19
|
+
decorators: "Declare modules with @Module and services with @Injectable.",
|
|
20
|
+
shared: "Shared code is reusable: it does not import app or feature code.",
|
|
21
|
+
api: "api/ wraps WoW calls. It takes plain values and returns plain values; it does not import services, stores or UI.",
|
|
22
|
+
services: "services/ hold logic. They use the feature's api/ and never stores or UI.",
|
|
23
|
+
model: "Stores call services, never api/ directly, and do not import UI.",
|
|
24
|
+
ui: "Components read stores and render. Call services and WoW through stores.",
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const deepImports = { group: [sdkPackage + "/*", "**/node_modules/**"], message: messages.deep };
|
|
28
|
+
const nativeImport = { name: "@kumi/wow", importNames: NATIVE_NAMES, message: messages.native };
|
|
29
|
+
const generated = { name: "@kumi/wow-generated", message: messages.native };
|
|
30
|
+
const legacyModule = { name: "@kumi/core", importNames: ["defineModule"], message: messages.decorators };
|
|
31
|
+
// `../other/model/x` from a module file or `../../other/ui/x` from a layer. `shared/` and the own layers stay allowed.
|
|
32
|
+
const otherFeatureDeep = { regex: "^(?:\\.\\./)+(?!shared/|app/)[^/.][^/]*/(?:api|services|model|ui|widgets)(?:/|$)", message: messages.module };
|
|
33
|
+
|
|
34
|
+
function restrict(patterns, native) {
|
|
35
|
+
const paths = [legacyModule];
|
|
36
|
+
if (!native) paths.push(nativeImport, generated);
|
|
37
|
+
return ["error", { paths, patterns: [deepImports, ...patterns] }];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Flat ESLint config for a Kumi project. Pass the project's TypeScript ESLint parser and plugin. */
|
|
41
|
+
export function kumiRules({ parser, plugin, files = ["src/**/*.{ts,tsx}"] }) {
|
|
42
|
+
const layer = (folder, patterns, native = false) => ({
|
|
43
|
+
files: ["src/modules/*/" + folder + "/**/*.{ts,tsx}"],
|
|
44
|
+
rules: { "no-restricted-imports": restrict(patterns, native) },
|
|
45
|
+
});
|
|
46
|
+
return [{
|
|
47
|
+
files,
|
|
48
|
+
languageOptions: { parser },
|
|
49
|
+
plugins: { "@typescript-eslint": plugin },
|
|
50
|
+
rules: {
|
|
51
|
+
"no-debugger": "error",
|
|
52
|
+
"no-restricted-globals": ["error", ...GAME_GLOBALS.map(name => ({ name, message: messages.native }))],
|
|
53
|
+
"no-restricted-imports": restrict([otherFeatureDeep], false),
|
|
54
|
+
"no-restricted-syntax": ["error", {
|
|
55
|
+
selector: "CallExpression[callee.type='MemberExpression'][callee.property.name=/^(CreateFrame|CreateTexture|SetTexture|SetAttribute|SetVertexColor|SetPoint|SetScript)$/]",
|
|
56
|
+
message: "Declare frames, textures and scripts in JSX, or use a typed SDK helper.",
|
|
57
|
+
}],
|
|
58
|
+
"@typescript-eslint/consistent-type-imports": "error",
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
layer("api", [{ regex: "^(?:\\.\\./)+(?:services|model|ui|widgets)(?:/|$)", message: messages.api }, otherFeatureDeep], true),
|
|
62
|
+
layer("services", [{ regex: "^(?:\\.\\./)+(?:model|ui|widgets)(?:/|$)", message: messages.services }, otherFeatureDeep]),
|
|
63
|
+
layer("model", [{ regex: "^(?:\\.\\./)+(?:api|ui|widgets)(?:/|$)", message: messages.model }, otherFeatureDeep]),
|
|
64
|
+
layer("ui", [{ regex: "^(?:\\.\\./)+(?:api|services|widgets)(?:/|$)", message: messages.ui }, otherFeatureDeep]),
|
|
65
|
+
layer("widgets", [{ regex: "^(?:\\.\\./)+(?:api|services)(?:/|$)", message: messages.ui }, otherFeatureDeep]),
|
|
66
|
+
{
|
|
67
|
+
files: ["src/shared/**/*.{ts,tsx}"],
|
|
68
|
+
rules: { "no-restricted-imports": restrict([{ regex: "^(?:\\.\\./)+(?:app|modules)(?:/|$)", message: messages.shared }], false) },
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
files: ["src/shared/api/**/*.{ts,tsx}"],
|
|
72
|
+
rules: { "no-restricted-imports": restrict([{ regex: "^(?:\\.\\./)+(?:app|modules)(?:/|$)", message: messages.shared }], true) },
|
|
73
|
+
}];
|
|
74
|
+
}
|