@phin-tech/dottie 0.9.0 → 0.11.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/PARITY.md +5 -0
- package/README.md +15 -0
- package/dist/compile.js +123 -15
- package/dist/dottie-compile.mjs +131 -17
- package/dist/dottie-logic.min.js +2171 -0
- package/dist/dottie-player.js +819 -209
- package/dist/dottie-player.min.js +55 -53
- package/dist/dottie-sim.min.js +5 -4
- package/dist/dottie.js +817 -209
- package/dist/types/clicks.d.ts +3 -2
- package/dist/types/compile.d.ts +3 -0
- package/dist/types/elbow.d.ts +18 -0
- package/dist/types/expression.d.ts +51 -0
- package/dist/types/flows.d.ts +2 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/logic-entry.d.ts +1 -0
- package/dist/types/logic-loader.d.ts +9 -0
- package/dist/types/logic-polyfill.d.ts +2 -0
- package/dist/types/logic.d.ts +32 -0
- package/dist/types/measure.d.ts +15 -3
- package/dist/types/model.d.ts +42 -3
- package/dist/types/player.d.ts +8 -3
- package/dist/types/state.d.ts +14 -13
- package/dist/types/theme.d.ts +13 -1
- package/package.json +3 -1
package/dist/types/clicks.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type DottieFile, type Element, type Marker, type Page } from "./model.ts";
|
|
1
|
+
import { type ClickValue, type DottieFile, type Element, type Marker, type Page } from "./model.ts";
|
|
2
2
|
/** Jump to scene `scene` (an index into the page's markers) and play on to the next; open `url` in a new tab; or,
|
|
3
3
|
* in <dottie-player> only, show page `page` (an index into the file's pages), where the element's link points. Any
|
|
4
4
|
* of them may first `set` and `toggle` page variables (ClickAction.set, .toggle), and a click may do only that. */
|
|
@@ -11,9 +11,10 @@ export type Click = ({
|
|
|
11
11
|
} | {
|
|
12
12
|
state: true;
|
|
13
13
|
}) & {
|
|
14
|
-
set?: Record<string,
|
|
14
|
+
set?: Record<string, ClickValue>;
|
|
15
15
|
toggle?: string[];
|
|
16
16
|
reset?: true;
|
|
17
|
+
run?: string;
|
|
17
18
|
};
|
|
18
19
|
/** The marker called `name`: an exact match, else one that differs only in case. */
|
|
19
20
|
export declare function sceneNamed(name: string, markers: Marker[]): number;
|
package/dist/types/compile.d.ts
CHANGED
|
@@ -11,6 +11,9 @@ export interface CompileOptions {
|
|
|
11
11
|
noAutoplay?: boolean;
|
|
12
12
|
noLoop?: boolean;
|
|
13
13
|
label?: string;
|
|
14
|
+
/** The click-logic engine (dist/dottie-logic.min.js): with it the page's logic may run (ADR 0007), and the player
|
|
15
|
+
* gets allow-logic; without it a click does its own set and toggle. */
|
|
16
|
+
logicEngine?: string;
|
|
14
17
|
/** A bundled font's file (`fontFile`) as base64, so the drawing carries the fonts it uses; without it the
|
|
15
18
|
* player fetches them from beside itself. dottie-compile reads them from dist/fonts. */
|
|
16
19
|
fontData?: (family: string, face: Face) => string | undefined;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Element } from "./model.ts";
|
|
2
|
+
import type { Point, Rect } from "./path.ts";
|
|
3
|
+
/** How far a route keeps from the shapes it goes round. */
|
|
4
|
+
export declare const MARGIN = 16;
|
|
5
|
+
/** What a bend costs, in points of length. */
|
|
6
|
+
export declare const BEND = 24;
|
|
7
|
+
/** Shapes smaller than this either way (packets, dots, small icons) aren't in the way. */
|
|
8
|
+
export declare const SMALLEST = 24;
|
|
9
|
+
/** More shapes in the way than this, and the plain route is kept. */
|
|
10
|
+
export declare const MOST = 48;
|
|
11
|
+
/** The box of `e` if a route goes round it: not a connector, text, freehand line or plain path, not invisible, and
|
|
12
|
+
* not small. */
|
|
13
|
+
export declare function obstacle(e: Element): Rect | null;
|
|
14
|
+
/** Whether the right-angled line through `points` passes through the inside of `r` (not just along its edge). */
|
|
15
|
+
export declare function crosses(points: Point[], r: Rect): boolean;
|
|
16
|
+
/** `plain` (the Z or L from `a` to `b`), or a way round the shapes among `elements` it crosses, leaving out `except`
|
|
17
|
+
* (the connector's own ends). */
|
|
18
|
+
export declare function avoiding(plain: Point[], a: Point, b: Point, startVertical: boolean, endVertical: boolean, elements: Iterable<Element>, except: Set<string>): Point[];
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** A page variable's value: true or false, or a number. */
|
|
2
|
+
export type Var = boolean | number;
|
|
3
|
+
export type Expr = {
|
|
4
|
+
k: "lit";
|
|
5
|
+
v: Var;
|
|
6
|
+
} | {
|
|
7
|
+
k: "name";
|
|
8
|
+
name: string;
|
|
9
|
+
} | {
|
|
10
|
+
k: "metric";
|
|
11
|
+
metric: string;
|
|
12
|
+
target: string;
|
|
13
|
+
} | {
|
|
14
|
+
k: "not";
|
|
15
|
+
e: Expr;
|
|
16
|
+
} | {
|
|
17
|
+
k: "neg";
|
|
18
|
+
e: Expr;
|
|
19
|
+
} | {
|
|
20
|
+
k: "bin";
|
|
21
|
+
op: string;
|
|
22
|
+
l: Expr;
|
|
23
|
+
r: Expr;
|
|
24
|
+
} | {
|
|
25
|
+
k: "call";
|
|
26
|
+
fn: string;
|
|
27
|
+
args: Expr[];
|
|
28
|
+
};
|
|
29
|
+
/** The metrics an expression can read (PageState.metricNames). */
|
|
30
|
+
export declare const METRIC_NAMES: string[];
|
|
31
|
+
/** As a condition reads it: a number holds unless it is 0 (or not a number). */
|
|
32
|
+
export declare const truthy: (v: Var) => boolean;
|
|
33
|
+
/** As arithmetic reads it: true is 1, false 0. */
|
|
34
|
+
export declare const num: (v: Var) => number;
|
|
35
|
+
/** `text` parsed, or null when it isn't an expression. Remembered, since a frame reads the same conditions often. */
|
|
36
|
+
export declare function parseExpr(text: string): Expr | null;
|
|
37
|
+
/** What a metric reads; null when it can't be had (every comparison with it then fails). */
|
|
38
|
+
export type MetricRead = (metric: string, target: string) => number | null;
|
|
39
|
+
/** The value with these variables (a missing one is false). */
|
|
40
|
+
export declare function evaluate(e: Expr, state: Record<string, Var>, metric?: MetricRead | null): Var;
|
|
41
|
+
/** The variable names it reads, in order, each once. */
|
|
42
|
+
export declare function exprNames(e: Expr): string[];
|
|
43
|
+
/** The metrics it reads. */
|
|
44
|
+
export declare function exprMetrics(e: Expr): {
|
|
45
|
+
metric: string;
|
|
46
|
+
target: string;
|
|
47
|
+
}[];
|
|
48
|
+
/** A variable's value as text shows it (Var.description): true or false, a number to two places. */
|
|
49
|
+
export declare function describeVar(v: Var): string;
|
|
50
|
+
/** `text` with each `{expression}` that reads only the page's variables replaced by its value (PageState.filling). */
|
|
51
|
+
export declare function filling(text: string, values: Record<string, Var>): string;
|
package/dist/types/flows.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ export declare const DEFAULT_COLOR: RGBA;
|
|
|
4
4
|
export declare const clamp: (v: number | null, fallback: number, lo: number, hi: number) => number;
|
|
5
5
|
/** The id of a flow's packet `k`: the flow's id with its last twelve digits standing for `k` (Flow.packetID). */
|
|
6
6
|
export declare function packetID(flow: string, k: number): string;
|
|
7
|
+
/** `cost` as routing uses it: 1 for null, kept within 0...1,000,000 (ConnectorData.routeCost). */
|
|
8
|
+
export declare const routeCost: (cost: number | null) => number;
|
|
7
9
|
/** Every shape traffic from `from` can reach in `frame`, with the cheapest way to each:
|
|
8
10
|
* by the connectors' cost (1 each unless set), ties to the shape reached first, earlier connectors first.
|
|
9
11
|
* With `until`, the search stops once that shape is settled: its way is final then, and it is the first goal of any
|
package/dist/types/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export { BUNDLED_FONTS } from "./text.ts";
|
|
|
5
5
|
export { inspect, inspectFrame, inspectPage, sampleTimes } from "./inspect.ts";
|
|
6
6
|
export { DottiePlayer, Playback, definePlayer, pageIndex, withRoughness } from "./player.ts";
|
|
7
7
|
export { bounds, plan, svg, svgParts, type Plan, type Part } from "./svg.ts";
|
|
8
|
-
export { themeNamed, themes, type Theme } from "./theme.ts";
|
|
8
|
+
export { pageTheme, paletteColor, themeNamed, themes, type Theme } from "./theme.ts";
|
|
9
9
|
export { cameraView, frameTimes, posterTime, resolved, sceneAt, still, transientElements } from "./timeline.ts";
|
|
10
10
|
export interface RenderOptions {
|
|
11
11
|
/** Page name or 1-based number; the first page by default. */
|
|
@@ -20,4 +20,4 @@ export interface RenderOptions {
|
|
|
20
20
|
/** One page of a drawing as an SVG document, as Dottie's own SVG export draws it. */
|
|
21
21
|
export declare function render(source: string | DottieFile | unknown, options?: RenderOptions): string;
|
|
22
22
|
/** The library's version. */
|
|
23
|
-
export declare const VERSION = "0.
|
|
23
|
+
export declare const VERSION = "0.11.0";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ClickEvent, LogicResult } from "./logic.ts";
|
|
2
|
+
import type { Var } from "./expression.ts";
|
|
3
|
+
interface Engine {
|
|
4
|
+
loadLogic(): Promise<void>;
|
|
5
|
+
runLogic(source: string, handler: string, state: Record<string, Var>, event: ClickEvent): LogicResult;
|
|
6
|
+
}
|
|
7
|
+
/** The engine, loaded; rejects where it can't be had. */
|
|
8
|
+
export declare function logicEngine(): Promise<Engine>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Var } from "./expression.ts";
|
|
2
|
+
/** What a handler is told about the click. */
|
|
3
|
+
export interface ClickEvent {
|
|
4
|
+
/** The clicked element's id, anchor and first line of text. */
|
|
5
|
+
id: string;
|
|
6
|
+
anchor: string | null;
|
|
7
|
+
text: string | null;
|
|
8
|
+
/** Seconds into the page's timeline, and the scene playing. */
|
|
9
|
+
time: number;
|
|
10
|
+
scene: string | null;
|
|
11
|
+
}
|
|
12
|
+
/** New variable values, or why there are none (the state then stays as it was). */
|
|
13
|
+
export type LogicResult = {
|
|
14
|
+
ok: true;
|
|
15
|
+
set: Record<string, Var>;
|
|
16
|
+
} | {
|
|
17
|
+
ok: false;
|
|
18
|
+
error: string;
|
|
19
|
+
};
|
|
20
|
+
/** How much a handler may do: QuickJS checks in every 10,000 or so operations, and this many check-ins is the
|
|
21
|
+
* limit (a few million operations, well under a second). */
|
|
22
|
+
export declare const OPERATION_BUDGET = 400;
|
|
23
|
+
/** How much memory a handler may use. */
|
|
24
|
+
export declare const MEMORY_LIMIT: number;
|
|
25
|
+
/** Longest logic a page may have, in characters. */
|
|
26
|
+
export declare const MAX_SOURCE: number;
|
|
27
|
+
/** Loads the engine (once). */
|
|
28
|
+
export declare function loadLogic(): Promise<void>;
|
|
29
|
+
/** Whether the engine is loaded, so `runLogic` can be called. */
|
|
30
|
+
export declare function logicReady(): boolean;
|
|
31
|
+
/** Runs `handler` from `source` for a click; the engine must be loaded. */
|
|
32
|
+
export declare function runLogic(source: string, handler: string, state: Record<string, Var>, event: ClickEvent): LogicResult;
|
package/dist/types/measure.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Element, Flow, Gauge, Page, RGBA } from "./model.ts";
|
|
2
2
|
import { type MetricTerm } from "./state.ts";
|
|
3
|
+
import type { Var } from "./expression.ts";
|
|
3
4
|
/** A connector's or shape's metrics in one frame (ElementMetrics). */
|
|
4
5
|
export interface ElementMetrics {
|
|
5
6
|
throughput: number;
|
|
@@ -28,15 +29,26 @@ export declare const emptyMetrics: () => FrameMetrics;
|
|
|
28
29
|
export declare function metricValue(m: FrameMetrics, metric: string, id: string): number | null;
|
|
29
30
|
/** A shape's delay as traffic feels it: 0...3600 seconds. */
|
|
30
31
|
export declare function delayOf(e: Element): number;
|
|
32
|
+
/** One way a flow's traffic takes in a frame (`flowFrame`'s routes): to `goal` over the connectors `hops`
|
|
33
|
+
* ([connector, backwards]), carrying `amount` of its volume at a cost of `cost`; `waits` when it goes only as far as
|
|
34
|
+
* the queue it waits in. */
|
|
35
|
+
export interface FlowRoute {
|
|
36
|
+
goal: string;
|
|
37
|
+
hops: [string, boolean][];
|
|
38
|
+
amount: number;
|
|
39
|
+
waits: boolean;
|
|
40
|
+
cost: number;
|
|
41
|
+
}
|
|
31
42
|
/** The key of a flow's queue at a shape in `FrameMetrics.carry` and `carried` (DottieDocument.queueKey). */
|
|
32
43
|
export declare const queueKey: (shape: string, flow: string) => string;
|
|
33
44
|
/** The packets the page's flows draw in `frame` (the page posed at `t`), with these values (null: every flow runs),
|
|
34
45
|
* and the frame's metrics. `since` is the seconds since the page's state last changed
|
|
35
46
|
* (null: `t`), and `carried` how much each flow's queue held at that moment: since then a queue grows by its
|
|
36
47
|
* backlog, or drains at the room its way on has left. */
|
|
37
|
-
export declare function flowFrame(flows: Flow[] | null, frame: Page, t: number, values: Record<string,
|
|
48
|
+
export declare function flowFrame(flows: Flow[] | null, frame: Page, t: number, values: Record<string, Var> | null, offline?: Set<string>, sinceChange?: number | null, carried?: Record<string, number>): {
|
|
38
49
|
packets: Element[];
|
|
39
50
|
metrics: FrameMetrics;
|
|
51
|
+
routes: Map<string, FlowRoute[]>;
|
|
40
52
|
};
|
|
41
53
|
/** The frame's metric for a condition's comparison: its target an element's anchor, or an element's or flow's id. */
|
|
42
54
|
export declare function metricLookup(m: FrameMetrics, frame: Page): (t: MetricTerm, own: string | null) => number | null;
|
|
@@ -51,13 +63,13 @@ export interface Finish {
|
|
|
51
63
|
/** For each of `elements`, the overrides that compare metrics that hold and the reading a gauge shows (easing, over
|
|
52
64
|
* `GAUGE_EASE` seconds since the state changed, from its reading then, `carried`); with no values ("all", the
|
|
53
65
|
* editor), nothing. The readings come back to carry over. */
|
|
54
|
-
export declare function finishPlan(elements: Element[], metrics: FrameMetrics, values: Record<string,
|
|
66
|
+
export declare function finishPlan(elements: Element[], metrics: FrameMetrics, values: Record<string, Var> | null, frame: Page, since?: number, carried?: Record<string, number>): {
|
|
55
67
|
plan: Finish[];
|
|
56
68
|
readings: Record<string, number>;
|
|
57
69
|
};
|
|
58
70
|
/** `elements` with the looks of overrides that compare metrics applied, and gauges drawn as plain elements; with
|
|
59
71
|
* no values ("all", the editor), both are left as they are (`finishPlan`). */
|
|
60
|
-
export declare function finishing(elements: Element[], metrics: FrameMetrics, values: Record<string,
|
|
72
|
+
export declare function finishing(elements: Element[], metrics: FrameMetrics, values: Record<string, Var> | null, frame: Page, flows: Flow[], since?: number, carried?: Record<string, number>): {
|
|
61
73
|
elements: Element[];
|
|
62
74
|
readings: Record<string, number>;
|
|
63
75
|
};
|
package/dist/types/model.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Var } from "./expression.ts";
|
|
1
2
|
export interface RGBA {
|
|
2
3
|
r: number;
|
|
3
4
|
g: number;
|
|
@@ -29,6 +30,29 @@ export interface Style {
|
|
|
29
30
|
dashOffset: number | null;
|
|
30
31
|
/** The color of a shape's or connector's label; null follows `stroke`. Text boxes and notes ignore it. */
|
|
31
32
|
textColor: RGBA | null;
|
|
33
|
+
/** Which colors are palette colors, by name (ADR 0005); set from the page's palette when it is read. */
|
|
34
|
+
named?: ColorNames | null;
|
|
35
|
+
}
|
|
36
|
+
/** What a click gives a variable (ClickValue): a value, or an expression over the state before the click. */
|
|
37
|
+
export type ClickValue = Var | string;
|
|
38
|
+
/** Palette names for an element's colors (Theme.swift's ColorNames). */
|
|
39
|
+
export interface ColorNames {
|
|
40
|
+
fill: string | null;
|
|
41
|
+
stroke: string | null;
|
|
42
|
+
textColor: string | null;
|
|
43
|
+
}
|
|
44
|
+
/** A named color in a theme's palette. */
|
|
45
|
+
export interface PaletteColor {
|
|
46
|
+
name: string;
|
|
47
|
+
color: RGBA;
|
|
48
|
+
}
|
|
49
|
+
/** A theme made in the drawing (CustomTheme): it takes the place of the page's `theme`. */
|
|
50
|
+
export interface CustomTheme {
|
|
51
|
+
name: string;
|
|
52
|
+
background: RGBA;
|
|
53
|
+
ink: RGBA;
|
|
54
|
+
palette: PaletteColor[];
|
|
55
|
+
base: string | null;
|
|
32
56
|
}
|
|
33
57
|
/** `portIndex` pins the end to one of the bound element's `ports`, and wins over `port`. */
|
|
34
58
|
export interface Endpoint {
|
|
@@ -55,6 +79,8 @@ export interface ConnectorData {
|
|
|
55
79
|
waypoints: StrokePoint[] | null;
|
|
56
80
|
/** Hops where the line crosses a connector drawn beneath it. */
|
|
57
81
|
hops: boolean | null;
|
|
82
|
+
/** An elbow line goes round the shapes in its way instead of through them (elbow.ts). */
|
|
83
|
+
avoid?: boolean | null;
|
|
58
84
|
/** What a flow's traffic pays to take this connector (ADR 0002); null is 1. */
|
|
59
85
|
cost: number | null;
|
|
60
86
|
}
|
|
@@ -75,10 +101,12 @@ export interface EmbeddedImage {
|
|
|
75
101
|
export interface ClickAction {
|
|
76
102
|
scene: string | null;
|
|
77
103
|
url: string | null;
|
|
78
|
-
set: Record<string,
|
|
104
|
+
set: Record<string, ClickValue> | null;
|
|
79
105
|
toggle: string[] | null;
|
|
80
106
|
/** Puts every page variable back to its starting value first. */
|
|
81
107
|
reset?: boolean | null;
|
|
108
|
+
/** A handler in the page's `logic` to run (ADR 0007); where logic may not run, `set` and `toggle` stand in. */
|
|
109
|
+
run?: string | null;
|
|
82
110
|
}
|
|
83
111
|
/** How a clickable element looks under the pointer or with keyboard focus; null keeps its own. */
|
|
84
112
|
/** A change to an element while `when` holds (StateOverride): a field left null keeps the element's own. */
|
|
@@ -163,6 +191,13 @@ export interface Element {
|
|
|
163
191
|
delay?: number | null;
|
|
164
192
|
/** A shape that is a queue: backlog waits at the nearest one before whatever is full. */
|
|
165
193
|
queue?: boolean | null;
|
|
194
|
+
/** The container this element is in (ADR 0006). */
|
|
195
|
+
containerID?: string | null;
|
|
196
|
+
/** On a rectangle: it's a container. Its title band is its `labelRect`, kept by the app, so drawing needs nothing more. */
|
|
197
|
+
container?: {
|
|
198
|
+
fixed: boolean | null;
|
|
199
|
+
lanes: "rows" | "columns" | null;
|
|
200
|
+
} | null;
|
|
166
201
|
/** Shows a metric; drawn as plain paths and a label when the page is posed (metrics.ts). */
|
|
167
202
|
gauge?: Gauge | null;
|
|
168
203
|
}
|
|
@@ -250,10 +285,14 @@ export interface Page {
|
|
|
250
285
|
layers: Layer[];
|
|
251
286
|
elements: Element[];
|
|
252
287
|
theme: string | null;
|
|
288
|
+
/** JavaScript defining the handlers clicks `run` (ADR 0007), run only on clicks, sealed, where allowed. */
|
|
289
|
+
logic?: string | null;
|
|
290
|
+
/** A theme of the page's own (ADR 0005), in place of `theme`. */
|
|
291
|
+
customTheme?: CustomTheme | null;
|
|
253
292
|
timeline: Timeline | null;
|
|
254
293
|
symbols: Symbol[] | null;
|
|
255
294
|
/** The page's variables and their starting values (DottieDocument.variables). */
|
|
256
|
-
variables: Record<string,
|
|
295
|
+
variables: Record<string, Var> | null;
|
|
257
296
|
/** Traffic routed over the connectors drawn in each frame (DottieDocument.flows; see flows.ts). */
|
|
258
297
|
flows: Flow[] | null;
|
|
259
298
|
}
|
|
@@ -298,7 +337,7 @@ export interface DottieFile {
|
|
|
298
337
|
warnings: string[];
|
|
299
338
|
}
|
|
300
339
|
/** The newest file version this library was written for. Newer files still load, with a warning. */
|
|
301
|
-
export declare const SUPPORTED_VERSION =
|
|
340
|
+
export declare const SUPPORTED_VERSION = 3;
|
|
302
341
|
export declare const KINDS: readonly string[];
|
|
303
342
|
/** The fields dottie.js reads, per object; the schema test checks they're exactly the schema's. Anything else
|
|
304
343
|
* in a file is newer than this version and is reported in `warnings`. */
|
package/dist/types/player.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type Click } from "./clicks.ts";
|
|
2
2
|
import { type DottieFile, type Page, type RGBA } from "./model.ts";
|
|
3
3
|
import { type Plan } from "./svg.ts";
|
|
4
|
+
import type { Var } from "./expression.ts";
|
|
4
5
|
/** Finds a page by name (any case) or 1-based number; the first page when `spec` is empty or matches nothing. */
|
|
5
6
|
export declare function pageIndex(file: DottieFile, spec: string | null | undefined): number;
|
|
6
7
|
export declare function withRoughness(page: Page, roughness: number): Page;
|
|
@@ -13,7 +14,7 @@ export declare class Playback {
|
|
|
13
14
|
/** Whether each scene loops (Marker.loop). */
|
|
14
15
|
readonly sceneLoops: boolean[];
|
|
15
16
|
/** The page's variables now: their starting values until clicks change them. */
|
|
16
|
-
state: Record<string,
|
|
17
|
+
state: Record<string, Var>;
|
|
17
18
|
/** When the variables last changed (performance.now() milliseconds): backlog piles up from then (ADR 0003). */
|
|
18
19
|
stateSince: number;
|
|
19
20
|
/** A still (the `at` attribute): backlog is drawn for the page time, not the wall clock. */
|
|
@@ -134,10 +135,14 @@ export declare class DottiePlayer extends ElementBase {
|
|
|
134
135
|
/** Does what clicking element `id` does: jumps to its scene and plays on to the next (with reduced motion, or in a
|
|
135
136
|
* still, straight to where that stops), opens its link in a new tab, or shows its page. */
|
|
136
137
|
activate(id: string): void;
|
|
138
|
+
/** Runs handler `handler` from the page's logic for a click on `id` (DottieDocument.clicked). Clicks take turns, so
|
|
139
|
+
* each handler sees the state the one before left. */
|
|
140
|
+
private logicQueue;
|
|
141
|
+
private runLogic;
|
|
137
142
|
/** The page's variables now. */
|
|
138
|
-
get variables(): Record<string,
|
|
143
|
+
get variables(): Record<string, Var>;
|
|
139
144
|
/** Gives the page's variables these values (the others keep theirs), redraws, and fires `state`. */
|
|
140
|
-
setState(values: Record<string,
|
|
145
|
+
setState(values: Record<string, Var>): void;
|
|
141
146
|
/** Redraws, while the page itself stands still, as long as a clicked copy is playing through. */
|
|
142
147
|
private scheduleReplay;
|
|
143
148
|
private setPlaying;
|
package/dist/types/state.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type Var } from "./expression.ts";
|
|
2
|
+
import { type ClickAction, type ClickValue, type Element, type Page, type StateOverride } from "./model.ts";
|
|
2
3
|
/** Whether `name` can name a variable: a letter or underscore, then letters, digits and underscores. */
|
|
3
4
|
export declare function isName(name: string): boolean;
|
|
4
|
-
|
|
5
|
-
export declare const METRIC_NAMES: string[];
|
|
5
|
+
export { METRIC_NAMES } from "./expression.ts";
|
|
6
6
|
/** A comparison of a metric in a condition (PageState.MetricTerm). */
|
|
7
7
|
export interface MetricTerm {
|
|
8
8
|
metric: string;
|
|
@@ -10,25 +10,24 @@ export interface MetricTerm {
|
|
|
10
10
|
op: string;
|
|
11
11
|
value: number;
|
|
12
12
|
}
|
|
13
|
-
/** `term`
|
|
13
|
+
/** `term` read as one metric comparison, `metric(target) op number`, or null. */
|
|
14
14
|
export declare function metricTerm(term: string): MetricTerm | null;
|
|
15
|
-
/** Whether `condition`
|
|
15
|
+
/** Whether `condition` reads a metric anywhere. */
|
|
16
16
|
export declare function mentionsMetric(condition: string): boolean;
|
|
17
|
-
/** The variable names `condition` reads, or null when it isn't one
|
|
18
|
-
* comparisons, joined by `&&` and `||` (`&&` binds tighter). */
|
|
17
|
+
/** The variable names `condition` reads, or null when it isn't one (ADR 0007's expressions). */
|
|
19
18
|
export declare function conditionNames(condition: string): string[] | null;
|
|
20
19
|
/** Whether `condition` holds with these values, and `metric` giving the frame's metrics. A missing variable is
|
|
21
|
-
* false, and
|
|
22
|
-
export declare function holds(condition: string, state: Record<string,
|
|
20
|
+
* false, and a comparison with a metric that can't be had fails; a condition that can't be read never holds. */
|
|
21
|
+
export declare function holds(condition: string, state: Record<string, Var>, metric?: ((m: MetricTerm) => number | null) | null): boolean;
|
|
23
22
|
/** Which elements a page shows as far as its variables go: their starting values ("initial"), these values (a
|
|
24
23
|
* missing one takes its starting value), or every element ("all"). */
|
|
25
|
-
export type StateChoice = "initial" | "all" | Record<string,
|
|
24
|
+
export type StateChoice = "initial" | "all" | Record<string, Var>;
|
|
26
25
|
/** The values `choice` gives each variable; null for "all". */
|
|
27
|
-
export declare function stateValues(page: Page, choice: StateChoice): Record<string,
|
|
26
|
+
export declare function stateValues(page: Page, choice: StateChoice): Record<string, Var> | null;
|
|
28
27
|
/** The ids of the elements whose `when` doesn't hold under `choice`. */
|
|
29
28
|
export declare function stateHidden(page: Page, choice: StateChoice): Set<string>;
|
|
30
29
|
/** The overrides of `e` that hold under `values`, in order; none for null ("all", the editor). */
|
|
31
|
-
export declare function activeOverrides(e: Element, values: Record<string,
|
|
30
|
+
export declare function activeOverrides(e: Element, values: Record<string, Var> | null): StateOverride[];
|
|
32
31
|
/** Only what an override comparing metrics may change: its looks (ADR 0003). */
|
|
33
32
|
export declare function looksOnly(o: StateOverride): StateOverride;
|
|
34
33
|
/** `e` with `o` applied (StateOverride.apply): opacity multiplies, the rest replaces. */
|
|
@@ -37,4 +36,6 @@ export declare function applyOverride(o: StateOverride, e: Element): Element;
|
|
|
37
36
|
export declare function changesState(c: ClickAction | null): boolean;
|
|
38
37
|
/** `state` after the click: the starting values (`initial`) back if it resets, then its `set` values, then each
|
|
39
38
|
* `toggle` flipped (a missing variable starts false). */
|
|
40
|
-
export declare function applyClick(c: ClickAction, state: Record<string,
|
|
39
|
+
export declare function applyClick(c: ClickAction, state: Record<string, Var>, initial?: Record<string, Var>): Record<string, Var>;
|
|
40
|
+
/** A click's value given the state before it (ClickValue.value); an expression that can't be read leaves `current`. */
|
|
41
|
+
export declare function clickValue(v: ClickValue, state: Record<string, Var>, current: Var | undefined): Var;
|
package/dist/types/theme.d.ts
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
|
-
import type { RGBA } from "./model.ts";
|
|
1
|
+
import type { Page, PaletteColor, RGBA } from "./model.ts";
|
|
2
2
|
export interface Theme {
|
|
3
3
|
id: string;
|
|
4
4
|
name: string;
|
|
5
5
|
background: RGBA;
|
|
6
6
|
ink: RGBA;
|
|
7
|
+
palette: PaletteColor[];
|
|
7
8
|
}
|
|
9
|
+
/** The palette names every built-in theme has, in order. */
|
|
10
|
+
export declare const PALETTE_NAMES: string[];
|
|
11
|
+
/** Light pages. */
|
|
12
|
+
export declare const LIGHT_PALETTE: PaletteColor[];
|
|
8
13
|
export declare const themes: Theme[];
|
|
9
14
|
/** The theme a page names, or null (white page, black ink) for none or one this version doesn't know. */
|
|
10
15
|
export declare function themeNamed(id: string | null | undefined): Theme | null;
|
|
16
|
+
/** The theme `page` is drawn in: its own, else the built-in it names, else null. */
|
|
17
|
+
export declare function pageTheme(page: Pick<Page, "theme" | "customTheme">): Theme | null;
|
|
18
|
+
/** The palette color `name` names on `page`, ignoring case. */
|
|
19
|
+
export declare function paletteColor(page: Pick<Page, "theme" | "customTheme">, name: string): RGBA | null;
|
|
20
|
+
/** `page` with every named color set from its palette (DottieDocument.resolvingPalette); a name the palette doesn't
|
|
21
|
+
* have keeps the color it had. */
|
|
22
|
+
export declare function resolvingPalette(page: Page): Page;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phin-tech/dottie",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Render, play and compile Dottie (.dottie) drawings and animations in the browser",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -46,12 +46,14 @@
|
|
|
46
46
|
"prepublishOnly": "npm test && node build.mjs"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
+
"@jitl/quickjs-singlefile-browser-release-sync": "^0.32.0",
|
|
49
50
|
"@types/node": "^24.19.2",
|
|
50
51
|
"@types/pngjs": "^6.0.5",
|
|
51
52
|
"esbuild": "^0.25.12",
|
|
52
53
|
"pixelmatch": "^7.2.0",
|
|
53
54
|
"playwright": "^1.64.1",
|
|
54
55
|
"pngjs": "^7.0.0",
|
|
56
|
+
"quickjs-emscripten-core": "^0.32.0",
|
|
55
57
|
"typescript": "^5.9.3"
|
|
56
58
|
},
|
|
57
59
|
"publishConfig": {
|