@plotwork.official/viewer 0.1.1 → 0.1.3
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/README.md
CHANGED
|
@@ -1,7 +1,28 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://plotwork.dev">
|
|
3
|
+
<picture>
|
|
4
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://plotwork.dev/brand/logo/plotwork-lockup-on-dark.svg">
|
|
5
|
+
<img alt="Plotwork" src="https://plotwork.dev/brand/logo/plotwork-lockup-on-light.svg" width="240">
|
|
6
|
+
</picture>
|
|
7
|
+
</a>
|
|
8
|
+
</p>
|
|
9
|
+
|
|
1
10
|
# @plotwork.official/viewer
|
|
2
11
|
|
|
12
|
+
<p>
|
|
13
|
+
<a href="https://www.npmjs.com/package/@plotwork.official/viewer"><img alt="npm" src="https://img.shields.io/npm/v/%40plotwork.official%2Fviewer?logo=npm&color=0f766e"></a>
|
|
14
|
+
<img alt="Provenance" src="https://img.shields.io/badge/provenance-signed-0f766e?logo=sigstore&logoColor=white">
|
|
15
|
+
<img alt="Runtime dependencies" src="https://img.shields.io/badge/runtime%20dependencies-0-0f766e?logo=dependabot&logoColor=white">
|
|
16
|
+
<img alt="TypeScript" src="https://img.shields.io/badge/types-included-3178c6?logo=typescript&logoColor=white">
|
|
17
|
+
<a href="https://github.com/plotwork-official/plotwork-sdk/blob/main/LICENSE"><img alt="MIT licence" src="https://img.shields.io/badge/licence-MIT-52514e"></a>
|
|
18
|
+
</p>
|
|
19
|
+
|
|
3
20
|
Embed interactive Plotwork diagrams in any page: pan and zoom, trace a box's lines, drill from an overview box into its part, light and dark, and live updates when a new version is published. A web component, `<plotwork-diagram>`, and a React component, `<PlotworkDiagram>`.
|
|
4
21
|
|
|
22
|
+
<p align="center">
|
|
23
|
+
<img alt="The viewer added to an app: npm install, a PlotworkDiagram in App.tsx, then the real component tracing a box, sending a drill event, and showing a new version live" src="https://assets.plotwork.dev/media/films/sdk/readme-light.webp" width="760">
|
|
24
|
+
</p>
|
|
25
|
+
|
|
5
26
|
## TL;DR
|
|
6
27
|
|
|
7
28
|
| Question | Answer |
|
|
@@ -76,7 +97,7 @@ It renders as the bare element on a server and comes alive in the browser.
|
|
|
76
97
|
| `svg` | Set the picture's text directly. |
|
|
77
98
|
| `labels` | Words in your language, over the English defaults. |
|
|
78
99
|
| `plotwork-load` | `{ fingerprint, hasSource }` |
|
|
79
|
-
| `plotwork-change` | `{ fingerprint, previous }`: a live
|
|
100
|
+
| `plotwork-change` | `{ fingerprint, previous }`: a new version is shown, from a live check or from `svg` set again (a hot reload). |
|
|
80
101
|
| `plotwork-error` | `{ reason }`: `address`, `missing`, `not-a-picture`, `network`, `fingerprint`, or `empty`. |
|
|
81
102
|
| `plotwork-drill` | `{ id, part, name }`: a box that opens a part was pressed. You decide what opens. |
|
|
82
103
|
| `plotwork-trace` | `{ id }`: the traced box, or `null`. |
|
|
@@ -96,6 +117,6 @@ Set custom properties on the element: `--plotwork-height`, `--plotwork-paper`, `
|
|
|
96
117
|
|
|
97
118
|
| Page | Why |
|
|
98
119
|
|---|---|
|
|
99
|
-
| [Picture contract](
|
|
100
|
-
| [Core](
|
|
101
|
-
| [Element](
|
|
120
|
+
| [Picture contract](https://github.com/plotwork-official/plotwork-sdk/blob/main/spec/picture.md) | What the viewer reads from a picture |
|
|
121
|
+
| [Core](https://github.com/plotwork-official/plotwork-sdk/blob/main/packages/viewer/src/core/README.md) | The parts that need no element |
|
|
122
|
+
| [Element](https://github.com/plotwork-official/plotwork-sdk/blob/main/packages/viewer/src/element/README.md) | How `<plotwork-diagram>` is built |
|
package/dist/element/events.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export interface LoadDetail {
|
|
|
9
9
|
/** True when the picture carries its source, which `source()` returns. */
|
|
10
10
|
hasSource: boolean;
|
|
11
11
|
}
|
|
12
|
-
/** A live picture changed on the server,
|
|
12
|
+
/** A new version of the picture is shown: a live picture changed on the server, or `svg` was set while a picture was shown. */
|
|
13
13
|
export interface ChangeDetail {
|
|
14
14
|
fingerprint: string;
|
|
15
15
|
previous: string;
|
package/dist/element/gestures.js
CHANGED
|
@@ -18,7 +18,12 @@ export function attachGestures(canvas, control) {
|
|
|
18
18
|
const onDown = (event) => {
|
|
19
19
|
if (event.button !== 0)
|
|
20
20
|
return;
|
|
21
|
-
|
|
21
|
+
try {
|
|
22
|
+
canvas.setPointerCapture?.(event.pointerId);
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
// The pointer is already gone (lifted, or not a real pointer): a drag without capture still works inside the canvas.
|
|
26
|
+
}
|
|
22
27
|
const point = local(event);
|
|
23
28
|
pointers.set(event.pointerId, point);
|
|
24
29
|
const both = pair();
|
|
@@ -106,7 +106,7 @@ export function createPlotworkDiagramClass() {
|
|
|
106
106
|
set svg(value) {
|
|
107
107
|
this.#svg = typeof value === 'string' && value !== '' ? value : null;
|
|
108
108
|
if (this.isConnected)
|
|
109
|
-
void this.#refresh();
|
|
109
|
+
void this.#refresh(false, this.#svg !== null);
|
|
110
110
|
}
|
|
111
111
|
get labels() {
|
|
112
112
|
return this.#ownLabels;
|
|
@@ -149,7 +149,11 @@ export function createPlotworkDiagramClass() {
|
|
|
149
149
|
await this.#refresh(true);
|
|
150
150
|
}
|
|
151
151
|
/* Loading. */
|
|
152
|
-
|
|
152
|
+
/**
|
|
153
|
+
* Loads the picture again. `update` says the new text is a new version of the picture shown (a revalidation, or `svg` set while
|
|
154
|
+
* a picture is shown, as a bundler's hot reload does): it keeps the view and sends `plotwork-change` instead of `plotwork-load`.
|
|
155
|
+
*/
|
|
156
|
+
async #refresh(revalidate = false, update = revalidate) {
|
|
153
157
|
this.#loading?.abort();
|
|
154
158
|
const loading = new AbortController();
|
|
155
159
|
this.#loading = loading;
|
|
@@ -159,7 +163,7 @@ export function createPlotworkDiagramClass() {
|
|
|
159
163
|
return;
|
|
160
164
|
if (text === null)
|
|
161
165
|
return this.#fail('empty');
|
|
162
|
-
await this.#show(text,
|
|
166
|
+
await this.#show(text, update && this.#fingerprint !== null);
|
|
163
167
|
}
|
|
164
168
|
catch (error) {
|
|
165
169
|
if (!loading.signal.aborted)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plotwork.official/viewer",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Embed interactive Plotwork diagrams in any page: a <plotwork-diagram> web component and a React component, with no runtime dependencies.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|