polotno 4.22.1 → 4.23.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.
Files changed (72) hide show
  1. package/THIRD_PARTY_NOTICES.md +7 -7
  2. package/blueprint/toolbar/color-picker.js +2 -2
  3. package/canvas/element.js +1 -1
  4. package/canvas/fade-overlay.d.ts +5 -0
  5. package/canvas/fade-overlay.js +1 -1
  6. package/canvas/html-element.js +1 -1
  7. package/canvas/image-element.js +1 -1
  8. package/canvas/line-element.js +1 -1
  9. package/canvas/page.js +1 -1
  10. package/canvas/quill-font-formats.d.ts +1 -0
  11. package/canvas/quill-font-formats.js +1 -1
  12. package/canvas/radial-gradient-handle.d.ts +14 -0
  13. package/canvas/radial-gradient-handle.js +1 -0
  14. package/canvas/render-tag-element.js +1 -1
  15. package/canvas/rich-editor.js +12 -6
  16. package/canvas/text-element/legacy-padding-warning.d.ts +6 -0
  17. package/canvas/text-element/legacy-padding-warning.js +1 -0
  18. package/canvas/text-element/max-font-size.js +1 -1
  19. package/canvas/text-element.js +1 -1
  20. package/canvas/use-color.d.ts +24 -2
  21. package/canvas/use-color.js +1 -1
  22. package/icons/registry.d.ts +1 -0
  23. package/icons/registry.js +1 -1
  24. package/model/group-model.d.ts +26 -10
  25. package/model/group-model.js +1 -1
  26. package/model/node-model.d.ts +10 -1
  27. package/model/node-model.js +1 -1
  28. package/model/page-model.d.ts +75 -33
  29. package/model/page-model.js +1 -1
  30. package/model/table-model.d.ts +29 -9
  31. package/model/table-model.js +1 -1
  32. package/model/text-model.d.ts +5 -1
  33. package/model/text-model.js +1 -1
  34. package/package.json +16 -16
  35. package/polotno.bundle.js +194 -202
  36. package/primitives/field-group.js +1 -1
  37. package/primitives/popover.d.ts +1 -1
  38. package/primitives/popover.js +1 -1
  39. package/side-panel/effects-panel.js +1 -1
  40. package/side-panel/templates-panel.js +1 -1
  41. package/toolbar/color-picker.js +1 -1
  42. package/toolbar/gradient-center-pad.d.ts +11 -0
  43. package/toolbar/gradient-center-pad.js +1 -0
  44. package/toolbar/padding-control.d.ts +29 -0
  45. package/toolbar/padding-control.js +1 -0
  46. package/toolbar/selection-colors.js +1 -1
  47. package/toolbar/stop-track.js +1 -1
  48. package/toolbar/table-toolbar.js +1 -1
  49. package/toolbar/text-toolbar.d.ts +7 -2
  50. package/toolbar/text-toolbar.js +1 -1
  51. package/toolbar/unit-numeric-input.d.ts +5 -0
  52. package/toolbar/unit-numeric-input.js +1 -0
  53. package/toolbar/use-copy-style.js +1 -1
  54. package/ui.css +1 -1
  55. package/utils/clipboard.d.ts +10 -2
  56. package/utils/clipboard.js +1 -1
  57. package/utils/gradient-handle.d.ts +18 -0
  58. package/utils/gradient-handle.js +1 -0
  59. package/utils/gradient-stops.d.ts +7 -2
  60. package/utils/gradient-stops.js +1 -1
  61. package/utils/history-gesture.d.ts +7 -0
  62. package/utils/history-gesture.js +1 -0
  63. package/utils/l10n.d.ts +16 -1
  64. package/utils/l10n.js +1 -1
  65. package/utils/measure-text.d.ts +4 -0
  66. package/utils/measure-text.js +1 -1
  67. package/utils/px.d.ts +4 -0
  68. package/utils/px.js +1 -1
  69. package/utils/rich-text-html.d.ts +1 -0
  70. package/utils/rich-text-html.js +1 -1
  71. package/utils/selection-transform.js +1 -1
  72. package/utils/validate-key.js +1 -1
@@ -0,0 +1,7 @@
1
+ import type { IAnyStateTreeNode } from 'mobx-state-tree';
2
+ import type { StoreType } from '../ui-types.js';
3
+ export declare function useHistoryGesture(store: StoreType, node?: IAnyStateTreeNode): {
4
+ begin: () => void;
5
+ end: () => void;
6
+ active: () => boolean;
7
+ };
@@ -0,0 +1 @@
1
+ import t from"react";export function useHistoryGesture(r,e){const n=t.useRef(!1),o=()=>{n.current&&(n.current=!1,r.history.endTransaction())};return t.useEffect(()=>()=>o(),[r,e]),{begin:()=>{o(),r.history.addUndoState(),r.history.startTransaction(),n.current=!0},end:o,active:()=>n.current}}
package/utils/l10n.d.ts CHANGED
@@ -78,10 +78,19 @@ export declare const getTranslations: () => {
78
78
  black: string;
79
79
  vibrance: string;
80
80
  textBackground: string;
81
- textBox: string;
82
81
  backgroundCornerRadius: string;
83
82
  backgroundOpacity: string;
84
83
  backgroundPadding: string;
84
+ backgroundShape: string;
85
+ backgroundFill: string;
86
+ backgroundShapeLines: string;
87
+ backgroundShapeBox: string;
88
+ textPadding: string;
89
+ paddingSides: string;
90
+ paddingTop: string;
91
+ paddingRight: string;
92
+ paddingBottom: string;
93
+ paddingLeft: string;
85
94
  brightness: string;
86
95
  filters: string;
87
96
  sepia: string;
@@ -266,7 +275,13 @@ export declare const getTranslations: () => {
266
275
  listFormat: string;
267
276
  colorPicker: {
268
277
  solid: string;
278
+ gradient: string;
279
+ gradientType: string;
269
280
  linear: string;
281
+ radial: string;
282
+ center: string;
283
+ centerX: string;
284
+ centerY: string;
270
285
  angle: string;
271
286
  stops: string;
272
287
  stop: string;
package/utils/l10n.js CHANGED
@@ -1 +1 @@
1
- import{observable as e,action as o,toJS as a}from"mobx";const r=e({variables:{title:"Variables",element:"Selected element",name:"Variable name",label:"Label",add:"Add variable",required:"Required",default:"Default",enterValue:"Enter a value",empty:"Add a variable, then insert it into text or link it to a selected element.",settings:"Settings",delete:"Delete variable",yes:"Yes",no:"No",insert:"Insert variable",search:"Search or add a variable",noMatch:"No matching variables",nameRule:"Use letters, digits, _ and dots",nameTaken:"Already exists",visible:"Visible",src:"Source",fill:"Color",unbound:"Not linked",always:"Always",fit:"Scale",manual:"Crop",cover:"Fill",contain:"Fit",focus:"Focus",orphan:"Unused","mixed-types":"Mixed types"},imageEdit:{title:"AI edit",expand:"Expand",upscale:"Upscale",inpaint:"Generative fill",replace:"Replace",remove:"Remove",prompt:"Your prompt",promptPlaceholder:"Describe what should be there",expandPromptPlaceholder:"Describe the new area (optional)",replaceDescription:"Select an area on the image, then describe what you want to change.",replaceHint:"Describe what should replace the selection, such as “plain wall” or “open sky”.",removeDescription:"Select an object to remove. The surrounding image will fill the selected area.",expandDescription:"Drag the frame beyond the image edges to make room for new content.",cropDescription:"Drag the frame to crop the image.",upscaleDescription:"Increase the image resolution.",removeBackgroundDescription:"Remove the image background.",applyCrop:"Apply crop",generate:"Generate",clear:"Clear selection",resetFrame:"Reset frame",processing:"Generating…",loadingImage:"Loading image…",upscaling:"Upscaling…",removingBackground:"Removing background…",failed:"The image could not be edited. Please try again.",rasterFailed:"This device could not prepare the image. Try a smaller image.",selectRegion:"Drag on the image to select an area."},toolbar:{duration:"Duration",opacity:"Opacity",effects:"Effects",blur:"Blur",curvedText:"Curved text",curvePower:"Power",temperature:"Temperature",saturation:"Saturation",contrast:"Contrast",shadows:"Shadows",white:"White",black:"Black",vibrance:"Vibrance",textBackground:"Background",textBox:"Text box",backgroundCornerRadius:"Corner radius",backgroundOpacity:"Opacity",backgroundPadding:"Padding",brightness:"Brightness",filters:"Filters",sepia:"Sepia",grayscale:"Grayscale",cold:"Cold",natural:"Natural",warm:"Warm",textStroke:"Text Stroke",textEffect:{none:"None",shadow:"Shadow",lift:"Lift",glow:"Glow",outline:"Outline",sticker:"Sticker",pop:"Pop",background:"Background"},blendMode:"Blending",blend:{"pass-through":"Pass Through",normal:"Normal",multiply:"Multiply",screen:"Screen",overlay:"Overlay",darken:"Darken",lighten:"Lighten","color-dodge":"Color Dodge","color-burn":"Color Burn","hard-light":"Hard Light","soft-light":"Soft Light",difference:"Difference",exclusion:"Exclusion",hue:"Hue",saturation:"Saturation",color:"Color",luminosity:"Luminosity"},strokeLineJoin:"Corners",joinRound:"Round",joinMiter:"Miter",joinBevel:"Bevel",shadow:"Drop shadow",border:"Border",cornerRadius:"Corner Radius",copyStyle:"Copy style",uppercase:"Uppercase",position:"Position",layering:"Layering",toForward:"To Front",up:"Forward",down:"Backward",toBottom:"To back",alignLeft:"Align left",alignCenter:"Align center",alignRight:"Align right",alignTop:"Align top",alignMiddle:"Align middle",alignBottom:"Align bottom",flip:"Flip",flipHorizontally:"Flip horizontally",flipVertically:"Flip vertically",fitToBackground:"Fit to page",fitToPage:"Fit to page",widthShort:"W",heightShort:"H",removeBackground:"Remove background",removeBackgroundTitle:"Remove background from image",cancelRemoveBackground:"Cancel",confirmRemoveBackground:"Confirm",crop:"Crop",cropDone:"Done",cropCancel:"Cancel",clip:"Apply mask",removeClip:"Remove mask",removeMask:"Remove mask",transparency:"Transparency",lockedDescription:"Object is locked. Unlock it to allow changes from canvas.",unlockedDescription:"Object is unlocked. Lock it to prevent changes from canvas.",removeElements:"Remove elements",duplicateElements:"Duplicate elements",download:"Download",saveAsImage:"Save as image",saveAsPDF:"Save as PDF",lineHeight:"Line height",letterSpacing:"Letter spacing",offsetX:"Offset X",offsetY:"Offset Y",color:"Color",selectable:"Selectable",draggable:"Draggable",removable:"Removable",resizable:"Resizable",contentEditable:"Can change content",styleEditable:"Can change style",alwaysOnTop:"Always on top",showInExport:"Show in export",ungroupElements:"Ungroup",groupElements:"Group",lineSize:"Line size",fade:"Fade",move:"Move",zoom:"Zoom",animate:"Animate",rotate:"Rotate",none:"None",bounce:"Bounce",blink:"Blink",count:"Count",pop:"Pop",rise:"Rise",flipAnimation:"Flip",growTurn:"Grow & turn",spinAnimation:"Spin",pulse:"Pulse",float:"Float",shake:"Shake",typewriter:"Typewriter",lineRise:"Line rise",wordRise:"Word rise",wordFade:"Word fade",letterPop:"Letter pop",wordBlur:"Word blur",wipe:"Wipe",glow:"Glow",lineWipe:"Line wipe",linePeek:"Line peek",letterWave:"Letter wave",kenBurns:"Ken Burns",strength:"Strength",spaceEvenly:"Space evenly",horizontalDistribution:"Horizontally",verticalDistribution:"Vertically",strokeWidth:"Stroke Width",strokeSettings:"Stroke settings",spacing:"Spacing",volume:"Volume",speed:"Speed",seconds:"sec",lineStyle:"Line style",lineStartHead:"Line start",lineEndHead:"Line end",textDirection:"Text direction",fontSize:"Font size",fontFamily:"Font family",fontFamilyMixed:"Mixed",fontsInSelection:"Fonts in selection",textAlign:"Text align",verticalAlign:"Vertical align",bold:"Bold",italic:"Italic",underline:"Underline",strikethrough:"Strikethrough",cellBackground:"Cell background",tableBorderSettings:"Border settings",tableBorderColor:"Border color",tableBorderWidth:"Border width",tableBorderStyle:"Border style",borderModeAll:"All borders",borderModeOuter:"Outer borders",borderModeInner:"Inner borders",borderModeBottomOnly:"Bottom only",borderModeTopOnly:"Top only",borderModeLeftOnly:"Left only",borderModeRightOnly:"Right only",borderModeInnerHorizontal:"Inner horizontal",borderModeInnerVertical:"Inner vertical",tableStructure:"Table structure",tableRows:"Rows",tableColumns:"Columns",insertRowAbove:"Insert row above",insertRowBelow:"Insert row below",deleteRow:"Delete row",insertColumnLeft:"Insert column left",insertColumnRight:"Insert column right",deleteColumn:"Delete column",deleteRows:"Delete rows",deleteColumns:"Delete columns",distributeRowsEvenly:"Distribute rows evenly",distributeColumnsEvenly:"Distribute columns evenly",cellPadding:"Cell padding",listFormat:"List",colorPicker:{solid:"Solid",linear:"Linear",angle:"Angle",stops:"Gradient stops",stop:"Stop",addStop:"Add stop",removeStop:"Remove stop",reverse:"Reverse gradient",colors:"Colors",resetColors:"Reset",recolorAll:"Recolor all"},clipFade:{title:"Fade",preparing:"Preparing mask…",shape:"Shape",linear:"Linear",radial:"Radial",stopOpacity:"Stop opacity",stops:"Fade stops",stop:"Stop",start:"Fade start",end:"Fade end",center:"Fade center",radius:"Fade radius",reverse:"Reverse",removeStop:"Remove stop",addStop:"Add stop",reset:"Reset",hint:"Drag the handles on the image to position the fade."},aiText:{aiWrite:"AI write",rewrite:"Rewrite",shorten:"Shorten",continue:"Continue writing",proofread:"Proofread",tones:"Tones",friendly:"Friendly",professional:"Professional",humorous:"Humorous",formal:"Formal",customPrompt:"Custom prompt",generatedResult:"Generated result",cancel:"Cancel",generate:"Generate",back:"Back",tryAgain:"Try Again",insert:"Insert",promptPlaceholder:"Describe what you want to generate"}},workspace:{noPages:"There are no pages yet...",addPage:"Add page",removePage:"Remove page",duplicatePage:"Duplicate page",moveUp:"Move up",moveDown:"Move down",moveLeft:"Move left",moveRight:"Move right"},scale:{reset:"Reset"},error:{removeBackground:"Ops! Something went wrong. Background can not be removed."},sidePanel:{close:"Close",templates:"Templates",searchTemplatesWithSameSize:"Show templates with the same size",searchPlaceholder:"Search...",otherFormats:"Other formats",noResults:"No results",error:"Loading is failed...",text:"Text",uploadFont:"Upload font",myFonts:"My fonts",photos:"Photos",videos:"Videos",animations:"Animations",effects:"Effects",elements:"Elements",shapes:"Shapes",tables:"Tables",lines:"Lines",draw:"Draw",drawTool:"Tool",drawSelection:"Selection",drawBrush:"Brush",drawHighlighter:"Highlighter",upload:"Upload",uploadImage:"Add file",uploadTip:"Upload your assets",uploadUnsupported:"Skipped some files. You can add images, video, audio and Lottie animations.",uploadFailed:"Upload failed. Please try again.",background:"Background",resize:"Resize",layers:"Layers",animate:"Animate",animationEnter:"Enter",animationBoth:"Both",animationExit:"Exit",animationLoop:"Loop",animationGeneral:"General",animationTextPresets:"Text",animationDuration:"Duration (s)",animationRepeatEvery:"Repeat every (s)",animationStartAt:"Start at (s)",animationEndAt:"End at (s)",animationDirection:"Direction",animationDirections:{right:"Right",left:"Left",up:"Up",down:"Down","bottom-right":"Bottom right","bottom-left":"Bottom left","top-right":"Top right","top-left":"Top left",none:"None"},zoomIn:"Zoom In",zoomOut:"Zoom Out",layerTypes:{image:"Image",text:"Text",svg:"SVG",line:"Line",figure:"Figure",group:"Group"},layersTip:"Elements on your active page:",noLayers:"No elements on the page...",namePlaceholder:"Type element name...",useMagicResize:"Use magic resize",advanced:"Advanced",bleed:"Bleed",showBleed:"Show bleed",clipImage:"Mask image",width:"Width",height:"Height",units:"Units",magicResizeDescription:"Magic resize will automatically resize and move all elements on the canvas",headerText:"Header",createHeader:"Create header",subHeaderText:"Sub Header",createSubHeader:"Create sub header",bodyText:"Body text",createBody:"Create body text"},pagesTimeline:{pages:"Pages",removePage:"Remove page",addPage:"Add page",duplicatePage:"Duplicate page",removeAudio:"Remove audio",duplicateAudio:"Duplicate audio",renameAudio:"Rename audio",muteAudio:"Mute",unmuteAudio:"Unmute",volume:"Volume",speed:"Speed",rewind:"Rewind to start",editAsVideo:"Edit as video",editAsVideoHint:"On: preview the frame at the playhead — timed elements hide outside their range. Off: show all elements while editing."},contextMenu:{duplicate:"Duplicate",split:"Split at playhead",rename:"Rename",remove:"Remove",lock:"Lock",unlock:"Unlock",copy:"Copy",paste:"Paste",copyStyle:"Copy style",moveUp:"Move up",moveDown:"Move down",moveBack:"Move back",moveForward:"Move forward"}}),n=e=>e&&"object"==typeof e;function i(e,o){Object.keys(o).forEach(a=>{const r=e[a],l=o[a];n(l)&&n(r)?i(r,l):e[a]=l})}function l(e,o,a=""){Object.keys(o).forEach(r=>{const i=o[r],s=a?`${a}.${r}`:r;n(i)?n(e[r])?l(e[r],i,s):console.warn(`Missing nested translation object at '${s}'`):void 0===e[r]&&console.warn(`Missing translation '${s}'`)})}export const setTranslations=o((e,{validate:o=!1}={})=>{o&&l(e,r),i(r,e)});export const getTranslations=()=>a(r);const s={};export const t=e=>{const o=function(e,o){var a,r=o.split("."),n=e;for(a=0;a<r.length;++a){if(null==n[r[a]]){return}n=n[r[a]]}return n}(r,e);if(void 0!==o){return o}s[e]||(s[e]=!0,console.warn(`Missing translation '${e}'`));const a=e.split("."),n=a[a.length-1]||" ";return n.charAt(0).toUpperCase()+n.slice(1)};
1
+ import{observable as e,action as o,toJS as a}from"mobx";const r=e({variables:{title:"Variables",element:"Selected element",name:"Variable name",label:"Label",add:"Add variable",required:"Required",default:"Default",enterValue:"Enter a value",empty:"Add a variable, then insert it into text or link it to a selected element.",settings:"Settings",delete:"Delete variable",yes:"Yes",no:"No",insert:"Insert variable",search:"Search or add a variable",noMatch:"No matching variables",nameRule:"Use letters, digits, _ and dots",nameTaken:"Already exists",visible:"Visible",src:"Source",fill:"Color",unbound:"Not linked",always:"Always",fit:"Scale",manual:"Crop",cover:"Fill",contain:"Fit",focus:"Focus",orphan:"Unused","mixed-types":"Mixed types"},imageEdit:{title:"AI edit",expand:"Expand",upscale:"Upscale",inpaint:"Generative fill",replace:"Replace",remove:"Remove",prompt:"Your prompt",promptPlaceholder:"Describe what should be there",expandPromptPlaceholder:"Describe the new area (optional)",replaceDescription:"Select an area on the image, then describe what you want to change.",replaceHint:"Describe what should replace the selection, such as “plain wall” or “open sky”.",removeDescription:"Select an object to remove. The surrounding image will fill the selected area.",expandDescription:"Drag the frame beyond the image edges to make room for new content.",cropDescription:"Drag the frame to crop the image.",upscaleDescription:"Increase the image resolution.",removeBackgroundDescription:"Remove the image background.",applyCrop:"Apply crop",generate:"Generate",clear:"Clear selection",resetFrame:"Reset frame",processing:"Generating…",loadingImage:"Loading image…",upscaling:"Upscaling…",removingBackground:"Removing background…",failed:"The image could not be edited. Please try again.",rasterFailed:"This device could not prepare the image. Try a smaller image.",selectRegion:"Drag on the image to select an area."},toolbar:{duration:"Duration",opacity:"Opacity",effects:"Effects",blur:"Blur",curvedText:"Curved text",curvePower:"Power",temperature:"Temperature",saturation:"Saturation",contrast:"Contrast",shadows:"Shadows",white:"White",black:"Black",vibrance:"Vibrance",textBackground:"Background",backgroundCornerRadius:"Corner radius",backgroundOpacity:"Opacity",backgroundPadding:"Spread",backgroundShape:"Shape",backgroundFill:"Fill",backgroundShapeLines:"Lines",backgroundShapeBox:"Box",textPadding:"Padding",paddingSides:"Independent sides",paddingTop:"Top",paddingRight:"Right",paddingBottom:"Bottom",paddingLeft:"Left",brightness:"Brightness",filters:"Filters",sepia:"Sepia",grayscale:"Grayscale",cold:"Cold",natural:"Natural",warm:"Warm",textStroke:"Text Stroke",textEffect:{none:"None",shadow:"Shadow",lift:"Lift",glow:"Glow",outline:"Outline",sticker:"Sticker",pop:"Pop",background:"Background"},blendMode:"Blending",blend:{"pass-through":"Pass Through",normal:"Normal",multiply:"Multiply",screen:"Screen",overlay:"Overlay",darken:"Darken",lighten:"Lighten","color-dodge":"Color Dodge","color-burn":"Color Burn","hard-light":"Hard Light","soft-light":"Soft Light",difference:"Difference",exclusion:"Exclusion",hue:"Hue",saturation:"Saturation",color:"Color",luminosity:"Luminosity"},strokeLineJoin:"Corners",joinRound:"Round",joinMiter:"Miter",joinBevel:"Bevel",shadow:"Drop shadow",border:"Border",cornerRadius:"Corner Radius",copyStyle:"Copy style",uppercase:"Uppercase",position:"Position",layering:"Layering",toForward:"To Front",up:"Forward",down:"Backward",toBottom:"To back",alignLeft:"Align left",alignCenter:"Align center",alignRight:"Align right",alignTop:"Align top",alignMiddle:"Align middle",alignBottom:"Align bottom",flip:"Flip",flipHorizontally:"Flip horizontally",flipVertically:"Flip vertically",fitToBackground:"Fit to page",fitToPage:"Fit to page",widthShort:"W",heightShort:"H",removeBackground:"Remove background",removeBackgroundTitle:"Remove background from image",cancelRemoveBackground:"Cancel",confirmRemoveBackground:"Confirm",crop:"Crop",cropDone:"Done",cropCancel:"Cancel",clip:"Apply mask",removeClip:"Remove mask",removeMask:"Remove mask",transparency:"Transparency",lockedDescription:"Object is locked. Unlock it to allow changes from canvas.",unlockedDescription:"Object is unlocked. Lock it to prevent changes from canvas.",removeElements:"Remove elements",duplicateElements:"Duplicate elements",download:"Download",saveAsImage:"Save as image",saveAsPDF:"Save as PDF",lineHeight:"Line height",letterSpacing:"Letter spacing",offsetX:"Offset X",offsetY:"Offset Y",color:"Color",selectable:"Selectable",draggable:"Draggable",removable:"Removable",resizable:"Resizable",contentEditable:"Can change content",styleEditable:"Can change style",alwaysOnTop:"Always on top",showInExport:"Show in export",ungroupElements:"Ungroup",groupElements:"Group",lineSize:"Line size",fade:"Fade",move:"Move",zoom:"Zoom",animate:"Animate",rotate:"Rotate",none:"None",bounce:"Bounce",blink:"Blink",count:"Count",pop:"Pop",rise:"Rise",flipAnimation:"Flip",growTurn:"Grow & turn",spinAnimation:"Spin",pulse:"Pulse",float:"Float",shake:"Shake",typewriter:"Typewriter",lineRise:"Line rise",wordRise:"Word rise",wordFade:"Word fade",letterPop:"Letter pop",wordBlur:"Word blur",wipe:"Wipe",glow:"Glow",lineWipe:"Line wipe",linePeek:"Line peek",letterWave:"Letter wave",kenBurns:"Ken Burns",strength:"Strength",spaceEvenly:"Space evenly",horizontalDistribution:"Horizontally",verticalDistribution:"Vertically",strokeWidth:"Stroke Width",strokeSettings:"Stroke settings",spacing:"Spacing",volume:"Volume",speed:"Speed",seconds:"sec",lineStyle:"Line style",lineStartHead:"Line start",lineEndHead:"Line end",textDirection:"Text direction",fontSize:"Font size",fontFamily:"Font family",fontFamilyMixed:"Mixed",fontsInSelection:"Fonts in selection",textAlign:"Text align",verticalAlign:"Vertical align",bold:"Bold",italic:"Italic",underline:"Underline",strikethrough:"Strikethrough",cellBackground:"Cell background",tableBorderSettings:"Border settings",tableBorderColor:"Border color",tableBorderWidth:"Border width",tableBorderStyle:"Border style",borderModeAll:"All borders",borderModeOuter:"Outer borders",borderModeInner:"Inner borders",borderModeBottomOnly:"Bottom only",borderModeTopOnly:"Top only",borderModeLeftOnly:"Left only",borderModeRightOnly:"Right only",borderModeInnerHorizontal:"Inner horizontal",borderModeInnerVertical:"Inner vertical",tableStructure:"Table structure",tableRows:"Rows",tableColumns:"Columns",insertRowAbove:"Insert row above",insertRowBelow:"Insert row below",deleteRow:"Delete row",insertColumnLeft:"Insert column left",insertColumnRight:"Insert column right",deleteColumn:"Delete column",deleteRows:"Delete rows",deleteColumns:"Delete columns",distributeRowsEvenly:"Distribute rows evenly",distributeColumnsEvenly:"Distribute columns evenly",cellPadding:"Cell padding",listFormat:"List",colorPicker:{solid:"Solid",gradient:"Gradient",gradientType:"Gradient type",linear:"Linear",radial:"Radial",center:"Gradient center",centerX:"Center X",centerY:"Center Y",angle:"Angle",stops:"Gradient stops",stop:"Stop",addStop:"Add stop",removeStop:"Remove stop",reverse:"Reverse gradient",colors:"Colors",resetColors:"Reset",recolorAll:"Recolor all"},clipFade:{title:"Fade",preparing:"Preparing mask…",shape:"Shape",linear:"Linear",radial:"Radial",stopOpacity:"Stop opacity",stops:"Fade stops",stop:"Stop",start:"Fade start",end:"Fade end",center:"Fade center",radius:"Fade radius",reverse:"Reverse",removeStop:"Remove stop",addStop:"Add stop",reset:"Reset",hint:"Drag the handles on the image to position the fade."},aiText:{aiWrite:"AI write",rewrite:"Rewrite",shorten:"Shorten",continue:"Continue writing",proofread:"Proofread",tones:"Tones",friendly:"Friendly",professional:"Professional",humorous:"Humorous",formal:"Formal",customPrompt:"Custom prompt",generatedResult:"Generated result",cancel:"Cancel",generate:"Generate",back:"Back",tryAgain:"Try Again",insert:"Insert",promptPlaceholder:"Describe what you want to generate"}},workspace:{noPages:"There are no pages yet...",addPage:"Add page",removePage:"Remove page",duplicatePage:"Duplicate page",moveUp:"Move up",moveDown:"Move down",moveLeft:"Move left",moveRight:"Move right"},scale:{reset:"Reset"},error:{removeBackground:"Ops! Something went wrong. Background can not be removed."},sidePanel:{close:"Close",templates:"Templates",searchTemplatesWithSameSize:"Show templates with the same size",searchPlaceholder:"Search...",otherFormats:"Other formats",noResults:"No results",error:"Loading is failed...",text:"Text",uploadFont:"Upload font",myFonts:"My fonts",photos:"Photos",videos:"Videos",animations:"Animations",effects:"Effects",elements:"Elements",shapes:"Shapes",tables:"Tables",lines:"Lines",draw:"Draw",drawTool:"Tool",drawSelection:"Selection",drawBrush:"Brush",drawHighlighter:"Highlighter",upload:"Upload",uploadImage:"Add file",uploadTip:"Upload your assets",uploadUnsupported:"Skipped some files. You can add images, video, audio and Lottie animations.",uploadFailed:"Upload failed. Please try again.",background:"Background",resize:"Resize",layers:"Layers",animate:"Animate",animationEnter:"Enter",animationBoth:"Both",animationExit:"Exit",animationLoop:"Loop",animationGeneral:"General",animationTextPresets:"Text",animationDuration:"Duration (s)",animationRepeatEvery:"Repeat every (s)",animationStartAt:"Start at (s)",animationEndAt:"End at (s)",animationDirection:"Direction",animationDirections:{right:"Right",left:"Left",up:"Up",down:"Down","bottom-right":"Bottom right","bottom-left":"Bottom left","top-right":"Top right","top-left":"Top left",none:"None"},zoomIn:"Zoom In",zoomOut:"Zoom Out",layerTypes:{image:"Image",text:"Text",svg:"SVG",line:"Line",figure:"Figure",group:"Group"},layersTip:"Elements on your active page:",noLayers:"No elements on the page...",namePlaceholder:"Type element name...",useMagicResize:"Use magic resize",advanced:"Advanced",bleed:"Bleed",showBleed:"Show bleed",clipImage:"Mask image",width:"Width",height:"Height",units:"Units",magicResizeDescription:"Magic resize will automatically resize and move all elements on the canvas",headerText:"Header",createHeader:"Create header",subHeaderText:"Sub Header",createSubHeader:"Create sub header",bodyText:"Body text",createBody:"Create body text"},pagesTimeline:{pages:"Pages",removePage:"Remove page",addPage:"Add page",duplicatePage:"Duplicate page",removeAudio:"Remove audio",duplicateAudio:"Duplicate audio",renameAudio:"Rename audio",muteAudio:"Mute",unmuteAudio:"Unmute",volume:"Volume",speed:"Speed",rewind:"Rewind to start",editAsVideo:"Edit as video",editAsVideoHint:"On: preview the frame at the playhead — timed elements hide outside their range. Off: show all elements while editing."},contextMenu:{duplicate:"Duplicate",split:"Split at playhead",rename:"Rename",remove:"Remove",lock:"Lock",unlock:"Unlock",copy:"Copy",paste:"Paste",copyStyle:"Copy style",moveUp:"Move up",moveDown:"Move down",moveBack:"Move back",moveForward:"Move forward"}}),n=e=>e&&"object"==typeof e;function i(e,o){Object.keys(o).forEach(a=>{const r=e[a],l=o[a];n(l)&&n(r)?i(r,l):e[a]=l})}function l(e,o,a=""){Object.keys(o).forEach(r=>{const i=o[r],s=a?`${a}.${r}`:r;n(i)?n(e[r])?l(e[r],i,s):console.warn(`Missing nested translation object at '${s}'`):void 0===e[r]&&console.warn(`Missing translation '${s}'`)})}export const setTranslations=o((e,{validate:o=!1}={})=>{o&&l(e,r),i(r,e)});export const getTranslations=()=>a(r);const s={};export const t=e=>{const o=function(e,o){var a,r=o.split("."),n=e;for(a=0;a<r.length;++a){if(null==n[r[a]]){return}n=n[r[a]]}return n}(r,e);if(void 0!==o){return o}s[e]||(s[e]=!0,console.warn(`Missing translation '${e}'`));const a=e.split("."),n=a[a.length-1]||" ";return n.charAt(0).toUpperCase()+n.slice(1)};
@@ -4,6 +4,10 @@ export interface MeasureTextOptions {
4
4
  text: string;
5
5
  width: number;
6
6
  height?: number;
7
+ paddingTop?: number;
8
+ paddingRight?: number;
9
+ paddingBottom?: number;
10
+ paddingLeft?: number;
7
11
  textOverflow?: string;
8
12
  maxLines?: number;
9
13
  minFontSize?: number;
@@ -1 +1 @@
1
- import{removeTags as t}from"@polotno/core/text";import{applyTextDefaults as o}from"@polotno/core/text-types";import{curveLayoutAt as e}from"@polotno/core/curve-glyphs";import{layoutCurvedTextSizing as n,layoutTextSizing as i,renderTagLayoutAt as r}from"@polotno/core/text-sizing";import{editorTextSizing as l}from"./text-sizing.js";export async function measureText(a){var s;const u=o(a),m=Object.assign(Object.assign({},u),{height:null!==(s=a.height)&&void 0!==s?s:0}),c=l(m);if(u.curveEnabled){const{fontSize:o,layout:i,truncated:r}=n({element:m,sizing:c,layoutAt:e(m,{getHtmlOptions:{fontFamily:u.fontFamily}})}),l=i.bounds.height;return{height:l,fontSize:o,lines:[{text:t(u.text),top:0,height:l,paragraph:0}],lineCount:1,totalLineCount:1,truncated:r}}const g=i({element:m,sizing:c,layoutAt:r(m,{getHtmlOptions:{fontFamily:u.fontFamily,forEditor:!0}})});return{height:g.height,fontSize:g.fontSize,lines:g.lines,lineCount:g.lineCount,totalLineCount:g.totalLineCount,truncated:g.truncated}}
1
+ import{removeTags as t}from"@polotno/core/text";import{applyTextDefaults as o,textContentElement as e}from"@polotno/core/text-types";import{curveLayoutAt as n}from"@polotno/core/curve-glyphs";import{layoutCurvedTextSizing as i,layoutTextSizing as r,renderTagLayoutAt as l}from"@polotno/core/text-sizing";import{editorTextSizing as a}from"./text-sizing.js";export async function measureText(s){var u;const m=o(s),c=Object.assign(Object.assign({},m),{height:null!==(u=s.height)&&void 0!==u?u:0}),g=a(c);if(m.curveEnabled){const{fontSize:o,layout:e,truncated:r}=i({element:c,sizing:g,layoutAt:n(c,{getHtmlOptions:{fontFamily:m.fontFamily}})}),l=e.bounds.height;return{height:l,fontSize:o,lines:[{text:t(m.text),top:0,height:l,paragraph:0}],lineCount:1,totalLineCount:1,truncated:r}}const p=e(c),f=r({element:p,sizing:g,layoutAt:l(p,{getHtmlOptions:{fontFamily:m.fontFamily,forEditor:!0}})});return{height:f.height,fontSize:f.fontSize,lines:f.lines,lineCount:f.lineCount,totalLineCount:f.totalLineCount,truncated:f.truncated}}
package/utils/px.d.ts CHANGED
@@ -6,6 +6,10 @@ export declare const isCornerAnchor: (anchor: string) => boolean;
6
6
  export declare const isRotateAnchor: (anchor: string) => boolean;
7
7
  export declare const transformScale: (scale: number) => number;
8
8
  export declare const textMinResizeWidth: (startWidth: number, fontSize: number) => number;
9
+ type TextPaddingSource = Partial<Record<'paddingTop' | 'paddingRight' | 'paddingBottom' | 'paddingLeft', number>>;
10
+ export declare const paddedTextMinResizeWidth: (element: TextPaddingSource, startWidth: number, fontSize: number) => number;
11
+ export declare const scaledTextPaddingAttrs: (element: TextPaddingSource, scale: number) => TextPaddingSource;
12
+ export declare const roundedTextPaddingAttrs: (element: TextPaddingSource) => TextPaddingSource;
9
13
  export declare const textMinWidthIsMeasured: (element: {
10
14
  curveEnabled?: boolean;
11
15
  letterSpacing?: number;
package/utils/px.js CHANGED
@@ -1 +1 @@
1
- var t=this&&this.__rest||function(t,e){var o={};for(var r in t){Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(o[r]=t[r])}if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(r=Object.getOwnPropertySymbols(t);n<r.length;n++){e.indexOf(r[n])<0&&Object.prototype.propertyIsEnumerable.call(t,r[n])&&(o[r[n]]=t[r[n]])}}return o};import{htmlInflatesMinContentWidth as e,scaleRichTextFontSizesInHtml as o}from"./rich-text-html.js";export const roundEnabledPx=t=>t>0?Math.max(1,Math.round(t)):0;export const MAIN_TRANSFORMER_NAME="main-transformer";export const activeAnchorOf=t=>{var e,o;const r=null===(e=t.getStage())||void 0===e?void 0:e.findOne(".main-transformer");return null!==(o=null==r?void 0:r.getActiveAnchor())&&void 0!==o?o:""};export const isCornerAnchor=t=>!(t.includes("middle")||t.includes("center"));export const isRotateAnchor=t=>t.startsWith("rotater");export const transformScale=t=>Math.abs(t-1)<1e-7?1:t;export const textMinResizeWidth=(t,e)=>t<e?1:e;export const textMinWidthIsMeasured=t=>{var o;return!!t.curveEnabled||0!==(null!==(o=t.letterSpacing)&&void 0!==o?o:0)||e(t.text)};const r=(t,e)=>{var o;return{cornerRadius:(null!==(o=t.cornerRadius)&&void 0!==o?o:0)*e,shadowBlur:t.shadowBlur*e,shadowOffsetX:t.shadowOffsetX*e,shadowOffsetY:t.shadowOffsetY*e}},n=t=>{var e;return{cornerRadius:roundEnabledPx(null!==(e=t.cornerRadius)&&void 0!==e?e:0),shadowBlur:Math.round(t.shadowBlur),shadowOffsetX:Math.round(t.shadowOffsetX),shadowOffsetY:Math.round(t.shadowOffsetY)}};export const scaledFontSizeAttrs=(t,e)=>{const o=t.fontSize>0?e/t.fontSize:1;return{fontSize:e,strokeWidth:t.strokeWidth*o,borderSize:t.borderSize*o,shadowBlur:t.shadowBlur*o,shadowOffsetX:t.shadowOffsetX*o,shadowOffsetY:t.shadowOffsetY*o}};export const scaledFontSizeBounds=(t,e,o=!1)=>{const r=t=>{if(1===e){return t}const r=t*e;return o?Math.round(r):r},n={};return void 0!==t.minFontSize&&(n.minFontSize=r(t.minFontSize)),void 0!==t.maxFontSize&&(n.maxFontSize=r(t.maxFontSize)),n};export const roundedGeometryPx=t=>Math.round(1e6*t)/1e6+0;export const roundedCropFraction=t=>Math.round(1e9*t)/1e9+0;export const roundedPosition=t=>({x:roundedGeometryPx(t.x()),y:roundedGeometryPx(t.y())});export const roundedGeometryAttrs=t=>({x:roundedGeometryPx(t.x),y:roundedGeometryPx(t.y),width:roundedGeometryPx(t.width),height:roundedGeometryPx(t.height),rotation:roundedGeometryPx(t.rotation)});export const roundedFontSizeAttrs=(t,e)=>{const o=scaledFontSizeAttrs(t,e);return{fontSize:Math.round(o.fontSize),strokeWidth:roundEnabledPx(o.strokeWidth),borderSize:roundEnabledPx(o.borderSize),shadowBlur:Math.round(o.shadowBlur),shadowOffsetX:Math.round(o.shadowOffsetX),shadowOffsetY:Math.round(o.shadowOffsetY)}};const s=["image","svg","gif","lottie","video"];export const isMedia=t=>s.includes(t);export const scaledStyleAttrs=(t,e)=>{const n=t;return"text"===n.type?Object.assign(Object.assign({},scaledFontSizeAttrs(n,n.fontSize*e)),{text:o(n.text,e)}):"figure"===n.type?Object.assign(Object.assign({},r(n,e)),{strokeWidth:n.strokeWidth*e}):isMedia(n.type)?Object.assign(Object.assign({},r(n,e)),{borderSize:n.borderSize*e}):{}};export const roundedStyleAttrs=t=>{const e=t;return"text"===e.type?roundedFontSizeAttrs(e,e.fontSize):"figure"===e.type?Object.assign(Object.assign({},n(e)),{strokeWidth:roundEnabledPx(e.strokeWidth)}):isMedia(e.type)?Object.assign(Object.assign({},n(e)),{borderSize:roundEnabledPx(e.borderSize)}):{}};export const roundedTextDecorationAttrs=e=>{const o=roundedFontSizeAttrs(e,e.fontSize),{fontSize:r}=o;return t(o,["fontSize"])};
1
+ var t=this&&this.__rest||function(t,e){var o={};for(var r in t){Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(o[r]=t[r])}if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(r=Object.getOwnPropertySymbols(t);n<r.length;n++){e.indexOf(r[n])<0&&Object.prototype.propertyIsEnumerable.call(t,r[n])&&(o[r[n]]=t[r[n]])}}return o};import{textPadding as e}from"@polotno/core/text-types";import{htmlInflatesMinContentWidth as o,scaleRichTextFontSizesInHtml as r}from"./rich-text-html.js";export const roundEnabledPx=t=>t>0?Math.max(1,Math.round(t)):0;export const MAIN_TRANSFORMER_NAME="main-transformer";export const activeAnchorOf=t=>{var e,o;const r=null===(e=t.getStage())||void 0===e?void 0:e.findOne(".main-transformer");return null!==(o=null==r?void 0:r.getActiveAnchor())&&void 0!==o?o:""};export const isCornerAnchor=t=>!(t.includes("middle")||t.includes("center"));export const isRotateAnchor=t=>t.startsWith("rotater");export const transformScale=t=>Math.abs(t-1)<1e-7?1:t;export const textMinResizeWidth=(t,e)=>t<e?1:e;export const paddedTextMinResizeWidth=(t,o,r)=>{const{left:n,right:s}=e(t),d=n+s;return textMinResizeWidth(o-d,r)+d};const n=["paddingTop","paddingRight","paddingBottom","paddingLeft"];export const scaledTextPaddingAttrs=(t,e)=>{const o={};for(const r of n){const n=t[r];"number"==typeof n&&(o[r]=n*e)}return o};export const roundedTextPaddingAttrs=t=>{const e={};for(const o of n){const r=t[o];"number"==typeof r&&(e[o]=Math.round(r))}return e};export const textMinWidthIsMeasured=t=>{var e;return!!t.curveEnabled||0!==(null!==(e=t.letterSpacing)&&void 0!==e?e:0)||o(t.text)};const s=(t,e)=>{var o;return{cornerRadius:(null!==(o=t.cornerRadius)&&void 0!==o?o:0)*e,shadowBlur:t.shadowBlur*e,shadowOffsetX:t.shadowOffsetX*e,shadowOffsetY:t.shadowOffsetY*e}},d=t=>{var e;return{cornerRadius:roundEnabledPx(null!==(e=t.cornerRadius)&&void 0!==e?e:0),shadowBlur:Math.round(t.shadowBlur),shadowOffsetX:Math.round(t.shadowOffsetX),shadowOffsetY:Math.round(t.shadowOffsetY)}};export const scaledFontSizeAttrs=(t,e)=>{const o=t.fontSize>0?e/t.fontSize:1;return{fontSize:e,strokeWidth:t.strokeWidth*o,borderSize:t.borderSize*o,shadowBlur:t.shadowBlur*o,shadowOffsetX:t.shadowOffsetX*o,shadowOffsetY:t.shadowOffsetY*o}};export const scaledFontSizeBounds=(t,e,o=!1)=>{const r=t=>{if(1===e){return t}const r=t*e;return o?Math.round(r):r},n={};return void 0!==t.minFontSize&&(n.minFontSize=r(t.minFontSize)),void 0!==t.maxFontSize&&(n.maxFontSize=r(t.maxFontSize)),n};export const roundedGeometryPx=t=>Math.round(1e6*t)/1e6+0;export const roundedCropFraction=t=>Math.round(1e9*t)/1e9+0;export const roundedPosition=t=>({x:roundedGeometryPx(t.x()),y:roundedGeometryPx(t.y())});export const roundedGeometryAttrs=t=>({x:roundedGeometryPx(t.x),y:roundedGeometryPx(t.y),width:roundedGeometryPx(t.width),height:roundedGeometryPx(t.height),rotation:roundedGeometryPx(t.rotation)});export const roundedFontSizeAttrs=(t,e)=>{const o=scaledFontSizeAttrs(t,e);return{fontSize:Math.round(o.fontSize),strokeWidth:roundEnabledPx(o.strokeWidth),borderSize:roundEnabledPx(o.borderSize),shadowBlur:Math.round(o.shadowBlur),shadowOffsetX:Math.round(o.shadowOffsetX),shadowOffsetY:Math.round(o.shadowOffsetY)}};const i=["image","svg","gif","lottie","video"];export const isMedia=t=>i.includes(t);export const scaledStyleAttrs=(t,e)=>{const o=t;return"text"===o.type?Object.assign(Object.assign(Object.assign({},scaledFontSizeAttrs(o,o.fontSize*e)),scaledTextPaddingAttrs(o,e)),{text:r(o.text,e)}):"figure"===o.type?Object.assign(Object.assign({},s(o,e)),{strokeWidth:o.strokeWidth*e}):isMedia(o.type)?Object.assign(Object.assign({},s(o,e)),{borderSize:o.borderSize*e}):{}};export const roundedStyleAttrs=t=>{const e=t;return"text"===e.type?Object.assign(Object.assign({},roundedFontSizeAttrs(e,e.fontSize)),roundedTextPaddingAttrs(e)):"figure"===e.type?Object.assign(Object.assign({},d(e)),{strokeWidth:roundEnabledPx(e.strokeWidth)}):isMedia(e.type)?Object.assign(Object.assign({},d(e)),{borderSize:roundEnabledPx(e.borderSize)}):{}};export const roundedTextDecorationAttrs=e=>{const o=roundedFontSizeAttrs(e,e.fontSize),{fontSize:r}=o;return t(o,["fontSize"])};
@@ -5,6 +5,7 @@ export declare function detachNativeColorsInHtml(html: string): string;
5
5
  export declare function attachNativeColorsInHtml(html: string): string;
6
6
  export declare function scaleRichTextFontSizesInHtml(html: string, factor: number): string;
7
7
  export declare function htmlInflatesMinContentWidth(html: string): boolean;
8
+ export declare const VARIABLE_TOKEN_CLASS = "polotno-variable-token";
8
9
  export declare function quillHtmlToModelText(html: string, defaults: {
9
10
  fontSize: number;
10
11
  fontFamily: string;
@@ -1 +1 @@
1
- export*from"@polotno/core/rich-text-html";import{hasMarkup as t,parseHtmlRoot as e,cleanupInlineWrappers as r,extractFontFamiliesFromHtml as o,normalizeRichTextHtml as n,scaleRichTextFontSizesInHtml as i}from"@polotno/core/rich-text-html";import{containsCmykColor as l,isCmykColor as s,toDisplayColor as c}from"@polotno/core/color";import{buildStyleAttribute as u,mapStyleAttributes as f,parseStyleAttribute as a,stripPriority as p,styleAttributeRanges as y}from"@polotno/core/style-attribute";import{sameColors as d}from"@polotno/core/svg";import{isGradient as m,parseColor as b}from"@polotno/core/gradient";import{LRUCache as v}from"./lru-cache.js";const h="data-native-";export function nativeColorAttribute(t){return h+t}const g=t=>s(t)||m(t)&&l(t);export function readNativeColor(t,e){var r;const o=t.getAttribute(nativeColorAttribute(e));if(null!==o){const n=null===(r=t.style)||void 0===r?void 0:r.getPropertyValue(e);return g(o)&&n&&function(t,e,r){const o=c(r);if(!m(o)){return d(e,o)}const n=function(t,e){if("undefined"==typeof document){return null}const r=document.createElement("span");return r.style.setProperty(t,e),r.style.getPropertyValue(t)||null}(t,o);if(null!==n){return n===e}if(!m(e)){return!1}const i=b(e),l=b(o);return i.rotation===l.rotation&&i.stops.length===l.stops.length&&i.stops.every((t,e)=>Math.abs(t.offset-l.stops[e].offset)<.001&&d(t.color,l.stops[e].color))}(e,n,o)?o:""}const n=a(t.getAttribute("style"))[e];return n&&g(n)?n:""}export function detachNativeColorsInHtml(t){if(!l(t)){return t}const r=e(t);return r?(function(t){for(const e of Array.from(t.querySelectorAll("[style]"))){const t=e.getAttribute("style");if(!l(t)){continue}const r=a(t);for(const[o,n]of Object.entries(r)){g(n)&&(e.setAttribute(nativeColorAttribute(o),n),r[o]=c(n))}e.setAttribute("style",u(r))}}(r),r.innerHTML):t}export function attachNativeColorsInHtml(t){if(!t||!t.includes(h)){return t}const o=e(t);if(!o){return t}let n=!1;for(const e of Array.from(o.querySelectorAll("*"))){for(const{name:t}of Array.from(e.attributes)){if(!t.startsWith(h)){continue}const r=t.slice(12),o=readNativeColor(e,r);if(e.removeAttribute(t),!o){n=!0;continue}const i=a(e.getAttribute("style"));i[r]=o,e.setAttribute("style",u(i))}}return n&&r(o),o.innerHTML}function x(t,e){if(!l(t)){return e(t)}const r=detachNativeColorsInHtml(t),o=e(r);return o===r?t:attachNativeColorsInHtml(o)}export function scaleRichTextFontSizesInHtml(t,e){return x(t,t=>i(t,e))}const A=new v(500);export function htmlInflatesMinContentWidth(t){if(!t||!t.includes("<")){return!1}let r=A.get(t);if(void 0===r){r=!1;const o=e(t);if(o){if(o.querySelector("ol, ul")){r=!0}else{for(const t of o.querySelectorAll("[style]")){if(t.style.fontSize||t.style.letterSpacing){r=!0;break}}}}A.set(t,r)}return r}export function quillHtmlToModelText(t,e){return attachNativeColorsInHtml(n(function(t){const e=(t||"").trim();if("<p><br></p>"===e||"<p></p>"===e){return""}if(e.startsWith("<p>")&&e.endsWith("</p>")){const t=e.slice(3,-4);if(!/(<\/?(p|div|h[1-6]|ul|ol|li|table|thead|tbody|tr|td|blockquote)\b)/i.test(t)){return t}}return t}(t),e))}export function shrinkParagraphStrutForRaster(t){var r;if(!t||!t.includes("<p")){return t}const o=e(t);if(!o){return t}for(const e of Array.from(o.querySelectorAll("p"))){let t=!1;const n=[],i=o.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_TEXT);let l=i.nextNode();for(;l;){if((l.textContent||"").length>0){let o=l.parentElement,i=null;for(;o&&o!==e;){const t=null===(r=o.style)||void 0===r?void 0:r.fontSize;if(t){const e=parseFloat(t);if(!Number.isNaN(e)){i=e;break}}o=o.parentElement}if(null==i){t=!0;break}n.push(i)}l=i.nextNode()}!t&&n.length>0&&(e.style.fontSize=`${Math.min(...n)}px`)}return o.innerHTML}const S={bold:["STRONG","B"],italic:["EM","I"],underline:["U"],strike:["S","DEL"]};export function isClipGradientSpan(t){return!!(null==t?void 0:t.style)&&("text"===(t.style.getPropertyValue("-webkit-background-clip")||t.style.getPropertyValue("background-clip"))&&(t.style.backgroundImage.includes("gradient")||!!readNativeColor(t,"background-image")))}const C={bold:t=>t.style.removeProperty("font-weight"),italic:t=>t.style.removeProperty("font-style"),color:t=>{!function(t){if(isClipGradientSpan(t)){for(const e of["background-image","background-size","-webkit-background-clip","background-clip","-webkit-text-fill-color"]){t.style.removeProperty(e)}}}(t),t.style.removeProperty("color")},underline:t=>{const e=t.style.textDecoration.replace(/\bunderline\b/g,"").trim();e?t.style.textDecoration=e:t.style.removeProperty("text-decoration")},strike:t=>{const e=t.style.textDecoration.replace(/\bline-through\b/g,"").trim();e?t.style.textDecoration=e:t.style.removeProperty("text-decoration")},"text-transform":t=>t.style.removeProperty("text-transform")};export function stripInlineFormat(o,n){return x(o,o=>function(o,n){var i,l;if(!o||!t(o)){return o}const s=e(o);if(!s){return o}const c=S[n]||[],u=C[n];for(const t of c){let e;for(;e=s.querySelector(t);){const t=e.parentNode;u&&u(e);const r=null===(i=e.getAttribute("style"))||void 0===i?void 0:i.trim();if(r){const o=s.ownerDocument.createElement("span");o.setAttribute("style",r);for(const{name:t,value:r}of Array.from(e.attributes)){t.startsWith(h)&&o.setAttribute(t,r)}for(;e.firstChild;){o.appendChild(e.firstChild)}t.insertBefore(o,e)}else{for(;e.firstChild;){t.insertBefore(e.firstChild,e)}}t.removeChild(e)}}if(u){for(const t of Array.from(s.querySelectorAll("[style]"))){u(t),(null===(l=t.getAttribute("style"))||void 0===l?void 0:l.trim())||t.removeAttribute("style")}}return r(s),s.innerHTML}(o,n))}const k=Symbol("unset");export function isQuillFormatMixed(t,e){var r;let o=k;for(const n of t.ops){if("string"!=typeof n.insert||"\n"===n.insert){continue}const t=null===(r=n.attributes)||void 0===r?void 0:r[e];if(o===k){o=t}else if(t!==o){return!0}}return!1}export function stripInlineFontSizes(t){return x(t,I)}function I(o){var n;if(!o||!o.includes("font-size")||!t(o)){return o}const i=e(o);if(!i){return o}const l=i.querySelectorAll("[style]");for(let t=0;t<l.length;t++){const e=l[t];e.style.fontSize&&(e.style.removeProperty("font-size"),(null===(n=e.getAttribute("style"))||void 0===n?void 0:n.trim())||e.removeAttribute("style"))}return r(i),i.innerHTML}export function stripInlineFontFamilies(t){return x(t,N)}function N(o){var n;if(!o||!o.includes("font-family")&&!o.includes("ql-font-")||!t(o)){return o}const i=e(o);if(!i){return o}for(const t of Array.from(i.querySelectorAll("[style]"))){t.style.fontFamily&&(t.style.removeProperty("font-family"),(null===(n=t.getAttribute("style"))||void 0===n?void 0:n.trim())||t.removeAttribute("style"))}for(const t of Array.from(i.querySelectorAll("[class]"))){const e=t.getAttribute("class")||"",r=e.split(/\s+/).filter(t=>t&&!t.startsWith("ql-font-"));r.length!==e.split(/\s+/).filter(Boolean).length&&(r.length?t.setAttribute("class",r.join(" ")):t.removeAttribute("class"))}return r(i),i.innerHTML}export function hasMultipleDistinctInlineFontSizes(t){if(!t||!t.includes("<")){return!1}const r=e(t);if(!r){return!1}const o=new Set;for(const e of r.querySelectorAll("[style]")){const t=e.style.fontSize;if(t){const e=t.match(/^(\d+(?:\.\d+)?)px$/i);if(e&&(o.add(parseFloat(e[1])),o.size>1)){return!0}}}return!1}export function listEffectiveFontFamilies(t,e){const r=[];e&&r.push(e),r.push(...o(t||""));const n=new Set,i=[];for(const o of r){n.has(o)||(n.add(o),i.push(o))}return i.sort((t,e)=>t.localeCompare(e,void 0,{sensitivity:"base"})),i}const T=t=>t.color&&!(t=>"text"===(t["-webkit-background-clip"]||t["background-clip"])&&!!t["background-image"])(t)?p(t.color):null;export function listInlineTextColors(t){const e=[];return y(t||"").forEach(([r,o],n)=>{const i=T(a(t.slice(r,o)));i&&e.push({index:n,color:i})}),e}export function setInlineTextColor(t,e,r){let o=-1;return f(t||"",t=>{o+=1;const n=a(t);return e.includes(o)&&T(n)?(n.color=r,u(n)):t})}
1
+ export*from"@polotno/core/rich-text-html";import{hasMarkup as t,parseHtmlRoot as e,cleanupInlineWrappers as r,extractFontFamiliesFromHtml as o,normalizeRichTextHtml as n,scaleRichTextFontSizesInHtml as i}from"@polotno/core/rich-text-html";import{containsCmykColor as l,isCmykColor as s,toDisplayColor as c}from"@polotno/core/color";import{buildStyleAttribute as u,mapStyleAttributes as f,parseStyleAttribute as a,stripPriority as p,styleAttributeRanges as y}from"@polotno/core/style-attribute";import{sameColors as d}from"@polotno/core/svg";import{isGradient as m,parseColor as b}from"@polotno/core/gradient";import{LRUCache as v}from"./lru-cache.js";const h="data-native-";export function nativeColorAttribute(t){return h+t}const A=t=>s(t)||m(t)&&l(t);export function readNativeColor(t,e){var r;const o=t.getAttribute(nativeColorAttribute(e));if(null!==o){const n=null===(r=t.style)||void 0===r?void 0:r.getPropertyValue(e);return A(o)&&n&&function(t,e,r){const o=c(r);if(!m(o)){return d(e,o)}const n=function(t,e){if("undefined"==typeof document){return null}const r=document.createElement("span");return r.style.setProperty(t,e),r.style.getPropertyValue(t)||null}(t,o);if(null!==n){return n===e}if(!m(e)){return!1}const i=b(e),l=b(o);return i.type===l.type&&i.rotation===l.rotation&&Math.abs(i.center.x-l.center.x)<.001&&Math.abs(i.center.y-l.center.y)<.001&&i.stops.length===l.stops.length&&i.stops.every((t,e)=>Math.abs(t.offset-l.stops[e].offset)<.001&&d(t.color,l.stops[e].color))}(e,n,o)?o:""}const n=a(t.getAttribute("style"))[e];return n&&A(n)?n:""}export function detachNativeColorsInHtml(t){if(!l(t)){return t}const r=e(t);return r?(function(t){for(const e of Array.from(t.querySelectorAll("[style]"))){const t=e.getAttribute("style");if(!l(t)){continue}const r=a(t);for(const[o,n]of Object.entries(r)){A(n)&&(e.setAttribute(nativeColorAttribute(o),n),r[o]=c(n))}e.setAttribute("style",u(r))}}(r),r.innerHTML):t}export function attachNativeColorsInHtml(t){if(!t||!t.includes(h)){return t}const o=e(t);if(!o){return t}let n=!1;for(const e of Array.from(o.querySelectorAll("*"))){for(const{name:t}of Array.from(e.attributes)){if(!t.startsWith(h)){continue}const r=t.slice(12),o=readNativeColor(e,r);if(e.removeAttribute(t),!o){n=!0;continue}const i=a(e.getAttribute("style"));i[r]=o,e.setAttribute("style",u(i))}}return n&&r(o),o.innerHTML}function g(t,e){if(!l(t)){return e(t)}const r=detachNativeColorsInHtml(t),o=e(r);return o===r?t:attachNativeColorsInHtml(o)}export function scaleRichTextFontSizesInHtml(t,e){return g(t,t=>i(t,e))}const x=new v(500);export function htmlInflatesMinContentWidth(t){if(!t||!t.includes("<")){return!1}let r=x.get(t);if(void 0===r){r=!1;const o=e(t);if(o){if(o.querySelector("ol, ul")){r=!0}else{for(const t of o.querySelectorAll("[style]")){if(t.style.fontSize||t.style.letterSpacing){r=!0;break}}}}x.set(t,r)}return r}export const VARIABLE_TOKEN_CLASS="polotno-variable-token";export function quillHtmlToModelText(t,o){return attachNativeColorsInHtml(n(function(t){const e=(t||"").trim();if("<p><br></p>"===e||"<p></p>"===e){return""}if(e.startsWith("<p>")&&e.endsWith("</p>")){const t=e.slice(3,-4);if(!/(<\/?(p|div|h[1-6]|ul|ol|li|table|thead|tbody|tr|td|blockquote)\b)/i.test(t)){return t}}return t}(function(t){if(!t.includes(VARIABLE_TOKEN_CLASS)){return t}const o=e(t);if(!o){return t}for(const e of o.querySelectorAll(`.${VARIABLE_TOKEN_CLASS}`)){e.classList.remove(VARIABLE_TOKEN_CLASS),e.classList.length||e.removeAttribute("class")}return r(o),o.innerHTML}(t)),o))}export function shrinkParagraphStrutForRaster(t){var r;if(!t||!t.includes("<p")){return t}const o=e(t);if(!o){return t}for(const e of Array.from(o.querySelectorAll("p"))){let t=!1;const n=[],i=o.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_TEXT);let l=i.nextNode();for(;l;){if((l.textContent||"").length>0){let o=l.parentElement,i=null;for(;o&&o!==e;){const t=null===(r=o.style)||void 0===r?void 0:r.fontSize;if(t){const e=parseFloat(t);if(!Number.isNaN(e)){i=e;break}}o=o.parentElement}if(null==i){t=!0;break}n.push(i)}l=i.nextNode()}!t&&n.length>0&&(e.style.fontSize=`${Math.min(...n)}px`)}return o.innerHTML}const S={bold:["STRONG","B"],italic:["EM","I"],underline:["U"],strike:["S","DEL"]};export function isClipGradientSpan(t){return!!(null==t?void 0:t.style)&&("text"===(t.style.getPropertyValue("-webkit-background-clip")||t.style.getPropertyValue("background-clip"))&&(t.style.backgroundImage.includes("gradient")||!!readNativeColor(t,"background-image")))}const C={bold:t=>t.style.removeProperty("font-weight"),italic:t=>t.style.removeProperty("font-style"),color:t=>{!function(t){if(isClipGradientSpan(t)){for(const e of["background-image","background-size","-webkit-background-clip","background-clip","-webkit-text-fill-color"]){t.style.removeProperty(e)}}}(t),t.style.removeProperty("color")},underline:t=>{const e=t.style.textDecoration.replace(/\bunderline\b/g,"").trim();e?t.style.textDecoration=e:t.style.removeProperty("text-decoration")},strike:t=>{const e=t.style.textDecoration.replace(/\bline-through\b/g,"").trim();e?t.style.textDecoration=e:t.style.removeProperty("text-decoration")},"text-transform":t=>t.style.removeProperty("text-transform")};export function stripInlineFormat(o,n){return g(o,o=>function(o,n){var i,l;if(!o||!t(o)){return o}const s=e(o);if(!s){return o}const c=S[n]||[],u=C[n];for(const t of c){let e;for(;e=s.querySelector(t);){const t=e.parentNode;u&&u(e);const r=null===(i=e.getAttribute("style"))||void 0===i?void 0:i.trim();if(r){const o=s.ownerDocument.createElement("span");o.setAttribute("style",r);for(const{name:t,value:r}of Array.from(e.attributes)){t.startsWith(h)&&o.setAttribute(t,r)}for(;e.firstChild;){o.appendChild(e.firstChild)}t.insertBefore(o,e)}else{for(;e.firstChild;){t.insertBefore(e.firstChild,e)}}t.removeChild(e)}}if(u){for(const t of Array.from(s.querySelectorAll("[style]"))){u(t),(null===(l=t.getAttribute("style"))||void 0===l?void 0:l.trim())||t.removeAttribute("style")}}return r(s),s.innerHTML}(o,n))}const k=Symbol("unset");export function isQuillFormatMixed(t,e){var r;let o=k;for(const n of t.ops){if("string"!=typeof n.insert||"\n"===n.insert){continue}const t=null===(r=n.attributes)||void 0===r?void 0:r[e];if(o===k){o=t}else if(t!==o){return!0}}return!1}export function stripInlineFontSizes(t){return g(t,T)}function T(o){var n;if(!o||!o.includes("font-size")||!t(o)){return o}const i=e(o);if(!i){return o}const l=i.querySelectorAll("[style]");for(let t=0;t<l.length;t++){const e=l[t];e.style.fontSize&&(e.style.removeProperty("font-size"),(null===(n=e.getAttribute("style"))||void 0===n?void 0:n.trim())||e.removeAttribute("style"))}return r(i),i.innerHTML}export function stripInlineFontFamilies(t){return g(t,I)}function I(o){var n;if(!o||!o.includes("font-family")&&!o.includes("ql-font-")||!t(o)){return o}const i=e(o);if(!i){return o}for(const t of Array.from(i.querySelectorAll("[style]"))){t.style.fontFamily&&(t.style.removeProperty("font-family"),(null===(n=t.getAttribute("style"))||void 0===n?void 0:n.trim())||t.removeAttribute("style"))}for(const t of Array.from(i.querySelectorAll("[class]"))){const e=t.getAttribute("class")||"",r=e.split(/\s+/).filter(t=>t&&!t.startsWith("ql-font-"));r.length!==e.split(/\s+/).filter(Boolean).length&&(r.length?t.setAttribute("class",r.join(" ")):t.removeAttribute("class"))}return r(i),i.innerHTML}export function hasMultipleDistinctInlineFontSizes(t){if(!t||!t.includes("<")){return!1}const r=e(t);if(!r){return!1}const o=new Set;for(const e of r.querySelectorAll("[style]")){const t=e.style.fontSize;if(t){const e=t.match(/^(\d+(?:\.\d+)?)px$/i);if(e&&(o.add(parseFloat(e[1])),o.size>1)){return!0}}}return!1}export function listEffectiveFontFamilies(t,e){const r=[];e&&r.push(e),r.push(...o(t||""));const n=new Set,i=[];for(const o of r){n.has(o)||(n.add(o),i.push(o))}return i.sort((t,e)=>t.localeCompare(e,void 0,{sensitivity:"base"})),i}const N=t=>t.color&&!(t=>"text"===(t["-webkit-background-clip"]||t["background-clip"])&&!!t["background-image"])(t)?p(t.color):null;export function listInlineTextColors(t){const e=[];return y(t||"").forEach(([r,o],n)=>{const i=N(a(t.slice(r,o)));i&&e.push({index:n,color:i})}),e}export function setInlineTextColor(t,e,r){let o=-1;return f(t||"",t=>{o+=1;const n=a(t);return e.includes(o)&&N(n)?(n.color=r,u(n)):t})}
@@ -1 +1 @@
1
- var e=this&&this.__rest||function(e,t){var i={};for(var n in e){Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(i[n]=e[n])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++){t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(i[n[o]]=e[n[o]])}}return i};import{getTotalClientRect as t}from"./math.js";import{roundedGeometryAttrs as i,roundedGeometryPx as n,roundedStyleAttrs as o,scaledFontSizeBounds as s,isMedia as r,scaledStyleAttrs as c,textMinResizeWidth as a,textMinWidthIsMeasured as h}from"./px.js";import{textResizeFloorFontSize as l}from"./text-sizing.js";import{sideResizeCrop as x}from"../canvas/media-resize.js";export const isAxisAligned=e=>{const t=(e%180+180)%180;return t<.1||180-t<.1};export const canStretchAxis=(e,t,i)=>{if(!isAxisAligned(e.rotation-i)){return!1}switch(e.type){case"text":return"x"===t&&!h(e);case"figure":case"video":case"table":return!0;case"image":case"svg":case"gif":case"lottie":return!e.keepRatio;default:return!1}};export const leafMinSize=(e,t,i,n)=>{if("table"===e.type){const i=e;return"x"===t?i.minWidth:i.minHeight}return"text"===e.type&&"x"===t&&i?a(n,l(e)):1};const p=e=>{const[t]=e.selectedElements;return 1===e.selectedElements.length&&"group"!==t.type?t:null};export const getSelectionBox=e=>{const i=p(e);if(i){const{x:e,y:t,width:n,height:o}=i;return{x:e,y:t,width:n,height:o}}const n=e.selectedShapes;return n.length?t(n):null};const d=e=>!e.pendingEdit;export const canResizeSelection=e=>{const t=e.selectedShapes;return t.length>0&&t.every(e=>e.resizable&&d(e))};export const canMoveSelection=e=>{const t=e.selectedShapes;return t.length>0&&t.every(e=>e.draggable&&d(e))};const g=(e,t,i)=>{e.set(t),e.setHeightRedistribute(i),e.set({x:n(e.x),y:n(e.y),width:n(e.width)}),e._resetBaseRowHeights()},y=(e,t,n)=>{const r=n.x+(e.x-n.x)*t,a=n.y+(e.y-n.y)*t;if("table"===e.type){return void g(e,{x:r,y:a,width:e.width*t},e.height*t)}const{fontSize:h,minFontSize:l,maxFontSize:x}=e;e.set(Object.assign({x:r,y:a,width:e.width*t,height:e.height*t},c(e,t))),e.set(Object.assign(Object.assign({},i(e)),o(e))),"text"===e.type&&e.set(s({minFontSize:l,maxFontSize:x},e.fontSize/h,!0))},u=e=>r(e.type)?e._sourceSize:null,f=e=>!r(e.type)||e.stretchEnabled||!!u(e);export const resizeSelection=(t,n,o)=>{const s=getSelectionBox(t),r="x"===n?null==s?void 0:s.width:null==s?void 0:s.height;if(!(s&&r&&o>0&&canResizeSelection(t))){return}const c=t.selectedShapes,a=p(t),h=c.every(f)&&(a?((e,t)=>"text"===e.type?"x"===t&&!e.curveEnabled:canStretchAxis(e,t,e.rotation))(a,n):c.every(e=>canStretchAxis(e,n,0))),l=Math.max(...c.flatMap(e=>(h?[n]:["x","y"]).map(t=>{const i="x"===t?e.width:e.height,n=leafMinSize(e,t,h,i);return i>=n?n/i:0}))),d=Math.max(o/r,l),S={x:s.x,y:s.y};t.history.transaction(()=>{c.forEach(t=>{h?((t,n,o,s)=>{const[r,c]="x"===n?["x","width"]:["y","height"],a=u(t),h=Object.assign({[r]:s[r]+(t[r]-s[r])*o,[c]:t[c]*o},a&&!t.fit&&x(t,a,"x"===n?o:1,"y"===n?o:1));if("table"===t.type){const{height:i=t.height}=h,n=e(h,["height"]);return void g(t,n,i)}t.set(h),t.set(i(t))})(t,n,d,S):y(t,d,S)})})};const S=(e,t,i)=>{e.forEach(e=>{e.set({x:n(e.x+t),y:n(e.y+i)})})};export const moveSelection=(e,t,i)=>{const n=getSelectionBox(e);if(!n||!Number.isFinite(i)||!canMoveSelection(e)){return}const o=i-("x"===t?n.x:n.y);e.history.transaction(()=>{S(e.selectedShapes,"x"===t?o:0,"y"===t?o:0)})};export const canFitSelectionToPage=e=>canResizeSelection(e)&&canMoveSelection(e);export const fitSelectionToPage=e=>{var i;const n=e.selectedShapes,o=null===(i=n[0])||void 0===i?void 0:i.page;if(!o||!canFitSelectionToPage(e)){return}const s=t(n);if(!s.width||!s.height){return}const r=Math.min(o.computedWidth/s.width,o.computedHeight/s.height);e.history.transaction(()=>{n.forEach(e=>y(e,r,{x:s.x,y:s.y}));const e=t(n);S(n,(o.computedWidth-e.width)/2-e.x,(o.computedHeight-e.height)/2-e.y)})};
1
+ var e=this&&this.__rest||function(e,t){var i={};for(var n in e){Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(i[n]=e[n])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++){t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(i[n[o]]=e[n[o]])}}return i};import{getTotalClientRect as t}from"./math.js";import{roundedGeometryAttrs as i,roundedGeometryPx as n,roundedStyleAttrs as o,scaledFontSizeBounds as s,isMedia as r,scaledStyleAttrs as c,paddedTextMinResizeWidth as a,textMinWidthIsMeasured as h}from"./px.js";import{textResizeFloorFontSize as l}from"./text-sizing.js";import{sideResizeCrop as x}from"../canvas/media-resize.js";export const isAxisAligned=e=>{const t=(e%180+180)%180;return t<.1||180-t<.1};export const canStretchAxis=(e,t,i)=>{if(!isAxisAligned(e.rotation-i)){return!1}switch(e.type){case"text":return"x"===t&&!h(e);case"figure":case"video":case"table":return!0;case"image":case"svg":case"gif":case"lottie":return!e.keepRatio;default:return!1}};export const leafMinSize=(e,t,i,n)=>{if("table"===e.type){const i=e;return"x"===t?i.minWidth:i.minHeight}return"text"===e.type&&"x"===t&&i?a(e,n,l(e)):1};const p=e=>{const[t]=e.selectedElements;return 1===e.selectedElements.length&&"group"!==t.type?t:null};export const getSelectionBox=e=>{const i=p(e);if(i){const{x:e,y:t,width:n,height:o}=i;return{x:e,y:t,width:n,height:o}}const n=e.selectedShapes;return n.length?t(n):null};const d=e=>!e.pendingEdit;export const canResizeSelection=e=>{const t=e.selectedShapes;return t.length>0&&t.every(e=>e.resizable&&d(e))};export const canMoveSelection=e=>{const t=e.selectedShapes;return t.length>0&&t.every(e=>e.draggable&&d(e))};const g=(e,t,i)=>{e.set(t),e.setHeightRedistribute(i),e.set({x:n(e.x),y:n(e.y),width:n(e.width)}),e._resetBaseRowHeights()},y=(e,t,n)=>{const r=n.x+(e.x-n.x)*t,a=n.y+(e.y-n.y)*t;if("table"===e.type){return void g(e,{x:r,y:a,width:e.width*t},e.height*t)}const{fontSize:h,minFontSize:l,maxFontSize:x}=e;e.set(Object.assign({x:r,y:a,width:e.width*t,height:e.height*t},c(e,t))),e.set(Object.assign(Object.assign({},i(e)),o(e))),"text"===e.type&&e.set(s({minFontSize:l,maxFontSize:x},e.fontSize/h,!0))},u=e=>r(e.type)?e._sourceSize:null,f=e=>!r(e.type)||e.stretchEnabled||!!u(e);export const resizeSelection=(t,n,o)=>{const s=getSelectionBox(t),r="x"===n?null==s?void 0:s.width:null==s?void 0:s.height;if(!(s&&r&&o>0&&canResizeSelection(t))){return}const c=t.selectedShapes,a=p(t),h=c.every(f)&&(a?((e,t)=>"text"===e.type?"x"===t&&!e.curveEnabled:canStretchAxis(e,t,e.rotation))(a,n):c.every(e=>canStretchAxis(e,n,0))),l=Math.max(...c.flatMap(e=>(h?[n]:["x","y"]).map(t=>{const i="x"===t?e.width:e.height,n=leafMinSize(e,t,h,i);return i>=n?n/i:0}))),d=Math.max(o/r,l),S={x:s.x,y:s.y};t.history.transaction(()=>{c.forEach(t=>{h?((t,n,o,s)=>{const[r,c]="x"===n?["x","width"]:["y","height"],a=u(t),h=Object.assign({[r]:s[r]+(t[r]-s[r])*o,[c]:t[c]*o},a&&!t.fit&&x(t,a,"x"===n?o:1,"y"===n?o:1));if("table"===t.type){const{height:i=t.height}=h,n=e(h,["height"]);return void g(t,n,i)}t.set(h),t.set(i(t))})(t,n,d,S):y(t,d,S)})})};const S=(e,t,i)=>{e.forEach(e=>{e.set({x:n(e.x+t),y:n(e.y+i)})})};export const moveSelection=(e,t,i)=>{const n=getSelectionBox(e);if(!n||!Number.isFinite(i)||!canMoveSelection(e)){return}const o=i-("x"===t?n.x:n.y);e.history.transaction(()=>{S(e.selectedShapes,"x"===t?o:0,"y"===t?o:0)})};export const canFitSelectionToPage=e=>canResizeSelection(e)&&canMoveSelection(e);export const fitSelectionToPage=e=>{var i;const n=e.selectedShapes,o=null===(i=n[0])||void 0===i?void 0:i.page;if(!o||!canFitSelectionToPage(e)){return}const s=t(n);if(!s.width||!s.height){return}const r=Math.min(o.computedWidth/s.width,o.computedHeight/s.height);e.history.transaction(()=>{n.forEach(e=>y(e,r,{x:s.x,y:s.y}));const e=t(n);S(n,(o.computedWidth-e.width)/2-e.x,(o.computedHeight-e.height)/2-e.y)})};
@@ -1 +1 @@
1
- import*as e from"mobx";import{NO_KEY_MESSAGE as o,NO_VALID_MESSAGE as t,NOT_PAID_MESSAGE as n,NOT_PAID_STYLE as a}from"@polotno/core/validate-key";import{getAPI as i}from"./api.js";import{removeBackgroundState as r}from"./flags.js";const s=e.observable({value:!1}),l=e.observable({value:"v1"});export const ___=()=>l.value;const c=e.observable({value:0});export const ____=()=>c.value;export const isCreditVisible=()=>s.value;const d=e.action(()=>{s.value=!0});let u="";export const getKey=()=>u||"";export const setKey=e=>{u=e||""};let p="undefined"!=typeof window?window.location.origin:"";const v="undefined"!=typeof navigator&&navigator.userAgent.indexOf("Headless")>-1,f="undefined"!=typeof navigator&&navigator.userAgent.indexOf("Electron")>-1;"file://"===p&&v&&(p="headless"),"file://"===p&&f&&(p="electron");const m=`%cPolotno error! Current domain is not allowed. It may lead to unexpected behavior and stop working. Please add "${p}" here: https://polotno.com/cabinet`;let g=fetch;export const __=e=>{g=e};export async function isKeyPaid(s){for(let u=0;u<5;u++){try{const d=await g(i()+"/validate-key",{method:"POST",body:JSON.stringify({key:s,sdkVersion:"4.22.1"})});if(e.runInAction(()=>{l.value=d.headers.get("x-api-version")||""}),!s){return console.error(o),e.runInAction(()=>{c.value=1}),!1}if(200!==d.status){await new Promise(e=>setTimeout(e,3e3));continue}const u=await d.json();return u.is_valid||(console.error(t),e.runInAction(()=>{c.value=1})),u.is_paid||(console.log(n,a),e.runInAction(()=>{0===c.value&&(c.value=2)})),u.is_domain_valid||console.log(m,"background: rgba(247, 101, 68, 1); color: white; padding: 5px; margin: 5px;"),e.runInAction(()=>{r.defaultEnabled=u.remove_background_enabled}),u.is_paid||!1}catch(d){await new Promise(e=>setTimeout(e,3e3))}}return console.error("Can not validate Polotno API key. Please report to anton@polotno.com immediately."),!0}export async function validateKey(e){await isKeyPaid(u)&&!e||d()}
1
+ import*as e from"mobx";import{NO_KEY_MESSAGE as o,NO_VALID_MESSAGE as t,NOT_PAID_MESSAGE as n,NOT_PAID_STYLE as a}from"@polotno/core/validate-key";import{getAPI as i}from"./api.js";import{removeBackgroundState as r}from"./flags.js";const s=e.observable({value:!1}),l=e.observable({value:"v1"});export const ___=()=>l.value;const c=e.observable({value:0});export const ____=()=>c.value;export const isCreditVisible=()=>s.value;const d=e.action(()=>{s.value=!0});let u="";export const getKey=()=>u||"";export const setKey=e=>{u=e||""};let p="undefined"!=typeof window?window.location.origin:"";const v="undefined"!=typeof navigator&&navigator.userAgent.indexOf("Headless")>-1,f="undefined"!=typeof navigator&&navigator.userAgent.indexOf("Electron")>-1;"file://"===p&&v&&(p="headless"),"file://"===p&&f&&(p="electron");const m=`%cPolotno error! Current domain is not allowed. It may lead to unexpected behavior and stop working. Please add "${p}" here: https://polotno.com/cabinet`;let g=fetch;export const __=e=>{g=e};export async function isKeyPaid(s){for(let u=0;u<5;u++){try{const d=await g(i()+"/validate-key",{method:"POST",body:JSON.stringify({key:s,sdkVersion:"4.23.0"})});if(e.runInAction(()=>{l.value=d.headers.get("x-api-version")||""}),!s){return console.error(o),e.runInAction(()=>{c.value=1}),!1}if(200!==d.status){await new Promise(e=>setTimeout(e,3e3));continue}const u=await d.json();return u.is_valid||(console.error(t),e.runInAction(()=>{c.value=1})),u.is_paid||(console.log(n,a),e.runInAction(()=>{0===c.value&&(c.value=2)})),u.is_domain_valid||console.log(m,"background: rgba(247, 101, 68, 1); color: white; padding: 5px; margin: 5px;"),e.runInAction(()=>{r.defaultEnabled=u.remove_background_enabled}),u.is_paid||!1}catch(d){await new Promise(e=>setTimeout(e,3e3))}}return console.error("Can not validate Polotno API key. Please report to anton@polotno.com immediately."),!0}export async function validateKey(e){await isKeyPaid(u)&&!e||d()}