polotno 3.15.0 → 3.15.2

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.
@@ -3479,7 +3479,7 @@ a > .bp6-running-text code{
3479
3479
  .bp6-code, .bp6-running-text code{
3480
3480
  font-family:monospace;
3481
3481
  text-transform:none;
3482
- border-radius:4px;
3482
+ border-radius:var(--bp-surface-border-radius);
3483
3483
  font-size:smaller;
3484
3484
  padding:2px 4px;
3485
3485
  }
@@ -3487,7 +3487,7 @@ a > .bp6-running-text code{
3487
3487
  .bp6-code-block, .bp6-running-text pre{
3488
3488
  font-family:monospace;
3489
3489
  text-transform:none;
3490
- border-radius:4px;
3490
+ border-radius:var(--bp-surface-border-radius);
3491
3491
  display:block;
3492
3492
  font-size:13px;
3493
3493
  line-height:1.4;
@@ -3503,7 +3503,7 @@ a > .bp6-running-text code{
3503
3503
 
3504
3504
  .bp6-key, .bp6-running-text kbd{
3505
3505
  align-items:center;
3506
- border-radius:4px;
3506
+ border-radius:var(--bp-surface-border-radius);
3507
3507
  display:inline-flex;
3508
3508
  font-family:inherit;
3509
3509
  font-size:12px;
@@ -3720,7 +3720,7 @@ a > .bp6-dark .bp6-running-text code{
3720
3720
  .bp6-breadcrumbs-collapsed{
3721
3721
  background:rgba(143, 153, 168, 0.15);
3722
3722
  border:none;
3723
- border-radius:4px;
3723
+ border-radius:var(--bp-surface-border-radius);
3724
3724
  cursor:pointer;
3725
3725
  margin-right:2px;
3726
3726
  padding:1px 4px;
@@ -5307,7 +5307,7 @@ a.bp6-button.bp6-disabled{
5307
5307
  .bp6-callout{
5308
5308
  font-size:14px;
5309
5309
  line-height:1.5;
5310
- border-radius:4px;
5310
+ border-radius:var(--bp-surface-border-radius);
5311
5311
  padding:16px;
5312
5312
  position:relative;
5313
5313
  width:100%;
@@ -5752,7 +5752,7 @@ a.bp6-button.bp6-disabled{
5752
5752
 
5753
5753
  .bp6-dialog{
5754
5754
  background:#f6f7f9;
5755
- border-radius:4px;
5755
+ border-radius:var(--bp-surface-border-radius);
5756
5756
  box-shadow:0 0 0 1px rgba(17, 20, 24, 0.1), 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 15px -3px rgba(0, 0, 0, 0.1);
5757
5757
  display:flex;
5758
5758
  flex-direction:column;
@@ -5781,7 +5781,7 @@ a.bp6-button.bp6-disabled{
5781
5781
  .bp6-dialog-header{
5782
5782
  align-items:center;
5783
5783
  background:#ffffff;
5784
- border-radius:4px 4px 0 0;
5784
+ border-radius:var(--bp-surface-border-radius) var(--bp-surface-border-radius) 0 0;
5785
5785
  box-shadow:0 1px 0 rgba(17, 20, 24, 0.15);
5786
5786
  display:flex;
5787
5787
  flex:0 0 auto;
@@ -5846,7 +5846,7 @@ a.bp6-button.bp6-disabled{
5846
5846
  .bp6-dialog-footer-fixed{
5847
5847
  align-items:center;
5848
5848
  background-color:#ffffff;
5849
- border-radius:0 0 4px 4px;
5849
+ border-radius:0 0 var(--bp-surface-border-radius) var(--bp-surface-border-radius);
5850
5850
  border-top:1px solid rgba(17, 20, 24, 0.15);
5851
5851
  display:flex;
5852
5852
  gap:16px;
@@ -5874,19 +5874,19 @@ a.bp6-button.bp6-disabled{
5874
5874
  display:flex;
5875
5875
  }
5876
5876
  .bp6-multistep-dialog-panels:first-child .bp6-dialog-step-container:first-child{
5877
- border-radius:4px 0 0 0;
5877
+ border-radius:var(--bp-surface-border-radius) 0 0 0;
5878
5878
  }
5879
5879
  .bp6-multistep-dialog-panels:first-child .bp6-multistep-dialog-right-panel{
5880
- border-top-right-radius:4px;
5880
+ border-top-right-radius:var(--bp-surface-border-radius);
5881
5881
  }
5882
5882
  .bp6-multistep-dialog-nav-top .bp6-multistep-dialog-panels{
5883
5883
  flex-direction:column;
5884
5884
  }
5885
5885
  .bp6-multistep-dialog-nav-top .bp6-multistep-dialog-panels:first-child .bp6-dialog-step-container:first-child{
5886
- border-radius:4px 0 0 0;
5886
+ border-radius:var(--bp-surface-border-radius) 0 0 0;
5887
5887
  }
5888
5888
  .bp6-multistep-dialog-nav-top .bp6-multistep-dialog-panels:first-child .bp6-dialog-step-container:last-child{
5889
- border-radius:0 4px 0 0;
5889
+ border-radius:0 var(--bp-surface-border-radius) 0 0;
5890
5890
  }
5891
5891
  .bp6-multistep-dialog-nav-top .bp6-multistep-dialog-panels .bp6-multistep-dialog-left-panel{
5892
5892
  flex-direction:row;
@@ -5905,23 +5905,23 @@ a.bp6-button.bp6-disabled{
5905
5905
  }
5906
5906
  .bp6-multistep-dialog-nav-top .bp6-multistep-dialog-panels .bp6-multistep-dialog-right-panel,
5907
5907
  .bp6-multistep-dialog-nav-top .bp6-multistep-dialog-panels .bp6-multistep-dialog-footer{
5908
- border-radius:0 0 4px 4px;
5908
+ border-radius:0 0 var(--bp-surface-border-radius) var(--bp-surface-border-radius);
5909
5909
  }
5910
5910
  .bp6-multistep-dialog-nav-right .bp6-multistep-dialog-panels{
5911
5911
  flex-direction:row-reverse;
5912
5912
  }
5913
5913
  .bp6-multistep-dialog-nav-right .bp6-multistep-dialog-panels:first-child .bp6-multistep-dialog-right-panel{
5914
- border-radius:4px 0 0 4px;
5914
+ border-radius:var(--bp-surface-border-radius) 0 0 var(--bp-surface-border-radius);
5915
5915
  }
5916
5916
  .bp6-multistep-dialog-nav-right .bp6-multistep-dialog-panels:first-child .bp6-dialog-step-container:first-child{
5917
- border-radius:0 4px 0 0;
5917
+ border-radius:0 var(--bp-surface-border-radius) 0 0;
5918
5918
  }
5919
5919
  .bp6-multistep-dialog-nav-right .bp6-multistep-dialog-panels .bp6-multistep-dialog-left-panel{
5920
- border-radius:0 0 4px;
5920
+ border-radius:0 0 var(--bp-surface-border-radius);
5921
5921
  }
5922
5922
  .bp6-multistep-dialog-nav-right .bp6-multistep-dialog-panels .bp6-multistep-dialog-right-panel{
5923
5923
  border-left:none;
5924
- border-radius:4px 0 0 4px;
5924
+ border-radius:var(--bp-surface-border-radius) 0 0 var(--bp-surface-border-radius);
5925
5925
  border-right:1px solid rgba(17, 20, 24, 0.15);
5926
5926
  }
5927
5927
  .bp6-dark .bp6-multistep-dialog-nav-right .bp6-multistep-dialog-panels .bp6-multistep-dialog-right-panel{
@@ -5939,21 +5939,21 @@ a.bp6-button.bp6-disabled{
5939
5939
  .bp6-dark .bp6-multistep-dialog-left-panel{
5940
5940
  background:#252a31;
5941
5941
  border-bottom:1px solid rgba(255, 255, 255, 0.2);
5942
- border-bottom-left-radius:4px;
5942
+ border-bottom-left-radius:var(--bp-surface-border-radius);
5943
5943
  border-left:1px solid rgba(255, 255, 255, 0.2);
5944
5944
  }
5945
5945
 
5946
5946
  .bp6-multistep-dialog-right-panel{
5947
5947
  background-color:#f6f7f9;
5948
5948
  border-left:1px solid rgba(17, 20, 24, 0.15);
5949
- border-radius:0 0 4px;
5949
+ border-radius:0 0 var(--bp-surface-border-radius);
5950
5950
  flex:3;
5951
5951
  min-width:0;
5952
5952
  }
5953
5953
  .bp6-dark .bp6-multistep-dialog-right-panel{
5954
5954
  background-color:#2f343c;
5955
5955
  border-bottom:1px solid rgba(255, 255, 255, 0.2);
5956
- border-bottom-right-radius:4px;
5956
+ border-bottom-right-radius:var(--bp-surface-border-radius);
5957
5957
  border-left:1px solid rgba(255, 255, 255, 0.2);
5958
5958
  border-right:1px solid rgba(255, 255, 255, 0.2);
5959
5959
  }
@@ -5975,7 +5975,7 @@ a.bp6-button.bp6-disabled{
5975
5975
 
5976
5976
  .bp6-dialog-step{
5977
5977
  align-items:center;
5978
- border-radius:4px;
5978
+ border-radius:var(--bp-surface-border-radius);
5979
5979
  cursor:not-allowed;
5980
5980
  display:flex;
5981
5981
  margin:4px;
@@ -6258,7 +6258,7 @@ a.bp6-button.bp6-disabled{
6258
6258
  .bp6-editable-text::before{
6259
6259
  inset:-2px;
6260
6260
  position:absolute;
6261
- border-radius:4px;
6261
+ border-radius:var(--bp-surface-border-radius);
6262
6262
  content:"";
6263
6263
  transition:background-color 100ms cubic-bezier(0.4, 1, 0.75, 0.9), box-shadow 100ms cubic-bezier(0.4, 1, 0.75, 0.9);
6264
6264
  }
@@ -7012,7 +7012,7 @@ a.bp6-button.bp6-disabled{
7012
7012
  color:rgba(255, 255, 255, 0.6);
7013
7013
  }
7014
7014
  .bp6-control.bp6-checkbox .bp6-control-indicator{
7015
- border-radius:4px;
7015
+ border-radius:var(--bp-surface-border-radius);
7016
7016
  }
7017
7017
  .bp6-control.bp6-checkbox input:checked ~ .bp6-control-indicator::before{
7018
7018
  background-image:url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='white' d='M12 5c-.28 0-.53.11-.71.29L7 9.59l-2.29-2.3a1.003 1.003 0 0 0-1.42 1.42l3 3c.18.18.43.29.71.29s.53-.11.71-.29l5-5A1.003 1.003 0 0 0 12 5'/%3e%3c/svg%3e");
@@ -8410,7 +8410,7 @@ label.bp6-label:not(.bp6-inline) .bp6-popover-target{
8410
8410
  .bp6-select select{
8411
8411
  -moz-appearance:none;
8412
8412
  -webkit-appearance:none;
8413
- border-radius:4px;
8413
+ border-radius:var(--bp-surface-border-radius);
8414
8414
  height:30px;
8415
8415
  padding:0 24px 0 8px;
8416
8416
  width:100%;
@@ -12227,7 +12227,7 @@ span.bp6-icon:empty.bp6-icon-large{
12227
12227
 
12228
12228
  .bp6-menu{
12229
12229
  background:#ffffff;
12230
- border-radius:4px;
12230
+ border-radius:var(--bp-surface-border-radius);
12231
12231
  color:#1c2127;
12232
12232
  list-style:none;
12233
12233
  margin:0;
@@ -12267,7 +12267,7 @@ span.bp6-icon:empty.bp6-icon-large{
12267
12267
  }
12268
12268
  .bp6-menu-item{
12269
12269
  align-items:flex-start;
12270
- border-radius:4px;
12270
+ border-radius:var(--bp-surface-border-radius);
12271
12271
  color:inherit;
12272
12272
  line-height:22px;
12273
12273
  padding:4px 8px;
@@ -13066,10 +13066,10 @@ body.bp6-overlay-open{
13066
13066
  flex:1 1 auto;
13067
13067
  }
13068
13068
  .bp6-button-group.bp6-vertical:not(.bp6-minimal) > .bp6-popover-target:first-child .bp6-button{
13069
- border-radius:4px 4px 0 0;
13069
+ border-radius:var(--bp-surface-border-radius) var(--bp-surface-border-radius) 0 0;
13070
13070
  }
13071
13071
  .bp6-button-group.bp6-vertical:not(.bp6-minimal) > .bp6-popover-target:last-child .bp6-button{
13072
- border-radius:0 0 4px 4px;
13072
+ border-radius:0 0 var(--bp-surface-border-radius) var(--bp-surface-border-radius);
13073
13073
  }
13074
13074
  .bp6-button-group.bp6-vertical:not(.bp6-minimal) > .bp6-popover-target:not(:last-child) .bp6-button{
13075
13075
  margin-bottom:-1px;
@@ -13167,12 +13167,12 @@ label.bp6-label .bp6-popover-target{
13167
13167
  transition-timing-function:cubic-bezier(0.54, 1.12, 0.38, 1.11);
13168
13168
  }
13169
13169
  .bp6-popover{
13170
- border-radius:4px;
13170
+ border-radius:var(--bp-surface-border-radius);
13171
13171
  display:inline-block;
13172
13172
  z-index:20;
13173
13173
  }
13174
13174
  .bp6-popover .bp6-popover-content{
13175
- border-radius:4px;
13175
+ border-radius:var(--bp-surface-border-radius);
13176
13176
  position:relative;
13177
13177
  }
13178
13178
  .bp6-popover.bp6-popover-content-sizing .bp6-popover-content{
@@ -13450,7 +13450,7 @@ span.bp6-popover-target{
13450
13450
  }
13451
13451
  .bp6-segmented-control{
13452
13452
  background-color:#f6f7f9;
13453
- border-radius:4px;
13453
+ border-radius:var(--bp-surface-border-radius);
13454
13454
  display:flex;
13455
13455
  gap:2px;
13456
13456
  padding:2px;
@@ -13874,7 +13874,7 @@ a > .bp6-dark .bp6-tooltip .bp6-running-text code{
13874
13874
  }
13875
13875
 
13876
13876
  .bp6-slider-track{
13877
- border-radius:4px;
13877
+ border-radius:var(--bp-surface-border-radius);
13878
13878
  overflow:hidden;
13879
13879
  }
13880
13880
 
@@ -13937,7 +13937,7 @@ a > .bp6-dark .bp6-tooltip .bp6-running-text code{
13937
13937
  }
13938
13938
  }
13939
13939
  .bp6-slider-handle{
13940
- border-radius:4px;
13940
+ border-radius:var(--bp-surface-border-radius);
13941
13941
  box-shadow:0 0 0 1px rgba(17, 20, 24, 0.5), 0 1px 1px rgba(17, 20, 24, 0.5);
13942
13942
  cursor:pointer;
13943
13943
  height:16px;
@@ -13994,7 +13994,7 @@ a > .bp6-dark .bp6-tooltip .bp6-running-text code{
13994
13994
  }
13995
13995
  .bp6-slider-handle .bp6-slider-label{
13996
13996
  background:#404854;
13997
- border-radius:4px;
13997
+ border-radius:var(--bp-surface-border-radius);
13998
13998
  box-shadow:0 0 0 1px rgba(17, 20, 24, 0.1), 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 15px -3px rgba(0, 0, 0, 0.1);
13999
13999
  color:#f6f7f9;
14000
14000
  margin-left:8px;
@@ -14065,7 +14065,7 @@ a > .bp6-dark .bp6-tooltip .bp6-running-text code{
14065
14065
  width:16px;
14066
14066
  }
14067
14067
  .bp6-slider.bp6-vertical .bp6-slider-handle.bp6-start{
14068
- border-bottom-right-radius:4px;
14068
+ border-bottom-right-radius:var(--bp-surface-border-radius);
14069
14069
  border-top-left-radius:0;
14070
14070
  }
14071
14071
  .bp6-slider.bp6-vertical .bp6-slider-handle.bp6-start .bp6-slider-label{
@@ -14074,7 +14074,7 @@ a > .bp6-dark .bp6-tooltip .bp6-running-text code{
14074
14074
  .bp6-slider.bp6-vertical .bp6-slider-handle.bp6-end{
14075
14075
  border-bottom-left-radius:0;
14076
14076
  border-bottom-right-radius:0;
14077
- border-top-left-radius:4px;
14077
+ border-top-left-radius:var(--bp-surface-border-radius);
14078
14078
  margin-bottom:8px;
14079
14079
  }
14080
14080
  @keyframes pt-spinner-animation{
@@ -14153,7 +14153,7 @@ a > .bp6-dark .bp6-tooltip .bp6-running-text code{
14153
14153
  }
14154
14154
  .bp6-tabs.bp6-vertical > .bp6-tab-list .bp6-tab{
14155
14155
  align-items:center;
14156
- border-radius:4px;
14156
+ border-radius:var(--bp-surface-border-radius);
14157
14157
  display:flex;
14158
14158
  padding:0 8px;
14159
14159
  width:100%;
@@ -14170,7 +14170,7 @@ a > .bp6-dark .bp6-tooltip .bp6-running-text code{
14170
14170
  }
14171
14171
  .bp6-tabs.bp6-vertical > .bp6-tab-list .bp6-tab-indicator-wrapper .bp6-tab-indicator{
14172
14172
  background-color:rgba(45, 114, 210, 0.2);
14173
- border-radius:4px;
14173
+ border-radius:var(--bp-surface-border-radius);
14174
14174
  height:auto;
14175
14175
  inset:0;
14176
14176
  }
@@ -15392,7 +15392,7 @@ a > .bp6-dark .bp6-tooltip .bp6-running-text code{
15392
15392
  .bp6-toast{
15393
15393
  align-items:flex-start;
15394
15394
  background-color:#ffffff;
15395
- border-radius:4px;
15395
+ border-radius:var(--bp-surface-border-radius);
15396
15396
  box-shadow:inset 0 0 0 1px rgba(17, 20, 24, 0.2), 0 2px 4px rgba(17, 20, 24, 0.2), 0 8px 24px rgba(17, 20, 24, 0.2);
15397
15397
  display:flex;
15398
15398
  margin:20px 0 0;
@@ -1 +1,3 @@
1
+ export declare const PRESERVED_INLINE_STYLES: readonly ["text-shadow", "letter-spacing", "word-spacing", "-webkit-text-stroke", "font-variant", "vertical-align"];
2
+ export declare const PRESERVED_BLOCK_STYLES: readonly ["text-align", "line-height", "margin-top", "margin-bottom", "text-indent", "list-style-type"];
1
3
  export declare function registerQuillUnrestrictedFontFormats(): void;
@@ -1 +1 @@
1
- import t from"quill";import{firstStopColor as e}from"@polotno/core/gradient";import{parsePrimaryFontFamily as r}from"@polotno/core/rich-text-html";import{cssFontFamily as o}from"@polotno/core/fonts";import{containsCmykColor as i,isCmykColor as n,toDisplayColor as s}from"@polotno/core/color";import{isClipGradientSpan as l,nativeColorAttribute as c,readNativeColor as u}from"../utils/rich-text-html.js";let a=!1;function m(t){const e=t.keyName,r=c(e),o=t.add.bind(t),i=t.remove.bind(t),l=t.value.bind(t);t.add=(t,e)=>n(e)?!!o(t,s(e))&&(t.setAttribute(r,e),!0):(t.removeAttribute(r),o(t,e)),t.remove=t=>{t.removeAttribute(r),i(t)},t.value=t=>u(t,e)||l(t)}const p=["background-image","background-size","-webkit-background-clip","background-clip","-webkit-text-fill-color","color"],b=c("background-image");export function registerQuillUnrestrictedFontFormats(){if(a){return}a=!0;const n=t.import("attributors/style/size"),c=t.import("attributors/style/font");n&&(delete n.whitelist,t.register(n,!0)),c&&(delete c.whitelist,c.add=(t,e)=>(t.style.fontFamily=o(e),!0),c.value=t=>r(t.style.fontFamily)||"",t.register(c,!0));const d=t.import("parchment");if((null==d?void 0:d.StyleAttributor)&&(null==d?void 0:d.Scope)){const r=new d.StyleAttributor("font-weight","font-weight",{scope:d.Scope.INLINE});t.register(r,!0),t.register(new d.StyleAttributor("text-transform","text-transform",{scope:d.Scope.INLINE}),!0),t.register(function(t){class r extends t.StyleAttributor{constructor(t,e,r){super(t,e,r)}add(t,r){if("string"!=typeof r||!r.includes("gradient")){return!1}t.style.setProperty("background-image",s(r)),i(r)?t.setAttribute(b,r):t.removeAttribute(b),t.style.setProperty("background-size","100% 100%"),t.style.setProperty("-webkit-background-clip","text"),t.style.setProperty("background-clip","text"),t.style.setProperty("-webkit-text-fill-color","transparent");try{t.style.setProperty("color",e(r))}catch(o){}return!0}remove(t){t.removeAttribute(b);for(const e of p){t.style.removeProperty(e)}}value(t){return l(t)?u(t,"background-image")||t.style.getPropertyValue("background-image"):""}}return new r("gradient","background-image",{scope:t.Scope.INLINE})}(d),!0);const o=t.import("attributors/style/color");if(o){m(o);const e=o.value.bind(o);o.value=t=>l(t)?"":e(t),t.register(o,!0)}const n=t.import("attributors/style/background");n&&(m(n),t.register(n,!0))}}
1
+ import t from"quill";import{firstStopColor as e}from"@polotno/core/gradient";import{parsePrimaryFontFamily as r}from"@polotno/core/rich-text-html";import{cssFontFamily as o}from"@polotno/core/fonts";import{containsCmykColor as i,isCmykColor as n,toDisplayColor as s}from"@polotno/core/color";import{isClipGradientSpan as l,nativeColorAttribute as c,readNativeColor as a}from"../utils/rich-text-html.js";let u=!1;export const PRESERVED_INLINE_STYLES=["text-shadow","letter-spacing","word-spacing","-webkit-text-stroke","font-variant","vertical-align"];export const PRESERVED_BLOCK_STYLES=["text-align","line-height","margin-top","margin-bottom","text-indent","list-style-type"];function p(t){const e=t.keyName,r=c(e),o=t.add.bind(t),i=t.remove.bind(t),l=t.value.bind(t);t.add=(t,e)=>n(e)?!!o(t,s(e))&&(t.setAttribute(r,e),!0):(t.removeAttribute(r),o(t,e)),t.remove=t=>{t.removeAttribute(r),i(t)},t.value=t=>a(t,e)||l(t)}const m=["background-image","background-size","-webkit-background-clip","background-clip","-webkit-text-fill-color","color"],g=c("background-image");export function registerQuillUnrestrictedFontFormats(){if(u){return}u=!0;const n=t.import("attributors/style/size"),c=t.import("attributors/style/font");n&&(delete n.whitelist,t.register(n,!0)),c&&(delete c.whitelist,c.add=(t,e)=>(t.style.fontFamily=o(e),!0),c.value=t=>r(t.style.fontFamily)||"",t.register(c,!0));const b=t.import("parchment");if((null==b?void 0:b.StyleAttributor)&&(null==b?void 0:b.Scope)){const r=new b.StyleAttributor("font-weight","font-weight",{scope:b.Scope.INLINE});t.register(r,!0),t.register(new b.StyleAttributor("text-transform","text-transform",{scope:b.Scope.INLINE}),!0);const o=(e,r)=>t.register(new b.StyleAttributor(e,e,{scope:r}),!0);PRESERVED_INLINE_STYLES.forEach(t=>o(t,b.Scope.INLINE)),PRESERVED_BLOCK_STYLES.forEach(t=>o(t,b.Scope.BLOCK)),t.register(function(t){class r extends t.StyleAttributor{constructor(t,e,r){super(t,e,r)}add(t,r){if("string"!=typeof r||!r.includes("gradient")){return!1}t.style.setProperty("background-image",s(r)),i(r)?t.setAttribute(g,r):t.removeAttribute(g),t.style.setProperty("background-size","100% 100%"),t.style.setProperty("-webkit-background-clip","text"),t.style.setProperty("background-clip","text"),t.style.setProperty("-webkit-text-fill-color","transparent");try{t.style.setProperty("color",e(r))}catch(o){}return!0}remove(t){t.removeAttribute(g);for(const e of m){t.style.removeProperty(e)}}value(t){return l(t)?a(t,"background-image")||t.style.getPropertyValue("background-image"):""}}return new r("gradient","background-image",{scope:t.Scope.INLINE})}(b),!0);const n=t.import("attributors/style/color");if(n){p(n);const e=n.value.bind(n);n.value=t=>l(t)?"":e(t),t.register(n,!0)}const c=t.import("attributors/style/background");c&&(p(c),t.register(c,!0))}}
@@ -36,6 +36,7 @@ export declare const createQuill: (node: any, options?: {
36
36
  placeholder?: string;
37
37
  }) => Quill;
38
38
  export declare const setQuillContent: (quill: any, html: any) => void;
39
+ export declare const editorHtml: (element: TextElementType) => string;
39
40
  type Point = {
40
41
  x: number;
41
42
  y: number;
@@ -1,4 +1,4 @@
1
- var e=this&&this.__rest||function(e,t){var o={};for(var n in e){Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(o[n]=e[n])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(n=Object.getOwnPropertySymbols(e);r<n.length;r++){t.indexOf(n[r])<0&&Object.prototype.propertyIsEnumerable.call(e,n[r])&&(o[n[r]]=e[n[r]])}}return o};import{jsx as t}from"react/jsx-runtime";import o from"react";import n from"quill";import*as r from"mobx";import{nodeReaction as i}from"../utils/mobx.js";import{isAlive as l}from"mobx-state-tree";import{getDir as s,getMeasureCtx as a,getQuillEditorHtml as d,textLayoutWidth as c}from"@polotno/core/text-html";import{quillHtmlToModelText as u,isQuillFormatMixed as f,isBoldWeight as p,detachNativeColorsInHtml as h}from"../utils/rich-text-html.js";import{toDisplayColor as m}from"@polotno/core/color";import{resetStyleContent as g,wrapHtmlForRenderTag as b}from"@polotno/core/reset-style";import{layout as v,lineBaselineOffset as y}from"render-tag";import{removeTags as x}from"@polotno/core/text";import{cssFontFamily as w}from"@polotno/core/fonts";import{isGradient as k,firstStopColor as S}from"@polotno/core/gradient";import{getOptimalCaretColor as q}from"./text-element/caret-color.js";import{visiblePlaceholder as T}from"./text-element/placeholder.js";import{registerQuillUnrestrictedFontFormats as E}from"./quill-font-formats.js";import{ALL_QUILL_MIXED_KEYS as C,setActiveTextEditor as L,updateActiveTextFormat as O,clearActiveTextEditor as R,getActiveTextEditor as F}from"../utils/text-format-state.js";import $ from"../utils/styled.js";import{applyOpacityToColor as j}from"@polotno/core/svg";import{elementDropShadow as N,shadowCastByBackground as z}from"@polotno/core/filters";export{j as applyOpacityToColor};export const quillRef=r.observable({enabled:!1,currentFormat:{},pendingToolbarInteraction:!1,editor:r.observable.object({instance:null},{},{deep:!1})});const M=C;export function syncQuillFormatState(e,t){const o=t?e.getFormat(t):{},n=function(e,t){const o={};if(!t||t.length<=0){return o}const n=e.getContents(t.index,t.length);for(const r of M){f(n,r)&&(o[r]=!0)}return o}(e,t);r.runInAction(()=>{quillRef.currentFormat=o}),O(o,n,t)}const P="polotno-saved-selection";function Q(){const e=window.getSelection();if(!e||0===e.rangeCount||e.isCollapsed){return}if("undefined"==typeof Highlight||!CSS.highlights){return}const t=e.getRangeAt(0).cloneRange();CSS.highlights.set(P,new Highlight(t)),D()}function A(){"undefined"!=typeof CSS&&CSS.highlights&&CSS.highlights.delete(P)}function D(){setTimeout(()=>{"undefined"!=typeof CSS&&CSS.highlights&&CSS.highlights.has(P)&&(document.querySelector(".polotno-portal")||V(document.activeElement)?D():A())},300)}if("undefined"!=typeof document&&"undefined"!=typeof CSS&&CSS.highlights&&!document.querySelector("[data-polotno-highlight]")){const X=document.createElement("style");X.setAttribute("data-polotno-highlight",""),X.textContent=`::highlight(${P}) { background-color: Highlight; }`,document.head.appendChild(X)}function H(e,t){"text"===e.type&&t.push(e);for(const o of e.children||[]){H(o,t)}}export function computeMarkerVars(e){var t,o,n;const r=e.fontSize;if(!r||r<=0){return null}const i=w(e.fontFamily),l=p(e.fontWeight)?700:400,s="italic"===e.fontStyle?"italic":"normal",d=a();d.fontKerning="normal",d.font=`${r}px ${i}`;const c=d.measureText("M"),u=(null!==(t=c.fontBoundingBoxAscent)&&void 0!==t?t:0)/r,f=(null!==(o=c.fontBoundingBoxDescent)&&void 0!==o?o:0)/r,h=`font-family:${i};font-size:${r}px;font-weight:${l};font-style:${s};line-height:${e.lineHeight};letter-spacing:${e.letterSpacing}em`,m=b(`<div style="${h}"><ul><li>x</li></ul><ol><li>x</li></ol></div>`);let g;try{g=v({html:m,width:Math.max(12*r,600)})}catch(E){return null}const x=[];H(g.layoutRoot,x);const k=x.find(e=>"•"===e.text),S=x.find(e=>/^\d/.test(e.text));if(!k){return null}const q=k.style.fontSize,T=2.1*r;return{bulletLeft:k.x,bulletTop:k.y-y(q,q*u,q*f),bulletFontSize:q,numberGap:S?Math.max(0,T-S.x-(null!==(n=S.width)&&void 0!==n?n:0)):0}}export const RichTextContainer=$("div",o.forwardRef)`
1
+ var e=this&&this.__rest||function(e,t){var o={};for(var n in e){Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(o[n]=e[n])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(n=Object.getOwnPropertySymbols(e);r<n.length;r++){t.indexOf(n[r])<0&&Object.prototype.propertyIsEnumerable.call(e,n[r])&&(o[n[r]]=e[n[r]])}}return o};import{jsx as t}from"react/jsx-runtime";import o from"react";import n from"quill";import*as r from"mobx";import{nodeReaction as i}from"../utils/mobx.js";import{isAlive as l}from"mobx-state-tree";import{getDir as s,getMeasureCtx as a,getQuillEditorHtml as d,textLayoutWidth as c}from"@polotno/core/text-html";import{quillHtmlToModelText as u,isQuillFormatMixed as f,isBoldWeight as p,detachNativeColorsInHtml as h}from"../utils/rich-text-html.js";import{toDisplayColor as m}from"@polotno/core/color";import{resetStyleContent as g,wrapHtmlForRenderTag as b}from"@polotno/core/reset-style";import{layout as v,lineBaselineOffset as y}from"render-tag";import{removeTags as x}from"@polotno/core/text";import{cssFontFamily as w}from"@polotno/core/fonts";import{isGradient as k,firstStopColor as S}from"@polotno/core/gradient";import{getOptimalCaretColor as T}from"./text-element/caret-color.js";import{visiblePlaceholder as q}from"./text-element/placeholder.js";import{registerQuillUnrestrictedFontFormats as E,PRESERVED_INLINE_STYLES as C,PRESERVED_BLOCK_STYLES as O}from"./quill-font-formats.js";import{ALL_QUILL_MIXED_KEYS as L,setActiveTextEditor as F,updateActiveTextFormat as R,clearActiveTextEditor as N,getActiveTextEditor as $}from"../utils/text-format-state.js";import j from"../utils/styled.js";import{applyOpacityToColor as M}from"@polotno/core/svg";import{elementDropShadow as z,shadowCastByBackground as P}from"@polotno/core/filters";export{M as applyOpacityToColor};export const quillRef=r.observable({enabled:!1,currentFormat:{},pendingToolbarInteraction:!1,editor:r.observable.object({instance:null},{},{deep:!1})});const D=L;export function syncQuillFormatState(e,t){const o=t?e.getFormat(t):{},n=function(e,t){const o={};if(!t||t.length<=0){return o}const n=e.getContents(t.index,t.length);for(const r of D){f(n,r)&&(o[r]=!0)}return o}(e,t);r.runInAction(()=>{quillRef.currentFormat=o}),R(o,n,t)}const H="polotno-saved-selection";function I(){const e=window.getSelection();if(!e||0===e.rangeCount||e.isCollapsed){return}if("undefined"==typeof Highlight||!CSS.highlights){return}const t=e.getRangeAt(0).cloneRange();CSS.highlights.set(H,new Highlight(t)),Q()}function A(){"undefined"!=typeof CSS&&CSS.highlights&&CSS.highlights.delete(H)}function Q(){setTimeout(()=>{"undefined"!=typeof CSS&&CSS.highlights&&CSS.highlights.has(H)&&(document.querySelector(".polotno-portal")||ee(document.activeElement)?Q():A())},300)}if("undefined"!=typeof document&&"undefined"!=typeof CSS&&CSS.highlights&&!document.querySelector("[data-polotno-highlight]")){const te=document.createElement("style");te.setAttribute("data-polotno-highlight",""),te.textContent=`::highlight(${H}) { background-color: Highlight; }`,document.head.appendChild(te)}function _(e,t){"text"===e.type&&t.push(e);for(const o of e.children||[]){_(o,t)}}export function computeMarkerVars(e){var t,o,n;const r=e.fontSize;if(!r||r<=0){return null}const i=w(e.fontFamily),l=p(e.fontWeight)?700:400,s="italic"===e.fontStyle?"italic":"normal",d=a();d.fontKerning="normal",d.font=`${r}px ${i}`;const c=d.measureText("M"),u=(null!==(t=c.fontBoundingBoxAscent)&&void 0!==t?t:0)/r,f=(null!==(o=c.fontBoundingBoxDescent)&&void 0!==o?o:0)/r,h=`font-family:${i};font-size:${r}px;font-weight:${l};font-style:${s};line-height:${e.lineHeight};letter-spacing:${e.letterSpacing}em`,m=b(`<div style="${h}"><ul><li>x</li></ul><ol><li>x</li></ol></div>`);let g;try{g=v({html:m,width:Math.max(12*r,600)})}catch(E){return null}const x=[];_(g.layoutRoot,x);const k=x.find(e=>"•"===e.text),S=x.find(e=>/^\d/.test(e.text));if(!k){return null}const T=k.style.fontSize,q=2.1*r;return{bulletLeft:k.x,bulletTop:k.y-y(T,T*u,T*f),bulletFontSize:T,numberGap:S?Math.max(0,q-S.x-(null!==(n=S.width)&&void 0!==n?n:0)):0}}export const RichTextContainer=j("div",o.forwardRef)`
2
2
  .ql-editor {
3
3
  outline: none;
4
4
  /* anchor for the absolutely-positioned ::before placeholder below */
@@ -163,4 +163,4 @@ var e=this&&this.__rest||function(e,t){var o={};for(var n in e){Object.prototype
163
163
  .ql-editor [style*='background-clip'] {
164
164
  -webkit-text-stroke-width: 0;
165
165
  }
166
- `;let I=["background","font-weight","color","gradient","font","italic","size","script","strike","underline","text-transform","indent","list","direction"];export const setQuillFormats=e=>{I=e};let _=!1;function B(){_||(_=!0,console.warn("[polotno] The Quill 'bold' format is deprecated. Use the numeric 'font-weight' format instead, e.g. quill.format('font-weight', '700') or applyTextFormat({ fontWeight: 700 })."))}function W(e){return e?"700":"400"}export const createQuill=(t,o)=>{E();const r=new n(t,{toolbar:!1,keyboard:!1,placeholder:(null==o?void 0:o.placeholder)||void 0,clipboard:{matchVisual:!1},formats:I});!function(t){const o=t.format.bind(t),n=t.formatText.bind(t),r=t.getFormat.bind(t);t.format=(e,t,n)=>"bold"===e?(B(),o("font-weight",W(t),n)):o(e,t,n),t.formatText=(t,o,r,i,l)=>{if(r&&"object"==typeof r){if("bold"in r){B();const{bold:l}=r,s=e(r,["bold"]);return n(t,o,Object.assign(Object.assign({},s),{"font-weight":W(l)}),i)}return n(t,o,r,i)}return"bold"===r?(B(),n(t,o,"font-weight",W(i),l)):n(t,o,r,i,l)},t.getFormat=(...e)=>{const t=r(...e);return t&&null!=t["font-weight"]&&!("bold"in t)&&(t.bold=p(t["font-weight"])),t}}(r);const i=n.import("delta"),l=(e,t)=>t.compose((new i).retain(t.length(),{"font-weight":"700"}));return r.clipboard.addMatcher("STRONG",l),r.clipboard.addMatcher("B",l),r};export const setQuillContent=(e,t)=>{var o=e.clipboard.convert({html:"<div class='ql-editor' style='outline: none;'>"+t.replace(/\t/g,"")+"<p><br></p></div>",text:""});o.ops.forEach(e=>{"string"==typeof e.insert&&e.insert.includes("")&&(e.insert=e.insert.split("").join("\t"))}),e.setContents(o),e.history.clear()};const G=e=>d(Object.assign(Object.assign({},e),{text:h(e.text)}),e.fontFamily);export const RichEditor=({onBlur:e,onChange:n,element:a,clickCoords:d})=>{const f=o.useRef(null),p=o.useRef(!1);o.useLayoutEffect(()=>{let t,o=!1,i=null,s=null,c=null,h=null,m=null;const g=()=>{if(!o&&f.current){try{t=createQuill(f.current,{placeholder:T(a.placeholder)}),r.runInAction(()=>{quillRef.editor.instance=t}),quillRef.pendingToolbarInteraction=!1,window.__polotnoQuill=t,L({instance:t,store:a.store,element:a});const o=e=>{e&&syncQuillFormatState(t,e)};t.on("text-change",()=>{const e=F(),r=e&&e.instance===t?e.lastSelection:null;o(t.getSelection()||r),setTimeout(()=>{var e,o;const r=t.root;if(!r||!r.isConnected){return}if(!l(a)){return}const i=r.innerHTML;p.current=!0,n(u(i,{fontSize:a.fontSize,fontFamily:a.fontFamily}));const s=t.getContents(),d=a.fill;let c=null,f=!0;for(const t of s.ops){if("string"!=typeof t.insert||"\n"===t.insert){continue}if(null===(e=t.attributes)||void 0===e?void 0:e.gradient){f=!1;break}const n=(null===(o=t.attributes)||void 0===o?void 0:o.color)||d;if(null===c){c=n}else if(n!==c){f=!1;break}}f&&c&&a.set({fill:c})},10)}),t.on("selection-change",o),setQuillContent(t,G(a)),p.current=!0;const g=f.current.closest(".polotno-workspace-inner"),b=null==g?void 0:g.scrollLeft,v=null==g?void 0:g.scrollTop;d?setCursorFromCoords(t,d):t.setSelection(0,0,"api"),g&&void 0!==b&&void 0!==v&&(g.scrollLeft=b,g.scrollTop=v);const y=t.root;h=t=>{const o=t.relatedTarget;(null==o?void 0:o.classList.contains("ql-clipboard"))||(V(o)||quillRef.pendingToolbarInteraction?Q():setTimeout(()=>{quillRef.pendingToolbarInteraction||V(document.activeElement)?Q():(A(),e())},0))},m=()=>{A()},y.addEventListener("blur",h),y.addEventListener("focus",m),i=y,s=e=>{var o,n;const r=t.getSelection();if(!r||0===r.length){return}const i=t.getText(r.index,r.length).replace(/\n$/,""),l=window.getSelection();let s="";if(l&&l.rangeCount>0){const e=l.getRangeAt(0);let t=e.cloneContents(),o=e.startContainer;o&&o.nodeType===Node.TEXT_NODE&&(o=o.parentNode);let n=e.endContainer;if(n&&n.nodeType===Node.TEXT_NODE&&(n=n.parentNode),o&&o===n){let e=o;for(;e&&e!==y&&e.nodeType===Node.ELEMENT_NODE;){const o=e.tagName;if("SPAN"!==o&&"EM"!==o&&"STRONG"!==o&&"U"!==o&&"S"!==o&&"A"!==o){break}const n=e.cloneNode(!1);n.appendChild(t),t=n,e=e.parentNode}}const r=document.createElement("div");r.appendChild(t),s=r.innerHTML}if(null===(o=e.clipboardData)||void 0===o||o.setData("text/plain",i),s){const t='<!DOCTYPE html><html><head><meta charset="utf-8"></head><body>\x3c!--StartFragment--\x3e<div style="white-space: pre-wrap; overflow-wrap: break-word;">'+s+"</div>\x3c!--EndFragment--\x3e</body></html>";null===(n=e.clipboardData)||void 0===n||n.setData("text/html",t)}e.preventDefault()},c=e=>{s&&s(e);const o=t.getSelection();o&&o.length>0&&t.deleteText(o.index,o.length)},i.addEventListener("copy",s),i.addEventListener("cut",c)}catch(g){console.error("RichEditor init failed:",g)}}};return f.current?g():queueMicrotask(g),()=>{o=!0,i&&h&&i.removeEventListener("blur",h),i&&m&&i.removeEventListener("focus",m),A(),i&&s&&c&&(i.removeEventListener("copy",s),i.removeEventListener("cut",c)),r.runInAction(()=>{quillRef.editor.instance=null,quillRef.currentFormat={}}),R(t),delete window.__polotnoQuill}},[]),o.useEffect(()=>i(a,()=>`${a.text}\0${a.fontSize}\0${a.fontFamily}`,()=>{const e=quillRef.editor.instance;if(!e){return}if(p.current){return void(p.current=!1)}const t=e.getSelection();setQuillContent(e,G(a)),p.current=!0,t&&(e.setSelection(t.index,t.length),syncQuillFormatState(e,e.getSelection()))},{fireImmediately:!0}),[]),o.useEffect(()=>i(a,()=>`${a.fontFamily}\0${a.fontSize}\0${a.fontWeight}\0${a.fontStyle}\0${a.lineHeight}\0${a.letterSpacing}\0${s(x(a.text))}`,()=>{const e=f.current;if(!e){return}const t="ltr"===s(x(a.text)),o=computeMarkerVars(a);o&&e.style.setProperty("--rt-number-gap",`${o.numberGap}px`),o&&t?(e.style.setProperty("--rt-bullet-left",`${o.bulletLeft}px`),e.style.setProperty("--rt-bullet-top",`${o.bulletTop}px`),e.style.setProperty("--rt-bullet-fs",`${o.bulletFontSize}px`),e.classList.add("rt-marker-geom")):e.classList.remove("rt-marker-geom")},{fireImmediately:!0}),[]),o.useEffect(()=>{window.addEventListener("blur",e);const t=t=>{var o;const n=t.target;"number"==typeof(null==n?void 0:n.nodeType)&&(null===(o=f.current)||void 0===o?void 0:o.contains(n))||V(n)||quillRef.pendingToolbarInteraction||(A(),e())};return window.addEventListener("mousedown",t),window.addEventListener("touchstart",t),()=>{window.removeEventListener("blur",e),window.removeEventListener("mousedown",t),window.removeEventListener("touchstart",t)}},[]);const h=m(a.fill),g={color:h};h.indexOf("gradient")>=0&&(g["--polotno-gradient"]=h,g.color="transparent"),a.strokeWidth>0&&(g.WebkitTextStroke=`${a.strokeWidth}px ${S(a.stroke)}`,g.paintOrder="stroke fill");const b=k(a.fill)?S(a.fill):q(a),v=a.shadowEnabled&&!z(a);return t(RichTextContainer,{ref:f,style:Object.assign(Object.assign({},g),{fontSize:a.fontSize,fontFamily:w(a.fontFamily),fontWeight:a.fontWeight,fontStyle:a.fontStyle,"--polotno-text-decoration":a.textDecoration||"none",textTransform:a.textTransform,width:c(a.a.width,a.letterSpacing,a.fontSize),lineHeight:a.lineHeight,letterSpacing:a.letterSpacing*a.fontSize+"px",textAlign:a.align,opacity:Math.max(a.a.opacity,.2),filter:v?N({shadowOffsetX:a.shadowOffsetX,shadowOffsetY:a.shadowOffsetY,shadowBlur:a.shadowBlur,shadowColor:a.shadowColor,shadowOpacity:a.shadowOpacity,rotation:a.a.rotation}):void 0,caretColor:b}),dir:s(x(a.text))})};function V(e){const t=e;return!("function"!=typeof(null==t?void 0:t.closest)||!t.closest(".sketch-picker")&&!t.closest("[data-polotno-keep-focus]")&&!t.closest(".polotno-portal")&&!t.closest(".polotno-toolbar"))}export function setCursorFromCoords(e,t){if(!e||!t){return}const{x:o,y:r}=t;try{let t=null;if(document.caretRangeFromPoint){t=document.caretRangeFromPoint(o,r)}else if(document.caretPositionFromPoint){const e=document.caretPositionFromPoint(o,r);e&&(t=document.createRange(),t.setStart(e.offsetNode,e.offset))}if(t){const o=n.find(t.startContainer,!0);if(o){const n=o.offset(e.scroll)+t.startOffset;return void e.setSelection(n,0,"api")}}}catch(i){}e.setSelection(0,0,"api")}
166
+ `;const W=[...C,...O,"header"];let B=["background","font-weight","color","gradient","font","italic","size","script","strike","underline","text-transform","indent","list","direction",...W];export const setQuillFormats=e=>{B=e};let X=!1;function G(){X||(X=!0,console.warn("[polotno] The Quill 'bold' format is deprecated. Use the numeric 'font-weight' format instead, e.g. quill.format('font-weight', '700') or applyTextFormat({ fontWeight: 700 })."))}function V(e){return e?"700":"400"}const Y=n.import("delta"),U="data-polotno-rich-text";export const createQuill=(t,o)=>{E();const r=new n(t,{toolbar:!1,keyboard:!1,placeholder:(null==o?void 0:o.placeholder)||void 0,clipboard:{matchVisual:!1},formats:B});!function(t){const o=t.format.bind(t),n=t.formatText.bind(t),r=t.getFormat.bind(t);t.format=(e,t,n)=>"bold"===e?(G(),o("font-weight",V(t),n)):o(e,t,n),t.formatText=(t,o,r,i,l)=>{if(r&&"object"==typeof r){if("bold"in r){G();const{bold:l}=r,s=e(r,["bold"]);return n(t,o,Object.assign(Object.assign({},s),{"font-weight":V(l)}),i)}return n(t,o,r,i)}return"bold"===r?(G(),n(t,o,"font-weight",V(i),l)):n(t,o,r,i,l)},t.getFormat=(...e)=>{const t=r(...e);return t&&null!=t["font-weight"]&&!("bold"in t)&&(t.bold=p(t["font-weight"])),t}}(r);const i=(e,t)=>t.compose((new Y).retain(t.length(),{"font-weight":"700"}));r.clipboard.addMatcher("STRONG",i),r.clipboard.addMatcher("B",i);const l=r.clipboard,s=l.onPaste.bind(l);return l.onPaste=(e,t)=>{var o;if(null===(o=t.html)||void 0===o?void 0:o.includes(U)){return Z(r,()=>s(e,t))}const n=l.convert;l.convert=(...e)=>((e,t)=>{for(const o of e.ops){if(o.attributes){for(const e of t){delete o.attributes[e]}}}return e})(n.apply(l,e),W);try{return s(e,t)}finally{l.convert=n}},r};const K=(e,t)=>t.insert(e.data),J=(e,t)=>{const o=t.ops[0];return parseFloat(e.style.textIndent)>0&&"string"==typeof(null==o?void 0:o.insert)&&o.insert.startsWith("\t")?t.compose((new Y).delete(1)):t};function Z(e,t){const{matchers:o}=e.clipboard,n=o.findIndex(([e])=>e===Node.TEXT_NODE),r=o[n];-1!==n&&(o[n]=[Node.TEXT_NODE,K]),o.push([Node.ELEMENT_NODE,J]);try{return t()}finally{o.pop(),-1!==n&&(o[n]=r)}}export const setQuillContent=(e,t)=>{const o=Z(e,()=>e.clipboard.convert({html:"<div class='ql-editor' style='outline: none;'>"+t+"<p><br></p></div>",text:""}));e.setContents(o),e.history.clear()};export const editorHtml=e=>d(Object.assign(Object.assign({},e),{text:h(e.text)}),e.fontFamily);export const RichEditor=({onBlur:e,onChange:n,element:a,clickCoords:d})=>{const f=o.useRef(null),p=o.useRef(!1),h=o.useRef(null),g=o.useRef(void 0),b=()=>`${a.text}\0${a.fontSize}\0${a.fontFamily}`,v=e=>u(e,{fontSize:a.fontSize,fontFamily:a.fontFamily}),y=e=>{setQuillContent(e,editorHtml(a)),h.current=v(e.root.innerHTML),g.current=b()},E=o.useRef(()=>{}),C=()=>{E.current(),e()};o.useLayoutEffect(()=>{let e,t,o=!1,i=null,s=null,c=null,u=null,m=null;const g=()=>{if(!o&&f.current){try{e=createQuill(f.current,{placeholder:q(a.placeholder)}),r.runInAction(()=>{quillRef.editor.instance=e}),quillRef.pendingToolbarInteraction=!1,window.__polotnoQuill=e,F({instance:e,store:a.store,element:a});const o=t=>{t&&syncQuillFormatState(e,t)},g=()=>{var o,r;if(clearTimeout(t),t=void 0,!l(a)){return}let i=e.root;if(i.querySelector(".ql-cursor")){i=i.cloneNode(!0);const e=i.querySelector(".ql-cursor");e.replaceWith(e.textContent.replace(/\uFEFF/g,""))}const s=v(i.innerHTML);if(s===h.current){return}h.current=s,p.current=!0,n(s);const d=e.getContents(),c=a.fill;let u=null,f=!0;for(const e of d.ops){if("string"!=typeof e.insert||"\n"===e.insert){continue}if(null===(o=e.attributes)||void 0===o?void 0:o.gradient){f=!1;break}const t=(null===(r=e.attributes)||void 0===r?void 0:r.color)||c;if(null===u){u=t}else if(t!==u){f=!1;break}}f&&u&&a.set({fill:u})};E.current=()=>{(void 0!==t||e.composition.isComposing)&&g()},e.on("text-change",()=>{const n=$(),r=n&&n.instance===e?n.lastSelection:null;o(e.getSelection()||r),void 0===t&&(t=setTimeout(g,10))}),e.on("selection-change",o),y(e);const b=f.current.closest(".polotno-workspace-inner"),x=null==b?void 0:b.scrollLeft,w=null==b?void 0:b.scrollTop;d?setCursorFromCoords(e,d):e.setSelection(0,0,"api"),b&&void 0!==x&&void 0!==w&&(b.scrollLeft=x,b.scrollTop=w);const k=e.root;u=e=>{const t=e.relatedTarget;(null==t?void 0:t.classList.contains("ql-clipboard"))||(ee(t)||quillRef.pendingToolbarInteraction?I():setTimeout(()=>{quillRef.pendingToolbarInteraction||ee(document.activeElement)?I():(A(),C())},0))},m=()=>{A()},k.addEventListener("blur",u),k.addEventListener("focus",m),i=k,s=t=>{var o,n;const r=e.getSelection();if(!r||0===r.length){return}const i=e.getText(r.index,r.length).replace(/\n$/,""),l=window.getSelection();let s="";if(l&&l.rangeCount>0){const e=l.getRangeAt(0);let t=e.cloneContents(),o=e.startContainer;o&&o.nodeType===Node.TEXT_NODE&&(o=o.parentNode);let n=e.endContainer;if(n&&n.nodeType===Node.TEXT_NODE&&(n=n.parentNode),o&&o===n){let e=o;for(;e&&e!==k&&e.nodeType===Node.ELEMENT_NODE;){const o=e.tagName;if("SPAN"!==o&&"EM"!==o&&"STRONG"!==o&&"U"!==o&&"S"!==o&&"A"!==o){break}const n=e.cloneNode(!1);n.appendChild(t),t=n,e=e.parentNode}}const r=document.createElement("div");r.appendChild(t),s=r.innerHTML}if(null===(o=t.clipboardData)||void 0===o||o.setData("text/plain",i),s){const e=`<!DOCTYPE html><html><head><meta charset="utf-8"></head><body>\x3c!--StartFragment--\x3e<div ${U} style="white-space: pre-wrap; overflow-wrap: break-word;">`+s+"</div>\x3c!--EndFragment--\x3e</body></html>";null===(n=t.clipboardData)||void 0===n||n.setData("text/html",e)}t.preventDefault()},c=t=>{s&&s(t);const o=e.getSelection();o&&o.length>0&&e.deleteText(o.index,o.length)},i.addEventListener("copy",s),i.addEventListener("cut",c)}catch(g){console.error("RichEditor init failed:",g)}}};return f.current?g():queueMicrotask(g),()=>{o=!0,clearTimeout(t),i&&u&&i.removeEventListener("blur",u),i&&m&&i.removeEventListener("focus",m),A(),i&&s&&c&&(i.removeEventListener("copy",s),i.removeEventListener("cut",c)),r.runInAction(()=>{quillRef.editor.instance=null,quillRef.currentFormat={}}),N(e),delete window.__polotnoQuill}},[]),o.useEffect(()=>i(a,b,e=>{const t=quillRef.editor.instance;if(!t){return}if(p.current){return p.current=!1,void(g.current=e)}if(e===g.current){return}const o=t.getSelection();y(t),o&&(t.setSelection(o.index,o.length),syncQuillFormatState(t,t.getSelection()))},{fireImmediately:!0}),[]),o.useEffect(()=>i(a,()=>`${a.fontFamily}\0${a.fontSize}\0${a.fontWeight}\0${a.fontStyle}\0${a.lineHeight}\0${a.letterSpacing}\0${s(x(a.text))}`,()=>{const e=f.current;if(!e){return}const t="ltr"===s(x(a.text)),o=computeMarkerVars(a);o&&e.style.setProperty("--rt-number-gap",`${o.numberGap}px`),o&&t?(e.style.setProperty("--rt-bullet-left",`${o.bulletLeft}px`),e.style.setProperty("--rt-bullet-top",`${o.bulletTop}px`),e.style.setProperty("--rt-bullet-fs",`${o.bulletFontSize}px`),e.classList.add("rt-marker-geom")):e.classList.remove("rt-marker-geom")},{fireImmediately:!0}),[]),o.useEffect(()=>{window.addEventListener("blur",C);const e=e=>{var t;const o=e.target;"number"==typeof(null==o?void 0:o.nodeType)&&(null===(t=f.current)||void 0===t?void 0:t.contains(o))||ee(o)||quillRef.pendingToolbarInteraction||(A(),C())};return window.addEventListener("mousedown",e),window.addEventListener("touchstart",e),()=>{window.removeEventListener("blur",C),window.removeEventListener("mousedown",e),window.removeEventListener("touchstart",e)}},[]);const O=m(a.fill),L={color:O};O.indexOf("gradient")>=0&&(L["--polotno-gradient"]=O,L.color="transparent"),a.strokeWidth>0&&(L.WebkitTextStroke=`${a.strokeWidth}px ${S(a.stroke)}`,L.paintOrder="stroke fill");const R=k(a.fill)?S(a.fill):T(a),j=a.shadowEnabled&&!P(a);return t(RichTextContainer,{ref:f,style:Object.assign(Object.assign({},L),{fontSize:a.fontSize,fontFamily:w(a.fontFamily),fontWeight:a.fontWeight,fontStyle:a.fontStyle,"--polotno-text-decoration":a.textDecoration||"none",textTransform:a.textTransform,width:c(a.a.width,a.letterSpacing,a.fontSize),lineHeight:a.lineHeight,letterSpacing:a.letterSpacing*a.fontSize+"px",textAlign:a.align,opacity:Math.max(a.a.opacity,.2),filter:j?z({shadowOffsetX:a.shadowOffsetX,shadowOffsetY:a.shadowOffsetY,shadowBlur:a.shadowBlur,shadowColor:a.shadowColor,shadowOpacity:a.shadowOpacity,rotation:a.a.rotation}):void 0,caretColor:R}),dir:s(x(a.text))})};function ee(e){const t=e;return!("function"!=typeof(null==t?void 0:t.closest)||!t.closest(".sketch-picker")&&!t.closest("[data-polotno-keep-focus]")&&!t.closest(".polotno-portal")&&!t.closest(".polotno-toolbar"))}export function setCursorFromCoords(e,t){if(!e||!t){return}const{x:o,y:r}=t;try{let t=null;if(document.caretRangeFromPoint){t=document.caretRangeFromPoint(o,r)}else if(document.caretPositionFromPoint){const e=document.caretPositionFromPoint(o,r);e&&(t=document.createRange(),t.setStart(e.offsetNode,e.offset))}if(t){const o=n.find(t.startContainer,!0);if(o){const n=o.offset(e.scroll)+t.startOffset;return void e.setSelection(n,0,"api")}}}catch(i){}e.setSelection(0,0,"api")}
@@ -1 +1 @@
1
- import r from"react";import{isFontLoaded as t}from"../../utils/fonts.js";import{incrementLoader as e}from"../../utils/loader.js";export const useFontSpecsLoader=(n,u,c)=>{const[,s]=r.useReducer(r=>r+1,0),o=u.map(r=>JSON.stringify([r,n.fonts.find(t=>t.fontFamily===r.family)])).join("|"),f=r=>r.every(r=>t(r.family,r.style,r.weight)),i=r.useRef(f(u)),l=r.useRef(null);return r.useLayoutEffect(()=>{if(i.current=f(u),i.current){return}let r=!0;return(async()=>{i.current=!1,s();const t=e(`text font specs ${o}`);await Promise.all(u.map(r=>n.loadFont(r.family,r.style,r.weight,c))),r?(l.current=t,i.current=!0,s()):t()})(),()=>{l.current&&(l.current(),l.current=null),r=!1}},[o]),r.useEffect(()=>{i.current&&setTimeout(()=>{l.current&&(l.current(),l.current=null)})},[i.current]),[i.current]};
1
+ import t from"react";import{isFontLoaded as e,textChars as r}from"../../utils/fonts.js";import{incrementLoader as n}from"../../utils/loader.js";export const useFontSpecsLoader=(u,s,c)=>{const[,o]=t.useReducer(t=>t+1,0),f=s.map(t=>JSON.stringify([t,u.fonts.find(e=>e.fontFamily===t.family)])).join("|")+r(c),i=t=>t.every(t=>e(t.family,t.style,t.weight,c)),[l]=t.useState(()=>i(s)),a=t.useRef(l),m=t.useRef(null);return t.useLayoutEffect(()=>{if(a.current=i(s),a.current){return}let t=!0;return(async()=>{a.current=!1,o();const e=n(`text font specs ${f}`);await Promise.all(s.map(t=>u.loadFont(t.family,t.style,t.weight,c))),t?(m.current=e,a.current=!0,o()):e()})(),()=>{m.current&&(m.current(),m.current=null),t=!1}},[f]),t.useEffect(()=>{a.current&&setTimeout(()=>{m.current&&(m.current(),m.current=null)})},[a.current]),[a.current]};
@@ -1 +1 @@
1
- import{jsx as t,Fragment as e,jsxs as r}from"react/jsx-runtime";import{elementOpacity as o}from"./paint-opacity.js";import n from"react";import{toDisplayColor as i}from"@polotno/core/color";import{observer as a}from"mobx-react-lite";import{Group as l,Path as s,Text as c,TextPath as u}from"react-konva";import{Html as d}from"react-konva-utils";import{nodeAutorun as f}from"../utils/mobx.js";import h from"konva";import{parsePath as g,roundCommands as m}from"svg-round-corners/lib/index.js";import{generateBackgroundShapeFromRects as p,textLinesToRects as x}from"@polotno/core/background-shape";import{useColor as b}from"./use-color.js";import{useWorkspaceStyle as v}from"./workspace-style.js";import{ROLES as w}from"../model/store.js";import{incrementLoader as S}from"../utils/loader.js";import{activeAnchorOf as y,scaledFontSizeAttrs as E,roundedFontSizeAttrs as z,roundedTextDecorationAttrs as k,roundedGeometryPx as R,roundedPosition as F,textMinResizeWidth as O}from"../utils/px.js";import{isFontLoaded as j}from"../utils/fonts.js";import{flags as A}from"../utils/flags.js";import{removeTags as M}from"@polotno/core/text";import{getDir as L,getCurvePath as C,resolveLineHeight as T,normalizeStrokeLineJoin as H}from"@polotno/core/text-html";import{cssFontFamily as P}from"@polotno/core/fonts";import{shadowCastByBackground as W}from"@polotno/core/filters";import{applyOpacityToColor as X}from"@polotno/core/svg";import{FIT_FONT_SIZE_STEP as D,FIT_HEIGHT_EPSILON as Y}from"@polotno/core/fit-text";import{applyFilter as $}from"./apply-filters.js";import{useFadeIn as I}from"./use-fadein.js";import{isTouchDevice as J}from"../utils/screen.js";import{isAlive as N,getParent as B}from"mobx-state-tree";import{getLimitedFontSize as _}from"./text-element/max-font-size.js";import{getOptimalCaretColor as V}from"./text-element/caret-color.js";import{visiblePlaceholder as q}from"./text-element/placeholder.js";import{hasMeasuredHeight as U,resolveTextBoxHeight as Z}from"@polotno/core/text-types";let G;function K(){return G||(G=document.getElementById("polotno-text-style"),G||(G=document.createElement("style"),G.id="polotno-text-style",document.head.appendChild(G)),G)}h._fixTextRendering=!0;const Q={border:"none",padding:"0px",overflow:"hidden",background:"none",outline:"none",resize:"none",overflowWrap:"break-word",whiteSpace:"pre-wrap",userSelect:"text",wordBreak:"normal",textTransform:"none"};export{getDir}from"@polotno/core/text-html";const tt=a(({textNodeRef:e,element:r,onBlur:o,selectAll:i,cursorPosition:a})=>{const[l,s]=n.useState(Q),c=e.current;n.useLayoutEffect(()=>{if(!c){return}const t={};t.width=c.width()-2*c.padding()+"px",t.height=c.height()-2*c.padding()+c.fontSize()*c.lineHeight()+"px",t.fontSize=c.fontSize()+"px",t.lineHeight=c.lineHeight()+.01,t.fontFamily=c.fontFamily(),t.textAlign=c.align(),t.color=c.fill(),t.fontWeight=r.fontWeight,t.fontStyle=r.fontStyle,t.letterSpacing=r.letterSpacing+"em",t.opacity=Math.max(r.a.opacity,.2),t.textTransform=r.textTransform,t.caretColor=V(r);const e=`\n .polotno-input::placeholder {\n color: ${l.color};\n opacity: 0.6;\n }\n `,o=K();o.innerHTML="",o.appendChild(document.createTextNode(e)),JSON.stringify(t)!==JSON.stringify(l)&&s(t)});const u=n.useRef(null);if(n.useLayoutEffect(()=>{var t;const e=u.current;if(!e){return}null===(t=u.current)||void 0===t||t.focus({preventScroll:!0});const r=a||e.value.length;e.selectionStart=e.selectionEnd=r,i&&(null==e||e.select(),document.execCommand("selectAll",!1,void 0))},[]),n.useEffect(()=>{window.addEventListener("blur",o);const t=t=>{var e;(null===(e=u.current)||void 0===e?void 0:e.contains(t.target))||o()};return window.addEventListener("touchstart",t),()=>{window.removeEventListener("blur",o),window.removeEventListener("touchstart",t)}},[]),!c){return null}let d=0;const f=c.textArr.length*c.lineHeight()*c.fontSize(),h=Z(r.a,f);"middle"===r.verticalAlign&&(d=(h-f)/2),"bottom"===r.verticalAlign&&(d=h-f);const g=M(r.text);return t("textarea",{className:"polotno-input",ref:u,dir:L(g),style:Object.assign(Object.assign(Object.assign({},Q),l),{paddingTop:d+"px"}),value:g,onChange:t=>{const e=_({oldText:r.text,newText:t.target.value,element:r});r.set(Object.assign({text:t.target.value},E(r,e)))},placeholder:q(r.placeholder),onBlur:o})}),et=e=>t(d,{children:t(tt,Object.assign({},e))});export const useFontLoader=(t,e,r,o,i)=>{const[a,l]=n.useReducer(t=>t+1,0),s=n.useRef(j(e,r,o)),c=n.useRef(null);return n.useLayoutEffect(()=>{if(s.current=j(e,r,o),s.current){return}let n=!0;return(async()=>{s.current=!1,l();const a=S(`text ${e}`);await t.loadFont(e,r,o,i),n?(c.current=a,s.current=!0,l()):a()})(),()=>{c.current&&(c.current(),c.current=null),n=!1}},[e,r,o]),n.useEffect(()=>{s.current&&setTimeout(()=>{c.current&&(c.current(),c.current=null)})},[s.current]),[s.current]};export const useFontFamiliesLoader=(t,e,r,o,i)=>{const[a,l]=n.useReducer(t=>t+1,0),s=e.join("\0"),c=n.useRef(e.every(t=>j(t,r,o))),u=n.useRef(null);return n.useLayoutEffect(()=>{if(c.current=e.every(t=>j(t,r,o)),c.current){return}let n=!0;return(async()=>{c.current=!1,l();const a=S(`text fonts ${s}`);await Promise.all(e.map(e=>t.loadFont(e,r,o,i))),n?(u.current=a,c.current=!0,l()):a()})(),()=>{u.current&&(u.current(),u.current=null),n=!1}},[s,r,o]),n.useEffect(()=>{c.current&&setTimeout(()=>{u.current&&(u.current(),u.current=null)})},[c.current]),[c.current]};export const getLineHeight=({fontLoaded:t,fontFamily:e,fontSize:r,lineHeight:o})=>n.useMemo(()=>T({fontFamily:e,fontSize:r,lineHeight:o}),[t,e,r,o]);export function usePrevious(t){const e=n.useRef(t),r=n.useRef(t);return n.useMemo(()=>{r.current=e.current,e.current=t},[t]),r.current}function rt(t,e,r=!1){const o=t.fontSize(),n=t.height(),i=M(e.text);let a=e.a.fontSize;t.height(void 0);const l=Math.round(2*e.a.fontSize)-1;for(let s=1;s<l;s++){const o=U(e.a)&&t.height()>e.a.height+Y;let n=i.split("\n").join(" ").split(/[\s-]+/).reduce((t,e)=>(e=e.toLowerCase(),/[\u3000-\u303F\u3040-\u309F\u30A0-\u30FF\uFF00-\uFFEF\u4E00-\u9FAF\uAC00-\uD7AF]/.test(e)?t.concat(e.split("")):t.concat(e)),[]),l=t.textArr.map(t=>t.text.toLowerCase()).join(";");const s=n.find(t=>!l.includes(t)||(l=l.replace(t,""),!1));if(!(o||s&&!r)){break}a-=D,t.fontSize(a)}return t.fontSize(o),t.height(n),a}export{getCurvePath}from"@polotno/core/text-html";export const TextElement=a(({element:a,store:d})=>{const{textOverflowIndicatorStyle:h}=v(),j=n.useRef(null),T=n.useRef(null),D=n.useRef(null),Y=n.useRef([]),_=n.useRef(!0),[,V]=n.useReducer(t=>t+1,0),{editorEnabled:G,selectAll:K}=(t=>{const[e,r]=n.useState(!1),o=n.useRef(!1);return n.useEffect(()=>{var e=!0;return setTimeout(()=>{e&&(t._editModeEnabled&&(o.current=!0),r(!0),setTimeout(()=>{o.current=!1},50))},50),()=>{e=!1}},[]),{editorEnabled:e&&t._editModeEnabled,selectAll:o.current}})(a),[Q,tt]=n.useState(!1),[ot,nt]=n.useState(!1),it=n.useRef(a.a.height),at=n.useRef(0),lt=n.useRef(""),st=n.useRef(0),ct=a.isSelected,ut=usePrevious(ct),{textVerticalResizeEnabled:dt}=A,ft=A.autoDeleteEmptyText,ht=usePrevious(a.fontFamily),[gt,mt]=n.useState([]);n.useEffect(()=>{var t,e;const r=null!==(e=null===(t=j.current)||void 0===t?void 0:t.textArr)&&void 0!==e?e:[];JSON.stringify(r)!==JSON.stringify(gt)&&mt(r)}),n.useEffect(()=>{if(a.a.width||"tablecell"===a.type){return}const t=j.current;t.width(600),a.set({width:1.4*t.getTextWidth()})},[]),n.useEffect(()=>{ut&&!ct&&ft&&""===a.text&&a.removable&&!q(a.placeholder)&&d.deleteElements([a.id])},[ft,a.placeholder,a.removable,a.text,ct,ut]);const pt=()=>{if(a.curveEnabled){const t=j.current;null==t||t.clearCache(),null==t||t.setAttrs({filters:[]});const e=T.current;e&&$(e,a)}else{const t=j.current;t&&$(t,a)}};n.useLayoutEffect(()=>{if(!ot){return f(a,()=>{pt()})}}),n.useEffect(()=>{const t=Y.current;t.length>0&&(Y.current=[],t.forEach(t=>t()))}),n.useEffect(()=>()=>{_.current=!1;const t=Y.current;t.length>0&&(Y.current=[],t.forEach(t=>t()))},[]);let xt=M(a.text);"uppercase"===a.textTransform&&(xt=xt.toUpperCase());const[bt]=useFontLoader(d,a.fontFamily,a.fontStyle,a.fontWeight,a.text||a.placeholder),vt=()=>{if(a.curveEnabled){const t=T.current;return t.getSelfRect().height||t.fontSize()}const t=j.current.clone({height:void 0}),e=Math.ceil(t.fontSize()*t.lineHeight()*t.textArr.length+1);return t.destroy(),e};n.useLayoutEffect(()=>{if(!bt){return}if("tablecell"===a.type){const{textOverflow:t}=A;if("resize"===t){const t=vt(),e=N(a)?B(a,2):null;(null==e?void 0:e.setCellContentHeight)&&e.setCellContentHeight(a.id,t)}else if("change-font-size"===t){const t=j.current;if(t){const e=rt(t,a,A.textSplitAllowed);e!==a.fontSize&&d.history.ignore(()=>{a.set({fontSize:e})})}}return}const{textOverflow:t,textSplitAllowed:e}=A,r=(t,e,r,o)=>{const n=S(`text ${a.id}`),i=()=>{d.history.ignore(t,e,r).then(()=>{_.current?(Y.current.push(n),V()):n()})};o?queueMicrotask(i):i()};if(!U(a)){const t=vt();return void r(()=>{U(a)||a.set({height:t})},void 0,void 0,!0)}if(!d.isPlaying){if("change-font-size"!==t||Q){if("resize"===t){const t=vt();dt&&a.height<t&&!Q&&r(()=>{var e;N(a)&&a.set({height:t}),null===(e=j.current)||void 0===e||e.height(t)},!1,!0),dt||a.height===t||Q||r(()=>{var e;N(a)&&a.set({height:t}),null===(e=j.current)||void 0===e||e.height(t)},!1,!0)}}else{const t=j.current,o=a.curveEnabled?a.fontSize:rt(t,a,e);if(o!==a.fontSize){return void r(()=>{a.set(E(a,o))},!1,!0)}const n=vt();a.height===n||dt||r(()=>{a.set({height:n})},!1,!0)}}}),n.useLayoutEffect(()=>{var t;if(bt&&a.curveEnabled){const e=null===(t=T.current)||void 0===t?void 0:t.getSelfRect().width;if(e){const t=e-a.a.width,r=a.a.rotation*Math.PI/180,o=-t/2*Math.cos(r),n=-t/2*Math.sin(r);a.set({width:e,x:a.a.x+o,y:a.a.y+n})}}},[bt,a.curveEnabled,a.curvePower,a.text,a.fontSize,a.fontFamily,a.fontWeight,a.fontStyle,a.letterSpacing]),n.useLayoutEffect(()=>{const t=j.current;t&&(t.width(t.width()+1e-8),t.width(t.width()-1e-8),t._setTextData(),pt())},[bt]);const wt=n.useRef(null),St=n.useRef(a.width),yt=n.useRef(0),Et=t=>{t.evt.preventDefault();const e=d.selectedShapes.find(t=>t===a);e&&a.contentEditable&&(yt.current=function(t){var e;const r=t.target,o=function(t){var e=t.getAbsoluteTransform().copy();e.invert();var r=t.getStage().getPointerPosition();return e.point(r)}(r),n=r.textArr,i=Math.floor(o.y/(r.fontSize()*r.lineHeight())),a=n.slice(0,i).reduce((t,e)=>t+e.text.length,i),l=null!==(e=n[i])&&void 0!==e?e:n[0];let s=0;return"right"===r.align()?s=r.width()-l.width:"center"===r.align()&&(s=r.width()/2-l.width/2),a+Math.round((o.x-s)/l.width*l.text.length)}(t),a.toggleEditMode())},zt=q(a.placeholder),kt=!xt&&zt?.6:o(a);I(j,kt);const Rt=getLineHeight({fontLoaded:bt,fontFamily:a.fontFamily,fontSize:a.a.fontSize,lineHeight:a.lineHeight}),Ft=a.selectable||d.role===w.ADMIN,Ot=b(a),jt=b(a,a.stroke,"stroke"),At=n.useMemo(()=>a.backgroundEnabled||a.borderSize?a.curveEnabled?function({width:t,height:e,padding:r=0,cornerRadius:o=0}){const n=-r,i=-r,a=t+r,l=e+r,s=g(`M ${n} ${i} L ${a} ${i} L ${a} ${l} L ${n} ${l} Z`);return m(s,o).path}({width:a.a.width,height:a.a.height,cornerRadius:a.backgroundCornerRadius*(a.a.fontSize*Rt*.5),padding:a.backgroundPadding*(a.a.fontSize*Rt*.5)}):function({lines:t,lineHeight:e,width:r,align:o="left",padding:n=0,cornerRadius:i=0}){const a=x({lines:t,lineHeight:e,width:r,align:o});return p({rects:a,padding:n,cornerRadius:i})}({lines:JSON.parse(JSON.stringify(gt)),cornerRadius:a.backgroundCornerRadius*(a.a.fontSize*Rt*.5),lineHeight:Rt*a.a.fontSize,padding:a.backgroundPadding*(a.a.fontSize*Rt*.5),width:a.a.width,align:a.align}):"",[a.backgroundEnabled,a.borderSize,a.curveEnabled,a.backgroundCornerRadius,a.a.fontSize,a.a.height,Rt,a.backgroundPadding,a.a.width,a.align,gt]),Mt=J();let Lt=0;if(!a.curveEnabled){const t=gt.length*Rt*a.a.fontSize,e=Z(a.a,t);"middle"===a.verticalAlign?Lt=(e-t)/2:"bottom"===a.verticalAlign&&(Lt=e-t)}const Ct=a.curveEnabled?C(a.a.width,a.a.height,a.curvePower,a.a.fontSize):"",Tt=bt?P(a.fontFamily):ht===a.fontFamily?"Arial":P(ht),Ht=L(xt),Pt=a.shadowEnabled&&!W(a),Wt={shadowEnabled:a.shadowEnabled&&(W(a)||a.borderSize>0),shadowBlur:a.shadowBlur,shadowOffsetX:a.shadowOffsetX,shadowOffsetY:a.shadowOffsetY,shadowColor:i(a.shadowColor),shadowOpacity:a.shadowOpacity};return r(e,{children:[t(s,Object.assign({ref:D,x:a.a.x,y:a.a.y,rotation:a.a.rotation,hideInExport:!a.showInExport,listening:!1,visible:a.backgroundEnabled||a.borderSize>0,opacity:kt,data:At,fillEnabled:a.backgroundEnabled,fill:X(a.backgroundColor,a.backgroundOpacity),strokeEnabled:a.borderSize>0,stroke:i(a.borderColor),strokeWidth:a.borderSize,lineJoin:a.backgroundCornerRadius>0?"round":"miter",offsetY:-Lt},Wt)),t(s,{data:Ct,stroke:h.stroke,strokeWidth:1,x:a.a.x,y:a.a.y,rotation:a.a.rotation,visible:!1}),t(u,Object.assign({ref:T,visible:a.curveEnabled,data:Ct,text:xt||zt,listening:!1,align:"center",textBaseline:"middle",direction:Ht},Ot,jt,{strokeWidth:a.strokeWidth,lineJoin:H(a.strokeLineJoin),fillAfterStrokeEnabled:!0,fontSize:a.a.fontSize,fontFamily:`${P(a.fontFamily)}, ${P(ht)}`,fontStyle:a.fontStyle+" "+a.fontWeight,textDecoration:a.textDecoration.trim(),letterSpacing:a.letterSpacing*a.a.fontSize,x:a.a.x,y:a.a.y,rotation:a.a.rotation,opacity:a._editModeEnabled?.3:kt,hideInExport:!a.showInExport},Wt,{shadowEnabled:Pt})),t(c,Object.assign({ref:j,id:a.selectable?a.id:void 0,name:a.selectable?"element":"",hideInExport:!a.showInExport,editModeEnabled:a._editModeEnabled,x:a.a.x,y:a.a.y,rotation:a.a.rotation,width:a.a.width,height:U(a.a)?a.a.height:void 0,text:xt||zt,direction:Ht},Ot,jt,{lineJoin:H(a.strokeLineJoin),strokeWidth:a.strokeWidth,fillAfterStrokeEnabled:!0,fontSize:a.a.fontSize,fontFamily:Tt,fontStyle:a.fontStyle+" "+a.fontWeight,textDecoration:a.textDecoration,align:a.align,verticalAlign:a.verticalAlign,draggable:Mt?a.draggable&&ct:a.draggable,preventDefault:!Mt||ct,opacity:a.curveEnabled?0:kt,visible:!a._editModeEnabled,ellipsis:"ellipsis"===A.textOverflow},Wt,{shadowEnabled:Pt,lineHeight:Rt,letterSpacing:a.letterSpacing*a.a.fontSize,listening:!!a.selectable&&Ft,onDragStart:()=>{nt(!0)},onDragMove:t=>{a.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{nt(!1),a.set(F(t.target))},onClick:Et,onTap:Et,onTransformStart:()=>{tt(!0);const t=j.current;it.current=t.height(),St.current=a.a.width,wt.current=t.position(),at.current=t.rotation(),st.current=t.height(),lt.current=y(t)},onTransform:t=>{var e,r;const o=t.target;null===(e=D.current)||void 0===e||e.setAttrs({x:o.x(),y:o.y(),rotation:o.rotation(),scale:o.scale()});const n=lt.current;if("middle-left"===n||"middle-right"===n){const t=o.scaleX(),e=o.width()*t,r=O(St.current,a.a.fontSize);let n=e;e<r&&(n=r,wt.current&&o.position(wt.current)),o.width(n),o.scaleX(1),o.scaleY(1);let i=vt();if("ellipsis"===A.textOverflow){i=it.current}else{const t=Math.max(i,it.current);o.height(t),a.set({height:o.height()})}const l=A.textVerticalResizeEnabled?Math.max(i,it.current):vt();a.set({x:o.x(),width:o.width(),rotation:o.rotation(),height:l}),o.skewX(0),o.skewY(0),pt()}if("top-center"===n||"bottom-center"===n){const e="resize"===A.textOverflow?vt():Rt*a.a.fontSize,r=t.target.height()*t.target.scaleY();if(r<e){if(t.target.height(e),wt.current){if("top-center"===lt.current){const r=at.current*Math.PI/180,o=st.current-e;t.target.x(wt.current.x-o*Math.sin(r)),t.target.y(wt.current.y+o*Math.cos(r))}else{t.target.position(wt.current)}}}else{t.target.height(r)}t.target.scaleY(1),t.target.scaleX(1),t.target.rotation(at.current),t.target.skewX(0),t.target.skewY(0),st.current=Math.max(e,r)}wt.current=t.target.position();const i=t.target.scaleX();null===(r=D.current)||void 0===r||r.setAttrs({scaleX:1,scaleY:1}),t.target.scaleX(1),t.target.scaleY(1),a.set({fontSize:a.a.fontSize*i,width:t.target.width()*i,x:t.target.x(),y:t.target.y(),rotation:t.target.rotation(),height:t.target.height()*i,shadowBlur:a.shadowBlur*i,shadowOffsetX:a.shadowOffsetX*i,shadowOffsetY:a.shadowOffsetY*i,strokeWidth:a.strokeWidth*i,borderSize:a.borderSize*i})},onTransformEnd:t=>{var e;const r=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1),a.set(Object.assign(Object.assign({},z(a,a.fontSize*r)),{width:Math.ceil(t.target.width()*r),x:R(t.target.x()),y:R(t.target.y()),rotation:R(t.target.rotation()),height:R(t.target.height()*r)})),null===(e=D.current)||void 0===e||e.setAttrs({scaleX:1,scaleY:1}),tt(!1)}})),G&&a.contentEditable&&t(l,{x:a.a.x,y:a.a.y,rotation:a.a.rotation,children:t(et,{textNodeRef:j,element:a,selectAll:K,cursorPosition:yt.current,onBlur:()=>{a.set(k(a)),a.toggleEditMode(!1)}})})]})});
1
+ import{jsx as t,Fragment as e,jsxs as r}from"react/jsx-runtime";import{elementOpacity as o}from"./paint-opacity.js";import n from"react";import{toDisplayColor as i}from"@polotno/core/color";import{observer as a}from"mobx-react-lite";import{Group as l,Path as s,Text as c,TextPath as u}from"react-konva";import{Html as d}from"react-konva-utils";import{nodeAutorun as f}from"../utils/mobx.js";import h from"konva";import{parsePath as g,roundCommands as m}from"svg-round-corners/lib/index.js";import{generateBackgroundShapeFromRects as p,textLinesToRects as x}from"@polotno/core/background-shape";import{useColor as b}from"./use-color.js";import{useWorkspaceStyle as v}from"./workspace-style.js";import{ROLES as w}from"../model/store.js";import{incrementLoader as S}from"../utils/loader.js";import{activeAnchorOf as y,scaledFontSizeAttrs as E,roundedFontSizeAttrs as z,roundedTextDecorationAttrs as k,roundedGeometryPx as R,roundedPosition as F,textMinResizeWidth as O}from"../utils/px.js";import{isFontLoaded as j}from"../utils/fonts.js";import{flags as A}from"../utils/flags.js";import{removeTags as M}from"@polotno/core/text";import{getDir as L,getCurvePath as C,resolveLineHeight as T,normalizeStrokeLineJoin as H}from"@polotno/core/text-html";import{cssFontFamily as P}from"@polotno/core/fonts";import{shadowCastByBackground as W}from"@polotno/core/filters";import{applyOpacityToColor as X}from"@polotno/core/svg";import{FIT_FONT_SIZE_STEP as D,fitHeightLimit as Y}from"@polotno/core/fit-text";import{applyFilter as $}from"./apply-filters.js";import{useFadeIn as I}from"./use-fadein.js";import{isTouchDevice as J}from"../utils/screen.js";import{isAlive as N,getParent as B}from"mobx-state-tree";import{getLimitedFontSize as _}from"./text-element/max-font-size.js";import{getOptimalCaretColor as V}from"./text-element/caret-color.js";import{visiblePlaceholder as q}from"./text-element/placeholder.js";import{hasMeasuredHeight as U,resolveTextBoxHeight as Z}from"@polotno/core/text-types";let G;function K(){return G||(G=document.getElementById("polotno-text-style"),G||(G=document.createElement("style"),G.id="polotno-text-style",document.head.appendChild(G)),G)}h._fixTextRendering=!0;const Q={border:"none",padding:"0px",overflow:"hidden",background:"none",outline:"none",resize:"none",overflowWrap:"break-word",whiteSpace:"pre-wrap",userSelect:"text",wordBreak:"normal",textTransform:"none"};export{getDir}from"@polotno/core/text-html";const tt=a(({textNodeRef:e,element:r,onBlur:o,selectAll:i,cursorPosition:a})=>{const[l,s]=n.useState(Q),c=e.current;n.useLayoutEffect(()=>{if(!c){return}const t={};t.width=c.width()-2*c.padding()+"px",t.height=c.height()-2*c.padding()+c.fontSize()*c.lineHeight()+"px",t.fontSize=c.fontSize()+"px",t.lineHeight=c.lineHeight()+.01,t.fontFamily=c.fontFamily(),t.textAlign=c.align(),t.color=c.fill(),t.fontWeight=r.fontWeight,t.fontStyle=r.fontStyle,t.letterSpacing=r.letterSpacing+"em",t.opacity=Math.max(r.a.opacity,.2),t.textTransform=r.textTransform,t.caretColor=V(r);const e=`\n .polotno-input::placeholder {\n color: ${l.color};\n opacity: 0.6;\n }\n `,o=K();o.innerHTML="",o.appendChild(document.createTextNode(e)),JSON.stringify(t)!==JSON.stringify(l)&&s(t)});const u=n.useRef(null);if(n.useLayoutEffect(()=>{var t;const e=u.current;if(!e){return}null===(t=u.current)||void 0===t||t.focus({preventScroll:!0});const r=a||e.value.length;e.selectionStart=e.selectionEnd=r,i&&(null==e||e.select(),document.execCommand("selectAll",!1,void 0))},[]),n.useEffect(()=>{window.addEventListener("blur",o);const t=t=>{var e;(null===(e=u.current)||void 0===e?void 0:e.contains(t.target))||o()};return window.addEventListener("touchstart",t),()=>{window.removeEventListener("blur",o),window.removeEventListener("touchstart",t)}},[]),!c){return null}let d=0;const f=c.textArr.length*c.lineHeight()*c.fontSize(),h=Z(r.a,f);"middle"===r.verticalAlign&&(d=(h-f)/2),"bottom"===r.verticalAlign&&(d=h-f);const g=M(r.text);return t("textarea",{className:"polotno-input",ref:u,dir:L(g),style:Object.assign(Object.assign(Object.assign({},Q),l),{paddingTop:d+"px"}),value:g,onChange:t=>{const e=_({oldText:r.text,newText:t.target.value,element:r});r.set(Object.assign({text:t.target.value},E(r,e)))},placeholder:q(r.placeholder),onBlur:o})}),et=e=>t(d,{children:t(tt,Object.assign({},e))});export const useFontLoader=(t,e,r,o,i)=>{const[a,l]=n.useReducer(t=>t+1,0),s=n.useRef(j(e,r,o)),c=n.useRef(null);return n.useLayoutEffect(()=>{if(s.current=j(e,r,o),s.current){return}let n=!0;return(async()=>{s.current=!1,l();const a=S(`text ${e}`);await t.loadFont(e,r,o,i),n?(c.current=a,s.current=!0,l()):a()})(),()=>{c.current&&(c.current(),c.current=null),n=!1}},[e,r,o]),n.useEffect(()=>{s.current&&setTimeout(()=>{c.current&&(c.current(),c.current=null)})},[s.current]),[s.current]};export const useFontFamiliesLoader=(t,e,r,o,i)=>{const[a,l]=n.useReducer(t=>t+1,0),s=e.join("\0"),c=n.useRef(e.every(t=>j(t,r,o))),u=n.useRef(null);return n.useLayoutEffect(()=>{if(c.current=e.every(t=>j(t,r,o)),c.current){return}let n=!0;return(async()=>{c.current=!1,l();const a=S(`text fonts ${s}`);await Promise.all(e.map(e=>t.loadFont(e,r,o,i))),n?(u.current=a,c.current=!0,l()):a()})(),()=>{u.current&&(u.current(),u.current=null),n=!1}},[s,r,o]),n.useEffect(()=>{c.current&&setTimeout(()=>{u.current&&(u.current(),u.current=null)})},[c.current]),[c.current]};export const getLineHeight=({fontLoaded:t,fontFamily:e,fontSize:r,lineHeight:o})=>n.useMemo(()=>T({fontFamily:e,fontSize:r,lineHeight:o}),[t,e,r,o]);export function usePrevious(t){const e=n.useRef(t),r=n.useRef(t);return n.useMemo(()=>{r.current=e.current,e.current=t},[t]),r.current}function rt(t,e,r=!1){const o=t.fontSize(),n=t.height(),i=M(e.text);let a=e.a.fontSize;t.height(void 0);const l=Math.round(2*e.a.fontSize)-1;for(let s=1;s<l;s++){const o=t.height()>Y(e.a);let n=i.split("\n").join(" ").split(/[\s-]+/).reduce((t,e)=>(e=e.toLowerCase(),/[\u3000-\u303F\u3040-\u309F\u30A0-\u30FF\uFF00-\uFFEF\u4E00-\u9FAF\uAC00-\uD7AF]/.test(e)?t.concat(e.split("")):t.concat(e)),[]),l=t.textArr.map(t=>t.text.toLowerCase()).join(";");const s=n.find(t=>!l.includes(t)||(l=l.replace(t,""),!1));if(!(o||s&&!r)){break}a-=D,t.fontSize(a)}return t.fontSize(o),t.height(n),a}export{getCurvePath}from"@polotno/core/text-html";export const TextElement=a(({element:a,store:d})=>{const{textOverflowIndicatorStyle:h}=v(),j=n.useRef(null),T=n.useRef(null),D=n.useRef(null),Y=n.useRef([]),_=n.useRef(!0),[,V]=n.useReducer(t=>t+1,0),{editorEnabled:G,selectAll:K}=(t=>{const[e,r]=n.useState(!1),o=n.useRef(!1);return n.useEffect(()=>{var e=!0;return setTimeout(()=>{e&&(t._editModeEnabled&&(o.current=!0),r(!0),setTimeout(()=>{o.current=!1},50))},50),()=>{e=!1}},[]),{editorEnabled:e&&t._editModeEnabled,selectAll:o.current}})(a),[Q,tt]=n.useState(!1),[ot,nt]=n.useState(!1),it=n.useRef(a.a.height),at=n.useRef(0),lt=n.useRef(""),st=n.useRef(0),ct=a.isSelected,ut=usePrevious(ct),{textVerticalResizeEnabled:dt}=A,ft=A.autoDeleteEmptyText,ht=usePrevious(a.fontFamily),[gt,mt]=n.useState([]);n.useEffect(()=>{var t,e;const r=null!==(e=null===(t=j.current)||void 0===t?void 0:t.textArr)&&void 0!==e?e:[];JSON.stringify(r)!==JSON.stringify(gt)&&mt(r)}),n.useEffect(()=>{if(a.a.width||"tablecell"===a.type){return}const t=j.current;t.width(600),a.set({width:1.4*t.getTextWidth()})},[]),n.useEffect(()=>{ut&&!ct&&ft&&""===a.text&&a.removable&&!q(a.placeholder)&&d.deleteElements([a.id])},[ft,a.placeholder,a.removable,a.text,ct,ut]);const pt=()=>{if(a.curveEnabled){const t=j.current;null==t||t.clearCache(),null==t||t.setAttrs({filters:[]});const e=T.current;e&&$(e,a)}else{const t=j.current;t&&$(t,a)}};n.useLayoutEffect(()=>{if(!ot){return f(a,()=>{pt()})}}),n.useEffect(()=>{const t=Y.current;t.length>0&&(Y.current=[],t.forEach(t=>t()))}),n.useEffect(()=>()=>{_.current=!1;const t=Y.current;t.length>0&&(Y.current=[],t.forEach(t=>t()))},[]);let xt=M(a.text);"uppercase"===a.textTransform&&(xt=xt.toUpperCase());const[bt]=useFontLoader(d,a.fontFamily,a.fontStyle,a.fontWeight,a.text||a.placeholder),vt=()=>{if(a.curveEnabled){const t=T.current;return t.getSelfRect().height||t.fontSize()}const t=j.current.clone({height:void 0}),e=Math.ceil(t.fontSize()*t.lineHeight()*t.textArr.length+1);return t.destroy(),e};n.useLayoutEffect(()=>{if(!bt){return}if("tablecell"===a.type){const{textOverflow:t}=A;if("resize"===t){const t=vt(),e=N(a)?B(a,2):null;(null==e?void 0:e.setCellContentHeight)&&e.setCellContentHeight(a.id,t)}else if("change-font-size"===t){const t=j.current;if(t){const e=rt(t,a,A.textSplitAllowed);e!==a.fontSize&&d.history.ignore(()=>{a.set({fontSize:e})})}}return}const{textOverflow:t,textSplitAllowed:e}=A,r=(t,e,r,o)=>{const n=S(`text ${a.id}`),i=()=>{d.history.ignore(t,e,r).then(()=>{_.current?(Y.current.push(n),V()):n()})};o?queueMicrotask(i):i()};if(!U(a)){const t=vt();return void r(()=>{U(a)||a.set({height:t})},void 0,void 0,!0)}if(!d.isPlaying){if("change-font-size"!==t||Q){if("resize"===t){const t=vt();dt&&a.height<t&&!Q&&r(()=>{var e;N(a)&&a.set({height:t}),null===(e=j.current)||void 0===e||e.height(t)},!1,!0),dt||a.height===t||Q||r(()=>{var e;N(a)&&a.set({height:t}),null===(e=j.current)||void 0===e||e.height(t)},!1,!0)}}else{const t=j.current,o=a.curveEnabled?a.fontSize:rt(t,a,e);if(o!==a.fontSize){return void r(()=>{a.set(E(a,o))},!1,!0)}const n=vt();a.height===n||dt||r(()=>{a.set({height:n})},!1,!0)}}}),n.useLayoutEffect(()=>{var t;if(bt&&a.curveEnabled){const e=null===(t=T.current)||void 0===t?void 0:t.getSelfRect().width;if(e){const t=e-a.a.width,r=a.a.rotation*Math.PI/180,o=-t/2*Math.cos(r),n=-t/2*Math.sin(r);a.set({width:e,x:a.a.x+o,y:a.a.y+n})}}},[bt,a.curveEnabled,a.curvePower,a.text,a.fontSize,a.fontFamily,a.fontWeight,a.fontStyle,a.letterSpacing]),n.useLayoutEffect(()=>{const t=j.current;t&&(t.width(t.width()+1e-8),t.width(t.width()-1e-8),t._setTextData(),pt())},[bt]);const wt=n.useRef(null),St=n.useRef(a.width),yt=n.useRef(0),Et=t=>{t.evt.preventDefault();const e=d.selectedShapes.find(t=>t===a);e&&a.contentEditable&&(yt.current=function(t){var e;const r=t.target,o=function(t){var e=t.getAbsoluteTransform().copy();e.invert();var r=t.getStage().getPointerPosition();return e.point(r)}(r),n=r.textArr,i=Math.floor(o.y/(r.fontSize()*r.lineHeight())),a=n.slice(0,i).reduce((t,e)=>t+e.text.length,i),l=null!==(e=n[i])&&void 0!==e?e:n[0];let s=0;return"right"===r.align()?s=r.width()-l.width:"center"===r.align()&&(s=r.width()/2-l.width/2),a+Math.round((o.x-s)/l.width*l.text.length)}(t),a.toggleEditMode())},zt=q(a.placeholder),kt=!xt&&zt?.6:o(a);I(j,kt);const Rt=getLineHeight({fontLoaded:bt,fontFamily:a.fontFamily,fontSize:a.a.fontSize,lineHeight:a.lineHeight}),Ft=a.selectable||d.role===w.ADMIN,Ot=b(a),jt=b(a,a.stroke,"stroke"),At=n.useMemo(()=>a.backgroundEnabled||a.borderSize?a.curveEnabled?function({width:t,height:e,padding:r=0,cornerRadius:o=0}){const n=-r,i=-r,a=t+r,l=e+r,s=g(`M ${n} ${i} L ${a} ${i} L ${a} ${l} L ${n} ${l} Z`);return m(s,o).path}({width:a.a.width,height:a.a.height,cornerRadius:a.backgroundCornerRadius*(a.a.fontSize*Rt*.5),padding:a.backgroundPadding*(a.a.fontSize*Rt*.5)}):function({lines:t,lineHeight:e,width:r,align:o="left",padding:n=0,cornerRadius:i=0}){const a=x({lines:t,lineHeight:e,width:r,align:o});return p({rects:a,padding:n,cornerRadius:i})}({lines:JSON.parse(JSON.stringify(gt)),cornerRadius:a.backgroundCornerRadius*(a.a.fontSize*Rt*.5),lineHeight:Rt*a.a.fontSize,padding:a.backgroundPadding*(a.a.fontSize*Rt*.5),width:a.a.width,align:a.align}):"",[a.backgroundEnabled,a.borderSize,a.curveEnabled,a.backgroundCornerRadius,a.a.fontSize,a.a.height,Rt,a.backgroundPadding,a.a.width,a.align,gt]),Mt=J();let Lt=0;if(!a.curveEnabled){const t=gt.length*Rt*a.a.fontSize,e=Z(a.a,t);"middle"===a.verticalAlign?Lt=(e-t)/2:"bottom"===a.verticalAlign&&(Lt=e-t)}const Ct=a.curveEnabled?C(a.a.width,a.a.height,a.curvePower,a.a.fontSize):"",Tt=bt?P(a.fontFamily):ht===a.fontFamily?"Arial":P(ht),Ht=L(xt),Pt=a.shadowEnabled&&!W(a),Wt={shadowEnabled:a.shadowEnabled&&(W(a)||a.borderSize>0),shadowBlur:a.shadowBlur,shadowOffsetX:a.shadowOffsetX,shadowOffsetY:a.shadowOffsetY,shadowColor:i(a.shadowColor),shadowOpacity:a.shadowOpacity};return r(e,{children:[t(s,Object.assign({ref:D,x:a.a.x,y:a.a.y,rotation:a.a.rotation,hideInExport:!a.showInExport,listening:!1,visible:a.backgroundEnabled||a.borderSize>0,opacity:kt,data:At,fillEnabled:a.backgroundEnabled,fill:X(a.backgroundColor,a.backgroundOpacity),strokeEnabled:a.borderSize>0,stroke:i(a.borderColor),strokeWidth:a.borderSize,lineJoin:a.backgroundCornerRadius>0?"round":"miter",offsetY:-Lt},Wt)),t(s,{data:Ct,stroke:h.stroke,strokeWidth:1,x:a.a.x,y:a.a.y,rotation:a.a.rotation,visible:!1}),t(u,Object.assign({ref:T,visible:a.curveEnabled,data:Ct,text:xt||zt,listening:!1,align:"center",textBaseline:"middle",direction:Ht},Ot,jt,{strokeWidth:a.strokeWidth,lineJoin:H(a.strokeLineJoin),fillAfterStrokeEnabled:!0,fontSize:a.a.fontSize,fontFamily:`${P(a.fontFamily)}, ${P(ht)}`,fontStyle:a.fontStyle+" "+a.fontWeight,textDecoration:a.textDecoration.trim(),letterSpacing:a.letterSpacing*a.a.fontSize,x:a.a.x,y:a.a.y,rotation:a.a.rotation,opacity:a._editModeEnabled?.3:kt,hideInExport:!a.showInExport},Wt,{shadowEnabled:Pt})),t(c,Object.assign({ref:j,id:a.selectable?a.id:void 0,name:a.selectable?"element":"",hideInExport:!a.showInExport,editModeEnabled:a._editModeEnabled,x:a.a.x,y:a.a.y,rotation:a.a.rotation,width:a.a.width,height:U(a.a)?a.a.height:void 0,text:xt||zt,direction:Ht},Ot,jt,{lineJoin:H(a.strokeLineJoin),strokeWidth:a.strokeWidth,fillAfterStrokeEnabled:!0,fontSize:a.a.fontSize,fontFamily:Tt,fontStyle:a.fontStyle+" "+a.fontWeight,textDecoration:a.textDecoration,align:a.align,verticalAlign:a.verticalAlign,draggable:Mt?a.draggable&&ct:a.draggable,preventDefault:!Mt||ct,opacity:a.curveEnabled?0:kt,visible:!a._editModeEnabled,ellipsis:"ellipsis"===A.textOverflow},Wt,{shadowEnabled:Pt,lineHeight:Rt,letterSpacing:a.letterSpacing*a.a.fontSize,listening:!!a.selectable&&Ft,onDragStart:()=>{nt(!0)},onDragMove:t=>{a.set({x:t.target.x(),y:t.target.y()})},onDragEnd:t=>{nt(!1),a.set(F(t.target))},onClick:Et,onTap:Et,onTransformStart:()=>{tt(!0);const t=j.current;it.current=t.height(),St.current=a.a.width,wt.current=t.position(),at.current=t.rotation(),st.current=t.height(),lt.current=y(t)},onTransform:t=>{var e,r;const o=t.target;null===(e=D.current)||void 0===e||e.setAttrs({x:o.x(),y:o.y(),rotation:o.rotation(),scale:o.scale()});const n=lt.current;if("middle-left"===n||"middle-right"===n){const t=o.scaleX(),e=o.width()*t,r=O(St.current,a.a.fontSize);let n=e;e<r&&(n=r,wt.current&&o.position(wt.current)),o.width(n),o.scaleX(1),o.scaleY(1);let i=vt();if("ellipsis"===A.textOverflow){i=it.current}else{const t=Math.max(i,it.current);o.height(t),a.set({height:o.height()})}const l=A.textVerticalResizeEnabled?Math.max(i,it.current):vt();a.set({x:o.x(),width:o.width(),rotation:o.rotation(),height:l}),o.skewX(0),o.skewY(0),pt()}if("top-center"===n||"bottom-center"===n){const e="resize"===A.textOverflow?vt():Rt*a.a.fontSize,r=t.target.height()*t.target.scaleY();if(r<e){if(t.target.height(e),wt.current){if("top-center"===lt.current){const r=at.current*Math.PI/180,o=st.current-e;t.target.x(wt.current.x-o*Math.sin(r)),t.target.y(wt.current.y+o*Math.cos(r))}else{t.target.position(wt.current)}}}else{t.target.height(r)}t.target.scaleY(1),t.target.scaleX(1),t.target.rotation(at.current),t.target.skewX(0),t.target.skewY(0),st.current=Math.max(e,r)}wt.current=t.target.position();const i=t.target.scaleX();null===(r=D.current)||void 0===r||r.setAttrs({scaleX:1,scaleY:1}),t.target.scaleX(1),t.target.scaleY(1),a.set({fontSize:a.a.fontSize*i,width:t.target.width()*i,x:t.target.x(),y:t.target.y(),rotation:t.target.rotation(),height:t.target.height()*i,shadowBlur:a.shadowBlur*i,shadowOffsetX:a.shadowOffsetX*i,shadowOffsetY:a.shadowOffsetY*i,strokeWidth:a.strokeWidth*i,borderSize:a.borderSize*i})},onTransformEnd:t=>{var e;const r=t.target.scaleX();t.target.scaleX(1),t.target.scaleY(1),a.set(Object.assign(Object.assign({},z(a,a.fontSize*r)),{width:Math.ceil(t.target.width()*r),x:R(t.target.x()),y:R(t.target.y()),rotation:R(t.target.rotation()),height:R(t.target.height()*r)})),null===(e=D.current)||void 0===e||e.setAttrs({scaleX:1,scaleY:1}),tt(!1)}})),G&&a.contentEditable&&t(l,{x:a.a.x,y:a.a.y,rotation:a.a.rotation,children:t(et,{textNodeRef:j,element:a,selectAll:K,cursorPosition:yt.current,onBlur:()=>{a.set(k(a)),a.toggleEditMode(!1)}})})]})});
package/model/history.js CHANGED
@@ -1 +1 @@
1
- import{types as t,resolvePath as e,onSnapshot as o,getSnapshot as n,applySnapshot as a}from"mobx-state-tree";import{deepEqual as r}from"../utils/deep-equal.js";import{observable as d,when as s}from"mobx";Object.assign(t);export const UndoManager=t.model("UndoManager",{history:t.array(t.frozen()),undoIdx:-1,targetPath:""}).views(t=>({get canUndo(){return t.undoIdx>0},get canRedo(){return t.undoIdx<t.history.length-1}})).actions(t=>{let i,c,u=!1,l=null,h=0;const g=d.box(0);let m=null;const f=()=>g.get()>0;function p(){const t=n(i);return{pages:t.pages,width:t.width,height:t.height,custom:t.custom,audios:t.audios}}function y(t,e,o){let n=!1;const a=t.map(t=>{if(t.id===e){return n=!0,Object.assign(Object.assign({},t),o)}if(!t.children){return t}const a=y(t.children,e,o);return a===t.children?t:(n=!0,Object.assign(Object.assign({},t),{children:a}))});return n?a:t}function S(){const t=p();return m?Object.assign(Object.assign({},t),{pages:t.pages.map(t=>Object.assign(Object.assign({},t),{children:y(t.children,m.id,m.entry)}))}):t}function x(t){const e=i.pages.map(t=>t.id),o=t.pages.map(t=>t.id),n=!r(e,o),d=!r(i.custom,t.custom);n?a(i.pages,t.pages):i.pages.forEach((e,o)=>{a(e,t.pages[o])}),d&&i.set({custom:t.custom}),i.setSize(t.width,t.height)}const U={startTransaction(){g.set(g.get()+1)},endTransaction(t){g.set(Math.max(0,g.get()-1)),t||U.requestAddState(S())},async ignore(t,e=!1,o=!1){o&&await new Promise(t=>setTimeout(t,10));const n=!!h;h&&U.addUndoState();let a=f();U.startTransaction();const r=g.get();try{await t()}catch(i){setTimeout(()=>{throw i})}const d=r!==g.get(),s=!d;U.endTransaction(s),e||a&&!n||U.replaceState(),d||(clearTimeout(h),h=0)},async transaction(t){await U.ignore(t,!0),f()||U.addUndoState()},_whenIdle:t=>s(()=>!f(),{signal:t}),_commitToolChange(t){if(f()){return!1}const e=p();U.requestAddState(S()),U.addUndoState();try{t()}catch(o){throw x(e),o}return U.requestAddState(S()),U.addUndoState(),!0},_startDraft(t,e){h&&U.addUndoState(),m={id:t,entry:e,state:p()}},_draftChange(t){t(),m&&(m.state=p())},_commitDraft(){m&&(h&&U.addUndoState(),l=m.state,m=null,U.addUndoState())},_discardDraft(){m=null},requestAddState(t){l=t,h||f()||(u?u=!1:h=setTimeout(()=>{h=0,clearTimeout(h),f()||U.addUndoState()},100))},addUndoState(){if(u){return void(u=!1)}const e=t.history[t.undoIdx];!r(l,e)&&(clearTimeout(h),h=0,t.history.splice(t.undoIdx+1),t.history.push(l),t.undoIdx=t.history.length-1)},afterCreate(){if(i=e(t,".."),!i){throw new Error("Failed to find target store for UndoManager. Please provide `targetPath` property, or a `targetStore` in the environment")}c=o(i,()=>{m&&(m.state=p()),U.requestAddState(S())}),0===t.history.length&&U.requestAddState(S())},clear(){clearTimeout(h),h=0,t.history.splice(0,t.history.length),t.undoIdx=-1,U.addUndoState()},beforeDestroy(){c()},undo(){var e;if(!(null===(e=i._beforeToolHistory)||void 0===e?void 0:e.call(i,"undo"))){if(h&&U.addUndoState(),f()){const e=t.history[t.undoIdx];return void(e&&x(e))}t.canUndo?(t.undoIdx--,u=!0,x(t.history[t.undoIdx])):console.warn("No undo history. Please check `store.history.canUndo` before calling undo action.")}},redo(){var e;h&&U.addUndoState(),t.canRedo?(null===(e=i._beforeToolHistory)||void 0===e||e.call(i,"redo"),t.undoIdx++,u=!0,x(t.history[t.undoIdx])):console.warn("No redo history. Please check `store.history.canRedo` before calling redo action.")},replaceState(){t.history[t.undoIdx]=S()}};return U});export default UndoManager;
1
+ import{types as t,resolvePath as e,onSnapshot as o,getSnapshot as a,applySnapshot as n}from"mobx-state-tree";import{deepEqual as r}from"../utils/deep-equal.js";import{observable as d,when as s}from"mobx";Object.assign(t);export const UndoManager=t.model("UndoManager",{history:t.array(t.frozen()),undoIdx:-1,targetPath:""}).views(t=>({get canUndo(){return t.undoIdx>0},get canRedo(){return t.undoIdx<t.history.length-1}})).actions(t=>{let i,c,u=!1,l=null,h=0;const g=d.box(0);let m=null;const f=()=>g.get()>0;function p(){const t=a(i);return{pages:t.pages,width:t.width,height:t.height,custom:t.custom,audios:t.audios}}function y(t,e,o){let a=!1;const n=t.map(t=>{if(t.id===e){return a=!0,Object.assign(Object.assign({},t),o)}if(!t.children){return t}const n=y(t.children,e,o);return n===t.children?t:(a=!0,Object.assign(Object.assign({},t),{children:n}))});return a?n:t}function S(){const t=p();return m?Object.assign(Object.assign({},t),{pages:t.pages.map(t=>Object.assign(Object.assign({},t),{children:y(t.children,m.id,m.entry)}))}):t}function x(t){const e=i.pages.map(t=>t.id),o=t.pages.map(t=>t.id),a=!r(e,o),d=!r(i.custom,t.custom);a?n(i.pages,t.pages):i.pages.forEach((e,o)=>{n(e,t.pages[o])}),d&&i.set({custom:t.custom}),n(i.audios,t.audios),i.setSize(t.width,t.height)}const U={startTransaction(){g.set(g.get()+1)},endTransaction(t){g.set(Math.max(0,g.get()-1)),t||U.requestAddState(S())},async ignore(t,e=!1,o=!1){o&&await new Promise(t=>setTimeout(t,10));const a=!!h;h&&U.addUndoState();let n=f();U.startTransaction();const r=g.get();try{await t()}catch(i){setTimeout(()=>{throw i})}const d=r!==g.get(),s=!d;U.endTransaction(s),e||n&&!a||U.replaceState(),d||(clearTimeout(h),h=0)},async transaction(t){await U.ignore(t,!0),f()||U.addUndoState()},_whenIdle:t=>s(()=>!f(),{signal:t}),_commitToolChange(t){if(f()){return!1}const e=p();U.requestAddState(S()),U.addUndoState();try{t()}catch(o){throw x(e),o}return U.requestAddState(S()),U.addUndoState(),!0},_startDraft(t,e){h&&U.addUndoState(),m={id:t,entry:e,state:p()}},_draftChange(t){t(),m&&(m.state=p())},_commitDraft(){m&&(h&&U.addUndoState(),l=m.state,m=null,U.addUndoState())},_discardDraft(){m=null},requestAddState(t){l=t,h||f()||(u?u=!1:h=setTimeout(()=>{h=0,clearTimeout(h),f()||U.addUndoState()},100))},addUndoState(){if(u){return void(u=!1)}const e=t.history[t.undoIdx];!r(l,e)&&(clearTimeout(h),h=0,t.history.splice(t.undoIdx+1),t.history.push(l),t.undoIdx=t.history.length-1)},afterCreate(){if(i=e(t,".."),!i){throw new Error("Failed to find target store for UndoManager. Please provide `targetPath` property, or a `targetStore` in the environment")}c=o(i,()=>{m&&(m.state=p()),U.requestAddState(S())}),0===t.history.length&&U.requestAddState(S())},clear(){clearTimeout(h),h=0,t.history.splice(0,t.history.length),t.undoIdx=-1,U.addUndoState()},beforeDestroy(){c()},undo(){var e;if(!(null===(e=i._beforeToolHistory)||void 0===e?void 0:e.call(i,"undo"))){if(h&&U.addUndoState(),f()){const e=t.history[t.undoIdx];return void(e&&x(e))}t.canUndo?(t.undoIdx--,u=!0,x(t.history[t.undoIdx])):console.warn("No undo history. Please check `store.history.canUndo` before calling undo action.")}},redo(){var e;h&&U.addUndoState(),t.canRedo?(null===(e=i._beforeToolHistory)||void 0===e||e.call(i,"redo"),t.undoIdx++,u=!0,x(t.history[t.undoIdx])):console.warn("No redo history. Please check `store.history.canRedo` before calling redo action.")},replaceState(){t.history[t.undoIdx]=S()}};return U});export default UndoManager;