svelte-rtf-editor 1.13.0 → 1.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -13,7 +13,11 @@ RTF viewer and rich-text editor components for **Svelte 5**.
13
13
  - **`InkEditor`** — Full rich-text editor that reads and writes RTF, built on `contenteditable`
14
14
  - Formatting toolbar: bold, italic, underline, strikethrough, font colour
15
15
  - Block-level controls: headings (H1–H3), paragraph, blockquote, code block
16
- - Images: upload, paste or drag-and-drop, with a description below each picture, drag-to-resize and left/centre/right placement — embedded in the RTF, not linked
16
+ - Bullet and numbered lists, and lists within lists, made the same in every browser. See [Lists](#lists)
17
+ - Undo and Redo of everything the editor changes, a picture or a table put in as much as typing. See [Undo and Redo](#undo-and-redo)
18
+ - Line spacing, and the space before and after a paragraph, in points; and the gap between a list's bullets or numbers and its text. See [Line and paragraph spacing](#line-and-paragraph-spacing)
19
+ - Tables: insert one with or without borders; the borders are in the RTF. See [Tables](#tables)
20
+ - Images: upload, paste or drag-and-drop, with a description below each picture, drag-to-resize, left/centre/right placement, move up and down, and two or more side by side, each with its own description — embedded in the RTF, not linked
17
21
  - Import an RTF file from disk; export as RTF, HTML, or Markdown
18
22
  - Optional auto-save to `localStorage` (off unless asked for)
19
23
  - HTML from outside (the `content` prop, `setHTML`, a restored draft, a paste, a drop) is made safe before it is shown. See [HTML from outside](#html-from-outside)
@@ -167,6 +171,12 @@ editor.importRtf() // → void — open the file picker to import .rtf
167
171
  editor.setFontSize(14) // → void — size, in points, of the selected text, or of what is typed next
168
172
  editor.setFont('Calibri') // → void — font of the selected text, or of what is typed next: one of `fonts`, or '' for the document font
169
173
  editor.clearFormatting() // → void — take bold, italic, underline, strike, color, size and font off the selected text
174
+ editor.setLineSpacing(1.5) // → void — line spacing of the selected paragraphs, in lines; null for the document's own
175
+ editor.setParagraphSpacing({ before: 6, after: 12 }) // → void — space before and after them, in points; either may be left out, 0 or null is none
176
+ editor.setListMarkerGap(27) // → void — gap between the markers and the text of the selected lists, in points (6 to 144); null for the quarter inch
177
+ editor.insertTable(3, 2, { borders: true, header: false }) // → void — a table of empty cells after the paragraph the caret is in
178
+ editor.undo() // → boolean — take back the last step; false if there was none
179
+ editor.redo() // → boolean — make a step that was taken back again; false if there was none
170
180
  ```
171
181
 
172
182
  #### Auto-save
@@ -367,12 +377,40 @@ The toolbar's Clear formatting button, next to the text color, takes the formatt
367
377
 
368
378
  - Only the selected words change: clearing two words of a bold sentence leaves the rest bold.
369
379
  - The result is the same HTML in Chromium, Firefox and Safari (the browser tests run in all three engines, on every push). The browsers' own command is not: one takes a paragraph's alignment with its color, another leaves the color on the paragraph, a third takes out the element your mark is on.
370
- - Undo puts the formatting back and Redo takes it off again, from the keyboard and from the toolbar, also after more has been typed and undone. In Safari one Undo may take back the step before it as well.
371
- - On a very long selection it takes time, and four times as long for twice the length. The time is the browser's own command, which the editor uses so that the browser's Undo knows of the change: measured on paragraphs with four formatted runs each, 250 of them (about eight pages) clear in a quarter of a second in Chromium, 1,000 in three seconds, 2,000 in twelve; Safari's engine takes about two thirds of that and Firefox a tenth. A report of ordinary length is not affected.
380
+ - Undo puts the formatting back and Redo takes it off again, from the keyboard and from the toolbar, also after more has been typed and undone.
381
+ - On a very long selection it takes time, and four times as long for twice the length. The time is the browser's own command: measured on paragraphs with four formatted runs each, 250 of them (about eight pages) clear in a quarter of a second in Chromium, 1,000 in three seconds, 2,000 in twelve; Safari's engine takes about two thirds of that and Firefox a tenth. A report of ordinary length is not affected.
372
382
  - A mark stays whole in all three browsers, whatever part of it is selected. In Firefox the words inside it keep the bold or italic they have there: its command cannot clear them without cutting the mark in two.
373
383
 
374
384
  ---
375
385
 
386
+ ## Lists
387
+
388
+ The toolbar's **Bullet list** and **Numbered list** buttons are the editor's own, not the browser's list commands, so a list is made the same in Chrome, Edge, Safari and Firefox, and its HTML is the same.
389
+
390
+ - **Making a list.** Every line the selection touches becomes an item: a paragraph, a heading, or a line of words in no paragraph. Lines next to each other are one list, and a line made an item next to a list of the same kind is an item of that list, whichever is made first; the numbers run on. The caret stays in the words where it was.
391
+ - **Taking it off.** The button of the kind the items already are makes them paragraphs again, one paragraph for each item. One item taken off in the middle leaves a list before it and a list after it.
392
+ - **The other kind.** With the caret in a list, the other button changes the whole list, bullets to numbers or back. With items selected, it changes those items.
393
+ - **A list within a list.** `Tab` at the start of an item, or Increase indent anywhere in it, puts the item under the item before it; `Shift+Tab` or Decrease indent takes it out again. Several items selected go together. The first item of a list has none before it to go under: there Increase indent moves the whole list, as it moves a paragraph, and `Tab` types a tab.
394
+ - **Leaving a list.** `Enter` in an item with nothing in it, and `Backspace` at the start of an item, take the item one list out; from a list that is in no other, it becomes a paragraph.
395
+ - The buttons are lit while the caret is in a list of their kind. In a list within a list, the kind is the inner list's.
396
+ - Not made an item: a picture with its caption, a table as a whole (a line inside a cell is), a code block.
397
+ - A lettered list or one in Roman numerals (`<ol type="A">`) is kept as it is and takes new items; the buttons make bullets and plain numbers only.
398
+
399
+ How a list is written to RTF and read back is under [What is written, and what is read back](#what-is-written-and-what-is-read-back).
400
+
401
+ ## Undo and Redo
402
+
403
+ The editor keeps its own history. `Ctrl+Z` / `Cmd+Z`, `Ctrl+Shift+Z` / `Cmd+Shift+Z`, `Ctrl+Y`, the toolbar's buttons, the browser's Edit menu, and `editor.undo()` / `editor.redo()` all go through it.
404
+
405
+ A browser's history knows only its own commands and what was typed. It knew nothing of a picture or a table put in, a picture moved, placed beside another or resized, an indent, a spacing, or a list: its Undo went past those to the typing before them, and after some of them it could undo nothing at all. The editor's history takes back whatever changed the document, in the order it was done.
406
+
407
+ - **A step** is one press of a button, one paste, one drop, a new paragraph, or a run of typing. Typing is one step until the writer pauses for a second, moves the caret, or changes from typing to deleting.
408
+ - **The caret** is put back where it was before the step.
409
+ - **Redo** makes a step again that Undo took back, until something else is changed.
410
+ - **A new document starts a new history.** After `setHTML()`, `clear()`, or an RTF file imported, Undo does not lead back into the document that was there before.
411
+ - What Undo puts back is checked as everything that reaches the editor is (see [HTML from outside](#html-from-outside)).
412
+ - 200 steps are kept. A step holds the document's HTML with each embedded picture kept once, not once per step, so a report with megabytes of pictures does not hold them 200 times.
413
+
376
414
  ## Paragraph formatting
377
415
 
378
416
  A `<p>` or `<div>` keeps its own indents, spacing and tab stops in the RTF, so a layout made of ordinary paragraphs, such as a bold label, a tab, and text in a column with later lines hanging under it, reaches the receiving system:
@@ -383,16 +421,40 @@ A `<p>` or `<div>` keeps its own indents, spacing and tab stops in the RTF, so a
383
421
  | `margin-right: 0.5in` | `\ri720` |
384
422
  | `text-indent: -1.75in` | `\fi-2520` |
385
423
  | `margin-top: 5pt` / `margin-bottom: 5pt` | `\sb100` / `\sa100` |
424
+ | `line-height: 1.5` (or `150%`) | `\sl360\slmult1` |
425
+ | `line-height: 14pt` | `\sl-280\slmult0` (exactly 14 pt) |
386
426
  | `break-after: avoid` or `page-break-after: avoid` | `\keepn` |
387
427
  | `data-rtf-tab-stops="1.75in"` (comma-separated) | `\tx2520` |
388
428
 
389
429
  - Lengths in `in`, `pt`, `cm`, `mm` or `px` (15 twips per px), rounded to whole twips. Only `text-indent` may be negative. A value the writer cannot read, or zero, writes nothing.
390
430
  - CSS has no absolute tab stop, hence the `data-` attribute. On screen, `white-space: pre-wrap; tab-size: 1.75in` with that hanging indent puts the browser's first stop at the same place, and `pre-wrap` makes the writer send the tab as `\tab`.
391
431
  - `margin-left` adds to the indent of the blocks around the paragraph (an indent pasted from a browser, or a `<div>` with a margin that holds paragraphs), and is written as one `\li`.
392
- - Inside a table cell the cell declares its own paragraph: only alignment and the left indent are written there, not the right or first-line indent, spacing, tab stops or keep-with-next.
432
+ - Inside a table cell the cell declares its own paragraph: alignment, the left indent and spacing are written there, not the right or first-line indent, tab stops or keep-with-next.
393
433
  - `rtfToHtml` reads the three indents back, in points: `\li720\ri720\fi-720` becomes `margin-left:36pt;margin-right:36pt;text-indent:-36pt`, and `RtfViewer` shows them. As in RTF, they hold from one paragraph to the next until `\pard`. Indents inside a table cell are not read.
394
434
  - A heading outside a table cell also writes its right and first-line indents, so a heading read from RTF with a hanging number goes back as it came. A picture is read with a left margin only, where its line starts.
395
- - `rtfToHtml` does not yet read spacing, keep-with-next or tab stops back.
435
+ - `rtfToHtml` reads spacing back too: `\sb120\sa240\sl360\slmult1` becomes `margin-top:6pt;margin-bottom:12pt;line-height:1.5`, on a paragraph, a heading, a list item (as the `<li>`'s style) or a picture, and holds until `\pard` as the indents do. Line spacing "at least" (a positive `\sl` without `\slmult1`) is not something CSS can say, and is left out. In a table cell where a paragraph is spaced, as Word writes a cell's paragraphs, each of the cell's paragraphs is read as a `<p>` with its spacing; a cell with none spaced is read as lines, as before.
436
+ - `rtfToHtml` does not yet read keep-with-next or tab stops back.
437
+
438
+ ### Line and paragraph spacing
439
+
440
+ The **Spacing** list in the toolbar sets, for the paragraphs the selection touches:
441
+
442
+ - **Line spacing**: 1, 1.15, 1.5 or 2 lines, or Default (the document's own).
443
+ - **Space before paragraph** and **Space after paragraph**: 0, 6 or 12 pt.
444
+
445
+ The list marks what the paragraph at the caret has, and shows a value it does not offer (`7.5 pt` from a pasted document) so that it can be seen and changed. A heading takes spacing as a paragraph does, and so does a list item: the item the caret is in, as one paragraph, its style on the `<li>`. In the RTF its space before is on its first paragraph, its space after on its last, and its line spacing on each. In a table cell the paragraph the caret is in is spaced; a line typed straight into the cell is made a paragraph first. With a picture selected, the space before and after is the picture's, which is how the distance between two pictures, one under the other, is set. Each change is one step for Undo.
446
+
447
+ `setLineSpacing(lines)` and `setParagraphSpacing({ before, after })` do the same from code, with any value: up to 10 lines, and up to 144 pt. Copy format carries a paragraph's spacing with its alignment and indents.
448
+
449
+ #### The gap after a list's bullets or numbers
450
+
451
+ With the caret in a list, the Spacing list also offers **Bullet or number gap**: how far each item's text starts from its bullet or number, 9, 18, 27 or 36 pt, or Default. It is Word's *text indent* of a list: the marker stays where it is, and the text moves. `setListMarkerGap(points)` sets any gap from 6 to 144 pt, and `null` takes it off. It is set on the lists the selection touches, the innermost for an item of a list within a list, and is one step for Undo.
452
+
453
+ - **In the HTML** the gap is the list's own `padding-left` (`<ol style="padding-left: 27pt;">`), which is that distance in CSS too. A list without one has the quarter inch (18 pt) every list always had, and is shown and written as before.
454
+ - **On the screen** the editor draws the bullets and numbers of a list with a gap itself, at the list's edge, where Word has them; a browser draws its own markers against the text, by how wide they are. The numbers are worked out as the RTF writer works them out, from the list's `start` and `type` and an item's own `value`. They are written on each item as `data-ink-marker`, for the screen only: `getHTML()`, `onchange`, `onsave`, the draft and the HTML export do not have them.
455
+ - **In the RTF** each item hangs by the gap: 27 pt is `\li900\fi-540`, the marker still a quarter inch in. `rtfToHtml` reads a list hung by any gap from 6 to 144 pt as a list with that gap, Word's own lists hung by 0.2 in among them, and lists whose markers stand at one place are at one level whatever their gaps.
456
+
457
+ In the editor and in `RtfViewer` a picture has no space of its own around it, as it has none in the RTF: what is set is what shows. (Through 1.13 a picture was drawn with 20 px above and below it that no reader of the RTF showed.)
396
458
 
397
459
  ---
398
460
 
@@ -417,9 +479,10 @@ A `<p>` or `<div>` keeps its own indents, spacing and tab stops in the RTF, so a
417
479
  | `<table>` | one `\trowd … \row` per row; see [Tables](#tables) | `<table>` |
418
480
  | `<br>` | `\line` | `<br>` |
419
481
 
420
- - **Lists.** Only the shape above is read back as a list: a bullet or `N.`, a tab, and a paragraph that hangs by 360 twips and has no right indent or alignment of its own. Word's lists have that shape and are read as lists, including the bullet it writes in a `{\listtext}` group. Anything else stays the paragraph it is, marker and all, because it could not be written back the same: a line typed as `- Invasive adenocarcinoma.`, a list hung by another distance, one marked `a)` or `1)`, a centered one. A list in a table cell is read as lines of text.
482
+ - **The HTML of a list made in the editor** is a `<ul>` or `<ol>` beside the paragraphs around it, and a list within a list is inside the item it is under (`<ul><li>skin<ul><li>left arm</li></ul></li></ul>`): the shape `rtfToHtml` returns, so what is kept reads back as the same document. See [Lists](#lists). A block a browser leaves inside a paragraph (Firefox leaves pasted paragraphs inside the paragraph they were pasted in), which no HTML can say, is put beside the paragraph as soon as it is there, and `getHTML()`, `onchange`, `onsave`, the draft kept by `autosave` and the HTML export never hand one out.
483
+ - **Lists.** Only the shape above is read back as a list: a bullet or `N.`, a tab, and a paragraph that hangs by 360 twips and has no right indent or alignment of its own. Word's lists have that shape and are read as lists, including the bullet it writes in a `{\listtext}` group. A paragraph hung by another distance, from 6 to 144 pt, is a list with that gap after its markers (see [the gap after a list's bullets or numbers](#the-gap-after-a-lists-bullets-or-numbers)). Anything else stays the paragraph it is, marker and all, because it could not be written back the same: a line typed as `- Invasive adenocarcinoma.`, one marked `a)` or `1)`, a centered one. A list in a table cell is read as lines of text.
421
484
  - **Lettered lists.** A list numbered in letters or Roman numerals (`type="A"`, `a`, `I`, `i`, or the same as `list-style-type`, on the list or on each item as Google Docs writes it) is written with the markers the screen shows, from the list's `start` and an item's own `value`: specimen parts lettered A, B, C are A, B, C in the RTF, and "see part B" finds its item. Through 1.12.0 they were written 1, 2, 3. Such a list is read back as a list of its kind. Letters that are numerals too are told apart by what comes next: `C.` before `D.` is the third letter, before `CI.` it is a hundred. A letter and a tab typed on a line of another shape (`A.`, a tab, the specimen, as other systems write a report) stay what was typed.
422
- - **Colors and backgrounds.** A text color is written (`\cf`). A background is not, neither a highlight nor the shading of a table cell, and shading in an RTF is not shown: every word ends up on white. So a color that can be read on its background and not on white is left out, and the words are in the reader's own color: the white header of a table with a dark header row, a sentence copied from a page with a dark theme. Through 1.12.0 such words were written white, and could not be seen in the report. A color that can be read on white is written whatever is behind it, and a light color with no background behind it is written as the screen shows it. The editor still shows a pasted table with its shading; the RTF has the same words without it.
485
+ - **Colors and backgrounds.** A text color is written (`\cf`). A background is not, neither a highlight nor the shading of a table cell, and shading in an RTF is not shown: every word ends up on white. So a color that can be read on its background and not on white is left out, and the words are in the reader's own color: the white header of a table with a dark header row, a sentence copied from a page with a dark theme. Through 1.12.0 such words were written white, and could not be seen in the report. A color that can be read on white is written whatever is behind it, and a light color with no background behind it is written as the screen shows it. The editor still shows a pasted table with its shading; the RTF has the same words without it. A picture or a gradient as a background is not kept at all (nothing is loaded for a document), so light words that stood on one are put in the page's own color when the document is made safe, in the editor as in the RTF, unless there is a background color behind them still.
423
486
  - **List items.** A paragraph inside an item (`<li><p>…</p></li>`, as Word and Google Docs paste a list) is the item's text; a second paragraph in the item is a line under it. A list written straight inside a list (`<ul><ul>`) is one level deeper. An item with no list around it is written as a bulleted line. The list a browser's own list command makes, which the toolbar's list buttons run, is left inside the paragraph it was made from (`<p><ul>…</ul></p>`); it is written as the list alone.
424
487
  - **Headings.** A paragraph is read as a heading when all of its text is at a heading's size and all of it is bold, as every heading `htmlToRtf` writes is. Size alone does not make a heading: a report set in 14 pt throughout is 14 pt paragraphs, with the words that were bold still the only bold ones. (Through 1.9.0, at a 12 pt body size, large text was read as a heading whether bold or not, and was saved bold.) A large word in an ordinary paragraph is a large word. A heading set larger than its level keeps that size.
425
488
  - **Links.** A link is read back only for an address `isSafeLinkUrl` accepts, the same test the writer applies: an absolute web, mail or phone address. A field with a `javascript:`, `data:` or `file:` address, a relative or network path, or a link to a bookmark is read as its text alone. A web link opens in a tab of its own, so a click in `RtfViewer` does not replace your application. A document with a link carries the link color as the first entry of its color table (`\red0\green0\blue255`); a document without one is written as before.
@@ -437,7 +500,9 @@ RTF has no table element: each row says where its cells end (`\cellx`), so colum
437
500
  - **`<caption>`** is written as a centered paragraph before the table, where a browser shows it, and is read back as that paragraph.
438
501
  - **A column no cell starts in is not a column.** `colspan="100"` on a cell meant to cross the whole table adds none.
439
502
  - **A row short of cells** is filled with empty ones, so its edges are the table's.
440
- - **`<th>`** gets a bottom border, on that cell only, which is how `rtfToHtml` knows a header cell: a bare `\clbrdrb\brdrs` and no border on any other side. A bottom border with a width or a color (`\brdrw`, `\brdrcf`), which is how Word and TextEdit write a line someone drew under a cell, is not a header: a signature line stays an ordinary cell.
503
+ - **Borders.** A cell's own borders are written, each side by itself: `border: 1px solid` is `\clbrdrt\brdrs\brdrw15` and the same for `l`, `b` and `r`. The line is `solid`, `double`, `dotted` or `dashed` (any other that draws one is a plain line), the width is in twentieths of a point up to the 3.75 pt RTF allows, and a color other than black is written by its place in the color table (`\brdrcf`). `rtfToHtml` reads them back as `border:1px solid` where the four sides are one, else as `border-top`, `border-right`, and so on. A border set on the `<table>` or by a style sheet is not a cell's own, and is not written.
504
+ - **Insert table.** The toolbar's table button asks for rows and columns (up to 50 by 12), whether the cells have borders, and whether the first row is a header, and puts the table after the paragraph the caret is in. `insertTable(rows, columns, { borders, header })` does the same from code. A table with no borders has none in the RTF; while it is edited its cells are drawn with a faint dashed line, which is not in `getHTML()` or the RTF. Adding and removing rows and columns is not there yet.
505
+ - **`<th>`** with no borders of its own gets a bottom border, on that cell only, which is how `rtfToHtml` knows a header cell: a bare `\clbrdrb\brdrs` and no border on any other side. A header cell that has borders is written with those, and marked in what it holds by `{\*\inkth}`, a group other readers skip: Word and TextEdit put a border on every cell of a gridded table, so a border cannot say which cells are headers there. A bottom border with a width or a color (`\brdrw`, `\brdrcf`), which is how Word and TextEdit write a line someone drew under a cell, is not a header: a signature line stays an ordinary cell.
441
506
  - **Each cell ends with `\cell` inside its group**, with no `\par` before it, and the last row of a table carries `\lastrow`. Through 1.9.0 a cell ended `\par}\cell`, which Apple's reader (TextEdit, Pages, Mail) showed as an empty second paragraph in every cell, and two tables with nothing between them were read back as one. `rtfToHtml` reads both shapes.
442
507
  - **`<thead>` and `<tfoot>`** are written first and last, wherever the source has them.
443
508
  - **A cell's `text-align`** is written on its paragraphs (`\qc`, `\qr`, `\qj`), and read back onto the cell.
@@ -489,7 +554,7 @@ Size is not the only way to exhaust a page: a file of nothing but braces is smal
489
554
 
490
555
  ### Markdown export
491
556
 
492
- `htmlToMarkdown` writes a table as a Markdown table (a merged cell where it starts, with the cells it covers left empty, since Markdown has none), a numbered list from its `start`, a list numbered in letters or Roman numerals as bullets that begin with their marker (`- B. Right breast, biopsy`: Markdown numbers in digits only), and `<h4>` to `<h6>` as headings. Characters that Markdown would read as markup are escaped in text (`*`, `_`, `` ` ``, `#`, `[`, `]`, `<`, `~`, `\` and `|`), and so are `-`, `+`, `>` and `1.` at the start of a line: a report line typed as `- Benign.` stays that line. A link with an address `isSafeLinkUrl` refuses is written as its text alone.
557
+ `htmlToMarkdown` writes a table as a Markdown table (a merged cell where it starts, with the cells it covers left empty, since Markdown has none), a numbered list from its `start` (an item with a number of its own, `<li value="7">`, and a numbered list right after another, are written with the other mark, `7)`: Markdown counts on from a list's first number whatever the numbers after it say, and the other mark is what starts a new list at its own number), a list numbered in letters or Roman numerals as bullets that begin with their marker (`- B. Right breast, biopsy`: Markdown numbers in digits only), and `<h4>` to `<h6>` as headings. Characters that Markdown would read as markup are escaped in text (`*`, `_`, `` ` ``, `#`, `[`, `]`, `<`, `~`, `\` and `|`), and so are `-`, `+`, `>` and `1.` at the start of a line: a report line typed as `- Benign.` stays that line. A link with an address `isSafeLinkUrl` refuses is written as its text alone.
493
558
 
494
559
  A line break in a paragraph is a hard break (two spaces before the new line; a `<br>` in a heading or a table cell, which are one line). Text typed before a block is a paragraph of its own, and so is each `<div>`, `<section>`, `<dt>` and `<dd>`. A quotation of several paragraphs, or one holding a code block, carries its `>` on every line. A list written straight inside a list is nested under the item before it. Bold with a space inside the tag (`<b>diagnosis </b>`) is written with the space outside the marks, and `<b style="font-weight:normal">` is not bold. `<sup>`, `<sub>`, `<u>` and `<ins>` are written as those tags, which Markdown allows, and `<del>` as `~~`. A table's `<caption>` is a line before the table; a figure writes everything it holds, then its caption. `&copy;` typed as text stays those characters, and a line of `---` or `===` is escaped so that it is not a rule or a heading. What the screen does not show (`<style>`, `<script>`, `hidden`, `display:none`, `visibility:hidden`, `mso-hide:all`) is not written.
495
560
 
@@ -517,6 +582,10 @@ The components use CSS custom properties with sensible fallbacks, so they work o
517
582
  }
518
583
  ```
519
584
 
585
+ ### In a page with styles of its own
586
+
587
+ The editor and the viewer say for themselves how a list is shown: a bullet, a circle and a square by depth, and numbers. A page that takes the markers off its own lists (`ol, ul { list-style: none }`, as Tailwind's base styles and most CSS resets do) does not take them off a document's; through 1.13 a list in such a page was indented lines with nothing in front of them. A list that says its own marker by `list-style-type` keeps it. One that says it by `type="A"` alone is still at the mercy of such a rule: CSS cannot tell `type="A"` from `type="a"` in every browser, so the editor has no rule of its own for it.
588
+
520
589
  ---
521
590
 
522
591
  ## Keyboard shortcuts
@@ -532,11 +601,14 @@ The components use CSS custom properties with sensible fallbacks, so they work o
532
601
  | `Backspace` / `Delete` | Remove the selected image |
533
602
  | `Ctrl+]` / `Cmd+]` | Increase indent of the selected paragraphs by 0.5 in (RTF `\li720` per step) |
534
603
  | `Ctrl+[` / `Cmd+[` | Decrease indent |
535
- | `Tab` | Insert a tab (sent to RTF as `\tab`); two spaces in a code block. With several lines selected, increase their indent |
536
- | `Shift+Tab` | Remove one tab from the start of the line. With several lines selected, decrease their indent |
604
+ | `Tab` | Insert a tab (sent to RTF as `\tab`); two spaces in a code block. With several lines selected, increase their indent. At the start of a list item, put the item under the item before it |
605
+ | `Shift+Tab` | Remove one tab from the start of the line. With several lines selected, decrease their indent. In an item of a list within a list, take the item out from under the item it is under |
606
+ | `Enter` in an empty list item, `Backspace` at the start of one | Take the item out of its list: one list out, then a paragraph |
607
+ | `Ctrl+Z` / `Cmd+Z` | Undo |
608
+ | `Ctrl+Shift+Z` / `Cmd+Shift+Z`, `Ctrl+Y` | Redo |
537
609
  | `Esc`, then `Tab` / `Shift+Tab` | Move focus out of the editor |
538
610
 
539
- The toolbar's Increase indent and Decrease indent buttons do the same as `Ctrl+]` and `Ctrl+[`. Undo reverses an indent step until the next edit.
611
+ The toolbar's Increase indent and Decrease indent buttons do the same as `Ctrl+]` and `Ctrl+[`. Each press is one Undo step. In a list they put the selected items under the item before them, and take them out again (see [Lists](#lists)).
540
612
 
541
613
  Four more toolbar buttons set the other two RTF indents, 0.5 in per press, on a paragraph outside a table cell (not on a list, a heading, a quotation or a code block):
542
614
 
@@ -594,7 +666,19 @@ Three ways to add a picture:
594
666
 
595
667
  Each picture is inserted as a `<figure>` with a `<figcaption>` under it. Click the caption line and type to describe the image — the description travels with the picture through every export. Insert as many images as a document needs.
596
668
 
597
- Click an image to select it. A frame appears with corner handles you can drag to resize (the aspect ratio is kept and the width is capped at the editor's text width), buttons for 25% / 50% / 100% width, left / centre / right placement, a shortcut to its description, and a remove button.
669
+ Click an image to select it. A frame appears with corner handles you can drag to resize (the aspect ratio is kept and the width is capped at the editor's text width), buttons for 25% / 50% / 100% width, left / centre / right placement, moving it, a shortcut to its description, and a remove button.
670
+
671
+ ### Where a picture is on the page
672
+
673
+ - **Move up** and **Move down** take the selected picture, with its description, over the block above or below it: a paragraph, a table, another picture.
674
+ - **Place beside the picture above** puts the selected picture to the right of the picture before it, each with its own description under it. A third and a fourth can join the row. Pictures too wide for their share of the page are made to fit; after that each is resized and aligned inside its own share, which is also how the distance between two of them is set (the left one aligned right and the right one aligned left are as close as they go).
675
+ - **Dragging a picture** with the mouse does the same as the buttons. Dropped on the left or right half of another picture, it is put beside it, in a row, each picture with its own description under it; dropped on a picture of a row, it joins the row there, or changes places in its own row; dropped anywhere else, it is moved there whole, with its description, before or after the block it is dropped on. (Through 1.13 the browser moved the picture alone into the line it was dropped in, inside the other picture's figure, and its description was left behind as an empty line.)
676
+ - **Gap** sets an exact distance between the pictures of a row, in points (72 pt = 1 inch), from the field in the frame of any picture in the row. Each picture's cell is then as wide as the picture and the gap is an empty cell between each two, so the distance is the same on the screen, in the RTF (`\cellx` edges, no padding inside a cell) and in Word; the row is as wide as what it holds, not stretched across the page. Pictures too wide for the page together with their gaps are made smaller alike. A picture that joins the row or leaves it keeps the gap; resizing one keeps it too. Left empty, the row shares the page equally again. `rtfToHtml` reads such a row back with the same widths.
677
+ - **Place on its own line** takes a picture out of a row, and puts it under the row. Removing a picture from a row closes the row up; the last picture left is on a line of its own again.
678
+ - A row of pictures is moved up and down as one.
679
+ - **The space above and below a picture** is set from the toolbar's Spacing list while the picture is selected (see [Line and paragraph spacing](#line-and-paragraph-spacing)). A row of pictures has none to set.
680
+
681
+ In the document a row of pictures is a table of one row with no borders, a `<figure>` in each cell (and, with a gap set, an empty cell between each two), and that is what the RTF holds: a row of cells, each with a picture and its description. Word and other readers show the pictures side by side; `rtfToHtml` reads the row back as it was written. A picture in a row that has no description is read back as the picture alone in its cell, and is given a `<figure>` again when one is typed (the frame's Edit description button). There is no wrapping of text around a picture: RTF can say it, but the systems these documents go to do not show it reliably.
598
682
 
599
683
  ### How images are stored
600
684
 
@@ -161,6 +161,29 @@
161
161
  margin-bottom: 0;
162
162
  }
163
163
 
164
+ /* The bullets and the numbers are said here: a page that takes them off its own lists
165
+ (`ol, ul { list-style: none }`, as Tailwind's base styles and most CSS resets do) does
166
+ not take them off a document's. A list that says its own marker keeps it. */
167
+ .rtf-viewer :global(ul:not([type])) {
168
+ list-style-type: disc;
169
+ }
170
+
171
+ .rtf-viewer :global(:is(ul, ol) ul:not([type])) {
172
+ list-style-type: circle;
173
+ }
174
+
175
+ .rtf-viewer :global(:is(ul, ol) :is(ul, ol) ul:not([type])) {
176
+ list-style-type: square;
177
+ }
178
+
179
+ .rtf-viewer :global(ol:not([type])) {
180
+ list-style-type: decimal;
181
+ }
182
+
183
+ .rtf-viewer :global(li) {
184
+ display: list-item;
185
+ }
186
+
164
187
  /* Code keeps the font the RTF names for it. A code block wraps, so a long line stays in
165
188
  the viewer. */
166
189
  .rtf-viewer :global(code),
@@ -187,8 +210,16 @@
187
210
  height: auto;
188
211
  }
189
212
 
213
+ /* (The space of a paragraph, as in the editor: the space before and after a picture is
214
+ what the document sets.) */
190
215
  .rtf-viewer :global(figure) {
191
- margin: 1em 0;
216
+ margin: 0 0 0.2em;
217
+ }
218
+
219
+ /* Pictures side by side are a row of cells, each picture at the top of its own, as the
220
+ RTF has them. */
221
+ .rtf-viewer :global(:is(td, th):has(> figure, > img)) {
222
+ vertical-align: top;
192
223
  }
193
224
 
194
225
  .rtf-viewer :global(figcaption) {
@@ -1,4 +1,6 @@
1
1
  <script lang="ts">
2
+ import { MOST_GAP_PT } from '../picture-rows.js';
3
+
2
4
  /**
3
5
  * ImageOverlay — selection frame for an image inside the editor.
4
6
  *
@@ -7,10 +9,22 @@
7
9
  * `bounds`, which must be a positioned ancestor of the editing surface.
8
10
  *
9
11
  * Provides drag-to-resize corner handles plus a small toolbar for
10
- * placement (left / centre / right), width presets, caption editing and
11
- * deletion.
12
+ * placement (left / centre / right), width presets, moving the picture up
13
+ * or down the document, putting it beside the picture above it (or back on
14
+ * a line of its own), caption editing and deletion.
12
15
  */
13
16
 
17
+ /** Where the selected picture can go from where it is. */
18
+ export interface PicturePlace {
19
+ /** There is something above it to move over, and something below. */
20
+ up: boolean;
21
+ down: boolean;
22
+ /** 'join': it can go beside the picture above it. 'leave': it is beside another, and can go on a line of its own. */
23
+ beside: 'join' | 'leave' | null;
24
+ /** For a picture beside another: the space set between the pictures of its row, in points; null where they share the page equally. */
25
+ gap?: number | null;
26
+ }
27
+
14
28
  interface Props {
15
29
  /** Image currently selected in the editor, or null when nothing is selected. */
16
30
  target?: HTMLImageElement | null;
@@ -23,9 +37,32 @@
23
37
  onchange?: () => void;
24
38
  onremove?: () => void;
25
39
  oncaption?: (img: HTMLImageElement) => void;
40
+ /** Where the picture can go; without it the frame has no buttons for moving it. */
41
+ place?: () => PicturePlace;
42
+ /** Move the picture over the block above it (-1) or below it (1). */
43
+ onmove?: (direction: -1 | 1) => void;
44
+ /** Put the picture beside the one above it, or back on a line of its own. */
45
+ onbeside?: () => void;
46
+ /** Set the space between the pictures of the row, in points; null: they share the page equally. */
47
+ ongap?: (points: number | null) => void;
48
+ /** The picture's width changed, and a resize is not over yet. */
49
+ onresizing?: () => void;
26
50
  }
27
51
 
28
- let { target = null, bounds = null, within = null, maxWidth, onchange, onremove, oncaption }: Props = $props();
52
+ let { target = null, bounds = null, within = null, maxWidth, onchange, onremove, oncaption, place, onmove, onbeside, ongap, onresizing }: Props = $props();
53
+
54
+ /** The gap typed: a number of points, or nothing (the row shares the page equally). */
55
+ function gapTyped(e: Event): void {
56
+ const input = e.currentTarget as HTMLInputElement;
57
+ const value = input.value.trim();
58
+ const points = value === '' ? null : Number(value);
59
+ if (points !== null && !(points > 0)) {
60
+ // (Not a gap: what the row has is shown again.)
61
+ input.value = where?.gap == null ? '' : String(where.gap);
62
+ return;
63
+ }
64
+ ongap?.(points);
65
+ }
29
66
 
30
67
  const MIN_WIDTH = 40;
31
68
  const CORNERS = ['nw', 'ne', 'sw', 'se'] as const;
@@ -34,6 +71,27 @@
34
71
  let visible = $state(false);
35
72
  let dragging = $state(false);
36
73
  let sizeLabel = $state('');
74
+ /** Where the picture can go: read again whenever the frame is placed again, as a move changes it. */
75
+ const where = $derived.by(() => (frame && target && place ? place() : null));
76
+ let toolsEl: HTMLElement | null = $state(null);
77
+ /** How far the tools are moved off the middle of the picture, to stay inside `bounds`. */
78
+ let toolsShift = $state(0);
79
+
80
+ // The tools sit over the middle of the picture, and are wider than a small one: over a
81
+ // picture at the edge of the page (the left one of two side by side) they would hang out
82
+ // over that edge, half of them out of reach.
83
+ $effect(() => {
84
+ const width = toolsEl?.offsetWidth ?? 0;
85
+ const room = bounds?.clientWidth ?? 0;
86
+ if (!visible || !width || !room) {
87
+ toolsShift = 0;
88
+ return;
89
+ }
90
+ const middle = frame.left + frame.width / 2;
91
+ const least = 4 + width / 2;
92
+ const most = room - 4 - width / 2;
93
+ toolsShift = most < least ? room / 2 - middle : Math.round(Math.min(Math.max(middle, least), most) - middle);
94
+ });
37
95
 
38
96
  /** Recompute the frame position — call after anything that reflows content. */
39
97
  export function reposition(): void {
@@ -73,6 +131,7 @@
73
131
  target.removeAttribute('height');
74
132
  target.style.width = `${width}px`;
75
133
  target.style.height = 'auto';
134
+ onresizing?.();
76
135
  reposition();
77
136
  }
78
137
 
@@ -113,20 +172,37 @@
113
172
  handle.addEventListener('pointercancel', onUp);
114
173
  }
115
174
 
175
+ /**
176
+ * What says where the picture is aligned: its figure, or the block it is in. A picture
177
+ * alone in a table cell (one of two side by side) is aligned by the cell, which is where
178
+ * the RTF has it and where it is read back.
179
+ */
180
+ function alignBlock(): HTMLElement | null {
181
+ if (!target) return null;
182
+ const figure = target.closest('figure');
183
+ const cell = (figure ?? target).parentElement;
184
+ if (cell && /^(TD|TH)$/.test(cell.tagName) && cell.children.length === 1) return cell;
185
+ return figure ?? target.parentElement;
186
+ }
187
+
116
188
  function align(value: 'left' | 'center' | 'right'): void {
117
- if (!target) return;
118
- const block = target.closest('figure') ?? target.parentElement;
119
- if (!block) return;
120
- if (value === 'left') block.removeAttribute('style');
121
- else (block as HTMLElement).style.textAlign = value;
189
+ const block = alignBlock();
190
+ if (!block || !target) return;
191
+ const figure = target.closest('figure');
192
+ if (figure && figure !== block) {
193
+ figure.style.textAlign = '';
194
+ if (!figure.getAttribute('style')) figure.removeAttribute('style');
195
+ }
196
+ // (A header cell says so when it is left: a browser centers one that does not. Only the
197
+ // alignment is changed: a picture's indent and the space around it stay.)
198
+ block.style.textAlign = value === 'left' && block.tagName !== 'TH' ? '' : value;
199
+ if (!block.getAttribute('style')) block.removeAttribute('style');
122
200
  reposition();
123
201
  onchange?.();
124
202
  }
125
203
 
126
- function currentAlign(): string {
127
- const block = target?.closest('figure') ?? target?.parentElement;
128
- return (block as HTMLElement | null)?.style?.textAlign || 'left';
129
- }
204
+ /** How the picture is aligned: read again whenever the frame is placed again, as a button here changes it. */
205
+ const aligned = $derived.by(() => (frame && target ? alignBlock()?.style?.textAlign || 'left' : 'left'));
130
206
 
131
207
  function scaleTo(percent: number): void {
132
208
  const max = maxWidth?.() ?? 0;
@@ -144,11 +220,11 @@
144
220
  class:dragging
145
221
  style="left:{frame.left}px;top:{frame.top}px;width:{frame.width}px;height:{frame.height}px"
146
222
  >
147
- <div class="ink-img-tools">
223
+ <div class="ink-img-tools" bind:this={toolsEl} style={toolsShift ? `transform:translateX(calc(-50% + ${toolsShift}px))` : undefined}>
148
224
  <button
149
225
  type="button"
150
226
  title="Align left"
151
- class:active={currentAlign() === 'left'}
227
+ class:active={aligned === 'left'}
152
228
  onclick={() => align('left')}
153
229
  >
154
230
  <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><line x1="3" y1="6" x2="21" y2="6"/><line x1="3" y1="12" x2="15" y2="12"/><line x1="3" y1="18" x2="18" y2="18"/></svg>
@@ -156,7 +232,7 @@
156
232
  <button
157
233
  type="button"
158
234
  title="Align center"
159
- class:active={currentAlign() === 'center'}
235
+ class:active={aligned === 'center'}
160
236
  onclick={() => align('center')}
161
237
  >
162
238
  <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><line x1="3" y1="6" x2="21" y2="6"/><line x1="6" y1="12" x2="18" y2="12"/><line x1="4" y1="18" x2="20" y2="18"/></svg>
@@ -164,7 +240,7 @@
164
240
  <button
165
241
  type="button"
166
242
  title="Align right"
167
- class:active={currentAlign() === 'right'}
243
+ class:active={aligned === 'right'}
168
244
  onclick={() => align('right')}
169
245
  >
170
246
  <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><line x1="3" y1="6" x2="21" y2="6"/><line x1="9" y1="12" x2="21" y2="12"/><line x1="6" y1="18" x2="21" y2="18"/></svg>
@@ -178,6 +254,40 @@
178
254
 
179
255
  <span class="ink-img-sep"></span>
180
256
 
257
+ {#if where}
258
+ <button type="button" title="Move up" disabled={!where.up} onclick={() => onmove?.(-1)}>
259
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="19" x2="12" y2="5"/><polyline points="6 11 12 5 18 11"/></svg>
260
+ </button>
261
+ <button type="button" title="Move down" disabled={!where.down} onclick={() => onmove?.(1)}>
262
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="5" x2="12" y2="19"/><polyline points="6 13 12 19 18 13"/></svg>
263
+ </button>
264
+ {#if where.beside === 'leave'}
265
+ <button type="button" class="active" title="Place on its own line" onclick={() => onbeside?.()}>
266
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="6" width="8" height="12" rx="1"/><rect x="13" y="6" width="8" height="12" rx="1"/></svg>
267
+ </button>
268
+ <label class="ink-img-gap" title="Space between the pictures, in points (72 pt = 1 inch). Empty: the pictures share the width of the page.">
269
+ <span>Gap</span>
270
+ <input
271
+ type="number"
272
+ min="1"
273
+ max={MOST_GAP_PT}
274
+ step="1"
275
+ placeholder="auto"
276
+ aria-label="Gap between the pictures, in points"
277
+ value={where.gap ?? ''}
278
+ onchange={gapTyped}
279
+ />
280
+ <span>pt</span>
281
+ </label>
282
+ {:else}
283
+ <button type="button" title="Place beside the picture above" disabled={where.beside !== 'join'} onclick={() => onbeside?.()}>
284
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="6" width="8" height="12" rx="1"/><rect x="13" y="6" width="8" height="12" rx="1"/></svg>
285
+ </button>
286
+ {/if}
287
+
288
+ <span class="ink-img-sep"></span>
289
+ {/if}
290
+
181
291
  <button type="button" title="Edit description" onclick={() => target && oncaption?.(target)}>
182
292
  <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M4 7V5h16v2"/><line x1="9" y1="19" x2="15" y2="19"/><line x1="12" y1="5" x2="12" y2="19"/></svg>
183
293
  </button>
@@ -267,11 +377,16 @@
267
377
  transition: all 150ms cubic-bezier(0.4, 0, 0.2, 1);
268
378
  }
269
379
 
270
- .ink-img-tools button:hover {
380
+ .ink-img-tools button:hover:not(:disabled) {
271
381
  background: var(--surface, #f2f0ec);
272
382
  color: var(--text, #2c2520);
273
383
  }
274
384
 
385
+ .ink-img-tools button:disabled {
386
+ opacity: 0.35;
387
+ cursor: default;
388
+ }
389
+
275
390
  .ink-img-tools button.active {
276
391
  background: var(--accent-soft, #fdf0e9);
277
392
  color: var(--accent, #d4622b);
@@ -287,6 +402,27 @@
287
402
  height: 14px;
288
403
  }
289
404
 
405
+ .ink-img-gap {
406
+ display: inline-flex;
407
+ align-items: center;
408
+ gap: 3px;
409
+ margin: 0 2px;
410
+ font-family: 'DM Sans', sans-serif;
411
+ font-size: 11px;
412
+ font-weight: 500;
413
+ color: var(--text-muted, #8a7e72);
414
+ }
415
+
416
+ .ink-img-gap input {
417
+ width: 4.2em;
418
+ padding: 1px 3px;
419
+ font: inherit;
420
+ color: inherit;
421
+ background: transparent;
422
+ border: 1px solid var(--border, #e5e2dc);
423
+ border-radius: 3px;
424
+ }
425
+
290
426
  .ink-img-sep {
291
427
  width: 1px;
292
428
  height: 16px;
@@ -6,9 +6,20 @@
6
6
  * `bounds`, which must be a positioned ancestor of the editing surface.
7
7
  *
8
8
  * Provides drag-to-resize corner handles plus a small toolbar for
9
- * placement (left / centre / right), width presets, caption editing and
10
- * deletion.
9
+ * placement (left / centre / right), width presets, moving the picture up
10
+ * or down the document, putting it beside the picture above it (or back on
11
+ * a line of its own), caption editing and deletion.
11
12
  */
13
+ /** Where the selected picture can go from where it is. */
14
+ export interface PicturePlace {
15
+ /** There is something above it to move over, and something below. */
16
+ up: boolean;
17
+ down: boolean;
18
+ /** 'join': it can go beside the picture above it. 'leave': it is beside another, and can go on a line of its own. */
19
+ beside: 'join' | 'leave' | null;
20
+ /** For a picture beside another: the space set between the pictures of its row, in points; null where they share the page equally. */
21
+ gap?: number | null;
22
+ }
12
23
  interface Props {
13
24
  /** Image currently selected in the editor, or null when nothing is selected. */
14
25
  target?: HTMLImageElement | null;
@@ -21,6 +32,16 @@ interface Props {
21
32
  onchange?: () => void;
22
33
  onremove?: () => void;
23
34
  oncaption?: (img: HTMLImageElement) => void;
35
+ /** Where the picture can go; without it the frame has no buttons for moving it. */
36
+ place?: () => PicturePlace;
37
+ /** Move the picture over the block above it (-1) or below it (1). */
38
+ onmove?: (direction: -1 | 1) => void;
39
+ /** Put the picture beside the one above it, or back on a line of its own. */
40
+ onbeside?: () => void;
41
+ /** Set the space between the pictures of the row, in points; null: they share the page equally. */
42
+ ongap?: (points: number | null) => void;
43
+ /** The picture's width changed, and a resize is not over yet. */
44
+ onresizing?: () => void;
24
45
  }
25
46
  declare const ImageOverlay: import("svelte").Component<Props, {
26
47
  reposition: () => void;