@pixerate/editor 0.26.1 → 0.28.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 +32 -3
- package/dist/agent/index.cjs +56 -6
- package/dist/agent/index.cjs.map +1 -1
- package/dist/agent/index.d.cts +6 -4
- package/dist/agent/index.d.ts +6 -4
- package/dist/agent/index.js +51 -1
- package/dist/agent/index.js.map +1 -1
- package/dist/animation/index.cjs +62 -0
- package/dist/animation/index.cjs.map +1 -0
- package/dist/animation/index.d.cts +296 -0
- package/dist/animation/index.d.ts +296 -0
- package/dist/animation/index.js +62 -0
- package/dist/animation/index.js.map +1 -0
- package/dist/{builtins-Chj6zv_O.d.ts → builtins-haN82vjT.d.ts} +33 -3
- package/dist/{builtins-CdPcLwwF.d.cts → builtins-nMXh9sT3.d.cts} +33 -3
- package/dist/canvas/index.cjs +535 -737
- package/dist/canvas/index.cjs.map +1 -1
- package/dist/canvas/index.d.cts +74 -291
- package/dist/canvas/index.d.ts +74 -291
- package/dist/canvas/index.js +417 -619
- package/dist/canvas/index.js.map +1 -1
- package/dist/{chunk-X7HXL2SB.js → chunk-3RPOW4CS.js} +342 -16
- package/dist/chunk-3RPOW4CS.js.map +1 -0
- package/dist/{chunk-UBCFIABU.js → chunk-5H2OPMXZ.js} +183 -6
- package/dist/chunk-5H2OPMXZ.js.map +1 -0
- package/dist/chunk-A6PHCAGX.cjs +87 -0
- package/dist/chunk-A6PHCAGX.cjs.map +1 -0
- package/dist/{chunk-HRMEDT2L.js → chunk-D6AVOTSD.js} +6 -85
- package/dist/chunk-D6AVOTSD.js.map +1 -0
- package/dist/chunk-HXDMZQTD.cjs +497 -0
- package/dist/chunk-HXDMZQTD.cjs.map +1 -0
- package/dist/chunk-IB3ZHQAX.js +497 -0
- package/dist/chunk-IB3ZHQAX.js.map +1 -0
- package/dist/{chunk-4BVP64JJ.cjs → chunk-K2UYKJ6M.cjs} +24 -103
- package/dist/chunk-K2UYKJ6M.cjs.map +1 -0
- package/dist/{chunk-HDYMLS3X.cjs → chunk-MC2LQN5S.cjs} +196 -19
- package/dist/chunk-MC2LQN5S.cjs.map +1 -0
- package/dist/{chunk-XQFHLT53.js → chunk-MXZJ4PKN.js} +24 -10
- package/dist/chunk-MXZJ4PKN.js.map +1 -0
- package/dist/{chunk-LN2POBHT.cjs → chunk-OYEFRO3D.cjs} +28 -14
- package/dist/chunk-OYEFRO3D.cjs.map +1 -0
- package/dist/chunk-PWJARCI4.js +637 -0
- package/dist/chunk-PWJARCI4.js.map +1 -0
- package/dist/chunk-TGD52FEZ.js +87 -0
- package/dist/chunk-TGD52FEZ.js.map +1 -0
- package/dist/chunk-TTYCN6ZH.cjs +637 -0
- package/dist/chunk-TTYCN6ZH.cjs.map +1 -0
- package/dist/{chunk-NQF32I6Z.cjs → chunk-U7VGDSNY.cjs} +463 -137
- package/dist/chunk-U7VGDSNY.cjs.map +1 -0
- package/dist/commands/index.cjs +30 -410
- package/dist/commands/index.cjs.map +1 -1
- package/dist/commands/index.d.cts +1 -1
- package/dist/commands/index.d.ts +1 -1
- package/dist/commands/index.js +17 -397
- package/dist/commands/index.js.map +1 -1
- package/dist/{controller-CxXGOEmy.d.ts → controller-w6eRTjF8.d.cts} +67 -2
- package/dist/{controller-CxXGOEmy.d.cts → controller-w6eRTjF8.d.ts} +67 -2
- package/dist/extensions/index.cjs +25 -7
- package/dist/extensions/index.cjs.map +1 -1
- package/dist/extensions/index.d.cts +1 -1
- package/dist/extensions/index.d.ts +1 -1
- package/dist/extensions/index.js +32 -14
- package/dist/generation/index.cjs +3 -3
- package/dist/generation/index.cjs.map +1 -1
- package/dist/generation/index.js +3 -3
- package/dist/{index-jcJwmBYt.d.cts → index-C6gaQRH0.d.cts} +53 -4
- package/dist/{index-B273Zllk.d.ts → index-DXAv_R08.d.ts} +53 -4
- package/dist/index.cjs +57 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -5
- package/dist/index.d.ts +7 -5
- package/dist/index.js +132 -94
- package/dist/index.js.map +1 -1
- package/dist/spreadsheet/index.cjs +23 -3
- package/dist/spreadsheet/index.cjs.map +1 -1
- package/dist/spreadsheet/index.d.cts +76 -3
- package/dist/spreadsheet/index.d.ts +76 -3
- package/dist/spreadsheet/index.js +28 -8
- package/dist/tokens/index.cjs +4 -2
- package/dist/tokens/index.cjs.map +1 -1
- package/dist/tokens/index.js +6 -4
- package/package.json +6 -1
- package/dist/chunk-4BVP64JJ.cjs.map +0 -1
- package/dist/chunk-HDYMLS3X.cjs.map +0 -1
- package/dist/chunk-HRMEDT2L.js.map +0 -1
- package/dist/chunk-LN2POBHT.cjs.map +0 -1
- package/dist/chunk-NQF32I6Z.cjs.map +0 -1
- package/dist/chunk-UBCFIABU.js.map +0 -1
- package/dist/chunk-X7HXL2SB.js.map +0 -1
- package/dist/chunk-XQFHLT53.js.map +0 -1
|
@@ -2,9 +2,174 @@ import {
|
|
|
2
2
|
isTrackChangesEnabled
|
|
3
3
|
} from "./chunk-SWE3NPOU.js";
|
|
4
4
|
|
|
5
|
+
// src/extensions/table/nesting.ts
|
|
6
|
+
import { Fragment, Slice } from "@tiptap/pm/model";
|
|
7
|
+
import { Plugin, PluginKey, Selection } from "@tiptap/pm/state";
|
|
8
|
+
import {
|
|
9
|
+
CellSelection,
|
|
10
|
+
__pastedCells,
|
|
11
|
+
handlePaste as handleTablePaste
|
|
12
|
+
} from "@tiptap/pm/tables";
|
|
13
|
+
var ALLOW_NESTED_TABLES_META = "allowNestedTables";
|
|
14
|
+
var tableNestingPluginKey = new PluginKey("tableNesting");
|
|
15
|
+
var roleOf = (node) => node.type.spec.tableRole;
|
|
16
|
+
var isTableNode = (node) => roleOf(node) === "table";
|
|
17
|
+
function outermostTableDepth($pos) {
|
|
18
|
+
for (let d = 1; d <= $pos.depth; d++) if (isTableNode($pos.node(d))) return d;
|
|
19
|
+
return -1;
|
|
20
|
+
}
|
|
21
|
+
function isInTableCell($pos) {
|
|
22
|
+
for (let d = $pos.depth; d > 0; d--) {
|
|
23
|
+
const role = roleOf($pos.node(d));
|
|
24
|
+
if (role === "cell" || role === "header_cell") return true;
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
function sliceContainsTable(content) {
|
|
29
|
+
const fragment = content instanceof Slice ? content.content : content;
|
|
30
|
+
let found = false;
|
|
31
|
+
fragment.descendants((node) => {
|
|
32
|
+
if (found) return false;
|
|
33
|
+
if (isTableNode(node)) found = true;
|
|
34
|
+
return !found;
|
|
35
|
+
});
|
|
36
|
+
return found;
|
|
37
|
+
}
|
|
38
|
+
function insertSliceAfterTable(tr, from, to, slice) {
|
|
39
|
+
const $from = tr.doc.resolve(from);
|
|
40
|
+
const depth = outermostTableDepth($from);
|
|
41
|
+
if (depth < 0) return null;
|
|
42
|
+
const tableStart = $from.before(depth);
|
|
43
|
+
const tableEnd = $from.after(depth);
|
|
44
|
+
if (to > from && to < tableEnd) {
|
|
45
|
+
if (tr.selection instanceof CellSelection && tr.selection.from === from && tr.selection.to === to) {
|
|
46
|
+
tr.deleteSelection();
|
|
47
|
+
} else {
|
|
48
|
+
tr.delete(from, to);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const table = tr.doc.nodeAt(tableStart);
|
|
52
|
+
if (!table) return null;
|
|
53
|
+
const after = tableStart + table.nodeSize;
|
|
54
|
+
const before = tr.doc.content.size;
|
|
55
|
+
tr.replace(after, after, new Slice(slice.content, 0, 0));
|
|
56
|
+
return after + (tr.doc.content.size - before);
|
|
57
|
+
}
|
|
58
|
+
function handleTablePasteWithoutNesting(view, event, slice) {
|
|
59
|
+
const { state } = view;
|
|
60
|
+
const { selection } = state;
|
|
61
|
+
if (outermostTableDepth(selection.$from) < 0) return false;
|
|
62
|
+
if (selection instanceof CellSelection || __pastedCells(slice)) {
|
|
63
|
+
if (handleTablePaste(view, event, slice)) return true;
|
|
64
|
+
}
|
|
65
|
+
if (!sliceContainsTable(slice)) return false;
|
|
66
|
+
const tr = state.tr;
|
|
67
|
+
const end = insertSliceAfterTable(tr, selection.from, selection.to, slice);
|
|
68
|
+
if (end === null) return false;
|
|
69
|
+
tr.setSelection(Selection.near(tr.doc.resolve(end), -1));
|
|
70
|
+
view.dispatch(tr.scrollIntoView().setMeta("paste", true).setMeta("uiEvent", "paste"));
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
function changedRanges(transactions, skip2) {
|
|
74
|
+
let ranges = [];
|
|
75
|
+
for (const tr of transactions) {
|
|
76
|
+
const skipped = skip2(tr);
|
|
77
|
+
for (const step of tr.steps) {
|
|
78
|
+
const map = step.getMap();
|
|
79
|
+
ranges = ranges.map(([from, to]) => [map.map(from, 1), map.map(to, -1)]).filter(([from, to]) => to > from);
|
|
80
|
+
if (skipped) continue;
|
|
81
|
+
map.forEach((_oldStart, _oldEnd, newStart, newEnd) => {
|
|
82
|
+
if (newEnd > newStart) ranges.push([newStart, newEnd]);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return ranges;
|
|
87
|
+
}
|
|
88
|
+
function findNestedTables(doc, ranges) {
|
|
89
|
+
const found = /* @__PURE__ */ new Set();
|
|
90
|
+
for (const [from, to] of ranges) {
|
|
91
|
+
doc.nodesBetween(from, to, (node, pos) => {
|
|
92
|
+
if (!isTableNode(node) || pos < from) return true;
|
|
93
|
+
if (isInTableCell(doc.resolve(pos))) {
|
|
94
|
+
found.add(pos);
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
return true;
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
const sorted = [...found].sort((a, b) => a - b);
|
|
101
|
+
const outer = [];
|
|
102
|
+
for (const pos of sorted) {
|
|
103
|
+
const last = outer[outer.length - 1];
|
|
104
|
+
if (last === void 0 || pos >= last + doc.nodeAt(last).nodeSize) outer.push(pos);
|
|
105
|
+
}
|
|
106
|
+
return outer;
|
|
107
|
+
}
|
|
108
|
+
function unnestTables(tr, ranges) {
|
|
109
|
+
let changed = false;
|
|
110
|
+
for (let round = 0; round < 32 && ranges.length; round++) {
|
|
111
|
+
const nested = findNestedTables(tr.doc, ranges);
|
|
112
|
+
if (!nested.length) break;
|
|
113
|
+
const groups = /* @__PURE__ */ new Map();
|
|
114
|
+
for (const pos of nested) {
|
|
115
|
+
const $pos = tr.doc.resolve(pos);
|
|
116
|
+
const outer = $pos.before(outermostTableDepth($pos));
|
|
117
|
+
groups.set(outer, [...groups.get(outer) ?? [], pos]);
|
|
118
|
+
}
|
|
119
|
+
const next = [];
|
|
120
|
+
for (const outer of [...groups.keys()].sort((a, b) => b - a)) {
|
|
121
|
+
const positions = groups.get(outer);
|
|
122
|
+
const nodes = positions.map((pos) => tr.doc.nodeAt(pos));
|
|
123
|
+
for (let i = positions.length - 1; i >= 0; i--) {
|
|
124
|
+
const pos = positions[i];
|
|
125
|
+
const node = nodes[i];
|
|
126
|
+
const $pos = tr.doc.resolve(pos);
|
|
127
|
+
const parent = $pos.parent;
|
|
128
|
+
const filler = parent.childCount === 1 ? parent.type.contentMatch.defaultType?.createAndFill() : null;
|
|
129
|
+
if (filler) tr.replaceWith(pos, pos + node.nodeSize, filler);
|
|
130
|
+
else tr.delete(pos, pos + node.nodeSize);
|
|
131
|
+
}
|
|
132
|
+
const table = tr.doc.nodeAt(outer);
|
|
133
|
+
const after = outer + table.nodeSize;
|
|
134
|
+
const fragment = Fragment.fromArray(nodes);
|
|
135
|
+
tr.insert(after, fragment);
|
|
136
|
+
next.push([after, after + fragment.size]);
|
|
137
|
+
changed = true;
|
|
138
|
+
}
|
|
139
|
+
ranges = next;
|
|
140
|
+
}
|
|
141
|
+
return changed;
|
|
142
|
+
}
|
|
143
|
+
function replacesDocument(tr) {
|
|
144
|
+
return tr.steps.some((step, i) => {
|
|
145
|
+
const { from, to } = step;
|
|
146
|
+
return from === 0 && to !== void 0 && to >= tr.docs[i].content.size;
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
var skip = (tr) => !tr.docChanged || tr.getMeta(ALLOW_NESTED_TABLES_META) === true || // Undo/redo and remote collaborative changes restore what was there.
|
|
150
|
+
!!tr.getMeta("history$") || !!tr.getMeta("y-sync$") || // Other plugins' housekeeping, e.g. Track Changes putting a deleted
|
|
151
|
+
// (nested) table back so the deletion can be reviewed.
|
|
152
|
+
!!tr.getMeta("appendedTransaction") || replacesDocument(tr);
|
|
153
|
+
function createTableNestingPlugin() {
|
|
154
|
+
return new Plugin({
|
|
155
|
+
key: tableNestingPluginKey,
|
|
156
|
+
props: {
|
|
157
|
+
handlePaste: (view, event, slice) => handleTablePasteWithoutNesting(view, event, slice)
|
|
158
|
+
},
|
|
159
|
+
appendTransaction(transactions, _oldState, newState) {
|
|
160
|
+
if (transactions.every(skip)) return null;
|
|
161
|
+
const ranges = changedRanges(transactions, skip);
|
|
162
|
+
if (!ranges.length) return null;
|
|
163
|
+
const tr = newState.tr;
|
|
164
|
+
if (!unnestTables(tr, ranges)) return null;
|
|
165
|
+
return tr;
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
|
|
5
170
|
// src/extensions/table/extension.ts
|
|
6
171
|
import { getHTMLFromFragment } from "@tiptap/core";
|
|
7
|
-
import { Fragment } from "@tiptap/pm/model";
|
|
172
|
+
import { Fragment as Fragment2 } from "@tiptap/pm/model";
|
|
8
173
|
import * as _Table from "@tiptap/extension-table";
|
|
9
174
|
import * as _TableRow from "@tiptap/extension-table-row";
|
|
10
175
|
import * as _TableHeader from "@tiptap/extension-table-header";
|
|
@@ -65,7 +230,7 @@ function isGfmTable(node) {
|
|
|
65
230
|
var DELIMITERS = { left: ":---", center: ":---:", right: "---:" };
|
|
66
231
|
function serializeTableMarkdown(state, node) {
|
|
67
232
|
if (!isGfmTable(node)) {
|
|
68
|
-
const html = getHTMLFromFragment(
|
|
233
|
+
const html = getHTMLFromFragment(Fragment2.from(node), node.type.schema);
|
|
69
234
|
state.write(html.replace(/\n{2,}/g, "\n"));
|
|
70
235
|
state.closeBlock(node);
|
|
71
236
|
return;
|
|
@@ -107,6 +272,9 @@ var DEFAULT_TABLE_OPTIONS = {
|
|
|
107
272
|
var Table = BaseTable.extend({
|
|
108
273
|
addStorage() {
|
|
109
274
|
return { markdown: { serialize: serializeTableMarkdown } };
|
|
275
|
+
},
|
|
276
|
+
addProseMirrorPlugins() {
|
|
277
|
+
return [...this.parent?.() ?? [], createTableNestingPlugin()];
|
|
110
278
|
}
|
|
111
279
|
});
|
|
112
280
|
var TableRow = BaseTableRow;
|
|
@@ -138,7 +306,7 @@ function createTableExtensions(options = {}) {
|
|
|
138
306
|
}
|
|
139
307
|
|
|
140
308
|
// src/extensions/table/actions.ts
|
|
141
|
-
import { CellSelection, isInTable, selectedRect } from "@tiptap/pm/tables";
|
|
309
|
+
import { CellSelection as CellSelection2, isInTable, selectedRect } from "@tiptap/pm/tables";
|
|
142
310
|
var TABLE_ACTIONS = [
|
|
143
311
|
{ action: "insertTable", label: "Insert Table", description: "Inserts a table (rows, cols, withHeaderRow) at the cursor.", keywords: ["table", "grid", "new"] },
|
|
144
312
|
{ action: "addRowBefore", label: "Insert Row Above", description: "Adds a row above the current row.", keywords: ["row", "add", "above"] },
|
|
@@ -183,7 +351,7 @@ function isTableEnabled(editor) {
|
|
|
183
351
|
}
|
|
184
352
|
function isSelectionInTable(state) {
|
|
185
353
|
if (!state.schema.nodes.table) return false;
|
|
186
|
-
return state.selection instanceof
|
|
354
|
+
return state.selection instanceof CellSelection2 || isInTable(state);
|
|
187
355
|
}
|
|
188
356
|
function shouldShowTableBubbleMenu({ editor, state }) {
|
|
189
357
|
return editor.isEditable && isSelectionInTable(state);
|
|
@@ -316,7 +484,7 @@ function getTableState(editor) {
|
|
|
316
484
|
return {
|
|
317
485
|
...base,
|
|
318
486
|
inTable: true,
|
|
319
|
-
cellSelection: state.selection instanceof
|
|
487
|
+
cellSelection: state.selection instanceof CellSelection2,
|
|
320
488
|
rows: map.height,
|
|
321
489
|
columns: map.width,
|
|
322
490
|
row: rect.top,
|
|
@@ -384,6 +552,15 @@ function createTableStore(editor) {
|
|
|
384
552
|
}
|
|
385
553
|
|
|
386
554
|
export {
|
|
555
|
+
ALLOW_NESTED_TABLES_META,
|
|
556
|
+
tableNestingPluginKey,
|
|
557
|
+
outermostTableDepth,
|
|
558
|
+
isInTableCell,
|
|
559
|
+
sliceContainsTable,
|
|
560
|
+
insertSliceAfterTable,
|
|
561
|
+
handleTablePasteWithoutNesting,
|
|
562
|
+
unnestTables,
|
|
563
|
+
createTableNestingPlugin,
|
|
387
564
|
normalizeTableCellAlignment,
|
|
388
565
|
normalizeTableCellColor,
|
|
389
566
|
isGfmTable,
|
|
@@ -406,4 +583,4 @@ export {
|
|
|
406
583
|
getTableState,
|
|
407
584
|
createTableStore
|
|
408
585
|
};
|
|
409
|
-
//# sourceMappingURL=chunk-
|
|
586
|
+
//# sourceMappingURL=chunk-5H2OPMXZ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/extensions/table/nesting.ts","../src/extensions/table/extension.ts","../src/extensions/table/actions.ts"],"sourcesContent":["import { Fragment, Slice, type Node as ProsemirrorNode, type ResolvedPos } from \"@tiptap/pm/model\";\nimport { Plugin, PluginKey, Selection, type Transaction } from \"@tiptap/pm/state\";\nimport type { EditorView } from \"@tiptap/pm/view\";\nimport {\n CellSelection,\n __pastedCells,\n handlePaste as handleTablePaste,\n} from \"@tiptap/pm/tables\";\n\n/**\n * Set this meta on a transaction to let it create tables inside table cells\n * (the nesting guard leaves it alone), e.g. when loading legacy content\n * through a transaction that does not replace the whole document.\n */\nexport const ALLOW_NESTED_TABLES_META = \"allowNestedTables\";\n\nexport const tableNestingPluginKey = new PluginKey(\"tableNesting\");\n\nconst roleOf = (node: ProsemirrorNode) => node.type.spec.tableRole as string | undefined;\nconst isTableNode = (node: ProsemirrorNode) => roleOf(node) === \"table\";\n\n/** Depth of the outermost table around `$pos`, or `-1` outside tables. */\nexport function outermostTableDepth($pos: ResolvedPos): number {\n for (let d = 1; d <= $pos.depth; d++) if (isTableNode($pos.node(d))) return d;\n return -1;\n}\n\n/** Whether `$pos` lies inside a table cell or header cell. */\nexport function isInTableCell($pos: ResolvedPos): boolean {\n for (let d = $pos.depth; d > 0; d--) {\n const role = roleOf($pos.node(d));\n if (role === \"cell\" || role === \"header_cell\") return true;\n }\n return false;\n}\n\n/** Whether a slice or fragment contains a table node at any depth. */\nexport function sliceContainsTable(content: Slice | Fragment): boolean {\n const fragment = content instanceof Slice ? content.content : content;\n let found = false;\n fragment.descendants((node) => {\n if (found) return false;\n if (isTableNode(node)) found = true;\n return !found;\n });\n return found;\n}\n\n/**\n * Inserts `slice` right after the outermost table around `from` instead of\n * inside the cell, deleting `from`–`to` first when both lie in that table.\n * Returns the position right after the inserted content, or `null` (and\n * leaves `tr` unchanged) when `from` is not in a table.\n */\nexport function insertSliceAfterTable(tr: Transaction, from: number, to: number, slice: Slice): number | null {\n const $from = tr.doc.resolve(from);\n const depth = outermostTableDepth($from);\n if (depth < 0) return null;\n const tableStart = $from.before(depth);\n const tableEnd = $from.after(depth);\n if (to > from && to < tableEnd) {\n if (tr.selection instanceof CellSelection && tr.selection.from === from && tr.selection.to === to) {\n tr.deleteSelection();\n } else {\n tr.delete(from, to);\n }\n }\n const table = tr.doc.nodeAt(tableStart);\n if (!table) return null;\n const after = tableStart + table.nodeSize;\n const before = tr.doc.content.size;\n // A closed slice: the content becomes blocks of its own after the table\n // instead of merging into whatever follows it.\n tr.replace(after, after, new Slice(slice.content, 0, 0));\n return after + (tr.doc.content.size - before);\n}\n\n/**\n * Paste handling for slices that contain a table while the selection is in a\n * table: a cell selection or a pasted table (rows, cells) fills the cells from\n * the cursor (prosemirror-tables), and anything else that contains a table is\n * inserted after the outermost table, with the cursor at its end. Returns\n * `false` when the paste needs no special handling.\n */\nexport function handleTablePasteWithoutNesting(view: EditorView, event: ClipboardEvent | null, slice: Slice): boolean {\n const { state } = view;\n const { selection } = state;\n if (outermostTableDepth(selection.$from) < 0) return false;\n if (selection instanceof CellSelection || __pastedCells(slice)) {\n if (handleTablePaste(view, event as ClipboardEvent, slice)) return true;\n }\n if (!sliceContainsTable(slice)) return false;\n const tr = state.tr;\n const end = insertSliceAfterTable(tr, selection.from, selection.to, slice);\n if (end === null) return false;\n tr.setSelection(Selection.near(tr.doc.resolve(end), -1));\n view.dispatch(tr.scrollIntoView().setMeta(\"paste\", true).setMeta(\"uiEvent\", \"paste\"));\n return true;\n}\n\n/**\n * Ranges of the final document that `transactions` changed, leaving out the\n * changes of skipped transactions (their steps still map the other ranges).\n */\nfunction changedRanges(transactions: readonly Transaction[], skip: (tr: Transaction) => boolean): [number, number][] {\n let ranges: [number, number][] = [];\n for (const tr of transactions) {\n const skipped = skip(tr);\n for (const step of tr.steps) {\n const map = step.getMap();\n // Content that later (skipped) steps insert at a range's edge is not\n // part of it; pure deletions leave nothing to check.\n ranges = ranges\n .map(([from, to]): [number, number] => [map.map(from, 1), map.map(to, -1)])\n .filter(([from, to]) => to > from);\n if (skipped) continue;\n map.forEach((_oldStart, _oldEnd, newStart, newEnd) => {\n if (newEnd > newStart) ranges.push([newStart, newEnd]);\n });\n }\n }\n return ranges;\n}\n\n/** Tables starting inside `ranges` that sit in a table cell. */\nfunction findNestedTables(doc: ProsemirrorNode, ranges: [number, number][]): number[] {\n const found = new Set<number>();\n for (const [from, to] of ranges) {\n doc.nodesBetween(from, to, (node, pos) => {\n if (!isTableNode(node) || pos < from) return true;\n if (isInTableCell(doc.resolve(pos))) {\n found.add(pos);\n return false;\n }\n return true;\n });\n }\n // A table inside another found table moves with it.\n const sorted = [...found].sort((a, b) => a - b);\n const outer: number[] = [];\n for (const pos of sorted) {\n const last = outer[outer.length - 1];\n if (last === undefined || pos >= last + doc.nodeAt(last)!.nodeSize) outer.push(pos);\n }\n return outer;\n}\n\n/**\n * Moves tables that sit in table cells (at positions in `ranges`) to right\n * after their outermost table, keeping their content, and repeats for tables\n * nested in the moved ones. A cell left without content gets an empty\n * paragraph. Returns whether `tr` changed.\n */\nexport function unnestTables(tr: Transaction, ranges: [number, number][]): boolean {\n let changed = false;\n for (let round = 0; round < 32 && ranges.length; round++) {\n const nested = findNestedTables(tr.doc, ranges);\n if (!nested.length) break;\n // Group by outermost table; handle later tables first so earlier\n // positions stay valid.\n const groups = new Map<number, number[]>();\n for (const pos of nested) {\n const $pos = tr.doc.resolve(pos);\n const outer = $pos.before(outermostTableDepth($pos));\n groups.set(outer, [...(groups.get(outer) ?? []), pos]);\n }\n const next: [number, number][] = [];\n for (const outer of [...groups.keys()].sort((a, b) => b - a)) {\n const positions = groups.get(outer)!;\n const nodes = positions.map((pos) => tr.doc.nodeAt(pos)!);\n for (let i = positions.length - 1; i >= 0; i--) {\n const pos = positions[i];\n const node = nodes[i];\n const $pos = tr.doc.resolve(pos);\n const parent = $pos.parent;\n const filler = parent.childCount === 1 ? parent.type.contentMatch.defaultType?.createAndFill() : null;\n if (filler) tr.replaceWith(pos, pos + node.nodeSize, filler);\n else tr.delete(pos, pos + node.nodeSize);\n }\n const table = tr.doc.nodeAt(outer)!;\n const after = outer + table.nodeSize;\n const fragment = Fragment.fromArray(nodes);\n tr.insert(after, fragment);\n // Later groups are before this one, so this range stays valid.\n next.push([after, after + fragment.size]);\n changed = true;\n }\n ranges = next;\n }\n return changed;\n}\n\n/**\n * Whether a transaction replaces the whole document (`setContent`, loading):\n * existing documents keep their nested tables.\n */\nfunction replacesDocument(tr: Transaction): boolean {\n return tr.steps.some((step, i) => {\n const { from, to } = step as unknown as { from?: number; to?: number };\n return from === 0 && to !== undefined && to >= tr.docs[i].content.size;\n });\n}\n\nconst skip = (tr: Transaction) =>\n !tr.docChanged ||\n tr.getMeta(ALLOW_NESTED_TABLES_META) === true ||\n // Undo/redo and remote collaborative changes restore what was there.\n !!tr.getMeta(\"history$\") ||\n !!tr.getMeta(\"y-sync$\") ||\n // Other plugins' housekeeping, e.g. Track Changes putting a deleted\n // (nested) table back so the deletion can be reviewed.\n !!tr.getMeta(\"appendedTransaction\") ||\n replacesDocument(tr);\n\n/**\n * Keeps tables out of table cells: paste handling (see\n * `handleTablePasteWithoutNesting`) plus a guard that moves any table a\n * local edit puts into a cell (`insertContent`, `insertTable`, drops) to\n * right after the outermost table. Documents that already contain nested\n * tables (initial content, `setContent`, undo/redo, collaboration, Track\n * Changes restoring a deleted table) are left as they are.\n */\nexport function createTableNestingPlugin(): Plugin {\n return new Plugin({\n key: tableNestingPluginKey,\n props: {\n handlePaste: (view, event, slice) => handleTablePasteWithoutNesting(view, event, slice),\n },\n appendTransaction(transactions, _oldState, newState) {\n if (transactions.every(skip)) return null;\n const ranges = changedRanges(transactions, skip);\n if (!ranges.length) return null;\n const tr = newState.tr;\n if (!unnestTables(tr, ranges)) return null;\n return tr;\n },\n });\n}\n","import { getHTMLFromFragment, type Extensions } from \"@tiptap/core\";\nimport { Fragment, type Node as ProsemirrorNode } from \"@tiptap/pm/model\";\nimport * as _Table from \"@tiptap/extension-table\";\nimport * as _TableRow from \"@tiptap/extension-table-row\";\nimport * as _TableHeader from \"@tiptap/extension-table-header\";\nimport * as _TableCell from \"@tiptap/extension-table-cell\";\nimport { createTableNestingPlugin } from \"./nesting\";\n\nconst resolveExt = (mod: any, name: string) =>\n mod?.[name] || mod?.default?.[name] || mod?.default?.default || mod?.default || mod;\n\nconst BaseTable = resolveExt(_Table, \"Table\");\nconst BaseTableRow = resolveExt(_TableRow, \"TableRow\");\nconst BaseTableHeader = resolveExt(_TableHeader, \"TableHeader\");\nconst BaseTableCell = resolveExt(_TableCell, \"TableCell\");\n\n/** Horizontal alignment of a table cell (`align` attribute). */\nexport type TableCellAlignment = \"left\" | \"center\" | \"right\" | \"justify\";\n\nconst ALIGNMENTS = new Set<TableCellAlignment>([\"left\", \"center\", \"right\", \"justify\"]);\n\n/** Returns a valid cell alignment, or `null`. */\nexport function normalizeTableCellAlignment(value: unknown): TableCellAlignment | null {\n const v = typeof value === \"string\" ? value.trim().toLowerCase() : \"\";\n return ALIGNMENTS.has(v as TableCellAlignment) ? (v as TableCellAlignment) : null;\n}\n\n/**\n * Color values allowed as a cell background: hex, `rgb()/rgba()/hsl()/hsla()`\n * with numeric arguments, or a CSS color keyword. Anything else (e.g.\n * `url(...)`, `expression(...)`, `;`) is rejected because the value ends up in\n * a `style` attribute.\n */\nconst COLOR_REGEX =\n /^(?:#[0-9a-f]{3,8}|(?:rgb|rgba|hsl|hsla)\\(\\s*[-0-9.%\\s,/deg]+\\)|[a-z]{3,20})$/i;\n\n/** Returns a safe CSS color for a cell background, or `null`. */\nexport function normalizeTableCellColor(value: unknown): string | null {\n const v = typeof value === \"string\" ? value.trim() : \"\";\n if (!v || v.length > 64 || !COLOR_REGEX.test(v)) return null;\n if (/^(?:inherit|initial|unset|revert|transparent)$/i.test(v)) return null;\n return v;\n}\n\n/** Cell attributes added on top of TipTap's `colspan` / `rowspan` / `colwidth`. */\nconst cellAttributes = () => ({\n align: {\n default: null,\n parseHTML: (element: HTMLElement) =>\n normalizeTableCellAlignment(element.style?.textAlign || element.getAttribute(\"align\")),\n renderHTML: (attrs: Record<string, any>) => {\n const align = normalizeTableCellAlignment(attrs.align);\n return align ? { style: `text-align: ${align}` } : {};\n },\n },\n backgroundColor: {\n default: null,\n parseHTML: (element: HTMLElement) =>\n normalizeTableCellColor(\n element.getAttribute(\"data-background-color\") ||\n element.style?.backgroundColor ||\n element.getAttribute(\"bgcolor\"),\n ),\n renderHTML: (attrs: Record<string, any>) => {\n const color = normalizeTableCellColor(attrs.backgroundColor);\n return color ? { style: `background-color: ${color}`, \"data-background-color\": color } : {};\n },\n },\n});\n\n// ---------------------------------------------------------------------------\n// Markdown (tiptap-markdown)\n// ---------------------------------------------------------------------------\n\nconst children = (node: ProsemirrorNode) => {\n const list: ProsemirrorNode[] = [];\n node.forEach((child) => list.push(child));\n return list;\n};\n\nconst hasSpan = (cell: ProsemirrorNode) => (cell.attrs.colspan ?? 1) > 1 || (cell.attrs.rowspan ?? 1) > 1;\n\n/**\n * Whether a table can be written as a GFM pipe table: the first row is all\n * header cells, the other rows have none, no cell spans rows or columns, and\n * every cell holds a single paragraph.\n */\nexport function isGfmTable(node: ProsemirrorNode): boolean {\n const rows = children(node);\n if (rows.length === 0) return false;\n const width = rows[0].childCount;\n return rows.every(\n (row, r) =>\n row.childCount === width &&\n children(row).every(\n (cell) =>\n (r === 0 ? cell.type.name === \"tableHeader\" : cell.type.name === \"tableCell\") &&\n !hasSpan(cell) &&\n cell.childCount === 1 &&\n cell.firstChild!.type.name === \"paragraph\",\n ),\n );\n}\n\nconst DELIMITERS: Record<string, string> = { left: \":---\", center: \":---:\", right: \"---:\" };\n\n/**\n * tiptap-markdown serializer for tables: GFM pipe tables (with column\n * alignment from the header cells and `|` escaped) when `isGfmTable`, HTML\n * otherwise (spans, header columns, multi-paragraph cells).\n */\nfunction serializeTableMarkdown(state: any, node: ProsemirrorNode) {\n if (!isGfmTable(node)) {\n const html = getHTMLFromFragment(Fragment.from(node), node.type.schema);\n // An HTML block must start on its own line and contain no blank lines.\n state.write(html.replace(/\\n{2,}/g, \"\\n\"));\n state.closeBlock(node);\n return;\n }\n const previous = state.inTable;\n state.inTable = true;\n children(node).forEach((row, r) => {\n if (r) state.ensureNewLine();\n state.write(\"| \");\n children(row).forEach((cell, c) => {\n if (c) state.write(\" | \");\n const paragraph = cell.firstChild!;\n // Render in place (mid-line, so no block prefix is added), then escape\n // the cell's pipes and line breaks, which would end the cell or row.\n const start = state.out.length;\n if (paragraph.childCount) state.renderInline(paragraph);\n const text: string = state.out.slice(start);\n state.out = state.out.slice(0, start) + text.replace(/\\n/g, \" \").replace(/\\|/g, \"\\\\|\");\n });\n state.write(\" |\");\n if (r === 0) {\n const delimiter = children(row).map((cell) => DELIMITERS[cell.attrs.align] ?? \"---\");\n state.ensureNewLine();\n state.write(`| ${delimiter.join(\" | \")} |`);\n }\n });\n state.inTable = previous;\n state.closeBlock(node);\n}\n\n// ---------------------------------------------------------------------------\n// Extensions\n// ---------------------------------------------------------------------------\n\nexport interface RichTextTableOptions {\n /** Drag column borders to resize columns (stored as `colwidth`). Default `true`. */\n resizable: boolean;\n /** Width of the resize handle in pixels. Default 5. */\n handleWidth: number;\n /** Minimum cell width in pixels. Default 25. */\n cellMinWidth: number;\n /** Whether the last column can be resized. Default `true`. */\n lastColumnResizable: boolean;\n /** Allow selecting the whole table as a node (click its border, Esc from a cell selection). Default `true`. */\n allowTableNodeSelection: boolean;\n /** HTML attributes of the `<table>` element. */\n HTMLAttributes: Record<string, any>;\n /** HTML attributes of `<td>` elements. */\n cellHTMLAttributes: Record<string, any>;\n /** HTML attributes of `<th>` elements. */\n headerHTMLAttributes: Record<string, any>;\n /** HTML attributes of `<tr>` elements. */\n rowHTMLAttributes: Record<string, any>;\n}\n\nexport const DEFAULT_TABLE_OPTIONS: RichTextTableOptions = {\n resizable: true,\n handleWidth: 5,\n cellMinWidth: 25,\n lastColumnResizable: true,\n allowTableNodeSelection: true,\n HTMLAttributes: { class: \"pixerate-table\" },\n cellHTMLAttributes: {},\n headerHTMLAttributes: {},\n rowHTMLAttributes: {},\n};\n\n/**\n * TipTap's `Table` with the GFM-aware markdown serializer and the nesting\n * guard (`createTableNestingPlugin`): tables are never pasted, imported or\n * inserted into table cells.\n */\nexport const Table = BaseTable.extend({\n addStorage() {\n return { markdown: { serialize: serializeTableMarkdown } };\n },\n addProseMirrorPlugins() {\n return [...(this.parent?.() ?? []), createTableNestingPlugin()];\n },\n});\n\nexport const TableRow = BaseTableRow;\n\n/** TipTap's `TableCell` plus `align` and `backgroundColor` attributes. */\nexport const TableCell = BaseTableCell.extend({\n addAttributes() {\n return { ...this.parent?.(), ...cellAttributes() };\n },\n});\n\n/** TipTap's `TableHeader` plus `align` and `backgroundColor` attributes. */\nexport const TableHeader = BaseTableHeader.extend({\n addAttributes() {\n return { ...this.parent?.(), ...cellAttributes() };\n },\n});\n\n/**\n * The table extensions (`table`, `tableRow`, `tableHeader`, `tableCell`)\n * configured for rich documents: resizable columns, header rows, columns and\n * cells, `colspan` / `rowspan` from imported HTML, cell alignment and\n * background, table node selection and GFM markdown. `createRichTextPreset`\n * adds them unless `table: false`.\n */\nexport function createTableExtensions(options: Partial<RichTextTableOptions> = {}): Extensions {\n const o = { ...DEFAULT_TABLE_OPTIONS, ...options };\n return [\n Table.configure({\n resizable: o.resizable,\n handleWidth: o.handleWidth,\n cellMinWidth: o.cellMinWidth,\n lastColumnResizable: o.lastColumnResizable,\n allowTableNodeSelection: o.allowTableNodeSelection,\n HTMLAttributes: o.HTMLAttributes,\n }),\n TableRow.configure({ HTMLAttributes: o.rowHTMLAttributes }),\n TableHeader.configure({ HTMLAttributes: o.headerHTMLAttributes }),\n TableCell.configure({ HTMLAttributes: o.cellHTMLAttributes }),\n ];\n}\n","import type { Editor } from \"@tiptap/core\";\nimport type { EditorState } from \"@tiptap/pm/state\";\nimport { CellSelection, isInTable, selectedRect } from \"@tiptap/pm/tables\";\nimport { isTrackChangesEnabled } from \"../track-changes\";\nimport {\n normalizeTableCellAlignment,\n normalizeTableCellColor,\n type TableCellAlignment,\n} from \"./extension\";\n\n/** Table operations shared by the command registry, the toolbars and agent tools. */\nexport type TableAction =\n | \"insertTable\"\n | \"addRowBefore\"\n | \"addRowAfter\"\n | \"deleteRow\"\n | \"addColumnBefore\"\n | \"addColumnAfter\"\n | \"deleteColumn\"\n | \"deleteTable\"\n | \"mergeCells\"\n | \"splitCell\"\n | \"toggleHeaderRow\"\n | \"toggleHeaderColumn\"\n | \"toggleHeaderCell\"\n | \"goToNextCell\"\n | \"goToPreviousCell\"\n | \"setCellAlignment\"\n | \"setCellBackground\";\n\n/** Parameters of `insertTable`, `setCellAlignment` and `setCellBackground`. */\nexport interface TableActionParams {\n /** `insertTable`: number of rows (1–100, default 3). */\n rows?: number;\n /** `insertTable`: number of columns (1–50, default 3). */\n cols?: number;\n /** `insertTable`: make the first row a header row (default `true`). */\n withHeaderRow?: boolean;\n /** `setCellAlignment`: `left`, `center`, `right`, `justify`, or `null` to clear. */\n align?: TableCellAlignment | null;\n /** `setCellBackground`: a CSS color, or `null` to clear. */\n color?: string | null;\n}\n\nexport interface TableActionInfo {\n action: TableAction;\n label: string;\n description: string;\n keywords: readonly string[];\n}\n\n/** Every table action with its label, in toolbar order. */\nexport const TABLE_ACTIONS: readonly TableActionInfo[] = [\n { action: \"insertTable\", label: \"Insert Table\", description: \"Inserts a table (rows, cols, withHeaderRow) at the cursor.\", keywords: [\"table\", \"grid\", \"new\"] },\n { action: \"addRowBefore\", label: \"Insert Row Above\", description: \"Adds a row above the current row.\", keywords: [\"row\", \"add\", \"above\"] },\n { action: \"addRowAfter\", label: \"Insert Row Below\", description: \"Adds a row below the current row.\", keywords: [\"row\", \"add\", \"below\"] },\n { action: \"deleteRow\", label: \"Delete Row\", description: \"Deletes the selected rows.\", keywords: [\"row\", \"remove\"] },\n { action: \"addColumnBefore\", label: \"Insert Column Left\", description: \"Adds a column left of the current column.\", keywords: [\"column\", \"add\", \"left\", \"before\"] },\n { action: \"addColumnAfter\", label: \"Insert Column Right\", description: \"Adds a column right of the current column.\", keywords: [\"column\", \"add\", \"right\", \"after\"] },\n { action: \"deleteColumn\", label: \"Delete Column\", description: \"Deletes the selected columns.\", keywords: [\"column\", \"remove\"] },\n { action: \"deleteTable\", label: \"Delete Table\", description: \"Deletes the table around the cursor.\", keywords: [\"table\", \"remove\"] },\n { action: \"mergeCells\", label: \"Merge Cells\", description: \"Merges the selected cells into one.\", keywords: [\"combine\", \"join\", \"span\"] },\n { action: \"splitCell\", label: \"Split Cell\", description: \"Splits a merged cell back into single cells.\", keywords: [\"unmerge\", \"span\"] },\n { action: \"toggleHeaderRow\", label: \"Toggle Header Row\", description: \"Turns the first row into header cells, or back.\", keywords: [\"header\", \"row\", \"th\"] },\n { action: \"toggleHeaderColumn\", label: \"Toggle Header Column\", description: \"Turns the first column into header cells, or back.\", keywords: [\"header\", \"column\", \"th\"] },\n { action: \"toggleHeaderCell\", label: \"Toggle Header Cell\", description: \"Turns the selected cells into header cells, or back.\", keywords: [\"header\", \"cell\", \"th\"] },\n { action: \"goToNextCell\", label: \"Next Cell\", description: \"Moves the cursor to the next cell.\", keywords: [\"tab\", \"navigate\"] },\n { action: \"goToPreviousCell\", label: \"Previous Cell\", description: \"Moves the cursor to the previous cell.\", keywords: [\"shift tab\", \"navigate\"] },\n { action: \"setCellAlignment\", label: \"Align Cells…\", description: \"Sets the horizontal alignment (align: left | center | right | justify | null) of the selected cells.\", keywords: [\"align\", \"left\", \"center\", \"right\"] },\n { action: \"setCellBackground\", label: \"Cell Background…\", description: \"Sets the background color (color: CSS color or null) of the selected cells.\", keywords: [\"shading\", \"fill\", \"color\"] },\n];\n\n/** A button of the table toolbars (`TableToolbar` in React and Svelte). */\nexport interface TableToolbarItem {\n /** Unique id (also the button's `data-action`). */\n id: string;\n action: TableAction;\n params?: TableActionParams;\n /** Short button text. */\n label: string;\n /** Accessible name and tooltip. */\n title: string;\n /** Items of one group are separated from the next group. */\n group: string;\n /** Toggle buttons: whether the button shows as pressed. */\n active?: (state: TableState) => boolean;\n}\n\n/** The default table toolbar: rows, columns, cells, headers, alignment, delete. */\nexport const DEFAULT_TABLE_TOOLBAR: readonly TableToolbarItem[] = [\n { id: \"addRowBefore\", action: \"addRowBefore\", label: \"+ Row ↑\", title: \"Insert row above\", group: \"rows\" },\n { id: \"addRowAfter\", action: \"addRowAfter\", label: \"+ Row ↓\", title: \"Insert row below\", group: \"rows\" },\n { id: \"deleteRow\", action: \"deleteRow\", label: \"− Row\", title: \"Delete row\", group: \"rows\" },\n { id: \"addColumnBefore\", action: \"addColumnBefore\", label: \"+ Col ←\", title: \"Insert column left\", group: \"columns\" },\n { id: \"addColumnAfter\", action: \"addColumnAfter\", label: \"+ Col →\", title: \"Insert column right\", group: \"columns\" },\n { id: \"deleteColumn\", action: \"deleteColumn\", label: \"− Col\", title: \"Delete column\", group: \"columns\" },\n { id: \"mergeCells\", action: \"mergeCells\", label: \"Merge\", title: \"Merge cells\", group: \"cells\" },\n { id: \"splitCell\", action: \"splitCell\", label: \"Split\", title: \"Split cell\", group: \"cells\" },\n { id: \"toggleHeaderRow\", action: \"toggleHeaderRow\", label: \"Header row\", title: \"Toggle header row\", group: \"headers\", active: (s) => s.headerRow },\n { id: \"toggleHeaderColumn\", action: \"toggleHeaderColumn\", label: \"Header col\", title: \"Toggle header column\", group: \"headers\", active: (s) => s.headerColumn },\n { id: \"toggleHeaderCell\", action: \"toggleHeaderCell\", label: \"Header cell\", title: \"Toggle header cell\", group: \"headers\", active: (s) => s.headerCell },\n { id: \"alignLeft\", action: \"setCellAlignment\", params: { align: \"left\" }, label: \"Left\", title: \"Align cell left\", group: \"align\", active: (s) => s.cellAlignment === \"left\" },\n { id: \"alignCenter\", action: \"setCellAlignment\", params: { align: \"center\" }, label: \"Center\", title: \"Align cell center\", group: \"align\", active: (s) => s.cellAlignment === \"center\" },\n { id: \"alignRight\", action: \"setCellAlignment\", params: { align: \"right\" }, label: \"Right\", title: \"Align cell right\", group: \"align\", active: (s) => s.cellAlignment === \"right\" },\n { id: \"deleteTable\", action: \"deleteTable\", label: \"Delete table\", title: \"Delete table\", group: \"table\" },\n];\n\nexport const MAX_TABLE_ROWS = 100;\nexport const MAX_TABLE_COLUMNS = 50;\n\nconst live = (editor: Editor | null | undefined): editor is Editor => !!editor && !editor.isDestroyed;\n\n/** Whether the editor's schema has the table nodes (`createRichTextPreset({ table })`). */\nexport function isTableEnabled(editor: Editor | null | undefined): boolean {\n return live(editor) && !!editor.schema.nodes.table && !!editor.schema.nodes.tableRow;\n}\n\n/** Whether the selection (cursor, text or cell selection) is inside a table. */\nexport function isSelectionInTable(state: EditorState): boolean {\n if (!state.schema.nodes.table) return false;\n return state.selection instanceof CellSelection || isInTable(state);\n}\n\n/**\n * `shouldShow` for a table bubble menu (TipTap's `BubbleMenuPlugin`): shown\n * while an editable editor's selection is in a table, even a collapsed cursor.\n */\nexport function shouldShowTableBubbleMenu({ editor, state }: { editor: Editor; state: EditorState }): boolean {\n return editor.isEditable && isSelectionInTable(state);\n}\n\nconst isInt = (value: unknown, min: number, max: number) =>\n typeof value === \"number\" && Number.isInteger(value) && value >= min && value <= max;\n\nconst can = (editor: Editor, run: (chain: any) => any): boolean => {\n try {\n return !!run(editor.can().chain()).run();\n } catch {\n return false;\n }\n};\n\n/**\n * Whether a table action can run: `true`, or the reason it cannot (e.g.\n * \"Place the cursor in a table first.\").\n */\nexport function getTableActionState(\n editor: Editor | null | undefined,\n action: TableAction,\n params: TableActionParams = {},\n): true | string {\n if (!live(editor)) return \"The editor is not available.\";\n if (!isTableEnabled(editor)) return \"Tables are not enabled in this editor.\";\n if (!editor.isEditable) return \"The editor is read-only.\";\n const state = editor.state;\n const inTable = isSelectionInTable(state);\n\n if (action === \"insertTable\") {\n if (inTable) return \"Tables cannot be nested: move the cursor out of the table first.\";\n if (params.rows !== undefined && !isInt(params.rows, 1, MAX_TABLE_ROWS)) {\n return `Rows must be a whole number from 1 to ${MAX_TABLE_ROWS}.`;\n }\n if (params.cols !== undefined && !isInt(params.cols, 1, MAX_TABLE_COLUMNS)) {\n return `Columns must be a whole number from 1 to ${MAX_TABLE_COLUMNS}.`;\n }\n return can(editor, (c) => c.insertTable({ rows: 1, cols: 1 })) ? true : \"A table cannot be inserted here.\";\n }\n\n if (!inTable) return \"Place the cursor in a table first.\";\n\n switch (action) {\n case \"mergeCells\":\n case \"splitCell\": {\n if (isTrackChangesEnabled(editor)) {\n return `${action === \"mergeCells\" ? \"Merging\" : \"Splitting\"} cells cannot be tracked: turn off Track Changes first.`;\n }\n if (action === \"mergeCells\") {\n return can(editor, (c) => c.mergeCells()) ? true : \"Select two or more adjacent cells to merge.\";\n }\n return can(editor, (c) => c.splitCell()) ? true : \"Only a merged cell can be split.\";\n }\n case \"deleteRow\":\n case \"deleteColumn\": {\n // prosemirror-tables only refuses to delete every row/column when dispatching.\n const rect = selectedRect(state);\n const all = action === \"deleteRow\"\n ? rect.top === 0 && rect.bottom === rect.map.height\n : rect.left === 0 && rect.right === rect.map.width;\n const what = action === \"deleteRow\" ? \"rows\" : \"columns\";\n if (all || !can(editor, (c) => c[action]())) return `These are all the ${what}: delete the table instead.`;\n return true;\n }\n case \"goToNextCell\":\n return can(editor, (c) => c.goToNextCell()) ? true : \"This is the last cell.\";\n case \"goToPreviousCell\":\n return can(editor, (c) => c.goToPreviousCell()) ? true : \"This is the first cell.\";\n case \"setCellAlignment\":\n if (params.align !== undefined && params.align !== null && !normalizeTableCellAlignment(params.align)) {\n return 'Alignment must be \"left\", \"center\", \"right\", \"justify\" or null.';\n }\n if (!editor.schema.nodes.tableCell?.spec.attrs?.align) return \"Cell alignment is not supported by this schema.\";\n return true;\n case \"setCellBackground\":\n if (params.color !== undefined && params.color !== null && !normalizeTableCellColor(params.color)) {\n return \"Color must be a CSS color such as #fde68a, rgb(…) or a color name, or null.\";\n }\n if (!editor.schema.nodes.tableCell?.spec.attrs?.backgroundColor) return \"Cell backgrounds are not supported by this schema.\";\n return true;\n default:\n return can(editor, (c) => c[action]()) ? true : \"This table action is not available here.\";\n }\n}\n\nexport interface RunTableActionOptions {\n /** Focus the editor (toolbars). Default `false`. */\n focus?: boolean;\n}\n\n/**\n * Runs a table action. Returns `false` (and changes nothing) when it cannot\n * run; check `getTableActionState` for the reason.\n */\nexport function runTableAction(\n editor: Editor | null | undefined,\n action: TableAction,\n params: TableActionParams = {},\n options: RunTableActionOptions = {},\n): boolean {\n if (getTableActionState(editor, action, params) !== true) return false;\n const ed = editor as Editor;\n let chain: any = ed.chain();\n if (options.focus) chain = chain.focus();\n switch (action) {\n case \"insertTable\":\n chain = chain.insertTable({\n rows: params.rows ?? 3,\n cols: params.cols ?? 3,\n withHeaderRow: params.withHeaderRow ?? true,\n });\n break;\n case \"setCellAlignment\":\n chain = chain.setCellAttribute(\"align\", normalizeTableCellAlignment(params.align));\n break;\n case \"setCellBackground\":\n chain = chain.setCellAttribute(\"backgroundColor\", normalizeTableCellColor(params.color));\n break;\n default:\n chain = chain[action]();\n }\n return !!chain.run();\n}\n\nexport interface TableActionStatus {\n enabled: boolean;\n /** Why the action cannot run (only when `enabled` is false). */\n reason?: string;\n}\n\n/** The table at the selection and what can be done there. */\nexport interface TableState {\n /** The schema has tables. */\n enabled: boolean;\n /** The selection is inside a table. */\n inTable: boolean;\n /** Cells are selected (a `CellSelection`). */\n cellSelection: boolean;\n /** Size of the table (0 outside a table). */\n rows: number;\n columns: number;\n /** Row and column (0-based) of the selection's first cell, or -1. */\n row: number;\n column: number;\n /** The first row / first column are all header cells. */\n headerRow: boolean;\n headerColumn: boolean;\n /** The cell at the selection is a header cell. */\n headerCell: boolean;\n /** Alignment / background of the cell at the selection. */\n cellAlignment: TableCellAlignment | null;\n cellBackground: string | null;\n /** Enablement of every action (with the default params). */\n actions: Record<TableAction, TableActionStatus>;\n}\n\nconst NO_ACTIONS = Object.fromEntries(\n TABLE_ACTIONS.map(({ action }) => [action, { enabled: false, reason: \"The editor is not available.\" }]),\n) as Record<TableAction, TableActionStatus>;\n\nexport const EMPTY_TABLE_STATE: TableState = Object.freeze({\n enabled: false,\n inTable: false,\n cellSelection: false,\n rows: 0,\n columns: 0,\n row: -1,\n column: -1,\n headerRow: false,\n headerColumn: false,\n headerCell: false,\n cellAlignment: null,\n cellBackground: null,\n actions: NO_ACTIONS,\n}) as TableState;\n\n/** Computes the table state at the editor's selection. */\nexport function getTableState(editor: Editor | null | undefined): TableState {\n if (!live(editor)) return EMPTY_TABLE_STATE;\n const actions = Object.fromEntries(\n TABLE_ACTIONS.map(({ action }) => {\n const result = getTableActionState(editor, action);\n return [action, result === true ? { enabled: true } : { enabled: false, reason: result }];\n }),\n ) as Record<TableAction, TableActionStatus>;\n const state = editor.state;\n const base: TableState = { ...EMPTY_TABLE_STATE, enabled: isTableEnabled(editor), actions };\n if (!base.enabled || !isSelectionInTable(state)) return base;\n try {\n const rect = selectedRect(state);\n const { map, table } = rect;\n const cellAt = (row: number, col: number) => table.nodeAt(map.map[row * map.width + col]);\n const allHeaders = (positions: number[]) =>\n positions.length > 0 && positions.every((pos) => table.nodeAt(pos)?.type.name === \"tableHeader\");\n const firstRow = map.cellsInRect({ left: 0, right: map.width, top: 0, bottom: 1 });\n const firstColumn = map.cellsInRect({ left: 0, right: 1, top: 0, bottom: map.height });\n const cell = cellAt(rect.top, rect.left);\n return {\n ...base,\n inTable: true,\n cellSelection: state.selection instanceof CellSelection,\n rows: map.height,\n columns: map.width,\n row: rect.top,\n column: rect.left,\n headerRow: allHeaders(firstRow),\n headerColumn: allHeaders(firstColumn),\n headerCell: cell?.type.name === \"tableHeader\",\n cellAlignment: normalizeTableCellAlignment(cell?.attrs.align),\n cellBackground: normalizeTableCellColor(cell?.attrs.backgroundColor),\n };\n } catch {\n return { ...base, inTable: true };\n }\n}\n\nconst stateKey = (state: TableState) => JSON.stringify(state);\n\nexport interface TableStore {\n getSnapshot(): TableState;\n subscribe(listener: () => void): () => void;\n destroy(): void;\n}\n\n/**\n * An external store of `getTableState(editor)` for UI bindings (React's\n * `useSyncExternalStore`, Svelte runes). The snapshot object only changes\n * when the state does, and the store listens to the editor only while it\n * has subscribers.\n */\nexport function createTableStore(editor: Editor | null | undefined): TableStore {\n const listeners = new Set<() => void>();\n let snapshot = getTableState(editor);\n let key = stateKey(snapshot);\n\n const update = () => {\n const next = getTableState(editor);\n const nextKey = stateKey(next);\n if (nextKey === key) return;\n snapshot = next;\n key = nextKey;\n listeners.forEach((listener) => listener());\n };\n const detach = () => {\n editor?.off(\"transaction\", update);\n editor?.off(\"update\", update);\n editor?.off(\"focus\", update);\n editor?.off(\"destroy\", update);\n };\n\n return {\n getSnapshot: () => {\n if (!listeners.size) {\n const next = getTableState(editor);\n const nextKey = stateKey(next);\n if (nextKey !== key) {\n snapshot = next;\n key = nextKey;\n }\n }\n return snapshot;\n },\n subscribe(listener) {\n if (!listeners.size && editor) {\n update();\n editor.on(\"transaction\", update);\n // `setEditable` emits `update` without a transaction.\n editor.on(\"update\", update);\n editor.on(\"focus\", update);\n editor.on(\"destroy\", update);\n }\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n if (!listeners.size) detach();\n };\n },\n destroy() {\n detach();\n listeners.clear();\n },\n };\n}\n"],"mappings":";;;;;AAAA,SAAS,UAAU,aAA6D;AAChF,SAAS,QAAQ,WAAW,iBAAmC;AAE/D;AAAA,EACE;AAAA,EACA;AAAA,EACA,eAAe;AAAA,OACV;AAOA,IAAM,2BAA2B;AAEjC,IAAM,wBAAwB,IAAI,UAAU,cAAc;AAEjE,IAAM,SAAS,CAAC,SAA0B,KAAK,KAAK,KAAK;AACzD,IAAM,cAAc,CAAC,SAA0B,OAAO,IAAI,MAAM;AAGzD,SAAS,oBAAoB,MAA2B;AAC7D,WAAS,IAAI,GAAG,KAAK,KAAK,OAAO,IAAK,KAAI,YAAY,KAAK,KAAK,CAAC,CAAC,EAAG,QAAO;AAC5E,SAAO;AACT;AAGO,SAAS,cAAc,MAA4B;AACxD,WAAS,IAAI,KAAK,OAAO,IAAI,GAAG,KAAK;AACnC,UAAM,OAAO,OAAO,KAAK,KAAK,CAAC,CAAC;AAChC,QAAI,SAAS,UAAU,SAAS,cAAe,QAAO;AAAA,EACxD;AACA,SAAO;AACT;AAGO,SAAS,mBAAmB,SAAoC;AACrE,QAAM,WAAW,mBAAmB,QAAQ,QAAQ,UAAU;AAC9D,MAAI,QAAQ;AACZ,WAAS,YAAY,CAAC,SAAS;AAC7B,QAAI,MAAO,QAAO;AAClB,QAAI,YAAY,IAAI,EAAG,SAAQ;AAC/B,WAAO,CAAC;AAAA,EACV,CAAC;AACD,SAAO;AACT;AAQO,SAAS,sBAAsB,IAAiB,MAAc,IAAY,OAA6B;AAC5G,QAAM,QAAQ,GAAG,IAAI,QAAQ,IAAI;AACjC,QAAM,QAAQ,oBAAoB,KAAK;AACvC,MAAI,QAAQ,EAAG,QAAO;AACtB,QAAM,aAAa,MAAM,OAAO,KAAK;AACrC,QAAM,WAAW,MAAM,MAAM,KAAK;AAClC,MAAI,KAAK,QAAQ,KAAK,U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,IACF;AAAA,IACA,UAAU;AACR,aAAO;AACP,gBAAU,MAAM;AAAA,IAClB;AAAA,EACF;AACF;","names":["skip","Fragment","Fragment","CellSelection","CellSelection"]}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/tokens/color.ts
|
|
2
|
+
var HEX = /^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
|
|
3
|
+
var RGB = /^rgba?\(([^()]*)\)$/i;
|
|
4
|
+
var clamp01 = (v) => Math.min(1, Math.max(0, v));
|
|
5
|
+
var byte = (v) => Math.round(clamp01(v) * 255);
|
|
6
|
+
var hex2 = (n) => n.toString(16).padStart(2, "0");
|
|
7
|
+
function rgbaToHex(r, g, b, a = 1) {
|
|
8
|
+
const head = `#${hex2(byte(r))}${hex2(byte(g))}${hex2(byte(b))}`;
|
|
9
|
+
const alpha = byte(a);
|
|
10
|
+
return alpha === 255 ? head : head + hex2(alpha);
|
|
11
|
+
}
|
|
12
|
+
function hexToRgba(hex) {
|
|
13
|
+
const normal = normalizeTokenColor(hex);
|
|
14
|
+
if (normal === null) return null;
|
|
15
|
+
const n = (i) => parseInt(normal.slice(i, i + 2), 16) / 255;
|
|
16
|
+
return { r: n(1), g: n(3), b: n(5), a: normal.length === 9 ? n(7) : 1 };
|
|
17
|
+
}
|
|
18
|
+
function channel(part, scale) {
|
|
19
|
+
const pct = part.endsWith("%");
|
|
20
|
+
const n = Number(pct ? part.slice(0, -1) : part);
|
|
21
|
+
if (!Number.isFinite(n)) return null;
|
|
22
|
+
return pct ? n / 100 : n / scale;
|
|
23
|
+
}
|
|
24
|
+
function normalizeTokenColor(input) {
|
|
25
|
+
if (typeof input === "string") {
|
|
26
|
+
const text = input.trim();
|
|
27
|
+
if (text.length > 200) return null;
|
|
28
|
+
const lower = text.toLowerCase();
|
|
29
|
+
if (lower === "transparent") return "#00000000";
|
|
30
|
+
if (lower === "black") return "#000000";
|
|
31
|
+
if (lower === "white") return "#ffffff";
|
|
32
|
+
const hex = HEX.exec(text);
|
|
33
|
+
if (hex) {
|
|
34
|
+
let digits = hex[1].toLowerCase();
|
|
35
|
+
if (digits.length <= 4) digits = [...digits].map((c) => c + c).join("");
|
|
36
|
+
if (digits.length === 8 && digits.endsWith("ff")) digits = digits.slice(0, 6);
|
|
37
|
+
return `#${digits}`;
|
|
38
|
+
}
|
|
39
|
+
const rgb = RGB.exec(text);
|
|
40
|
+
if (rgb) {
|
|
41
|
+
const [colour, alphaPart] = rgb[1].split("/");
|
|
42
|
+
const parts = colour.split(/[\s,]+/).filter(Boolean);
|
|
43
|
+
let alpha = _optionalChain([alphaPart, 'optionalAccess', _ => _.trim, 'call', _2 => _2()]);
|
|
44
|
+
if (parts.length === 4 && alpha === void 0) alpha = parts.pop();
|
|
45
|
+
if (parts.length !== 3) return null;
|
|
46
|
+
const channels = parts.map((p) => channel(p, 255));
|
|
47
|
+
const a = alpha === void 0 || alpha === "" ? 1 : channel(alpha, 1);
|
|
48
|
+
if (channels.some((c) => c === null) || a === null) return null;
|
|
49
|
+
return rgbaToHex(channels[0], channels[1], channels[2], a);
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
if (typeof input === "object" && input !== null) {
|
|
54
|
+
const obj = input;
|
|
55
|
+
if (Array.isArray(obj.components)) {
|
|
56
|
+
const space = obj.colorSpace;
|
|
57
|
+
if (space === void 0 || space === "srgb") {
|
|
58
|
+
const [r2, g2, b2] = obj.components;
|
|
59
|
+
const a2 = obj.alpha === void 0 ? 1 : obj.alpha;
|
|
60
|
+
if ([r2, g2, b2, a2].every((v) => typeof v === "number" && Number.isFinite(v))) {
|
|
61
|
+
return rgbaToHex(r2, g2, b2, a2);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (typeof obj.hex === "string") {
|
|
65
|
+
const base = normalizeTokenColor(obj.hex);
|
|
66
|
+
if (base === null) return null;
|
|
67
|
+
const a2 = typeof obj.alpha === "number" ? obj.alpha : 1;
|
|
68
|
+
const c = hexToRgba(base);
|
|
69
|
+
return rgbaToHex(c.r, c.g, c.b, a2);
|
|
70
|
+
}
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
const { r, g, b } = obj;
|
|
74
|
+
const a = obj.a === void 0 ? 1 : obj.a;
|
|
75
|
+
if ([r, g, b, a].every((v) => typeof v === "number" && Number.isFinite(v))) {
|
|
76
|
+
return rgbaToHex(r, g, b, a);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
exports.rgbaToHex = rgbaToHex; exports.hexToRgba = hexToRgba; exports.normalizeTokenColor = normalizeTokenColor;
|
|
87
|
+
//# sourceMappingURL=chunk-A6PHCAGX.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/editor/editor/packages/core/dist/chunk-A6PHCAGX.cjs","../src/tokens/color.ts"],"names":["g"],"mappings":"AAAA;ACQA,IAAM,IAAA,EAAM,uDAAA;AAEZ,IAAM,IAAA,EAAM,sBAAA;AAEZ,IAAM,QAAA,EAAU,CAAC,CAAA,EAAA,GAAc,IAAA,CAAK,GAAA,CAAI,CAAA,EAAG,IAAA,CAAK,GAAA,CAAI,CAAA,EAAG,CAAC,CAAC,CAAA;AACzD,IAAM,KAAA,EAAO,CAAC,CAAA,EAAA,GAAc,IAAA,CAAK,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cjs","sourcesContent":[null,"/**\n * Colour parsing for colour tokens. Colours are stored as lowercase hex: `#rrggbb`, or\n * `#rrggbbaa` when not opaque. Accepted input: `#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa`,\n * `rgb()` / `rgba()` (numbers or percentages, comma or space separated, `/ alpha`),\n * `transparent`, `black`, `white`, `{ r, g, b, a? }` with channels in 0–1 (Figma JSON) and\n * W3C colour objects (`{ colorSpace: 'srgb', components: [r, g, b], alpha?, hex? }`).\n */\n\nconst HEX = /^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;\n// Anchored with one character-class run: linear time.\nconst RGB = /^rgba?\\(([^()]*)\\)$/i;\n\nconst clamp01 = (v: number) => Math.min(1, Math.max(0, v));\nconst byte = (v: number) => Math.round(clamp01(v) * 255);\nconst hex2 = (n: number) => n.toString(16).padStart(2, '0');\n\n/** `#rrggbb` / `#rrggbbaa` from 0–1 channels. */\nexport function rgbaToHex(r: number, g: number, b: number, a = 1): string {\n\tconst head = `#${hex2(byte(r))}${hex2(byte(g))}${hex2(byte(b))}`;\n\tconst alpha = byte(a);\n\treturn alpha === 255 ? head : head + hex2(alpha);\n}\n\n/** 0–1 channels of a normalised hex colour. */\nexport function hexToRgba(hex: string): { r: number; g: number; b: number; a: number } | null {\n\tconst normal = normalizeTokenColor(hex);\n\tif (normal === null) return null;\n\tconst n = (i: number) => parseInt(normal.slice(i, i + 2), 16) / 255;\n\treturn { r: n(1), g: n(3), b: n(5), a: normal.length === 9 ? n(7) : 1 };\n}\n\nfunction channel(part: string, scale: number): number | null {\n\tconst pct = part.endsWith('%');\n\tconst n = Number(pct ? part.slice(0, -1) : part);\n\tif (!Number.isFinite(n)) return null;\n\treturn pct ? n / 100 : n / scale;\n}\n\n/** The colour as normalised hex, or `null` when it is not a colour this module reads. */\nexport function normalizeTokenColor(input: unknown): string | null {\n\tif (typeof input === 'string') {\n\t\tconst text = input.trim();\n\t\tif (text.length > 200) return null;\n\t\tconst lower = text.toLowerCase();\n\t\tif (lower === 'transparent') return '#00000000';\n\t\tif (lower === 'black') return '#000000';\n\t\tif (lower === 'white') return '#ffffff';\n\t\tconst hex = HEX.exec(text);\n\t\tif (hex) {\n\t\t\tlet digits = hex[1].toLowerCase();\n\t\t\tif (digits.length <= 4) digits = [...digits].map((c) => c + c).join('');\n\t\t\tif (digits.length === 8 && digits.endsWith('ff')) digits = digits.slice(0, 6);\n\t\t\treturn `#${digits}`;\n\t\t}\n\t\tconst rgb = RGB.exec(text);\n\t\tif (rgb) {\n\t\t\tconst [colour, alphaPart] = rgb[1].split('/');\n\t\t\tconst parts = colour.split(/[\\s,]+/).filter(Boolean);\n\t\t\tlet alpha: string | undefined = alphaPart?.trim();\n\t\t\tif (parts.length === 4 && alpha === undefined) alpha = parts.pop();\n\t\t\tif (parts.length !== 3) return null;\n\t\t\tconst channels = parts.map((p) => channel(p, 255));\n\t\t\tconst a = alpha === undefined || alpha === '' ? 1 : channel(alpha, 1);\n\t\t\tif (channels.some((c) => c === null) || a === null) return null;\n\t\t\treturn rgbaToHex(channels[0]!, channels[1]!, channels[2]!, a);\n\t\t}\n\t\treturn null;\n\t}\n\tif (typeof input === 'object' && input !== null) {\n\t\tconst obj = input as Record<string, unknown>;\n\t\tif (Array.isArray(obj.components)) {\n\t\t\tconst space = obj.colorSpace;\n\t\t\tif (space === undefined || space === 'srgb') {\n\t\t\t\tconst [r, g, b] = obj.components as unknown[];\n\t\t\t\tconst a = obj.alpha === undefined ? 1 : obj.alpha;\n\t\t\t\tif ([r, g, b, a].every((v) => typeof v === 'number' && Number.isFinite(v))) {\n\t\t\t\t\treturn rgbaToHex(r as number, g as number, b as number, a as number);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (typeof obj.hex === 'string') {\n\t\t\t\tconst base = normalizeTokenColor(obj.hex);\n\t\t\t\tif (base === null) return null;\n\t\t\t\tconst a = typeof obj.alpha === 'number' ? obj.alpha : 1;\n\t\t\t\tconst c = hexToRgba(base)!;\n\t\t\t\treturn rgbaToHex(c.r, c.g, c.b, a);\n\t\t\t}\n\t\t\treturn null;\n\t\t}\n\t\tconst { r, g, b } = obj;\n\t\tconst a = obj.a === undefined ? 1 : obj.a;\n\t\tif ([r, g, b, a].every((v) => typeof v === 'number' && Number.isFinite(v))) {\n\t\t\treturn rgbaToHex(r as number, g as number, b as number, a as number);\n\t\t}\n\t}\n\treturn null;\n}\n"]}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import {
|
|
2
|
+
hexToRgba,
|
|
3
|
+
normalizeTokenColor
|
|
4
|
+
} from "./chunk-TGD52FEZ.js";
|
|
5
|
+
|
|
1
6
|
// src/tokens/types.ts
|
|
2
7
|
var TOKEN_TYPES = ["color", "number", "string", "boolean"];
|
|
3
8
|
var TokenError = class extends Error {
|
|
@@ -13,87 +18,6 @@ function isTokenAlias(value) {
|
|
|
13
18
|
}
|
|
14
19
|
var EMPTY_TOKEN_STATE = Object.freeze({ collections: Object.freeze([]), variables: Object.freeze([]) });
|
|
15
20
|
|
|
16
|
-
// src/tokens/color.ts
|
|
17
|
-
var HEX = /^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
|
|
18
|
-
var RGB = /^rgba?\(([^()]*)\)$/i;
|
|
19
|
-
var clamp01 = (v) => Math.min(1, Math.max(0, v));
|
|
20
|
-
var byte = (v) => Math.round(clamp01(v) * 255);
|
|
21
|
-
var hex2 = (n) => n.toString(16).padStart(2, "0");
|
|
22
|
-
function rgbaToHex(r, g, b, a = 1) {
|
|
23
|
-
const head = `#${hex2(byte(r))}${hex2(byte(g))}${hex2(byte(b))}`;
|
|
24
|
-
const alpha = byte(a);
|
|
25
|
-
return alpha === 255 ? head : head + hex2(alpha);
|
|
26
|
-
}
|
|
27
|
-
function hexToRgba(hex) {
|
|
28
|
-
const normal = normalizeTokenColor(hex);
|
|
29
|
-
if (normal === null) return null;
|
|
30
|
-
const n = (i) => parseInt(normal.slice(i, i + 2), 16) / 255;
|
|
31
|
-
return { r: n(1), g: n(3), b: n(5), a: normal.length === 9 ? n(7) : 1 };
|
|
32
|
-
}
|
|
33
|
-
function channel(part, scale) {
|
|
34
|
-
const pct = part.endsWith("%");
|
|
35
|
-
const n = Number(pct ? part.slice(0, -1) : part);
|
|
36
|
-
if (!Number.isFinite(n)) return null;
|
|
37
|
-
return pct ? n / 100 : n / scale;
|
|
38
|
-
}
|
|
39
|
-
function normalizeTokenColor(input) {
|
|
40
|
-
if (typeof input === "string") {
|
|
41
|
-
const text = input.trim();
|
|
42
|
-
if (text.length > 200) return null;
|
|
43
|
-
const lower = text.toLowerCase();
|
|
44
|
-
if (lower === "transparent") return "#00000000";
|
|
45
|
-
if (lower === "black") return "#000000";
|
|
46
|
-
if (lower === "white") return "#ffffff";
|
|
47
|
-
const hex = HEX.exec(text);
|
|
48
|
-
if (hex) {
|
|
49
|
-
let digits = hex[1].toLowerCase();
|
|
50
|
-
if (digits.length <= 4) digits = [...digits].map((c) => c + c).join("");
|
|
51
|
-
if (digits.length === 8 && digits.endsWith("ff")) digits = digits.slice(0, 6);
|
|
52
|
-
return `#${digits}`;
|
|
53
|
-
}
|
|
54
|
-
const rgb = RGB.exec(text);
|
|
55
|
-
if (rgb) {
|
|
56
|
-
const [colour, alphaPart] = rgb[1].split("/");
|
|
57
|
-
const parts = colour.split(/[\s,]+/).filter(Boolean);
|
|
58
|
-
let alpha = alphaPart?.trim();
|
|
59
|
-
if (parts.length === 4 && alpha === void 0) alpha = parts.pop();
|
|
60
|
-
if (parts.length !== 3) return null;
|
|
61
|
-
const channels = parts.map((p) => channel(p, 255));
|
|
62
|
-
const a = alpha === void 0 || alpha === "" ? 1 : channel(alpha, 1);
|
|
63
|
-
if (channels.some((c) => c === null) || a === null) return null;
|
|
64
|
-
return rgbaToHex(channels[0], channels[1], channels[2], a);
|
|
65
|
-
}
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
if (typeof input === "object" && input !== null) {
|
|
69
|
-
const obj = input;
|
|
70
|
-
if (Array.isArray(obj.components)) {
|
|
71
|
-
const space = obj.colorSpace;
|
|
72
|
-
if (space === void 0 || space === "srgb") {
|
|
73
|
-
const [r2, g2, b2] = obj.components;
|
|
74
|
-
const a2 = obj.alpha === void 0 ? 1 : obj.alpha;
|
|
75
|
-
if ([r2, g2, b2, a2].every((v) => typeof v === "number" && Number.isFinite(v))) {
|
|
76
|
-
return rgbaToHex(r2, g2, b2, a2);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
if (typeof obj.hex === "string") {
|
|
80
|
-
const base = normalizeTokenColor(obj.hex);
|
|
81
|
-
if (base === null) return null;
|
|
82
|
-
const a2 = typeof obj.alpha === "number" ? obj.alpha : 1;
|
|
83
|
-
const c = hexToRgba(base);
|
|
84
|
-
return rgbaToHex(c.r, c.g, c.b, a2);
|
|
85
|
-
}
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
const { r, g, b } = obj;
|
|
89
|
-
const a = obj.a === void 0 ? 1 : obj.a;
|
|
90
|
-
if ([r, g, b, a].every((v) => typeof v === "number" && Number.isFinite(v))) {
|
|
91
|
-
return rgbaToHex(r, g, b, a);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
return null;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
21
|
// src/tokens/model.ts
|
|
98
22
|
var indexes = /* @__PURE__ */ new WeakMap();
|
|
99
23
|
function indexOf(state) {
|
|
@@ -1351,9 +1275,6 @@ export {
|
|
|
1351
1275
|
TokenError,
|
|
1352
1276
|
isTokenAlias,
|
|
1353
1277
|
EMPTY_TOKEN_STATE,
|
|
1354
|
-
rgbaToHex,
|
|
1355
|
-
hexToRgba,
|
|
1356
|
-
normalizeTokenColor,
|
|
1357
1278
|
getTokenCollection,
|
|
1358
1279
|
getTokenVariable,
|
|
1359
1280
|
findTokenCollection,
|
|
@@ -1403,4 +1324,4 @@ export {
|
|
|
1403
1324
|
exportW3CTokensJson,
|
|
1404
1325
|
importW3CTokens
|
|
1405
1326
|
};
|
|
1406
|
-
//# sourceMappingURL=chunk-
|
|
1327
|
+
//# sourceMappingURL=chunk-D6AVOTSD.js.map
|