uncial 1.0.0 → 2.0.1

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 (52) hide show
  1. package/README.md +7 -7
  2. package/dist/core/attributes.d.ts +14 -2
  3. package/dist/core/attributes.js +52 -0
  4. package/dist/core/defineBlock.js +19 -32
  5. package/dist/core/migrations.d.ts +1 -1
  6. package/dist/core/migrations.js +10 -3
  7. package/dist/core/normalize.js +19 -7
  8. package/dist/core/registry.js +13 -0
  9. package/dist/core/types.d.ts +23 -1
  10. package/dist/core/validate.js +5 -1
  11. package/dist/editor/AttributeFieldControl.svelte +125 -5
  12. package/dist/editor/AttributeFieldControl.svelte.d.ts +1 -0
  13. package/dist/editor/BlockAttributesPanel.svelte +50 -17
  14. package/dist/editor/Editor.svelte +144 -11
  15. package/dist/editor/Editor.svelte.d.ts +37 -0
  16. package/dist/editor/attributesController.d.ts +5 -0
  17. package/dist/editor/attributesController.js +26 -3
  18. package/dist/editor/bindEditor.d.ts +7 -0
  19. package/dist/editor/bindEditor.js +39 -1
  20. package/dist/editor/containerChildOps.js +22 -1
  21. package/dist/editor/dropdownFloat.d.ts +16 -0
  22. package/dist/editor/dropdownFloat.js +127 -0
  23. package/dist/index.d.ts +1 -0
  24. package/dist/index.js +1 -0
  25. package/dist/render/RichContent.svelte +10 -2
  26. package/dist/render/RichContent.svelte.d.ts +2 -0
  27. package/dist/render/RichNode.svelte +64 -8
  28. package/dist/render/RichNode.svelte.d.ts +2 -0
  29. package/dist/render/Tab.svelte +27 -0
  30. package/dist/render/Tab.svelte.d.ts +10 -0
  31. package/dist/render/Tabs.svelte +57 -0
  32. package/dist/render/Tabs.svelte.d.ts +10 -0
  33. package/dist/render/index.d.ts +3 -0
  34. package/dist/render/index.js +6 -0
  35. package/dist/render/tabSelection.svelte.d.ts +8 -0
  36. package/dist/render/tabSelection.svelte.js +40 -0
  37. package/dist/shared/documentIdentity.d.ts +6 -0
  38. package/dist/shared/documentIdentity.js +64 -0
  39. package/dist/shared/syntaxHighlight.d.ts +14 -0
  40. package/dist/shared/syntaxHighlight.js +36 -3
  41. package/dist/shared/tiptap.js +84 -6
  42. package/dist/styles/base.css +185 -1
  43. package/dist/styles/controls.css +2 -0
  44. package/dist/styles/prose.css +26 -0
  45. package/dist/styles/tokens.css +53 -69
  46. package/dist/tabs.d.ts +6 -0
  47. package/dist/tabs.js +36 -0
  48. package/dist/web-components/UncialEditor.svelte +13 -12
  49. package/dist/web-components/UncialEditor.svelte.d.ts +2 -0
  50. package/dist/web-components/index.d.ts +6 -0
  51. package/dist/web-components/index.js +12 -0
  52. package/package.json +135 -133
@@ -0,0 +1,127 @@
1
+ /** Breathing room between the menu and the viewport edge it is clamped to. */
2
+ const VIEWPORT_MARGIN = 8;
3
+ /** The vertical padding and border `max-height` does not account for. */
4
+ function frameHeight(element) {
5
+ const style = getComputedStyle(element);
6
+ if (style.boxSizing === 'border-box')
7
+ return 0;
8
+ return (Number.parseFloat(style.borderTopWidth) +
9
+ Number.parseFloat(style.borderBottomWidth) +
10
+ Number.parseFloat(style.paddingTop) +
11
+ Number.parseFloat(style.paddingBottom));
12
+ }
13
+ /**
14
+ * Lifts an open `<details>` dropdown's menu out of every scrolling ancestor and
15
+ * places it against the viewport, under (or over) its own summary.
16
+ *
17
+ * The attributes sidebar's panel is `position: sticky` with a `max-height` and
18
+ * `overflow-y: auto`, which clips an absolutely positioned menu at the panel's
19
+ * edge — so the "Add block" list was unreachable by mouse. A viewport-positioned
20
+ * menu is not clipped by an overflow ancestor, and the top layer (`popover`,
21
+ * where the browser has it) also lifts it clear of a transformed ancestor, which
22
+ * a `position: fixed` element alone would still be trapped inside.
23
+ *
24
+ * Positioning only. Dismissal stays with `dropdownDismiss`, which the menu's
25
+ * unchanged place in the DOM tree keeps working.
26
+ */
27
+ export function dropdownFloat(node) {
28
+ let gap = null;
29
+ function parts() {
30
+ const summary = node.querySelector('summary');
31
+ const menu = node.querySelector('.uncial-dropdown__menu');
32
+ return summary && menu ? { summary, menu } : null;
33
+ }
34
+ function place() {
35
+ const found = parts();
36
+ if (!found)
37
+ return;
38
+ const { summary, menu } = found;
39
+ // The stylesheet's `margin-top` is the trigger-to-menu gap; it has to be
40
+ // read before the first placement zeroes it.
41
+ if (gap === null)
42
+ gap = Number.parseFloat(getComputedStyle(menu).marginTop) || 0;
43
+ if (menu.popover !== 'manual' && 'popover' in menu)
44
+ menu.popover = 'manual';
45
+ if (menu.popover && !menu.matches(':popover-open'))
46
+ menu.showPopover();
47
+ // Lifting the height cap to measure resets the menu's own scroll, so a
48
+ // re-place must not lose how far the reader had scrolled the list.
49
+ const scrolled = menu.scrollTop;
50
+ menu.style.position = 'fixed';
51
+ menu.style.margin = '0';
52
+ menu.style.right = 'auto';
53
+ menu.style.bottom = 'auto';
54
+ menu.style.maxHeight = '';
55
+ menu.style.overflowY = '';
56
+ menu.style.top = '0px';
57
+ menu.style.left = '0px';
58
+ const anchor = summary.getBoundingClientRect();
59
+ const natural = menu.getBoundingClientRect();
60
+ const spaceBelow = window.innerHeight - anchor.bottom - gap - VIEWPORT_MARGIN;
61
+ const spaceAbove = anchor.top - gap - VIEWPORT_MARGIN;
62
+ const below = natural.height <= spaceBelow || spaceBelow >= spaceAbove;
63
+ const available = Math.max(below ? spaceBelow : spaceAbove, 0);
64
+ if (natural.height > available) {
65
+ // Under `content-box` sizing — the default, and the package's stylesheet
66
+ // sets none — `max-height` bounds the content alone, so the menu's own
67
+ // frame has to come out of the space asked for.
68
+ menu.style.maxHeight = `${Math.max(available - frameHeight(menu), 0)}px`;
69
+ menu.style.overflowY = 'auto';
70
+ }
71
+ menu.scrollTop = scrolled;
72
+ const height = menu.getBoundingClientRect().height;
73
+ const top = below ? anchor.bottom + gap : anchor.top - gap - height;
74
+ // `--end` dropdowns hang their right edge off the trigger's right edge.
75
+ const preferredLeft = node.classList.contains('uncial-dropdown--end')
76
+ ? anchor.right - natural.width
77
+ : anchor.left;
78
+ const left = Math.max(VIEWPORT_MARGIN, Math.min(preferredLeft, window.innerWidth - natural.width - VIEWPORT_MARGIN));
79
+ menu.style.top = `${Math.max(top, VIEWPORT_MARGIN)}px`;
80
+ menu.style.left = `${left}px`;
81
+ }
82
+ function release() {
83
+ const found = parts();
84
+ if (!found)
85
+ return;
86
+ const { menu } = found;
87
+ if (menu.popover && menu.matches(':popover-open'))
88
+ menu.hidePopover();
89
+ for (const property of [
90
+ 'position',
91
+ 'margin',
92
+ 'top',
93
+ 'left',
94
+ 'right',
95
+ 'bottom',
96
+ 'max-height',
97
+ 'overflow-y'
98
+ ]) {
99
+ menu.style.removeProperty(property);
100
+ }
101
+ }
102
+ function onToggle() {
103
+ if (node.open) {
104
+ place();
105
+ // Capture, so a scroll in any ancestor — the panel or the page — moves
106
+ // the menu with its trigger.
107
+ document.addEventListener('scroll', place, true);
108
+ window.addEventListener('resize', place);
109
+ }
110
+ else {
111
+ release();
112
+ document.removeEventListener('scroll', place, true);
113
+ window.removeEventListener('resize', place);
114
+ }
115
+ }
116
+ node.addEventListener('toggle', onToggle);
117
+ if (node.open)
118
+ onToggle();
119
+ return {
120
+ destroy() {
121
+ node.removeEventListener('toggle', onToggle);
122
+ document.removeEventListener('scroll', place, true);
123
+ window.removeEventListener('resize', place);
124
+ release();
125
+ }
126
+ };
127
+ }
package/dist/index.d.ts CHANGED
@@ -2,3 +2,4 @@ export * from './core/index.js';
2
2
  export * from './runtime/svelte.js';
3
3
  export * from './editor/index.js';
4
4
  export * from './render/index.js';
5
+ export { tabBlock, tabsBlock } from './tabs.js';
package/dist/index.js CHANGED
@@ -2,3 +2,4 @@ export * from './core/index.js';
2
2
  export * from './runtime/svelte.js';
3
3
  export * from './editor/index.js';
4
4
  export * from './render/index.js';
5
+ export { tabBlock, tabsBlock } from './tabs.js';
@@ -7,9 +7,17 @@
7
7
  nodes?: PMNode[];
8
8
  registry: BlockRegistry;
9
9
  schema?: ContentSchema;
10
+ tabsGroup?: string;
11
+ tabsLabels?: string[];
10
12
  }
11
13
 
12
- let { nodes = [], registry, schema = undefined }: Props = $props();
14
+ let {
15
+ nodes = [],
16
+ registry,
17
+ schema = undefined,
18
+ tabsGroup = undefined,
19
+ tabsLabels = undefined
20
+ }: Props = $props();
13
21
 
14
22
  function getNodeKey(node: PMNode, index: number): string {
15
23
  const id = node.attrs?.id;
@@ -26,5 +34,5 @@
26
34
  </script>
27
35
 
28
36
  {#each nodes as node, index (getNodeKey(node, index))}
29
- <RichNode {node} {registry} {schema} />
37
+ <RichNode {node} {registry} {schema} {tabsGroup} {tabsLabels} />
30
38
  {/each}
@@ -4,6 +4,8 @@ interface Props {
4
4
  nodes?: PMNode[];
5
5
  registry: BlockRegistry;
6
6
  schema?: ContentSchema;
7
+ tabsGroup?: string;
8
+ tabsLabels?: string[];
7
9
  }
8
10
  declare const RichContent: import("svelte").Component<Props, {}, "">;
9
11
  type RichContent = ReturnType<typeof RichContent>;
@@ -10,9 +10,17 @@
10
10
  node: PMNode;
11
11
  registry: BlockRegistry;
12
12
  schema?: ContentSchema;
13
+ tabsGroup?: string;
14
+ tabsLabels?: string[];
13
15
  }
14
16
 
15
- let { node, registry, schema = undefined }: Props = $props();
17
+ let {
18
+ node,
19
+ registry,
20
+ schema = undefined,
21
+ tabsGroup = undefined,
22
+ tabsLabels = undefined
23
+ }: Props = $props();
16
24
 
17
25
  const block = $derived(registry.get(node.type));
18
26
  const blockAttrs = $derived((node.attrs ?? {}) as Record<string, unknown>);
@@ -25,6 +33,18 @@
25
33
  .join('')
26
34
  );
27
35
  const highlightedCode = $derived(highlightCodeToHtml(codeText, codeLanguage));
36
+ const childTabsGroup = $derived.by(() => {
37
+ if (node.type !== 'tabs' || typeof node.attrs?.group !== 'string') return tabsGroup;
38
+ return node.attrs.group.trim() || undefined;
39
+ });
40
+ const childTabsLabels = $derived.by(() => {
41
+ if (node.type !== 'tabs') return tabsLabels;
42
+ return blockContent.flatMap((child) => {
43
+ if (child.type !== 'tab' || typeof child.attrs?.label !== 'string') return [];
44
+ const label = child.attrs.label.trim();
45
+ return label ? [label] : [];
46
+ });
47
+ });
28
48
 
29
49
  function getActiveMarks(marks: PMMark[] = []): PMMark[] {
30
50
  return schema ? marks.filter((mark) => schema.allowedMarks.has(mark.type)) : marks;
@@ -50,7 +70,13 @@
50
70
  </script>
51
71
 
52
72
  {#snippet blockChildren()}
53
- <RichContent nodes={blockContent} {registry} {schema} />
73
+ <RichContent
74
+ nodes={blockContent}
75
+ {registry}
76
+ {schema}
77
+ tabsGroup={childTabsGroup}
78
+ tabsLabels={childTabsLabels}
79
+ />
54
80
  {/snippet}
55
81
 
56
82
  {#snippet renderMarkedText(text: string, marks: PMMark[])}
@@ -92,6 +118,8 @@
92
118
  {...blockAttrs}
93
119
  {...(block as unknown as { renderProps?: Record<string, unknown> }).renderProps ?? {}}
94
120
  content={blockContent}
121
+ {tabsGroup}
122
+ {tabsLabels}
95
123
  children={block.content ? blockChildren : undefined}
96
124
  />
97
125
  {:else if node.type === 'paragraph'}
@@ -100,19 +128,47 @@
100
128
  </p>
101
129
  {:else if node.type === 'heading'}
102
130
  {@const level = Math.min(6, Math.max(1, Number(node.attrs?.level ?? 1)))}
131
+ <!-- The anchor is the heading's persisted slug, never its text: a slug is
132
+ stamped once at authoring time so that retitling a section leaves every
133
+ link into it resolving. A heading that carries no slug gets no id
134
+ rather than a text-derived one, which would rot on the next edit. -->
135
+ {@const anchor =
136
+ typeof node.attrs?.slug === 'string' && node.attrs.slug.length > 0
137
+ ? node.attrs.slug
138
+ : undefined}
103
139
  {#if level === 1}
104
- <h1><RichContent nodes={node.content ?? []} {registry} {schema} /></h1>
140
+ <h1 id={anchor}><RichContent nodes={node.content ?? []} {registry} {schema} /></h1>
105
141
  {:else if level === 2}
106
- <h2><RichContent nodes={node.content ?? []} {registry} {schema} /></h2>
142
+ <h2 id={anchor}><RichContent nodes={node.content ?? []} {registry} {schema} /></h2>
107
143
  {:else if level === 3}
108
- <h3><RichContent nodes={node.content ?? []} {registry} {schema} /></h3>
144
+ <h3 id={anchor}><RichContent nodes={node.content ?? []} {registry} {schema} /></h3>
109
145
  {:else if level === 4}
110
- <h4><RichContent nodes={node.content ?? []} {registry} {schema} /></h4>
146
+ <h4 id={anchor}><RichContent nodes={node.content ?? []} {registry} {schema} /></h4>
111
147
  {:else if level === 5}
112
- <h5><RichContent nodes={node.content ?? []} {registry} {schema} /></h5>
148
+ <h5 id={anchor}><RichContent nodes={node.content ?? []} {registry} {schema} /></h5>
113
149
  {:else}
114
- <h6><RichContent nodes={node.content ?? []} {registry} {schema} /></h6>
150
+ <h6 id={anchor}><RichContent nodes={node.content ?? []} {registry} {schema} /></h6>
115
151
  {/if}
152
+ {:else if node.type === 'table'}
153
+ <div class="uncial-table-scroll">
154
+ <table>
155
+ <tbody>
156
+ <RichContent nodes={node.content ?? []} {registry} {schema} />
157
+ </tbody>
158
+ </table>
159
+ </div>
160
+ {:else if node.type === 'tableRow'}
161
+ <tr>
162
+ <RichContent nodes={node.content ?? []} {registry} {schema} />
163
+ </tr>
164
+ {:else if node.type === 'tableHeader'}
165
+ <th>
166
+ <RichContent nodes={node.content ?? []} {registry} {schema} />
167
+ </th>
168
+ {:else if node.type === 'tableCell'}
169
+ <td>
170
+ <RichContent nodes={node.content ?? []} {registry} {schema} />
171
+ </td>
116
172
  {:else if node.type === 'bulletList'}
117
173
  <ul>
118
174
  <RichContent nodes={node.content ?? []} {registry} {schema} />
@@ -5,6 +5,8 @@ interface Props {
5
5
  node: PMNode;
6
6
  registry: BlockRegistry;
7
7
  schema?: ContentSchema;
8
+ tabsGroup?: string;
9
+ tabsLabels?: string[];
8
10
  }
9
11
  declare const RichNode: Component<Props, {}, "">;
10
12
  type RichNode = ReturnType<typeof RichNode>;
@@ -0,0 +1,27 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from 'svelte';
3
+ import { getTabSelection } from './tabSelection.svelte.js';
4
+
5
+ interface Props {
6
+ label?: string;
7
+ tabsGroup?: string;
8
+ tabsLabels?: string[];
9
+ children?: Snippet;
10
+ }
11
+
12
+ let { label = '', tabsGroup = undefined, tabsLabels = [], children }: Props = $props();
13
+
14
+ const normalizedLabel = $derived(label.trim());
15
+ const selection = $derived.by(() => (tabsGroup ? getTabSelection(tabsGroup) : null));
16
+ const activeTab = $derived.by(() => {
17
+ if (!selection) return true;
18
+ const selected = selection.value;
19
+ return (tabsLabels.includes(selected) ? selected : tabsLabels[0]) === normalizedLabel;
20
+ });
21
+ </script>
22
+
23
+ <section role={tabsGroup ? 'tabpanel' : undefined} aria-label={normalizedLabel} hidden={!activeTab}>
24
+ {#if children}
25
+ {@render children()}
26
+ {/if}
27
+ </section>
@@ -0,0 +1,10 @@
1
+ import type { Snippet } from 'svelte';
2
+ interface Props {
3
+ label?: string;
4
+ tabsGroup?: string;
5
+ tabsLabels?: string[];
6
+ children?: Snippet;
7
+ }
8
+ declare const Tab: import("svelte").Component<Props, {}, "">;
9
+ type Tab = ReturnType<typeof Tab>;
10
+ export default Tab;
@@ -0,0 +1,57 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from 'svelte';
3
+ import type { PMNode } from '../shared/document.js';
4
+ import { getTabSelection, loadTabSelection, saveTabSelection } from './tabSelection.svelte.js';
5
+
6
+ interface Props {
7
+ group?: string;
8
+ content?: PMNode[];
9
+ children?: Snippet;
10
+ }
11
+
12
+ let { group = '', content = [], children }: Props = $props();
13
+
14
+ const tabs = $derived.by(() =>
15
+ content.flatMap((node) => {
16
+ if (node.type !== 'tab' || typeof node.attrs?.label !== 'string') return [];
17
+ const label = node.attrs.label.trim();
18
+ return label ? [label] : [];
19
+ })
20
+ );
21
+ const selection = $derived.by(() => (group ? getTabSelection(group) : null));
22
+ const activeTab = $derived.by(() => {
23
+ if (!selection) return tabs[0] ?? '';
24
+ return tabs.includes(selection.value) ? selection.value : (tabs[0] ?? '');
25
+ });
26
+
27
+ $effect(() => {
28
+ if (!selection) return;
29
+ loadTabSelection(group, selection);
30
+ saveTabSelection(group, selection);
31
+ });
32
+
33
+ function selectTab(label: string): void {
34
+ if (!selection) return;
35
+ selection.value = label;
36
+ saveTabSelection(group, selection);
37
+ }
38
+ </script>
39
+
40
+ <section class="uncial-tabs">
41
+ <div role="tablist" aria-label={`${group} tabs`}>
42
+ {#each tabs as tab}
43
+ <button
44
+ type="button"
45
+ role="tab"
46
+ aria-selected={activeTab === tab}
47
+ tabindex={activeTab === tab ? 0 : -1}
48
+ onclick={() => selectTab(tab)}>{tab}</button
49
+ >
50
+ {/each}
51
+ </div>
52
+ <div class="uncial-tabs-content">
53
+ {#if children}
54
+ {@render children()}
55
+ {/if}
56
+ </div>
57
+ </section>
@@ -0,0 +1,10 @@
1
+ import type { Snippet } from 'svelte';
2
+ import type { PMNode } from '../shared/document.js';
3
+ interface Props {
4
+ group?: string;
5
+ content?: PMNode[];
6
+ children?: Snippet;
7
+ }
8
+ declare const Tabs: import("svelte").Component<Props, {}, "">;
9
+ type Tabs = ReturnType<typeof Tabs>;
10
+ export default Tabs;
@@ -1,2 +1,5 @@
1
1
  export { default as Renderer } from './Renderer.svelte';
2
2
  export { default as RichText } from './RichText.svelte';
3
+ export { default as Tab } from './Tab.svelte';
4
+ export { default as Tabs } from './Tabs.svelte';
5
+ export { getCodeLanguageClass, highlightCodeToHtml } from '../shared/syntaxHighlight.js';
@@ -1,2 +1,8 @@
1
1
  export { default as Renderer } from './Renderer.svelte';
2
2
  export { default as RichText } from './RichText.svelte';
3
+ export { default as Tab } from './Tab.svelte';
4
+ export { default as Tabs } from './Tabs.svelte';
5
+ // A consumer's own code block — one built from a component rather than placed in
6
+ // a document — has to read the same as a fence the renderer produced, so the
7
+ // highlighter the renderer uses is part of the render surface.
8
+ export { getCodeLanguageClass, highlightCodeToHtml } from '../shared/syntaxHighlight.js';
@@ -0,0 +1,8 @@
1
+ interface TabSelectionState {
2
+ value: string;
3
+ loaded: boolean;
4
+ }
5
+ export declare function getTabSelection(group: string): TabSelectionState;
6
+ export declare function loadTabSelection(group: string, selection: TabSelectionState): void;
7
+ export declare function saveTabSelection(group: string, selection: TabSelectionState): void;
8
+ export {};
@@ -0,0 +1,40 @@
1
+ const STORAGE_PREFIX = 'uncial-tabs:';
2
+ const selections = new Map();
3
+ class TabSelection {
4
+ value = $state('');
5
+ loaded = $state(false);
6
+ }
7
+ export function getTabSelection(group) {
8
+ if (typeof window === 'undefined') {
9
+ return { value: '', loaded: false };
10
+ }
11
+ let selection = selections.get(group);
12
+ if (!selection) {
13
+ selection = new TabSelection();
14
+ selections.set(group, selection);
15
+ }
16
+ return selection;
17
+ }
18
+ export function loadTabSelection(group, selection) {
19
+ if (selection.loaded || typeof window === 'undefined')
20
+ return;
21
+ selection.loaded = true;
22
+ try {
23
+ const stored = localStorage.getItem(`${STORAGE_PREFIX}${group}`);
24
+ if (stored)
25
+ selection.value = stored;
26
+ }
27
+ catch {
28
+ // Tabs still work for readers whose browser denies storage access.
29
+ }
30
+ }
31
+ export function saveTabSelection(group, selection) {
32
+ if (!selection.loaded || typeof window === 'undefined')
33
+ return;
34
+ try {
35
+ localStorage.setItem(`${STORAGE_PREFIX}${group}`, selection.value);
36
+ }
37
+ catch {
38
+ // Persistence is an enhancement; storage failures must not disable a tab group.
39
+ }
40
+ }
@@ -0,0 +1,6 @@
1
+ import type { PMDoc, PMNode } from './document.js';
2
+ export declare function createBlockId(): string;
3
+ export declare function isBlockNode(node: Pick<PMNode, 'type'>): boolean;
4
+ export declare function headingSlug(node: PMNode): string;
5
+ export declare function stampNodeIdentity(node: PMNode, attrs: Record<string, unknown> | undefined, ids: Set<string>): Record<string, unknown> | undefined;
6
+ export declare function stampDocumentIdentity(document: PMDoc): PMDoc;
@@ -0,0 +1,64 @@
1
+ let fallbackIdSequence = 0;
2
+ export function createBlockId() {
3
+ if (typeof globalThis.crypto?.randomUUID === 'function') {
4
+ return globalThis.crypto.randomUUID();
5
+ }
6
+ fallbackIdSequence += 1;
7
+ return `uncial-${Date.now().toString(36)}-${fallbackIdSequence.toString(36)}`;
8
+ }
9
+ export function isBlockNode(node) {
10
+ return node.type !== 'text' && node.type !== 'hardBreak';
11
+ }
12
+ function nodeText(node) {
13
+ if (node.type === 'text')
14
+ return node.text ?? '';
15
+ return node.content?.map(nodeText).join('') ?? '';
16
+ }
17
+ export function headingSlug(node) {
18
+ const slug = nodeText(node)
19
+ .normalize('NFKD')
20
+ .replace(/\p{M}/gu, '')
21
+ .toLowerCase()
22
+ .replace(/[^a-z0-9]+/g, '-')
23
+ .replace(/^-+|-+$/g, '');
24
+ return slug || 'section';
25
+ }
26
+ export function stampNodeIdentity(node, attrs, ids) {
27
+ if (!isBlockNode(node))
28
+ return attrs;
29
+ const persistedId = attrs?.id;
30
+ const id = typeof persistedId === 'string' && persistedId.length > 0 && !ids.has(persistedId)
31
+ ? persistedId
32
+ : createBlockId();
33
+ ids.add(id);
34
+ const stamped = { ...attrs, id };
35
+ if (node.type === 'heading' && typeof attrs?.slug !== 'string') {
36
+ stamped.slug = headingSlug(node);
37
+ }
38
+ return stamped;
39
+ }
40
+ function stampNode(node, ids) {
41
+ const content = node.content?.map((child) => stampNode(child, ids));
42
+ const stamped = { ...node };
43
+ if (content === undefined) {
44
+ delete stamped.content;
45
+ }
46
+ else {
47
+ stamped.content = content;
48
+ }
49
+ const attrs = stampNodeIdentity(stamped, node.attrs, ids);
50
+ if (attrs === undefined) {
51
+ delete stamped.attrs;
52
+ }
53
+ else {
54
+ stamped.attrs = attrs;
55
+ }
56
+ return stamped;
57
+ }
58
+ export function stampDocumentIdentity(document) {
59
+ const ids = new Set();
60
+ return {
61
+ ...document,
62
+ content: document.content?.map((node) => stampNode(node, ids))
63
+ };
64
+ }
@@ -1,3 +1,17 @@
1
+ /**
2
+ * Registered grammars, named one by one rather than lowlight's `common` set.
3
+ *
4
+ * `common` is 37 grammars and about 172 KB minified, and it lands in the chunk
5
+ * every page rendering a document hydrates — including pages that contain no
6
+ * code at all. These are the languages the alias table below maps, which is the
7
+ * set this renderer can actually name.
8
+ *
9
+ * `plaintext` is registered for the opposite reason to the rest: it matches
10
+ * nothing, and that is its job. An unregistered language falls to
11
+ * `highlightAuto`, so a block declared `plaintext` — console output, a directory
12
+ * tree, a licence key — would be guessed at and coloured, which is precisely
13
+ * what declaring it asks the renderer not to do.
14
+ */
1
15
  export declare const lowlight: {
2
16
  highlight: (language: string, value: string, options?: Readonly<import("lowlight").Options> | null | undefined) => import("hast").Root;
3
17
  highlightAuto: (value: string, options?: Readonly<import("lowlight").AutoOptions> | null | undefined) => import("hast").Root;
@@ -1,10 +1,43 @@
1
- import { common, createLowlight } from 'lowlight';
2
- export const lowlight = createLowlight(common);
1
+ import bash from 'highlight.js/lib/languages/bash';
2
+ import css from 'highlight.js/lib/languages/css';
3
+ import javascript from 'highlight.js/lib/languages/javascript';
4
+ import json from 'highlight.js/lib/languages/json';
5
+ import plaintext from 'highlight.js/lib/languages/plaintext';
6
+ import python from 'highlight.js/lib/languages/python';
7
+ import typescript from 'highlight.js/lib/languages/typescript';
8
+ import xml from 'highlight.js/lib/languages/xml';
9
+ import { createLowlight } from 'lowlight';
10
+ /**
11
+ * Registered grammars, named one by one rather than lowlight's `common` set.
12
+ *
13
+ * `common` is 37 grammars and about 172 KB minified, and it lands in the chunk
14
+ * every page rendering a document hydrates — including pages that contain no
15
+ * code at all. These are the languages the alias table below maps, which is the
16
+ * set this renderer can actually name.
17
+ *
18
+ * `plaintext` is registered for the opposite reason to the rest: it matches
19
+ * nothing, and that is its job. An unregistered language falls to
20
+ * `highlightAuto`, so a block declared `plaintext` — console output, a directory
21
+ * tree, a licence key — would be guessed at and coloured, which is precisely
22
+ * what declaring it asks the renderer not to do.
23
+ */
24
+ export const lowlight = createLowlight({
25
+ bash,
26
+ css,
27
+ javascript,
28
+ json,
29
+ plaintext,
30
+ python,
31
+ typescript,
32
+ xml
33
+ });
3
34
  lowlight.registerAlias({
4
35
  javascript: ['js', 'jsx'],
5
36
  python: ['py'],
6
37
  typescript: ['ts', 'tsx'],
7
- xml: ['html', 'svelte']
38
+ // Vue single-file components are XML-shaped, and naming the alias keeps them
39
+ // off the auto-detect path, whose guess narrowed with the registry above.
40
+ xml: ['html', 'svelte', 'vue']
8
41
  });
9
42
  function escapeHtml(value) {
10
43
  return value