quill-table-up 3.3.1 → 3.4.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 CHANGED
@@ -69,7 +69,7 @@ const quill = new Quill('#editor', {
69
69
  | ------------- | --------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- | ------------------------------------------ |
70
70
  | full | if set `true`. width max will be 100% | `boolean` | `false` |
71
71
  | fullSwitch | enable to choose insert a full width table | `boolean` | `true` |
72
- | texts | the text used to create the table | `TableTextOptions` | `defaultTexts` |
72
+ | texts | the text used to create the table | `TableTextOptions \| ((key: string) => string)` | `defaultTexts` |
73
73
  | customSelect | display a custom select to custom row and column number add a table. module provides default selector `defaultCustomSelect` | `(tableModule: TableUp, picker: Picker) => Promise<HTMLElement> \| HTMLElement` | - |
74
74
  | customBtn | display a custom button to custom row and column number add a table. it only when use `defaultCustomSelect` will effect | `boolean` | `false` |
75
75
  | icon | picker svg icon string. it will set with `innerHTML` | `string` | `origin table icon` |
@@ -116,6 +116,48 @@ const defaultTexts = {
116
116
 
117
117
  </details>
118
118
 
119
+ ### `texts` Dynamic Usage
120
+
121
+ You can pass `texts` as a function.\
122
+ When internal UI reads a text, it will call `texts(key)` and use the returned string.
123
+
124
+ ```ts
125
+ let locale: 'en' | 'zh' = 'en';
126
+
127
+ const textMap = {
128
+ en: {
129
+ customBtnText: 'Custom',
130
+ confirmText: 'Confirm',
131
+ cancelText: 'Cancel',
132
+ },
133
+ zh: {
134
+ customBtnText: '自定义',
135
+ confirmText: '确认',
136
+ cancelText: '取消',
137
+ },
138
+ } as const;
139
+
140
+ const quill = new Quill('#editor', {
141
+ modules: {
142
+ [TableUp.moduleName]: {
143
+ customSelect: defaultCustomSelect,
144
+ customBtn: true,
145
+ texts: key => textMap[locale][key as keyof typeof textMap.en] || '',
146
+ modules: [
147
+ { module: TableSelection },
148
+ { module: TableMenuContextmenu },
149
+ ],
150
+ },
151
+ },
152
+ });
153
+
154
+ // switch language
155
+ locale = 'zh';
156
+ await quill.getModule(TableUp.moduleName).refreshUI();
157
+ ```
158
+
159
+ `refreshUI()` will rebuild table-up UI and read latest text values.
160
+
119
161
  ## Export Internal Module
120
162
 
121
163
  ### TableSelection
package/dist/index.d.ts CHANGED
@@ -983,6 +983,7 @@ interface TableTextOptions extends TableCreatorTextOptions, TableMenuTexts {
983
983
  transparent: string;
984
984
  perWidthInsufficient: string;
985
985
  }
986
+ type TableTextOptionsInput = Partial<TableTextOptions> | ((this: TableUp, key: string) => string);
986
987
  interface TableUpExtraModule extends Constructor<any, [TableUp, Quill, any]> {
987
988
  moduleName: string;
988
989
  }
@@ -1000,6 +1001,9 @@ interface TableUpOptions {
1000
1001
  autoMergeCell: boolean;
1001
1002
  modules: TableUpModule[];
1002
1003
  }
1004
+ interface TableUpOptionsInput extends Partial<Omit<TableUpOptions, 'texts'>> {
1005
+ texts?: TableTextOptionsInput;
1006
+ }
1003
1007
  interface TableColValue {
1004
1008
  tableId: string;
1005
1009
  colId: string;
@@ -1110,7 +1114,7 @@ interface TableSelectOptions {
1110
1114
  customBtn: boolean;
1111
1115
  texts: Partial<TableCreatorTextOptions>;
1112
1116
  }
1113
- declare function createSelectBox(options?: Partial<TableSelectOptions>): HTMLDivElement;
1117
+ declare function createSelectBox(options?: Partial<TableSelectOptions>): HTMLSpanElement;
1114
1118
  //#endregion
1115
1119
  //#region src/utils/components/tooltip.d.ts
1116
1120
  interface ToolTipOptions {
@@ -1172,7 +1176,7 @@ declare const randomId: () => string;
1172
1176
  //#endregion
1173
1177
  //#region src/table-up.d.ts
1174
1178
  declare function updateTableConstants(data: Partial<TableConstantsData>): void;
1175
- declare function defaultCustomSelect(tableModule: TableUp, picker: QuillThemePicker): HTMLDivElement;
1179
+ declare function defaultCustomSelect(tableModule: TableUp, picker: QuillThemePicker): HTMLSpanElement;
1176
1180
  declare class TableUp {
1177
1181
  static moduleName: string;
1178
1182
  static toolName: string;
@@ -1225,6 +1229,7 @@ declare class TableUp {
1225
1229
  static register(): void;
1226
1230
  quill: Quill;
1227
1231
  options: TableUpOptions;
1232
+ textOptionsInput: TableTextOptionsInput | undefined;
1228
1233
  toolBox: HTMLDivElement;
1229
1234
  fixTableByLisenter: (this: any) => void;
1230
1235
  selector?: HTMLElement;
@@ -1232,36 +1237,13 @@ declare class TableUp {
1232
1237
  editableObserver: MutationObserver;
1233
1238
  modules: Record<string, Constructor>;
1234
1239
  get statics(): any;
1235
- constructor(quill: Quill, options: Partial<TableUpOptions>);
1240
+ constructor(quill: Quill, options: TableUpOptionsInput);
1236
1241
  initialContainer(): HTMLDivElement;
1237
1242
  addContainer(classes: string | HTMLElement): HTMLElement;
1238
- resolveOptions(options: Partial<TableUpOptions>): TableUpOptions;
1239
- resolveTexts(options: Partial<TableTextOptions>): {
1240
- fullCheckboxText: string;
1241
- customBtnText: string;
1242
- confirmText: string;
1243
- cancelText: string;
1244
- rowText: string;
1245
- colText: string;
1246
- notPositiveNumberError: string;
1247
- custom: string;
1248
- clear: string;
1249
- transparent: string;
1250
- perWidthInsufficient: string;
1251
- CopyCell: string;
1252
- CutCell: string;
1253
- InsertTop: string;
1254
- InsertRight: string;
1255
- InsertBottom: string;
1256
- InsertLeft: string;
1257
- MergeCell: string;
1258
- SplitCell: string;
1259
- DeleteRow: string;
1260
- DeleteColumn: string;
1261
- DeleteTable: string;
1262
- BackgroundColor: string;
1263
- BorderColor: string;
1264
- } & Partial<TableTextOptions>;
1243
+ getToolbarPicker(): QuillThemePicker | undefined;
1244
+ resolveOptions(options: TableUpOptionsInput): TableUpOptions;
1245
+ resolveTexts(options?: TableTextOptionsInput): TableTextOptions;
1246
+ refreshUI(): Promise<void>;
1265
1247
  initModules(): void;
1266
1248
  listenEditableChange(): void;
1267
1249
  destroyModules(): void;
@@ -1290,5 +1272,5 @@ declare class TableUp {
1290
1272
  convertTableBodyByCells(tableBlot: TableMainFormat, selecteds: TableCellInnerFormat[], tag: TableBodyTag): void;
1291
1273
  }
1292
1274
  //#endregion
1293
- export { BlockEmbedOverride, BlockOverride, ClipboardOptions, Constructor, ContainerFormat, InternalModule, InternalTableMenuModule, InternalTableSelectionModule, Matcher, MenuTooltipInstance, Position, QuillTheme, QuillThemePicker, RelactiveRect, ScrollOverride, Scrollbar, SelectionData, Selector, SkipRowCount, TableAlign, TableBodyFormat, TableBodyTag, TableCaptionFormat, TableCaptionValue, TableCellFormat, TableCellInnerFormat, TableCellValue, TableClipboard, TableColFormat, TableColValue, TableColgroupFormat, TableConstantsData, TableCreatorTextOptions, TableDomSelector, TableFootFormat, TableHeadFormat, TableMainFormat, TableMenuCommon, TableMenuContextmenu, TableMenuOptions, TableMenuOptionsInput, TableMenuSelect, TableMenuTexts, TableModuleLifecycle, TableResizeBox, TableResizeBoxOptions, TableResizeCommon, TableResizeCommonHelper, TableResizeLine, TableResizeScale, TableResizeScaleOptions, TableRowFormat, TableRowValue, TableSelection, TableSelectionOptions, TableTextOptions, TableUp, TableUp as default, TableUpExtraModule, TableUpModule, TableUpOptions, TableValue, TableVirtualScrollbar, TableWrapperFormat, Tool, ToolOption, ToolOptionBreak, Writable, applyCellUpdates, blotName, createColorPicker, createSelectBox, createTooltip, defaultCustomSelect, findParentBlot, findParentBlots, getCellPositions, getColRect, getCountByPosition, getTableCellStructure, getTableMainRect, groupCellByRow, isCellsSpan, isTableAlignRight, parsePasteDelta, pasteCells, pasteWithLoop, pasteWithStructure, prepareCellUpdate, randomId, removeOverlappingCells, tableMenuTools, tableUpEvent, tableUpInternal, tableUpSize, updateTableConstants };
1275
+ export { BlockEmbedOverride, BlockOverride, ClipboardOptions, Constructor, ContainerFormat, InternalModule, InternalTableMenuModule, InternalTableSelectionModule, Matcher, MenuTooltipInstance, Position, QuillTheme, QuillThemePicker, RelactiveRect, ScrollOverride, Scrollbar, SelectionData, Selector, SkipRowCount, TableAlign, TableBodyFormat, TableBodyTag, TableCaptionFormat, TableCaptionValue, TableCellFormat, TableCellInnerFormat, TableCellValue, TableClipboard, TableColFormat, TableColValue, TableColgroupFormat, TableConstantsData, TableCreatorTextOptions, TableDomSelector, TableFootFormat, TableHeadFormat, TableMainFormat, TableMenuCommon, TableMenuContextmenu, TableMenuOptions, TableMenuOptionsInput, TableMenuSelect, TableMenuTexts, TableModuleLifecycle, TableResizeBox, TableResizeBoxOptions, TableResizeCommon, TableResizeCommonHelper, TableResizeLine, TableResizeScale, TableResizeScaleOptions, TableRowFormat, TableRowValue, TableSelection, TableSelectionOptions, TableTextOptions, TableTextOptionsInput, TableUp, TableUp as default, TableUpExtraModule, TableUpModule, TableUpOptions, TableUpOptionsInput, TableValue, TableVirtualScrollbar, TableWrapperFormat, Tool, ToolOption, ToolOptionBreak, Writable, applyCellUpdates, blotName, createColorPicker, createSelectBox, createTooltip, defaultCustomSelect, findParentBlot, findParentBlots, getCellPositions, getColRect, getCountByPosition, getTableCellStructure, getTableMainRect, groupCellByRow, isCellsSpan, isTableAlignRight, parsePasteDelta, pasteCells, pasteWithLoop, pasteWithStructure, prepareCellUpdate, randomId, removeOverlappingCells, tableMenuTools, tableUpEvent, tableUpInternal, tableUpSize, updateTableConstants };
1294
1276
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import e from"quill";const t={container:`table-up-container`,tableCaption:`table-up-caption`,tableWrapper:`table-up`,tableMain:`table-up-main`,tableColgroup:`table-up-colgroup`,tableCol:`table-up-col`,tableHead:`table-up-head`,tableBody:`table-up-body`,tableFoot:`table-up-foot`,tableRow:`table-up-row`,tableCell:`table-up-cell`,tableCellInner:`table-up-cell-inner`},n={colMinWidthPre:5,colMinWidthPx:40,colDefaultWidth:100,rowMinHeightPx:36},r={AFTER_TABLE_RESIZE:`after-table-resize`,TABLE_SELECTION_DRAG_START:`table-selection-drag-start`,TABLE_SELECTION_DRAG_END:`table-selection-drag-end`,TABLE_SELECTION_CHANGE:`table-selection-change`,TABLE_SELECTION_DISPLAY_CHANGE:`table-selection-display-change`},i={moduleName:`table-up`,tableSelectionName:`table-selection`},a=[[`rgb(255, 255, 255)`,`rgb(0, 0, 0)`,`rgb(72, 83, 104)`,`rgb(41, 114, 244)`,`rgb(0, 163, 245)`,`rgb(49, 155, 98)`,`rgb(222, 60, 54)`,`rgb(248, 136, 37)`,`rgb(245, 196, 0)`,`rgb(153, 56, 215)`],[`rgb(242, 242, 242)`,`rgb(127, 127, 127)`,`rgb(243, 245, 247)`,`rgb(229, 239, 255)`,`rgb(229, 246, 255)`,`rgb(234, 250, 241)`,`rgb(254, 233, 232)`,`rgb(254, 243, 235)`,`rgb(254, 249, 227)`,`rgb(253, 235, 255)`],[`rgb(216, 216, 216)`,`rgb(89, 89, 89)`,`rgb(197, 202, 211)`,`rgb(199, 220, 255)`,`rgb(199, 236, 255)`,`rgb(195, 234, 213)`,`rgb(255, 201, 199)`,`rgb(255, 220, 196)`,`rgb(255, 238, 173)`,`rgb(242, 199, 255)`],[`rgb(191, 191, 191)`,`rgb(63, 63, 63)`,`rgb(128, 139, 158)`,`rgb(153, 190, 255)`,`rgb(153, 221, 255)`,`rgb(152, 215, 182)`,`rgb(255, 156, 153)`,`rgb(255, 186, 132)`,`rgb(255, 226, 112)`,`rgb(213, 142, 255)`],[`rgb(165, 165, 165)`,`rgb(38, 38, 38)`,`rgb(53, 59, 69)`,`rgb(20, 80, 184)`,`rgb(18, 116, 165)`,`rgb(39, 124, 79)`,`rgb(158, 30, 26)`,`rgb(184, 96, 20)`,`rgb(163, 130, 0)`,`rgb(94, 34, 129)`],[`rgb(147, 147, 147)`,`rgb(13, 13, 13)`,`rgb(36, 39, 46)`,`rgb(12, 48, 110)`,`rgb(10, 65, 92)`,`rgb(24, 78, 50)`,`rgb(88, 17, 14)`,`rgb(92, 48, 10)`,`rgb(102, 82, 0)`,`rgb(59, 21, 81)`]],o=new Set([t.tableCellInner]),s=e=>o.has(e.statics.blotName);function c(e){return e?.parent?s(e.parent)?!0:c(e.parent):!1}function l(e,t=`table-up`){let n=t?`${t}-`:``;return{b:()=>`${n}${e}`,be:t=>t?`${n}${e}__${t}`:``,bm:t=>t?`${n}${e}--${t}`:``,bem:(t,r)=>t&&r?`${n}${e}__${t}--${r}`:``,ns:e=>e?`${n}${e}`:``,bs:t=>t?`${n}${e}-${t}`:``,cv:e=>e?`--${n}${e}`:``,is:e=>`is-${e}`}}function u(e,t){let n=e.parent;for(;n&&n.statics.blotName!==t&&n!==e.scroll;)n=n.parent;if(n===e.scroll)throw Error(`${e.statics.blotName} must be a child of ${t}`);return n}function d(e,t){let n=Array(t.length),r=new Map(t.map((e,t)=>[e,t])),i=e.parent;for(;i&&i!==e.scroll&&r.size!==0;){if(r.has(i.statics.blotName)){let e=r.get(i.statics.blotName);n[e]=i,r.delete(i.statics.blotName)}i=i.parent}if(r.size>0)throw Error(`${e.statics.blotName} must be a child of ${Array.from(r.keys()).join(`, `)}`);return n}function f(e){let t=new Map,n=e;for(;n&&n.statics.blotName!==`scroll`;)t.set(n.statics.blotName,n),n=n.parent;return t}function p(e,t){let n=[],r=e.children.iterator(),i=null;for(;i=r();)i instanceof t&&n.push(i);return n}function m(e,t,n){for(let r of Object.getOwnPropertyNames(t))n?.test(r)||Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r));return e}function h(e,t){let n=class extends e{};for(let e of t)m(n.prototype,e.prototype,/^constructor$/);return n}function g(e,t){return e.prototype&&e.prototype instanceof t}function _(e,t){return e=Math.min(t,Math.max(0,Number.parseFloat(`${e}`))),Math.abs(e-t)<1e-6?1:e%t/Number.parseFloat(t)}function v(e){return{h:Math.min(360,Math.max(0,e.h)),s:Math.min(100,Math.max(0,e.s)),b:Math.min(100,Math.max(0,e.b)),a:Math.min(1,Math.max(0,e.a))}}function y(e){return e=e.startsWith(`#`)?e.slice(1):e,{r:Number.parseInt(e.slice(0,2),16),g:Number.parseInt(e.slice(2,4),16),b:Number.parseInt(e.slice(4,6),16),a:Number((Number.parseInt(e.slice(6,8)||`ff`,16)/255).toFixed(2))}}function b(e){let{r:t,g:n,b:r,a:i}=e;t=_(t,255),n=_(n,255),r=_(r,255);let a=Math.max(t,n,r),o=Math.min(t,n,r),s,c=a,l=a-o,u=a===0?0:l/a;if(a===o)s=0;else{switch(a){case t:s=(n-r)/l+(n<r?6:0);break;case n:s=(r-t)/l+2;break;case r:s=(t-n)/l+4;break}s/=6}return{h:s*360,s:u*100,b:c*100,a:i}}function ee(e){let{h:t,s:n,b:r,a:i}=e;t=_(t,360)*6,n=_(n,100),r=_(r,100);let a=Math.floor(t),o=t-a,s=r*(1-n),c=r*(1-o*n),l=r*(1-(1-o)*n),u=a%6,d=[r,c,s,s,l,r][u],f=[l,r,r,c,s,s][u],p=[s,s,l,r,r,c][u];return{r:Math.round(d*255),g:Math.round(f*255),b:Math.round(p*255),a:i}}function te(e){let t=[e.r.toString(16),e.g.toString(16),e.b.toString(16),Math.round(e.a*255).toString(16)];for(let e in t)t[e].length===1&&(t[e]=`0${t[e]}`);return t.join(``)}const ne=e=>te(ee(e)),x=e=>typeof e==`function`,S=Array.isArray,C=e=>typeof e==`string`,re=e=>typeof e==`number`,ie=e=>typeof e==`object`&&!!e,ae=e=>e===void 0,oe=e=>!Number.isNaN(e)&&Number(e)>0,se=e=>S(e)?e:[e];function ce(e){let{type:t=`default`,content:n}=e||{},r=l(`button`),i=document.createElement(`button`);return i.classList.add(r.b(),t),n&&(C(n)?i.textContent=n:i.appendChild(n)),i}function le(e={}){let t=b(y(e.color||`#ff0000`)),n=l(`color-picker`),r=document.createElement(`div`);r.classList.add(n.b());let i=document.createElement(`div`);i.classList.add(n.be(`content`));let a=document.createElement(`div`);a.classList.add(n.be(`selector`));let o=document.createElement(`div`);o.classList.add(n.be(`background`)),a.appendChild(o);let s=document.createElement(`div`);s.classList.add(n.be(`background-handle`)),o.appendChild(s);let c=document.createElement(`div`);c.classList.add(n.be(`alpha`));let u=document.createElement(`div`);u.classList.add(n.be(`alpha-bg`));let d=document.createElement(`div`);d.classList.add(n.be(`alpha-handle`)),c.appendChild(u),c.appendChild(d);let f=document.createElement(`div`);f.classList.add(n.be(`hue`));let p=document.createElement(`div`);p.classList.add(n.be(`hue-handle`)),f.appendChild(p);let m=document.createElement(`div`);m.classList.add(n.be(`action`));let[h,g,_,x]=[`r`,`g`,`b`,`a`].map(e=>{let r=document.createElement(`div`);r.classList.add(n.be(`action-item`),e);let i=document.createElement(`label`);i.textContent=e.toUpperCase();let a=document.createElement(`input`);return a.classList.add(n.be(`input`)),a.addEventListener(`input`,()=>{a.value=a.value.replaceAll(/[^0-9]/g,``)}),a.addEventListener(`change`,()=>{let n=Math.round(Number(a.value));e===`a`&&(n/=100),de(v(b(Object.assign({},ee(t),{[e]:n})))),ue()}),r.appendChild(i),r.appendChild(a),m.appendChild(r),a});i.appendChild(f),i.appendChild(a),i.appendChild(c),r.appendChild(i),r.appendChild(m);let S=!1,C=!1,re=!1;function ie(){let e=ne(t);for(let[t,n]of[h,g,_].entries())n.value=String(Number.parseInt(e[t*2]+e[t*2+1],16));x.value=String((t.a*100).toFixed(0))}function ae(){Object.assign(s.style,{left:`${Math.floor(230*t.s/100)}px`,top:`${Math.floor(150*(100-t.b)/100)}px`})}function oe(){a.style.backgroundColor=`#${te(ee({h:t.h,s:100,b:100,a:1}))}`}function se(){p.style.top=`${Math.floor(150-150*t.h/360)}px`}function ce(){d.style.left=`${t.a*100}%`}function le(){let{r:e,g:n,b:r}=ee(t);u.style.background=`linear-gradient(to right, rgba(${e}, ${n}, ${r}, 0) 0%, rgba(${e}, ${n}, ${r}, 1) 100%)`}function ue(){ae(),oe(),se(),ce(),le(),ie()}function de(n){t=v(Object.assign({},t,n)),ie(),e.onChange&&e.onChange(`#${ne(t)}`)}function fe(e){let t=a.getBoundingClientRect(),n=t.top+(window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0),r=t.left+document.body.scrollLeft;de({s:Math.floor(100*Math.max(0,Math.min(230,e.pageX-r))/230),b:Math.floor(100*(150-Math.max(0,Math.min(150,e.pageY-n)))/150)}),ue()}function pe(e){let t=f.getBoundingClientRect().top+(window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0);de({h:Math.floor(360*(150-Math.max(0,Math.min(150,e.pageY-t)))/150)}),ue()}function me(e){let{pageX:t}=e,n=c.getBoundingClientRect(),r=t-n.left;r=Math.max(10/2,r),r=Math.min(r,n.width-10/2),de({a:Math.round((r-10/2)/(n.width-10)*100)/100}),ue()}function w(e){S&&(e.preventDefault(),fe(e)),C&&(e.preventDefault(),pe(e)),re&&(e.preventDefault(),me(e))}function he(){document.removeEventListener(`mousemove`,w),document.removeEventListener(`mouseup`,he),S=!1}function T(e){document.addEventListener(`mousemove`,w),document.addEventListener(`mouseup`,he),S=!0,fe(e)}a.addEventListener(`mousedown`,T);function ge(){document.removeEventListener(`mousemove`,w),document.removeEventListener(`mouseup`,ge),C=!1}function _e(e){document.addEventListener(`mousemove`,w),document.addEventListener(`mouseup`,ge),C=!0,pe(e)}f.addEventListener(`mousedown`,_e);function E(){document.removeEventListener(`mousemove`,w),document.removeEventListener(`mouseup`,E),re=!1}function ve(e){document.addEventListener(`mousemove`,w),document.addEventListener(`mouseup`,E),re=!0,me(e)}return c.addEventListener(`mousedown`,ve),ue(),r}let ue=8e3;function de({child:e,target:t=document.body,beforeClose:n=()=>{}}={}){let r=l(`dialog`),i=t,a=document.createElement(`div`);a.classList.add(r.b()),a.style.zIndex=String(ue);let o=document.createElement(`div`);if(o.classList.add(r.be(`overlay`)),a.appendChild(o),e){let t=document.createElement(`div`);t.classList.add(r.be(`content`)),t.appendChild(e),o.appendChild(t),t.addEventListener(`click`,e=>{e.stopPropagation()})}let s=getComputedStyle(i).overflow;i.style.overflow=`hidden`,i.appendChild(a);let c=()=>{n(),a.remove(),i.style.overflow=s};return a.addEventListener(`click`,c),ue+=1,{dialog:a,close:c}}async function fe({message:e,confirm:t,cancel:n}){return new Promise(r=>{let i=document.createElement(`div`);Object.assign(i.style,{padding:`8px 12px`,fontSize:`14px`,lineHeight:`1.5`});let a=document.createElement(`p`);a.textContent=e;let o=document.createElement(`div`);Object.assign(o.style,{display:`flex`,justifyContent:`flex-end`,gap:`6px`});let s=ce({content:n}),c=ce({type:`confirm`,content:t});o.appendChild(s),o.appendChild(c),i.appendChild(a),i.appendChild(o);let{close:l}=de({child:i});s.addEventListener(`click`,()=>{r(!1),l()}),c.addEventListener(`click`,()=>{r(!0),l()})})}function pe(e,t){let n=l(`input`);t.type||=`text`,t.value||=``;let r=document.createElement(`div`);if(r.classList.add(n.be(`item`)),e){let t=document.createElement(`span`);t.classList.add(n.be(`label`)),t.textContent=e,r.appendChild(t)}let i=document.createElement(`div`);i.classList.add(n.be(`input`));let a=document.createElement(`input`);for(let e in t)a.setAttribute(e,t[e]);return(t.max||t.min)&&a.addEventListener(`blur`,()=>{t.max&&t.max<=Number(a.value)&&(a.value=String(t.max)),t.min&&t.min>=Number(a.value)&&(a.value=String(t.min))}),i.appendChild(a),r.appendChild(i),a.addEventListener(`focus`,()=>{i.classList.add(`focus`)}),a.addEventListener(`blur`,()=>{i.classList.remove(`focus`)}),{item:r,input:a,errorTip:e=>{let t;return i.classList.contains(`error`)?t=i.querySelector(`.${n.be(`error-tip`)}`):(t=document.createElement(`span`),t.classList.add(n.be(`error-tip`)),i.appendChild(t)),t.textContent=e,i.classList.add(`error`),{removeError:()=>{i.classList.remove(`error`),t.remove()}}}}}async function me(e={}){let t=l(`creator`),n=document.createElement(`div`);n.classList.add(t.b());let r=document.createElement(`div`);r.classList.add(t.be(`input`));let{item:i,input:a,errorTip:o}=pe(e.rowText||`Row`,{type:`number`,value:String(e.row||``),max:99}),{item:s,input:c,errorTip:u}=pe(e.colText||`Column`,{type:`number`,value:String(e.col||``),max:99});r.appendChild(i),r.appendChild(s),n.appendChild(r);let d=document.createElement(`div`);d.classList.add(t.be(`control`));let f=ce({type:`confirm`,content:e.confirmText||`Confirm`}),p=ce({type:`default`,content:e.cancelText||`Cancel`});d.appendChild(f),d.appendChild(p),n.appendChild(d);let m=(t=Number(a.value),n=Number(c.value))=>{if(Number.isNaN(t)||t<=0){o(e.notPositiveNumberError||`Please enter a positive integer`);return}if(Number.isNaN(n)||n<=0){u(e.notPositiveNumberError||`Please enter a positive integer`);return}return{row:t,col:n}},h=e=>{e.key===`Escape`&&(close(),document.removeEventListener(`keydown`,h))};return new Promise((e,t)=>{let{close:r}=de({child:n,beforeClose:t});a.focus();for(let t of[a,c])t.addEventListener(`keydown`,t=>{if(t.key===`Enter`){let t=m();t&&(e(t),r())}});f.addEventListener(`click`,()=>{let t=m();t&&(e(t),r())}),document.addEventListener(`keydown`,h),p.addEventListener(`click`,r)}).finally(()=>{document.removeEventListener(`keydown`,h)})}function w(e={}){let t=l(`select-box`),n=document.createElement(`div`);n.classList.add(t.b());let r=document.createElement(`div`);r.classList.add(t.be(`block`));for(let n=0;n<(e.row||8);n++)for(let i=0;i<(e.col||8);i++){let e=document.createElement(`div`);e.classList.add(t.be(`item`)),e.dataset.row=String(n+1),e.dataset.col=String(i+1),r.appendChild(e)}let i=()=>{let{row:e,col:t}=n.dataset;for(let e of Array.from(r.querySelectorAll(`.active`)))e.classList.remove(`active`);if(!e||!t)return;let i=Array.from(r.children);for(let n of i){let{row:r,col:i}=n.dataset;if(r>e&&i>t)return;n.classList.toggle(`active`,r<=e&&i<=t)}};if(r.addEventListener(`mousemove`,e=>{if(!e.target)return;let{row:t,col:r}=e.target.dataset;!t||!r||(n.dataset.row=t,n.dataset.col=r,i())}),r.addEventListener(`mouseleave`,()=>{n.removeAttribute(`data-row`),n.removeAttribute(`data-col`),i()}),r.addEventListener(`click`,()=>{let{row:t,col:r}=n.dataset;!t||!r||e.onSelect?.(Number(t),Number(r))}),n.appendChild(r),e.customBtn){let r=e.texts||{},i=document.createElement(`div`);i.classList.add(t.be(`custom`)),i.textContent=r.customBtnText||`Custom`,i.addEventListener(`click`,async()=>{let t=await me(r);t&&e.onSelect?.(t.row,t.col)}),n.appendChild(i)}return n}const he=Math.min,T=Math.max,ge=Math.round,_e=Math.floor,E=e=>({x:e,y:e}),ve={left:`right`,right:`left`,bottom:`top`,top:`bottom`},ye={start:`end`,end:`start`};function be(e,t,n){return T(e,he(t,n))}function xe(e,t){return typeof e==`function`?e(t):e}function D(e){return e.split(`-`)[0]}function Se(e){return e.split(`-`)[1]}function Ce(e){return e===`x`?`y`:`x`}function we(e){return e===`y`?`height`:`width`}const Te=new Set([`top`,`bottom`]);function O(e){return Te.has(D(e))?`y`:`x`}function Ee(e){return Ce(O(e))}function De(e,t,n){n===void 0&&(n=!1);let r=Se(e),i=Ee(e),a=we(i),o=i===`x`?r===(n?`end`:`start`)?`right`:`left`:r===`start`?`bottom`:`top`;return t.reference[a]>t.floating[a]&&(o=Ie(o)),[o,Ie(o)]}function Oe(e){let t=Ie(e);return[ke(e),t,ke(t)]}function ke(e){return e.replace(/start|end/g,e=>ye[e])}const Ae=[`left`,`right`],je=[`right`,`left`],Me=[`top`,`bottom`],Ne=[`bottom`,`top`];function Pe(e,t,n){switch(e){case`top`:case`bottom`:return n?t?je:Ae:t?Ae:je;case`left`:case`right`:return t?Me:Ne;default:return[]}}function Fe(e,t,n,r){let i=Se(e),a=Pe(D(e),n===`start`,r);return i&&(a=a.map(e=>e+`-`+i),t&&(a=a.concat(a.map(ke)))),a}function Ie(e){return e.replace(/left|right|bottom|top/g,e=>ve[e])}function Le(e){return{top:0,right:0,bottom:0,left:0,...e}}function Re(e){return typeof e==`number`?{top:e,right:e,bottom:e,left:e}:Le(e)}function ze(e){let{x:t,y:n,width:r,height:i}=e;return{width:r,height:i,top:n,left:t,right:t+r,bottom:n+i,x:t,y:n}}function Be(e,t,n){let{reference:r,floating:i}=e,a=O(t),o=Ee(t),s=we(o),c=D(t),l=a===`y`,u=r.x+r.width/2-i.width/2,d=r.y+r.height/2-i.height/2,f=r[s]/2-i[s]/2,p;switch(c){case`top`:p={x:u,y:r.y-i.height};break;case`bottom`:p={x:u,y:r.y+r.height};break;case`right`:p={x:r.x+r.width,y:d};break;case`left`:p={x:r.x-i.width,y:d};break;default:p={x:r.x,y:r.y}}switch(Se(t)){case`start`:p[o]-=f*(n&&l?-1:1);break;case`end`:p[o]+=f*(n&&l?-1:1);break}return p}async function Ve(e,t){t===void 0&&(t={});let{x:n,y:r,platform:i,rects:a,elements:o,strategy:s}=e,{boundary:c=`clippingAncestors`,rootBoundary:l=`viewport`,elementContext:u=`floating`,altBoundary:d=!1,padding:f=0}=xe(t,e),p=Re(f),m=o[d?u===`floating`?`reference`:`floating`:u],h=ze(await i.getClippingRect({element:await(i.isElement==null?void 0:i.isElement(m))??!0?m:m.contextElement||await(i.getDocumentElement==null?void 0:i.getDocumentElement(o.floating)),boundary:c,rootBoundary:l,strategy:s})),g=u===`floating`?{x:n,y:r,width:a.floating.width,height:a.floating.height}:a.reference,_=await(i.getOffsetParent==null?void 0:i.getOffsetParent(o.floating)),v=await(i.isElement==null?void 0:i.isElement(_))&&await(i.getScale==null?void 0:i.getScale(_))||{x:1,y:1},y=ze(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:o,rect:g,offsetParent:_,strategy:s}):g);return{top:(h.top-y.top+p.top)/v.y,bottom:(y.bottom-h.bottom+p.bottom)/v.y,left:(h.left-y.left+p.left)/v.x,right:(y.right-h.right+p.right)/v.x}}const He=async(e,t,n)=>{let{placement:r=`bottom`,strategy:i=`absolute`,middleware:a=[],platform:o}=n,s=a.filter(Boolean),c=await(o.isRTL==null?void 0:o.isRTL(t)),l=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:u,y:d}=Be(l,r,c),f=r,p={},m=0;for(let n=0;n<s.length;n++){let{name:a,fn:h}=s[n],{x:g,y:_,data:v,reset:y}=await h({x:u,y:d,initialPlacement:r,placement:f,strategy:i,middlewareData:p,rects:l,platform:{...o,detectOverflow:o.detectOverflow??Ve},elements:{reference:e,floating:t}});u=g??u,d=_??d,p={...p,[a]:{...p[a],...v}},y&&m<=50&&(m++,typeof y==`object`&&(y.placement&&(f=y.placement),y.rects&&(l=y.rects===!0?await o.getElementRects({reference:e,floating:t,strategy:i}):y.rects),{x:u,y:d}=Be(l,f,c)),n=-1)}return{x:u,y:d,placement:f,strategy:i,middlewareData:p}},Ue=function(e){return e===void 0&&(e={}),{name:`flip`,options:e,async fn(t){var n;let{placement:r,middlewareData:i,rects:a,initialPlacement:o,platform:s,elements:c}=t,{mainAxis:l=!0,crossAxis:u=!0,fallbackPlacements:d,fallbackStrategy:f=`bestFit`,fallbackAxisSideDirection:p=`none`,flipAlignment:m=!0,...h}=xe(e,t);if((n=i.arrow)!=null&&n.alignmentOffset)return{};let g=D(r),_=O(o),v=D(o)===o,y=await(s.isRTL==null?void 0:s.isRTL(c.floating)),b=d||(v||!m?[Ie(o)]:Oe(o)),ee=p!==`none`;!d&&ee&&b.push(...Fe(o,m,p,y));let te=[o,...b],ne=await s.detectOverflow(t,h),x=[],S=i.flip?.overflows||[];if(l&&x.push(ne[g]),u){let e=De(r,a,y);x.push(ne[e[0]],ne[e[1]])}if(S=[...S,{placement:r,overflows:x}],!x.every(e=>e<=0)){let e=(i.flip?.index||0)+1,t=te[e];if(t&&(!(u===`alignment`&&_!==O(t))||S.every(e=>O(e.placement)===_?e.overflows[0]>0:!0)))return{data:{index:e,overflows:S},reset:{placement:t}};let n=S.filter(e=>e.overflows[0]<=0).sort((e,t)=>e.overflows[1]-t.overflows[1])[0]?.placement;if(!n)switch(f){case`bestFit`:{let e=S.filter(e=>{if(ee){let t=O(e.placement);return t===_||t===`y`}return!0}).map(e=>[e.placement,e.overflows.filter(e=>e>0).reduce((e,t)=>e+t,0)]).sort((e,t)=>e[1]-t[1])[0]?.[0];e&&(n=e);break}case`initialPlacement`:n=o;break}if(r!==n)return{reset:{placement:n}}}return{}}}},We=new Set([`left`,`top`]);async function Ge(e,t){let{placement:n,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=D(n),s=Se(n),c=O(n)===`y`,l=We.has(o)?-1:1,u=a&&c?-1:1,d=xe(t,e),{mainAxis:f,crossAxis:p,alignmentAxis:m}=typeof d==`number`?{mainAxis:d,crossAxis:0,alignmentAxis:null}:{mainAxis:d.mainAxis||0,crossAxis:d.crossAxis||0,alignmentAxis:d.alignmentAxis};return s&&typeof m==`number`&&(p=s===`end`?m*-1:m),c?{x:p*u,y:f*l}:{x:f*l,y:p*u}}const Ke=function(e){return e===void 0&&(e=0),{name:`offset`,options:e,async fn(t){var n;let{x:r,y:i,placement:a,middlewareData:o}=t,s=await Ge(t,e);return a===o.offset?.placement&&(n=o.arrow)!=null&&n.alignmentOffset?{}:{x:r+s.x,y:i+s.y,data:{...s,placement:a}}}}},qe=function(e){return e===void 0&&(e={}),{name:`shift`,options:e,async fn(t){let{x:n,y:r,placement:i,platform:a}=t,{mainAxis:o=!0,crossAxis:s=!1,limiter:c={fn:e=>{let{x:t,y:n}=e;return{x:t,y:n}}},...l}=xe(e,t),u={x:n,y:r},d=await a.detectOverflow(t,l),f=O(D(i)),p=Ce(f),m=u[p],h=u[f];if(o){let e=p===`y`?`top`:`left`,t=p===`y`?`bottom`:`right`,n=m+d[e],r=m-d[t];m=be(n,m,r)}if(s){let e=f===`y`?`top`:`left`,t=f===`y`?`bottom`:`right`,n=h+d[e],r=h-d[t];h=be(n,h,r)}let g=c.fn({...t,[p]:m,[f]:h});return{...g,data:{x:g.x-n,y:g.y-r,enabled:{[p]:o,[f]:s}}}}}},Je=function(e){return e===void 0&&(e={}),{options:e,fn(t){let{x:n,y:r,placement:i,rects:a,middlewareData:o}=t,{offset:s=0,mainAxis:c=!0,crossAxis:l=!0}=xe(e,t),u={x:n,y:r},d=O(i),f=Ce(d),p=u[f],m=u[d],h=xe(s,t),g=typeof h==`number`?{mainAxis:h,crossAxis:0}:{mainAxis:0,crossAxis:0,...h};if(c){let e=f===`y`?`height`:`width`,t=a.reference[f]-a.floating[e]+g.mainAxis,n=a.reference[f]+a.reference[e]-g.mainAxis;p<t?p=t:p>n&&(p=n)}if(l){let e=f===`y`?`width`:`height`,t=We.has(D(i)),n=a.reference[d]-a.floating[e]+(t&&o.offset?.[d]||0)+(t?0:g.crossAxis),r=a.reference[d]+a.reference[e]+(t?0:o.offset?.[d]||0)-(t?g.crossAxis:0);m<n?m=n:m>r&&(m=r)}return{[f]:p,[d]:m}}}};function Ye(){return typeof window<`u`}function Xe(e){return Ze(e)?(e.nodeName||``).toLowerCase():`#document`}function k(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function A(e){return((Ze(e)?e.ownerDocument:e.document)||window.document)?.documentElement}function Ze(e){return Ye()?e instanceof Node||e instanceof k(e).Node:!1}function j(e){return Ye()?e instanceof Element||e instanceof k(e).Element:!1}function M(e){return Ye()?e instanceof HTMLElement||e instanceof k(e).HTMLElement:!1}function Qe(e){return!Ye()||typeof ShadowRoot>`u`?!1:e instanceof ShadowRoot||e instanceof k(e).ShadowRoot}const $e=new Set([`inline`,`contents`]);function et(e){let{overflow:t,overflowX:n,overflowY:r,display:i}=N(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!$e.has(i)}const tt=new Set([`table`,`td`,`th`]);function nt(e){return tt.has(Xe(e))}const rt=[`:popover-open`,`:modal`];function it(e){return rt.some(t=>{try{return e.matches(t)}catch{return!1}})}const at=[`transform`,`translate`,`scale`,`rotate`,`perspective`],ot=[`transform`,`translate`,`scale`,`rotate`,`perspective`,`filter`],st=[`paint`,`layout`,`strict`,`content`];function ct(e){let t=ut(),n=j(e)?N(e):e;return at.some(e=>n[e]?n[e]!==`none`:!1)||(n.containerType?n.containerType!==`normal`:!1)||!t&&(n.backdropFilter?n.backdropFilter!==`none`:!1)||!t&&(n.filter?n.filter!==`none`:!1)||ot.some(e=>(n.willChange||``).includes(e))||st.some(e=>(n.contain||``).includes(e))}function lt(e){let t=P(e);for(;M(t)&&!ft(t);){if(ct(t))return t;if(it(t))return null;t=P(t)}return null}function ut(){return typeof CSS>`u`||!CSS.supports?!1:CSS.supports(`-webkit-backdrop-filter`,`none`)}const dt=new Set([`html`,`body`,`#document`]);function ft(e){return dt.has(Xe(e))}function N(e){return k(e).getComputedStyle(e)}function pt(e){return j(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function P(e){if(Xe(e)===`html`)return e;let t=e.assignedSlot||e.parentNode||Qe(e)&&e.host||A(e);return Qe(t)?t.host:t}function mt(e){let t=P(e);return ft(t)?e.ownerDocument?e.ownerDocument.body:e.body:M(t)&&et(t)?t:mt(t)}function ht(e,t,n){t===void 0&&(t=[]),n===void 0&&(n=!0);let r=mt(e),i=r===e.ownerDocument?.body,a=k(r);if(i){let e=gt(a);return t.concat(a,a.visualViewport||[],et(r)?r:[],e&&n?ht(e):[])}return t.concat(r,ht(r,[],n))}function gt(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function _t(e){let t=N(e),n=parseFloat(t.width)||0,r=parseFloat(t.height)||0,i=M(e),a=i?e.offsetWidth:n,o=i?e.offsetHeight:r,s=ge(n)!==a||ge(r)!==o;return s&&(n=a,r=o),{width:n,height:r,$:s}}function vt(e){return j(e)?e:e.contextElement}function yt(e){let t=vt(e);if(!M(t))return E(1);let n=t.getBoundingClientRect(),{width:r,height:i,$:a}=_t(t),o=(a?ge(n.width):n.width)/r,s=(a?ge(n.height):n.height)/i;return(!o||!Number.isFinite(o))&&(o=1),(!s||!Number.isFinite(s))&&(s=1),{x:o,y:s}}const bt=E(0);function xt(e){let t=k(e);return!ut()||!t.visualViewport?bt:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function St(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==k(e)?!1:t}function Ct(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);let i=e.getBoundingClientRect(),a=vt(e),o=E(1);t&&(r?j(r)&&(o=yt(r)):o=yt(e));let s=St(a,n,r)?xt(a):E(0),c=(i.left+s.x)/o.x,l=(i.top+s.y)/o.y,u=i.width/o.x,d=i.height/o.y;if(a){let e=k(a),t=r&&j(r)?k(r):r,n=e,i=gt(n);for(;i&&r&&t!==n;){let e=yt(i),t=i.getBoundingClientRect(),r=N(i),a=t.left+(i.clientLeft+parseFloat(r.paddingLeft))*e.x,o=t.top+(i.clientTop+parseFloat(r.paddingTop))*e.y;c*=e.x,l*=e.y,u*=e.x,d*=e.y,c+=a,l+=o,n=k(i),i=gt(n)}}return ze({width:u,height:d,x:c,y:l})}function wt(e,t){let n=pt(e).scrollLeft;return t?t.left+n:Ct(A(e)).left+n}function Tt(e,t){let n=e.getBoundingClientRect();return{x:n.left+t.scrollLeft-wt(e,n),y:n.top+t.scrollTop}}function Et(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e,a=i===`fixed`,o=A(r),s=t?it(t.floating):!1;if(r===o||s&&a)return n;let c={scrollLeft:0,scrollTop:0},l=E(1),u=E(0),d=M(r);if((d||!d&&!a)&&((Xe(r)!==`body`||et(o))&&(c=pt(r)),M(r))){let e=Ct(r);l=yt(r),u.x=e.x+r.clientLeft,u.y=e.y+r.clientTop}let f=o&&!d&&!a?Tt(o,c):E(0);return{width:n.width*l.x,height:n.height*l.y,x:n.x*l.x-c.scrollLeft*l.x+u.x+f.x,y:n.y*l.y-c.scrollTop*l.y+u.y+f.y}}function Dt(e){return Array.from(e.getClientRects())}function Ot(e){let t=A(e),n=pt(e),r=e.ownerDocument.body,i=T(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),a=T(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight),o=-n.scrollLeft+wt(e),s=-n.scrollTop;return N(r).direction===`rtl`&&(o+=T(t.clientWidth,r.clientWidth)-i),{width:i,height:a,x:o,y:s}}function kt(e,t){let n=k(e),r=A(e),i=n.visualViewport,a=r.clientWidth,o=r.clientHeight,s=0,c=0;if(i){a=i.width,o=i.height;let e=ut();(!e||e&&t===`fixed`)&&(s=i.offsetLeft,c=i.offsetTop)}let l=wt(r);if(l<=0){let e=r.ownerDocument,t=e.body,n=getComputedStyle(t),i=e.compatMode===`CSS1Compat`&&parseFloat(n.marginLeft)+parseFloat(n.marginRight)||0,o=Math.abs(r.clientWidth-t.clientWidth-i);o<=25&&(a-=o)}else l<=25&&(a+=l);return{width:a,height:o,x:s,y:c}}const At=new Set([`absolute`,`fixed`]);function jt(e,t){let n=Ct(e,!0,t===`fixed`),r=n.top+e.clientTop,i=n.left+e.clientLeft,a=M(e)?yt(e):E(1);return{width:e.clientWidth*a.x,height:e.clientHeight*a.y,x:i*a.x,y:r*a.y}}function Mt(e,t,n){let r;if(t===`viewport`)r=kt(e,n);else if(t===`document`)r=Ot(A(e));else if(j(t))r=jt(t,n);else{let n=xt(e);r={x:t.x-n.x,y:t.y-n.y,width:t.width,height:t.height}}return ze(r)}function Nt(e,t){let n=P(e);return n===t||!j(n)||ft(n)?!1:N(n).position===`fixed`||Nt(n,t)}function Pt(e,t){let n=t.get(e);if(n)return n;let r=ht(e,[],!1).filter(e=>j(e)&&Xe(e)!==`body`),i=null,a=N(e).position===`fixed`,o=a?P(e):e;for(;j(o)&&!ft(o);){let t=N(o),n=ct(o);!n&&t.position===`fixed`&&(i=null),(a?!n&&!i:!n&&t.position===`static`&&i&&At.has(i.position)||et(o)&&!n&&Nt(e,o))?r=r.filter(e=>e!==o):i=t,o=P(o)}return t.set(e,r),r}function Ft(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e,a=[...n===`clippingAncestors`?it(t)?[]:Pt(t,this._c):[].concat(n),r],o=a[0],s=a.reduce((e,n)=>{let r=Mt(t,n,i);return e.top=T(r.top,e.top),e.right=he(r.right,e.right),e.bottom=he(r.bottom,e.bottom),e.left=T(r.left,e.left),e},Mt(t,o,i));return{width:s.right-s.left,height:s.bottom-s.top,x:s.left,y:s.top}}function It(e){let{width:t,height:n}=_t(e);return{width:t,height:n}}function Lt(e,t,n){let r=M(t),i=A(t),a=n===`fixed`,o=Ct(e,!0,a,t),s={scrollLeft:0,scrollTop:0},c=E(0);function l(){c.x=wt(i)}if(r||!r&&!a)if((Xe(t)!==`body`||et(i))&&(s=pt(t)),r){let e=Ct(t,!0,a,t);c.x=e.x+t.clientLeft,c.y=e.y+t.clientTop}else i&&l();a&&!r&&i&&l();let u=i&&!r&&!a?Tt(i,s):E(0);return{x:o.left+s.scrollLeft-c.x-u.x,y:o.top+s.scrollTop-c.y-u.y,width:o.width,height:o.height}}function Rt(e){return N(e).position===`static`}function zt(e,t){if(!M(e)||N(e).position===`fixed`)return null;if(t)return t(e);let n=e.offsetParent;return A(e)===n&&(n=n.ownerDocument.body),n}function Bt(e,t){let n=k(e);if(it(e))return n;if(!M(e)){let t=P(e);for(;t&&!ft(t);){if(j(t)&&!Rt(t))return t;t=P(t)}return n}let r=zt(e,t);for(;r&&nt(r)&&Rt(r);)r=zt(r,t);return r&&ft(r)&&Rt(r)&&!ct(r)?n:r||lt(e)||n}const Vt=async function(e){let t=this.getOffsetParent||Bt,n=this.getDimensions,r=await n(e.floating);return{reference:Lt(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Ht(e){return N(e).direction===`rtl`}const Ut={convertOffsetParentRelativeRectToViewportRelativeRect:Et,getDocumentElement:A,getClippingRect:Ft,getOffsetParent:Bt,getElementRects:Vt,getClientRects:Dt,getDimensions:It,getScale:yt,isElement:j,isRTL:Ht};function Wt(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function Gt(e,t){let n=null,r,i=A(e);function a(){var e;clearTimeout(r),(e=n)==null||e.disconnect(),n=null}function o(s,c){s===void 0&&(s=!1),c===void 0&&(c=1),a();let l=e.getBoundingClientRect(),{left:u,top:d,width:f,height:p}=l;if(s||t(),!f||!p)return;let m=_e(d),h=_e(i.clientWidth-(u+f)),g=_e(i.clientHeight-(d+p)),_=_e(u),v={rootMargin:-m+`px `+-h+`px `+-g+`px `+-_+`px`,threshold:T(0,he(1,c))||1},y=!0;function b(t){let n=t[0].intersectionRatio;if(n!==c){if(!y)return o();n?o(!1,n):r=setTimeout(()=>{o(!1,1e-7)},1e3)}n===1&&!Wt(l,e.getBoundingClientRect())&&o(),y=!1}try{n=new IntersectionObserver(b,{...v,root:i.ownerDocument})}catch{n=new IntersectionObserver(b,v)}n.observe(e)}return o(!0),a}function Kt(e,t,n,r){r===void 0&&(r={});let{ancestorScroll:i=!0,ancestorResize:a=!0,elementResize:o=typeof ResizeObserver==`function`,layoutShift:s=typeof IntersectionObserver==`function`,animationFrame:c=!1}=r,l=vt(e),u=i||a?[...l?ht(l):[],...ht(t)]:[];u.forEach(e=>{i&&e.addEventListener(`scroll`,n,{passive:!0}),a&&e.addEventListener(`resize`,n)});let d=l&&s?Gt(l,n):null,f=-1,p=null;o&&(p=new ResizeObserver(e=>{let[r]=e;r&&r.target===l&&p&&(p.unobserve(t),cancelAnimationFrame(f),f=requestAnimationFrame(()=>{var e;(e=p)==null||e.observe(t)})),n()}),l&&!c&&p.observe(l),p.observe(t));let m,h=c?Ct(e):null;c&&g();function g(){let t=Ct(e);h&&!Wt(h,t)&&n(),h=t,m=requestAnimationFrame(g)}return n(),()=>{var e;u.forEach(e=>{i&&e.removeEventListener(`scroll`,n),a&&e.removeEventListener(`resize`,n)}),d?.(),(e=p)==null||e.disconnect(),p=null,c&&cancelAnimationFrame(m)}}const qt=Ke,Jt=qe,Yt=Ue,Xt=Je,Zt=(e,t,n)=>{let r=new Map,i={platform:Ut,...n},a={...i.platform,_c:r};return He(e,t,{...i,platform:a})};function Qt(e,t,n,r,i){return i&&clearTimeout(i),e.addEventListener(`transitionend`,n,r),setTimeout(()=>{n()},t)}function $t(e,t={}){let{msg:n=``,delay:r=150,content:i,direction:a=`bottom`,type:o=`hover`,container:s,onOpen:c,onClose:u,closed:d,onDestroy:f}=t,p=l(`tooltip`);if(n||i){let t=s||document.body,l=document.createElement(`div`);l.classList.add(p.b(),`hidden`,`transparent`),i?l.appendChild(i):n&&(l.textContent=n);let m,h,g,_=()=>{g&&g(),Zt(e,l,{placement:a,middleware:[Yt(),Jt({limiter:Xt()}),qt(4)]}).then(({x:e,y:t})=>{Object.assign(l.style,{left:`${e}px`,top:`${t}px`})})},v=()=>{l.classList.add(`hidden`),t.contains(l)&&t.removeChild(l),g&&g(),d&&d()},y=(n=!1)=>{h&&clearTimeout(h),m=setTimeout(()=>{if(c){let e=c(n);if(!n&&e)return}t.appendChild(l),l.removeEventListener(`transitionend`,v),l.classList.remove(`hidden`),g=Kt(e,l,_),l.classList.remove(`transparent`)},r)},b=(e=!1)=>{m&&clearTimeout(m),h=setTimeout(()=>{if(u){let t=u(e);if(!e&&t)return}Qt(l,150,v,{once:!0}),l.classList.add(`transparent`)},r)},{prepare:ee,show:te,hide:ne,destroy:x}={hover:()=>{let t=[e,l],n=b.bind(void 0,!1),r=y.bind(void 0,!1);return{prepare:()=>{for(let e of t)e.addEventListener(`mouseenter`,r),e.addEventListener(`mouseleave`,n)},show:y,hide:b,destroy:()=>{for(let e of t)e.removeEventListener(`mouseenter`,r),e.removeEventListener(`mouseleave`,n)}}},click:()=>{let t=e=>{e.stopPropagation(),b(!1)},n=e=>{e.stopPropagation(),y(),document.removeEventListener(`click`,t),document.addEventListener(`click`,t,{once:!0})};return{prepare:()=>{l.addEventListener(`click`,e=>e.stopPropagation()),e.addEventListener(`click`,n)},show:y,hide:(e=!1)=>{b(e),document.removeEventListener(`click`,t)},destroy:()=>{e.removeEventListener(`click`,n),document.removeEventListener(`click`,t)}}}}[o]();return ee(),{show:te,hide:ne,destroy:()=>{ne(!0),f&&f(),x(),g&&g(),l.remove()}}}return null}function en(e,t={}){let{axis:n=`both`,onMove:r=()=>{},onStart:i=()=>{},onEnd:a=()=>{},buttons:o=[0],container:s,draggingElement:c=document,exact:l=!0}=t,u={x:0,y:0},d,f={x:0,y:0};function p(t){if(!d)return;let r=e.getBoundingClientRect(),{x:i,y:a}=u;(n===`x`||n===`both`)&&(i=t.clientX-d.x,s&&(i=Math.min(Math.max(0,i),s.scrollWidth-r.width))),(n===`y`||n===`both`)&&(a=t.clientY-d.y,s&&(a=Math.min(Math.max(0,a),s.scrollHeight-r.height))),u={x:i,y:a}}function m(t){if(!o.includes(t.button)||l&&t.target!==e)return;c.addEventListener(`pointerup`,g),c.addEventListener(`pointermove`,h);let n=s?.getBoundingClientRect?.(),r=e.getBoundingClientRect(),a={x:t.clientX-(s?r.left-n.left+s.scrollLeft:r.left),y:t.clientY-(s?r.top-n.top+s.scrollTop:r.top)};f={x:t.clientX,y:t.clientY},i({position:u,startPosition:a,movePosition:{x:t.clientX-f.x,y:t.clientY-f.y}},t)!==!1&&(d=a,u=a)}function h(e){d&&(p(e),r({position:u,startPosition:d,movePosition:{x:e.clientX-f.x,y:e.clientY-f.y}},e))}function g(e){c.removeEventListener(`pointermove`,h),c.removeEventListener(`pointerup`,g),p(e),a({position:u,startPosition:d,movePosition:{x:e.clientX-f.x,y:e.clientY-f.y}},e),d=void 0,f={x:0,y:0},u={x:0,y:0}}return c.addEventListener(`pointerdown`,m),{stop:()=>{c.removeEventListener(`pointerdown`,m)}}}function tn(e,t,n=0,r=!0){let{x:i,y:a,x1:o,y1:s}=e,{x:c,y:l,x1:u,y1:d}=t,f,p;return r?(f=o<c+n||i-n>u,p=s<l+n||a-n>d):(f=o<=c+n||i-n>=u,p=s<=l+n||a-n>=d),!(f||p)}function nn(e,t){let n=t.getBoundingClientRect();return{x:e.x-n.x-t.scrollLeft,y:e.y-n.y-t.scrollTop,x1:e.x-n.x-t.scrollLeft+e.width,y1:e.y-n.y-t.scrollTop+e.height,width:e.width,height:e.height}}function rn(e){let{left:t,top:n,width:r,height:i}=e,{clientWidth:a,clientHeight:o}=document.documentElement,s=!1,c=!1;return t+r>a?(t=a-r-8,s=!0):t<0&&(t=8,s=!0),n+i>o?(n=o-i-8,c=!0):n<0&&(n=8,c=!0),{left:t,top:n,leftLimited:s,topLimited:c}}function an(e,t={}){let n=Symbol(`ignoreFirstBind`),r=new Set,i=new ResizeObserver(r=>{t.ignoreFirstBind&&r.some(e=>{let t=e.target,r=t[n];return t[n]=!0,!r})||e(r)}),a=i.observe.bind(i);i.observe=(e,t)=>{r.add(e),a(e,t)};let o=i.unobserve;i.unobserve=e=>{r.has(e)&&(r.delete(e),e[n]=void 0),o.call(i,e)};let s=i.disconnect;return i.disconnect=()=>{for(let e of r.values())e[n]=void 0;s.call(i)},i}function F(e,t){e.addEventListener(`scroll`,t),this.scrollHandler.push([e,t])}function on(e,t){for(let n=0;n<this.scrollHandler.length;n++){let[r,i]=this.scrollHandler[n];if(r===e&&i===t){this.scrollHandler.splice(n,1);break}}}function I(){for(let[e,t]of this.scrollHandler)e.removeEventListener(`scroll`,t);this.scrollHandler=[]}function sn(e){return{y:e.scrollTop,x:e.scrollLeft}}function cn({target:e=document.body}={}){let t=document.createElement(`div`);Object.assign(t.style,{visibility:`hidden`,width:`100px`,height:`100%`,overflow:`auto`,position:`absolute`,top:`-9999px`}),e.appendChild(t);let n=t.offsetWidth;t.style.overflow=`scroll`;let r=document.createElement(`div`);r.style.width=`100%`,t.appendChild(r);let i=r.offsetWidth;return t.parentNode?.removeChild(t),n-i}var ln=class{mouseY=0;mouseX=0;animationId=null;constructor(e=50,t=20,n=20){this.scrollThresholdX=e,this.scrollThresholdY=t,this.maxScrollSpeed=n}checkMinY(e){return this.mouseY<e.top+this.scrollThresholdY}checkMaxY(e){return this.mouseY>e.bottom-this.scrollThresholdY}checkMinX(e){return this.mouseX<e.left+this.scrollThresholdX}checkMaxX(e){return this.mouseX>e.right-this.scrollThresholdX}start(e,t){let n=e.getBoundingClientRect(),r=()=>{let i=!1,a=0,o=0;if(this.checkMinY(n)){let t=n.top+this.scrollThresholdY-this.mouseY,r=Math.min(t/this.scrollThresholdY*this.maxScrollSpeed,this.maxScrollSpeed);e.scrollTop-=r,o=-1*r,i=!0}else if(this.checkMaxY(n)){let t=this.mouseY-(n.bottom-this.scrollThresholdY),r=Math.min(t/this.scrollThresholdY*this.maxScrollSpeed,this.maxScrollSpeed);e.scrollTop+=r,o=r,i=!0}if(this.checkMinX(n)){let t=n.left+this.scrollThresholdX-this.mouseX,r=Math.min(t/this.scrollThresholdX*this.maxScrollSpeed,this.maxScrollSpeed);e.scrollLeft-=r,a=-1*r,i=!0}else if(this.checkMaxX(n)){let t=this.mouseX-(n.right-this.scrollThresholdX),r=Math.min(t/this.scrollThresholdX*this.maxScrollSpeed,this.maxScrollSpeed);e.scrollLeft+=r,a=r,i=!0}i&&t&&t(a,o),this.animationId=requestAnimationFrame(r)};this.animationId=requestAnimationFrame(r)}updateMousePosition(e,t){this.mouseX=e,this.mouseY=t}stop(){this.animationId!==null&&(cancelAnimationFrame(this.animationId),this.animationId=null)}};function un(e){return e.replaceAll(/([A-Z])/g,` $1`).trim().split(` `).join(`-`).toLowerCase()}function dn(e){return e.replaceAll(/-(\w)/g,(e,t)=>t.toUpperCase())}function fn(e){let t={};if(!e.style.cssText)return t;let n=e.style.cssText.split(`;`).filter(e=>e.trim());for(let e of n){let n=e.indexOf(`:`);if(n===-1)continue;let r=e.slice(0,n).trim();t[r]=e.slice(n+1).trim()}return t}function pn(e){let t={},n=e.trim().split(`;`);for(let e of n){let n=e.trim();if(!n)continue;let r=n.indexOf(`:`);if(r===-1)continue;let i=n.slice(0,Math.max(0,r)).trim(),a=n.slice(Math.max(0,r+1)).trim();t[dn(i)]=a}return t}function mn(e){return Object.entries(e).map(([e,t])=>`${un(e)}: ${t};`).join(` `)}const L=()=>Math.random().toString(36).slice(2);function hn(e,t){let n;return function(...r){n&&clearTimeout(n),n=setTimeout(()=>{e.apply(this,r)},t)}}const gn=e.import(`parchment`),_n=e.import(`blots/container`),vn=e.import(`blots/block`),yn=e.import(`blots/block/embed`);var R=class e extends _n{static tagName;static blotName=t.container;static scope=gn.Scope.BLOCK_BLOT;static allowedChildren=[vn,yn,_n];static requiredContainer;static defaultChild;static allowAttrs=new Set;static allowDataAttrs=new Set;static allowDataAttrsChangeHandler={};static create(e){let t=document.createElement(this.tagName);return this.className&&t.classList.add(this.className),t}setFormatValue(e,t){if(this.statics.allowAttrs.has(e)||this.statics.allowDataAttrs.has(e)){let n=e;this.statics.allowDataAttrs.has(e)&&(n=`data-${e}`),t?this.domNode.setAttribute(n,t):this.domNode.removeAttribute(n);let r=this.statics.allowDataAttrsChangeHandler[e];r&&x(this[r])&&this[r](t)}}optimize(e){if(this.children.length===0)if(this.statics.defaultChild!=null){let e=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(e)}else this.remove();this.children.length>0&&this.next!=null&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}enforceAllowedChildren(){this.children.forEach(t=>{this.statics.allowedChildren.some(e=>t instanceof e)||(t.statics.scope===gn.Scope.BLOCK_BLOT?(t.parent instanceof e?(t.next!=null&&t.parent.splitAfter(t),t.prev!=null&&t.parent.splitAfter(t.prev)):(t.next!=null&&this.splitAfter(t),t.prev!=null&&this.splitAfter(t.prev)),t.parent.unwrap()):t instanceof gn.ParentBlot?t.unwrap():t.remove())})}};const z=e=>oe(e)?e:1;function bn(e,t){return Object.keys(e).every(n=>JSON.stringify(e[n])===JSON.stringify(t[n]))}const xn=e.import(`parchment`),Sn=e.import(`blots/block`),Cn=e.import(`blots/block/embed`),wn=e.import(`blots/container`);var Tn=class extends Sn{replaceWith(e,n){let r=C(e)?this.scroll.create(e,n):e;if(r instanceof xn.ParentBlot)if(r.statics.blotName===t.tableCellInner){let e=null;try{if(e=u(this,t.tableCellInner),bn(e.formats(),r.formats()))return e}catch{}if(e)e.insertBefore(r,this),r.appendChild(this),e.children.length===0&&e.remove();else{let e=this,t=e;for(;e.parent!==this.scroll&&e.parent instanceof wn;)t=e,e=e.parent;e===this.scroll&&(e=t);let n=this.offset(e),i=this.length(),a=e.isolate(n,i);a?.parent&&a.parent.insertBefore(r,a.next),r.appendChild(this)}return r}else this.moveChildren(r);return this.parent!==null&&(this.parent.insertBefore(r,this.next),this.remove()),this.attributes.copy(r),r}format(e,n){if(e===t.tableCellInner&&this.parent.statics.blotName===e&&!n){if(this.prev&&this.prev instanceof Cn)return;try{u(this,t.tableCellInner).unwrap()}catch{console.error(`unwrap TableCellInner error`)}}else super.format(e,n)}};const En=e.import(`blots/block/embed`);var Dn=class extends En{delta(){let e=super.delta(),n=On(this);return n[t.tableCellInner]&&e.insert(`
1
+ import e from"quill";const t={container:`table-up-container`,tableCaption:`table-up-caption`,tableWrapper:`table-up`,tableMain:`table-up-main`,tableColgroup:`table-up-colgroup`,tableCol:`table-up-col`,tableHead:`table-up-head`,tableBody:`table-up-body`,tableFoot:`table-up-foot`,tableRow:`table-up-row`,tableCell:`table-up-cell`,tableCellInner:`table-up-cell-inner`},n={colMinWidthPre:5,colMinWidthPx:40,colDefaultWidth:100,rowMinHeightPx:36},r={AFTER_TABLE_RESIZE:`after-table-resize`,TABLE_SELECTION_DRAG_START:`table-selection-drag-start`,TABLE_SELECTION_DRAG_END:`table-selection-drag-end`,TABLE_SELECTION_CHANGE:`table-selection-change`,TABLE_SELECTION_DISPLAY_CHANGE:`table-selection-display-change`},i={moduleName:`table-up`,tableSelectionName:`table-selection`},a=[[`rgb(255, 255, 255)`,`rgb(0, 0, 0)`,`rgb(72, 83, 104)`,`rgb(41, 114, 244)`,`rgb(0, 163, 245)`,`rgb(49, 155, 98)`,`rgb(222, 60, 54)`,`rgb(248, 136, 37)`,`rgb(245, 196, 0)`,`rgb(153, 56, 215)`],[`rgb(242, 242, 242)`,`rgb(127, 127, 127)`,`rgb(243, 245, 247)`,`rgb(229, 239, 255)`,`rgb(229, 246, 255)`,`rgb(234, 250, 241)`,`rgb(254, 233, 232)`,`rgb(254, 243, 235)`,`rgb(254, 249, 227)`,`rgb(253, 235, 255)`],[`rgb(216, 216, 216)`,`rgb(89, 89, 89)`,`rgb(197, 202, 211)`,`rgb(199, 220, 255)`,`rgb(199, 236, 255)`,`rgb(195, 234, 213)`,`rgb(255, 201, 199)`,`rgb(255, 220, 196)`,`rgb(255, 238, 173)`,`rgb(242, 199, 255)`],[`rgb(191, 191, 191)`,`rgb(63, 63, 63)`,`rgb(128, 139, 158)`,`rgb(153, 190, 255)`,`rgb(153, 221, 255)`,`rgb(152, 215, 182)`,`rgb(255, 156, 153)`,`rgb(255, 186, 132)`,`rgb(255, 226, 112)`,`rgb(213, 142, 255)`],[`rgb(165, 165, 165)`,`rgb(38, 38, 38)`,`rgb(53, 59, 69)`,`rgb(20, 80, 184)`,`rgb(18, 116, 165)`,`rgb(39, 124, 79)`,`rgb(158, 30, 26)`,`rgb(184, 96, 20)`,`rgb(163, 130, 0)`,`rgb(94, 34, 129)`],[`rgb(147, 147, 147)`,`rgb(13, 13, 13)`,`rgb(36, 39, 46)`,`rgb(12, 48, 110)`,`rgb(10, 65, 92)`,`rgb(24, 78, 50)`,`rgb(88, 17, 14)`,`rgb(92, 48, 10)`,`rgb(102, 82, 0)`,`rgb(59, 21, 81)`]],o=new Set([t.tableCellInner]),s=e=>o.has(e.statics.blotName);function c(e){return e?.parent?s(e.parent)?!0:c(e.parent):!1}function l(e,t=`table-up`){let n=t?`${t}-`:``;return{b:()=>`${n}${e}`,be:t=>t?`${n}${e}__${t}`:``,bm:t=>t?`${n}${e}--${t}`:``,bem:(t,r)=>t&&r?`${n}${e}__${t}--${r}`:``,ns:e=>e?`${n}${e}`:``,bs:t=>t?`${n}${e}-${t}`:``,cv:e=>e?`--${n}${e}`:``,is:e=>`is-${e}`}}function u(e,t){let n=e.parent;for(;n&&n.statics.blotName!==t&&n!==e.scroll;)n=n.parent;if(n===e.scroll)throw Error(`${e.statics.blotName} must be a child of ${t}`);return n}function d(e,t){let n=Array(t.length),r=new Map(t.map((e,t)=>[e,t])),i=e.parent;for(;i&&i!==e.scroll&&r.size!==0;){if(r.has(i.statics.blotName)){let e=r.get(i.statics.blotName);n[e]=i,r.delete(i.statics.blotName)}i=i.parent}if(r.size>0)throw Error(`${e.statics.blotName} must be a child of ${Array.from(r.keys()).join(`, `)}`);return n}function f(e){let t=new Map,n=e;for(;n&&n.statics.blotName!==`scroll`;)t.set(n.statics.blotName,n),n=n.parent;return t}function p(e,t){let n=[],r=e.children.iterator(),i=null;for(;i=r();)i instanceof t&&n.push(i);return n}function m(e,t,n){for(let r of Object.getOwnPropertyNames(t))n?.test(r)||Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r));return e}function h(e,t){let n=class extends e{};for(let e of t)m(n.prototype,e.prototype,/^constructor$/);return n}function g(e,t){return e.prototype&&e.prototype instanceof t}function _(e,t){return e=Math.min(t,Math.max(0,Number.parseFloat(`${e}`))),Math.abs(e-t)<1e-6?1:e%t/Number.parseFloat(t)}function v(e){return{h:Math.min(360,Math.max(0,e.h)),s:Math.min(100,Math.max(0,e.s)),b:Math.min(100,Math.max(0,e.b)),a:Math.min(1,Math.max(0,e.a))}}function y(e){return e=e.startsWith(`#`)?e.slice(1):e,{r:Number.parseInt(e.slice(0,2),16),g:Number.parseInt(e.slice(2,4),16),b:Number.parseInt(e.slice(4,6),16),a:Number((Number.parseInt(e.slice(6,8)||`ff`,16)/255).toFixed(2))}}function b(e){let{r:t,g:n,b:r,a:i}=e;t=_(t,255),n=_(n,255),r=_(r,255);let a=Math.max(t,n,r),o=Math.min(t,n,r),s,c=a,l=a-o,u=a===0?0:l/a;if(a===o)s=0;else{switch(a){case t:s=(n-r)/l+(n<r?6:0);break;case n:s=(r-t)/l+2;break;case r:s=(t-n)/l+4;break}s/=6}return{h:s*360,s:u*100,b:c*100,a:i}}function ee(e){let{h:t,s:n,b:r,a:i}=e;t=_(t,360)*6,n=_(n,100),r=_(r,100);let a=Math.floor(t),o=t-a,s=r*(1-n),c=r*(1-o*n),l=r*(1-(1-o)*n),u=a%6,d=[r,c,s,s,l,r][u],f=[l,r,r,c,s,s][u],p=[s,s,l,r,r,c][u];return{r:Math.round(d*255),g:Math.round(f*255),b:Math.round(p*255),a:i}}function te(e){let t=[e.r.toString(16),e.g.toString(16),e.b.toString(16),Math.round(e.a*255).toString(16)];for(let e in t)t[e].length===1&&(t[e]=`0${t[e]}`);return t.join(``)}const ne=e=>te(ee(e)),x=e=>typeof e==`function`,S=Array.isArray,C=e=>typeof e==`string`,re=e=>typeof e==`number`,ie=e=>typeof e==`object`&&!!e,ae=e=>e===void 0,oe=e=>!Number.isNaN(e)&&Number(e)>0,se=e=>S(e)?e:[e];function ce(e){let{type:t=`default`,content:n}=e||{},r=l(`button`),i=document.createElement(`button`);return i.classList.add(r.b(),t),n&&(C(n)?i.textContent=n:i.appendChild(n)),i}function le(e={}){let t=b(y(e.color||`#ff0000`)),n=l(`color-picker`),r=document.createElement(`div`);r.classList.add(n.b());let i=document.createElement(`div`);i.classList.add(n.be(`content`));let a=document.createElement(`div`);a.classList.add(n.be(`selector`));let o=document.createElement(`div`);o.classList.add(n.be(`background`)),a.appendChild(o);let s=document.createElement(`div`);s.classList.add(n.be(`background-handle`)),o.appendChild(s);let c=document.createElement(`div`);c.classList.add(n.be(`alpha`));let u=document.createElement(`div`);u.classList.add(n.be(`alpha-bg`));let d=document.createElement(`div`);d.classList.add(n.be(`alpha-handle`)),c.appendChild(u),c.appendChild(d);let f=document.createElement(`div`);f.classList.add(n.be(`hue`));let p=document.createElement(`div`);p.classList.add(n.be(`hue-handle`)),f.appendChild(p);let m=document.createElement(`div`);m.classList.add(n.be(`action`));let[h,g,_,x]=[`r`,`g`,`b`,`a`].map(e=>{let r=document.createElement(`div`);r.classList.add(n.be(`action-item`),e);let i=document.createElement(`label`);i.textContent=e.toUpperCase();let a=document.createElement(`input`);return a.classList.add(n.be(`input`)),a.addEventListener(`input`,()=>{a.value=a.value.replaceAll(/[^0-9]/g,``)}),a.addEventListener(`change`,()=>{let n=Math.round(Number(a.value));e===`a`&&(n/=100),de(v(b(Object.assign({},ee(t),{[e]:n})))),ue()}),r.appendChild(i),r.appendChild(a),m.appendChild(r),a});i.appendChild(f),i.appendChild(a),i.appendChild(c),r.appendChild(i),r.appendChild(m);let S=!1,C=!1,re=!1;function ie(){let e=ne(t);for(let[t,n]of[h,g,_].entries())n.value=String(Number.parseInt(e[t*2]+e[t*2+1],16));x.value=String((t.a*100).toFixed(0))}function ae(){Object.assign(s.style,{left:`${Math.floor(230*t.s/100)}px`,top:`${Math.floor(150*(100-t.b)/100)}px`})}function oe(){a.style.backgroundColor=`#${te(ee({h:t.h,s:100,b:100,a:1}))}`}function se(){p.style.top=`${Math.floor(150-150*t.h/360)}px`}function ce(){d.style.left=`${t.a*100}%`}function le(){let{r:e,g:n,b:r}=ee(t);u.style.background=`linear-gradient(to right, rgba(${e}, ${n}, ${r}, 0) 0%, rgba(${e}, ${n}, ${r}, 1) 100%)`}function ue(){ae(),oe(),se(),ce(),le(),ie()}function de(n){t=v(Object.assign({},t,n)),ie(),e.onChange&&e.onChange(`#${ne(t)}`)}function fe(e){let t=a.getBoundingClientRect(),n=t.top+(window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0),r=t.left+document.body.scrollLeft;de({s:Math.floor(100*Math.max(0,Math.min(230,e.pageX-r))/230),b:Math.floor(100*(150-Math.max(0,Math.min(150,e.pageY-n)))/150)}),ue()}function pe(e){let t=f.getBoundingClientRect().top+(window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0);de({h:Math.floor(360*(150-Math.max(0,Math.min(150,e.pageY-t)))/150)}),ue()}function me(e){let{pageX:t}=e,n=c.getBoundingClientRect(),r=t-n.left;r=Math.max(10/2,r),r=Math.min(r,n.width-10/2),de({a:Math.round((r-10/2)/(n.width-10)*100)/100}),ue()}function w(e){S&&(e.preventDefault(),fe(e)),C&&(e.preventDefault(),pe(e)),re&&(e.preventDefault(),me(e))}function he(){document.removeEventListener(`mousemove`,w),document.removeEventListener(`mouseup`,he),S=!1}function T(e){document.addEventListener(`mousemove`,w),document.addEventListener(`mouseup`,he),S=!0,fe(e)}a.addEventListener(`mousedown`,T);function ge(){document.removeEventListener(`mousemove`,w),document.removeEventListener(`mouseup`,ge),C=!1}function _e(e){document.addEventListener(`mousemove`,w),document.addEventListener(`mouseup`,ge),C=!0,pe(e)}f.addEventListener(`mousedown`,_e);function E(){document.removeEventListener(`mousemove`,w),document.removeEventListener(`mouseup`,E),re=!1}function ve(e){document.addEventListener(`mousemove`,w),document.addEventListener(`mouseup`,E),re=!0,me(e)}return c.addEventListener(`mousedown`,ve),ue(),r}let ue=8e3;function de({child:e,target:t=document.body,beforeClose:n=()=>{}}={}){let r=l(`dialog`),i=t,a=document.createElement(`div`);a.classList.add(r.b()),a.style.zIndex=String(ue);let o=document.createElement(`div`);if(o.classList.add(r.be(`overlay`)),a.appendChild(o),e){let t=document.createElement(`div`);t.classList.add(r.be(`content`)),t.appendChild(e),o.appendChild(t),t.addEventListener(`click`,e=>{e.stopPropagation()})}let s=getComputedStyle(i).overflow;i.style.overflow=`hidden`,i.appendChild(a);let c=()=>{n(),a.remove(),i.style.overflow=s};return a.addEventListener(`click`,c),ue+=1,{dialog:a,close:c}}async function fe({message:e,confirm:t,cancel:n}){return new Promise(r=>{let i=document.createElement(`div`);Object.assign(i.style,{padding:`8px 12px`,fontSize:`14px`,lineHeight:`1.5`});let a=document.createElement(`p`);a.textContent=e;let o=document.createElement(`div`);Object.assign(o.style,{display:`flex`,justifyContent:`flex-end`,gap:`6px`});let s=ce({content:n}),c=ce({type:`confirm`,content:t});o.appendChild(s),o.appendChild(c),i.appendChild(a),i.appendChild(o);let{close:l}=de({child:i});s.addEventListener(`click`,()=>{r(!1),l()}),c.addEventListener(`click`,()=>{r(!0),l()})})}function pe(e,t){let n=l(`input`);t.type||=`text`,t.value||=``;let r=document.createElement(`div`);if(r.classList.add(n.be(`item`)),e){let t=document.createElement(`span`);t.classList.add(n.be(`label`)),t.textContent=e,r.appendChild(t)}let i=document.createElement(`div`);i.classList.add(n.be(`input`));let a=document.createElement(`input`);for(let e in t)a.setAttribute(e,t[e]);return(t.max||t.min)&&a.addEventListener(`blur`,()=>{t.max&&t.max<=Number(a.value)&&(a.value=String(t.max)),t.min&&t.min>=Number(a.value)&&(a.value=String(t.min))}),i.appendChild(a),r.appendChild(i),a.addEventListener(`focus`,()=>{i.classList.add(`focus`)}),a.addEventListener(`blur`,()=>{i.classList.remove(`focus`)}),{item:r,input:a,errorTip:e=>{let t;return i.classList.contains(`error`)?t=i.querySelector(`.${n.be(`error-tip`)}`):(t=document.createElement(`span`),t.classList.add(n.be(`error-tip`)),i.appendChild(t)),t.textContent=e,i.classList.add(`error`),{removeError:()=>{i.classList.remove(`error`),t.remove()}}}}}async function me(e={}){let t=l(`creator`),n=document.createElement(`div`);n.classList.add(t.b());let r=document.createElement(`div`);r.classList.add(t.be(`input`));let{item:i,input:a,errorTip:o}=pe(e.rowText||`Row`,{type:`number`,value:String(e.row||``),max:99}),{item:s,input:c,errorTip:u}=pe(e.colText||`Column`,{type:`number`,value:String(e.col||``),max:99});r.appendChild(i),r.appendChild(s),n.appendChild(r);let d=document.createElement(`div`);d.classList.add(t.be(`control`));let f=ce({type:`confirm`,content:e.confirmText||`Confirm`}),p=ce({type:`default`,content:e.cancelText||`Cancel`});d.appendChild(f),d.appendChild(p),n.appendChild(d);let m=(t=Number(a.value),n=Number(c.value))=>{if(Number.isNaN(t)||t<=0){o(e.notPositiveNumberError||`Please enter a positive integer`);return}if(Number.isNaN(n)||n<=0){u(e.notPositiveNumberError||`Please enter a positive integer`);return}return{row:t,col:n}},h=e=>{e.key===`Escape`&&(close(),document.removeEventListener(`keydown`,h))};return new Promise((e,t)=>{let{close:r}=de({child:n,beforeClose:t});a.focus();for(let t of[a,c])t.addEventListener(`keydown`,t=>{if(t.key===`Enter`){let t=m();t&&(e(t),r())}});f.addEventListener(`click`,()=>{let t=m();t&&(e(t),r())}),document.addEventListener(`keydown`,h),p.addEventListener(`click`,r)}).finally(()=>{document.removeEventListener(`keydown`,h)})}function w(e={}){let t=l(`select-box`),n=document.createElement(`span`);n.classList.add(t.b());let r=document.createElement(`span`);r.classList.add(t.be(`block`));for(let n=0;n<(e.row||8);n++)for(let i=0;i<(e.col||8);i++){let e=document.createElement(`span`);e.classList.add(t.be(`item`)),e.dataset.row=String(n+1),e.dataset.col=String(i+1),r.appendChild(e)}let i=()=>{let{row:e,col:t}=n.dataset;for(let e of Array.from(r.querySelectorAll(`.active`)))e.classList.remove(`active`);if(!e||!t)return;let i=Array.from(r.children);for(let n of i){let{row:r,col:i}=n.dataset;if(r>e&&i>t)return;n.classList.toggle(`active`,r<=e&&i<=t)}};if(r.addEventListener(`mousemove`,e=>{if(!e.target)return;let{row:t,col:r}=e.target.dataset;!t||!r||(n.dataset.row=t,n.dataset.col=r,i())}),r.addEventListener(`mouseleave`,()=>{n.removeAttribute(`data-row`),n.removeAttribute(`data-col`),i()}),r.addEventListener(`click`,()=>{let{row:t,col:r}=n.dataset;!t||!r||e.onSelect?.(Number(t),Number(r))}),n.appendChild(r),e.customBtn){let r=e.texts||{},i=document.createElement(`span`);i.classList.add(t.be(`custom`)),i.textContent=r.customBtnText||`Custom`,i.addEventListener(`click`,async()=>{let t=await me(r);t&&e.onSelect?.(t.row,t.col)}),n.appendChild(i)}return n}const he=Math.min,T=Math.max,ge=Math.round,_e=Math.floor,E=e=>({x:e,y:e}),ve={left:`right`,right:`left`,bottom:`top`,top:`bottom`},ye={start:`end`,end:`start`};function be(e,t,n){return T(e,he(t,n))}function xe(e,t){return typeof e==`function`?e(t):e}function D(e){return e.split(`-`)[0]}function Se(e){return e.split(`-`)[1]}function Ce(e){return e===`x`?`y`:`x`}function we(e){return e===`y`?`height`:`width`}const Te=new Set([`top`,`bottom`]);function O(e){return Te.has(D(e))?`y`:`x`}function Ee(e){return Ce(O(e))}function De(e,t,n){n===void 0&&(n=!1);let r=Se(e),i=Ee(e),a=we(i),o=i===`x`?r===(n?`end`:`start`)?`right`:`left`:r===`start`?`bottom`:`top`;return t.reference[a]>t.floating[a]&&(o=Ie(o)),[o,Ie(o)]}function Oe(e){let t=Ie(e);return[ke(e),t,ke(t)]}function ke(e){return e.replace(/start|end/g,e=>ye[e])}const Ae=[`left`,`right`],je=[`right`,`left`],Me=[`top`,`bottom`],Ne=[`bottom`,`top`];function Pe(e,t,n){switch(e){case`top`:case`bottom`:return n?t?je:Ae:t?Ae:je;case`left`:case`right`:return t?Me:Ne;default:return[]}}function Fe(e,t,n,r){let i=Se(e),a=Pe(D(e),n===`start`,r);return i&&(a=a.map(e=>e+`-`+i),t&&(a=a.concat(a.map(ke)))),a}function Ie(e){return e.replace(/left|right|bottom|top/g,e=>ve[e])}function Le(e){return{top:0,right:0,bottom:0,left:0,...e}}function Re(e){return typeof e==`number`?{top:e,right:e,bottom:e,left:e}:Le(e)}function ze(e){let{x:t,y:n,width:r,height:i}=e;return{width:r,height:i,top:n,left:t,right:t+r,bottom:n+i,x:t,y:n}}function Be(e,t,n){let{reference:r,floating:i}=e,a=O(t),o=Ee(t),s=we(o),c=D(t),l=a===`y`,u=r.x+r.width/2-i.width/2,d=r.y+r.height/2-i.height/2,f=r[s]/2-i[s]/2,p;switch(c){case`top`:p={x:u,y:r.y-i.height};break;case`bottom`:p={x:u,y:r.y+r.height};break;case`right`:p={x:r.x+r.width,y:d};break;case`left`:p={x:r.x-i.width,y:d};break;default:p={x:r.x,y:r.y}}switch(Se(t)){case`start`:p[o]-=f*(n&&l?-1:1);break;case`end`:p[o]+=f*(n&&l?-1:1);break}return p}async function Ve(e,t){t===void 0&&(t={});let{x:n,y:r,platform:i,rects:a,elements:o,strategy:s}=e,{boundary:c=`clippingAncestors`,rootBoundary:l=`viewport`,elementContext:u=`floating`,altBoundary:d=!1,padding:f=0}=xe(t,e),p=Re(f),m=o[d?u===`floating`?`reference`:`floating`:u],h=ze(await i.getClippingRect({element:await(i.isElement==null?void 0:i.isElement(m))??!0?m:m.contextElement||await(i.getDocumentElement==null?void 0:i.getDocumentElement(o.floating)),boundary:c,rootBoundary:l,strategy:s})),g=u===`floating`?{x:n,y:r,width:a.floating.width,height:a.floating.height}:a.reference,_=await(i.getOffsetParent==null?void 0:i.getOffsetParent(o.floating)),v=await(i.isElement==null?void 0:i.isElement(_))&&await(i.getScale==null?void 0:i.getScale(_))||{x:1,y:1},y=ze(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:o,rect:g,offsetParent:_,strategy:s}):g);return{top:(h.top-y.top+p.top)/v.y,bottom:(y.bottom-h.bottom+p.bottom)/v.y,left:(h.left-y.left+p.left)/v.x,right:(y.right-h.right+p.right)/v.x}}const He=async(e,t,n)=>{let{placement:r=`bottom`,strategy:i=`absolute`,middleware:a=[],platform:o}=n,s=a.filter(Boolean),c=await(o.isRTL==null?void 0:o.isRTL(t)),l=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:u,y:d}=Be(l,r,c),f=r,p={},m=0;for(let n=0;n<s.length;n++){let{name:a,fn:h}=s[n],{x:g,y:_,data:v,reset:y}=await h({x:u,y:d,initialPlacement:r,placement:f,strategy:i,middlewareData:p,rects:l,platform:{...o,detectOverflow:o.detectOverflow??Ve},elements:{reference:e,floating:t}});u=g??u,d=_??d,p={...p,[a]:{...p[a],...v}},y&&m<=50&&(m++,typeof y==`object`&&(y.placement&&(f=y.placement),y.rects&&(l=y.rects===!0?await o.getElementRects({reference:e,floating:t,strategy:i}):y.rects),{x:u,y:d}=Be(l,f,c)),n=-1)}return{x:u,y:d,placement:f,strategy:i,middlewareData:p}},Ue=function(e){return e===void 0&&(e={}),{name:`flip`,options:e,async fn(t){var n;let{placement:r,middlewareData:i,rects:a,initialPlacement:o,platform:s,elements:c}=t,{mainAxis:l=!0,crossAxis:u=!0,fallbackPlacements:d,fallbackStrategy:f=`bestFit`,fallbackAxisSideDirection:p=`none`,flipAlignment:m=!0,...h}=xe(e,t);if((n=i.arrow)!=null&&n.alignmentOffset)return{};let g=D(r),_=O(o),v=D(o)===o,y=await(s.isRTL==null?void 0:s.isRTL(c.floating)),b=d||(v||!m?[Ie(o)]:Oe(o)),ee=p!==`none`;!d&&ee&&b.push(...Fe(o,m,p,y));let te=[o,...b],ne=await s.detectOverflow(t,h),x=[],S=i.flip?.overflows||[];if(l&&x.push(ne[g]),u){let e=De(r,a,y);x.push(ne[e[0]],ne[e[1]])}if(S=[...S,{placement:r,overflows:x}],!x.every(e=>e<=0)){let e=(i.flip?.index||0)+1,t=te[e];if(t&&(!(u===`alignment`&&_!==O(t))||S.every(e=>O(e.placement)===_?e.overflows[0]>0:!0)))return{data:{index:e,overflows:S},reset:{placement:t}};let n=S.filter(e=>e.overflows[0]<=0).sort((e,t)=>e.overflows[1]-t.overflows[1])[0]?.placement;if(!n)switch(f){case`bestFit`:{let e=S.filter(e=>{if(ee){let t=O(e.placement);return t===_||t===`y`}return!0}).map(e=>[e.placement,e.overflows.filter(e=>e>0).reduce((e,t)=>e+t,0)]).sort((e,t)=>e[1]-t[1])[0]?.[0];e&&(n=e);break}case`initialPlacement`:n=o;break}if(r!==n)return{reset:{placement:n}}}return{}}}},We=new Set([`left`,`top`]);async function Ge(e,t){let{placement:n,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=D(n),s=Se(n),c=O(n)===`y`,l=We.has(o)?-1:1,u=a&&c?-1:1,d=xe(t,e),{mainAxis:f,crossAxis:p,alignmentAxis:m}=typeof d==`number`?{mainAxis:d,crossAxis:0,alignmentAxis:null}:{mainAxis:d.mainAxis||0,crossAxis:d.crossAxis||0,alignmentAxis:d.alignmentAxis};return s&&typeof m==`number`&&(p=s===`end`?m*-1:m),c?{x:p*u,y:f*l}:{x:f*l,y:p*u}}const Ke=function(e){return e===void 0&&(e=0),{name:`offset`,options:e,async fn(t){var n;let{x:r,y:i,placement:a,middlewareData:o}=t,s=await Ge(t,e);return a===o.offset?.placement&&(n=o.arrow)!=null&&n.alignmentOffset?{}:{x:r+s.x,y:i+s.y,data:{...s,placement:a}}}}},qe=function(e){return e===void 0&&(e={}),{name:`shift`,options:e,async fn(t){let{x:n,y:r,placement:i,platform:a}=t,{mainAxis:o=!0,crossAxis:s=!1,limiter:c={fn:e=>{let{x:t,y:n}=e;return{x:t,y:n}}},...l}=xe(e,t),u={x:n,y:r},d=await a.detectOverflow(t,l),f=O(D(i)),p=Ce(f),m=u[p],h=u[f];if(o){let e=p===`y`?`top`:`left`,t=p===`y`?`bottom`:`right`,n=m+d[e],r=m-d[t];m=be(n,m,r)}if(s){let e=f===`y`?`top`:`left`,t=f===`y`?`bottom`:`right`,n=h+d[e],r=h-d[t];h=be(n,h,r)}let g=c.fn({...t,[p]:m,[f]:h});return{...g,data:{x:g.x-n,y:g.y-r,enabled:{[p]:o,[f]:s}}}}}},Je=function(e){return e===void 0&&(e={}),{options:e,fn(t){let{x:n,y:r,placement:i,rects:a,middlewareData:o}=t,{offset:s=0,mainAxis:c=!0,crossAxis:l=!0}=xe(e,t),u={x:n,y:r},d=O(i),f=Ce(d),p=u[f],m=u[d],h=xe(s,t),g=typeof h==`number`?{mainAxis:h,crossAxis:0}:{mainAxis:0,crossAxis:0,...h};if(c){let e=f===`y`?`height`:`width`,t=a.reference[f]-a.floating[e]+g.mainAxis,n=a.reference[f]+a.reference[e]-g.mainAxis;p<t?p=t:p>n&&(p=n)}if(l){let e=f===`y`?`width`:`height`,t=We.has(D(i)),n=a.reference[d]-a.floating[e]+(t&&o.offset?.[d]||0)+(t?0:g.crossAxis),r=a.reference[d]+a.reference[e]+(t?0:o.offset?.[d]||0)-(t?g.crossAxis:0);m<n?m=n:m>r&&(m=r)}return{[f]:p,[d]:m}}}};function Ye(){return typeof window<`u`}function Xe(e){return Ze(e)?(e.nodeName||``).toLowerCase():`#document`}function k(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function A(e){return((Ze(e)?e.ownerDocument:e.document)||window.document)?.documentElement}function Ze(e){return Ye()?e instanceof Node||e instanceof k(e).Node:!1}function j(e){return Ye()?e instanceof Element||e instanceof k(e).Element:!1}function M(e){return Ye()?e instanceof HTMLElement||e instanceof k(e).HTMLElement:!1}function Qe(e){return!Ye()||typeof ShadowRoot>`u`?!1:e instanceof ShadowRoot||e instanceof k(e).ShadowRoot}const $e=new Set([`inline`,`contents`]);function et(e){let{overflow:t,overflowX:n,overflowY:r,display:i}=N(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!$e.has(i)}const tt=new Set([`table`,`td`,`th`]);function nt(e){return tt.has(Xe(e))}const rt=[`:popover-open`,`:modal`];function it(e){return rt.some(t=>{try{return e.matches(t)}catch{return!1}})}const at=[`transform`,`translate`,`scale`,`rotate`,`perspective`],ot=[`transform`,`translate`,`scale`,`rotate`,`perspective`,`filter`],st=[`paint`,`layout`,`strict`,`content`];function ct(e){let t=ut(),n=j(e)?N(e):e;return at.some(e=>n[e]?n[e]!==`none`:!1)||(n.containerType?n.containerType!==`normal`:!1)||!t&&(n.backdropFilter?n.backdropFilter!==`none`:!1)||!t&&(n.filter?n.filter!==`none`:!1)||ot.some(e=>(n.willChange||``).includes(e))||st.some(e=>(n.contain||``).includes(e))}function lt(e){let t=P(e);for(;M(t)&&!ft(t);){if(ct(t))return t;if(it(t))return null;t=P(t)}return null}function ut(){return typeof CSS>`u`||!CSS.supports?!1:CSS.supports(`-webkit-backdrop-filter`,`none`)}const dt=new Set([`html`,`body`,`#document`]);function ft(e){return dt.has(Xe(e))}function N(e){return k(e).getComputedStyle(e)}function pt(e){return j(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function P(e){if(Xe(e)===`html`)return e;let t=e.assignedSlot||e.parentNode||Qe(e)&&e.host||A(e);return Qe(t)?t.host:t}function mt(e){let t=P(e);return ft(t)?e.ownerDocument?e.ownerDocument.body:e.body:M(t)&&et(t)?t:mt(t)}function ht(e,t,n){t===void 0&&(t=[]),n===void 0&&(n=!0);let r=mt(e),i=r===e.ownerDocument?.body,a=k(r);if(i){let e=gt(a);return t.concat(a,a.visualViewport||[],et(r)?r:[],e&&n?ht(e):[])}return t.concat(r,ht(r,[],n))}function gt(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function _t(e){let t=N(e),n=parseFloat(t.width)||0,r=parseFloat(t.height)||0,i=M(e),a=i?e.offsetWidth:n,o=i?e.offsetHeight:r,s=ge(n)!==a||ge(r)!==o;return s&&(n=a,r=o),{width:n,height:r,$:s}}function vt(e){return j(e)?e:e.contextElement}function yt(e){let t=vt(e);if(!M(t))return E(1);let n=t.getBoundingClientRect(),{width:r,height:i,$:a}=_t(t),o=(a?ge(n.width):n.width)/r,s=(a?ge(n.height):n.height)/i;return(!o||!Number.isFinite(o))&&(o=1),(!s||!Number.isFinite(s))&&(s=1),{x:o,y:s}}const bt=E(0);function xt(e){let t=k(e);return!ut()||!t.visualViewport?bt:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function St(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==k(e)?!1:t}function Ct(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);let i=e.getBoundingClientRect(),a=vt(e),o=E(1);t&&(r?j(r)&&(o=yt(r)):o=yt(e));let s=St(a,n,r)?xt(a):E(0),c=(i.left+s.x)/o.x,l=(i.top+s.y)/o.y,u=i.width/o.x,d=i.height/o.y;if(a){let e=k(a),t=r&&j(r)?k(r):r,n=e,i=gt(n);for(;i&&r&&t!==n;){let e=yt(i),t=i.getBoundingClientRect(),r=N(i),a=t.left+(i.clientLeft+parseFloat(r.paddingLeft))*e.x,o=t.top+(i.clientTop+parseFloat(r.paddingTop))*e.y;c*=e.x,l*=e.y,u*=e.x,d*=e.y,c+=a,l+=o,n=k(i),i=gt(n)}}return ze({width:u,height:d,x:c,y:l})}function wt(e,t){let n=pt(e).scrollLeft;return t?t.left+n:Ct(A(e)).left+n}function Tt(e,t){let n=e.getBoundingClientRect();return{x:n.left+t.scrollLeft-wt(e,n),y:n.top+t.scrollTop}}function Et(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e,a=i===`fixed`,o=A(r),s=t?it(t.floating):!1;if(r===o||s&&a)return n;let c={scrollLeft:0,scrollTop:0},l=E(1),u=E(0),d=M(r);if((d||!d&&!a)&&((Xe(r)!==`body`||et(o))&&(c=pt(r)),M(r))){let e=Ct(r);l=yt(r),u.x=e.x+r.clientLeft,u.y=e.y+r.clientTop}let f=o&&!d&&!a?Tt(o,c):E(0);return{width:n.width*l.x,height:n.height*l.y,x:n.x*l.x-c.scrollLeft*l.x+u.x+f.x,y:n.y*l.y-c.scrollTop*l.y+u.y+f.y}}function Dt(e){return Array.from(e.getClientRects())}function Ot(e){let t=A(e),n=pt(e),r=e.ownerDocument.body,i=T(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),a=T(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight),o=-n.scrollLeft+wt(e),s=-n.scrollTop;return N(r).direction===`rtl`&&(o+=T(t.clientWidth,r.clientWidth)-i),{width:i,height:a,x:o,y:s}}function kt(e,t){let n=k(e),r=A(e),i=n.visualViewport,a=r.clientWidth,o=r.clientHeight,s=0,c=0;if(i){a=i.width,o=i.height;let e=ut();(!e||e&&t===`fixed`)&&(s=i.offsetLeft,c=i.offsetTop)}let l=wt(r);if(l<=0){let e=r.ownerDocument,t=e.body,n=getComputedStyle(t),i=e.compatMode===`CSS1Compat`&&parseFloat(n.marginLeft)+parseFloat(n.marginRight)||0,o=Math.abs(r.clientWidth-t.clientWidth-i);o<=25&&(a-=o)}else l<=25&&(a+=l);return{width:a,height:o,x:s,y:c}}const At=new Set([`absolute`,`fixed`]);function jt(e,t){let n=Ct(e,!0,t===`fixed`),r=n.top+e.clientTop,i=n.left+e.clientLeft,a=M(e)?yt(e):E(1);return{width:e.clientWidth*a.x,height:e.clientHeight*a.y,x:i*a.x,y:r*a.y}}function Mt(e,t,n){let r;if(t===`viewport`)r=kt(e,n);else if(t===`document`)r=Ot(A(e));else if(j(t))r=jt(t,n);else{let n=xt(e);r={x:t.x-n.x,y:t.y-n.y,width:t.width,height:t.height}}return ze(r)}function Nt(e,t){let n=P(e);return n===t||!j(n)||ft(n)?!1:N(n).position===`fixed`||Nt(n,t)}function Pt(e,t){let n=t.get(e);if(n)return n;let r=ht(e,[],!1).filter(e=>j(e)&&Xe(e)!==`body`),i=null,a=N(e).position===`fixed`,o=a?P(e):e;for(;j(o)&&!ft(o);){let t=N(o),n=ct(o);!n&&t.position===`fixed`&&(i=null),(a?!n&&!i:!n&&t.position===`static`&&i&&At.has(i.position)||et(o)&&!n&&Nt(e,o))?r=r.filter(e=>e!==o):i=t,o=P(o)}return t.set(e,r),r}function Ft(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e,a=[...n===`clippingAncestors`?it(t)?[]:Pt(t,this._c):[].concat(n),r],o=a[0],s=a.reduce((e,n)=>{let r=Mt(t,n,i);return e.top=T(r.top,e.top),e.right=he(r.right,e.right),e.bottom=he(r.bottom,e.bottom),e.left=T(r.left,e.left),e},Mt(t,o,i));return{width:s.right-s.left,height:s.bottom-s.top,x:s.left,y:s.top}}function It(e){let{width:t,height:n}=_t(e);return{width:t,height:n}}function Lt(e,t,n){let r=M(t),i=A(t),a=n===`fixed`,o=Ct(e,!0,a,t),s={scrollLeft:0,scrollTop:0},c=E(0);function l(){c.x=wt(i)}if(r||!r&&!a)if((Xe(t)!==`body`||et(i))&&(s=pt(t)),r){let e=Ct(t,!0,a,t);c.x=e.x+t.clientLeft,c.y=e.y+t.clientTop}else i&&l();a&&!r&&i&&l();let u=i&&!r&&!a?Tt(i,s):E(0);return{x:o.left+s.scrollLeft-c.x-u.x,y:o.top+s.scrollTop-c.y-u.y,width:o.width,height:o.height}}function Rt(e){return N(e).position===`static`}function zt(e,t){if(!M(e)||N(e).position===`fixed`)return null;if(t)return t(e);let n=e.offsetParent;return A(e)===n&&(n=n.ownerDocument.body),n}function Bt(e,t){let n=k(e);if(it(e))return n;if(!M(e)){let t=P(e);for(;t&&!ft(t);){if(j(t)&&!Rt(t))return t;t=P(t)}return n}let r=zt(e,t);for(;r&&nt(r)&&Rt(r);)r=zt(r,t);return r&&ft(r)&&Rt(r)&&!ct(r)?n:r||lt(e)||n}const Vt=async function(e){let t=this.getOffsetParent||Bt,n=this.getDimensions,r=await n(e.floating);return{reference:Lt(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Ht(e){return N(e).direction===`rtl`}const Ut={convertOffsetParentRelativeRectToViewportRelativeRect:Et,getDocumentElement:A,getClippingRect:Ft,getOffsetParent:Bt,getElementRects:Vt,getClientRects:Dt,getDimensions:It,getScale:yt,isElement:j,isRTL:Ht};function Wt(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function Gt(e,t){let n=null,r,i=A(e);function a(){var e;clearTimeout(r),(e=n)==null||e.disconnect(),n=null}function o(s,c){s===void 0&&(s=!1),c===void 0&&(c=1),a();let l=e.getBoundingClientRect(),{left:u,top:d,width:f,height:p}=l;if(s||t(),!f||!p)return;let m=_e(d),h=_e(i.clientWidth-(u+f)),g=_e(i.clientHeight-(d+p)),_=_e(u),v={rootMargin:-m+`px `+-h+`px `+-g+`px `+-_+`px`,threshold:T(0,he(1,c))||1},y=!0;function b(t){let n=t[0].intersectionRatio;if(n!==c){if(!y)return o();n?o(!1,n):r=setTimeout(()=>{o(!1,1e-7)},1e3)}n===1&&!Wt(l,e.getBoundingClientRect())&&o(),y=!1}try{n=new IntersectionObserver(b,{...v,root:i.ownerDocument})}catch{n=new IntersectionObserver(b,v)}n.observe(e)}return o(!0),a}function Kt(e,t,n,r){r===void 0&&(r={});let{ancestorScroll:i=!0,ancestorResize:a=!0,elementResize:o=typeof ResizeObserver==`function`,layoutShift:s=typeof IntersectionObserver==`function`,animationFrame:c=!1}=r,l=vt(e),u=i||a?[...l?ht(l):[],...ht(t)]:[];u.forEach(e=>{i&&e.addEventListener(`scroll`,n,{passive:!0}),a&&e.addEventListener(`resize`,n)});let d=l&&s?Gt(l,n):null,f=-1,p=null;o&&(p=new ResizeObserver(e=>{let[r]=e;r&&r.target===l&&p&&(p.unobserve(t),cancelAnimationFrame(f),f=requestAnimationFrame(()=>{var e;(e=p)==null||e.observe(t)})),n()}),l&&!c&&p.observe(l),p.observe(t));let m,h=c?Ct(e):null;c&&g();function g(){let t=Ct(e);h&&!Wt(h,t)&&n(),h=t,m=requestAnimationFrame(g)}return n(),()=>{var e;u.forEach(e=>{i&&e.removeEventListener(`scroll`,n),a&&e.removeEventListener(`resize`,n)}),d?.(),(e=p)==null||e.disconnect(),p=null,c&&cancelAnimationFrame(m)}}const qt=Ke,Jt=qe,Yt=Ue,Xt=Je,Zt=(e,t,n)=>{let r=new Map,i={platform:Ut,...n},a={...i.platform,_c:r};return He(e,t,{...i,platform:a})};function Qt(e,t,n,r,i){return i&&clearTimeout(i),e.addEventListener(`transitionend`,n,r),setTimeout(()=>{n()},t)}function $t(e,t={}){let{msg:n=``,delay:r=150,content:i,direction:a=`bottom`,type:o=`hover`,container:s,onOpen:c,onClose:u,closed:d,onDestroy:f}=t,p=l(`tooltip`);if(n||i){let t=s||document.body,l=document.createElement(`div`);l.classList.add(p.b(),`hidden`,`transparent`),i?l.appendChild(i):n&&(l.textContent=n);let m,h,g,_=()=>{g&&g(),Zt(e,l,{placement:a,middleware:[Yt(),Jt({limiter:Xt()}),qt(4)]}).then(({x:e,y:t})=>{Object.assign(l.style,{left:`${e}px`,top:`${t}px`})})},v=()=>{l.classList.add(`hidden`),t.contains(l)&&t.removeChild(l),g&&g(),d&&d()},y=(n=!1)=>{h&&clearTimeout(h),m=setTimeout(()=>{if(c){let e=c(n);if(!n&&e)return}t.appendChild(l),l.removeEventListener(`transitionend`,v),l.classList.remove(`hidden`),g=Kt(e,l,_),l.classList.remove(`transparent`)},r)},b=(e=!1)=>{m&&clearTimeout(m),h=setTimeout(()=>{if(u){let t=u(e);if(!e&&t)return}Qt(l,150,v,{once:!0}),l.classList.add(`transparent`)},r)},{prepare:ee,show:te,hide:ne,destroy:x}={hover:()=>{let t=[e,l],n=b.bind(void 0,!1),r=y.bind(void 0,!1);return{prepare:()=>{for(let e of t)e.addEventListener(`mouseenter`,r),e.addEventListener(`mouseleave`,n)},show:y,hide:b,destroy:()=>{for(let e of t)e.removeEventListener(`mouseenter`,r),e.removeEventListener(`mouseleave`,n)}}},click:()=>{let t=e=>{e.stopPropagation(),b(!1)},n=e=>{e.stopPropagation(),y(),document.removeEventListener(`click`,t),document.addEventListener(`click`,t,{once:!0})};return{prepare:()=>{l.addEventListener(`click`,e=>e.stopPropagation()),e.addEventListener(`click`,n)},show:y,hide:(e=!1)=>{b(e),document.removeEventListener(`click`,t)},destroy:()=>{e.removeEventListener(`click`,n),document.removeEventListener(`click`,t)}}}}[o]();return ee(),{show:te,hide:ne,destroy:()=>{ne(!0),f&&f(),x(),g&&g(),l.remove()}}}return null}function en(e,t={}){let{axis:n=`both`,onMove:r=()=>{},onStart:i=()=>{},onEnd:a=()=>{},buttons:o=[0],container:s,draggingElement:c=document,exact:l=!0}=t,u={x:0,y:0},d,f={x:0,y:0};function p(t){if(!d)return;let r=e.getBoundingClientRect(),{x:i,y:a}=u;(n===`x`||n===`both`)&&(i=t.clientX-d.x,s&&(i=Math.min(Math.max(0,i),s.scrollWidth-r.width))),(n===`y`||n===`both`)&&(a=t.clientY-d.y,s&&(a=Math.min(Math.max(0,a),s.scrollHeight-r.height))),u={x:i,y:a}}function m(t){if(!o.includes(t.button)||l&&t.target!==e)return;c.addEventListener(`pointerup`,g),c.addEventListener(`pointermove`,h);let n=s?.getBoundingClientRect?.(),r=e.getBoundingClientRect(),a={x:t.clientX-(s?r.left-n.left+s.scrollLeft:r.left),y:t.clientY-(s?r.top-n.top+s.scrollTop:r.top)};f={x:t.clientX,y:t.clientY},i({position:u,startPosition:a,movePosition:{x:t.clientX-f.x,y:t.clientY-f.y}},t)!==!1&&(d=a,u=a)}function h(e){d&&(p(e),r({position:u,startPosition:d,movePosition:{x:e.clientX-f.x,y:e.clientY-f.y}},e))}function g(e){c.removeEventListener(`pointermove`,h),c.removeEventListener(`pointerup`,g),p(e),a({position:u,startPosition:d,movePosition:{x:e.clientX-f.x,y:e.clientY-f.y}},e),d=void 0,f={x:0,y:0},u={x:0,y:0}}return c.addEventListener(`pointerdown`,m),{stop:()=>{c.removeEventListener(`pointerdown`,m)}}}function tn(e,t,n=0,r=!0){let{x:i,y:a,x1:o,y1:s}=e,{x:c,y:l,x1:u,y1:d}=t,f,p;return r?(f=o<c+n||i-n>u,p=s<l+n||a-n>d):(f=o<=c+n||i-n>=u,p=s<=l+n||a-n>=d),!(f||p)}function nn(e,t){let n=t.getBoundingClientRect();return{x:e.x-n.x-t.scrollLeft,y:e.y-n.y-t.scrollTop,x1:e.x-n.x-t.scrollLeft+e.width,y1:e.y-n.y-t.scrollTop+e.height,width:e.width,height:e.height}}function rn(e){let{left:t,top:n,width:r,height:i}=e,{clientWidth:a,clientHeight:o}=document.documentElement,s=!1,c=!1;return t+r>a?(t=a-r-8,s=!0):t<0&&(t=8,s=!0),n+i>o?(n=o-i-8,c=!0):n<0&&(n=8,c=!0),{left:t,top:n,leftLimited:s,topLimited:c}}function an(e,t={}){let n=Symbol(`ignoreFirstBind`),r=new Set,i=new ResizeObserver(r=>{t.ignoreFirstBind&&r.some(e=>{let t=e.target,r=t[n];return t[n]=!0,!r})||e(r)}),a=i.observe.bind(i);i.observe=(e,t)=>{r.add(e),a(e,t)};let o=i.unobserve;i.unobserve=e=>{r.has(e)&&(r.delete(e),e[n]=void 0),o.call(i,e)};let s=i.disconnect;return i.disconnect=()=>{for(let e of r.values())e[n]=void 0;s.call(i)},i}function F(e,t){e.addEventListener(`scroll`,t),this.scrollHandler.push([e,t])}function on(e,t){for(let n=0;n<this.scrollHandler.length;n++){let[r,i]=this.scrollHandler[n];if(r===e&&i===t){this.scrollHandler.splice(n,1);break}}}function I(){for(let[e,t]of this.scrollHandler)e.removeEventListener(`scroll`,t);this.scrollHandler=[]}function sn(e){return{y:e.scrollTop,x:e.scrollLeft}}function cn({target:e=document.body}={}){let t=document.createElement(`div`);Object.assign(t.style,{visibility:`hidden`,width:`100px`,height:`100%`,overflow:`auto`,position:`absolute`,top:`-9999px`}),e.appendChild(t);let n=t.offsetWidth;t.style.overflow=`scroll`;let r=document.createElement(`div`);r.style.width=`100%`,t.appendChild(r);let i=r.offsetWidth;return t.parentNode?.removeChild(t),n-i}var ln=class{mouseY=0;mouseX=0;animationId=null;constructor(e=50,t=20,n=20){this.scrollThresholdX=e,this.scrollThresholdY=t,this.maxScrollSpeed=n}checkMinY(e){return this.mouseY<e.top+this.scrollThresholdY}checkMaxY(e){return this.mouseY>e.bottom-this.scrollThresholdY}checkMinX(e){return this.mouseX<e.left+this.scrollThresholdX}checkMaxX(e){return this.mouseX>e.right-this.scrollThresholdX}start(e,t){let n=e.getBoundingClientRect(),r=()=>{let i=!1,a=0,o=0;if(this.checkMinY(n)){let t=n.top+this.scrollThresholdY-this.mouseY,r=Math.min(t/this.scrollThresholdY*this.maxScrollSpeed,this.maxScrollSpeed);e.scrollTop-=r,o=-1*r,i=!0}else if(this.checkMaxY(n)){let t=this.mouseY-(n.bottom-this.scrollThresholdY),r=Math.min(t/this.scrollThresholdY*this.maxScrollSpeed,this.maxScrollSpeed);e.scrollTop+=r,o=r,i=!0}if(this.checkMinX(n)){let t=n.left+this.scrollThresholdX-this.mouseX,r=Math.min(t/this.scrollThresholdX*this.maxScrollSpeed,this.maxScrollSpeed);e.scrollLeft-=r,a=-1*r,i=!0}else if(this.checkMaxX(n)){let t=this.mouseX-(n.right-this.scrollThresholdX),r=Math.min(t/this.scrollThresholdX*this.maxScrollSpeed,this.maxScrollSpeed);e.scrollLeft+=r,a=r,i=!0}i&&t&&t(a,o),this.animationId=requestAnimationFrame(r)};this.animationId=requestAnimationFrame(r)}updateMousePosition(e,t){this.mouseX=e,this.mouseY=t}stop(){this.animationId!==null&&(cancelAnimationFrame(this.animationId),this.animationId=null)}};function un(e){return e.replaceAll(/([A-Z])/g,` $1`).trim().split(` `).join(`-`).toLowerCase()}function dn(e){return e.replaceAll(/-(\w)/g,(e,t)=>t.toUpperCase())}function fn(e){let t={};if(!e.style.cssText)return t;let n=e.style.cssText.split(`;`).filter(e=>e.trim());for(let e of n){let n=e.indexOf(`:`);if(n===-1)continue;let r=e.slice(0,n).trim();t[r]=e.slice(n+1).trim()}return t}function pn(e){let t={},n=e.trim().split(`;`);for(let e of n){let n=e.trim();if(!n)continue;let r=n.indexOf(`:`);if(r===-1)continue;let i=n.slice(0,Math.max(0,r)).trim(),a=n.slice(Math.max(0,r+1)).trim();t[dn(i)]=a}return t}function mn(e){return Object.entries(e).map(([e,t])=>`${un(e)}: ${t};`).join(` `)}const L=()=>Math.random().toString(36).slice(2);function hn(e,t){let n;return function(...r){n&&clearTimeout(n),n=setTimeout(()=>{e.apply(this,r)},t)}}const gn=e.import(`parchment`),_n=e.import(`blots/container`),vn=e.import(`blots/block`),yn=e.import(`blots/block/embed`);var R=class e extends _n{static tagName;static blotName=t.container;static scope=gn.Scope.BLOCK_BLOT;static allowedChildren=[vn,yn,_n];static requiredContainer;static defaultChild;static allowAttrs=new Set;static allowDataAttrs=new Set;static allowDataAttrsChangeHandler={};static create(e){let t=document.createElement(this.tagName);return this.className&&t.classList.add(this.className),t}setFormatValue(e,t){if(this.statics.allowAttrs.has(e)||this.statics.allowDataAttrs.has(e)){let n=e;this.statics.allowDataAttrs.has(e)&&(n=`data-${e}`),t?this.domNode.setAttribute(n,t):this.domNode.removeAttribute(n);let r=this.statics.allowDataAttrsChangeHandler[e];r&&x(this[r])&&this[r](t)}}optimize(e){if(this.children.length===0)if(this.statics.defaultChild!=null){let e=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(e)}else this.remove();this.children.length>0&&this.next!=null&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}enforceAllowedChildren(){this.children.forEach(t=>{this.statics.allowedChildren.some(e=>t instanceof e)||(t.statics.scope===gn.Scope.BLOCK_BLOT?(t.parent instanceof e?(t.next!=null&&t.parent.splitAfter(t),t.prev!=null&&t.parent.splitAfter(t.prev)):(t.next!=null&&this.splitAfter(t),t.prev!=null&&this.splitAfter(t.prev)),t.parent.unwrap()):t instanceof gn.ParentBlot?t.unwrap():t.remove())})}};const z=e=>oe(e)?e:1;function bn(e,t){return Object.keys(e).every(n=>JSON.stringify(e[n])===JSON.stringify(t[n]))}const xn=e.import(`parchment`),Sn=e.import(`blots/block`),Cn=e.import(`blots/block/embed`),wn=e.import(`blots/container`);var Tn=class extends Sn{replaceWith(e,n){let r=C(e)?this.scroll.create(e,n):e;if(r instanceof xn.ParentBlot)if(r.statics.blotName===t.tableCellInner){let e=null;try{if(e=u(this,t.tableCellInner),bn(e.formats(),r.formats()))return e}catch{}if(e)e.insertBefore(r,this),r.appendChild(this),e.children.length===0&&e.remove();else{let e=this,t=e;for(;e.parent!==this.scroll&&e.parent instanceof wn;)t=e,e=e.parent;e===this.scroll&&(e=t);let n=this.offset(e),i=this.length(),a=e.isolate(n,i);a?.parent&&a.parent.insertBefore(r,a.next),r.appendChild(this)}return r}else this.moveChildren(r);return this.parent!==null&&(this.parent.insertBefore(r,this.next),this.remove()),this.attributes.copy(r),r}format(e,n){if(e===t.tableCellInner&&this.parent.statics.blotName===e&&!n){if(this.prev&&this.prev instanceof Cn)return;try{u(this,t.tableCellInner).unwrap()}catch{console.error(`unwrap TableCellInner error`)}}else super.format(e,n)}};const En=e.import(`blots/block/embed`);var Dn=class extends En{delta(){let e=super.delta(),n=On(this);return n[t.tableCellInner]&&e.insert(`
2
2
  `,{[t.tableCellInner]:n[t.tableCellInner]}),e}length(){return On(this)[t.tableCellInner]?super.length()+1:super.length()}formatAt(e,n,r,i){if(r===t.tableCellInner)try{let e=u(this,t.tableCellInner),n=this.scroll.create(t.tableCellInner,i);e.insertBefore(n,this),n.appendChild(this),e.length()===0&&e.remove()}catch{}else this.format(r,i)}};function On(e,t={},n=!0){return e==null||(`formats`in e&&typeof e.formats==`function`&&(t={...t,...e.formats()},n&&delete t[`code-token`]),e.parent==null||e.parent.statics.blotName===`scroll`||e.parent.statics.scope!==e.statics.scope)?t:On(e.parent,t,n)}var B=class extends R{static blotName=t.tableBody;static tagName=`tbody`;static create(e){let t=super.create();return t.dataset.tableId=e,t}get tableId(){return this.domNode.dataset.tableId}checkMerge(){let e=this.next;return e!==null&&e.statics.blotName===this.statics.blotName&&e.tableId===this.tableId}optimize(e){let n=this.parent;if(n!==null&&n.statics.blotName!==t.tableMain){let{tableId:e}=this;this.wrap(t.tableMain,{tableId:e})}super.optimize(e)}convertBody(e){let t=this.descendants(V);for(let n of t)n.wrapTag=e}getRows(){return Array.from(this.domNode.querySelectorAll(`tr`)).map(e=>this.scroll.find(e)).filter(Boolean)}};const kn=e.import(`blots/block`),An=e.import(`blots/block/embed`);var V=class extends R{static blotName=t.tableCellInner;static tagName=`div`;static className=`ql-table-cell-inner`;static allowDataAttrs=new Set([`table-id`,`row-id`,`col-id`,`rowspan`,`colspan`,`empty-row`,`wrap-tag`]);static defaultChild=kn;static allowStyle=new Set([`background-color`,`border`,`height`]);static isAllowStyle(e){let t=dn(e);for(let e of this.allowStyle)if(t.startsWith(dn(e)))return!0;return!1}static create(e){let{tableId:t,rowId:n,colId:r,rowspan:i,colspan:a,style:o,emptyRow:s,tag:c=`td`,wrapTag:l=`tbody`}=e,u=super.create();u.dataset.tableId=t,u.dataset.rowId=n,u.dataset.colId=r,u.dataset.rowspan=String(z(i)),u.dataset.colspan=String(z(a)),u.dataset.tag=c,u.dataset.wrapTag=l,o&&(u.dataset.style=o);try{s&&(u.dataset.emptyRow=JSON.stringify(s))}catch{}return u}static formats(e){let{tableId:t,rowId:n,colId:r,rowspan:i,colspan:a,style:o,emptyRow:s,tag:c=`td`,wrapTag:l=`tbody`}=e.dataset,u={tableId:String(t),rowId:String(n),colId:String(r),rowspan:Number(z(i)),colspan:Number(z(a)),tag:c,wrapTag:l};o&&(u.style=o);try{s&&(u.emptyRow=JSON.parse(s))}catch{}return u}constructor(e,t,n){super(e,t),t.setAttribute(`contenteditable`,String(e.isEnabled()))}setFormatValue(e,n,r=!1){if(r){if(!this.statics.isAllowStyle(e))return}else super.setFormatValue(e,n);this.parent?.statics.blotName===t.tableCell&&this.parent.setFormatValue(e,n),this.clearCache()}clearCache(){let e=this.descendants(kn,0);for(let t of e)t.cache={}}get tableId(){return this.domNode.dataset.tableId}get rowId(){return this.domNode.dataset.rowId}set rowId(e){this.setFormatValue(`row-id`,e)}get colId(){return this.domNode.dataset.colId}set colId(e){this.setFormatValue(`col-id`,e)}get rowspan(){return Number(this.domNode.dataset.rowspan)}set rowspan(e){this.setFormatValue(`rowspan`,e)}get colspan(){return Number(this.domNode.dataset.colspan)}set colspan(e){this.setFormatValue(`colspan`,e)}get emptyRow(){try{return JSON.parse(this.domNode.dataset.emptyRow)}catch{return[]}}set emptyRow(e){if(this.emptyRow.toString()!==e.toString())try{e.length>0?this.setFormatValue(`empty-row`,JSON.stringify(e),!1):this.setFormatValue(`empty-row`,null,!1)}catch{this.setFormatValue(`empty-row`,null,!1)}}set wrapTag(e){this.setFormatValue(`wrap-tag`,e)}get wrapTag(){return this.domNode.dataset.wrapTag||`tbody`}getColumnIndex(){return u(this,t.tableMain).getColIds().indexOf(this.colId)}getRowIndex(){return u(this,t.tableMain).getRowIds().indexOf(this.rowId)}getTableBody(){let e=this.parent;for(;e&&!(e instanceof B)&&e!==this.scroll;)e=e.parent;return e===this.scroll?null:e}getTableRow(){try{return u(this,t.tableRow)}catch{return null}}setStyleByString(e){let t=pn(e);for(let[e,n]of Object.entries(t))this.setFormatValue(e,n,!0)}convertTableCell(){this.parent.statics.blotName===t.tableCell&&(this.parent.convertTableCell(),this.clearCache())}formatAt(e,t,n,r){if(this.children.length===0){let e=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(e),t+=e.length()}super.formatAt(e,t,n,r),r?.style&&this.setStyleByString(r.style)}insertAt(e,t,n){let[r]=this.children.find(e);if(!r&&this.statics.defaultChild){let e=this.scroll.create(this.statics.defaultChild.blotName||`block`);this.appendChild(e)}super.insertAt(e,t,n),(n==null?this.scroll.create(`text`,t):this.scroll.create(t,n))instanceof An&&r&&r.length()<=1&&r.remove()}formats(){let e=this.statics.formats(this.domNode);return{[this.statics.blotName]:e}}checkMerge(){let{colId:e,rowId:t,colspan:n,rowspan:r}=this,i=this.next;return i!==null&&i.statics.blotName===this.statics.blotName&&i.rowId===t&&i.colId===e&&i.colspan===n&&i.rowspan===r}optimize(){let e=this.parent,n=this.statics.formats(this.domNode);if(this.prev&&this.prev instanceof An){let e=this.prev;if(this.insertBefore(e,this.children.head),this.length()<=1){let t=this.scroll.create(`block`);this.insertBefore(t,e.next)}}let r=e!==null&&e.statics.blotName!==t.tableCell;if(r&&(this.wrap(t.tableCell,n),this.children.length===0)){let e=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(e)}this.children.length>0&&this.next!=null&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove()),this.uiNode!=null&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),this.children.length===0?this.remove():this.domNode.dataset.style&&r&&e.domNode.style.cssText!==this.domNode.dataset.style&&this.setStyleByString(this.domNode.dataset.style)}insertBefore(e,n){if(e.statics.blotName===this.statics.blotName){let r=e,i=this.statics.formats(r.domNode),a=this.statics.formats(this.domNode);if(bn(a,i)){let e=this.split(n?n.offset():0);return this.parent.insertBefore(r,e)}else{let[e,o]=d(this,[t.tableRow,t.tableCell]),s=o;if(n){let r=n.offset(),i=this.length();if(r!==0&&r<i){let n=this.split(r).wrap(t.tableCell,a);e.insertBefore(n,o.next),s=n}}if(this.tableId!==r.tableId){let e=u(this,t.tableWrapper),n=this.offset(e),i=e.split(n);return e.parent.insertBefore(r,i)}if(this.rowId!==r.rowId){let a=e,o=n;if(o){let t=o.offset(e);a=e.split(t)}let s=this.scroll.create(t.tableRow,i),c=this.scroll.create(t.tableCell,i);return c.appendChild(r),s.appendChild(c),e.parent.insertBefore(s,a)}return e.insertBefore(r.wrap(t.tableCell,i),s)}}else if(e.statics.blotName===t.tableCol){try{let n=u(this,t.tableBody),r=this.offset(n),i=n.split(r);n.parent.insertBefore(e,i),e.optimize({})}catch{console.warn(`TableCellInner not in TableBody`)}return}super.insertBefore(e,n)}};const jn=e.import(`parchment`),Mn=e.import(`blots/scroll`);var Nn=class extends Mn{enable(n=!0){let r=e.import(`formats/${t.tableCellInner}`),i=this.domNode.querySelectorAll(`.${r.className}`);for(let e of Array.from(i))e.setAttribute(`contenteditable`,String(!!n));let a=e.import(`formats/${t.tableCaption}`),o=this.domNode.querySelectorAll(`.${a.className}`);for(let e of Array.from(o))e.setAttribute(`contenteditable`,String(!!n));super.enable(n)}createBlock(e,n){let r,i={};if(e[t.tableCellInner])r=t.tableCellInner;else for(let[t,n]of Object.entries(e))this.query(t,jn.Scope.BLOCK&jn.Scope.BLOT)==null?i[t]=n:r=t;r===t.tableCellInner&&(i={...e},delete i[r]);let a=this.create(r||this.statics.defaultChild.blotName,r?e[r]:void 0);this.insertBefore(a,n||void 0);let o=a.length();a instanceof V&&o===0&&(o+=1);for(let[e,t]of Object.entries(i))a.formatAt(0,o,e,t);return a}},Pn=`<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">
3
3
  <!-- Icon from Tabler Icons by Paweł Kuna - https://github.com/tabler/tabler-icons/blob/master/LICENSE -->
4
4
  <path
@@ -130,8 +130,8 @@ import e from"quill";const t={container:`table-up-container`,tableCaption:`table
130
130
  <div class="${this.bem.be(`col-separator`)}" style="height: ${e.height+this.options.size-3}px"></div>
131
131
  </div>`}let i=document.createElement(`div`);i.classList.add(this.bem.be(`col`));let a=document.createElement(`div`);a.classList.add(this.bem.be(`col-wrapper`)),Object.assign(i.style,{transform:`translateY(-${this.options.size}px)`,maxWidth:`${r.width}px`,height:`${this.options.size}px`}),Object.assign(a.style,{width:`${e.width}px`}),a.innerHTML=n,i.appendChild(a),this.root.appendChild(i),i.scrollLeft=this.tableWrapperBlot.domNode.scrollLeft,this.colHeadWrapper=i,this.bindColEvents()}if(n.length>0){let t=``;for(let r=0;r<n.length;r++){let i=r,a=n[r],o=a.domNode.getBoundingClientRect().height;if(a.children.length===1&&(a.children.head?.emptyRow.length||0)>0){let e=a.children.head.emptyRow.length;for(let t=r+1;t<n.length&&t<=r+e;t++){let e=n[t];o+=e.domNode.getBoundingClientRect().height}r+=e}t+=`<div class="${this.bem.be(`row-header`)}" data-index="${i}" style="height: ${o}px">
132
132
  <div class="${this.bem.be(`row-separator`)}" style="width: ${e.width+this.options.size-3}px"></div>
133
- </div>`}let i=document.createElement(`div`);i.classList.add(this.bem.be(`row`));let a=document.createElement(`div`);a.classList.add(this.bem.be(`row-wrapper`)),Object.assign(i.style,{transform:`translateX(-${this.options.size}px)`,width:`${this.options.size}px`,maxHeight:`${r.height}px`}),Object.assign(a.style,{height:`${e.height}px`}),a.innerHTML=t,i.appendChild(a),this.root.appendChild(i),i.scrollTop=this.tableWrapperBlot.domNode.scrollTop,this.rowHeadWrapper=i,this.bindRowEvents()}let[o]=p(this.tableBlot,Rn),s=!o||o?.side!==`top`;s?this.root.classList.remove(this.bem.is(`caption-bottom`)):this.root.classList.add(this.bem.is(`caption-bottom`));let c=-1*this.options.size,l=-1*this.options.size;kr(this.tableBlot)?(this.root.classList.add(this.bem.is(`align-right`)),c=Math.min(r.width,e.width),l=Math.min(r.width,e.width)):this.root.classList.remove(this.bem.is(`align-right`)),this.corner&&Object.assign(this.corner.style,{transform:`translateY(${-1*this.options.size}px) translateX(${c}px)`,top:`${s?0:e.height+this.options.size}px`}),this.rowHeadWrapper&&Object.assign(this.rowHeadWrapper.style,{transform:`translateX(${l}px)`,maxHeight:`${r.height}px`}),this.colHeadWrapper&&Object.assign(this.colHeadWrapper.style,{top:`${s?0:e.height+this.options.size}px`,maxWidth:`${r.width}px`})}show(){!this.table||!this.tableBlot||(this.root.classList.remove(this.bem.is(`hidden`)),this.resizeObserver=an(()=>this.update(),{ignoreFirstBind:!0}),this.resizeObserver.observe(this.table),this.update(),F.call(this,this.quill.root,()=>{this.update()}))}hide(){this.root.classList.add(this.bem.is(`hidden`)),this.resizeObserver&&=(this.resizeObserver.disconnect(),void 0)}destroy(){super.destroy(),this.hide(),I.call(this),this.quill.off(e.events.EDITOR_CHANGE,this.updateWhenTextChange);for(let[e,t]of this.scrollHandler)e.removeEventListener(`scroll`,t);this.root.remove()}},Lr=class extends Nr{static moduleName=`table-resize-line`;colResizer;rowResizer;currentTableCell;tableCellBlot;bem=l(`resize-line`);stopColDrag;stopRowDrag;scrollHandler=[];constructor(t,n){super(t,n),this.tableModule=t,this.quill=n,this.colResizer=this.tableModule.addContainer(this.bem.be(`col`)),this.rowResizer=this.tableModule.addContainer(this.bem.be(`row`)),this.quill.on(e.events.EDITOR_CHANGE,this.updateWhenTextChange)}setSelectionTable(e){this.table!==e&&(this.hide(),this.table=e,this.table&&this.show())}updateWhenTextChange=t=>{t===e.events.TEXT_CHANGE&&(this.table&&!this.quill.root.contains(this.table)?this.setSelectionTable(void 0):this.update())};findTableCell(e){for(let t of e.composedPath()){if(t instanceof HTMLElement&&[`TD`,`TH`].includes(t.tagName))return t;if(t===document.body)return null}return null}pointermoveHandler=n=>{if(this.dragging||this.tableModule.getModule(i.tableSelectionName)?.dragging)return;let r=this.findTableCell(n);if(!r)return this.hide();let a=e.find(r);a&&this.currentTableCell!==r&&(this.show(),this.currentTableCell=r,this.tableCellBlot=a,this.tableBlot=u(a,t.tableMain),this.tableBlot.getCols().length>0&&this.updateColResizer(),this.updateRowResizer(),F.call(this,this.quill.root,()=>{this.dragging||this.hideResizer()}))};findDragColIndex(e){return this.tableCellBlot?e.findIndex(e=>e.colId===this.tableCellBlot.colId):-1}updateColResizer(){if(!this.tableBlot||!this.tableCellBlot||!this.colResizer)return;this.colResizer.remove();let{rect:e}=J(this.tableBlot);if(!e)return;this.colResizer=this.tableModule.addContainer(this.bem.be(`col`));let t=this.tableCellBlot.domNode.getBoundingClientRect(),n=this.quill.root.getBoundingClientRect(),r=t.right-n.x;kr(this.tableBlot)&&(r=t.left-n.x),Object.assign(this.colResizer.style,{top:`${e.y-n.y}px`,left:`${r}px`,height:`${e.height}px`});let{stop:i}=en(this.colResizer,{axis:`x`,onStart:(e,t)=>{if(this.dragging=!0,this.calculateColDragRange(),this.dragXCommon.createBreak(),!this.tableBlot)return;let n=this.tableBlot.domNode.parentElement.getBoundingClientRect(),{rect:r}=J(this.tableBlot);if(!r)return;this.dragXCommon.startValue=r.x;let i=this.quill.root.getBoundingClientRect();Object.assign(this.dragXCommon.dragBreak.style,{top:`${Math.max(n.y,r.y)-i.y}px`,left:`${t.clientX-i.x}px`,height:`${Math.min(n.height,r.height)}px`})},onMove:({position:e})=>{if(!this.dragXCommon.dragBreak)return;let t=this.dragXCommon.limitRange(this.tableBlot,e.x,!0),n=this.quill.root.getBoundingClientRect();this.dragXCommon.dragBreak.style.left=`${t-n.x}px`},onEnd:({position:e})=>{if(this.dragging=!1,this.colResizer){let t=this.dragXCommon.limitRange(this.tableBlot,e.x,!0),n=this.quill.root.getBoundingClientRect();this.colResizer.style.left=`${t-n.x}px`}this.updateTableCol(e.x),this.removeBreak()}});this.stopColDrag&&this.stopColDrag(),this.stopColDrag=i,this.colResizer.addEventListener(`dragstart`,e=>e.preventDefault())}findDragRowIndex(e){if(!this.tableCellBlot)return-1;let t=this.tableCellBlot.parent;return t instanceof H?e.indexOf(t):-1}updateRowResizer(){if(!this.tableBlot||!this.tableCellBlot||!this.rowResizer)return;let e=this.tableCellBlot;this.rowResizer.remove();let{rect:t}=J(this.tableBlot);if(!t)return;this.rowResizer=this.tableModule.addContainer(this.bem.be(`row`));let n=e.domNode.getBoundingClientRect(),r=this.quill.root.getBoundingClientRect();Object.assign(this.rowResizer.style,{top:`${n.bottom-r.y}px`,left:`${t.x-r.x}px`,width:`${t.width}px`});let{stop:i}=en(this.rowResizer,{axis:`y`,onStart:(e,t)=>{if(this.dragging=!0,this.calculateRowDragRange(),this.dragYCommon.createBreak(),!this.tableBlot)return;let n=this.tableBlot.domNode.parentElement.getBoundingClientRect(),{rect:r}=J(this.tableBlot);if(!r)return;this.dragYCommon.startValue=r.y;let i=this.quill.root.getBoundingClientRect();Object.assign(this.dragYCommon.dragBreak.style,{top:`${t.clientY-i.y}px`,left:`${Math.max(n.x,r.x)-i.x}px`,width:`${Math.min(n.width,r.width)}px`})},onMove:({position:e})=>{if(!this.dragYCommon.dragBreak||!this.table)return;let t=this.dragYCommon.limitRange(this.tableBlot,e.y,!0),n=this.quill.root.getBoundingClientRect();this.dragYCommon.dragBreak.style.top=`${t-n.y}px`},onEnd:({position:e})=>{if(this.dragging=!1,this.rowResizer){let t=this.dragYCommon.limitRange(this.tableBlot,e.y,!0),n=this.quill.root.getBoundingClientRect();this.rowResizer.style.left=`${t-n.y}px`}this.updateTableRow(e.y),this.removeBreak()}});this.stopRowDrag&&this.stopRowDrag(),this.stopRowDrag=i,this.rowResizer.addEventListener(`dragstart`,e=>e.preventDefault())}show(){!this.table||!this.rowResizer||!this.colResizer||(this.rowResizer.classList.remove(this.bem.is(`hidden`)),this.colResizer.classList.remove(this.bem.is(`hidden`)),this.table.addEventListener(`pointermove`,this.pointermoveHandler))}hideResizer(){!this.rowResizer||!this.colResizer||(this.rowResizer.classList.add(this.bem.is(`hidden`)),this.colResizer.classList.add(this.bem.is(`hidden`)))}hide(){this.currentTableCell=void 0,I.call(this),this.hideResizer(),this.table&&this.table.removeEventListener(`pointermove`,this.pointermoveHandler)}destroy(){super.destroy(),this.colResizer&&=(this.colResizer.remove(),void 0),this.rowResizer&&=(this.rowResizer.remove(),void 0),this.quill.off(e.events.EDITOR_CHANGE,this.updateWhenTextChange)}},Rr=class extends Y{static moduleName=`table-resize-scale`;scrollHandler=[];tableMainBlot;tableWrapperBlot;bem=l(`scale`);options;root;block;resizeobserver=new ResizeObserver(()=>this.update());constructor(t,n,r){super(t,n),this.tableModule=t,this.quill=n,this.options=this.resolveOptions(r),this.quill.on(e.events.EDITOR_CHANGE,this.updateWhenTextChange)}updateWhenTextChange=t=>{t===e.events.TEXT_CHANGE&&(this.table&&!this.quill.root.contains(this.table)?this.setSelectionTable(void 0):this.update())};resolveOptions(e){return Object.assign({blockSize:12,offset:6},e)}buildResizer(){if(!this.tableMainBlot||!this.tableWrapperBlot)return;this.root=this.tableModule.addContainer(this.bem.b()),this.block=document.createElement(`div`),this.block.classList.add(this.bem.be(`block`)),Object.assign(this.block.style,{width:`${this.options.blockSize}px`,height:`${this.options.blockSize}px`}),this.root.appendChild(this.block);let e=[],t=[];en(this.block,{onStart:()=>{this.tableMainBlot&&(e=this.tableMainBlot.getCols().map(e=>({blot:e,width:Math.floor(e.width)})),t=this.tableMainBlot.getRows().map(e=>({blot:e,height:Math.floor(e.domNode.getBoundingClientRect().height)})))},onMove:({movePosition:r})=>{if(!this.tableMainBlot)return;let i=kr(this.tableMainBlot)?-1:1,a=r.x*i,o=r.y,s=Math.floor(a/e.length),c=Math.floor(o/t.length);for(let{blot:t,width:r}of e)t.width=Math.max(r+s,n.colMinWidthPx);for(let{blot:e,height:r}of t)e.setHeight(`${Math.max(r+c,n.rowMinHeightPx)}px`)},onEnd:()=>{e=[],t=[]}}),this.block.addEventListener(`dragstart`,e=>e.preventDefault())}update(){if(!this.block||!this.root||!this.tableMainBlot||!this.tableWrapperBlot)return;if(this.tableMainBlot.full){this.hide();return}let{rect:e}=J(this.tableMainBlot);if(!e)return;let t=this.tableWrapperBlot.domNode.getBoundingClientRect(),n=this.quill.root.getBoundingClientRect(),{scrollTop:r,scrollLeft:i}=this.tableWrapperBlot.domNode,a=this.options.blockSize*2+this.options.offset,o=Math.min(e.width,t.width)+a,s=Math.min(e.height,t.height)+a;Object.assign(this.root.style,{width:`${o}px`,height:`${s}px`,left:`${Math.max(e.x,t.x)-n.x-this.options.blockSize}px`,top:`${Math.max(e.y,t.y)-n.y-this.options.blockSize}px`});let c={left:`${e.width+a-i}px`,top:`${s-r}px`};kr(this.tableMainBlot)?(this.root.classList.add(this.bem.is(`align-right`)),c.left=`${this.options.blockSize+-1*i}px`):this.root.classList.remove(this.bem.is(`align-right`)),Object.assign(this.block.style,c)}show(){this.table&&(this.tableMainBlot=e.find(this.table),this.tableMainBlot&&!this.tableMainBlot.full&&(this.tableWrapperBlot=this.tableMainBlot.parent,this.resizeobserver.observe(this.tableMainBlot.domNode),F.call(this,this.quill.root,()=>this.update()),F.call(this,this.tableWrapperBlot.domNode,()=>this.update())),this.buildResizer())}hide(){this.tableMainBlot=void 0,this.tableWrapperBlot=void 0,this.root&&(this.root.remove(),this.root=void 0,this.block=void 0),I.call(this)}destroy(){super.destroy(),this.hide(),this.quill.off(e.events.EDITOR_CHANGE,this.updateWhenTextChange),this.resizeobserver.disconnect()}};const zr={size:`height`,offset:`offsetHeight`,scrollDirection:`scrollTop`,scrollSize:`scrollHeight`,axis:`y`,direction:`top`,client:`clientY`},Br={size:`width`,offset:`offsetWidth`,scrollDirection:`scrollLeft`,scrollSize:`scrollWidth`,axis:`x`,direction:`left`,client:`clientX`};var Vr=class{minSize=20;gap=4;move=0;cursorDown=!1;cursorLeave=!1;ratioY=1;ratioX=1;sizeWidth=``;sizeHeight=``;size=``;bem=l(`scrollbar`);tableMainBlot;ob;container;scrollbar;thumb=document.createElement(`div`);scrollHandler=[];propertyMap;thumbState={x:0,y:0};get isVertical(){return this.options.isVertical}constructor(t,n,r){this.quill=t,this.table=n,this.options=r,this.tableMainBlot=e.find(this.table),this.container=n.parentElement,this.propertyMap=this.isVertical?zr:Br,this.calculateSize(),this.ob=new ResizeObserver(()=>this.update()),this.ob.observe(n),this.scrollbar=this.createScrollbar(),this.setScrollbarPosition(),F.call(this,this.quill.root,()=>this.setScrollbarPosition()),this.showScrollbar()}update(){this.calculateSize(),this.setScrollbarPosition()}setScrollbarPosition(){let{rect:e,head:t,body:n,foot:r}=J(this.tableMainBlot),i=t||n||r;if(!i||!e)return;let{scrollLeft:a,scrollTop:o,offsetLeft:s,offsetTop:c}=this.quill.root,{offsetLeft:l,offsetTop:u}=this.container,{offsetLeft:d,offsetTop:f}=i.domNode,{width:p,height:m}=this.container.getBoundingClientRect(),h=l+d-s,g=u+f-c;this.isVertical?h+=Math.min(p,e.width):g+=Math.min(m,e.height),this.tableMainBlot&&this.tableMainBlot.align!==`left`&&(h+=this.table.offsetLeft-l),Object.assign(this.scrollbar.style,{[this.propertyMap.size]:`${this.isVertical?Math.min(m,e.height):p}px`,transform:`translate(${h-a}px, ${g-o}px)`}),this.containerScrollHandler(this.container)}calculateSize(){let e=this.container.offsetHeight-this.gap,t=this.container.offsetWidth-this.gap,n=e**2/this.container.scrollHeight,r=t**2/this.container.scrollWidth,i=Math.max(n,this.minSize),a=Math.max(r,this.minSize);this.ratioY=n/(e-n)/(i/(e-i)),this.ratioX=r/(t-r)/(a/(t-a)),this.sizeWidth=a+this.gap<t?`${a}px`:``,this.sizeHeight=i+this.gap<e?`${i}px`:``,this.size=this.isVertical?this.sizeHeight:this.sizeWidth}createScrollbar(){let e=document.createElement(`div`);e.classList.add(this.bem.b(),this.isVertical?this.bem.is(`vertical`):this.bem.is(`horizontal`),this.bem.is(`transparent`)),Object.assign(e.style,{display:`none`}),this.thumb.classList.add(this.bem.be(`thumb`));let t=null,n=e=>{if(this.cursorDown===!1)return;let t=this.thumbState[this.propertyMap.axis];if(!t)return;let n=this.scrollbar[this.propertyMap.offset]**2/this.container[this.propertyMap.scrollSize]/(this.isVertical?this.ratioY:this.ratioX)/this.thumb[this.propertyMap.offset],r=((this.scrollbar.getBoundingClientRect()[this.propertyMap.direction]-e[this.propertyMap.client])*-1-(this.thumb[this.propertyMap.offset]-t))*100*n/this.scrollbar[this.propertyMap.offset];this.container[this.propertyMap.scrollDirection]=r*this.container[this.propertyMap.scrollSize]/100},r=()=>{this.thumbState[this.propertyMap.axis]=0,this.cursorDown=!1,document.removeEventListener(`mousemove`,n),document.removeEventListener(`mouseup`,r),this.cursorLeave&&this.hideScrollbar(),document.onselectstart=t},i=e=>{e.stopImmediatePropagation(),this.cursorDown=!0,document.addEventListener(`mousemove`,n),document.addEventListener(`mouseup`,r),t=document.onselectstart,document.onselectstart=()=>!1};this.thumb.addEventListener(`mousedown`,e=>{if(e.stopPropagation(),e.ctrlKey||[1,2].includes(e.button))return;window.getSelection()?.removeAllRanges(),i(e);let t=e.currentTarget;t&&(this.thumbState[this.propertyMap.axis]=t[this.propertyMap.offset]-(e[this.propertyMap.client]-t.getBoundingClientRect()[this.propertyMap.direction]))});let a=[this.table,e];for(let e of a)e.addEventListener(`mouseenter`,this.showScrollbar),e.addEventListener(`mouseleave`,this.hideScrollbar);return F.call(this,this.container,()=>{this.containerScrollHandler(this.container)}),e.appendChild(this.thumb),e}containerScrollHandler(e){let t=e[this.propertyMap.offset]-this.gap;this.move=e[this.propertyMap.scrollDirection]*100/t*(this.isVertical?this.ratioY:this.ratioX),Object.assign(this.thumb.style,{[this.propertyMap.size]:this.size,transform:`translate${this.propertyMap.axis.toUpperCase()}(${this.move}%)`})}showScrollbar=hn(()=>{this.cursorLeave=!1,this.scrollbar.removeEventListener(`transitionend`,this.hideScrollbarTransitionend),this.scrollbar.style.display=this.size?`block`:`none`,requestAnimationFrame(()=>{this.scrollbar.classList.remove(this.bem.is(`transparent`))})},200);hideScrollbar=hn(()=>{this.cursorLeave=!0,!this.cursorDown&&(this.scrollbar.removeEventListener(`transitionend`,this.hideScrollbarTransitionend),this.scrollbar.addEventListener(`transitionend`,this.hideScrollbarTransitionend,{once:!0}),this.scrollbar.classList.add(this.bem.is(`transparent`)))},200);hideScrollbarTransitionend=()=>{this.scrollbar.style.display=this.cursorDown&&this.size?`block`:`none`};destroy(){this.ob.disconnect(),I.call(this),this.table.removeEventListener(`mouseenter`,this.showScrollbar),this.table.removeEventListener(`mouseleave`,this.hideScrollbar)}},Hr=class extends Y{static moduleName=`table-scrollbar`;scrollbarContainer;scrollbar=[];bem=l(`scrollbar`);constructor(t,n,r){super(t,n),this.tableModule=t,this.quill=n;let i=l(`scrollbar`);this.quill.container.classList.add(i.bm(`virtual`)),this.scrollbarContainer=this.tableModule.addContainer(this.bem.be(`container`)),this.quill.on(e.events.EDITOR_CHANGE,this.updateWhenTextChange)}updateWhenTextChange=t=>{t===e.events.TEXT_CHANGE&&(this.table&&!this.quill.root.contains(this.table)?this.setSelectionTable(void 0):this.update())};hide(){for(let e of this.scrollbar)e.destroy();this.scrollbar=[],this.scrollbarContainer.innerHTML=``}show(){if(this.table){this.scrollbar=[new Vr(this.quill,this.table,{isVertical:!0}),new Vr(this.quill,this.table,{isVertical:!1})];for(let e of this.scrollbar)this.scrollbarContainer.appendChild(e.scrollbar),e.showScrollbar()}}update(){if(this.table){this.scrollbar.length<=0&&this.show();for(let e of this.scrollbar)e.calculateSize(),e.setScrollbarPosition()}else this.scrollbar.length>0&&this.hide()}destroy(){super.destroy(),this.hide(),this.scrollbarContainer.remove(),this.quill.off(e.events.TEXT_CHANGE,this.updateWhenTextChange)}},Ur=class extends Y{static moduleName=i.tableSelectionName;options;boundary=null;scrollRecordEls=[];startScrollRecordPosition=[];selectedTableScrollX=0;selectedTableScrollY=0;selectedEditorScrollX=0;selectedEditorScrollY=0;selectedTds=[];cellSelectWrap;cellSelect;scrollHandler=[];resizeObserver;isDisplaySelection=!1;bem=l(`selection`);autoScroller;lastSelection={anchorNode:null,anchorOffset:0,focusNode:null,focusOffset:0};_dragging=!1;set dragging(e){this._dragging!==e&&(this._dragging=e,this.quill.emitter.emit(e?r.TABLE_SELECTION_DRAG_START:r.TABLE_SELECTION_DRAG_END,this))}get dragging(){return this._dragging}constructor(t,n,i={}){super(t,n),this.tableModule=t,this.quill=n,this.options=this.resolveOptions(i),this.scrollRecordEls=[this.quill.root,document.documentElement],this.cellSelectWrap=t.addContainer(this.bem.b()),this.cellSelect=this.helpLinesInitial(),this.resizeObserver=an(this.updateAfterEvent,{ignoreFirstBind:!0}),this.resizeObserver.observe(this.quill.root),document.addEventListener(`paste`,this.handlePaste),document.addEventListener(`selectionchange`,this.selectionChangeHandler),this.quill.on(r.AFTER_TABLE_RESIZE,this.updateAfterEvent),this.quill.on(e.events.SELECTION_CHANGE,this.quillSelectionChangeHandler),this.quill.on(e.events.EDITOR_CHANGE,this.updateWhenTextChange),this.autoScroller=new ln(50,40),this.hide()}handlePaste=e=>{if(!(document.activeElement&&this.quill.root.contains(document.activeElement))||this.quill.getSelection())return;let n=e.clipboardData;if(!n)return;e.preventDefault();let r=this.selectedTds;if(r.length<=0)return;let i=n.getData(`text/html`),a=this.quill.clipboard.convert({html:i}).ops.filter(e=>e.attributes?.[t.tableCellInner]);a.length!==0&&Gn({quill:this.quill,talbeModule:this.tableModule},r,a)};keyboardHandler=async e=>{if(e.ctrlKey)switch(e.key){case`c`:case`x`:await wr(this.tableModule,this.selectedTds,e.key===`x`);break}else (e.key===`Backspace`||e.key===`Delete`)&&this.removeCellBySelectedTds()};updateWhenTextChange=t=>{t===e.events.TEXT_CHANGE&&(this.table&&!this.quill.root.contains(this.table)?this.setSelectionTable(void 0):this.updateAfterEvent())};updateAfterEvent=()=>{for(let e of this.selectedTds)if(!e.domNode.isConnected){this.selectedTds=[];break}this.updateWithSelectedTds()};removeCellBySelectedTds(){let t=this.quill.getSelection(),n=document.activeElement;if(!(t||!this.quill.root.contains(n))){if(this.table){let t=e.find(this.table),n=t.descendants(V);if(this.selectedTds.length===n.length){t.remove();return}}for(let e of this.selectedTds){let t=e.clone();t.appendChild(e.scroll.create(`block`)),e.parent.insertBefore(t,e),e.remove()}}}setSelectedTds(e){let t=new Set(this.selectedTds),n=this.selectedTds.length===e.length&&e.every(e=>t.has(e));this.selectedTds=e,n||this.quill.emitter.emit(r.TABLE_SELECTION_CHANGE,this,this.selectedTds)}quillSelectionChangeHandler=(n,r,i)=>{if(i!==e.sources.API&&n&&!this.quill.composition.isComposing&&this.selectedTds.length>0){let e=this.quill.getFormat(n),[r]=this.quill.getLine(n.index),i=!!e[t.tableCellInner]&&!!r,a=r&&this.selectedTds.some(e=>e.domNode.contains(r.domNode));if(i&&!a)try{let e=u(r,t.tableCellInner);this.setSelectedTds([e]),this.updateWithSelectedTds()}catch{}else i&&a||this.hide()}};setSelectionData(e,t){let{anchorNode:n,anchorOffset:r,focusNode:i,focusOffset:a}=t;if(!n||!i)return;let o=document.createRange(),s=this.selectionDirectionUp(t);s?(o.setStart(n,r),o.setEnd(n,r)):(o.setStart(n,r),o.setEnd(i,a)),e.removeAllRanges(),e.addRange(o),s&&e.extend(i,a)}selectionDirectionUp(e){let{anchorNode:t,anchorOffset:n,focusNode:r,focusOffset:i}=e;if(!t||!r)return!1;if(t===r)return n>i;let a=t.compareDocumentPosition(r);return a&Node.DOCUMENT_POSITION_CONTAINS||a&Node.DOCUMENT_POSITION_CONTAINED_BY?(a&Node.DOCUMENT_POSITION_FOLLOWING)!==0:(a&Node.DOCUMENT_POSITION_PRECEDING)!==0}resolveOptions(e){return Object.assign({selectColor:`#0589f340`},e)}selectionChangeHandler=()=>{let n=window.getSelection();if(!n)return;let{anchorNode:r,focusNode:i,anchorOffset:a,focusOffset:o}=n;if(!r||!i)return;let s=e.find(r),c=e.find(i);if(!s||!c||s.scroll!==this.quill.scroll||c.scroll!==this.quill.scroll)return;let l=f(s),u=f(c),d=l.has(t.tableColgroup),p=u.has(t.tableColgroup);if(d||p){let e=r,s=a,c=i,f=o;if(d){let n=l.get(t.tableWrapper).descendants(V);n.length>0&&(e=n[0].domNode,s=0)}if(p){let e=u.get(t.tableWrapper).descendants(V);e.length>0&&(c=e[0].domNode,f=0)}this.setSelectionData(n,{anchorNode:e,anchorOffset:s,focusNode:c,focusOffset:f});return}let m=l.has(t.tableCellInner),h=u.has(t.tableCellInner),g=m&&h;if(g){let e=l.get(t.tableCellInner),n=u.get(t.tableCellInner);g&&=e!==n}if(m&&h&&g||!m&&h||!h&&m){this.setSelectionData(n,this.lastSelection),this.selectedTds.length>0&&this.hide();return}this.lastSelection={anchorNode:r,anchorOffset:a,focusNode:i,focusOffset:o}};helpLinesInitial(){this.cellSelectWrap.style.setProperty(`--select-color`,this.options.selectColor);let e=document.createElement(`div`);return e.classList.add(this.bem.be(`line`)),this.cellSelectWrap.appendChild(e),e}computeSelectedTds(t,n){if(!this.table)return[];let r=e.find(this.table);if(!r)return[];let i=new Set(r.descendants(U).map((e,t)=>(e.index=t,e))),a=this.getScrollPositionDiff(),{rect:o}=J(r);if(!o)return[];let s=t.x+a.x,c=t.y+a.y,l={x:Math.max(o.left,Math.min(n.x,s)),y:Math.max(o.top,Math.min(n.y,c)),x1:Math.min(o.right,Math.max(n.x,s)),y1:Math.min(o.bottom,Math.max(n.y,c))},u=new Set,d=!0;for(;d;){d=!1;for(let e of i){e.__rect||=e.domNode.getBoundingClientRect();let{x:t,y:n,right:r,bottom:a}=e.__rect;if(tn({x:Math.floor(l.x),y:Math.floor(l.y),x1:Math.floor(l.x1),y1:Math.floor(l.y1)},{x:Math.floor(t),y:Math.floor(n),x1:Math.floor(r),y1:Math.floor(a)},0,u.size===0)){u.add(e),i.delete(e),l={x:Math.min(l.x,t),y:Math.min(l.y,n),x1:Math.max(l.x1,r),y1:Math.max(l.y1,a)},d=!0;break}}}for(let e of[...u,...i])delete e.__rect;return this.boundary=nn({...l,width:l.x1-l.x,height:l.y1-l.y},this.quill.root),Array.from(u).toSorted((e,t)=>e.index-t.index).map(e=>(delete e.index,e.getCellInner()))}getScrollPositionDiff(){let{x:e,y:t}=this.getTableViewScroll(),{x:n,y:r}=sn(this.quill.root);return this.selectedTableScrollX=e,this.selectedTableScrollY=t,this.selectedEditorScrollX=n,this.selectedEditorScrollY=r,this.startScrollRecordPosition.reduce((e,{x:t,y:n},r)=>{let{x:i,y:a}=sn(this.scrollRecordEls[r]);return e.x+=t-i,e.y+=n-a,e},{x:0,y:0})}recordScrollPosition(){this.clearRecordScrollPosition();for(let e of this.scrollRecordEls)this.startScrollRecordPosition.push(sn(e))}clearRecordScrollPosition(){this.startScrollRecordPosition=[]}tableSelectHandler(t){let{button:n,target:r,clientX:i,clientY:a}=t,o=r.closest(`table`),s=r.closest(`caption`);if(n!==0||!o||s)return;this.setSelectionTable(o);let c=o.dataset.tableId,l={x:i,y:a};this.recordScrollPosition(),this.setSelectedTds(this.computeSelectedTds(l,l)),this.show();let u=e=>{this.dragging=!0;let{button:t,target:n,clientX:r,clientY:i}=e,a=n.closest(`.ql-table`),o=n.closest(`caption`);if(t!==0||o||!a||a.dataset.tableId!==c)return;let s={x:r,y:i};this.setSelectedTds(this.computeSelectedTds(l,s)),this.selectedTds.length>1&&this.quill.blur(),this.update(),this.autoScroller.updateMousePosition(r,i)},d=()=>{document.body.removeEventListener(`mousemove`,u,!1),document.body.removeEventListener(`mouseup`,d,!1),this.autoScroller.stop(),this.dragging=!1,this.clearRecordScrollPosition()};document.body.addEventListener(`mousemove`,u,!1),document.body.addEventListener(`mouseup`,d,!1);let f=e.find(o);if(!f)return;let p=f.parent.domNode;this.autoScroller.updateMousePosition(i,a),this.autoScroller.start(p)}updateWithSelectedTds(){if(this.selectedTds.length<=0){this.hide();return}let e={x:1/0,y:1/0},t={x:-1/0,y:-1/0};for(let n of this.selectedTds){let r=n.domNode.getBoundingClientRect();e.x=Math.min(e.x,r.left),e.y=Math.min(e.y,r.top),t.x=Math.max(t.x,r.right),t.y=Math.max(t.y,r.bottom)}this.setSelectedTds(this.computeSelectedTds(e,t)),this.selectedTds.length>0?this.update():this.hide()}update(){if(!this.table){this.hide();return}if(this.selectedTds.length===0||!this.boundary)return;let{x:e,y:t}=sn(this.quill.root),{x:n,y:i}=this.getTableViewScroll(),a=this.table.parentElement.getBoundingClientRect(),o=this.quill.root.getBoundingClientRect(),s=a.x-o.x,c=a.y-o.y;Object.assign(this.cellSelect.style,{left:`${this.selectedEditorScrollX*2-e+this.boundary.x+this.selectedTableScrollX-n-s}px`,top:`${this.selectedEditorScrollY*2-t+this.boundary.y+this.selectedTableScrollY-i-c}px`,width:`${this.boundary.width}px`,height:`${this.boundary.height}px`}),Object.assign(this.cellSelectWrap.style,{left:`${s}px`,top:`${c}px`,width:`${a.width}px`,height:`${a.height}px`}),this.quill.emitter.emit(r.TABLE_SELECTION_DISPLAY_CHANGE,this)}getTableViewScroll(){return this.table?sn(this.table.parentElement):{x:0,y:0}}setSelectionTable(e){this.table!==e&&(this.table=e,this.table?this.scrollRecordEls.push(this.table.parentElement):this.scrollRecordEls.pop())}showDisplay(){Object.assign(this.cellSelectWrap.style,{display:`block`}),this.isDisplaySelection=!0,this.table&&this.resizeObserver.observe(this.table)}show(){this.table&&(I.call(this),this.showDisplay(),this.update(),this.quill.root.addEventListener(`keydown`,this.keyboardHandler),F.call(this,this.quill.root,()=>{this.update()}),F.call(this,this.table.parentElement,()=>{this.update()}))}hideDisplay(){Object.assign(this.cellSelectWrap.style,{display:`none`}),this.isDisplaySelection=!1,this.table&&this.resizeObserver.unobserve(this.table)}hide(){I.call(this),this.quill.root.removeEventListener(`keydown`,this.keyboardHandler),this.hideDisplay(),this.boundary=null,this.setSelectedTds([]),this.setSelectionTable(void 0)}destroy(){super.destroy(),this.resizeObserver.disconnect(),this.hide(),this.cellSelectWrap.remove(),I.call(this),document.removeEventListener(`paste`,this.handlePaste),document.removeEventListener(`selectionchange`,this.selectionChangeHandler),this.quill.off(r.AFTER_TABLE_RESIZE,this.updateAfterEvent),this.quill.off(e.events.EDITOR_CHANGE,this.updateWhenTextChange),this.quill.off(e.events.SELECTION_CHANGE,this.quillSelectionChangeHandler)}};const Wr=e.import(`parchment`),$=e.import(`delta`),Gr=e.import(`ui/icons`),Kr=e.import(`blots/break`),qr=e.import(`blots/block`),Jr=e.import(`blots/block/embed`);function Yr(e,{tableId:n,rowId:r,colId:i}){let a={tableId:n,rowId:r,colId:i,colspan:1,rowspan:1},o=e.create(t.tableCell,a),s=e.create(t.tableCellInner,a),c=e.create(`block`);return c.appendChild(e.create(`break`)),s.appendChild(c),o.appendChild(s),o}function Xr(e){o.delete(t.tableCellInner),Object.assign(t,e.blotName||{}),Object.assign(n,e.tableUpSize||{}),Object.assign(r,e.tableUpEvent||{}),Object.assign(i,e.tableUpInternal||{}),$r.moduleName=i.moduleName,$r.toolName=t.tableWrapper,R.blotName=t.container,Rn.blotName=t.tableCaption,q.blotName=t.tableWrapper,G.blotName=t.tableMain,K.blotName=t.tableColgroup,W.blotName=t.tableCol,Vn.blotName=t.tableHead,B.blotName=t.tableBody,Bn.blotName=t.tableFoot,H.blotName=t.tableRow,U.blotName=t.tableCell,V.blotName=t.tableCellInner,o.add(t.tableCellInner)}function Zr(t,n){return w({onSelect:(r,i)=>{t.insertTable(r,i,e.sources.USER),n&&n.close()},customBtn:t.options.customBtn,texts:t.options.texts})}function Qr(n){return{bindInHead:!1,key:n?`ArrowUp`:`ArrowDown`,collapsed:!0,format:[t.tableCellInner],handler(r,i){let a=n?`prev`:`next`,o=n?`tail`:`head`;if(i.line[a])return!0;let s=this.quill.selection.getBounds(r.index),c=i.line.domNode.getBoundingClientRect();if(!s||!c)return!0;if(n){if(s.top-c.top>3)return!0}else if(c.bottom-s.bottom>3)return!0;let l,u,f,p;try{[l,u,f,p]=d(i.line,[t.tableWrapper,t.tableMain,t.tableRow,t.tableCell])}catch{return!0}let m=u.getColIds(),h=l.descendants(Rn,0)[0],g;if(h){let e=window.getComputedStyle(h.domNode);g=a===`next`&&e.captionSide===`bottom`?h:a===`next`?l.next:h}else g=l[a];if(i.line[a]||!g)return!0;let _=f[a];if(_){let t=m.indexOf(p.colId),n=_.getCellByColId(m[t],a);if(!n)return!0;let r=n.children[o];r.children&&(r=r.children[o]);let s=r.offset(this.quill.scroll)+Math.min(i.offset,r.length()-1);this.quill.setSelection(s,0,e.sources.USER)}else{let t=g.offset(this.quill.scroll)+(n?g.length()-1:0);this.quill.setSelection(t,0,e.sources.USER)}return!1}}}var $r=class r{static moduleName=i.moduleName;static toolName=t.tableWrapper;static keyboradHandler={"forbid remove table by backspace":{bindInHead:!0,key:`Backspace`,collapsed:!0,offset:0,handler(e,n){let r=this.quill.getLine(e.index)[0];return r.prev instanceof q?(r.prev.remove(),!1):!(n.format[t.tableCellInner]&&r.offset(u(r,t.tableCellInner))===0)}},"forbid remove table by delete":{bindInHead:!0,key:`Delete`,collapsed:!0,handler(e,n){let r=this.quill.getLine(e.index),i=r[0],a=r[1];return!((i.next instanceof q||i.next instanceof W)&&a===i.length()-1||n.format[t.tableCellInner]&&i===u(i,t.tableCellInner).children.tail&&a===i.length()-1)}},"table up":Qr(!0),"table down":Qr(!1),"table caption break":{bindInHead:!0,key:`Enter`,shiftKey:null,format:[t.tableCaption],handler(e,t){return!1}}};static register(){q.allowedChildren=[G],G.allowedChildren=[K,Rn,Vn,B,Bn],G.requiredContainer=q,Rn.requiredContainer=G,K.allowedChildren=[W],K.requiredContainer=G,Vn.allowedChildren=[H],Vn.requiredContainer=G,B.allowedChildren=[H],B.requiredContainer=G,Bn.allowedChildren=[H],Bn.requiredContainer=G,H.allowedChildren=[U],U.allowedChildren=[V,Kr],U.requiredContainer=H,V.requiredContainer=U;let n=new Set([`table`]),r=Object.entries(e.imports).filter(([e,t])=>{let r=e.split(`formats/`)[1];return e.startsWith(`formats/`)&&!n.has(r)&&(g(t,qr)||g(t,Jr))}).reduce((e,[t,n])=>{let r=g(n,Jr)?Dn:Tn;return e[t]=class extends h(n,[r]){static register(){}},e},{});e.register({"blots/scroll":Nn,"blots/block":Tn,"blots/block/embed":Dn,...r,[`blots/${t.container}`]:R,[`formats/${t.tableCell}`]:U,[`formats/${t.tableCellInner}`]:V,[`formats/${t.tableRow}`]:H,[`formats/${t.tableHead}`]:Vn,[`formats/${t.tableBody}`]:B,[`formats/${t.tableFoot}`]:Bn,[`formats/${t.tableCol}`]:W,[`formats/${t.tableColgroup}`]:K,[`formats/${t.tableCaption}`]:Rn,[`formats/${t.tableMain}`]:G,[`formats/${t.tableWrapper}`]:q,"modules/clipboard":or},!0)}quill;options;toolBox;fixTableByLisenter=hn(this.balanceTables,100);selector;resizeOb;editableObserver;modules={};get statics(){return this.constructor}constructor(e,t){this.quill=e,this.options=this.resolveOptions(t||{}),this.toolBox=this.initialContainer();let n=this.quill.getModule(`toolbar`);if(n&&this.quill.theme.pickers){let[,e]=(n.controls||[]).find(([e])=>e===this.statics.toolName)||[];if(e?.tagName.toLocaleLowerCase()===`select`){let t=this.quill.theme.pickers.find(t=>t.select===e);t&&(t.label.innerHTML=this.options.icon,this.buildCustomSelect(this.options.customSelect,t),t.label.addEventListener(`mousedown`,()=>{if(!this.selector||!t)return;let{leftLimited:e}=rn(this.selector.getBoundingClientRect());if(e){let e=t.label.getBoundingClientRect();Object.assign(t.options.style,{transform:`translateX(calc(-100% + ${e.width}px))`})}else Object.assign(t.options.style,{transform:void 0})}))}}let i=this.quill.getModule(`keyboard`);for(let e of Object.values(r.keyboradHandler))e.bindInHead?i.bindings[e.key].unshift(e):i.addBinding(e.key,e);this.initModules(),this.listenEditableChange(),this.quillHack(),this.listenBalanceCells()}initialContainer(){let e=l(`toolbox`),t=this.quill.addContainer(e.b());return this.resizeOb=new ResizeObserver(()=>{let e=this.quill.root.getBoundingClientRect(),{offsetLeft:n,offsetTop:r}=this.quill.root;Object.assign(t.style,{top:`${r}px`,left:`${n}px`,width:`${e.width}px`,height:`${e.height}px`})}),this.resizeOb.observe(this.quill.root),t}addContainer(e){if(C(e)){let t=document.createElement(`div`);for(let n of e.split(` `))t.classList.add(n);return this.toolBox.appendChild(t),t}else return this.toolBox.appendChild(e),e}resolveOptions(e){return Object.assign({customBtn:!1,texts:this.resolveTexts(e.texts||{}),full:!1,fullSwitch:!0,icon:Gr.table,autoMergeCell:!0,modules:[]},e)}resolveTexts(e){return Object.assign({fullCheckboxText:`Insert full width table`,customBtnText:`Custom`,confirmText:`Confirm`,cancelText:`Cancel`,rowText:`Row`,colText:`Column`,notPositiveNumberError:`Please enter a positive integer`,custom:`Custom`,clear:`Clear`,transparent:`Transparent`,perWidthInsufficient:`The percentage width is insufficient. To complete the operation, the table needs to be converted to a fixed width. Do you want to continue?`,CopyCell:`Copy cell`,CutCell:`Cut cell`,InsertTop:`Insert row above`,InsertRight:`Insert column right`,InsertBottom:`Insert row below`,InsertLeft:`Insert column Left`,MergeCell:`Merge Cell`,SplitCell:`Split Cell`,DeleteRow:`Delete Row`,DeleteColumn:`Delete Column`,DeleteTable:`Delete table`,BackgroundColor:`Set background color`,BorderColor:`Set border color`},e)}initModules(){if(this.quill.isEnabled())for(let e of this.options.modules)this.modules[e.module.moduleName]=new e.module(this,this.quill,e.options)}listenEditableChange(){this.editableObserver=new MutationObserver(e=>{for(let t of e)if(t.type===`attributes`&&t.attributeName===`contenteditable`){this.quill.root.getAttribute(`contenteditable`)===`false`?this.destroyModules():this.initModules();break}}),this.editableObserver.observe(this.quill.root,{attributes:!0,attributeFilter:[`contenteditable`]})}destroyModules(){for(let[e,t]of Object.entries(this.modules))if(t&&typeof t.destroy==`function`)try{t.destroy()}catch(t){console.warn(`Failed to destroy module ${e}:`,t)}this.modules={}}getModule(e){return this.modules[e]}quillHack(){let n=this.quill.getSemanticHTML;this.quill.getSemanticHTML=((r=0,i)=>{let a=n.call(this.quill,r,i),o=e.import(`formats/${t.tableWrapper}`),s=new DOMParser().parseFromString(a,`text/html`);for(let e of Array.from(s.querySelectorAll(`.${o.className} caption[contenteditable], .${o.className} .${U.className} > [contenteditable]`)))e.removeAttribute(`contenteditable`);return s.body.innerHTML});let r=this.quill.format;this.quill.format=function(n,a,o=e.sources.API){if(!(this.scroll.query(n).prototype instanceof Wr.EmbedBlot)){let e=this.getModule(i.moduleName),s=this.getSelection(!0),c=this.getFormat(s),l=e.getModule(i.tableSelectionName);if(!c[t.tableCellInner]||s.length>0||e&&l&&l.selectedTds.length<=1)return r.call(this,n,a,o);if(e&&l&&l.selectedTds.length>0){let e=l.selectedTds,t=!1,r=[];for(let i of e){let e=i.offset(this.scroll),o=i.length();r.push({index:e,length:o}),this.getFormat(e,o)[n]!==a&&(t=!0)}let i=t?a:!1,s=new $;for(let[e,{index:t,length:a}]of r.entries()){let o=e===0?0:r[e-1].index+r[e-1].length;s.retain(t-o).retain(a,{[n]:i})}let c=this.updateContents(s,o);return this.blur(),c}}return r.call(this,n,a,o)};let a=this.quill.theme.modules.toolbar;if(a){let n=a.handlers?.clean;if(n){let r=(e,n,r=()=>``)=>{let i=this.quill.getText(e,n),[a,o]=this.quill.getLine(e+n),s=0,c=new $;a!=null&&(s=a.length()-o,c=a.delta().slice(o,o+s-1).insert(`
134
- `));let l=this.quill.getContents(e,n+s),u=l.diff(new $().insert(i).concat(c)),d=0;return new $(u.ops.map(e=>{let{attributes:n,...i}=e;if(e.insert?d-=C(e.insert)?e.insert.length:1:e.retain?d+=re(e.retain)?e.retain:1:e.delete&&(d+=e.delete),n){let{[t.tableCellInner]:e,...a}=n;if(r){let e=l.slice(d-1,d).ops[0];if(e?.attributes?.[t.tableCellInner]){let{style:n,...o}=e.attributes[t.tableCellInner],s=r(n);return s?{...i,attributes:{...a,[t.tableCellInner]:{style:s,...o}}}:{...i,attributes:{...a,[t.tableCellInner]:o}}}}return{...i,attributes:{...a}}}return e}))};a.handlers.clean=function(a){let o=this.quill.getModule(i.moduleName),s=this.quill.getSelection();if(s&&s.length>0&&this.quill.getFormat(s)[t.tableCellInner]){let t=r(s.index,s.length,!1),n=new $().retain(s.index).concat(t);this.quill.updateContents(n,e.sources.USER);return}let c=o.getModule(i.tableSelectionName);if(o&&c&&c.selectedTds.length>0&&c.table){let t=e.find(c.table);if(!t){console.warn(`TableMainFormat not found`);return}let n=c.selectedTds,i=new Set,a=[];for(let e of n)if(e.parent instanceof U){for(let t of e.parent.getNearByCell(`top`))i.has(t)||(i.add(t),a.push({td:t,cleanBorder:`bottom`}));for(let t of e.parent.getNearByCell(`left`))i.has(t)||(i.add(t),a.push({td:t,cleanBorder:`right`}));i.add(e.parent),a.push({td:e.parent,cleanBorder:!0})}let o=t.descendants(U),s=new Map(o.map((e,t)=>[e,t]));a.sort((e,t)=>s.get(e.td)-s.get(t.td));let l=new $,u=0;for(let{td:e,cleanBorder:t}of a){let n=e.getCellInner().offset(this.quill.scroll),i=e.getCellInner().length(),a=r(n,i-1,e=>{if(!e||t===!0)return``;let n=pn(e);return mn(Object.keys(n).filter(e=>!e.startsWith(dn(`border-${t}`))).reduce((e,t)=>(e[t]=n[t],e),{}))}),o=new $().retain(n-u).concat(a);l=l.concat(o),u=n+i}this.quill.updateContents(l,e.sources.USER),n.length>1&&this.quill.blur();return}return n.call(this,a)}}}}async buildCustomSelect(e,t){if(!e||!x(e))return;let n=document.createElement(`div`);if(n.classList.add(`ql-custom-select`),this.selector=await e(this,t),n.appendChild(this.selector),this.options.fullSwitch){let e=l(`creator`),t=document.createElement(`label`);t.classList.add(e.be(`checkbox`));let r=document.createElement(`input`);r.type=`checkbox`,r.checked=this.options.full,r.addEventListener(`change`,()=>{this.options.full=r.checked});let i=document.createElement(`span`);i.textContent=this.options.texts.fullCheckboxText,t.appendChild(r),t.appendChild(i),n.appendChild(t)}t.options.innerHTML=``,t.options.appendChild(n)}setCellAttrs(e,t,n,r=!1){if(e.length!==0)for(let i of e)i.setFormatValue(t,n,r)}getTextByCell(e){let t=``;for(let n of e){let e=n.offset(this.quill.scroll),r=n.length();for(let n of this.quill.getContents(e,r).ops)C(n.insert)&&(t+=n.insert)}return t}getHTMLByCell(e,n=!1){if(e.length===0)return``;let r=null;try{for(let n of e){let e=u(n,t.tableMain);if(r||=e,e!==r)return console.error(`tableMain is not same`),``}}catch{return console.error(`tds must be in same tableMain`),``}if(!r)return``;let i=this.quill.getIndex(r),a=r.length(),o=this.quill.getSemanticHTML(i,a),s=new DOMParser().parseFromString(o,`text/html`),c=Array.from(s.querySelectorAll(`col`)),l=c.map(e=>e.dataset.colId),d=[],f=new Set,p=new Set;for(let t of e){f.add(t.colId);let e=t.colId,n=l.indexOf(e);for(let e=0;e<t.colspan;e++)f.add(l[n+e]);p.add(`${t.rowId}-${t.colId}`)}for(let e=0;e<c.length;e++){let t=c[e];f.has(t.dataset.colId)?d.push(t.getAttribute(`width`)):(t.remove(),c.splice(e--,1))}let m=0,h=null;for(let e of Array.from(s.querySelectorAll(`td, th`)))if(p.has(`${e.dataset.rowId}-${e.dataset.colId}`))h!==e.dataset.rowId&&(m+=1,h=e.dataset.rowId);else{let t=e.parentElement;e.remove(),t&&t.children.length<=0&&t.remove()}let g=c.map(e=>W.value(e));if(r.full){let e=g.reduce((e,t)=>t.width+e,0);for(let[t,n]of g.entries())n.width=Math.round(n.width/e*100),c[t].setAttribute(`width`,`${n.width}%`)}else{let e=0;for(let t of g)e+=t.width;let t=s.querySelector(`table`);t.style.width=`${e}px`}if(n){let t=r.getRows();if(m===t.length)this.removeCol(e);else for(let t of e)t.domNode.innerHTML=`<p><br></p>`}return s.body.innerHTML}insertTable(r,i,a=e.sources.API){if(r>=30||i>=30)throw Error(`Both rows and columns must be less than 30.`);this.quill.focus();let o=this.quill.getSelection();if(o==null)return;let[s]=this.quill.getLeaf(o.index);if(!s)return;if(c(s))throw Error(`Not supported ${s.statics.blotName} insert into table.`);let l=L(),u=Array(i).fill(0).map(()=>L()),d=this.calculateTableCellBorderWidth(),f=getComputedStyle(this.quill.root),p=Number.parseInt(f.paddingLeft),m=Number.parseInt(f.paddingRight),h=this.quill.root.scrollHeight>this.quill.root.clientHeight?cn({target:this.quill.root}):0,g=Number.parseInt(f.width)-p-m-d-h,_=this.options.full?`${Math.max(1/i*100,n.colMinWidthPre)}%`:`${Math.max(Math.floor(g/i),n.colMinWidthPx)}px`,v=[{retain:o.index}],y=this.quill.getContents(o.index,1),[,b]=this.quill.getLine(o.index);y.ops[0].insert!==`
133
+ </div>`}let i=document.createElement(`div`);i.classList.add(this.bem.be(`row`));let a=document.createElement(`div`);a.classList.add(this.bem.be(`row-wrapper`)),Object.assign(i.style,{transform:`translateX(-${this.options.size}px)`,width:`${this.options.size}px`,maxHeight:`${r.height}px`}),Object.assign(a.style,{height:`${e.height}px`}),a.innerHTML=t,i.appendChild(a),this.root.appendChild(i),i.scrollTop=this.tableWrapperBlot.domNode.scrollTop,this.rowHeadWrapper=i,this.bindRowEvents()}let[o]=p(this.tableBlot,Rn),s=!o||o?.side!==`top`;s?this.root.classList.remove(this.bem.is(`caption-bottom`)):this.root.classList.add(this.bem.is(`caption-bottom`));let c=-1*this.options.size,l=-1*this.options.size;kr(this.tableBlot)?(this.root.classList.add(this.bem.is(`align-right`)),c=Math.min(r.width,e.width),l=Math.min(r.width,e.width)):this.root.classList.remove(this.bem.is(`align-right`)),this.corner&&Object.assign(this.corner.style,{transform:`translateY(${-1*this.options.size}px) translateX(${c}px)`,top:`${s?0:e.height+this.options.size}px`}),this.rowHeadWrapper&&Object.assign(this.rowHeadWrapper.style,{transform:`translateX(${l}px)`,maxHeight:`${r.height}px`}),this.colHeadWrapper&&Object.assign(this.colHeadWrapper.style,{top:`${s?0:e.height+this.options.size}px`,maxWidth:`${r.width}px`})}show(){!this.table||!this.tableBlot||(this.root.classList.remove(this.bem.is(`hidden`)),this.resizeObserver=an(()=>this.update(),{ignoreFirstBind:!0}),this.resizeObserver.observe(this.table),this.update(),F.call(this,this.quill.root,()=>{this.update()}))}hide(){this.root.classList.add(this.bem.is(`hidden`)),this.resizeObserver&&=(this.resizeObserver.disconnect(),void 0)}destroy(){super.destroy(),this.hide(),I.call(this),this.quill.off(e.events.EDITOR_CHANGE,this.updateWhenTextChange);for(let[e,t]of this.scrollHandler)e.removeEventListener(`scroll`,t);this.root.remove()}},Lr=class extends Nr{static moduleName=`table-resize-line`;colResizer;rowResizer;currentTableCell;tableCellBlot;bem=l(`resize-line`);stopColDrag;stopRowDrag;scrollHandler=[];constructor(t,n){super(t,n),this.tableModule=t,this.quill=n,this.colResizer=this.tableModule.addContainer(this.bem.be(`col`)),this.rowResizer=this.tableModule.addContainer(this.bem.be(`row`)),this.quill.on(e.events.EDITOR_CHANGE,this.updateWhenTextChange)}setSelectionTable(e){this.table!==e&&(this.hide(),this.table=e,this.table&&this.show())}updateWhenTextChange=t=>{t===e.events.TEXT_CHANGE&&(this.table&&!this.quill.root.contains(this.table)?this.setSelectionTable(void 0):this.update())};findTableCell(e){for(let t of e.composedPath()){if(t instanceof HTMLElement&&[`TD`,`TH`].includes(t.tagName))return t;if(t===document.body)return null}return null}pointermoveHandler=n=>{if(this.dragging||this.tableModule.getModule(i.tableSelectionName)?.dragging)return;let r=this.findTableCell(n);if(!r)return this.hide();let a=e.find(r);a&&this.currentTableCell!==r&&(this.show(),this.currentTableCell=r,this.tableCellBlot=a,this.tableBlot=u(a,t.tableMain),this.tableBlot.getCols().length>0&&this.updateColResizer(),this.updateRowResizer(),F.call(this,this.quill.root,()=>{this.dragging||this.hideResizer()}))};findDragColIndex(e){return this.tableCellBlot?e.findIndex(e=>e.colId===this.tableCellBlot.colId):-1}updateColResizer(){if(!this.tableBlot||!this.tableCellBlot||!this.colResizer)return;this.colResizer.remove();let{rect:e}=J(this.tableBlot);if(!e)return;this.colResizer=this.tableModule.addContainer(this.bem.be(`col`));let t=this.tableCellBlot.domNode.getBoundingClientRect(),n=this.quill.root.getBoundingClientRect(),r=t.right-n.x;kr(this.tableBlot)&&(r=t.left-n.x),Object.assign(this.colResizer.style,{top:`${e.y-n.y}px`,left:`${r}px`,height:`${e.height}px`});let{stop:i}=en(this.colResizer,{axis:`x`,onStart:(e,t)=>{if(this.dragging=!0,this.calculateColDragRange(),this.dragXCommon.createBreak(),!this.tableBlot)return;let n=this.tableBlot.domNode.parentElement.getBoundingClientRect(),{rect:r}=J(this.tableBlot);if(!r)return;this.dragXCommon.startValue=r.x;let i=this.quill.root.getBoundingClientRect();Object.assign(this.dragXCommon.dragBreak.style,{top:`${Math.max(n.y,r.y)-i.y}px`,left:`${t.clientX-i.x}px`,height:`${Math.min(n.height,r.height)}px`})},onMove:({position:e})=>{if(!this.dragXCommon.dragBreak)return;let t=this.dragXCommon.limitRange(this.tableBlot,e.x,!0),n=this.quill.root.getBoundingClientRect();this.dragXCommon.dragBreak.style.left=`${t-n.x}px`},onEnd:({position:e})=>{if(this.dragging=!1,this.colResizer){let t=this.dragXCommon.limitRange(this.tableBlot,e.x,!0),n=this.quill.root.getBoundingClientRect();this.colResizer.style.left=`${t-n.x}px`}this.updateTableCol(e.x),this.removeBreak()}});this.stopColDrag&&this.stopColDrag(),this.stopColDrag=i,this.colResizer.addEventListener(`dragstart`,e=>e.preventDefault())}findDragRowIndex(e){if(!this.tableCellBlot)return-1;let t=this.tableCellBlot.parent;return t instanceof H?e.indexOf(t):-1}updateRowResizer(){if(!this.tableBlot||!this.tableCellBlot||!this.rowResizer)return;let e=this.tableCellBlot;this.rowResizer.remove();let{rect:t}=J(this.tableBlot);if(!t)return;this.rowResizer=this.tableModule.addContainer(this.bem.be(`row`));let n=e.domNode.getBoundingClientRect(),r=this.quill.root.getBoundingClientRect();Object.assign(this.rowResizer.style,{top:`${n.bottom-r.y}px`,left:`${t.x-r.x}px`,width:`${t.width}px`});let{stop:i}=en(this.rowResizer,{axis:`y`,onStart:(e,t)=>{if(this.dragging=!0,this.calculateRowDragRange(),this.dragYCommon.createBreak(),!this.tableBlot)return;let n=this.tableBlot.domNode.parentElement.getBoundingClientRect(),{rect:r}=J(this.tableBlot);if(!r)return;this.dragYCommon.startValue=r.y;let i=this.quill.root.getBoundingClientRect();Object.assign(this.dragYCommon.dragBreak.style,{top:`${t.clientY-i.y}px`,left:`${Math.max(n.x,r.x)-i.x}px`,width:`${Math.min(n.width,r.width)}px`})},onMove:({position:e})=>{if(!this.dragYCommon.dragBreak||!this.table)return;let t=this.dragYCommon.limitRange(this.tableBlot,e.y,!0),n=this.quill.root.getBoundingClientRect();this.dragYCommon.dragBreak.style.top=`${t-n.y}px`},onEnd:({position:e})=>{if(this.dragging=!1,this.rowResizer){let t=this.dragYCommon.limitRange(this.tableBlot,e.y,!0),n=this.quill.root.getBoundingClientRect();this.rowResizer.style.left=`${t-n.y}px`}this.updateTableRow(e.y),this.removeBreak()}});this.stopRowDrag&&this.stopRowDrag(),this.stopRowDrag=i,this.rowResizer.addEventListener(`dragstart`,e=>e.preventDefault())}show(){!this.table||!this.rowResizer||!this.colResizer||(this.rowResizer.classList.remove(this.bem.is(`hidden`)),this.colResizer.classList.remove(this.bem.is(`hidden`)),this.table.addEventListener(`pointermove`,this.pointermoveHandler))}hideResizer(){!this.rowResizer||!this.colResizer||(this.rowResizer.classList.add(this.bem.is(`hidden`)),this.colResizer.classList.add(this.bem.is(`hidden`)))}hide(){this.currentTableCell=void 0,I.call(this),this.hideResizer(),this.table&&this.table.removeEventListener(`pointermove`,this.pointermoveHandler)}destroy(){super.destroy(),this.colResizer&&=(this.colResizer.remove(),void 0),this.rowResizer&&=(this.rowResizer.remove(),void 0),this.quill.off(e.events.EDITOR_CHANGE,this.updateWhenTextChange)}},Rr=class extends Y{static moduleName=`table-resize-scale`;scrollHandler=[];tableMainBlot;tableWrapperBlot;bem=l(`scale`);options;root;block;resizeobserver=new ResizeObserver(()=>this.update());constructor(t,n,r){super(t,n),this.tableModule=t,this.quill=n,this.options=this.resolveOptions(r),this.quill.on(e.events.EDITOR_CHANGE,this.updateWhenTextChange)}updateWhenTextChange=t=>{t===e.events.TEXT_CHANGE&&(this.table&&!this.quill.root.contains(this.table)?this.setSelectionTable(void 0):this.update())};resolveOptions(e){return Object.assign({blockSize:12,offset:6},e)}buildResizer(){if(!this.tableMainBlot||!this.tableWrapperBlot)return;this.root=this.tableModule.addContainer(this.bem.b()),this.block=document.createElement(`div`),this.block.classList.add(this.bem.be(`block`)),Object.assign(this.block.style,{width:`${this.options.blockSize}px`,height:`${this.options.blockSize}px`}),this.root.appendChild(this.block);let e=[],t=[];en(this.block,{onStart:()=>{this.tableMainBlot&&(e=this.tableMainBlot.getCols().map(e=>({blot:e,width:Math.floor(e.width)})),t=this.tableMainBlot.getRows().map(e=>({blot:e,height:Math.floor(e.domNode.getBoundingClientRect().height)})))},onMove:({movePosition:r})=>{if(!this.tableMainBlot)return;let i=kr(this.tableMainBlot)?-1:1,a=r.x*i,o=r.y,s=Math.floor(a/e.length),c=Math.floor(o/t.length);for(let{blot:t,width:r}of e)t.width=Math.max(r+s,n.colMinWidthPx);for(let{blot:e,height:r}of t)e.setHeight(`${Math.max(r+c,n.rowMinHeightPx)}px`)},onEnd:()=>{e=[],t=[]}}),this.block.addEventListener(`dragstart`,e=>e.preventDefault())}update(){if(!this.block||!this.root||!this.tableMainBlot||!this.tableWrapperBlot)return;if(this.tableMainBlot.full){this.hide();return}let{rect:e}=J(this.tableMainBlot);if(!e)return;let t=this.tableWrapperBlot.domNode.getBoundingClientRect(),n=this.quill.root.getBoundingClientRect(),{scrollTop:r,scrollLeft:i}=this.tableWrapperBlot.domNode,a=this.options.blockSize*2+this.options.offset,o=Math.min(e.width,t.width)+a,s=Math.min(e.height,t.height)+a;Object.assign(this.root.style,{width:`${o}px`,height:`${s}px`,left:`${Math.max(e.x,t.x)-n.x-this.options.blockSize}px`,top:`${Math.max(e.y,t.y)-n.y-this.options.blockSize}px`});let c={left:`${e.width+a-i}px`,top:`${s-r}px`};kr(this.tableMainBlot)?(this.root.classList.add(this.bem.is(`align-right`)),c.left=`${this.options.blockSize+-1*i}px`):this.root.classList.remove(this.bem.is(`align-right`)),Object.assign(this.block.style,c)}show(){this.table&&(this.tableMainBlot=e.find(this.table),this.tableMainBlot&&!this.tableMainBlot.full&&(this.tableWrapperBlot=this.tableMainBlot.parent,this.resizeobserver.observe(this.tableMainBlot.domNode),F.call(this,this.quill.root,()=>this.update()),F.call(this,this.tableWrapperBlot.domNode,()=>this.update())),this.buildResizer())}hide(){this.tableMainBlot=void 0,this.tableWrapperBlot=void 0,this.root&&(this.root.remove(),this.root=void 0,this.block=void 0),I.call(this)}destroy(){super.destroy(),this.hide(),this.quill.off(e.events.EDITOR_CHANGE,this.updateWhenTextChange),this.resizeobserver.disconnect()}};const zr={size:`height`,offset:`offsetHeight`,scrollDirection:`scrollTop`,scrollSize:`scrollHeight`,axis:`y`,direction:`top`,client:`clientY`},Br={size:`width`,offset:`offsetWidth`,scrollDirection:`scrollLeft`,scrollSize:`scrollWidth`,axis:`x`,direction:`left`,client:`clientX`};var Vr=class{minSize=20;gap=4;move=0;cursorDown=!1;cursorLeave=!1;ratioY=1;ratioX=1;sizeWidth=``;sizeHeight=``;size=``;bem=l(`scrollbar`);tableMainBlot;ob;container;scrollbar;thumb=document.createElement(`div`);scrollHandler=[];propertyMap;thumbState={x:0,y:0};get isVertical(){return this.options.isVertical}constructor(t,n,r){this.quill=t,this.table=n,this.options=r,this.tableMainBlot=e.find(this.table),this.container=n.parentElement,this.propertyMap=this.isVertical?zr:Br,this.calculateSize(),this.ob=new ResizeObserver(()=>this.update()),this.ob.observe(n),this.scrollbar=this.createScrollbar(),this.setScrollbarPosition(),F.call(this,this.quill.root,()=>this.setScrollbarPosition()),this.showScrollbar()}update(){this.calculateSize(),this.setScrollbarPosition()}setScrollbarPosition(){let{rect:e,head:t,body:n,foot:r}=J(this.tableMainBlot),i=t||n||r;if(!i||!e)return;let{scrollLeft:a,scrollTop:o,offsetLeft:s,offsetTop:c}=this.quill.root,{offsetLeft:l,offsetTop:u}=this.container,{offsetLeft:d,offsetTop:f}=i.domNode,{width:p,height:m}=this.container.getBoundingClientRect(),h=l+d-s,g=u+f-c;this.isVertical?h+=Math.min(p,e.width):g+=Math.min(m,e.height),this.tableMainBlot&&this.tableMainBlot.align!==`left`&&(h+=this.table.offsetLeft-l),Object.assign(this.scrollbar.style,{[this.propertyMap.size]:`${this.isVertical?Math.min(m,e.height):p}px`,transform:`translate(${h-a}px, ${g-o}px)`}),this.containerScrollHandler(this.container)}calculateSize(){let e=this.container.offsetHeight-this.gap,t=this.container.offsetWidth-this.gap,n=e**2/this.container.scrollHeight,r=t**2/this.container.scrollWidth,i=Math.max(n,this.minSize),a=Math.max(r,this.minSize);this.ratioY=n/(e-n)/(i/(e-i)),this.ratioX=r/(t-r)/(a/(t-a)),this.sizeWidth=a+this.gap<t?`${a}px`:``,this.sizeHeight=i+this.gap<e?`${i}px`:``,this.size=this.isVertical?this.sizeHeight:this.sizeWidth}createScrollbar(){let e=document.createElement(`div`);e.classList.add(this.bem.b(),this.isVertical?this.bem.is(`vertical`):this.bem.is(`horizontal`),this.bem.is(`transparent`)),Object.assign(e.style,{display:`none`}),this.thumb.classList.add(this.bem.be(`thumb`));let t=null,n=e=>{if(this.cursorDown===!1)return;let t=this.thumbState[this.propertyMap.axis];if(!t)return;let n=this.scrollbar[this.propertyMap.offset]**2/this.container[this.propertyMap.scrollSize]/(this.isVertical?this.ratioY:this.ratioX)/this.thumb[this.propertyMap.offset],r=((this.scrollbar.getBoundingClientRect()[this.propertyMap.direction]-e[this.propertyMap.client])*-1-(this.thumb[this.propertyMap.offset]-t))*100*n/this.scrollbar[this.propertyMap.offset];this.container[this.propertyMap.scrollDirection]=r*this.container[this.propertyMap.scrollSize]/100},r=()=>{this.thumbState[this.propertyMap.axis]=0,this.cursorDown=!1,document.removeEventListener(`mousemove`,n),document.removeEventListener(`mouseup`,r),this.cursorLeave&&this.hideScrollbar(),document.onselectstart=t},i=e=>{e.stopImmediatePropagation(),this.cursorDown=!0,document.addEventListener(`mousemove`,n),document.addEventListener(`mouseup`,r),t=document.onselectstart,document.onselectstart=()=>!1};this.thumb.addEventListener(`mousedown`,e=>{if(e.stopPropagation(),e.ctrlKey||[1,2].includes(e.button))return;window.getSelection()?.removeAllRanges(),i(e);let t=e.currentTarget;t&&(this.thumbState[this.propertyMap.axis]=t[this.propertyMap.offset]-(e[this.propertyMap.client]-t.getBoundingClientRect()[this.propertyMap.direction]))});let a=[this.table,e];for(let e of a)e.addEventListener(`mouseenter`,this.showScrollbar),e.addEventListener(`mouseleave`,this.hideScrollbar);return F.call(this,this.container,()=>{this.containerScrollHandler(this.container)}),e.appendChild(this.thumb),e}containerScrollHandler(e){let t=e[this.propertyMap.offset]-this.gap;this.move=e[this.propertyMap.scrollDirection]*100/t*(this.isVertical?this.ratioY:this.ratioX),Object.assign(this.thumb.style,{[this.propertyMap.size]:this.size,transform:`translate${this.propertyMap.axis.toUpperCase()}(${this.move}%)`})}showScrollbar=hn(()=>{this.cursorLeave=!1,this.scrollbar.removeEventListener(`transitionend`,this.hideScrollbarTransitionend),this.scrollbar.style.display=this.size?`block`:`none`,requestAnimationFrame(()=>{this.scrollbar.classList.remove(this.bem.is(`transparent`))})},200);hideScrollbar=hn(()=>{this.cursorLeave=!0,!this.cursorDown&&(this.scrollbar.removeEventListener(`transitionend`,this.hideScrollbarTransitionend),this.scrollbar.addEventListener(`transitionend`,this.hideScrollbarTransitionend,{once:!0}),this.scrollbar.classList.add(this.bem.is(`transparent`)))},200);hideScrollbarTransitionend=()=>{this.scrollbar.style.display=this.cursorDown&&this.size?`block`:`none`};destroy(){this.ob.disconnect(),I.call(this),this.table.removeEventListener(`mouseenter`,this.showScrollbar),this.table.removeEventListener(`mouseleave`,this.hideScrollbar)}},Hr=class extends Y{static moduleName=`table-scrollbar`;scrollbarContainer;scrollbar=[];bem=l(`scrollbar`);constructor(t,n,r){super(t,n),this.tableModule=t,this.quill=n;let i=l(`scrollbar`);this.quill.container.classList.add(i.bm(`virtual`)),this.scrollbarContainer=this.tableModule.addContainer(this.bem.be(`container`)),this.quill.on(e.events.EDITOR_CHANGE,this.updateWhenTextChange)}updateWhenTextChange=t=>{t===e.events.TEXT_CHANGE&&(this.table&&!this.quill.root.contains(this.table)?this.setSelectionTable(void 0):this.update())};hide(){for(let e of this.scrollbar)e.destroy();this.scrollbar=[],this.scrollbarContainer.innerHTML=``}show(){if(this.table){this.scrollbar=[new Vr(this.quill,this.table,{isVertical:!0}),new Vr(this.quill,this.table,{isVertical:!1})];for(let e of this.scrollbar)this.scrollbarContainer.appendChild(e.scrollbar),e.showScrollbar()}}update(){if(this.table){this.scrollbar.length<=0&&this.show();for(let e of this.scrollbar)e.calculateSize(),e.setScrollbarPosition()}else this.scrollbar.length>0&&this.hide()}destroy(){super.destroy(),this.hide(),this.scrollbarContainer.remove(),this.quill.off(e.events.TEXT_CHANGE,this.updateWhenTextChange)}},Ur=class extends Y{static moduleName=i.tableSelectionName;options;boundary=null;scrollRecordEls=[];startScrollRecordPosition=[];selectedTableScrollX=0;selectedTableScrollY=0;selectedEditorScrollX=0;selectedEditorScrollY=0;selectedTds=[];cellSelectWrap;cellSelect;scrollHandler=[];resizeObserver;isDisplaySelection=!1;bem=l(`selection`);autoScroller;lastSelection={anchorNode:null,anchorOffset:0,focusNode:null,focusOffset:0};_dragging=!1;set dragging(e){this._dragging!==e&&(this._dragging=e,this.quill.emitter.emit(e?r.TABLE_SELECTION_DRAG_START:r.TABLE_SELECTION_DRAG_END,this))}get dragging(){return this._dragging}constructor(t,n,i={}){super(t,n),this.tableModule=t,this.quill=n,this.options=this.resolveOptions(i),this.scrollRecordEls=[this.quill.root,document.documentElement],this.cellSelectWrap=t.addContainer(this.bem.b()),this.cellSelect=this.helpLinesInitial(),this.resizeObserver=an(this.updateAfterEvent,{ignoreFirstBind:!0}),this.resizeObserver.observe(this.quill.root),document.addEventListener(`paste`,this.handlePaste),document.addEventListener(`selectionchange`,this.selectionChangeHandler),this.quill.on(r.AFTER_TABLE_RESIZE,this.updateAfterEvent),this.quill.on(e.events.SELECTION_CHANGE,this.quillSelectionChangeHandler),this.quill.on(e.events.EDITOR_CHANGE,this.updateWhenTextChange),this.autoScroller=new ln(50,40),this.hide()}handlePaste=e=>{if(!(document.activeElement&&this.quill.root.contains(document.activeElement))||this.quill.getSelection())return;let n=e.clipboardData;if(!n)return;e.preventDefault();let r=this.selectedTds;if(r.length<=0)return;let i=n.getData(`text/html`),a=this.quill.clipboard.convert({html:i}).ops.filter(e=>e.attributes?.[t.tableCellInner]);a.length!==0&&Gn({quill:this.quill,talbeModule:this.tableModule},r,a)};keyboardHandler=async e=>{if(e.ctrlKey)switch(e.key){case`c`:case`x`:await wr(this.tableModule,this.selectedTds,e.key===`x`);break}else (e.key===`Backspace`||e.key===`Delete`)&&this.removeCellBySelectedTds()};updateWhenTextChange=t=>{t===e.events.TEXT_CHANGE&&(this.table&&!this.quill.root.contains(this.table)?this.setSelectionTable(void 0):this.updateAfterEvent())};updateAfterEvent=()=>{for(let e of this.selectedTds)if(!e.domNode.isConnected){this.selectedTds=[];break}this.updateWithSelectedTds()};removeCellBySelectedTds(){let t=this.quill.getSelection(),n=document.activeElement;if(!(t||!this.quill.root.contains(n))){if(this.table){let t=e.find(this.table),n=t.descendants(V);if(this.selectedTds.length===n.length){t.remove();return}}for(let e of this.selectedTds){let t=e.clone();t.appendChild(e.scroll.create(`block`)),e.parent.insertBefore(t,e),e.remove()}}}setSelectedTds(e){let t=new Set(this.selectedTds),n=this.selectedTds.length===e.length&&e.every(e=>t.has(e));this.selectedTds=e,n||this.quill.emitter.emit(r.TABLE_SELECTION_CHANGE,this,this.selectedTds)}quillSelectionChangeHandler=(n,r,i)=>{if(i!==e.sources.API&&n&&!this.quill.composition.isComposing&&this.selectedTds.length>0){let e=this.quill.getFormat(n),[r]=this.quill.getLine(n.index),i=!!e[t.tableCellInner]&&!!r,a=r&&this.selectedTds.some(e=>e.domNode.contains(r.domNode));if(i&&!a)try{let e=u(r,t.tableCellInner);this.setSelectedTds([e]),this.updateWithSelectedTds()}catch{}else i&&a||this.hide()}};setSelectionData(e,t){let{anchorNode:n,anchorOffset:r,focusNode:i,focusOffset:a}=t;if(!n||!i)return;let o=document.createRange(),s=this.selectionDirectionUp(t);s?(o.setStart(n,r),o.setEnd(n,r)):(o.setStart(n,r),o.setEnd(i,a)),e.removeAllRanges(),e.addRange(o),s&&e.extend(i,a)}selectionDirectionUp(e){let{anchorNode:t,anchorOffset:n,focusNode:r,focusOffset:i}=e;if(!t||!r)return!1;if(t===r)return n>i;let a=t.compareDocumentPosition(r);return a&Node.DOCUMENT_POSITION_CONTAINS||a&Node.DOCUMENT_POSITION_CONTAINED_BY?(a&Node.DOCUMENT_POSITION_FOLLOWING)!==0:(a&Node.DOCUMENT_POSITION_PRECEDING)!==0}resolveOptions(e){return Object.assign({selectColor:`#0589f340`},e)}selectionChangeHandler=()=>{let n=window.getSelection();if(!n)return;let{anchorNode:r,focusNode:i,anchorOffset:a,focusOffset:o}=n;if(!r||!i)return;let s=e.find(r),c=e.find(i);if(!s||!c||s.scroll!==this.quill.scroll||c.scroll!==this.quill.scroll)return;let l=f(s),u=f(c),d=l.has(t.tableColgroup),p=u.has(t.tableColgroup);if(d||p){let e=r,s=a,c=i,f=o;if(d){let n=l.get(t.tableWrapper).descendants(V);n.length>0&&(e=n[0].domNode,s=0)}if(p){let e=u.get(t.tableWrapper).descendants(V);e.length>0&&(c=e[0].domNode,f=0)}this.setSelectionData(n,{anchorNode:e,anchorOffset:s,focusNode:c,focusOffset:f});return}let m=l.has(t.tableCellInner),h=u.has(t.tableCellInner),g=m&&h;if(g){let e=l.get(t.tableCellInner),n=u.get(t.tableCellInner);g&&=e!==n}if(m&&h&&g||!m&&h||!h&&m){this.setSelectionData(n,this.lastSelection),this.selectedTds.length>0&&this.hide();return}this.lastSelection={anchorNode:r,anchorOffset:a,focusNode:i,focusOffset:o}};helpLinesInitial(){this.cellSelectWrap.style.setProperty(`--select-color`,this.options.selectColor);let e=document.createElement(`div`);return e.classList.add(this.bem.be(`line`)),this.cellSelectWrap.appendChild(e),e}computeSelectedTds(t,n){if(!this.table)return[];let r=e.find(this.table);if(!r)return[];let i=new Set(r.descendants(U).map((e,t)=>(e.index=t,e))),a=this.getScrollPositionDiff(),{rect:o}=J(r);if(!o)return[];let s=t.x+a.x,c=t.y+a.y,l={x:Math.max(o.left,Math.min(n.x,s)),y:Math.max(o.top,Math.min(n.y,c)),x1:Math.min(o.right,Math.max(n.x,s)),y1:Math.min(o.bottom,Math.max(n.y,c))},u=new Set,d=!0;for(;d;){d=!1;for(let e of i){e.__rect||=e.domNode.getBoundingClientRect();let{x:t,y:n,right:r,bottom:a}=e.__rect;if(tn({x:Math.floor(l.x),y:Math.floor(l.y),x1:Math.floor(l.x1),y1:Math.floor(l.y1)},{x:Math.floor(t),y:Math.floor(n),x1:Math.floor(r),y1:Math.floor(a)},0,u.size===0)){u.add(e),i.delete(e),l={x:Math.min(l.x,t),y:Math.min(l.y,n),x1:Math.max(l.x1,r),y1:Math.max(l.y1,a)},d=!0;break}}}for(let e of[...u,...i])delete e.__rect;return this.boundary=nn({...l,width:l.x1-l.x,height:l.y1-l.y},this.quill.root),Array.from(u).toSorted((e,t)=>e.index-t.index).map(e=>(delete e.index,e.getCellInner()))}getScrollPositionDiff(){let{x:e,y:t}=this.getTableViewScroll(),{x:n,y:r}=sn(this.quill.root);return this.selectedTableScrollX=e,this.selectedTableScrollY=t,this.selectedEditorScrollX=n,this.selectedEditorScrollY=r,this.startScrollRecordPosition.reduce((e,{x:t,y:n},r)=>{let{x:i,y:a}=sn(this.scrollRecordEls[r]);return e.x+=t-i,e.y+=n-a,e},{x:0,y:0})}recordScrollPosition(){this.clearRecordScrollPosition();for(let e of this.scrollRecordEls)this.startScrollRecordPosition.push(sn(e))}clearRecordScrollPosition(){this.startScrollRecordPosition=[]}tableSelectHandler(t){let{button:n,target:r,clientX:i,clientY:a}=t,o=r.closest(`table`),s=r.closest(`caption`);if(n!==0||!o||s)return;this.setSelectionTable(o);let c=o.dataset.tableId,l={x:i,y:a};this.recordScrollPosition(),this.setSelectedTds(this.computeSelectedTds(l,l)),this.show();let u=e=>{this.dragging=!0;let{button:t,target:n,clientX:r,clientY:i}=e,a=n.closest(`.ql-table`),o=n.closest(`caption`);if(t!==0||o||!a||a.dataset.tableId!==c)return;let s={x:r,y:i};this.setSelectedTds(this.computeSelectedTds(l,s)),this.selectedTds.length>1&&this.quill.blur(),this.update(),this.autoScroller.updateMousePosition(r,i)},d=()=>{document.body.removeEventListener(`mousemove`,u,!1),document.body.removeEventListener(`mouseup`,d,!1),this.autoScroller.stop(),this.dragging=!1,this.clearRecordScrollPosition()};document.body.addEventListener(`mousemove`,u,!1),document.body.addEventListener(`mouseup`,d,!1);let f=e.find(o);if(!f)return;let p=f.parent.domNode;this.autoScroller.updateMousePosition(i,a),this.autoScroller.start(p)}updateWithSelectedTds(){if(this.selectedTds.length<=0){this.hide();return}let e={x:1/0,y:1/0},t={x:-1/0,y:-1/0};for(let n of this.selectedTds){let r=n.domNode.getBoundingClientRect();e.x=Math.min(e.x,r.left),e.y=Math.min(e.y,r.top),t.x=Math.max(t.x,r.right),t.y=Math.max(t.y,r.bottom)}this.setSelectedTds(this.computeSelectedTds(e,t)),this.selectedTds.length>0?this.update():this.hide()}update(){if(!this.table){this.hide();return}if(this.selectedTds.length===0||!this.boundary)return;let{x:e,y:t}=sn(this.quill.root),{x:n,y:i}=this.getTableViewScroll(),a=this.table.parentElement.getBoundingClientRect(),o=this.quill.root.getBoundingClientRect(),s=a.x-o.x,c=a.y-o.y;Object.assign(this.cellSelect.style,{left:`${this.selectedEditorScrollX*2-e+this.boundary.x+this.selectedTableScrollX-n-s}px`,top:`${this.selectedEditorScrollY*2-t+this.boundary.y+this.selectedTableScrollY-i-c}px`,width:`${this.boundary.width}px`,height:`${this.boundary.height}px`}),Object.assign(this.cellSelectWrap.style,{left:`${s}px`,top:`${c}px`,width:`${a.width}px`,height:`${a.height}px`}),this.quill.emitter.emit(r.TABLE_SELECTION_DISPLAY_CHANGE,this)}getTableViewScroll(){return this.table?sn(this.table.parentElement):{x:0,y:0}}setSelectionTable(e){this.table!==e&&(this.table=e,this.table?this.scrollRecordEls.push(this.table.parentElement):this.scrollRecordEls.pop())}showDisplay(){Object.assign(this.cellSelectWrap.style,{display:`block`}),this.isDisplaySelection=!0,this.table&&this.resizeObserver.observe(this.table)}show(){this.table&&(I.call(this),this.showDisplay(),this.update(),this.quill.root.addEventListener(`keydown`,this.keyboardHandler),F.call(this,this.quill.root,()=>{this.update()}),F.call(this,this.table.parentElement,()=>{this.update()}))}hideDisplay(){Object.assign(this.cellSelectWrap.style,{display:`none`}),this.isDisplaySelection=!1,this.table&&this.resizeObserver.unobserve(this.table)}hide(){I.call(this),this.quill.root.removeEventListener(`keydown`,this.keyboardHandler),this.hideDisplay(),this.boundary=null,this.setSelectedTds([]),this.setSelectionTable(void 0)}destroy(){super.destroy(),this.resizeObserver.disconnect(),this.hide(),this.cellSelectWrap.remove(),I.call(this),document.removeEventListener(`paste`,this.handlePaste),document.removeEventListener(`selectionchange`,this.selectionChangeHandler),this.quill.off(r.AFTER_TABLE_RESIZE,this.updateAfterEvent),this.quill.off(e.events.EDITOR_CHANGE,this.updateWhenTextChange),this.quill.off(e.events.SELECTION_CHANGE,this.quillSelectionChangeHandler)}};const Wr=e.import(`parchment`),$=e.import(`delta`),Gr=e.import(`ui/icons`),Kr=e.import(`blots/break`),qr=e.import(`blots/block`),Jr=e.import(`blots/block/embed`);function Yr(e,{tableId:n,rowId:r,colId:i}){let a={tableId:n,rowId:r,colId:i,colspan:1,rowspan:1},o=e.create(t.tableCell,a),s=e.create(t.tableCellInner,a),c=e.create(`block`);return c.appendChild(e.create(`break`)),s.appendChild(c),o.appendChild(s),o}function Xr(e){o.delete(t.tableCellInner),Object.assign(t,e.blotName||{}),Object.assign(n,e.tableUpSize||{}),Object.assign(r,e.tableUpEvent||{}),Object.assign(i,e.tableUpInternal||{}),$r.moduleName=i.moduleName,$r.toolName=t.tableWrapper,R.blotName=t.container,Rn.blotName=t.tableCaption,q.blotName=t.tableWrapper,G.blotName=t.tableMain,K.blotName=t.tableColgroup,W.blotName=t.tableCol,Vn.blotName=t.tableHead,B.blotName=t.tableBody,Bn.blotName=t.tableFoot,H.blotName=t.tableRow,U.blotName=t.tableCell,V.blotName=t.tableCellInner,o.add(t.tableCellInner)}function Zr(t,n){return w({onSelect:(r,i)=>{t.insertTable(r,i,e.sources.USER),n&&n.close()},customBtn:t.options.customBtn,texts:t.options.texts})}function Qr(n){return{bindInHead:!1,key:n?`ArrowUp`:`ArrowDown`,collapsed:!0,format:[t.tableCellInner],handler(r,i){let a=n?`prev`:`next`,o=n?`tail`:`head`;if(i.line[a])return!0;let s=this.quill.selection.getBounds(r.index),c=i.line.domNode.getBoundingClientRect();if(!s||!c)return!0;if(n){if(s.top-c.top>3)return!0}else if(c.bottom-s.bottom>3)return!0;let l,u,f,p;try{[l,u,f,p]=d(i.line,[t.tableWrapper,t.tableMain,t.tableRow,t.tableCell])}catch{return!0}let m=u.getColIds(),h=l.descendants(Rn,0)[0],g;if(h){let e=window.getComputedStyle(h.domNode);g=a===`next`&&e.captionSide===`bottom`?h:a===`next`?l.next:h}else g=l[a];if(i.line[a]||!g)return!0;let _=f[a];if(_){let t=m.indexOf(p.colId),n=_.getCellByColId(m[t],a);if(!n)return!0;let r=n.children[o];r.children&&(r=r.children[o]);let s=r.offset(this.quill.scroll)+Math.min(i.offset,r.length()-1);this.quill.setSelection(s,0,e.sources.USER)}else{let t=g.offset(this.quill.scroll)+(n?g.length()-1:0);this.quill.setSelection(t,0,e.sources.USER)}return!1}}}var $r=class r{static moduleName=i.moduleName;static toolName=t.tableWrapper;static keyboradHandler={"forbid remove table by backspace":{bindInHead:!0,key:`Backspace`,collapsed:!0,offset:0,handler(e,n){let r=this.quill.getLine(e.index)[0];return r.prev instanceof q?(r.prev.remove(),!1):!(n.format[t.tableCellInner]&&r.offset(u(r,t.tableCellInner))===0)}},"forbid remove table by delete":{bindInHead:!0,key:`Delete`,collapsed:!0,handler(e,n){let r=this.quill.getLine(e.index),i=r[0],a=r[1];return!((i.next instanceof q||i.next instanceof W)&&a===i.length()-1||n.format[t.tableCellInner]&&i===u(i,t.tableCellInner).children.tail&&a===i.length()-1)}},"table up":Qr(!0),"table down":Qr(!1),"table caption break":{bindInHead:!0,key:`Enter`,shiftKey:null,format:[t.tableCaption],handler(e,t){return!1}}};static register(){q.allowedChildren=[G],G.allowedChildren=[K,Rn,Vn,B,Bn],G.requiredContainer=q,Rn.requiredContainer=G,K.allowedChildren=[W],K.requiredContainer=G,Vn.allowedChildren=[H],Vn.requiredContainer=G,B.allowedChildren=[H],B.requiredContainer=G,Bn.allowedChildren=[H],Bn.requiredContainer=G,H.allowedChildren=[U],U.allowedChildren=[V,Kr],U.requiredContainer=H,V.requiredContainer=U;let n=new Set([`table`]),r=Object.entries(e.imports).filter(([e,t])=>{let r=e.split(`formats/`)[1];return e.startsWith(`formats/`)&&!n.has(r)&&(g(t,qr)||g(t,Jr))}).reduce((e,[t,n])=>{let r=g(n,Jr)?Dn:Tn;return e[t]=class extends h(n,[r]){static register(){}},e},{});e.register({"blots/scroll":Nn,"blots/block":Tn,"blots/block/embed":Dn,...r,[`blots/${t.container}`]:R,[`formats/${t.tableCell}`]:U,[`formats/${t.tableCellInner}`]:V,[`formats/${t.tableRow}`]:H,[`formats/${t.tableHead}`]:Vn,[`formats/${t.tableBody}`]:B,[`formats/${t.tableFoot}`]:Bn,[`formats/${t.tableCol}`]:W,[`formats/${t.tableColgroup}`]:K,[`formats/${t.tableCaption}`]:Rn,[`formats/${t.tableMain}`]:G,[`formats/${t.tableWrapper}`]:q,"modules/clipboard":or},!0)}quill;options;textOptionsInput;toolBox;fixTableByLisenter=hn(this.balanceTables,100);selector;resizeOb;editableObserver;modules={};get statics(){return this.constructor}constructor(e,t){this.quill=e,this.textOptionsInput=t?.texts,this.options=this.resolveOptions(t||{}),this.toolBox=this.initialContainer();let n=this.getToolbarPicker();n&&(n.label.innerHTML=this.options.icon,this.buildCustomSelect(this.options.customSelect,n),n.label.addEventListener(`mousedown`,()=>{if(!this.selector)return;let{leftLimited:e}=rn(this.selector.getBoundingClientRect());if(e){let e=n.label.getBoundingClientRect();Object.assign(n.options.style,{transform:`translateX(calc(-100% + ${e.width}px))`})}else Object.assign(n.options.style,{transform:void 0})}));let i=this.quill.getModule(`keyboard`);for(let e of Object.values(r.keyboradHandler))e.bindInHead?i.bindings[e.key].unshift(e):i.addBinding(e.key,e);this.initModules(),this.listenEditableChange(),this.quillHack(),this.listenBalanceCells()}initialContainer(){let e=l(`toolbox`),t=this.quill.addContainer(e.b());return this.resizeOb=new ResizeObserver(()=>{let e=this.quill.root.getBoundingClientRect(),{offsetLeft:n,offsetTop:r}=this.quill.root;Object.assign(t.style,{top:`${r}px`,left:`${n}px`,width:`${e.width}px`,height:`${e.height}px`})}),this.resizeOb.observe(this.quill.root),t}addContainer(e){if(C(e)){let t=document.createElement(`div`);for(let n of e.split(` `))t.classList.add(n);return this.toolBox.appendChild(t),t}else return this.toolBox.appendChild(e),e}getToolbarPicker(){let e=this.quill.getModule(`toolbar`);if(!e||!this.quill.theme.pickers)return;let[,t]=(e.controls||[]).find(([e])=>e===this.statics.toolName)||[];if(t?.tagName.toLocaleLowerCase()===`select`)return this.quill.theme.pickers.find(e=>e.select===t)}resolveOptions(e){let{texts:t,...n}=e;return Object.assign({customBtn:!1,texts:this.resolveTexts(t),full:!1,fullSwitch:!0,icon:Gr.table,autoMergeCell:!0,modules:[]},n)}resolveTexts(e){let t={fullCheckboxText:`Insert full width table`,customBtnText:`Custom`,confirmText:`Confirm`,cancelText:`Cancel`,rowText:`Row`,colText:`Column`,notPositiveNumberError:`Please enter a positive integer`,custom:`Custom`,clear:`Clear`,transparent:`Transparent`,perWidthInsufficient:`The percentage width is insufficient. To complete the operation, the table needs to be converted to a fixed width. Do you want to continue?`,CopyCell:`Copy cell`,CutCell:`Cut cell`,InsertTop:`Insert row above`,InsertRight:`Insert column right`,InsertBottom:`Insert row below`,InsertLeft:`Insert column Left`,MergeCell:`Merge Cell`,SplitCell:`Split Cell`,DeleteRow:`Delete Row`,DeleteColumn:`Delete Column`,DeleteTable:`Delete table`,BackgroundColor:`Set background color`,BorderColor:`Set border color`};if(x(e)){let n=e,r=this;return new Proxy(t,{get(e,t){if(typeof t!=`string`)return Reflect.get(e,t);let i=n.call(r,t);return C(i)?i:e[t]}})}return Object.assign(t,e)}async refreshUI(){this.options.texts=this.resolveTexts(this.textOptionsInput);let e=this.getToolbarPicker();e&&(e.label.innerHTML=this.options.icon,await this.buildCustomSelect(this.options.customSelect,e));for(let e of Object.values(this.modules))e&&typeof e.hide==`function`&&e.hide()}initModules(){if(this.quill.isEnabled())for(let e of this.options.modules)this.modules[e.module.moduleName]=new e.module(this,this.quill,e.options)}listenEditableChange(){this.editableObserver=new MutationObserver(e=>{for(let t of e)if(t.type===`attributes`&&t.attributeName===`contenteditable`){this.quill.root.getAttribute(`contenteditable`)===`false`?this.destroyModules():this.initModules();break}}),this.editableObserver.observe(this.quill.root,{attributes:!0,attributeFilter:[`contenteditable`]})}destroyModules(){for(let[e,t]of Object.entries(this.modules))if(t&&typeof t.destroy==`function`)try{t.destroy()}catch(t){console.warn(`Failed to destroy module ${e}:`,t)}this.modules={}}getModule(e){return this.modules[e]}quillHack(){let n=this.quill.getSemanticHTML;this.quill.getSemanticHTML=((r=0,i)=>{let a=n.call(this.quill,r,i),o=e.import(`formats/${t.tableWrapper}`),s=new DOMParser().parseFromString(a,`text/html`);for(let e of Array.from(s.querySelectorAll(`.${o.className} caption[contenteditable], .${o.className} .${U.className} > [contenteditable]`)))e.removeAttribute(`contenteditable`);return s.body.innerHTML});let r=this.quill.format;this.quill.format=function(n,a,o=e.sources.API){if(!(this.scroll.query(n).prototype instanceof Wr.EmbedBlot)){let e=this.getModule(i.moduleName),s=this.getSelection(!0),c=this.getFormat(s),l=e.getModule(i.tableSelectionName);if(!c[t.tableCellInner]||s.length>0||e&&l&&l.selectedTds.length<=1)return r.call(this,n,a,o);if(e&&l&&l.selectedTds.length>0){let e=l.selectedTds,t=!1,r=[];for(let i of e){let e=i.offset(this.scroll),o=i.length();r.push({index:e,length:o}),this.getFormat(e,o)[n]!==a&&(t=!0)}let i=t?a:!1,s=new $;for(let[e,{index:t,length:a}]of r.entries()){let o=e===0?0:r[e-1].index+r[e-1].length;s.retain(t-o).retain(a,{[n]:i})}let c=this.updateContents(s,o);return this.blur(),c}}return r.call(this,n,a,o)};let a=this.quill.theme.modules.toolbar;if(a){let n=a.handlers?.clean;if(n){let r=(e,n,r=()=>``)=>{let i=this.quill.getText(e,n),[a,o]=this.quill.getLine(e+n),s=0,c=new $;a!=null&&(s=a.length()-o,c=a.delta().slice(o,o+s-1).insert(`
134
+ `));let l=this.quill.getContents(e,n+s),u=l.diff(new $().insert(i).concat(c)),d=0;return new $(u.ops.map(e=>{let{attributes:n,...i}=e;if(e.insert?d-=C(e.insert)?e.insert.length:1:e.retain?d+=re(e.retain)?e.retain:1:e.delete&&(d+=e.delete),n){let{[t.tableCellInner]:e,...a}=n;if(r){let e=l.slice(d-1,d).ops[0];if(e?.attributes?.[t.tableCellInner]){let{style:n,...o}=e.attributes[t.tableCellInner],s=r(n);return s?{...i,attributes:{...a,[t.tableCellInner]:{style:s,...o}}}:{...i,attributes:{...a,[t.tableCellInner]:o}}}}return{...i,attributes:{...a}}}return e}))};a.handlers.clean=function(a){let o=this.quill.getModule(i.moduleName),s=this.quill.getSelection();if(s&&s.length>0&&this.quill.getFormat(s)[t.tableCellInner]){let t=r(s.index,s.length,!1),n=new $().retain(s.index).concat(t);this.quill.updateContents(n,e.sources.USER);return}let c=o.getModule(i.tableSelectionName);if(o&&c&&c.selectedTds.length>0&&c.table){let t=e.find(c.table);if(!t){console.warn(`TableMainFormat not found`);return}let n=c.selectedTds,i=new Set,a=[];for(let e of n)if(e.parent instanceof U){for(let t of e.parent.getNearByCell(`top`))i.has(t)||(i.add(t),a.push({td:t,cleanBorder:`bottom`}));for(let t of e.parent.getNearByCell(`left`))i.has(t)||(i.add(t),a.push({td:t,cleanBorder:`right`}));i.add(e.parent),a.push({td:e.parent,cleanBorder:!0})}let o=t.descendants(U),s=new Map(o.map((e,t)=>[e,t]));a.sort((e,t)=>s.get(e.td)-s.get(t.td));let l=new $,u=0;for(let{td:e,cleanBorder:t}of a){let n=e.getCellInner().offset(this.quill.scroll),i=e.getCellInner().length(),a=r(n,i-1,e=>{if(!e||t===!0)return``;let n=pn(e);return mn(Object.keys(n).filter(e=>!e.startsWith(dn(`border-${t}`))).reduce((e,t)=>(e[t]=n[t],e),{}))}),o=new $().retain(n-u).concat(a);l=l.concat(o),u=n+i}this.quill.updateContents(l,e.sources.USER),n.length>1&&this.quill.blur();return}return n.call(this,a)}}}}async buildCustomSelect(e,t){if(!e||!x(e))return;let n=document.createElement(`span`);if(n.classList.add(`ql-custom-select`),this.selector=await e(this,t),n.appendChild(this.selector),this.options.fullSwitch){let e=l(`creator`),t=document.createElement(`label`);t.classList.add(e.be(`checkbox`));let r=document.createElement(`input`);r.type=`checkbox`,r.checked=this.options.full,r.addEventListener(`change`,()=>{this.options.full=r.checked});let i=document.createElement(`span`);i.textContent=this.options.texts.fullCheckboxText,t.appendChild(r),t.appendChild(i),n.appendChild(t)}t.options.innerHTML=``,t.options.appendChild(n)}setCellAttrs(e,t,n,r=!1){if(e.length!==0)for(let i of e)i.setFormatValue(t,n,r)}getTextByCell(e){let t=``;for(let n of e){let e=n.offset(this.quill.scroll),r=n.length();for(let n of this.quill.getContents(e,r).ops)C(n.insert)&&(t+=n.insert)}return t}getHTMLByCell(e,n=!1){if(e.length===0)return``;let r=null;try{for(let n of e){let e=u(n,t.tableMain);if(r||=e,e!==r)return console.error(`tableMain is not same`),``}}catch{return console.error(`tds must be in same tableMain`),``}if(!r)return``;let i=this.quill.getIndex(r),a=r.length(),o=this.quill.getSemanticHTML(i,a),s=new DOMParser().parseFromString(o,`text/html`),c=Array.from(s.querySelectorAll(`col`)),l=c.map(e=>e.dataset.colId),d=[],f=new Set,p=new Set;for(let t of e){f.add(t.colId);let e=t.colId,n=l.indexOf(e);for(let e=0;e<t.colspan;e++)f.add(l[n+e]);p.add(`${t.rowId}-${t.colId}`)}for(let e=0;e<c.length;e++){let t=c[e];f.has(t.dataset.colId)?d.push(t.getAttribute(`width`)):(t.remove(),c.splice(e--,1))}let m=0,h=null;for(let e of Array.from(s.querySelectorAll(`td, th`)))if(p.has(`${e.dataset.rowId}-${e.dataset.colId}`))h!==e.dataset.rowId&&(m+=1,h=e.dataset.rowId);else{let t=e.parentElement;e.remove(),t&&t.children.length<=0&&t.remove()}let g=c.map(e=>W.value(e));if(r.full){let e=g.reduce((e,t)=>t.width+e,0);for(let[t,n]of g.entries())n.width=Math.round(n.width/e*100),c[t].setAttribute(`width`,`${n.width}%`)}else{let e=0;for(let t of g)e+=t.width;let t=s.querySelector(`table`);t.style.width=`${e}px`}if(n){let t=r.getRows();if(m===t.length)this.removeCol(e);else for(let t of e)t.domNode.innerHTML=`<p><br></p>`}return s.body.innerHTML}insertTable(r,i,a=e.sources.API){if(r>=30||i>=30)throw Error(`Both rows and columns must be less than 30.`);this.quill.focus();let o=this.quill.getSelection();if(o==null)return;let[s]=this.quill.getLeaf(o.index);if(!s)return;if(c(s))throw Error(`Not supported ${s.statics.blotName} insert into table.`);let l=L(),u=Array(i).fill(0).map(()=>L()),d=this.calculateTableCellBorderWidth(),f=getComputedStyle(this.quill.root),p=Number.parseInt(f.paddingLeft),m=Number.parseInt(f.paddingRight),h=this.quill.root.scrollHeight>this.quill.root.clientHeight?cn({target:this.quill.root}):0,g=Number.parseInt(f.width)-p-m-d-h,_=this.options.full?`${Math.max(1/i*100,n.colMinWidthPre)}%`:`${Math.max(Math.floor(g/i),n.colMinWidthPx)}px`,v=[{retain:o.index}],y=this.quill.getContents(o.index,1),[,b]=this.quill.getLine(o.index);y.ops[0].insert!==`
135
135
  `&&b!==0&&v.push({insert:`
136
136
  `});for(let e=0;e<i;e++)v.push({insert:{[t.tableCol]:{width:_,tableId:l,colId:u[e],full:this.options.full}}});for(let e=0;e<r;e++){let e=L();for(let n=0;n<i;n++)v.push({insert:`
137
137
  `,attributes:{[t.tableCellInner]:{tableId:l,rowId:e,colId:u[n],rowspan:1,colspan:1}}})}this.quill.updateContents(new $(v),a),this.quill.setSelection(o.index+i,e.sources.SILENT),this.quill.focus()}calculateTableCellBorderWidth(){let e=`