bearminion 1.8.0 → 1.9.0
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/CHANGELOG.md +12 -0
- package/dist/astro.js +5 -5
- package/dist/cli.js +761 -25
- package/dist/content.js +2 -2
- package/dist/hash-BeBymBO1.js +59 -0
- package/dist/index.js +4 -4
- package/dist/marks-DPBilumg.js +174 -0
- package/dist/marks.js +1 -174
- package/dist/{page-NOFVEqn1.js → page-X-WnOu7-.js} +1 -1
- package/dist/{preview--S1QUrMM.js → preview-B_88I5Jm.js} +1 -1
- package/dist/{reload-BPkPoQ-P.js → reload-Dkp3xC0l.js} +1 -1
- package/dist/rich-text-70hddxMC.js +403 -0
- package/dist/rich-text.js +1 -403
- package/dist/{sections-manifest-CU-xBjMi.js → sections-manifest-CO9QfJPG.js} +1 -1
- package/dist/{theme-DFjHjgFO.js → theme-Dv7_7B56.js} +2 -2
- package/dist/ui/mount.js +20 -7
- package/package.json +4 -1
- package/registry/default/files/src/components/atoms/Button.astro +64 -0
- package/registry/default/files/src/components/atoms/Emphasis.astro +24 -0
- package/registry/default/files/src/components/atoms/Image.astro +78 -0
- package/registry/default/files/src/components/atoms/Typography.astro +53 -0
- package/registry/default/files/src/components/atoms/button.ts +31 -0
- package/registry/default/files/src/components/atoms/image.ts +34 -0
- package/registry/default/files/src/components/atoms/options.ts +39 -0
- package/registry/default/files/src/components/atoms/typography.ts +64 -0
- package/registry/default/files/src/components/molecules/CommandLine.astro +109 -0
- package/registry/default/files/src/components/molecules/MediaFrame.astro +71 -0
- package/registry/default/files/src/components/molecules/Pill.astro +24 -0
- package/registry/default/files/src/components/molecules/SectionHeader.astro +63 -0
- package/registry/default/files/src/components/molecules/SectionShell.astro +33 -0
- package/registry/default/files/src/components/sections/contact/Contact.astro +231 -0
- package/registry/default/files/src/components/sections/contact/definition.ts +52 -0
- package/registry/default/files/src/components/sections/contact/form.ts +313 -0
- package/registry/default/files/src/components/sections/contact/wireframe.ts +15 -0
- package/registry/default/files/src/components/sections/cta/Cta.astro +206 -0
- package/registry/default/files/src/components/sections/cta/definition.ts +49 -0
- package/registry/default/files/src/components/sections/cta/wireframe.ts +9 -0
- package/registry/default/files/src/components/sections/faq/Faq.astro +136 -0
- package/registry/default/files/src/components/sections/faq/definition.ts +54 -0
- package/registry/default/files/src/components/sections/faq/wireframe.ts +19 -0
- package/registry/default/files/src/components/sections/features/Features.astro +146 -0
- package/registry/default/files/src/components/sections/features/definition.ts +54 -0
- package/registry/default/files/src/components/sections/features/wireframe.ts +19 -0
- package/registry/default/files/src/components/sections/gallery/Gallery.astro +128 -0
- package/registry/default/files/src/components/sections/gallery/definition.ts +59 -0
- package/registry/default/files/src/components/sections/gallery/lightbox.ts +159 -0
- package/registry/default/files/src/components/sections/gallery/wireframe.ts +12 -0
- package/registry/default/files/src/components/sections/hero/Hero.astro +185 -0
- package/registry/default/files/src/components/sections/hero/HeroBadge.astro +26 -0
- package/registry/default/files/src/components/sections/hero/definition.ts +74 -0
- package/registry/default/files/src/components/sections/hero/wireframe.ts +12 -0
- package/registry/default/files/src/components/sections/logo-strip/LogoStrip.astro +107 -0
- package/registry/default/files/src/components/sections/logo-strip/definition.ts +30 -0
- package/registry/default/files/src/components/sections/logo-strip/wireframe.ts +11 -0
- package/registry/default/files/src/components/sections/media/Media.astro +118 -0
- package/registry/default/files/src/components/sections/media/MediaPlayer.astro +176 -0
- package/registry/default/files/src/components/sections/media/definition.ts +77 -0
- package/registry/default/files/src/components/sections/media/source.ts +3 -0
- package/registry/default/files/src/components/sections/media/wireframe.ts +9 -0
- package/registry/default/files/src/components/sections/pricing/Pricing.astro +210 -0
- package/registry/default/files/src/components/sections/pricing/definition.ts +62 -0
- package/registry/default/files/src/components/sections/pricing/wireframe.ts +18 -0
- package/registry/default/files/src/components/sections/shared.ts +13 -0
- package/registry/default/files/src/components/sections/stats/Stats.astro +110 -0
- package/registry/default/files/src/components/sections/stats/definition.ts +41 -0
- package/registry/default/files/src/components/sections/stats/wireframe.ts +15 -0
- package/registry/default/files/src/components/sections/steps/Steps.astro +139 -0
- package/registry/default/files/src/components/sections/steps/definition.ts +62 -0
- package/registry/default/files/src/components/sections/steps/icons.ts +27 -0
- package/registry/default/files/src/components/sections/steps/wireframe.ts +16 -0
- package/registry/default/files/src/components/sections/testimonials/Testimonials.astro +172 -0
- package/registry/default/files/src/components/sections/testimonials/definition.ts +42 -0
- package/registry/default/files/src/components/sections/testimonials/wireframe.ts +21 -0
- package/registry/default/files/src/components/sections/text/Text.astro +43 -0
- package/registry/default/files/src/components/sections/text/definition.ts +36 -0
- package/registry/default/files/src/components/sections/text/wireframe.ts +12 -0
- package/registry/default/files/src/components/sections/text-image/TextImage.astro +107 -0
- package/registry/default/files/src/components/sections/text-image/definition.ts +39 -0
- package/registry/default/files/src/components/sections/text-image/wireframe.ts +12 -0
- package/registry/default/files/src/lib/assets.ts +13 -0
- package/registry/default/files/src/lib/cn.ts +6 -0
- package/registry/default/files/src/lib/contact-form.ts +97 -0
- package/registry/default/files/src/lib/hidden-text.ts +32 -0
- package/registry/default/files/src/lib/image-url.ts +38 -0
- package/registry/default/files/src/lib/link-attrs.ts +74 -0
- package/registry/default/registry.json +670 -0
package/dist/content.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { n as createPageSchema, r as createTolerantPageSchema } from "./page-
|
|
1
|
+
import { n as createPageSchema, r as createTolerantPageSchema } from "./page-X-WnOu7-.js";
|
|
2
2
|
import { n as createMigrator } from "./migrate-b408EaLp.js";
|
|
3
|
-
import { t as CONTENT_COLLECTIONS_MARKER } from "./reload-
|
|
3
|
+
import { t as CONTENT_COLLECTIONS_MARKER } from "./reload-Dkp3xC0l.js";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { pathToFileURL } from "node:url";
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
//#region src/registry/types.ts
|
|
5
|
+
/** The lock file in a site's root. */
|
|
6
|
+
const LOCK_FILE = "bearminion.lock.json";
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region src/add/lock.ts
|
|
9
|
+
/** The site's lock file, or an empty one for the template when it has none. */
|
|
10
|
+
function readLock(root, template) {
|
|
11
|
+
const file = path.join(root, LOCK_FILE);
|
|
12
|
+
if (!fs.existsSync(file)) return {
|
|
13
|
+
schemaVersion: 1,
|
|
14
|
+
template,
|
|
15
|
+
files: {}
|
|
16
|
+
};
|
|
17
|
+
const lock = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
18
|
+
if (lock.template !== template) throw new Error(`${LOCK_FILE} belongs to the "${lock.template}" template, and this is "${template}".`);
|
|
19
|
+
return lock;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Notes that `paths` now hold what `registry` has, keeping an older entry whose hash is still right: the file has not
|
|
23
|
+
* changed since that release, and that release is the one a later update has to start from.
|
|
24
|
+
*/
|
|
25
|
+
function recordFiles(lock, registry, paths) {
|
|
26
|
+
const files = { ...lock.files };
|
|
27
|
+
for (const file of paths) {
|
|
28
|
+
const hash = registry.files[file]?.hash;
|
|
29
|
+
if (hash === void 0) continue;
|
|
30
|
+
if (files[file]?.hash !== hash) files[file] = {
|
|
31
|
+
version: registry.version,
|
|
32
|
+
hash
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
...lock,
|
|
37
|
+
files: Object.fromEntries(Object.entries(files).sort(([a], [b]) => a < b ? -1 : 1))
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function writeLock(root, lock) {
|
|
41
|
+
fs.writeFileSync(path.join(root, LOCK_FILE), `${JSON.stringify(lock, null, 2)}\n`);
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/registry/hash.ts
|
|
45
|
+
const TEXT_FILE = /\.(?:astro|ts|mts|js|mjs|json|css|md|svg|html)$/;
|
|
46
|
+
/**
|
|
47
|
+
* The hash of a file's content, as hex. Text files hash with `\r\n` read as `\n`, so a Windows checkout with
|
|
48
|
+
* autocrlf and a Unix one agree.
|
|
49
|
+
*/
|
|
50
|
+
function hashContent(file, content) {
|
|
51
|
+
const hash = createHash("sha256");
|
|
52
|
+
if (TEXT_FILE.test(file)) {
|
|
53
|
+
const text = typeof content === "string" ? content : Buffer.from(content).toString("utf8");
|
|
54
|
+
hash.update(text.replace(/\r\n/g, "\n"));
|
|
55
|
+
} else hash.update(typeof content === "string" ? content : Buffer.from(content));
|
|
56
|
+
return hash.digest("hex");
|
|
57
|
+
}
|
|
58
|
+
//#endregion
|
|
59
|
+
export { writeLock as i, readLock as n, recordFiles as r, hashContent as t };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { c as ContentReadError, i as enumFields, l as ContentValidationError, n as defineThemePreview, o as schemaProps, s as ContentError, u as formatContentIssues } from "./preview
|
|
2
|
-
import { n as defineTheme, t as defaultTheme } from "./theme-
|
|
3
|
-
import { A as textSchema, C as MAX_NAV_DEPTH, D as linkSchema, E as imageSchema, F as DEFAULT_IMAGE_POSITION, G as tones, H as motionOption, I as IMAGE_FITS, K as variantOption, L as IMAGE_POSITIONS, M as trackingIdSchema, N as withEmphasis, O as richTextSchema, P as DEFAULT_IMAGE_FIT, R as isImageFit, S as upsertJsonLd, T as htmlIdSchema, U as themeModes, V as buttonStyles, W as toneOption, _ as jsonLdSchema, a as seoSchema, b as parseJsonLdInput, c as anchorSchema, d as sectionIdSchema, f as walkLinkIds, g as isPlaceholderSiteUrl, h as hasJsonLdId, i as isSystemPage, j as toneSchema, k as textMarkSchema, l as createSectionSchema, m as generateSiteJsonLd, n as createPageSchema, p as formatJsonLd, s as withoutOrphanSections, t as SYSTEM_PAGES, v as jsonLdWarnings, w as addMarkIssues, x as siteJsonLdIds, y as mergeJsonLd, z as isImagePosition } from "./page-
|
|
4
|
-
import {
|
|
1
|
+
import { c as ContentReadError, i as enumFields, l as ContentValidationError, n as defineThemePreview, o as schemaProps, s as ContentError, u as formatContentIssues } from "./preview-B_88I5Jm.js";
|
|
2
|
+
import { n as defineTheme, t as defaultTheme } from "./theme-Dv7_7B56.js";
|
|
3
|
+
import { A as textSchema, C as MAX_NAV_DEPTH, D as linkSchema, E as imageSchema, F as DEFAULT_IMAGE_POSITION, G as tones, H as motionOption, I as IMAGE_FITS, K as variantOption, L as IMAGE_POSITIONS, M as trackingIdSchema, N as withEmphasis, O as richTextSchema, P as DEFAULT_IMAGE_FIT, R as isImageFit, S as upsertJsonLd, T as htmlIdSchema, U as themeModes, V as buttonStyles, W as toneOption, _ as jsonLdSchema, a as seoSchema, b as parseJsonLdInput, c as anchorSchema, d as sectionIdSchema, f as walkLinkIds, g as isPlaceholderSiteUrl, h as hasJsonLdId, i as isSystemPage, j as toneSchema, k as textMarkSchema, l as createSectionSchema, m as generateSiteJsonLd, n as createPageSchema, p as formatJsonLd, s as withoutOrphanSections, t as SYSTEM_PAGES, v as jsonLdWarnings, w as addMarkIssues, x as siteJsonLdIds, y as mergeJsonLd, z as isImagePosition } from "./page-X-WnOu7-.js";
|
|
4
|
+
import { d as reconcileMarks, f as renderMarkedHtml, i as fontMarks, l as marksFromEmphasis, m as weightMarks, p as splitMarkedText, s as markClass, t as applyTextMark } from "./marks-DPBilumg.js";
|
|
5
5
|
import { n as createMigrator, r as API_PREFIX, t as SCHEMA_VERSION_KEY } from "./migrate-b408EaLp.js";
|
|
6
6
|
import { n as TURNSTILE_FIELD, t as HONEYPOT_FIELD } from "./form-contract-CIDTNab-.js";
|
|
7
7
|
import { _ as consentCopy, a as contrastRatio, b as parseMediaSource, c as hasThemeColors, d as tokenToHex, f as CONSENT_COPY, g as CONSENT_REOPEN, h as CONSENT_LIMITS, i as contrastChecks, l as hexToToken, m as CONSENT_HREF_MESSAGE, n as HEX_COLOR, o as derivePalette, p as CONSENT_HREF, s as hasOverrides, u as themeCss, v as consentTextIssues, y as VIDEO_FILE } from "./theme-colors-CHROGZkI.js";
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
//#region src/marks.ts
|
|
2
|
+
/**
|
|
3
|
+
* Inline marks for headings and the site wordmark.
|
|
4
|
+
* A heading stays a plain string. Marks name ranges inside it.
|
|
5
|
+
* No HTML and no arbitrary CSS: each mark is a weight, italic, and/or a font token.
|
|
6
|
+
*/
|
|
7
|
+
const fontMarks = [
|
|
8
|
+
"sans",
|
|
9
|
+
"serif",
|
|
10
|
+
"mono"
|
|
11
|
+
];
|
|
12
|
+
const weightMarks = [
|
|
13
|
+
"regular",
|
|
14
|
+
"medium",
|
|
15
|
+
"semibold",
|
|
16
|
+
"bold"
|
|
17
|
+
];
|
|
18
|
+
const fonts = new Set(fontMarks);
|
|
19
|
+
const weights = new Set(weightMarks);
|
|
20
|
+
function isFontMark(value) {
|
|
21
|
+
return typeof value === "string" && fonts.has(value);
|
|
22
|
+
}
|
|
23
|
+
function isWeightMark(value) {
|
|
24
|
+
return typeof value === "string" && weights.has(value);
|
|
25
|
+
}
|
|
26
|
+
/** The legacy `em` / `nameEm` accent: Instrument Serif italic on that substring. */
|
|
27
|
+
function marksFromEmphasis(text, em) {
|
|
28
|
+
if (!em) return void 0;
|
|
29
|
+
const start = text.indexOf(em);
|
|
30
|
+
if (start < 0) return void 0;
|
|
31
|
+
return [{
|
|
32
|
+
start,
|
|
33
|
+
end: start + em.length,
|
|
34
|
+
italic: true,
|
|
35
|
+
font: "serif"
|
|
36
|
+
}];
|
|
37
|
+
}
|
|
38
|
+
function markHasStyle(mark) {
|
|
39
|
+
return mark.weight !== void 0 || mark.italic === true || mark.font !== void 0;
|
|
40
|
+
}
|
|
41
|
+
/** Drop marks that fall outside the text or carry no style. */
|
|
42
|
+
function clampMarks(text, marks) {
|
|
43
|
+
if (!marks || marks.length === 0) return [];
|
|
44
|
+
return marks.map((mark) => ({
|
|
45
|
+
...mark,
|
|
46
|
+
start: Math.max(0, Math.trunc(mark.start)),
|
|
47
|
+
end: Math.min(text.length, Math.trunc(mark.end))
|
|
48
|
+
})).filter((mark) => mark.end > mark.start && markHasStyle(mark)).sort((a, b) => a.start - b.start || a.end - b.end);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Shift marks across a plain-text edit.
|
|
52
|
+
* A mark that still names a unique substring is kept when the edit overlaps it.
|
|
53
|
+
*/
|
|
54
|
+
function reconcileMarks(previous, next, marks) {
|
|
55
|
+
const source = clampMarks(previous, marks);
|
|
56
|
+
if (source.length === 0) return [];
|
|
57
|
+
if (previous === next) return source;
|
|
58
|
+
let prefix = 0;
|
|
59
|
+
const limit = Math.min(previous.length, next.length);
|
|
60
|
+
while (prefix < limit && previous[prefix] === next[prefix]) prefix += 1;
|
|
61
|
+
let suffix = 0;
|
|
62
|
+
while (suffix < previous.length - prefix && suffix < next.length - prefix && previous[previous.length - 1 - suffix] === next[next.length - 1 - suffix]) suffix += 1;
|
|
63
|
+
const delta = next.length - previous.length;
|
|
64
|
+
const changeEnd = previous.length - suffix;
|
|
65
|
+
const clamped = clampMarks(next, source.flatMap((mark) => {
|
|
66
|
+
if (mark.end <= prefix) return [mark];
|
|
67
|
+
if (mark.start >= changeEnd) return [{
|
|
68
|
+
...mark,
|
|
69
|
+
start: mark.start + delta,
|
|
70
|
+
end: mark.end + delta
|
|
71
|
+
}];
|
|
72
|
+
return [];
|
|
73
|
+
}));
|
|
74
|
+
if (clamped.length > 0 || source.length !== 1) return clamped;
|
|
75
|
+
const only = source[0];
|
|
76
|
+
if (!only) return clamped;
|
|
77
|
+
const slice = previous.slice(only.start, only.end);
|
|
78
|
+
if (slice.length === 0) return clamped;
|
|
79
|
+
const at = next.indexOf(slice);
|
|
80
|
+
if (at < 0 || next.indexOf(slice, at + 1) !== -1) return clamped;
|
|
81
|
+
return [{
|
|
82
|
+
...only,
|
|
83
|
+
start: at,
|
|
84
|
+
end: at + slice.length
|
|
85
|
+
}];
|
|
86
|
+
}
|
|
87
|
+
/** Apply one style to [start, end), keeping styles on either side of the range. */
|
|
88
|
+
function applyTextMark(text, marks, start, end, patch) {
|
|
89
|
+
const from = Math.max(0, Math.trunc(start));
|
|
90
|
+
const to = Math.min(text.length, Math.trunc(end));
|
|
91
|
+
const current = clampMarks(text, marks);
|
|
92
|
+
if (to <= from) return current;
|
|
93
|
+
const pieces = [];
|
|
94
|
+
let covering;
|
|
95
|
+
for (const mark of current) {
|
|
96
|
+
if (mark.end <= from || mark.start >= to) {
|
|
97
|
+
pieces.push(mark);
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
covering ??= mark;
|
|
101
|
+
if (mark.start < from) pieces.push({
|
|
102
|
+
...mark,
|
|
103
|
+
end: from
|
|
104
|
+
});
|
|
105
|
+
if (mark.end > to) pieces.push({
|
|
106
|
+
...mark,
|
|
107
|
+
start: to
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
const next = {
|
|
111
|
+
start: from,
|
|
112
|
+
end: to,
|
|
113
|
+
weight: "weight" in patch ? patch.weight : covering?.weight,
|
|
114
|
+
italic: "italic" in patch ? patch.italic : covering?.italic,
|
|
115
|
+
font: "font" in patch ? patch.font : covering?.font
|
|
116
|
+
};
|
|
117
|
+
if (next.italic !== true) delete next.italic;
|
|
118
|
+
if (next.weight === void 0) delete next.weight;
|
|
119
|
+
if (next.font === void 0) delete next.font;
|
|
120
|
+
if (markHasStyle(next)) pieces.push(next);
|
|
121
|
+
return clampMarks(text, pieces);
|
|
122
|
+
}
|
|
123
|
+
function splitMarkedText(text, marks) {
|
|
124
|
+
const sorted = clampMarks(text, marks);
|
|
125
|
+
const runs = [];
|
|
126
|
+
let cursor = 0;
|
|
127
|
+
for (const mark of sorted) {
|
|
128
|
+
if (mark.start < cursor) continue;
|
|
129
|
+
if (mark.start > cursor) runs.push({ text: text.slice(cursor, mark.start) });
|
|
130
|
+
runs.push({
|
|
131
|
+
text: text.slice(mark.start, mark.end),
|
|
132
|
+
weight: mark.weight,
|
|
133
|
+
italic: mark.italic,
|
|
134
|
+
font: mark.font
|
|
135
|
+
});
|
|
136
|
+
cursor = mark.end;
|
|
137
|
+
}
|
|
138
|
+
if (cursor < text.length) runs.push({ text: text.slice(cursor) });
|
|
139
|
+
return runs.filter((run) => run.text.length > 0);
|
|
140
|
+
}
|
|
141
|
+
/** Classes from the typography tokens: font-sans/serif/mono and the weight scale. */
|
|
142
|
+
function markClass(run) {
|
|
143
|
+
const classes = [];
|
|
144
|
+
if (run.font === "sans") classes.push("font-sans");
|
|
145
|
+
else if (run.font === "mono") classes.push("font-mono");
|
|
146
|
+
else if (run.font === "serif" || run.italic) classes.push("font-serif");
|
|
147
|
+
if (run.italic && (run.font === void 0 || run.font === "serif")) classes.push("bm-em");
|
|
148
|
+
else if (run.italic) classes.push("italic");
|
|
149
|
+
if (run.weight === "regular") classes.push("font-normal");
|
|
150
|
+
else if (run.weight === "medium") classes.push("font-medium");
|
|
151
|
+
else if (run.weight === "semibold") classes.push("font-semibold");
|
|
152
|
+
else if (run.weight === "bold") classes.push("font-bold");
|
|
153
|
+
return classes.join(" ");
|
|
154
|
+
}
|
|
155
|
+
function escapeHtml(value) {
|
|
156
|
+
return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll("\"", """);
|
|
157
|
+
}
|
|
158
|
+
function renderMarkedHtml(text, marks) {
|
|
159
|
+
return splitMarkedText(text, marks).map((run) => {
|
|
160
|
+
const cls = markClass(run);
|
|
161
|
+
return cls ? `<span class="${cls}">${escapeHtml(run.text)}</span>` : escapeHtml(run.text);
|
|
162
|
+
}).join("");
|
|
163
|
+
}
|
|
164
|
+
function marksOverlap(marks) {
|
|
165
|
+
const sorted = [...marks].sort((a, b) => a.start - b.start || a.end - b.end);
|
|
166
|
+
for (let index = 1; index < sorted.length; index += 1) {
|
|
167
|
+
const previous = sorted[index - 1];
|
|
168
|
+
const mark = sorted[index];
|
|
169
|
+
if (previous && mark && mark.start < previous.end) return true;
|
|
170
|
+
}
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
//#endregion
|
|
174
|
+
export { isFontMark as a, markHasStyle as c, reconcileMarks as d, renderMarkedHtml as f, fontMarks as i, marksFromEmphasis as l, weightMarks as m, clampMarks as n, isWeightMark as o, splitMarkedText as p, escapeHtml as r, markClass as s, applyTextMark as t, marksOverlap as u };
|
package/dist/marks.js
CHANGED
|
@@ -1,174 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Inline marks for headings and the site wordmark.
|
|
4
|
-
* A heading stays a plain string. Marks name ranges inside it.
|
|
5
|
-
* No HTML and no arbitrary CSS: each mark is a weight, italic, and/or a font token.
|
|
6
|
-
*/
|
|
7
|
-
const fontMarks = [
|
|
8
|
-
"sans",
|
|
9
|
-
"serif",
|
|
10
|
-
"mono"
|
|
11
|
-
];
|
|
12
|
-
const weightMarks = [
|
|
13
|
-
"regular",
|
|
14
|
-
"medium",
|
|
15
|
-
"semibold",
|
|
16
|
-
"bold"
|
|
17
|
-
];
|
|
18
|
-
const fonts = new Set(fontMarks);
|
|
19
|
-
const weights = new Set(weightMarks);
|
|
20
|
-
function isFontMark(value) {
|
|
21
|
-
return typeof value === "string" && fonts.has(value);
|
|
22
|
-
}
|
|
23
|
-
function isWeightMark(value) {
|
|
24
|
-
return typeof value === "string" && weights.has(value);
|
|
25
|
-
}
|
|
26
|
-
/** The legacy `em` / `nameEm` accent: Instrument Serif italic on that substring. */
|
|
27
|
-
function marksFromEmphasis(text, em) {
|
|
28
|
-
if (!em) return void 0;
|
|
29
|
-
const start = text.indexOf(em);
|
|
30
|
-
if (start < 0) return void 0;
|
|
31
|
-
return [{
|
|
32
|
-
start,
|
|
33
|
-
end: start + em.length,
|
|
34
|
-
italic: true,
|
|
35
|
-
font: "serif"
|
|
36
|
-
}];
|
|
37
|
-
}
|
|
38
|
-
function markHasStyle(mark) {
|
|
39
|
-
return mark.weight !== void 0 || mark.italic === true || mark.font !== void 0;
|
|
40
|
-
}
|
|
41
|
-
/** Drop marks that fall outside the text or carry no style. */
|
|
42
|
-
function clampMarks(text, marks) {
|
|
43
|
-
if (!marks || marks.length === 0) return [];
|
|
44
|
-
return marks.map((mark) => ({
|
|
45
|
-
...mark,
|
|
46
|
-
start: Math.max(0, Math.trunc(mark.start)),
|
|
47
|
-
end: Math.min(text.length, Math.trunc(mark.end))
|
|
48
|
-
})).filter((mark) => mark.end > mark.start && markHasStyle(mark)).sort((a, b) => a.start - b.start || a.end - b.end);
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Shift marks across a plain-text edit.
|
|
52
|
-
* A mark that still names a unique substring is kept when the edit overlaps it.
|
|
53
|
-
*/
|
|
54
|
-
function reconcileMarks(previous, next, marks) {
|
|
55
|
-
const source = clampMarks(previous, marks);
|
|
56
|
-
if (source.length === 0) return [];
|
|
57
|
-
if (previous === next) return source;
|
|
58
|
-
let prefix = 0;
|
|
59
|
-
const limit = Math.min(previous.length, next.length);
|
|
60
|
-
while (prefix < limit && previous[prefix] === next[prefix]) prefix += 1;
|
|
61
|
-
let suffix = 0;
|
|
62
|
-
while (suffix < previous.length - prefix && suffix < next.length - prefix && previous[previous.length - 1 - suffix] === next[next.length - 1 - suffix]) suffix += 1;
|
|
63
|
-
const delta = next.length - previous.length;
|
|
64
|
-
const changeEnd = previous.length - suffix;
|
|
65
|
-
const clamped = clampMarks(next, source.flatMap((mark) => {
|
|
66
|
-
if (mark.end <= prefix) return [mark];
|
|
67
|
-
if (mark.start >= changeEnd) return [{
|
|
68
|
-
...mark,
|
|
69
|
-
start: mark.start + delta,
|
|
70
|
-
end: mark.end + delta
|
|
71
|
-
}];
|
|
72
|
-
return [];
|
|
73
|
-
}));
|
|
74
|
-
if (clamped.length > 0 || source.length !== 1) return clamped;
|
|
75
|
-
const only = source[0];
|
|
76
|
-
if (!only) return clamped;
|
|
77
|
-
const slice = previous.slice(only.start, only.end);
|
|
78
|
-
if (slice.length === 0) return clamped;
|
|
79
|
-
const at = next.indexOf(slice);
|
|
80
|
-
if (at < 0 || next.indexOf(slice, at + 1) !== -1) return clamped;
|
|
81
|
-
return [{
|
|
82
|
-
...only,
|
|
83
|
-
start: at,
|
|
84
|
-
end: at + slice.length
|
|
85
|
-
}];
|
|
86
|
-
}
|
|
87
|
-
/** Apply one style to [start, end), keeping styles on either side of the range. */
|
|
88
|
-
function applyTextMark(text, marks, start, end, patch) {
|
|
89
|
-
const from = Math.max(0, Math.trunc(start));
|
|
90
|
-
const to = Math.min(text.length, Math.trunc(end));
|
|
91
|
-
const current = clampMarks(text, marks);
|
|
92
|
-
if (to <= from) return current;
|
|
93
|
-
const pieces = [];
|
|
94
|
-
let covering;
|
|
95
|
-
for (const mark of current) {
|
|
96
|
-
if (mark.end <= from || mark.start >= to) {
|
|
97
|
-
pieces.push(mark);
|
|
98
|
-
continue;
|
|
99
|
-
}
|
|
100
|
-
covering ??= mark;
|
|
101
|
-
if (mark.start < from) pieces.push({
|
|
102
|
-
...mark,
|
|
103
|
-
end: from
|
|
104
|
-
});
|
|
105
|
-
if (mark.end > to) pieces.push({
|
|
106
|
-
...mark,
|
|
107
|
-
start: to
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
const next = {
|
|
111
|
-
start: from,
|
|
112
|
-
end: to,
|
|
113
|
-
weight: "weight" in patch ? patch.weight : covering?.weight,
|
|
114
|
-
italic: "italic" in patch ? patch.italic : covering?.italic,
|
|
115
|
-
font: "font" in patch ? patch.font : covering?.font
|
|
116
|
-
};
|
|
117
|
-
if (next.italic !== true) delete next.italic;
|
|
118
|
-
if (next.weight === void 0) delete next.weight;
|
|
119
|
-
if (next.font === void 0) delete next.font;
|
|
120
|
-
if (markHasStyle(next)) pieces.push(next);
|
|
121
|
-
return clampMarks(text, pieces);
|
|
122
|
-
}
|
|
123
|
-
function splitMarkedText(text, marks) {
|
|
124
|
-
const sorted = clampMarks(text, marks);
|
|
125
|
-
const runs = [];
|
|
126
|
-
let cursor = 0;
|
|
127
|
-
for (const mark of sorted) {
|
|
128
|
-
if (mark.start < cursor) continue;
|
|
129
|
-
if (mark.start > cursor) runs.push({ text: text.slice(cursor, mark.start) });
|
|
130
|
-
runs.push({
|
|
131
|
-
text: text.slice(mark.start, mark.end),
|
|
132
|
-
weight: mark.weight,
|
|
133
|
-
italic: mark.italic,
|
|
134
|
-
font: mark.font
|
|
135
|
-
});
|
|
136
|
-
cursor = mark.end;
|
|
137
|
-
}
|
|
138
|
-
if (cursor < text.length) runs.push({ text: text.slice(cursor) });
|
|
139
|
-
return runs.filter((run) => run.text.length > 0);
|
|
140
|
-
}
|
|
141
|
-
/** Classes from the typography tokens: font-sans/serif/mono and the weight scale. */
|
|
142
|
-
function markClass(run) {
|
|
143
|
-
const classes = [];
|
|
144
|
-
if (run.font === "sans") classes.push("font-sans");
|
|
145
|
-
else if (run.font === "mono") classes.push("font-mono");
|
|
146
|
-
else if (run.font === "serif" || run.italic) classes.push("font-serif");
|
|
147
|
-
if (run.italic && (run.font === void 0 || run.font === "serif")) classes.push("bm-em");
|
|
148
|
-
else if (run.italic) classes.push("italic");
|
|
149
|
-
if (run.weight === "regular") classes.push("font-normal");
|
|
150
|
-
else if (run.weight === "medium") classes.push("font-medium");
|
|
151
|
-
else if (run.weight === "semibold") classes.push("font-semibold");
|
|
152
|
-
else if (run.weight === "bold") classes.push("font-bold");
|
|
153
|
-
return classes.join(" ");
|
|
154
|
-
}
|
|
155
|
-
function escapeHtml(value) {
|
|
156
|
-
return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll("\"", """);
|
|
157
|
-
}
|
|
158
|
-
function renderMarkedHtml(text, marks) {
|
|
159
|
-
return splitMarkedText(text, marks).map((run) => {
|
|
160
|
-
const cls = markClass(run);
|
|
161
|
-
return cls ? `<span class="${cls}">${escapeHtml(run.text)}</span>` : escapeHtml(run.text);
|
|
162
|
-
}).join("");
|
|
163
|
-
}
|
|
164
|
-
function marksOverlap(marks) {
|
|
165
|
-
const sorted = [...marks].sort((a, b) => a.start - b.start || a.end - b.end);
|
|
166
|
-
for (let index = 1; index < sorted.length; index += 1) {
|
|
167
|
-
const previous = sorted[index - 1];
|
|
168
|
-
const mark = sorted[index];
|
|
169
|
-
if (previous && mark && mark.start < previous.end) return true;
|
|
170
|
-
}
|
|
171
|
-
return false;
|
|
172
|
-
}
|
|
173
|
-
//#endregion
|
|
174
|
-
export { applyTextMark, clampMarks, escapeHtml, fontMarks, isFontMark, isWeightMark, markClass, markHasStyle, marksFromEmphasis, marksOverlap, reconcileMarks, renderMarkedHtml, splitMarkedText, weightMarks };
|
|
1
|
+
export { t as applyTextMark, n as clampMarks, r as escapeHtml, i as fontMarks, a as isFontMark, o as isWeightMark, s as markClass, c as markHasStyle, l as marksFromEmphasis, u as marksOverlap, d as reconcileMarks, f as renderMarkedHtml, p as splitMarkedText, m as weightMarks } from "./marks-DPBilumg.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as markHasStyle, i as fontMarks, l as marksFromEmphasis, m as weightMarks, u as marksOverlap } from "./marks-DPBilumg.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
//#region src/section-options.ts
|
|
4
4
|
/**
|