polotno 3.20.1 → 3.22.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/THIRD_PARTY_NOTICES.md +8 -8
- package/blueprint/side-panel/select-video.d.ts +74 -0
- package/blueprint.polotno.css +165 -230
- package/canvas/crop-overlay.d.ts +20 -8
- package/canvas/crop-overlay.js +1 -1
- package/canvas/element.js +1 -1
- package/canvas/fade-overlay.js +1 -1
- package/canvas/figure-element.js +1 -1
- package/canvas/gif-element.d.ts +28 -4
- package/canvas/gif-element.js +1 -1
- package/canvas/image-element.js +1 -1
- package/canvas/lottie-element.js +1 -1
- package/canvas/lottie-player.wasm.js +1 -1
- package/canvas/media-resize.d.ts +19 -0
- package/canvas/media-resize.js +1 -0
- package/canvas/page.js +1 -1
- package/canvas/quill-font-formats.d.ts +1 -1
- package/canvas/quill-font-formats.js +1 -1
- package/canvas/render-tag-element.js +1 -1
- package/canvas/rich-editor.js +3 -5
- package/canvas/text-element/render-tag-source.d.ts +5 -0
- package/canvas/text-element/render-tag-source.js +1 -1
- package/canvas/tooltip.js +1 -1
- package/canvas/use-color.js +1 -1
- package/canvas/use-mediabunny-video.js +1 -1
- package/canvas/video-element.js +1 -1
- package/canvas/workspace-canvas.js +1 -1
- package/config.d.ts +1 -1
- package/config.js +1 -1
- package/icons/registry.d.ts +7 -0
- package/icons/registry.js +1 -1
- package/image-tools/host.d.ts +3 -0
- package/image-tools/sessions.js +1 -1
- package/image-tools/target.d.ts +5 -0
- package/image-tools/target.js +1 -1
- package/image-tools/types.d.ts +5 -0
- package/model/crop-mode.d.ts +3 -0
- package/model/crop-mode.js +1 -1
- package/model/figure-model.d.ts +29 -0
- package/model/gif-model.d.ts +40 -0
- package/model/group-model.d.ts +304 -2
- package/model/group-model.js +1 -1
- package/model/history.js +1 -1
- package/model/image-model.d.ts +40 -0
- package/model/image-model.js +1 -1
- package/model/line-model.d.ts +29 -0
- package/model/lottie-model.d.ts +40 -0
- package/model/node-model.d.ts +32 -0
- package/model/node-model.js +1 -1
- package/model/page-model.d.ts +912 -6
- package/model/shape-model.d.ts +29 -0
- package/model/shape-model.js +1 -1
- package/model/store.d.ts +61 -2
- package/model/store.js +1 -1
- package/model/svg-model.d.ts +27 -0
- package/model/table-model.d.ts +37 -1
- package/model/table-model.js +1 -1
- package/model/text-model.d.ts +29 -1
- package/model/text-model.js +1 -1
- package/model/video-model.d.ts +40 -0
- package/package.json +25 -27
- package/polotno.bundle.js +240 -238
- package/primitives/autocomplete.d.ts +11 -0
- package/primitives/autocomplete.js +1 -0
- package/primitives/select.js +1 -1
- package/side-panel/index.d.ts +1 -0
- package/side-panel/index.js +1 -1
- package/side-panel/layers-panel.js +1 -1
- package/side-panel/select-image.js +1 -1
- package/side-panel/select-video.d.ts +74 -0
- package/side-panel/select-video.js +1 -1
- package/side-panel/variables-panel.d.ts +10 -0
- package/side-panel/variables-panel.js +1 -0
- package/side-panel/videos-grid.d.ts +1 -1
- package/side-panel/videos-grid.js +1 -1
- package/toolbar/color-picker.d.ts +8 -0
- package/toolbar/color-picker.js +1 -1
- package/toolbar/download-button.js +1 -1
- package/toolbar/element-container.d.ts +6 -0
- package/toolbar/element-container.js +1 -1
- package/toolbar/figure-toolbar.d.ts +8 -9
- package/toolbar/figure-toolbar.js +1 -1
- package/toolbar/gif-toolbar.d.ts +4 -5
- package/toolbar/gif-toolbar.js +1 -1
- package/toolbar/group-toolbar.d.ts +2 -3
- package/toolbar/group-toolbar.js +1 -1
- package/toolbar/image-toolbar.d.ts +11 -12
- package/toolbar/image-toolbar.js +1 -1
- package/toolbar/index.d.ts +1 -0
- package/toolbar/index.js +1 -1
- package/toolbar/line-toolbar.js +1 -1
- package/toolbar/many-toolbar.d.ts +2 -3
- package/toolbar/many-toolbar.js +1 -1
- package/toolbar/page-toolbar.d.ts +2 -3
- package/toolbar/page-toolbar.js +1 -1
- package/toolbar/svg-toolbar.d.ts +2 -3
- package/toolbar/svg-toolbar.js +1 -1
- package/toolbar/text-toolbar.js +1 -1
- package/toolbar/text-variables.d.ts +15 -0
- package/toolbar/text-variables.js +1 -0
- package/toolbar/toolbar.js +1 -1
- package/toolbar/video-toolbar.js +1 -1
- package/ui.css +1 -1
- package/utils/animations.js +1 -1
- package/utils/clipboard.d.ts +54 -2
- package/utils/l10n.d.ts +32 -0
- package/utils/l10n.js +1 -1
- package/utils/selection-transform.js +1 -1
- package/utils/use-api.d.ts +1 -1
- package/utils/use-api.js +1 -1
- package/utils/validate-key.js +1 -1
package/model/table-model.d.ts
CHANGED
|
@@ -65,6 +65,13 @@ export declare const TableCell: import("mobx-state-tree").IModelType<{
|
|
|
65
65
|
readonly row: number;
|
|
66
66
|
readonly col: number;
|
|
67
67
|
readonly store: any;
|
|
68
|
+
readonly filled: Partial<{
|
|
69
|
+
text?: string;
|
|
70
|
+
placeholder?: string;
|
|
71
|
+
src?: string;
|
|
72
|
+
fill?: string;
|
|
73
|
+
visible?: boolean;
|
|
74
|
+
}>;
|
|
68
75
|
readonly page: any;
|
|
69
76
|
readonly fontSize: number;
|
|
70
77
|
readonly fontFamily: string;
|
|
@@ -200,6 +207,8 @@ export declare const TableElement: import("mobx-state-tree").IModelType<{
|
|
|
200
207
|
opacity: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
201
208
|
blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "normal" | "overlay" | "saturation" | "screen" | "soft-light">, [undefined]>;
|
|
202
209
|
custom: import("mobx-state-tree").IType<any, any, any>;
|
|
210
|
+
bindings: import("mobx-state-tree").IMaybe<import("mobx-state-tree").IType<import("@polotno/schema").Bindings, import("@polotno/schema").Bindings, import("@polotno/schema").Bindings>>;
|
|
211
|
+
href: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<string>>;
|
|
203
212
|
visible: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
204
213
|
selectable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
205
214
|
removable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
@@ -305,6 +314,13 @@ export declare const TableElement: import("mobx-state-tree").IModelType<{
|
|
|
305
314
|
readonly row: number;
|
|
306
315
|
readonly col: number;
|
|
307
316
|
readonly store: any;
|
|
317
|
+
readonly filled: Partial<{
|
|
318
|
+
text?: string;
|
|
319
|
+
placeholder?: string;
|
|
320
|
+
src?: string;
|
|
321
|
+
fill?: string;
|
|
322
|
+
visible?: boolean;
|
|
323
|
+
}>;
|
|
308
324
|
readonly page: any;
|
|
309
325
|
readonly fontSize: number;
|
|
310
326
|
readonly fontFamily: string;
|
|
@@ -453,6 +469,13 @@ export declare const TableElement: import("mobx-state-tree").IModelType<{
|
|
|
453
469
|
}, {
|
|
454
470
|
readonly page: any;
|
|
455
471
|
readonly store: any;
|
|
472
|
+
readonly filled: Partial<{
|
|
473
|
+
text?: string;
|
|
474
|
+
placeholder?: string;
|
|
475
|
+
src?: string;
|
|
476
|
+
fill?: string;
|
|
477
|
+
visible?: boolean;
|
|
478
|
+
}>;
|
|
456
479
|
readonly top: import("mobx-state-tree").ModelInstanceTypeProps<{
|
|
457
480
|
id: import("mobx-state-tree").ISimpleType<string>;
|
|
458
481
|
type: import("mobx-state-tree").IType<string | undefined, string, string>;
|
|
@@ -460,6 +483,8 @@ export declare const TableElement: import("mobx-state-tree").IModelType<{
|
|
|
460
483
|
opacity: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
461
484
|
blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "normal" | "overlay" | "saturation" | "screen" | "soft-light">, [undefined]>;
|
|
462
485
|
custom: import("mobx-state-tree").IType<any, any, any>;
|
|
486
|
+
bindings: import("mobx-state-tree").IMaybe<import("mobx-state-tree").IType<import("@polotno/schema").Bindings, import("@polotno/schema").Bindings, import("@polotno/schema").Bindings>>;
|
|
487
|
+
href: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<string>>;
|
|
463
488
|
visible: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
464
489
|
selectable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
465
490
|
removable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
@@ -472,6 +497,8 @@ export declare const TableElement: import("mobx-state-tree").IModelType<{
|
|
|
472
497
|
opacity: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
473
498
|
blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "normal" | "overlay" | "saturation" | "screen" | "soft-light">, [undefined]>;
|
|
474
499
|
custom: import("mobx-state-tree").IType<any, any, any>;
|
|
500
|
+
bindings: import("mobx-state-tree").IMaybe<import("mobx-state-tree").IType<import("@polotno/schema").Bindings, import("@polotno/schema").Bindings, import("@polotno/schema").Bindings>>;
|
|
501
|
+
href: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<string>>;
|
|
475
502
|
visible: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
476
503
|
selectable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
477
504
|
removable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
@@ -484,6 +511,8 @@ export declare const TableElement: import("mobx-state-tree").IModelType<{
|
|
|
484
511
|
opacity: number | undefined;
|
|
485
512
|
blendMode: "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "normal" | "overlay" | "saturation" | "screen" | "soft-light" | undefined;
|
|
486
513
|
custom: any;
|
|
514
|
+
bindings: import("@polotno/schema").Bindings | undefined;
|
|
515
|
+
href: string | undefined;
|
|
487
516
|
visible: boolean | undefined;
|
|
488
517
|
selectable: boolean | undefined;
|
|
489
518
|
removable: boolean | undefined;
|
|
@@ -495,6 +524,8 @@ export declare const TableElement: import("mobx-state-tree").IModelType<{
|
|
|
495
524
|
name: string;
|
|
496
525
|
opacity: number;
|
|
497
526
|
custom: any;
|
|
527
|
+
bindings: import("@polotno/schema").Bindings | undefined;
|
|
528
|
+
href: string | undefined;
|
|
498
529
|
visible: boolean;
|
|
499
530
|
selectable: boolean;
|
|
500
531
|
removable: boolean;
|
|
@@ -506,6 +537,8 @@ export declare const TableElement: import("mobx-state-tree").IModelType<{
|
|
|
506
537
|
name: string;
|
|
507
538
|
opacity: number;
|
|
508
539
|
custom: any;
|
|
540
|
+
bindings: import("@polotno/schema").Bindings | undefined;
|
|
541
|
+
href: string | undefined;
|
|
509
542
|
visible: boolean;
|
|
510
543
|
selectable: boolean;
|
|
511
544
|
removable: boolean;
|
|
@@ -523,6 +556,8 @@ export declare const TableElement: import("mobx-state-tree").IModelType<{
|
|
|
523
556
|
name: string;
|
|
524
557
|
opacity: number;
|
|
525
558
|
custom: any;
|
|
559
|
+
bindings: import("@polotno/schema").Bindings | undefined;
|
|
560
|
+
href: string | undefined;
|
|
526
561
|
visible: boolean;
|
|
527
562
|
selectable: boolean;
|
|
528
563
|
removable: boolean;
|
|
@@ -534,6 +569,8 @@ export declare const TableElement: import("mobx-state-tree").IModelType<{
|
|
|
534
569
|
name: string;
|
|
535
570
|
opacity: number;
|
|
536
571
|
custom: any;
|
|
572
|
+
bindings: import("@polotno/schema").Bindings | undefined;
|
|
573
|
+
href: string | undefined;
|
|
537
574
|
visible: boolean;
|
|
538
575
|
selectable: boolean;
|
|
539
576
|
removable: boolean;
|
|
@@ -589,7 +626,6 @@ export declare const TableElement: import("mobx-state-tree").IModelType<{
|
|
|
589
626
|
readonly basePixelRowHeights: number[];
|
|
590
627
|
contentFloors(divider?: number): number[];
|
|
591
628
|
readonly rowContentFloors: number[];
|
|
592
|
-
getRowContentOuterHeight(row: number): number;
|
|
593
629
|
readonly minHeight: number;
|
|
594
630
|
readonly actualHeight: number;
|
|
595
631
|
getCellRect(row: number, col: number, rowSpan?: number, colSpan?: number): {
|
package/model/table-model.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{types as e,getParent as t,getSnapshot as o,isAlive as l,getRoot as r,cast as n}from"mobx-state-tree";import{observable as s}from"mobx";import{nanoid as i}from"nanoid";import{clampFontSize as c,resolveTableCellBorder as d,TABLE_CELL_OVERRIDABLE_KEYS as a,tableCellBorderInsets as g}from"@polotno/schema/defaults";import{tableCellContentBox as u,tableCellRect as h}from"@polotno/core/table";import{Shape as f}from"./shape-model.js";const b=.05,m=e.enumeration(["solid","dashed","dotted","none"]),p={borderColor:"#000000",borderWidth:1,borderStyle:"solid"};function w(e){return t(e,2)}function C(e,t,o){const r=e[`_${t}`];return null!=r?r:l(e)?w(e)[t]:o}function _(e){return t(e,1)}const y=e.model("BorderSide",{color:e.maybe(e.string),width:e.maybe(e.number),style:e.maybe(m)}).postProcessSnapshot(e=>{const t={};for(const[o,l]of Object.entries(e)){null!=l&&(t[o]=l)}return t}),I=e.model("CellBorders",{top:e.maybe(y),right:e.maybe(y),bottom:e.maybe(y),left:e.maybe(y)}).postProcessSnapshot(e=>{const t={};for(const[o,l]of Object.entries(e)){null!=l&&"object"==typeof l&&Object.keys(l).length>0&&(t[o]=l)}return t}),S=a,v=new Set(S),H=["blurEnabled","blurRadius","brightnessEnabled","brightness","sepiaEnabled","grayscaleEnabled","filters","shadowEnabled","shadowBlur","shadowOffsetX","shadowOffsetY","shadowColor","shadowOpacity"],R=["id","type","text","opacity","rowSpan","colSpan","mergedInto","name","custom","borders"],x=new Set(["row","col","x","y","width","height","rotation","draggable","resizable","selectable","removable","contentEditable","visible","showInExport","alwaysOnTop","backgroundEnabled","backgroundOpacity","backgroundColor","backgroundCornerRadius","backgroundPadding","curveEnabled","curvePower","shadowEnabled","shadowBlur","shadowOffsetX","shadowOffsetY","shadowColor","shadowOpacity","blurEnabled","blurRadius","brightnessEnabled","brightness","sepiaEnabled","grayscaleEnabled","placeholder","animations","filters"]),E={opacity:1,rowSpan:1,colSpan:1,name:""},O=[];export const TableCell=e.model("TableCell",{id:e.identifier,type:e.optional(e.literal("tablecell"),"tablecell"),text:"",_fontSize:e.maybe(e.number),_fontFamily:e.maybe(e.string),_fontWeight:e.maybe(e.string),_fontStyle:e.maybe(e.string),_textDecoration:e.maybe(e.string),_textTransform:e.maybe(e.string),_fill:e.maybe(e.string),_align:e.maybe(e.string),_verticalAlign:e.maybe(e.string),_lineHeight:e.maybe(e.union(e.number,e.string)),_letterSpacing:e.maybe(e.number),_strokeWidth:e.maybe(e.number),_stroke:e.maybe(e.string),_cellBackground:e.maybe(e.string),_cellPadding:e.maybe(e.number),opacity:1,rowSpan:1,colSpan:1,mergedInto:e.maybe(e.string),borders:e.maybe(I),name:"",custom:e.frozen()}).volatile(()=>({_editModeEnabled:!1})).preProcessSnapshot(e=>{if(!e){return e}for(const o in e){null===e[o]&&(e[o]=void 0)}const t={};for(const o of R){o in e&&(t[o]=e[o])}for(const o of S){void 0!==e[o]&&(t[`_${o}`]=e[o])}return void 0!==t._fontSize&&(t._fontSize=c(t._fontSize)),t}).postProcessSnapshot(e=>{const t={};for(const[o,l]of Object.entries(e)){if(o.startsWith("_")){null!=l&&(t[o.slice(1)]=l)}else if("borders"===o){null!=l&&"object"==typeof l&&Object.keys(l).length>0&&(t.borders=l)}else{if(o in E&&l===E[o]){continue}t[o]=l}}return t}).views(e=>{const t={get row(){if(!l(e)){return 0}const t=w(e),o=_(e).indexOf(e);return-1===o?0:Math.floor(o/t.cols)},get col(){if(!l(e)){return 0}const t=w(e),o=_(e).indexOf(e);return-1===o?0:o%t.cols},get store(){return l(e)?r(e):null},get page(){if(!l(e)){return null}try{return w(e).page}catch(t){return null}},get fontSize(){return C(e,"fontSize",30)},get fontFamily(){return C(e,"fontFamily","Roboto")},get fontWeight(){return C(e,"fontWeight","normal")},get fontStyle(){return C(e,"fontStyle","normal")},get textDecoration(){return C(e,"textDecoration","")},get textTransform(){return C(e,"textTransform","none")},get fill(){return C(e,"fill","black")},get align(){return C(e,"align","left")},get verticalAlign(){return C(e,"verticalAlign","top")},get lineHeight(){return C(e,"lineHeight",1.2)},get letterSpacing(){return C(e,"letterSpacing",0)},get strokeWidth(){return C(e,"strokeWidth",0)},get stroke(){return C(e,"stroke","black")},get cellBackground(){return C(e,"cellBackground","transparent")},get cellPadding(){return C(e,"cellPadding",4)},get width(){if(!l(e)){return 100}try{return w(e).getCellRect(t.row,t.col,e.rowSpan,e.colSpan).width}catch(o){return 100}},get height(){if(!l(e)){return 100}try{return w(e).getCellRect(t.row,t.col,e.rowSpan,e.colSpan).height}catch(o){return 100}},get gridCell(){return{row:t.row,col:t.col,rowSpan:e.rowSpan,colSpan:e.colSpan,borders:e.borders,cellPadding:t.cellPadding}},get borderInsets(){return l(e)?g(t.gridCell,w(e)):{top:0,right:0,bottom:0,left:0}},get a(){var o;return l(e)?Object.assign(Object.assign({},u(w(e),t.gridCell)),{rotation:0,opacity:null!==(o=e.opacity)&&void 0!==o?o:1,fontSize:t.fontSize}):{x:0,y:0,width:100,height:100,rotation:0,opacity:1,fontSize:16}},getEffectiveBorder:t=>d(e,l(e)?w(e):p,t),get x(){return 0},get y(){return 0},get rotation(){return 0},get draggable(){return!1},get resizable(){return!1},get selectable(){return!1},get removable(){return!1},get contentEditable(){return!0},get visible(){return!0},get showInExport(){return!0},get alwaysOnTop(){return!1},get placeholder(){return""},get backgroundEnabled(){return!1},get backgroundOpacity(){return 1},get backgroundColor(){return"transparent"},get backgroundCornerRadius(){return 0},get backgroundPadding(){return 0},get curveEnabled(){return!1},get curvePower(){return 0},get shadowEnabled(){return!1},get shadowBlur(){return 0},get shadowOffsetX(){return 0},get shadowOffsetY(){return 0},get shadowColor(){return"black"},get shadowOpacity(){return 1},get blurEnabled(){return!1},get blurRadius(){return 0},get brightnessEnabled(){return!1},get brightness(){return 0},get sepiaEnabled(){return!1},get grayscaleEnabled(){return!1},get animations(){return O}};return t}).actions(e=>({toJSON:()=>Object.assign({},o(e)),set(t){null!=t.fontSize&&(t=Object.assign(Object.assign({},t),{fontSize:c(t.fontSize)}));const o={};for(const[e,l]of Object.entries(t)){v.has(e)?o[`_${e}`]=l:"borders"===e?o.borders=l?JSON.parse(JSON.stringify(l)):l:x.has(e)||(o[e]=l)}Object.assign(e,o)},setBorder(t,l){const r=e.borders?Object.assign({},o(e.borders)):{},s=r[t]||{},i=Object.assign({},s);void 0!==l.color&&(i.color=l.color),void 0!==l.width&&(i.width=l.width),void 0!==l.style&&(i.style=l.style),r[t]=i,e.borders=n(r)},toggleEditMode(t){if(!l(e)){return}const o=null!=t?t:!e._editModeEnabled;o!==e._editModeEnabled&&(e._editModeEnabled=o,e._editModeEnabled?e.store.history.startTransaction():e.store.history.endTransaction())},beforeDestroy(){e._editModeEnabled&&e.store.history.endTransaction()}}));function M(e,t){const l=[];for(const r of e){const e={id:i(10),text:""};if(!r){l.push(e);continue}for(const t of S){const o=r[`_${t}`];null!=o&&(e[t]=o)}const n=r.borders;if(n){const l={},r=t?["left","right","top"]:["top","bottom","left"];for(const e of r){const t=n[e];t&&(l[e]=o(t))}Object.keys(l).length>0&&(e.borders=l)}l.push(e)}return l}function k(e){return Array.from({length:e},()=>1/e)}function z(e){const t=e.reduce((e,t)=>e+t,0);return 0===t?k(e.length):e.map(e=>e/t)}export const TableElement=f.named("Table").props({type:"table",width:300,height:200,rows:3,cols:3,colWidths:e.array(e.number),rowHeights:e.array(e.number),cells:e.array(TableCell),borderColor:"#000000",borderWidth:1,borderStyle:e.optional(e.enumeration(["solid","dashed","dotted","none"]),"solid"),fontSize:30,fontFamily:"Roboto",fontWeight:"normal",fontStyle:"normal",textDecoration:"",textTransform:"none",fill:"black",align:"center",verticalAlign:"middle",lineHeight:e.optional(e.union(e.number,e.string),1.2),letterSpacing:0,strokeWidth:0,stroke:"black",cellBackground:"transparent",cellPadding:4}).preProcessSnapshot(e=>null==(null==e?void 0:e.fontSize)?e:Object.assign(Object.assign({},e),{fontSize:c(e.fontSize)})).postProcessSnapshot(e=>{e.cells&&((e=Object.assign({},e)).cells=e.cells.map(t=>{const o={};for(const[l,r]of Object.entries(t)){v.has(l)&&r===e[l]||(o[l]=r)}return o}));for(const t of H){delete e[t]}return e}).volatile(()=>({_focusedCellIds:[],_editingCellId:void 0,_editClickCoords:null,_anchorCellId:void 0,_cellContentHeights:s.map(),_baseRowHeights:null,_baseHeight:null})).actions(e=>({afterCreate(){const t=e.rows*e.cols;if(0===e.cells.length){e.cells.replace(function(e,t){const o=[];for(let l=0;l<e*t;l++){o.push({id:i(10),text:""})}return o}(e.rows,e.cols))}else if(e.cells.length<t){for(;e.cells.length<t;){e.cells.push(n({id:i(10),text:""}))}}else{e.cells.length>t&&e.cells.splice(t)}0===e.colWidths.length&&e.colWidths.replace(k(e.cols)),0===e.rowHeights.length&&e.rowHeights.replace(k(e.rows))}})).views(e=>({get _cellMap(){const t=new Map,o=e.cols;return e.cells.forEach((e,l)=>{t.set(`${Math.floor(l/o)}:${l%o}`,e)}),t},getActualRowHeight:t=>e.rowHeights[t]*e.height})).views(e=>{const t={getCell:(t,o)=>e._cellMap.get(`${t}:${o}`),visibleCellAt(o,l){const r=t.getCell(o,l);return(null==r?void 0:r.mergedInto)?e.cells.find(e=>e.id===r.mergedInto):r},get minWidth(){return 20*e.cols},get basePixelRowHeights(){var t,o;const l=null!==(t=e._baseHeight)&&void 0!==t?t:e.height;return(null!==(o=e._baseRowHeights)&&void 0!==o?o:e.rowHeights).map(e=>e*l)},contentFloors(o){const l=t.basePixelRowHeights,r=new Array(e.rows).fill(0),n=[];for(const s of t.visibleCells){const t=e._cellContentHeights.get(s.id);if(void 0===t){continue}const l=s.borderInsets,i=t+2*s.cellPadding+l.top+l.bottom,c=s.row,d=Math.min(c+s.rowSpan,e.rows);d-c===1?r[c]=Math.max(r[c],i):void 0!==o&&c<=o&&o+1<d||n.push({start:c,end:d,outer:i})}n.sort((e,t)=>e.end-e.start-(t.end-t.start));for(const{start:e,end:t,outer:s}of n){const o=r.slice(e,t),n=l.slice(e,t),i=s-o.reduce((e,t)=>e+t,0);if(i<=0){continue}const c=o.map((e,t)=>Math.max(0,n[t]-e)),d=c.reduce((e,t)=>e+t,0),a=n.reduce((e,t)=>e+t,0),g=Math.min(i,d);o.forEach((t,l)=>{r[e+l]=t+(d>0?g*c[l]/d:0)+(i-g)*(a>0?n[l]/a:1/o.length)})}return r},get rowContentFloors(){return t.contentFloors()},getRowContentOuterHeight(e){var o;return null!==(o=t.rowContentFloors[e])&&void 0!==o?o:0},get minHeight(){const o=20*e.rows;if(0===e._cellContentHeights.size){return o}const l=t.rowContentFloors.reduce((e,t)=>e+t,0);return Math.max(o,l)},get actualHeight(){let t=0;for(let o=0;o<e.rows;o++){t+=e.getActualRowHeight(o)}return t},getCellRect:(t,o,l=1,r=1)=>h(e,{row:t,col:o,rowSpan:l,colSpan:r}),get visibleCells(){return e.cells.filter(e=>!e.mergedInto)},get focusedCells(){return e.cells.filter(t=>e._focusedCellIds.includes(t.id))},get editingCell(){if(e._editingCellId){return e.cells.find(t=>t.id===e._editingCellId)}},get textCells(){const e=t.editingCell;return e?[e]:t.focusedCells.filter(e=>!e.mergedInto)},getFocusedCellRange(){if(0===e._focusedCellIds.length){return null}let t=1/0,o=-1/0,l=1/0,r=-1/0;const n=new Set(e._focusedCellIds);for(const s of e.cells){n.has(s.id)&&(s.row<t&&(t=s.row),s.row>o&&(o=s.row),s.col<l&&(l=s.col),s.col>r&&(r=s.col))}return t===1/0?null:{minRow:t,maxRow:o,minCol:l,maxCol:r}},get _fitRowsToContent(){if(0===e._cellContentHeights.size){return null}const o=t.basePixelRowHeights,l=t.rowContentFloors;let r=!1;const n=[];for(let t=0;t<e.rows;t++){const s=e.rowHeights[t]*e.height,i=Math.max(l[t],o[t]);Math.abs(i-s)>1?(n.push(i),r=!0):n.push(s)}if(!r){return null}const s=n.reduce((e,t)=>e+t,0);return{rowHeights:n.map(e=>e/s),height:s}}};return t}).actions(e=>{const t=e.set,o={set(e){null!=e.fontSize&&(e=Object.assign(Object.assign({},e),{fontSize:c(e.fontSize)})),t(e)},setCellContentHeight(t,o){e._cellContentHeights.set(t,o)},_applyFitRowsToContent(){if(!l(e)){return}null===e._baseRowHeights&&(e._baseRowHeights=[...e.rowHeights],e._baseHeight=e.height);const t=e._fitRowsToContent;t&&(e.height=t.height,e.rowHeights.replace(t.rowHeights))},focusCell(t,o=!1){o?e._focusedCellIds.includes(t)||(e._focusedCellIds=[...e._focusedCellIds,t]):(e._focusedCellIds=[t],e._anchorCellId=t)},selectRowRange(t,o){const l=Math.max(0,Math.min(t,o)),r=Math.min(e.rows-1,Math.max(t,o)),n=[];for(let s=l;s<=r;s++){for(let t=0;t<e.cols;t++){const o=e.getCell(s,t);o&&n.push(o.id)}}e._focusedCellIds=n,e._anchorCellId=n[0]},selectColumnRange(t,o){const l=Math.max(0,Math.min(t,o)),r=Math.min(e.cols-1,Math.max(t,o)),n=[];for(let s=0;s<e.rows;s++){for(let t=l;t<=r;t++){const o=e.getCell(s,t);o&&n.push(o.id)}}e._focusedCellIds=n,e._anchorCellId=n[0]},selectRow(e){o.selectRowRange(e,e)},selectColumn(e){o.selectColumnRange(e,e)},focusCellRange(t,o){const l=e.cells.find(t=>t.id===e._anchorCellId);if(!l){return}const r=Math.min(l.row,t),n=Math.max(l.row,t),s=Math.min(l.col,o),i=Math.max(l.col,o),c=[];for(const d of e.cells){d.row>=r&&d.row<=n&&d.col>=s&&d.col<=i&&c.push(d.id)}e._focusedCellIds=c},clearCellFocus(){if(l(e)){if(e._editingCellId){const t=e.cells.find(t=>t.id===e._editingCellId);t&&t.toggleEditMode(!1)}e._focusedCellIds=[],e._editingCellId=void 0,e._editClickCoords=null,e._anchorCellId=void 0}},enterCellEdit(t,l=null){e._editingCellId!==t&&o.exitCellEdit(),e._editingCellId=t,e._editClickCoords=l,e._focusedCellIds.includes(t)||(e._focusedCellIds=[t]);const r=e.cells.find(e=>e.id===t);r&&r.toggleEditMode(!0)},exitCellEdit(){if(e._editingCellId){const t=e.cells.find(t=>t.id===e._editingCellId);t&&t.toggleEditMode(!1)}e._editingCellId=void 0,e._editClickCoords=null},_resetBaseRowHeights(){e._baseRowHeights=null,e._baseHeight=null},setHeightRedistribute(t){const o=e.rows;if(0===o||t<=0){return void(e.height=t)}const l=e.height;if(l<=0||t>=l){return void(e.height=t)}const r=e.rowHeights.map(e=>e*l),n=e.rowContentFloors,s=n.reduce((e,t)=>e+t,0);if(t<=s||s<=0){return void(e.height=t)}const i=t-s;let c=0;const d=[];for(let e=0;e<o;e++){const t=Math.max(0,r[e]-n[e]);d.push(t),c+=t}const a=[];if(c<=0){const e=t/l;for(let t=0;t<o;t++){a.push(r[t]*e)}}else{for(let e=0;e<o;e++){a.push(n[e]+d[e]/c*i)}}const g=a.map(e=>e/t);e.height=t,e.rowHeights.replace(g)},addRow(t){o._resetBaseRowHeights();const l=t>0?t-1:0,r=(e.rowHeights[l]||1/(e.rows+1))*e.height,n=e.height+r,s=[];for(let o=0;o<e.rows;o++){s.push(e.rowHeights[o]*e.height/n)}s.splice(t,0,r/n);const i=t>0?t-1:0,c=[];for(let o=0;o<e.cols;o++){c.push(e.cells[i*e.cols+o])}const d=t*e.cols,a=M(c,!0);e.cells.splice(d,0,...a),e.rows+=1,e.height=n,e.rowHeights.replace(z(s))},removeRow(t){if(e.rows<=1){return}o._resetBaseRowHeights();const l=t*e.cols,r=[];for(let o=l;o<l+e.cols;o++){r.push(e.cells[o].id)}if(e._editingCellId&&r.includes(e._editingCellId)){const t=e.cells.find(t=>t.id===e._editingCellId);t&&t.toggleEditMode(!1),e._editingCellId=void 0}e._focusedCellIds=e._focusedCellIds.filter(e=>!r.includes(e)),r.forEach(t=>e._cellContentHeights.delete(t)),e.cells.splice(l,e.cols);const n=[...e.rowHeights];n.splice(t,1),e.rows-=1,e.rowHeights.replace(z(n))},addColumn(t){const o=t>0?t-1:0,l=(e.colWidths[o]||1/(e.cols+1))*e.width,r=e.width+l,s=[];for(let n=0;n<e.cols;n++){s.push(e.colWidths[n]*e.width/r)}s.splice(t,0,l/r);const i=e.cols,c=t>0?t-1:0,d=[];for(let n=0;n<e.rows;n++){d.push(e.cells[n*i+c])}const a=M(d,!1);for(let g=e.rows-1;g>=0;g--){e.cells.splice(g*i+t,0,n(a[g]))}e.cols+=1,e.width=r,e.colWidths.replace(z(s))},removeColumn(t){if(e.cols<=1){return}const o=e.cols,l=[];for(let n=0;n<e.rows;n++){l.push(e.cells[n*o+t].id)}if(e._editingCellId&&l.includes(e._editingCellId)){const t=e.cells.find(t=>t.id===e._editingCellId);t&&t.toggleEditMode(!1),e._editingCellId=void 0}e._focusedCellIds=e._focusedCellIds.filter(e=>!l.includes(e)),l.forEach(t=>e._cellContentHeights.delete(t));for(let n=e.rows-1;n>=0;n--){e.cells.splice(n*o+t,1)}const r=[...e.colWidths];r.splice(t,1),e.cols-=1,e.colWidths.replace(z(r))},removeRowRange(t,l){for(let r=l;r>=t&&!(e.rows<=1);r--){o.removeRow(r)}},removeColumnRange(t,l){for(let r=l;r>=t&&!(e.cols<=1);r--){o.removeColumn(r)}},distributeRowsEvenly(){const t=e.rows,l=Math.max(20,...e.rowContentFloors);o._resetBaseRowHeights(),e.height=Math.max(e.height,l*t),e.rowHeights.replace(k(t))},distributeColumnsEvenly(){e.colWidths.replace(k(e.cols))},resizeColumn(t,o){if(t>=e.cols-1){return}const l=[...e.colWidths],r=l[t]+l[t+1],n=l[t]+o,s=l[t+1]-o;n<b?(l[t]=b,l[t+1]=r-b):s<b?(l[t+1]=b,l[t]=r-b):(l[t]=n,l[t+1]=s),e.colWidths.replace(l)},resizeRow(t,o){if(t>=e.rows-1){return}const l=[...e.rowHeights],r=l[t]+l[t+1],n=e.height,s=e.contentFloors(t),i=n>0?s[t]/n:0,c=n>0?s[t+1]/n:0,d=Math.max(b,i),a=Math.max(b,c),g=l[t]+o,u=l[t+1]-o;g<d?(l[t]=d,l[t+1]=r-d):u<a?(l[t+1]=a,l[t]=r-a):(l[t]=g,l[t+1]=u),e.rowHeights.replace(l)},setCellBorders(t,o,l){const r={top:{side:"bottom",dr:-1,dc:0},bottom:{side:"top",dr:1,dc:0},left:{side:"right",dr:0,dc:-1},right:{side:"left",dr:0,dc:1}};for(const n of t){const t=e.cells.find(e=>e.id===n);if(t){for(const n of o){t.setBorder(n,l);const o=r[n],s=t.row+o.dr,i=t.col+o.dc,c=e.getCell(s,i);c&&c.setBorder(o.side,l)}}}},applyBorderMode(t,l){var r;const n=function(e,t,o){const{minRow:l,maxRow:r,minCol:n,maxCol:s}=t,i=(e,t,l,r)=>{const n=[];for(let s=e;s<=t;s++){for(let e=l;e<=r;e++){const t=o(s,e);t&&n.push(t.id)}}return n};if("all"===e){return[{cellIds:i(l,r,n,s),sides:["top","right","bottom","left"]}]}const c=[],d="outer"===e||"topOnly"===e||"topBottom"===e,a="outer"===e||"bottomOnly"===e||"topBottom"===e,g="outer"===e||"leftOnly"===e,u="outer"===e||"rightOnly"===e;if(d){const e=i(l,l,n,s);e.length&&c.push({cellIds:e,sides:["top"]})}if(a){const e=i(r,r,n,s);e.length&&c.push({cellIds:e,sides:["bottom"]})}if(g){const e=i(l,r,n,n);e.length&&c.push({cellIds:e,sides:["left"]})}if(u){const e=i(l,r,s,s);e.length&&c.push({cellIds:e,sides:["right"]})}if(d||a||g||u){return c}if(("inner"===e||"innerHorizontal"===e)&&r>l){const e=i(l,r-1,n,s);e.length&&c.push({cellIds:e,sides:["bottom"]})}if(("inner"===e||"innerVertical"===e)&&s>n){const e=i(l,r,n,s-1);e.length&&c.push({cellIds:e,sides:["right"]})}return c}(t,null!==(r=e.getFocusedCellRange())&&void 0!==r?r:{minRow:0,maxRow:e.rows-1,minCol:0,maxCol:e.cols-1},(t,o)=>e.getCell(t,o));for(const{cellIds:e,sides:s}of n){o.setCellBorders(e,s,l)}}};return o}).actions(e=>({clone(t={},{skipSelect:o=!1}={}){const l=JSON.parse(JSON.stringify(e.toJSON()));if(t.id=t.id||i(10),l.cells){const e=new Map;l.cells.forEach(t=>{const o=t.id,l=i(10);e.set(o,l),t.id=l}),l.cells.forEach(t=>{t.mergedInto&&e.has(t.mergedInto)&&(t.mergedInto=e.get(t.mergedInto))})}return Object.assign(l,t),e.page.addElement(l,{skipSelect:o})}}));
|
|
1
|
+
import{types as e,getParent as t,getSnapshot as o,isAlive as l,getRoot as r,cast as n}from"mobx-state-tree";import{observable as s}from"mobx";import{fillElement as i}from"@polotno/schema/variables";import{nanoid as c}from"nanoid";import{clampFontSize as d,resolveTableCellBorder as a,TABLE_CELL_OVERRIDABLE_KEYS as g,tableCellBorderInsets as u}from"@polotno/schema/defaults";import{tableCellContentBox as h,tableCellRect as f}from"@polotno/core/table";import{fitTableRows as b,tableContentFloors as p}from"@polotno/core/table-fit";import{Shape as m}from"./shape-model.js";const w=.05,C=e.enumeration(["solid","dashed","dotted","none"]),_={borderColor:"#000000",borderWidth:1,borderStyle:"solid"};function y(e){return t(e,2)}function I(e,t,o){const r=e[`_${t}`];return null!=r?r:l(e)?y(e)[t]:o}function S(e){return t(e,1)}const v=e.model("BorderSide",{color:e.maybe(e.string),width:e.maybe(e.number),style:e.maybe(C)}).postProcessSnapshot(e=>{const t={};for(const[o,l]of Object.entries(e)){null!=l&&(t[o]=l)}return t}),H=e.model("CellBorders",{top:e.maybe(v),right:e.maybe(v),bottom:e.maybe(v),left:e.maybe(v)}).postProcessSnapshot(e=>{const t={};for(const[o,l]of Object.entries(e)){null!=l&&"object"==typeof l&&Object.keys(l).length>0&&(t[o]=l)}return t}),R=g,x=new Set(R),E=["blurEnabled","blurRadius","brightnessEnabled","brightness","sepiaEnabled","grayscaleEnabled","filters","shadowEnabled","shadowBlur","shadowOffsetX","shadowOffsetY","shadowColor","shadowOpacity"],O=["id","type","text","opacity","rowSpan","colSpan","mergedInto","name","custom","borders"],M=new Set(["row","col","x","y","width","height","rotation","draggable","resizable","selectable","removable","contentEditable","visible","showInExport","alwaysOnTop","backgroundEnabled","backgroundOpacity","backgroundColor","backgroundCornerRadius","backgroundPadding","curveEnabled","curvePower","shadowEnabled","shadowBlur","shadowOffsetX","shadowOffsetY","shadowColor","shadowOpacity","blurEnabled","blurRadius","brightnessEnabled","brightness","sepiaEnabled","grayscaleEnabled","placeholder","animations","filters"]),k={opacity:1,rowSpan:1,colSpan:1,name:""},z=[];export const TableCell=e.model("TableCell",{id:e.identifier,type:e.optional(e.literal("tablecell"),"tablecell"),text:"",_fontSize:e.maybe(e.number),_fontFamily:e.maybe(e.string),_fontWeight:e.maybe(e.string),_fontStyle:e.maybe(e.string),_textDecoration:e.maybe(e.string),_textTransform:e.maybe(e.string),_fill:e.maybe(e.string),_align:e.maybe(e.string),_verticalAlign:e.maybe(e.string),_lineHeight:e.maybe(e.union(e.number,e.string)),_letterSpacing:e.maybe(e.number),_strokeWidth:e.maybe(e.number),_stroke:e.maybe(e.string),_cellBackground:e.maybe(e.string),_cellPadding:e.maybe(e.number),opacity:1,rowSpan:1,colSpan:1,mergedInto:e.maybe(e.string),borders:e.maybe(H),name:"",custom:e.frozen()}).volatile(()=>({_editModeEnabled:!1})).preProcessSnapshot(e=>{if(!e){return e}for(const o in e){null===e[o]&&(e[o]=void 0)}const t={};for(const o of O){o in e&&(t[o]=e[o])}for(const o of R){void 0!==e[o]&&(t[`_${o}`]=e[o])}return void 0!==t._fontSize&&(t._fontSize=d(t._fontSize)),t}).postProcessSnapshot(e=>{const t={};for(const[o,l]of Object.entries(e)){if(o.startsWith("_")){null!=l&&(t[o.slice(1)]=l)}else if("borders"===o){null!=l&&"object"==typeof l&&Object.keys(l).length>0&&(t.borders=l)}else{if(o in k&&l===k[o]){continue}t[o]=l}}return t}).views(e=>{const t={get row(){if(!l(e)){return 0}const t=y(e),o=S(e).indexOf(e);return-1===o?0:Math.floor(o/t.cols)},get col(){if(!l(e)){return 0}const t=y(e),o=S(e).indexOf(e);return-1===o?0:o%t.cols},get store(){return l(e)?r(e):null},get filled(){var o;if(!l(e)||e._editModeEnabled){return{}}const r=null===(o=t.store)||void 0===o?void 0:o._variablesByName;return r?i({type:"tablecell",text:e.text},r):{}},get page(){if(!l(e)){return null}try{return y(e).page}catch(t){return null}},get fontSize(){return I(e,"fontSize",30)},get fontFamily(){return I(e,"fontFamily","Roboto")},get fontWeight(){return I(e,"fontWeight","normal")},get fontStyle(){return I(e,"fontStyle","normal")},get textDecoration(){return I(e,"textDecoration","")},get textTransform(){return I(e,"textTransform","none")},get fill(){return I(e,"fill","black")},get align(){return I(e,"align","left")},get verticalAlign(){return I(e,"verticalAlign","top")},get lineHeight(){return I(e,"lineHeight",1.2)},get letterSpacing(){return I(e,"letterSpacing",0)},get strokeWidth(){return I(e,"strokeWidth",0)},get stroke(){return I(e,"stroke","black")},get cellBackground(){return I(e,"cellBackground","transparent")},get cellPadding(){return I(e,"cellPadding",4)},get width(){if(!l(e)){return 100}try{return y(e).getCellRect(t.row,t.col,e.rowSpan,e.colSpan).width}catch(o){return 100}},get height(){if(!l(e)){return 100}try{return y(e).getCellRect(t.row,t.col,e.rowSpan,e.colSpan).height}catch(o){return 100}},get gridCell(){return{row:t.row,col:t.col,rowSpan:e.rowSpan,colSpan:e.colSpan,borders:e.borders,cellPadding:t.cellPadding}},get borderInsets(){return l(e)?u(t.gridCell,y(e)):{top:0,right:0,bottom:0,left:0}},get a(){var o;return l(e)?Object.assign(Object.assign({},h(y(e),t.gridCell)),{rotation:0,opacity:null!==(o=e.opacity)&&void 0!==o?o:1,fontSize:t.fontSize}):{x:0,y:0,width:100,height:100,rotation:0,opacity:1,fontSize:16}},getEffectiveBorder:t=>a(e,l(e)?y(e):_,t),get x(){return 0},get y(){return 0},get rotation(){return 0},get draggable(){return!1},get resizable(){return!1},get selectable(){return!1},get removable(){return!1},get contentEditable(){return!0},get visible(){return!0},get showInExport(){return!0},get alwaysOnTop(){return!1},get placeholder(){return""},get backgroundEnabled(){return!1},get backgroundOpacity(){return 1},get backgroundColor(){return"transparent"},get backgroundCornerRadius(){return 0},get backgroundPadding(){return 0},get curveEnabled(){return!1},get curvePower(){return 0},get shadowEnabled(){return!1},get shadowBlur(){return 0},get shadowOffsetX(){return 0},get shadowOffsetY(){return 0},get shadowColor(){return"black"},get shadowOpacity(){return 1},get blurEnabled(){return!1},get blurRadius(){return 0},get brightnessEnabled(){return!1},get brightness(){return 0},get sepiaEnabled(){return!1},get grayscaleEnabled(){return!1},get animations(){return z}};return t}).actions(e=>({toJSON:()=>Object.assign({},o(e)),set(t){null!=t.fontSize&&(t=Object.assign(Object.assign({},t),{fontSize:d(t.fontSize)}));const o={};for(const[e,l]of Object.entries(t)){x.has(e)?o[`_${e}`]=l:"borders"===e?o.borders=l?JSON.parse(JSON.stringify(l)):l:M.has(e)||(o[e]=l)}Object.assign(e,o)},setBorder(t,l){const r=e.borders?Object.assign({},o(e.borders)):{},s=r[t]||{},i=Object.assign({},s);void 0!==l.color&&(i.color=l.color),void 0!==l.width&&(i.width=l.width),void 0!==l.style&&(i.style=l.style),r[t]=i,e.borders=n(r)},toggleEditMode(t){if(!l(e)){return}const o=null!=t?t:!e._editModeEnabled;o!==e._editModeEnabled&&(e._editModeEnabled=o,e._editModeEnabled?e.store.history.startTransaction():e.store.history.endTransaction())},beforeDestroy(){e._editModeEnabled&&e.store.history.endTransaction()}}));function j(e,t){const l=[];for(const r of e){const e={id:c(10),text:""};if(!r){l.push(e);continue}for(const t of R){const o=r[`_${t}`];null!=o&&(e[t]=o)}const n=r.borders;if(n){const l={},r=t?["left","right","top"]:["top","bottom","left"];for(const e of r){const t=n[e];t&&(l[e]=o(t))}Object.keys(l).length>0&&(e.borders=l)}l.push(e)}return l}function B(e){return Array.from({length:e},()=>1/e)}function W(e){const t=e.reduce((e,t)=>e+t,0);return 0===t?B(e.length):e.map(e=>e/t)}export const TableElement=m.named("Table").props({type:"table",width:300,height:200,rows:3,cols:3,colWidths:e.array(e.number),rowHeights:e.array(e.number),cells:e.array(TableCell),borderColor:"#000000",borderWidth:1,borderStyle:e.optional(e.enumeration(["solid","dashed","dotted","none"]),"solid"),fontSize:30,fontFamily:"Roboto",fontWeight:"normal",fontStyle:"normal",textDecoration:"",textTransform:"none",fill:"black",align:"center",verticalAlign:"middle",lineHeight:e.optional(e.union(e.number,e.string),1.2),letterSpacing:0,strokeWidth:0,stroke:"black",cellBackground:"transparent",cellPadding:4}).preProcessSnapshot(e=>null==(null==e?void 0:e.fontSize)?e:Object.assign(Object.assign({},e),{fontSize:d(e.fontSize)})).postProcessSnapshot(e=>{e.cells&&((e=Object.assign({},e)).cells=e.cells.map(t=>{const o={};for(const[l,r]of Object.entries(t)){x.has(l)&&r===e[l]||(o[l]=r)}return o}));for(const t of E){delete e[t]}return e}).volatile(()=>({_focusedCellIds:[],_editingCellId:void 0,_editClickCoords:null,_anchorCellId:void 0,_cellContentHeights:s.map(),_baseRowHeights:null,_baseHeight:null})).actions(e=>({afterCreate(){const t=e.rows*e.cols;if(0===e.cells.length){e.cells.replace(function(e,t){const o=[];for(let l=0;l<e*t;l++){o.push({id:c(10),text:""})}return o}(e.rows,e.cols))}else if(e.cells.length<t){for(;e.cells.length<t;){e.cells.push(n({id:c(10),text:""}))}}else{e.cells.length>t&&e.cells.splice(t)}0===e.colWidths.length&&e.colWidths.replace(B(e.cols)),0===e.rowHeights.length&&e.rowHeights.replace(B(e.rows))}})).views(e=>({get _cellMap(){const t=new Map,o=e.cols;return e.cells.forEach((e,l)=>{t.set(`${Math.floor(l/o)}:${l%o}`,e)}),t},getActualRowHeight:t=>e.rowHeights[t]*e.height})).views(e=>{const t={getCell:(t,o)=>e._cellMap.get(`${t}:${o}`),visibleCellAt(o,l){const r=t.getCell(o,l);return(null==r?void 0:r.mergedInto)?e.cells.find(e=>e.id===r.mergedInto):r},get minWidth(){return 20*e.cols},get basePixelRowHeights(){var t,o;const l=null!==(t=e._baseHeight)&&void 0!==t?t:e.height;return(null!==(o=e._baseRowHeights)&&void 0!==o?o:e.rowHeights).map(e=>e*l)},contentFloors(o){const l=[];for(const r of t.visibleCells){const t=e._cellContentHeights.get(r.id);if(void 0===t){continue}const o=r.borderInsets;l.push({row:r.row,rowSpan:r.rowSpan,outer:t+2*r.cellPadding+o.top+o.bottom})}return p(e.rows,t.basePixelRowHeights,l,o)},get rowContentFloors(){return t.contentFloors()},get minHeight(){const o=20*e.rows;if(0===e._cellContentHeights.size){return o}const l=t.rowContentFloors.reduce((e,t)=>e+t,0);return Math.max(o,l)},get actualHeight(){let t=0;for(let o=0;o<e.rows;o++){t+=e.getActualRowHeight(o)}return t},getCellRect:(t,o,l=1,r=1)=>f(e,{row:t,col:o,rowSpan:l,colSpan:r}),get visibleCells(){return e.cells.filter(e=>!e.mergedInto)},get focusedCells(){return e.cells.filter(t=>e._focusedCellIds.includes(t.id))},get editingCell(){if(e._editingCellId){return e.cells.find(t=>t.id===e._editingCellId)}},get textCells(){const e=t.editingCell;return e?[e]:t.focusedCells.filter(e=>!e.mergedInto)},getFocusedCellRange(){if(0===e._focusedCellIds.length){return null}let t=1/0,o=-1/0,l=1/0,r=-1/0;const n=new Set(e._focusedCellIds);for(const s of e.cells){n.has(s.id)&&(s.row<t&&(t=s.row),s.row>o&&(o=s.row),s.col<l&&(l=s.col),s.col>r&&(r=s.col))}return t===1/0?null:{minRow:t,maxRow:o,minCol:l,maxCol:r}},get _fitRowsToContent(){return 0===e._cellContentHeights.size?null:b(e.rowHeights.map(t=>t*e.height),t.basePixelRowHeights,t.rowContentFloors)}};return t}).actions(e=>{const t=e.set,o={set(e){null!=e.fontSize&&(e=Object.assign(Object.assign({},e),{fontSize:d(e.fontSize)})),t(e)},setCellContentHeight(t,o){e._cellContentHeights.set(t,o)},_applyFitRowsToContent(){if(!l(e)){return}null===e._baseRowHeights&&(e._baseRowHeights=[...e.rowHeights],e._baseHeight=e.height);const t=e._fitRowsToContent;t&&(e.height=t.height,e.rowHeights.replace(t.rowHeights))},focusCell(t,o=!1){o?e._focusedCellIds.includes(t)||(e._focusedCellIds=[...e._focusedCellIds,t]):(e._focusedCellIds=[t],e._anchorCellId=t)},selectRowRange(t,o){const l=Math.max(0,Math.min(t,o)),r=Math.min(e.rows-1,Math.max(t,o)),n=[];for(let s=l;s<=r;s++){for(let t=0;t<e.cols;t++){const o=e.getCell(s,t);o&&n.push(o.id)}}e._focusedCellIds=n,e._anchorCellId=n[0]},selectColumnRange(t,o){const l=Math.max(0,Math.min(t,o)),r=Math.min(e.cols-1,Math.max(t,o)),n=[];for(let s=0;s<e.rows;s++){for(let t=l;t<=r;t++){const o=e.getCell(s,t);o&&n.push(o.id)}}e._focusedCellIds=n,e._anchorCellId=n[0]},selectRow(e){o.selectRowRange(e,e)},selectColumn(e){o.selectColumnRange(e,e)},focusCellRange(t,o){const l=e.cells.find(t=>t.id===e._anchorCellId);if(!l){return}const r=Math.min(l.row,t),n=Math.max(l.row,t),s=Math.min(l.col,o),i=Math.max(l.col,o),c=[];for(const d of e.cells){d.row>=r&&d.row<=n&&d.col>=s&&d.col<=i&&c.push(d.id)}e._focusedCellIds=c},clearCellFocus(){if(l(e)){if(e._editingCellId){const t=e.cells.find(t=>t.id===e._editingCellId);t&&t.toggleEditMode(!1)}e._focusedCellIds=[],e._editingCellId=void 0,e._editClickCoords=null,e._anchorCellId=void 0}},enterCellEdit(t,l=null){e._editingCellId!==t&&o.exitCellEdit(),e._editingCellId=t,e._editClickCoords=l,e._focusedCellIds.includes(t)||(e._focusedCellIds=[t]);const r=e.cells.find(e=>e.id===t);r&&r.toggleEditMode(!0)},exitCellEdit(){if(e._editingCellId){const t=e.cells.find(t=>t.id===e._editingCellId);t&&t.toggleEditMode(!1)}e._editingCellId=void 0,e._editClickCoords=null},_resetBaseRowHeights(){e._baseRowHeights=null,e._baseHeight=null},setHeightRedistribute(t){const o=e.rows;if(0===o||t<=0){return void(e.height=t)}const l=e.height;if(l<=0||t>=l){return void(e.height=t)}const r=e.rowHeights.map(e=>e*l),n=e.rowContentFloors,s=n.reduce((e,t)=>e+t,0);if(t<=s||s<=0){return void(e.height=t)}const i=t-s;let c=0;const d=[];for(let e=0;e<o;e++){const t=Math.max(0,r[e]-n[e]);d.push(t),c+=t}const a=[];if(c<=0){const e=t/l;for(let t=0;t<o;t++){a.push(r[t]*e)}}else{for(let e=0;e<o;e++){a.push(n[e]+d[e]/c*i)}}const g=a.map(e=>e/t);e.height=t,e.rowHeights.replace(g)},addRow(t){o._resetBaseRowHeights();const l=t>0?t-1:0,r=(e.rowHeights[l]||1/(e.rows+1))*e.height,n=e.height+r,s=[];for(let o=0;o<e.rows;o++){s.push(e.rowHeights[o]*e.height/n)}s.splice(t,0,r/n);const i=t>0?t-1:0,c=[];for(let o=0;o<e.cols;o++){c.push(e.cells[i*e.cols+o])}const d=t*e.cols,a=j(c,!0);e.cells.splice(d,0,...a),e.rows+=1,e.height=n,e.rowHeights.replace(W(s))},removeRow(t){if(e.rows<=1){return}o._resetBaseRowHeights();const l=t*e.cols,r=[];for(let o=l;o<l+e.cols;o++){r.push(e.cells[o].id)}if(e._editingCellId&&r.includes(e._editingCellId)){const t=e.cells.find(t=>t.id===e._editingCellId);t&&t.toggleEditMode(!1),e._editingCellId=void 0}e._focusedCellIds=e._focusedCellIds.filter(e=>!r.includes(e)),r.forEach(t=>e._cellContentHeights.delete(t)),e.cells.splice(l,e.cols);const n=[...e.rowHeights];n.splice(t,1),e.rows-=1,e.rowHeights.replace(W(n))},addColumn(t){const o=t>0?t-1:0,l=(e.colWidths[o]||1/(e.cols+1))*e.width,r=e.width+l,s=[];for(let n=0;n<e.cols;n++){s.push(e.colWidths[n]*e.width/r)}s.splice(t,0,l/r);const i=e.cols,c=t>0?t-1:0,d=[];for(let n=0;n<e.rows;n++){d.push(e.cells[n*i+c])}const a=j(d,!1);for(let g=e.rows-1;g>=0;g--){e.cells.splice(g*i+t,0,n(a[g]))}e.cols+=1,e.width=r,e.colWidths.replace(W(s))},removeColumn(t){if(e.cols<=1){return}const o=e.cols,l=[];for(let n=0;n<e.rows;n++){l.push(e.cells[n*o+t].id)}if(e._editingCellId&&l.includes(e._editingCellId)){const t=e.cells.find(t=>t.id===e._editingCellId);t&&t.toggleEditMode(!1),e._editingCellId=void 0}e._focusedCellIds=e._focusedCellIds.filter(e=>!l.includes(e)),l.forEach(t=>e._cellContentHeights.delete(t));for(let n=e.rows-1;n>=0;n--){e.cells.splice(n*o+t,1)}const r=[...e.colWidths];r.splice(t,1),e.cols-=1,e.colWidths.replace(W(r))},removeRowRange(t,l){for(let r=l;r>=t&&!(e.rows<=1);r--){o.removeRow(r)}},removeColumnRange(t,l){for(let r=l;r>=t&&!(e.cols<=1);r--){o.removeColumn(r)}},distributeRowsEvenly(){const t=e.rows,l=Math.max(20,...e.rowContentFloors);o._resetBaseRowHeights(),e.height=Math.max(e.height,l*t),e.rowHeights.replace(B(t))},distributeColumnsEvenly(){e.colWidths.replace(B(e.cols))},resizeColumn(t,o){if(t>=e.cols-1){return}const l=[...e.colWidths],r=l[t]+l[t+1],n=l[t]+o,s=l[t+1]-o;n<w?(l[t]=w,l[t+1]=r-w):s<w?(l[t+1]=w,l[t]=r-w):(l[t]=n,l[t+1]=s),e.colWidths.replace(l)},resizeRow(t,o){if(t>=e.rows-1){return}const l=[...e.rowHeights],r=l[t]+l[t+1],n=e.height,s=e.contentFloors(t),i=n>0?s[t]/n:0,c=n>0?s[t+1]/n:0,d=Math.max(w,i),a=Math.max(w,c),g=l[t]+o,u=l[t+1]-o;g<d?(l[t]=d,l[t+1]=r-d):u<a?(l[t+1]=a,l[t]=r-a):(l[t]=g,l[t+1]=u),e.rowHeights.replace(l)},setCellBorders(t,o,l){const r={top:{side:"bottom",dr:-1,dc:0},bottom:{side:"top",dr:1,dc:0},left:{side:"right",dr:0,dc:-1},right:{side:"left",dr:0,dc:1}};for(const n of t){const t=e.cells.find(e=>e.id===n);if(t){for(const n of o){t.setBorder(n,l);const o=r[n],s=t.row+o.dr,i=t.col+o.dc,c=e.getCell(s,i);c&&c.setBorder(o.side,l)}}}},applyBorderMode(t,l){var r;const n=function(e,t,o){const{minRow:l,maxRow:r,minCol:n,maxCol:s}=t,i=(e,t,l,r)=>{const n=[];for(let s=e;s<=t;s++){for(let e=l;e<=r;e++){const t=o(s,e);t&&n.push(t.id)}}return n};if("all"===e){return[{cellIds:i(l,r,n,s),sides:["top","right","bottom","left"]}]}const c=[],d="outer"===e||"topOnly"===e||"topBottom"===e,a="outer"===e||"bottomOnly"===e||"topBottom"===e,g="outer"===e||"leftOnly"===e,u="outer"===e||"rightOnly"===e;if(d){const e=i(l,l,n,s);e.length&&c.push({cellIds:e,sides:["top"]})}if(a){const e=i(r,r,n,s);e.length&&c.push({cellIds:e,sides:["bottom"]})}if(g){const e=i(l,r,n,n);e.length&&c.push({cellIds:e,sides:["left"]})}if(u){const e=i(l,r,s,s);e.length&&c.push({cellIds:e,sides:["right"]})}if(d||a||g||u){return c}if(("inner"===e||"innerHorizontal"===e)&&r>l){const e=i(l,r-1,n,s);e.length&&c.push({cellIds:e,sides:["bottom"]})}if(("inner"===e||"innerVertical"===e)&&s>n){const e=i(l,r,n,s-1);e.length&&c.push({cellIds:e,sides:["right"]})}return c}(t,null!==(r=e.getFocusedCellRange())&&void 0!==r?r:{minRow:0,maxRow:e.rows-1,minCol:0,maxCol:e.cols-1},(t,o)=>e.getCell(t,o));for(const{cellIds:e,sides:s}of n){o.setCellBorders(e,s,l)}}};return o}).actions(e=>({clone(t={},{skipSelect:o=!1}={}){const l=JSON.parse(JSON.stringify(e.toJSON()));if(t.id=t.id||c(10),l.cells){const e=new Map;l.cells.forEach(t=>{const o=t.id,l=c(10);e.set(o,l),t.id=l}),l.cells.forEach(t=>{t.mergedInto&&e.has(t.mergedInto)&&(t.mergedInto=e.get(t.mergedInto))})}return Object.assign(l,t),e.page.addElement(l,{skipSelect:o})}}));
|
package/model/text-model.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ export declare const TextElement: import("mobx-state-tree").IModelType<{
|
|
|
6
6
|
opacity: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
7
7
|
blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "normal" | "overlay" | "saturation" | "screen" | "soft-light">, [undefined]>;
|
|
8
8
|
custom: import("mobx-state-tree").IType<any, any, any>;
|
|
9
|
+
bindings: import("mobx-state-tree").IMaybe<import("mobx-state-tree").IType<import("@polotno/schema").Bindings, import("@polotno/schema").Bindings, import("@polotno/schema").Bindings>>;
|
|
10
|
+
href: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<string>>;
|
|
9
11
|
visible: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
10
12
|
selectable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
11
13
|
removable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
@@ -70,7 +72,6 @@ export declare const TextElement: import("mobx-state-tree").IModelType<{
|
|
|
70
72
|
strokeLineJoin: import("mobx-state-tree").IType<string | undefined, string, string>;
|
|
71
73
|
lineHeight: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree/dist/internal").IUnionType<[import("mobx-state-tree").ISimpleType<number>, import("mobx-state-tree").ISimpleType<string>]>, [undefined]>;
|
|
72
74
|
letterSpacing: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
73
|
-
_editModeEnabled: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
74
75
|
backgroundEnabled: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
75
76
|
backgroundColor: import("mobx-state-tree").IType<string | undefined, string, string>;
|
|
76
77
|
backgroundOpacity: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
@@ -88,6 +89,13 @@ export declare const TextElement: import("mobx-state-tree").IModelType<{
|
|
|
88
89
|
}, {
|
|
89
90
|
readonly page: any;
|
|
90
91
|
readonly store: any;
|
|
92
|
+
readonly filled: Partial<{
|
|
93
|
+
text?: string;
|
|
94
|
+
placeholder?: string;
|
|
95
|
+
src?: string;
|
|
96
|
+
fill?: string;
|
|
97
|
+
visible?: boolean;
|
|
98
|
+
}>;
|
|
91
99
|
readonly top: import("mobx-state-tree").ModelInstanceTypeProps<{
|
|
92
100
|
id: import("mobx-state-tree").ISimpleType<string>;
|
|
93
101
|
type: import("mobx-state-tree").IType<string | undefined, string, string>;
|
|
@@ -95,6 +103,8 @@ export declare const TextElement: import("mobx-state-tree").IModelType<{
|
|
|
95
103
|
opacity: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
96
104
|
blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "normal" | "overlay" | "saturation" | "screen" | "soft-light">, [undefined]>;
|
|
97
105
|
custom: import("mobx-state-tree").IType<any, any, any>;
|
|
106
|
+
bindings: import("mobx-state-tree").IMaybe<import("mobx-state-tree").IType<import("@polotno/schema").Bindings, import("@polotno/schema").Bindings, import("@polotno/schema").Bindings>>;
|
|
107
|
+
href: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<string>>;
|
|
98
108
|
visible: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
99
109
|
selectable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
100
110
|
removable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
@@ -107,6 +117,8 @@ export declare const TextElement: import("mobx-state-tree").IModelType<{
|
|
|
107
117
|
opacity: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
108
118
|
blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "normal" | "overlay" | "saturation" | "screen" | "soft-light">, [undefined]>;
|
|
109
119
|
custom: import("mobx-state-tree").IType<any, any, any>;
|
|
120
|
+
bindings: import("mobx-state-tree").IMaybe<import("mobx-state-tree").IType<import("@polotno/schema").Bindings, import("@polotno/schema").Bindings, import("@polotno/schema").Bindings>>;
|
|
121
|
+
href: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<string>>;
|
|
110
122
|
visible: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
111
123
|
selectable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
112
124
|
removable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
@@ -119,6 +131,8 @@ export declare const TextElement: import("mobx-state-tree").IModelType<{
|
|
|
119
131
|
opacity: number | undefined;
|
|
120
132
|
blendMode: "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "normal" | "overlay" | "saturation" | "screen" | "soft-light" | undefined;
|
|
121
133
|
custom: any;
|
|
134
|
+
bindings: import("@polotno/schema").Bindings | undefined;
|
|
135
|
+
href: string | undefined;
|
|
122
136
|
visible: boolean | undefined;
|
|
123
137
|
selectable: boolean | undefined;
|
|
124
138
|
removable: boolean | undefined;
|
|
@@ -130,6 +144,8 @@ export declare const TextElement: import("mobx-state-tree").IModelType<{
|
|
|
130
144
|
name: string;
|
|
131
145
|
opacity: number;
|
|
132
146
|
custom: any;
|
|
147
|
+
bindings: import("@polotno/schema").Bindings | undefined;
|
|
148
|
+
href: string | undefined;
|
|
133
149
|
visible: boolean;
|
|
134
150
|
selectable: boolean;
|
|
135
151
|
removable: boolean;
|
|
@@ -141,6 +157,8 @@ export declare const TextElement: import("mobx-state-tree").IModelType<{
|
|
|
141
157
|
name: string;
|
|
142
158
|
opacity: number;
|
|
143
159
|
custom: any;
|
|
160
|
+
bindings: import("@polotno/schema").Bindings | undefined;
|
|
161
|
+
href: string | undefined;
|
|
144
162
|
visible: boolean;
|
|
145
163
|
selectable: boolean;
|
|
146
164
|
removable: boolean;
|
|
@@ -158,6 +176,8 @@ export declare const TextElement: import("mobx-state-tree").IModelType<{
|
|
|
158
176
|
name: string;
|
|
159
177
|
opacity: number;
|
|
160
178
|
custom: any;
|
|
179
|
+
bindings: import("@polotno/schema").Bindings | undefined;
|
|
180
|
+
href: string | undefined;
|
|
161
181
|
visible: boolean;
|
|
162
182
|
selectable: boolean;
|
|
163
183
|
removable: boolean;
|
|
@@ -169,6 +189,8 @@ export declare const TextElement: import("mobx-state-tree").IModelType<{
|
|
|
169
189
|
name: string;
|
|
170
190
|
opacity: number;
|
|
171
191
|
custom: any;
|
|
192
|
+
bindings: import("@polotno/schema").Bindings | undefined;
|
|
193
|
+
href: string | undefined;
|
|
172
194
|
visible: boolean;
|
|
173
195
|
selectable: boolean;
|
|
174
196
|
removable: boolean;
|
|
@@ -201,6 +223,8 @@ export declare const TextElement: import("mobx-state-tree").IModelType<{
|
|
|
201
223
|
} & {
|
|
202
224
|
setAnimation(type: 'enter' | 'exit' | 'loop', attrs: import("../utils/animations.js").AnimationAttrs): void;
|
|
203
225
|
setFilter(type: any, value: any): void;
|
|
226
|
+
} & {
|
|
227
|
+
_editModeEnabled: boolean;
|
|
204
228
|
} & {
|
|
205
229
|
set(attrs: any): void;
|
|
206
230
|
toggleEditMode(editing?: boolean): void;
|
|
@@ -211,6 +235,8 @@ export declare const TextElement: import("mobx-state-tree").IModelType<{
|
|
|
211
235
|
name: string;
|
|
212
236
|
opacity: number;
|
|
213
237
|
custom: any;
|
|
238
|
+
bindings: import("@polotno/schema").Bindings | undefined;
|
|
239
|
+
href: string | undefined;
|
|
214
240
|
visible: boolean;
|
|
215
241
|
selectable: boolean;
|
|
216
242
|
removable: boolean;
|
|
@@ -222,6 +248,8 @@ export declare const TextElement: import("mobx-state-tree").IModelType<{
|
|
|
222
248
|
name: string;
|
|
223
249
|
opacity: number;
|
|
224
250
|
custom: any;
|
|
251
|
+
bindings: import("@polotno/schema").Bindings | undefined;
|
|
252
|
+
href: string | undefined;
|
|
225
253
|
visible: boolean;
|
|
226
254
|
selectable: boolean;
|
|
227
255
|
removable: boolean;
|
package/model/text-model.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{types as e,isAlive as t}from"mobx-state-tree";import{clampFontSize as o}from"@polotno/schema/defaults";import{hasMeasuredHeight as n,parseNumericLineHeight as i}from"@polotno/core/text-types";import{Shape as r}from"./shape-model.js";const a=e=>{var t;return"string"!=typeof e?e:null!==(t=i(e))&&void 0!==t?t:e};export const TextElement=r.named("Text").props({type:"text",text:"",placeholder:"",fontSize:14,fontFamily:"Roboto",fontStyle:"normal",fontWeight:"normal",textDecoration:"",textTransform:"none",fill:"black",align:"center",width:100,height:0,verticalAlign:"top",strokeWidth:0,stroke:"black",strokeLineJoin:"round",lineHeight:e.optional(e.union(e.number,e.string),1.2),letterSpacing:0,
|
|
1
|
+
import{types as e,isAlive as t}from"mobx-state-tree";import{clampFontSize as o}from"@polotno/schema/defaults";import{hasMeasuredHeight as n,parseNumericLineHeight as i}from"@polotno/core/text-types";import{Shape as r}from"./shape-model.js";const a=e=>{var t;return"string"!=typeof e?e:null!==(t=i(e))&&void 0!==t?t:e};export const TextElement=r.named("Text").props({type:"text",text:"",placeholder:"",fontSize:14,fontFamily:"Roboto",fontStyle:"normal",fontWeight:"normal",textDecoration:"",textTransform:"none",fill:"black",align:"center",width:100,height:0,verticalAlign:"top",strokeWidth:0,stroke:"black",strokeLineJoin:"round",lineHeight:e.optional(e.union(e.number,e.string),1.2),letterSpacing:0,backgroundEnabled:!1,backgroundColor:"#7ED321",backgroundOpacity:1,backgroundCornerRadius:.5,backgroundPadding:.5,borderColor:"black",borderSize:0,legacyBackground:e.maybe(e.boolean),curveEnabled:!1,curvePower:.5,textOverflow:e.maybe(e.string),maxLines:e.maybe(e.number),minFontSize:e.maybe(e.number),maxFontSize:e.maybe(e.number)}).volatile(()=>({_editModeEnabled:!1})).preProcessSnapshot(e=>{const t=Object.assign(Object.assign({},e),{fontSize:o(e.fontSize),minFontSize:o(e.minFontSize),maxFontSize:o(e.maxFontSize),lineHeight:a(e.lineHeight)});return n(t)||delete t.height,t}).actions(e=>{const n=e.set;return{set(e){for(const t of["fontSize","minFontSize","maxFontSize"]){null!=e[t]&&(e=Object.assign(Object.assign({},e),{[t]:o(e[t])}))}"string"==typeof e.lineHeight&&(e=Object.assign(Object.assign({},e),{lineHeight:a(e.lineHeight)})),n(e)},toggleEditMode(o){if(!t(e)){return}const n=null!=o?o:!e._editModeEnabled;n!==e._editModeEnabled&&(e._editModeEnabled=n,e._editModeEnabled?e.store.history.startTransaction():e.store.history.endTransaction())},beforeDestroy(){e._editModeEnabled&&e.store.history.endTransaction()}}});
|
package/model/video-model.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ export declare const VideoElement: import("mobx-state-tree").IModelType<{
|
|
|
6
6
|
opacity: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
7
7
|
blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "normal" | "overlay" | "saturation" | "screen" | "soft-light">, [undefined]>;
|
|
8
8
|
custom: import("mobx-state-tree").IType<any, any, any>;
|
|
9
|
+
bindings: import("mobx-state-tree").IMaybe<import("mobx-state-tree").IType<import("@polotno/schema").Bindings, import("@polotno/schema").Bindings, import("@polotno/schema").Bindings>>;
|
|
10
|
+
href: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<string>>;
|
|
9
11
|
visible: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
10
12
|
selectable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
11
13
|
removable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
@@ -52,6 +54,17 @@ export declare const VideoElement: import("mobx-state-tree").IModelType<{
|
|
|
52
54
|
showInExport: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
53
55
|
} & {
|
|
54
56
|
type: import("mobx-state-tree").IType<string | undefined, string, string>;
|
|
57
|
+
fit: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<"contain" | "cover">>;
|
|
58
|
+
focus: import("mobx-state-tree").IMaybe<import("mobx-state-tree").IType<{
|
|
59
|
+
x: number;
|
|
60
|
+
y: number;
|
|
61
|
+
}, {
|
|
62
|
+
x: number;
|
|
63
|
+
y: number;
|
|
64
|
+
}, {
|
|
65
|
+
x: number;
|
|
66
|
+
y: number;
|
|
67
|
+
}>>;
|
|
55
68
|
width: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
56
69
|
height: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
57
70
|
src: import("mobx-state-tree").IType<string | undefined, string, string>;
|
|
@@ -77,6 +90,13 @@ export declare const VideoElement: import("mobx-state-tree").IModelType<{
|
|
|
77
90
|
}, {
|
|
78
91
|
readonly page: any;
|
|
79
92
|
readonly store: any;
|
|
93
|
+
readonly filled: Partial<{
|
|
94
|
+
text?: string;
|
|
95
|
+
placeholder?: string;
|
|
96
|
+
src?: string;
|
|
97
|
+
fill?: string;
|
|
98
|
+
visible?: boolean;
|
|
99
|
+
}>;
|
|
80
100
|
readonly top: import("mobx-state-tree").ModelInstanceTypeProps<{
|
|
81
101
|
id: import("mobx-state-tree").ISimpleType<string>;
|
|
82
102
|
type: import("mobx-state-tree").IType<string | undefined, string, string>;
|
|
@@ -84,6 +104,8 @@ export declare const VideoElement: import("mobx-state-tree").IModelType<{
|
|
|
84
104
|
opacity: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
85
105
|
blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "normal" | "overlay" | "saturation" | "screen" | "soft-light">, [undefined]>;
|
|
86
106
|
custom: import("mobx-state-tree").IType<any, any, any>;
|
|
107
|
+
bindings: import("mobx-state-tree").IMaybe<import("mobx-state-tree").IType<import("@polotno/schema").Bindings, import("@polotno/schema").Bindings, import("@polotno/schema").Bindings>>;
|
|
108
|
+
href: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<string>>;
|
|
87
109
|
visible: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
88
110
|
selectable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
89
111
|
removable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
@@ -96,6 +118,8 @@ export declare const VideoElement: import("mobx-state-tree").IModelType<{
|
|
|
96
118
|
opacity: import("mobx-state-tree").IType<number | undefined, number, number>;
|
|
97
119
|
blendMode: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<"color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "normal" | "overlay" | "saturation" | "screen" | "soft-light">, [undefined]>;
|
|
98
120
|
custom: import("mobx-state-tree").IType<any, any, any>;
|
|
121
|
+
bindings: import("mobx-state-tree").IMaybe<import("mobx-state-tree").IType<import("@polotno/schema").Bindings, import("@polotno/schema").Bindings, import("@polotno/schema").Bindings>>;
|
|
122
|
+
href: import("mobx-state-tree").IMaybe<import("mobx-state-tree").ISimpleType<string>>;
|
|
99
123
|
visible: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
100
124
|
selectable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
101
125
|
removable: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
|
|
@@ -108,6 +132,8 @@ export declare const VideoElement: import("mobx-state-tree").IModelType<{
|
|
|
108
132
|
opacity: number | undefined;
|
|
109
133
|
blendMode: "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "normal" | "overlay" | "saturation" | "screen" | "soft-light" | undefined;
|
|
110
134
|
custom: any;
|
|
135
|
+
bindings: import("@polotno/schema").Bindings | undefined;
|
|
136
|
+
href: string | undefined;
|
|
111
137
|
visible: boolean | undefined;
|
|
112
138
|
selectable: boolean | undefined;
|
|
113
139
|
removable: boolean | undefined;
|
|
@@ -119,6 +145,8 @@ export declare const VideoElement: import("mobx-state-tree").IModelType<{
|
|
|
119
145
|
name: string;
|
|
120
146
|
opacity: number;
|
|
121
147
|
custom: any;
|
|
148
|
+
bindings: import("@polotno/schema").Bindings | undefined;
|
|
149
|
+
href: string | undefined;
|
|
122
150
|
visible: boolean;
|
|
123
151
|
selectable: boolean;
|
|
124
152
|
removable: boolean;
|
|
@@ -130,6 +158,8 @@ export declare const VideoElement: import("mobx-state-tree").IModelType<{
|
|
|
130
158
|
name: string;
|
|
131
159
|
opacity: number;
|
|
132
160
|
custom: any;
|
|
161
|
+
bindings: import("@polotno/schema").Bindings | undefined;
|
|
162
|
+
href: string | undefined;
|
|
133
163
|
visible: boolean;
|
|
134
164
|
selectable: boolean;
|
|
135
165
|
removable: boolean;
|
|
@@ -147,6 +177,8 @@ export declare const VideoElement: import("mobx-state-tree").IModelType<{
|
|
|
147
177
|
name: string;
|
|
148
178
|
opacity: number;
|
|
149
179
|
custom: any;
|
|
180
|
+
bindings: import("@polotno/schema").Bindings | undefined;
|
|
181
|
+
href: string | undefined;
|
|
150
182
|
visible: boolean;
|
|
151
183
|
selectable: boolean;
|
|
152
184
|
removable: boolean;
|
|
@@ -158,6 +190,8 @@ export declare const VideoElement: import("mobx-state-tree").IModelType<{
|
|
|
158
190
|
name: string;
|
|
159
191
|
opacity: number;
|
|
160
192
|
custom: any;
|
|
193
|
+
bindings: import("@polotno/schema").Bindings | undefined;
|
|
194
|
+
href: string | undefined;
|
|
161
195
|
visible: boolean;
|
|
162
196
|
selectable: boolean;
|
|
163
197
|
removable: boolean;
|
|
@@ -214,6 +248,8 @@ export declare const VideoElement: import("mobx-state-tree").IModelType<{
|
|
|
214
248
|
opacity: number | undefined;
|
|
215
249
|
blendMode: "color" | "color-burn" | "color-dodge" | "darken" | "difference" | "exclusion" | "hard-light" | "hue" | "lighten" | "luminosity" | "multiply" | "normal" | "overlay" | "saturation" | "screen" | "soft-light" | undefined;
|
|
216
250
|
custom: any;
|
|
251
|
+
bindings: import("@polotno/schema").Bindings | undefined;
|
|
252
|
+
href: string | undefined;
|
|
217
253
|
visible: boolean | undefined;
|
|
218
254
|
selectable: boolean | undefined;
|
|
219
255
|
removable: boolean | undefined;
|
|
@@ -225,6 +261,8 @@ export declare const VideoElement: import("mobx-state-tree").IModelType<{
|
|
|
225
261
|
name: string;
|
|
226
262
|
opacity: number;
|
|
227
263
|
custom: any;
|
|
264
|
+
bindings: import("@polotno/schema").Bindings | undefined;
|
|
265
|
+
href: string | undefined;
|
|
228
266
|
visible: boolean;
|
|
229
267
|
selectable: boolean;
|
|
230
268
|
removable: boolean;
|
|
@@ -236,6 +274,8 @@ export declare const VideoElement: import("mobx-state-tree").IModelType<{
|
|
|
236
274
|
name: string;
|
|
237
275
|
opacity: number;
|
|
238
276
|
custom: any;
|
|
277
|
+
bindings: import("@polotno/schema").Bindings | undefined;
|
|
278
|
+
href: string | undefined;
|
|
239
279
|
visible: boolean;
|
|
240
280
|
selectable: boolean;
|
|
241
281
|
removable: boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "polotno",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.22.0",
|
|
4
4
|
"description": "Design editor SDK: embed a Canva-like editor, generate designs from templates and data, export PNG, PDF, and video in the browser or on a server.",
|
|
5
5
|
"author": "Anton Lavrenov",
|
|
6
6
|
"keywords": [
|
|
@@ -108,28 +108,28 @@
|
|
|
108
108
|
},
|
|
109
109
|
"dependencies": {
|
|
110
110
|
"@base-ui/react": "^1.9.0",
|
|
111
|
-
"@lottiefiles/dotlottie-web": "0.
|
|
112
|
-
"@polotno/core": "0.
|
|
113
|
-
"@polotno/html-export": "0.
|
|
114
|
-
"@polotno/schema": "0.
|
|
115
|
-
"@polotno/svg-export": "0.
|
|
111
|
+
"@lottiefiles/dotlottie-web": "0.83.2",
|
|
112
|
+
"@polotno/core": "0.23.0",
|
|
113
|
+
"@polotno/html-export": "0.13.0",
|
|
114
|
+
"@polotno/schema": "0.14.0",
|
|
115
|
+
"@polotno/svg-export": "0.14.0",
|
|
116
116
|
"class-variance-authority": "^0.7.1",
|
|
117
117
|
"clsx": "^2.1.1",
|
|
118
118
|
"gifuct-js": "^2.1.2",
|
|
119
119
|
"konva": "^10.9.1",
|
|
120
120
|
"lodash-es": "^4.18.1",
|
|
121
|
-
"lucide-react": "^1.
|
|
122
|
-
"mediabunny": "^1.
|
|
123
|
-
"mobx": "7.1.
|
|
124
|
-
"mobx-react-lite": "^5.1.
|
|
125
|
-
"mobx-state-tree": "9.0.
|
|
121
|
+
"lucide-react": "^1.75.0",
|
|
122
|
+
"mediabunny": "^1.66.0",
|
|
123
|
+
"mobx": "7.1.7",
|
|
124
|
+
"mobx-react-lite": "^5.1.3",
|
|
125
|
+
"mobx-state-tree": "9.0.2",
|
|
126
126
|
"nanoid": "^6.0.2",
|
|
127
127
|
"quill": "^2.0.3",
|
|
128
128
|
"react-konva": "18.2.16",
|
|
129
|
-
"react-konva-utils": "^2.1.
|
|
129
|
+
"react-konva-utils": "^2.1.1",
|
|
130
130
|
"react-sortablejs": "6.1.4",
|
|
131
131
|
"react-window": "^2.5.3",
|
|
132
|
-
"render-tag": "0.4.
|
|
132
|
+
"render-tag": "0.4.6",
|
|
133
133
|
"sortablejs": "^1.15.7",
|
|
134
134
|
"svg-round-corners": "^0.4.3",
|
|
135
135
|
"swr": "^2.5.1",
|
|
@@ -156,12 +156,12 @@
|
|
|
156
156
|
}
|
|
157
157
|
},
|
|
158
158
|
"devDependencies": {
|
|
159
|
-
"@babel/parser": "^8.1.
|
|
160
|
-
"@babel/traverse": "^8.1.
|
|
161
|
-
"@blueprintjs/core": "6.
|
|
162
|
-
"@blueprintjs/icons": "^6.
|
|
163
|
-
"@blueprintjs/select": "6.4.
|
|
164
|
-
"@napi-rs/canvas": "1.1.
|
|
159
|
+
"@babel/parser": "^8.1.2",
|
|
160
|
+
"@babel/traverse": "^8.1.2",
|
|
161
|
+
"@blueprintjs/core": "6.23.1",
|
|
162
|
+
"@blueprintjs/icons": "^6.17.0",
|
|
163
|
+
"@blueprintjs/select": "6.4.3",
|
|
164
|
+
"@napi-rs/canvas": "1.1.1",
|
|
165
165
|
"@polotno/design-fixtures": "0.0.0",
|
|
166
166
|
"@polotno/visual-testing": "0.0.0",
|
|
167
167
|
"@tailwindcss/cli": "^4.3.5",
|
|
@@ -170,22 +170,21 @@
|
|
|
170
170
|
"@testing-library/react": "^16.3.3",
|
|
171
171
|
"@types/react": "^19.3.0",
|
|
172
172
|
"@vitejs/plugin-react": "^6.3.0",
|
|
173
|
-
"@vitest/browser-playwright": "^5.1.
|
|
173
|
+
"@vitest/browser-playwright": "^5.1.1",
|
|
174
174
|
"assemblyscript": "^0.28.20",
|
|
175
175
|
"bippy": "^0.7.3",
|
|
176
|
-
"glob": "^14.0.4",
|
|
177
176
|
"linkedom": "^0.18.15",
|
|
178
|
-
"playwright": "^1.65.
|
|
179
|
-
"postcss": "^8.5.
|
|
180
|
-
"postcss-selector-parser": "^7.2.
|
|
177
|
+
"playwright": "^1.65.1",
|
|
178
|
+
"postcss": "^8.5.33",
|
|
179
|
+
"postcss-selector-parser": "^7.2.1",
|
|
181
180
|
"react": "^19.3.1",
|
|
182
181
|
"react-dom": "^19.3.1",
|
|
183
182
|
"tailwindcss": "^4.3.5",
|
|
184
183
|
"terser": "^5.51.2",
|
|
185
184
|
"tw-animate-css": "^1.4.0",
|
|
186
185
|
"typescript": "~7.0.2",
|
|
187
|
-
"vite": "^8.3.
|
|
188
|
-
"vitest": "^5.1.
|
|
186
|
+
"vite": "^8.3.8",
|
|
187
|
+
"vitest": "^5.1.1"
|
|
189
188
|
},
|
|
190
189
|
"homepage": "https://polotno.com/",
|
|
191
190
|
"scripts": {
|
|
@@ -201,7 +200,6 @@
|
|
|
201
200
|
"check:no-blueprint": "node build/check-no-blueprint.cjs ./lib",
|
|
202
201
|
"minify": "node minify.cjs",
|
|
203
202
|
"build": "node build/build.mjs",
|
|
204
|
-
"remove-test-from-lib": "find ./lib -type d -name \"__tests__\" -exec rm -rf {} + && find ./lib \\( -name \"*.test.js\" -o -name \"*.test.d.ts\" \\) -type f -delete",
|
|
205
203
|
"add_version": "node ../../scripts/stamp-version.mjs",
|
|
206
204
|
"build:bundle": "vite build && find ./lib -name '*.js.map' -type f -delete",
|
|
207
205
|
"test": "node scripts/run-tests-parallel.mjs",
|