@inkandswitch/patchwork-pkg-base 0.0.100 → 0.0.102

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 (91) hide show
  1. package/module-settings-url +1 -1
  2. package/package.json +1 -1
  3. package/packages/account/dist/index.css +32 -32
  4. package/packages/account/dist/index.css.map +2 -2
  5. package/packages/account-history/dist/assets/HistoryRecorder-_3PrVW6n.js +1 -1
  6. package/packages/account-history/dist/assets/HistoryViewer-BmG0rAfK.js +1 -1
  7. package/packages/account-history/dist/assets/NotebookViewer-DZ_ZQU5x.js +37 -37
  8. package/packages/add-doc-to-sidebar-button/styles.css +2 -2
  9. package/packages/chat/dist/{ChatRoot-BYmq4SXi.js → ChatRoot-1d-658Rr.js} +2 -2
  10. package/packages/chat/dist/{context-tool-Bob-FZ_T.js → context-tool-iP64Oz6H.js} +2 -2
  11. package/packages/chat/dist/{index-wkaHcVCz.js → index-Dm_2jZcu.js} +3 -3
  12. package/packages/chat/dist/index.js +2 -2
  13. package/packages/chat/dist/{tool-DCOdh_fx.js → tool-BmNd5mrj.js} +1 -1
  14. package/packages/codemirror-base/dist/{chunk-QRT4ZVQ4.js → chunk-A2WBDY3J.js} +5 -5
  15. package/packages/codemirror-base/dist/{chunk-QRT4ZVQ4.js.map → chunk-A2WBDY3J.js.map} +1 -1
  16. package/packages/codemirror-base/dist/lib/codemirror.js +1 -1
  17. package/packages/codemirror-base/dist/tool.js +3 -3
  18. package/packages/codemirror-base/dist/tool.js.map +1 -1
  19. package/packages/codemirror-markdown/dist/extensions/embed.js +1 -1
  20. package/packages/codemirror-markdown/dist/extensions/embed.js.map +1 -1
  21. package/packages/codemirror-markdown/dist/extensions/links.js +1 -1
  22. package/packages/codemirror-markdown/dist/extensions/links.js.map +1 -1
  23. package/packages/codemirror-markdown/dist/extensions/markdown.js +6 -6
  24. package/packages/codemirror-markdown/dist/extensions/markdown.js.map +1 -1
  25. package/packages/commands/dist/main.js +1 -1
  26. package/packages/commands/dist/main.js.map +1 -1
  27. package/packages/comments-view/dist/assets/main-wSSvAVfi.js +1 -1
  28. package/packages/doc-openwith/doc-openwith.js +5 -5
  29. package/packages/doc-presence/doc-presence.js +1 -1
  30. package/packages/drafts/dist/assets/main-CG9HOCai.js +31 -31
  31. package/packages/embed/dist/assets/tool-D58NGTZ7.js +1 -1
  32. package/packages/file/dist/index.js +2 -2
  33. package/packages/file/dist/{new-file-tool-DGKllnzw.js → new-file-tool-BolBDUrL.js} +27 -27
  34. package/packages/file/dist/new-file-tool-BolBDUrL.js.map +1 -0
  35. package/packages/file/dist/{tool-UKWDK93W.js → tool-Bt8I8T2-.js} +4 -4
  36. package/packages/file/dist/tool-Bt8I8T2-.js.map +1 -0
  37. package/packages/file/dist/{typescript-language-server-BgBx0vSF.js → typescript-language-server-Db4173Y5.js} +2 -2
  38. package/packages/file/dist/{typescript-language-server-BgBx0vSF.js.map → typescript-language-server-Db4173Y5.js.map} +1 -1
  39. package/packages/folder/dist/index.js +1 -1
  40. package/packages/folder/dist/{tool-WAWTPB4A.js → tool-5E3YPGES.js} +2 -2
  41. package/packages/folder/dist/{tool-WAWTPB4A.js.map → tool-5E3YPGES.js.map} +1 -1
  42. package/packages/history-view/dist/assets/{HistoryTimeline-COYNGORP.js → HistoryTimeline-Bo-BTf2A.js} +6 -6
  43. package/packages/history-view/dist/assets/{HistoryTimeline-COYNGORP.js.map → HistoryTimeline-Bo-BTf2A.js.map} +1 -1
  44. package/packages/history-view/dist/assets/{index-C1gYt7m5.js → index-B5Afrk9Y.js} +2 -2
  45. package/packages/history-view/dist/assets/{index-C1gYt7m5.js.map → index-B5Afrk9Y.js.map} +1 -1
  46. package/packages/history-view/dist/index.js +1 -1
  47. package/packages/llm-host/dist/{LlmConfigTray-DdZHZT4F.js → LlmConfigTray-CjW04jeT.js} +108 -108
  48. package/packages/llm-host/dist/index.js +1 -1
  49. package/packages/packages/dist/index.js +46 -46
  50. package/packages/patternwitch/tool.js +21 -0
  51. package/packages/raw/raw-editor.js +22 -22
  52. package/packages/settings/dist/assets/FrameConfigurator-DVRBzIR-.js +1 -1
  53. package/packages/sideboard/dist/index.css +1 -1
  54. package/packages/sideboard/dist/index.css.map +2 -2
  55. package/packages/sideboard/dist/index.js +1 -1
  56. package/packages/sync-indicator/dist/assets/{SyncIndicator-B2ag1OoZ.js → SyncIndicator-oVMcVRXg.js} +3 -3
  57. package/packages/sync-indicator/dist/assets/{SyncIndicator-B2ag1OoZ.js.map → SyncIndicator-oVMcVRXg.js.map} +1 -1
  58. package/packages/sync-indicator/dist/index.js +1 -1
  59. package/packages/tasks/dist/assets/index-BbuRtBN3.js +1 -1
  60. package/packages/theming/dist/{active-theme-BMSIQXBV.js → active-theme-CC3CS64F.js} +2 -2
  61. package/packages/theming/dist/{chunk-Z3JB7ERH.js → chunk-DH4YUYFJ.js} +2 -2
  62. package/packages/theming/dist/chunk-VJZ4NPK4.js +136 -0
  63. package/packages/theming/dist/chunk-VJZ4NPK4.js.map +7 -0
  64. package/packages/theming/dist/main.js +4 -4
  65. package/packages/theming/dist/{theme-7OG2K56L.css → theme-HE7ECLIW.css} +212 -58
  66. package/packages/theming/dist/{theme-editor-datatype-TMYH7U2S.js → theme-editor-datatype-TJ6LYT2U.js} +2 -2
  67. package/packages/theming/dist/theme-editor.js +35 -25
  68. package/packages/theming/dist/theme-editor.js.map +2 -2
  69. package/packages/theming/dist/{theme-titlebar-YIFJINPJ.js → theme-titlebar-BO2Y2GRN.js} +2 -2
  70. package/packages/theming/dist/{theme-tray-7J247NRY.js → theme-tray-V6BEXQWR.js} +15 -15
  71. package/packages/theming/dist/theme-tray-V6BEXQWR.js.map +7 -0
  72. package/packages/theming/dist/tool.js +9 -9
  73. package/packages/theming/dist/tool.js.map +1 -1
  74. package/packages/threepane/dist/IsolatedDocumentArea-IZWZ74TV.js +2 -0
  75. package/packages/threepane/dist/{PatchworkFrame-GEEBBGCS.js → PatchworkFrame-UNWWAISP.js} +2 -2
  76. package/packages/threepane/dist/{chunk-YC5AHP5G.js → chunk-MSZ7JVNB.js} +31 -31
  77. package/packages/threepane/dist/{chunk-YC5AHP5G.js.map → chunk-MSZ7JVNB.js.map} +3 -3
  78. package/packages/threepane/dist/index.js +1 -1
  79. package/plugin-registry-url +1 -1
  80. package/packages/file/dist/new-file-tool-DGKllnzw.js.map +0 -1
  81. package/packages/file/dist/tool-UKWDK93W.js.map +0 -1
  82. package/packages/theming/dist/chunk-GIPQLUDU.js +0 -86
  83. package/packages/theming/dist/chunk-GIPQLUDU.js.map +0 -7
  84. package/packages/theming/dist/theme-tray-7J247NRY.js.map +0 -7
  85. package/packages/threepane/dist/IsolatedDocumentArea-G3V7KYHJ.js +0 -2
  86. /package/packages/theming/dist/{active-theme-BMSIQXBV.js.map → active-theme-CC3CS64F.js.map} +0 -0
  87. /package/packages/theming/dist/{chunk-Z3JB7ERH.js.map → chunk-DH4YUYFJ.js.map} +0 -0
  88. /package/packages/theming/dist/{theme-editor-datatype-TMYH7U2S.js.map → theme-editor-datatype-TJ6LYT2U.js.map} +0 -0
  89. /package/packages/theming/dist/{theme-titlebar-YIFJINPJ.js.map → theme-titlebar-BO2Y2GRN.js.map} +0 -0
  90. /package/packages/threepane/dist/{IsolatedDocumentArea-G3V7KYHJ.js.map → IsolatedDocumentArea-IZWZ74TV.js.map} +0 -0
  91. /package/packages/threepane/dist/{PatchworkFrame-GEEBBGCS.js.map → PatchworkFrame-UNWWAISP.js.map} +0 -0
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/extensions/embed.ts", "../../src/themes/embed.ts"],
4
- "sourcesContent": ["import {\n EditorView,\n Decoration,\n WidgetType,\n ViewPlugin,\n ViewUpdate,\n dropCursor,\n type DecorationSet,\n} from \"@codemirror/view\";\nimport { Range } from \"@codemirror/state\";\nimport {\n type AutomergeUrl,\n type DocumentId,\n isValidDocumentId,\n parseAutomergeUrl,\n} from \"@automerge/automerge-repo/slim\";\nimport { embedTheme } from \"../themes/embed.ts\";\n\n/**\n * Renders an embedded doc through the shared \"embed\" tool, which draws the\n * chrome and nests the content view. The inner tool travels via the\n * `embed-tool-id` attribute; tool picks come back as\n * `patchwork:embed-tool-changed` events and are persisted by rewriting the\n * marker (which recreates the widget).\n */\nclass EmbedWidget extends WidgetType {\n readonly docId: DocumentId;\n // `null` = no pinned tool; the embed frame uses the datatype's fallback.\n readonly toolId: string | null;\n readonly embedText: string;\n\n constructor(docId: DocumentId, toolId: string | null, embedText: string) {\n super();\n this.docId = docId;\n this.toolId = toolId;\n this.embedText = embedText;\n }\n\n eq(other: EmbedWidget) {\n return other.docId === this.docId && other.toolId === this.toolId;\n }\n\n toDOM(view: EditorView) {\n const container = document.createElement(\"div\");\n container.className = \"cm-embed\";\n\n const patchworkView = document.createElement(\"patchwork-view\");\n // No heads in the url: the embed follows whatever version the host\n // resolves \u2014 the active checkpoint when one is checked out, live otherwise.\n patchworkView.setAttribute(\"doc-url\", `automerge:${this.docId}`);\n patchworkView.setAttribute(\"tool-id\", \"embed\");\n if (this.toolId) patchworkView.setAttribute(\"embed-tool-id\", this.toolId);\n // Explicit inline height: without it the element collapses to 0px (the\n // stylesheet rule isn't reliably applied here).\n patchworkView.style.display = \"block\";\n patchworkView.style.height = \"500px\";\n patchworkView.style.width = \"100%\";\n\n // Persist tool picks into the marker text. Stop propagation so nested\n // embeds don't also change the outer embed's tool.\n container.addEventListener(\"patchwork:embed-tool-changed\", (e) => {\n e.stopPropagation();\n const toolId = (e as CustomEvent<{ toolId?: string }>).detail?.toolId;\n if (toolId) this.setTool(view, container, toolId);\n });\n\n container.appendChild(patchworkView);\n return container;\n }\n\n private setTool(\n view: EditorView,\n container: HTMLElement,\n toolId: string\n ): void {\n const from = view.posAtDOM(container);\n const to = from + this.embedText.length;\n // Only rewrite if the marker is still exactly where this widget maps to.\n if (view.state.doc.sliceString(from, to) !== this.embedText) return;\n view.dispatch({\n changes: { from, to, insert: embedSyntax({ docId: this.docId, toolId }) },\n });\n }\n\n ignoreEvent() {\n // Atomic embed: the editor ignores all events; the frame handles them.\n return true;\n }\n}\n\n// Marker syntax: [patchwork:docId] or [patchwork:docId/toolId] (ids can't\n// contain `/` or `]`). We scan plain text instead of the markdown syntax tree\n// on purpose: `@codemirror/language` isn't a shared singleton across\n// patchwork's separately-bundled extensions, so `syntaxTree(state)` here would\n// read a different `Language` facet and always come back empty.\nconst EMBED_PATTERN = /\\[patchwork:([^/\\]]+)(?:\\/([^\\]]+))?\\]/g;\n\nfunction getEmbedLinks(view: EditorView) {\n const widgets: Range<Decoration>[] = [];\n const { state } = view;\n\n // Visible ranges are line-aligned and markers never span lines, so a marker\n // is always fully inside or fully outside a range.\n for (const { from, to } of view.visibleRanges) {\n const text = state.doc.sliceString(from, to);\n EMBED_PATTERN.lastIndex = 0;\n let m: RegExpExecArray | null;\n while ((m = EMBED_PATTERN.exec(text)) !== null) {\n const matchFrom = from + m.index;\n const matchTo = matchFrom + m[0].length;\n const [matchText, docId, toolId] = m;\n\n if (!isValidDocumentId(docId)) continue;\n\n const embed = Decoration.replace({\n widget: new EmbedWidget(docId as DocumentId, toolId ?? null, matchText),\n });\n widgets.push(embed.range(matchFrom, matchTo));\n }\n }\n\n // `true` lets CodeMirror sort the ranges defensively (matches are already in\n // document order, but this is cheap insurance).\n return Decoration.set(widgets, true);\n}\n\n// MIME types we accept document drags from. Mirrors the sideboard's convention.\nconst PATCHWORK_DND = \"text/x-patchwork-dnd\";\nconst PATCHWORK_URLS = \"text/x-patchwork-urls\";\n\ntype DocRef = { docId: DocumentId; toolId: string | null };\n\n/** Turn an automerge url or a patchwork web link into a DocumentId, or null. */\nfunction urlToDocId(raw: string): DocumentId | null {\n const trimmed = raw.trim();\n if (!trimmed) return null;\n // Plain automerge url (optionally carrying heads/query/subpath).\n const am = trimmed.match(/automerge:([a-zA-Z0-9]+)/);\n if (am && isValidDocumentId(am[1])) return am[1] as DocumentId;\n // Patchwork web link: #doc=<documentId> (also &doc= / ?doc=).\n const web = trimmed.match(/[#&?]doc=([a-zA-Z0-9]+)/);\n if (web && isValidDocumentId(web[1])) return web[1] as DocumentId;\n return null;\n}\n\n/**\n * Read dragged documents out of a drop event, in order of format preference.\n * Only an *explicit* `toolId` on a structured item pins the tool; otherwise we\n * embed tool-less and let the view fall back to the datatype's default tool.\n */\nfunction extractDocRefs(dt: DataTransfer): DocRef[] {\n const refs: DocRef[] = [];\n const seen = new Set<string>();\n const push = (docId: DocumentId | null, toolId: string | null) => {\n if (!docId || seen.has(docId)) return;\n seen.add(docId);\n refs.push({ docId, toolId });\n };\n\n const dnd = dt.getData(PATCHWORK_DND);\n if (dnd) {\n try {\n const parsed = JSON.parse(dnd) as {\n items?: Array<{ url?: string; toolId?: string }>;\n };\n for (const item of parsed?.items ?? []) {\n if (item?.url) push(urlToDocId(item.url), item.toolId ?? null);\n }\n } catch {\n // fall through to the other formats\n }\n }\n if (refs.length > 0) return refs;\n\n const urls = dt.getData(PATCHWORK_URLS);\n if (urls) {\n try {\n const parsed: unknown = JSON.parse(urls);\n if (Array.isArray(parsed)) {\n for (const u of parsed) push(urlToDocId(String(u)), null);\n }\n } catch {\n // fall through\n }\n }\n if (refs.length > 0) return refs;\n\n const text = dt.getData(\"text/uri-list\") || dt.getData(\"text/plain\");\n if (text) {\n for (const line of text.split(/\\r?\\n/)) {\n if (line.startsWith(\"#\")) continue; // uri-list comments\n push(urlToDocId(line), null);\n }\n }\n return refs;\n}\n\nfunction embedSyntax({ docId, toolId }: DocRef): string {\n return toolId ? `[patchwork:${docId}/${toolId}]` : `[patchwork:${docId}]`;\n}\n\n/**\n * Import each OS file dropped from the desktop as a Patchwork `file` document,\n * returning tool-less refs to embed. Uses the realm-local `window.repo` (the\n * documented global) \u2014 fine for creating brand-new docs, which aren't subject\n * to draft remapping.\n */\nasync function fileDropRefs(files: FileList): Promise<DocRef[]> {\n const repo = (window as unknown as { repo?: any }).repo;\n if (!repo) {\n console.warn(\n \"[codemirror-embed] window.repo unavailable; ignoring dropped files\"\n );\n return [];\n }\n const refs: DocRef[] = [];\n for (const file of Array.from(files)) {\n try {\n const mimeType = file.type || \"application/octet-stream\";\n const isText =\n mimeType.startsWith(\"text/\") || mimeType === \"application/json\";\n const content = isText\n ? await file.text()\n : new Uint8Array(await file.arrayBuffer());\n const parts = file.name.split(\".\");\n const extension = parts.length > 1 ? parts.pop()! : \"\";\n const handle = repo.create();\n handle.change((d: any) => {\n d[\"@patchwork\"] = { type: \"file\" };\n d.content = content;\n d.mimeType = mimeType;\n d.extension = extension;\n d.name = file.name;\n });\n const { documentId } = parseAutomergeUrl(handle.url as AutomergeUrl);\n if (isValidDocumentId(documentId)) {\n refs.push({ docId: documentId as DocumentId, toolId: null });\n }\n } catch (err) {\n console.warn(\n \"[codemirror-embed] failed to import dropped file\",\n file.name,\n err\n );\n }\n }\n return refs;\n}\n\nfunction insertRefs(view: EditorView, pos: number, refs: DocRef[]): void {\n if (refs.length === 0) return;\n let text = refs.map(embedSyntax).join(\"\\n\\n\");\n // On a non-empty line, add just enough breaks to put the embed on its own line.\n const line = view.state.doc.lineAt(pos);\n if (/\\S/.test(line.text)) {\n if (pos > line.from) text = \"\\n\" + text;\n if (pos < line.to) text = text + \"\\n\";\n }\n view.dispatch({\n changes: { from: pos, insert: text },\n selection: { anchor: pos + text.length },\n });\n}\n\n/**\n * Drop handler that accepts:\n * - documents dragged from the sidebar / canvases / other tools\n * (`text/x-patchwork-dnd`, `text/x-patchwork-urls`, `text/uri-list`, and\n * `text/plain` patchwork links), and\n * - files dragged in from the operating system (imported as `file` docs).\n * Inserts `[patchwork:docId]` (or `[patchwork:docId/toolId]`) at the drop point.\n */\nfunction embedDropHandlers() {\n // Only claim the *dragover* for unambiguous patchwork/OS drags \u2014 plain\n // text/uri-list can be an ordinary in-editor text drag, which we must not\n // swallow. (`Files` covers OS drags, whose `dt.files` is empty until drop.)\n const wantsDragover = (dt: DataTransfer | null): boolean =>\n !!dt &&\n (dt.types.includes(\"Files\") ||\n dt.types.includes(PATCHWORK_DND) ||\n dt.types.includes(PATCHWORK_URLS));\n\n return EditorView.domEventHandlers({\n dragover(event) {\n const dt = event.dataTransfer;\n if (!wantsDragover(dt)) return false;\n event.preventDefault();\n // Doc drags insert a *reference* to the same automerge doc, so show the\n // link cursor; OS file drags genuinely copy content into new docs.\n if (dt) dt.dropEffect = dt.types.includes(\"Files\") ? \"copy\" : \"link\";\n return true;\n },\n drop(event, view) {\n const dt = event.dataTransfer;\n if (!dt) return false;\n const pos = view.posAtCoords({ x: event.clientX, y: event.clientY });\n if (pos == null) return false;\n\n // OS files import asynchronously; insert once the docs exist.\n if (dt.files && dt.files.length > 0) {\n event.preventDefault();\n void fileDropRefs(dt.files).then((refs) => insertRefs(view, pos, refs));\n return true;\n }\n\n // Otherwise only handle the drop if it actually resolves to patchwork\n // docs (dnd/urls always do; uri-list/plain only for patchwork links).\n // If not, let CodeMirror handle it as a normal text drop.\n const refs = extractDocRefs(dt);\n if (refs.length === 0) return false;\n event.preventDefault();\n insertRefs(view, pos, refs);\n return true;\n },\n });\n}\n\nconst embedPlugin = ViewPlugin.fromClass(\n class {\n decorations: DecorationSet;\n\n constructor(view: EditorView) {\n this.decorations = getEmbedLinks(view);\n }\n\n update(update: ViewUpdate) {\n // Viewport too, so newly-visible markers get decorated.\n if (update.docChanged || update.viewportChanged) {\n this.decorations = getEmbedLinks(update.view);\n }\n }\n },\n {\n decorations: (v) => v.decorations,\n // Atomic: the cursor skips embeds and delete removes the whole marker.\n provide: (plugin) =>\n EditorView.atomicRanges.of(\n (view) => view.plugin(plugin)?.decorations ?? Decoration.none\n ),\n }\n);\n\nexport function markdownEmbed() {\n // `dropCursor` observes events, so it coexists with our dragover handler.\n return [embedPlugin, embedTheme, embedDropHandlers(), dropCursor()];\n}\n", "import { EditorView } from \"@codemirror/view\";\n\n// Outer container only; all embed chrome lives in the shared \"embed\" tool.\nexport const embedTheme = EditorView.baseTheme({\n \".cm-embed\": {\n display: \"block\",\n border: \"1px solid\",\n borderRadius: \"4px\",\n overflow: \"hidden\",\n },\n \"&light .cm-embed\": {\n borderColor: \"#ddd\",\n },\n \"&dark .cm-embed\": {\n borderColor: \"#333\",\n },\n \".cm-embed > patchwork-view\": {\n display: \"block\",\n height: \"500px\",\n width: \"100%\",\n },\n});\n"],
4
+ "sourcesContent": ["import {\n EditorView,\n Decoration,\n WidgetType,\n ViewPlugin,\n ViewUpdate,\n dropCursor,\n type DecorationSet,\n} from \"@codemirror/view\";\nimport { Range } from \"@codemirror/state\";\nimport {\n type AutomergeUrl,\n type DocumentId,\n isValidDocumentId,\n parseAutomergeUrl,\n} from \"@automerge/automerge-repo/slim\";\nimport { embedTheme } from \"../themes/embed.ts\";\n\n/**\n * Renders an embedded doc through the shared \"embed\" tool, which draws the\n * chrome and nests the content view. The inner tool travels via the\n * `embed-tool-id` attribute; tool picks come back as\n * `patchwork:embed-tool-changed` events and are persisted by rewriting the\n * marker (which recreates the widget).\n */\nclass EmbedWidget extends WidgetType {\n readonly docId: DocumentId;\n // `null` = no pinned tool; the embed frame uses the datatype's fallback.\n readonly toolId: string | null;\n readonly embedText: string;\n\n constructor(docId: DocumentId, toolId: string | null, embedText: string) {\n super();\n this.docId = docId;\n this.toolId = toolId;\n this.embedText = embedText;\n }\n\n eq(other: EmbedWidget) {\n return other.docId === this.docId && other.toolId === this.toolId;\n }\n\n toDOM(view: EditorView) {\n const container = document.createElement(\"div\");\n container.className = \"cm-embed\";\n\n const patchworkView = document.createElement(\"patchwork-view\");\n // No heads in the url: the embed follows whatever version the host\n // resolves \u2014 the active checkpoint when one is checked out, live otherwise.\n patchworkView.setAttribute(\"doc-url\", `automerge:${this.docId}`);\n patchworkView.setAttribute(\"tool-id\", \"embed\");\n if (this.toolId) patchworkView.setAttribute(\"embed-tool-id\", this.toolId);\n // Explicit inline height: without it the element collapses to 0px (the\n // stylesheet rule isn't reliably applied here).\n patchworkView.style.display = \"block\";\n patchworkView.style.height = \"500px\";\n patchworkView.style.width = \"100%\";\n\n // Persist tool picks into the marker text. Stop propagation so nested\n // embeds don't also change the outer embed's tool.\n container.addEventListener(\"patchwork:embed-tool-changed\", (e) => {\n e.stopPropagation();\n const toolId = (e as CustomEvent<{ toolId?: string }>).detail?.toolId;\n if (toolId) this.setTool(view, container, toolId);\n });\n\n container.appendChild(patchworkView);\n return container;\n }\n\n private setTool(\n view: EditorView,\n container: HTMLElement,\n toolId: string\n ): void {\n const from = view.posAtDOM(container);\n const to = from + this.embedText.length;\n // Only rewrite if the marker is still exactly where this widget maps to.\n if (view.state.doc.sliceString(from, to) !== this.embedText) return;\n view.dispatch({\n changes: { from, to, insert: embedSyntax({ docId: this.docId, toolId }) },\n });\n }\n\n ignoreEvent() {\n // Atomic embed: the editor ignores all events; the frame handles them.\n return true;\n }\n}\n\n// Marker syntax: [patchwork:docId] or [patchwork:docId/toolId] (ids can't\n// contain `/` or `]`). We scan plain text instead of the markdown syntax tree\n// on purpose: `@codemirror/language` isn't a shared singleton across\n// patchwork's separately-bundled extensions, so `syntaxTree(state)` here would\n// read a different `Language` facet and always come back empty.\nconst EMBED_PATTERN = /\\[patchwork:([^/\\]]+)(?:\\/([^\\]]+))?\\]/g;\n\nfunction getEmbedLinks(view: EditorView) {\n const widgets: Range<Decoration>[] = [];\n const { state } = view;\n\n // Visible ranges are line-aligned and markers never span lines, so a marker\n // is always fully inside or fully outside a range.\n for (const { from, to } of view.visibleRanges) {\n const text = state.doc.sliceString(from, to);\n EMBED_PATTERN.lastIndex = 0;\n let m: RegExpExecArray | null;\n while ((m = EMBED_PATTERN.exec(text)) !== null) {\n const matchFrom = from + m.index;\n const matchTo = matchFrom + m[0].length;\n const [matchText, docId, toolId] = m;\n\n if (!isValidDocumentId(docId)) continue;\n\n const embed = Decoration.replace({\n widget: new EmbedWidget(docId as DocumentId, toolId ?? null, matchText),\n });\n widgets.push(embed.range(matchFrom, matchTo));\n }\n }\n\n // `true` lets CodeMirror sort the ranges defensively (matches are already in\n // document order, but this is cheap insurance).\n return Decoration.set(widgets, true);\n}\n\n// MIME types we accept document drags from. Mirrors the sideboard's convention.\nconst PATCHWORK_DND = \"text/x-patchwork-dnd\";\nconst PATCHWORK_URLS = \"text/x-patchwork-urls\";\n\ntype DocRef = { docId: DocumentId; toolId: string | null };\n\n/** Turn an automerge url or a patchwork web link into a DocumentId, or null. */\nfunction urlToDocId(raw: string): DocumentId | null {\n const trimmed = raw.trim();\n if (!trimmed) return null;\n // Plain automerge url (optionally carrying heads/query/subpath).\n const am = trimmed.match(/automerge:([a-zA-Z0-9]+)/);\n if (am && isValidDocumentId(am[1])) return am[1] as DocumentId;\n // Patchwork web link: #doc=<documentId> (also &doc= / ?doc=).\n const web = trimmed.match(/[#&?]doc=([a-zA-Z0-9]+)/);\n if (web && isValidDocumentId(web[1])) return web[1] as DocumentId;\n return null;\n}\n\n/**\n * Read dragged documents out of a drop event, in order of format preference.\n * Only an *explicit* `toolId` on a structured item pins the tool; otherwise we\n * embed tool-less and let the view fall back to the datatype's default tool.\n */\nfunction extractDocRefs(dt: DataTransfer): DocRef[] {\n const refs: DocRef[] = [];\n const seen = new Set<string>();\n const push = (docId: DocumentId | null, toolId: string | null) => {\n if (!docId || seen.has(docId)) return;\n seen.add(docId);\n refs.push({ docId, toolId });\n };\n\n const dnd = dt.getData(PATCHWORK_DND);\n if (dnd) {\n try {\n const parsed = JSON.parse(dnd) as {\n items?: Array<{ url?: string; toolId?: string }>;\n };\n for (const item of parsed?.items ?? []) {\n if (item?.url) push(urlToDocId(item.url), item.toolId ?? null);\n }\n } catch {\n // fall through to the other formats\n }\n }\n if (refs.length > 0) return refs;\n\n const urls = dt.getData(PATCHWORK_URLS);\n if (urls) {\n try {\n const parsed: unknown = JSON.parse(urls);\n if (Array.isArray(parsed)) {\n for (const u of parsed) push(urlToDocId(String(u)), null);\n }\n } catch {\n // fall through\n }\n }\n if (refs.length > 0) return refs;\n\n const text = dt.getData(\"text/uri-list\") || dt.getData(\"text/plain\");\n if (text) {\n for (const line of text.split(/\\r?\\n/)) {\n if (line.startsWith(\"#\")) continue; // uri-list comments\n push(urlToDocId(line), null);\n }\n }\n return refs;\n}\n\nfunction embedSyntax({ docId, toolId }: DocRef): string {\n return toolId ? `[patchwork:${docId}/${toolId}]` : `[patchwork:${docId}]`;\n}\n\n/**\n * Import each OS file dropped from the desktop as a Patchwork `file` document,\n * returning tool-less refs to embed. Uses the realm-local `window.repo` (the\n * documented global) \u2014 fine for creating brand-new docs, which aren't subject\n * to draft remapping.\n */\nasync function fileDropRefs(files: FileList): Promise<DocRef[]> {\n const repo = (window as unknown as { repo?: any }).repo;\n if (!repo) {\n console.warn(\n \"[codemirror-embed] window.repo unavailable; ignoring dropped files\"\n );\n return [];\n }\n const refs: DocRef[] = [];\n for (const file of Array.from(files)) {\n try {\n const mimeType = file.type || \"application/octet-stream\";\n const isText =\n mimeType.startsWith(\"text/\") || mimeType === \"application/json\";\n const content = isText\n ? await file.text()\n : new Uint8Array(await file.arrayBuffer());\n const parts = file.name.split(\".\");\n const extension = parts.length > 1 ? parts.pop()! : \"\";\n const handle = repo.create();\n handle.change((d: any) => {\n d[\"@patchwork\"] = { type: \"file\" };\n d.content = content;\n d.mimeType = mimeType;\n d.extension = extension;\n d.name = file.name;\n });\n const { documentId } = parseAutomergeUrl(handle.url as AutomergeUrl);\n if (isValidDocumentId(documentId)) {\n refs.push({ docId: documentId as DocumentId, toolId: null });\n }\n } catch (err) {\n console.warn(\n \"[codemirror-embed] failed to import dropped file\",\n file.name,\n err\n );\n }\n }\n return refs;\n}\n\nfunction insertRefs(view: EditorView, pos: number, refs: DocRef[]): void {\n if (refs.length === 0) return;\n let text = refs.map(embedSyntax).join(\"\\n\\n\");\n // On a non-empty line, add just enough breaks to put the embed on its own line.\n const line = view.state.doc.lineAt(pos);\n if (/\\S/.test(line.text)) {\n if (pos > line.from) text = \"\\n\" + text;\n if (pos < line.to) text = text + \"\\n\";\n }\n view.dispatch({\n changes: { from: pos, insert: text },\n selection: { anchor: pos + text.length },\n });\n}\n\n/**\n * Drop handler that accepts:\n * - documents dragged from the sidebar / canvases / other tools\n * (`text/x-patchwork-dnd`, `text/x-patchwork-urls`, `text/uri-list`, and\n * `text/plain` patchwork links), and\n * - files dragged in from the operating system (imported as `file` docs).\n * Inserts `[patchwork:docId]` (or `[patchwork:docId/toolId]`) at the drop point.\n */\nfunction embedDropHandlers() {\n // Only claim the *dragover* for unambiguous patchwork/OS drags \u2014 plain\n // text/uri-list can be an ordinary in-editor text drag, which we must not\n // swallow. (`Files` covers OS drags, whose `dt.files` is empty until drop.)\n const wantsDragover = (dt: DataTransfer | null): boolean =>\n !!dt &&\n (dt.types.includes(\"Files\") ||\n dt.types.includes(PATCHWORK_DND) ||\n dt.types.includes(PATCHWORK_URLS));\n\n return EditorView.domEventHandlers({\n dragover(event) {\n const dt = event.dataTransfer;\n if (!wantsDragover(dt)) return false;\n event.preventDefault();\n // Doc drags insert a *reference* to the same automerge doc, so show the\n // link cursor; OS file drags genuinely copy content into new docs.\n if (dt) dt.dropEffect = dt.types.includes(\"Files\") ? \"copy\" : \"link\";\n return true;\n },\n drop(event, view) {\n const dt = event.dataTransfer;\n if (!dt) return false;\n const pos = view.posAtCoords({ x: event.clientX, y: event.clientY });\n if (pos == null) return false;\n\n // OS files import asynchronously; insert once the docs exist.\n if (dt.files && dt.files.length > 0) {\n event.preventDefault();\n void fileDropRefs(dt.files).then((refs) => insertRefs(view, pos, refs));\n return true;\n }\n\n // Otherwise only handle the drop if it actually resolves to patchwork\n // docs (dnd/urls always do; uri-list/plain only for patchwork links).\n // If not, let CodeMirror handle it as a normal text drop.\n const refs = extractDocRefs(dt);\n if (refs.length === 0) return false;\n event.preventDefault();\n insertRefs(view, pos, refs);\n return true;\n },\n });\n}\n\nconst embedPlugin = ViewPlugin.fromClass(\n class {\n decorations: DecorationSet;\n\n constructor(view: EditorView) {\n this.decorations = getEmbedLinks(view);\n }\n\n update(update: ViewUpdate) {\n // Viewport too, so newly-visible markers get decorated.\n if (update.docChanged || update.viewportChanged) {\n this.decorations = getEmbedLinks(update.view);\n }\n }\n },\n {\n decorations: (v) => v.decorations,\n // Atomic: the cursor skips embeds and delete removes the whole marker.\n provide: (plugin) =>\n EditorView.atomicRanges.of(\n (view) => view.plugin(plugin)?.decorations ?? Decoration.none\n ),\n }\n);\n\nexport function markdownEmbed() {\n // `dropCursor` observes events, so it coexists with our dragover handler.\n return [embedPlugin, embedTheme, embedDropHandlers(), dropCursor()];\n}\n", "import { EditorView } from \"@codemirror/view\";\n\n// Outer container only; all embed chrome lives in the shared \"embed\" tool.\nexport const embedTheme = EditorView.baseTheme({\n \".cm-embed\": {\n display: \"block\",\n border: \"var(--studio-border-width, 1px) var(--studio-border-style, solid)\",\n borderRadius: \"4px\",\n overflow: \"hidden\",\n },\n \"&light .cm-embed\": {\n borderColor: \"#ddd\",\n },\n \"&dark .cm-embed\": {\n borderColor: \"#333\",\n },\n \".cm-embed > patchwork-view\": {\n display: \"block\",\n height: \"500px\",\n width: \"100%\",\n },\n});\n"],
5
5
  "mappings": ";AAAA;AAAA,EACE,cAAAA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,OAEK;AAEP;AAAA,EAGE;AAAA,EACA;AAAA,OACK;;;ACfP,SAAS,kBAAkB;AAGpB,IAAM,aAAa,WAAW,UAAU;AAAA,EAC7C,aAAa;AAAA,IACX,SAAS;AAAA,IACT,QAAQ;AAAA,IACR,cAAc;AAAA,IACd,UAAU;AAAA,EACZ;AAAA,EACA,oBAAoB;AAAA,IAClB,aAAa;AAAA,EACf;AAAA,EACA,mBAAmB;AAAA,IACjB,aAAa;AAAA,EACf;AAAA,EACA,8BAA8B;AAAA,IAC5B,SAAS;AAAA,IACT,QAAQ;AAAA,IACR,OAAO;AAAA,EACT;AACF,CAAC;;;ADID,IAAM,cAAN,cAA0B,WAAW;AAAA,EAC1B;AAAA;AAAA,EAEA;AAAA,EACA;AAAA,EAET,YAAY,OAAmB,QAAuB,WAAmB;AACvE,UAAM;AACN,SAAK,QA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View", "refs"]
7
7
  }
@@ -12,7 +12,7 @@ import { EditorView } from "@codemirror/view";
12
12
  var linkTheme = EditorView.baseTheme({
13
13
  ".cm-link": {
14
14
  textDecoration: "underline",
15
- cursor: "pointer",
15
+ cursor: "var(--studio-cursor-pointer, pointer)",
16
16
  fontFamily: '"Merriweather Sans", sans-serif',
17
17
  color: "var(--syntax-link, #0066cc)",
18
18
  "&:hover": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/extensions/links.ts", "../../src/themes/links.ts"],
4
- "sourcesContent": ["import {\n EditorView,\n Decoration,\n WidgetType,\n ViewPlugin,\n ViewUpdate,\n type DecorationSet,\n} from \"@codemirror/view\";\nimport { Range } from \"@codemirror/state\";\nimport { syntaxTree } from \"@codemirror/language\";\nimport { isValidAutomergeUrl } from \"@automerge/automerge-repo/slim\";\nimport { linkTheme } from \"../themes/links.ts\";\n\n/**\n * Widget to render a clickable link in the editor\n */\nclass LinkWidget extends WidgetType {\n readonly url: string;\n readonly text: string;\n\n constructor(url: string, text: string) {\n super();\n this.url = url;\n this.text = text;\n }\n\n eq(other: LinkWidget) {\n return other.url === this.url && other.text === this.text;\n }\n\n toDOM() {\n const link = document.createElement(\"a\");\n link.href = this.url;\n link.textContent = this.text;\n link.className = \"cm-link\";\n link.title = this.url;\n\n link.onclick = (e) => {\n e.preventDefault();\n if (isValidAutomergeUrl(this.url)) {\n // Open the document inside Patchwork rather than as a browser URL\n // (automerge: isn't navigable). bubbles/composed so the event escapes\n // the editor and any shadow root up to whoever drives selection.\n link.dispatchEvent(\n new CustomEvent(\"patchwork:open-document\", {\n detail: { url: this.url },\n bubbles: true,\n composed: true,\n }),\n );\n } else {\n window.open(this.url, \"_blank noopener noreferrer\");\n }\n };\n\n return link;\n }\n\n ignoreEvent(e: Event) {\n // Let click events through to our widget\n return e.type !== \"click\";\n }\n}\n\nfunction getLinks(view: EditorView) {\n const widgets: Range<Decoration>[] = [];\n const { state } = view;\n const selection = state.selection.main;\n\n for (let { from, to } of view.visibleRanges) {\n syntaxTree(state).iterate({\n from,\n to,\n enter: (node) => {\n // Match markdown link syntax\n if (node.name === \"Link\") {\n const linkFrom = node.from;\n const linkTo = node.to;\n\n // Check if cursor is inside this link\n const cursorInLink =\n selection.from >= linkFrom && selection.from <= linkTo;\n // Check if the link is inside the selection\n const selectionSpansLink =\n selection.from < linkFrom && selection.to > linkTo;\n\n // Replace if cursor is outside the link and there's no selection across the link\n if (!cursorInLink && !selectionSpansLink) {\n const linkText = state.doc.sliceString(linkFrom, linkTo);\n const match = linkText.match(/\\[([^\\]]+)\\]\\(([^)]+)\\)/);\n\n if (match) {\n const [, text, url] = match;\n\n // Replace the entire [text](url) with just the link widget\n const deco = Decoration.replace({\n widget: new LinkWidget(url, text),\n });\n\n widgets.push(deco.range(linkFrom, linkTo));\n }\n }\n }\n },\n });\n }\n\n return Decoration.set(widgets);\n}\n\nconst linkPlugin = ViewPlugin.fromClass(\n class {\n decorations: DecorationSet;\n\n constructor(view: EditorView) {\n this.decorations = getLinks(view);\n }\n\n update(update: ViewUpdate) {\n // Recompute when doc changes, selection moves, or viewport changes\n if (\n update.docChanged ||\n update.selectionSet ||\n update.viewportChanged ||\n syntaxTree(update.startState) !== syntaxTree(update.state)\n ) {\n this.decorations = getLinks(update.view);\n }\n }\n },\n {\n decorations: (v) => v.decorations,\n }\n);\n\nexport function markdownLinks() {\n return [linkPlugin, linkTheme];\n}\n", "import { EditorView } from \"@codemirror/view\";\n\nexport const linkTheme = EditorView.baseTheme({\n \".cm-link\": {\n textDecoration: \"underline\",\n cursor: \"pointer\",\n fontFamily: '\"Merriweather Sans\", sans-serif',\n color: \"var(--syntax-link, #0066cc)\",\n \"&:hover\": {\n color: \"inherit\",\n },\n },\n});\n"],
4
+ "sourcesContent": ["import {\n EditorView,\n Decoration,\n WidgetType,\n ViewPlugin,\n ViewUpdate,\n type DecorationSet,\n} from \"@codemirror/view\";\nimport { Range } from \"@codemirror/state\";\nimport { syntaxTree } from \"@codemirror/language\";\nimport { isValidAutomergeUrl } from \"@automerge/automerge-repo/slim\";\nimport { linkTheme } from \"../themes/links.ts\";\n\n/**\n * Widget to render a clickable link in the editor\n */\nclass LinkWidget extends WidgetType {\n readonly url: string;\n readonly text: string;\n\n constructor(url: string, text: string) {\n super();\n this.url = url;\n this.text = text;\n }\n\n eq(other: LinkWidget) {\n return other.url === this.url && other.text === this.text;\n }\n\n toDOM() {\n const link = document.createElement(\"a\");\n link.href = this.url;\n link.textContent = this.text;\n link.className = \"cm-link\";\n link.title = this.url;\n\n link.onclick = (e) => {\n e.preventDefault();\n if (isValidAutomergeUrl(this.url)) {\n // Open the document inside Patchwork rather than as a browser URL\n // (automerge: isn't navigable). bubbles/composed so the event escapes\n // the editor and any shadow root up to whoever drives selection.\n link.dispatchEvent(\n new CustomEvent(\"patchwork:open-document\", {\n detail: { url: this.url },\n bubbles: true,\n composed: true,\n }),\n );\n } else {\n window.open(this.url, \"_blank noopener noreferrer\");\n }\n };\n\n return link;\n }\n\n ignoreEvent(e: Event) {\n // Let click events through to our widget\n return e.type !== \"click\";\n }\n}\n\nfunction getLinks(view: EditorView) {\n const widgets: Range<Decoration>[] = [];\n const { state } = view;\n const selection = state.selection.main;\n\n for (let { from, to } of view.visibleRanges) {\n syntaxTree(state).iterate({\n from,\n to,\n enter: (node) => {\n // Match markdown link syntax\n if (node.name === \"Link\") {\n const linkFrom = node.from;\n const linkTo = node.to;\n\n // Check if cursor is inside this link\n const cursorInLink =\n selection.from >= linkFrom && selection.from <= linkTo;\n // Check if the link is inside the selection\n const selectionSpansLink =\n selection.from < linkFrom && selection.to > linkTo;\n\n // Replace if cursor is outside the link and there's no selection across the link\n if (!cursorInLink && !selectionSpansLink) {\n const linkText = state.doc.sliceString(linkFrom, linkTo);\n const match = linkText.match(/\\[([^\\]]+)\\]\\(([^)]+)\\)/);\n\n if (match) {\n const [, text, url] = match;\n\n // Replace the entire [text](url) with just the link widget\n const deco = Decoration.replace({\n widget: new LinkWidget(url, text),\n });\n\n widgets.push(deco.range(linkFrom, linkTo));\n }\n }\n }\n },\n });\n }\n\n return Decoration.set(widgets);\n}\n\nconst linkPlugin = ViewPlugin.fromClass(\n class {\n decorations: DecorationSet;\n\n constructor(view: EditorView) {\n this.decorations = getLinks(view);\n }\n\n update(update: ViewUpdate) {\n // Recompute when doc changes, selection moves, or viewport changes\n if (\n update.docChanged ||\n update.selectionSet ||\n update.viewportChanged ||\n syntaxTree(update.startState) !== syntaxTree(update.state)\n ) {\n this.decorations = getLinks(update.view);\n }\n }\n },\n {\n decorations: (v) => v.decorations,\n }\n);\n\nexport function markdownLinks() {\n return [linkPlugin, linkTheme];\n}\n", "import { EditorView } from \"@codemirror/view\";\n\nexport const linkTheme = EditorView.baseTheme({\n \".cm-link\": {\n textDecoration: \"underline\",\n cursor: \"var(--studio-cursor-pointer, pointer)\",\n fontFamily: '\"Merriweather Sans\", sans-serif',\n color: \"var(--syntax-link, #0066cc)\",\n \"&:hover\": {\n color: \"inherit\",\n },\n },\n});\n"],
5
5
  "mappings": ";AAAA;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AAEP,SAAS,kBAAkB;AAC3B,SAAS,2BAA2B;;;ACVpC,SAAS,kBAAkB;AAEpB,IAAM,YAAY,WAAW,UAAU;AAAA,EAC5C,YAAY;AAAA,IACV,gBAAgB;AAAA,IAChB,QAAQ;AAAA,IACR,YAAY;AAAA,IACZ,OAAO;AAAA,IACP,WAAW;AAAA,MACT,OAAO;AAAA,IACT;AAAA,EACF;AACF,CAAC;;;ADID,IAAM,aAAN,cAAyB,WAAW;AAAA,EACzB;AAAA,EACA;AAAA,EAET,YAAY,KAAa,MAAc;AACrC,UAAM;AACN,SAAK,MAAM;AACX,SAAK,OAAO;AAAA,EACd;AAAA,EAEA,GAAG,OAAmB;AACpB,WAAO,MAAM,QAAQ,KAAK,OAAO,MAAM,SAAS,KAAK;AAAA,EACvD;AAAA,EAEA,QAAQ;AACN,UA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cAClC,CAAC;AAED,sBAAQ,KAAK,KAAK,MAAM,UAAU,MAAM,CAAC;AAAA,YAC3C;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO,WAAW,IAAI,OAAO;AAC/B;AAEA,IAAM,aAAa,WAAW;AAAA,EAC5B,MAAM;AAAA,IACJ;AAAA,IAEA,YAAY,MAAkB;AAC5B,WAAK,cAAc,SAAS,IAAI;AAAA,IAClC;AAAA,IAEA,OAAO,QAAoB;AAEzB,UACE,OAAO,cACP,OAAO,gBACP,OAAO,mBACP,WAAW,OAAO,UAAU,MAAM,WAAW,OAAO,KAAK,GACzD;AACA,aAAK,cAAc,SAAS,OAAO,IAAI;AAAA,MACzC;AAAA,IACF;AAAA,EACF;AAAA,EACA;AAAA,IACE,aAAa,CAAC,MAAM,EAAE;AAAA,EACxB;AACF;AAEO,SAAS,gBAAgB;AAC9B,SAAO,CAAC,YAAY,SAAS;AAC/B;",
6
6
  "names": []
7
7
  }
@@ -2247,8 +2247,8 @@ var markdownStyles = (style) => ({
2247
2247
  }
2248
2248
  });
2249
2249
  var baseHeadingStyles = {
2250
- fontFamily: "var(--text-editor-family-sans)",
2251
- fontWeight: 400,
2250
+ fontFamily: "var(--studio-heading-family, var(--text-editor-family-sans))",
2251
+ fontWeight: "var(--studio-heading-weight, 400)",
2252
2252
  textDecoration: "none"
2253
2253
  };
2254
2254
  var baseCodeStyles = {
@@ -2264,7 +2264,7 @@ var markdownSyntaxHighlighting = (style) => HighlightStyle.define([
2264
2264
  {
2265
2265
  tag: tags.heading1,
2266
2266
  ...baseHeadingStyles,
2267
- fontSize: "1.5rem",
2267
+ fontSize: "var(--studio-heading-size-1, 1.5rem)",
2268
2268
  lineHeight: "2rem",
2269
2269
  marginBottom: "1rem",
2270
2270
  marginTop: "2rem"
@@ -2272,7 +2272,7 @@ var markdownSyntaxHighlighting = (style) => HighlightStyle.define([
2272
2272
  {
2273
2273
  tag: tags.heading2,
2274
2274
  ...baseHeadingStyles,
2275
- fontSize: "1.5rem",
2275
+ fontSize: "var(--studio-heading-size-2, 1.5rem)",
2276
2276
  lineHeight: "2rem",
2277
2277
  marginBottom: "1rem",
2278
2278
  marginTop: "2rem"
@@ -2280,7 +2280,7 @@ var markdownSyntaxHighlighting = (style) => HighlightStyle.define([
2280
2280
  {
2281
2281
  tag: tags.heading3,
2282
2282
  ...baseHeadingStyles,
2283
- fontSize: "1.25rem",
2283
+ fontSize: "var(--studio-heading-size-3, 1.25rem)",
2284
2284
  lineHeight: "1.75rem",
2285
2285
  marginBottom: "1rem",
2286
2286
  marginTop: "2rem"
@@ -2288,7 +2288,7 @@ var markdownSyntaxHighlighting = (style) => HighlightStyle.define([
2288
2288
  {
2289
2289
  tag: tags.heading4,
2290
2290
  ...baseHeadingStyles,
2291
- fontSize: "1.1rem",
2291
+ fontSize: "var(--studio-heading-size-4, 1.1rem)",
2292
2292
  marginBottom: "1rem",
2293
2293
  marginTop: "2rem"
2294
2294
  },