@immediately-run/sdk 0.95.0 → 0.97.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/dist/components/DirectoryView.cjs +62 -0
- package/dist/components/DirectoryView.cjs.map +1 -0
- package/dist/components/DirectoryView.d.cts +16 -0
- package/dist/components/DirectoryView.d.ts +16 -0
- package/dist/components/DirectoryView.js +39 -0
- package/dist/components/DirectoryView.js.map +1 -0
- package/dist/components/FileRouter.cjs +30 -1
- package/dist/components/FileRouter.cjs.map +1 -1
- package/dist/components/FileRouter.js +31 -2
- package/dist/components/FileRouter.js.map +1 -1
- package/dist/components/Prose.cjs +35 -2
- package/dist/components/Prose.cjs.map +1 -1
- package/dist/components/Prose.d.cts +10 -2
- package/dist/components/Prose.d.ts +10 -2
- package/dist/components/Prose.js +36 -3
- package/dist/components/Prose.js.map +1 -1
- package/dist/directoryListing.cjs +84 -0
- package/dist/directoryListing.cjs.map +1 -0
- package/dist/directoryListing.d.cts +34 -0
- package/dist/directoryListing.d.ts +34 -0
- package/dist/directoryListing.js +56 -0
- package/dist/directoryListing.js.map +1 -0
- package/dist/proseTokens.cjs +235 -0
- package/dist/proseTokens.cjs.map +1 -0
- package/dist/proseTokens.d.cts +80 -0
- package/dist/proseTokens.d.ts +80 -0
- package/dist/proseTokens.js +204 -0
- package/dist/proseTokens.js.map +1 -0
- package/dist/proseTokensHook.cjs +116 -0
- package/dist/proseTokensHook.cjs.map +1 -0
- package/dist/proseTokensHook.d.cts +10 -0
- package/dist/proseTokensHook.d.ts +10 -0
- package/dist/proseTokensHook.js +99 -0
- package/dist/proseTokensHook.js.map +1 -0
- package/dist/version.cjs +1 -1
- package/dist/version.cjs.map +1 -1
- package/dist/version.d.cts +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** One entry of a listed directory. `path` is repo-relative with a leading `/`, the form
|
|
2
|
+
* `Link` turns into a `/files/…` URL; a directory's path ends in `/`. */
|
|
3
|
+
interface DirectoryEntry {
|
|
4
|
+
name: string;
|
|
5
|
+
path: string;
|
|
6
|
+
isDirectory: boolean;
|
|
7
|
+
}
|
|
8
|
+
interface DirectoryListing {
|
|
9
|
+
/** Repo-relative, leading `/`, trailing `/` (the root is `/`). */
|
|
10
|
+
dir: string;
|
|
11
|
+
/** The parent directory in the same form, or `null` at the repo root. */
|
|
12
|
+
parent: string | null;
|
|
13
|
+
entries: DirectoryEntry[];
|
|
14
|
+
/** Repo-relative path of the README rendered under the listing, if the folder has one. */
|
|
15
|
+
readme: string | null;
|
|
16
|
+
}
|
|
17
|
+
/** `tickets/` / `/tickets` / `tickets` → `/tickets/`; `''` and `/` → `/`. */
|
|
18
|
+
declare const toDirPath: (repoPath: string) => string;
|
|
19
|
+
/** A trailing slash is the URL saying "folder" — no filesystem round-trip needed. */
|
|
20
|
+
declare const namesDirectory: (repoPath: string) => boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Whether a repo-relative path is a directory in the sandbox fs. `false` when the path
|
|
23
|
+
* does not exist or no fs is available: the caller then renders it as a file, and the
|
|
24
|
+
* module loader reports the missing file itself — this probe never hides that error.
|
|
25
|
+
*/
|
|
26
|
+
declare const isDirectoryPath: (repoPath: string) => Promise<boolean>;
|
|
27
|
+
/** Directories first, then files; each group by name, case-insensitively. */
|
|
28
|
+
declare const sortEntries: (entries: DirectoryEntry[]) => DirectoryEntry[];
|
|
29
|
+
declare const pickReadme: (entries: DirectoryEntry[]) => DirectoryEntry | null;
|
|
30
|
+
/** Read and shape one directory. Rejects (into the caller's error boundary) when the
|
|
31
|
+
* fs is unavailable or the read fails — an empty listing would be a lie. */
|
|
32
|
+
declare const readDirectoryListing: (repoPath: string) => Promise<DirectoryListing>;
|
|
33
|
+
|
|
34
|
+
export { type DirectoryEntry, type DirectoryListing, isDirectoryPath, namesDirectory, pickReadme, readDirectoryListing, sortEntries, toDirPath };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import "./chunk-VHAA22YE.js";
|
|
2
|
+
import { sandboxFs } from "./fs.js";
|
|
3
|
+
import { underAppRoot } from "./urlUtils.js";
|
|
4
|
+
const README_NAMES = ["README.md", "README.mdx", "readme.md", "index.md", "index.mdx"];
|
|
5
|
+
const toDirPath = (repoPath) => {
|
|
6
|
+
const trimmed = repoPath.replace(/^\/+|\/+$/g, "");
|
|
7
|
+
return trimmed ? `/${trimmed}/` : "/";
|
|
8
|
+
};
|
|
9
|
+
const namesDirectory = (repoPath) => repoPath === "" || repoPath.endsWith("/");
|
|
10
|
+
const fsPromises = () => {
|
|
11
|
+
const fs = sandboxFs();
|
|
12
|
+
return fs?.promises ?? null;
|
|
13
|
+
};
|
|
14
|
+
const isDirectoryPath = async (repoPath) => {
|
|
15
|
+
const promises = fsPromises();
|
|
16
|
+
if (!promises) return false;
|
|
17
|
+
try {
|
|
18
|
+
const st = await promises.stat(underAppRoot(repoPath.replace(/^\/+/, "")));
|
|
19
|
+
return typeof st?.isDirectory === "function" ? Boolean(st.isDirectory()) : false;
|
|
20
|
+
} catch {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const sortEntries = (entries) => [...entries].sort(
|
|
25
|
+
(a, b) => Number(b.isDirectory) - Number(a.isDirectory) || a.name.localeCompare(b.name, void 0, { sensitivity: "base" }) || a.name.localeCompare(b.name)
|
|
26
|
+
);
|
|
27
|
+
const pickReadme = (entries) => {
|
|
28
|
+
for (const name of README_NAMES) {
|
|
29
|
+
const hit = entries.find((e) => !e.isDirectory && e.name === name);
|
|
30
|
+
if (hit) return hit;
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
};
|
|
34
|
+
const readDirectoryListing = async (repoPath) => {
|
|
35
|
+
const promises = fsPromises();
|
|
36
|
+
if (!promises) throw new Error(`Cannot list ${repoPath || "/"}: the sandbox filesystem is unavailable`);
|
|
37
|
+
const dir = toDirPath(repoPath);
|
|
38
|
+
const raw = await promises.readdir(underAppRoot(dir.slice(1)), { withFileTypes: true });
|
|
39
|
+
const entries = sortEntries(
|
|
40
|
+
raw.map((d) => {
|
|
41
|
+
const isDirectory = d.isDirectory();
|
|
42
|
+
return { name: d.name, isDirectory, path: `${dir}${d.name}${isDirectory ? "/" : ""}` };
|
|
43
|
+
})
|
|
44
|
+
);
|
|
45
|
+
const parent = dir === "/" ? null : toDirPath(dir.slice(0, -1).replace(/[^/]*$/, ""));
|
|
46
|
+
return { dir, parent, entries, readme: pickReadme(entries)?.path ?? null };
|
|
47
|
+
};
|
|
48
|
+
export {
|
|
49
|
+
isDirectoryPath,
|
|
50
|
+
namesDirectory,
|
|
51
|
+
pickReadme,
|
|
52
|
+
readDirectoryListing,
|
|
53
|
+
sortEntries,
|
|
54
|
+
toDirPath
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=directoryListing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/directoryListing.ts"],"sourcesContent":["// What `FileRouter` needs to route a DIRECTORY under `/files/*`. `files/<repo path>` is the\n// filesystem-true address for anything in the mount (REPO_CONTENT_DISPATCH_SPEC §9), and\n// a folder is part of the mount: a README that links to `tickets/` must land on something\n// other than `require('/app/tickets')`, which is what every `/files/*` path used to become.\n//\n// Kept outside the component (R13) so the decisions — what counts as a directory, entry\n// order, which file is the folder's README — are testable without rendering.\nimport { sandboxFs } from './fs';\nimport { underAppRoot } from './urlUtils';\n\n/** One entry of a listed directory. `path` is repo-relative with a leading `/`, the form\n * `Link` turns into a `/files/…` URL; a directory's path ends in `/`. */\nexport interface DirectoryEntry {\n name: string;\n path: string;\n isDirectory: boolean;\n}\n\nexport interface DirectoryListing {\n /** Repo-relative, leading `/`, trailing `/` (the root is `/`). */\n dir: string;\n /** The parent directory in the same form, or `null` at the repo root. */\n parent: string | null;\n entries: DirectoryEntry[];\n /** Repo-relative path of the README rendered under the listing, if the folder has one. */\n readme: string | null;\n}\n\n/** Shown below the listing, first match wins — GitHub's convention for a folder page. */\nconst README_NAMES = ['README.md', 'README.mdx', 'readme.md', 'index.md', 'index.mdx'];\n\n/** `tickets/` / `/tickets` / `tickets` → `/tickets/`; `''` and `/` → `/`. */\nexport const toDirPath = (repoPath: string): string => {\n const trimmed = repoPath.replace(/^\\/+|\\/+$/g, '');\n return trimmed ? `/${trimmed}/` : '/';\n};\n\n/** A trailing slash is the URL saying \"folder\" — no filesystem round-trip needed. */\nexport const namesDirectory = (repoPath: string): boolean => repoPath === '' || repoPath.endsWith('/');\n\nconst fsPromises = () => {\n const fs = sandboxFs();\n return fs?.promises ?? null;\n};\n\n/**\n * Whether a repo-relative path is a directory in the sandbox fs. `false` when the path\n * does not exist or no fs is available: the caller then renders it as a file, and the\n * module loader reports the missing file itself — this probe never hides that error.\n */\nexport const isDirectoryPath = async (repoPath: string): Promise<boolean> => {\n const promises = fsPromises();\n if (!promises) return false;\n try {\n const st = await promises.stat(underAppRoot(repoPath.replace(/^\\/+/, '')));\n return typeof st?.isDirectory === 'function' ? Boolean(st.isDirectory()) : false;\n } catch {\n // ENOENT and friends: not a directory. Include surfaces the real error for the path.\n return false;\n }\n};\n\n/** Directories first, then files; each group by name, case-insensitively. */\nexport const sortEntries = (entries: DirectoryEntry[]): DirectoryEntry[] =>\n [...entries].sort(\n (a, b) =>\n Number(b.isDirectory) - Number(a.isDirectory) ||\n a.name.localeCompare(b.name, undefined, { sensitivity: 'base' }) ||\n a.name.localeCompare(b.name),\n );\n\nexport const pickReadme = (entries: DirectoryEntry[]): DirectoryEntry | null => {\n for (const name of README_NAMES) {\n const hit = entries.find((e) => !e.isDirectory && e.name === name);\n if (hit) return hit;\n }\n return null;\n};\n\n/** Read and shape one directory. Rejects (into the caller's error boundary) when the\n * fs is unavailable or the read fails — an empty listing would be a lie. */\nexport const readDirectoryListing = async (repoPath: string): Promise<DirectoryListing> => {\n const promises = fsPromises();\n if (!promises) throw new Error(`Cannot list ${repoPath || '/'}: the sandbox filesystem is unavailable`);\n const dir = toDirPath(repoPath);\n const raw = (await promises.readdir(underAppRoot(dir.slice(1)), { withFileTypes: true })) as Array<{\n name: string;\n isDirectory(): boolean;\n }>;\n const entries = sortEntries(\n raw.map((d) => {\n const isDirectory = d.isDirectory();\n return { name: d.name, isDirectory, path: `${dir}${d.name}${isDirectory ? '/' : ''}` };\n }),\n );\n const parent = dir === '/' ? null : toDirPath(dir.slice(0, -1).replace(/[^/]*$/, ''));\n return { dir, parent, entries, readme: pickReadme(entries)?.path ?? null };\n};\n"],"mappings":";AAOA,SAAS,iBAAiB;AAC1B,SAAS,oBAAoB;AAqB7B,MAAM,eAAe,CAAC,aAAa,cAAc,aAAa,YAAY,WAAW;AAG9E,MAAM,YAAY,CAAC,aAA6B;AACrD,QAAM,UAAU,SAAS,QAAQ,cAAc,EAAE;AACjD,SAAO,UAAU,IAAI,OAAO,MAAM;AACpC;AAGO,MAAM,iBAAiB,CAAC,aAA8B,aAAa,MAAM,SAAS,SAAS,GAAG;AAErG,MAAM,aAAa,MAAM;AACvB,QAAM,KAAK,UAAU;AACrB,SAAO,IAAI,YAAY;AACzB;AAOO,MAAM,kBAAkB,OAAO,aAAuC;AAC3E,QAAM,WAAW,WAAW;AAC5B,MAAI,CAAC,SAAU,QAAO;AACtB,MAAI;AACF,UAAM,KAAK,MAAM,SAAS,KAAK,aAAa,SAAS,QAAQ,QAAQ,EAAE,CAAC,CAAC;AACzE,WAAO,OAAO,IAAI,gBAAgB,aAAa,QAAQ,GAAG,YAAY,CAAC,IAAI;AAAA,EAC7E,QAAQ;AAEN,WAAO;AAAA,EACT;AACF;AAGO,MAAM,cAAc,CAAC,YAC1B,CAAC,GAAG,OAAO,EAAE;AAAA,EACX,CAAC,GAAG,MACF,OAAO,EAAE,WAAW,IAAI,OAAO,EAAE,WAAW,KAC5C,EAAE,KAAK,cAAc,EAAE,MAAM,QAAW,EAAE,aAAa,OAAO,CAAC,KAC/D,EAAE,KAAK,cAAc,EAAE,IAAI;AAC/B;AAEK,MAAM,aAAa,CAAC,YAAqD;AAC9E,aAAW,QAAQ,cAAc;AAC/B,UAAM,MAAM,QAAQ,KAAK,CAAC,MAAM,CAAC,EAAE,eAAe,EAAE,SAAS,IAAI;AACjE,QAAI,IAAK,QAAO;AAAA,EAClB;AACA,SAAO;AACT;AAIO,MAAM,uBAAuB,OAAO,aAAgD;AACzF,QAAM,WAAW,WAAW;AAC5B,MAAI,CAAC,SAAU,OAAM,IAAI,MAAM,eAAe,YAAY,GAAG,yCAAyC;AACtG,QAAM,MAAM,UAAU,QAAQ;AAC9B,QAAM,MAAO,MAAM,SAAS,QAAQ,aAAa,IAAI,MAAM,CAAC,CAAC,GAAG,EAAE,eAAe,KAAK,CAAC;AAIvF,QAAM,UAAU;AAAA,IACd,IAAI,IAAI,CAAC,MAAM;AACb,YAAM,cAAc,EAAE,YAAY;AAClC,aAAO,EAAE,MAAM,EAAE,MAAM,aAAa,MAAM,GAAG,GAAG,GAAG,EAAE,IAAI,GAAG,cAAc,MAAM,EAAE,GAAG;AAAA,IACvF,CAAC;AAAA,EACH;AACA,QAAM,SAAS,QAAQ,MAAM,OAAO,UAAU,IAAI,MAAM,GAAG,EAAE,EAAE,QAAQ,UAAU,EAAE,CAAC;AACpF,SAAO,EAAE,KAAK,QAAQ,SAAS,QAAQ,WAAW,OAAO,GAAG,QAAQ,KAAK;AAC3E;","names":[]}
|
|
@@ -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;AAChC,SAAO,wBAAwB,KAAK,CAAC,aAAa,MAAM,SAAS,QAAQ,CAAC;AAC5E;AAEA,MAAM,aAAa,CAAC,SAAyB,IAAI,YAAY,EAAE,OAAO,IAAI,EAAE;AAa5E,MAAM,cAAc,CAAC,SAAsC;AACzD,QAAM,SAAqB,CAAC;AAC5B,MAAI,SAAS;AACb,MAAI,UAA2B;AAC/B,MAAI,IAAI;AACR,SAAO,IAA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,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 };
|