@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 @@
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":";AAUA,SAAS,oBAAoB;AAGtB,MAAM,mBAAmB;AAGzB,MAAM,oBAAoB;AAG1B,MAAM,6BAA6B;AAGnC,MAAM,+BAA+B;AAiB5C,MAAM,UAAU,IAAI,IAAI,aAAa,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;AAA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KAAK,MAAM;AAC1C,UAAI,YAAY,UAAU;AACxB,iBAAS,KAAK,GAAG,UAAU,KAAK,SAAS,MAAM,yBAAyB;AACxE,eAAO,EAAE,MAAM,MAAM,MAAM,MAAM,OAAO,MAAM,KAAK,SAAS;AAAA,MAC9D;AACA,YAAM,OAAO,MAAM,MAAM,KAAK,SAAS,IAAI;AAC3C,UAAI,SAAS,KAAM,UAAS,KAAK,GAAG,UAAU,oBAAoB,SAAS,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,116 @@
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 proseTokensHook_exports = {};
20
+ __export(proseTokensHook_exports, {
21
+ useProseTokens: () => useProseTokens
22
+ });
23
+ module.exports = __toCommonJS(proseTokensHook_exports);
24
+ var import_react = require("react");
25
+ var import_fs = require("./fs");
26
+ var import_proseTokens = require("./proseTokens");
27
+ const warn = (message) => {
28
+ console.warn(`[immediately.run] ${message}`);
29
+ };
30
+ const isAbsent = (error) => {
31
+ const code = error?.code;
32
+ return code === "not-found" || code === "unavailable";
33
+ };
34
+ const failed = (path, error) => new Error(`${path} could not be read (${error?.code ?? String(error)})`);
35
+ const probeOf = (fs) => ({
36
+ async size(path) {
37
+ try {
38
+ const stat = await fs.stat(path);
39
+ return stat.kind === "file" ? stat.size : null;
40
+ } catch (error) {
41
+ if (isAbsent(error)) return null;
42
+ throw failed(path, error);
43
+ }
44
+ },
45
+ async read(path) {
46
+ try {
47
+ return await fs.readFile(path, "utf8");
48
+ } catch (error) {
49
+ if (isAbsent(error)) return null;
50
+ throw failed(path, error);
51
+ }
52
+ }
53
+ });
54
+ async function loadTokens(fs, startDir) {
55
+ const resolved = await (0, import_proseTokens.resolveTokenFile)(startDir, probeOf(fs));
56
+ resolved.warnings.forEach(warn);
57
+ const { path, size, watch } = resolved;
58
+ if (path === null) return { blocks: null, watch };
59
+ if (size !== null && size > import_proseTokens.PROSE_TOKEN_FILE_MAX_BYTES) {
60
+ warn(`${path} is larger than ${import_proseTokens.PROSE_TOKEN_FILE_MAX_BYTES} bytes; author tokens are off`);
61
+ return { blocks: null, watch };
62
+ }
63
+ let text;
64
+ try {
65
+ text = await probeOf(fs).read(path);
66
+ } catch (error) {
67
+ warn(`${error instanceof Error ? error.message : String(error)}; author tokens are off`);
68
+ return { blocks: null, watch };
69
+ }
70
+ if (text === null) {
71
+ warn(`${path} disappeared while it was being read; author tokens are off`);
72
+ return { blocks: null, watch };
73
+ }
74
+ const parsed = (0, import_proseTokens.parseProseTokenFile)(text);
75
+ if (!parsed.ok) {
76
+ warn(`${path} is refused because ${parsed.reason}; author tokens are off`);
77
+ return { blocks: null, watch };
78
+ }
79
+ parsed.warnings.forEach((w) => warn(`${path}: ${w}`));
80
+ return { blocks: parsed.blocks, watch };
81
+ }
82
+ function useProseTokens(filename) {
83
+ const startDir = filename === void 0 ? null : (0, import_proseTokens.dirOfFile)(filename);
84
+ const [change, setChange] = (0, import_react.useState)(0);
85
+ const [loaded, setLoaded] = (0, import_react.useState)({ blocks: null, watch: null, key: null });
86
+ (0, import_react.useEffect)(() => {
87
+ if (startDir === null) return;
88
+ let live = true;
89
+ loadTokens((0, import_fs.openAppFs)(), startDir).then(
90
+ (result) => {
91
+ if (live) setLoaded({ ...result, key: startDir });
92
+ },
93
+ (error) => {
94
+ if (!live) return;
95
+ warn(`${error instanceof Error ? error.message : String(error)}; author tokens are off`);
96
+ setLoaded({ blocks: null, watch: null, key: startDir });
97
+ }
98
+ );
99
+ return () => {
100
+ live = false;
101
+ };
102
+ }, [startDir, change]);
103
+ const watchedPath = loaded.key === startDir ? loaded.watch : null;
104
+ (0, import_react.useEffect)(() => {
105
+ if (startDir === null) return;
106
+ return (0, import_fs.openAppFs)().onChange((paths) => {
107
+ if (paths.some((p) => (0, import_proseTokens.affectsTokenLookup)(p, startDir, watchedPath))) setChange((n) => n + 1);
108
+ });
109
+ }, [startDir, watchedPath]);
110
+ return loaded.key === startDir ? loaded.blocks : null;
111
+ }
112
+ // Annotate the CommonJS export names for ESM import in node:
113
+ 0 && (module.exports = {
114
+ useProseTokens
115
+ });
116
+ //# sourceMappingURL=proseTokensHook.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/proseTokensHook.ts"],"sourcesContent":["// The I/O half of the author token file (MARKDOWN_SYNTAX_SPEC §16.6): read the file the\n// lookup resolves for a routed Markdown file, and re-read it when the file, or a marker on\n// the walked path, changes. The parse and the lookup are pure, in `proseTokens.ts`.\n\nimport { useEffect, useState } from 'react';\n\nimport { openAppFs, type MountFs } from './fs';\nimport {\n affectsTokenLookup,\n dirOfFile,\n parseProseTokenFile,\n PROSE_TOKEN_FILE_MAX_BYTES,\n resolveTokenFile,\n type ProseTokenBlocks,\n type ProseTokenProbe,\n} from './proseTokens';\n\nconst warn = (message: string): void => {\n console.warn(`[immediately.run] ${message}`);\n};\n\n/**\n * \"No file here\" is a missing path, a directory, or no sandbox fs at all. Any other error\n * (a failed read, a permission error) is not an absence: it propagates with the path named,\n * and the hook warns rather than quietly dropping a marker's boundary or a token file.\n */\nconst isAbsent = (error: unknown): boolean => {\n const code = (error as { code?: unknown } | null)?.code;\n return code === 'not-found' || code === 'unavailable';\n};\n\nconst failed = (path: string, error: unknown): Error =>\n new Error(`${path} could not be read (${(error as { code?: unknown } | null)?.code ?? String(error)})`);\n\nconst probeOf = (fs: MountFs): ProseTokenProbe => ({\n async size(path) {\n try {\n const stat = await fs.stat(path);\n return stat.kind === 'file' ? stat.size : null;\n } catch (error) {\n if (isAbsent(error)) return null;\n throw failed(path, error);\n }\n },\n async read(path) {\n try {\n return await fs.readFile(path, 'utf8');\n } catch (error) {\n if (isAbsent(error)) return null;\n throw failed(path, error);\n }\n },\n});\n\ninterface Loaded {\n readonly blocks: ProseTokenBlocks | null;\n /** The token file to re-run the lookup for when it changes (`ResolvedTokenFile.watch`). */\n readonly watch: string | null;\n}\n\n/** Resolve, size-check, read and parse. Every refusal warns and yields no tokens. */\nasync function loadTokens(fs: MountFs, startDir: string): Promise<Loaded> {\n const resolved = await resolveTokenFile(startDir, probeOf(fs));\n resolved.warnings.forEach(warn);\n const { path, size, watch } = resolved;\n if (path === null) return { blocks: null, watch };\n if (size !== null && size > PROSE_TOKEN_FILE_MAX_BYTES) {\n warn(`${path} is larger than ${PROSE_TOKEN_FILE_MAX_BYTES} bytes; author tokens are off`);\n return { blocks: null, watch };\n }\n let text: string | null;\n try {\n text = await probeOf(fs).read(path);\n } catch (error) {\n // Keep the watch: fixing the file must restyle the page, even a `styles`-named one.\n warn(`${error instanceof Error ? error.message : String(error)}; author tokens are off`);\n return { blocks: null, watch };\n }\n if (text === null) {\n // Present at the lookup, gone at the read: a delete raced it, and its change re-runs us.\n warn(`${path} disappeared while it was being read; author tokens are off`);\n return { blocks: null, watch };\n }\n const parsed = parseProseTokenFile(text);\n if (!parsed.ok) {\n warn(`${path} is refused because ${parsed.reason}; author tokens are off`);\n return { blocks: null, watch };\n }\n parsed.warnings.forEach((w) => warn(`${path}: ${w}`));\n return { blocks: parsed.blocks, watch };\n}\n\n/**\n * The author token values for a routed Markdown file (repo-relative path), or `null` while\n * none apply or before the first read settles — the page renders with the defaults\n * meanwhile and is never suspended on the token file. `undefined` reads nothing.\n */\nexport function useProseTokens(filename: string | undefined): ProseTokenBlocks | null {\n const startDir = filename === undefined ? null : dirOfFile(filename);\n const [change, setChange] = useState(0);\n const [loaded, setLoaded] = useState<Loaded & { key: string | null }>({ blocks: null, watch: null, key: null });\n\n // One read per (directory, change). A result that lands after unmount, or after a newer\n // read has started, is dropped.\n useEffect(() => {\n if (startDir === null) return;\n let live = true;\n loadTokens(openAppFs(), startDir).then(\n (result) => {\n if (live) setLoaded({ ...result, key: startDir });\n },\n (error: unknown) => {\n if (!live) return;\n warn(`${error instanceof Error ? error.message : String(error)}; author tokens are off`);\n setLoaded({ blocks: null, watch: null, key: startDir });\n },\n );\n return () => {\n live = false;\n };\n }, [startDir, change]);\n\n const watchedPath = loaded.key === startDir ? loaded.watch : null;\n useEffect(() => {\n if (startDir === null) return;\n return openAppFs().onChange((paths) => {\n if (paths.some((p) => affectsTokenLookup(p, startDir, watchedPath))) setChange((n) => n + 1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,OAAO,MAAM,KAAK,SAAS,CAAC;AAAA,MACxD;AAAA,IACF;AACA,WAAO,MAAM;AACX,aAAO;AAAA,IACT;AAAA,EACF,GAAG,CAAC,UAAU,MAAM,CAAC;AAErB,QAAM,cAAc,OAAO,QAAQ,WAAW,OAAO,QAAQ;AAC7D,8BAAU,MAAM;AACd,QAAI,aAAa,KAAM;AACvB,eAAO,qBAAU,EAAE,SAAS,CAAC,UAAU;AACrC,UAAI,MAAM,KAAK,CAAC,UAAM,uCAAmB,GAAG,UAAU,WAAW,CAAC,EAAG,WAAU,CAAC,MAAM,IAAI,CAAC;AAAA,IAC7F,CAAC;AAAA,EACH,GAAG,CAAC,UAAU,WAAW,CAAC;AAE1B,SAAO,OAAO,QAAQ,WAAW,OAAO,SAAS;AACnD;","names":[]}
@@ -0,0 +1,10 @@
1
+ import { ProseTokenBlocks } from './proseTokens.cjs';
2
+
3
+ /**
4
+ * The author token values for a routed Markdown file (repo-relative path), or `null` while
5
+ * none apply or before the first read settles — the page renders with the defaults
6
+ * meanwhile and is never suspended on the token file. `undefined` reads nothing.
7
+ */
8
+ declare function useProseTokens(filename: string | undefined): ProseTokenBlocks | null;
9
+
10
+ export { useProseTokens };
@@ -0,0 +1,10 @@
1
+ import { ProseTokenBlocks } from './proseTokens.js';
2
+
3
+ /**
4
+ * The author token values for a routed Markdown file (repo-relative path), or `null` while
5
+ * none apply or before the first read settles — the page renders with the defaults
6
+ * meanwhile and is never suspended on the token file. `undefined` reads nothing.
7
+ */
8
+ declare function useProseTokens(filename: string | undefined): ProseTokenBlocks | null;
9
+
10
+ export { useProseTokens };
@@ -0,0 +1,99 @@
1
+ import "./chunk-VHAA22YE.js";
2
+ import { useEffect, useState } from "react";
3
+ import { openAppFs } from "./fs.js";
4
+ import {
5
+ affectsTokenLookup,
6
+ dirOfFile,
7
+ parseProseTokenFile,
8
+ PROSE_TOKEN_FILE_MAX_BYTES,
9
+ resolveTokenFile
10
+ } from "./proseTokens.js";
11
+ const warn = (message) => {
12
+ console.warn(`[immediately.run] ${message}`);
13
+ };
14
+ const isAbsent = (error) => {
15
+ const code = error?.code;
16
+ return code === "not-found" || code === "unavailable";
17
+ };
18
+ const failed = (path, error) => new Error(`${path} could not be read (${error?.code ?? String(error)})`);
19
+ const probeOf = (fs) => ({
20
+ async size(path) {
21
+ try {
22
+ const stat = await fs.stat(path);
23
+ return stat.kind === "file" ? stat.size : null;
24
+ } catch (error) {
25
+ if (isAbsent(error)) return null;
26
+ throw failed(path, error);
27
+ }
28
+ },
29
+ async read(path) {
30
+ try {
31
+ return await fs.readFile(path, "utf8");
32
+ } catch (error) {
33
+ if (isAbsent(error)) return null;
34
+ throw failed(path, error);
35
+ }
36
+ }
37
+ });
38
+ async function loadTokens(fs, startDir) {
39
+ const resolved = await resolveTokenFile(startDir, probeOf(fs));
40
+ resolved.warnings.forEach(warn);
41
+ const { path, size, watch } = resolved;
42
+ if (path === null) return { blocks: null, watch };
43
+ if (size !== null && size > PROSE_TOKEN_FILE_MAX_BYTES) {
44
+ warn(`${path} is larger than ${PROSE_TOKEN_FILE_MAX_BYTES} bytes; author tokens are off`);
45
+ return { blocks: null, watch };
46
+ }
47
+ let text;
48
+ try {
49
+ text = await probeOf(fs).read(path);
50
+ } catch (error) {
51
+ warn(`${error instanceof Error ? error.message : String(error)}; author tokens are off`);
52
+ return { blocks: null, watch };
53
+ }
54
+ if (text === null) {
55
+ warn(`${path} disappeared while it was being read; author tokens are off`);
56
+ return { blocks: null, watch };
57
+ }
58
+ const parsed = parseProseTokenFile(text);
59
+ if (!parsed.ok) {
60
+ warn(`${path} is refused because ${parsed.reason}; author tokens are off`);
61
+ return { blocks: null, watch };
62
+ }
63
+ parsed.warnings.forEach((w) => warn(`${path}: ${w}`));
64
+ return { blocks: parsed.blocks, watch };
65
+ }
66
+ function useProseTokens(filename) {
67
+ const startDir = filename === void 0 ? null : dirOfFile(filename);
68
+ const [change, setChange] = useState(0);
69
+ const [loaded, setLoaded] = useState({ blocks: null, watch: null, key: null });
70
+ useEffect(() => {
71
+ if (startDir === null) return;
72
+ let live = true;
73
+ loadTokens(openAppFs(), startDir).then(
74
+ (result) => {
75
+ if (live) setLoaded({ ...result, key: startDir });
76
+ },
77
+ (error) => {
78
+ if (!live) return;
79
+ warn(`${error instanceof Error ? error.message : String(error)}; author tokens are off`);
80
+ setLoaded({ blocks: null, watch: null, key: startDir });
81
+ }
82
+ );
83
+ return () => {
84
+ live = false;
85
+ };
86
+ }, [startDir, change]);
87
+ const watchedPath = loaded.key === startDir ? loaded.watch : null;
88
+ useEffect(() => {
89
+ if (startDir === null) return;
90
+ return openAppFs().onChange((paths) => {
91
+ if (paths.some((p) => affectsTokenLookup(p, startDir, watchedPath))) setChange((n) => n + 1);
92
+ });
93
+ }, [startDir, watchedPath]);
94
+ return loaded.key === startDir ? loaded.blocks : null;
95
+ }
96
+ export {
97
+ useProseTokens
98
+ };
99
+ //# sourceMappingURL=proseTokensHook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/proseTokensHook.ts"],"sourcesContent":["// The I/O half of the author token file (MARKDOWN_SYNTAX_SPEC §16.6): read the file the\n// lookup resolves for a routed Markdown file, and re-read it when the file, or a marker on\n// the walked path, changes. The parse and the lookup are pure, in `proseTokens.ts`.\n\nimport { useEffect, useState } from 'react';\n\nimport { openAppFs, type MountFs } from './fs';\nimport {\n affectsTokenLookup,\n dirOfFile,\n parseProseTokenFile,\n PROSE_TOKEN_FILE_MAX_BYTES,\n resolveTokenFile,\n type ProseTokenBlocks,\n type ProseTokenProbe,\n} from './proseTokens';\n\nconst warn = (message: string): void => {\n console.warn(`[immediately.run] ${message}`);\n};\n\n/**\n * \"No file here\" is a missing path, a directory, or no sandbox fs at all. Any other error\n * (a failed read, a permission error) is not an absence: it propagates with the path named,\n * and the hook warns rather than quietly dropping a marker's boundary or a token file.\n */\nconst isAbsent = (error: unknown): boolean => {\n const code = (error as { code?: unknown } | null)?.code;\n return code === 'not-found' || code === 'unavailable';\n};\n\nconst failed = (path: string, error: unknown): Error =>\n new Error(`${path} could not be read (${(error as { code?: unknown } | null)?.code ?? String(error)})`);\n\nconst probeOf = (fs: MountFs): ProseTokenProbe => ({\n async size(path) {\n try {\n const stat = await fs.stat(path);\n return stat.kind === 'file' ? stat.size : null;\n } catch (error) {\n if (isAbsent(error)) return null;\n throw failed(path, error);\n }\n },\n async read(path) {\n try {\n return await fs.readFile(path, 'utf8');\n } catch (error) {\n if (isAbsent(error)) return null;\n throw failed(path, error);\n }\n },\n});\n\ninterface Loaded {\n readonly blocks: ProseTokenBlocks | null;\n /** The token file to re-run the lookup for when it changes (`ResolvedTokenFile.watch`). */\n readonly watch: string | null;\n}\n\n/** Resolve, size-check, read and parse. Every refusal warns and yields no tokens. */\nasync function loadTokens(fs: MountFs, startDir: string): Promise<Loaded> {\n const resolved = await resolveTokenFile(startDir, probeOf(fs));\n resolved.warnings.forEach(warn);\n const { path, size, watch } = resolved;\n if (path === null) return { blocks: null, watch };\n if (size !== null && size > PROSE_TOKEN_FILE_MAX_BYTES) {\n warn(`${path} is larger than ${PROSE_TOKEN_FILE_MAX_BYTES} bytes; author tokens are off`);\n return { blocks: null, watch };\n }\n let text: string | null;\n try {\n text = await probeOf(fs).read(path);\n } catch (error) {\n // Keep the watch: fixing the file must restyle the page, even a `styles`-named one.\n warn(`${error instanceof Error ? error.message : String(error)}; author tokens are off`);\n return { blocks: null, watch };\n }\n if (text === null) {\n // Present at the lookup, gone at the read: a delete raced it, and its change re-runs us.\n warn(`${path} disappeared while it was being read; author tokens are off`);\n return { blocks: null, watch };\n }\n const parsed = parseProseTokenFile(text);\n if (!parsed.ok) {\n warn(`${path} is refused because ${parsed.reason}; author tokens are off`);\n return { blocks: null, watch };\n }\n parsed.warnings.forEach((w) => warn(`${path}: ${w}`));\n return { blocks: parsed.blocks, watch };\n}\n\n/**\n * The author token values for a routed Markdown file (repo-relative path), or `null` while\n * none apply or before the first read settles — the page renders with the defaults\n * meanwhile and is never suspended on the token file. `undefined` reads nothing.\n */\nexport function useProseTokens(filename: string | undefined): ProseTokenBlocks | null {\n const startDir = filename === undefined ? null : dirOfFile(filename);\n const [change, setChange] = useState(0);\n const [loaded, setLoaded] = useState<Loaded & { key: string | null }>({ blocks: null, watch: null, key: null });\n\n // One read per (directory, change). A result that lands after unmount, or after a newer\n // read has started, is dropped.\n useEffect(() => {\n if (startDir === null) return;\n let live = true;\n loadTokens(openAppFs(), startDir).then(\n (result) => {\n if (live) setLoaded({ ...result, key: startDir });\n },\n (error: unknown) => {\n if (!live) return;\n warn(`${error instanceof Error ? error.message : String(error)}; author tokens are off`);\n setLoaded({ blocks: null, watch: null, key: startDir });\n },\n );\n return () => {\n live = false;\n };\n }, [startDir, change]);\n\n const watchedPath = loaded.key === startDir ? loaded.watch : null;\n useEffect(() => {\n if (startDir === null) return;\n return openAppFs().onChange((paths) => {\n if (paths.some((p) => affectsTokenLookup(p, startDir, watchedPath))) setChange((n) => n + 1);\n });\n }, [startDir, watchedPath]);\n\n return loaded.key === startDir ? loaded.blocks : null;\n}\n"],"mappings":";AAIA,SAAS,WAAW,gBAAgB;AAEpC,SAAS,iBAA+B;AACxC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AAEP,MAAM,OAAO,CAAC,YAA0B;AACtC,UAAQ,KAAK,qBAAqB,OAAO,EAAE;AAC7C;AAOA,MAAM,WAAW,CAAC,UAA4B;AAC5C,QAAM,OAAQ,OAAqC;AACnD,SAAO,SAAS,eAAe,SAAS;AAC1C;AAEA,MAAM,SAAS,CAAC,MAAc,UAC5B,IAAI,MAAM,GAAG,IAAI,uBAAwB,OAAqC,QAAQ,OAAO,KAAK,CAAC,GAAG;AAExG,MAAM,UAAU,CAAC,QAAkC;AAAA,EACjD,MAAM,KAAK,MAAM;AACf,QAAI;AACF,YAAM,OAAO,MAAM,GAAG,KAAK,IAAI;AAC/B,aAAO,KAAK,SAAS,SAAS,KAAK,OAAO;AAAA,IAC5C,S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,SAAO,EAAE,QAAQ,OAAO,QAAQ,MAAM;AACxC;AAOO,SAAS,eAAe,UAAuD;AACpF,QAAM,WAAW,aAAa,SAAY,OAAO,UAAU,QAAQ;AACnE,QAAM,CAAC,QAAQ,SAAS,IAAI,SAAS,CAAC;AACtC,QAAM,CAAC,QAAQ,SAAS,IAAI,SAA0C,EAAE,QAAQ,MAAM,OAAO,MAAM,KAAK,KAAK,CAAC;AAI9G,YAAU,MAAM;AACd,QAAI,aAAa,KAAM;AACvB,QAAI,OAAO;AACX,eAAW,UAAU,GAAG,QAAQ,EAAE;AAAA,MAChC,CAAC,WAAW;AACV,YAAI,KAAM,WAAU,EAAE,GAAG,QAAQ,KAAK,SAAS,CAAC;AAAA,MAClD;AAAA,MACA,CAAC,UAAmB;AAClB,YAAI,CAAC,KAAM;AACX,aAAK,GAAG,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC,yBAAyB;AACvF,kBAAU,EAAE,QAAQ,MAAM,OAAO,MAAM,KAAK,SAAS,CAAC;AAAA,MACxD;AAAA,IACF;AACA,WAAO,MAAM;AACX,aAAO;AAAA,IACT;AAAA,EACF,GAAG,CAAC,UAAU,MAAM,CAAC;AAErB,QAAM,cAAc,OAAO,QAAQ,WAAW,OAAO,QAAQ;AAC7D,YAAU,MAAM;AACd,QAAI,aAAa,KAAM;AACvB,WAAO,UAAU,EAAE,SAAS,CAAC,UAAU;AACrC,UAAI,MAAM,KAAK,CAAC,MAAM,mBAAmB,GAAG,UAAU,WAAW,CAAC,EAAG,WAAU,CAAC,MAAM,IAAI,CAAC;AAAA,IAC7F,CAAC;AAAA,EACH,GAAG,CAAC,UAAU,WAAW,CAAC;AAE1B,SAAO,OAAO,QAAQ,WAAW,OAAO,SAAS;AACnD;","names":[]}
@@ -0,0 +1,37 @@
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 styleElement_exports = {};
20
+ __export(styleElement_exports, {
21
+ ensureStyleElement: () => ensureStyleElement
22
+ });
23
+ module.exports = __toCommonJS(styleElement_exports);
24
+ function ensureStyleElement(id, text, options = {}) {
25
+ if (typeof document === "undefined") return;
26
+ if (document.getElementById(id)) return;
27
+ const el = document.createElement("style");
28
+ el.id = id;
29
+ el.textContent = text;
30
+ if (options.first) document.head.prepend(el);
31
+ else document.head.appendChild(el);
32
+ }
33
+ // Annotate the CommonJS export names for ESM import in node:
34
+ 0 && (module.exports = {
35
+ ensureStyleElement
36
+ });
37
+ //# sourceMappingURL=styleElement.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/styleElement.ts"],"sourcesContent":["// The one inject-once `<style>` guard the SDK's self-styling components share\n// (`loading.tsx`, `proseStyles.ts`). A published library cannot import a CSS file in the\n// sandbox — the bundler evaluates a dist CSS import as JavaScript — so each stylesheet is\n// text the component injects itself.\n\n/**\n * Insert `<style id={id}>{text}</style>` into `<head>` unless one with that id exists.\n * Idempotent and browser-only (a no-op without `document`).\n *\n * `first: true` puts it before every other stylesheet. A sheet whose rules sit in a\n * cascade layer needs that: layers rank by the order they first appear, later layers\n * winning, so an appended layered sheet would outrank the app's own layers.\n */\nexport function ensureStyleElement(id: string, text: string, options: { first?: boolean } = {}): void {\n if (typeof document === 'undefined') return;\n if (document.getElementById(id)) return;\n const el = document.createElement('style');\n el.id = id;\n el.textContent = text;\n if (options.first) document.head.prepend(el);\n else document.head.appendChild(el);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAaO,SAAS,mBAAmB,IAAY,MAAc,UAA+B,CAAC,GAAS;AACpG,MAAI,OAAO,aAAa,YAAa;AACrC,MAAI,SAAS,eAAe,EAAE,EAAG;AACjC,QAAM,KAAK,SAAS,cAAc,OAAO;AACzC,KAAG,KAAK;AACR,KAAG,cAAc;AACjB,MAAI,QAAQ,MAAO,UAAS,KAAK,QAAQ,EAAE;AAAA,MACtC,UAAS,KAAK,YAAY,EAAE;AACnC;","names":[]}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Insert `<style id={id}>{text}</style>` into `<head>` unless one with that id exists.
3
+ * Idempotent and browser-only (a no-op without `document`).
4
+ *
5
+ * `first: true` puts it before every other stylesheet. A sheet whose rules sit in a
6
+ * cascade layer needs that: layers rank by the order they first appear, later layers
7
+ * winning, so an appended layered sheet would outrank the app's own layers.
8
+ */
9
+ declare function ensureStyleElement(id: string, text: string, options?: {
10
+ first?: boolean;
11
+ }): void;
12
+
13
+ export { ensureStyleElement };
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Insert `<style id={id}>{text}</style>` into `<head>` unless one with that id exists.
3
+ * Idempotent and browser-only (a no-op without `document`).
4
+ *
5
+ * `first: true` puts it before every other stylesheet. A sheet whose rules sit in a
6
+ * cascade layer needs that: layers rank by the order they first appear, later layers
7
+ * winning, so an appended layered sheet would outrank the app's own layers.
8
+ */
9
+ declare function ensureStyleElement(id: string, text: string, options?: {
10
+ first?: boolean;
11
+ }): void;
12
+
13
+ export { ensureStyleElement };
@@ -0,0 +1,14 @@
1
+ import "./chunk-VHAA22YE.js";
2
+ function ensureStyleElement(id, text, options = {}) {
3
+ if (typeof document === "undefined") return;
4
+ if (document.getElementById(id)) return;
5
+ const el = document.createElement("style");
6
+ el.id = id;
7
+ el.textContent = text;
8
+ if (options.first) document.head.prepend(el);
9
+ else document.head.appendChild(el);
10
+ }
11
+ export {
12
+ ensureStyleElement
13
+ };
14
+ //# sourceMappingURL=styleElement.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/styleElement.ts"],"sourcesContent":["// The one inject-once `<style>` guard the SDK's self-styling components share\n// (`loading.tsx`, `proseStyles.ts`). A published library cannot import a CSS file in the\n// sandbox — the bundler evaluates a dist CSS import as JavaScript — so each stylesheet is\n// text the component injects itself.\n\n/**\n * Insert `<style id={id}>{text}</style>` into `<head>` unless one with that id exists.\n * Idempotent and browser-only (a no-op without `document`).\n *\n * `first: true` puts it before every other stylesheet. A sheet whose rules sit in a\n * cascade layer needs that: layers rank by the order they first appear, later layers\n * winning, so an appended layered sheet would outrank the app's own layers.\n */\nexport function ensureStyleElement(id: string, text: string, options: { first?: boolean } = {}): void {\n if (typeof document === 'undefined') return;\n if (document.getElementById(id)) return;\n const el = document.createElement('style');\n el.id = id;\n el.textContent = text;\n if (options.first) document.head.prepend(el);\n else document.head.appendChild(el);\n}\n"],"mappings":";AAaO,SAAS,mBAAmB,IAAY,MAAc,UAA+B,CAAC,GAAS;AACpG,MAAI,OAAO,aAAa,YAAa;AACrC,MAAI,SAAS,eAAe,EAAE,EAAG;AACjC,QAAM,KAAK,SAAS,cAAc,OAAO;AACzC,KAAG,KAAK;AACR,KAAG,cAAc;AACjB,MAAI,QAAQ,MAAO,UAAS,KAAK,QAAQ,EAAE;AAAA,MACtC,UAAS,KAAK,YAAY,EAAE;AACnC;","names":[]}
package/dist/version.cjs CHANGED
@@ -21,7 +21,7 @@ __export(version_exports, {
21
21
  SDK_VERSION: () => SDK_VERSION
22
22
  });
23
23
  module.exports = __toCommonJS(version_exports);
24
- const SDK_VERSION = "0.94.0";
24
+ const SDK_VERSION = "0.96.0";
25
25
  // Annotate the CommonJS export names for ESM import in node:
26
26
  0 && (module.exports = {
27
27
  SDK_VERSION
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/version.ts"],"sourcesContent":["// GENERATED by scripts/gen-version.mjs from package.json — do not edit by hand.\n// Regenerated on every build (prebuild); kept honest by version.test.ts.\n\n/** This SDK's package version, baked from package.json at build (SP2-6). */\nexport const SDK_VERSION = '0.94.0';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIO,MAAM,cAAc;","names":[]}
1
+ {"version":3,"sources":["../src/version.ts"],"sourcesContent":["// GENERATED by scripts/gen-version.mjs from package.json — do not edit by hand.\n// Regenerated on every build (prebuild); kept honest by version.test.ts.\n\n/** This SDK's package version, baked from package.json at build (SP2-6). */\nexport const SDK_VERSION = '0.96.0';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIO,MAAM,cAAc;","names":[]}
@@ -1,4 +1,4 @@
1
1
  /** This SDK's package version, baked from package.json at build (SP2-6). */
2
- declare const SDK_VERSION = "0.94.0";
2
+ declare const SDK_VERSION = "0.96.0";
3
3
 
4
4
  export { SDK_VERSION };
package/dist/version.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  /** This SDK's package version, baked from package.json at build (SP2-6). */
2
- declare const SDK_VERSION = "0.94.0";
2
+ declare const SDK_VERSION = "0.96.0";
3
3
 
4
4
  export { SDK_VERSION };
package/dist/version.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./chunk-VHAA22YE.js";
2
- const SDK_VERSION = "0.94.0";
2
+ const SDK_VERSION = "0.96.0";
3
3
  export {
4
4
  SDK_VERSION
5
5
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/version.ts"],"sourcesContent":["// GENERATED by scripts/gen-version.mjs from package.json — do not edit by hand.\n// Regenerated on every build (prebuild); kept honest by version.test.ts.\n\n/** This SDK's package version, baked from package.json at build (SP2-6). */\nexport const SDK_VERSION = '0.94.0';\n"],"mappings":";AAIO,MAAM,cAAc;","names":[]}
1
+ {"version":3,"sources":["../src/version.ts"],"sourcesContent":["// GENERATED by scripts/gen-version.mjs from package.json — do not edit by hand.\n// Regenerated on every build (prebuild); kept honest by version.test.ts.\n\n/** This SDK's package version, baked from package.json at build (SP2-6). */\nexport const SDK_VERSION = '0.96.0';\n"],"mappings":";AAIO,MAAM,cAAc;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@immediately-run/sdk",
3
- "version": "0.94.0",
3
+ "version": "0.96.0",
4
4
  "description": "Runtime SDK for code executing inside an immediately.run sandbox.",
5
5
  "license": "MIT",
6
6
  "repository": "github:immediately-run/immediately-run-sdk",