rapier-html 1.2.18 → 1.2.20
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/BUILD.json +18 -18
- package/README.md +10 -10
- package/dist/ledger/template-page.mjs +6 -0
- package/dist/page.d.mts +3 -0
- package/dist/rapier.html +69 -51
- package/dist/wrap.mjs +10 -5
- package/package.json +1 -1
package/dist/wrap.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
import {encodeCarried, decodeCarried, writeParts, takeParts, readDocument, readBase, writeBase, takeBase} from './ledger/carried.mjs';
|
|
3
3
|
import {sha256} from './ledger/hash.mjs';
|
|
4
|
+
import {isTemplatePage} from './ledger/template-page.mjs';
|
|
4
5
|
import {PAGE_SEED, returnAddress, returnExpiresAt} from './return-address.mjs';
|
|
5
6
|
|
|
6
7
|
const START = '<script type="text/markdown" id="rapier-document"';
|
|
@@ -14,6 +15,7 @@ const OFFLINE_POLICY = "default-src 'none'; script-src 'unsafe-inline' 'wasm-uns
|
|
|
14
15
|
export {encodeCarried, decodeCarried};
|
|
15
16
|
|
|
16
17
|
const PREVIEW = /<meta (?:name="(?:description|generator)"|property="og:(?:title|description)") content="[^"]*" data-rapier-preview>\n?/g;
|
|
18
|
+
const APPEARANCE = /<meta name="rapier-appearance" content="(light|dark)">\n?/g;
|
|
17
19
|
const plainWords = text => text.replace(/!\[[^\]]*\]\[[^\]]*\]|!\[[^\]]*\]\([^)]*\)/g, '').replace(/\[([^\]]*)\](?:\([^)]*\)|\[[^\]]*\])/g, '$1')
|
|
18
20
|
.replace(/<[^>]*>/g, '').replace(/[*_`~=]+|\[\^[^\]]*\]/g, '').replace(/\s+/g, ' ').trim();
|
|
19
21
|
export function pagePreview(markdown) {
|
|
@@ -96,8 +98,7 @@ export function portableNeeds(text, {base, flowchart} = {}) {
|
|
|
96
98
|
for (const source of [text, base]) {
|
|
97
99
|
if (typeof source !== 'string') continue;
|
|
98
100
|
let prose = '';
|
|
99
|
-
|
|
100
|
-
if (front && /^template:[ \t]*page[ \t]*$/m.test(front[0])) needs.add('layout');
|
|
101
|
+
if (isTemplatePage(source)) needs.add('layout');
|
|
101
102
|
const lines = source.split(/\r\n|\r|\n/);
|
|
102
103
|
for (let at = 0; at < lines.length; at++) {
|
|
103
104
|
const open = /^ {0,3}(`{3,}|~{3,})\s*([^\s`]*)/.exec(lines[at]);
|
|
@@ -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'
|
|
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.
|
|
3
|
+
"version": "1.2.20",
|
|
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",
|