@overmvp/kumi 0.3.0 → 0.5.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/animation/index.ts +4 -0
- package/animation/motion-policy.ts +20 -0
- package/animation/slide.ts +61 -0
- package/animation/spring.ts +75 -0
- package/animation/staggered-reveal.ts +34 -0
- package/builder/css-gradients.mjs +74 -0
- package/builder/css-mask-assets.mjs +52 -0
- package/builder/css-mask-assets.test.mjs +31 -0
- package/builder/css-v1.mjs +73 -22
- package/builder/css-v1.test.mjs +42 -2
- package/builder/module-declarations.mjs +2 -2
- package/builder/module-declarations.test.mjs +4 -2
- package/builder/src/compiler.rs +25 -0
- package/builder/src/lua_upvalues.rs +641 -0
- package/builder/src/main.rs +1 -0
- package/builder/style-modules.mjs +21 -3
- package/builder/style-modules.test.mjs +24 -0
- package/builder/style-states.mjs +6 -4
- package/package.json +1 -1
- package/router/index.ts +1 -0
- package/router/link.tsx +32 -0
- package/router/router-view.ts +5 -3
- package/scripts/addon-build.mjs +17 -2
- package/scripts/addon-project.mjs +22 -11
- package/scripts/kumi-cli.mjs +0 -0
- package/src/bindings.ts +10 -4
- package/src/context.ts +31 -7
- package/src/css-tokens.ts +11 -2
- package/src/css-v1.ts +3 -0
- package/src/elements.ts +20 -1
- package/src/flex-layout.ts +26 -5
- package/src/frame-scheduler.ts +3 -1
- package/src/index.ts +2 -2
- package/src/keyed-list.ts +9 -6
- package/src/module-ui.ts +22 -2
- package/src/module.ts +26 -7
- package/src/reactivity.ts +14 -1
- package/src/style-classes.ts +22 -1
- package/src/style-states.ts +13 -6
- package/state/setup-store.ts +3 -3
- package/templates/addon/.agents/skills/kumi-ui/SKILL.md +1 -1
- package/templates/addon/.claude/skills/kumi-ui/SKILL.md +1 -1
- package/templates/addon/AGENTS.md +1 -1
- package/templates/addon/kumi.config.ts +17 -17
- package/templates/addon/src/app/app.module.ts +3 -5
- package/templates/addon/src/app/layout/{AppWindow.module.scss → AppWindow.module.css} +10 -12
- package/templates/addon/src/modules/greeting/greeting.module.ts +2 -2
- package/templates/addon/src/modules/greeting/ui/{Greeting.module.scss → Greeting.module.css} +9 -11
- package/templates/addon/src/modules/playtime/playtime.module.ts +3 -5
- package/templates/addon/src/modules/playtime/ui/{Playtime.module.scss → Playtime.module.css} +3 -5
- package/templates/addon/src/shared/styles/tokens.css +13 -0
- package/templates/addon/src/shared/ui/{Controls.module.scss → Controls.module.css} +18 -20
- package/utils/format.ts +13 -0
- package/utils/index.ts +1 -1
- package/wow/action-button.ts +26 -1
- package/wow/addon-manifest.ts +2 -0
- package/wow/animation.ts +19 -18
- package/wow/app-ui.ts +150 -31
- package/wow/aura-container.ts +132 -38
- package/wow/aura-countdown.ts +19 -3
- package/wow/aura-follower.ts +32 -0
- package/wow/aura-view.ts +49 -0
- package/wow/css-background-image.ts +75 -0
- package/wow/css-box.ts +14 -9
- package/wow/css-image-mask.ts +32 -0
- package/wow/css-surfaces.ts +88 -35
- package/wow/element-events.ts +33 -13
- package/wow/frames.ts +2 -0
- package/wow/heal-prediction.ts +2 -4
- package/wow/hooks.ts +17 -0
- package/wow/hotkeys.ts +221 -0
- package/wow/index.ts +11 -6
- package/wow/initial-view.ts +99 -0
- package/wow/layout-view.ts +19 -10
- package/wow/module-replacements.ts +103 -0
- package/wow/native.ts +1 -0
- package/wow/pixel.ts +25 -0
- package/wow/pointer-click.ts +35 -0
- package/wow/protected-view.ts +49 -13
- package/wow/rounded-texture.ts +9 -4
- package/wow/scroll-view.ts +5 -4
- package/wow/state-paint.ts +5 -14
- package/wow/status-bar.ts +65 -0
- package/wow/texture-fill.ts +10 -0
- package/wow/unit-button.ts +25 -4
- package/wow/unit-cast.ts +6 -4
- package/wow/view-nodes.ts +11 -4
- package/wow/view.ts +387 -278
- package/templates/addon/src/shared/styles/_tokens.scss +0 -12
package/animation/index.ts
CHANGED
|
@@ -11,3 +11,7 @@ export type { AttentionOptions, BeaconOptions, BreatheOptions, BurstOptions, Dri
|
|
|
11
11
|
FloatOptions, GlimmerOptions, HeartbeatOptions, HopOptions, PopOptions, PulseOptions, RippleOptions, ShakeOptions, Side, SlideOptions,
|
|
12
12
|
SpinOptions } from "./presets";
|
|
13
13
|
export { createColorTransitions, type ColorTransitionOptions, type ColorTransitions } from "./color-transition";
|
|
14
|
+
export { configureAnimations, isReducedMotion, type AnimationDefaults, type MotionMode } from "./motion-policy";
|
|
15
|
+
export { useSlide, type SlideValueOptions } from "./slide";
|
|
16
|
+
export { useStaggeredReveal, type StaggeredReveal, type StaggeredRevealOptions } from "./staggered-reveal";
|
|
17
|
+
export { useSpring, type SpringOptions } from "./spring";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ref } from "../src/reactivity";
|
|
2
|
+
|
|
3
|
+
/** Reduced motion skips one-shot motion and freezes looping native animations. */
|
|
4
|
+
export type MotionMode = "full" | "reduced";
|
|
5
|
+
|
|
6
|
+
export interface AnimationDefaults {
|
|
7
|
+
/** Read when an animation has no `motion` option of its own. */
|
|
8
|
+
motion?: (this: void) => MotionMode;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const defaultMotion = ref<AnimationDefaults["motion"]>(undefined);
|
|
12
|
+
|
|
13
|
+
/** Set application-wide defaults for native animations and reactive slides. */
|
|
14
|
+
export function configureAnimations(this: void, options: AnimationDefaults): void {
|
|
15
|
+
defaultMotion.value = options.motion;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function isReducedMotion(this: void, motion?: AnimationDefaults["motion"]): boolean {
|
|
19
|
+
return (motion ?? defaultMotion.value)?.() === "reduced";
|
|
20
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { currentScope } from "../src/reactive-scope";
|
|
2
|
+
import { ref, type ReadonlyRef } from "../src/reactivity";
|
|
3
|
+
import { fail } from "../src/result";
|
|
4
|
+
import { easeProgress } from "./ease";
|
|
5
|
+
import { isReducedMotion, type AnimationDefaults } from "./motion-policy";
|
|
6
|
+
import type { Ease } from "./spec";
|
|
7
|
+
|
|
8
|
+
export interface SlideValueOptions {
|
|
9
|
+
/** Seconds to reach a new target. Defaults to 0.14. */
|
|
10
|
+
readonly duration?: number;
|
|
11
|
+
readonly ease?: Ease;
|
|
12
|
+
/** Overrides the application-wide motion preference for this slide. */
|
|
13
|
+
readonly motion?: AnimationDefaults["motion"];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Follow a reactive coordinate, continuing from the current position when the target changes. */
|
|
17
|
+
export function useSlide(this: void, read: (this: void) => number,
|
|
18
|
+
{ duration = 0.14, ease = "out", motion }: SlideValueOptions = {}): ReadonlyRef<number> {
|
|
19
|
+
const scope = currentScope();
|
|
20
|
+
if (scope === undefined || !scope.isActive()) throw new Error("useSlide requires an active scope");
|
|
21
|
+
const intervalMs = duration * 1000;
|
|
22
|
+
if (!Number.isFinite(intervalMs) || intervalMs < 0) throw new Error("Slide duration must be nonnegative and finite");
|
|
23
|
+
|
|
24
|
+
const initial = read();
|
|
25
|
+
if (!Number.isFinite(initial)) throw new Error("Slide target must be finite");
|
|
26
|
+
const value = ref(initial);
|
|
27
|
+
const frames = scope.frameJobs;
|
|
28
|
+
const nowMs = frames.nowMs;
|
|
29
|
+
const job = {};
|
|
30
|
+
let target = initial;
|
|
31
|
+
let from = initial;
|
|
32
|
+
let started = 0;
|
|
33
|
+
|
|
34
|
+
function step(this: void) {
|
|
35
|
+
const now = nowMs?.();
|
|
36
|
+
if (now === undefined || !Number.isFinite(now) || isReducedMotion(motion) || now - started >= intervalMs) {
|
|
37
|
+
value.value = target;
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
value.value = from + (target - from) * easeProgress(ease, (now - started) / intervalMs);
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const watched = scope.watch(() => ({ next: read(), reduced: isReducedMotion(motion) }), ({ next, reduced }) => {
|
|
45
|
+
if (!Number.isFinite(next)) return fail("Slide target must be finite");
|
|
46
|
+
if (next === target && !reduced) return;
|
|
47
|
+
frames.cancel(job);
|
|
48
|
+
target = next;
|
|
49
|
+
from = value.value;
|
|
50
|
+
const now = nowMs?.();
|
|
51
|
+
if (reduced || intervalMs === 0 || from === target || now === undefined || !Number.isFinite(now)) {
|
|
52
|
+
value.value = target;
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
started = now;
|
|
56
|
+
frames.queue(job, step, { label: "Slide" });
|
|
57
|
+
});
|
|
58
|
+
if (!watched.ok) throw new Error(watched.reason);
|
|
59
|
+
scope.onDispose(() => { frames.cancel(job); });
|
|
60
|
+
return value;
|
|
61
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { currentScope } from "../src/reactive-scope";
|
|
2
|
+
import { ref, type ReadonlyRef } from "../src/reactivity";
|
|
3
|
+
import { fail } from "../src/result";
|
|
4
|
+
import { isReducedMotion, type AnimationDefaults } from "./motion-policy";
|
|
5
|
+
|
|
6
|
+
export interface SpringOptions {
|
|
7
|
+
/** Natural frequency in hertz. Defaults to 4. */
|
|
8
|
+
readonly frequency?: number;
|
|
9
|
+
/** Distance below which a nearly stationary spring settles. Defaults to 0.01. */
|
|
10
|
+
readonly precision?: number;
|
|
11
|
+
readonly motion?: AnimationDefaults["motion"];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Follow a reactive target with a critically damped spring. Retargeting preserves velocity. */
|
|
15
|
+
export function useSpring(this: void, read: (this: void) => number,
|
|
16
|
+
{ frequency = 4, precision = 0.01, motion }: SpringOptions = {}): ReadonlyRef<number> {
|
|
17
|
+
const scope = currentScope();
|
|
18
|
+
if (scope === undefined || !scope.isActive()) throw new Error("useSpring requires an active scope");
|
|
19
|
+
const rate = 2 * Math.PI * frequency;
|
|
20
|
+
if (!Number.isFinite(rate) || rate <= 0) throw new Error("Spring frequency must be positive and finite");
|
|
21
|
+
if (!Number.isFinite(precision) || precision <= 0) throw new Error("Spring precision must be positive and finite");
|
|
22
|
+
let target = read();
|
|
23
|
+
if (!Number.isFinite(target)) throw new Error("Spring target must be finite");
|
|
24
|
+
|
|
25
|
+
const value = ref(target);
|
|
26
|
+
const frames = scope.frameJobs;
|
|
27
|
+
const nowMs = frames.nowMs;
|
|
28
|
+
const job = {};
|
|
29
|
+
let velocity = 0;
|
|
30
|
+
let previous = 0;
|
|
31
|
+
|
|
32
|
+
function settle() {
|
|
33
|
+
velocity = 0;
|
|
34
|
+
value.value = target;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function step(this: void) {
|
|
38
|
+
const now = nowMs?.();
|
|
39
|
+
if (now === undefined || !Number.isFinite(now) || isReducedMotion(motion)) return settle();
|
|
40
|
+
const elapsed = Math.max(0, (now - previous) / 1000);
|
|
41
|
+
previous = now;
|
|
42
|
+
if (elapsed === 0) return true;
|
|
43
|
+
|
|
44
|
+
// Closed-form critical damping preserves the same trajectory across different frame intervals.
|
|
45
|
+
const distance = value.value - target;
|
|
46
|
+
const tangent = (velocity + rate * distance) * elapsed;
|
|
47
|
+
const decay = Math.exp(-rate * elapsed);
|
|
48
|
+
const displacement = (distance + tangent) * decay;
|
|
49
|
+
const nextVelocity = (velocity - rate * tangent) * decay;
|
|
50
|
+
if (!Number.isFinite(displacement) || !Number.isFinite(nextVelocity)
|
|
51
|
+
|| Math.abs(displacement) <= precision && Math.abs(nextVelocity) / rate <= precision) return settle();
|
|
52
|
+
|
|
53
|
+
velocity = nextVelocity;
|
|
54
|
+
value.value = target + displacement;
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const watched = scope.watch(() => ({ next: read(), reduced: isReducedMotion(motion) }), ({ next, reduced }) => {
|
|
59
|
+
if (!Number.isFinite(next)) return fail("Spring target must be finite");
|
|
60
|
+
if (next === target && !reduced) return;
|
|
61
|
+
target = next;
|
|
62
|
+
const now = nowMs?.();
|
|
63
|
+
if (reduced || now === undefined || !Number.isFinite(now) || value.value === target && velocity === 0) {
|
|
64
|
+
frames.cancel(job);
|
|
65
|
+
settle();
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
previous = now;
|
|
70
|
+
if (frames.queued(job) === undefined) frames.queue(job, step, { label: "Spring" });
|
|
71
|
+
});
|
|
72
|
+
if (!watched.ok) throw new Error(watched.reason);
|
|
73
|
+
scope.onDispose(() => { frames.cancel(job); });
|
|
74
|
+
return value;
|
|
75
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { easeProgress } from "./ease";
|
|
2
|
+
import { useSlide, type SlideValueOptions } from "./slide";
|
|
3
|
+
|
|
4
|
+
export interface StaggeredRevealOptions extends SlideValueOptions {
|
|
5
|
+
/** Seconds between the start of adjacent items. Defaults to 0.024. */
|
|
6
|
+
readonly stagger?: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface StaggeredReveal {
|
|
10
|
+
/** Eased progress from 0 to 1 for one item, using a zero-based index. */
|
|
11
|
+
progress(this: void, index: number): number;
|
|
12
|
+
/** Keep the container visible through the exit. */
|
|
13
|
+
visible(this: void): boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Reveal a fixed group in order, then close in reverse using the same timeline. */
|
|
17
|
+
export function useStaggeredReveal(this: void, open: (this: void) => boolean, count: number,
|
|
18
|
+
{ duration = 0.2, stagger = 0.024, ease = "out", motion }: StaggeredRevealOptions = {}): StaggeredReveal {
|
|
19
|
+
if (!Number.isInteger(count) || count < 1) throw new Error("Staggered reveal requires a positive item count");
|
|
20
|
+
if (!Number.isFinite(duration) || duration < 0 || !Number.isFinite(stagger) || stagger < 0) {
|
|
21
|
+
throw new Error("Staggered reveal timings must be nonnegative and finite");
|
|
22
|
+
}
|
|
23
|
+
const total = duration === 0 ? 0 : duration + (count - 1) * stagger;
|
|
24
|
+
const timeline = useSlide(() => open() ? 1 : 0, { duration: total, ease: "linear", motion });
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
progress(index) {
|
|
28
|
+
const position = timeline.value;
|
|
29
|
+
if (position === 0 || position === 1 || duration === 0) return position;
|
|
30
|
+
return easeProgress(ease, (position * total - index * stagger) / duration);
|
|
31
|
+
},
|
|
32
|
+
visible: () => open() || timeline.value > 0,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
const directions = new Map([
|
|
2
|
+
["to right", ["HORIZONTAL", false]], ["90deg", ["HORIZONTAL", false]],
|
|
3
|
+
["to left", ["HORIZONTAL", true]], ["270deg", ["HORIZONTAL", true]],
|
|
4
|
+
["to top", ["VERTICAL", false]], ["0deg", ["VERTICAL", false]],
|
|
5
|
+
["to bottom", ["VERTICAL", true]], ["180deg", ["VERTICAL", true]],
|
|
6
|
+
]);
|
|
7
|
+
|
|
8
|
+
function argumentsOf(value) {
|
|
9
|
+
if (!value.startsWith("linear-gradient(") || !value.endsWith(")")) return;
|
|
10
|
+
const body = value.slice(16, -1);
|
|
11
|
+
const result = [];
|
|
12
|
+
let depth = 0;
|
|
13
|
+
let start = 0;
|
|
14
|
+
for (let index = 0; index < body.length; index++) {
|
|
15
|
+
const char = body[index];
|
|
16
|
+
if (char === "(") depth++;
|
|
17
|
+
if (char === ")") {
|
|
18
|
+
depth--;
|
|
19
|
+
if (depth < 0) return;
|
|
20
|
+
}
|
|
21
|
+
if (char === "," && depth === 0) {
|
|
22
|
+
result.push(body.slice(start, index).trim());
|
|
23
|
+
start = index + 1;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (depth !== 0) return;
|
|
27
|
+
result.push(body.slice(start).trim());
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function gradient(value) {
|
|
32
|
+
const args = argumentsOf(value);
|
|
33
|
+
if (args === undefined) return;
|
|
34
|
+
const direction = directions.get(args[0]?.replace(/\s+/gu, " "));
|
|
35
|
+
if (direction !== undefined) args.shift();
|
|
36
|
+
const [axis, reverse] = direction ?? directions.get("to bottom");
|
|
37
|
+
return { axis, reverse, stops: args };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function parseLinearGradient(value, readColor) {
|
|
41
|
+
const input = gradient(value);
|
|
42
|
+
if (input?.stops.length !== 2) return;
|
|
43
|
+
const [first, last] = input.stops.map(readColor);
|
|
44
|
+
if (first === undefined || last === undefined) return;
|
|
45
|
+
const { axis, reverse } = input;
|
|
46
|
+
return { gradient: { axis, min: reverse ? last : first, max: reverse ? first : last } };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function parseMaskGradient(value, readColor) {
|
|
50
|
+
const input = gradient(value);
|
|
51
|
+
if (input === undefined || input.stops.length < 2) return;
|
|
52
|
+
const stops = [];
|
|
53
|
+
for (const stop of input.stops) {
|
|
54
|
+
const [, color, percentage] = /^([\s\S]*?)(?:\s+((?:\d+(?:\.\d+)?|\.\d+))%)?$/u.exec(stop);
|
|
55
|
+
const literal = readColor(color);
|
|
56
|
+
const position = percentage === undefined ? undefined : Number(percentage) / 100;
|
|
57
|
+
if (literal === undefined || (position !== undefined && position > 1)) return;
|
|
58
|
+
stops.push({ position, alpha: literal.length === 9 ? Number.parseInt(literal.slice(7), 16) : 255 });
|
|
59
|
+
}
|
|
60
|
+
stops[0].position ??= 0;
|
|
61
|
+
stops.at(-1).position ??= 1;
|
|
62
|
+
let previous = 0;
|
|
63
|
+
for (let index = 1; index < stops.length; index++) {
|
|
64
|
+
const stop = stops[index];
|
|
65
|
+
if (stop.position === undefined) continue;
|
|
66
|
+
stop.position = Math.max(stop.position, stops[previous].position);
|
|
67
|
+
for (let gap = previous + 1; gap < index; gap++) {
|
|
68
|
+
const start = stops[previous].position;
|
|
69
|
+
stops[gap].position = start + (stop.position - start) * (gap - previous) / (index - previous);
|
|
70
|
+
}
|
|
71
|
+
previous = index;
|
|
72
|
+
}
|
|
73
|
+
return { gradient: { axis: input.axis, reverse: input.reverse, stops } };
|
|
74
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
|
|
3
|
+
const samples = 256;
|
|
4
|
+
const thickness = 4;
|
|
5
|
+
|
|
6
|
+
function alphaAt(stops, position) {
|
|
7
|
+
if (position < stops[0].position) return stops[0].alpha;
|
|
8
|
+
const next = stops.findIndex(stop => stop.position > position);
|
|
9
|
+
if (next === -1) return stops.at(-1).alpha;
|
|
10
|
+
const before = stops[next - 1], after = stops[next];
|
|
11
|
+
const amount = (position - before.position) / (after.position - before.position);
|
|
12
|
+
return Math.round(before.alpha + (after.alpha - before.alpha) * amount);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function encodeMask({ axis, reverse, stops }) {
|
|
16
|
+
const horizontal = axis === "HORIZONTAL";
|
|
17
|
+
const width = horizontal ? samples : thickness;
|
|
18
|
+
const height = horizontal ? thickness : samples;
|
|
19
|
+
const data = Buffer.alloc(18 + width * height * 4, 255);
|
|
20
|
+
data.fill(0, 0, 18);
|
|
21
|
+
data[2] = 2; // Uncompressed truecolor.
|
|
22
|
+
data.writeUInt16LE(width, 12);
|
|
23
|
+
data.writeUInt16LE(height, 14);
|
|
24
|
+
data[16] = 32;
|
|
25
|
+
data[17] = 0x28; // Eight bits of alpha, origin at the top left.
|
|
26
|
+
for (let y = 0; y < height; y++) {
|
|
27
|
+
for (let x = 0; x < width; x++) {
|
|
28
|
+
const sample = horizontal ? x : height - 1 - y;
|
|
29
|
+
const position = (reverse ? samples - 1 - sample : sample) / (samples - 1);
|
|
30
|
+
data[18 + (y * width + x) * 4 + 3] = alphaAt(stops, position);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return data;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function prepareCssMaskImages(classes, addonName, assets) {
|
|
37
|
+
const root = `Interface/AddOns/${addonName}/`;
|
|
38
|
+
for (const style of Object.values(classes)) {
|
|
39
|
+
const mask = style.maskImage;
|
|
40
|
+
if (mask === undefined) continue;
|
|
41
|
+
if ("gradient" in mask) {
|
|
42
|
+
const data = encodeMask(mask.gradient);
|
|
43
|
+
const hash = createHash("sha256").update(data).digest("hex");
|
|
44
|
+
const output = `KumiGenerated/Masks/${hash}.tga`;
|
|
45
|
+
if (!assets.has(output)) assets.set(output, data);
|
|
46
|
+
style.maskImage = { path: root + output };
|
|
47
|
+
} else {
|
|
48
|
+
const path = mask.path.replace(/^\.\//u, "");
|
|
49
|
+
if (path.startsWith("Assets/")) style.maskImage = { path: root + path };
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { strict as assert } from "node:assert";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { prepareCssMaskImages } from "./css-mask-assets.mjs";
|
|
4
|
+
import { compileCssDeclarations } from "./css-v1.mjs";
|
|
5
|
+
|
|
6
|
+
function mask(value) {
|
|
7
|
+
return compileCssDeclarations([{ prop: "mask-image", value }]);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
test("packages one TGA for identical gradient masks and preserves their orientation and alpha", () => {
|
|
11
|
+
const styles = {
|
|
12
|
+
right: mask("linear-gradient(to right, transparent, black 43%)"),
|
|
13
|
+
same: mask("linear-gradient(90deg, transparent, black 43%)"),
|
|
14
|
+
bottom: mask("linear-gradient(transparent, black)"),
|
|
15
|
+
file: mask('url("./Assets/Fade.tga")'),
|
|
16
|
+
};
|
|
17
|
+
const assets = new Map();
|
|
18
|
+
prepareCssMaskImages(styles, "Sample", assets);
|
|
19
|
+
const root = "Interface/AddOns/Sample/";
|
|
20
|
+
assert.deepEqual(styles.right, styles.same);
|
|
21
|
+
assert.equal(styles.file.maskImage.path, root + "Assets/Fade.tga");
|
|
22
|
+
assert.equal(assets.size, 2);
|
|
23
|
+
const right = assets.get(styles.right.maskImage.path.slice(root.length));
|
|
24
|
+
const bottom = assets.get(styles.bottom.maskImage.path.slice(root.length));
|
|
25
|
+
assert.equal(right.readUInt16LE(12), 256);
|
|
26
|
+
assert.equal(bottom.readUInt16LE(14), 256);
|
|
27
|
+
assert.equal(right[21], 0);
|
|
28
|
+
assert.equal(right[21 + 128 * 4], 255);
|
|
29
|
+
assert.equal(bottom[21], 0);
|
|
30
|
+
assert.equal(bottom[21 + 255 * 16], 255);
|
|
31
|
+
});
|
package/builder/css-v1.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
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]);
|
|
@@ -15,8 +16,8 @@ const ordered = new Set(["margin", "border", "inset", "border-style", ...borderP
|
|
|
15
16
|
const decimal = String.raw`(?:\d+(?:\.\d+)?|\.\d+)`;
|
|
16
17
|
const unitlessNumber = new RegExp(`^[+-]?${decimal}$`);
|
|
17
18
|
const pixels = new RegExp(`^[+-]?${decimal}px$`);
|
|
18
|
-
const variable = String.raw`var\(\s*(--[
|
|
19
|
-
const reference =
|
|
19
|
+
const variable = String.raw`var\(\s*(--[\w-]+)\s*\)`;
|
|
20
|
+
const reference = /^var\(\s*(--[\w-]+)\s*(?:,\s*([\s\S]+))?\)$/u;
|
|
20
21
|
const arithmetic = new RegExp(`^calc\\(\\s*${variable}\\s+([+-])\\s+(${decimal})(px)?\\s*\\)$`);
|
|
21
22
|
|
|
22
23
|
function numberIn(value, unit) {
|
|
@@ -42,12 +43,19 @@ const positiveLength = numeric("positiveLength", "px", value => value > 0);
|
|
|
42
43
|
const percent = new RegExp(`^${decimal}%$`);
|
|
43
44
|
// A size is auto, a length, or a percentage of the parent's content box (kept as "50%" for the layout solver).
|
|
44
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) };
|
|
45
47
|
const number = numeric("number", "", value => value >= 0);
|
|
46
48
|
const integer = numeric("integer", "", Number.isInteger);
|
|
47
49
|
const opacity = numeric("opacity", "", value => value >= 0 && value <= 1);
|
|
48
50
|
const columns = Array.from({ length: 10 }, (_, index) => index + 1);
|
|
49
51
|
const columnCount = numeric("integer", "", value => columns.includes(value), columns);
|
|
50
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
|
+
} };
|
|
51
59
|
const image = {
|
|
52
60
|
kind: "backgroundImage",
|
|
53
61
|
parse(value) {
|
|
@@ -64,7 +72,7 @@ const scalarProperties = {
|
|
|
64
72
|
"background-image": ["backgroundImage", image],
|
|
65
73
|
opacity: ["opacity", opacity],
|
|
66
74
|
position: ["position", keywords("static", "relative", "absolute")],
|
|
67
|
-
width: ["width",
|
|
75
|
+
width: ["width", width],
|
|
68
76
|
height: ["height", size],
|
|
69
77
|
"min-width": ["minWidth", length],
|
|
70
78
|
"max-width": ["maxWidth", length],
|
|
@@ -117,13 +125,29 @@ function pieces(source) {
|
|
|
117
125
|
return words;
|
|
118
126
|
}
|
|
119
127
|
|
|
120
|
-
function
|
|
121
|
-
|
|
122
|
-
|
|
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;
|
|
123
147
|
}
|
|
124
148
|
|
|
125
149
|
function bind(input, spec, tokens) {
|
|
126
|
-
const token = reference.exec(input)
|
|
150
|
+
const [, token, fallback] = reference.exec(input) ?? [];
|
|
127
151
|
const calc = arithmetic.exec(input);
|
|
128
152
|
if (calc) {
|
|
129
153
|
const [, name, operation, amount, unit = ""] = calc;
|
|
@@ -134,11 +158,13 @@ function bind(input, spec, tokens) {
|
|
|
134
158
|
const add = Number(amount) * (operation === "+" ? 1 : -1);
|
|
135
159
|
const value = base + add;
|
|
136
160
|
if (!Number.isFinite(value) || !spec.accepts(value)) return;
|
|
137
|
-
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 };
|
|
138
162
|
}
|
|
139
|
-
const
|
|
163
|
+
const source = token === undefined ? input : tokenValue(tokens, token, fallback);
|
|
164
|
+
const value = spec.parse(source);
|
|
140
165
|
if (value === undefined) return;
|
|
141
|
-
return token === undefined || spec.kind === undefined ? { value }
|
|
166
|
+
return token === undefined || spec.kind === undefined ? { value }
|
|
167
|
+
: { value, token, source, fallbackExpression: fallback?.trim(), kind: spec.kind, values: spec.values };
|
|
142
168
|
}
|
|
143
169
|
|
|
144
170
|
function rectangle(values) {
|
|
@@ -181,20 +207,25 @@ function readShadow(source, read) {
|
|
|
181
207
|
}
|
|
182
208
|
|
|
183
209
|
function compound(source, kind, parse, keys, tokens) {
|
|
184
|
-
const token = reference.exec(source)
|
|
210
|
+
const [, token, fallback] = reference.exec(source) ?? [];
|
|
185
211
|
if (token === undefined) return parse(source, (input, spec) => bind(input, spec, tokens));
|
|
186
|
-
const
|
|
212
|
+
const resolved = tokenValue(tokens, token, fallback);
|
|
213
|
+
const value = parse(resolved, (input, spec) => spec.parse(input));
|
|
187
214
|
if (value === undefined) return;
|
|
188
|
-
return Object.fromEntries(keys.map(part => [part, {
|
|
215
|
+
return Object.fromEntries(keys.map(part => [part, {
|
|
216
|
+
value: value[part], token, source: resolved, fallbackExpression: fallback?.trim(), kind, part,
|
|
217
|
+
}]));
|
|
189
218
|
}
|
|
190
219
|
|
|
191
220
|
function compileInsets(source, property, spec, tokens) {
|
|
192
|
-
const token = reference.exec(source)
|
|
221
|
+
const [, token, fallback] = reference.exec(source) ?? [];
|
|
193
222
|
if (token === undefined) return readInsets(source, input => bind(input, spec, tokens));
|
|
194
|
-
const
|
|
223
|
+
const resolved = tokenValue(tokens, token, fallback);
|
|
224
|
+
const values = readInsets(resolved, input => spec.parse(input));
|
|
195
225
|
if (values === undefined) return;
|
|
196
|
-
|
|
197
|
-
|
|
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 }));
|
|
198
229
|
}
|
|
199
230
|
|
|
200
231
|
function declarationError(declaration, message) {
|
|
@@ -220,17 +251,35 @@ export function compileCssDeclarations(declarations, {
|
|
|
220
251
|
const key = path[index];
|
|
221
252
|
parent = parent[key] ??= typeof path[index + 1] === "number" ? [] : {};
|
|
222
253
|
}
|
|
223
|
-
const { value, token, kind, add, part, values } = resolved;
|
|
254
|
+
const { value, token, source, fallbackExpression, kind, add, part, values } = resolved;
|
|
224
255
|
parent[path.at(-1)] = value;
|
|
225
256
|
const key = JSON.stringify(path);
|
|
226
257
|
if (live && token !== undefined) {
|
|
227
|
-
recipes.set(key, { path, token, kind, fallback: value, source
|
|
258
|
+
recipes.set(key, { path, token, kind, fallback: value, source,
|
|
259
|
+
...(fallbackExpression === undefined ? {} : { fallbackExpression }),
|
|
228
260
|
...(add === undefined ? {} : { add }), ...(part === undefined ? {} : { part }),
|
|
229
261
|
...(values === undefined ? {} : { values }) });
|
|
230
262
|
} else recipes.delete(key);
|
|
231
263
|
}
|
|
232
264
|
|
|
233
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
|
+
}
|
|
234
283
|
if (state && property === "border-color") {
|
|
235
284
|
const resolved = bind(source, color, tokens);
|
|
236
285
|
if (resolved === undefined) return false;
|
|
@@ -328,8 +377,10 @@ export function compileCssDeclarations(declarations, {
|
|
|
328
377
|
const [key, spec] = entry;
|
|
329
378
|
const resolved = bind(source, spec, tokens);
|
|
330
379
|
if (resolved === undefined) return false;
|
|
331
|
-
const { value, token } = resolved;
|
|
332
|
-
if ((key === "color" || key === "backgroundColor") && token !== undefined)
|
|
380
|
+
const { value, token, fallbackExpression } = resolved;
|
|
381
|
+
if ((key === "color" || key === "backgroundColor") && token !== undefined) {
|
|
382
|
+
write([key], { value: `var(${token}, ${fallbackExpression ?? value})` });
|
|
383
|
+
}
|
|
333
384
|
else write([key], resolved, key !== "overflow");
|
|
334
385
|
return true;
|
|
335
386
|
}
|
package/builder/css-v1.test.mjs
CHANGED
|
@@ -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"],
|
|
@@ -149,11 +159,41 @@ test("accepts a single quoted local URL or atlas using the same grammar in base
|
|
|
149
159
|
'url("textures/../tab.tga")', 'url("textures/%2e%2e/tab.tga")', 'url("textures\\..\\tab.tga")',
|
|
150
160
|
'url("textures//tab.tga")', 'url("tab.tga?query")', 'url("tab.tga#fragment")', 'url("tab.tga"), atlas(other)',
|
|
151
161
|
'url("tab.tga") center', 'url("")', "url(tab.tga)", "atlas()", 'atlas("x/y")', 'atlas("x y")',
|
|
152
|
-
"linear-gradient(#123456, #ffffff)", "none",
|
|
162
|
+
"linear-gradient(45deg, #123456, #ffffff)", "none",
|
|
153
163
|
]) assert.throws(() => single("background-image", value, { state }), /Invalid value for background-image/, value);
|
|
154
164
|
}
|
|
155
165
|
});
|
|
156
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
|
+
|
|
157
197
|
test("validates typography properties and registered font weights", () => {
|
|
158
198
|
assert.deepEqual(compile([
|
|
159
199
|
["font-size", "13.5px"], ["font-weight", "600"], ["text-align", "center"],
|
|
@@ -312,7 +352,7 @@ test("checks typed token defaults and restricted calc operands and results", ()
|
|
|
312
352
|
["width", "calc(var(--space) * 2px)"], ["width", "calc(var(--space) + var(--space))"],
|
|
313
353
|
["width", "calc(var(--space) + 2px - 2px)"], ["width", "calc(var(--space)+2px)"],
|
|
314
354
|
["width", "calc(2px + var(--space))"], ["width", "calc(calc(var(--space) + 2px) + 2px)"],
|
|
315
|
-
["width", "var(--
|
|
355
|
+
["width", "var(--missing, #123456)"], ["width", "var(--space)px"], ["color", "calc(var(--ink) + 2)"],
|
|
316
356
|
["border-radius", "calc(var(--round) + 0px)"], ["opacity", "calc(var(--number) + .75)"],
|
|
317
357
|
]) assert.throws(() => single(prop, value, options), /Invalid value for/, prop + " " + value);
|
|
318
358
|
for (const [prop, value] of [
|
|
@@ -478,8 +478,8 @@ export function transformModuleDeclarations(ts, path, source, { program, rejectU
|
|
|
478
478
|
if (ts.getDecorators(node)?.length !== 1) error(decorator, "@Module must be the only decorator on its class");
|
|
479
479
|
const heritage = node.heritageClauses?.[0]?.types[0];
|
|
480
480
|
if (node.heritageClauses?.length !== 1 || node.heritageClauses[0].token !== ts.SyntaxKind.ExtendsKeyword || !heritage
|
|
481
|
-
|| marker(heritage.expression) !== "ModuleType" || heritage.typeArguments?.length
|
|
482
|
-
error(node, "Extend ModuleType
|
|
481
|
+
|| marker(heritage.expression) !== "ModuleType" || (heritage.typeArguments?.length ?? 0) > 1) {
|
|
482
|
+
error(node, "Extend ModuleType. Supply its metadata type when the module exports services");
|
|
483
483
|
}
|
|
484
484
|
if (node.typeParameters?.length || ts.getModifiers(node)?.some(modifier =>
|
|
485
485
|
modifier.kind !== ts.SyntaxKind.ExportKeyword && modifier.kind !== ts.SyntaxKind.DefaultKeyword)) {
|
|
@@ -11,7 +11,7 @@ declare module "@kumi/core" {
|
|
|
11
11
|
export interface RuntimeScope { readonly scope: true }
|
|
12
12
|
export const moduleScope: { readonly name: "module scope" };
|
|
13
13
|
export function Module(metadata: unknown): ClassDecorator;
|
|
14
|
-
export class ModuleType<T> {}
|
|
14
|
+
export class ModuleType<T = { exports: {} }> {}
|
|
15
15
|
export function Injectable(): ClassDecorator;
|
|
16
16
|
export function Inject(token: object): ParameterDecorator;
|
|
17
17
|
export function defineModule<Metadata>(metadata: Metadata): Metadata;
|
|
@@ -183,10 +183,12 @@ test("lowers an empty injectable constructor and preserves an undecorated no-arg
|
|
|
183
183
|
});
|
|
184
184
|
|
|
185
185
|
test("retains AST-only Vite module lowering and rejects unknown decorators in the checked transform", () => {
|
|
186
|
-
const source = 'import { Module, ModuleType } from "@kumi/core";\nclass Service {}\n'
|
|
186
|
+
const source = 'import { Module, ModuleType } from "@kumi/core";\nclass Service {}\n'
|
|
187
|
+
+ '@Module({ id: "fixture", providers: [Service], exports: {} })\nexport class Fixture extends ModuleType {}\n';
|
|
187
188
|
const output = viteModuleDeclarations(ts).transform(source, "/fixture.ts?source");
|
|
188
189
|
assert.match(output, /providers: \[Service\]/);
|
|
189
190
|
assert.match(output, /defineModule as __kumiDefineModule/);
|
|
191
|
+
assert.doesNotMatch(output, /@Module|extends ModuleType/);
|
|
190
192
|
const unknown = fixture({ "fixture.ts": source.replace("class Service", "@Unrelated()\nclass Service") });
|
|
191
193
|
assert.throws(() => unknown.transform("fixture.ts"), /fixture\.ts:2:1: Unsupported WoW decorator/);
|
|
192
194
|
});
|