polotno 3.3.0 → 3.5.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 (123) hide show
  1. package/blueprint/toolbar/text-toolbar.js +2 -2
  2. package/blueprint.polotno.css +297 -297
  3. package/canvas/apply-filters.d.ts +1 -2
  4. package/canvas/apply-filters.js +1 -1
  5. package/canvas/figure-element.js +1 -1
  6. package/canvas/gif-element.js +1 -1
  7. package/canvas/hotkeys.js +1 -1
  8. package/canvas/html-element.js +1 -1
  9. package/canvas/image-element.js +1 -1
  10. package/canvas/line-element.js +1 -1
  11. package/canvas/page.js +1 -1
  12. package/canvas/quill-font-formats.js +1 -1
  13. package/canvas/render-tag-element.d.ts +2 -2
  14. package/canvas/render-tag-element.js +1 -1
  15. package/canvas/rich-editor.d.ts +17 -2
  16. package/canvas/rich-editor.js +28 -5
  17. package/canvas/text-element/fit-font-size.d.ts +3 -6
  18. package/canvas/text-element/fit-font-size.js +1 -1
  19. package/canvas/text-element.d.ts +2 -2
  20. package/canvas/text-element.js +1 -1
  21. package/canvas/tooltip.js +1 -1
  22. package/canvas/use-color.js +1 -1
  23. package/canvas/use-mediabunny-video.js +1 -1
  24. package/canvas/video-element.d.ts +1 -1
  25. package/canvas/video-element.js +1 -1
  26. package/model/group-model.d.ts +1 -2
  27. package/model/group-model.js +1 -1
  28. package/model/page-model.js +1 -1
  29. package/model/store.js +1 -1
  30. package/model/table-model.js +1 -1
  31. package/package.json +34 -48
  32. package/polotno.bundle.js +242 -225
  33. package/primitives/slider-field.d.ts +2 -1
  34. package/primitives/slider-field.js +1 -1
  35. package/primitives/slider.js +1 -1
  36. package/primitives/tabs.d.ts +1 -1
  37. package/side-panel/ai-images-panel.js +1 -1
  38. package/side-panel/draw-panel.js +1 -1
  39. package/side-panel/effect-card.d.ts +1 -1
  40. package/side-panel/effect-card.js +1 -1
  41. package/side-panel/effects-panel.js +1 -1
  42. package/side-panel/image-clip-panel.js +1 -1
  43. package/side-panel/layers-panel.js +1 -1
  44. package/side-panel/select-gif.js +1 -1
  45. package/side-panel/select-image.js +1 -1
  46. package/side-panel/select-svg.js +1 -1
  47. package/side-panel/select-video.js +1 -1
  48. package/toolbar/color-picker.js +1 -1
  49. package/toolbar/figure-toolbar.js +1 -1
  50. package/toolbar/html-toolbar.js +4 -4
  51. package/toolbar/image-toolbar.js +1 -1
  52. package/toolbar/svg-toolbar.js +1 -1
  53. package/toolbar/text-toolbar.js +1 -1
  54. package/toolbar/video-toolbar.js +1 -1
  55. package/ui.css +1 -1
  56. package/utils/background-shape.d.ts +1 -21
  57. package/utils/background-shape.js +1 -1
  58. package/utils/clipboard.js +1 -1
  59. package/utils/css-optimizer.js +1 -1
  60. package/utils/deprecation.d.ts +1 -0
  61. package/utils/deprecation.js +7 -0
  62. package/utils/errors.d.ts +3 -6
  63. package/utils/errors.js +1 -1
  64. package/utils/figure-to-svg.d.ts +1 -650
  65. package/utils/figure-to-svg.js +1 -1
  66. package/utils/filters.d.ts +1 -19
  67. package/utils/filters.js +1 -1
  68. package/utils/flags.d.ts +2 -1
  69. package/utils/fonts.d.ts +2 -3
  70. package/utils/fonts.js +1 -1
  71. package/utils/from-svg.js +1 -1
  72. package/utils/gradient.d.ts +1 -8
  73. package/utils/gradient.js +1 -1
  74. package/utils/html-to-svg/font-inliner.js +1 -1
  75. package/utils/html-to-svg/index.js +1 -1
  76. package/utils/html-to-svg/render-cache.js +1 -1
  77. package/utils/html-to-svg/xhtml.js +1 -1
  78. package/utils/html.js +1 -1
  79. package/utils/html2canvas.d.ts +1 -10
  80. package/utils/html2canvas.js +1 -1
  81. package/utils/image.d.ts +1 -14
  82. package/utils/image.js +1 -1
  83. package/utils/list-marker-geometry.d.ts +1 -14
  84. package/utils/list-marker-geometry.js +1 -1
  85. package/utils/loader.d.ts +1 -1
  86. package/utils/loader.js +1 -1
  87. package/utils/luma.js +1 -1
  88. package/utils/math.d.ts +6 -0
  89. package/utils/math.js +1 -1
  90. package/utils/measure-text.js +1 -1
  91. package/utils/path-to-svg.js +1 -1
  92. package/utils/px.d.ts +54 -0
  93. package/utils/px.js +1 -0
  94. package/utils/reset-style.d.ts +1 -2
  95. package/utils/reset-style.js +1 -1
  96. package/utils/rich-text-html.d.ts +4 -16
  97. package/utils/rich-text-html.js +1 -1
  98. package/utils/svg.d.ts +2 -12
  99. package/utils/svg.js +2 -1
  100. package/utils/text-format-state.d.ts +4 -4
  101. package/utils/text-format-state.js +1 -1
  102. package/utils/text-format.d.ts +11 -2
  103. package/utils/text-format.js +1 -1
  104. package/utils/text-html.d.ts +3 -35
  105. package/utils/text-html.js +1 -1
  106. package/utils/text-types.d.ts +1 -48
  107. package/utils/text-types.js +1 -1
  108. package/utils/text.d.ts +1 -16
  109. package/utils/text.js +1 -1
  110. package/utils/to-html.d.ts +6 -17
  111. package/utils/to-html.js +1 -1
  112. package/utils/to-pptx.js +1 -1
  113. package/utils/to-svg.d.ts +6 -17
  114. package/utils/to-svg.js +1 -1
  115. package/utils/use-svg-colors.d.ts +1 -0
  116. package/utils/use-svg-colors.js +1 -0
  117. package/utils/validate-key.js +1 -1
  118. package/utils/video.d.ts +1 -7
  119. package/utils/video.js +1 -1
  120. package/utils/xml.d.ts +1 -1
  121. package/utils/xml.js +1 -7
  122. /package/utils/{html-to-svg/lru-cache.d.ts → lru-cache.d.ts} +0 -0
  123. /package/utils/{html-to-svg/lru-cache.js → lru-cache.js} +0 -0
package/utils/to-svg.js CHANGED
@@ -1 +1 @@
1
- var t=this&&this.__rest||function(t,e){var n={};for(var o in t){Object.prototype.hasOwnProperty.call(t,o)&&e.indexOf(o)<0&&(n[o]=t[o])}if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(o=Object.getOwnPropertySymbols(t);i<o.length;i++){e.indexOf(o[i])<0&&Object.prototype.propertyIsEnumerable.call(t,o[i])&&(n[o[i]]=t[o[i]])}}return n};import{cropImage as e,getCrop as n,loadImage as o}from"./image.js";import*as i from"./svg.js";import{figureToSvg as r}from"./figure-to-svg.js";import{Effects as l,shapeFilterToCSS as s}from"./filters.js";import{getElementBlurRadius as a}from"../canvas/apply-filters.js";import{removeTags as h,parseHtmlToSegments as c}from"./text.js";import{segmentsToTspans as d,normalizeStrokeLineJoin as f}from"./text-html.js";import{xmlEscape as g}from"./xml.js";import{getCurvePath as p}from"../canvas/text-element.js";import*as u from"./gradient.js";import{normalizeRichTextHtml as m,extractFontFamiliesFromHtml as y}from"./rich-text-html.js";import{bulletMarkerPosition as x,numberMarkerPosition as k}from"./list-marker-geometry.js";import{generateBackgroundShapeFromRects as w,textLinesToRects as b}from"./background-shape.js";export const forEveryNode=(t,e)=>{if(t.children){for(const n of t.children){if(!0===e(n)){break}forEveryNode(n,e)}}if(t.cells){for(const n of t.cells){if(!0===e(n)){break}}}};const $=(t,e,...n)=>({type:t,props:e,children:n||[]});function v(t,e){if(!u.isGradient(t)){return null}const{stops:n,rotation:o}=u.parseColor(t),i=o*Math.PI/180,r=.5-.5*Math.sin(i),l=.5+.5*Math.cos(i),s=.5+.5*Math.sin(i),a=.5-.5*Math.cos(i),h=n.map(({offset:t,color:e})=>$("stop",{offset:100*t+"%","stop-color":e}));return $("linearGradient",{id:e,x1:100*r+"%",y1:100*l+"%",x2:100*s+"%",y2:100*a+"%"},...h)}export function fixRatio(t){var e=(new DOMParser).parseFromString(t,"image/svg+xml");return e.documentElement.setAttribute("preserveAspectRatio","none"),(new XMLSerializer).serializeToString(e)}const S=async t=>{try{const e=await fetch(t);if("undefined"!=typeof Buffer){const t=await e.arrayBuffer(),n=Buffer.from(t).toString("base64");return`data:${e.headers.get("content-type")||"image/png"};base64,${n}`}{const t=await e.blob();return new Promise((e,n)=>{const o=new FileReader;o.onloadend=()=>e(o.result),o.onerror=n,o.readAsDataURL(t)})}}catch(e){return console.error("Error converting URL to data URL:",e),t}},j=async({element:t,page:e,store:n})=>{let{src:r}=t;if("svg"===t.type){const e=await i.urlToString(r);r=i.replaceColors(e,new Map(Object.entries(t.colorsReplace)))}else{r=await S(r)}let l,s,a,h,c="";if(t.flipX||t.flipY){const e=t.flipX?-1:1,n=t.flipY?-1:1,o=t.width/2,i=t.height/2;c=`translate(${o}, ${i}) scale(${e}, ${n}) translate(${-o}, ${-i})`}t.clipSrc&&(l=`clip-img-mask-${t.id}`,s=await S(t.clipSrc)),t.maskSrc&&(a=`mask-img-${t.id}`,h=await S(t.maskSrc));const d=await o(r),f=d.width*t.cropWidth,g=d.height*t.cropHeight,p=t.width/t.height;let m,y;const x=f/g,k="boolean"==typeof t.stretchEnabled&&t.stretchEnabled||"svg"===t.type;k?(m=f,y=g):p>=x?(m=f,y=f/p):(m=g*p,y=g);const w=m/d.width,b=y/d.height,j=m/y>t.width/t.height?t.height/y:t.width/m,O=k?t.width/m:j,H=k?t.height/y:j,W=m*O/w,z=y*H/b;let M=t.cropX*d.width*O,L=t.cropY*d.height*H;t.flipX&&(M=(1-t.cropX-t.cropWidth)*d.width*O),t.flipY&&(L=(1-t.cropY-t.cropHeight)*d.height*H);const E=`clip-${t.id}`,F=t.cornerRadius||0,T=r.replace(/&/g,"&amp;"),C={x:-M,y:-L,width:W,height:z,preserveAspectRatio:"none","clip-path":`url(#${E})`},A=[$("clipPath",{id:E},$("rect",{x:0,y:0,width:t.width,height:t.height,rx:F||void 0,ry:F||void 0}))];l&&s&&A.push($("mask",{id:l,maskUnits:"userSpaceOnUse","mask-type":"alpha"},$("image",{href:s.replace(/&/g,"&amp;"),x:0,y:0,width:t.width,height:t.height,preserveAspectRatio:"none"}))),a&&A.push($("mask",{id:a,maskUnits:"userSpaceOnUse","mask-type":"alpha"},$("image",Object.assign({href:T},C))));let B=T;const R={};a&&h&&(B=h.replace(/&/g,"&amp;"),R.mask=`url(#${a})`);const P={};l&&(P.mask=`url(#${l})`);const D=t.borderSize||0,N=D>0&&u.isGradient(t.borderColor),U=N?`border-grad-${t.id}`:null;if(N){const e=v(t.borderColor,U);e&&A.push(e)}const G=D>0?$("rect",{x:D/2,y:D/2,width:Math.max(0,t.width-D),height:Math.max(0,t.height-D),fill:"none",stroke:N?`url(#${U})`:t.borderColor,"stroke-width":D,rx:Math.max(0,F-D)||void 0,ry:Math.max(0,F-D)||void 0}):null,I=$("g",{},$("defs",{},...A),$("image",Object.assign(Object.assign({href:B},C),R)),G);return $("g",P,c?$("g",{transform:c},I):I)},O=({element:t,type:e})=>{const n={"stroke-width":t.height,stroke:t.color,"stroke-linecap":"round","stroke-linejoin":"round"},o=Object.assign(Object.assign({},n),{fill:t.color}),i=Object.assign(Object.assign({},n),{fill:"none"});return"arrow"===e?$("polyline",Object.assign({points:`${3*t.height},${2*-t.height} 0,0 ${3*t.height},${2*t.height}`},i)):"triangle"===e?$("polygon",Object.assign({points:`${3*t.height},${2*-t.height} 0,0 ${3*t.height},${2*t.height}`},o)):"bar"===e?$("polyline",Object.assign({points:`0,${2*-t.height} 0,${2*t.height}`},i)):"circle"===e?$("circle",Object.assign({cx:2*t.height,cy:0,r:2*t.height},o)):"square"===e?$("polygon",Object.assign({points:`0,${2*-t.height} ${4*t.height},${2*-t.height} ${4*t.height},${2*t.height} 0,${2*t.height}`},o)):null},H={image:j,svg:j,text:async({element:t,page:e,store:n})=>{const o=u.isGradient(t.fill),i=u.isGradient(t.stroke);if(t.curveEnabled){const e=m(t.text,{fontSize:t.fontSize,fontFamily:t.fontFamily}),n=c(e,{fontSize:t.fontSize,fontFamily:t.fontFamily}),r=Math.max(t.fontSize,...n.map(e=>{var n;return null!==(n=e.fontSize)&&void 0!==n?n:t.fontSize})),l=p(t.width,t.height,t.curvePower,r),s=M(t.id||"temp"),a=`curve-path-${s}`,h={fontWeight:t.fontWeight||"normal",fontStyle:t.fontStyle||"normal",fill:t.fill||"black",fontFamily:t.fontFamily,fontSize:t.fontSize},g=d(n,h),u=d(n,h,{omitColors:!0}),y=t.backgroundPadding*(t.fontSize*t.lineHeight*.5),x=t.backgroundEnabled?$("rect",{x:-y,y:-y,width:t.width+2*y,height:t.height+2*y,fill:t.backgroundColor,opacity:t.backgroundOpacity,rx:t.backgroundCornerRadius*(t.fontSize*t.lineHeight*.5),ry:t.backgroundCornerRadius*(t.fontSize*t.lineHeight*.5)}):null,k=[$("path",{id:a,d:l,fill:"none"})],w=t.strokeWidth&&(i||o&&!i);if(o){const e=`curve-fill-grad-${s}`,n=v(t.fill,e);n&&k.push(n)}if(i&&t.strokeWidth){const e=`curve-stroke-grad-${s}`,n=v(t.stroke,e);n&&k.push(n)}if(w){const e={"font-size":t.fontSize+"px","text-anchor":"middle","dominant-baseline":"central","font-family":t.fontFamily,"font-style":t.fontStyle,"font-weight":t.fontWeight,"text-decoration":t.textDecoration||void 0,"letter-spacing":t.letterSpacing*r},n=i?`url(#curve-stroke-grad-${s})`:t.stroke,l=$("text",Object.assign(Object.assign({},e),{fill:n,"stroke-width":t.strokeWidth,stroke:n,"stroke-linejoin":f(t.strokeLineJoin)}),$("textPath",{href:`#${a}`,startOffset:"50%",innerHTML:u})),h=o?`url(#curve-fill-grad-${s})`:t.fill,c=$("text",Object.assign(Object.assign({},e),{fill:h}),$("textPath",{href:`#${a}`,startOffset:"50%",innerHTML:g}));return $("g",{},x,$("defs",{},...k),l,c)}return $("g",{},x,$("defs",{},...k),$("text",{fill:o?`url(#curve-fill-grad-${s})`:t.fill,"font-size":t.fontSize+"px","text-anchor":"middle","dominant-baseline":"central","font-family":t.fontFamily,"font-style":t.fontStyle,"font-weight":t.fontWeight,"text-decoration":t.textDecoration||void 0,"letter-spacing":t.letterSpacing*r,"stroke-width":t.strokeWidth||void 0,stroke:t.strokeWidth?i?`url(#curve-stroke-grad-${s})`:t.stroke:void 0,"stroke-linejoin":t.strokeWidth?f(t.strokeLineJoin):void 0,"paint-order":t.strokeWidth?"stroke fill":void 0},$("textPath",{href:`#${a}`,startOffset:"50%",innerHTML:g})))}let r=null;const l=()=>(r||(r=document.createElement("canvas").getContext("2d")),r),s=(t,e,n,o,i,r=0)=>{const s=l();return s.font=`${i} ${o} ${e}px ${n}`,s.measureText(t).width+Math.max(0,(t?t.length:0)-1)*r*e},a=(e,n,o)=>{let i=n;null!=e.fontSize&&e.fontSize!==t.fontSize&&t.fontSize>0&&(i=e.fontSize*(n/t.fontSize));const r=e.fontFamily||t.fontFamily,l=e.bold?"bold":t.fontWeight||"normal",a=e.italic?"italic":t.fontStyle||"normal";return s(e.text,i,r,l,a,o)},h=/<[a-z][\s\S]*>/i.test(t.text);let y=t.text;!h&&y.includes("\n")&&(y=y.split("\n").map(t=>`<p>${t}</p>`).join(""));const S=m(y,{fontSize:t.fontSize,fontFamily:t.fontFamily}),j={fontSize:t.fontSize,fontFamily:t.fontFamily},O=[],H=(new DOMParser).parseFromString(S,"text/html"),W=H.body.querySelectorAll("p");W.length>0?W.forEach((t,e)=>{const n=t.innerHTML,o=c(n,j);O.push(...o),e<W.length-1&&O.push({text:"\n"})}):O.push(...c(S,j)),"uppercase"===t.textTransform&&O.forEach(t=>{"\n"!==t.text&&(t.text=t.text.toUpperCase())});const z=t=>{const e=[];let n=[];for(const o of t){if("\n"===o.text){n.length>0&&(e.push(n),n=[]),e.push([Object.assign(Object.assign({},o),{text:"\n"})]);continue}const t=o.text.split(/( )/);for(const i of t){""!==i&&(" "===i?(n.length>0&&(e.push(n),n=[]),e.push([Object.assign(Object.assign({},o),{text:" "})])):n.push(Object.assign(Object.assign({},o),{text:i})))}}return n.length>0&&e.push(n),e},L=(t,e,n,o)=>{const i=[[]];let r=0;for(const l of t){if(1===l.length&&"\n"===l[0].text){i.push([]),r=0;continue}const t=l.reduce((t,e)=>t+a(e,n,o),0);1!==l.length||" "!==l[0].text?(r+t>e+.5&&i[i.length-1].length>0&&(i.push([]),r=0),i[i.length-1].push(...l),r+=t):r+t<=e+.5&&(i[i.length-1].push(...l),r+=t)}return i},E=(t,e,n)=>t.reduce((t,o)=>t+a(o,e,n),0),F=(t,e)=>1===e?t:t.map(t=>t.map(t=>t.fontSize?Object.assign(Object.assign({},t),{fontSize:Math.round(t.fontSize*e*1e3)/1e3}):t));if(H.body.querySelector("ul, ol")){const e=[],n=2.1,r=e=>{const n=e.cloneNode(!0);n.querySelectorAll("ul, ol").forEach(t=>t.remove());const o=c(n.innerHTML,j);return"uppercase"===t.textTransform&&o.forEach(t=>{"\n"!==t.text&&(t.text=t.text.toUpperCase())}),o},a=(t,n)=>{for(const o of Array.from(t.children)){const t=o.tagName.toLowerCase();if("ul"===t||"ol"===t){const i="ol"===t;let l=parseInt(o.getAttribute("start")||"1",10)||1;for(const t of Array.from(o.children)){if("li"!==t.tagName.toLowerCase()){continue}const o=t.getAttribute("value");o&&!Number.isNaN(parseInt(o,10))&&(l=parseInt(o,10));const s=i?{text:`${l}.`,isOrdered:!0}:{text:"•",isOrdered:!1};e.push({segments:r(t),depth:n+1,marker:s}),i&&(l+=1),a(t,n+1)}}else{"p"===t||"div"===t?e.push({segments:r(o),depth:0,marker:null}):e.push({segments:c(o.outerHTML,j),depth:0,marker:null})}}};a(H.body,0);const h=o=>{const i=[],r=[];for(const l of e){const e=l.depth*n*o,s=Math.max(1,t.width-e);(0===l.segments.length?[[]]:L(z(l.segments),s,o,t.letterSpacing)).forEach((t,n)=>{i.push(t),r.push({indent:e,marker:0===n?l.marker:null})})}return{L:i,M:r}};let p=t.fontSize,u=[],m=[];for(;;){const e=h(p);u=e.L,m=e.M;const n=Math.max(0,...u.map((e,n)=>m[n].indent+E(e,p,t.letterSpacing))),o=u.length*p*t.lineHeight;if(n<=t.width&&(!t.height||o<=t.height)){break}if(p-=1,p<4){break}}u=F(u,p/t.fontSize);const y=p*t.lineHeight,b=u.length*y;let S=0;"middle"===t.verticalAlign?S=(t.height-b)/2:"bottom"===t.verticalAlign&&(S=t.height-b);const O=p+S,W={fontWeight:t.fontWeight||"normal",fontStyle:t.fontStyle||"normal",fill:t.fill||"black",fontFamily:t.fontFamily,fontSize:p},M=t=>{let e=t.length;for(;e>0&&""===t[e-1].text.trim();){e--}return t.slice(0,e)},T=l(),C=t.fontWeight||"normal",A=t.fontStyle||"normal";T.font=`${A} ${C} ${p}px ${t.fontFamily}`;const B=T.measureText(" ").width,R=m.map((e,n)=>{var o,i,r,l,a;if(!e.marker){return null}const h=O+n*y;let c;if(e.marker.isOrdered){const n=s(e.marker.text,p,t.fontFamily,C,A,t.letterSpacing);c=k(e.indent,h,{markerWidth:n,spaceWidth:B})}else{const t=T.measureText(e.marker.text);c=x(e.indent,h,{ascent:null!==(i=null!==(o=t.fontBoundingBoxAscent)&&void 0!==o?o:t.actualBoundingBoxAscent)&&void 0!==i?i:.8*p,inkRight:null!==(r=t.actualBoundingBoxRight)&&void 0!==r?r:0,inkAscent:null!==(l=t.actualBoundingBoxAscent)&&void 0!==l?l:0,inkDescent:null!==(a=t.actualBoundingBoxDescent)&&void 0!==a?a:0})}return $("tspan",{x:c.x,y:c.y,"letter-spacing":e.marker.isOrdered?t.letterSpacing*p+"px":void 0,innerHTML:g(e.marker.text)})}),P=t=>{const e=[];return u.forEach((n,o)=>{const i=M(n);i.length>0&&e.push($("tspan",{x:m[o].indent,y:O+o*y,innerHTML:d(i,W,{omitColors:t})})),R[o]&&e.push(R[o])}),e};let D=null;if(t.backgroundEnabled){const e=t.backgroundPadding*(p*t.lineHeight*.5),n=t.backgroundCornerRadius*(p*t.lineHeight*.5);if(t.legacyBackground){D=$("rect",{x:-e,y:-e,width:t.width+2*e,height:t.height+2*e,fill:t.backgroundColor,opacity:t.backgroundOpacity,rx:n,ry:n})}else{const o=u.map((e,n)=>{const o=e.length?E(e,p,t.letterSpacing):0,i=n*y;return{left:m[n].indent,right:m[n].indent+o,top:i,bottom:i+y}}).filter(t=>t.right>t.left),i=w({rects:o,padding:e,cornerRadius:n});i&&(D=$("path",{d:i,fill:t.backgroundColor,opacity:t.backgroundOpacity,transform:S?`translate(0,${S})`:void 0}))}}const N=[];if(o){const e=v(t.fill,`text-fill-grad-${t.id}`);e&&N.push(e)}if(i&&t.strokeWidth){const e=v(t.stroke,`text-stroke-grad-${t.id}`);e&&N.push(e)}const U=t.strokeWidth&&(i||o&&!i),G={"font-size":p+"px","text-anchor":"start","font-family":t.fontFamily,"font-style":t.fontStyle,"font-weight":t.fontWeight,"text-decoration":t.textDecoration,"letter-spacing":t.letterSpacing*p+"px"};if(U){const e=P(!0),n=i?`url(#text-stroke-grad-${t.id})`:t.stroke,r=$("text",Object.assign(Object.assign({},G),{fill:n,"stroke-width":t.strokeWidth,stroke:n,"stroke-linejoin":f(t.strokeLineJoin)}),...e.map(t=>$("tspan",t.props,t.props.innerHTML))),l=o?`url(#text-fill-grad-${t.id})`:t.fill,s=o?e:P(!1),a=$("text",Object.assign(Object.assign({},G),{fill:l}),...s.map(t=>$("tspan",t.props,t.props.innerHTML)));return $("g",{},D,N.length>0?$("defs",{},...N):null,r,a)}return $("g",{},D,N.length>0?$("defs",{},...N):null,$("text",Object.assign(Object.assign({},G),{fill:o?`url(#text-fill-grad-${t.id})`:t.fill,"stroke-width":t.strokeWidth||void 0,stroke:t.strokeWidth?t.stroke:void 0,"stroke-linejoin":t.strokeWidth?f(t.strokeLineJoin):void 0,"paint-order":t.strokeWidth?"stroke fill":void 0}),...P(!1)))}let T=t.fontSize;const C=z(O);let A=[];for(;;){A=L(C,t.width,T,t.letterSpacing);const e=Math.max(...A.map(e=>E(e,T,t.letterSpacing)),0),n=A.length*T*t.lineHeight;if(e<=t.width&&n<=t.height){break}if(T-=1,T<4){break}}A=F(A,T/t.fontSize);const B=T*t.lineHeight,R=A.length*B;let P=T;"middle"===t.verticalAlign?P=(t.height-R)/2+T:"bottom"===t.verticalAlign&&(P=t.height-R+T);const D="center"===t.align?"middle":"right"===t.align?"end":"start",N={fontWeight:t.fontWeight||"normal",fontStyle:t.fontStyle||"normal",fill:t.fill||"black",fontFamily:t.fontFamily,fontSize:T},U="center"===t.align?t.width/2:"right"===t.align?t.width:0,G=t=>{let e=t.length;for(;e>0&&""===t[e-1].text.trim();){e--}return t.slice(0,e)},I=A.map((t,e)=>{const n=G(t),o=0===n.length?"​":d(n,N);return $("tspan",{x:U,dy:0===e?0:B,innerHTML:o})}),X=t.backgroundPadding*(T*t.lineHeight*.5),J=t.backgroundCornerRadius*(T*t.lineHeight*.5);let Y=null;if(t.backgroundEnabled){if(t.legacyBackground){Y=$("rect",{x:-X,y:-X,width:t.width+2*X,height:t.height+2*X,fill:t.backgroundColor,opacity:t.backgroundOpacity,rx:J,ry:J})}else{const e=b({lines:A.map(e=>({width:0===e.length?0:E(e,T,t.letterSpacing)})),lineHeight:B,width:t.width,align:"justify"===t.align?"justify":t.align});let n=0;"middle"===t.verticalAlign?n=(t.height-A.length*B)/2:"bottom"===t.verticalAlign&&(n=t.height-A.length*B);const o=w({rects:e,padding:X,cornerRadius:J});o&&(Y=$("path",{d:o,fill:t.backgroundColor,opacity:t.backgroundOpacity,transform:n?`translate(0,${n})`:void 0}))}}const q=[],V=t.strokeWidth&&(i||o&&!i);if(o){const e=`text-fill-grad-${t.id}`,n=v(t.fill,e);n&&q.push(n)}if(i&&t.strokeWidth){const e=`text-stroke-grad-${t.id}`,n=v(t.stroke,e);n&&q.push(n)}if(V){const e=A.map((t,e)=>{const n=G(t),o=d(n,N,{omitColors:!0});return $("tspan",{x:U,dy:0===e?0:B,innerHTML:o})}),n={y:P,"font-size":T+"px","text-anchor":D,"font-family":t.fontFamily,"font-style":t.fontStyle,"font-weight":t.fontWeight,"text-decoration":t.textDecoration,"letter-spacing":t.letterSpacing*T+"px"},r=i?`url(#text-stroke-grad-${t.id})`:t.stroke,l=$("text",Object.assign(Object.assign({},n),{fill:r,"stroke-width":t.strokeWidth,stroke:r,"stroke-linejoin":f(t.strokeLineJoin)}),...e.map(t=>$("tspan",t.props,t.props.innerHTML))),s=o?`url(#text-fill-grad-${t.id})`:t.fill,a=o?e:I,h=$("text",Object.assign(Object.assign({},n),{fill:s}),...a.map(t=>$("tspan",t.props,t.props.innerHTML)));return $("g",{},Y,q.length>0?$("defs",{},...q):null,l,h)}return $("g",{},Y,q.length>0?$("defs",{},...q):null,$("text",{fill:o?`url(#text-fill-grad-${t.id})`:t.fill,y:P,"font-size":T+"px","text-anchor":D,"font-family":t.fontFamily,"font-style":t.fontStyle,"font-weight":t.fontWeight,"text-decoration":t.textDecoration,"letter-spacing":t.letterSpacing*T+"px","stroke-width":t.strokeWidth||void 0,stroke:t.strokeWidth?t.stroke:void 0,"stroke-linejoin":t.strokeWidth?f(t.strokeLineJoin):void 0,"paint-order":t.strokeWidth?"stroke fill":void 0},...I))},line:async({element:t,page:e,store:n})=>$("g",{},$("line",{x1:0,y1:t.height/2,x2:t.width,y2:t.height/2,stroke:t.color,"stroke-width":t.height,"stroke-dasharray":t.dash&&t.dash.length?t.dash.map(e=>e*t.height).join(" "):void 0}),$("g",{transform:`translate(0 ${t.height/2})`},O({element:t,type:t.startHead})),$("g",{transform:`translate(${t.width} ${t.height/2}) rotate(180)`},O({element:t,type:t.endHead}))),figure:async({element:t,page:e,store:n,elementHook:o})=>{let i=function(t){let e=t.replace(/<svg[^>]*>/,"");return e=e.replace(/<\/svg>/,""),e}(r(t));const l=[];if(t.strokeWidth&&u.isGradient(t.stroke)){const e=`figure-stroke-grad-${t.id}`,n=v(t.stroke,e);if(n){l.push(n);const o=t.stroke.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");i=i.replace(new RegExp(`stroke="${o}"`,"g"),`stroke="url(#${e})"`)}}if(u.isGradient(t.fill)){const e=`figure-fill-grad-${t.id}`,n=v(t.fill,e);if(n){l.push(n);const o=t.fill.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");i=i.replace(new RegExp(`fill="${o}"`,"g"),`fill="url(#${e})"`)}}if(l.length>0){const e=$("g",{},$("defs",{},...l),$("g",{innerHTML:i}));return o&&o({dom:e,element:t})||e}const s=$("g",{innerHTML:i});return o&&o({dom:s,element:t})||s},group:async({element:t,page:e,store:n,elementHook:o})=>{const i=await Promise.all(t.children.map(t=>W({element:t,page:e,store:n,elementHook:o}))),r=$("g",{style:{"transform-origin":"top left"}},...i);return o&&o({dom:r,element:t})||r},gif:j,table:async({element:t})=>{t.rows;const e=t.cols,n=t.colWidths,o=t.rowHeights,i=["fontSize","fontFamily","fontWeight","fontStyle","textDecoration","textTransform","fill","align","verticalAlign","lineHeight","letterSpacing","strokeWidth","stroke","cellBackground","cellPadding"],r=(t.cells||[]).map((n,o)=>{const r=Object.assign(Object.assign({},n),{row:Math.floor(o/e),col:o%e});for(const e of i){void 0===r[e]&&(r[e]=t[e])}return r}),l=[],s=(e,i,r,l)=>{let s=0;for(let o=0;o<i;o++){s+=n[o]*t.width}let a=0;for(let n=0;n<e;n++){a+=o[n]*t.height}let h=0;for(let o=i;o<i+l;o++){h+=(n[o]||0)*t.width}let c=0;for(let n=e;n<e+r;n++){c+=(o[n]||0)*t.height}return{x:s,y:a,width:h,height:c}};for(const h of r){if(!h.mergedInto&&h.cellBackground&&"transparent"!==h.cellBackground){s(h.row,h.col,h.colSpan||1,h.colSpan||1);const{x:t,y:e,width:n,height:o}=s(h.row,h.col,h.rowSpan||1,h.colSpan||1);l.push($("rect",{x:t,y:e,width:n,height:o,fill:h.cellBackground}))}}const a=(t,e)=>"dashed"===t?`${4*e},${2*e}`:"dotted"===t?`${e},${e}`:void 0,c=(e,n)=>{var o,i,r,l,s;const a=null===(o=e.borders)||void 0===o?void 0:o[n];return{width:null!==(i=null==a?void 0:a.width)&&void 0!==i?i:t.borderWidth,style:null!==(l=null!==(r=null==a?void 0:a.style)&&void 0!==r?r:t.borderStyle)&&void 0!==l?l:"solid",color:null!==(s=null==a?void 0:a.color)&&void 0!==s?s:t.borderColor}};for(const h of r){if(h.mergedInto){continue}const t=s(h.row,h.col,h.rowSpan||1,h.colSpan||1);if(0===h.row){const e=c(h,"top");"none"!==e.style&&e.width>0&&l.push($("line",{x1:t.x,y1:t.y+e.width/2,x2:t.x+t.width,y2:t.y+e.width/2,stroke:e.color,"stroke-width":e.width,"stroke-dasharray":a(e.style,e.width)}))}if(0===h.col){const e=c(h,"left");"none"!==e.style&&e.width>0&&l.push($("line",{x1:t.x+e.width/2,y1:t.y,x2:t.x+e.width/2,y2:t.y+t.height,stroke:e.color,"stroke-width":e.width,"stroke-dasharray":a(e.style,e.width)}))}{const e=c(h,"bottom");"none"!==e.style&&e.width>0&&l.push($("line",{x1:t.x,y1:t.y+t.height-e.width/2,x2:t.x+t.width,y2:t.y+t.height-e.width/2,stroke:e.color,"stroke-width":e.width,"stroke-dasharray":a(e.style,e.width)}))}{const e=c(h,"right");"none"!==e.style&&e.width>0&&l.push($("line",{x1:t.x+t.width-e.width/2,y1:t.y,x2:t.x+t.width-e.width/2,y2:t.y+t.height,stroke:e.color,"stroke-width":e.width,"stroke-dasharray":a(e.style,e.width)}))}}for(const d of r){if(d.mergedInto){continue}let e=h(d.text||"");if(!e){continue}"uppercase"===d.textTransform&&(e=e.toUpperCase());const i=d.cellPadding||4;let r=0;for(let o=0;o<d.col;o++){r+=n[o]*t.width}let s=0;for(let n=0;n<d.row;n++){s+=o[n]*t.height}const a=n[d.col]*t.width,c=o[d.row]*t.height,f=d.fontSize||12,p=d.align||"left";let u=r+i,m="start";"center"===p?(u=r+a/2,m="middle"):"right"===p&&(u=r+a-i,m="end");let y=s+i+f;const x=d.verticalAlign||"top";"middle"===x?y=s+c/2+f/3:"bottom"===x&&(y=s+c-i),l.push($("text",{x:u,y,"font-size":f,"font-family":d.fontFamily||"Roboto","font-weight":d.fontWeight||"normal","font-style":d.fontStyle||"normal",fill:d.fill||"black","text-anchor":m,"text-decoration":d.textDecoration||"none","letter-spacing":d.letterSpacing?d.letterSpacing*f+"px":void 0},g(e)))}return $("g",{},...l)}};async function W({element:t,page:e,store:n,elementHook:o}){var i;let r=await H[t.type];r||(r=()=>$("g",{}),console.error(`SVG export does not support ${t.type} type...`));const h=await r({element:t,page:e,store:n}),c=[],d=[];if(t.blurEnabled&&c.push(`blur(${a(t)/2}px)`),t.brightnessEnabled&&c.push(`brightness(${100*t.brightness+100}%)`),t.sepiaEnabled&&c.push("sepia()"),t.grayscaleEnabled&&c.push("grayscale()"),t.shadowEnabled&&c.push(`drop-shadow(${t.shadowOffsetX}px ${t.shadowOffsetY}px ${t.shadowBlur}px ${t.shadowColor})`),t.filters){for(const[a,g]of Object.entries(t.filters)){const t=s(l[a],g.intensity);if(t&&(c.push(t.filter),t.html)){const e=t.html.replace(/<svg([^>]*)>/,"<g$1>").replace(/<\/svg>/,"</g>");d.push(e)}}}const f=$("g",{className:"element",id:t.id,transform:"group"!==t.type?`translate(${t.x}, ${t.y}) rotate(${t.rotation})`:void 0,display:null===(i=t.visible)||void 0===i||i?void 0:"none",opacity:t.opacity,style:{"transform-origin":"top left",filter:c.join(" ")}},h,...d);return o&&o({dom:f,element:t})||f}async function z(t){try{const e=await fetch(t),n=e.headers.get("content-type")||"font/ttf",o=await e.arrayBuffer();return`data:${n};base64,${"undefined"!=typeof Buffer?Buffer.from(o).toString("base64"):function(t){const e=new Uint8Array(t);let n="";for(let o=0;o<e.length;o+=32768){const t=e.subarray(o,o+32768);n+=String.fromCharCode(...t)}if("undefined"!=typeof btoa){return btoa(n)}if("undefined"!=typeof Buffer){return Buffer.from(e).toString("base64")}throw new Error("No base64 encoder available in this environment")}(o)}`}catch(e){return console.error("Error embedding font:",e),t}}export async function jsonToDOM({json:t,elementHook:i,fontEmbedding:r="inline"}){const l=[];forEveryNode({children:t.pages},t=>{if(("text"===t.type||"tablecell"===t.type||"table"===t.type)&&(t.fontFamily&&-1===l.indexOf(t.fontFamily)&&l.push(t.fontFamily),t.text)){for(const e of y(t.text)){-1===l.indexOf(e)&&l.push(e)}}});const s="inline"===r?await async function(t,e){return await Promise.all(t.map(async t=>{var n,o;if("Arial"===t){return null}const i=e.find(e=>e.fontFamily===t);if(i){const e=i.styles||(i.url?[{src:`url("${i.url}")`,fontStyle:"normal",fontWeight:"normal"}]:[]),n=await Promise.all(e.map(async e=>{var n,o;const r=(null===(o=null===(n=e.src)||void 0===n?void 0:n.match(/url\("?(.*?)"?\)/))||void 0===o?void 0:o[1])||i.url,l=await z(r);return`@font-face {\n font-family: '${t}';\n font-style: ${e.fontStyle||"normal"};\n font-weight: ${e.fontWeight||"normal"};\n src: url(${l});\n}`}));return $("style",{},n.join("\n"))}{const e=`https://fonts.googleapis.com/css?family=${encodeURIComponent(t)}:bi,normal,i,b`;try{const i=await fetch(e),r=await i.text(),l=null===(o=null===(n=r.match(/url\((.*?)\)/g))||void 0===n?void 0:n.map(t=>t.replace(/url\((.*?)\)/,"$1")))||void 0===o?void 0:o.filter(t=>t.startsWith("https"));if(!(null==l?void 0:l.length)){throw new Error("No font URLs found")}const s=await Promise.all(l.map(async e=>{const n=await z(e),o=(r.match(/@font-face\s*\{[^}]*?\}/g)||[]).find(t=>t.includes(e))||"",i=o.match(/font-style:\s*(.*?)[;\s}]/),l=o.match(/font-weight:\s*(.*?)[;\s}]/),s=i?i[1].trim():"normal",a=l?l[1].trim():"normal";return`@font-face {\n font-family: '${t}';\n font-style: ${s};\n font-weight: ${a};\n src: url(${n});\n}`}));return $("style",{},s.join("\n"))}catch(r){return console.error("Error embedding Google Font:",r),$("defs",{},$("style",{type:"text/css",innerHTML:`@import url('${e}');`.replace(/&/g,"&amp;")}))}}}))}(l,t.fonts):[],a=await Promise.all(t.pages.map(r=>async function({page:t,store:i,elementHook:r}){const l=[...t.children.filter(t=>!t.alwaysOnTop),...t.children.filter(t=>t.alwaysOnTop)],s=await Promise.all(l.map(e=>W({element:e,page:t,store:i,elementHook:r}))),a=t.background.indexOf("url")>=0||t.background.indexOf("http")>=0||t.background.indexOf(".jpg")>=0||t.background.indexOf(".png")>=0||t.background.indexOf(".jpeg")>=0;let h;if(a){const r=await o(t.background);h=await e(t.background,Object.assign({width:i.width,height:i.height,x:0,y:0},n({width:i.width,height:i.height},{width:r.width,height:r.height})))}return $("g",{className:"page",style:{}},a?$("image",{"xlink:href":h,x:0,y:0,width:i.width,height:i.height,preserveAspectRatio:"none"}):$("rect",{x:0,y:0,width:i.width,height:i.height,fill:a?void 0:t.background}),...s)}({page:r,store:t,elementHook:i})));return $("svg",{xmlns:"http://www.w3.org/2000/svg","xmlns:xlink":"http://www.w3.org/1999/xlink",viewBox:`0 0 ${t.width} ${t.height}`,width:t.width,height:t.height},...s,...a)}function M(t){return String(t).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}const L=({dom:e,nestLevel:n=0})=>{if("string"==typeof e){return e}if(!e){return""}const o=e.props,{innerHTML:i}=o,r=t(o,["innerHTML"]),l=Object.keys(r).map(t=>((t,e)=>"object"==typeof e?`${t}="${Object.keys(e).map(t=>`${t}:${e[t]};`).join(" ")}"`:null==e||""===e?"":`${t}="${M(String(e))}"`)(t,r[t])).filter(t=>t&&t.trim().length>0).join(" "),s=" ".repeat(n);return`${s}<${e.type}${l?" "+l:""}>${i||"\n"+e.children.map(t=>L({dom:t,nestLevel:n+1})).join("")}${s}</${e.type}>\n`};export async function jsonToSVG({json:t,elementHook:e,fontEmbedding:n="inline"}){const o=await jsonToDOM({json:t,elementHook:e,fontEmbedding:n});return L({dom:o})}
1
+ var o=this&&this.__rest||function(o,t){var r={};for(var e in o){Object.prototype.hasOwnProperty.call(o,e)&&t.indexOf(e)<0&&(r[e]=o[e])}if(null!=o&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(e=Object.getOwnPropertySymbols(o);n<e.length;n++){t.indexOf(e[n])<0&&Object.prototype.propertyIsEnumerable.call(o,e[n])&&(r[e[n]]=o[e[n]])}}return r};export*from"@polotno/svg-export";import{jsonToSVG as t,jsonToDOM as r}from"@polotno/svg-export";export const jsonToDOM=t=>{var{json:e}=t,n=o(t,["json"]);return r(e,n)};export const jsonToSVG=r=>{var{json:e}=r,n=o(r,["json"]);return t(e,n)};console.warn('"polotno/utils/to-svg" is deprecated, use the "@polotno/svg-export" package instead');
@@ -0,0 +1 @@
1
+ export declare const useSvgColors: (src: string) => string[];
@@ -0,0 +1 @@
1
+ import t from"react";import{urlToString as o,getColors as r}from"@polotno/core/svg";export const useSvgColors=e=>{const[s,c]=t.useState([]);return t.useEffect(()=>{let t=!1;return(async()=>{c([]);const s=await o(e),n=r(s);t||c(n)})(),()=>{t=!0}},[e]),s};
@@ -1 +1 @@
1
- import*as e from"mobx";import{getAPI as o}from"./api.js";import{setRemoveBackgroundEnabled as t}from"./flags.js";const n=e.observable({value:!1}),a=e.observable({value:"v1"});export const ___=()=>a.value;const i=e.observable({value:0});export const ____=()=>i.value;export const isCreditVisible=()=>n.value;const r=e.action(()=>{n.value=!0});let s="";export const getKey=()=>s||"";export const setKey=e=>{s=e||""};let l="undefined"!=typeof window?window.location.origin:"";const c="undefined"!=typeof navigator&&navigator.userAgent.indexOf("Headless")>-1,d="undefined"!=typeof navigator&&navigator.userAgent.indexOf("Electron")>-1;"file://"===l&&c&&(l="headless"),"file://"===l&&d&&(l="electron");const p=`%cPolotno error! Current domain is not allowed. It may lead to unexpected behavior and stop working. Please add "${l}" here: https://polotno.com/cabinet`;let u=fetch;export const __=e=>{u=e};export async function isKeyPaid(n){for(let s=0;s<5;s++){try{const r=await u(o()+"/validate-key",{method:"POST",body:JSON.stringify({key:n,site:location.host,skdVersion:"3.3.0"})});if(e.runInAction(()=>{a.value=r.headers.get("x-api-version")||""}),!n){return console.error("Polotno API is initialized without API key. It may lead to unexpected behavior and stop working. Please create API key here: https://polotno.com/cabinet"),e.runInAction(()=>{i.value=1}),!1}if(200!==r.status){await new Promise(e=>setTimeout(e,3e3));continue}const s=await r.json();return s.is_valid||(console.error("Polotno API key is not valid. Please get new API key here: https://polotno.com/cabinet"),e.runInAction(()=>{i.value=1})),s.is_paid||(console.log("%cPolotno Free Version. For development usage only. https://polotno.com/","background: rgb(0, 161, 255); color: white; padding: 5px; margin: 5px;"),e.runInAction(()=>{0===i.value&&(i.value=2)})),s.is_domain_valid||console.log(p,"background: rgba(247, 101, 68, 1); color: white; padding: 5px; margin: 5px;"),t(s.remove_background_enabled),s.is_paid||!1}catch(r){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(s)&&!e||r()}
1
+ import*as e from"mobx";import{getAPI as o}from"./api.js";import{setRemoveBackgroundEnabled as t}from"./flags.js";const n=e.observable({value:!1}),a=e.observable({value:"v1"});export const ___=()=>a.value;const i=e.observable({value:0});export const ____=()=>i.value;export const isCreditVisible=()=>n.value;const r=e.action(()=>{n.value=!0});let s="";export const getKey=()=>s||"";export const setKey=e=>{s=e||""};let l="undefined"!=typeof window?window.location.origin:"";const c="undefined"!=typeof navigator&&navigator.userAgent.indexOf("Headless")>-1,d="undefined"!=typeof navigator&&navigator.userAgent.indexOf("Electron")>-1;"file://"===l&&c&&(l="headless"),"file://"===l&&d&&(l="electron");const p=`%cPolotno error! Current domain is not allowed. It may lead to unexpected behavior and stop working. Please add "${l}" here: https://polotno.com/cabinet`;let u=fetch;export const __=e=>{u=e};export async function isKeyPaid(n){for(let s=0;s<5;s++){try{const r=await u(o()+"/validate-key",{method:"POST",body:JSON.stringify({key:n,site:location.host,skdVersion:"3.5.0"})});if(e.runInAction(()=>{a.value=r.headers.get("x-api-version")||""}),!n){return console.error("Polotno API is initialized without API key. It may lead to unexpected behavior and stop working. Please create API key here: https://polotno.com/cabinet"),e.runInAction(()=>{i.value=1}),!1}if(200!==r.status){await new Promise(e=>setTimeout(e,3e3));continue}const s=await r.json();return s.is_valid||(console.error("Polotno API key is not valid. Please get new API key here: https://polotno.com/cabinet"),e.runInAction(()=>{i.value=1})),s.is_paid||(console.log("%cPolotno Free Version. For development usage only. https://polotno.com/","background: rgb(0, 161, 255); color: white; padding: 5px; margin: 5px;"),e.runInAction(()=>{0===i.value&&(i.value=2)})),s.is_domain_valid||console.log(p,"background: rgba(247, 101, 68, 1); color: white; padding: 5px; margin: 5px;"),t(s.remove_background_enabled),s.is_paid||!1}catch(r){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(s)&&!e||r()}
package/utils/video.d.ts CHANGED
@@ -1,7 +1 @@
1
- export declare function getVideoSize(url: string): Promise<{
2
- width: number;
3
- height: number;
4
- }>;
5
- export declare function getVideoDuration(url: string): Promise<number>;
6
- export declare function getVideoPreview(videoUrl: any, captureTime?: number): Promise<string>;
7
- export declare function getVideoObjectPreview(video: any, canvas: any, captureTime: any): Promise<unknown>;
1
+ export * from '@polotno/core/video';
package/utils/video.js CHANGED
@@ -1 +1 @@
1
- import{polotnoError as e}from"./errors.js";export async function getVideoSize(t){return new Promise((n,o)=>{const r=document.createElement("video");r.crossOrigin="anonymous",r.src=t,r.addEventListener("loadedmetadata",()=>{const{videoWidth:e,videoHeight:t}=r;n({width:e,height:t})}),r.addEventListener("error",n=>{const r=t.slice(0,100);o(e("VIDEO_FAILED",`Failed to load video: ${r}`,{src:r,reason:"load"}))})})}export async function getVideoDuration(e){return new Promise(t=>{const n=document.createElement("video");n.crossOrigin="anonymous",n.src=e,n.addEventListener("loadedmetadata",()=>{const{duration:e}=n;t(e)})})}export async function getVideoPreview(t,n=5){return new Promise((o,r)=>{var i=document.createElement("video"),d=document.createElement("canvas");d.width=480,d.height=360;var a=d.getContext("2d");i.crossOrigin="anonymous",i.src=t,i.addEventListener("error",n=>{const o=String(t).slice(0,100);r(e("VIDEO_FAILED",`Failed to load video: ${o}`,{src:o,reason:"load"},n))}),i.addEventListener("loadeddata",function(){const e=i.videoWidth/i.videoHeight;d.width=480,d.height=480/e,i.currentTime=n}),i.addEventListener("seeked",function(){a.drawImage(i,0,0,d.width,d.height);try{var e=d.toDataURL();o(e)}catch(t){r(t)}})})}export async function getVideoObjectPreview(e,t,n){return new Promise((o,r)=>{const i=t.getContext("2d"),d=()=>{try{i.drawImage(e,0,0,t.width,t.height);const n=t.toDataURL();o(n),e.removeEventListener("seeked",d)}catch(n){r(n),e.removeEventListener("seeked",d)}};e.addEventListener("seeked",d),e.currentTime=n})}
1
+ export * from '@polotno/core/video';
package/utils/xml.d.ts CHANGED
@@ -1 +1 @@
1
- export declare function xmlEscape(text: string): string;
1
+ export * from '@polotno/core/xml';
package/utils/xml.js CHANGED
@@ -1,7 +1 @@
1
- export function xmlEscape(text) {
2
- return text
3
- .replace(/&/g, '&amp;')
4
- .replace(/</g, '&lt;')
5
- .replace(/>/g, '&gt;')
6
- .replace(/"/g, '&quot;');
7
- }
1
+ export * from '@polotno/core/xml';