polotno 4.6.0 → 4.8.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 (59) hide show
  1. package/LICENSE.md +22 -7
  2. package/README.md +1 -1
  3. package/blueprint/side-panel/text-panel.js +3 -3
  4. package/blueprint/toolbar/text-toolbar.js +2 -2
  5. package/blueprint.polotno.css +116 -116
  6. package/canvas/figure-element.js +1 -1
  7. package/canvas/gif-element.js +1 -1
  8. package/canvas/html-element.js +1 -1
  9. package/canvas/image-element.js +1 -1
  10. package/canvas/page.js +1 -1
  11. package/canvas/quill-font-formats.js +1 -1
  12. package/canvas/render-tag-element.js +1 -1
  13. package/canvas/rich-editor.d.ts +0 -4
  14. package/canvas/rich-editor.js +5 -2
  15. package/canvas/text-element.js +1 -1
  16. package/canvas/use-mediabunny-video.js +1 -1
  17. package/canvas/video-element.js +1 -1
  18. package/model/group-model.d.ts +2 -12
  19. package/model/image-model.js +1 -1
  20. package/model/page-model.d.ts +2 -12
  21. package/model/store.d.ts +18 -108
  22. package/model/store.js +1 -1
  23. package/model/table-model.d.ts +2 -12
  24. package/model/table-model.js +1 -1
  25. package/model/text-model.js +1 -1
  26. package/package.json +28 -28
  27. package/pages-timeline/audio-track.js +1 -1
  28. package/pages-timeline/current-time.js +1 -1
  29. package/pages-timeline/element-track.js +1 -1
  30. package/pages-timeline/page-preview.js +1 -1
  31. package/pages-timeline/pages-timeline.js +1 -1
  32. package/pages-timeline/pages.js +1 -1
  33. package/pages-timeline/play-button.js +1 -1
  34. package/pages-timeline/time-ruler.js +1 -1
  35. package/pages-timeline/track-styles.js +1 -1
  36. package/polotno.bundle.js +171 -168
  37. package/primitives/select.d.ts +1 -1
  38. package/side-panel/images-grid.d.ts +2 -1
  39. package/side-panel/images-grid.js +1 -1
  40. package/side-panel/select-svg.js +1 -1
  41. package/side-panel/text-panel.js +1 -1
  42. package/side-panel/text-template.d.ts +12 -0
  43. package/side-panel/text-template.js +1 -0
  44. package/toolbar/text-toolbar.js +1 -1
  45. package/toolbar/video-toolbar.js +1 -1
  46. package/ui.css +2 -2
  47. package/utils/font-metric.js +1 -1
  48. package/utils/fonts.js +1 -1
  49. package/utils/html-to-svg/font-inliner.js +1 -1
  50. package/utils/html2canvas.js +1 -1
  51. package/utils/measure-text.js +1 -1
  52. package/utils/pointer-drag.d.ts +13 -0
  53. package/utils/pointer-drag.js +1 -0
  54. package/utils/px.d.ts +2 -0
  55. package/utils/px.js +1 -1
  56. package/utils/rich-text-html.js +1 -1
  57. package/utils/text-format-state.js +1 -1
  58. package/utils/text-format.js +1 -1
  59. package/utils/validate-key.js +1 -1
@@ -15,7 +15,7 @@ declare const SelectContent: React.ForwardRefExoticComponent<Omit<Omit<import("@
15
15
  }, "ref"> & React.RefAttributes<HTMLDivElement>>;
16
16
  declare const SelectLabel: React.ForwardRefExoticComponent<Omit<Omit<import("@base-ui/react").SelectGroupLabelProps, "ref"> & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
17
17
  declare const SelectItem: React.ForwardRefExoticComponent<Omit<Omit<import("@base-ui/react").SelectItemProps, "ref"> & React.RefAttributes<HTMLElement>, "ref"> & React.RefAttributes<HTMLElement>>;
18
- declare const SelectSeparator: React.ForwardRefExoticComponent<Omit<Omit<import("@base-ui/react").SeparatorProps, "ref"> & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
18
+ declare const SelectSeparator: React.ForwardRefExoticComponent<Omit<import("@base-ui/react").SelectSeparatorProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
19
19
  declare const SelectScrollUpButton: React.ForwardRefExoticComponent<Omit<Omit<import("@base-ui/react").SelectScrollUpArrowProps, "ref"> & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
20
20
  declare const SelectScrollDownButton: React.ForwardRefExoticComponent<Omit<Omit<import("@base-ui/react").SelectScrollDownArrowProps, "ref"> & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
21
21
  export { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, };
@@ -12,6 +12,7 @@ type Props<ImageType> = {
12
12
  getCredit?: (image: ImageType) => any;
13
13
  getAlt?: (image: ImageType) => string;
14
14
  getImageClassName?: (image: ImageType) => string;
15
+ getIsLoading?: (image: ImageType) => boolean;
15
16
  rowsNumber?: number;
16
17
  crossOrigin?: string;
17
18
  shadowEnabled?: boolean;
@@ -19,5 +20,5 @@ type Props<ImageType> = {
19
20
  error?: any;
20
21
  hideNoResults?: boolean;
21
22
  };
22
- export declare const ImagesGrid: <ImageType>({ images, onSelect, isLoading, getPreview, loadMore, getCredit, getAlt, getImageClassName, rowsNumber, crossOrigin, shadowEnabled, itemHeight, error, hideNoResults, }: Props<ImageType>) => React.JSX.Element;
23
+ export declare const ImagesGrid: <ImageType>({ images, onSelect, isLoading, getPreview, loadMore, getCredit, getAlt, getImageClassName, getIsLoading, rowsNumber, crossOrigin, shadowEnabled, itemHeight, error, hideNoResults, }: Props<ImageType>) => React.JSX.Element;
23
24
  export {};
@@ -1 +1 @@
1
- import{jsx as e,jsxs as n}from"react/jsx-runtime";import t from"react";import{registerNextDomDrop as r}from"../canvas/page.js";import{t as l}from"../utils/l10n.js";import{cn as o}from"../lib/utils.js";import{Spinner as a}from"../primitives/spinner.js";const s=({url:t,credit:l,onSelect:a,crossOrigin:s,shadowEnabled:p,itemHeight:i,className:c,onLoad:d,alt:m})=>{const u=null==p||p;return e("div",{role:"button",onClick:()=>{a()},className:"polotno-close-panel pn:group/img-wrap pn:p-[5px] pn:w-full pn:md:[&_.credit]:opacity-0 pn:md:hover:[&_.credit]:opacity-100 pn:[&_.credit]:opacity-100",children:n("div",{"data-shadowenabled":u,className:o("pn:relative pn:overflow-hidden pn:rounded-[5px]",u?"pn:shadow-[0_0_5px_rgba(16,22,26,0.3),0_0_0_1px_rgba(16,22,26,0.12)] pn:dark:shadow-[0_0_0_1px_rgba(255,255,255,0.16)]":""),children:[e("img",{className:o("pn:block pn:max-h-[300px] pn:min-h-[50px] pn:w-full pn:cursor-pointer pn:object-contain",c),style:{height:null!=i?i:"auto"},src:t,draggable:!0,loading:"lazy",crossOrigin:s,alt:m,onDragStart:()=>{r(({x:e,y:n},t,r)=>{a({x:e,y:n},t,r)})},onDragEnd:()=>{r(null)},onLoad:d}),l&&e("div",{className:"credit pn:absolute pn:bottom-0 pn:left-0 pn:w-full pn:bg-gradient-to-b pn:from-transparent pn:via-black/40 pn:to-black/60 pn:p-[3px] pn:pt-[10px] pn:text-center pn:text-[10px] pn:text-white pn:[&_a]:text-white pn:[&_a]:underline",children:l})]})})};export const ImagesGrid=({images:r,onSelect:o,isLoading:p,getPreview:i,loadMore:c,getCredit:d,getAlt:m,getImageClassName:u,rowsNumber:g,crossOrigin:h="anonymous",shadowEnabled:f,itemHeight:x,error:b,hideNoResults:w=!1})=>{const v=g||2,_=t.useRef(null),N=[];for(var y=0;y<v;y++){N.push((r||[]).filter((e,n)=>n%v===y))}const j=t.useRef(null),H=()=>{var e;const n=_.current,t=!!n&&n.scrollHeight>n.offsetHeight+5,l=r&&r.length,o=Array.from(null!==(e=null==n?void 0:n.querySelectorAll("img"))&&void 0!==e?e:[]).every(e=>e.complete);!t&&c&&!p&&l&&o&&(j.current||(j.current=window.setTimeout(()=>{j.current=null,c&&c()},100)))},S=()=>{H()};return t.useEffect(()=>(H(),()=>{null!==j.current&&window.clearTimeout(j.current),j.current=null}),[r&&r.length,p]),n("div",{onScroll:e=>{const n=e.target.scrollHeight-e.target.scrollTop-e.target.offsetHeight;c&&!p&&n<200&&c()},ref:_,className:"pn:h-full pn:overflow-auto",children:[N.map((n,t)=>e("div",{className:"pn:float-left",style:{width:100/v+"%"},children:n.map((n,t)=>e(s,{url:i(n),onSelect:(e,t,r)=>o(n,e,t,r),credit:d&&d(n),crossOrigin:h,shadowEnabled:f,itemHeight:x,className:u&&u(n),onLoad:S,alt:m&&m(n)||""},t))},t)),p&&e("div",{className:"pn:clear-both pn:flex pn:justify-center pn:p-[30px]",children:e(a,{className:"pn:size-5 pn:text-muted-foreground"})}),!p&&(!r||!r.length)&&!b&&!w&&e("p",{className:"pn:p-[30px] pn:text-center",children:l("sidePanel.noResults")}),b&&e("p",{className:"pn:clear-both pn:p-[30px] pn:text-center",children:l("sidePanel.error")})]})};
1
+ import{jsx as e,jsxs as n}from"react/jsx-runtime";import t from"react";import{registerNextDomDrop as r}from"../canvas/page.js";import{t as l}from"../utils/l10n.js";import{cn as o}from"../lib/utils.js";import{Spinner as a}from"../primitives/spinner.js";const s=({url:t,credit:l,onSelect:s,crossOrigin:p,shadowEnabled:i,itemHeight:c,className:d,onLoad:u,alt:m,pending:g})=>{const h=null==i||i;return e("div",{role:"button",onClick:()=>{s()},className:"polotno-close-panel pn:group/img-wrap pn:p-[5px] pn:w-full pn:md:[&_.credit]:opacity-0 pn:md:hover:[&_.credit]:opacity-100 pn:[&_.credit]:opacity-100",children:n("div",{"data-shadowenabled":h,className:o("pn:relative pn:overflow-hidden pn:rounded-[5px]",h?"pn:shadow-[0_0_5px_rgba(16,22,26,0.3),0_0_0_1px_rgba(16,22,26,0.12)] pn:dark:shadow-[0_0_0_1px_rgba(255,255,255,0.16)]":""),children:[e("img",{className:o("pn:block pn:max-h-[300px] pn:min-h-[50px] pn:w-full pn:cursor-pointer pn:object-contain",d),style:{height:null!=c?c:"auto"},src:t,draggable:!0,loading:"lazy",crossOrigin:p,alt:m,onDragStart:()=>{r(({x:e,y:n},t,r)=>{s({x:e,y:n},t,r)})},onDragEnd:()=>{r(null)},onLoad:u}),g&&e("div",{className:"pn:absolute pn:inset-0 pn:flex pn:items-center pn:justify-center pn:bg-background/70",children:e(a,{className:"pn:size-5 pn:text-muted-foreground"})}),l&&e("div",{className:"credit pn:absolute pn:bottom-0 pn:left-0 pn:w-full pn:bg-gradient-to-b pn:from-transparent pn:via-black/40 pn:to-black/60 pn:p-[3px] pn:pt-[10px] pn:text-center pn:text-[10px] pn:text-white pn:[&_a]:text-white pn:[&_a]:underline",children:l})]})})};export const ImagesGrid=({images:r,onSelect:o,isLoading:p,getPreview:i,loadMore:c,getCredit:d,getAlt:u,getImageClassName:m,getIsLoading:g,rowsNumber:h,crossOrigin:f="anonymous",shadowEnabled:x,itemHeight:b,error:v,hideNoResults:w=!1})=>{const N=h||2,_=t.useRef(null),y=[];for(var j=0;j<N;j++){y.push((r||[]).filter((e,n)=>n%N===j))}const H=t.useRef(null),k=()=>{var e;const n=_.current,t=!!n&&n.scrollHeight>n.offsetHeight+5,l=r&&r.length,o=Array.from(null!==(e=null==n?void 0:n.querySelectorAll("img"))&&void 0!==e?e:[]).every(e=>e.complete);!t&&c&&!p&&l&&o&&(H.current||(H.current=window.setTimeout(()=>{H.current=null,c&&c()},100)))},S=()=>{k()};return t.useEffect(()=>(k(),()=>{null!==H.current&&window.clearTimeout(H.current),H.current=null}),[r&&r.length,p]),n("div",{onScroll:e=>{const n=e.target.scrollHeight-e.target.scrollTop-e.target.offsetHeight;c&&!p&&n<200&&c()},ref:_,className:"pn:h-full pn:overflow-auto",children:[y.map((n,t)=>e("div",{className:"pn:float-left",style:{width:100/N+"%"},children:n.map((n,t)=>e(s,{url:i(n),onSelect:(e,t,r)=>o(n,e,t,r),credit:d&&d(n),crossOrigin:f,shadowEnabled:x,itemHeight:b,className:m&&m(n),onLoad:S,alt:u&&u(n)||"",pending:null==g?void 0:g(n)},t))},t)),p&&e("div",{className:"pn:clear-both pn:flex pn:justify-center pn:p-[30px]",children:e(a,{className:"pn:size-5 pn:text-muted-foreground"})}),!p&&(!r||!r.length)&&!v&&!w&&e("p",{className:"pn:p-[30px] pn:text-center",children:l("sidePanel.noResults")}),v&&e("p",{className:"pn:clear-both pn:p-[30px] pn:text-center",children:l("sidePanel.error")})]})};
@@ -1 +1 @@
1
- import{getImageSize as t}from"@polotno/core/image";export const selectSvg=async({src:e,droppedPos:i,targetElement:o,store:r})=>{var d;if(o&&"image"===o.type&&o.contentEditable){return void o.set({clipSrc:e})}if(o&&"video"===o.type&&o.contentEditable){return void o.set({clipSrc:e})}const{width:n,height:c}=await t(e),l=((null==i?void 0:i.x)||r.width/2)-n/2,a=((null==i?void 0:i.y)||r.height/2)-c/2;null===(d=r.activePage)||void 0===d||d.addElement({type:"svg",width:n,height:c,x:l,y:a,src:e})};
1
+ import{getImageSize as t}from"@polotno/core/image";export const selectSvg=async({src:e,droppedPos:i,targetElement:o,store:n})=>{var d;if(o&&"image"===o.type&&o.contentEditable){return void o.set({clipSrc:e})}if(o&&"video"===o.type&&o.contentEditable){return void o.set({clipSrc:e})}let{width:r,height:c}=await t(e);const l=Math.min(n.width/r,n.height/c,1);r*=l,c*=l;const a=((null==i?void 0:i.x)||n.width/2)-r/2,h=((null==i?void 0:i.y)||n.height/2)-c/2;null===(d=n.activePage)||void 0===d||d.addElement({type:"svg",width:r,height:c,x:a,y:h,src:e})};
@@ -1 +1 @@
1
- var e=this&&this.__rest||function(e,t){var o={};for(var n in e){Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(o[n]=e[n])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(e);i<n.length;i++){t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(o[n[i]]=e[n[i]])}}return o};import{jsx as t,jsxs as o}from"react/jsx-runtime";import*as n from"react";import{observer as i}from"mobx-react-lite";import l from"swr";import{PolotnoIcon as a}from"../icons/registry.js";import{t as r}from"../utils/l10n.js";import{isMobile as s}from"../utils/screen.js";import{textTemplateList as p}from"../utils/api.js";import{fetcher as c}from"../utils/use-api.js";import{localFileToURL as f}from"../utils/file.js";import{registerNextDomDrop as d}from"../canvas/page.js";import{Button as m}from"../primitives/button.js";import{Tabs as h,TabsList as y,TabsTrigger as x}from"../primitives/tabs.js";import{ImagesGrid as u}from"./images-grid.js";let g=async e=>f(e);export function setFontUploadFunc(e){g=e}const v=i(({onSelect:e,onRemove:n,font:i})=>o("div",{style:{fontFamily:i.fontFamily},className:"polotno-font-item pn:relative pn:mb-2.5 pn:flex pn:h-[100px] pn:cursor-pointer pn:flex-col pn:justify-center pn:rounded-md pn:bg-black/40 pn:text-center pn:text-[25px] pn:text-white pn:shadow-[0_0_5px_rgba(16,22,26,0.3)]",onClick:e,children:[i.fontFamily," text",t(m,{style:{position:"absolute",right:0,bottom:0},variant:"ghost",size:"icon-sm",onClick:e=>{e.stopPropagation(),n()},children:t(a,{name:"action.remove"})})]})),b=o=>{var{onSelect:n}=o,i=e(o,["onSelect"]);return t(m,Object.assign({},i,{draggable:!0,className:"polotno-close-panel",onClick:()=>n(),onDragStart:()=>{d(({x:e,y:t})=>{n({x:e,y:t})})},onDragEnd:()=>{d(null)}}))},w=[{previewSize:"25px",fontSize:76,labelKey:"sidePanel.createHeader",textKey:"sidePanel.headerText"},{previewSize:"18px",fontSize:44,labelKey:"sidePanel.createSubHeader",textKey:"sidePanel.subHeaderText"},{previewSize:"14px",fontSize:30,labelKey:"sidePanel.createBody",textKey:"sidePanel.bodyText"}];export const TextPanel=i(({store:e})=>{n.useEffect(()=>{e.loadFont("Roboto")},[]);const i=t=>{var o;const n=t.width||e.width/2,i=((null==t?void 0:t.x)||e.width/2)-n/2,l=((null==t?void 0:t.y)||e.height/2)-t.fontSize/2,a=(e.width+e.height)/2160,r=null===(o=e.activePage)||void 0===o?void 0:o.addElement(Object.assign(Object.assign({type:"text",fontFamily:"Roboto"},t),{x:i,y:l,width:n,fontSize:t.fontSize*a}));s()||null==r||r.toggleEditMode(!0)};n.useEffect(()=>{e.fonts.forEach(t=>e.loadFont(t.fontFamily))},[e.fonts]);const{data:f,error:d}=l(p(),c),[j,S]=n.useState("text");return o("div",{style:{height:"100%",display:"flex",flexDirection:"column"},children:[t(h,{value:j,onValueChange:e=>S(String(e)),className:"pn:mb-3",children:o(y,{className:"pn:w-full pn:h-10",children:[t(x,{value:"text",children:r("sidePanel.text")}),t(x,{value:"font",children:r("sidePanel.myFonts")})]})}),"text"===j&&o("div",{className:"polotno-text-panel-container pn:flex pn:flex-col",style:{height:"calc(100% - 52px)"},children:[w.map(({previewSize:e,fontSize:o,labelKey:n,textKey:l})=>t(b,{style:{fontSize:e},variant:"ghost",className:"pn:mb-[5px] pn:w-full pn:h-auto pn:min-h-[2.5rem] pn:py-1 pn:justify-start pn:font-['Roboto']",onSelect:e=>{i(Object.assign(Object.assign({},e),{fontSize:o,text:r(l),fontFamily:"Roboto"}))},children:r(n)},n)),t(u,{shadowEnabled:!1,images:null==f?void 0:f.items,getPreview:e=>e.preview,getImageClassName:e=>e.json.indexOf("plain")>=0?"polotno-text-preview-plain":"",isLoading:!f,error:d,onSelect:async(t,o)=>{const n=await fetch(t.json),i=await n.json();if(!e.activePage){return}const l=(e.width+e.height)/2160,a=o?o.x-i.width/2*l:e.width/2-i.width/2*l,r=o?o.y-i.height/2*l:e.height/2-i.height/2*l;e.history.transaction(()=>{const t=i.pages[0].children,o=[];t.forEach(t=>{delete t.id;const{id:n}=e.activePage.addElement(Object.assign(Object.assign({},t),{fontSize:t.fontSize*l,x:t.x*l+a,y:t.y*l+r,width:t.width*l,height:t.height*l}));o.push(n)}),e.selectElements(o)})}})]}),"font"===j&&o("div",{style:{display:"flex",flexDirection:"column",height:"calc(100% - 62px)"},children:[o("label",{htmlFor:"polotno-font-upload",children:[o(m,{style:{width:"100%"},onClick:()=>{var e;null===(e=document.querySelector("#polotno-font-upload"))||void 0===e||e.click()},children:[t(a,{name:"text.uploadFont"}),r("sidePanel.uploadFont")]}),t("input",{type:"file",accept:".ttf, .otf, .woff, .woff2, .eot",id:"polotno-font-upload",style:{display:"none"},onChange:async t=>{const{target:o}=t;for(const n of Array.from(o.files||[])){const t=await g(n),o=n.name.split(".")[0].replace(/,/g,"");e.addFont({fontFamily:o,url:t})}o.value=""}})]}),t("div",{style:{paddingTop:"20px",overflow:"auto",height:"100%"},children:e.fonts.map((o,n)=>t(v,{font:o,onSelect:()=>{i({fontSize:80,text:"Cool text",fontFamily:o.fontFamily})},onRemove:()=>{e.find(e=>("text"===e.type&&e.fontFamily===o.fontFamily&&e.set({fontFamily:"Roboto"}),!1)),e.removeFont(o.fontFamily)}},n))})]})]})});
1
+ var e=this&&this.__rest||function(e,t){var o={};for(var n in e){Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(o[n]=e[n])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(e);i<n.length;i++){t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(o[n[i]]=e[n[i]])}}return o};import{jsx as t,jsxs as o}from"react/jsx-runtime";import*as n from"react";import{observer as i}from"mobx-react-lite";import l from"swr";import{PolotnoIcon as a}from"../icons/registry.js";import{t as r}from"../utils/l10n.js";import{isMobile as s}from"../utils/screen.js";import{textTemplateList as p}from"../utils/api.js";import{fetcher as c}from"../utils/use-api.js";import{localFileToURL as f}from"../utils/file.js";import{cssFontFamily as d}from"@polotno/core/fonts";import{registerNextDomDrop as m}from"../canvas/page.js";import{Button as h}from"../primitives/button.js";import{Tabs as y,TabsList as u,TabsTrigger as x}from"../primitives/tabs.js";import{ImagesGrid as g}from"./images-grid.js";import{loadTextTemplate as v}from"./text-template.js";let b=async e=>f(e);export function setFontUploadFunc(e){b=e}const w=i(({onSelect:e,onRemove:n,font:i})=>o("div",{style:{fontFamily:d(i.fontFamily)},className:"polotno-font-item pn:relative pn:mb-2.5 pn:flex pn:h-[100px] pn:cursor-pointer pn:flex-col pn:justify-center pn:rounded-md pn:bg-black/40 pn:text-center pn:text-[25px] pn:text-white pn:shadow-[0_0_5px_rgba(16,22,26,0.3)]",onClick:e,children:[i.fontFamily," text",t(h,{style:{position:"absolute",right:0,bottom:0},variant:"ghost",size:"icon-sm",onClick:e=>{e.stopPropagation(),n()},children:t(a,{name:"action.remove"})})]})),j=o=>{var{onSelect:n}=o,i=e(o,["onSelect"]);return t(h,Object.assign({},i,{draggable:!0,className:"polotno-close-panel",onClick:()=>n(),onDragStart:()=>{m(({x:e,y:t})=>{n({x:e,y:t})})},onDragEnd:()=>{m(null)}}))},S=[{previewSize:"25px",fontSize:76,labelKey:"sidePanel.createHeader",textKey:"sidePanel.headerText"},{previewSize:"18px",fontSize:44,labelKey:"sidePanel.createSubHeader",textKey:"sidePanel.subHeaderText"},{previewSize:"14px",fontSize:30,labelKey:"sidePanel.createBody",textKey:"sidePanel.bodyText"}];export const TextPanel=i(({store:e})=>{n.useEffect(()=>{e.loadFont("Roboto")},[]);const i=t=>{var o;const n=t.width||e.width/2,i=((null==t?void 0:t.x)||e.width/2)-n/2,l=((null==t?void 0:t.y)||e.height/2)-t.fontSize/2,a=(e.width+e.height)/2160,r=null===(o=e.activePage)||void 0===o?void 0:o.addElement(Object.assign(Object.assign({type:"text",fontFamily:"Roboto"},t),{x:i,y:l,width:n,fontSize:t.fontSize*a}));s()||null==r||r.toggleEditMode(!0)};n.useEffect(()=>{e.fonts.forEach(t=>e.loadFont(t.fontFamily))},[e.fonts]);const{data:f,error:d}=l(p(),c),[m,F]=n.useState("text"),[P,z]=n.useState(null),O=n.useRef(null),E=e=>{O.current=e,z(e)};return o("div",{style:{height:"100%",display:"flex",flexDirection:"column"},children:[t(y,{value:m,onValueChange:e=>F(String(e)),className:"pn:mb-3",children:o(u,{className:"pn:w-full pn:h-10",children:[t(x,{value:"text",children:r("sidePanel.text")}),t(x,{value:"font",children:r("sidePanel.myFonts")})]})}),"text"===m&&o("div",{className:"polotno-text-panel-container pn:flex pn:flex-col",style:{height:"calc(100% - 52px)"},children:[S.map(({previewSize:e,fontSize:o,labelKey:n,textKey:l})=>t(j,{style:{fontSize:e},variant:"ghost",className:"pn:mb-[5px] pn:w-full pn:h-auto pn:min-h-[2.5rem] pn:py-1 pn:justify-start pn:font-['Roboto']",onSelect:e=>{i(Object.assign(Object.assign({},e),{fontSize:o,text:r(l),fontFamily:"Roboto"}))},children:r(n)},n)),t(g,{shadowEnabled:!1,images:null==f?void 0:f.items,getPreview:e=>e.preview,getImageClassName:e=>e.json.indexOf("plain")>=0?"polotno-text-preview-plain":"",isLoading:!f,error:d,getIsLoading:e=>e.json===P,onSelect:async(t,o)=>{if(O.current===t.json){return}E(t.json);const n=await v(e,t).finally(()=>{O.current===t.json&&E(null)});if(!e.activePage){return}const i=(e.width+e.height)/2160,l=o?o.x-n.width/2*i:e.width/2-n.width/2*i,a=o?o.y-n.height/2*i:e.height/2-n.height/2*i;e.history.transaction(()=>{const t=n.pages[0].children,o=[];t.forEach(t=>{delete t.id;const{id:n}=e.activePage.addElement(Object.assign(Object.assign({},t),{fontSize:t.fontSize*i,x:t.x*i+l,y:t.y*i+a,width:t.width*i,height:t.height*i}));o.push(n)}),e.selectElements(o)})}})]}),"font"===m&&o("div",{style:{display:"flex",flexDirection:"column",height:"calc(100% - 62px)"},children:[o("label",{htmlFor:"polotno-font-upload",children:[o(h,{style:{width:"100%"},onClick:()=>{var e;null===(e=document.querySelector("#polotno-font-upload"))||void 0===e||e.click()},children:[t(a,{name:"text.uploadFont"}),r("sidePanel.uploadFont")]}),t("input",{type:"file",accept:".ttf, .otf, .woff, .woff2, .eot",id:"polotno-font-upload",style:{display:"none"},onChange:async t=>{const{target:o}=t;for(const n of Array.from(o.files||[])){const t=await b(n),o=n.name.split(".")[0].replace(/,/g,"");e.addFont({fontFamily:o,url:t})}o.value=""}})]}),t("div",{style:{paddingTop:"20px",overflow:"auto",height:"100%"},children:e.fonts.map((o,n)=>t(w,{font:o,onSelect:()=>{i({fontSize:80,text:"Cool text",fontFamily:o.fontFamily})},onRemove:()=>{e.find(e=>("text"===e.type&&e.fontFamily===o.fontFamily&&e.set({fontFamily:"Roboto"}),!1)),e.removeFont(o.fontFamily)}},n))})]})]})});
@@ -0,0 +1,12 @@
1
+ import type { StoreType } from '../ui-types.js';
2
+ export type TextTemplateFont = {
3
+ fontFamily: string;
4
+ fontStyle?: string;
5
+ fontWeight?: string | number;
6
+ };
7
+ export type TextTemplateItem = {
8
+ preview: string;
9
+ json: string;
10
+ fonts?: TextTemplateFont[];
11
+ };
12
+ export declare function loadTextTemplate(store: Pick<StoreType, 'loadFont'>, item: TextTemplateItem): Promise<any>;
@@ -0,0 +1 @@
1
+ import{extractFontSpecsFromHtml as t}from"../utils/rich-text-html.js";export async function loadTextTemplate(o,e){const a=Date.now(),l=((o=[])=>o.filter(t=>t.fontFamily).flatMap(o=>{var e,a;return t("",{fontFamily:o.fontFamily,fontWeight:null!==(e=o.fontWeight)&&void 0!==e?e:"normal",fontStyle:null!==(a=o.fontStyle)&&void 0!==a?a:"normal"})}))(e.fonts).map(t=>o.loadFont(t.family,t.style,t.weight).catch(()=>{})),n=await(await fetch(e.json)).json(),i=3e3-(Date.now()-a);if(i>0){let t;await Promise.race([Promise.all(l),new Promise(o=>{t=setTimeout(o,i)})]),clearTimeout(t)}return n}
@@ -1 +1 @@
1
- import{jsx as t,jsxs as e}from"react/jsx-runtime";import n from"react";import{observer as o}from"mobx-react-lite";import{List as i}from"react-window";import r from"swr";import{PolotnoIcon as a}from"../icons/registry.js";import{getFontsList as s,globalFonts as l,isGoogleFontChanged as c}from"../utils/fonts.js";import{getGoogleFontImage as p,getGoogleFontsListAPI as m}from"../utils/api.js";import{t as d}from"../utils/l10n.js";import{flags as f}from"../utils/flags.js";import{Button as h}from"../primitives/button.js";import{NumberInput as u}from"../primitives/numeric-input.js";export{NumberInput}from"../primitives/numeric-input.js";import{InputGroup as x}from"../primitives/input-group.js";import{SliderField as g}from"../primitives/slider-field.js";import{Popover as v,PopoverContent as b,PopoverTrigger as T}from"../primitives/popover.js";import{Tooltip as F,TooltipContent as y,TooltipTrigger as N}from"../primitives/tooltip.js";import{TooltipIconButton as S}from"../primitives/tooltip-icon-button.js";import{Separator as C}from"../primitives/separator.js";import{cn as w}from"../lib/utils.js";import{cycleNext as j}from"./toolbar-shared.js";import{isBoldWeight as z}from"@polotno/core/rich-text-html";import{ColorPicker as E}from"./color-picker.js";import A from"./filters-picker.js";import{AnimationsPicker as D}from"./animations-picker.js";import{ElementContainer as k,extendToolbar as I}from"./element-container.js";import{TextAiWrite as O}from"./text-ai-write.js";const M=s(),L=({fontFamily:e,handleClick:o,modifiers:i,store:r,isCustom:a})=>{const[s,l]=n.useState(!a);if(n.useEffect(()=>{s||r.loadFont(e)},[e,s]),"_divider"===e){return t("div",{style:{paddingTop:"10px"},children:t(C,{})})}const c=s?t("img",{src:p(e),alt:e,onError:()=>{l(!1)},className:"pn:h-5 pn:dark:invert"}):e;return t("button",{type:"button",onClick:o,disabled:i.disabled,"data-active":i.active||void 0,className:w("pn:flex pn:w-full pn:items-center pn:rounded-sm pn:px-2 pn:py-1.5 pn:text-left pn:text-sm pn:hover:bg-muted",i.active&&"pn:bg-muted"),style:{fontFamily:'"'+e+'"'},children:c})},V=({index:e,style:n,filteredFonts:o,activeFont:i,onFontSelect:r,store:a})=>{const s=o[e];return t("div",{style:n,children:t(L,{fontFamily:s,modifiers:{active:i===s},handleClick:()=>r(s),store:a,isCustom:a.fonts.find(t=>t.fontFamily===s)||l.find(t=>t.fontFamily===s)},s)})},_=({onChange:o,defaultValue:i})=>{const r=n.useRef(null);return n.useEffect(()=>{r.current&&r.current.focus()},[]),e(x,{children:[t("span",{className:"pn:flex pn:items-center pn:pl-2 pn:pr-1 pn:text-muted-foreground",children:t(a,{name:"action.search",className:"pn:size-3.5 pn:shrink-0 pn:opacity-50"})}),t("input",{ref:r,"data-slot":"input-group-control",defaultValue:i,onChange:t=>o(t.target.value),className:"pn:h-full pn:w-full pn:flex-1 pn:border-0 pn:bg-transparent pn:px-2 pn:text-xs pn:outline-none pn:placeholder:text-muted-foreground"})]})};export const FontMenu=({store:o,fonts:r,activeFont:s,activeFontLabel:l,onFontSelect:c,mixed:p,mixedFonts:m,open:f,onOpenChange:u})=>{const[x,g]=n.useState(""),S=r.filter(t=>(null==t?void 0:t.toLowerCase().indexOf(x.toLowerCase()))>=0);return e(v,{open:f,onOpenChange:u,children:[e(F,{children:[t(N,{render:t(T,{render:e(h,{variant:"ghost",size:"sm",className:"pn:gap-1 pn:overflow-hidden pn:whitespace-nowrap",style:{fontFamily:p?void 0:'"'+s+'"',fontStyle:p?"italic":void 0,color:p?"#5c7080":void 0},"aria-label":d("toolbar.fontFamily"),children:[t("span",{className:"pn:truncate",children:p?d("toolbar.fontFamilyMixed"):l}),t(a,{name:"ui.chevronDown",className:"pn:size-3 pn:shrink-0 pn:opacity-50"})]})})}),t(y,{side:"bottom",children:p&&m&&m.length>0?`${d("toolbar.fontsInSelection")}: ${m.join(", ")}`:d("toolbar.fontFamily")})]}),t(b,{className:"pn:w-[230px] pn:p-2",align:"start",children:e("div",{children:[t(_,{onChange:t=>g(t),defaultValue:x}),t("div",{style:{paddingTop:"5px"},children:t(i,{style:{height:Math.min(400,30*S.length)+10,width:210},rowCount:S.length,rowHeight:30,rowComponent:V,rowProps:{filteredFonts:S,activeFont:s,onFontSelect:c,store:o}})})]})})]})};const R={};export const fetcher=t=>R[t]?Promise.resolve(R[t]):fetch(t).then(t=>t.json()).then(e=>(R[t]=e,e));export const TextFontFamily=o(({elements:e,store:o})=>{const[i,a]=n.useState(!1),{data:s,mutate:p}=r(i?m():null,fetcher,{isPaused:()=>c(),fallbackData:[]});n.useEffect(()=>{p()},[c()]);const d=o.fonts.concat(l).map(t=>t.fontFamily).concat((null==s?void 0:s.length)&&!c()?s:M);let f=e[0].fontFamily;f.length>15&&(f=f.slice(0,15)+"...");const h=[];o.find(t=>("text"===t.type&&h.push(t.fontFamily),!1));const u=[...new Set(h.concat("_divider").concat(d))];return t(FontMenu,{fonts:u,activeFont:e[0].fontFamily,activeFontLabel:f,store:o,open:i,onOpenChange:a,onFontSelect:t=>{o.history.transaction(()=>{e.forEach(e=>{e.set({fontFamily:t})})})}})});export const TextFontSize=o(({elements:o,store:i})=>{const[r,a]=n.useState(!1),[s,l]=n.useState(!1);return e(F,{open:!s&&r,onOpenChange:t=>{s||a(t)},children:[t(N,{render:t(u,{"aria-label":d("toolbar.fontSize"),onFocus:()=>l(!0),onBlur:()=>l(!1),onValueChange:t=>{i.history.transaction(()=>{o.forEach(e=>{e.set({fontSize:t,width:Math.max(t,e.width)})})})},value:Math.round(o[0].fontSize),style:{width:"50px"},min:5,max:4*i.height})}),t(y,{side:"bottom",children:d("toolbar.fontSize")})]})});export const ALIGN_OPTIONS=["left","center","right","justify"];export const VERTICAL_ALIGN_OPTIONS=["top","middle","bottom"];export const VERTICAL_ALIGN_ICONS={top:t(a,{name:"text.valignTop",className:"pn:size-4"}),middle:t(a,{name:"text.valignMiddle",className:"pn:size-4"}),bottom:t(a,{name:"text.valignBottom",className:"pn:size-4"})};export const TextFontVariant=o(({elements:n,store:o})=>{const i=n[0],r=z(i.fontWeight),s="italic"===i.fontStyle,l=i.textDecoration.indexOf("underline")>=0,c=i.textDecoration.indexOf("line-through")>=0;return e("div",{className:"pn:flex pn:items-center pn:gap-0.5",children:[e(F,{children:[t(N,{render:t(h,{variant:"ghost",size:"icon-sm",onMouseDown:t=>{t.preventDefault()},onClick:()=>{const t=j(ALIGN_OPTIONS,i.align);o.history.transaction(()=>{n.forEach(e=>{e.set({align:t})})})},"aria-label":d("toolbar.textAlign"),children:"left"===i.align?t(a,{name:"text.alignLeft",className:"pn:size-4"}):"center"===i.align?t(a,{name:"text.alignCenter",className:"pn:size-4"}):"right"===i.align?t(a,{name:"text.alignRight",className:"pn:size-4"}):t(a,{name:"text.alignJustify",className:"pn:size-4"})})}),t(y,{side:"bottom",children:d("toolbar.textAlign")})]}),f.textVerticalResizeEnabled&&e(F,{children:[t(N,{render:t(h,{variant:"ghost",size:"icon-sm",onMouseDown:t=>{t.preventDefault()},onClick:()=>{const t=j(VERTICAL_ALIGN_OPTIONS,i.verticalAlign);o.history.transaction(()=>{n.forEach(e=>{e.set({verticalAlign:t})})})},"aria-label":d("toolbar.verticalAlign"),children:VERTICAL_ALIGN_ICONS[i.verticalAlign]})}),t(y,{side:"bottom",children:d("toolbar.verticalAlign")})]}),t(S,{label:d("toolbar.bold"),side:"bottom",active:r,onMouseDown:t=>{t.preventDefault()},onClick:()=>{const t=z(i.fontWeight);o.history.transaction(()=>{n.forEach(e=>{e.set({fontWeight:t?"400":"700"})})})},children:t(a,{name:"text.bold",className:"pn:size-4"})}),t(S,{label:d("toolbar.italic"),side:"bottom",active:s,onMouseDown:t=>{t.preventDefault()},onClick:()=>{const t="italic"===i.fontStyle;o.history.transaction(()=>{n.forEach(e=>{t?e.set({fontStyle:"normal"}):e.set({fontStyle:"italic"})})})},children:t(a,{name:"text.italic",className:"pn:size-4"})}),t(S,{label:d("toolbar.underline"),side:"bottom",active:l,onMouseDown:t=>{t.preventDefault()},onClick:()=>{let t=i.textDecoration.split(" ");t.indexOf("underline")>=0?t=t.filter(t=>"underline"!==t):t.push("underline"),o.history.transaction(()=>{n.forEach(e=>{e.set({textDecoration:t.join(" ")})})})},children:t(a,{name:"text.underline",className:"pn:size-4"})}),t(S,{label:d("toolbar.strikethrough"),side:"bottom",active:c,onMouseDown:t=>{t.preventDefault()},onClick:()=>{let t=i.textDecoration.split(" ");t.indexOf("line-through")>=0?t=t.filter(t=>"line-through"!==t):t.push("line-through"),o.history.transaction(()=>{n.forEach(e=>{e.set({textDecoration:t.join(" ")})})})},children:t(a,{name:"text.strikethrough",className:"pn:size-4"})})]})});export const TextTransform=o(({elements:e,store:n})=>{const o="uppercase"==e[0].textTransform;return t("div",{className:"pn:flex pn:items-center pn:gap-0.5",children:t(S,{label:d("toolbar.uppercase"),active:o,onMouseDown:t=>{t.preventDefault()},onClick:()=>{n.history.transaction(()=>{e.forEach(t=>{t.set({textTransform:"uppercase"===t.textTransform?"none":"uppercase"})})})},children:t(a,{name:"text.uppercase",className:"pn:size-4"})})})});export const TextFill=o(({elements:e,store:n})=>t(E,{value:e[0].fill,gradientEnabled:!0,onChange:t=>n.history.transaction(()=>{e.forEach(e=>{e.set({fill:t})})}),store:n}));export const TextSpacing=o(({elements:n,store:o})=>{const i=n[0],r=t=>{o.history.transaction(()=>{n.forEach(e=>{e.set(t)})})},s="number"==typeof i.lineHeight?100*i.lineHeight:120;return e(v,{children:[e(F,{children:[t(N,{render:t(T,{render:t(h,{variant:"ghost",size:"icon-sm","aria-label":d("toolbar.spacing"),children:t(a,{name:"text.spacing",className:"pn:size-5"})})})}),t(y,{side:"bottom",children:d("toolbar.spacing")})]}),e(b,{align:"start",className:"pn:w-[230px] pn:p-[15px]",children:[t(g,{label:d("toolbar.lineHeight"),value:Math.round(s),onChange:t=>r({lineHeight:t/100}),min:50,max:250}),t(g,{label:d("toolbar.letterSpacing"),value:Math.round(100*i.letterSpacing),onChange:t=>r({letterSpacing:t/100}),min:-50,max:250})]})]})});export const TextFilters=A;export const TextAnimations=D;const P={TextFontFamily,TextFontSize,TextFontVariant,TextTransform,TextFill,TextSpacing,TextAiWrite:O,TextFilters:A,TextAnimations:D};export const TextToolbar=o(({store:e,components:n})=>{const o=e.selectedElements,i=["TextFill","TextFontFamily","TextFontSize","TextFontVariant","TextSpacing","TextTransform","TextFilters",f.animationsEnabled&&"TextAnimations",f.aiTextEnabled&&"TextAiWrite"],r=I({type:"text",usedItems:i,components:n});return t(k,{items:r,itemRender:i=>{const r=(null==n?void 0:n[i])||P[i];return r?t(r,{elements:o,element:o[0],store:e},i):null}})});export default TextToolbar;
1
+ import{jsx as t,jsxs as e}from"react/jsx-runtime";import n from"react";import{observer as o}from"mobx-react-lite";import{List as i}from"react-window";import r from"swr";import{PolotnoIcon as a}from"../icons/registry.js";import{getFontsList as s,globalFonts as l,isGoogleFontChanged as c}from"../utils/fonts.js";import{getGoogleFontImage as p,getGoogleFontsListAPI as m}from"../utils/api.js";import{t as d}from"../utils/l10n.js";import{flags as f}from"../utils/flags.js";import{Button as h}from"../primitives/button.js";import{NumberInput as u}from"../primitives/numeric-input.js";export{NumberInput}from"../primitives/numeric-input.js";import{InputGroup as x}from"../primitives/input-group.js";import{SliderField as g}from"../primitives/slider-field.js";import{Popover as v,PopoverContent as b,PopoverTrigger as T}from"../primitives/popover.js";import{Tooltip as F,TooltipContent as y,TooltipTrigger as N}from"../primitives/tooltip.js";import{TooltipIconButton as S}from"../primitives/tooltip-icon-button.js";import{Separator as C}from"../primitives/separator.js";import{cn as w}from"../lib/utils.js";import{cycleNext as j}from"./toolbar-shared.js";import{isBoldWeight as z}from"@polotno/core/rich-text-html";import{cssFontFamily as E}from"@polotno/core/fonts";import{ColorPicker as A}from"./color-picker.js";import D from"./filters-picker.js";import{AnimationsPicker as k}from"./animations-picker.js";import{ElementContainer as I,extendToolbar as O}from"./element-container.js";import{TextAiWrite as M}from"./text-ai-write.js";const L=s(),V=({fontFamily:e,handleClick:o,modifiers:i,store:r,isCustom:a})=>{const[s,l]=n.useState(!a);if(n.useEffect(()=>{s||r.loadFont(e)},[e,s]),"_divider"===e){return t("div",{style:{paddingTop:"10px"},children:t(C,{})})}const c=s?t("img",{src:p(e),alt:e,onError:()=>{l(!1)},className:"pn:h-5 pn:dark:invert"}):e;return t("button",{type:"button",onClick:o,disabled:i.disabled,"data-active":i.active||void 0,className:w("pn:flex pn:w-full pn:items-center pn:rounded-sm pn:px-2 pn:py-1.5 pn:text-left pn:text-sm pn:hover:bg-muted",i.active&&"pn:bg-muted"),style:{fontFamily:E(e)},children:c})},_=({index:e,style:n,filteredFonts:o,activeFont:i,onFontSelect:r,store:a})=>{const s=o[e];return t("div",{style:n,children:t(V,{fontFamily:s,modifiers:{active:i===s},handleClick:()=>r(s),store:a,isCustom:a.fonts.find(t=>t.fontFamily===s)||l.find(t=>t.fontFamily===s)},s)})},R=({onChange:o,defaultValue:i})=>{const r=n.useRef(null);return n.useEffect(()=>{r.current&&r.current.focus()},[]),e(x,{children:[t("span",{className:"pn:flex pn:items-center pn:pl-2 pn:pr-1 pn:text-muted-foreground",children:t(a,{name:"action.search",className:"pn:size-3.5 pn:shrink-0 pn:opacity-50"})}),t("input",{ref:r,"data-slot":"input-group-control",defaultValue:i,onChange:t=>o(t.target.value),className:"pn:h-full pn:w-full pn:flex-1 pn:border-0 pn:bg-transparent pn:px-2 pn:text-xs pn:outline-none pn:placeholder:text-muted-foreground"})]})};export const FontMenu=({store:o,fonts:r,activeFont:s,activeFontLabel:l,onFontSelect:c,mixed:p,mixedFonts:m,open:f,onOpenChange:u})=>{const[x,g]=n.useState(""),S=r.filter(t=>(null==t?void 0:t.toLowerCase().indexOf(x.toLowerCase()))>=0);return e(v,{open:f,onOpenChange:u,children:[e(F,{children:[t(N,{render:t(T,{render:e(h,{variant:"ghost",size:"sm",className:"pn:gap-1 pn:overflow-hidden pn:whitespace-nowrap",style:{fontFamily:p?void 0:E(s),fontStyle:p?"italic":void 0,color:p?"#5c7080":void 0},"aria-label":d("toolbar.fontFamily"),children:[t("span",{className:"pn:truncate",children:p?d("toolbar.fontFamilyMixed"):l}),t(a,{name:"ui.chevronDown",className:"pn:size-3 pn:shrink-0 pn:opacity-50"})]})})}),t(y,{side:"bottom",children:p&&m&&m.length>0?`${d("toolbar.fontsInSelection")}: ${m.join(", ")}`:d("toolbar.fontFamily")})]}),t(b,{className:"pn:w-[230px] pn:p-2",align:"start",children:e("div",{children:[t(R,{onChange:t=>g(t),defaultValue:x}),t("div",{style:{paddingTop:"5px"},children:t(i,{style:{height:Math.min(400,30*S.length)+10,width:210},rowCount:S.length,rowHeight:30,rowComponent:_,rowProps:{filteredFonts:S,activeFont:s,onFontSelect:c,store:o}})})]})})]})};const P={};export const fetcher=t=>P[t]?Promise.resolve(P[t]):fetch(t).then(t=>t.json()).then(e=>(P[t]=e,e));export const TextFontFamily=o(({elements:e,store:o})=>{const[i,a]=n.useState(!1),{data:s,mutate:p}=r(i?m():null,fetcher,{isPaused:()=>c(),fallbackData:[]});n.useEffect(()=>{p()},[c()]);const d=o.fonts.concat(l).map(t=>t.fontFamily).concat((null==s?void 0:s.length)&&!c()?s:L);let f=e[0].fontFamily;f.length>15&&(f=f.slice(0,15)+"...");const h=[];o.find(t=>("text"===t.type&&h.push(t.fontFamily),!1));const u=[...new Set(h.concat("_divider").concat(d))];return t(FontMenu,{fonts:u,activeFont:e[0].fontFamily,activeFontLabel:f,store:o,open:i,onOpenChange:a,onFontSelect:t=>{o.history.transaction(()=>{e.forEach(e=>{e.set({fontFamily:t})})})}})});export const TextFontSize=o(({elements:o,store:i})=>{const[r,a]=n.useState(!1),[s,l]=n.useState(!1);return e(F,{open:!s&&r,onOpenChange:t=>{s||a(t)},children:[t(N,{render:t(u,{"aria-label":d("toolbar.fontSize"),onFocus:()=>l(!0),onBlur:()=>l(!1),onValueChange:t=>{i.history.transaction(()=>{o.forEach(e=>{e.set({fontSize:t,width:Math.max(t,e.width)})})})},value:Math.round(o[0].fontSize),style:{width:"50px"},min:5,max:4*i.height})}),t(y,{side:"bottom",children:d("toolbar.fontSize")})]})});export const ALIGN_OPTIONS=["left","center","right","justify"];export const VERTICAL_ALIGN_OPTIONS=["top","middle","bottom"];export const VERTICAL_ALIGN_ICONS={top:t(a,{name:"text.valignTop",className:"pn:size-4"}),middle:t(a,{name:"text.valignMiddle",className:"pn:size-4"}),bottom:t(a,{name:"text.valignBottom",className:"pn:size-4"})};export const TextFontVariant=o(({elements:n,store:o})=>{const i=n[0],r=z(i.fontWeight),s="italic"===i.fontStyle,l=i.textDecoration.indexOf("underline")>=0,c=i.textDecoration.indexOf("line-through")>=0;return e("div",{className:"pn:flex pn:items-center pn:gap-0.5",children:[e(F,{children:[t(N,{render:t(h,{variant:"ghost",size:"icon-sm",onMouseDown:t=>{t.preventDefault()},onClick:()=>{const t=j(ALIGN_OPTIONS,i.align);o.history.transaction(()=>{n.forEach(e=>{e.set({align:t})})})},"aria-label":d("toolbar.textAlign"),children:"left"===i.align?t(a,{name:"text.alignLeft",className:"pn:size-4"}):"center"===i.align?t(a,{name:"text.alignCenter",className:"pn:size-4"}):"right"===i.align?t(a,{name:"text.alignRight",className:"pn:size-4"}):t(a,{name:"text.alignJustify",className:"pn:size-4"})})}),t(y,{side:"bottom",children:d("toolbar.textAlign")})]}),f.textVerticalResizeEnabled&&e(F,{children:[t(N,{render:t(h,{variant:"ghost",size:"icon-sm",onMouseDown:t=>{t.preventDefault()},onClick:()=>{const t=j(VERTICAL_ALIGN_OPTIONS,i.verticalAlign);o.history.transaction(()=>{n.forEach(e=>{e.set({verticalAlign:t})})})},"aria-label":d("toolbar.verticalAlign"),children:VERTICAL_ALIGN_ICONS[i.verticalAlign]})}),t(y,{side:"bottom",children:d("toolbar.verticalAlign")})]}),t(S,{label:d("toolbar.bold"),side:"bottom",active:r,onMouseDown:t=>{t.preventDefault()},onClick:()=>{const t=z(i.fontWeight);o.history.transaction(()=>{n.forEach(e=>{e.set({fontWeight:t?"400":"700"})})})},children:t(a,{name:"text.bold",className:"pn:size-4"})}),t(S,{label:d("toolbar.italic"),side:"bottom",active:s,onMouseDown:t=>{t.preventDefault()},onClick:()=>{const t="italic"===i.fontStyle;o.history.transaction(()=>{n.forEach(e=>{t?e.set({fontStyle:"normal"}):e.set({fontStyle:"italic"})})})},children:t(a,{name:"text.italic",className:"pn:size-4"})}),t(S,{label:d("toolbar.underline"),side:"bottom",active:l,onMouseDown:t=>{t.preventDefault()},onClick:()=>{let t=i.textDecoration.split(" ");t.indexOf("underline")>=0?t=t.filter(t=>"underline"!==t):t.push("underline"),o.history.transaction(()=>{n.forEach(e=>{e.set({textDecoration:t.join(" ")})})})},children:t(a,{name:"text.underline",className:"pn:size-4"})}),t(S,{label:d("toolbar.strikethrough"),side:"bottom",active:c,onMouseDown:t=>{t.preventDefault()},onClick:()=>{let t=i.textDecoration.split(" ");t.indexOf("line-through")>=0?t=t.filter(t=>"line-through"!==t):t.push("line-through"),o.history.transaction(()=>{n.forEach(e=>{e.set({textDecoration:t.join(" ")})})})},children:t(a,{name:"text.strikethrough",className:"pn:size-4"})})]})});export const TextTransform=o(({elements:e,store:n})=>{const o="uppercase"==e[0].textTransform;return t("div",{className:"pn:flex pn:items-center pn:gap-0.5",children:t(S,{label:d("toolbar.uppercase"),active:o,onMouseDown:t=>{t.preventDefault()},onClick:()=>{n.history.transaction(()=>{e.forEach(t=>{t.set({textTransform:"uppercase"===t.textTransform?"none":"uppercase"})})})},children:t(a,{name:"text.uppercase",className:"pn:size-4"})})})});export const TextFill=o(({elements:e,store:n})=>t(A,{value:e[0].fill,gradientEnabled:!0,onChange:t=>n.history.transaction(()=>{e.forEach(e=>{e.set({fill:t})})}),store:n}));export const TextSpacing=o(({elements:n,store:o})=>{const i=n[0],r=t=>{o.history.transaction(()=>{n.forEach(e=>{e.set(t)})})},s="number"==typeof i.lineHeight?100*i.lineHeight:120;return e(v,{children:[e(F,{children:[t(N,{render:t(T,{render:t(h,{variant:"ghost",size:"icon-sm","aria-label":d("toolbar.spacing"),children:t(a,{name:"text.spacing",className:"pn:size-5"})})})}),t(y,{side:"bottom",children:d("toolbar.spacing")})]}),e(b,{align:"start",className:"pn:w-[230px] pn:p-[15px]",children:[t(g,{label:d("toolbar.lineHeight"),value:Math.round(s),onChange:t=>r({lineHeight:t/100}),min:50,max:250}),t(g,{label:d("toolbar.letterSpacing"),value:Math.round(100*i.letterSpacing),onChange:t=>r({letterSpacing:t/100}),min:-50,max:250})]})]})});export const TextFilters=D;export const TextAnimations=k;const G={TextFontFamily,TextFontSize,TextFontVariant,TextTransform,TextFill,TextSpacing,TextAiWrite:M,TextFilters:D,TextAnimations:k};export const TextToolbar=o(({store:e,components:n})=>{const o=e.selectedElements,i=["TextFill","TextFontFamily","TextFontSize","TextFontVariant","TextSpacing","TextTransform","TextFilters",f.animationsEnabled&&"TextAnimations",f.aiTextEnabled&&"TextAiWrite"],r=O({type:"text",usedItems:i,components:n});return t(I,{items:r,itemRender:i=>{const r=(null==n?void 0:n[i])||G[i];return r?t(r,{elements:o,element:o[0],store:e},i):null}})});export default TextToolbar;
@@ -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 d}from"../lib/utils.js";import{NumericInput as l}from"../primitives/numeric-input.js";import{SpeedControl as m}from"../primitives/speed-control.js";import{Slider as p}from"../primitives/slider.js";import{Popover as c,PopoverContent as h,PopoverTrigger as u}from"../primitives/popover.js";import{Tooltip as g,TooltipContent as v,TooltipTrigger as x}from"../primitives/tooltip.js";import{AnimationsPicker as f}from"./animations-picker.js";import{flags as b}from"../utils/flags.js";import{getVideoDuration as w,getVideoObjectPreview as y,getVideoSize as V}from"@polotno/core/video";import{t as C}from"../utils/l10n.js";import{PolotnoIcon as T}from"../icons/registry.js";export const VideoTrim=o(({element:o})=>{const r=i.useRef(null),[n,a]=i.useState([]);i.useEffect(()=>{a([])},[o.src]);const d=async()=>{if(!o.src){return}if(n.length){return}const{width:e,height:t}=await V(o.src),i=e/t,{src:s}=o,d=r.current.offsetHeight,l=r.current.offsetWidth,m=d*i,p=Math.ceil(l/m),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)}),a([]);for(let e=0;e<p;e++){const t=e*c/p,i=await y(h,u,t);a(e=>e.concat(i))}}catch(g){console.error("Error generating previews:",g)}},l=(e,t)=>{e.preventDefault();const i=e=>{e.preventDefault();const{clientX:i}=e,{left:n,width:s}=r.current.getBoundingClientRect(),a=(i-n)/s;"start"===t?o.set({startTime:Math.min(o.endTime,Math.max(0,a))}):"end"===t&&o.set({endTime:Math.min(1,Math.max(o.startTime,a))})},n=()=>{window.removeEventListener("mousemove",i),window.removeEventListener("mouseup",n)};window.addEventListener("mousemove",i),window.addEventListener("mouseup",n)};return t(c,{onOpenChange:e=>{e&&setTimeout(d,0)},children:[e(u,{render:t(s,{variant:"ghost",size:"sm",children:[e(T,{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:C("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)"}}),e("div",{style:{position:"absolute",top:"0",left:100*o.startTime+"%",width:"10px",height:"30px",borderRadius:"0px",backgroundColor:"rgb(0, 161, 255, 0.9)",cursor:"ew-resize"},onMouseDown:e=>{l(e,"start")}}),e("div",{style:{position:"absolute",top:"0",right:100-100*o.endTime+"%",width:"10px",height:"30px",borderRadius:"0px",backgroundColor:"rgb(0, 161, 255, 0.9)",cursor:"ew-resize"},onMouseDown:e=>{l(e,"end")}})]})]})})]})});const j=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(x,{render:e(u,{render:e(s,{variant:"ghost",size:"icon-sm","aria-label":C("toolbar.volume"),children:e(T,{name:"action.unmuted",className:"pn:size-4"})})})}),e(v,{children:C("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(p,{value:[o],onValueChange:e=>{r(d(e))},min:0,max:100,step:1})}),e(l,{value:o,onValueChange:e=>{r(a(e,0,100))},style:{width:"50px",padding:"0 5px",marginLeft:"10px"},min:0,max:100})]})})]})}),E=o(({element:i})=>t(c,{children:[t(g,{children:[e(x,{render:e(u,{render:t(s,{variant:"ghost",size:"sm","aria-label":C("toolbar.speed"),children:[e(T,{name:"toolbar.duration",className:"pn:size-4"}),i.speed,"×"]})})}),e(v,{children:C("toolbar.speed")})]}),t(h,{style:{padding:"10px",width:"250px"},align:"start",children:[e("div",{style:{fontSize:"12px",marginBottom:"8px"},children:C("toolbar.speed")}),e(m,{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:C("toolbar.removeClip")}):e(s,{variant:"ghost",size:"sm",onClickCapture:e=>{e.stopPropagation(),i.openSidePanel("image-clip")},children:C("toolbar.clip")}):null);const z={VideoTrim,VideoAnimations:f,VideoVolume:j,VideoSpeed:E,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]||z[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 r}from"mobx-react-lite";import{ElementContainer as o,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,startPointerDrag as z}from"../utils/pointer-drag.js";import{PolotnoIcon as E}from"../icons/registry.js";export const VideoTrim=r(({element:r})=>{const o=i.useRef(null),[n,l]=i.useState([]);i.useEffect(()=>{l([])},[r.src]);const d=async()=>{if(!r.src){return}if(n.length){return}const{width:e,height:t}=await j(r.src);if(!o.current){return}const i=e/t,{src:s}=r,a=o.current.offsetHeight,d=o.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)}},p=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*r.startTime+"%"}:{right:100-100*r.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}=o.current.getBoundingClientRect(),s=r.startTime,l=r.endTime;z(e,{slopX:T,onMove:e=>{const o=(e.clientX-i)/n;"start"===t?r.set({startTime:a(s+o,0,l)}):r.set({endTime:a(l+o,s,1)})}})})(e,t)});return t(c,{onOpenChange:e=>{e&&setTimeout(d,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:(r.duration*(r.endTime-r.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:o,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*r.startTime+"%",height:"30px",backgroundColor:"rgb(0, 0, 0, 0.5)"}}),e("div",{style:{position:"absolute",top:"0",right:"0%",width:100-100*r.endTime+"%",height:"30px",backgroundColor:"rgb(0, 0, 0, 0.5)"}}),p("start"),p("end")]})]})})]})});const N=r(({element:i})=>{const r=Math.round(100*i.volume),o=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:[r],onValueChange:e=>{o(l(e))},min:0,max:100,step:1})}),e(d,{value:r,onValueChange:e=>{o(a(e,0,100))},style:{width:"50px",padding:"0 5px",marginLeft:"10px"},min:0,max:100})]})})]})}),S=r(({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=r(({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=r(({store:t,components:i})=>{const r=t.selectedElements,s=["VideoTrim","VideoVolume","VideoSpeed","VideoClip",b.animationsEnabled&&"VideoAnimations"],a=n({type:"video",usedItems:s,components:i});return e(o,{items:a,itemRender:o=>{const n=i[o]||k[o];return e(n,{elements:r,element:r[0],store:t},o)}})});export default VideoToolbar;