@meltemi/diagrams-player 0.0.0-stage → 1.10.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.
Files changed (52) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +48 -2
  3. package/dist/controller.d.ts +146 -0
  4. package/dist/controller.d.ts.map +1 -0
  5. package/dist/controller.js +500 -0
  6. package/dist/controller.js.map +1 -0
  7. package/dist/document.d.ts +54 -0
  8. package/dist/document.d.ts.map +1 -0
  9. package/dist/document.js +204 -0
  10. package/dist/document.js.map +1 -0
  11. package/dist/ease.d.ts +14 -0
  12. package/dist/ease.d.ts.map +1 -0
  13. package/dist/ease.js +57 -0
  14. package/dist/ease.js.map +1 -0
  15. package/dist/format.d.ts +102 -0
  16. package/dist/format.d.ts.map +1 -0
  17. package/dist/format.js +18 -0
  18. package/dist/format.js.map +1 -0
  19. package/dist/frame.d.ts +30 -0
  20. package/dist/frame.d.ts.map +1 -0
  21. package/dist/frame.js +47 -0
  22. package/dist/frame.js.map +1 -0
  23. package/dist/html.d.ts +54 -0
  24. package/dist/html.d.ts.map +1 -0
  25. package/dist/html.js +123 -0
  26. package/dist/html.js.map +1 -0
  27. package/dist/index.d.ts +6 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +6 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/messages/en.d.ts +151 -0
  32. package/dist/messages/en.d.ts.map +1 -0
  33. package/dist/messages/en.js +157 -0
  34. package/dist/messages/en.js.map +1 -0
  35. package/dist/messages/es.d.ts +4 -0
  36. package/dist/messages/es.d.ts.map +1 -0
  37. package/dist/messages/es.js +105 -0
  38. package/dist/messages/es.js.map +1 -0
  39. package/dist/messages/index.d.ts +104 -0
  40. package/dist/messages/index.d.ts.map +1 -0
  41. package/dist/messages/index.js +9 -0
  42. package/dist/messages/index.js.map +1 -0
  43. package/dist/node.d.ts +6 -0
  44. package/dist/node.d.ts.map +1 -0
  45. package/dist/node.js +37 -0
  46. package/dist/node.js.map +1 -0
  47. package/dist/player.js +150 -0
  48. package/dist/viewport.d.ts +69 -0
  49. package/dist/viewport.d.ts.map +1 -0
  50. package/dist/viewport.js +189 -0
  51. package/dist/viewport.js.map +1 -0
  52. package/package.json +51 -3
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Architecture Studio contributors
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 CHANGED
@@ -1,3 +1,49 @@
1
- # Temporary Holding Version
1
+ # @meltemi/diagrams-player
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The HTML player of stories and diagram effects: a custom element with play, pause, scenes,
4
+ keyboard control, reduced motion, a static view and a text summary, written as a whole offline
5
+ page or a fragment to paste into a page. Every drawing zooms and pans, shows hover cards and a
6
+ detail panel, and opens the views its boxes hold with a double click or a plus sign, all drawn
7
+ around the frame and never in it. The `./node` entry gives the bundled runtime script.
8
+
9
+ It is part of [Meltemi Diagrams](https://github.com/askenaz-dev/meltemi-diagrams#readme), diagrams as code with a canvas, motion and
10
+ exports. Every package of the product has the same version.
11
+
12
+ ## Install
13
+
14
+ ```bash
15
+ npm install @meltemi/diagrams-player
16
+ ```
17
+
18
+ Node 22.12.0 or later. The package is an ES module with type declarations.
19
+
20
+ ## Use
21
+
22
+ Most people get a player from the command line:
23
+
24
+ ```bash
25
+ meltemi-diagrams export stories/purchase.meltemi --story purchase --format html
26
+ ```
27
+
28
+ In code, a player document is built from a compiled story and its laid-out views:
29
+
30
+ ```js
31
+ import { playerPage, storyDocument, storyViews } from "@meltemi/diagrams-player";
32
+ import { playerScript } from "@meltemi/diagrams-player/node";
33
+
34
+ const layouts = new Map();
35
+ for (const [key, view] of storyViews(story)) {
36
+ layouts.set(key, { diagram: view.diagram, layout: layoutDiagram(compilation, view.diagram) });
37
+ }
38
+ const html = playerPage(storyDocument(story, layouts), playerScript());
39
+ ```
40
+
41
+ ## Documentation
42
+
43
+ - [The player](https://github.com/askenaz-dev/meltemi-diagrams/blob/main/docs/player.md)
44
+ - [Stories](https://github.com/askenaz-dev/meltemi-diagrams/blob/main/docs/language/stories.md)
45
+ - [All documentation](https://github.com/askenaz-dev/meltemi-diagrams/blob/main/docs/README.md)
46
+
47
+ ## Licence
48
+
49
+ MIT. Third-party components and their licences are listed in [THIRD_PARTY_LICENSES.md](https://github.com/askenaz-dev/meltemi-diagrams/blob/main/THIRD_PARTY_LICENSES.md).
@@ -0,0 +1,146 @@
1
+ import { type Locale } from "@meltemi/diagrams-i18n";
2
+ import { type DrillSpec, type StoryViewData, type TimelineScene } from "@meltemi/diagrams-motion";
3
+ import type { EffectsPlayerDocument, OpenTarget, PlayerDocument, StoryPlayerDocument } from "./format.js";
4
+ /** An element or a relation of the view on screen. */
5
+ export interface ItemRef {
6
+ readonly role: "element" | "relation";
7
+ readonly id: string;
8
+ }
9
+ /** A drill-down on its way: the move, its clock, and what to do when it settles. */
10
+ export interface DrillState {
11
+ readonly spec: DrillSpec;
12
+ /** Milliseconds since it started. */
13
+ time: number;
14
+ /** Views the document lacks, by key: the view a catalog page came from. */
15
+ readonly extra: Readonly<Record<string, StoryViewData>>;
16
+ /** The element to select once it settles. */
17
+ readonly select: string | null;
18
+ /** Whether the effects were playing before. */
19
+ readonly resume: boolean;
20
+ }
21
+ /** Where the trail of views went down: the view, and its element that opened the next one. */
22
+ export interface TrailStep {
23
+ readonly view: string;
24
+ readonly element: string;
25
+ }
26
+ /** The trail never grows past this: `link` cycles are legal. */
27
+ export declare const TRAIL_LIMIT = 32;
28
+ export interface PlayerOptions {
29
+ /** Starts playing at once, unless the viewer asks for reduced motion. */
30
+ readonly autoplay?: boolean;
31
+ /** Starts again at the end. */
32
+ readonly loop?: boolean;
33
+ /** Starts in the static view. */
34
+ readonly static?: boolean;
35
+ /** The viewer asks for reduced motion: the static view, and no autoplay. */
36
+ readonly reducedMotion?: boolean;
37
+ /** The language of what the player says; English by default. */
38
+ readonly locale?: Locale;
39
+ }
40
+ export type PlayerCommand = "toggle" | "back" | "forward" | "backSmall" | "forwardSmall" | "start" | "end" | "previousScene" | "nextScene" | "toggleStatic";
41
+ /** Steps of the arrow keys, in milliseconds. */
42
+ export declare const STEP = 1000;
43
+ export declare const SMALL_STEP = 100;
44
+ /**
45
+ * The command of a key pressed in the player, or undefined. Left and Right step a second, `,` and
46
+ * `.` a tenth (Shift and the arrows pan the drawing).
47
+ */
48
+ export declare function commandForKey(key: string): PlayerCommand | undefined;
49
+ /** `1.2 s`, `800 ms` or `0 s`, with the language's decimal mark: `1,2 s` in Spanish. */
50
+ export declare function formatTime(ms: number, locale?: Locale): string;
51
+ /**
52
+ * The state of a player without its page: the clock, the scenes, the static view and what to
53
+ * announce. The runtime draws `frameTime` and calls `tick` on animation frames.
54
+ */
55
+ export declare class PlayerController {
56
+ readonly document: PlayerDocument;
57
+ time: number;
58
+ playing: boolean;
59
+ staticView: boolean;
60
+ readonly loop: boolean;
61
+ /** The language of the announcements. */
62
+ readonly locale: Locale;
63
+ constructor(document: PlayerDocument, options?: PlayerOptions);
64
+ /** The view of an effects document on screen, by key. */
65
+ protected effectsView: string;
66
+ /** The element or relation selected, whose details the panel shows. */
67
+ selection: ItemRef | null;
68
+ /** The item the keyboard walk reached. */
69
+ focused: ItemRef | null;
70
+ /** The views above the one on screen, outermost first. */
71
+ readonly trail: TrailStep[];
72
+ /** A drill-down on its way, or null. */
73
+ drill: DrillState | null;
74
+ private readonly reducedMotion;
75
+ /** What to announce once a drill-down settles, until the runtime takes it. */
76
+ private settled;
77
+ /** The key of the view on screen: an effects document's current view, or the scene's view. */
78
+ get view(): string;
79
+ /** How long the document plays, or null for effects that repeat forever. */
80
+ get duration(): number | null;
81
+ get scenes(): readonly TimelineScene[];
82
+ /** The scene at a time: the last one that has started. */
83
+ sceneIndexAt(t: number): number;
84
+ get sceneIndex(): number;
85
+ /** The time of a scene's final state. */
86
+ sceneEnd(index: number): number;
87
+ /** Whether the play button can play: never in the static view of a story. */
88
+ get canPlay(): boolean;
89
+ play(): void;
90
+ pause(): void;
91
+ toggle(): void;
92
+ /** Moves the clock on by `elapsed` ms while playing; returns true when playback ended. */
93
+ tick(elapsed: number): boolean;
94
+ /** Shows a time; in the static view, the final state of the scene at that time. */
95
+ seek(t: number): void;
96
+ goToScene(index: number): void;
97
+ setStatic(on: boolean): void;
98
+ /** The time whose frame is drawn. */
99
+ get frameTime(): number;
100
+ /** Runs a keyboard command. */
101
+ run(command: PlayerCommand): void;
102
+ /** The title of a view, or its key. */
103
+ titleOf(view: string): string;
104
+ /** The elements (with a box) and relations (with a track) of a view, in drawing order. */
105
+ items(view?: string): ItemRef[];
106
+ /**
107
+ * Moves the keyboard walk to the next (`1`) or previous (`-1`) item that `shown` accepts,
108
+ * wrapping at the ends; returns the item reached, or null when there is none.
109
+ */
110
+ moveFocus(step: 1 | -1, shown?: (item: ItemRef) => boolean): ItemRef | null;
111
+ /** Selects an item of the view on screen, or clears; false for an unknown item. */
112
+ select(item: ItemRef | null): boolean;
113
+ /** What an element of the view on screen opens in the document; null for stories and drills. */
114
+ canOpen(id: string): OpenTarget | null;
115
+ private durations;
116
+ /** How long the drill-down on its way lasts. */
117
+ get drillDuration(): number;
118
+ private start;
119
+ private settle;
120
+ /** Opens what an element of the view on screen opens; false when it opens nothing here. */
121
+ open(id: string): boolean;
122
+ /**
123
+ * Plays a drill-down into the document's own view from a view the document lacks (a catalog
124
+ * page that came from another page): going down, `element` is in `from`; going up, in the
125
+ * document's view.
126
+ */
127
+ enter(from: {
128
+ readonly key: string;
129
+ readonly view: StoryViewData;
130
+ }, element: string, direction: "down" | "up", transition: "morph" | "fade", select?: string | null): void;
131
+ /** Goes up to a view of the trail (the one just above by default); false when there is none. */
132
+ up(index?: number): boolean;
133
+ /** What a settled drill-down says, once: "Opened containers". */
134
+ takeSettled(): string | null;
135
+ /** What a screen reader hears about the current scene, in the player's language. */
136
+ announcement(): string;
137
+ }
138
+ export interface SummaryScene {
139
+ readonly heading: string;
140
+ readonly items: readonly string[];
141
+ }
142
+ /** The scenes of a story and their actions in words, with labels instead of ids. */
143
+ export declare function storySummary(doc: StoryPlayerDocument, locale?: Locale): SummaryScene[];
144
+ /** The effects of a diagram in words. */
145
+ export declare function effectsSummary(doc: EffectsPlayerDocument, locale?: Locale, view?: string): string[];
146
+ //# sourceMappingURL=controller.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../src/controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,MAAM,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,EAIL,KAAK,SAAS,EACd,KAAK,aAAa,EAElB,KAAK,aAAa,EACnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EACV,qBAAqB,EACrB,UAAU,EACV,cAAc,EACd,mBAAmB,EACpB,MAAM,aAAa,CAAC;AAGrB,sDAAsD;AACtD,MAAM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