@overmvp/kumi 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +14 -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 +334 -0
- package/builder/css-v1.test.mjs +321 -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 +86 -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 +444 -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 +2164 -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 +367 -0
- package/builder/src/native_ir.rs +65 -0
- package/builder/src/native_signal.rs +47 -0
- package/builder/src/numbers.lua +62 -0
- package/builder/src/project-front.mjs +3331 -0
- package/builder/src/records.lua +75 -0
- package/builder/src/routes.rs +127 -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_client.rs +253 -0
- package/builder/src/wow_types.rs +564 -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 +17 -0
- package/form/index.ts +522 -0
- package/form/package.json +13 -0
- package/motion/index.ts +2 -0
- package/motion/package.json +10 -0
- package/package.json +22 -4
- package/router/index.ts +43 -0
- package/router/package.json +12 -0
- package/router/routes.ts +64 -0
- package/scripts/kumi-cli.mjs +70 -0
- package/scripts/link-addons.mjs +51 -0
- package/src/bindings.ts +35 -0
- package/src/context.ts +15 -0
- package/src/css-tokens.ts +234 -0
- package/src/css-v1.ts +58 -0
- package/src/cvars.ts +91 -0
- package/src/element-node.ts +32 -0
- package/src/elements.ts +479 -0
- package/src/feature-scope.ts +82 -0
- package/src/flex-layout.ts +807 -0
- package/src/frame-scheduler.ts +334 -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 +28 -0
- package/src/jsx-dev-runtime.ts +2 -0
- package/src/jsx-runtime.ts +22 -0
- package/src/jsx.d.ts +12 -0
- package/src/keyed-list.ts +363 -0
- package/src/media-query.ts +144 -0
- package/src/module.ts +277 -0
- package/src/node-selectors.ts +114 -0
- package/src/owned-collections.ts +44 -0
- package/src/providers.ts +235 -0
- package/src/reactive-scope.ts +34 -0
- package/src/reactivity.ts +254 -0
- package/src/result.ts +58 -0
- package/src/runtime.ts +52 -0
- package/src/scheduler.ts +185 -0
- package/src/signal-kernel.ts +30 -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 +3 -0
- package/state/package.json +12 -0
- package/state/store-bindings.ts +25 -0
- package/state/store.ts +82 -0
- package/styles/_layers.scss +14 -0
- package/templates/addon/README.md +14 -0
- package/templates/addon/__ADDON_NAME__.toc +4 -0
- package/templates/addon/eslint.config.mjs +12 -0
- package/templates/addon/gitignore +8 -0
- package/templates/addon/package.json +21 -0
- package/templates/addon/scripts/build.mjs +25 -0
- package/templates/addon/src/app/main.tsx +13 -0
- package/templates/addon/tsconfig.json +24 -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/animation.ts +428 -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/css-box.ts +110 -0
- package/wow/css-color.ts +12 -0
- package/wow/css-style.ts +109 -0
- package/wow/css-surfaces.ts +398 -0
- package/wow/css-text.ts +399 -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 +31 -0
- package/wow/frame-layer.ts +5 -0
- package/wow/frames.ts +236 -0
- package/wow/heal-prediction.ts +305 -0
- package/wow/image-layers.ts +55 -0
- package/wow/index.ts +97 -0
- package/wow/layout-view.ts +651 -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 +135 -0
- package/wow/number-format.ts +8 -0
- package/wow/number-input.ts +10 -0
- package/wow/protect.ts +24 -0
- package/wow/protected-layout.ts +133 -0
- package/wow/range-art.ts +74 -0
- package/wow/reparent-frame.ts +99 -0
- package/wow/rounded-texture.ts +156 -0
- package/wow/saved-variables.ts +60 -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/start-addon.ts +99 -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 +1746 -0
- package/wow/visible-frame-job.ts +34 -0
- package/wow/width-reserve.ts +108 -0
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
import { direct, fail, type Failure, type Protect } from "./result";
|
|
2
|
+
import type { Cancel, Clock } from "./scheduler";
|
|
3
|
+
|
|
4
|
+
export type FrameLane = "user" | "normal" | "idle";
|
|
5
|
+
export type FrameKey = string | number | boolean | object;
|
|
6
|
+
export type FrameJob = (this: void) => void | boolean | Failure;
|
|
7
|
+
export type FrameStep = (this: void) => number | undefined;
|
|
8
|
+
|
|
9
|
+
export interface FrameJobOptions {
|
|
10
|
+
lane?: FrameLane;
|
|
11
|
+
label?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface FrameTiming {
|
|
15
|
+
nowMs?: (this: void) => number;
|
|
16
|
+
inCombat?: (this: void) => boolean;
|
|
17
|
+
remainingMs?: (this: void) => number;
|
|
18
|
+
/** Diagnostics: called after each job with its label and how long it ran (only when set; costs a clock read). */
|
|
19
|
+
onJob?: (this: void, label: string, elapsedMs: number) => void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface FrameDriver extends FrameTiming {
|
|
23
|
+
start(this: void, step: FrameStep, delaySeconds: number): Cancel;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface FrameLimits {
|
|
27
|
+
maxJobs?: number;
|
|
28
|
+
budgetMs?: number;
|
|
29
|
+
combatBudgetMs?: number;
|
|
30
|
+
idleWaitMs?: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface FrameScheduler {
|
|
34
|
+
queue(this: void, key: FrameKey, run: FrameJob, options?: FrameJobOptions): void;
|
|
35
|
+
cancel(this: void, key: FrameKey): void;
|
|
36
|
+
queued(this: void, key: FrameKey): FrameLane | undefined;
|
|
37
|
+
remainingMs(this: void): number;
|
|
38
|
+
combatChanged(this: void): void;
|
|
39
|
+
/** @internal Runs an explicit diagnostic frame. Nested calls do not dispatch. */
|
|
40
|
+
step(this: void, unlimited?: boolean): number;
|
|
41
|
+
/** @internal Inspect queued work and counters without scheduling anything. */
|
|
42
|
+
inspect(this: void): FrameDiagnostics;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
interface Entry {
|
|
46
|
+
key: FrameKey;
|
|
47
|
+
run: FrameJob;
|
|
48
|
+
lane: FrameLane;
|
|
49
|
+
label: string;
|
|
50
|
+
queuedAt: number;
|
|
51
|
+
order: number;
|
|
52
|
+
previous?: Entry;
|
|
53
|
+
next?: Entry;
|
|
54
|
+
running: boolean;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
interface Queue { head?: Entry; tail?: Entry }
|
|
58
|
+
const lanes: readonly FrameLane[] = ["user", "normal", "idle"];
|
|
59
|
+
const rank: Record<FrameLane, number> = { user: 1, normal: 2, idle: 3 };
|
|
60
|
+
|
|
61
|
+
interface FrameStatistics { ran: number; batched: number; sliced: number; deferred: number; worstMs: number }
|
|
62
|
+
interface FrameDiagnostics {
|
|
63
|
+
readonly jobs: readonly { key: FrameKey; lane: FrameLane; label: string; waitedMs: number }[];
|
|
64
|
+
readonly last: Readonly<FrameStatistics>;
|
|
65
|
+
readonly current: Readonly<FrameStatistics>;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function statistics(): FrameStatistics { return { ran: 0, batched: 0, sliced: 0, deferred: 0, worstMs: 0 }; }
|
|
69
|
+
|
|
70
|
+
function snapshotStatistics(stats: FrameStatistics): FrameStatistics {
|
|
71
|
+
const { ran, batched, sliced, deferred, worstMs } = stats;
|
|
72
|
+
return { ran, batched, sliced, deferred, worstMs };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function nonnegative(value: number | undefined, fallback: number) {
|
|
76
|
+
return typeof value === "number" && Number.isFinite(value) ? Math.max(0, value) : fallback;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function createFrameDriver(clock: Clock, timing: FrameTiming = {}): FrameDriver {
|
|
80
|
+
return {
|
|
81
|
+
nowMs: timing.nowMs,
|
|
82
|
+
inCombat: timing.inCombat,
|
|
83
|
+
remainingMs: timing.remainingMs,
|
|
84
|
+
onJob: timing.onJob,
|
|
85
|
+
start(step, delaySeconds) {
|
|
86
|
+
let timer: Cancel | undefined;
|
|
87
|
+
let active = true;
|
|
88
|
+
function advance() {
|
|
89
|
+
timer = undefined;
|
|
90
|
+
if (!active) return;
|
|
91
|
+
const delay = step();
|
|
92
|
+
if (active && delay !== undefined) timer = clock(delay, advance);
|
|
93
|
+
}
|
|
94
|
+
timer = clock(delaySeconds, advance);
|
|
95
|
+
return () => {
|
|
96
|
+
active = false;
|
|
97
|
+
timer?.();
|
|
98
|
+
};
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function createFrameScheduler(
|
|
104
|
+
driver: FrameDriver,
|
|
105
|
+
limits: FrameLimits = {},
|
|
106
|
+
onError?: (this: void, failure: Failure, label: string) => void,
|
|
107
|
+
protect: Protect = direct,
|
|
108
|
+
): FrameScheduler {
|
|
109
|
+
const queues: Record<FrameLane, Queue> = { user: {}, normal: {}, idle: {} };
|
|
110
|
+
const byKey = new Map<FrameKey, Entry>();
|
|
111
|
+
const now = driver.nowMs ?? (() => 0);
|
|
112
|
+
const maxJobs = Math.max(1, Math.floor(nonnegative(limits.maxJobs, 6)));
|
|
113
|
+
const normalBudget = nonnegative(limits.budgetMs, 4);
|
|
114
|
+
const combatBudget = nonnegative(limits.combatBudgetMs, 2);
|
|
115
|
+
const idleWait = nonnegative(limits.idleWaitMs, 5000);
|
|
116
|
+
let serial = 0;
|
|
117
|
+
let cancelDriver: Cancel | undefined;
|
|
118
|
+
let due: number | undefined;
|
|
119
|
+
let running = false;
|
|
120
|
+
let deadline: number | undefined;
|
|
121
|
+
let nextLane = 0;
|
|
122
|
+
let generation = 0;
|
|
123
|
+
let secondStart = now();
|
|
124
|
+
let current = statistics();
|
|
125
|
+
let last = statistics();
|
|
126
|
+
let drive: FrameStep;
|
|
127
|
+
|
|
128
|
+
function report(failure: Failure, label: string) {
|
|
129
|
+
// A broken error observer cannot leave the queue in its running state.
|
|
130
|
+
if (onError !== undefined) protect(() => onError(failure, label));
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function fighting() { return driver.inCombat?.() === true; }
|
|
134
|
+
|
|
135
|
+
function budget() { return fighting() ? combatBudget : normalBudget; }
|
|
136
|
+
|
|
137
|
+
function append(entry: Entry) {
|
|
138
|
+
const queue = queues[entry.lane];
|
|
139
|
+
entry.order = ++serial;
|
|
140
|
+
entry.previous = queue.tail;
|
|
141
|
+
entry.next = undefined;
|
|
142
|
+
if (queue.tail) queue.tail.next = entry;
|
|
143
|
+
else queue.head = entry;
|
|
144
|
+
queue.tail = entry;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function remove(entry: Entry) {
|
|
148
|
+
const queue = queues[entry.lane];
|
|
149
|
+
if (entry.previous) entry.previous.next = entry.next;
|
|
150
|
+
else queue.head = entry.next;
|
|
151
|
+
if (entry.next) entry.next.previous = entry.previous;
|
|
152
|
+
else queue.tail = entry.previous;
|
|
153
|
+
entry.previous = entry.next = undefined;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function idleDelayMs() {
|
|
157
|
+
let entry = queues.idle.head;
|
|
158
|
+
if (!entry) return undefined;
|
|
159
|
+
if (!driver.nowMs || !fighting()) return 0;
|
|
160
|
+
let earliest = entry.queuedAt;
|
|
161
|
+
while (entry.next) {
|
|
162
|
+
entry = entry.next;
|
|
163
|
+
earliest = Math.min(earliest, entry.queuedAt);
|
|
164
|
+
}
|
|
165
|
+
return Math.max(0, earliest + idleWait - now());
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function delayMs() {
|
|
169
|
+
if (queues.user.head || queues.normal.head) return 0;
|
|
170
|
+
return idleDelayMs();
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function stopWake() {
|
|
174
|
+
generation++;
|
|
175
|
+
cancelDriver?.();
|
|
176
|
+
cancelDriver = due = undefined;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function wake() {
|
|
180
|
+
if (running) return;
|
|
181
|
+
const delay = delayMs();
|
|
182
|
+
if (delay === undefined) {
|
|
183
|
+
nextLane = 0;
|
|
184
|
+
stopWake();
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
const startAt = now() + delay;
|
|
188
|
+
if (due !== undefined && due <= startAt) return;
|
|
189
|
+
stopWake();
|
|
190
|
+
const request = generation;
|
|
191
|
+
const result = protect(() => driver.start(() => {
|
|
192
|
+
if (request === generation) return drive();
|
|
193
|
+
}, delay / 1000));
|
|
194
|
+
if (!result.ok) {
|
|
195
|
+
cancelDriver = due = undefined;
|
|
196
|
+
report(result, "Frame scheduler");
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
due = startAt;
|
|
200
|
+
cancelDriver = result.value;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function remainingMs() {
|
|
204
|
+
const own = deadline === undefined ? budget() : deadline - now();
|
|
205
|
+
return Math.max(0, Math.min(own, driver.remainingMs?.() ?? own));
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function roll(time: number) {
|
|
209
|
+
if (time - secondStart < 1000) return;
|
|
210
|
+
last = current;
|
|
211
|
+
current = statistics();
|
|
212
|
+
secondStart = time;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function ready(lane: FrameLane, cutoff: number, time: number, waitForIdle: boolean) {
|
|
216
|
+
const queue = queues[lane];
|
|
217
|
+
while (queue.head && queue.head.order <= cutoff) {
|
|
218
|
+
const entry = queue.head;
|
|
219
|
+
remove(entry);
|
|
220
|
+
if (lane !== "idle" || !waitForIdle || time - entry.queuedAt >= idleWait) return entry;
|
|
221
|
+
append(entry);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function runFrame(unlimited: boolean) {
|
|
226
|
+
running = true;
|
|
227
|
+
const time = now();
|
|
228
|
+
const inCombat = fighting();
|
|
229
|
+
roll(time);
|
|
230
|
+
deadline = unlimited ? Infinity : time + (inCombat ? combatBudget : normalBudget);
|
|
231
|
+
const cutoff = serial;
|
|
232
|
+
let count = 0;
|
|
233
|
+
const waitForIdle = !unlimited && driver.nowMs !== undefined && inCombat;
|
|
234
|
+
while (unlimited || count < maxJobs && (count === 0 || remainingMs() > 0)) {
|
|
235
|
+
let entry: Entry | undefined;
|
|
236
|
+
for (let offset = 0; offset < lanes.length; offset++) {
|
|
237
|
+
const index = (nextLane + offset) % lanes.length;
|
|
238
|
+
entry = ready(lanes[index], cutoff, time, waitForIdle);
|
|
239
|
+
if (!entry) continue;
|
|
240
|
+
// Carry the turn across budget boundaries, including a frame spent on one slow job.
|
|
241
|
+
nextLane = (index + 1) % lanes.length;
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
if (!entry) break;
|
|
245
|
+
count++;
|
|
246
|
+
entry.running = true;
|
|
247
|
+
const observe = driver.onJob;
|
|
248
|
+
const started = observe === undefined ? 0 : now();
|
|
249
|
+
const result = protect(entry.run);
|
|
250
|
+
entry.running = false;
|
|
251
|
+
if (byKey.get(entry.key) === entry) {
|
|
252
|
+
if (result.ok && result.value === true) {
|
|
253
|
+
current.sliced++;
|
|
254
|
+
append(entry);
|
|
255
|
+
} else byKey.delete(entry.key);
|
|
256
|
+
}
|
|
257
|
+
const failure = result.ok ? result.value : result;
|
|
258
|
+
if (typeof failure === "object") report(failure, entry.label);
|
|
259
|
+
if (observe !== undefined) {
|
|
260
|
+
const measured = protect(() => observe(entry.label, now() - started));
|
|
261
|
+
if (!measured.ok) report(fail("Frame job diagnostics: " + measured.reason), entry.label);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
deadline = undefined;
|
|
265
|
+
running = false;
|
|
266
|
+
current.ran += count;
|
|
267
|
+
current.worstMs = Math.max(current.worstMs, now() - time);
|
|
268
|
+
if (byKey.size > 0) current.deferred++;
|
|
269
|
+
else nextLane = 0;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
drive = () => {
|
|
273
|
+
if (running) return;
|
|
274
|
+
runFrame(false);
|
|
275
|
+
const delay = delayMs();
|
|
276
|
+
if (delay === undefined) {
|
|
277
|
+
cancelDriver = due = undefined;
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
due = now() + delay;
|
|
281
|
+
return delay / 1000;
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
function step(unlimited = false) {
|
|
285
|
+
if (running) return 0;
|
|
286
|
+
stopWake();
|
|
287
|
+
runFrame(unlimited);
|
|
288
|
+
wake();
|
|
289
|
+
return byKey.size;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function inspect(): FrameDiagnostics {
|
|
293
|
+
const time = now();
|
|
294
|
+
roll(time);
|
|
295
|
+
const jobs: FrameDiagnostics["jobs"][number][] = [];
|
|
296
|
+
for (const lane of lanes) {
|
|
297
|
+
for (let entry = queues[lane].head; entry; entry = entry.next) {
|
|
298
|
+
jobs.push({ key: entry.key, lane, label: entry.label, waitedMs: time - entry.queuedAt });
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return { jobs, last: snapshotStatistics(last), current: snapshotStatistics(current) };
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function queue(key: FrameKey, run: FrameJob, options?: FrameJobOptions) {
|
|
305
|
+
const lane = options?.lane ?? "normal";
|
|
306
|
+
const pending = byKey.get(key);
|
|
307
|
+
if (pending && !pending.running) {
|
|
308
|
+
roll(now());
|
|
309
|
+
current.batched++;
|
|
310
|
+
pending.run = run;
|
|
311
|
+
pending.label = options?.label ?? pending.label;
|
|
312
|
+
if (rank[lane] < rank[pending.lane]) {
|
|
313
|
+
remove(pending);
|
|
314
|
+
pending.lane = lane;
|
|
315
|
+
append(pending);
|
|
316
|
+
}
|
|
317
|
+
} else {
|
|
318
|
+
const entry = { key, run, lane, label: options?.label ?? "Frame job", queuedAt: now(), order: 0, running: false };
|
|
319
|
+
byKey.set(key, entry);
|
|
320
|
+
append(entry);
|
|
321
|
+
}
|
|
322
|
+
wake();
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
function cancel(key: FrameKey) {
|
|
326
|
+
const entry = byKey.get(key);
|
|
327
|
+
if (!entry) return;
|
|
328
|
+
byKey.delete(key);
|
|
329
|
+
if (!entry.running) remove(entry);
|
|
330
|
+
wake();
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
return { queue, cancel, remainingMs, queued: key => byKey.get(key)?.lane, combatChanged: wake, step, inspect };
|
|
334
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { ownedArray, type OwnedArray } from "./owned-collections";
|
|
2
|
+
|
|
3
|
+
export type GridTrack =
|
|
4
|
+
| { kind: "fixed"; size: number }
|
|
5
|
+
| { kind: "auto" }
|
|
6
|
+
| { kind: "fraction"; factor: number; minimum?: number };
|
|
7
|
+
|
|
8
|
+
// Bound explicit tracks and column spans before allocating repeated track lists.
|
|
9
|
+
const maxTracks = 1024;
|
|
10
|
+
|
|
11
|
+
function isSpace(character: string): boolean {
|
|
12
|
+
return character === " " || character === "\t" || character === "\n" || character === "\r" || character === "\f";
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function endOfDigits(value: string, start: number): number {
|
|
16
|
+
let end = start;
|
|
17
|
+
while (end < value.length) {
|
|
18
|
+
const character = value.charAt(end);
|
|
19
|
+
if (character < "0" || character > "9") break;
|
|
20
|
+
end += 1;
|
|
21
|
+
}
|
|
22
|
+
return end;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function skipSign(value: string, start: number): number {
|
|
26
|
+
const character = value.charAt(start);
|
|
27
|
+
return character === "+" || character === "-" ? start + 1 : start;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function readNumber(value: string, integer = false): number | undefined {
|
|
31
|
+
const start = skipSign(value, 0);
|
|
32
|
+
let end = endOfDigits(value, start);
|
|
33
|
+
if (!integer && value.charAt(end) === ".") {
|
|
34
|
+
const decimalStart = end + 1;
|
|
35
|
+
end = endOfDigits(value, decimalStart);
|
|
36
|
+
if (end === decimalStart) return undefined;
|
|
37
|
+
}
|
|
38
|
+
if (end === start) return undefined;
|
|
39
|
+
if (!integer && value.charAt(end) === "e") {
|
|
40
|
+
const exponent = skipSign(value, end + 1);
|
|
41
|
+
end = endOfDigits(value, exponent);
|
|
42
|
+
if (end === exponent) return undefined;
|
|
43
|
+
}
|
|
44
|
+
if (end !== value.length) return undefined;
|
|
45
|
+
const number = Number(value);
|
|
46
|
+
return Number.isFinite(number) && number >= 0 ? number : undefined;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function readCount(value: string): number | undefined {
|
|
50
|
+
const count = readNumber(value, true);
|
|
51
|
+
return count !== undefined && count > 0 && count <= maxTracks ? count : undefined;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function readLength(value: string): number | undefined {
|
|
55
|
+
if (value.endsWith("px")) return readNumber(value.slice(0, -2));
|
|
56
|
+
return readNumber(value) === 0 ? 0 : undefined;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function readFraction(value: string): number | undefined {
|
|
60
|
+
return value.endsWith("fr") ? readNumber(value.slice(0, -2)) : undefined;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
class GridInput {
|
|
64
|
+
private position = 0;
|
|
65
|
+
constructor(private readonly value: string) {}
|
|
66
|
+
|
|
67
|
+
skipSpace(): boolean {
|
|
68
|
+
const start = this.position;
|
|
69
|
+
while (isSpace(this.peek())) this.position += 1;
|
|
70
|
+
return this.position > start;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
take(character: string): boolean {
|
|
74
|
+
if (this.peek() !== character) return false;
|
|
75
|
+
this.position += 1;
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
readWord(): string {
|
|
80
|
+
const start = this.position;
|
|
81
|
+
let character = this.peek();
|
|
82
|
+
while (character !== "" && !isSpace(character) && character !== "(" && character !== ")" && character !== ",") {
|
|
83
|
+
this.position += 1;
|
|
84
|
+
character = this.peek();
|
|
85
|
+
}
|
|
86
|
+
return this.value.slice(start, this.position);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
atEnd(): boolean {
|
|
90
|
+
return this.position === this.value.length;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
readTracks(allowRepeat: boolean): OwnedArray<GridTrack> | undefined {
|
|
94
|
+
const tracks = ownedArray<GridTrack>();
|
|
95
|
+
this.skipSpace();
|
|
96
|
+
while (!this.atEnd() && this.peek() !== ")") {
|
|
97
|
+
const word = this.readWord();
|
|
98
|
+
if (word === "repeat") {
|
|
99
|
+
if (!allowRepeat || !this.readRepeat(tracks)) return undefined;
|
|
100
|
+
} else {
|
|
101
|
+
const track = this.readTrack(word);
|
|
102
|
+
if (track === undefined || tracks.length === maxTracks) return undefined;
|
|
103
|
+
tracks.push(track);
|
|
104
|
+
}
|
|
105
|
+
const separated = this.skipSpace();
|
|
106
|
+
if (!separated && !this.atEnd() && this.peek() !== ")") return undefined;
|
|
107
|
+
}
|
|
108
|
+
return tracks.length > 0 ? tracks : undefined;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
private peek(): string {
|
|
112
|
+
return this.value.charAt(this.position);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
private readTrack(word: string): GridTrack | undefined {
|
|
116
|
+
if (word === "minmax") return this.readMinmax();
|
|
117
|
+
if (word === "auto") return { kind: "auto" };
|
|
118
|
+
const factor = readFraction(word);
|
|
119
|
+
if (factor !== undefined) return { kind: "fraction", factor };
|
|
120
|
+
const size = readLength(word);
|
|
121
|
+
return size !== undefined ? { kind: "fixed", size } : undefined;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
private readRepeat(tracks: OwnedArray<GridTrack>): boolean {
|
|
125
|
+
if (!this.take("(")) return false;
|
|
126
|
+
this.skipSpace();
|
|
127
|
+
const count = readCount(this.readWord());
|
|
128
|
+
this.skipSpace();
|
|
129
|
+
if (count === undefined || !this.take(",")) return false;
|
|
130
|
+
const pattern = this.readTracks(false);
|
|
131
|
+
if (pattern === undefined || !this.take(")") || count * pattern.length > maxTracks - tracks.length) return false;
|
|
132
|
+
for (let repetition = 0; repetition < count; repetition += 1) {
|
|
133
|
+
for (const track of pattern) tracks.push(track);
|
|
134
|
+
}
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
private readMinmax(): GridTrack | undefined {
|
|
139
|
+
if (!this.take("(")) return undefined;
|
|
140
|
+
this.skipSpace();
|
|
141
|
+
const minimum = readLength(this.readWord());
|
|
142
|
+
this.skipSpace();
|
|
143
|
+
if (minimum === undefined || !this.take(",")) return undefined;
|
|
144
|
+
this.skipSpace();
|
|
145
|
+
const factor = readFraction(this.readWord());
|
|
146
|
+
this.skipSpace();
|
|
147
|
+
if (factor === undefined || !this.take(")")) return undefined;
|
|
148
|
+
return { kind: "fraction", factor, minimum };
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function parseGridTracks(this: void, value: string): readonly GridTrack[] | undefined {
|
|
153
|
+
const input = new GridInput(value.toLowerCase());
|
|
154
|
+
const tracks = input.readTracks(true);
|
|
155
|
+
return input.atEnd() ? tracks : undefined;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export function parseGridSpan(this: void, value: string): number | undefined {
|
|
159
|
+
const input = new GridInput(value.toLowerCase());
|
|
160
|
+
input.skipSpace();
|
|
161
|
+
if (input.readWord() !== "span" || !input.skipSpace()) return undefined;
|
|
162
|
+
const count = readCount(input.readWord());
|
|
163
|
+
input.skipSpace();
|
|
164
|
+
return input.atEnd() ? count : undefined;
|
|
165
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
declare module "*.png" {
|
|
2
|
+
const source: import("./images").ImageAsset;
|
|
3
|
+
export default source;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
declare module "*.jpg" {
|
|
7
|
+
const source: import("./images").ImageAsset;
|
|
8
|
+
export default source;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
declare module "*.jpeg" {
|
|
12
|
+
const source: import("./images").ImageAsset;
|
|
13
|
+
export default source;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare module "*.webp" {
|
|
17
|
+
const source: import("./images").ImageAsset;
|
|
18
|
+
export default source;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
declare module "*.tga" {
|
|
22
|
+
const source: import("./images").ImageAsset;
|
|
23
|
+
export default source;
|
|
24
|
+
}
|
package/src/images.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { Binding } from "./elements";
|
|
2
|
+
import { fail, ok, type Result } from "./result";
|
|
3
|
+
import type { RuntimeScope } from "./runtime";
|
|
4
|
+
import type { RGBA } from "../utils/colors";
|
|
5
|
+
|
|
6
|
+
/** A WoW image can paint a vertical fill in place of its source texture. */
|
|
7
|
+
export interface ImageVerticalGradient {
|
|
8
|
+
readonly bottom: Readonly<RGBA>;
|
|
9
|
+
readonly top: Readonly<RGBA>;
|
|
10
|
+
readonly fallback: Readonly<RGBA>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** A statically imported image, resolved for the target at build time. */
|
|
14
|
+
export interface ImageAsset {
|
|
15
|
+
readonly path: string;
|
|
16
|
+
readonly width?: number;
|
|
17
|
+
readonly height?: number;
|
|
18
|
+
readonly uMax?: number;
|
|
19
|
+
readonly vMax?: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** A decorative WoW texture in logical units relative to its frame's top-left corner. */
|
|
23
|
+
export interface NativeImageLayer {
|
|
24
|
+
readonly source: string | number;
|
|
25
|
+
readonly x: number;
|
|
26
|
+
readonly y: number;
|
|
27
|
+
readonly width: number;
|
|
28
|
+
readonly height: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function imageSize(source: ImageAsset, width?: number, height?: number) {
|
|
32
|
+
const ratio = source.width !== undefined && source.height !== undefined && source.height > 0
|
|
33
|
+
? source.width / source.height : undefined;
|
|
34
|
+
if (width === undefined && height === undefined) return { width: source.width, height: source.height };
|
|
35
|
+
if (width === undefined && height !== undefined && ratio !== undefined) return { width: height * ratio, height };
|
|
36
|
+
if (height === undefined && width !== undefined && ratio !== undefined) return { width, height: width / ratio };
|
|
37
|
+
return { width, height };
|
|
38
|
+
}
|
|
39
|
+
type SizeBinding = Binding<number | "auto">;
|
|
40
|
+
|
|
41
|
+
function readSize(binding: SizeBinding | undefined): Result<number | undefined> {
|
|
42
|
+
if (typeof binding !== "object") return ok(binding === "auto" ? undefined : binding);
|
|
43
|
+
const value = binding.value;
|
|
44
|
+
if (typeof value !== "object") return ok(value === "auto" ? undefined : value);
|
|
45
|
+
return value.ok ? ok(value.value === "auto" ? undefined : value.value) : value;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function bindImageSize(scope: RuntimeScope, source: ImageAsset, width?: SizeBinding, height?: SizeBinding) {
|
|
49
|
+
if (typeof width !== "object" && typeof height !== "object") {
|
|
50
|
+
return imageSize(source, width === "auto" ? undefined : width, height === "auto" ? undefined : height);
|
|
51
|
+
}
|
|
52
|
+
const measured = scope.computedResult(() => {
|
|
53
|
+
const w = readSize(width);
|
|
54
|
+
if (!w.ok) return w;
|
|
55
|
+
const h = readSize(height);
|
|
56
|
+
if (!h.ok) return h;
|
|
57
|
+
return ok(imageSize(source, w.value, h.value));
|
|
58
|
+
});
|
|
59
|
+
const dimension = (key: "width" | "height") => scope.computedResult(() => {
|
|
60
|
+
const current = measured.value;
|
|
61
|
+
if (!current.ok) return current;
|
|
62
|
+
const value = current.value[key];
|
|
63
|
+
return value === undefined ? fail("Image requires positive dimensions") : ok(value);
|
|
64
|
+
});
|
|
65
|
+
return { width: dimension("width"), height: dimension("height") };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function positiveImageDimension(scope: RuntimeScope, dimension: Binding<number> | undefined): Result<Binding<number>> {
|
|
69
|
+
function validate(value: number) {
|
|
70
|
+
return Number.isFinite(value) && value > 0 ? ok(value) : fail("Image requires positive dimensions");
|
|
71
|
+
}
|
|
72
|
+
if (dimension === undefined) return fail("Image requires positive dimensions");
|
|
73
|
+
if (typeof dimension === "number") return validate(dimension);
|
|
74
|
+
return ok(scope.computedResult(() => {
|
|
75
|
+
const current = dimension.value;
|
|
76
|
+
if (typeof current === "number") return validate(current);
|
|
77
|
+
return current.ok ? validate(current.value) : current;
|
|
78
|
+
}));
|
|
79
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/// <reference path="./image-imports.d.ts" />
|
|
2
|
+
/// <reference path="./jsx.d.ts" />
|
|
3
|
+
export * from "./elements";
|
|
4
|
+
export type { StatePaint, StateStyleVariant, StyleState } from "./style-states";
|
|
5
|
+
export type { ClassNames, StyleClass } from "./style-classes";
|
|
6
|
+
export type { KumiNode, MountedElementKind, NodeRect, NodeRef } from "./element-node";
|
|
7
|
+
export type { NodeQuery, SelectorError } from "./node-selectors";
|
|
8
|
+
export * from "./bindings";
|
|
9
|
+
export * from "./context";
|
|
10
|
+
export * from "./cvars";
|
|
11
|
+
export * from "./frame-scheduler";
|
|
12
|
+
export { solveLayout, type LayoutRect, type LayoutSize, type LayoutStyle } from "./flex-layout";
|
|
13
|
+
export * from "./module";
|
|
14
|
+
export { provide, serviceToken, type ResolveProviderInput, type ServiceProvider, type ServiceToken } from "./providers";
|
|
15
|
+
export * from "./images";
|
|
16
|
+
export * from "./keyed-list";
|
|
17
|
+
export { createMediaHooks, type BreakpointTable, type MediaQuery } from "./media-query";
|
|
18
|
+
export type { OwnedArray, OwnedLuaArray, OwnedReadonlyArray, OwnedRecord } from "./owned-collections";
|
|
19
|
+
export { ownedArray, ownedMap, ownedSet, type OwnedMap, type OwnedReadonlyMap, type OwnedSet } from "./owned-collections";
|
|
20
|
+
export * from "./reactivity";
|
|
21
|
+
export * from "./reactive-scope";
|
|
22
|
+
export * from "./result";
|
|
23
|
+
export { createScheduler, wait } from "./scheduler";
|
|
24
|
+
export type { Cancel, Clock, Job, RoutineStep, Scheduler, SchedulerOptions } from "./scheduler";
|
|
25
|
+
export * from "./runtime";
|
|
26
|
+
export * from "./theme";
|
|
27
|
+
export type { StyleVariables, StyleVariable } from "./style-variables";
|
|
28
|
+
export * from "./transition";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createElement, type Element, type ElementKey, type IntrinsicElements as KumiIntrinsicElements, type IntrinsicKind, type IntrinsicTag, type UIElement } from "./elements";
|
|
2
|
+
|
|
3
|
+
export { Fragment } from "./elements";
|
|
4
|
+
|
|
5
|
+
export namespace JSX {
|
|
6
|
+
export type Element = UIElement;
|
|
7
|
+
export interface IntrinsicElements extends KumiIntrinsicElements {}
|
|
8
|
+
export interface IntrinsicAttributes { key?: ElementKey }
|
|
9
|
+
export interface ElementChildrenAttribute { children: unknown }
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function jsx<K extends IntrinsicTag>(this: void, component: K, props: KumiIntrinsicElements[K], key?: ElementKey): Element<IntrinsicKind<K>>;
|
|
13
|
+
export function jsx<Props, Node extends UIElement>(this: void, component: (this: void, props: Props) => Node,
|
|
14
|
+
props: Props, key?: ElementKey): Node;
|
|
15
|
+
export function jsx<Props>(this: void, component: IntrinsicTag | ((this: void, props: Props) => UIElement),
|
|
16
|
+
props: Props, key?: ElementKey) {
|
|
17
|
+
const inputs = key === undefined ? props : { ...props, key };
|
|
18
|
+
if (typeof component === "string") return createElement(component, inputs as KumiIntrinsicElements[IntrinsicTag]);
|
|
19
|
+
return createElement(component, inputs);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const jsxs = jsx;
|
package/src/jsx.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ElementKey, IntrinsicElements as KumiIntrinsicElements, UIElement } from "./elements";
|
|
2
|
+
|
|
3
|
+
declare global {
|
|
4
|
+
namespace JSX {
|
|
5
|
+
type Element = UIElement;
|
|
6
|
+
interface IntrinsicElements extends KumiIntrinsicElements {}
|
|
7
|
+
interface IntrinsicAttributes { key?: ElementKey }
|
|
8
|
+
interface ElementChildrenAttribute {
|
|
9
|
+
children: unknown;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|