rapier-embed 1.2.62 → 1.2.63

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
@@ -45,7 +45,7 @@ downloaded copy yourself and pass it as `src`.
45
45
  document access remain enforced.
46
46
 
47
47
  ```sh
48
- npm install rapier-embed@1.2.57
48
+ npm install rapier-embed@1.2.62
49
49
  ```
50
50
 
51
51
  Or copy the package's `embed.mjs` and `contract.mjs` into one directory of your app; no runtime CDN is needed.
@@ -133,7 +133,7 @@ The reader on its own page opens a document at an address on its own origin: `ht
133
133
 
134
134
  Keep the helper, page and plug-in manifest on one version. For version 1.2.46:
135
135
 
136
- 1. Install the helper: `npm install rapier-embed@1.2.57`.
136
+ 1. Install the helper: `npm install rapier-embed@1.2.62`.
137
137
  2. Create `public/vendor/rapier/` and save the reader into it from
138
138
  `https://cdn.jsdelivr.net/gh/jackskip22/rapier-plugins@cdn-v1.2.46/embed/rapier-reader.html`.
139
139
  3. Fetch its plug-ins from the same version's manifest:
@@ -167,7 +167,7 @@ length and SHA-384 before it runs it, and keeps on the device. A file that fails
167
167
  | `elements` | The Elements sheet's traced ornaments: 3,155 pieces from the ornament book. | 16.2 MB (51 files) | `rapier.html` |
168
168
  | `lettersets` | The Gallery's letter sets: 31 sets of ornamental capitals. | 2.82 MB (31 files) | `rapier.html` |
169
169
 
170
- Totals: the reader, 9.34 MB (31.0 MB with `ocr`); `rapier.html`, 57.2 MB. Release 1.2.62.
170
+ Totals: the reader, 9.34 MB (31.0 MB with `ocr`); `rapier.html`, 57.2 MB. Release 1.2.63.
171
171
  <!-- PLUGIN_TABLE_END -->
172
172
 
173
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
@@ -88,7 +88,8 @@ export function assetURL(value: string): string;
88
88
  export function assetBytes(value: Uint8Array, limit?: number): Uint8Array;
89
89
  /** Lowercase hex SHA-256. */
90
90
  export function bytesHash(bytes: BufferSource): Promise<string>;
91
- export function externalImage(raw: string, asset: {label: string; title?: string}, url: string | null | undefined): string;
91
+ /** The picture's Markdown with the host's address; an address in the folder of `base` (the load's baseUrl) is written relative to it. */
92
+ export function externalImage(raw: string, asset: {label: string; title?: string}, url: string | null | undefined, base?: string): string;
92
93
  export interface BrokerAsset {
93
94
  bytes: Uint8Array;
94
95
  codec: AssetType;
@@ -119,4 +120,4 @@ export interface AssetBroker {
119
120
  export function createAssetBroker(ports: AssetBrokerPorts): Readonly<AssetBroker>;
120
121
  /** 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
121
122
  * `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. */
122
- export function pictureBase(value: string | null | undefined): (((src: string) => string | null) & {vouched: Set<string>}) | null;
123
+ export function pictureBase(value: string | null | undefined): (((src: string) => string | null) & {vouched: Set<string>; base: string}) | null;
package/contract.mjs CHANGED
@@ -179,12 +179,15 @@ function ownedPicture(bytes) {
179
179
  copy.set(bytes);
180
180
  return copy;
181
181
  }
182
- export function externalImage(raw, asset, url) {
182
+ export function externalImage(raw, asset, url, base) {
183
183
  if (!url) return raw;
184
184
  const token = '[' + asset.label + ']', at = raw.lastIndexOf(token);
185
185
  if (at < 0) throw refusal('asset_reference_invalid');
186
186
  const title = asset.title ? ' "' + String(asset.title).replace(/&/g, '&amp;').replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/[\r\n]/g, ' ') + '"' : '';
187
- return raw.slice(0, at) + '(<' + assetURL(url).replace(/&/g, '&amp;') + '>' + title + ')' + raw.slice(at + token.length);
187
+ let address = assetURL(url);
188
+ const folder = base ? new URL('.', base).href : '';
189
+ if (folder && address.startsWith(folder) && address.length > folder.length && !/[?#]/.test(address)) address = address.slice(folder.length);
190
+ return raw.slice(0, at) + '(<' + address.replace(/&/g, '&amp;') + '>' + title + ')' + raw.slice(at + token.length);
188
191
  }
189
192
 
190
193
  export function createAssetBroker({current, send}) {
@@ -265,5 +268,5 @@ export function pictureBase(value) {
265
268
  const text = String(src || '').trim();
266
269
  if (!text || /^(?:[a-z][a-z0-9+.-]*:|\/\/|#)/i.test(text)) return null;
267
270
  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
- }, {vouched});
271
+ }, {vouched, base: base.href});
269
272
  }
package/embed.mjs CHANGED
@@ -271,7 +271,7 @@ function pictureBase(value) {
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.62';
274
+ const PACKAGE_VERSION = '1.2.63';
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'];
@@ -317,9 +317,9 @@ function readerStyle(value) {
317
317
  }
318
318
 
319
319
  const HOSTED_ORIGIN = new URL(BUILDS.full).origin;
320
- function framingProblem(host, source, sandbox, noun) {
320
+ function framingProblem(host, source, sandbox, noun, ownCopy = false) {
321
321
  const here = host.location, local = ['localhost', '127.0.0.1', '[::1]'].includes(here.hostname);
322
- if (here.protocol !== 'https:' && here.protocol !== 'http:')
322
+ if (!ownCopy && here.protocol !== 'https:' && here.protocol !== 'http:')
323
323
  return {code: 'host_scheme_unsupported', reason: 'The ' + noun + ' cannot be framed by a ' + here.protocol + ' page: it needs an https page, or http on localhost. Serve your app over one of those.'};
324
324
  if (source.origin === HOSTED_ORIGIN && here.protocol === 'http:' && !local)
325
325
  return {code: 'host_not_secure', reason: 'The hosted ' + noun + ' can be framed by https pages and by http on localhost only. Serve your app over https, or serve a copy of the page yourself and set src.'};
@@ -359,12 +359,15 @@ function mount(target, options = {}) {
359
359
  if (options.src !== undefined && typeof options.src !== 'string') throw new TypeError();
360
360
  source = new URL(options.src || BUILDS[build], host.location.href);
361
361
  } catch { throw coded('invalid_src', TypeError, 'src must be a page address'); }
362
- if (source.username || source.password || !(source.protocol === 'https:' || source.protocol === 'http:' && ['localhost', '127.0.0.1', '[::1]'].includes(source.hostname)))
363
- throw coded('host_not_secure', TypeError, 'The editor needs HTTPS, or HTTP on localhost');
362
+ const ownCopy = source.protocol === 'blob:' && host.origin !== 'null' && source.origin === host.origin;
363
+ if (!ownCopy && (source.username || source.password || !(source.protocol === 'https:' || source.protocol === 'http:' && ['localhost', '127.0.0.1', '[::1]'].includes(source.hostname))))
364
+ throw coded('host_not_secure', TypeError, 'The editor needs HTTPS, or HTTP on localhost, or a blob: copy of the page on this page\'s own origin');
365
+ if (ownCopy && (options.plugins !== undefined || options.approvePlugins === true))
366
+ throw coded('invalid_plugins', TypeError, 'A blob: copy of the page takes no plugins or approvePlugins: its address carries no query');
364
367
  const page = source.pathname.split('/').pop();
365
368
  if (reader ? page === 'rapier.html' : page === 'rapier-reader.html')
366
369
  throw Object.assign(new TypeError('build ' + build + ' cannot frame ' + page + '; set build: \'' + (reader ? 'full' : 'reader') + '\' or src to ' + (reader ? 'rapier-reader.html' : 'rapier.html')), {code: 'build_mismatch'});
367
- source.searchParams.set('embed', '1');
370
+ if (!ownCopy) source.searchParams.set('embed', '1');
368
371
  if (options.plugins !== undefined) {
369
372
  let directory;
370
373
  try { directory = new URL(options.plugins, host.location.href); } catch { throw coded('invalid_plugins', TypeError, 'plugins is not an address'); }
@@ -375,7 +378,7 @@ function mount(target, options = {}) {
375
378
  source.searchParams.set('plugins', directory.href);
376
379
  }
377
380
  if (options.approvePlugins === true) source.searchParams.set('approvePlugins', '1');
378
- const origin = source.origin, auto = options.sessionId === undefined && options.documentId === undefined ? autoIdentity(options, host.location) : null;
381
+ const origin = ownCopy ? host.origin : source.origin, auto = options.sessionId === undefined && options.documentId === undefined ? autoIdentity(options, host.location) : null;
379
382
  const pageSession = options.documentId !== undefined && options.save ? 'page-' + fnv(host.location.origin + host.location.pathname) : null;
380
383
  const askedSession = options.sessionId ?? (auto ? 'page-' + auto : pageSession ?? mint('session')), askedDocument = options.documentId ?? (auto ? 'doc-' + auto : mint('document'));
381
384
  if (!identifier(askedSession) || !identifier(askedDocument)) throw coded('invalid_id', TypeError, 'Session and document IDs must be nonempty strings of at most 256 code units');
@@ -842,13 +845,14 @@ function mount(target, options = {}) {
842
845
  iframe.setAttribute('allow', options.agent ? 'clipboard-write; tools' : 'clipboard-write');
843
846
  const ownSandbox = iframe === target && iframe.hasAttribute('sandbox');
844
847
  if (!ownSandbox) iframe.setAttribute('sandbox', 'allow-scripts allow-same-origin allow-downloads');
845
- const blocked = framingProblem(host, source, ownSandbox ? iframe.sandbox : null, noun);
848
+ const blocked = framingProblem(host, source, ownSandbox ? iframe.sandbox : null, noun, ownCopy);
846
849
  if (blocked) {
847
850
  if (iframe !== target) target.append(iframe);
848
851
  queueMicrotask(() => bootFailed(blocked.code, blocked.reason));
849
852
  return handle;
850
853
  }
851
854
  host.addEventListener('message', onWindowMessage); iframe.addEventListener('load', onLoad);
855
+ if (ownCopy) iframe.name = 'rapier-embed';
852
856
  iframe.src = source.href;
853
857
  if (iframe !== target) target.append(iframe);
854
858
  function watch() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rapier-embed",
3
- "version": "1.2.62",
3
+ "version": "1.2.63",
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",