@astl/editor-tiptap 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/styles.js CHANGED
@@ -184,6 +184,10 @@ const baseSurfaceStyles = css `
184
184
  outline: var(--astl-focus-width) solid var(--astl-focus);
185
185
  outline-offset: var(--astl-focus-offset);
186
186
  }
187
+ /* The surface's authoring controls (the page heads' buttons, a page box's, the blocks' "Add option", a frame's
188
+ position line, a picture's buttons) are compact, ghost at rest, so that the exercise looks as students see it. A
189
+ host sizes them with --astl-editor-control-size (their height, 1.75rem), --astl-editor-control-font-size (0.8125rem)
190
+ and --astl-editor-control-icon-size (0.875rem); a target stays at least 24px (WCAG 2.5.8). */
187
191
  .astl-surface
188
192
  :is(
189
193
  .astl-page-join,
@@ -194,17 +198,44 @@ const baseSurfaceStyles = css `
194
198
  .astl-help-remove,
195
199
  .astl-help-free
196
200
  ) {
197
- min-block-size: var(--astl-target-min);
198
- min-inline-size: var(--astl-target-min);
199
- padding-inline: var(--astl-space-3);
200
- border: var(--astl-outline-width) solid var(--astl-outline);
201
+ box-sizing: border-box;
202
+ display: inline-flex;
203
+ align-items: center;
204
+ justify-content: center;
205
+ gap: 0.25rem;
206
+ min-block-size: max(24px, var(--astl-editor-control-size, 1.75rem));
207
+ min-inline-size: max(24px, var(--astl-editor-control-size, 1.75rem));
208
+ padding-block: 0;
209
+ padding-inline: var(--astl-space-2);
210
+ border: var(--astl-outline-width) solid transparent;
201
211
  border-radius: var(--astl-radius-s);
202
- background: var(--astl-surface);
203
- color: var(--astl-ink);
212
+ background: transparent;
213
+ color: var(--astl-ink-muted);
204
214
  font: inherit;
205
- font-size: var(--astl-size-small);
215
+ font-family: var(--astl-font-body);
216
+ font-size: var(--astl-editor-control-font-size, 0.8125rem);
217
+ font-weight: 600;
218
+ line-height: 1.2;
219
+ white-space: nowrap;
206
220
  cursor: pointer;
207
221
  }
222
+ .astl-surface
223
+ :is(
224
+ .astl-page-join,
225
+ .astl-page-delete,
226
+ .astl-page-add-title,
227
+ .astl-page-remove-title,
228
+ .astl-page-check,
229
+ .astl-help-remove,
230
+ .astl-help-free
231
+ ):hover {
232
+ background: var(--astl-accent-soft);
233
+ color: var(--astl-ink);
234
+ }
235
+ .astl-surface :is(.astl-help-remove, .astl-block-add button) .astl-icon {
236
+ inline-size: var(--astl-editor-control-icon-size, 0.875rem);
237
+ block-size: var(--astl-editor-control-icon-size, 0.875rem);
238
+ }
208
239
  .astl-surface
209
240
  :is(.astl-page-join, .astl-page-delete, .astl-page-add-title, .astl-page-remove-title, .astl-help-free)[hidden] {
210
241
  display: none;
@@ -213,6 +244,7 @@ const baseSurfaceStyles = css `
213
244
  .astl-surface .astl-page-check[aria-pressed='true'] {
214
245
  border-color: var(--astl-accent);
215
246
  background: var(--astl-accent-soft);
247
+ color: var(--astl-ink);
216
248
  }
217
249
  .astl-surface .astl-page-check[aria-pressed='true']::before {
218
250
  content: '✓ ' / '';
@@ -411,8 +443,7 @@ const baseSurfaceStyles = css `
411
443
  .astl-surface .astl-frame-note[data-severity='warning'] .astl-icon {
412
444
  color: var(--astl-warning);
413
445
  }
414
- .astl-surface .astl-flag,
415
- .astl-surface .astl-block-add button {
446
+ .astl-surface .astl-flag {
416
447
  box-sizing: border-box;
417
448
  display: inline-flex;
418
449
  align-items: center;
@@ -429,9 +460,9 @@ const baseSurfaceStyles = css `
429
460
  font: inherit;
430
461
  cursor: pointer;
431
462
  }
432
- .astl-surface .astl-block-add button:hover {
433
- border-color: var(--astl-line);
463
+ .astl-surface .astl-block-add button:hover:not(:disabled) {
434
464
  background: var(--astl-accent-soft);
465
+ color: var(--astl-ink);
435
466
  }
436
467
  .astl-surface .astl-block-add :focus-visible,
437
468
  .astl-surface .astl-flag:focus-visible {
@@ -490,22 +521,25 @@ const baseSurfaceStyles = css `
490
521
  position: relative;
491
522
  z-index: 1;
492
523
  box-sizing: border-box;
524
+ display: inline-flex;
525
+ align-items: center;
493
526
  visibility: hidden;
494
- min-block-size: var(--astl-target-min);
527
+ min-block-size: max(24px, var(--astl-editor-control-size, 1.75rem));
495
528
  margin-block: 0 var(--astl-space-1);
496
529
  margin-inline-start: auto;
497
- padding-block: var(--astl-space-1);
530
+ padding-block: 0;
498
531
  padding-inline: var(--astl-space-2);
499
- border: var(--astl-outline-width) solid var(--astl-outline);
532
+ border: var(--astl-outline-width) solid transparent;
500
533
  border-radius: var(--astl-radius-s);
501
- background: var(--astl-surface);
502
- color: var(--astl-ink);
534
+ background: transparent;
535
+ color: var(--astl-ink-muted);
503
536
  font: inherit;
504
537
  font-family: var(--astl-font-body);
505
- font-size: var(--astl-editor-kicker-size, var(--astl-size-small));
538
+ font-size: var(--astl-editor-control-font-size, 0.8125rem);
506
539
  font-style: normal;
507
- font-weight: 400;
508
- line-height: 1.3;
540
+ font-weight: 600;
541
+ line-height: 1.2;
542
+ white-space: nowrap;
509
543
  }
510
544
  .astl-surface .astl-frame-head-current > .astl-frame-line {
511
545
  visibility: visible;
@@ -515,6 +549,7 @@ const baseSurfaceStyles = css `
515
549
  }
516
550
  .astl-surface button.astl-frame-line:hover {
517
551
  background: var(--astl-accent-soft);
552
+ color: var(--astl-ink);
518
553
  }
519
554
  .astl-surface .astl-frame-line:focus-visible {
520
555
  outline: var(--astl-focus-width) solid var(--astl-focus);
@@ -554,13 +589,15 @@ const baseSurfaceStyles = css `
554
589
  }
555
590
  .astl-surface .astl-help-head select {
556
591
  box-sizing: border-box;
557
- min-block-size: var(--astl-target-min);
592
+ min-block-size: max(24px, var(--astl-editor-control-size, 1.75rem));
593
+ padding-block: 0;
558
594
  padding-inline: var(--astl-space-2);
559
595
  border: var(--astl-outline-width) solid var(--astl-outline);
560
596
  border-radius: var(--astl-radius-s);
561
597
  background: var(--astl-surface);
562
598
  color: var(--astl-ink);
563
599
  font: inherit;
600
+ font-size: var(--astl-editor-control-font-size, 0.8125rem);
564
601
  font-weight: 400;
565
602
  cursor: pointer;
566
603
  }
@@ -603,14 +640,16 @@ const baseSurfaceStyles = css `
603
640
  color: var(--astl-ink-muted);
604
641
  pointer-events: none;
605
642
  }
606
- /* A frame's tags: the help for students its component has, small pills in its tab. Each is a 44px target that keeps
643
+ /* A frame's tags: the help for students its component has, small pills in its tab. Each is a 24px target that keeps
607
644
  the tab as high as its line. */
608
645
  .astl-surface .astl-frame-help {
609
646
  box-sizing: border-box;
610
647
  display: inline-flex;
611
648
  align-items: center;
612
- min-block-size: var(--astl-target-min);
613
- margin-block: calc((1.3em - var(--astl-target-min)) / 2);
649
+ justify-content: center;
650
+ min-block-size: 24px;
651
+ min-inline-size: 24px;
652
+ margin-block: calc((1.3em - 24px) / 2);
614
653
  padding: 0;
615
654
  border: 0;
616
655
  background: none;
@@ -702,17 +741,35 @@ const baseSurfaceStyles = css `
702
741
  .astl-surface .astl-block-add {
703
742
  display: flex;
704
743
  flex-wrap: wrap;
705
- gap: var(--astl-space-2);
744
+ gap: var(--astl-space-1);
706
745
  padding-block-start: var(--astl-space-1);
707
746
  }
708
747
  .astl-surface .astl-block-add button[hidden],
709
748
  .astl-surface .astl-block-add:not(:has(button:not([hidden]))) {
710
749
  display: none;
711
750
  }
751
+ /* A small text button under the last child, as the page heads' are. */
712
752
  .astl-surface .astl-block-add button {
713
- padding-inline: var(--astl-space-2) var(--astl-space-3);
714
- color: var(--astl-accent);
753
+ box-sizing: border-box;
754
+ display: inline-flex;
755
+ align-items: center;
756
+ gap: 0.25rem;
757
+ min-block-size: max(24px, var(--astl-editor-control-size, 1.75rem));
758
+ min-inline-size: max(24px, var(--astl-editor-control-size, 1.75rem));
759
+ margin: 0;
760
+ padding-block: 0;
761
+ padding-inline: var(--astl-space-1) var(--astl-space-2);
762
+ border: var(--astl-outline-width) solid transparent;
763
+ border-radius: var(--astl-radius-s);
764
+ background: transparent;
765
+ color: var(--astl-ink-muted);
766
+ font: inherit;
767
+ font-family: var(--astl-font-body);
768
+ font-size: var(--astl-editor-control-font-size, 0.8125rem);
715
769
  font-weight: 600;
770
+ line-height: 1.2;
771
+ white-space: nowrap;
772
+ cursor: pointer;
716
773
  }
717
774
  .astl-surface .astl-block-add button:disabled {
718
775
  color: var(--astl-ink-muted);
@@ -862,28 +919,30 @@ const baseSurfaceStyles = css `
862
919
  font-size: var(--astl-size-small);
863
920
  }
864
921
  .astl-surface button.astl-picture-place {
865
- min-block-size: var(--astl-target-min);
866
- min-inline-size: var(--astl-target-min);
922
+ min-block-size: max(24px, var(--astl-editor-control-size, 1.75rem));
923
+ min-inline-size: max(24px, var(--astl-editor-control-size, 1.75rem));
924
+ padding-block: 0;
867
925
  padding-inline: var(--astl-space-2);
868
926
  border: var(--astl-outline-width) solid var(--astl-outline);
869
927
  border-radius: var(--astl-radius-s);
870
928
  background: var(--astl-surface);
871
929
  color: var(--astl-ink);
872
930
  font: inherit;
873
- font-size: var(--astl-size-small);
931
+ font-size: var(--astl-editor-control-font-size, 0.8125rem);
874
932
  cursor: pointer;
875
933
  }
876
934
  .astl-surface .astl-picture-edit {
877
935
  align-self: flex-start;
878
- min-block-size: var(--astl-target-min);
879
- min-inline-size: var(--astl-target-min);
936
+ min-block-size: max(24px, var(--astl-editor-control-size, 1.75rem));
937
+ min-inline-size: max(24px, var(--astl-editor-control-size, 1.75rem));
938
+ padding-block: 0;
880
939
  padding-inline: var(--astl-space-2);
881
940
  border: var(--astl-outline-width) solid var(--astl-outline);
882
941
  border-radius: var(--astl-radius-s);
883
942
  background: var(--astl-surface);
884
943
  color: var(--astl-ink);
885
944
  font: inherit;
886
- font-size: var(--astl-size-small);
945
+ font-size: var(--astl-editor-control-font-size, 0.8125rem);
887
946
  cursor: pointer;
888
947
  }
889
948
  .astl-surface .astl-figure {
@@ -1 +1 @@
1
- {"version":3,"file":"styles.js","sourceRoot":"","sources":["../src/styles.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAkB,GAAG,EAAE,SAAS,EAAE,M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,CAAC,kBAAkB,GAAG,CAAC,GAAG,IAAI,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;AAC9G,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astl/editor-tiptap",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "<astl-editor>: the authoring kit around a TipTap surface, loaded only when no other editor is plugged in through an adapter.",
5
5
  "keywords": [
6
6
  "astrolabe",
@@ -53,11 +53,11 @@
53
53
  "access": "public"
54
54
  },
55
55
  "dependencies": {
56
- "@astl/core": "0.2.1",
57
- "@astl/editor": "0.2.1",
58
- "@astl/engine": "0.2.1",
59
- "@astl/player": "0.2.1",
60
- "@astl/tokens": "0.2.1",
56
+ "@astl/core": "0.2.2",
57
+ "@astl/editor": "0.2.2",
58
+ "@astl/engine": "0.2.2",
59
+ "@astl/player": "0.2.2",
60
+ "@astl/tokens": "0.2.2",
61
61
  "@tiptap/core": "3.32.0",
62
62
  "@tiptap/pm": "3.32.0",
63
63
  "@tiptap/starter-kit": "3.32.0",
package/src/nodes.ts CHANGED
@@ -67,6 +67,7 @@ import {
67
67
  type DOMOutputSpec,
68
68
  DOMSerializer,
69
69
  Fragment,
70
+ type MarkType,
70
71
  type Mark as PMMark,
71
72
  type Node as PMNode,
72
73
  Slice,
@@ -1032,8 +1033,19 @@ function blockNode(manifest: ComponentManifest, pictures?: PictureView, authorin
1032
1033
  add.addEventListener('click', () => {
1033
1034
  const pos = getPos();
1034
1035
  const block = typeof pos === 'number' ? editor.state.doc.nodeAt(pos) : null;
1036
+ if (typeof pos !== 'number' || block === null) return;
1037
+ // In a rich block the child is a mark in its text (Select words' word): a new word ends its last line.
1038
+ const markType = editor.schema.marks[childType];
1039
+ if (markType !== undefined) {
1040
+ const word = authoring.t(EDITOR_NAMESPACE, 'surface.newWord');
1041
+ const tr = addMarkedWord(editor.state, pos, block, markType, repeated.tag, word);
1042
+ if (tr === null) return;
1043
+ editor.view.dispatch(tr.scrollIntoView());
1044
+ editor.view.focus();
1045
+ return;
1046
+ }
1035
1047
  const type = editor.schema.nodes[childType];
1036
- if (typeof pos !== 'number' || block === null || type === undefined) return;
1048
+ if (type === undefined) return;
1037
1049
  // After the last child of that tag (an option goes after the options, before anything after them).
1038
1050
  let at = pos + block.nodeSize - 1;
1039
1051
  block.forEach((child, offset) => {
@@ -1093,6 +1105,113 @@ function blockNode(manifest: ComponentManifest, pictures?: PictureView, authorin
1093
1105
  });
1094
1106
  }
1095
1107
 
1108
+ /**
1109
+ * A new child of a rich block that is a mark in its text (Select words' word, `markType`): `text` at the end of the
1110
+ * block's last line (after a space), with a fresh id, selected so that typing replaces it and keeps the mark; one undo
1111
+ * step. A block without a line of text gets one.
1112
+ */
1113
+ function addMarkedWord(
1114
+ state: EditorState,
1115
+ pos: number,
1116
+ block: PMNode,
1117
+ markType: MarkType,
1118
+ tag: string,
1119
+ text: string,
1120
+ ): Transaction | null {
1121
+ const tr = closeHistory(state.tr);
1122
+ let end: number | null = null;
1123
+ block.descendants((node, offset) => {
1124
+ if (node.type.name === 'paragraph' || node.type.name === 'heading')
1125
+ end = pos + 2 + offset + node.content.size;
1126
+ return !node.isTextblock;
1127
+ });
1128
+ if (end === null) {
1129
+ const paragraph = state.schema.nodes.paragraph;
1130
+ if (paragraph === undefined) return null;
1131
+ const at = pos + block.nodeSize - 1;
1132
+ tr.insert(at, paragraph.create());
1133
+ end = at + 1;
1134
+ }
1135
+ let at: number = end;
1136
+ const $end = tr.doc.resolve(at);
1137
+ const before = $end.parent.textBetween(0, $end.parentOffset, undefined, '\ufffc');
1138
+ // A plain space before it: inserted text would take the mark of a word that ends the line.
1139
+ if (before !== '' && !/\s$/u.test(before)) {
1140
+ tr.insert(at, state.schema.text(' '));
1141
+ at += 1;
1142
+ }
1143
+ const taken = idsIn(tr.doc);
1144
+ tr.doc.descendants((node) => {
1145
+ for (const mark of node.marks) if (mark.type === markType) taken.add(markId(mark));
1146
+ return true;
1147
+ });
1148
+ const id = freshId(tag.replace(/^astl-/, ''), taken);
1149
+ tr.insert(at, state.schema.text(text, [markType.create({ attributes: { id } })]));
1150
+ // The word grows as the author types over it or at its end (`growingWordExtension`).
1151
+ return tr
1152
+ .setSelection(TextSelection.create(tr.doc, at, at + text.length))
1153
+ .setMeta(GROWING, { id, type: markType });
1154
+ }
1155
+
1156
+ /** The word "Add option" just added in a rich block: its id and mark type, until the cursor leaves it. */
1157
+ interface Growing {
1158
+ readonly id: string;
1159
+ readonly type: MarkType;
1160
+ }
1161
+ const GROWING = new PluginKey<Growing | null>('astlGrowingWord');
1162
+
1163
+ /** Where the run of text marked `growing` is (one word), with its mark, or null. */
1164
+ function growingRun(doc: PMNode, growing: Growing): { from: number; to: number; mark: PMMark } | null {
1165
+ let run: { from: number; to: number; mark: PMMark } | null = null;
1166
+ doc.descendants((node, pos) => {
1167
+ if (!node.isText) return run === null;
1168
+ const mark = node.marks.find((m) => m.type === growing.type && markId(m) === growing.id);
1169
+ if (mark === undefined) return false;
1170
+ run = run === null ? { from: pos, to: pos + node.nodeSize, mark } : { ...run, to: pos + node.nodeSize };
1171
+ return false;
1172
+ });
1173
+ return run;
1174
+ }
1175
+
1176
+ /**
1177
+ * A word "Add option" added keeps growing while the author types it: text typed over it (it comes selected) or at its
1178
+ * end joins it, though the words' marks end with them, until a space or the cursor leaves it. Other words keep their
1179
+ * marks as they are.
1180
+ */
1181
+ const growingWordExtension = Extension.create({
1182
+ name: 'astlGrowingWord',
1183
+ addProseMirrorPlugins: () => [
1184
+ new Plugin<Growing | null>({
1185
+ key: GROWING,
1186
+ state: {
1187
+ init: () => null,
1188
+ apply: (tr, value, _, state) => {
1189
+ const set = tr.getMeta(GROWING) as Growing | null | undefined;
1190
+ const growing = set === undefined ? value : set;
1191
+ if (growing === null) return null;
1192
+ const run = growingRun(state.doc, growing);
1193
+ const { from, to } = state.selection;
1194
+ return run !== null && from >= run.from && to <= run.to ? growing : null;
1195
+ },
1196
+ },
1197
+ props: {
1198
+ handleTextInput: (view, from, to, text) => {
1199
+ const growing = GROWING.getState(view.state);
1200
+ if (growing === null || growing === undefined || !/^[\p{L}\p{N}\p{M}'’-]+$/u.test(text))
1201
+ return false;
1202
+ const run = growingRun(view.state.doc, growing);
1203
+ if (run === null) return false;
1204
+ const over = from === run.from && to === run.to;
1205
+ if (!over && !(from === to && from === run.to)) return false;
1206
+ const tr = view.state.tr.insertText(text, from, to);
1207
+ view.dispatch(tr.addMark(from, from + text.length, run.mark));
1208
+ return true;
1209
+ },
1210
+ },
1211
+ }),
1212
+ ],
1213
+ });
1214
+
1096
1215
  /**
1097
1216
  * A rich child of a block (prompt, option): one line of rich text, in a plain element so no custom element claims
1098
1217
  * it. A child the manifest allows once (a prompt) is marked `single`.
@@ -3054,6 +3173,7 @@ export function astrolabeExtensions(
3054
3173
  referencesExtension(authoring, manifests),
3055
3174
  childrenExtension(manifests),
3056
3175
  richBlocksExtension(authoring, manifests),
3176
+ growingWordExtension,
3057
3177
  pastedIdsExtension(authoring, manifests, hooks),
3058
3178
  blocksExtension(
3059
3179
  authoring,
package/src/styles.ts CHANGED
@@ -186,6 +186,10 @@ const baseSurfaceStyles: CSSResult = css`
186
186
  outline: var(--astl-focus-width) solid var(--astl-focus);
187
187
  outline-offset: var(--astl-focus-offset);
188
188
  }
189
+ /* The surface's authoring controls (the page heads' buttons, a page box's, the blocks' "Add option", a frame's
190
+ position line, a picture's buttons) are compact, ghost at rest, so that the exercise looks as students see it. A
191
+ host sizes them with --astl-editor-control-size (their height, 1.75rem), --astl-editor-control-font-size (0.8125rem)
192
+ and --astl-editor-control-icon-size (0.875rem); a target stays at least 24px (WCAG 2.5.8). */
189
193
  .astl-surface
190
194
  :is(
191
195
  .astl-page-join,
@@ -196,17 +200,44 @@ const baseSurfaceStyles: CSSResult = css`
196
200
  .astl-help-remove,
197
201
  .astl-help-free
198
202
  ) {
199
- min-block-size: var(--astl-target-min);
200
- min-inline-size: var(--astl-target-min);
201
- padding-inline: var(--astl-space-3);
202
- border: var(--astl-outline-width) solid var(--astl-outline);
203
+ box-sizing: border-box;
204
+ display: inline-flex;
205
+ align-items: center;
206
+ justify-content: center;
207
+ gap: 0.25rem;
208
+ min-block-size: max(24px, var(--astl-editor-control-size, 1.75rem));
209
+ min-inline-size: max(24px, var(--astl-editor-control-size, 1.75rem));
210
+ padding-block: 0;
211
+ padding-inline: var(--astl-space-2);
212
+ border: var(--astl-outline-width) solid transparent;
203
213
  border-radius: var(--astl-radius-s);
204
- background: var(--astl-surface);
205
- color: var(--astl-ink);
214
+ background: transparent;
215
+ color: var(--astl-ink-muted);
206
216
  font: inherit;
207
- font-size: var(--astl-size-small);
217
+ font-family: var(--astl-font-body);
218
+ font-size: var(--astl-editor-control-font-size, 0.8125rem);
219
+ font-weight: 600;
220
+ line-height: 1.2;
221
+ white-space: nowrap;
208
222
  cursor: pointer;
209
223
  }
224
+ .astl-surface
225
+ :is(
226
+ .astl-page-join,
227
+ .astl-page-delete,
228
+ .astl-page-add-title,
229
+ .astl-page-remove-title,
230
+ .astl-page-check,
231
+ .astl-help-remove,
232
+ .astl-help-free
233
+ ):hover {
234
+ background: var(--astl-accent-soft);
235
+ color: var(--astl-ink);
236
+ }
237
+ .astl-surface :is(.astl-help-remove, .astl-block-add button) .astl-icon {
238
+ inline-size: var(--astl-editor-control-icon-size, 0.875rem);
239
+ block-size: var(--astl-editor-control-icon-size, 0.875rem);
240
+ }
210
241
  .astl-surface
211
242
  :is(.astl-page-join, .astl-page-delete, .astl-page-add-title, .astl-page-remove-title, .astl-help-free)[hidden] {
212
243
  display: none;
@@ -215,6 +246,7 @@ const baseSurfaceStyles: CSSResult = css`
215
246
  .astl-surface .astl-page-check[aria-pressed='true'] {
216
247
  border-color: var(--astl-accent);
217
248
  background: var(--astl-accent-soft);
249
+ color: var(--astl-ink);
218
250
  }
219
251
  .astl-surface .astl-page-check[aria-pressed='true']::before {
220
252
  content: '✓ ' / '';
@@ -413,8 +445,7 @@ const baseSurfaceStyles: CSSResult = css`
413
445
  .astl-surface .astl-frame-note[data-severity='warning'] .astl-icon {
414
446
  color: var(--astl-warning);
415
447
  }
416
- .astl-surface .astl-flag,
417
- .astl-surface .astl-block-add button {
448
+ .astl-surface .astl-flag {
418
449
  box-sizing: border-box;
419
450
  display: inline-flex;
420
451
  align-items: center;
@@ -431,9 +462,9 @@ const baseSurfaceStyles: CSSResult = css`
431
462
  font: inherit;
432
463
  cursor: pointer;
433
464
  }
434
- .astl-surface .astl-block-add button:hover {
435
- border-color: var(--astl-line);
465
+ .astl-surface .astl-block-add button:hover:not(:disabled) {
436
466
  background: var(--astl-accent-soft);
467
+ color: var(--astl-ink);
437
468
  }
438
469
  .astl-surface .astl-block-add :focus-visible,
439
470
  .astl-surface .astl-flag:focus-visible {
@@ -492,22 +523,25 @@ const baseSurfaceStyles: CSSResult = css`
492
523
  position: relative;
493
524
  z-index: 1;
494
525
  box-sizing: border-box;
526
+ display: inline-flex;
527
+ align-items: center;
495
528
  visibility: hidden;
496
- min-block-size: var(--astl-target-min);
529
+ min-block-size: max(24px, var(--astl-editor-control-size, 1.75rem));
497
530
  margin-block: 0 var(--astl-space-1);
498
531
  margin-inline-start: auto;
499
- padding-block: var(--astl-space-1);
532
+ padding-block: 0;
500
533
  padding-inline: var(--astl-space-2);
501
- border: var(--astl-outline-width) solid var(--astl-outline);
534
+ border: var(--astl-outline-width) solid transparent;
502
535
  border-radius: var(--astl-radius-s);
503
- background: var(--astl-surface);
504
- color: var(--astl-ink);
536
+ background: transparent;
537
+ color: var(--astl-ink-muted);
505
538
  font: inherit;
506
539
  font-family: var(--astl-font-body);
507
- font-size: var(--astl-editor-kicker-size, var(--astl-size-small));
540
+ font-size: var(--astl-editor-control-font-size, 0.8125rem);
508
541
  font-style: normal;
509
- font-weight: 400;
510
- line-height: 1.3;
542
+ font-weight: 600;
543
+ line-height: 1.2;
544
+ white-space: nowrap;
511
545
  }
512
546
  .astl-surface .astl-frame-head-current > .astl-frame-line {
513
547
  visibility: visible;
@@ -517,6 +551,7 @@ const baseSurfaceStyles: CSSResult = css`
517
551
  }
518
552
  .astl-surface button.astl-frame-line:hover {
519
553
  background: var(--astl-accent-soft);
554
+ color: var(--astl-ink);
520
555
  }
521
556
  .astl-surface .astl-frame-line:focus-visible {
522
557
  outline: var(--astl-focus-width) solid var(--astl-focus);
@@ -556,13 +591,15 @@ const baseSurfaceStyles: CSSResult = css`
556
591
  }
557
592
  .astl-surface .astl-help-head select {
558
593
  box-sizing: border-box;
559
- min-block-size: var(--astl-target-min);
594
+ min-block-size: max(24px, var(--astl-editor-control-size, 1.75rem));
595
+ padding-block: 0;
560
596
  padding-inline: var(--astl-space-2);
561
597
  border: var(--astl-outline-width) solid var(--astl-outline);
562
598
  border-radius: var(--astl-radius-s);
563
599
  background: var(--astl-surface);
564
600
  color: var(--astl-ink);
565
601
  font: inherit;
602
+ font-size: var(--astl-editor-control-font-size, 0.8125rem);
566
603
  font-weight: 400;
567
604
  cursor: pointer;
568
605
  }
@@ -605,14 +642,16 @@ const baseSurfaceStyles: CSSResult = css`
605
642
  color: var(--astl-ink-muted);
606
643
  pointer-events: none;
607
644
  }
608
- /* A frame's tags: the help for students its component has, small pills in its tab. Each is a 44px target that keeps
645
+ /* A frame's tags: the help for students its component has, small pills in its tab. Each is a 24px target that keeps
609
646
  the tab as high as its line. */
610
647
  .astl-surface .astl-frame-help {
611
648
  box-sizing: border-box;
612
649
  display: inline-flex;
613
650
  align-items: center;
614
- min-block-size: var(--astl-target-min);
615
- margin-block: calc((1.3em - var(--astl-target-min)) / 2);
651
+ justify-content: center;
652
+ min-block-size: 24px;
653
+ min-inline-size: 24px;
654
+ margin-block: calc((1.3em - 24px) / 2);
616
655
  padding: 0;
617
656
  border: 0;
618
657
  background: none;
@@ -704,17 +743,35 @@ const baseSurfaceStyles: CSSResult = css`
704
743
  .astl-surface .astl-block-add {
705
744
  display: flex;
706
745
  flex-wrap: wrap;
707
- gap: var(--astl-space-2);
746
+ gap: var(--astl-space-1);
708
747
  padding-block-start: var(--astl-space-1);
709
748
  }
710
749
  .astl-surface .astl-block-add button[hidden],
711
750
  .astl-surface .astl-block-add:not(:has(button:not([hidden]))) {
712
751
  display: none;
713
752
  }
753
+ /* A small text button under the last child, as the page heads' are. */
714
754
  .astl-surface .astl-block-add button {
715
- padding-inline: var(--astl-space-2) var(--astl-space-3);
716
- color: var(--astl-accent);
755
+ box-sizing: border-box;
756
+ display: inline-flex;
757
+ align-items: center;
758
+ gap: 0.25rem;
759
+ min-block-size: max(24px, var(--astl-editor-control-size, 1.75rem));
760
+ min-inline-size: max(24px, var(--astl-editor-control-size, 1.75rem));
761
+ margin: 0;
762
+ padding-block: 0;
763
+ padding-inline: var(--astl-space-1) var(--astl-space-2);
764
+ border: var(--astl-outline-width) solid transparent;
765
+ border-radius: var(--astl-radius-s);
766
+ background: transparent;
767
+ color: var(--astl-ink-muted);
768
+ font: inherit;
769
+ font-family: var(--astl-font-body);
770
+ font-size: var(--astl-editor-control-font-size, 0.8125rem);
717
771
  font-weight: 600;
772
+ line-height: 1.2;
773
+ white-space: nowrap;
774
+ cursor: pointer;
718
775
  }
719
776
  .astl-surface .astl-block-add button:disabled {
720
777
  color: var(--astl-ink-muted);
@@ -864,28 +921,30 @@ const baseSurfaceStyles: CSSResult = css`
864
921
  font-size: var(--astl-size-small);
865
922
  }
866
923
  .astl-surface button.astl-picture-place {
867
- min-block-size: var(--astl-target-min);
868
- min-inline-size: var(--astl-target-min);
924
+ min-block-size: max(24px, var(--astl-editor-control-size, 1.75rem));
925
+ min-inline-size: max(24px, var(--astl-editor-control-size, 1.75rem));
926
+ padding-block: 0;
869
927
  padding-inline: var(--astl-space-2);
870
928
  border: var(--astl-outline-width) solid var(--astl-outline);
871
929
  border-radius: var(--astl-radius-s);
872
930
  background: var(--astl-surface);
873
931
  color: var(--astl-ink);
874
932
  font: inherit;
875
- font-size: var(--astl-size-small);
933
+ font-size: var(--astl-editor-control-font-size, 0.8125rem);
876
934
  cursor: pointer;
877
935
  }
878
936
  .astl-surface .astl-picture-edit {
879
937
  align-self: flex-start;
880
- min-block-size: var(--astl-target-min);
881
- min-inline-size: var(--astl-target-min);
938
+ min-block-size: max(24px, var(--astl-editor-control-size, 1.75rem));
939
+ min-inline-size: max(24px, var(--astl-editor-control-size, 1.75rem));
940
+ padding-block: 0;
882
941
  padding-inline: var(--astl-space-2);
883
942
  border: var(--astl-outline-width) solid var(--astl-outline);
884
943
  border-radius: var(--astl-radius-s);
885
944
  background: var(--astl-surface);
886
945
  color: var(--astl-ink);
887
946
  font: inherit;
888
- font-size: var(--astl-size-small);
947
+ font-size: var(--astl-editor-control-font-size, 0.8125rem);
889
948
  cursor: pointer;
890
949
  }
891
950
  .astl-surface .astl-figure {