tosijs-styled-editor 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,85 @@
1
+ /**
2
+ * DOM traversal utilities for the tosijs-styled-editor component.
3
+ *
4
+ * All operations work in terms of "leaf nodes" — nodes with no children
5
+ * (text nodes, <img>, <hr>, <input>, etc.).
6
+ */
7
+ export type NodeFilter = ((node: Node) => boolean) | string;
8
+ /**
9
+ * Normalize a filter to a predicate function.
10
+ * - string: matches via Element.matches(selector) (text nodes never match)
11
+ * - function: used directly
12
+ * - undefined: matches everything
13
+ */
14
+ export declare function makeFilter(filter?: NodeFilter): (node: Node) => boolean;
15
+ /** Returns true if `a` comes before `b` in document order. */
16
+ export declare function isBefore(a: Node, b: Node): boolean;
17
+ /** Returns the index of `node` among its parent's childNodes (-1 if no parent). */
18
+ export declare function siblingOrder(node: Node): number;
19
+ /** Returns the first leaf node (deepest first-child) within `node`. */
20
+ export declare function firstLeafNode(node: Node): Node;
21
+ /** Returns the last leaf node (deepest last-child) within `node`. */
22
+ export declare function lastLeafNode(node: Node): Node;
23
+ /**
24
+ * Returns the next leaf node after `node`, stopping at `root`.
25
+ * If `filter` is provided, skips nodes that don't match.
26
+ */
27
+ export declare function nextLeafNode(node: Node, root?: Node, filter?: NodeFilter): Node | null;
28
+ /**
29
+ * Returns the previous leaf node before `node`, stopping at `root`.
30
+ * If `filter` is provided, skips nodes that don't match.
31
+ */
32
+ export declare function previousLeafNode(node: Node, root?: Node, filter?: NodeFilter): Node | null;
33
+ /** Collect all leaf nodes within `node`, optionally filtered. */
34
+ export declare function leafNodes(node: Node, filter?: NodeFilter): Node[];
35
+ /**
36
+ * Walk up the chain of ancestors that have only one child.
37
+ * Returns the topmost single-parent ancestor, or the node itself
38
+ * if its parent has multiple children.
39
+ */
40
+ export declare function topSingleParentAncestor(node: Node, filter?: NodeFilter): Node;
41
+ /**
42
+ * Walk up the chain of single-parent ancestors until one satisfies the filter.
43
+ * Returns null if none match before the chain breaks.
44
+ */
45
+ export declare function closestSingleParentAncestor(node: Node, filter: NodeFilter): Node | null;
46
+ /** Set user-select CSS on an element. */
47
+ export declare function allowSelection(element: HTMLElement, allow: boolean): void;
48
+ /** A character position found by measurement: where it is, and which side of it */
49
+ export interface CharacterHit {
50
+ node: Text;
51
+ offset: number;
52
+ rect: DOMRect;
53
+ after: boolean;
54
+ }
55
+ /**
56
+ * Find the character nearest a point WITHOUT changing the document.
57
+ *
58
+ * The editor used to answer this by wrapping every character in a span and
59
+ * reading the spans' rects. That works, but it is a DOM mutation performed in
60
+ * order to measure — and measuring by mutating changes the thing measured:
61
+ * line-breaking shifts, and in engines that do not shape across inline box
62
+ * boundaries, cursive scripts come apart.
63
+ *
64
+ * A Range reports the same geometry read-only. This is Range as a measuring
65
+ * tape, not as a selection model: no execCommand, no browser selection, no
66
+ * editing behaviour handed back to the engine.
67
+ */
68
+ export declare function characterAtPoint(root: Element, x: number, y: number): CharacterHit | null;
69
+ /**
70
+ * Where a caret sitting at `marker` should actually paint.
71
+ *
72
+ * The marker is an empty element, so its own rect is 0x0 and carries no line
73
+ * box — falling back to the PARENT's rect gives the height of the whole block,
74
+ * which paints a caret several lines tall. The geometry has to come from an
75
+ * adjacent character instead, measured with a Range.
76
+ *
77
+ * Which edge of that character depends on direction: a caret before a character
78
+ * sits at its leading edge (left in LTR, right in RTL); a caret after the last
79
+ * character sits at its trailing edge.
80
+ */
81
+ export declare function caretGeometryAt(marker: Element, root: Element): {
82
+ left: number;
83
+ top: number;
84
+ height: number;
85
+ } | null;
@@ -0,0 +1,7 @@
1
+ export * from './dom-utils';
2
+ export * from './selection';
3
+ export * from './commands';
4
+ export * from './tosijs-styled-editor';
5
+ export * from './toolbar';
6
+ export * from './table-utils';
7
+ export { version } from './version';