@datalking/begonia-table 0.3.0 → 0.3.7
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/dist/chunk-T3O7N3HW.js +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/dist/table-layout.d.ts +0 -9
- package/dist/table-layout.js +1 -1
- package/dist/table-text-space.d.ts +120 -0
- package/package.json +1 -1
- package/dist/chunk-AYAWI6IR.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as y}from"./chunk-VRAHV7NM.js";var G=" | ",V=1;function C(e){let n=e.length;for(;n>0&&e.charCodeAt(n-1)===32;)n-=1;return e.slice(0,n)}function S(e){return e.join(" | ")}function k(e){return S(e).length+1}function O(e){return e.map(n=>C(n).trim()).filter(n=>n.length>0).join(" | ")}function B(e,n=0){let t=[],l=0;for(let o=0;o<e.length;o+=1){let a=typeof e[o]=="string"?e[o]:"";o>0&&(l+=3);let c=C(a);t.push({textStart:l,textLength:a.length,addressableLength:c.length,text:a,addressableText:c}),l+=a.length}let r=S(e);return{from:n,to:n+r.length,text:r,paintText:O(e),cells:t}}function L(e){let n=[],t=0;for(let l of e)n.push(B(l,t)),t+=k(l);return{rows:n,length:n.length>0?n[n.length-1].to:0}}function z(e,n,t,l){let r=e.rows[n],o=r?.cells[t];return!r||!o?null:r.from+o.textStart+l}function H(e,n){for(let t=0;t<e.rows.length;t+=1){let l=e.rows[t];if(!(n<l.from||n>l.to)){for(let r=0;r<l.cells.length;r+=1){let o=l.cells[r],a=l.from+o.textStart;if(n>=a&&n<=a+o.addressableLength)return{rowIndex:t,cellIndex:r,cell:o,inCell:n-a}}return null}}return null}var q=10,J=0,f=4096;function b(e){try{if(!Array.isArray(e))return!1;let n=Number(e.length);if(!Number.isSafeInteger(n)||n<0||n>f)return!1;for(let t=0;t<n;t+=1)if(!Object.prototype.hasOwnProperty.call(e,t))return!1;return!0}catch{return!1}}function i(e,n=0){try{let t=Number(e);return Number.isFinite(t)?t:n}catch{return n}}function g(e,n){let t=i(e,n);return t<0?n:Math.min(f,Math.max(0,Math.round(t)))}function A(e){return Math.max(1,g(e,1))}function N(e){return e==="start"||e==="continue"?e:null}function K(e,n,t){return{text:e,blocks:null,inlineSpans:null,lineSlices:null,originRow:n,originColumn:t,rowSpan:1,colSpan:1,mergeKind:null}}function F(e,n){let t=i(e?.[n],-1);return Number.isInteger(t)&&t>=0?t:n}function P(e){return b(e)?e.length:0}function D(e,n){return Math.max(P(e),P(n))}function M(e){return`${e.originRow}:${e.originColumn}`}function X(e,n){return e.cells.some(t=>M(t)===n)}function W(e,n,t){let l=0;for(let r=n;r<e.length&&X(e[r],t);r+=1)l+=1;return Math.max(1,l)}function j(e){let{row:n=[],cellLayouts:t=[],fragmentRowIndex:l=0,sourceRowIndex:r=l}=e,o=n??[],a=t??[],c=[],s=0;for(let m=0;m<D(o,a);m+=1){let w=o[m]??"",u=a[m]??K(w,r,s),R=u.text??w,d=A(u.colSpan),T=g(u.originColumn,s),x=N(u.mergeKind),v=g(u.originRow,r),p=Math.min(r,v),_=x==="continue"?r-p+1:1,h=Math.max(_,A(u.rowSpan)),I={...u,text:R,originRow:p,originColumn:T,rowSpan:h,colSpan:d,mergeKind:x};c.push({text:R,layout:I,physicalIndex:m,fragmentRowIndex:l,sourceRowIndex:r,originRow:p,originColumn:T,rowSpan:h,colSpan:d,mergeKind:x}),s=Math.max(s,T+d)}return c}function E(e){let n=y(e),t=b(n?.rows)?n.rows:[],l=b(n?.cells)?n.cells:[];return Array.from({length:Math.max(t.length,l.length)},(r,o)=>{let a=F(n?.rowSourceIndexes,o),c=t[o]??[],s=l[o]??[];return{row:c,cellLayouts:s,fragmentRowIndex:o,sourceRowIndex:a,cells:j({row:c,cellLayouts:s,fragmentRowIndex:o,sourceRowIndex:a})}})}function Q(e,n,t){let l=Math.max(0,Math.min(Math.trunc(i(n,0)),Math.max(0,t)));return l<=0?0:Math.trunc(i(e.sourceRowIndex,0))<l?1:0}function Y(e){let n=E(e),t=new Set;return n.map((l,r)=>{let o=L([l.row]).rows[0];return{...l,cells:l.cells.flatMap(a=>{let c=M(a);return t.has(c)?[]:(t.add(c),[{...a,rowSpanInFragment:W(n,r,c),textStart:o.cells[a.physicalIndex]?.textStart??0}])})}})}function ee(e){let n=e.table?.columnWidths,t=b(n)?n.length:0;for(let l of E(e))for(let r of l.cells)t=Math.max(t,r.originColumn+r.colSpan);return Math.min(f,Math.max(t,1))}function ne(e,n){let t=Math.max(0,n.originColumn),l=Math.max(t+1,t+Math.max(1,n.colSpan)),r=b(e)?e.slice(t,l).reduce((a,c)=>a+Math.max(0,i(c)),0):0;return r>0?r:Math.max(0,i(e[e.length-1]))*Math.max(1,n.colSpan)}export{G as a,V as b,C as c,S as d,k as e,O as f,B as g,L as h,z as i,H as j,q as k,J as l,N as m,j as n,E as o,Q as p,Y as q,ee as r,ne as s};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './table-primitives.ts';
|
|
2
2
|
export * from './table-cell-text-segment.ts';
|
|
3
3
|
export * from './table-layout.ts';
|
|
4
|
+
export * from './table-text-space.ts';
|
|
4
5
|
export * from './table-block-metrics.ts';
|
|
5
6
|
export * from './table-cell-blocks.ts';
|
|
6
7
|
export * from './table-cell-margins.ts';
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as l,b,c as h,d as M,e as c,f as d,g as s,h as g,i as w,j as N}from"./chunk-
|
|
1
|
+
import{a as l,b,c as h,d as M,e as c,f as d,g as s,h as g,i as w,j as N,k,l as v,m as y,n as B,o as C,p as F,q as T,r as j,s as q}from"./chunk-T3O7N3HW.js";import{a as u}from"./chunk-VRAHV7NM.js";import{a as E,b as G}from"./chunk-DODR4QN4.js";import{a as z}from"./chunk-N2TXWMCR.js";import"./chunk-RVGFFYBA.js";import"./chunk-36EAGHXY.js";import"./chunk-2OAH5RMT.js";import{a as A,b as D}from"./chunk-4VNOCJ4Y.js";function H(e,t,x,a,p){let o=Math.max(0,Math.min(t,e.length)),i=Math.max(o,Math.min(o+Math.max(1,x),e.length)),m=0;for(let r=0;r<o;r+=1)m+=f(e[r]);let n=0;for(let r=o;r<i;r+=1)n+=f(e[r]);return p?{left:Math.max(0,a-m-n),width:n}:{left:m,width:n}}function f(e){let t=Number(e);return Number.isFinite(t)&&t>0?t:0}export{k as TABLE_CELL_HORIZONTAL_PADDING,l as TABLE_CELL_TEXT_SEPARATOR,v as TABLE_CELL_VERTICAL_PADDING,b as TABLE_ROW_TEXT_ADVANCE,y as normalizeMergeKind,A as normalizeTableCellVerticalAlign,u as resolveLayoutTableBlockMetrics,T as resolveRenderableTableRows,E as resolveTableCellAnchorOffsetX,G as resolveTableCellAnchorOffsetY,N as resolveTableCellAtTextOffset,q as resolveTableCellColumnWidth,w as resolveTableCellTextOffset,D as resolveTableCellVerticalOffset,H as resolveTableColumnBox,C as resolveTableFragmentRows,F as resolveTableHeaderStyleRowCount,j as resolveTableLogicalColumnCount,c as resolveTableRowAdvance,B as resolveTableRowCells,d as resolveTableRowPaintText,M as resolveTableRowText,s as resolveTableRowTextSpace,g as resolveTableTextSpace,z as sliceTableCellBlocksByOffsets,h as trimTableCellAddressableText};
|
package/dist/table-layout.d.ts
CHANGED
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
import { type LayoutTableBlockMetrics } from './table-block-metrics.ts';
|
|
2
2
|
import type { TableCellMergeKind, TableCellPlacement } from './table-cell-placement.ts';
|
|
3
|
-
/**
|
|
4
|
-
* Separator inserted between non-empty cell texts when a table row is flattened
|
|
5
|
-
* into one text run.
|
|
6
|
-
*
|
|
7
|
-
* The renderer paints each cell in its own column, but the layout addresses the
|
|
8
|
-
* row as a single string. Both the projection and any DOM-first hit resolution
|
|
9
|
-
* must agree on this one value or a click lands a few characters off.
|
|
10
|
-
*/
|
|
11
|
-
export declare const TABLE_CELL_TEXT_SEPARATOR = " | ";
|
|
12
3
|
/**
|
|
13
4
|
* Space between a cell's border and its text, on one horizontal side.
|
|
14
5
|
*
|
package/dist/table-layout.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a,b,c,d,e,f,g,h,i
|
|
1
|
+
import{k as a,l as b,m as c,n as d,o as e,p as f,q as g,r as h,s as i}from"./chunk-T3O7N3HW.js";import"./chunk-VRAHV7NM.js";export{a as TABLE_CELL_HORIZONTAL_PADDING,b as TABLE_CELL_VERTICAL_PADDING,c as normalizeMergeKind,g as resolveRenderableTableRows,i as resolveTableCellColumnWidth,e as resolveTableFragmentRows,f as resolveTableHeaderStyleRowCount,h as resolveTableLogicalColumnCount,d as resolveTableRowCells};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one definition of the text space a laid-out table row is addressed in.
|
|
3
|
+
*
|
|
4
|
+
* A table is projected as a single block. Its rows are flattened into one
|
|
5
|
+
* character string per row - every cell's painted text, joined by
|
|
6
|
+
* {@link TABLE_CELL_TEXT_SEPARATOR} - and the rows themselves are stacked one
|
|
7
|
+
* character apart ({@link TABLE_ROW_TEXT_ADVANCE}). That string is what the
|
|
8
|
+
* renderer annotates (\`data-begonia-cell-text-start\`), what the caret geometry
|
|
9
|
+
* measures, what the row slicer reports, and what the document-to-projection
|
|
10
|
+
* mapping recomputes from the model.
|
|
11
|
+
*
|
|
12
|
+
* Every one of those call sites used to carry its own copy of the arithmetic:
|
|
13
|
+
* \`row.join(' | ').length + 1\` in one module, a running cursor over
|
|
14
|
+
* \`cellText.length\` plus \`' | '.length\` in another, a trimmed variant in a
|
|
15
|
+
* third. They agreed only as long as nobody edited one of them, and the
|
|
16
|
+
* disagreement showed up as a caret painted one character off. This module is
|
|
17
|
+
* the only place allowed to decide:
|
|
18
|
+
*
|
|
19
|
+
* - the cell separator and its length,
|
|
20
|
+
* - the advance between rows,
|
|
21
|
+
* - how a cell's painted text becomes a cell span inside the row,
|
|
22
|
+
* - which characters are addressable (trailing plain spaces are painted but
|
|
23
|
+
* not addressable; a tab or a line break at the end still is),
|
|
24
|
+
* - what the row's measured \"paint text\" is (see
|
|
25
|
+
* {@link TableTextSpaceRow.paintText}).
|
|
26
|
+
*
|
|
27
|
+
* It is deliberately pure and dependency-free so every layer - the table
|
|
28
|
+
* contract, the paginator, the projection geometry and the browser SDK - can
|
|
29
|
+
* share it instead of re-deriving offsets.
|
|
30
|
+
*/
|
|
31
|
+
/** Separator the layout paints between two cells of the same row. */
|
|
32
|
+
export declare const TABLE_CELL_TEXT_SEPARATOR = " | ";
|
|
33
|
+
/**
|
|
34
|
+
* Characters the layout spends past a row before the next row starts.
|
|
35
|
+
*
|
|
36
|
+
* One, because a row is addressed as one line: the next row's first character
|
|
37
|
+
* sits one past the previous row's last addressable offset. It is not painted,
|
|
38
|
+
* so it belongs to no cell.
|
|
39
|
+
*/
|
|
40
|
+
export declare const TABLE_ROW_TEXT_ADVANCE = 1;
|
|
41
|
+
/** A cell span inside a row's flattened text. */
|
|
42
|
+
export interface TableTextSpaceCell {
|
|
43
|
+
/** Offset of the cell's first painted character, relative to the row. */
|
|
44
|
+
readonly textStart: number;
|
|
45
|
+
/** Painted characters the cell occupies, trailing spaces included. */
|
|
46
|
+
readonly textLength: number;
|
|
47
|
+
/**
|
|
48
|
+
* Characters a caret may address.
|
|
49
|
+
*
|
|
50
|
+
* Trailing plain spaces paint nothing at the end of a cell, so the boundary
|
|
51
|
+
* past them is not reachable; a trailing tab or hard break opens its own
|
|
52
|
+
* caret slot and stays addressable. Everything before the first trailing
|
|
53
|
+
* plain space is addressable either way.
|
|
54
|
+
*/
|
|
55
|
+
readonly addressableLength: number;
|
|
56
|
+
/** The cell's painted text, exactly as the layout joins it. */
|
|
57
|
+
readonly text: string;
|
|
58
|
+
/** {@link addressableLength} characters of {@link text}. */
|
|
59
|
+
readonly addressableText: string;
|
|
60
|
+
}
|
|
61
|
+
/** A row inside the table's flattened text. */
|
|
62
|
+
export interface TableTextSpaceRow {
|
|
63
|
+
/** Offset of the row's first character, relative to the table's text. */
|
|
64
|
+
readonly from: number;
|
|
65
|
+
/** One past the row's last character. The row advance follows it. */
|
|
66
|
+
readonly to: number;
|
|
67
|
+
/** The row's offset string: every cell, joined by the separator. */
|
|
68
|
+
readonly text: string;
|
|
69
|
+
/**
|
|
70
|
+
* The string the measured line geometry uses for this row.
|
|
71
|
+
*
|
|
72
|
+
* Deliberately NOT the offset string: empty cells paint no glyphs, so a
|
|
73
|
+
* measured row is the non-empty trimmed cells joined by the separator. It can
|
|
74
|
+
* therefore be shorter than \`to - from\`, and a measured line's text may cover
|
|
75
|
+
* fewer characters than its offset range. That is an approximation of the
|
|
76
|
+
* measurement, not of the offsets - offsets always come from {@link from},
|
|
77
|
+
* {@link to} and the cell spans below.
|
|
78
|
+
*/
|
|
79
|
+
readonly paintText: string;
|
|
80
|
+
readonly cells: readonly TableTextSpaceCell[];
|
|
81
|
+
}
|
|
82
|
+
/** A whole table's flattened text, row by row. */
|
|
83
|
+
export interface TableTextSpace {
|
|
84
|
+
readonly rows: readonly TableTextSpaceRow[];
|
|
85
|
+
/** One past the last row's end. */
|
|
86
|
+
readonly length: number;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* A cell's addressable text: trailing plain spaces removed.
|
|
90
|
+
*
|
|
91
|
+
* Only U+0020 is dropped. A trailing tab still advances the line and a trailing
|
|
92
|
+
* hard break still opens an empty one, so both keep their caret slot; trimming
|
|
93
|
+
* them made the last position of such a cell unreachable.
|
|
94
|
+
*/
|
|
95
|
+
export declare function trimTableCellAddressableText(text: string): string;
|
|
96
|
+
/** The offset string of one row: every cell joined by the separator. */
|
|
97
|
+
export declare function resolveTableRowText(row: readonly string[]): string;
|
|
98
|
+
/** The row's flattened length plus the advance the layout spends past it. */
|
|
99
|
+
export declare function resolveTableRowAdvance(row: readonly string[]): number;
|
|
100
|
+
/** The row's measured string: non-empty trimmed cells joined by the separator. */
|
|
101
|
+
export declare function resolveTableRowPaintText(row: readonly string[]): string;
|
|
102
|
+
/** One row's cell spans, starting at \`from\` in the table's text. */
|
|
103
|
+
export declare function resolveTableRowTextSpace(row: readonly string[], from?: number): TableTextSpaceRow;
|
|
104
|
+
/** Every row's cell spans, numbered the way the layout numbers them. */
|
|
105
|
+
export declare function resolveTableTextSpace(rows: readonly (readonly string[])[]): TableTextSpace;
|
|
106
|
+
/**
|
|
107
|
+
* The table offset of a cell-relative character boundary.
|
|
108
|
+
*
|
|
109
|
+
* \`inCellOffset\` may exceed the cell's addressable length: a boundary past the
|
|
110
|
+
* last glyph still has a place in the row, and callers that want to reject it
|
|
111
|
+
* compare against {@link TableTextSpaceCell.addressableLength} first.
|
|
112
|
+
*/
|
|
113
|
+
export declare function resolveTableCellTextOffset(space: TableTextSpace, rowIndex: number, cellIndex: number, inCellOffset: number): number | null;
|
|
114
|
+
/** The cell that owns a table offset, or null for a separator or a gap. */
|
|
115
|
+
export declare function resolveTableCellAtTextOffset(space: TableTextSpace, offset: number): {
|
|
116
|
+
rowIndex: number;
|
|
117
|
+
cellIndex: number;
|
|
118
|
+
cell: TableTextSpaceCell;
|
|
119
|
+
inCell: number;
|
|
120
|
+
} | null;
|
package/package.json
CHANGED
package/dist/chunk-AYAWI6IR.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as C}from"./chunk-VRAHV7NM.js";var v=" | ",D=10,G=0,R=4096;function b(e){try{if(!Array.isArray(e))return!1;let n=Number(e.length);if(!Number.isSafeInteger(n)||n<0||n>R)return!1;for(let t=0;t<n;t+=1)if(!Object.prototype.hasOwnProperty.call(e,t))return!1;return!0}catch{return!1}}function m(e,n=0){try{let t=Number(e);return Number.isFinite(t)?t:n}catch{return n}}function x(e,n){let t=m(e,n);return t<0?n:Math.min(R,Math.max(0,Math.round(t)))}function y(e){return Math.max(1,x(e,1))}function A(e){return e==="start"||e==="continue"?e:null}function _(e,n,t){return{text:e,blocks:null,inlineSpans:null,lineSlices:null,originRow:n,originColumn:t,rowSpan:1,colSpan:1,mergeKind:null}}function E(e,n){let t=m(e?.[n],-1);return Number.isInteger(t)&&t>=0?t:n}function L(e){return b(e)?e.length:0}function N(e,n){return Math.max(L(e),L(n))}function M(e){return`${e.originRow}:${e.originColumn}`}function K(e,n){return e.cells.some(t=>M(t)===n)}function F(e,n,t){let l=0;for(let o=n;o<e.length&&K(e[o],t);o+=1)l+=1;return Math.max(1,l)}function O(e){let{row:n=[],cellLayouts:t=[],fragmentRowIndex:l=0,sourceRowIndex:o=l}=e,a=n??[],u=t??[],c=[],r=0;for(let s=0;s<N(a,u);s+=1){let p=a[s]??"",i=u[s]??_(p,o,r),T=i.text??p,d=y(i.colSpan),w=x(i.originColumn,r),f=A(i.mergeKind),S=x(i.originRow,o),g=Math.min(o,S),I=f==="continue"?o-g+1:1,h=Math.max(I,y(i.rowSpan)),k={...i,text:T,originRow:g,originColumn:w,rowSpan:h,colSpan:d,mergeKind:f};c.push({text:T,layout:k,physicalIndex:s,fragmentRowIndex:l,sourceRowIndex:o,originRow:g,originColumn:w,rowSpan:h,colSpan:d,mergeKind:f}),r=Math.max(r,w+d)}return c}function P(e){let n=C(e),t=b(n?.rows)?n.rows:[],l=b(n?.cells)?n.cells:[];return Array.from({length:Math.max(t.length,l.length)},(o,a)=>{let u=E(n?.rowSourceIndexes,a),c=t[a]??[],r=l[a]??[];return{row:c,cellLayouts:r,fragmentRowIndex:a,sourceRowIndex:u,cells:O({row:c,cellLayouts:r,fragmentRowIndex:a,sourceRowIndex:u})}})}function W(e,n,t){let l=Math.max(0,Math.min(Math.trunc(m(n,0)),Math.max(0,t)));return l<=0?0:Math.trunc(m(e.sourceRowIndex,0))<l?1:0}function z(e){let n=P(e),t=new Set;return n.map((l,o)=>{let a=l.row,u=[],c=0;for(let r=0;r<a.length;r+=1){u[r]=c;let s=typeof a[r]=="string"?a[r]:"";c+=s.length,r<a.length-1&&(c+=v.length)}return{...l,cells:l.cells.flatMap(r=>{let s=M(r);return t.has(s)?[]:(t.add(s),[{...r,rowSpanInFragment:F(n,o,s),textStart:u[r.physicalIndex]??0}])})}})}function H(e){let n=e.table?.columnWidths,t=b(n)?n.length:0;for(let l of P(e))for(let o of l.cells)t=Math.max(t,o.originColumn+o.colSpan);return Math.min(R,Math.max(t,1))}function X(e,n){let t=Math.max(0,n.originColumn),l=Math.max(t+1,t+Math.max(1,n.colSpan)),o=b(e)?e.slice(t,l).reduce((u,c)=>u+Math.max(0,m(c)),0):0;return o>0?o:Math.max(0,m(e[e.length-1]))*Math.max(1,n.colSpan)}export{v as a,D as b,G as c,A as d,O as e,P as f,W as g,z as h,H as i,X as j};
|