@czap/worker 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 +19 -0
- package/dist/compositor-script.d.ts +19 -0
- package/dist/compositor-script.d.ts.map +1 -0
- package/dist/compositor-script.js +374 -0
- package/dist/compositor-script.js.map +1 -0
- package/dist/compositor-startup.d.ts +200 -0
- package/dist/compositor-startup.d.ts.map +1 -0
- package/dist/compositor-startup.js +490 -0
- package/dist/compositor-startup.js.map +1 -0
- package/dist/compositor-types.d.ts +135 -0
- package/dist/compositor-types.d.ts.map +1 -0
- package/dist/compositor-types.js +7 -0
- package/dist/compositor-types.js.map +1 -0
- package/dist/compositor-worker.d.ts +65 -0
- package/dist/compositor-worker.d.ts.map +1 -0
- package/dist/compositor-worker.js +454 -0
- package/dist/compositor-worker.js.map +1 -0
- package/dist/evaluate-inline.d.ts +22 -0
- package/dist/evaluate-inline.d.ts.map +1 -0
- package/dist/evaluate-inline.js +42 -0
- package/dist/evaluate-inline.js.map +1 -0
- package/dist/host.d.ts +97 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +115 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +40 -0
- package/dist/index.js.map +1 -0
- package/dist/messages.d.ts +254 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +55 -0
- package/dist/messages.js.map +1 -0
- package/dist/render-worker.d.ts +77 -0
- package/dist/render-worker.d.ts.map +1 -0
- package/dist/render-worker.js +396 -0
- package/dist/render-worker.js.map +1 -0
- package/dist/spsc-ring.d.ts +171 -0
- package/dist/spsc-ring.d.ts.map +1 -0
- package/dist/spsc-ring.js +240 -0
- package/dist/spsc-ring.js.map +1 -0
- package/package.json +51 -0
- package/src/compositor-script.ts +374 -0
- package/src/compositor-startup.ts +666 -0
- package/src/compositor-types.ts +175 -0
- package/src/compositor-worker.ts +613 -0
- package/src/evaluate-inline.ts +42 -0
- package/src/host.ts +189 -0
- package/src/index.ts +49 -0
- package/src/messages.ts +343 -0
- package/src/render-worker.ts +454 -0
- package/src/spsc-ring.ts +309 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-2026 Eassa Ayoub <eassa@heyoub.dev>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# @czap/worker
|
|
2
|
+
|
|
3
|
+
Off-thread: SPSC ring buffer, compositor worker, render worker, OffscreenCanvas.
|
|
4
|
+
|
|
5
|
+
## Docs
|
|
6
|
+
|
|
7
|
+
- [Naming & vocabulary](../../docs/GLOSSARY.md) — LiteShip, CZAP, `@czap/*`
|
|
8
|
+
|
|
9
|
+
- [API reference](https://github.com/heyoub/LiteShip/tree/main/docs/api/worker/) — generated from source TSDoc
|
|
10
|
+
- [Architecture index](https://github.com/heyoub/LiteShip/blob/main/docs/ARCHITECTURE.md)
|
|
11
|
+
- [ADRs](https://github.com/heyoub/LiteShip/tree/main/docs/adr/)
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pnpm add @czap/worker
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Part of [LiteShip](https://github.com/heyoub/LiteShip#readme)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inline worker script implementing a simplified compositor.
|
|
3
|
+
*
|
|
4
|
+
* This string is turned into a Blob URL at runtime so no separate
|
|
5
|
+
* worker file is needed. It cannot use ES module imports since it
|
|
6
|
+
* runs inside a classic Worker created from a Blob.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* JavaScript source of the inline compositor worker.
|
|
12
|
+
*
|
|
13
|
+
* The string is wrapped in a `Blob` at runtime and fed to the
|
|
14
|
+
* `Worker(url)` constructor, so this package ships without a separate
|
|
15
|
+
* worker entry file or bundler glue. Keep this source ES5-compatible:
|
|
16
|
+
* it runs inside a classic Worker and cannot use ES module imports.
|
|
17
|
+
*/
|
|
18
|
+
export declare const COMPOSITOR_WORKER_SCRIPT = "\n\"use strict\";\n\n// ---------------------------------------------------------------------------\n// Simplified compositor state inside the worker\n// ---------------------------------------------------------------------------\n\n/** @type {Map<string, { id: string; states: string[]; thresholds: number[]; currentState: string; currentGeneration: number; cssKey: string|null; glslKey: string|null; ariaKey: string|null; oneHotWeights: Record<string, Record<string, number>>|null; _keysResolved: boolean }>} */\nconst quantizers = new Map();\n\n/** @type {Map<string, Record<string, number>>} */\nconst blendOverrides = new Map();\n\n/** @type {Set<string>} */\nconst dirtyNames = new Set();\n\nconst MS_PER_SEC = 1000;\n\n/** @type {number} */\nlet lastComputeTime = 0;\nlet frameCount = 0;\nlet fpsAccum = 0;\nlet currentFps = 0;\n\nfunction removeQuantizer(name) {\n quantizers.delete(name);\n blendOverrides.delete(name);\n dirtyNames.delete(name);\n}\n\nfunction evaluateQuantizer(name, value) {\n const q = quantizers.get(name);\n if (q) {\n const newState = evaluateThresholds(q.thresholds, q.states, value);\n if (newState !== q.currentState) {\n q.currentState = newState;\n dirtyNames.add(name);\n }\n }\n}\n\nfunction setBlendWeights(name, weights) {\n blendOverrides.set(name, weights);\n dirtyNames.add(name);\n}\n\nfunction applyResolvedStateEntry(entry) {\n const q = quantizers.get(entry.name);\n if (!q) {\n return;\n }\n\n const nextGeneration = typeof entry.generation === \"number\" ? entry.generation : q.currentGeneration;\n const changed = entry.state !== q.currentState || nextGeneration !== q.currentGeneration;\n q.currentState = entry.state;\n q.currentGeneration = nextGeneration;\n if (changed) {\n dirtyNames.add(entry.name);\n }\n}\n\nfunction applyUpdate(update) {\n switch (update.type) {\n case \"remove-quantizer\":\n removeQuantizer(update.name);\n break;\n case \"evaluate\":\n evaluateQuantizer(update.name, update.value);\n break;\n case \"set-blend\":\n setBlendWeights(update.name, update.weights);\n break;\n }\n}\n\nfunction registerQuantizer(registration) {\n const initialState =\n typeof registration.initialState === \"string\"\n ? registration.initialState\n : registration.states[0] || \"\";\n const thresholdsRaw = registration.thresholds;\n const thresholds = thresholdsRaw instanceof Float64Array\n ? Array.from(thresholdsRaw)\n : Array.from(thresholdsRaw);\n quantizers.set(registration.name, {\n id: registration.boundaryId,\n states: Array.from(registration.states),\n thresholds: thresholds,\n currentState: initialState,\n currentGeneration: 0,\n cssKey: null,\n glslKey: null,\n ariaKey: null,\n oneHotWeights: null,\n _keysResolved: false,\n });\n if (registration.blendWeights && typeof registration.blendWeights === \"object\") {\n blendOverrides.set(registration.name, registration.blendWeights);\n } else {\n blendOverrides.delete(registration.name);\n }\n dirtyNames.add(registration.name);\n}\n\nfunction resolveOutputKeys(q, name) {\n if (q._keysResolved) return;\n q.cssKey = \"--czap-\" + name;\n q.glslKey = \"u_\" + name;\n q.ariaKey = \"data-czap-\" + name;\n q.oneHotWeights = Object.fromEntries(\n q.states.map((activeState) => [\n activeState,\n Object.fromEntries(\n q.states.map((stateName) => [stateName, stateName === activeState ? 1 : 0]),\n ),\n ]),\n );\n q._keysResolved = true;\n}\n\nfunction resetWorkerState() {\n quantizers.clear();\n blendOverrides.clear();\n dirtyNames.clear();\n}\n\n/**\n * Evaluate which discrete state a value falls into based on thresholds.\n * Thresholds are sorted ascending; the value maps to the state whose\n * threshold it first exceeds (or the first state if below all thresholds).\n *\n * @param {number[]} thresholds\n * @param {string[]} states\n * @param {number} value\n * @returns {string}\n */\nfunction evaluateThresholds(thresholds, states, value) {\n for (let i = thresholds.length - 1; i >= 0; i--) {\n if (value >= thresholds[i]) {\n return states[i] || states[0] || \"\";\n }\n }\n return states[0] || \"\";\n}\n\n/**\n * Build a CompositeState from the current quantizer state.\n * @returns {{ discrete: Record<string, string>; blend: Record<string, Record<string, number>>; outputs: { css: Record<string, number|string>; glsl: Record<string, number>; aria: Record<string, string> } }}\n */\nfunction compute() {\n const now = typeof performance !== \"undefined\" ? performance.now() : Date.now();\n\n const discrete = {};\n const blend = {};\n const css = {};\n const glsl = {};\n const aria = {};\n const resolvedStateGenerations = {};\n\n // Only recompute dirty quantizers if we have a dirty set,\n // otherwise recompute all (initial case or fallback).\n const names = dirtyNames.size > 0\n ? Array.from(dirtyNames)\n : Array.from(quantizers.keys());\n\n for (const name of names) {\n const q = quantizers.get(name);\n if (!q) continue;\n\n // Lazily resolve output keys on first compute\n resolveOutputKeys(q, name);\n\n const stateStr = q.currentState;\n discrete[name] = stateStr;\n resolvedStateGenerations[name] = q.currentGeneration;\n\n // Blend weights\n const override = blendOverrides.get(name);\n if (override !== undefined) {\n blend[name] = override;\n } else {\n blend[name] = q.oneHotWeights[stateStr] || {};\n }\n\n // CSS output\n css[q.cssKey] = stateStr;\n\n // GLSL output: index of current state\n let stateIndex = 0;\n for (let i = 0; i < q.states.length; i++) {\n if (q.states[i] === stateStr) {\n stateIndex = i;\n break;\n }\n }\n glsl[q.glslKey] = stateIndex;\n\n // ARIA output\n aria[q.ariaKey] = stateStr;\n }\n\n dirtyNames.clear();\n\n // Metrics\n if (lastComputeTime > 0) {\n const dt = now - lastComputeTime;\n frameCount++;\n fpsAccum += dt;\n if (fpsAccum >= MS_PER_SEC) {\n currentFps = Math.round((frameCount * MS_PER_SEC) / fpsAccum);\n frameCount = 0;\n fpsAccum -= MS_PER_SEC;\n\n self.postMessage({\n type: \"metrics\",\n fps: currentFps,\n budgetUsed: dt,\n });\n }\n }\n lastComputeTime = now;\n\n return { discrete, blend, outputs: { css, glsl, aria }, resolvedStateGenerations };\n}\n\n// ---------------------------------------------------------------------------\n// Message handler\n// ---------------------------------------------------------------------------\n\nself.addEventListener(\"message\", function (e) {\n const msg = e.data;\n if (!msg || typeof msg.type !== \"string\") return;\n\n switch (msg.type) {\n case \"init\": {\n // Reset state on init\n resetWorkerState();\n self.postMessage({ type: \"ready\" });\n break;\n }\n\n case \"add-quantizer\": {\n registerQuantizer(msg);\n break;\n }\n\n case \"bootstrap-quantizers\": {\n for (const registration of msg.registrations) {\n registerQuantizer(registration);\n }\n break;\n }\n\n case \"startup-compute\": {\n resetWorkerState();\n const packet = msg.packet ?? { registrations: [], updates: [] };\n for (const registration of packet.registrations) {\n registerQuantizer(registration);\n }\n for (const update of packet.updates) {\n applyUpdate(update);\n }\n try {\n const state = compute();\n self.postMessage({ type: \"state\", state: state, resolvedStateGenerations: state.resolvedStateGenerations });\n } catch (err) {\n self.postMessage({\n type: \"error\",\n message: err instanceof Error ? err.message : String(err),\n });\n }\n break;\n }\n\n case \"bootstrap-resolved-state\": {\n for (const entry of msg.states) {\n applyResolvedStateEntry(entry);\n }\n if (msg.ack === true) {\n self.postMessage({\n type: \"resolved-state-ack\",\n generation: typeof msg.states[0]?.generation === \"number\" ? msg.states[0].generation : 0,\n states: msg.states.map((entry) => ({ name: entry.name, state: entry.state })),\n additionalOutputsChanged: false,\n });\n }\n break;\n }\n\n case \"apply-resolved-state\": {\n for (const entry of msg.states) {\n applyResolvedStateEntry(entry);\n }\n if (msg.ack === true) {\n self.postMessage({\n type: \"resolved-state-ack\",\n generation: typeof msg.states[0]?.generation === \"number\" ? msg.states[0].generation : 0,\n states: msg.states.map((entry) => ({ name: entry.name, state: entry.state })),\n additionalOutputsChanged: false,\n });\n }\n break;\n }\n\n case \"remove-quantizer\": {\n removeQuantizer(msg.name);\n break;\n }\n\n case \"evaluate\": {\n evaluateQuantizer(msg.name, msg.value);\n break;\n }\n\n case \"set-blend\": {\n setBlendWeights(msg.name, msg.weights);\n break;\n }\n\n case \"apply-updates\": {\n for (const update of msg.updates) {\n applyUpdate(update);\n }\n break;\n }\n\n case \"warm-reset\": {\n blendOverrides.clear();\n dirtyNames.clear();\n for (const quantizer of quantizers.values()) {\n quantizer.currentState = quantizer.states[0] || \"\";\n }\n break;\n }\n\n case \"compute\": {\n try {\n const state = compute();\n self.postMessage({ type: \"state\", state: state, resolvedStateGenerations: state.resolvedStateGenerations });\n } catch (err) {\n self.postMessage({\n type: \"error\",\n message: err instanceof Error ? err.message : String(err),\n });\n }\n break;\n }\n\n case \"dispose\": {\n resetWorkerState();\n self.close();\n break;\n }\n }\n});\n";
|
|
19
|
+
//# sourceMappingURL=compositor-script.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compositor-script.d.ts","sourceRoot":"","sources":["../src/compositor-script.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,y1TAmWpC,CAAC"}
|
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inline worker script implementing a simplified compositor.
|
|
3
|
+
*
|
|
4
|
+
* This string is turned into a Blob URL at runtime so no separate
|
|
5
|
+
* worker file is needed. It cannot use ES module imports since it
|
|
6
|
+
* runs inside a classic Worker created from a Blob.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* JavaScript source of the inline compositor worker.
|
|
12
|
+
*
|
|
13
|
+
* The string is wrapped in a `Blob` at runtime and fed to the
|
|
14
|
+
* `Worker(url)` constructor, so this package ships without a separate
|
|
15
|
+
* worker entry file or bundler glue. Keep this source ES5-compatible:
|
|
16
|
+
* it runs inside a classic Worker and cannot use ES module imports.
|
|
17
|
+
*/
|
|
18
|
+
export const COMPOSITOR_WORKER_SCRIPT = /* js */ `
|
|
19
|
+
"use strict";
|
|
20
|
+
|
|
21
|
+
// ---------------------------------------------------------------------------
|
|
22
|
+
// Simplified compositor state inside the worker
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
|
|
25
|
+
/** @type {Map<string, { id: string; states: string[]; thresholds: number[]; currentState: string; currentGeneration: number; cssKey: string|null; glslKey: string|null; ariaKey: string|null; oneHotWeights: Record<string, Record<string, number>>|null; _keysResolved: boolean }>} */
|
|
26
|
+
const quantizers = new Map();
|
|
27
|
+
|
|
28
|
+
/** @type {Map<string, Record<string, number>>} */
|
|
29
|
+
const blendOverrides = new Map();
|
|
30
|
+
|
|
31
|
+
/** @type {Set<string>} */
|
|
32
|
+
const dirtyNames = new Set();
|
|
33
|
+
|
|
34
|
+
const MS_PER_SEC = 1000;
|
|
35
|
+
|
|
36
|
+
/** @type {number} */
|
|
37
|
+
let lastComputeTime = 0;
|
|
38
|
+
let frameCount = 0;
|
|
39
|
+
let fpsAccum = 0;
|
|
40
|
+
let currentFps = 0;
|
|
41
|
+
|
|
42
|
+
function removeQuantizer(name) {
|
|
43
|
+
quantizers.delete(name);
|
|
44
|
+
blendOverrides.delete(name);
|
|
45
|
+
dirtyNames.delete(name);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function evaluateQuantizer(name, value) {
|
|
49
|
+
const q = quantizers.get(name);
|
|
50
|
+
if (q) {
|
|
51
|
+
const newState = evaluateThresholds(q.thresholds, q.states, value);
|
|
52
|
+
if (newState !== q.currentState) {
|
|
53
|
+
q.currentState = newState;
|
|
54
|
+
dirtyNames.add(name);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function setBlendWeights(name, weights) {
|
|
60
|
+
blendOverrides.set(name, weights);
|
|
61
|
+
dirtyNames.add(name);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function applyResolvedStateEntry(entry) {
|
|
65
|
+
const q = quantizers.get(entry.name);
|
|
66
|
+
if (!q) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const nextGeneration = typeof entry.generation === "number" ? entry.generation : q.currentGeneration;
|
|
71
|
+
const changed = entry.state !== q.currentState || nextGeneration !== q.currentGeneration;
|
|
72
|
+
q.currentState = entry.state;
|
|
73
|
+
q.currentGeneration = nextGeneration;
|
|
74
|
+
if (changed) {
|
|
75
|
+
dirtyNames.add(entry.name);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function applyUpdate(update) {
|
|
80
|
+
switch (update.type) {
|
|
81
|
+
case "remove-quantizer":
|
|
82
|
+
removeQuantizer(update.name);
|
|
83
|
+
break;
|
|
84
|
+
case "evaluate":
|
|
85
|
+
evaluateQuantizer(update.name, update.value);
|
|
86
|
+
break;
|
|
87
|
+
case "set-blend":
|
|
88
|
+
setBlendWeights(update.name, update.weights);
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function registerQuantizer(registration) {
|
|
94
|
+
const initialState =
|
|
95
|
+
typeof registration.initialState === "string"
|
|
96
|
+
? registration.initialState
|
|
97
|
+
: registration.states[0] || "";
|
|
98
|
+
const thresholdsRaw = registration.thresholds;
|
|
99
|
+
const thresholds = thresholdsRaw instanceof Float64Array
|
|
100
|
+
? Array.from(thresholdsRaw)
|
|
101
|
+
: Array.from(thresholdsRaw);
|
|
102
|
+
quantizers.set(registration.name, {
|
|
103
|
+
id: registration.boundaryId,
|
|
104
|
+
states: Array.from(registration.states),
|
|
105
|
+
thresholds: thresholds,
|
|
106
|
+
currentState: initialState,
|
|
107
|
+
currentGeneration: 0,
|
|
108
|
+
cssKey: null,
|
|
109
|
+
glslKey: null,
|
|
110
|
+
ariaKey: null,
|
|
111
|
+
oneHotWeights: null,
|
|
112
|
+
_keysResolved: false,
|
|
113
|
+
});
|
|
114
|
+
if (registration.blendWeights && typeof registration.blendWeights === "object") {
|
|
115
|
+
blendOverrides.set(registration.name, registration.blendWeights);
|
|
116
|
+
} else {
|
|
117
|
+
blendOverrides.delete(registration.name);
|
|
118
|
+
}
|
|
119
|
+
dirtyNames.add(registration.name);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function resolveOutputKeys(q, name) {
|
|
123
|
+
if (q._keysResolved) return;
|
|
124
|
+
q.cssKey = "--czap-" + name;
|
|
125
|
+
q.glslKey = "u_" + name;
|
|
126
|
+
q.ariaKey = "data-czap-" + name;
|
|
127
|
+
q.oneHotWeights = Object.fromEntries(
|
|
128
|
+
q.states.map((activeState) => [
|
|
129
|
+
activeState,
|
|
130
|
+
Object.fromEntries(
|
|
131
|
+
q.states.map((stateName) => [stateName, stateName === activeState ? 1 : 0]),
|
|
132
|
+
),
|
|
133
|
+
]),
|
|
134
|
+
);
|
|
135
|
+
q._keysResolved = true;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function resetWorkerState() {
|
|
139
|
+
quantizers.clear();
|
|
140
|
+
blendOverrides.clear();
|
|
141
|
+
dirtyNames.clear();
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Evaluate which discrete state a value falls into based on thresholds.
|
|
146
|
+
* Thresholds are sorted ascending; the value maps to the state whose
|
|
147
|
+
* threshold it first exceeds (or the first state if below all thresholds).
|
|
148
|
+
*
|
|
149
|
+
* @param {number[]} thresholds
|
|
150
|
+
* @param {string[]} states
|
|
151
|
+
* @param {number} value
|
|
152
|
+
* @returns {string}
|
|
153
|
+
*/
|
|
154
|
+
function evaluateThresholds(thresholds, states, value) {
|
|
155
|
+
for (let i = thresholds.length - 1; i >= 0; i--) {
|
|
156
|
+
if (value >= thresholds[i]) {
|
|
157
|
+
return states[i] || states[0] || "";
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return states[0] || "";
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Build a CompositeState from the current quantizer state.
|
|
165
|
+
* @returns {{ discrete: Record<string, string>; blend: Record<string, Record<string, number>>; outputs: { css: Record<string, number|string>; glsl: Record<string, number>; aria: Record<string, string> } }}
|
|
166
|
+
*/
|
|
167
|
+
function compute() {
|
|
168
|
+
const now = typeof performance !== "undefined" ? performance.now() : Date.now();
|
|
169
|
+
|
|
170
|
+
const discrete = {};
|
|
171
|
+
const blend = {};
|
|
172
|
+
const css = {};
|
|
173
|
+
const glsl = {};
|
|
174
|
+
const aria = {};
|
|
175
|
+
const resolvedStateGenerations = {};
|
|
176
|
+
|
|
177
|
+
// Only recompute dirty quantizers if we have a dirty set,
|
|
178
|
+
// otherwise recompute all (initial case or fallback).
|
|
179
|
+
const names = dirtyNames.size > 0
|
|
180
|
+
? Array.from(dirtyNames)
|
|
181
|
+
: Array.from(quantizers.keys());
|
|
182
|
+
|
|
183
|
+
for (const name of names) {
|
|
184
|
+
const q = quantizers.get(name);
|
|
185
|
+
if (!q) continue;
|
|
186
|
+
|
|
187
|
+
// Lazily resolve output keys on first compute
|
|
188
|
+
resolveOutputKeys(q, name);
|
|
189
|
+
|
|
190
|
+
const stateStr = q.currentState;
|
|
191
|
+
discrete[name] = stateStr;
|
|
192
|
+
resolvedStateGenerations[name] = q.currentGeneration;
|
|
193
|
+
|
|
194
|
+
// Blend weights
|
|
195
|
+
const override = blendOverrides.get(name);
|
|
196
|
+
if (override !== undefined) {
|
|
197
|
+
blend[name] = override;
|
|
198
|
+
} else {
|
|
199
|
+
blend[name] = q.oneHotWeights[stateStr] || {};
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// CSS output
|
|
203
|
+
css[q.cssKey] = stateStr;
|
|
204
|
+
|
|
205
|
+
// GLSL output: index of current state
|
|
206
|
+
let stateIndex = 0;
|
|
207
|
+
for (let i = 0; i < q.states.length; i++) {
|
|
208
|
+
if (q.states[i] === stateStr) {
|
|
209
|
+
stateIndex = i;
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
glsl[q.glslKey] = stateIndex;
|
|
214
|
+
|
|
215
|
+
// ARIA output
|
|
216
|
+
aria[q.ariaKey] = stateStr;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
dirtyNames.clear();
|
|
220
|
+
|
|
221
|
+
// Metrics
|
|
222
|
+
if (lastComputeTime > 0) {
|
|
223
|
+
const dt = now - lastComputeTime;
|
|
224
|
+
frameCount++;
|
|
225
|
+
fpsAccum += dt;
|
|
226
|
+
if (fpsAccum >= MS_PER_SEC) {
|
|
227
|
+
currentFps = Math.round((frameCount * MS_PER_SEC) / fpsAccum);
|
|
228
|
+
frameCount = 0;
|
|
229
|
+
fpsAccum -= MS_PER_SEC;
|
|
230
|
+
|
|
231
|
+
self.postMessage({
|
|
232
|
+
type: "metrics",
|
|
233
|
+
fps: currentFps,
|
|
234
|
+
budgetUsed: dt,
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
lastComputeTime = now;
|
|
239
|
+
|
|
240
|
+
return { discrete, blend, outputs: { css, glsl, aria }, resolvedStateGenerations };
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// ---------------------------------------------------------------------------
|
|
244
|
+
// Message handler
|
|
245
|
+
// ---------------------------------------------------------------------------
|
|
246
|
+
|
|
247
|
+
self.addEventListener("message", function (e) {
|
|
248
|
+
const msg = e.data;
|
|
249
|
+
if (!msg || typeof msg.type !== "string") return;
|
|
250
|
+
|
|
251
|
+
switch (msg.type) {
|
|
252
|
+
case "init": {
|
|
253
|
+
// Reset state on init
|
|
254
|
+
resetWorkerState();
|
|
255
|
+
self.postMessage({ type: "ready" });
|
|
256
|
+
break;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
case "add-quantizer": {
|
|
260
|
+
registerQuantizer(msg);
|
|
261
|
+
break;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
case "bootstrap-quantizers": {
|
|
265
|
+
for (const registration of msg.registrations) {
|
|
266
|
+
registerQuantizer(registration);
|
|
267
|
+
}
|
|
268
|
+
break;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
case "startup-compute": {
|
|
272
|
+
resetWorkerState();
|
|
273
|
+
const packet = msg.packet ?? { registrations: [], updates: [] };
|
|
274
|
+
for (const registration of packet.registrations) {
|
|
275
|
+
registerQuantizer(registration);
|
|
276
|
+
}
|
|
277
|
+
for (const update of packet.updates) {
|
|
278
|
+
applyUpdate(update);
|
|
279
|
+
}
|
|
280
|
+
try {
|
|
281
|
+
const state = compute();
|
|
282
|
+
self.postMessage({ type: "state", state: state, resolvedStateGenerations: state.resolvedStateGenerations });
|
|
283
|
+
} catch (err) {
|
|
284
|
+
self.postMessage({
|
|
285
|
+
type: "error",
|
|
286
|
+
message: err instanceof Error ? err.message : String(err),
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
case "bootstrap-resolved-state": {
|
|
293
|
+
for (const entry of msg.states) {
|
|
294
|
+
applyResolvedStateEntry(entry);
|
|
295
|
+
}
|
|
296
|
+
if (msg.ack === true) {
|
|
297
|
+
self.postMessage({
|
|
298
|
+
type: "resolved-state-ack",
|
|
299
|
+
generation: typeof msg.states[0]?.generation === "number" ? msg.states[0].generation : 0,
|
|
300
|
+
states: msg.states.map((entry) => ({ name: entry.name, state: entry.state })),
|
|
301
|
+
additionalOutputsChanged: false,
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
break;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
case "apply-resolved-state": {
|
|
308
|
+
for (const entry of msg.states) {
|
|
309
|
+
applyResolvedStateEntry(entry);
|
|
310
|
+
}
|
|
311
|
+
if (msg.ack === true) {
|
|
312
|
+
self.postMessage({
|
|
313
|
+
type: "resolved-state-ack",
|
|
314
|
+
generation: typeof msg.states[0]?.generation === "number" ? msg.states[0].generation : 0,
|
|
315
|
+
states: msg.states.map((entry) => ({ name: entry.name, state: entry.state })),
|
|
316
|
+
additionalOutputsChanged: false,
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
break;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
case "remove-quantizer": {
|
|
323
|
+
removeQuantizer(msg.name);
|
|
324
|
+
break;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
case "evaluate": {
|
|
328
|
+
evaluateQuantizer(msg.name, msg.value);
|
|
329
|
+
break;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
case "set-blend": {
|
|
333
|
+
setBlendWeights(msg.name, msg.weights);
|
|
334
|
+
break;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
case "apply-updates": {
|
|
338
|
+
for (const update of msg.updates) {
|
|
339
|
+
applyUpdate(update);
|
|
340
|
+
}
|
|
341
|
+
break;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
case "warm-reset": {
|
|
345
|
+
blendOverrides.clear();
|
|
346
|
+
dirtyNames.clear();
|
|
347
|
+
for (const quantizer of quantizers.values()) {
|
|
348
|
+
quantizer.currentState = quantizer.states[0] || "";
|
|
349
|
+
}
|
|
350
|
+
break;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
case "compute": {
|
|
354
|
+
try {
|
|
355
|
+
const state = compute();
|
|
356
|
+
self.postMessage({ type: "state", state: state, resolvedStateGenerations: state.resolvedStateGenerations });
|
|
357
|
+
} catch (err) {
|
|
358
|
+
self.postMessage({
|
|
359
|
+
type: "error",
|
|
360
|
+
message: err instanceof Error ? err.message : String(err),
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
break;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
case "dispose": {
|
|
367
|
+
resetWorkerState();
|
|
368
|
+
self.close();
|
|
369
|
+
break;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
`;
|
|
374
|
+
//# sourceMappingURL=compositor-script.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compositor-script.js","sourceRoot":"","sources":["../src/compositor-script.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,QAAQ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmWhD,CAAC"}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Startup packet building, startup mode management, and compositor lease
|
|
3
|
+
* lifecycle helpers for the CompositorWorker module.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { RuntimeCoordinator } from '@czap/core';
|
|
8
|
+
import type { ToWorkerMessage, WorkerUpdate, BootstrapQuantizerRegistration, StartupComputePacket, ResolvedStateEntry } from './messages.js';
|
|
9
|
+
import type { CompositorWorkerStartupTelemetry, CompositorWorkerStartupDiagnosticStage, ResolvedStateAckPayload, StartupPacketState } from './compositor-types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Return the current high-resolution wall-clock time in nanoseconds.
|
|
12
|
+
*
|
|
13
|
+
* Uses `performance.now()` when available; falls back to `Date.now()`
|
|
14
|
+
* in environments without the performance timeline.
|
|
15
|
+
*/
|
|
16
|
+
export declare function currentTimeNs(): number;
|
|
17
|
+
/**
|
|
18
|
+
* Forward a fine-grained startup-diagnostic duration sample to a
|
|
19
|
+
* telemetry sink (if the sink opts into diagnostic stages).
|
|
20
|
+
*
|
|
21
|
+
* Safe to call when `telemetry` is undefined or does not implement
|
|
22
|
+
* `recordDiagnosticStage` -- the call becomes a no-op.
|
|
23
|
+
*/
|
|
24
|
+
export declare function recordStartupDiagnosticStage(telemetry: CompositorWorkerStartupTelemetry | undefined, stage: CompositorWorkerStartupDiagnosticStage, durationNs: number): void;
|
|
25
|
+
/**
|
|
26
|
+
* Notify a telemetry sink that the worker acknowledged a resolved-state
|
|
27
|
+
* hydration. Safe to call when the sink does not implement
|
|
28
|
+
* `onResolvedStateSettled`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function notifyResolvedStateSettled(telemetry: CompositorWorkerStartupTelemetry | undefined, states: readonly ResolvedStateEntry[]): void;
|
|
31
|
+
/**
|
|
32
|
+
* Project a set of bootstrap registrations down to the minimal
|
|
33
|
+
* `{ name, states }` shape the runtime coordinator needs to seed its
|
|
34
|
+
* quantizer registry.
|
|
35
|
+
*/
|
|
36
|
+
export declare function registrationsToRuntimeSeed(registrations: readonly BootstrapQuantizerRegistration[]): readonly {
|
|
37
|
+
readonly name: string;
|
|
38
|
+
readonly states: readonly string[];
|
|
39
|
+
}[];
|
|
40
|
+
/**
|
|
41
|
+
* Build a fresh {@link StartupPacketState} seeded with an initial
|
|
42
|
+
* bootstrap mode and registration list. Used by the compositor worker to
|
|
43
|
+
* stage messages before flushing them in a single `startup-compute` post.
|
|
44
|
+
*/
|
|
45
|
+
export declare function createStartupPacketState(bootstrapMode: StartupComputePacket['bootstrapMode'], initialRegistrations?: readonly BootstrapQuantizerRegistration[]): StartupPacketState;
|
|
46
|
+
/**
|
|
47
|
+
* Snapshot a {@link StartupPacketState} into an immutable
|
|
48
|
+
* {@link StartupComputePacket} suitable for `postMessage`.
|
|
49
|
+
*/
|
|
50
|
+
export declare function buildStartupComputePacket(packet: StartupPacketState): StartupComputePacket;
|
|
51
|
+
/**
|
|
52
|
+
* Return the ordered list of registrations in the startup packet,
|
|
53
|
+
* caching the result so repeated reads are O(1).
|
|
54
|
+
*/
|
|
55
|
+
export declare function getStartupPacketRegistrations(packet: StartupPacketState): readonly BootstrapQuantizerRegistration[];
|
|
56
|
+
/**
|
|
57
|
+
* Return the runtime-seed projection of the startup packet's
|
|
58
|
+
* registrations, recomputing on demand if invalidated.
|
|
59
|
+
*/
|
|
60
|
+
export declare function getStartupPacketRuntimeSeed(packet: StartupPacketState): readonly {
|
|
61
|
+
readonly name: string;
|
|
62
|
+
readonly states: readonly string[];
|
|
63
|
+
}[];
|
|
64
|
+
/**
|
|
65
|
+
* Return `true` when the given runtime coordinator already has every
|
|
66
|
+
* quantizer referenced by the runtime seed registered (by name).
|
|
67
|
+
*
|
|
68
|
+
* Used to decide whether a pre-warmed lease's runtime can be reused
|
|
69
|
+
* as-is or must be reset before replay.
|
|
70
|
+
*/
|
|
71
|
+
export declare function runtimeMatchesStartupSeed(runtime: RuntimeCoordinator.Shape, runtimeSeed: readonly {
|
|
72
|
+
readonly name: string;
|
|
73
|
+
readonly states: readonly string[];
|
|
74
|
+
}[]): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Insert or overwrite a registration in the startup packet, invalidating
|
|
77
|
+
* derived caches. Pass `invalidateRuntimeSeed: false` when the caller
|
|
78
|
+
* already knows the runtime seed is structurally unchanged (e.g. only
|
|
79
|
+
* initial state or blend weights changed).
|
|
80
|
+
*/
|
|
81
|
+
export declare function setStartupPacketRegistration(packet: StartupPacketState, registration: BootstrapQuantizerRegistration, invalidateRuntimeSeed?: boolean): void;
|
|
82
|
+
/**
|
|
83
|
+
* Drop a registration by name from the startup packet and invalidate
|
|
84
|
+
* derived caches.
|
|
85
|
+
*/
|
|
86
|
+
export declare function removeStartupPacketRegistration(packet: StartupPacketState, name: string): void;
|
|
87
|
+
/**
|
|
88
|
+
* Queue a {@link WorkerUpdate} to be replayed after bootstrap. Order is
|
|
89
|
+
* preserved to match main-thread issue order.
|
|
90
|
+
*/
|
|
91
|
+
export declare function pushStartupPacketUpdate(packet: StartupPacketState, update: WorkerUpdate): void;
|
|
92
|
+
/**
|
|
93
|
+
* Filter the packet's pending update queue in-place. Typically used to
|
|
94
|
+
* drop redundant updates (e.g. newer `set-blend` supersedes older ones).
|
|
95
|
+
*/
|
|
96
|
+
export declare function filterStartupPacketUpdates(packet: StartupPacketState, keep: (update: WorkerUpdate) => boolean): void;
|
|
97
|
+
/**
|
|
98
|
+
* Structural equality check for `Record<string, number>` blend-weight
|
|
99
|
+
* maps. `undefined === undefined` is true; mismatched presence is false.
|
|
100
|
+
*/
|
|
101
|
+
export declare function sameNumericRecord(left: Record<string, number> | undefined, right: Record<string, number> | undefined): boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Merge an updated initial-state assignment into an existing registration.
|
|
104
|
+
* Also scrubs any queued `evaluate` update targeting the same quantizer,
|
|
105
|
+
* since the new initial state supersedes it.
|
|
106
|
+
*/
|
|
107
|
+
export declare function setStartupPacketInitialState(packet: StartupPacketState, registration: BootstrapQuantizerRegistration, state: string): void;
|
|
108
|
+
/**
|
|
109
|
+
* Merge updated blend weights for an existing registration. Returns
|
|
110
|
+
* `false` when no registration with that name is present (the update is
|
|
111
|
+
* ignored). Scrubs superseded `set-blend` updates from the queue.
|
|
112
|
+
*/
|
|
113
|
+
export declare function setStartupPacketBlendWeights(packet: StartupPacketState, name: string, weights: Record<string, number>): boolean;
|
|
114
|
+
/**
|
|
115
|
+
* Remove a registration and every pending update targeting it.
|
|
116
|
+
* Equivalent to undoing `add-quantizer` + any in-flight mutations.
|
|
117
|
+
*/
|
|
118
|
+
export declare function removeStartupPacketEntries(packet: StartupPacketState, name: string): void;
|
|
119
|
+
/**
|
|
120
|
+
* Clear all transient state on a startup packet, leaving only the
|
|
121
|
+
* `bootstrapMode` in place. Used when the lease is recycled and the
|
|
122
|
+
* caller wants to start accumulating fresh messages.
|
|
123
|
+
*/
|
|
124
|
+
export declare function resetStartupPacketTransientState(packet: StartupPacketState): void;
|
|
125
|
+
/**
|
|
126
|
+
* Claim a compositor lease: either hand back the standby pre-warmed
|
|
127
|
+
* worker (if one is parked and matches the requested capacity) or mint a
|
|
128
|
+
* fresh `Worker` + {@link RuntimeCoordinator}. Emits
|
|
129
|
+
* `claim-or-create` and `coordinator-reset-or-create` stage samples to
|
|
130
|
+
* the optional telemetry sink.
|
|
131
|
+
*
|
|
132
|
+
* @param capacity - Runtime coordinator capacity to request.
|
|
133
|
+
* @param startupTelemetry - Optional sink for stage timings.
|
|
134
|
+
* @returns The worker, its coordinator, and any bootstrap snapshot the
|
|
135
|
+
* parked lease brought with it.
|
|
136
|
+
*/
|
|
137
|
+
export declare function claimCompositorLease(capacity: number, startupTelemetry?: CompositorWorkerStartupTelemetry): {
|
|
138
|
+
readonly worker: Worker;
|
|
139
|
+
readonly runtime: RuntimeCoordinator.Shape;
|
|
140
|
+
readonly bootstrapSnapshot: readonly BootstrapQuantizerRegistration[];
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* Park a compositor lease in the module-level standby slot so a future
|
|
144
|
+
* {@link claimCompositorLease} can reuse it. If the standby slot is
|
|
145
|
+
* already occupied, the incoming lease is disposed (`dispose` message +
|
|
146
|
+
* `terminate()`) instead.
|
|
147
|
+
*/
|
|
148
|
+
export declare function parkOrDisposeCompositorLease(lease: {
|
|
149
|
+
readonly worker: Worker;
|
|
150
|
+
readonly runtime: RuntimeCoordinator.Shape;
|
|
151
|
+
readonly capacity: number;
|
|
152
|
+
readonly bootstrapSnapshot: readonly BootstrapQuantizerRegistration[];
|
|
153
|
+
}): void;
|
|
154
|
+
/**
|
|
155
|
+
* Internal `postMessage` helper with an explicit transfer-list default.
|
|
156
|
+
* Named with a leading underscore to signal that host code should use
|
|
157
|
+
* the typed methods on {@link CompositorWorkerShape} instead.
|
|
158
|
+
*/
|
|
159
|
+
export declare function _send(worker: Worker, msg: ToWorkerMessage, transfer?: Transferable[]): void;
|
|
160
|
+
/**
|
|
161
|
+
* Convert a registration's thresholds to a Float64Array for transfer.
|
|
162
|
+
* Returns a new registration object with the typed array and the ArrayBuffer to transfer.
|
|
163
|
+
*/
|
|
164
|
+
export declare function prepareRegistrationForTransfer(registration: BootstrapQuantizerRegistration): {
|
|
165
|
+
registration: BootstrapQuantizerRegistration;
|
|
166
|
+
buffer: ArrayBuffer;
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
* Prepare a list of registrations for transfer, returning new registrations
|
|
170
|
+
* and the collected ArrayBuffers to include in the transfer list.
|
|
171
|
+
*/
|
|
172
|
+
export declare function prepareRegistrationsForTransfer(registrations: readonly BootstrapQuantizerRegistration[]): {
|
|
173
|
+
registrations: readonly BootstrapQuantizerRegistration[];
|
|
174
|
+
buffers: ArrayBuffer[];
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* Structural equality for two `ArrayLike` sequences (same length, same
|
|
178
|
+
* `===` elements at every index). Works for both plain arrays and typed
|
|
179
|
+
* arrays.
|
|
180
|
+
*/
|
|
181
|
+
export declare function sameArray<T>(left: ArrayLike<T>, right: ArrayLike<T>): boolean;
|
|
182
|
+
/**
|
|
183
|
+
* Return `true` when two bootstrap registrations share the same
|
|
184
|
+
* `boundaryId`, state list, and threshold list. Used to elide redundant
|
|
185
|
+
* `add-quantizer` messages during bootstrap coalescing.
|
|
186
|
+
*/
|
|
187
|
+
export declare function sameBootstrapRegistration(left: BootstrapQuantizerRegistration | undefined, right: BootstrapQuantizerRegistration): boolean;
|
|
188
|
+
/**
|
|
189
|
+
* Quantize a numeric value against a registration's thresholds and
|
|
190
|
+
* return the corresponding state label. Falls back to `states[0]` if the
|
|
191
|
+
* value lies below every threshold.
|
|
192
|
+
*/
|
|
193
|
+
export declare function evaluateRegistrationState(registration: BootstrapQuantizerRegistration, value: number): string;
|
|
194
|
+
/**
|
|
195
|
+
* Re-shape a {@link ResolvedStateAckPayload} into the flat
|
|
196
|
+
* {@link ResolvedStateEntry} form that the main-thread state store
|
|
197
|
+
* consumes. Propagates `ack.generation` into each entry.
|
|
198
|
+
*/
|
|
199
|
+
export declare function toResolvedStateEntriesFromAck(ack: ResolvedStateAckPayload): readonly ResolvedStateEntry[];
|
|
200
|
+
//# sourceMappingURL=compositor-startup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compositor-startup.d.ts","sourceRoot":"","sources":["../src/compositor-startup.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EACV,eAAe,EACf,YAAY,EACZ,8BAA8B,EAC9B,oBAAoB,EACpB,kBAAkB,EACnB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EACV,gCAAgC,EAChC,sCAAsC,EACtC,uBAAuB,EAEvB,kBAAkB,EACnB,MAAM,uBAAuB,CAAC;AAgB/B;;;;;GAKG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAGtC;AAED;;;;;;GAMG;AACH,wBAAgB,4BAA4B,CAC1C,SAAS,EAAE,gCAAgC,GAAG,SAAS,EACvD,KAAK,EAAE,sCAAsC,EAC7C,UAAU,EAAE,MAAM,GACjB,IAAI,CAaN;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,gCAAgC,GAAG,S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