@rowsncolumns/utils 9.4.0 → 9.5.1

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.
@@ -28,4 +28,6 @@ export * from "./formula-locale";
28
28
  export * from "./table-names";
29
29
  export * from "./table-totals";
30
30
  export * from "./sparkline-groups";
31
+ export * from "./rich-text-html";
32
+ export * from "./rich-text-links";
31
33
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC"}
package/dist/cjs/index.js CHANGED
@@ -31,3 +31,5 @@ tslib_1.__exportStar(require("./formula-locale"), exports);
31
31
  tslib_1.__exportStar(require("./table-names"), exports);
32
32
  tslib_1.__exportStar(require("./table-totals"), exports);
33
33
  tslib_1.__exportStar(require("./sparkline-groups"), exports);
34
+ tslib_1.__exportStar(require("./rich-text-html"), exports);
35
+ tslib_1.__exportStar(require("./rich-text-links"), exports);
@@ -0,0 +1,82 @@
1
+ import type { TextFormat, TextFormatRun } from "@rowsncolumns/common-types";
2
+ /**
3
+ * Clipboard HTML → the engine's native rich-text shape.
4
+ *
5
+ * Google Sheets and Excel both put a cell's mixed formatting into `text/html`
6
+ * — Google as `<span style="…">` / `<a href>` runs inside a `<td>` (wrapped in
7
+ * `<google-sheets-html-origin>`), Excel as `<b>` / `<font color>` /
8
+ * `<font class="fontN">` (class rules in `<head><style>`) / `<span style>` /
9
+ * `<a href>` inside a `<td>`. This module is the ONE converter every paste
10
+ * target uses (the grid's cell paste in `spreadsheet-state/api/parse-html`,
11
+ * the formula bar and the in-cell editor in `ui/editor-pm`), so a rich cell
12
+ * lands identically wherever it is pasted:
13
+ *
14
+ * - `text` — the full text, whitespace normalized like `extractTextContent`
15
+ * (source-newlines collapse to a space, `<br>` / block boundaries become
16
+ * `\n`, outer whitespace trimmed).
17
+ * - `runs` — `TextFormatRun`s RELATIVE to `baseFormat` (only the properties a
18
+ * segment changes), adjacent equal segments merged, empty formats dropped —
19
+ * the same normal form `extractTextFormatRuns` produces from the editor.
20
+ * `undefined` when the text is uniformly formatted (then `baseFormat`
21
+ * already says everything).
22
+ * - `links` — every `<a href>` in document order, as `[start, end)` spans.
23
+ * A link is also carried on its run as `format.link` (Google Sheets keeps
24
+ * several links per cell), and the engines promote the first run link to the
25
+ * cell-level `hyperlink` on commit (Excel keeps one link per cell).
26
+ * - `hyperlink` — the cell-level link: an anchor wrapping the whole text
27
+ * (Excel), else the first link.
28
+ * - `baseFormat` — the container's own formatting (the `<td>` class / inline
29
+ * style), i.e. the CELL-level text format of the source cell.
30
+ *
31
+ * Styles are read from the inline `style`, the tag semantics and
32
+ * `getComputedStyle` (the element must be mounted — see
33
+ * {@link mountClipboardHtml}) so Excel's class-based `<font class="fontN">`
34
+ * runs resolve. `<a>` elements read inline styles only: a browser's UA sheet
35
+ * would otherwise paint every pasted link `-webkit-link` blue.
36
+ */
37
+ export type RichTextLink = {
38
+ startIndex: number;
39
+ endIndex: number;
40
+ uri: string;
41
+ };
42
+ export type ParsedRichText = {
43
+ text: string;
44
+ runs: TextFormatRun[] | undefined;
45
+ links: RichTextLink[];
46
+ hyperlink: string | undefined;
47
+ baseFormat: TextFormat;
48
+ /** Mixed formatting or at least one link — the reasons to prefer runs over flat text. */
49
+ isRich: boolean;
50
+ };
51
+ /**
52
+ * Parse an HTML clipboard payload into a hidden, mounted sandbox so
53
+ * `getComputedStyle` resolves the payload's own `<style>` rules (Excel's
54
+ * `.fontN` / `.xlNN` classes). Callers must `cleanup()` when done.
55
+ */
56
+ export declare const mountClipboardHtml: (clipboardValue: string) => {
57
+ root: HTMLDivElement;
58
+ cleanup: () => void;
59
+ };
60
+ export declare const cssColorToHex: (value: string | null | undefined) => string | undefined;
61
+ /** CSS font-size → points. `pt` verbatim, `px` at 96dpi, `em`/`rem` on a 16px base. */
62
+ export declare const cssFontSizeToPt: (value: string | null | undefined) => number | undefined;
63
+ /**
64
+ * Convert a mounted element (a clipboard `<td>`, or the sandbox wrapper for
65
+ * table-less HTML) into the engine's rich-text shape. See the module doc.
66
+ */
67
+ export declare const htmlElementToRichText: (root: HTMLElement) => ParsedRichText;
68
+ /**
69
+ * The element a single-cell clipboard payload's text lives in: the lone
70
+ * `<td>`/`<th>` of a one-cell table (Excel / Google Sheets), or the mounted
71
+ * wrapper for table-less HTML. `undefined` for a multi-cell table — that is a
72
+ * grid paste, not a rich-text one.
73
+ */
74
+ export declare const findSingleClipboardCell: (root: HTMLElement) => HTMLElement | undefined;
75
+ /**
76
+ * One-shot helper for the editor targets: mount the clipboard HTML, convert
77
+ * the single cell it carries, clean up. `undefined` when the payload is a
78
+ * multi-cell table or carries no formatting/links worth keeping (the caller
79
+ * then falls back to its plain-text handling).
80
+ */
81
+ export declare const clipboardHtmlToRichText: (html: string) => ParsedRichText | undefined;
82
+ //# sourceMappingURL=rich-text-html.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rich-text-html.d.ts","sourceRoot":"","sources":["../../rich-text-html.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAK5E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,MAAM,MAAM,YAAY,GAAG;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,aAAa,EAAE,GAAG,SAAS,CAAC;IAClC,KAAK,EAAE,YAAY,EAAE,CAAC;IACtB,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,UAAU,EAAE,UAAU,CAAC;IACvB,yFAAyF;IACzF,MAAM,EAAE,OAAO,CAAC;CACjB,CAAC;AAgGF;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,GAAI,gBAAgB,MAAM;;;CAmBxD,CAAC;AAEF,eAAO,MAAM,aAAa,GACxB,OAAO,MAAM,GAAG,IAAI,GAAG,SAAS,KAC/B,MAAM,GAAG,SAkBX,CAAC;AAEF,uFAAuF;AACvF,eAAO,MAAM,eAAe,GAC1B,OAAO,MAAM,GAAG,IAAI,GAAG,SAAS,KAC/B,MAAM,GAAG,SAoBX,CAAC;AA+SF;;;GAGG;AACH,eAAO,MAAM,qBAAqB,GAAI,MAAM,WAAW,KAAG,cA+DzD,CAAC;AAgBF;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,GAClC,MAAM,WAAW,KAChB,WAAW,GAAG,SAShB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,GAClC,MAAM,MAAM,KACX,cAAc,GAAG,SAkBnB,CAAC"}