@glw907/cairn-cms 0.51.0 → 0.52.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 (31) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/dist/components/EditPage.svelte +38 -2
  3. package/dist/components/EditorToolbar.svelte +60 -6
  4. package/dist/components/EditorToolbar.svelte.d.ts +10 -1
  5. package/dist/components/MarkdownEditor.svelte +114 -24
  6. package/dist/components/MarkdownEditor.svelte.d.ts +4 -0
  7. package/dist/components/cairn-admin.css +27 -11
  8. package/dist/components/editor-highlight.d.ts +2 -1
  9. package/dist/components/editor-highlight.js +60 -19
  10. package/dist/components/editor-modes.d.ts +26 -0
  11. package/dist/components/editor-modes.js +92 -0
  12. package/dist/components/fonts/iAWriterMono-OFL.txt +100 -0
  13. package/dist/components/fonts/ia-writer-mono-latin-400-italic.woff2 +0 -0
  14. package/dist/components/fonts/ia-writer-mono-latin-400-normal.woff2 +0 -0
  15. package/dist/components/fonts/ia-writer-mono-latin-700-italic.woff2 +0 -0
  16. package/dist/components/fonts/ia-writer-mono-latin-700-normal.woff2 +0 -0
  17. package/dist/components/markdown-directives.d.ts +48 -7
  18. package/dist/components/markdown-directives.js +89 -13
  19. package/package.json +1 -1
  20. package/src/lib/components/EditPage.svelte +38 -2
  21. package/src/lib/components/EditorToolbar.svelte +60 -6
  22. package/src/lib/components/MarkdownEditor.svelte +114 -24
  23. package/src/lib/components/cairn-admin.css +62 -31
  24. package/src/lib/components/editor-highlight.ts +72 -20
  25. package/src/lib/components/editor-modes.ts +106 -0
  26. package/src/lib/components/fonts/iAWriterMono-OFL.txt +100 -0
  27. package/src/lib/components/fonts/ia-writer-mono-latin-400-italic.woff2 +0 -0
  28. package/src/lib/components/fonts/ia-writer-mono-latin-400-normal.woff2 +0 -0
  29. package/src/lib/components/fonts/ia-writer-mono-latin-700-italic.woff2 +0 -0
  30. package/src/lib/components/fonts/ia-writer-mono-latin-700-normal.woff2 +0 -0
  31. package/src/lib/components/markdown-directives.ts +113 -13
package/CHANGELOG.md CHANGED
@@ -2,6 +2,35 @@
2
2
 
3
3
  All notable changes to this project are recorded here, most recent first.
4
4
 
5
+ ## 0.52.1
6
+
7
+ Two field reports from the first 0.52.0 session, both in-editor polish with no consumer action.
8
+ In Write mode the editor card now hugs the manuscript (the column caps at 48rem and centers), so
9
+ a wide window no longer frames empty space inside the card; Preview keeps the full column for
10
+ its device widths. The directive rails take a 4px gap between nested bars (twice the bar
11
+ weight, so two rails read as two lines), and directive text gains a matching step of gutter.
12
+
13
+ ## 0.52.0
14
+
15
+ The editor became a quiet writing surface. The manuscript renders in self-hosted iA Writer Mono
16
+ (SIL OFL) at a centered 70-character measure, heading sizes step by level, every syntax marker
17
+ and URL recedes to the muted ink while the content keeps full strength, inline code sits on a
18
+ soft chip, and quote text reads in full ink with only the `>` dimmed. The editor also parses
19
+ GFM now, so the toolbar's strikethrough, tables, and task lists highlight as you type.
20
+
21
+ Directive machinery trades its row bands for bracket rails: a container draws a depth-stepped
22
+ rail from opener to closer, nested containers draw nested rails, the fence line's name and label
23
+ keep the accent while the colons and braces fade, and the block holding your caret reads one
24
+ step stronger. The treatment is AA-checked in both themes.
25
+
26
+ Two writing modes join the toolbar's overflow menu, each persisted per browser: focus mode fades
27
+ every paragraph but the caret's (a deliberate, documented sub-AA dim with chip backgrounds
28
+ flattened), and typewriter scrolling holds the caret line at vertical center.
29
+
30
+ Consumers may: pass the new optional `focusMode` and `typewriter` booleans when embedding
31
+ `MarkdownEditor` directly; sites on the stock `EditPage` get the toggles and persistence for
32
+ free. No action required; the release is additive.
33
+
5
34
  ## 0.51.0
6
35
 
7
36
  The `svelte` peer dependency floor rises from `^5.0.0` to `^5.56.3`, turning the 0.40.0 advisory
@@ -178,6 +178,25 @@ transient flashes, and the editor card's footer holds the word count and the Mar
178
178
  device = id;
179
179
  localStorage.setItem(deviceStorageKey, id);
180
180
  }
181
+ // The writing modes (focus, typewriter), per-browser preferences on the device pick's pattern:
182
+ // off by default, read in an effect so SSR never touches localStorage, written by the
183
+ // toolbar's toggles. The effect tracks nothing reactive, so it runs once.
184
+ const focusStorageKey = 'cairn-editor-focus-mode';
185
+ const typewriterStorageKey = 'cairn-editor-typewriter';
186
+ let focusMode = $state(false);
187
+ let typewriter = $state(false);
188
+ $effect(() => {
189
+ focusMode = localStorage.getItem(focusStorageKey) === 'true';
190
+ typewriter = localStorage.getItem(typewriterStorageKey) === 'true';
191
+ });
192
+ function setFocusMode(on: boolean) {
193
+ focusMode = on;
194
+ localStorage.setItem(focusStorageKey, String(on));
195
+ }
196
+ function setTypewriter(on: boolean) {
197
+ typewriter = on;
198
+ localStorage.setItem(typewriterStorageKey, String(on));
199
+ }
181
200
  const activeDevice = $derived(previewDevice(device));
182
201
  // The iframe document around the rendered html: the site's stylesheets from the adapter's
183
202
  // preview knob, or a styleless document (behind the hint below) when the site sets none.
@@ -619,7 +638,12 @@ transient flashes, and the editor card's footer holds the word count and the Mar
619
638
  <CsrfField />
620
639
  {#if data.isNew}<input type="hidden" name="new" value="1" />{/if}
621
640
 
622
- <div class="lg:order-1">
641
+ <!-- In Write mode the card hugs the manuscript: the column caps near the 70ch measure and
642
+ centers, so the card frame never spans emptiness on a wide window. Preview keeps the full
643
+ column for its device frames. 48rem = the measure (70ch of the editor face at 1rem is
644
+ about 42rem) plus the surface padding and the card borders, with enough left over that
645
+ the toolbar keeps its single row. -->
646
+ <div class={mode === 'preview' ? 'lg:order-1' : 'lg:order-1 mx-auto w-full max-w-[48rem]'}>
623
647
  {#if titleField}
624
648
  <!-- The hoisted document title: large, borderless, in the display face, so the manuscript
625
649
  reads as the protagonist. It submits as name="title", the same field as before. The
@@ -641,7 +665,17 @@ transient flashes, and the editor card's footer holds the word count and the Mar
641
665
  role="group"
642
666
  aria-label="Editor"
643
667
  >
644
- <EditorToolbar {format} {mode} onMode={setMode} {device} onDevice={setDevice}>
668
+ <EditorToolbar
669
+ {format}
670
+ {mode}
671
+ onMode={setMode}
672
+ {device}
673
+ onDevice={setDevice}
674
+ {focusMode}
675
+ onFocusMode={setFocusMode}
676
+ {typewriter}
677
+ onTypewriter={setTypewriter}
678
+ >
645
679
  {#snippet insertControls()}
646
680
  <!-- Plain triggers only: the dialogs they open hold their own <form> elements, so the
647
681
  dialogs themselves mount outside the edit form at the bottom of this component. -->
@@ -704,6 +738,8 @@ transient flashes, and the editor card's footer holds the word count and the Mar
704
738
  registerGetSelection={(fn) => (getSelection = fn)}
705
739
  registerFormat={(fn) => (format = fn)}
706
740
  {completionSources}
741
+ {focusMode}
742
+ {typewriter}
707
743
  />
708
744
  </div>
709
745
  {#if mode === 'preview'}
@@ -5,7 +5,8 @@ More overflow menu, then the host's Insert controls) and the Write/Preview segme
5
5
  right. Format buttons ask the host to transform the editor's current selection; the host supplies the
6
6
  Insert group through the `insertControls` snippet so the strip stays free of picker wiring. While
7
7
  Preview shows, a device trigger joins the segmented capsule and opens a popover menu of preview
8
- widths, reported to the host through `onDevice`. The glyphs are stroke SVG icons in the admin's
8
+ widths, reported to the host through `onDevice`. The More menu also carries the host's persisted
9
+ writing-mode toggles (focus mode, typewriter scrolling) as pressed-state buttons above the format picks. The glyphs are stroke SVG icons in the admin's
9
10
  house style (24x24 viewBox, `currentColor`, round caps).
10
11
  -->
11
12
  <script lang="ts">
@@ -25,11 +26,30 @@ house style (24x24 viewBox, `currentColor`, round caps).
25
26
  /** Pick a preview-frame width. When set, a device trigger joins the Write/Preview capsule
26
27
  * while Preview shows. */
27
28
  onDevice?: (id: PreviewDeviceId) => void;
29
+ /** Whether focus mode is on; the More menu's toggle reflects it. */
30
+ focusMode?: boolean;
31
+ /** Flip focus mode. When set, the toggle joins the More menu. */
32
+ onFocusMode?: (on: boolean) => void;
33
+ /** Whether typewriter scrolling is on; the More menu's toggle reflects it. */
34
+ typewriter?: boolean;
35
+ /** Flip typewriter scrolling. When set, the toggle joins the More menu. */
36
+ onTypewriter?: (on: boolean) => void;
28
37
  /** The host's Insert controls (link picker, component insert, image), rendered in the Insert group. */
29
38
  insertControls?: Snippet;
30
39
  }
31
40
 
32
- let { format, mode, onMode, device = 'desktop', onDevice, insertControls }: Props = $props();
41
+ let {
42
+ format,
43
+ mode,
44
+ onMode,
45
+ device = 'desktop',
46
+ onDevice,
47
+ focusMode = false,
48
+ onFocusMode,
49
+ typewriter = false,
50
+ onTypewriter,
51
+ insertControls,
52
+ }: Props = $props();
33
53
 
34
54
  // Each icon is a set of stroke `<path>` d-strings rendered into the shared 24x24 svg below, so the
35
55
  // markup stays declarative (no per-icon raw html). Paths follow the house outline style.
@@ -76,6 +96,8 @@ house style (24x24 viewBox, `currentColor`, round caps).
76
96
  ];
77
97
 
78
98
  const ellipsisPaths = ['M5 12h.01', 'M12 12h.01', 'M19 12h.01'];
99
+ // The check glyph marking an active pick, shared by the More menu's toggles and the device list.
100
+ const checkPaths = ['M20 6 9 17l-5-5'];
79
101
 
80
102
  const moreItems: { kind: FormatKind; label: string }[] = [
81
103
  { kind: 'strike', label: 'Strikethrough' },
@@ -91,10 +113,14 @@ house style (24x24 viewBox, `currentColor`, round caps).
91
113
  let moreMenu = $state<HTMLUListElement | null>(null);
92
114
  let moreOpen = $state(false);
93
115
 
116
+ // Picking dismisses the menu; hiding returns focus to the trigger, keeping the roving order.
117
+ function hideMenu(menu: HTMLUListElement | null) {
118
+ if (menu?.matches(':popover-open')) menu.hidePopover();
119
+ }
120
+
94
121
  function pickMore(kind: FormatKind) {
95
122
  format(kind);
96
- // Picking dismisses the menu; hiding returns focus to the trigger, keeping the roving order.
97
- if (moreMenu?.matches(':popover-open')) moreMenu.hidePopover();
123
+ hideMenu(moreMenu);
98
124
  }
99
125
 
100
126
  // The device menu's popover element and its open state, mirrored from the toggle event into
@@ -107,7 +133,7 @@ house style (24x24 viewBox, `currentColor`, round caps).
107
133
 
108
134
  function pickDevice(id: PreviewDeviceId) {
109
135
  onDevice?.(id);
110
- if (deviceMenu?.matches(':popover-open')) deviceMenu.hidePopover();
136
+ hideMenu(deviceMenu);
111
137
  }
112
138
 
113
139
  let toolbarEl = $state<HTMLDivElement | null>(null);
@@ -239,6 +265,34 @@ house style (24x24 viewBox, `currentColor`, round caps).
239
265
  ontoggle={(e) => (moreOpen = e.newState === 'open')}
240
266
  class="dropdown menu menu-sm bg-base-100 rounded-box w-44 border border-[var(--cairn-card-border)] p-1 shadow-[var(--cairn-shadow)]"
241
267
  >
268
+ <!-- The writing modes sit above the format items behind a hairline, persisted by the host.
269
+ The device list's idiom: plain buttons with aria-pressed carrying the on/off state (this
270
+ popover list is not an ARIA menu, so a menuitemcheckbox would sit in an invalid context);
271
+ the check glyph mirrors the state visually. A flip leaves the menu open so the new
272
+ pressed state is perceivable in place; only a format pick dismisses it. -->
273
+ {#if onFocusMode}
274
+ <li>
275
+ <button type="button" aria-pressed={focusMode} onclick={() => onFocusMode(!focusMode)}>
276
+ <span class="grow">Focus mode</span>
277
+ {#if focusMode}
278
+ {@render strokeIcon(checkPaths)}
279
+ {/if}
280
+ </button>
281
+ </li>
282
+ {/if}
283
+ {#if onTypewriter}
284
+ <li>
285
+ <button type="button" aria-pressed={typewriter} onclick={() => onTypewriter(!typewriter)}>
286
+ <span class="grow">Typewriter scrolling</span>
287
+ {#if typewriter}
288
+ {@render strokeIcon(checkPaths)}
289
+ {/if}
290
+ </button>
291
+ </li>
292
+ {/if}
293
+ {#if onFocusMode || onTypewriter}
294
+ <li class="my-1 border-t border-[var(--cairn-card-border)]" role="separator"></li>
295
+ {/if}
242
296
  {#each moreItems as item (item.kind)}
243
297
  <li><button type="button" onclick={() => pickMore(item.kind)}>{item.label}</button></li>
244
298
  {/each}
@@ -299,7 +353,7 @@ house style (24x24 viewBox, `currentColor`, round caps).
299
353
  <button type="button" aria-pressed={device === d.id} onclick={() => pickDevice(d.id)}>
300
354
  <span class="grow">{deviceLabel(d)}</span>
301
355
  {#if device === d.id}
302
- {@render strokeIcon(['M20 6 9 17l-5-5'])}
356
+ {@render strokeIcon(checkPaths)}
303
357
  {/if}
304
358
  </button>
305
359
  </li>
@@ -13,6 +13,14 @@ interface Props {
13
13
  /** Pick a preview-frame width. When set, a device trigger joins the Write/Preview capsule
14
14
  * while Preview shows. */
15
15
  onDevice?: (id: PreviewDeviceId) => void;
16
+ /** Whether focus mode is on; the More menu's toggle reflects it. */
17
+ focusMode?: boolean;
18
+ /** Flip focus mode. When set, the toggle joins the More menu. */
19
+ onFocusMode?: (on: boolean) => void;
20
+ /** Whether typewriter scrolling is on; the More menu's toggle reflects it. */
21
+ typewriter?: boolean;
22
+ /** Flip typewriter scrolling. When set, the toggle joins the More menu. */
23
+ onTypewriter?: (on: boolean) => void;
16
24
  /** The host's Insert controls (link picker, component insert, image), rendered in the Insert group. */
17
25
  insertControls?: Snippet;
18
26
  }
@@ -22,7 +30,8 @@ interface Props {
22
30
  * right. Format buttons ask the host to transform the editor's current selection; the host supplies the
23
31
  * Insert group through the `insertControls` snippet so the strip stays free of picker wiring. While
24
32
  * Preview shows, a device trigger joins the segmented capsule and opens a popover menu of preview
25
- * widths, reported to the host through `onDevice`. The glyphs are stroke SVG icons in the admin's
33
+ * widths, reported to the host through `onDevice`. The More menu also carries the host's persisted
34
+ * writing-mode toggles (focus mode, typewriter scrolling) as pressed-state buttons above the format picks. The glyphs are stroke SVG icons in the admin's
26
35
  * house style (24x24 viewBox, `currentColor`, round caps).
27
36
  */
28
37
  declare const EditorToolbar: import("svelte").Component<Props, {}, "">;
@@ -27,6 +27,10 @@ through the adapter's render. Swapping the editor stays a one-file change.
27
27
  /** Generic CodeMirror completion sources wired into the editor; the link autocomplete is one. The
28
28
  * type is referenced inline so no static `@codemirror/*` import sits in this client-only file. */
29
29
  completionSources?: import('@codemirror/autocomplete').CompletionSource[];
30
+ /** Focus mode: dim every line outside the caret's paragraph. Off by default. */
31
+ focusMode?: boolean;
32
+ /** Typewriter scroll: hold the cursor line at vertical center while typing. Off by default. */
33
+ typewriter?: boolean;
30
34
  }
31
35
 
32
36
  let {
@@ -37,6 +41,8 @@ through the adapter's render. Swapping the editor stays a one-file change.
37
41
  registerGetSelection,
38
42
  registerFormat,
39
43
  completionSources = [],
44
+ focusMode = false,
45
+ typewriter = false,
40
46
  }: Props = $props();
41
47
 
42
48
  let host = $state<HTMLDivElement | null>(null);
@@ -45,6 +51,12 @@ through the adapter's render. Swapping the editor stays a one-file change.
45
51
  // browser. The type-only `import(...)` annotation is erased; the value import is dynamic in onMount,
46
52
  // so the server bundle never pulls CodeMirror (guarded by the editor-boundary test).
47
53
  let view: import('@codemirror/view').EditorView | null = null;
54
+ // The writing-mode extensions live in their own compartments so the toolbar toggles swap them
55
+ // in and out of the mounted editor without rebuilding it. Assigned in onMount with the rest of
56
+ // the dynamic editor modules.
57
+ let modes: typeof import('./editor-modes.js') | null = null;
58
+ let focusCompartment: import('@codemirror/state').Compartment | null = null;
59
+ let typewriterCompartment: import('@codemirror/state').Compartment | null = null;
48
60
 
49
61
  onMount(async () => {
50
62
  const viewMod = await import('@codemirror/view');
@@ -54,6 +66,7 @@ through the adapter's render. Swapping the editor stays a one-file change.
54
66
  const languageMod = await import('@codemirror/language');
55
67
  const autocompleteMod = await import('@codemirror/autocomplete');
56
68
  const highlightMod = await import('./editor-highlight.js');
69
+ const modesMod = await import('./editor-modes.js');
57
70
 
58
71
  if (!host) return;
59
72
 
@@ -61,29 +74,66 @@ through the adapter's render. Swapping the editor stays a one-file change.
61
74
  // Mirror the admin theme into CodeMirror's own dark flag, so its base chrome (the autocomplete
62
75
  // tooltip above all) renders dark-on-dark instead of light-on-dark.
63
76
  const isDark = host.closest('[data-theme]')?.getAttribute('data-theme')?.includes('dark') ?? false;
64
- // The directive machinery treatment. The fence bands and content rails step their alpha by
65
- // nesting depth through the per-theme vars in cairn-admin.css; the fallbacks are the light
66
- // values, so the editor still renders sensibly outside an admin theme wrapper. The deeper
67
- // bands swap in a darker ink (--cairn-directive-ink-N) to hold AA on their own tint.
68
- const band = (depth: number, fallback: string) =>
69
- `color-mix(in oklab, var(--color-accent) var(--cairn-directive-band-${depth}, ${fallback}), transparent)`;
70
- const rail = (depth: number, fallback: string) =>
71
- `inset 2px 0 0 0 color-mix(in oklab, var(--color-accent) var(--cairn-directive-rail-${depth}, ${fallback}), transparent)`;
77
+ // The directive machinery treatment: rails, not bands. A row at depth N draws every rail
78
+ // 1..N as literal nested brackets: 2px accent bars at x offsets 0-2, 6-8, and 12-14 with 4px
79
+ // of surface between them (a gap of twice the bar weight, the floor for two parallel rules
80
+ // to read as separate lines rather than one thick one), stacked as inset box shadows (top
81
+ // layer first, so each bar sits over the spacer and deeper bar beneath it). The alphas step through the per-theme vars in
82
+ // cairn-admin.css; the fallbacks are the light values, so the editor still renders sensibly
83
+ // outside an admin theme wrapper. On a fence line the colon runs, brackets, and {attrs}
84
+ // braces dim to the marker tone while the name and label keep a depth-stepped ink. Leaf and
85
+ // inline directives keep a fixed 8% accent chip; the accent ink holds AA on it (4.75:1
86
+ // light, 5.20:1 dark).
87
+ const railFallbacks = ['72%', '82%', '92%'];
88
+ const railColor = (step: number | 'active', fallback: string) =>
89
+ `color-mix(in oklab, var(--color-accent) var(--cairn-directive-rail-${step}, ${fallback}), transparent)`;
90
+ // With `active`, the row's own (deepest) bar takes the full-strength -active mix and widens
91
+ // 1px, so the caret's container reads at a glance; a bar-width change shifts no text.
92
+ const rails = (depth: number, active = false): string => {
93
+ const layers: string[] = [];
94
+ for (let d = 1; d <= depth; d++) {
95
+ const edge = 6 * d - 4;
96
+ if (d > 1) layers.push(`inset ${edge - 2}px 0 0 0 var(--color-base-100, oklch(99% 0.004 75))`);
97
+ const own = active && d === depth;
98
+ layers.push(
99
+ own
100
+ ? `inset ${edge + 1}px 0 0 0 ${railColor('active', '100%')}`
101
+ : `inset ${edge}px 0 0 0 ${railColor(d, railFallbacks[d - 1] ?? '92%')}`,
102
+ );
103
+ }
104
+ return layers.join(', ');
105
+ };
72
106
  const directiveInk = {
73
- backgroundColor: band(1, '8%'),
107
+ backgroundColor: 'color-mix(in oklab, var(--color-accent) 8%, transparent)',
74
108
  color: 'var(--color-accent)',
75
109
  };
110
+ // The rail rules, one quiet and one caret-active pair per visual depth step (deeper nesting
111
+ // shares the third step). Fence and content rows at a depth share a rule, so a fence and its
112
+ // body rail identically. The caret-active selector adds the caret-block class, so it outranks
113
+ // its quiet twin on any contested row and the caret's container reads one step stronger.
114
+ const railRules: Record<string, { boxShadow: string }> = {};
115
+ for (const depth of [1, 2, 3]) {
116
+ const row = (prefix: string) =>
117
+ `${prefix}.cm-cairn-directive-fence.cm-cairn-depth-${depth}, ${prefix}.cm-cairn-directive-content.cm-cairn-depth-${depth}`;
118
+ railRules[row('')] = { boxShadow: rails(depth) };
119
+ railRules[row('.cm-cairn-caret-block')] = { boxShadow: rails(depth, true) };
120
+ }
76
121
  const theme = EditorView.theme(
77
122
  {
78
- '&': { backgroundColor: 'var(--color-base-100)', color: 'var(--color-base-content)', fontSize: '0.9375rem' },
123
+ '&': { backgroundColor: 'var(--color-base-100)', color: 'var(--color-base-content)', fontSize: '1rem' },
79
124
  // The 50vh floor keeps a short entry reading as a writing surface, and because the
80
125
  // contenteditable content area carries the height, a click in the empty space below the
81
- // text still lands in the editor and focuses it.
126
+ // text still lands in the editor and focuses it. The 70ch cap with auto margins holds
127
+ // the manuscript to a readable measure, centered in whatever width the card gives it.
82
128
  '.cm-content': {
83
- fontFamily: 'ui-monospace, monospace',
129
+ // The theme roots set --font-editor to the self-hosted iA Writer Mono; the inline
130
+ // fallback keeps the surface monospace outside an admin theme wrapper.
131
+ fontFamily: "var(--font-editor, ui-monospace, monospace)",
84
132
  padding: '0.875rem 1.25rem',
85
133
  lineHeight: '1.8',
86
134
  minHeight: '50vh',
135
+ maxWidth: '70ch',
136
+ margin: '0 auto',
87
137
  },
88
138
  '.cm-cursor': { borderLeftColor: 'var(--color-primary)' },
89
139
  // A quiet always-on focus hairline. :focus-visible is no escape here: browsers treat a
@@ -96,32 +146,57 @@ through the adapter's render. Swapping the editor stays a one-file change.
96
146
  outlineOffset: '-1px',
97
147
  },
98
148
  '.cm-line': { padding: '0' },
99
- '.cm-cairn-directive-fence': directiveInk,
100
- '.cm-cairn-directive-fence.cm-cairn-depth-2': {
101
- backgroundColor: band(2, '14%'),
102
- color: 'var(--cairn-directive-ink-2, oklch(50% 0.16 300))',
103
- },
104
- '.cm-cairn-directive-fence.cm-cairn-depth-3': {
105
- backgroundColor: band(3, '20%'),
106
- color: 'var(--cairn-directive-ink-3, oklch(48% 0.16 300))',
149
+ // The gutter: directive rows pad left so the text clears the deepest rail stack (the
150
+ // depth-3 bar ends at 14px, the active one at 15px; 1.5rem keeps ~10px of air beyond
151
+ // it). Static structure (caret-independent), so caret movement shifts no layout.
152
+ '.cm-cairn-directive-fence, .cm-cairn-directive-content': { paddingLeft: '1.5rem' },
153
+ ...railRules,
154
+ '.cm-cairn-directive-mark': { color: 'var(--color-muted)' },
155
+ '.cm-cairn-directive-label': { color: 'var(--color-accent)' },
156
+ '.cm-cairn-directive-label.cm-cairn-depth-2': { color: 'var(--cairn-directive-ink-2, oklch(50% 0.16 300))' },
157
+ '.cm-cairn-directive-label.cm-cairn-depth-3': { color: 'var(--cairn-directive-ink-3, oklch(48% 0.16 300))' },
158
+ // Cursor-aware emphasis for the label ink: the caret's container takes the strongest
159
+ // ink, through the -active variable in cairn-admin.css. This selector TIES the depth
160
+ // rules above at two classes, so its place after them breaks the tie in its favor.
161
+ '.cm-cairn-caret-block .cm-cairn-directive-label': {
162
+ color: 'var(--cairn-directive-ink-active, oklch(46% 0.16 300))',
107
163
  },
108
- '.cm-cairn-directive-content.cm-cairn-depth-1': { boxShadow: rail(1, '75%') },
109
- '.cm-cairn-directive-content.cm-cairn-depth-2': { boxShadow: rail(2, '82%') },
110
- '.cm-cairn-directive-content.cm-cairn-depth-3': { boxShadow: rail(3, '90%') },
111
164
  '.cm-cairn-directive-leaf': directiveInk,
112
165
  '.cm-cairn-directive-inline': directiveInk,
166
+ // Focus mode's dim ink, on the lines editor-modes marks outside the caret's paragraph.
167
+ // Last on purpose: a dimmed line's spans (markers, tokens, directive labels) all drop to
168
+ // the dim tone, and spec order breaks the specificity ties with the label rules above.
169
+ // The fallback is the light theme's value, like the rail fallbacks. Backgrounds flatten
170
+ // along with the ink: the dim tone on the code chip or an 8% accent chip measures under
171
+ // the design's 3:1 floor, so a dimmed line keeps no tinted chip behind its text. The
172
+ // span arm outranks the chip rules on specificity (the highlight style's generated
173
+ // class, the inline-directive mark); the line arm covers the leaf chip, where spec
174
+ // order breaks the tie.
175
+ '.cm-cairn-focus-dim, .cm-cairn-focus-dim span, .cm-cairn-focus-dim .cm-cairn-directive-label': {
176
+ color: 'var(--cairn-focus-dim-ink, oklch(66% 0.01 75))',
177
+ backgroundColor: 'transparent',
178
+ },
113
179
  },
114
180
  { dark: isDark },
115
181
  );
116
182
 
183
+ modes = modesMod;
184
+ focusCompartment = new stateMod.Compartment();
185
+ typewriterCompartment = new stateMod.Compartment();
186
+
117
187
  view = new EditorView({
118
188
  parent: host,
119
189
  state: stateMod.EditorState.create({
120
190
  doc: value,
121
191
  extensions: [
192
+ focusCompartment.of(focusMode ? modesMod.focusMode() : []),
193
+ typewriterCompartment.of(typewriter ? modesMod.typewriterScroll() : []),
122
194
  commandsMod.history(),
123
195
  keymap.of([...autocompleteMod.completionKeymap, ...commandsMod.defaultKeymap, ...commandsMod.historyKeymap]),
124
- markdownMod.markdown(),
196
+ // The GFM base (strikethrough, tables, task lists, autolink) over the commonmark
197
+ // default. markdown() also wires markdownKeymap (Enter continues a list, Backspace
198
+ // removes an empty marker) at high precedence through its addKeymap default.
199
+ markdownMod.markdown({ base: markdownMod.markdownLanguage }),
125
200
  ...(completionSources.length
126
201
  ? // interactionDelay 0: the popup opens only on an explicit `[[` trigger, so the default
127
202
  // accidental-accept guard adds no value and would swallow an immediate Enter into a newline.
@@ -158,6 +233,21 @@ through the adapter's render. Swapping the editor stays a one-file change.
158
233
  view.dispatch({ changes: { from: 0, to: current.length, insert: incoming } });
159
234
  });
160
235
 
236
+ // Reconfigure the writing-mode compartments when their props change. Reading `mounted` re-runs
237
+ // the effect once the editor exists, so a preference arriving between render and mount still
238
+ // applies; the reconfigure is idempotent, so the extra pass after mount costs nothing.
239
+ $effect(() => {
240
+ const focus = focusMode;
241
+ const typing = typewriter;
242
+ if (!mounted || !view || !modes || !focusCompartment || !typewriterCompartment) return;
243
+ view.dispatch({
244
+ effects: [
245
+ focusCompartment.reconfigure(focus ? modes.focusMode() : []),
246
+ typewriterCompartment.reconfigure(typing ? modes.typewriterScroll() : []),
247
+ ],
248
+ });
249
+ });
250
+
161
251
  function insertAtCursor(text: string) {
162
252
  if (!view) {
163
253
  value = value ? `${value}\n\n${text}` : text;
@@ -15,6 +15,10 @@ interface Props {
15
15
  /** Generic CodeMirror completion sources wired into the editor; the link autocomplete is one. The
16
16
  * type is referenced inline so no static `@codemirror/*` import sits in this client-only file. */
17
17
  completionSources?: import('@codemirror/autocomplete').CompletionSource[];
18
+ /** Focus mode: dim every line outside the caret's paragraph. Off by default. */
19
+ focusMode?: boolean;
20
+ /** Typewriter scroll: hold the cursor line at vertical center while typing. Off by default. */
21
+ typewriter?: boolean;
18
22
  }
19
23
  /**
20
24
  * The `MarkdownEditor` seam (spec §6, seam 5): a thin wrapper over CodeMirror 6 exposing a bindable
@@ -1,5 +1,9 @@
1
1
  @font-face{font-family:'Figtree Variable';font-style:normal;font-display:swap;font-weight:300 900;src:url('./fonts/figtree.woff2') format('woff2')}
2
2
  @font-face{font-family:'Bricolage Grotesque Variable';font-style:normal;font-display:swap;font-weight:400 800;src:url('./fonts/bricolage-grotesque.woff2') format('woff2')}
3
+ @font-face{font-family:'iA Writer Mono';font-style:normal;font-display:swap;font-weight:400;src:url('./fonts/ia-writer-mono-latin-400-normal.woff2') format('woff2')}
4
+ @font-face{font-family:'iA Writer Mono';font-style:normal;font-display:swap;font-weight:700;src:url('./fonts/ia-writer-mono-latin-700-normal.woff2') format('woff2')}
5
+ @font-face{font-family:'iA Writer Mono';font-style:italic;font-display:swap;font-weight:400;src:url('./fonts/ia-writer-mono-latin-400-italic.woff2') format('woff2')}
6
+ @font-face{font-family:'iA Writer Mono';font-style:italic;font-display:swap;font-weight:700;src:url('./fonts/ia-writer-mono-latin-700-italic.woff2') format('woff2')}
3
7
  /*! tailwindcss v4.3.0 | MIT License | https://tailwindcss.com */
4
8
  @layer properties {
5
9
  @supports (((-webkit-hyphens: none)) and (not (margin-trim: inline))) or ((-moz-orient: inline) and (not (color: rgb(from red r g b)))) {
@@ -3290,6 +3294,10 @@
3290
3294
  }
3291
3295
  }
3292
3296
 
3297
+ :where([data-theme='cairn-admin'], [data-theme='cairn-admin-dark']) .my-1 {
3298
+ margin-block: calc(var(--spacing) * 1);
3299
+ }
3300
+
3293
3301
  @layer daisyui.l1.l2.l3 {
3294
3302
  :where([data-theme='cairn-admin'], [data-theme='cairn-admin-dark']) .breadcrumbs {
3295
3303
  max-width: 100%;
@@ -4044,6 +4052,10 @@
4044
4052
  max-width: 30%;
4045
4053
  }
4046
4054
 
4055
+ :where([data-theme='cairn-admin'], [data-theme='cairn-admin-dark']) .max-w-\[48rem\] {
4056
+ max-width: 48rem;
4057
+ }
4058
+
4047
4059
  :where([data-theme='cairn-admin'], [data-theme='cairn-admin-dark']) .max-w-full {
4048
4060
  max-width: 100%;
4049
4061
  }
@@ -5432,6 +5444,7 @@
5432
5444
  color-scheme: light;
5433
5445
  --font-body: "Figtree Variable", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
5434
5446
  --font-display: "Bricolage Grotesque Variable", var(--font-body);
5447
+ --font-editor: "iA Writer Mono", ui-monospace, monospace;
5435
5448
  font-family: var(--font-body);
5436
5449
  -webkit-font-smoothing: antialiased;
5437
5450
  -moz-osx-font-smoothing: grayscale;
@@ -5445,14 +5458,15 @@
5445
5458
  --color-secondary-content: oklch(98% .004 75);
5446
5459
  --color-accent: oklch(54% .16 300);
5447
5460
  --color-accent-content: oklch(98% .012 300);
5448
- --cairn-directive-band-1: 8%;
5449
- --cairn-directive-band-2: 14%;
5450
- --cairn-directive-band-3: 20%;
5451
5461
  --cairn-directive-ink-2: oklch(50% .16 300);
5452
5462
  --cairn-directive-ink-3: oklch(48% .16 300);
5453
- --cairn-directive-rail-1: 75%;
5463
+ --cairn-directive-rail-1: 72%;
5454
5464
  --cairn-directive-rail-2: 82%;
5455
- --cairn-directive-rail-3: 90%;
5465
+ --cairn-directive-rail-3: 92%;
5466
+ --cairn-directive-rail-active: 100%;
5467
+ --cairn-directive-ink-active: oklch(46% .16 300);
5468
+ --cairn-code-chip: oklch(94.5% .008 75);
5469
+ --cairn-focus-dim-ink: oklch(66% .01 75);
5456
5470
  --color-neutral: oklch(32% .012 75);
5457
5471
  --color-neutral-content: oklch(96% .004 75);
5458
5472
  --color-info: oklch(52% .12 240);
@@ -5481,6 +5495,7 @@
5481
5495
  color-scheme: dark;
5482
5496
  --font-body: "Figtree Variable", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
5483
5497
  --font-display: "Bricolage Grotesque Variable", var(--font-body);
5498
+ --font-editor: "iA Writer Mono", ui-monospace, monospace;
5484
5499
  font-family: var(--font-body);
5485
5500
  -webkit-font-smoothing: antialiased;
5486
5501
  -moz-osx-font-smoothing: grayscale;
@@ -5494,14 +5509,15 @@
5494
5509
  --color-secondary-content: oklch(20% .008 75);
5495
5510
  --color-accent: oklch(70% .14 300);
5496
5511
  --color-accent-content: oklch(20% .04 300);
5497
- --cairn-directive-band-1: 10%;
5498
- --cairn-directive-band-2: 16%;
5499
- --cairn-directive-band-3: 22%;
5500
5512
  --cairn-directive-ink-2: oklch(74% .14 300);
5501
5513
  --cairn-directive-ink-3: oklch(78% .14 300);
5502
- --cairn-directive-rail-1: 65%;
5503
- --cairn-directive-rail-2: 75%;
5504
- --cairn-directive-rail-3: 85%;
5514
+ --cairn-directive-rail-1: 62%;
5515
+ --cairn-directive-rail-2: 74%;
5516
+ --cairn-directive-rail-3: 86%;
5517
+ --cairn-directive-rail-active: 100%;
5518
+ --cairn-directive-ink-active: oklch(82% .14 300);
5519
+ --cairn-code-chip: oklch(29.5% .012 75);
5520
+ --cairn-focus-dim-ink: oklch(53% .01 75);
5505
5521
  --color-neutral: oklch(80% .01 75);
5506
5522
  --color-neutral-content: oklch(22% .008 75);
5507
5523
  --color-info: oklch(72% .12 240);
@@ -1,10 +1,11 @@
1
1
  import { HighlightStyle } from '@codemirror/language';
2
2
  import { ViewPlugin, type DecorationSet, type ViewUpdate } from '@codemirror/view';
3
+ import { type FenceScan } from './markdown-directives.js';
3
4
  /** Markdown token colors over the admin theme variables. */
4
5
  export declare function cairnHighlightStyle(): HighlightStyle;
5
6
  /** Line and mark decorations flagging remark-directive machinery. */
6
7
  export declare function cairnDirectivePlugin(): ViewPlugin<{
7
8
  decorations: DecorationSet;
8
- depths: (number | null)[];
9
+ scan: FenceScan;
9
10
  update(update: ViewUpdate): void;
10
11
  }, undefined>;