rapier-embed 1.2.51 → 1.2.55

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
@@ -2,11 +2,6 @@
2
2
 
3
3
  Put Rapier's Markdown editor or reader in your web app, each one offline HTML file.
4
4
 
5
- <picture>
6
- <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/jackskip22/rapier-plugins/main/assets/write-1280-dark.png">
7
- <img src="https://raw.githubusercontent.com/jackskip22/rapier-plugins/main/assets/write-1280-light.png" alt="The Rapier editor on a computer: a launch plan with an agent's change marked" width="960">
8
- </picture>
9
-
10
5
  Try the editor at [rapier.website](https://rapier.website).
11
6
  Install: `npm install rapier-embed`.
12
7
 
@@ -20,7 +15,7 @@ Honor no-upload or no-host instructions. The workflow choices below are alternat
20
15
  Embed Rapier's Markdown editor or lightweight reader in your web app. Each build is one offline HTML file. The helper is an ES module: `import {Rapier} from 'rapier-embed'` or `<script type="module">`; there is no classic script or UMD build. Your
21
16
  app owns the document and storage; its agent edits live through WebMCP. The person sees the agent's presence and
22
17
  change marks, taps a change to see the before and undoes anything. Honor the person's Will/1 regions.
23
- The reader is one file of about 410 kB, `rapier.html` about 4.0 MB, with optional fonts and plug-ins. The helper is MIT with no dependencies. The two builds it frames are AGPL-3.0-only: use them under the AGPL, or
18
+ The reader is one file of about 420 kB, `rapier.html` about 4.0 MB, with optional fonts and plug-ins. The helper is MIT with no dependencies. The two builds it frames are AGPL-3.0-only: use them under the AGPL, or
24
19
  buy a commercial license for other terms (`LICENSING.md` in the Rapier repository).
25
20
 
26
21
  Choose one of two builds:
@@ -50,7 +45,7 @@ downloaded copy yourself and pass it as `src`.
50
45
  document access remain enforced.
51
46
 
52
47
  ```sh
53
- npm install rapier-embed@1.2.51
48
+ npm install rapier-embed@1.2.52
54
49
  ```
55
50
 
56
51
  Or copy the package's `embed.mjs` and `contract.mjs` into one directory of your app; no runtime CDN is needed.
@@ -64,7 +59,7 @@ sends Markdown only when saving; change notifications contain no source.
64
59
  Rapier is a phone-first Markdown editor for notes, diagrams, drawing and watercolor painting. It runs offline
65
60
  as one HTML file on Android, Web, Windows and Linux.
66
61
  Collaborate over MCP and WebMCP, use optional plain-file sync to your own cloud storage, or embed the
67
- editor and lightweight reader (about 410 kB). The agent edits live; the person sees its presence and
62
+ editor and lightweight reader (about 420 kB). The agent edits live; the person sees its presence and
68
63
  changes, taps a change to see the before and undoes anything. Use `show {target:"comparison"}` to show a diff deliberately.
69
64
 
70
65
  1. **Work together live.** Connect to `https://mcp.rapier.website/door/mcp`, then call `open` to share one document with the person.
@@ -138,7 +133,7 @@ The reader on its own page opens a document at an address on its own origin: `ht
138
133
 
139
134
  Keep the helper, page and plug-in manifest on one version. For version 1.2.46:
140
135
 
141
- 1. Install the helper: `npm install rapier-embed@1.2.51`.
136
+ 1. Install the helper: `npm install rapier-embed@1.2.52`.
142
137
  2. Create `public/vendor/rapier/` and save the reader into it from
143
138
  `https://cdn.jsdelivr.net/gh/jackskip22/rapier-plugins@cdn-v1.2.46/embed/rapier-reader.html`.
144
139
  3. Fetch its plug-ins from the same version's manifest:
@@ -160,8 +155,8 @@ length and SHA-384 before it runs it, and keeps on the device. A file that fails
160
155
  <!-- PLUGIN_TABLE_BEGIN (tools/embed-plugin-table.mjs writes this table) -->
161
156
  | Plug-in | Adds | Size | Pages |
162
157
  | --- | --- | --- | --- |
163
- | `flowchart` | Draws Mermaid flowcharts and graphs natively, in the editor's own style. | 0.34 MB | The reader |
164
- | `docx` | Opens a Word document (.docx) as a Markdown document: headings, lists, tables, pictures and comments. | 0.91 MB | The reader |
158
+ | `flowchart` | Draws Mermaid flowcharts and graphs natively, in the editor's own style. | 0.36 MB | The reader |
159
+ | `docx` | Opens a Word document (.docx) as a Markdown document: headings, lists, tables, pictures and comments. | 0.94 MB | The reader |
165
160
  | `math` | Typesets TeX math ($...$ and $$...$$) as SVG. | 0.74 MB | Both |
166
161
  | `diagrams` | Draws every other Mermaid diagram: sequence, class, state, ER, Gantt, pie and more. | 1.14 MB (2 files) | Both |
167
162
  | `pdf` | Opens a PDF as a Markdown document: its text layer, or each page as a picture. Fetches the pdf.js files itself. | 6.16 MB (198 files) | Both |
@@ -172,7 +167,7 @@ length and SHA-384 before it runs it, and keeps on the device. A file that fails
172
167
  | `elements` | The Elements sheet's traced ornaments: 3,155 pieces from the ornament book. | 16.2 MB (51 files) | `rapier.html` |
173
168
  | `lettersets` | The Gallery's letter sets: 31 sets of ornamental capitals. | 2.82 MB (31 files) | `rapier.html` |
174
169
 
175
- Totals: the reader, 9.29 MB (31.0 MB with `ocr`); `rapier.html`, 57.2 MB. Release 1.2.51.
170
+ Totals: the reader, 9.34 MB (31.0 MB with `ocr`); `rapier.html`, 57.2 MB. Release 1.2.55.
176
171
  <!-- PLUGIN_TABLE_END -->
177
172
 
178
173
  The manifest lists every plug-in file and, in `builds`, the pages that use it. `rapier.html` has flowcharts and Word import
package/contract.d.mts CHANGED
@@ -34,8 +34,54 @@ export function normalizeSettings(value?: Settings, policy?: {features?: readonl
34
34
  export function snapshotSettings(value: Settings | undefined): Readonly<Partial<AcceptedSettings>> | undefined;
35
35
  /** Opens the device's file chooser; resolves null when canceled or aborted. */
36
36
  export function pickDeviceFile(document: Document, signal?: AbortSignal): Promise<File | null>;
37
- /** The editor page's open-file exchange; used by the page itself. */
38
- export function createFilePicker(ports: Record<string, unknown>): unknown;
37
+ export interface FilePickerSnapshot {
38
+ port: unknown;
39
+ portGeneration: unknown;
40
+ baseRevision: number | string | null;
41
+ timer?: ReturnType<typeof setTimeout>;
42
+ reading?: boolean;
43
+ committing?: boolean;
44
+ }
45
+ /** Ticket-owned fields replace or widen snapshot fields as the picker advances. */
46
+ export type FilePickerPending<Snapshot extends FilePickerSnapshot = FilePickerSnapshot> =
47
+ Omit<Snapshot, 'requestId' | 'controller' | 'started' | 'host' | 'timer' | 'reading' | 'committing'> & {
48
+ requestId: string;
49
+ controller: AbortController;
50
+ started(value: boolean): void;
51
+ host: boolean;
52
+ timer?: ReturnType<typeof setTimeout>;
53
+ reading?: boolean;
54
+ committing?: boolean;
55
+ };
56
+ export type FilePickerReply = {requestId: string; baseRevision: number | string | null} & (
57
+ {type: 'open-ack'; payload?: Record<string, never>} |
58
+ {type: 'open-result'; payload: {file: File | null}} |
59
+ {type: 'open-nack'; payload: {code: string; reason: string}}
60
+ );
61
+ export interface FilePickerPorts<Snapshot extends FilePickerSnapshot = FilePickerSnapshot> {
62
+ document: Document;
63
+ refusal(): string | null | undefined;
64
+ snapshot(): Snapshot;
65
+ current(row: FilePickerPending<Snapshot>): boolean;
66
+ settle(): boolean;
67
+ post(type: 'open-request' | 'open-cancel', payload: Record<string, never>, requestId: string, baseRevision: number | string | null): boolean;
68
+ /** The picker awaits completion but does not use the returned value. */
69
+ open(file: File, row: FilePickerPending<Snapshot>): unknown;
70
+ notify(code: string): void;
71
+ error(failure: unknown): void;
72
+ }
73
+ export interface FilePicker<Snapshot extends FilePickerSnapshot = FilePickerSnapshot> {
74
+ pending: FilePickerPending<Snapshot> | null;
75
+ refusal(): string | null | undefined;
76
+ current(row: FilePickerPending<Snapshot> | null | undefined): boolean;
77
+ check(): void;
78
+ cancel(code?: string, tellHost?: boolean): void;
79
+ begin(event?: Pick<Event, 'isTrusted'> | null): false | Promise<boolean>;
80
+ answer(data: FilePickerReply): string;
81
+ selected(file: File | null, row: FilePickerPending<Snapshot>): Promise<void>;
82
+ }
83
+ /** The page's open-file exchange, not a mount option. Call methods on the returned picker. */
84
+ export function createFilePicker<Snapshot extends FilePickerSnapshot>(ports: FilePickerPorts<Snapshot>): FilePicker<Snapshot>;
39
85
  /** An absolute HTTPS address without credentials, at most 4,096 code units; throws `asset_url_invalid`. */
40
86
  export function assetURL(value: string): string;
41
87
  /** Nonempty bytes within the picture limit; throws `asset_bytes_invalid` or `picture_too_large`. */
@@ -43,8 +89,34 @@ export function assetBytes(value: Uint8Array, limit?: number): Uint8Array;
43
89
  /** Lowercase hex SHA-256. */
44
90
  export function bytesHash(bytes: BufferSource): Promise<string>;
45
91
  export function externalImage(raw: string, asset: {label: string; title?: string}, url: string | null | undefined): string;
46
- /** The editor page's picture exchange; used by the page itself. */
47
- export function createAssetBroker(ports: Record<string, unknown>): unknown;
92
+ export interface BrokerAsset {
93
+ bytes: Uint8Array;
94
+ codec: AssetType;
95
+ [metadata: string]: unknown;
96
+ }
97
+ /** A shallow asset copy with owned bytes; metadata is not cloned or frozen. */
98
+ export interface RetainedAsset extends BrokerAsset { bytes: Uint8Array<ArrayBuffer>; }
99
+ export interface AssetBrokerState {
100
+ identity: unknown;
101
+ generation: unknown;
102
+ connected: boolean;
103
+ granted: boolean;
104
+ pictureBytes: number;
105
+ baseRevision: number | string | null;
106
+ }
107
+ export type AssetBrokerResult = {url: string} | {code: string};
108
+ export interface AssetBrokerPorts {
109
+ current(): AssetBrokerState;
110
+ send(type: 'asset-request', payload: {bytesSha256: string; mediaType: AssetType; bytes: Uint8Array<ArrayBuffer>}, requestId: string, baseRevision: number | string | null): boolean;
111
+ }
112
+ export interface AssetBroker {
113
+ request(asset: BrokerAsset): Promise<AssetBrokerResult>;
114
+ answer(message: {type: 'asset-ack' | 'asset-nack'; requestId: string; baseRevision: number | string | null; payload?: {url?: string; code?: string; reason?: string}}): AssetBrokerResult;
115
+ cancel(code?: string): void;
116
+ lookup(url: string): RetainedAsset | null;
117
+ }
118
+ /** The page's picture exchange, not the host's assets callback. */
119
+ export function createAssetBroker(ports: AssetBrokerPorts): Readonly<AssetBroker>;
48
120
  /** Not a mount option: the option is `baseUrl` on `load`. The host's picture base: returns a function that turns a relative picture address into an address under `baseUrl` (or null), with
49
121
  * `vouched`, the addresses it produced. Null when no base is given; throws `invalid_base_url` for anything but an absolute https address (or http on localhost). Used by the page itself. */
50
122
  export function pictureBase(value: string | null | undefined): (((src: string) => string | null) & {vouched: Set<string>}) | null;
package/contract.mjs CHANGED
@@ -264,6 +264,6 @@ export function pictureBase(value) {
264
264
  return Object.assign(src => {
265
265
  const text = String(src || '').trim();
266
266
  if (!text || /^(?:[a-z][a-z0-9+.-]*:|\/\/|#)/i.test(text)) return null;
267
- try { const href = new URL(text, base).href; vouched.add(href); return href; } catch (_) { return null; }
267
+ try { const url = new URL(text, base); if (url.origin !== base.origin) return null; vouched.add(url.href); return url.href; } catch (_) { return null; }
268
268
  }, {vouched});
269
269
  }
package/embed.mjs CHANGED
@@ -265,13 +265,13 @@ function pictureBase(value) {
265
265
  return Object.assign(src => {
266
266
  const text = String(src || '').trim();
267
267
  if (!text || /^(?:[a-z][a-z0-9+.-]*:|\/\/|#)/i.test(text)) return null;
268
- try { const href = new URL(text, base).href; vouched.add(href); return href; } catch (_) { return null; }
268
+ try { const url = new URL(text, base); if (url.origin !== base.origin) return null; vouched.add(url.href); return url.href; } catch (_) { return null; }
269
269
  }, {vouched});
270
270
  }
271
271
  return {FEATURES, LIMITS, ASSET_TYPES, refusal, coded, normalizeSettings, snapshotSettings, pickDeviceFile, createFilePicker, assetURL, assetBytes, bytesHash, externalImage, createAssetBroker, pictureBase};
272
272
  })();
273
273
  const BUILDS = Object.freeze({full: 'https://rapier.website/embed/rapier.html', reader: 'https://rapier.website/embed/rapier-reader.html'});
274
- const PACKAGE_VERSION = '1.2.51';
274
+ const PACKAGE_VERSION = '1.2.55';
275
275
  const OPTIONS = ['build', 'src', 'plugins', 'approvePlugins', 'sessionId', 'documentId', 'agent', 'agentName', 'theme', 'save', 'assets', 'openFile', 'load',
276
276
  'onState', 'compare', 'onClose', 'settings', 'style', 'title', 'onError', 'timeout'];
277
277
  const READER_FEATURES = ['find', 'readAloud', 'share'];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rapier-embed",
3
- "version": "1.2.51",
3
+ "version": "1.2.55",
4
4
  "description": "Embed the Rapier Markdown editor or its lightweight reader (about 360 kB) in your web app. Runs offline from your own copy, saves to your storage, and takes your CSS and fonts. Your app's AI agent edits directly over WebMCP under the Will. MIT, no dependencies.",
5
5
  "keywords": [
6
6
  "markdown",