polotno 4.20.1 → 4.21.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.
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  export declare const VideosGrid: ({ items, onSelect, loadMore, isLoading, error, getCredit, }: {
3
3
  items: any[];
4
4
  onSelect: (item: any, pos?: any, element?: any) => void;
5
- loadMore: any;
5
+ loadMore?: false | undefined | null | (() => void);
6
6
  isLoading: boolean;
7
7
  error?: any;
8
8
  getCredit?: (item: any) => any;
@@ -1 +1 @@
1
- import{jsx as e,jsxs as n}from"react/jsx-runtime";import{useCallback as r,useRef as t}from"react";import{registerNextDomDrop as i}from"../canvas/page.js";import{Spinner as p}from"../primitives/spinner.js";export const VideosGrid=({items:l,onSelect:a,loadMore:s,isLoading:c,error:d,getCredit:u})=>{const m=t(null),v=r(e=>{c||(m.current&&m.current.disconnect(),m.current=new IntersectionObserver(e=>{e[0].isIntersecting&&s()}),e&&m.current.observe(e))},[c]);if(d){return e("div",{children:d.message})}if(!l||0===l.length){return null}const g=l.filter((e,n)=>n%2==1),x=l.filter((e,n)=>n%2==0);return n("div",{className:"pn:h-full pn:overflow-auto",children:[[g,x].map((n,r)=>e("div",{className:"pn:float-left pn:w-1/2",children:n.map(n=>e(o,{item:n,onClick:()=>a(n),onDragStart:()=>{i((e,r)=>{a(n,e,r)})},onDragEnd:()=>i(null),getCredit:u},n.id))},r)),e("div",{ref:v,className:"pn:clear-both pn:flex pn:justify-center pn:p-12",children:c&&e(p,{className:"pn:size-5 pn:text-muted-foreground"})})]})};const o=({item:r,onClick:i,onDragEnd:p,onDragStart:o,getCredit:l})=>{var a;const s=t(null),c=(null===(a=r.video_files.find(e=>"sd"===e.quality))||void 0===a?void 0:a.link)||"";if(!c){return null}const d=new Date(1e3*r.duration).toISOString();let u;return u=r.duration>3600?d.substring(11,19):d.substring(14,19),e("div",{className:"pn:group/video pn:w-full pn:p-[5px] pn:hover:[&_.video-grid__item-credit]:opacity-100",children:n("div",{className:"pn:relative",draggable:!0,onClick:i,onDragEnd:p,onDragStart:o,onMouseEnter:()=>{var e,n;null===(n=null===(e=s.current)||void 0===e?void 0:e.play())||void 0===n||n.catch(()=>{})},onMouseLeave:()=>{var e;null===(e=s.current)||void 0===e||e.pause(),s.current&&(s.current.currentTime=0)},children:[e("video",{poster:r.video_pictures[0].picture,controls:!1,ref:s,muted:!0,preload:"none",playsInline:!0,className:"pn:block pn:max-h-[300px] pn:min-h-[50px] pn:w-full pn:cursor-pointer pn:rounded-[5px] pn:object-cover pn:shadow-[0_0_5px_rgba(16,22,26,0.3)]",children:e("source",{src:c})}),e("div",{className:"pn:absolute pn:right-2 pn:top-2 pn:flex pn:items-center pn:justify-center pn:rounded-full pn:bg-black/50 pn:px-[7px] pn:py-[2px] pn:text-center pn:text-white",children:e("span",{className:"pn:text-xs",children:u})}),l&&e("div",{className:"video-grid__item-credit pn:absolute pn:inset-x-0 pn:bottom-0 pn:bg-gradient-to-b pn:from-transparent pn:via-black/40 pn:to-black/60 pn:p-[3px] pn:text-center pn:text-[10px] pn:text-white pn:opacity-0 pn:[&_a]:text-white pn:[&_a]:underline",children:l(r)})]})})};
1
+ import{jsx as e,jsxs as n}from"react/jsx-runtime";import{useCallback as r,useRef as t}from"react";import{registerNextDomDrop as i}from"../canvas/page.js";import{Spinner as p}from"../primitives/spinner.js";export const VideosGrid=({items:l,onSelect:a,loadMore:s,isLoading:c,error:d,getCredit:u})=>{const m=t(null),v=r(e=>{c||(m.current&&m.current.disconnect(),m.current=new IntersectionObserver(e=>{e[0].isIntersecting&&s&&s()}),e&&m.current.observe(e))},[c,s]);if(d){return e("div",{children:d.message})}if(!l||0===l.length){return null}const g=l.filter((e,n)=>n%2==1),x=l.filter((e,n)=>n%2==0);return n("div",{className:"pn:h-full pn:overflow-auto",children:[[g,x].map((n,r)=>e("div",{className:"pn:float-left pn:w-1/2",children:n.map(n=>e(o,{item:n,onClick:()=>a(n),onDragStart:()=>{i((e,r)=>{a(n,e,r)})},onDragEnd:()=>i(null),getCredit:u},n.id))},r)),e("div",{ref:v,className:"pn:clear-both pn:flex pn:justify-center pn:p-12",children:c&&e(p,{className:"pn:size-5 pn:text-muted-foreground"})})]})};const o=({item:r,onClick:i,onDragEnd:p,onDragStart:o,getCredit:l})=>{var a;const s=t(null),c=(null===(a=r.video_files.find(e=>"sd"===e.quality))||void 0===a?void 0:a.link)||"";if(!c){return null}const d=new Date(1e3*r.duration).toISOString();let u;return u=r.duration>3600?d.substring(11,19):d.substring(14,19),e("div",{className:"pn:group/video pn:w-full pn:p-[5px] pn:hover:[&_.video-grid__item-credit]:opacity-100",children:n("div",{className:"pn:relative",draggable:!0,onClick:i,onDragEnd:p,onDragStart:o,onMouseEnter:()=>{var e,n;null===(n=null===(e=s.current)||void 0===e?void 0:e.play())||void 0===n||n.catch(()=>{})},onMouseLeave:()=>{var e;null===(e=s.current)||void 0===e||e.pause(),s.current&&(s.current.currentTime=0)},children:[e("video",{poster:r.video_pictures[0].picture,controls:!1,ref:s,muted:!0,preload:"none",playsInline:!0,className:"pn:block pn:max-h-[300px] pn:min-h-[50px] pn:w-full pn:cursor-pointer pn:rounded-[5px] pn:object-cover pn:shadow-[0_0_5px_rgba(16,22,26,0.3)]",children:e("source",{src:c})}),e("div",{className:"pn:absolute pn:right-2 pn:top-2 pn:flex pn:items-center pn:justify-center pn:rounded-full pn:bg-black/50 pn:px-[7px] pn:py-[2px] pn:text-center pn:text-white",children:e("span",{className:"pn:text-xs",children:u})}),l&&e("div",{className:"video-grid__item-credit pn:absolute pn:inset-x-0 pn:bottom-0 pn:bg-gradient-to-b pn:from-transparent pn:via-black/40 pn:to-black/60 pn:p-[3px] pn:text-center pn:text-[10px] pn:text-white pn:opacity-0 pn:[&_a]:text-white pn:[&_a]:underline",children:l(r)})]})})};
@@ -17,5 +17,13 @@ type Props = {
17
17
  export declare const ColoredBox: React.ForwardRefExoticComponent<Omit<any, "ref"> & React.RefAttributes<HTMLDivElement>>;
18
18
  declare let getColorsPreset: (store: StoreType) => string[];
19
19
  export declare function setColorsPresetFunc(func: typeof getColorsPreset): void;
20
+ export type ColorPickerContentProps = {
21
+ value: string;
22
+ onChange: (color: string) => void;
23
+ store: StoreType;
24
+ gradientEnabled: boolean;
25
+ presetColors: string[];
26
+ };
27
+ export declare function setColorPickerContent(component: React.ComponentType<ColorPickerContentProps> | null): void;
20
28
  export declare const ColorPicker: ({ value, onChange, size, store, gradientEnabled, children, style, onOpen, onClose, }: Props) => React.JSX.Element;
21
29
  export default ColorPicker;
@@ -1 +1 @@
1
- var e=this&&this.__rest||function(e,o){var r={};for(var t in e){Object.prototype.hasOwnProperty.call(e,t)&&o.indexOf(t)<0&&(r[t]=e[t])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(t=Object.getOwnPropertySymbols(e);n<t.length;n++){o.indexOf(t[n])<0&&Object.prototype.propertyIsEnumerable.call(e,t[n])&&(r[t[n]]=e[t[n]])}}return r};import{jsx as o,jsxs as r}from"react/jsx-runtime";import t from"react";import{observer as n}from"mobx-react-lite";import{t as l}from"../utils/l10n.js";import{isGradient as s,parseColor as a}from"@polotno/core/gradient";import{sameColors as i}from"@polotno/core/svg";import{formatCmykColor as c,isCmykColor as p,toDisplayColor as d}from"@polotno/core/color";import u,{cmykFromColor as m}from"./sketch.js";import{addStop as h,insertStop as f,readGradient as g,writeGradient as v}from"../utils/gradient-stops.js";import{canRemoveStop as b,reverseStops as C}from"../utils/stops.js";import{StopTrack as x}from"./stop-track.js";import{PolotnoIcon as y}from"../icons/registry.js";import{cn as k,firstSliderValue as w}from"../lib/utils.js";import{NumericInput as E}from"../primitives/numeric-input.js";import{Slider as N}from"../primitives/slider.js";import{TooltipIconButton as j}from"../primitives/tooltip-icon-button.js";import{Popover as O,PopoverContent as P,PopoverTrigger as F}from"../primitives/popover.js";import{Tabs as S,TabsContent as $,TabsList as B,TabsTrigger as R}from"../primitives/tabs.js";export const DEFAULT_COLORS=["#D0021B","#F5A623","#F8E71C","#8B572A","#7ED321","#417505","#BD10E0","#9013FE","#4A90E2","#50E3C2","#B8E986","#000000","#4A4A4A","#9B9B9B","#FFFFFF"].reverse();export const getUsedColors=e=>{const o=[];e.pages.forEach(e=>{e.children.forEach(e=>{e.shadowEnabled&&o.push(e.shadowColor),"text"===e.type&&(o.push(e.fill),e.backgroundEnabled&&o.push(e.backgroundColor),e.strokeWidth&&o.push(e.stroke)),"svg"===e.type&&o.push(...e.colorsReplace.values()),"figure"===e.type&&(o.push(e.fill),e.strokeWidth&&o.push(e.stroke)),"line"===e.type&&o.push(e.color)})});const r=[];return o.forEach(e=>{if(s(e)){const{stops:o}=g(e);r.push(...o.map(e=>e.color))}else{r.push(e)}}),[...new Set(r)]};const z=r=>{var{style:n,color:l,onChange:s}=r,a=e(r,["style","color","onChange"]);const[i,p]=t.useState(l);t.useEffect(()=>{p(l)},[l]);const d=t.useRef(void 0),m=t.useRef(void 0);return o("div",{className:"pn-color-picker-solid",style:n,onMouseDown:e=>{"INPUT"!==e.target.tagName&&e.preventDefault()},children:o(u,Object.assign({color:i},a,{onChange:e=>{const{r:o,g:r,b:t,a:n}=e.rgb,l=e.cmyk?c(e.cmyk):`rgba(${o},${r},${t},${n})`;p(l),m.current=l,d.current||(d.current=window.setTimeout(()=>{d.current=0,s(m.current||l)},50))}}))})},D=({value:e,onChange:n,store:s,preset:i})=>{var u,k;const{rotation:O,stops:P}=g(e),F=t.useId(),[S,$]=t.useState(0),B=Math.min(S,P.length-1),R=t.useRef(null),D=t.useRef(null),A=(e,o=O)=>n(v({rotation:o,stops:e})),I=e=>{$(e.index),A(e.stops)},M=v({rotation:90,stops:P});return t.useLayoutEffect(()=>{const e=D.current,o=e.getContext("2d"),r=o.createLinearGradient(0,0,e.width,0);a(M).stops.forEach(({offset:e,color:o})=>r.addColorStop(e,o)),o.clearRect(0,0,e.width,1),o.fillStyle=r,o.fillRect(0,0,e.width,1)},[M]),r("div",{className:"pn:flex pn:flex-col pn:gap-1 pn:pt-2",children:[o("div",{className:"pn:mx-2.5",children:o(x,{handle:R,store:s,node:null!==(k=null!==(u=s.selectedElements[0])&&void 0!==u?u:s.activePage)&&void 0!==k?k:void 0,label:l("toolbar.colorPicker.stops"),stops:P,selected:B,onSelect:$,onChange:I,insert:f,stopLabel:(e,o)=>`${l("toolbar.colorPicker.stop")} ${o+1}: ${Math.round(100*e.offset)}%`,swatch:e=>{const o=d(e.color);return`linear-gradient(${o}, ${o}), ${L}`},bar:o("canvas",{ref:D,width:512,height:1,"aria-hidden":!0,className:"pn:block pn:size-full",style:{backgroundImage:L}})})}),r("div",{className:"pn:flex pn:items-center pn:gap-1 pn:px-2.5",children:[o(j,{label:l("toolbar.colorPicker.addStop"),onClick:()=>I(h(P)),children:o(y,{name:"action.add",className:"pn:size-4"})}),o(j,{label:l("toolbar.colorPicker.removeStop"),disabled:!b(P),onClick:()=>{var e;return null===(e=R.current)||void 0===e?void 0:e.remove(B)},children:o(y,{name:"action.remove",className:"pn:size-4"})}),o(j,{label:l("toolbar.colorPicker.reverse"),onClick:()=>I({stops:C(P),index:P.length-1-B}),children:o(y,{name:"colorPicker.reverseGradient",className:"pn:size-4"})}),o("label",{id:`${F}-label`,className:"pn:ml-auto pn:text-sm",htmlFor:F,children:l("toolbar.colorPicker.angle")}),r("div",{className:"pn:relative",children:[o(E,{id:F,value:O,min:0,max:360,onValueChange:e=>A(P,e),style:{width:64},className:"pn:pl-1 pn:pr-8"}),o("span",{"aria-hidden":!0,className:"pn:pointer-events-none pn:absolute pn:right-6 pn:top-1/2 pn:-translate-y-1/2 pn:text-sm pn:text-muted-foreground",children:"°"})]})]}),o("div",{className:"pn:px-2.5 pn:py-1",children:o(N,{"aria-labelledby":`${F}-label`,value:[O],min:0,max:360,onValueChange:e=>A(P,Math.round(w(e)))})}),o(z,{color:P[B].color,presetColors:i,onChange:e=>A(P.map((o,r)=>{return{offset:o.offset,color:r===B?e:(t=e,n=o.color,p(t)?p(n)?n:c(m(n)):p(n)?d(n):n)};var t,n}))})]})},A=n(({value:e,onChange:n,preset:a,store:i})=>{const[c,p]=t.useState(s(e)?"gradient":"solid");return o("div",{style:{padding:"5px"},children:r(S,{value:c,onValueChange:e=>p(e),className:"pn:w-full",children:[r(B,{className:"pn:flex pn:w-full pn:flex-row",children:[o(R,{value:"solid",className:"pn:flex-1",children:l("toolbar.colorPicker.solid")}),o(R,{value:"gradient",className:"pn:flex-1",children:l("toolbar.colorPicker.linear")})]}),o($,{value:"solid",className:"pn:w-full",children:o(z,{color:s(e)?g(e).stops[0].color:e,onChange:n,presetColors:a,style:{padding:"0"}})}),o($,{value:"gradient",className:"ember-panel pn:w-full",children:o(D,{value:e,onChange:n,store:i,preset:a})})]})})}),L="url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 8 8'%3E%3Cg fill='rgba(112, 112, 116, 1)' fill-opacity='1'%3E%3Cpath fill-rule='evenodd' d='M0 0h4v4H0V0zm4 4h4v4H4V4z'/%3E%3C/g%3E%3C/svg%3E\")";export const ColoredBox=t.forwardRef(function(r,t){var{size:n=30,background:l,style:s={},className:a,children:i=null}=r,c=e(r,["size","background","style","className","children"]);const p="string"==typeof l?d(l):"transparent",u=p.includes("gradient")?p:`linear-gradient(${p}, ${p}), ${L}`;return o("div",Object.assign({ref:t,role:"button",tabIndex:0,"aria-label":"Pick color",onMouseDown:e=>e.preventDefault(),className:k("pn:flex pn:cursor-pointer pn:items-center pn:justify-center pn:overflow-hidden pn:rounded-md pn:border pn:border-foreground/30",a),style:Object.assign({width:n+"px",height:n+"px",backgroundImage:u},s)},c,{children:i}))});let I=e=>{const o=getUsedColors(e).slice(0,8).filter(e=>!DEFAULT_COLORS.find(o=>i(o,e)));return o.concat(DEFAULT_COLORS.slice(0,16-o.length).reverse())};export function setColorsPresetFunc(e){I=e}export const ColorPicker=({value:e,onChange:n,size:l,store:s,gradientEnabled:a,children:i,style:c,onOpen:p,onClose:d})=>{const u=I(s),[m,h]=t.useState(!1);return r(O,{open:m,onOpenChange:e=>{h(e),e?null==p||p():null==d||d()},children:[o(F,{nativeButton:!1,render:o(ColoredBox,{size:l,background:e,style:c,children:i})}),o(P,{className:"pn:w-[280px] pn:p-0",initialFocus:!1,children:a?o(A,{preset:u,value:e,onChange:n,store:s}):o("div",{style:{padding:"5px"},children:o(z,{color:e,onChange:n,presetColors:u})})})]})};export default ColorPicker;
1
+ var e=this&&this.__rest||function(e,o){var r={};for(var t in e){Object.prototype.hasOwnProperty.call(e,t)&&o.indexOf(t)<0&&(r[t]=e[t])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(t=Object.getOwnPropertySymbols(e);n<t.length;n++){o.indexOf(t[n])<0&&Object.prototype.propertyIsEnumerable.call(e,t[n])&&(r[t[n]]=e[t[n]])}}return r};import{jsx as o,jsxs as r}from"react/jsx-runtime";import t from"react";import{observer as n}from"mobx-react-lite";import{t as l}from"../utils/l10n.js";import{isGradient as s,parseColor as a}from"@polotno/core/gradient";import{sameColors as i}from"@polotno/core/svg";import{formatCmykColor as c,isCmykColor as p,toDisplayColor as d}from"@polotno/core/color";import u,{cmykFromColor as m}from"./sketch.js";import{addStop as h,insertStop as f,readGradient as g,writeGradient as v}from"../utils/gradient-stops.js";import{canRemoveStop as b,reverseStops as C}from"../utils/stops.js";import{StopTrack as x}from"./stop-track.js";import{PolotnoIcon as y}from"../icons/registry.js";import{cn as k,firstSliderValue as w}from"../lib/utils.js";import{NumericInput as E}from"../primitives/numeric-input.js";import{Slider as N}from"../primitives/slider.js";import{TooltipIconButton as j}from"../primitives/tooltip-icon-button.js";import{Popover as O,PopoverContent as P,PopoverTrigger as F}from"../primitives/popover.js";import{Tabs as S,TabsContent as $,TabsList as B,TabsTrigger as R}from"../primitives/tabs.js";export const DEFAULT_COLORS=["#D0021B","#F5A623","#F8E71C","#8B572A","#7ED321","#417505","#BD10E0","#9013FE","#4A90E2","#50E3C2","#B8E986","#000000","#4A4A4A","#9B9B9B","#FFFFFF"].reverse();export const getUsedColors=e=>{const o=[];e.pages.forEach(e=>{e.children.forEach(e=>{e.shadowEnabled&&o.push(e.shadowColor),"text"===e.type&&(o.push(e.fill),e.backgroundEnabled&&o.push(e.backgroundColor),e.strokeWidth&&o.push(e.stroke)),"svg"===e.type&&o.push(...e.colorsReplace.values()),"figure"===e.type&&(o.push(e.fill),e.strokeWidth&&o.push(e.stroke)),"line"===e.type&&o.push(e.color)})});const r=[];return o.forEach(e=>{if(s(e)){const{stops:o}=g(e);r.push(...o.map(e=>e.color))}else{r.push(e)}}),[...new Set(r)]};const z=r=>{var{style:n,color:l,onChange:s}=r,a=e(r,["style","color","onChange"]);const[i,p]=t.useState(l);t.useEffect(()=>{p(l)},[l]);const d=t.useRef(void 0),m=t.useRef(void 0);return o("div",{className:"pn-color-picker-solid",style:n,onMouseDown:e=>{"INPUT"!==e.target.tagName&&e.preventDefault()},children:o(u,Object.assign({color:i},a,{onChange:e=>{const{r:o,g:r,b:t,a:n}=e.rgb,l=e.cmyk?c(e.cmyk):`rgba(${o},${r},${t},${n})`;p(l),m.current=l,d.current||(d.current=window.setTimeout(()=>{d.current=0,s(m.current||l)},50))}}))})},D=({value:e,onChange:n,store:s,preset:i})=>{var u,k;const{rotation:O,stops:P}=g(e),F=t.useId(),[S,$]=t.useState(0),B=Math.min(S,P.length-1),R=t.useRef(null),D=t.useRef(null),A=(e,o=O)=>n(v({rotation:o,stops:e})),I=e=>{$(e.index),A(e.stops)},M=v({rotation:90,stops:P});return t.useLayoutEffect(()=>{const e=D.current,o=e.getContext("2d"),r=o.createLinearGradient(0,0,e.width,0);a(M).stops.forEach(({offset:e,color:o})=>r.addColorStop(e,o)),o.clearRect(0,0,e.width,1),o.fillStyle=r,o.fillRect(0,0,e.width,1)},[M]),r("div",{className:"pn:flex pn:flex-col pn:gap-1 pn:pt-2",children:[o("div",{className:"pn:mx-2.5",children:o(x,{handle:R,store:s,node:null!==(k=null!==(u=s.selectedElements[0])&&void 0!==u?u:s.activePage)&&void 0!==k?k:void 0,label:l("toolbar.colorPicker.stops"),stops:P,selected:B,onSelect:$,onChange:I,insert:f,stopLabel:(e,o)=>`${l("toolbar.colorPicker.stop")} ${o+1}: ${Math.round(100*e.offset)}%`,swatch:e=>{const o=d(e.color);return`linear-gradient(${o}, ${o}), ${L}`},bar:o("canvas",{ref:D,width:512,height:1,"aria-hidden":!0,className:"pn:block pn:size-full",style:{backgroundImage:L}})})}),r("div",{className:"pn:flex pn:items-center pn:gap-1 pn:px-2.5",children:[o(j,{label:l("toolbar.colorPicker.addStop"),onClick:()=>I(h(P)),children:o(y,{name:"action.add",className:"pn:size-4"})}),o(j,{label:l("toolbar.colorPicker.removeStop"),disabled:!b(P),onClick:()=>{var e;return null===(e=R.current)||void 0===e?void 0:e.remove(B)},children:o(y,{name:"action.remove",className:"pn:size-4"})}),o(j,{label:l("toolbar.colorPicker.reverse"),onClick:()=>I({stops:C(P),index:P.length-1-B}),children:o(y,{name:"colorPicker.reverseGradient",className:"pn:size-4"})}),o("label",{id:`${F}-label`,className:"pn:ml-auto pn:text-sm",htmlFor:F,children:l("toolbar.colorPicker.angle")}),r("div",{className:"pn:relative",children:[o(E,{id:F,value:O,min:0,max:360,onValueChange:e=>A(P,e),style:{width:64},className:"pn:pl-1 pn:pr-8"}),o("span",{"aria-hidden":!0,className:"pn:pointer-events-none pn:absolute pn:right-6 pn:top-1/2 pn:-translate-y-1/2 pn:text-sm pn:text-muted-foreground",children:"°"})]})]}),o("div",{className:"pn:px-2.5 pn:py-1",children:o(N,{"aria-labelledby":`${F}-label`,value:[O],min:0,max:360,onValueChange:e=>A(P,Math.round(w(e)))})}),o(z,{color:P[B].color,presetColors:i,onChange:e=>A(P.map((o,r)=>{return{offset:o.offset,color:r===B?e:(t=e,n=o.color,p(t)?p(n)?n:c(m(n)):p(n)?d(n):n)};var t,n}))})]})},A=n(({value:e,onChange:n,preset:a,store:i})=>{const[c,p]=t.useState(s(e)?"gradient":"solid");return o("div",{style:{padding:"5px"},children:r(S,{value:c,onValueChange:e=>p(e),className:"pn:w-full",children:[r(B,{className:"pn:flex pn:w-full pn:flex-row",children:[o(R,{value:"solid",className:"pn:flex-1",children:l("toolbar.colorPicker.solid")}),o(R,{value:"gradient",className:"pn:flex-1",children:l("toolbar.colorPicker.linear")})]}),o($,{value:"solid",className:"pn:w-full",children:o(z,{color:s(e)?g(e).stops[0].color:e,onChange:n,presetColors:a,style:{padding:"0"}})}),o($,{value:"gradient",className:"ember-panel pn:w-full",children:o(D,{value:e,onChange:n,store:i,preset:a})})]})})}),L="url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 8 8'%3E%3Cg fill='rgba(112, 112, 116, 1)' fill-opacity='1'%3E%3Cpath fill-rule='evenodd' d='M0 0h4v4H0V0zm4 4h4v4H4V4z'/%3E%3C/g%3E%3C/svg%3E\")";export const ColoredBox=t.forwardRef(function(r,t){var{size:n=30,background:l,style:s={},className:a,children:i=null}=r,c=e(r,["size","background","style","className","children"]);const p="string"==typeof l?d(l):"transparent",u=p.includes("gradient")?p:`linear-gradient(${p}, ${p}), ${L}`;return o("div",Object.assign({ref:t,role:"button",tabIndex:0,"aria-label":"Pick color",onMouseDown:e=>e.preventDefault(),className:k("pn:flex pn:cursor-pointer pn:items-center pn:justify-center pn:overflow-hidden pn:rounded-md pn:border pn:border-foreground/30",a),style:Object.assign({width:n+"px",height:n+"px",backgroundImage:u},s)},c,{children:i}))});let I=e=>{const o=getUsedColors(e).slice(0,8).filter(e=>!DEFAULT_COLORS.find(o=>i(o,e)));return o.concat(DEFAULT_COLORS.slice(0,16-o.length).reverse())};export function setColorsPresetFunc(e){I=e}const M=({value:e,onChange:r,store:t,gradientEnabled:n,presetColors:l})=>n?o(A,{preset:l,value:e,onChange:r,store:t}):o("div",{style:{padding:"5px"},children:o(z,{color:e,onChange:r,presetColors:l})});let U=M;const T=e=>o(U,Object.assign({},e,{presetColors:I(e.store)}));export function setColorPickerContent(e){U=null!=e?e:M}export const ColorPicker=({value:e,onChange:n,size:l,store:s,gradientEnabled:a,children:i,style:c,onOpen:p,onClose:d})=>{const[u,m]=t.useState(!1);return r(O,{open:u,onOpenChange:e=>{m(e),e?null==p||p():null==d||d()},children:[o(F,{nativeButton:!1,render:o(ColoredBox,{size:l,background:e,style:c,children:i})}),o(P,{className:"pn:w-[280px] pn:p-0",initialFocus:!1,children:o(T,{value:e,onChange:n,store:s,gradientEnabled:!!a})})]})};export default ColorPicker;
@@ -1 +1 @@
1
- import{jsx as e,jsxs as o}from"react/jsx-runtime";import*as s from"react";import{observer as t}from"mobx-react-lite";import{PolotnoIcon as a}from"../icons/registry.js";import{Button as r}from"../primitives/button.js";import{Spinner as i}from"../primitives/spinner.js";import{DropdownMenu as n,DropdownMenuContent as l,DropdownMenuItem as d,DropdownMenuTrigger as m}from"../primitives/dropdown-menu.js";import{t as p}from"../utils/l10n.js";import{downloadFile as c}from"../utils/download.js";import{getAPI as f}from"../utils/api.js";import{getKey as u}from"../utils/validate-key.js";import{flags as w}from"../utils/flags.js";const g=e=>{const o=[];return e.pages.forEach(e=>{e.children.forEach(e=>{"text"===e.type&&o.push(e.text)})}),o.join(" ").split(" ").slice(0,6).join(" ").replace(/\s/g,"-").toLowerCase()||"polotno"};export const DownloadButton=t(({store:t})=>{const[h,j]=s.useState(!1);return o(n,{children:[e(m,{render:o(r,{variant:"ghost",size:"sm",className:"polotno-download-button",disabled:h,children:[h?e(i,{className:"pn:mr-1.5"}):e(a,{name:"download.export",className:"pn:mr-1.5 pn:size-4"}),p("toolbar.download")]})}),o(l,{align:"end",children:[o(d,{onClick:async()=>{t.pages.forEach((e,o)=>{const s=t.pages.length>1?"-"+(o+1):"";t.saveAsImage({pageId:e.id,fileName:g(t)+s+".png"})})},children:[e(a,{name:"download.image",className:"pn:size-4"}),p("toolbar.saveAsImage")]}),o(d,{onClick:async()=>{j(!0),await t.saveAsPDF({fileName:g(t)+".pdf",includeBleed:!0}),j(!1)},children:[e(a,{name:"download.pdf",className:"pn:size-4"}),p("toolbar.saveAsPDF")]}),w.animationsEnabled&&o(d,{onClick:async()=>{j(!0);try{await(async({store:e,onProgress:o})=>{const s=e.toJSON(),t=await fetch(`${f()}/renders?KEY=${u()}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({design:s,pixelRatio:1,format:"mp4"})}),a=await t.json();for(;;){const s=await fetch(`${f()}/renders/${a.id}?KEY=${u()}`),t=await s.json();if("done"===t.status){c(t.output,g(e)+".mp4");break}if("error"===t.status){throw new Error("Failed to render video")}null==o||o(t.progress||0,t.status||"processing"),await new Promise(e=>setTimeout(e,5e3))}})({store:t})}catch(e){console.error("Video export failed:",e),alert("Failed to export video. Please try again.")}j(!1)},children:[e(a,{name:"download.video",className:"pn:size-4"}),"Save as Video"]})]})]})});export default DownloadButton;
1
+ import{jsx as e,jsxs as o}from"react/jsx-runtime";import*as t from"react";import{observer as s}from"mobx-react-lite";import{PolotnoIcon as a}from"../icons/registry.js";import{Button as r}from"../primitives/button.js";import{Spinner as i}from"../primitives/spinner.js";import{DropdownMenu as n,DropdownMenuContent as l,DropdownMenuItem as d,DropdownMenuTrigger as m}from"../primitives/dropdown-menu.js";import{t as p}from"../utils/l10n.js";import{downloadFile as c}from"../utils/download.js";import{getAPI as f}from"../utils/api.js";import{getKey as u}from"../utils/validate-key.js";import{flags as w}from"../utils/flags.js";const g=e=>{const o=[];return e.pages.forEach(e=>{e.children.forEach(e=>{"text"===e.type&&o.push(e.text)})}),o.join(" ").split(" ").slice(0,6).join(" ").replace(/\s/g,"-").toLowerCase()||"polotno"};export const DownloadButton=s(({store:s})=>{const[h,j]=t.useState(!1);return o(n,{children:[e(m,{render:o(r,{variant:"ghost",size:"sm",className:"polotno-download-button",disabled:h,children:[h?e(i,{className:"pn:mr-1.5"}):e(a,{name:"download.export",className:"pn:mr-1.5 pn:size-4"}),p("toolbar.download")]})}),o(l,{align:"end",children:[o(d,{onClick:async()=>{s.pages.forEach((e,o)=>{const t=s.pages.length>1?"-"+(o+1):"";s.saveAsImage({pageId:e.id,fileName:g(s)+t+".png"})})},children:[e(a,{name:"download.image",className:"pn:size-4"}),p("toolbar.saveAsImage")]}),o(d,{onClick:async()=>{j(!0);try{await s.saveAsPDF({fileName:g(s)+".pdf",includeBleed:!0})}finally{j(!1)}},children:[e(a,{name:"download.pdf",className:"pn:size-4"}),p("toolbar.saveAsPDF")]}),w.animationsEnabled&&o(d,{onClick:async()=>{j(!0);try{await(async({store:e,onProgress:o})=>{const t=e.toJSON(),s=await fetch(`${f()}/renders?KEY=${u()}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({design:t,pixelRatio:1,format:"mp4"})}),a=await s.json();for(;;){const t=await fetch(`${f()}/renders/${a.id}?KEY=${u()}`),s=await t.json();if("done"===s.status){c(s.output,g(e)+".mp4");break}if("error"===s.status){throw new Error("Failed to render video")}null==o||o(s.progress||0,s.status||"processing"),await new Promise(e=>setTimeout(e,5e3))}})({store:s})}catch(e){console.error("Video export failed:",e),alert("Failed to export video. Please try again.")}j(!1)},children:[e(a,{name:"download.video",className:"pn:size-4"}),"Save as Video"]})]})]})});export default DownloadButton;
@@ -1 +1 @@
1
- import{jsx as e,jsxs as t}from"react/jsx-runtime";import i from"react";import{observer as o}from"mobx-react-lite";import{ElementContainer as r,extendToolbar as n}from"./element-container.js";import{Button as s}from"../primitives/button.js";import{clamp as a,firstSliderValue as l}from"../lib/utils.js";import{NumericInput as d}from"../primitives/numeric-input.js";import{SpeedControl as p}from"../primitives/speed-control.js";import{Slider as m}from"../primitives/slider.js";import{Popover as c,PopoverContent as h,PopoverTrigger as u}from"../primitives/popover.js";import{Tooltip as g,TooltipContent as f,TooltipTrigger as v}from"../primitives/tooltip.js";import{AnimationsPicker as x}from"./animations-picker.js";import{flags as b}from"../utils/flags.js";import{getVideoDuration as w,getVideoObjectPreview as y,getVideoSize as j}from"@polotno/core/video";import{t as V}from"../utils/l10n.js";import{DRAG_SLOP_PX as T,isPrimaryDrag as C,usePointerDrag as z}from"../utils/pointer-drag.js";import{PolotnoIcon as E}from"../icons/registry.js";export const VideoTrim=o(({element:o})=>{const r=i.useRef(null),[n,l]=i.useState([]),d=z();i.useEffect(()=>{l([])},[o.src]);const p=async()=>{if(!o.src){return}if(n.length){return}const{width:e,height:t}=await j(o.src);if(!r.current){return}const i=e/t,{src:s}=o,a=r.current.offsetHeight,d=r.current.offsetWidth,p=a*i,m=Math.ceil(d/p),c=await w(s),h=document.createElement("video");h.crossOrigin="anonymous",h.src=s;const u=document.createElement("canvas");u.width=480;try{await new Promise((e,t)=>{h.addEventListener("loadeddata",()=>{const t=h.videoWidth/h.videoHeight;u.height=480/t,e()}),h.addEventListener("error",t)}),l([]);for(let e=0;e<m;e++){const t=e*c/m,i=await y(h,u,t);l(e=>e.concat(i))}}catch(g){console.error("Error generating previews:",g)}},m=t=>e("div",{className:"polotno-video-trim-handle pn:w-[10px] pn:touch-pan-y pn:pointer-coarse:w-5",style:Object.assign(Object.assign({position:"absolute",top:"0"},"start"===t?{left:100*o.startTime+"%"}:{right:100-100*o.endTime+"%"}),{height:"30px",borderRadius:"0px",backgroundColor:"rgb(0, 161, 255, 0.9)",cursor:"ew-resize"}),onPointerDown:e=>((e,t)=>{if(!C(e)){return}const i=e.clientX,{width:n}=r.current.getBoundingClientRect(),s=o.startTime,l=o.endTime;d(e,{slopX:T,node:o,onMove:e=>{const r=(e.clientX-i)/n;"start"===t?o.set({startTime:a(s+r,0,l)}):o.set({endTime:a(l+r,s,1)})}})})(e,t)});return t(c,{onOpenChange:e=>{e&&setTimeout(p,0)},children:[e(u,{render:t(s,{variant:"ghost",size:"sm",children:[e(E,{name:"toolbar.trim",className:"pn:size-4"}),"Trim"]})}),e(h,{align:"start",className:"pn:p-3",style:{width:"600px"},children:t("div",{className:"pn:flex pn:items-center",children:[e("div",{className:"pn:flex pn:h-[30px] pn:items-center pn:rounded-md pn:border pn:border-input pn:px-3 pn:text-sm pn:tabular-nums",children:(o.duration*(o.endTime-o.startTime)/1e3).toFixed(2)}),e("span",{className:"pn:ml-1 pn:text-xs pn:text-muted-foreground",children:V("toolbar.seconds")}),t("div",{style:{flex:1,height:"30px",display:"flex",position:"relative",overflow:"hidden",marginLeft:"10px",borderRadius:"4px"},ref:r,children:[n.map((t,i)=>e("img",{src:t,style:{width:"auto",height:"100%",objectFit:"cover"}},i)),e("div",{style:{position:"absolute",top:"0",left:0,width:100*o.startTime+"%",height:"30px",backgroundColor:"rgb(0, 0, 0, 0.5)"}}),e("div",{style:{position:"absolute",top:"0",right:"0%",width:100-100*o.endTime+"%",height:"30px",backgroundColor:"rgb(0, 0, 0, 0.5)"}}),m("start"),m("end")]})]})})]})});const N=o(({element:i})=>{const o=Math.round(100*i.volume),r=e=>{i.set({volume:e/100})};return t(c,{children:[t(g,{children:[e(v,{render:e(u,{render:e(s,{variant:"ghost",size:"icon-sm","aria-label":V("toolbar.volume"),children:e(E,{name:"action.unmuted",className:"pn:size-4"})})})}),e(f,{children:V("toolbar.volume")})]}),e(h,{style:{padding:"10px",width:"250px"},align:"start",children:t("div",{style:{display:"flex",width:"100%",justifyContent:"space-between"},children:[e("div",{style:{paddingTop:"7px",paddingLeft:"10px",width:"calc(100% - 80px)"},children:e(m,{value:[o],onValueChange:e=>{r(l(e))},min:0,max:100,step:1})}),e(d,{value:o,onValueChange:e=>{r(a(e,0,100))},style:{width:"50px",padding:"0 5px",marginLeft:"10px"},min:0,max:100})]})})]})}),S=o(({element:i})=>t(c,{children:[t(g,{children:[e(v,{render:e(u,{render:t(s,{variant:"ghost",size:"sm","aria-label":V("toolbar.speed"),children:[e(E,{name:"toolbar.duration",className:"pn:size-4"}),i.speed,"×"]})})}),e(f,{children:V("toolbar.speed")})]}),t(h,{style:{padding:"10px",width:"250px"},align:"start",children:[e("div",{style:{fontSize:"12px",marginBottom:"8px"},children:V("toolbar.speed")}),e(p,{value:i.speed,onChange:e=>i.set({speed:e})})]})]}));export const VideoClip=o(({element:t,store:i})=>t.contentEditable?t.clipSrc?e(s,{variant:"ghost",size:"sm",onClickCapture:()=>{t.set({clipSrc:""})},children:V("toolbar.removeClip")}):e(s,{variant:"ghost",size:"sm",onClickCapture:e=>{e.stopPropagation(),i.openSidePanel("image-clip")},children:V("toolbar.clip")}):null);const k={VideoTrim,VideoAnimations:x,VideoVolume:N,VideoSpeed:S,VideoClip};export const VideoToolbar=o(({store:t,components:i})=>{const o=t.selectedElements,s=["VideoTrim","VideoVolume","VideoSpeed","VideoClip",b.animationsEnabled&&"VideoAnimations"],a=n({type:"video",usedItems:s,components:i});return e(r,{items:a,itemRender:r=>{const n=i[r]||k[r];return e(n,{elements:o,element:o[0],store:t},r)}})});export default VideoToolbar;
1
+ import{jsx as e,jsxs as t}from"react/jsx-runtime";import i from"react";import{observer as o}from"mobx-react-lite";import{ElementContainer as r,extendToolbar as n}from"./element-container.js";import{Button as s}from"../primitives/button.js";import{clamp as a,firstSliderValue as l}from"../lib/utils.js";import{NumericInput as d}from"../primitives/numeric-input.js";import{SpeedControl as p}from"../primitives/speed-control.js";import{Slider as m}from"../primitives/slider.js";import{Popover as c,PopoverContent as h,PopoverTrigger as u}from"../primitives/popover.js";import{Tooltip as g,TooltipContent as f,TooltipTrigger as v}from"../primitives/tooltip.js";import{AnimationsPicker as x}from"./animations-picker.js";import{flags as b}from"../utils/flags.js";import{getVideoObjectPreview as w,getVideoSize as y}from"@polotno/core/video";import{t as j}from"../utils/l10n.js";import{DRAG_SLOP_PX as V,isPrimaryDrag as T,usePointerDrag as C}from"../utils/pointer-drag.js";import{PolotnoIcon as z}from"../icons/registry.js";export const VideoTrim=o(({element:o})=>{const r=i.useRef(null),[n,l]=i.useState([]),d=C();i.useEffect(()=>{l([])},[o.src]);const p=async()=>{if(!o.src){return}if(n.length){return}const{width:e,height:t,duration:i}=await y(o.src);if(!r.current){return}const s=e/t,{src:a}=o,d=r.current.offsetHeight,p=r.current.offsetWidth,m=d*s,c=Math.ceil(p/m),h=document.createElement("video");h.crossOrigin="anonymous",h.src=a;const u=document.createElement("canvas");u.width=480;try{await new Promise((e,t)=>{h.addEventListener("loadeddata",()=>{const t=h.videoWidth/h.videoHeight;u.height=480/t,e()}),h.addEventListener("error",t)}),l([]);for(let e=0;e<c;e++){const t=e*i/c,o=await w(h,u,t);l(e=>e.concat(o))}}catch(g){console.error("Error generating previews:",g)}},m=t=>e("div",{className:"polotno-video-trim-handle pn:w-[10px] pn:touch-pan-y pn:pointer-coarse:w-5",style:Object.assign(Object.assign({position:"absolute",top:"0"},"start"===t?{left:100*o.startTime+"%"}:{right:100-100*o.endTime+"%"}),{height:"30px",borderRadius:"0px",backgroundColor:"rgb(0, 161, 255, 0.9)",cursor:"ew-resize"}),onPointerDown:e=>((e,t)=>{if(!T(e)){return}const i=e.clientX,{width:n}=r.current.getBoundingClientRect(),s=o.startTime,l=o.endTime;d(e,{slopX:V,node:o,onMove:e=>{const r=(e.clientX-i)/n;"start"===t?o.set({startTime:a(s+r,0,l)}):o.set({endTime:a(l+r,s,1)})}})})(e,t)});return t(c,{onOpenChange:e=>{e&&setTimeout(p,0)},children:[e(u,{render:t(s,{variant:"ghost",size:"sm",children:[e(z,{name:"toolbar.trim",className:"pn:size-4"}),"Trim"]})}),e(h,{align:"start",className:"pn:p-3",style:{width:"600px"},children:t("div",{className:"pn:flex pn:items-center",children:[e("div",{className:"pn:flex pn:h-[30px] pn:items-center pn:rounded-md pn:border pn:border-input pn:px-3 pn:text-sm pn:tabular-nums",children:(o.duration*(o.endTime-o.startTime)/1e3).toFixed(2)}),e("span",{className:"pn:ml-1 pn:text-xs pn:text-muted-foreground",children:j("toolbar.seconds")}),t("div",{style:{flex:1,height:"30px",display:"flex",position:"relative",overflow:"hidden",marginLeft:"10px",borderRadius:"4px"},ref:r,children:[n.map((t,i)=>e("img",{src:t,style:{width:"auto",height:"100%",objectFit:"cover"}},i)),e("div",{style:{position:"absolute",top:"0",left:0,width:100*o.startTime+"%",height:"30px",backgroundColor:"rgb(0, 0, 0, 0.5)"}}),e("div",{style:{position:"absolute",top:"0",right:"0%",width:100-100*o.endTime+"%",height:"30px",backgroundColor:"rgb(0, 0, 0, 0.5)"}}),m("start"),m("end")]})]})})]})});const E=o(({element:i})=>{const o=Math.round(100*i.volume),r=e=>{i.set({volume:e/100})};return t(c,{children:[t(g,{children:[e(v,{render:e(u,{render:e(s,{variant:"ghost",size:"icon-sm","aria-label":j("toolbar.volume"),children:e(z,{name:"action.unmuted",className:"pn:size-4"})})})}),e(f,{children:j("toolbar.volume")})]}),e(h,{style:{padding:"10px",width:"250px"},align:"start",children:t("div",{style:{display:"flex",width:"100%",justifyContent:"space-between"},children:[e("div",{style:{paddingTop:"7px",paddingLeft:"10px",width:"calc(100% - 80px)"},children:e(m,{value:[o],onValueChange:e=>{r(l(e))},min:0,max:100,step:1})}),e(d,{value:o,onValueChange:e=>{r(a(e,0,100))},style:{width:"50px",padding:"0 5px",marginLeft:"10px"},min:0,max:100})]})})]})}),N=o(({element:i})=>t(c,{children:[t(g,{children:[e(v,{render:e(u,{render:t(s,{variant:"ghost",size:"sm","aria-label":j("toolbar.speed"),children:[e(z,{name:"toolbar.duration",className:"pn:size-4"}),i.speed,"×"]})})}),e(f,{children:j("toolbar.speed")})]}),t(h,{style:{padding:"10px",width:"250px"},align:"start",children:[e("div",{style:{fontSize:"12px",marginBottom:"8px"},children:j("toolbar.speed")}),e(p,{value:i.speed,onChange:e=>i.set({speed:e})})]})]}));export const VideoClip=o(({element:t,store:i})=>t.contentEditable?t.clipSrc?e(s,{variant:"ghost",size:"sm",onClickCapture:()=>{t.set({clipSrc:""})},children:j("toolbar.removeClip")}):e(s,{variant:"ghost",size:"sm",onClickCapture:e=>{e.stopPropagation(),i.openSidePanel("image-clip")},children:j("toolbar.clip")}):null);const S={VideoTrim,VideoAnimations:x,VideoVolume:E,VideoSpeed:N,VideoClip};export const VideoToolbar=o(({store:t,components:i})=>{const o=t.selectedElements,s=["VideoTrim","VideoVolume","VideoSpeed","VideoClip",b.animationsEnabled&&"VideoAnimations"],a=n({type:"video",usedItems:s,components:i});return e(r,{items:a,itemRender:r=>{const n=i[r]||S[r];return e(n,{elements:o,element:o[0],store:t},r)}})});export default VideoToolbar;
@@ -78,7 +78,6 @@ export declare const insertTextElement: (store: StoreType, text: string, extra?:
78
78
  strokeLineJoin: import("mobx-state-tree").IType<string | undefined, string, string>;
79
79
  lineHeight: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree/dist/internal").IUnionType<[import("mobx-state-tree").ISimpleType<number>, import("mobx-state-tree").ISimpleType<string>]>, [undefined]>;
80
80
  letterSpacing: import("mobx-state-tree").IType<number | undefined, number, number>;
81
- _editModeEnabled: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
82
81
  backgroundEnabled: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
83
82
  backgroundColor: import("mobx-state-tree").IType<string | undefined, string, string>;
84
83
  backgroundOpacity: import("mobx-state-tree").IType<number | undefined, number, number>;
@@ -209,6 +208,8 @@ export declare const insertTextElement: (store: StoreType, text: string, extra?:
209
208
  } & {
210
209
  setAnimation(type: 'enter' | 'exit' | 'loop', attrs: import("./animations.js").AnimationAttrs): void;
211
210
  setFilter(type: any, value: any): void;
211
+ } & {
212
+ _editModeEnabled: boolean;
212
213
  } & {
213
214
  set(attrs: any): void;
214
215
  toggleEditMode(editing?: boolean): void;
@@ -284,7 +285,6 @@ export declare const insertTextElement: (store: StoreType, text: string, extra?:
284
285
  strokeLineJoin: import("mobx-state-tree").IType<string | undefined, string, string>;
285
286
  lineHeight: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree/dist/internal").IUnionType<[import("mobx-state-tree").ISimpleType<number>, import("mobx-state-tree").ISimpleType<string>]>, [undefined]>;
286
287
  letterSpacing: import("mobx-state-tree").IType<number | undefined, number, number>;
287
- _editModeEnabled: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
288
288
  backgroundEnabled: import("mobx-state-tree").IType<boolean | undefined, boolean, boolean>;
289
289
  backgroundColor: import("mobx-state-tree").IType<string | undefined, string, string>;
290
290
  backgroundOpacity: import("mobx-state-tree").IType<number | undefined, number, number>;
@@ -415,6 +415,8 @@ export declare const insertTextElement: (store: StoreType, text: string, extra?:
415
415
  } & {
416
416
  setAnimation(type: 'enter' | 'exit' | 'loop', attrs: import("./animations.js").AnimationAttrs): void;
417
417
  setFilter(type: any, value: any): void;
418
+ } & {
419
+ _editModeEnabled: boolean;
418
420
  } & {
419
421
  set(attrs: any): void;
420
422
  toggleEditMode(editing?: boolean): void;
@@ -1 +1 @@
1
- var e=this&&this.__rest||function(e,t){var n={};for(var i in e){Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(i=Object.getOwnPropertySymbols(e);o<i.length;o++){t.indexOf(i[o])<0&&Object.prototype.propertyIsEnumerable.call(e,i[o])&&(n[i[o]]=e[i[o]])}}return n};import{getTotalClientRect as t}from"./math.js";import{roundedGeometryAttrs as n,roundedGeometryPx as i,roundedStyleAttrs as o,scaledFontSizeBounds as s,isMedia as r,scaledStyleAttrs as c,textMinResizeWidth as h,textMinWidthIsMeasured as a}from"./px.js";import{textResizeFloorFontSize as l}from"./text-sizing.js";export const isAxisAligned=e=>{const t=(e%180+180)%180;return t<.1||180-t<.1};export const canStretchAxis=(e,t,n)=>{if(!isAxisAligned(e.rotation-n)){return!1}switch(e.type){case"text":return"x"===t&&!a(e);case"figure":case"video":case"table":return!0;case"image":case"svg":case"gif":case"lottie":return!e.keepRatio;default:return!1}};export const leafMinSize=(e,t,n,i)=>{if("table"===e.type){const n=e;return"x"===t?n.minWidth:n.minHeight}return"text"===e.type&&"x"===t&&n?h(i,l(e)):1};const x=e=>{const[t]=e.selectedElements;return 1===e.selectedElements.length&&"group"!==t.type?t:null};export const getSelectionBox=e=>{const n=x(e);if(n){const{x:e,y:t,width:i,height:o}=n;return{x:e,y:t,width:i,height:o}}const i=e.selectedShapes;return i.length?t(i):null};const p=e=>!e.pendingEdit;export const canResizeSelection=e=>{const t=e.selectedShapes;return t.length>0&&t.every(e=>e.resizable&&p(e))};export const canMoveSelection=e=>{const t=e.selectedShapes;return t.length>0&&t.every(e=>e.draggable&&p(e))};const g=(e,t,n)=>{e.set(t),e.setHeightRedistribute(n),e.set({x:i(e.x),y:i(e.y),width:i(e.width)}),e._resetBaseRowHeights()},d=(e,t,i)=>{const r=i.x+(e.x-i.x)*t,h=i.y+(e.y-i.y)*t;if("table"===e.type){return void g(e,{x:r,y:h,width:e.width*t},e.height*t)}const{fontSize:a,minFontSize:l,maxFontSize:x}=e;e.set(Object.assign({x:r,y:h,width:e.width*t,height:e.height*t},c(e,t))),e.set(Object.assign(Object.assign({},n(e)),o(e))),"text"===e.type&&e.set(s({minFontSize:l,maxFontSize:x},e.fontSize/a,!0))};export const resizeSelection=(t,i,o)=>{const s=getSelectionBox(t),c="x"===i?null==s?void 0:s.width:null==s?void 0:s.height;if(!(s&&c&&o>0&&canResizeSelection(t))){return}const h=t.selectedShapes,a=x(t),l=h.every(e=>!r(e.type))&&(a?((e,t)=>"text"===e.type?"x"===t&&!e.curveEnabled:canStretchAxis(e,t,e.rotation))(a,i):h.every(e=>canStretchAxis(e,i,0))),p=Math.max(...h.flatMap(e=>(l?[i]:["x","y"]).map(t=>{const n="x"===t?e.width:e.height,i=leafMinSize(e,t,l,n);return n>=i?i/n:0}))),y=Math.max(o/c,p),u={x:s.x,y:s.y};t.history.transaction(()=>{h.forEach(t=>{l?((t,i,o,s)=>{const[r,c]="x"===i?["x","width"]:["y","height"],h={[r]:s[r]+(t[r]-s[r])*o,[c]:t[c]*o};if("table"===t.type){const{height:n=t.height}=h,i=e(h,["height"]);return void g(t,i,n)}t.set(h),t.set(n(t))})(t,i,y,u):d(t,y,u)})})};const y=(e,t,n)=>{e.forEach(e=>{e.set({x:i(e.x+t),y:i(e.y+n)})})};export const moveSelection=(e,t,n)=>{const i=getSelectionBox(e);if(!i||!Number.isFinite(n)||!canMoveSelection(e)){return}const o=n-("x"===t?i.x:i.y);e.history.transaction(()=>{y(e.selectedShapes,"x"===t?o:0,"y"===t?o:0)})};export const canFitSelectionToPage=e=>canResizeSelection(e)&&canMoveSelection(e);export const fitSelectionToPage=e=>{var n;const i=e.selectedShapes,o=null===(n=i[0])||void 0===n?void 0:n.page;if(!o||!canFitSelectionToPage(e)){return}const s=t(i);if(!s.width||!s.height){return}const r=Math.min(o.computedWidth/s.width,o.computedHeight/s.height);e.history.transaction(()=>{i.forEach(e=>d(e,r,{x:s.x,y:s.y}));const e=t(i);y(i,(o.computedWidth-e.width)/2-e.x,(o.computedHeight-e.height)/2-e.y)})};
1
+ var e=this&&this.__rest||function(e,t){var i={};for(var n in e){Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(i[n]=e[n])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++){t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(i[n[o]]=e[n[o]])}}return i};import{getTotalClientRect as t}from"./math.js";import{roundedGeometryAttrs as i,roundedGeometryPx as n,roundedStyleAttrs as o,scaledFontSizeBounds as s,isMedia as r,scaledStyleAttrs as c,textMinResizeWidth as a,textMinWidthIsMeasured as h}from"./px.js";import{textResizeFloorFontSize as l}from"./text-sizing.js";import{sideResizeCrop as x}from"../canvas/media-resize.js";export const isAxisAligned=e=>{const t=(e%180+180)%180;return t<.1||180-t<.1};export const canStretchAxis=(e,t,i)=>{if(!isAxisAligned(e.rotation-i)){return!1}switch(e.type){case"text":return"x"===t&&!h(e);case"figure":case"video":case"table":return!0;case"image":case"svg":case"gif":case"lottie":return!e.keepRatio;default:return!1}};export const leafMinSize=(e,t,i,n)=>{if("table"===e.type){const i=e;return"x"===t?i.minWidth:i.minHeight}return"text"===e.type&&"x"===t&&i?a(n,l(e)):1};const p=e=>{const[t]=e.selectedElements;return 1===e.selectedElements.length&&"group"!==t.type?t:null};export const getSelectionBox=e=>{const i=p(e);if(i){const{x:e,y:t,width:n,height:o}=i;return{x:e,y:t,width:n,height:o}}const n=e.selectedShapes;return n.length?t(n):null};const d=e=>!e.pendingEdit;export const canResizeSelection=e=>{const t=e.selectedShapes;return t.length>0&&t.every(e=>e.resizable&&d(e))};export const canMoveSelection=e=>{const t=e.selectedShapes;return t.length>0&&t.every(e=>e.draggable&&d(e))};const g=(e,t,i)=>{e.set(t),e.setHeightRedistribute(i),e.set({x:n(e.x),y:n(e.y),width:n(e.width)}),e._resetBaseRowHeights()},y=(e,t,n)=>{const r=n.x+(e.x-n.x)*t,a=n.y+(e.y-n.y)*t;if("table"===e.type){return void g(e,{x:r,y:a,width:e.width*t},e.height*t)}const{fontSize:h,minFontSize:l,maxFontSize:x}=e;e.set(Object.assign({x:r,y:a,width:e.width*t,height:e.height*t},c(e,t))),e.set(Object.assign(Object.assign({},i(e)),o(e))),"text"===e.type&&e.set(s({minFontSize:l,maxFontSize:x},e.fontSize/h,!0))},u=e=>r(e.type)?e._sourceSize:null,S=e=>!r(e.type)||e.stretchEnabled||!!u(e);export const resizeSelection=(t,n,o)=>{const s=getSelectionBox(t),r="x"===n?null==s?void 0:s.width:null==s?void 0:s.height;if(!(s&&r&&o>0&&canResizeSelection(t))){return}const c=t.selectedShapes,a=p(t),h=c.every(S)&&(a?((e,t)=>"text"===e.type?"x"===t&&!e.curveEnabled:canStretchAxis(e,t,e.rotation))(a,n):c.every(e=>canStretchAxis(e,n,0))),l=Math.max(...c.flatMap(e=>(h?[n]:["x","y"]).map(t=>{const i="x"===t?e.width:e.height,n=leafMinSize(e,t,h,i);return i>=n?n/i:0}))),d=Math.max(o/r,l),f={x:s.x,y:s.y};t.history.transaction(()=>{c.forEach(t=>{h?((t,n,o,s)=>{const[r,c]="x"===n?["x","width"]:["y","height"],a=u(t),h=Object.assign({[r]:s[r]+(t[r]-s[r])*o,[c]:t[c]*o},a&&x(t,a,"x"===n?o:1,"y"===n?o:1));if("table"===t.type){const{height:i=t.height}=h,n=e(h,["height"]);return void g(t,n,i)}t.set(h),t.set(i(t))})(t,n,d,f):y(t,d,f)})})};const f=(e,t,i)=>{e.forEach(e=>{e.set({x:n(e.x+t),y:n(e.y+i)})})};export const moveSelection=(e,t,i)=>{const n=getSelectionBox(e);if(!n||!Number.isFinite(i)||!canMoveSelection(e)){return}const o=i-("x"===t?n.x:n.y);e.history.transaction(()=>{f(e.selectedShapes,"x"===t?o:0,"y"===t?o:0)})};export const canFitSelectionToPage=e=>canResizeSelection(e)&&canMoveSelection(e);export const fitSelectionToPage=e=>{var i;const n=e.selectedShapes,o=null===(i=n[0])||void 0===i?void 0:i.page;if(!o||!canFitSelectionToPage(e)){return}const s=t(n);if(!s.width||!s.height){return}const r=Math.min(o.computedWidth/s.width,o.computedHeight/s.height);e.history.transaction(()=>{n.forEach(e=>y(e,r,{x:s.x,y:s.y}));const e=t(n);f(n,(o.computedWidth-e.width)/2-e.x,(o.computedHeight-e.height)/2-e.y)})};
@@ -14,7 +14,7 @@ export declare const useInfiniteAPI: ({ defaultQuery, timeout, getAPI, getSize,
14
14
  setQuery: (newQuery: string) => void;
15
15
  isLoading: boolean;
16
16
  loadMore: () => void;
17
- isReachingEnd: any;
17
+ isReachingEnd: boolean;
18
18
  data: any[] | undefined;
19
19
  items: any[];
20
20
  hasMore: boolean;
package/utils/use-api.js CHANGED
@@ -1 +1 @@
1
- import{useRef as e,useState as t,useCallback as r}from"react";import i from"swr/infinite";export const fetcher=e=>fetch(e).then(e=>e.json());export const useInfiniteAPI=({defaultQuery:o="",timeout:a=1e3,getAPI:n,getSize:l=e=>e.total_pages,fetchFunc:u=fetcher})=>{var s;const[d,c]=t(o),v=e(void 0),{data:f,error:g,size:h,setSize:m,mutate:p}=i(e=>n({query:d,page:e+1}),u,{revalidateAll:!1,revalidateOnFocus:!1,revalidateFirstPage:!1}),y=!f&&!g||!!(h>0&&f&&void 0===f[h-1]),z=0===(null===(s=null==f?void 0:f[0])||void 0===s?void 0:s.length),A=null==f?void 0:f[f.length-1],F=z||A&&l(A)===h;return{setQuery:r(e=>{clearTimeout(v.current),v.current=setTimeout(()=>{c(e)},a)},[a]),isLoading:y,loadMore:()=>{F||m(h+1)},isReachingEnd:F,data:null==f?void 0:f.filter(Boolean),items:(null==f?void 0:f.flat())||[],hasMore:!F,reset:p,error:g}};
1
+ import{useRef as e,useState as t,useCallback as r}from"react";import i from"swr/infinite";export const fetcher=e=>fetch(e).then(e=>e.json());export const useInfiniteAPI=({defaultQuery:o="",timeout:a=1e3,getAPI:n,getSize:l=e=>e.total_pages,fetchFunc:u=fetcher})=>{var s;const[d,c]=t(o),v=e(void 0),{data:f,error:g,size:h,setSize:m,mutate:p}=i(e=>n({query:d,page:e+1}),u,{revalidateAll:!1,revalidateOnFocus:!1,revalidateFirstPage:!1}),y=!f&&!g||!!(h>0&&f&&void 0===f[h-1]),z=0===(null===(s=null==f?void 0:f[0])||void 0===s?void 0:s.length),A=null==f?void 0:f[f.length-1],F=z||!!A&&h>=l(A);return{setQuery:r(e=>{clearTimeout(v.current),v.current=setTimeout(()=>{c(e)},a)},[a]),isLoading:y,loadMore:()=>{F||m(h+1)},isReachingEnd:F,data:null==f?void 0:f.filter(Boolean),items:(null==f?void 0:f.flat())||[],hasMore:!F,reset:p,error:g}};
@@ -1 +1 @@
1
- import*as e from"mobx";import{NO_KEY_MESSAGE as o,NO_VALID_MESSAGE as t,NOT_PAID_MESSAGE as n,NOT_PAID_STYLE as a}from"@polotno/core/validate-key";import{getAPI as i}from"./api.js";import{removeBackgroundState as r}from"./flags.js";const s=e.observable({value:!1}),l=e.observable({value:"v1"});export const ___=()=>l.value;const c=e.observable({value:0});export const ____=()=>c.value;export const isCreditVisible=()=>s.value;const d=e.action(()=>{s.value=!0});let u="";export const getKey=()=>u||"";export const setKey=e=>{u=e||""};let p="undefined"!=typeof window?window.location.origin:"";const v="undefined"!=typeof navigator&&navigator.userAgent.indexOf("Headless")>-1,f="undefined"!=typeof navigator&&navigator.userAgent.indexOf("Electron")>-1;"file://"===p&&v&&(p="headless"),"file://"===p&&f&&(p="electron");const m=`%cPolotno error! Current domain is not allowed. It may lead to unexpected behavior and stop working. Please add "${p}" here: https://polotno.com/cabinet`;let g=fetch;export const __=e=>{g=e};export async function isKeyPaid(s){for(let u=0;u<5;u++){try{const d=await g(i()+"/validate-key",{method:"POST",body:JSON.stringify({key:s,sdkVersion:"4.20.1"})});if(e.runInAction(()=>{l.value=d.headers.get("x-api-version")||""}),!s){return console.error(o),e.runInAction(()=>{c.value=1}),!1}if(200!==d.status){await new Promise(e=>setTimeout(e,3e3));continue}const u=await d.json();return u.is_valid||(console.error(t),e.runInAction(()=>{c.value=1})),u.is_paid||(console.log(n,a),e.runInAction(()=>{0===c.value&&(c.value=2)})),u.is_domain_valid||console.log(m,"background: rgba(247, 101, 68, 1); color: white; padding: 5px; margin: 5px;"),e.runInAction(()=>{r.defaultEnabled=u.remove_background_enabled}),u.is_paid||!1}catch(d){await new Promise(e=>setTimeout(e,3e3))}}return console.error("Can not validate Polotno API key. Please report to anton@polotno.com immediately."),!0}export async function validateKey(e){await isKeyPaid(u)&&!e||d()}
1
+ import*as e from"mobx";import{NO_KEY_MESSAGE as o,NO_VALID_MESSAGE as t,NOT_PAID_MESSAGE as n,NOT_PAID_STYLE as a}from"@polotno/core/validate-key";import{getAPI as i}from"./api.js";import{removeBackgroundState as r}from"./flags.js";const s=e.observable({value:!1}),l=e.observable({value:"v1"});export const ___=()=>l.value;const c=e.observable({value:0});export const ____=()=>c.value;export const isCreditVisible=()=>s.value;const d=e.action(()=>{s.value=!0});let u="";export const getKey=()=>u||"";export const setKey=e=>{u=e||""};let p="undefined"!=typeof window?window.location.origin:"";const v="undefined"!=typeof navigator&&navigator.userAgent.indexOf("Headless")>-1,f="undefined"!=typeof navigator&&navigator.userAgent.indexOf("Electron")>-1;"file://"===p&&v&&(p="headless"),"file://"===p&&f&&(p="electron");const m=`%cPolotno error! Current domain is not allowed. It may lead to unexpected behavior and stop working. Please add "${p}" here: https://polotno.com/cabinet`;let g=fetch;export const __=e=>{g=e};export async function isKeyPaid(s){for(let u=0;u<5;u++){try{const d=await g(i()+"/validate-key",{method:"POST",body:JSON.stringify({key:s,sdkVersion:"4.21.0"})});if(e.runInAction(()=>{l.value=d.headers.get("x-api-version")||""}),!s){return console.error(o),e.runInAction(()=>{c.value=1}),!1}if(200!==d.status){await new Promise(e=>setTimeout(e,3e3));continue}const u=await d.json();return u.is_valid||(console.error(t),e.runInAction(()=>{c.value=1})),u.is_paid||(console.log(n,a),e.runInAction(()=>{0===c.value&&(c.value=2)})),u.is_domain_valid||console.log(m,"background: rgba(247, 101, 68, 1); color: white; padding: 5px; margin: 5px;"),e.runInAction(()=>{r.defaultEnabled=u.remove_background_enabled}),u.is_paid||!1}catch(d){await new Promise(e=>setTimeout(e,3e3))}}return console.error("Can not validate Polotno API key. Please report to anton@polotno.com immediately."),!0}export async function validateKey(e){await isKeyPaid(u)&&!e||d()}