@immediately-run/sdk 0.94.0 → 0.96.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.
Files changed (55) hide show
  1. package/dist/components/FileRouter.cjs +4 -1
  2. package/dist/components/FileRouter.cjs.map +1 -1
  3. package/dist/components/FileRouter.js +4 -1
  4. package/dist/components/FileRouter.js.map +1 -1
  5. package/dist/components/HeadingAnchor.cjs.map +1 -1
  6. package/dist/components/HeadingAnchor.d.cts +4 -3
  7. package/dist/components/HeadingAnchor.d.ts +4 -3
  8. package/dist/components/HeadingAnchor.js.map +1 -1
  9. package/dist/components/Prose.cjs +72 -0
  10. package/dist/components/Prose.cjs.map +1 -0
  11. package/dist/components/Prose.d.cts +23 -0
  12. package/dist/components/Prose.d.ts +23 -0
  13. package/dist/components/Prose.js +49 -0
  14. package/dist/components/Prose.js.map +1 -0
  15. package/dist/index.cjs +6 -0
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.d.cts +2 -0
  18. package/dist/index.d.ts +2 -0
  19. package/dist/index.js +4 -0
  20. package/dist/index.js.map +1 -1
  21. package/dist/loading.cjs +2 -6
  22. package/dist/loading.cjs.map +1 -1
  23. package/dist/loading.js +2 -6
  24. package/dist/loading.js.map +1 -1
  25. package/dist/proseStyles.cjs +181 -0
  26. package/dist/proseStyles.cjs.map +1 -0
  27. package/dist/proseStyles.d.cts +36 -0
  28. package/dist/proseStyles.d.ts +36 -0
  29. package/dist/proseStyles.js +153 -0
  30. package/dist/proseStyles.js.map +1 -0
  31. package/dist/proseTokens.cjs +235 -0
  32. package/dist/proseTokens.cjs.map +1 -0
  33. package/dist/proseTokens.d.cts +80 -0
  34. package/dist/proseTokens.d.ts +80 -0
  35. package/dist/proseTokens.js +204 -0
  36. package/dist/proseTokens.js.map +1 -0
  37. package/dist/proseTokensHook.cjs +116 -0
  38. package/dist/proseTokensHook.cjs.map +1 -0
  39. package/dist/proseTokensHook.d.cts +10 -0
  40. package/dist/proseTokensHook.d.ts +10 -0
  41. package/dist/proseTokensHook.js +99 -0
  42. package/dist/proseTokensHook.js.map +1 -0
  43. package/dist/styleElement.cjs +37 -0
  44. package/dist/styleElement.cjs.map +1 -0
  45. package/dist/styleElement.d.cts +13 -0
  46. package/dist/styleElement.d.ts +13 -0
  47. package/dist/styleElement.js +14 -0
  48. package/dist/styleElement.js.map +1 -0
  49. package/dist/version.cjs +1 -1
  50. package/dist/version.cjs.map +1 -1
  51. package/dist/version.d.cts +1 -1
  52. package/dist/version.d.ts +1 -1
  53. package/dist/version.js +1 -1
  54. package/dist/version.js.map +1 -1
  55. package/package.json +1 -1
@@ -0,0 +1,235 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var proseTokens_exports = {};
20
+ __export(proseTokens_exports, {
21
+ PROSE_MARKER_FILE: () => PROSE_MARKER_FILE,
22
+ PROSE_TOKEN_FILE: () => PROSE_TOKEN_FILE,
23
+ PROSE_TOKEN_FILE_MAX_BYTES: () => PROSE_TOKEN_FILE_MAX_BYTES,
24
+ PROSE_TOKEN_VALUE_MAX_LENGTH: () => PROSE_TOKEN_VALUE_MAX_LENGTH,
25
+ affectsTokenLookup: () => affectsTokenLookup,
26
+ dirOfFile: () => dirOfFile,
27
+ parseProseTokenFile: () => parseProseTokenFile,
28
+ resolveTokenFile: () => resolveTokenFile,
29
+ tokensFor: () => tokensFor
30
+ });
31
+ module.exports = __toCommonJS(proseTokens_exports);
32
+ var import_proseStyles = require("./proseStyles");
33
+ const PROSE_TOKEN_FILE = "immediately.run.css";
34
+ const PROSE_MARKER_FILE = "immediately.run.json";
35
+ const PROSE_TOKEN_FILE_MAX_BYTES = 16384;
36
+ const PROSE_TOKEN_VALUE_MAX_LENGTH = 256;
37
+ const ALLOWED = new Set(import_proseStyles.PROSE_TOKENS.map((token) => `--${token.name}`));
38
+ const REFUSED_VALUE_FRAGMENTS = [
39
+ "url(",
40
+ "image(",
41
+ "image-set(",
42
+ "cross-fade(",
43
+ "element(",
44
+ "src(",
45
+ "@",
46
+ "\\",
47
+ ";",
48
+ "{",
49
+ "}",
50
+ "<",
51
+ ">"
52
+ ];
53
+ const SELECTORS = {
54
+ ":root": "root",
55
+ ':root[data-theme="light"]': "light",
56
+ ':root[data-theme="dark"]': "dark"
57
+ };
58
+ const blockFor = (selector) => SELECTORS[selector.replace(/\s+/g, "").replace(/'/g, '"')] ?? null;
59
+ const refusedFragment = (value) => {
60
+ const lower = value.toLowerCase();
61
+ return REFUSED_VALUE_FRAGMENTS.find((fragment) => lower.includes(fragment));
62
+ };
63
+ const byteLength = (text) => new TextEncoder().encode(text).length;
64
+ const splitBlocks = (text) => {
65
+ const blocks = [];
66
+ let buffer = "";
67
+ let current = null;
68
+ let i = 0;
69
+ while (i < text.length) {
70
+ const ch = text[i];
71
+ if (ch === "/" && text[i + 1] === "*") {
72
+ const end = text.indexOf("*/", i + 2);
73
+ if (end < 0) return "an unterminated comment";
74
+ i = end + 2;
75
+ buffer += " ";
76
+ continue;
77
+ }
78
+ if (ch === '"' || ch === "'") {
79
+ let j = i + 1;
80
+ while (j < text.length && text[j] !== ch) {
81
+ if (text[j] === "\\") j += 1;
82
+ if (text[j] === "\n") return "an unterminated string";
83
+ j += 1;
84
+ }
85
+ if (j >= text.length) return "an unterminated string";
86
+ buffer += text.slice(i, j + 1);
87
+ i = j + 1;
88
+ continue;
89
+ }
90
+ if (ch === "{") {
91
+ if (current) return "a nested block";
92
+ current = { selector: buffer.trim(), declarations: [] };
93
+ buffer = "";
94
+ } else if (ch === "}") {
95
+ if (!current) return 'an unmatched "}"';
96
+ if (buffer.trim()) current.declarations.push(buffer.trim());
97
+ blocks.push(current);
98
+ current = null;
99
+ buffer = "";
100
+ } else if (ch === ";" && current) {
101
+ if (buffer.trim()) current.declarations.push(buffer.trim());
102
+ buffer = "";
103
+ } else {
104
+ buffer += ch;
105
+ }
106
+ i += 1;
107
+ }
108
+ if (current) return "an unclosed block";
109
+ if (buffer.trim()) return `"${buffer.trim().slice(0, 40)}" outside a block`;
110
+ return blocks;
111
+ };
112
+ function parseProseTokenFile(text) {
113
+ if (byteLength(text) > PROSE_TOKEN_FILE_MAX_BYTES) {
114
+ return { ok: false, reason: `it is larger than ${PROSE_TOKEN_FILE_MAX_BYTES} bytes` };
115
+ }
116
+ const split = splitBlocks(text);
117
+ if (typeof split === "string") return { ok: false, reason: `it contains ${split}` };
118
+ const blocks = { root: {}, light: {}, dark: {} };
119
+ const warnings = [];
120
+ for (const { selector, declarations } of split) {
121
+ const block = blockFor(selector);
122
+ if (!block) {
123
+ return {
124
+ ok: false,
125
+ reason: `"${selector.slice(0, 60)}" is not one of :root, :root[data-theme="light"], :root[data-theme="dark"]`
126
+ };
127
+ }
128
+ for (const declaration of declarations) {
129
+ const match = /^(--[A-Za-z0-9_-]+)\s*:([\s\S]*)$/.exec(declaration);
130
+ if (!match) {
131
+ return { ok: false, reason: `"${declaration.slice(0, 60)}" is not a custom property declaration` };
132
+ }
133
+ const name = match[1];
134
+ const value = match[2].trim();
135
+ if (!ALLOWED.has(name)) {
136
+ warnings.push(`${name} is not a prose token; ignored`);
137
+ continue;
138
+ }
139
+ if (!value) {
140
+ warnings.push(`${name} has an empty value; ignored`);
141
+ continue;
142
+ }
143
+ if (value.length > PROSE_TOKEN_VALUE_MAX_LENGTH) {
144
+ warnings.push(`${name} is longer than ${PROSE_TOKEN_VALUE_MAX_LENGTH} characters; ignored`);
145
+ continue;
146
+ }
147
+ const fragment = refusedFragment(value);
148
+ if (fragment) {
149
+ warnings.push(`${name} contains "${fragment}"; ignored`);
150
+ continue;
151
+ }
152
+ blocks[block][name] = value;
153
+ }
154
+ }
155
+ return { ok: true, blocks, warnings };
156
+ }
157
+ function tokensFor(blocks, polarity) {
158
+ return Object.entries({ ...blocks.root, ...blocks[polarity] });
159
+ }
160
+ const join = (dir, name) => dir ? `${dir}/${name}` : name;
161
+ const parentOf = (dir) => dir === "" ? null : dir.includes("/") ? dir.slice(0, dir.lastIndexOf("/")) : "";
162
+ const dirOfFile = (file) => {
163
+ const clean = file.replace(/^\/+/, "");
164
+ return clean.includes("/") ? clean.slice(0, clean.lastIndexOf("/")) : "";
165
+ };
166
+ const resolveStyles = (dir, styles) => {
167
+ if (styles.startsWith("/")) return { reason: `"styles": "${styles}" is absolute` };
168
+ if (/^[A-Za-z][A-Za-z0-9+.-]*:/.test(styles)) return { reason: `"styles": "${styles}" names a URL` };
169
+ const parts = [];
170
+ for (const segment of styles.split("/")) {
171
+ if (segment === "" || segment === ".") continue;
172
+ if (segment === "..") return { reason: `"styles": "${styles}" leaves the directory of its marker` };
173
+ parts.push(segment);
174
+ }
175
+ if (!parts.length) return { reason: `"styles": "${styles}" names no file` };
176
+ return { path: join(dir, parts.join("/")) };
177
+ };
178
+ async function resolveTokenFile(startDir, probe) {
179
+ const warnings = [];
180
+ for (let dir = startDir.replace(/^\/+|\/+$/g, ""); dir !== null; dir = parentOf(dir)) {
181
+ const markerPath = join(dir, PROSE_MARKER_FILE);
182
+ const defaultPath = join(dir, PROSE_TOKEN_FILE);
183
+ const [markerText, defaultSize] = await Promise.all([probe.read(markerPath), probe.size(defaultPath)]);
184
+ if (markerText === null && defaultSize === null) continue;
185
+ let styles;
186
+ if (markerText !== null) {
187
+ try {
188
+ const marker = JSON.parse(markerText);
189
+ styles = marker && typeof marker === "object" ? marker.styles : void 0;
190
+ } catch {
191
+ warnings.push(`${markerPath} is not valid JSON; its "styles" field is ignored`);
192
+ }
193
+ if (styles !== void 0 && styles !== false && typeof styles !== "string") {
194
+ warnings.push(`${markerPath}: "styles" must be a file name or false; ignored`);
195
+ styles = void 0;
196
+ }
197
+ }
198
+ if (styles === false) return { path: null, size: null, watch: null, dir, warnings };
199
+ if (typeof styles === "string") {
200
+ const resolved = resolveStyles(dir, styles);
201
+ if ("reason" in resolved) {
202
+ warnings.push(`${markerPath}: ${resolved.reason}; author tokens are off`);
203
+ return { path: null, size: null, watch: null, dir, warnings };
204
+ }
205
+ const size = await probe.size(resolved.path);
206
+ if (size === null) warnings.push(`${markerPath}: "styles" names ${resolved.path}, which does not exist`);
207
+ return { path: size === null ? null : resolved.path, size, watch: resolved.path, dir, warnings };
208
+ }
209
+ const path = defaultSize === null ? null : defaultPath;
210
+ return { path, size: defaultSize, watch: path, dir, warnings };
211
+ }
212
+ return { path: null, size: null, watch: null, dir: "", warnings };
213
+ }
214
+ function affectsTokenLookup(changed, startDir, watched) {
215
+ const path = changed.replace(/^\/+/, "");
216
+ if (watched !== null && path === watched) return true;
217
+ const name = path.slice(path.lastIndexOf("/") + 1);
218
+ if (name !== PROSE_MARKER_FILE && name !== PROSE_TOKEN_FILE) return false;
219
+ const dir = dirOfFile(path);
220
+ const start = startDir.replace(/^\/+|\/+$/g, "");
221
+ return dir === "" || start === dir || start.startsWith(`${dir}/`);
222
+ }
223
+ // Annotate the CommonJS export names for ESM import in node:
224
+ 0 && (module.exports = {
225
+ PROSE_MARKER_FILE,
226
+ PROSE_TOKEN_FILE,
227
+ PROSE_TOKEN_FILE_MAX_BYTES,
228
+ PROSE_TOKEN_VALUE_MAX_LENGTH,
229
+ affectsTokenLookup,
230
+ dirOfFile,
231
+ parseProseTokenFile,
232
+ resolveTokenFile,
233
+ tokensFor
234
+ });
235
+ //# sourceMappingURL=proseTokens.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/proseTokens.ts"],"sourcesContent":["// The author token file for rendered Markdown (MARKDOWN_SYNTAX_SPEC §16.6).\n//\n// A repo or bundle restyles its Markdown with a token-only stylesheet. It is never\n// injected as CSS: it is parsed here into an allow-listed map of public token values,\n// and `Prose` applies each one with `style.setProperty` on its own element. A value\n// passed to `setProperty` cannot leave its declaration, and with no author selector\n// there is no attribute-selector oracle over other writers' files (Grove plans 05 §2.2).\n//\n// Pure logic only — the file I/O and the change subscription are `proseTokensHook.ts`.\n\nimport { PROSE_TOKENS } from './proseStyles';\n\n/** The default token file's name. The one place this name is spelled. */\nexport const PROSE_TOKEN_FILE = 'immediately.run.css';\n\n/** The bundle marker that may carry a `styles` field naming another token file. */\nexport const PROSE_MARKER_FILE = 'immediately.run.json';\n\n/** A token file larger than this is refused unread: it sits on the first-paint path. */\nexport const PROSE_TOKEN_FILE_MAX_BYTES = 16384;\n\n/** A single value longer than this is dropped. */\nexport const PROSE_TOKEN_VALUE_MAX_LENGTH = 256;\n\n/** The polarity the host theme reports, and the block that applies to it. */\nexport type ProsePolarity = 'light' | 'dark';\n\n/** Values per block, keyed by the public custom property (`--ink`). */\nexport interface ProseTokenBlocks {\n readonly root: Readonly<Record<string, string>>;\n readonly light: Readonly<Record<string, string>>;\n readonly dark: Readonly<Record<string, string>>;\n}\n\n/** The outcome of parsing a token file. `warnings` name every dropped declaration. */\nexport type ParsedProseTokenFile =\n | { readonly ok: true; readonly blocks: ProseTokenBlocks; readonly warnings: readonly string[] }\n | { readonly ok: false; readonly reason: string };\n\nconst ALLOWED = new Set(PROSE_TOKENS.map((token) => `--${token.name}`));\n\n/**\n * Value fragments that are dropped, case-insensitively. Each one can fetch a resource\n * (`url(` and the image functions), smuggle one in (`\\` escapes spell `url(` without its\n * letters, `@` starts an at-rule), or break out of a declaration in a context that\n * re-serialises it (`;`, braces, angle brackets).\n */\nconst REFUSED_VALUE_FRAGMENTS = [\n 'url(',\n 'image(',\n 'image-set(',\n 'cross-fade(',\n 'element(',\n 'src(',\n '@',\n '\\\\',\n ';',\n '{',\n '}',\n '<',\n '>',\n] as const;\n\nconst SELECTORS: Record<string, keyof ProseTokenBlocks> = {\n ':root': 'root',\n ':root[data-theme=\"light\"]': 'light',\n ':root[data-theme=\"dark\"]': 'dark',\n};\n\n/** The block a selector names, or `null`. Either quote style; whitespace is not significant. */\nconst blockFor = (selector: string): keyof ProseTokenBlocks | null =>\n SELECTORS[selector.replace(/\\s+/g, '').replace(/'/g, '\"')] ?? null;\n\nconst refusedFragment = (value: string): string | undefined => {\n const lower = value.toLowerCase();\n return REFUSED_VALUE_FRAGMENTS.find((fragment) => lower.includes(fragment));\n};\n\nconst byteLength = (text: string): number => new TextEncoder().encode(text).length;\n\ninterface RawBlock {\n selector: string;\n declarations: string[];\n}\n\n/**\n * Split the text into `selector { decl; decl }` blocks. Quote-aware (a `;` or `}` inside\n * a string stays in its value, where the value check drops it) and comment-stripping.\n * Returns a reason string for anything that is not a flat sequence of blocks: a nested\n * brace, a statement outside a block (`@import …;`), an unterminated string or comment.\n */\nconst splitBlocks = (text: string): RawBlock[] | string => {\n const blocks: RawBlock[] = [];\n let buffer = '';\n let current: RawBlock | null = null;\n let i = 0;\n while (i < text.length) {\n const ch = text[i];\n if (ch === '/' && text[i + 1] === '*') {\n const end = text.indexOf('*/', i + 2);\n if (end < 0) return 'an unterminated comment';\n i = end + 2;\n buffer += ' ';\n continue;\n }\n if (ch === '\"' || ch === \"'\") {\n let j = i + 1;\n while (j < text.length && text[j] !== ch) {\n if (text[j] === '\\\\') j += 1;\n if (text[j] === '\\n') return 'an unterminated string';\n j += 1;\n }\n if (j >= text.length) return 'an unterminated string';\n buffer += text.slice(i, j + 1);\n i = j + 1;\n continue;\n }\n if (ch === '{') {\n if (current) return 'a nested block';\n current = { selector: buffer.trim(), declarations: [] };\n buffer = '';\n } else if (ch === '}') {\n if (!current) return 'an unmatched \"}\"';\n if (buffer.trim()) current.declarations.push(buffer.trim());\n blocks.push(current);\n current = null;\n buffer = '';\n } else if (ch === ';' && current) {\n if (buffer.trim()) current.declarations.push(buffer.trim());\n buffer = '';\n } else {\n buffer += ch;\n }\n i += 1;\n }\n if (current) return 'an unclosed block';\n if (buffer.trim()) return `\"${buffer.trim().slice(0, 40)}\" outside a block`;\n return blocks;\n};\n\n/**\n * Parse a token file. All-or-nothing per file for its SHAPE (Grove plans 05 §3, the rule\n * Grove's check-theme-token-only script enforces): any at-rule, any selector but the\n * three token blocks, or any property that is not a custom property refuses the whole file.\n * Per declaration for its CONTENT: an unknown token name or a refused value is dropped with\n * a warning and the rest of the file applies.\n */\nexport function parseProseTokenFile(text: string): ParsedProseTokenFile {\n if (byteLength(text) > PROSE_TOKEN_FILE_MAX_BYTES) {\n return { ok: false, reason: `it is larger than ${PROSE_TOKEN_FILE_MAX_BYTES} bytes` };\n }\n const split = splitBlocks(text);\n if (typeof split === 'string') return { ok: false, reason: `it contains ${split}` };\n\n const blocks = { root: {}, light: {}, dark: {} } as Record<keyof ProseTokenBlocks, Record<string, string>>;\n const warnings: string[] = [];\n for (const { selector, declarations } of split) {\n const block = blockFor(selector);\n if (!block) {\n return {\n ok: false,\n reason: `\"${selector.slice(0, 60)}\" is not one of :root, :root[data-theme=\"light\"], :root[data-theme=\"dark\"]`,\n };\n }\n for (const declaration of declarations) {\n const match = /^(--[A-Za-z0-9_-]+)\\s*:([\\s\\S]*)$/.exec(declaration);\n if (!match) {\n return { ok: false, reason: `\"${declaration.slice(0, 60)}\" is not a custom property declaration` };\n }\n const name = match[1];\n const value = match[2].trim();\n if (!ALLOWED.has(name)) {\n warnings.push(`${name} is not a prose token; ignored`);\n continue;\n }\n if (!value) {\n warnings.push(`${name} has an empty value; ignored`);\n continue;\n }\n if (value.length > PROSE_TOKEN_VALUE_MAX_LENGTH) {\n warnings.push(`${name} is longer than ${PROSE_TOKEN_VALUE_MAX_LENGTH} characters; ignored`);\n continue;\n }\n const fragment = refusedFragment(value);\n if (fragment) {\n warnings.push(`${name} contains \"${fragment}\"; ignored`);\n continue;\n }\n blocks[block][name] = value;\n }\n }\n return { ok: true, blocks, warnings };\n}\n\n/**\n * The values to set for one polarity, in application order: `:root` first, then the\n * polarity block, so a polarity value wins over the shared one.\n */\nexport function tokensFor(blocks: ProseTokenBlocks, polarity: ProsePolarity): [string, string][] {\n return Object.entries({ ...blocks.root, ...blocks[polarity] });\n}\n\n/**\n * Reads the lookup needs, injected so the walk is tested without a filesystem. Paths are\n * repo-relative with no leading slash (`''` is the repo root).\n * - `size`: the byte size of a regular file, or `null` when there is none;\n * - `read`: a file's UTF-8 text, or `null` when there is none.\n */\nexport interface ProseTokenProbe {\n size(path: string): Promise<number | null>;\n read(path: string): Promise<string | null>;\n}\n\n/** Where the walk landed: the token file to read (or none), and what to warn about. */\nexport interface ResolvedTokenFile {\n /** The repo-relative token file, or `null` when no author tokens apply. */\n readonly path: string | null;\n /** Its size in bytes when `path` is set. */\n readonly size: number | null;\n /**\n * The file a change should re-run the lookup for: `path`, or the file a marker's `styles`\n * names while it does not exist yet, so creating it restyles the page.\n */\n readonly watch: string | null;\n /** The directory the walk stopped in (`''` is the repo root). */\n readonly dir: string;\n readonly warnings: readonly string[];\n}\n\nconst join = (dir: string, name: string): string => (dir ? `${dir}/${name}` : name);\n\n/** The parent of a repo-relative directory, or `null` above the repo root. */\nconst parentOf = (dir: string): string | null =>\n dir === '' ? null : dir.includes('/') ? dir.slice(0, dir.lastIndexOf('/')) : '';\n\n/** The directory of a repo-relative file path. */\nexport const dirOfFile = (file: string): string => {\n const clean = file.replace(/^\\/+/, '');\n return clean.includes('/') ? clean.slice(0, clean.lastIndexOf('/')) : '';\n};\n\n/**\n * A `styles` value normalised under `dir`, or a reason it is refused: it must be relative,\n * carry no scheme, and stay inside the marker's directory.\n */\nconst resolveStyles = (dir: string, styles: string): { path: string } | { reason: string } => {\n if (styles.startsWith('/')) return { reason: `\"styles\": \"${styles}\" is absolute` };\n if (/^[A-Za-z][A-Za-z0-9+.-]*:/.test(styles)) return { reason: `\"styles\": \"${styles}\" names a URL` };\n const parts: string[] = [];\n for (const segment of styles.split('/')) {\n if (segment === '' || segment === '.') continue;\n if (segment === '..') return { reason: `\"styles\": \"${styles}\" leaves the directory of its marker` };\n parts.push(segment);\n }\n if (!parts.length) return { reason: `\"styles\": \"${styles}\" names no file` };\n return { path: join(dir, parts.join('/')) };\n};\n\n/**\n * Find the token file for Markdown in `startDir`. Walk up to the repo root and stop at the\n * first directory holding a marker or the default token file. There, a marker's `styles`\n * string names the file, `styles: false` turns author tokens off, and otherwise the default\n * file applies if it exists. Every refusal is a warning and leaves the defaults in place.\n */\nexport async function resolveTokenFile(startDir: string, probe: ProseTokenProbe): Promise<ResolvedTokenFile> {\n const warnings: string[] = [];\n for (let dir: string | null = startDir.replace(/^\\/+|\\/+$/g, ''); dir !== null; dir = parentOf(dir)) {\n const markerPath = join(dir, PROSE_MARKER_FILE);\n const defaultPath = join(dir, PROSE_TOKEN_FILE);\n const [markerText, defaultSize] = await Promise.all([probe.read(markerPath), probe.size(defaultPath)]);\n if (markerText === null && defaultSize === null) continue;\n\n let styles: unknown;\n if (markerText !== null) {\n try {\n const marker: unknown = JSON.parse(markerText);\n styles = marker && typeof marker === 'object' ? (marker as Record<string, unknown>).styles : undefined;\n } catch {\n warnings.push(`${markerPath} is not valid JSON; its \"styles\" field is ignored`);\n }\n if (styles !== undefined && styles !== false && typeof styles !== 'string') {\n warnings.push(`${markerPath}: \"styles\" must be a file name or false; ignored`);\n styles = undefined;\n }\n }\n if (styles === false) return { path: null, size: null, watch: null, dir, warnings };\n if (typeof styles === 'string') {\n const resolved = resolveStyles(dir, styles);\n if ('reason' in resolved) {\n warnings.push(`${markerPath}: ${resolved.reason}; author tokens are off`);\n return { path: null, size: null, watch: null, dir, warnings };\n }\n const size = await probe.size(resolved.path);\n if (size === null) warnings.push(`${markerPath}: \"styles\" names ${resolved.path}, which does not exist`);\n return { path: size === null ? null : resolved.path, size, watch: resolved.path, dir, warnings };\n }\n const path = defaultSize === null ? null : defaultPath;\n return { path, size: defaultSize, watch: path, dir, warnings };\n }\n return { path: null, size: null, watch: null, dir: '', warnings };\n}\n\n/**\n * Does a changed repo-relative path bear on the token lookup for `startDir`? True for the\n * watched token file (`ResolvedTokenFile.watch`), and for any marker or default token file in a directory the walk\n * visits (one created or deleted there moves the lookup).\n */\nexport function affectsTokenLookup(changed: string, startDir: string, watched: string | null): boolean {\n const path = changed.replace(/^\\/+/, '');\n if (watched !== null && path === watched) return true;\n const name = path.slice(path.lastIndexOf('/') + 1);\n if (name !== PROSE_MARKER_FILE && name !== PROSE_TOKEN_FILE) return false;\n const dir = dirOfFile(path);\n const start = startDir.replace(/^\\/+|\\/+$/g, '');\n return dir === '' || start === dir || start.startsWith(`${dir}/`);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA,yBAA6B;AAGtB,MAAM,mBAAmB;AAGzB,MAAM,oBAAoB;AAG1B,MAAM,6BAA6B;AAGnC,MAAM,+BAA+B;AAiB5C,MAAM,UAAU,IAAI,IAAI,gCAAa,IAAI,CAAC,UAAU,KAAK,MAAM,IAAI,EAAE,CAAC;AAQtE,MAAM,0BAA0B;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,MAAM,YAAoD;AAAA,EACxD,SAAS;AAAA,EACT,6BAA6B;AAAA,EAC7B,4BAA4B;AAC9B;AAGA,MAAM,WAAW,CAAC,aAChB,UAAU,SAAS,QAAQ,QAAQ,EAAE,EAAE,QAAQ,MAAM,GAAG,CAAC,KAAK;AAEhE,MAAM,kBAAkB,CAAC,UAAsC;AAC7D,QAAM,QAAQ,MAAM,YAAY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IAAI,wBAAwB;AACvG,aAAO,EAAE,MAAM,SAAS,OAAO,OAAO,SAAS,MAAM,MAAM,OAAO,SAAS,MAAM,KAAK,SAAS;AAAA,IACjG;AACA,UAAM,OAAO,gBAAgB,OAAO,OAAO;AAC3C,WAAO,EAAE,MAAM,MAAM,aAAa,OAAO,MAAM,KAAK,SAAS;AAAA,EAC/D;AACA,SAAO,EAAE,MAAM,MAAM,MAAM,MAAM,OAAO,MAAM,KAAK,IAAI,SAAS;AAClE;AAOO,SAAS,mBAAmB,SAAiB,UAAkB,SAAiC;AACrG,QAAM,OAAO,QAAQ,QAAQ,QAAQ,EAAE;AACvC,MAAI,YAAY,QAAQ,SAAS,QAAS,QAAO;AACjD,QAAM,OAAO,KAAK,MAAM,KAAK,YAAY,GAAG,IAAI,CAAC;AACjD,MAAI,SAAS,qBAAqB,SAAS,iBAAkB,QAAO;AACpE,QAAM,MAAM,UAAU,IAAI;AAC1B,QAAM,QAAQ,SAAS,QAAQ,cAAc,EAAE;AAC/C,SAAO,QAAQ,MAAM,UAAU,OAAO,MAAM,WAAW,GAAG,GAAG,GAAG;AAClE;","names":[]}
@@ -0,0 +1,80 @@
1
+ /** The default token file's name. The one place this name is spelled. */
2
+ declare const PROSE_TOKEN_FILE = "immediately.run.css";
3
+ /** The bundle marker that may carry a `styles` field naming another token file. */
4
+ declare const PROSE_MARKER_FILE = "immediately.run.json";
5
+ /** A token file larger than this is refused unread: it sits on the first-paint path. */
6
+ declare const PROSE_TOKEN_FILE_MAX_BYTES = 16384;
7
+ /** A single value longer than this is dropped. */
8
+ declare const PROSE_TOKEN_VALUE_MAX_LENGTH = 256;
9
+ /** The polarity the host theme reports, and the block that applies to it. */
10
+ type ProsePolarity = 'light' | 'dark';
11
+ /** Values per block, keyed by the public custom property (`--ink`). */
12
+ interface ProseTokenBlocks {
13
+ readonly root: Readonly<Record<string, string>>;
14
+ readonly light: Readonly<Record<string, string>>;
15
+ readonly dark: Readonly<Record<string, string>>;
16
+ }
17
+ /** The outcome of parsing a token file. `warnings` name every dropped declaration. */
18
+ type ParsedProseTokenFile = {
19
+ readonly ok: true;
20
+ readonly blocks: ProseTokenBlocks;
21
+ readonly warnings: readonly string[];
22
+ } | {
23
+ readonly ok: false;
24
+ readonly reason: string;
25
+ };
26
+ /**
27
+ * Parse a token file. All-or-nothing per file for its SHAPE (Grove plans 05 §3, the rule
28
+ * Grove's check-theme-token-only script enforces): any at-rule, any selector but the
29
+ * three token blocks, or any property that is not a custom property refuses the whole file.
30
+ * Per declaration for its CONTENT: an unknown token name or a refused value is dropped with
31
+ * a warning and the rest of the file applies.
32
+ */
33
+ declare function parseProseTokenFile(text: string): ParsedProseTokenFile;
34
+ /**
35
+ * The values to set for one polarity, in application order: `:root` first, then the
36
+ * polarity block, so a polarity value wins over the shared one.
37
+ */
38
+ declare function tokensFor(blocks: ProseTokenBlocks, polarity: ProsePolarity): [string, string][];
39
+ /**
40
+ * Reads the lookup needs, injected so the walk is tested without a filesystem. Paths are
41
+ * repo-relative with no leading slash (`''` is the repo root).
42
+ * - `size`: the byte size of a regular file, or `null` when there is none;
43
+ * - `read`: a file's UTF-8 text, or `null` when there is none.
44
+ */
45
+ interface ProseTokenProbe {
46
+ size(path: string): Promise<number | null>;
47
+ read(path: string): Promise<string | null>;
48
+ }
49
+ /** Where the walk landed: the token file to read (or none), and what to warn about. */
50
+ interface ResolvedTokenFile {
51
+ /** The repo-relative token file, or `null` when no author tokens apply. */
52
+ readonly path: string | null;
53
+ /** Its size in bytes when `path` is set. */
54
+ readonly size: number | null;
55
+ /**
56
+ * The file a change should re-run the lookup for: `path`, or the file a marker's `styles`
57
+ * names while it does not exist yet, so creating it restyles the page.
58
+ */
59
+ readonly watch: string | null;
60
+ /** The directory the walk stopped in (`''` is the repo root). */
61
+ readonly dir: string;
62
+ readonly warnings: readonly string[];
63
+ }
64
+ /** The directory of a repo-relative file path. */
65
+ declare const dirOfFile: (file: string) => string;
66
+ /**
67
+ * Find the token file for Markdown in `startDir`. Walk up to the repo root and stop at the
68
+ * first directory holding a marker or the default token file. There, a marker's `styles`
69
+ * string names the file, `styles: false` turns author tokens off, and otherwise the default
70
+ * file applies if it exists. Every refusal is a warning and leaves the defaults in place.
71
+ */
72
+ declare function resolveTokenFile(startDir: string, probe: ProseTokenProbe): Promise<ResolvedTokenFile>;
73
+ /**
74
+ * Does a changed repo-relative path bear on the token lookup for `startDir`? True for the
75
+ * watched token file (`ResolvedTokenFile.watch`), and for any marker or default token file in a directory the walk
76
+ * visits (one created or deleted there moves the lookup).
77
+ */
78
+ declare function affectsTokenLookup(changed: string, startDir: string, watched: string | null): boolean;
79
+
80
+ export { PROSE_MARKER_FILE, PROSE_TOKEN_FILE, PROSE_TOKEN_FILE_MAX_BYTES, PROSE_TOKEN_VALUE_MAX_LENGTH, type ParsedProseTokenFile, type ProsePolarity, type ProseTokenBlocks, type ProseTokenProbe, type ResolvedTokenFile, affectsTokenLookup, dirOfFile, parseProseTokenFile, resolveTokenFile, tokensFor };
@@ -0,0 +1,80 @@
1
+ /** The default token file's name. The one place this name is spelled. */
2
+ declare const PROSE_TOKEN_FILE = "immediately.run.css";
3
+ /** The bundle marker that may carry a `styles` field naming another token file. */
4
+ declare const PROSE_MARKER_FILE = "immediately.run.json";
5
+ /** A token file larger than this is refused unread: it sits on the first-paint path. */
6
+ declare const PROSE_TOKEN_FILE_MAX_BYTES = 16384;
7
+ /** A single value longer than this is dropped. */
8
+ declare const PROSE_TOKEN_VALUE_MAX_LENGTH = 256;
9
+ /** The polarity the host theme reports, and the block that applies to it. */
10
+ type ProsePolarity = 'light' | 'dark';
11
+ /** Values per block, keyed by the public custom property (`--ink`). */
12
+ interface ProseTokenBlocks {
13
+ readonly root: Readonly<Record<string, string>>;
14
+ readonly light: Readonly<Record<string, string>>;
15
+ readonly dark: Readonly<Record<string, string>>;
16
+ }
17
+ /** The outcome of parsing a token file. `warnings` name every dropped declaration. */
18
+ type ParsedProseTokenFile = {
19
+ readonly ok: true;
20
+ readonly blocks: ProseTokenBlocks;
21
+ readonly warnings: readonly string[];
22
+ } | {
23
+ readonly ok: false;
24
+ readonly reason: string;
25
+ };
26
+ /**
27
+ * Parse a token file. All-or-nothing per file for its SHAPE (Grove plans 05 §3, the rule
28
+ * Grove's check-theme-token-only script enforces): any at-rule, any selector but the
29
+ * three token blocks, or any property that is not a custom property refuses the whole file.
30
+ * Per declaration for its CONTENT: an unknown token name or a refused value is dropped with
31
+ * a warning and the rest of the file applies.
32
+ */
33
+ declare function parseProseTokenFile(text: string): ParsedProseTokenFile;
34
+ /**
35
+ * The values to set for one polarity, in application order: `:root` first, then the
36
+ * polarity block, so a polarity value wins over the shared one.
37
+ */
38
+ declare function tokensFor(blocks: ProseTokenBlocks, polarity: ProsePolarity): [string, string][];
39
+ /**
40
+ * Reads the lookup needs, injected so the walk is tested without a filesystem. Paths are
41
+ * repo-relative with no leading slash (`''` is the repo root).
42
+ * - `size`: the byte size of a regular file, or `null` when there is none;
43
+ * - `read`: a file's UTF-8 text, or `null` when there is none.
44
+ */
45
+ interface ProseTokenProbe {
46
+ size(path: string): Promise<number | null>;
47
+ read(path: string): Promise<string | null>;
48
+ }
49
+ /** Where the walk landed: the token file to read (or none), and what to warn about. */
50
+ interface ResolvedTokenFile {
51
+ /** The repo-relative token file, or `null` when no author tokens apply. */
52
+ readonly path: string | null;
53
+ /** Its size in bytes when `path` is set. */
54
+ readonly size: number | null;
55
+ /**
56
+ * The file a change should re-run the lookup for: `path`, or the file a marker's `styles`
57
+ * names while it does not exist yet, so creating it restyles the page.
58
+ */
59
+ readonly watch: string | null;
60
+ /** The directory the walk stopped in (`''` is the repo root). */
61
+ readonly dir: string;
62
+ readonly warnings: readonly string[];
63
+ }
64
+ /** The directory of a repo-relative file path. */
65
+ declare const dirOfFile: (file: string) => string;
66
+ /**
67
+ * Find the token file for Markdown in `startDir`. Walk up to the repo root and stop at the
68
+ * first directory holding a marker or the default token file. There, a marker's `styles`
69
+ * string names the file, `styles: false` turns author tokens off, and otherwise the default
70
+ * file applies if it exists. Every refusal is a warning and leaves the defaults in place.
71
+ */
72
+ declare function resolveTokenFile(startDir: string, probe: ProseTokenProbe): Promise<ResolvedTokenFile>;
73
+ /**
74
+ * Does a changed repo-relative path bear on the token lookup for `startDir`? True for the
75
+ * watched token file (`ResolvedTokenFile.watch`), and for any marker or default token file in a directory the walk
76
+ * visits (one created or deleted there moves the lookup).
77
+ */
78
+ declare function affectsTokenLookup(changed: string, startDir: string, watched: string | null): boolean;
79
+
80
+ export { PROSE_MARKER_FILE, PROSE_TOKEN_FILE, PROSE_TOKEN_FILE_MAX_BYTES, PROSE_TOKEN_VALUE_MAX_LENGTH, type ParsedProseTokenFile, type ProsePolarity, type ProseTokenBlocks, type ProseTokenProbe, type ResolvedTokenFile, affectsTokenLookup, dirOfFile, parseProseTokenFile, resolveTokenFile, tokensFor };
@@ -0,0 +1,204 @@
1
+ import "./chunk-VHAA22YE.js";
2
+ import { PROSE_TOKENS } from "./proseStyles.js";
3
+ const PROSE_TOKEN_FILE = "immediately.run.css";
4
+ const PROSE_MARKER_FILE = "immediately.run.json";
5
+ const PROSE_TOKEN_FILE_MAX_BYTES = 16384;
6
+ const PROSE_TOKEN_VALUE_MAX_LENGTH = 256;
7
+ const ALLOWED = new Set(PROSE_TOKENS.map((token) => `--${token.name}`));
8
+ const REFUSED_VALUE_FRAGMENTS = [
9
+ "url(",
10
+ "image(",
11
+ "image-set(",
12
+ "cross-fade(",
13
+ "element(",
14
+ "src(",
15
+ "@",
16
+ "\\",
17
+ ";",
18
+ "{",
19
+ "}",
20
+ "<",
21
+ ">"
22
+ ];
23
+ const SELECTORS = {
24
+ ":root": "root",
25
+ ':root[data-theme="light"]': "light",
26
+ ':root[data-theme="dark"]': "dark"
27
+ };
28
+ const blockFor = (selector) => SELECTORS[selector.replace(/\s+/g, "").replace(/'/g, '"')] ?? null;
29
+ const refusedFragment = (value) => {
30
+ const lower = value.toLowerCase();
31
+ return REFUSED_VALUE_FRAGMENTS.find((fragment) => lower.includes(fragment));
32
+ };
33
+ const byteLength = (text) => new TextEncoder().encode(text).length;
34
+ const splitBlocks = (text) => {
35
+ const blocks = [];
36
+ let buffer = "";
37
+ let current = null;
38
+ let i = 0;
39
+ while (i < text.length) {
40
+ const ch = text[i];
41
+ if (ch === "/" && text[i + 1] === "*") {
42
+ const end = text.indexOf("*/", i + 2);
43
+ if (end < 0) return "an unterminated comment";
44
+ i = end + 2;
45
+ buffer += " ";
46
+ continue;
47
+ }
48
+ if (ch === '"' || ch === "'") {
49
+ let j = i + 1;
50
+ while (j < text.length && text[j] !== ch) {
51
+ if (text[j] === "\\") j += 1;
52
+ if (text[j] === "\n") return "an unterminated string";
53
+ j += 1;
54
+ }
55
+ if (j >= text.length) return "an unterminated string";
56
+ buffer += text.slice(i, j + 1);
57
+ i = j + 1;
58
+ continue;
59
+ }
60
+ if (ch === "{") {
61
+ if (current) return "a nested block";
62
+ current = { selector: buffer.trim(), declarations: [] };
63
+ buffer = "";
64
+ } else if (ch === "}") {
65
+ if (!current) return 'an unmatched "}"';
66
+ if (buffer.trim()) current.declarations.push(buffer.trim());
67
+ blocks.push(current);
68
+ current = null;
69
+ buffer = "";
70
+ } else if (ch === ";" && current) {
71
+ if (buffer.trim()) current.declarations.push(buffer.trim());
72
+ buffer = "";
73
+ } else {
74
+ buffer += ch;
75
+ }
76
+ i += 1;
77
+ }
78
+ if (current) return "an unclosed block";
79
+ if (buffer.trim()) return `"${buffer.trim().slice(0, 40)}" outside a block`;
80
+ return blocks;
81
+ };
82
+ function parseProseTokenFile(text) {
83
+ if (byteLength(text) > PROSE_TOKEN_FILE_MAX_BYTES) {
84
+ return { ok: false, reason: `it is larger than ${PROSE_TOKEN_FILE_MAX_BYTES} bytes` };
85
+ }
86
+ const split = splitBlocks(text);
87
+ if (typeof split === "string") return { ok: false, reason: `it contains ${split}` };
88
+ const blocks = { root: {}, light: {}, dark: {} };
89
+ const warnings = [];
90
+ for (const { selector, declarations } of split) {
91
+ const block = blockFor(selector);
92
+ if (!block) {
93
+ return {
94
+ ok: false,
95
+ reason: `"${selector.slice(0, 60)}" is not one of :root, :root[data-theme="light"], :root[data-theme="dark"]`
96
+ };
97
+ }
98
+ for (const declaration of declarations) {
99
+ const match = /^(--[A-Za-z0-9_-]+)\s*:([\s\S]*)$/.exec(declaration);
100
+ if (!match) {
101
+ return { ok: false, reason: `"${declaration.slice(0, 60)}" is not a custom property declaration` };
102
+ }
103
+ const name = match[1];
104
+ const value = match[2].trim();
105
+ if (!ALLOWED.has(name)) {
106
+ warnings.push(`${name} is not a prose token; ignored`);
107
+ continue;
108
+ }
109
+ if (!value) {
110
+ warnings.push(`${name} has an empty value; ignored`);
111
+ continue;
112
+ }
113
+ if (value.length > PROSE_TOKEN_VALUE_MAX_LENGTH) {
114
+ warnings.push(`${name} is longer than ${PROSE_TOKEN_VALUE_MAX_LENGTH} characters; ignored`);
115
+ continue;
116
+ }
117
+ const fragment = refusedFragment(value);
118
+ if (fragment) {
119
+ warnings.push(`${name} contains "${fragment}"; ignored`);
120
+ continue;
121
+ }
122
+ blocks[block][name] = value;
123
+ }
124
+ }
125
+ return { ok: true, blocks, warnings };
126
+ }
127
+ function tokensFor(blocks, polarity) {
128
+ return Object.entries({ ...blocks.root, ...blocks[polarity] });
129
+ }
130
+ const join = (dir, name) => dir ? `${dir}/${name}` : name;
131
+ const parentOf = (dir) => dir === "" ? null : dir.includes("/") ? dir.slice(0, dir.lastIndexOf("/")) : "";
132
+ const dirOfFile = (file) => {
133
+ const clean = file.replace(/^\/+/, "");
134
+ return clean.includes("/") ? clean.slice(0, clean.lastIndexOf("/")) : "";
135
+ };
136
+ const resolveStyles = (dir, styles) => {
137
+ if (styles.startsWith("/")) return { reason: `"styles": "${styles}" is absolute` };
138
+ if (/^[A-Za-z][A-Za-z0-9+.-]*:/.test(styles)) return { reason: `"styles": "${styles}" names a URL` };
139
+ const parts = [];
140
+ for (const segment of styles.split("/")) {
141
+ if (segment === "" || segment === ".") continue;
142
+ if (segment === "..") return { reason: `"styles": "${styles}" leaves the directory of its marker` };
143
+ parts.push(segment);
144
+ }
145
+ if (!parts.length) return { reason: `"styles": "${styles}" names no file` };
146
+ return { path: join(dir, parts.join("/")) };
147
+ };
148
+ async function resolveTokenFile(startDir, probe) {
149
+ const warnings = [];
150
+ for (let dir = startDir.replace(/^\/+|\/+$/g, ""); dir !== null; dir = parentOf(dir)) {
151
+ const markerPath = join(dir, PROSE_MARKER_FILE);
152
+ const defaultPath = join(dir, PROSE_TOKEN_FILE);
153
+ const [markerText, defaultSize] = await Promise.all([probe.read(markerPath), probe.size(defaultPath)]);
154
+ if (markerText === null && defaultSize === null) continue;
155
+ let styles;
156
+ if (markerText !== null) {
157
+ try {
158
+ const marker = JSON.parse(markerText);
159
+ styles = marker && typeof marker === "object" ? marker.styles : void 0;
160
+ } catch {
161
+ warnings.push(`${markerPath} is not valid JSON; its "styles" field is ignored`);
162
+ }
163
+ if (styles !== void 0 && styles !== false && typeof styles !== "string") {
164
+ warnings.push(`${markerPath}: "styles" must be a file name or false; ignored`);
165
+ styles = void 0;
166
+ }
167
+ }
168
+ if (styles === false) return { path: null, size: null, watch: null, dir, warnings };
169
+ if (typeof styles === "string") {
170
+ const resolved = resolveStyles(dir, styles);
171
+ if ("reason" in resolved) {
172
+ warnings.push(`${markerPath}: ${resolved.reason}; author tokens are off`);
173
+ return { path: null, size: null, watch: null, dir, warnings };
174
+ }
175
+ const size = await probe.size(resolved.path);
176
+ if (size === null) warnings.push(`${markerPath}: "styles" names ${resolved.path}, which does not exist`);
177
+ return { path: size === null ? null : resolved.path, size, watch: resolved.path, dir, warnings };
178
+ }
179
+ const path = defaultSize === null ? null : defaultPath;
180
+ return { path, size: defaultSize, watch: path, dir, warnings };
181
+ }
182
+ return { path: null, size: null, watch: null, dir: "", warnings };
183
+ }
184
+ function affectsTokenLookup(changed, startDir, watched) {
185
+ const path = changed.replace(/^\/+/, "");
186
+ if (watched !== null && path === watched) return true;
187
+ const name = path.slice(path.lastIndexOf("/") + 1);
188
+ if (name !== PROSE_MARKER_FILE && name !== PROSE_TOKEN_FILE) return false;
189
+ const dir = dirOfFile(path);
190
+ const start = startDir.replace(/^\/+|\/+$/g, "");
191
+ return dir === "" || start === dir || start.startsWith(`${dir}/`);
192
+ }
193
+ export {
194
+ PROSE_MARKER_FILE,
195
+ PROSE_TOKEN_FILE,
196
+ PROSE_TOKEN_FILE_MAX_BYTES,
197
+ PROSE_TOKEN_VALUE_MAX_LENGTH,
198
+ affectsTokenLookup,
199
+ dirOfFile,
200
+ parseProseTokenFile,
201
+ resolveTokenFile,
202
+ tokensFor
203
+ };
204
+ //# sourceMappingURL=proseTokens.js.map