@phin-tech/dottie 0.6.2 → 0.7.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.
@@ -1,12 +1,18 @@
1
1
  import { 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
- * in <dottie-player> only, show page `page` (an index into the file's pages), where the element's link points. */
4
- export type Click = {
3
+ * in <dottie-player> only, show page `page` (an index into the file's pages), where the element's link points. Any
4
+ * of them may first `set` and `toggle` page variables (ClickAction.set, .toggle), and a click may do only that. */
5
+ export type Click = ({
5
6
  scene: number;
6
7
  } | {
7
8
  url: string;
8
9
  } | {
9
10
  page: number;
11
+ } | {
12
+ state: true;
13
+ }) & {
14
+ set?: Record<string, boolean>;
15
+ toggle?: string[];
10
16
  };
11
17
  /** The marker called `name`: an exact match, else one that differs only in case. */
12
18
  export declare function sceneNamed(name: string, markers: Marker[]): number;
@@ -6,18 +6,18 @@ export declare function portPoint(shape: Element, port: Port): Point;
6
6
  /** Where the line from the shape's center toward `target` crosses its outline. */
7
7
  export declare function edgePoint(shape: Element, toward: Point): Point;
8
8
  export declare function endpoints(e: Element, index: Index): [Point, Point];
9
+ /** A curve is joined cubic Béziers: the start, then two controls and an end per segment. */
9
10
  export type Route = {
10
11
  kind: "polyline";
11
12
  points: Point[];
12
13
  } | {
13
- kind: "cubic";
14
- a: Point;
15
- b: Point;
16
- c: Point;
17
- d: Point;
14
+ kind: "curve";
15
+ points: Point[];
18
16
  };
19
- /** A route's centerline as points; a cubic is sampled at 25 points. */
17
+ /** A route's centerline as points; each cubic segment is sampled at 25 points. */
20
18
  export declare function routePoints(r: Route): Point[];
19
+ /** Drops repeated points and the middle of three in a line, so dragged bends that fall into line disappear. */
20
+ export declare function simplified(pts: Point[]): Point[];
21
21
  export declare function route(e: Element, index: Index): Route;
22
22
  /** Arrowhead wing points for a tip at `tip` arriving from `from`. */
23
23
  export declare function arrowhead(tip: Point, from: Point, size: number): [Point, Point];
@@ -11,6 +11,9 @@ export declare const unrotated: (e: Element, p: Point) => Point;
11
11
  export declare function rotatedBounds(e: Element): Rect;
12
12
  /** The element with automatic ink drawn as `ink`; a light ink is not used on a light, mostly opaque fill. */
13
13
  export declare function resolvingInk(e: Element, ink: RGBA): Element;
14
+ /** What the element's text is drawn in: a text box's and a note's stroke, any other label's `textColor` or,
15
+ * without one, its stroke. */
16
+ export declare function labelColor(e: Element): RGBA;
14
17
  export interface Contour {
15
18
  closed: boolean;
16
19
  points: Point[];
@@ -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.6.2";
23
+ export declare const VERSION = "0.7.0";
@@ -27,6 +27,8 @@ export interface Style {
27
27
  opacity: number | null;
28
28
  /** How far into its dash pattern a dashed or dotted line starts; marching ants set it on every frame. */
29
29
  dashOffset: number | null;
30
+ /** The color of a shape's or connector's label; null follows `stroke`. Text boxes and notes ignore it. */
31
+ textColor: RGBA | null;
30
32
  }
31
33
  /** `portIndex` pins the end to one of the bound element's `ports`, and wins over `port`. */
32
34
  export interface Endpoint {
@@ -49,6 +51,10 @@ export interface ConnectorData {
49
51
  routing: Routing;
50
52
  startHead: Arrowhead;
51
53
  endHead: Arrowhead;
54
+ /** Bends on the canvas the line passes through, start to end. */
55
+ waypoints: StrokePoint[] | null;
56
+ /** Hops where the line crosses a connector drawn beneath it. */
57
+ hops: boolean | null;
52
58
  }
53
59
  export interface PathSubpath {
54
60
  closed: boolean;
@@ -62,10 +68,13 @@ export interface EmbeddedImage {
62
68
  data: string;
63
69
  format: string;
64
70
  }
65
- /** What clicking an element does in a played drawing: a scene to jump to and play on from, or a link. */
71
+ /** What clicking an element does in a played drawing: a scene to jump to and play on from, or a link; and page
72
+ * variables to set and flip (ClickAction.set, .toggle), which change what shows without touching the playhead. */
66
73
  export interface ClickAction {
67
74
  scene: string | null;
68
75
  url: string | null;
76
+ set: Record<string, boolean> | null;
77
+ toggle: string[] | null;
69
78
  }
70
79
  /** How a clickable element looks under the pointer or with keyboard focus; null keeps its own. */
71
80
  export interface HoverLook {
@@ -99,6 +108,8 @@ export interface Element {
99
108
  anchor: string | null;
100
109
  click: ClickAction | null;
101
110
  hover: HoverLook | null;
111
+ /** A condition on the page's variables: drawn only while it holds (Element.when; see state.ts). */
112
+ when: string | null;
102
113
  /** For a `symbol` element: the page's symbol it shows, how it plays it, and from how far in. */
103
114
  symbol: string | null;
104
115
  playback: SymbolPlayback | null;
@@ -173,9 +184,11 @@ export interface CameraKey {
173
184
  height: number;
174
185
  ease: Ease | null;
175
186
  }
187
+ /** A scene; `loop` plays it round until something leaves it, instead of stopping on it (Marker.loop). */
176
188
  export interface Marker {
177
189
  t: number;
178
190
  name: string;
191
+ loop: boolean | null;
179
192
  }
180
193
  export interface Timeline {
181
194
  fps: number;
@@ -195,6 +208,8 @@ export interface Page {
195
208
  theme: string | null;
196
209
  timeline: Timeline | null;
197
210
  symbols: Symbol[] | null;
211
+ /** The page's variables and their starting values (DottieDocument.variables). */
212
+ variables: Record<string, boolean> | null;
198
213
  }
199
214
  /** A drawing defined once on a page and placed by `symbol` elements, with its own timeline (Symbol). */
200
215
  export interface Symbol {
@@ -10,6 +10,10 @@ export declare class Playback {
10
10
  readonly plan: Plan;
11
11
  readonly scenes: number[];
12
12
  readonly sceneNames: string[];
13
+ /** Whether each scene loops (Marker.loop). */
14
+ readonly sceneLoops: boolean[];
15
+ /** The page's variables now: their starting values until clicks change them. */
16
+ state: Record<string, boolean>;
13
17
  readonly background: RGBA;
14
18
  readonly ink: RGBA;
15
19
  /** What clicking each clickable element does, by element id. */
@@ -56,6 +60,14 @@ export declare class Playback {
56
60
  private buttonPart;
57
61
  /** The scene frame `i` is in, or -1 before the first. */
58
62
  sceneAt(i: number): number;
63
+ /** The frame after scene `s`'s last: the next scene's, or the frame count after the last scene. */
64
+ sceneEnd(s: number): number;
65
+ /** Where playing goes from frame `i`, and whether it stops there: on into a looping scene, round to the start of
66
+ * the looping scene `i` ends, or a stop at a scene or the end (`loops`: whether the timeline loops at its end). */
67
+ step(i: number, loops: boolean): {
68
+ frame: number;
69
+ stop: boolean;
70
+ };
59
71
  }
60
72
  /** HTMLElement where there is a DOM; a stand-in elsewhere, so the library still loads in Node (to render SVG). */
61
73
  declare const ElementBase: typeof HTMLElement;
@@ -95,18 +107,23 @@ export declare class DottiePlayer extends ElementBase {
95
107
  get duration(): number;
96
108
  play(): void;
97
109
  pause(): void;
98
- /** Plays on to the next scene (from the start after the last). */
110
+ /** Plays on to the next scene (from the start after the last). Out of a looping scene it jumps to the next. */
99
111
  nextScene(): void;
100
112
  /** Back to the start of this scene, or the one before if already there. */
101
113
  prevScene(): void;
102
114
  /** Does what clicking element `id` does: jumps to its scene and plays on to the next (with reduced motion, or in a
103
115
  * still, straight to where that stops), opens its link in a new tab, or shows its page. */
104
116
  activate(id: string): void;
117
+ /** The page's variables now. */
118
+ get variables(): Record<string, boolean>;
119
+ /** Gives the page's variables these values (the others keep theirs), redraws, and fires `state`. */
120
+ setState(values: Record<string, boolean>): void;
105
121
  /** Redraws, while the page itself stands still, as long as a clicked copy is playing through. */
106
122
  private scheduleReplay;
107
123
  private setPlaying;
108
124
  private schedule;
109
- /** Steps whole frames at the timeline's rate; with scenes, playing stops at each one and at the end. */
125
+ /** Steps whole frames at the timeline's rate; with scenes, playing stops at each one and at the end, except that a
126
+ * looping scene plays round (Playback.step). */
110
127
  private tick;
111
128
  private key;
112
129
  }
@@ -1,5 +1,5 @@
1
- import { type Index } from "./connector.ts";
2
- import type { DashStyle, Element } from "./model.ts";
1
+ import { type Index, type Route } from "./connector.ts";
2
+ import { type DashStyle, type Element, type Page } from "./model.ts";
3
3
  import { Path, type Point } from "./path.ts";
4
4
  /** The `.grid` cell size actually drawn. */
5
5
  export declare const cellSize: (e: Element) => number;
@@ -13,5 +13,18 @@ export declare function fillPath(e: Element): Path;
13
13
  export declare function hachurePath(e: Element): Path;
14
14
  /** Dash lengths for a stroke width; null for a solid line. */
15
15
  export declare function dashPattern(dash: DashStyle, width: number): number[] | null;
16
- /** A connector as the stroked line (with open arrowheads) and the closed heads filled in the stroke color. */
17
- export declare function connectorParts(e: Element, index: Index): [Path, Path];
16
+ /**
17
+ * A connector as the stroked line (with open arrowheads) and the closed heads filled in the stroke color. `page`
18
+ * holds the connectors a hopping line hops over; without it a line draws no hops.
19
+ */
20
+ export declare function connectorParts(e: Element, index: Index, page?: Page): [Path, Path];
21
+ /** How big a hop is for a line `strokeWidth` wide: its radius. */
22
+ export declare function hopRadius(strokeWidth: number): number;
23
+ /** The points a route's segments are measured along: a straight segment's two ends, or a cubic sampled at 25. */
24
+ export declare function hopSamples(r: Route): Point[][];
25
+ /**
26
+ * Where a hopping connector's segments (straight, or each cubic of a curve) cross the connectors drawn beneath it
27
+ * (earlier on a visible layer): for each segment, the distances along it, ascending, leaving out crossings too close
28
+ * to its ends or the hop before.
29
+ */
30
+ export declare function hopCrossings(e: Element, r: Route, page: Page, index: Index): number[][];
@@ -0,0 +1,20 @@
1
+ import type { ClickAction, Page } from "./model.ts";
2
+ /** Whether `name` can name a variable: a letter or underscore, then letters, digits and underscores. */
3
+ export declare function isName(name: string): boolean;
4
+ /** The variable names `condition` reads, or null when it isn't one: names, each optionally after `!`, joined by
5
+ * `&&` and `||` (`&&` binds tighter). */
6
+ export declare function conditionNames(condition: string): string[] | null;
7
+ /** Whether `condition` holds with these values. A missing variable is false; a condition that can't be read never
8
+ * holds. */
9
+ export declare function holds(condition: string, state: Record<string, boolean>): boolean;
10
+ /** Which elements a page shows as far as its variables go: their starting values ("initial"), these values (a
11
+ * missing one takes its starting value), or every element ("all"). */
12
+ export type StateChoice = "initial" | "all" | Record<string, boolean>;
13
+ /** The values `choice` gives each variable; null for "all". */
14
+ export declare function stateValues(page: Page, choice: StateChoice): Record<string, boolean> | null;
15
+ /** The ids of the elements whose `when` doesn't hold under `choice`. */
16
+ export declare function stateHidden(page: Page, choice: StateChoice): Set<string>;
17
+ /** Whether a click sets or flips a variable. */
18
+ export declare function changesState(c: ClickAction | null): boolean;
19
+ /** `state` after the click: its `set` values, then each `toggle` flipped (a missing variable starts false). */
20
+ export declare function applyClick(c: ClickAction, state: Record<string, boolean>): Record<string, boolean>;
@@ -1,5 +1,6 @@
1
1
  import { type Ease, type Element, type Follow, type Page, type Timeline, type Track } from "./model.ts";
2
2
  import { Polyline, type Point, type Rect } from "./path.ts";
3
+ import { type StateChoice } from "./state.ts";
3
4
  export declare function applyEase(ease: Ease, u: number): number;
4
5
  /** The time inside the track's own keys that `t` plays (repeats folded back). */
5
6
  export declare function localTime(track: Track, t: number): number;
@@ -20,9 +21,10 @@ export declare function following(track: Track, e: Element, t: number, page: Pag
20
21
  export declare function marchOffset(tl: Timeline, speed: number, period: number, t: number): number;
21
22
  /** The page as a still drawing at `t` seconds, symbol instances expanded (DottieDocument.resolved(at:)). A page with
22
23
  * no timeline and no instances is returned as is. */
23
- export declare function resolved(page: Page, t: number): Page;
24
- /** The page posed at `t` seconds, instances kept (DottieDocument.posed(at:)). */
25
- export declare function posed(page: Page, t: number): Page;
24
+ export declare function resolved(page: Page, t: number, state?: StateChoice): Page;
25
+ /** The page posed at `t` seconds, instances kept, and the elements whose `when` doesn't hold under `state` left out
26
+ * with their connectors (DottieDocument.posed(at:state:)). */
27
+ export declare function posed(page: Page, t: number, state?: StateChoice): Page;
26
28
  /** The moment a still picture of the page shows: its poster, else the end. */
27
29
  export declare function posterTime(page: Page): number;
28
30
  /** The page as a still picture (its poster frame when animated). */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phin-tech/dottie",
3
- "version": "0.6.2",
3
+ "version": "0.7.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",