@folijs/core 0.0.0-stage → 0.2.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/CHANGELOG.md +29 -0
- package/LICENSE +21 -0
- package/README.md +34 -2
- package/dist/document.d.ts +50 -0
- package/dist/document.d.ts.map +1 -0
- package/dist/document.js +94 -0
- package/dist/document.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/model/attrs.d.ts +19 -0
- package/dist/model/attrs.d.ts.map +1 -0
- package/dist/model/attrs.js +57 -0
- package/dist/model/attrs.js.map +1 -0
- package/dist/model/content.d.ts +53 -0
- package/dist/model/content.d.ts.map +1 -0
- package/dist/model/content.js +167 -0
- package/dist/model/content.js.map +1 -0
- package/dist/model/errors.d.ts +11 -0
- package/dist/model/errors.d.ts.map +1 -0
- package/dist/model/errors.js +13 -0
- package/dist/model/errors.js.map +1 -0
- package/dist/model/fragment.d.ts +46 -0
- package/dist/model/fragment.d.ts.map +1 -0
- package/dist/model/fragment.js +180 -0
- package/dist/model/fragment.js.map +1 -0
- package/dist/model/index.d.ts +10 -0
- package/dist/model/index.d.ts.map +1 -0
- package/dist/model/index.js +9 -0
- package/dist/model/index.js.map +1 -0
- package/dist/model/mark.d.ts +30 -0
- package/dist/model/mark.d.ts.map +1 -0
- package/dist/model/mark.js +76 -0
- package/dist/model/mark.js.map +1 -0
- package/dist/model/node.d.ts +103 -0
- package/dist/model/node.d.ts.map +1 -0
- package/dist/model/node.js +241 -0
- package/dist/model/node.js.map +1 -0
- package/dist/model/replace.d.ts +9 -0
- package/dist/model/replace.d.ts.map +1 -0
- package/dist/model/replace.js +119 -0
- package/dist/model/replace.js.map +1 -0
- package/dist/model/resolvedpos.d.ts +73 -0
- package/dist/model/resolvedpos.d.ts.map +1 -0
- package/dist/model/resolvedpos.js +194 -0
- package/dist/model/resolvedpos.js.map +1 -0
- package/dist/model/schema.d.ts +143 -0
- package/dist/model/schema.d.ts.map +1 -0
- package/dist/model/schema.js +340 -0
- package/dist/model/schema.js.map +1 -0
- package/dist/model/slice.d.ts +31 -0
- package/dist/model/slice.d.ts.map +1 -0
- package/dist/model/slice.js +83 -0
- package/dist/model/slice.js.map +1 -0
- package/dist/schema.d.ts +100 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +106 -0
- package/dist/schema.js.map +1 -0
- package/dist/state/attempt.d.ts +4 -0
- package/dist/state/attempt.d.ts.map +1 -0
- package/dist/state/attempt.js +19 -0
- package/dist/state/attempt.js.map +1 -0
- package/dist/state/commands.d.ts +58 -0
- package/dist/state/commands.d.ts.map +1 -0
- package/dist/state/commands.js +446 -0
- package/dist/state/commands.js.map +1 -0
- package/dist/state/editor.d.ts +74 -0
- package/dist/state/editor.d.ts.map +1 -0
- package/dist/state/editor.js +90 -0
- package/dist/state/editor.js.map +1 -0
- package/dist/state/format.d.ts +27 -0
- package/dist/state/format.d.ts.map +1 -0
- package/dist/state/format.js +144 -0
- package/dist/state/format.js.map +1 -0
- package/dist/state/history.d.ts +21 -0
- package/dist/state/history.d.ts.map +1 -0
- package/dist/state/history.js +277 -0
- package/dist/state/history.js.map +1 -0
- package/dist/state/index.d.ts +9 -0
- package/dist/state/index.d.ts.map +1 -0
- package/dist/state/index.js +9 -0
- package/dist/state/index.js.map +1 -0
- package/dist/state/links.d.ts +42 -0
- package/dist/state/links.d.ts.map +1 -0
- package/dist/state/links.js +186 -0
- package/dist/state/links.js.map +1 -0
- package/dist/state/lists.d.ts +36 -0
- package/dist/state/lists.d.ts.map +1 -0
- package/dist/state/lists.js +383 -0
- package/dist/state/lists.js.map +1 -0
- package/dist/state/selection.d.ts +66 -0
- package/dist/state/selection.d.ts.map +1 -0
- package/dist/state/selection.js +200 -0
- package/dist/state/selection.js.map +1 -0
- package/dist/state/state.d.ts +90 -0
- package/dist/state/state.d.ts.map +1 -0
- package/dist/state/state.js +203 -0
- package/dist/state/state.js.map +1 -0
- package/dist/transform/index.d.ts +5 -0
- package/dist/transform/index.d.ts.map +1 -0
- package/dist/transform/index.js +5 -0
- package/dist/transform/index.js.map +1 -0
- package/dist/transform/stepmap.d.ts +65 -0
- package/dist/transform/stepmap.d.ts.map +1 -0
- package/dist/transform/stepmap.js +163 -0
- package/dist/transform/stepmap.js.map +1 -0
- package/dist/transform/steps.d.ts +117 -0
- package/dist/transform/steps.d.ts.map +1 -0
- package/dist/transform/steps.js +397 -0
- package/dist/transform/steps.js.map +1 -0
- package/dist/transform/structure.d.ts +26 -0
- package/dist/transform/structure.d.ts.map +1 -0
- package/dist/transform/structure.js +116 -0
- package/dist/transform/structure.js.map +1 -0
- package/dist/transform/transform.d.ts +80 -0
- package/dist/transform/transform.d.ts.map +1 -0
- package/dist/transform/transform.js +306 -0
- package/dist/transform/transform.js.map +1 -0
- package/package.json +36 -3
- package/src/document.ts +133 -0
- package/src/index.ts +45 -0
- package/src/model/attrs.ts +71 -0
- package/src/model/content.ts +193 -0
- package/src/model/errors.ts +14 -0
- package/src/model/fragment.ts +189 -0
- package/src/model/index.ts +16 -0
- package/src/model/mark.ts +80 -0
- package/src/model/node.ts +296 -0
- package/src/model/replace.ts +137 -0
- package/src/model/resolvedpos.ts +197 -0
- package/src/model/schema.ts +441 -0
- package/src/model/slice.ts +120 -0
- package/src/schema.ts +201 -0
- package/src/state/attempt.ts +22 -0
- package/src/state/commands.ts +471 -0
- package/src/state/editor.ts +187 -0
- package/src/state/format.ts +133 -0
- package/src/state/history.ts +310 -0
- package/src/state/index.ts +75 -0
- package/src/state/links.ts +185 -0
- package/src/state/lists.ts +427 -0
- package/src/state/selection.ts +233 -0
- package/src/state/state.ts +257 -0
- package/src/transform/index.ts +19 -0
- package/src/transform/stepmap.ts +187 -0
- package/src/transform/steps.ts +456 -0
- package/src/transform/structure.ts +135 -0
- package/src/transform/transform.ts +347 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# @folijs/core
|
|
2
|
+
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Rich content (schema v2): bulleted and numbered lists (nested, across pages), links, text color, highlight, alignment and horizontal rules, with toolbar controls and keyboard shortcuts; HTML paste from Word, Google Docs and web pages keeps them. Documents saved by 0.1.0 load unchanged; 0.1.0 cannot read documents saved by 0.2.0.
|
|
8
|
+
|
|
9
|
+
Known risks, besides those of 0.1.0 (manual IME, screen-reader and real-paste checks not run): Word and Google Docs lists are read from hand-written fixtures; long documents made of lists miss the editing-speed targets (Enter near the top, first layout, full re-flow). See [Known limitations](https://github.com/josep-audenis/foli/blob/main/docs/limitations.md).
|
|
10
|
+
|
|
11
|
+
Breaking (pre-1.0 minor): upgrade every app that reads your documents before saving with 0.2.0, since 0.1.0 cannot read version 2. `Transform.split(pos, after)` is now `split(pos, depth, typesAfter)` (`split(pos, 1, [after])`); `StepMap.side` is now `sides`; `MARK_TYPES` now lists every mark, `link`, `textColor` and `highlight` included (for attribute-free toggles use `SIMPLE_MARK_TYPES`); JSON no longer writes attributes equal to their default; `setBlockType` returns false when nothing changes, and `toggleMark` with invalid attributes returns false instead of throwing.
|
|
12
|
+
|
|
13
|
+
- 069f986: Alignment, colors and horizontal rules. Core: `setAlign`, `setTextColor`, `setHighlight` (null removes; at a caret, for the next typed text), `insertHorizontalRule`, `alignAt`, `colorAt`, `Transform.setBlockAttrs`, and `editor.commands` for each; typing over a selected rule replaces it with a paragraph, Enter adds one after it; arrow keys select a rule from the text beside it and leave it again (`arrowAcrossLeaf`). View: Up/Down onto a rule from a textblock's first or last line. React: toolbar alignment group, text color and highlight menu buttons (accessible menus, fixed palette), horizontal rule button; CSS variables `--foli-link-color`, `--foli-marker-color`, `--foli-rule-color`, `--foli-rule-thickness`; a rule is a taller box (easier to click) with its line in the middle.
|
|
14
|
+
- c0290aa: Links. Core: `setLink(href)`, `removeLink`, `insertLink(href, text?)`, `linkAt(state)`, `normalizeHref` (trim, `\` to `/`, spaces percent-encoded, `mailto:` for an email address and `https://` for a host name) and `autolinkHref`; the commands, the dialog and plain-text paste normalize the href, and every entry (including document load and paste) validates it, so unsafe protocols never apply; `editor.commands.setLink` and `removeLink`. Mod-K runs `openLinkEditor`, a request (`linkEditorRequest` transaction metadata, `requestsLinkEditor(tr)`) that a link UI answers. View: Ctrl+click (Cmd+click on Apple platforms) opens a link in a new tab with `noopener,noreferrer`; pasting plain text that is one URL makes a link (over selected text, links it), except paste as plain text; `view.paste(data, autolink?)`. React: a Link toolbar button (pressed in a link) and Mod-K open an accessible link dialog (URL field, Apply, Remove link, Cancel, Escape; an invalid URL is announced and not applied); new CSS variable `--foli-error-color`.
|
|
15
|
+
- ed66e43: List editing. Core: `toggleList`, `wrapInList`, `splitListItem`, `sinkListItem`, `liftListItem`, `liftListItemAtStart`, `listTypeAt` and `listKeymap()` (in every editor): Enter splits an item and leaves the list on an empty one, Tab and Shift+Tab nest and lift items (outside a list Tab is left to the browser), Backspace at an item's start lifts it, Ctrl/Cmd+Shift+7 and +8 toggle numbered and bulleted lists; `editor.commands.toggleList`, `wrapInList`, `indentListItem`, `outdentListItem`. Backspace after a list and Delete before one join into it; Delete at the end of a list item pulls in the next item's text (or what follows the list). Toggling a list off takes the selected items out of every list of that type they are in, leaving unselected items of outer lists; a numbered list split by lifting items goes on counting. Enter over a range across items deletes it, then splits. Each list change is its own undo step. View: Ctrl/Cmd+Shift+digit shortcuts work on every layout; `insertParagraph` and one-character delete inputs (keyboards without keydown) go through the same key bindings. React: toolbar buttons for bulleted and numbered lists (pressed inside one, disabled where no list can be made), decrease and increase indent.
|
|
16
|
+
- ef157b2: Document format v2 (`schemaVersion: 2`): bullet and ordered lists (`bulletList`, `orderedList` with `start`, `listItem`), `horizontalRule`, `align` on paragraphs and headings (`start`, `center`, `end`, `justify`; changing a block's type keeps it), and the marks `link` (`href` limited to relative URLs and http, https, mailto, tel: see `isSafeHref`), `textColor` and `highlight` (lowercase `#rrggbb`: see `isColor`). Documents saved by 0.1.0 (v1) load unchanged through a migration; 0.1.0 cannot read v2 documents. Attributes equal to their default are no longer written to JSON. `MARK_TYPES` now lists every mark (attribute-free ones are `SIMPLE_MARK_TYPES`). `setBlockType` no longer applies (or records undo) when nothing changes; `toggleMark` with invalid attributes (a link with an unsafe href) does not apply instead of throwing.
|
|
17
|
+
- f09aefe: Structure editing in the engine (for lists in schema v2): `ReplaceAroundStep`; `Transform.wrap`, `lift`, `split(pos, depth, typesAfter)` and `join(pos, depth)`; the checks `findWrapping`, `liftTarget`, `canSplit`, `canJoin` and `ResolvedPos.blockRange`; `NodeSelection`; the node spec `selectable` and the mark spec `inclusive` (a link does not grow when typing at its end). The node spec `atom` is declared for atoms that are not leaves (no v2 node uses it; a rule is an atom as a leaf). Breaking: `Transform.split(pos, after)` is now `split(pos, depth, typesAfter)` (`split(pos, 1, [after])`); `StepMap.side` is replaced by `sides`.
|
|
18
|
+
|
|
19
|
+
## 0.1.0
|
|
20
|
+
|
|
21
|
+
### Minor Changes
|
|
22
|
+
|
|
23
|
+
- First release: a document editor for the web with its own editing engine, on real pages.
|
|
24
|
+
- **Documents** (`@folijs/core`): a versioned JSON format (`schemaVersion: 1`) with page size and margins in millimetres; `parseDocument` validates untrusted input and never drops document content silently. Schema v1: paragraphs, headings 1–6, line breaks, page breaks; bold, italic, underline, strikethrough.
|
|
25
|
+
- **Engine** (`@folijs/core`): immutable state, steps and transactions, undo/redo history, commands, key bindings, a headless `createEditor`. No DOM.
|
|
26
|
+
- **View** (`@folijs/view`): `EditorView` renders the document on A4 or Letter pages in one `contenteditable` host. Paragraphs split across pages at a line, with widow/orphan and keep-with-next rules, explicit page breaks, incremental reflow, and print with one sheet per page (PDF output checked in Chromium). Typing, IME composition, copy, cut and paste (Foli JSON, HTML mapped to the schema, plain text), read-only mode, placeholder.
|
|
27
|
+
- **React** (`@folijs/react`, React 18.2+ and 19): `FoliEditor` with a formatting toolbar and `onChange`; `useFoliEditor`, `FoliEditorProvider`, `FoliCanvas`, `FoliToolbar`, `useCurrentEditor`, `useEditorState`. Server rendering gives the editor's shell; the document appears on hydration. Default theme in `@folijs/react/styles.css` (CSS variables).
|
|
28
|
+
|
|
29
|
+
Known risks: real IME and dead keys (Windows, macOS, Android, iOS input methods), NVDA and VoiceOver, macOS key bindings, spellcheck at a page break, and pastes from real Word, Google Docs and LibreOffice have not been checked by hand. Automated tests run in Chromium, Firefox and WebKit on Windows (IME only through Chromium's emulation, paste not in WebKit, no screen-reader tests); Safari on macOS and iOS is not tested. See [Known limitations](https://github.com/josep-audenis/foli/blob/main/docs/limitations.md).
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Josep Audenis
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,35 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @folijs/core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The document model and headless editing engine of [Foli](https://github.com/josep-audenis/foli):
|
|
4
|
+
document format and validation, schema, transactions, undo history and commands. No DOM: runs
|
|
5
|
+
in the browser, Node and workers.
|
|
6
|
+
|
|
7
|
+
> Early release: the API may change in any 0.x minor version (changes in `CHANGELOG.md`).
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @folijs/core
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { createDocument, createEditor, parseDocument } from "@folijs/core";
|
|
15
|
+
|
|
16
|
+
const text = JSON.stringify(createDocument()); // stand-in for a saved document
|
|
17
|
+
const doc = parseDocument(JSON.parse(text)); // throws FoliDocumentError on invalid input
|
|
18
|
+
const editor = createEditor({ document: doc });
|
|
19
|
+
editor.subscribe((_state, transactions) => {
|
|
20
|
+
if (transactions.some((tr) => tr.docChanged)) console.log("content changed");
|
|
21
|
+
});
|
|
22
|
+
editor.select(1); // inside the first paragraph
|
|
23
|
+
editor.commands.toggleMark("bold"); // the next typed text is bold
|
|
24
|
+
editor.commands.insertText("Hello");
|
|
25
|
+
const saved = JSON.stringify(editor.getDocument());
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
To show and edit a document in the browser, use [`@folijs/react`](https://www.npmjs.com/package/@folijs/react)
|
|
29
|
+
or [`@folijs/view`](https://www.npmjs.com/package/@folijs/view).
|
|
30
|
+
|
|
31
|
+
- [Document format](https://github.com/josep-audenis/foli/blob/main/docs/document-model.md)
|
|
32
|
+
- [API reference](https://github.com/josep-audenis/foli/blob/main/docs/api.md#folicore)
|
|
33
|
+
- [Known limitations](https://github.com/josep-audenis/foli/blob/main/docs/limitations.md)
|
|
34
|
+
|
|
35
|
+
MIT
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type Node } from "./model/index.js";
|
|
2
|
+
import { type DocJSON } from "./schema.js";
|
|
3
|
+
/**
|
|
4
|
+
* Bump when the persisted envelope or content schema changes; add a migration from the previous
|
|
5
|
+
* version to MIGRATIONS. A published version never changes in place: documents saved with it
|
|
6
|
+
* exist (v1: 0.1.0).
|
|
7
|
+
*/
|
|
8
|
+
export declare const SCHEMA_VERSION = 2;
|
|
9
|
+
/** All page geometry is in millimetres. See docs/document-model.md for unit conversions. */
|
|
10
|
+
export interface PageSize {
|
|
11
|
+
width: number;
|
|
12
|
+
height: number;
|
|
13
|
+
}
|
|
14
|
+
export interface PageMargins {
|
|
15
|
+
top: number;
|
|
16
|
+
right: number;
|
|
17
|
+
bottom: number;
|
|
18
|
+
left: number;
|
|
19
|
+
}
|
|
20
|
+
export interface DocumentSettings {
|
|
21
|
+
pageSize: PageSize;
|
|
22
|
+
margins: PageMargins;
|
|
23
|
+
}
|
|
24
|
+
/** The persisted document: a versioned envelope around the content tree. */
|
|
25
|
+
export interface FoliDocument {
|
|
26
|
+
schemaVersion: typeof SCHEMA_VERSION;
|
|
27
|
+
settings: DocumentSettings;
|
|
28
|
+
content: DocJSON;
|
|
29
|
+
}
|
|
30
|
+
export declare const PAGE_SIZES: {
|
|
31
|
+
readonly A4: {
|
|
32
|
+
readonly width: 210;
|
|
33
|
+
readonly height: 297;
|
|
34
|
+
};
|
|
35
|
+
readonly Letter: {
|
|
36
|
+
readonly width: 215.9;
|
|
37
|
+
readonly height: 279.4;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
export declare const DEFAULT_SETTINGS: DocumentSettings;
|
|
41
|
+
export declare function createDocument(content?: DocJSON, settings?: Partial<DocumentSettings>): FoliDocument;
|
|
42
|
+
/**
|
|
43
|
+
* Validates untrusted input (e.g. JSON loaded from storage) against the schema and returns a
|
|
44
|
+
* FoliDocument with content in canonical form (see docs/document-model.md, "Normalization").
|
|
45
|
+
* Throws FoliDocumentError instead of silently dropping invalid content.
|
|
46
|
+
*/
|
|
47
|
+
export declare function parseDocument(input: unknown): FoliDocument;
|
|
48
|
+
/** Parses untrusted content JSON into a `doc` node of the current schema (v2). */
|
|
49
|
+
export declare function parseContent(value: unknown, path?: string): Node;
|
|
50
|
+
//# sourceMappingURL=document.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../src/document.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,KAAK,OAAO,EAAU,MAAM,aAAa,CAAC;AAEnD;;;;GAIG;AACH,eAAO,MAAM,cAAc,IAAI,CAAC;AAchC,4FAA4F;AAC5F,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,QAAQ,CAAC;IACnB,OAAO,EAAE,WAAW,CAAC;CACtB;AAED,4EAA4E;AAC5E,MAAM,WAAW,YAAY;IAC3B,aAAa,EAAE,OAAO,cAAc,CAAC;IACrC,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,eAAO,MAAM,UAAU;;iBACf,KAAK,EAAE,GAAG;iBAAE,MAAM,EAAE,GAAG;;;iBACnB,KAAK,EAAE,KAAK;iBAAE,MAAM,EAAE,KAAK;;CACM,CAAC;AAE9C,eAAO,MAAM,gBAAgB,EAAE,gBAG9B,CAAC;AAEF,wBAAgB,cAAc,CAC5B,OAAO,GAAE,OAA2D,EACpE,QAAQ,GAAE,OAAO,CAAC,gBAAgB,CAAM,GACvC,YAAY,CAEd;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,YAAY,CAqB1D;AAED,kFAAkF;AAClF,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,SAAY,GAAG,IAAI,CAQnE"}
|
package/dist/document.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { FoliDocumentError } from "./model/index.js";
|
|
2
|
+
import { schema } from "./schema.js";
|
|
3
|
+
/**
|
|
4
|
+
* Bump when the persisted envelope or content schema changes; add a migration from the previous
|
|
5
|
+
* version to MIGRATIONS. A published version never changes in place: documents saved with it
|
|
6
|
+
* exist (v1: 0.1.0).
|
|
7
|
+
*/
|
|
8
|
+
export const SCHEMA_VERSION = 2;
|
|
9
|
+
/**
|
|
10
|
+
* `MIGRATIONS[n]` turns a version-n envelope into version n + 1; `parseDocument` runs them in
|
|
11
|
+
* order, then validates against the current schema. Migrations never drop content.
|
|
12
|
+
*/
|
|
13
|
+
const MIGRATIONS = {
|
|
14
|
+
// v2 adds lists, horizontal rules, links, text color, highlight and alignment. Every v1
|
|
15
|
+
// document is a valid v2 document: only the version changes.
|
|
16
|
+
1: (doc) => ({ ...doc, schemaVersion: 2 }),
|
|
17
|
+
};
|
|
18
|
+
export const PAGE_SIZES = {
|
|
19
|
+
A4: { width: 210, height: 297 },
|
|
20
|
+
Letter: { width: 215.9, height: 279.4 },
|
|
21
|
+
};
|
|
22
|
+
export const DEFAULT_SETTINGS = {
|
|
23
|
+
pageSize: PAGE_SIZES.A4,
|
|
24
|
+
margins: { top: 25.4, right: 25.4, bottom: 25.4, left: 25.4 },
|
|
25
|
+
};
|
|
26
|
+
export function createDocument(content = { type: "doc", content: [{ type: "paragraph" }] }, settings = {}) {
|
|
27
|
+
return { schemaVersion: SCHEMA_VERSION, settings: { ...DEFAULT_SETTINGS, ...settings }, content };
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Validates untrusted input (e.g. JSON loaded from storage) against the schema and returns a
|
|
31
|
+
* FoliDocument with content in canonical form (see docs/document-model.md, "Normalization").
|
|
32
|
+
* Throws FoliDocumentError instead of silently dropping invalid content.
|
|
33
|
+
*/
|
|
34
|
+
export function parseDocument(input) {
|
|
35
|
+
if (!isRecord(input))
|
|
36
|
+
throw new FoliDocumentError("Document must be an object");
|
|
37
|
+
const version = input.schemaVersion;
|
|
38
|
+
if (!Number.isInteger(version) || version < 1) {
|
|
39
|
+
throw new FoliDocumentError(`Unsupported schemaVersion: ${String(version)}`);
|
|
40
|
+
}
|
|
41
|
+
if (version > SCHEMA_VERSION) {
|
|
42
|
+
throw new FoliDocumentError(`Unsupported schemaVersion: ${version} (this version of @folijs/core reads 1 to ` +
|
|
43
|
+
`${SCHEMA_VERSION}; the document was saved by a newer one)`);
|
|
44
|
+
}
|
|
45
|
+
let doc = input;
|
|
46
|
+
for (let v = version; v < SCHEMA_VERSION; v++) {
|
|
47
|
+
const migrate = MIGRATIONS[v];
|
|
48
|
+
if (!migrate)
|
|
49
|
+
throw new FoliDocumentError(`No migration from schemaVersion ${v}`);
|
|
50
|
+
doc = migrate(doc);
|
|
51
|
+
}
|
|
52
|
+
const settings = parseSettings(doc.settings);
|
|
53
|
+
const content = parseContent(doc.content).toJSON();
|
|
54
|
+
return { schemaVersion: SCHEMA_VERSION, settings, content };
|
|
55
|
+
}
|
|
56
|
+
/** Parses untrusted content JSON into a `doc` node of the current schema (v2). */
|
|
57
|
+
export function parseContent(value, path = "content") {
|
|
58
|
+
const doc = schema.nodeFromJSON(value, path);
|
|
59
|
+
if (doc.type !== schema.topNodeType) {
|
|
60
|
+
throw new FoliDocumentError(`${path}: root node must be of type "doc"`);
|
|
61
|
+
}
|
|
62
|
+
// The root has no parent to check its marks against.
|
|
63
|
+
if (doc.marks.length)
|
|
64
|
+
throw new FoliDocumentError(`${path}.marks: doc cannot have marks`);
|
|
65
|
+
return doc;
|
|
66
|
+
}
|
|
67
|
+
function parseSettings(input) {
|
|
68
|
+
if (!isRecord(input) || !isRecord(input.pageSize) || !isRecord(input.margins)) {
|
|
69
|
+
throw new FoliDocumentError("settings.pageSize and settings.margins are required");
|
|
70
|
+
}
|
|
71
|
+
const { width, height } = input.pageSize;
|
|
72
|
+
const { top, right, bottom, left } = input.margins;
|
|
73
|
+
if (!isPositive(width) || !isPositive(height)) {
|
|
74
|
+
throw new FoliDocumentError("pageSize width/height must be positive numbers (mm)");
|
|
75
|
+
}
|
|
76
|
+
if (![top, right, bottom, left].every(isNonNegative)) {
|
|
77
|
+
throw new FoliDocumentError("margins must be non-negative numbers (mm)");
|
|
78
|
+
}
|
|
79
|
+
const margins = { top, right, bottom, left };
|
|
80
|
+
if (margins.left + margins.right >= width || margins.top + margins.bottom >= height) {
|
|
81
|
+
throw new FoliDocumentError("margins leave no content area on the page");
|
|
82
|
+
}
|
|
83
|
+
return { pageSize: { width, height }, margins };
|
|
84
|
+
}
|
|
85
|
+
function isRecord(value) {
|
|
86
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
87
|
+
}
|
|
88
|
+
function isPositive(value) {
|
|
89
|
+
return typeof value === "number" && Number.isFinite(value) && value > 0;
|
|
90
|
+
}
|
|
91
|
+
function isNonNegative(value) {
|
|
92
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0;
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=document.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document.js","sourceRoot":"","sources":["../src/document.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAa,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAgB,MAAM,EAAE,MAAM,aAAa,CAAC;AAEnD;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC;AAIhC;;;GAGG;AACH,MAAM,UAAU,GAA0D;IACxE,wFAAwF;IACxF,6DAA6D;IAC7D,CAA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AC,KAAc;IAChC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC;AAC1E,CAAC;AAED,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;AAC3E,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { createDocument, DEFAULT_SETTINGS, type DocumentSettings, type FoliDocument, PAGE_SIZES, type PageMargins, type PageSize, parseContent, parseDocument, SCHEMA_VERSION, } from "./document.js";
|
|
2
|
+
export * from "./model/index.js";
|
|
3
|
+
export { ALIGNMENTS, type Alignment, type BlockJSON, type BulletListJSON, type ColorMarkJSON, type DocJSON, type HardBreakJSON, HEADING_LEVELS, type HeadingJSON, type HeadingLevel, type HorizontalRuleJSON, type InlineJSON, isColor, isSafeHref, type LinkMarkJSON, type ListItemJSON, MARK_TYPES, type MarkName, type MarkNameJSON, type OrderedListJSON, type PageBreakJSON, type ParagraphJSON, SAFE_LINK_PROTOCOLS, SIMPLE_MARK_TYPES, type SimpleMarkJSON, type SimpleMarkName, schema, type TextJSON, } from "./schema.js";
|
|
4
|
+
export * from "./state/index.js";
|
|
5
|
+
export * from "./transform/index.js";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,UAAU,EACV,KAAK,WAAW,EAChB,KAAK,QAAQ,EACb,YAAY,EACZ,aAAa,EACb,cAAc,GACf,MAAM,eAAe,CAAC;AACvB,cAAc,kBAAkB,CAAC;AACjC,OAAO,EACL,UAAU,EACV,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,OAAO,EACZ,KAAK,aAAa,EAClB,cAAc,EACd,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,UAAU,EACf,OAAO,EACP,UAAU,EACV,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,UAAU,EACV,KAAK,QAAQ,EACb,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,mBAAmB,EACnB,iBAAiB,EACjB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,MAAM,EACN,KAAK,QAAQ,GACd,MAAM,aAAa,CAAC;AACrB,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { createDocument, DEFAULT_SETTINGS, PAGE_SIZES, parseContent, parseDocument, SCHEMA_VERSION, } from "./document.js";
|
|
2
|
+
export * from "./model/index.js";
|
|
3
|
+
export { ALIGNMENTS, HEADING_LEVELS, isColor, isSafeHref, MARK_TYPES, SAFE_LINK_PROTOCOLS, SIMPLE_MARK_TYPES, schema, } from "./schema.js";
|
|
4
|
+
export * from "./state/index.js";
|
|
5
|
+
export * from "./transform/index.js";
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,gBAAgB,EAGhB,UAAU,EAGV,YAAY,EACZ,aAAa,EACb,cAAc,GACf,MAAM,eAAe,CAAC;AACvB,cAAc,kBAAkB,CAAC;AACjC,OAAO,EACL,UAAU,EAOV,cAAc,EAKd,OAAO,EACP,UAAU,EAGV,UAAU,EAMV,mBAAmB,EACnB,iBAAiB,EAGjB,MAAM,GAEP,MAAM,aAAa,CAAC;AACrB,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type Attrs = Readonly<Record<string, unknown>>;
|
|
2
|
+
export interface AttributeSpec {
|
|
3
|
+
/** Used when the attribute is missing. Without a default the attribute is required. */
|
|
4
|
+
default?: unknown;
|
|
5
|
+
/** Returns an error message for an invalid value, or undefined when it is valid. */
|
|
6
|
+
validate?: (value: unknown) => string | undefined;
|
|
7
|
+
}
|
|
8
|
+
export type AttributeSpecs = Readonly<Record<string, AttributeSpec>>;
|
|
9
|
+
export declare const NO_ATTRS: Attrs;
|
|
10
|
+
/** Fills defaults and validates. Unknown or missing required attributes are errors. */
|
|
11
|
+
export declare function computeAttrs(specs: AttributeSpecs | undefined, given: Attrs | undefined, path: string): Attrs;
|
|
12
|
+
/**
|
|
13
|
+
* The persisted form of `attrs`: only attributes that differ from their default (required ones
|
|
14
|
+
* always). Undefined when none remain, so a paragraph with default alignment has no `attrs`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function attrsToJSON(specs: AttributeSpecs | undefined, attrs: Attrs): Record<string, unknown> | undefined;
|
|
17
|
+
/** Structural equality for JSON-like attribute values. */
|
|
18
|
+
export declare function deepEqual(a: unknown, b: unknown): boolean;
|
|
19
|
+
//# sourceMappingURL=attrs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attrs.d.ts","sourceRoot":"","sources":["../../src/model/attrs.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAEtD,MAAM,WAAW,aAAa;IAC5B,uFAAuF;IACvF,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,oFAAoF;IACpF,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,MAAM,GAAG,SAAS,CAAC;CACnD;AAED,MAAM,MAAM,cAAc,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC;AAErE,eAAO,MAAM,QAAQ,EAAE,KAAyB,CAAC;AAEjD,uFAAuF;AACvF,wBAAgB,YAAY,CAC1B,KAAK,EAAE,cAAc,GAAG,SAAS,EACjC,KAAK,EAAE,KAAK,GAAG,SAAS,EACxB,IAAI,EAAE,MAAM,GACX,KAAK,CAiBP;AAED;;;GAGG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,cAAc,GAAG,SAAS,EACjC,KAAK,EAAE,KAAK,GACX,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAUrC;AAED,0DAA0D;AAC1D,wBAAgB,SAAS,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAWzD"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { fail } from "./errors.js";
|
|
2
|
+
export const NO_ATTRS = Object.freeze({});
|
|
3
|
+
/** Fills defaults and validates. Unknown or missing required attributes are errors. */
|
|
4
|
+
export function computeAttrs(specs, given, path) {
|
|
5
|
+
for (const key of Object.keys(given ?? NO_ATTRS)) {
|
|
6
|
+
if (!specs || !Object.hasOwn(specs, key))
|
|
7
|
+
fail(`${path}.${key}`, "unknown attribute");
|
|
8
|
+
}
|
|
9
|
+
if (!specs)
|
|
10
|
+
return NO_ATTRS;
|
|
11
|
+
const attrs = {};
|
|
12
|
+
for (const [name, spec] of Object.entries(specs)) {
|
|
13
|
+
let value = given?.[name];
|
|
14
|
+
if (value === undefined) {
|
|
15
|
+
if (!("default" in spec))
|
|
16
|
+
fail(`${path}.${name}`, "required attribute is missing");
|
|
17
|
+
value = spec.default;
|
|
18
|
+
}
|
|
19
|
+
const error = spec.validate?.(value);
|
|
20
|
+
if (error !== undefined)
|
|
21
|
+
fail(`${path}.${name}`, error);
|
|
22
|
+
attrs[name] = value;
|
|
23
|
+
}
|
|
24
|
+
return attrs;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The persisted form of `attrs`: only attributes that differ from their default (required ones
|
|
28
|
+
* always). Undefined when none remain, so a paragraph with default alignment has no `attrs`.
|
|
29
|
+
*/
|
|
30
|
+
export function attrsToJSON(specs, attrs) {
|
|
31
|
+
if (!specs)
|
|
32
|
+
return undefined;
|
|
33
|
+
let json;
|
|
34
|
+
for (const [name, spec] of Object.entries(specs)) {
|
|
35
|
+
const value = attrs[name];
|
|
36
|
+
if ("default" in spec && deepEqual(value, spec.default))
|
|
37
|
+
continue;
|
|
38
|
+
json ??= {};
|
|
39
|
+
json[name] = value;
|
|
40
|
+
}
|
|
41
|
+
return json;
|
|
42
|
+
}
|
|
43
|
+
/** Structural equality for JSON-like attribute values. */
|
|
44
|
+
export function deepEqual(a, b) {
|
|
45
|
+
if (a === b)
|
|
46
|
+
return true;
|
|
47
|
+
if (typeof a !== "object" || typeof b !== "object" || a === null || b === null)
|
|
48
|
+
return false;
|
|
49
|
+
if (Array.isArray(a) !== Array.isArray(b))
|
|
50
|
+
return false;
|
|
51
|
+
const keys = Object.keys(a);
|
|
52
|
+
if (keys.length !== Object.keys(b).length)
|
|
53
|
+
return false;
|
|
54
|
+
return keys.every((key) => Object.hasOwn(b, key) &&
|
|
55
|
+
deepEqual(a[key], b[key]));
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=attrs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attrs.js","sourceRoot":"","sources":["../../src/model/attrs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAanC,MAAM,CAAC,MAAM,QAAQ,GAAU,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAEjD,uFAAuF;AACvF,MAAM,UAAU,YAAY,CAC1B,KAAiC,EACjC,KAAwB,EACxB,IAAY;IAEZ,KAAK,MAAM,GAAG,IAAI,MAAM,CA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K,CAAC,IAAI,CAAC,CAAC;QAC1B,IAAI,SAAS,IAAI,IAAI,IAAI,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC;YAAE,SAAS;QAClE,IAAI,KAAK,EAAE,CAAC;QACZ,IAAI,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;IACrB,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,0DAA0D;AAC1D,MAAM,UAAU,SAAS,CAAC,CAAU,EAAE,CAAU;IAC9C,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACzB,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IAC7F,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;QAAE,OAAO,KAAK,CAAC;IACxD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC5B,IAAI,IAAI,CAAC,MAAM,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IACxD,OAAO,IAAI,CAAC,KAAK,CACf,CAAC,GAAG,EAAE,EAAE,CACN,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC;QACrB,SAAS,CAAE,CAA6B,CAAC,GAAG,CAAC,EAAG,CAA6B,CAAC,GAAG,CAAC,CAAC,CACtF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { Fragment } from "./fragment.js";
|
|
2
|
+
import type { NodeType } from "./schema.js";
|
|
3
|
+
/**
|
|
4
|
+
* Content expressions, a deliberately small subset: a space-separated sequence of terms; a term
|
|
5
|
+
* is a node name or group, or a choice `(a | b)`, optionally followed by `*`, `+` or `?`.
|
|
6
|
+
* Examples: `block+`, `inline*`, `heading paragraph*`, `(paragraph | heading)+`.
|
|
7
|
+
* Compiled to an NFA whose state sets are interned, so matching allocates nothing once warm.
|
|
8
|
+
*/
|
|
9
|
+
interface Element {
|
|
10
|
+
readonly types: readonly NodeType[];
|
|
11
|
+
readonly optional: boolean;
|
|
12
|
+
readonly repeat: boolean;
|
|
13
|
+
}
|
|
14
|
+
declare class Program {
|
|
15
|
+
readonly expr: string;
|
|
16
|
+
readonly elements: readonly Element[];
|
|
17
|
+
readonly matches: Map<string, ContentMatch>;
|
|
18
|
+
constructor(expr: string, elements: readonly Element[]);
|
|
19
|
+
/** The interned match for a state set (sorted, epsilon-closed). */
|
|
20
|
+
match(states: number[]): ContentMatch;
|
|
21
|
+
/** Adds the states reachable by skipping optional elements; returns them sorted. */
|
|
22
|
+
close(states: Iterable<number>): number[];
|
|
23
|
+
}
|
|
24
|
+
/** A position inside a content expression: which node types may come next, and whether it may end. */
|
|
25
|
+
export declare class ContentMatch {
|
|
26
|
+
private readonly program;
|
|
27
|
+
private readonly states;
|
|
28
|
+
private readonly next;
|
|
29
|
+
/** True when the content may end here. */
|
|
30
|
+
readonly validEnd: boolean;
|
|
31
|
+
/** @internal Use NodeType.contentMatch. */
|
|
32
|
+
constructor(program: Program, states: readonly number[]);
|
|
33
|
+
/** The match after a node of `type`, or null if `type` is not allowed here. */
|
|
34
|
+
matchType(type: NodeType): ContentMatch | null;
|
|
35
|
+
/** Matches `fragment.child(start)` up to `end`; null as soon as a child is not allowed. */
|
|
36
|
+
matchFragment(fragment: Fragment, start?: number, end?: number): ContentMatch | null;
|
|
37
|
+
/** The node types that may come next, in expression order, each once. */
|
|
38
|
+
get nextTypes(): readonly NodeType[];
|
|
39
|
+
/** The first type that may come next and can be created without attributes or content. */
|
|
40
|
+
get defaultType(): NodeType | null;
|
|
41
|
+
/**
|
|
42
|
+
* The shortest chain of wrapper types (outermost first) that makes a node of `target` fit
|
|
43
|
+
* here: `[]` when it fits as is, null when no chain of creatable types does. Wrappers must
|
|
44
|
+
* be creatable without attributes; inner wrappers must leave their parent complete.
|
|
45
|
+
*/
|
|
46
|
+
findWrapping(target: NodeType): readonly NodeType[] | null;
|
|
47
|
+
/** True when the expression's node types are inline (all are, or none are). */
|
|
48
|
+
get inlineContent(): boolean;
|
|
49
|
+
toString(): string;
|
|
50
|
+
static compile(expr: string, types: readonly NodeType[]): ContentMatch;
|
|
51
|
+
}
|
|
52
|
+
export {};
|
|
53
|
+
//# sourceMappingURL=content.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content.d.ts","sourceRoot":"","sources":["../../src/model/content.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C;;;;;GAKG;AAEH,UAAU,OAAO;IACf,QAAQ,CAAC,KAAK,EAAE,SAAS,QAAQ,EAAE,CAAC;IACpC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;CAC1B;AAED,cAAM,OAAO;IAGT,QAAQ,CAAC,IAAI,EAAE,MAAM;IACrB,QAAQ,CAAC,QAAQ,EAAE,SAAS,OAAO,EAAE;IAHvC,QAAQ,CAAC,OAAO,4BAAmC;IACnD,YACW,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,SAAS,OAAO,EAAE,EACnC;IAEJ,mEAAmE;IACnE,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,YAAY,CAQpC;IAED,oFAAoF;IACpF,KAAK,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,MAAM,EAAE,CAOxC;CACF;AAED,sGAAsG;AACtG,qBAAa,YAAY;IAOrB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAPzB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAA4C;IACjE,0CAA0C;IAC1C,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAE3B,2CAA2C;IAC3C,YACmB,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,SAAS,MAAM,EAAE,EAG3C;IAED,+EAA+E;IAC/E,SAAS,CAAC,IAAI,EAAE,QAAQ,GAAG,YAAY,GAAG,IAAI,CAY7C;IAED,2FAA2F;IAC3F,aAAa,CAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,SAAI,EAAE,GAAG,SAAsB,GAAG,YAAY,GAAG,IAAI,CAI3F;IAED,yEAAyE;IACzE,IAAI,SAAS,IAAI,SAAS,QAAQ,EAAE,CAQnC;IAED,0FAA0F;IAC1F,IAAI,WAAW,IAAI,QAAQ,GAAG,IAAI,CAMjC;IAED;;;;OAIG;IACH,YAAY,CAAC,MAAM,EAAE,QAAQ,GAAG,SAAS,QAAQ,EAAE,GAAG,IAAI,CA6BzD;IAED,+EAA+E;IAC/E,IAAI,aAAa,IAAI,OAAO,CAE3B;IAED,QAAQ,IAAI,MAAM,CAEjB;IAED,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,QAAQ,EAAE,GAAG,YAAY,CAOrE;CACF"}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
class Program {
|
|
2
|
+
expr;
|
|
3
|
+
elements;
|
|
4
|
+
matches = new Map();
|
|
5
|
+
constructor(expr, elements) {
|
|
6
|
+
this.expr = expr;
|
|
7
|
+
this.elements = elements;
|
|
8
|
+
}
|
|
9
|
+
/** The interned match for a state set (sorted, epsilon-closed). */
|
|
10
|
+
match(states) {
|
|
11
|
+
const key = states.join(",");
|
|
12
|
+
let match = this.matches.get(key);
|
|
13
|
+
if (!match) {
|
|
14
|
+
match = new ContentMatch(this, states);
|
|
15
|
+
this.matches.set(key, match);
|
|
16
|
+
}
|
|
17
|
+
return match;
|
|
18
|
+
}
|
|
19
|
+
/** Adds the states reachable by skipping optional elements; returns them sorted. */
|
|
20
|
+
close(states) {
|
|
21
|
+
const out = new Set();
|
|
22
|
+
for (let state of states) {
|
|
23
|
+
out.add(state);
|
|
24
|
+
while (state < this.elements.length && this.elements[state]?.optional)
|
|
25
|
+
out.add(++state);
|
|
26
|
+
}
|
|
27
|
+
return [...out].sort((a, b) => a - b);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/** A position inside a content expression: which node types may come next, and whether it may end. */
|
|
31
|
+
export class ContentMatch {
|
|
32
|
+
program;
|
|
33
|
+
states;
|
|
34
|
+
next = new Map();
|
|
35
|
+
/** True when the content may end here. */
|
|
36
|
+
validEnd;
|
|
37
|
+
/** @internal Use NodeType.contentMatch. */
|
|
38
|
+
constructor(program, states) {
|
|
39
|
+
this.program = program;
|
|
40
|
+
this.states = states;
|
|
41
|
+
this.validEnd = states.includes(program.elements.length);
|
|
42
|
+
}
|
|
43
|
+
/** The match after a node of `type`, or null if `type` is not allowed here. */
|
|
44
|
+
matchType(type) {
|
|
45
|
+
let result = this.next.get(type);
|
|
46
|
+
if (result === undefined) {
|
|
47
|
+
const reached = [];
|
|
48
|
+
for (const state of this.states) {
|
|
49
|
+
const element = this.program.elements[state];
|
|
50
|
+
if (element?.types.includes(type))
|
|
51
|
+
reached.push(element.repeat ? state : state + 1);
|
|
52
|
+
}
|
|
53
|
+
result = reached.length ? this.program.match(this.program.close(reached)) : null;
|
|
54
|
+
this.next.set(type, result);
|
|
55
|
+
}
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
/** Matches `fragment.child(start)` up to `end`; null as soon as a child is not allowed. */
|
|
59
|
+
matchFragment(fragment, start = 0, end = fragment.childCount) {
|
|
60
|
+
let match = this;
|
|
61
|
+
for (let i = start; match && i < end; i++)
|
|
62
|
+
match = match.matchType(fragment.child(i).type);
|
|
63
|
+
return match;
|
|
64
|
+
}
|
|
65
|
+
/** The node types that may come next, in expression order, each once. */
|
|
66
|
+
get nextTypes() {
|
|
67
|
+
const types = [];
|
|
68
|
+
for (const state of this.states) {
|
|
69
|
+
for (const type of this.program.elements[state]?.types ?? []) {
|
|
70
|
+
if (!types.includes(type))
|
|
71
|
+
types.push(type);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return types;
|
|
75
|
+
}
|
|
76
|
+
/** The first type that may come next and can be created without attributes or content. */
|
|
77
|
+
get defaultType() {
|
|
78
|
+
return (this.nextTypes.find((type) => !type.isText && !type.hasRequiredAttrs() && type.contentMatch.validEnd) ?? null);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The shortest chain of wrapper types (outermost first) that makes a node of `target` fit
|
|
82
|
+
* here: `[]` when it fits as is, null when no chain of creatable types does. Wrappers must
|
|
83
|
+
* be creatable without attributes; inner wrappers must leave their parent complete.
|
|
84
|
+
*/
|
|
85
|
+
findWrapping(target) {
|
|
86
|
+
const seen = new Set();
|
|
87
|
+
const active = [{ match: this, type: null, via: null }];
|
|
88
|
+
while (active.length) {
|
|
89
|
+
const current = active.shift();
|
|
90
|
+
if (current.match.matchType(target)) {
|
|
91
|
+
const result = [];
|
|
92
|
+
for (let step = current; step?.type; step = step.via)
|
|
93
|
+
result.push(step.type);
|
|
94
|
+
return result.reverse();
|
|
95
|
+
}
|
|
96
|
+
for (const type of current.match.nextTypes) {
|
|
97
|
+
const next = current.match.matchType(type);
|
|
98
|
+
if (!type.isLeaf &&
|
|
99
|
+
!type.hasRequiredAttrs() &&
|
|
100
|
+
!seen.has(type) &&
|
|
101
|
+
(!current.type || next?.validEnd)) {
|
|
102
|
+
seen.add(type);
|
|
103
|
+
active.push({ match: type.contentMatch, type, via: current });
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
/** True when the expression's node types are inline (all are, or none are). */
|
|
110
|
+
get inlineContent() {
|
|
111
|
+
return this.program.elements[0]?.types[0]?.isInline ?? false;
|
|
112
|
+
}
|
|
113
|
+
toString() {
|
|
114
|
+
return this.program.expr;
|
|
115
|
+
}
|
|
116
|
+
static compile(expr, types) {
|
|
117
|
+
const program = new Program(expr, parse(expr, types));
|
|
118
|
+
const inline = program.elements.flatMap((e) => e.types).map((t) => t.isInline);
|
|
119
|
+
if (inline.some((value) => value !== inline[0])) {
|
|
120
|
+
throw new Error(`Content expression "${expr}" mixes inline and block nodes`);
|
|
121
|
+
}
|
|
122
|
+
return program.match(program.close([0]));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function parse(expr, types) {
|
|
126
|
+
const tokens = expr.match(/\w+|[()|*+?]|\S/g) ?? [];
|
|
127
|
+
const elements = [];
|
|
128
|
+
let pos = 0;
|
|
129
|
+
const error = (message) => {
|
|
130
|
+
throw new Error(`Invalid content expression "${expr}": ${message}`);
|
|
131
|
+
};
|
|
132
|
+
const resolve = (name) => {
|
|
133
|
+
if (name === undefined || !/^\w+$/.test(name))
|
|
134
|
+
return error(`expected a name, got ${name}`);
|
|
135
|
+
const found = types.filter((t) => t.name === name);
|
|
136
|
+
const matched = found.length ? found : types.filter((t) => t.groups.includes(name));
|
|
137
|
+
return matched.length ? matched : error(`no node type or group "${name}"`);
|
|
138
|
+
};
|
|
139
|
+
while (pos < tokens.length) {
|
|
140
|
+
let choice;
|
|
141
|
+
if (tokens[pos] === "(") {
|
|
142
|
+
pos++;
|
|
143
|
+
choice = resolve(tokens[pos++]);
|
|
144
|
+
while (tokens[pos] === "|") {
|
|
145
|
+
pos++;
|
|
146
|
+
choice = choice.concat(resolve(tokens[pos++]));
|
|
147
|
+
}
|
|
148
|
+
if (tokens[pos++] !== ")")
|
|
149
|
+
error('expected ")"');
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
choice = resolve(tokens[pos++]);
|
|
153
|
+
}
|
|
154
|
+
const quantifier = tokens[pos];
|
|
155
|
+
if (quantifier === "*" || quantifier === "+" || quantifier === "?")
|
|
156
|
+
pos++;
|
|
157
|
+
if (quantifier === "+")
|
|
158
|
+
elements.push({ types: choice, optional: false, repeat: false });
|
|
159
|
+
elements.push({
|
|
160
|
+
types: choice,
|
|
161
|
+
optional: quantifier === "*" || quantifier === "+" || quantifier === "?",
|
|
162
|
+
repeat: quantifier === "*" || quantifier === "+",
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
return elements;
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=content.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content.js","sourceRoot":"","sources":["../../src/model/content.ts"],"names":[],"mappings":"AAgBA,MAAM,OAAO;IAGA,IAAI;IACJ,QAAQ;IAHV,OAAO,GAAG,IAAI,GAAG,EAAwB,CAAC;IACnD,YACW,IAAY,EACZ,QAA4B;oBAD5B,IAAI;wBACJ,QAAQ;IAChB,CAAC;IAEJ,mEAAmE;IACnE,KAAK,CAAC,MAAgB;QACpB,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC7B,IAAI,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAClC,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,KAAK,GAAG,IAAI,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YACvC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC/B,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,oFAAoF;IACpF,KAAK,CAAC,MAAwB;QAC5B,MAAM,GAAG,GAAG,IAAI,GAAG,EAAU,CAAC;QAC9B,KAAK,IAAI,KAAK,IAAI,MAAM,EAAE,CAAC;YACzB,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YACf,OAAO,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,IAAI,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,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G,MAAM,CAAC,GAAG,CAAC,CAAC;QAC/B,IAAI,UAAU,KAAK,GAAG,IAAI,UAAU,KAAK,GAAG,IAAI,UAAU,KAAK,GAAG;YAAE,GAAG,EAAE,CAAC;QAC1E,IAAI,UAAU,KAAK,GAAG;YAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;QACzF,QAAQ,CAAC,IAAI,CAAC;YACZ,KAAK,EAAE,MAAM;YACb,QAAQ,EAAE,UAAU,KAAK,GAAG,IAAI,UAAU,KAAK,GAAG,IAAI,UAAU,KAAK,GAAG;YACxE,MAAM,EAAE,UAAU,KAAK,GAAG,IAAI,UAAU,KAAK,GAAG;SACjD,CAAC,CAAC;IACL,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Invalid document content: unknown types, bad attributes, content that breaks the schema. */
|
|
2
|
+
export declare class FoliDocumentError extends Error {
|
|
3
|
+
name: string;
|
|
4
|
+
}
|
|
5
|
+
/** A replace that would produce content the schema does not allow. */
|
|
6
|
+
export declare class ReplaceError extends Error {
|
|
7
|
+
name: string;
|
|
8
|
+
}
|
|
9
|
+
/** Throws a FoliDocumentError whose message starts with a JSON path. */
|
|
10
|
+
export declare function fail(path: string, message: string): never;
|
|
11
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/model/errors.ts"],"names":[],"mappings":"AAAA,+FAA+F;AAC/F,qBAAa,iBAAkB,SAAQ,KAAK;IACjC,IAAI,SAAuB;CACrC;AAED,sEAAsE;AACtE,qBAAa,YAAa,SAAQ,KAAK;IAC5B,IAAI,SAAkB;CAChC;AAED,wEAAwE;AACxE,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,KAAK,CAEzD"}
|