@open-artifact/dc 0.0.0-stage → 0.1.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/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +5 -2
- package/package.json +53 -4
- package/src/check.d.ts +30 -0
- package/src/check.js +337 -0
- package/src/document.d.ts +63 -0
- package/src/document.js +126 -0
- package/src/edit.d.ts +72 -0
- package/src/edit.js +249 -0
- package/src/holes.d.ts +46 -0
- package/src/holes.js +91 -0
- package/src/html.d.ts +113 -0
- package/src/html.js +335 -0
- package/src/index.d.ts +16 -0
- package/src/index.js +15 -0
- package/src/props.d.ts +51 -0
- package/src/props.js +57 -0
- package/src/protocol.d.ts +266 -0
- package/src/protocol.js +16 -0
- package/src/render.d.ts +34 -0
- package/src/render.js +256 -0
- package/src/rich-text.d.ts +106 -0
- package/src/rich-text.js +515 -0
- package/src/runtime/board.d.ts +6 -0
- package/src/runtime/board.js +509 -0
- package/src/runtime/focus-guard.d.ts +18 -0
- package/src/runtime/focus-guard.js +40 -0
- package/src/runtime/index.d.ts +16 -0
- package/src/runtime/index.js +15 -0
- package/src/runtime/logic.d.ts +31 -0
- package/src/runtime/logic.js +47 -0
- package/src/runtime/text-edit.d.ts +121 -0
- package/src/runtime/text-edit.js +1251 -0
- package/src/style.d.ts +30 -0
- package/src/style.js +108 -0
- package/src/template.d.ts +80 -0
- package/src/template.js +186 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import type { BoardEvent, BoardRect, ImportTextTargetSpec, TextEditOptions, TextEditTarget, TextFormat } from '../protocol.ts';
|
|
2
|
+
/** Where a glyph of drawn text starts, on screen. */
|
|
3
|
+
interface Stop {
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
/** Baseline angle, radians. */
|
|
7
|
+
ang: number;
|
|
8
|
+
/** Advance to the next glyph (0 past the end). */
|
|
9
|
+
w: number;
|
|
10
|
+
/** False for glyphs the browser does not draw (collapsed spaces). */
|
|
11
|
+
drawn: boolean;
|
|
12
|
+
}
|
|
13
|
+
/** SVG text being edited: a hidden field takes the keys, the drawing mirrors it. */
|
|
14
|
+
interface SvgEdit {
|
|
15
|
+
svg: SVGTextContentElement;
|
|
16
|
+
/** The one text node the drawing shows while editing. */
|
|
17
|
+
text: Text;
|
|
18
|
+
/** Spaces are kept as typed (`white-space: pre`). */
|
|
19
|
+
pre: boolean;
|
|
20
|
+
/** The element's own inline `white-space`, restored after. */
|
|
21
|
+
ws: string;
|
|
22
|
+
startText: string;
|
|
23
|
+
lastStop: Stop | null;
|
|
24
|
+
/** Caret and selection marks. */
|
|
25
|
+
marks: HTMLElement[];
|
|
26
|
+
/** Where a drag started (a character index), and whether it moved. */
|
|
27
|
+
anchor: number | null;
|
|
28
|
+
down: {
|
|
29
|
+
x: number;
|
|
30
|
+
y: number;
|
|
31
|
+
moved: boolean;
|
|
32
|
+
} | null;
|
|
33
|
+
}
|
|
34
|
+
/** Words of a component instance being edited in place. */
|
|
35
|
+
interface ImportEdit {
|
|
36
|
+
/** The instance's mount (the stamped `<x-import>`). */
|
|
37
|
+
mount: Element;
|
|
38
|
+
/** The text node the words were in, emptied while the field stands in for it. */
|
|
39
|
+
node: Text;
|
|
40
|
+
/** Its value before. */
|
|
41
|
+
value: string;
|
|
42
|
+
startText: string;
|
|
43
|
+
key: string;
|
|
44
|
+
words: string;
|
|
45
|
+
watch: MutationObserver;
|
|
46
|
+
}
|
|
47
|
+
/** One editing session. */
|
|
48
|
+
interface Session {
|
|
49
|
+
/** What takes the keys: the element itself, or a stand-in field for drawn or component words. */
|
|
50
|
+
element: HTMLElement;
|
|
51
|
+
/** The template element being edited (the element, or the SVG text, or the instance's mount). */
|
|
52
|
+
host: Element;
|
|
53
|
+
tid: number;
|
|
54
|
+
/** React's rendered children, put back when the edit ends. */
|
|
55
|
+
saved: Node[];
|
|
56
|
+
/** The content when the edit started: an unchanged edit reports nothing. */
|
|
57
|
+
startHtml: string;
|
|
58
|
+
/** Where the text is written when a hole shows it. */
|
|
59
|
+
target: TextEditTarget | null;
|
|
60
|
+
/** The element's own `contenteditable`, restored after. */
|
|
61
|
+
ownEditable: string | null;
|
|
62
|
+
/** ARIA attributes this edit added. */
|
|
63
|
+
aria: string[];
|
|
64
|
+
/** The last selection inside the element (restored when focus comes back for a format). */
|
|
65
|
+
range: Range | null;
|
|
66
|
+
/** The selection a `link-edit` is about. */
|
|
67
|
+
linkRange: Range | null;
|
|
68
|
+
/** The link just set: the editor selects it once the words are written. */
|
|
69
|
+
newLink: Element | null;
|
|
70
|
+
svg: SvgEdit | null;
|
|
71
|
+
imported: ImportEdit | null;
|
|
72
|
+
listeners: [EventTarget, string, EventListener, boolean?][];
|
|
73
|
+
}
|
|
74
|
+
/** In-place text editing of one element at a time. */
|
|
75
|
+
export declare class TextEditor {
|
|
76
|
+
private readonly report;
|
|
77
|
+
private session;
|
|
78
|
+
private stateTimer;
|
|
79
|
+
constructor(report: (event: BoardEvent) => void);
|
|
80
|
+
/** True while an element is being edited. */
|
|
81
|
+
get active(): boolean;
|
|
82
|
+
/** The element being edited. */
|
|
83
|
+
get element(): HTMLElement | null;
|
|
84
|
+
/** Starts editing `host` (template node `tid`). */
|
|
85
|
+
start(host: Element, tid: number, options?: TextEditOptions): boolean;
|
|
86
|
+
startImport(mount: Element, tid: number, x: number, y: number, targets: readonly ImportTextTargetSpec[]): boolean;
|
|
87
|
+
/** The field's own listeners: input, paste, and focus leaving. */
|
|
88
|
+
private listenField;
|
|
89
|
+
/** Ends the edit, reporting the change (or none). */
|
|
90
|
+
end(commit: boolean): void;
|
|
91
|
+
/** Toggles a format on the selection. */
|
|
92
|
+
format(verb: TextFormat): void;
|
|
93
|
+
applyLink(href: string | null): void;
|
|
94
|
+
/** Answers a `link-edit` without a change. */
|
|
95
|
+
cancelLinkEdit(): void;
|
|
96
|
+
/** Keys while editing; true when the key was handled here. */
|
|
97
|
+
keydown(event: KeyboardEvent): boolean;
|
|
98
|
+
/** Focuses the element, putting back the selection it had when focus left. */
|
|
99
|
+
private refocus;
|
|
100
|
+
private selectionChanged;
|
|
101
|
+
private scheduleState;
|
|
102
|
+
postState(): void;
|
|
103
|
+
/** The link at the selection inside the edited element. */
|
|
104
|
+
selectedLink(session: Session): HTMLElement | null;
|
|
105
|
+
/** Rect of a range or element in board pixels. */
|
|
106
|
+
static rectOf(target: Range | Element): BoardRect;
|
|
107
|
+
private paste;
|
|
108
|
+
/** Keeps the hidden field over the drawn text and redraws the marks. */
|
|
109
|
+
private placeSvgField;
|
|
110
|
+
/** Draws the caret, or the selection, over the drawn text. */
|
|
111
|
+
private drawSvgMarks;
|
|
112
|
+
private onSvgText;
|
|
113
|
+
/** A press on the drawn text places the caret there; three select it all. */
|
|
114
|
+
private svgPointerDown;
|
|
115
|
+
/** Dragging over the drawn text selects. */
|
|
116
|
+
private svgPointerMove;
|
|
117
|
+
/** A double-click on the drawn text selects the word there. */
|
|
118
|
+
private svgSelectWord;
|
|
119
|
+
askLink(session: Session): void;
|
|
120
|
+
}
|
|
121
|
+
export {};
|