rapier-html 1.2.17 → 1.2.19

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/dist/wrap.mjs CHANGED
@@ -14,6 +14,7 @@ const OFFLINE_POLICY = "default-src 'none'; script-src 'unsafe-inline' 'wasm-uns
14
14
  export {encodeCarried, decodeCarried};
15
15
 
16
16
  const PREVIEW = /<meta (?:name="(?:description|generator)"|property="og:(?:title|description)") content="[^"]*" data-rapier-preview>\n?/g;
17
+ const APPEARANCE = /<meta name="rapier-appearance" content="(light|dark)">\n?/g;
17
18
  const plainWords = text => text.replace(/!\[[^\]]*\]\[[^\]]*\]|!\[[^\]]*\]\([^)]*\)/g, '').replace(/\[([^\]]*)\](?:\([^)]*\)|\[[^\]]*\])/g, '$1')
18
19
  .replace(/<[^>]*>/g, '').replace(/[*_`~=]+|\[\^[^\]]*\]/g, '').replace(/\s+/g, ' ').trim();
19
20
  export function pagePreview(markdown) {
@@ -118,6 +119,8 @@ export function wrap(pageHtml, text, name, options) {
118
119
  text = saved.text;
119
120
  const previous = unwrap(pageHtml);
120
121
  const opts = {...saved, ...(options || {})};
122
+ const theme = opts.theme ?? previous.theme;
123
+ if (theme != null && !['light', 'dark'].includes(theme)) throw new Error('the theme is light or dark');
121
124
  const docName = safeName(name, 'document.md');
122
125
  if (opts.kind != null && !['markdown', 'text', 'code'].includes(opts.kind)) throw new Error('invalid document kind');
123
126
  if (opts.view != null && !['draw', 'notes'].includes(opts.view)) throw new Error('the view is draw or notes');
@@ -148,11 +151,12 @@ export function wrap(pageHtml, text, name, options) {
148
151
  }
149
152
  if (baseline) baseline = readBase({...baseline, ...(opts.by != null ? {by: String(opts.by).trim()} : {}), ...(opts.at != null ? {at: String(opts.at)} : {})});
150
153
  carriedBlocks += '\n' + writeBase(text, baseline);
151
- const unseeded = offlineTemplate(previous.html.replace(SEARCH_WORDS, '').replace(PREVIEW, '').split(PAGE_SEED + '\n').join(''), address);
154
+ const unseeded = offlineTemplate(previous.html.replace(SEARCH_WORDS, '').replace(PREVIEW, '').replace(APPEARANCE, '').split(PAGE_SEED + '\n').join(''), address);
152
155
  const headTag = /<meta charset[^>]*>\n?/i.exec(unseeded) || /<head[^>]*>\n?/.exec(unseeded);
153
156
  if (!headTag) throw new Error('not a Rapier page: no <head>');
154
157
  const seededAt = headTag.index + headTag[0].length;
155
- const stripped = unseeded.slice(0, seededAt) + PAGE_SEED + '\n' + unseeded.slice(seededAt);
158
+ const stripped = unseeded.slice(0, seededAt) + PAGE_SEED + '\n'
159
+ + (theme ? '<meta name="rapier-appearance" content="' + theme + '">\n' : '') + unseeded.slice(seededAt);
156
160
  const bodyTag = /<body[^>]*>/.exec(stripped);
157
161
  if (!bodyTag) throw new Error('not a Rapier page: no <body>');
158
162
  const at = bodyTag.index + bodyTag[0].length;
@@ -162,6 +166,7 @@ export function wrap(pageHtml, text, name, options) {
162
166
  return titled.slice(0, at + shift) + '\n' + block + carriedBlocks + titled.slice(at + shift);
163
167
  }
164
168
  export function unwrap(pageHtml) {
169
+ const theme = Array.from(pageHtml.matchAll(APPEARANCE), match => match[1])[0] || null;
165
170
  let html = pageHtml, text = null, name = null, kind = null, view = null, address = null, expiry = null;
166
171
  const a = pageHtml.indexOf(START);
167
172
  if (a >= 0) {
@@ -192,5 +197,5 @@ export function unwrap(pageHtml) {
192
197
  const carriedBase = takeBase(html); html = carriedBase.html;
193
198
  const comparisonBase = carriedBase.base;
194
199
  const parts = takeParts(html, text);
195
- return {...parts, text, name, kind, view, drawing, drawingName, comparisonBase, base: comparisonBase?.text ?? null, baseName: comparisonBase?.name ?? null, baseSha256: comparisonBase?.sha256 ?? null, baseRevision: comparisonBase?.revision ?? null, by: comparisonBase?.by ?? null, at: comparisonBase?.at ?? null, return: address, return_expires_at: expiry};
200
+ return {...parts, text, name, kind, view, theme, drawing, drawingName, comparisonBase, base: comparisonBase?.text ?? null, baseName: comparisonBase?.name ?? null, baseSha256: comparisonBase?.sha256 ?? null, baseRevision: comparisonBase?.revision ?? null, by: comparisonBase?.by ?? null, at: comparisonBase?.at ?? null, return: address, return_expires_at: expiry};
196
201
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rapier-html",
3
- "version": "1.2.17",
3
+ "version": "1.2.19",
4
4
  "description": "One command turns a Markdown file into one offline HTML file: the whole Rapier editor with the document inside. Opens in any browser, phone or desktop, with no install or account. Write, draw and paint watercolor, then Send back the edits to your AI agent.",
5
5
  "keywords": [
6
6
  "markdown",