polotno 4.22.0 → 4.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/THIRD_PARTY_NOTICES.md +7 -7
  2. package/blueprint/toolbar/color-picker.js +2 -2
  3. package/canvas/element.js +1 -1
  4. package/canvas/fade-overlay.d.ts +5 -0
  5. package/canvas/fade-overlay.js +1 -1
  6. package/canvas/html-element.js +1 -1
  7. package/canvas/image-element.js +1 -1
  8. package/canvas/line-element.js +1 -1
  9. package/canvas/page.js +1 -1
  10. package/canvas/quill-font-formats.d.ts +1 -0
  11. package/canvas/quill-font-formats.js +1 -1
  12. package/canvas/radial-gradient-handle.d.ts +14 -0
  13. package/canvas/radial-gradient-handle.js +1 -0
  14. package/canvas/render-tag-element.js +1 -1
  15. package/canvas/rich-editor.js +12 -6
  16. package/canvas/text-element/legacy-padding-warning.d.ts +6 -0
  17. package/canvas/text-element/legacy-padding-warning.js +1 -0
  18. package/canvas/text-element/max-font-size.js +1 -1
  19. package/canvas/text-element.js +1 -1
  20. package/canvas/use-color.d.ts +24 -2
  21. package/canvas/use-color.js +1 -1
  22. package/icons/registry.d.ts +1 -0
  23. package/icons/registry.js +1 -1
  24. package/model/group-model.d.ts +26 -10
  25. package/model/group-model.js +1 -1
  26. package/model/node-model.d.ts +10 -1
  27. package/model/node-model.js +1 -1
  28. package/model/page-model.d.ts +75 -33
  29. package/model/page-model.js +1 -1
  30. package/model/table-model.d.ts +29 -9
  31. package/model/table-model.js +1 -1
  32. package/model/text-model.d.ts +5 -1
  33. package/model/text-model.js +1 -1
  34. package/package.json +16 -16
  35. package/polotno.bundle.js +194 -202
  36. package/primitives/field-group.js +1 -1
  37. package/primitives/popover.d.ts +1 -1
  38. package/primitives/popover.js +1 -1
  39. package/side-panel/effects-panel.js +1 -1
  40. package/side-panel/side-panel.d.ts +1 -0
  41. package/side-panel/side-panel.js +1 -1
  42. package/side-panel/templates-panel.js +1 -1
  43. package/toolbar/color-picker.js +1 -1
  44. package/toolbar/gradient-center-pad.d.ts +11 -0
  45. package/toolbar/gradient-center-pad.js +1 -0
  46. package/toolbar/padding-control.d.ts +29 -0
  47. package/toolbar/padding-control.js +1 -0
  48. package/toolbar/selection-colors.js +1 -1
  49. package/toolbar/stop-track.js +1 -1
  50. package/toolbar/table-toolbar.js +1 -1
  51. package/toolbar/text-toolbar.d.ts +7 -2
  52. package/toolbar/text-toolbar.js +1 -1
  53. package/toolbar/unit-numeric-input.d.ts +5 -0
  54. package/toolbar/unit-numeric-input.js +1 -0
  55. package/toolbar/use-copy-style.js +1 -1
  56. package/ui.css +1 -1
  57. package/utils/clipboard.d.ts +10 -2
  58. package/utils/clipboard.js +1 -1
  59. package/utils/gradient-handle.d.ts +18 -0
  60. package/utils/gradient-handle.js +1 -0
  61. package/utils/gradient-stops.d.ts +7 -2
  62. package/utils/gradient-stops.js +1 -1
  63. package/utils/history-gesture.d.ts +7 -0
  64. package/utils/history-gesture.js +1 -0
  65. package/utils/l10n.d.ts +16 -1
  66. package/utils/l10n.js +1 -1
  67. package/utils/measure-text.d.ts +4 -0
  68. package/utils/measure-text.js +1 -1
  69. package/utils/px.d.ts +4 -0
  70. package/utils/px.js +1 -1
  71. package/utils/rich-text-html.d.ts +1 -0
  72. package/utils/rich-text-html.js +1 -1
  73. package/utils/selection-transform.js +1 -1
  74. package/utils/validate-key.js +1 -1
@@ -1 +1 @@
1
- import{jsx as e,jsxs as n}from"react/jsx-runtime";import{cn as s}from"../lib/utils.js";import{Switch as l}from"./switch.js";function i({label:i,enabled:a,onEnabledChange:p,visible:t=!0,disabled:d,className:r,children:c}){if(!t){return null}const m=!p||!!a;return n("div",{className:s("pn:py-1",r),children:[n("div",{className:"pn:flex pn:items-center pn:justify-between pn:gap-2 pn:py-1",children:[e("label",{className:"pn:text-sm pn:font-medium",children:i}),p&&e(l,{checked:!!a,onCheckedChange:p,disabled:d})]}),m&&e("div",{className:"pn:mt-1.5 pn:rounded-lg pn:bg-muted/60 pn:px-3 pn:py-1",children:c})]})}export{i as FieldGroup};
1
+ import{jsx as e,jsxs as n}from"react/jsx-runtime";import*as s from"react";import{cn as l}from"../lib/utils.js";import{Switch as a}from"./switch.js";function i({label:i,enabled:r,onEnabledChange:t,visible:d=!0,disabled:p,className:c,children:m}){const o=s.useId();if(!d){return null}const b=!t||!!r;return n("div",{className:l("pn:py-1",c),children:[n("div",{className:"pn:flex pn:items-center pn:justify-between pn:gap-2 pn:py-1",children:[e("label",{id:o,className:"pn:text-sm pn:font-medium",children:i}),t&&e(a,{"aria-labelledby":o,checked:!!r,onCheckedChange:t,disabled:p})]}),b&&e("div",{className:"pn:mt-1.5 pn:rounded-lg pn:bg-muted/60 pn:px-3 pn:py-1",children:m})]})}export{i as FieldGroup};
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { Popover as PopoverPrimitive } from '@base-ui/react/popover';
3
- declare function Popover({ ...props }: React.ComponentProps<typeof PopoverPrimitive.Root>): React.JSX.Element;
3
+ declare function Popover({ onOpenChange, ...props }: React.ComponentProps<typeof PopoverPrimitive.Root>): React.JSX.Element;
4
4
  declare function PopoverTrigger({ ...props }: React.ComponentProps<typeof PopoverPrimitive.Trigger>): React.JSX.Element;
5
5
  type PositionerProps = React.ComponentProps<typeof PopoverPrimitive.Positioner>;
6
6
  declare const PopoverContent: React.ForwardRefExoticComponent<Omit<Omit<import("@base-ui/react").PopoverPopupProps, "ref"> & React.RefAttributes<HTMLDivElement> & {
@@ -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 r=0;for(n=Object.getOwnPropertySymbols(e);r<n.length;r++){t.indexOf(n[r])<0&&Object.prototype.propertyIsEnumerable.call(e,n[r])&&(o[n[r]]=e[n[r]])}}return o};import{jsx as t}from"react/jsx-runtime";import*as o from"react";import{Popover as n}from"@base-ui/react/popover";import{cn as r}from"../lib/utils.js";import{usePortalScope as a}from"./portal-scope.js";function i(o){var r=e(o,[]);return t(n.Root,Object.assign({"data-slot":"popover"},r))}function s(o){var r=e(o,[]);return t(n.Trigger,Object.assign({"data-slot":"popover-trigger"},r))}const p=o.forwardRef((o,i)=>{var{className:s,side:p,align:d="center",sideOffset:l=4,alignOffset:f}=o,c=e(o,["className","side","align","sideOffset","alignOffset"]);const m=a(),{container:g,className:u}=m,O=e(m,["container","className"]);return t(n.Portal,{container:g,children:t(n.Positioner,{side:p,align:d,sideOffset:l,alignOffset:f,positionMethod:"fixed",className:"pn:z-[200]",children:t(n.Popup,Object.assign({ref:i,"data-slot":"popover-content"},O,{className:r(u,"pn:z-50 pn:w-72 origin-(--transform-origin) pn:rounded-md pn:border pn:bg-popover pn:p-4 pn:text-popover-foreground pn:shadow-md pn:outline-hidden pn:data-[side=bottom]:slide-in-from-top-2 pn:data-[side=left]:slide-in-from-right-2 pn:data-[side=right]:slide-in-from-left-2 pn:data-[side=top]:slide-in-from-bottom-2 pn:data-[closed]:animate-out pn:data-[closed]:fade-out-0 pn:data-[closed]:zoom-out-95 pn:data-[open]:animate-in pn:data-[open]:fade-in-0 pn:data-[open]:zoom-in-95",s)},c))})})});p.displayName="PopoverContent";export{i as Popover,s as PopoverTrigger,p as PopoverContent};
1
+ var e=this&&this.__rest||function(e,o){var t={};for(var n in e){Object.prototype.hasOwnProperty.call(e,n)&&o.indexOf(n)<0&&(t[n]=e[n])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var a=0;for(n=Object.getOwnPropertySymbols(e);a<n.length;a++){o.indexOf(n[a])<0&&Object.prototype.propertyIsEnumerable.call(e,n[a])&&(t[n[a]]=e[n[a]])}}return t};import{jsx as o}from"react/jsx-runtime";import*as t from"react";import{Popover as n}from"@base-ui/react/popover";import{cn as a}from"../lib/utils.js";import{keepOpenForRadialHandle as r}from"../utils/gradient-handle.js";import{usePortalScope as i}from"./portal-scope.js";function s(t){var{onOpenChange:a}=t,i=e(t,["onOpenChange"]);return o(n.Root,Object.assign({"data-slot":"popover",onOpenChange:(e,o)=>{r(e,o)||null==a||a(e,o)}},i))}function p(t){var a=e(t,[]);return o(n.Trigger,Object.assign({"data-slot":"popover-trigger"},a))}const d=t.forwardRef((t,r)=>{var{className:s,side:p,align:d="center",sideOffset:l=4,alignOffset:f}=t,m=e(t,["className","side","align","sideOffset","alignOffset"]);const c=i(),{container:g,className:u}=c,O=e(c,["container","className"]);return o(n.Portal,{container:g,children:o(n.Positioner,{side:p,align:d,sideOffset:l,alignOffset:f,positionMethod:"fixed",className:"pn:z-[200]",children:o(n.Popup,Object.assign({ref:r,"data-slot":"popover-content"},O,{className:a(u,"pn:z-50 pn:w-72 origin-(--transform-origin) pn:rounded-md pn:border pn:bg-popover pn:p-4 pn:text-popover-foreground pn:shadow-md pn:outline-hidden pn:data-[side=bottom]:slide-in-from-top-2 pn:data-[side=left]:slide-in-from-right-2 pn:data-[side=right]:slide-in-from-left-2 pn:data-[side=top]:slide-in-from-bottom-2 pn:data-[closed]:animate-out pn:data-[closed]:fade-out-0 pn:data-[closed]:zoom-out-95 pn:data-[open]:animate-in pn:data-[open]:fade-in-0 pn:data-[open]:zoom-in-95",s)},m))})})});d.displayName="PopoverContent";export{s as Popover,p as PopoverTrigger,d as PopoverContent};
@@ -1 +1 @@
1
- import{Fragment as e,jsx as a,jsxs as o}from"react/jsx-runtime";import r from"react";import{Slider as l}from"../primitives/slider.js";import{firstSliderValue as t}from"../lib/utils.js";import{SliderField as n}from"../primitives/slider-field.js";import{FieldGroup as i}from"../primitives/field-group.js";import{observer as s}from"mobx-react-lite";import{INDEPENDENT_FILTERS as d}from"../model/shape-model.js";import{ColorPicker as c}from"../toolbar/color-picker.js";import{t as b}from"../utils/l10n.js";import{EffectCard as h}from"./effect-card.js";import{TextEffectPresets as u}from"./text-effect-presets.js";import{Effects as p}from"@polotno/core/filters";import{CurvePowerSlider as m}from"../toolbar/filters-picker.js";import{NumericInput as f}from"../primitives/numeric-input.js";import{FieldRow as g}from"../primitives/field-row.js";import{PanelHeader as v}from"../primitives/panel-header.js";import{ToggleGroup as C,ToggleGroupItem as x}from"../primitives/toggle-group.js";import{normalizeStrokeLineJoin as y}from"@polotno/core/text-html";import{defaultFade as w,insertFadeStop as k,fadePreview as j,fadeStopColor as E,FADE_CHECKERBOARD as M}from"../utils/fade-gradient.js";import{Button as S}from"../primitives/button.js";import{canRemoveStop as O,reverseStops as z}from"../utils/stops.js";import{StopTrack as F}from"../toolbar/stop-track.js";import{useFadeStopFocus as R}from"../hooks/use-fade-stop-focus.js";import{getSelectedFadeStop as V,setSelectedFadeStop as P}from"../utils/fade-overlay.js";import{readClipFade as N,writeClipFade as L}from"../utils/clip-fade.js";import{urlToBase64 as B}from"@polotno/core/svg";import{isAlive as W}from"mobx-state-tree";import{PanelScrollArea as X}from"../primitives/panel-scroll-area.js";const Y=[{value:"round",labelKey:"toolbar.joinRound"},{value:"miter",labelKey:"toolbar.joinMiter"},{value:"bevel",labelKey:"toolbar.joinBevel"}],$=({join:e})=>a("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:a("path",{d:"M7 21 L7 7 L21 7",stroke:"currentColor",strokeWidth:"9",strokeLinejoin:e,strokeLinecap:"butt"})});export{f as NumberInput};const K=(e,a,o)=>Math.max(a,Math.min(o,e)),J=(e,a)=>Math.max(e,Math.ceil(a)),I=(e,a)=>Math.min(e,Math.floor(a)),T=[["temperature","toolbar.temperature"],["contrast","toolbar.contrast"],["shadows","toolbar.shadows"],["white","toolbar.white"],["black","toolbar.black"],["vibrance","toolbar.vibrance"],["saturation","toolbar.saturation"]],D=s(({store:l,elements:t})=>{const[n,s]=r.useState(""),[d,c]=r.useState(!1),h=t.filter(e=>["image","video","gif","lottie"].includes(e.type)),u=h[0];if(!u){return null}const p=N(u.clipSrc);return o(e,{children:[a(i,{label:b("toolbar.clipFade.title"),enabled:!!p,disabled:d,onEnabledChange:e=>{(async e=>{if(!d){c(!0),s("");try{const a=await Promise.all(h.map(async a=>{var o;const r=a.clipSrc,l=N(r),t=null!==(o=null==l?void 0:l.baseSrc)&&void 0!==o?o:r,n=e&&t&&!t.startsWith("data:")?await B(t,{binary:!0}):t;return{item:a,previous:r,clipSrc:e?L(w(),n):null==l?void 0:l.baseSrc}}));l.history.transaction(()=>a.forEach(({item:e,previous:a,clipSrc:o})=>{W(e)&&e.clipSrc===a&&null!=o&&e.set({clipSrc:o})}))}catch(n){s(n instanceof Error?n.message:String(n))}finally{c(!1)}}})(e)},children:p&&a(q,{store:l,element:u,value:p.fade,onChange:e=>l.history.transaction(()=>{h.forEach(a=>{if(!W(a)){return}const o=N(a.clipSrc);o&&a.set({clipSrc:L(e,o.baseSrc)})})})},u.id)}),d&&a("div",{role:"status",children:b("toolbar.clipFade.preparing")}),n&&a("div",{role:"alert",children:n})]})}),q=s(({store:l,element:t,value:i,onChange:s})=>{const d=Math.min(V(l),i.stops.length-1),c=i.stops[d],h=r.useRef(null),u=e=>P(l,e);R(l,t.id,e=>{var a,o;return u(e),null!==(o=null===(a=h.current)||void 0===a?void 0:a.focus(e))&&void 0!==o&&o});const p=e=>{u(e.index),s(Object.assign(Object.assign({},i),{stops:e.stops}))};return o(e,{children:[a(g,{label:b("toolbar.clipFade.shape"),children:o(C,{value:[i.shape],onValueChange:e=>{const a=e[0];"linear"!==a&&"radial"!==a||a===i.shape||s(Object.assign(Object.assign({},w(a)),{stops:i.stops}))},children:[a(x,{value:"linear","aria-label":b("toolbar.clipFade.linear"),children:b("toolbar.clipFade.linear")}),a(x,{value:"radial","aria-label":b("toolbar.clipFade.radial"),children:b("toolbar.clipFade.radial")})]})}),a("p",{className:"pn:py-1 pn:text-xs pn:text-muted-foreground",children:b("toolbar.clipFade.hint")}),a("div",{className:"pn:px-3",children:a(F,{handle:h,store:l,node:t,label:b("toolbar.clipFade.stops"),stops:i.stops,selected:d,onSelect:u,onChange:p,insert:k,stopLabel:(e,a)=>`${b("toolbar.clipFade.stop")} ${a+1}: ${Math.round(100*e.alpha)}%`,swatch:e=>E(e.alpha),bar:a("div",{className:"pn:size-full",style:{background:`${j(i.stops)}, ${M}`}})})}),a(n,{label:b("toolbar.clipFade.stopOpacity"),value:Math.round(100*c.alpha),min:0,max:100,onChange:e=>s(Object.assign(Object.assign({},i),{stops:i.stops.map((a,o)=>o===d?Object.assign(Object.assign({},a),{alpha:e/100}):a)}))}),o("div",{className:"pn:flex pn:flex-wrap pn:justify-end pn:gap-1 pn:py-1",children:[a(S,{variant:"ghost",size:"sm",onClick:()=>p({stops:z(i.stops),index:i.stops.length-1-d}),children:b("toolbar.clipFade.reverse")}),a(S,{variant:"ghost",size:"sm",disabled:!O(i.stops),onClick:()=>{var e;return null===(e=h.current)||void 0===e?void 0:e.remove(d)},children:b("toolbar.clipFade.removeStop")}),a(S,{variant:"ghost",size:"sm",onClick:()=>{u(0),s(w(i.shape))},children:b("toolbar.clipFade.reset")})]})]})}),A=({store:e,color:r,onColorChange:n,value:i,onValueChange:s,min:d,max:b,sliderMax:h,gradientEnabled:u=!0})=>o("div",{style:{display:"flex",alignItems:"center",padding:"8px 0"},children:[a(c,{value:r,size:30,gradientEnabled:u,onChange:n,store:e}),a("div",{style:{flex:1,paddingLeft:"10px",paddingRight:"10px"},children:a(l,{value:[i],onValueChange:e=>s(K(Math.round(t(e)),d,b)),min:d,max:null!=h?h:b,step:1})}),a(f,{value:Math.round(i),onValueChange:e=>s(K(e,d,b)),min:d,max:b,style:{width:64}})]});export const EffectsPanel=s(({store:e})=>{var l;const t=e.selectedElements,s=t[0],w=t.map(e=>e.id).join(","),k="effects"===e.openedSidePanel;if(r.useEffect(()=>{k&&(s&&s.filters||e.restoreSidePanel())},[k,w]),!s||!s.filters){return null}const j="text"===s.type,E="image"===s.type,M="svg"===s.type,S=E||M,O=["image","video","gif","lottie"].includes(s.type),z=Math.min(s.width,s.height)/2,F=Math.min(null!==(l=s.cornerRadius)&&void 0!==l?l:0,z),R=a=>{e.history.transaction(()=>{t.forEach(e=>{e.set(a)})})},V=(a,o)=>{e.history.transaction(()=>{t.forEach(e=>{let r=Number(o);return 0==o||o||(r=e.filters.has(a)?null:1),d.includes(a)||e.set({grayscaleEnabled:"grayscale"===a&&!!o,sepiaEnabled:"sepia"===a&&!!o}),e.setFilter(a,r)})})};return o(X,{header:a(v,{title:b("sidePanel.effects"),onClose:()=>e.restoreSidePanel()}),children:[j&&a(u,{store:e}),S&&a("div",{style:{display:"flex",flexDirection:"column",gap:"16px",marginTop:"16px"},children:o("div",{style:{display:"flex",gap:"16px",flexWrap:"wrap"},children:[a(h,{active:s.grayscaleEnabled,onClick:()=>{V("grayscale",!s.grayscaleEnabled)},title:b("toolbar.grayscale"),imageSrc:s.src,effect:p.grayscale}),a(h,{active:s.sepiaEnabled,onClick:()=>{V("sepia",!s.sepiaEnabled)},title:b("toolbar.sepia"),imageSrc:s.src,effect:p.sepia}),a(h,{active:s.filters.has("cold"),onClick:()=>{V("cold",s.filters.has("cold")?null:1)},title:b("toolbar.cold"),imageSrc:s.src,effect:p.cold}),a(h,{active:s.filters.has("natural"),onClick:()=>{V("natural",s.filters.has("natural")?null:1)},title:b("toolbar.natural"),imageSrc:s.src,effect:p.natural}),a(h,{active:s.filters.has("warm"),onClick:()=>{V("warm",s.filters.has("warm")?null:1)},title:b("toolbar.warm"),imageSrc:s.src,effect:p.warm})]})}),a(n,{label:b("toolbar.blur"),enabled:s.blurEnabled,visible:S||j,onEnabledChange:e=>{R({blurEnabled:e})},value:s.blurRadius,onChange:e=>{R({blurRadius:e})},min:0,max:100}),a(n,{label:b("toolbar.brightness"),visible:S,enabled:s.brightnessEnabled,onEnabledChange:e=>{R({brightnessEnabled:e})},value:Math.round(100*s.brightness),onChange:e=>{R({brightness:e/100})},min:-100,max:100}),T.map(([e,o])=>{var r,l;return a(n,{label:b(o),visible:S,enabled:s.filters.has(e),onEnabledChange:a=>{V(e,a?0:null)},value:Math.round(100*(null!==(l=null===(r=s.filters.get(e))||void 0===r?void 0:r.intensity)&&void 0!==l?l:0)),onChange:a=>{V(e,a/100)},min:-100,max:100},e)}),j&&o(i,{label:b("toolbar.curvedText")||"Curved text",enabled:!!s.curveEnabled,onEnabledChange:e=>R({curveEnabled:e}),children:[a(g,{label:b("toolbar.curvePower")||"Curve",className:"pn:py-2",children:a(f,{value:Math.round(100*s.curvePower),onValueChange:e=>{R({curvePower:K(e,-100,100)/100})},style:{width:64},min:-100,max:100})}),a(m,{textEl:s,eachSet:R})]}),j&&o(i,{label:b("toolbar.textStroke"),enabled:!!s.strokeWidth,onEnabledChange:e=>R({strokeWidth:e?2:0}),children:[a(A,{store:e,color:s.stroke,onColorChange:e=>{R({stroke:e})},value:s.strokeWidth,onValueChange:e=>{R({strokeWidth:e})},min:1,max:Math.max(1,Math.round(s.fontSize/2)),sliderMax:Math.max(1,s.fontSize/2)}),a(g,{label:b("toolbar.strokeLineJoin"),className:"pn:py-2",children:a(C,{variant:"outline",value:[y(s.strokeLineJoin)],onValueChange:e=>{const a=e[0];a&&R({strokeLineJoin:a})},children:Y.map(({value:e,labelKey:o})=>a(x,{value:e,"aria-label":b(o),title:b(o),children:a($,{join:e})},e))})})]}),j&&o(i,{label:b("toolbar.textBackground"),enabled:!!s.backgroundEnabled,onEnabledChange:e=>R({backgroundEnabled:e}),children:[a(n,{label:b("toolbar.opacity"),value:Math.round(100*s.backgroundOpacity),onChange:e=>R({backgroundOpacity:e/100}),min:0,max:100}),a(g,{label:b("toolbar.color"),className:"pn:py-2",children:a(c,{value:s.backgroundColor,size:30,onChange:e=>{R({backgroundColor:e})},store:e})})]}),j&&a(i,{label:b("toolbar.border"),enabled:!!s.borderSize,onEnabledChange:e=>R({borderSize:e?2:0}),children:a(A,{store:e,color:s.borderColor,onColorChange:e=>R({borderColor:e}),value:s.borderSize,onValueChange:e=>R({borderSize:e}),min:1,max:Math.max(1,Math.round(s.fontSize/2)),gradientEnabled:!1})}),j&&(s.backgroundEnabled||s.borderSize>0)&&o(i,{label:b("toolbar.textBox"),children:[a(n,{label:b("toolbar.backgroundCornerRadius"),value:Math.round(100*s.backgroundCornerRadius),onChange:e=>R({backgroundCornerRadius:e/100}),min:0,max:200}),a(n,{label:b("toolbar.backgroundPadding"),value:Math.round(100*s.backgroundPadding),onChange:e=>R({backgroundPadding:e/100}),min:0,max:100})]}),S&&a(i,{label:b("toolbar.border"),enabled:!!s.borderSize,onEnabledChange:e=>R({borderSize:e?2:0}),children:a(A,{store:e,color:s.borderColor,onColorChange:e=>{R({borderColor:e})},value:s.borderSize,onValueChange:e=>{R({borderSize:e})},min:1,max:Math.max(1,Math.round(z)),sliderMax:Math.max(1,z)})}),S&&a(n,{label:b("toolbar.cornerRadius"),visible:S,enabled:0!==s.cornerRadius,onEnabledChange:e=>{R({cornerRadius:e?Math.min(s.width/4,s.height/4):0})},value:Math.round(F),sliderValue:F,onChange:e=>{R({cornerRadius:e})},min:1,max:Math.round(z),sliderMax:z}),O&&a(D,{store:e,elements:t}),o(i,{label:b("toolbar.shadow"),enabled:s.shadowEnabled,onEnabledChange:e=>R({shadowEnabled:e}),children:[a(n,{label:b("toolbar.blur"),value:Math.round(s.shadowBlur),sliderValue:s.shadowBlur,onChange:e=>{R({shadowBlur:e})},min:0,max:J(50,s.shadowBlur)}),a(n,{label:b("toolbar.offsetX"),value:Math.round(s.shadowOffsetX),sliderValue:s.shadowOffsetX,onChange:e=>{R({shadowOffsetX:e})},min:I(-50,s.shadowOffsetX),max:J(50,s.shadowOffsetX)}),a(n,{label:b("toolbar.offsetY"),value:Math.round(s.shadowOffsetY),sliderValue:s.shadowOffsetY,onChange:e=>{R({shadowOffsetY:e})},min:I(-50,s.shadowOffsetY),max:J(50,s.shadowOffsetY)}),a(n,{label:b("toolbar.opacity"),value:Math.round(100*s.shadowOpacity),onChange:e=>{R({shadowOpacity:e/100})},min:0,max:100}),a(g,{label:b("toolbar.color"),className:"pn:py-2",children:a(c,{value:s.shadowColor,size:30,onChange:e=>{R({shadowColor:e})},store:e})})]})]})});
1
+ import{Fragment as e,jsx as a,jsxs as o}from"react/jsx-runtime";import r from"react";import{Slider as l}from"../primitives/slider.js";import{firstSliderValue as t}from"../lib/utils.js";import{SliderField as n}from"../primitives/slider-field.js";import{FieldGroup as i}from"../primitives/field-group.js";import{observer as s}from"mobx-react-lite";import{INDEPENDENT_FILTERS as d}from"../model/shape-model.js";import{ColorPicker as c}from"../toolbar/color-picker.js";import{t as b}from"../utils/l10n.js";import{EffectCard as h}from"./effect-card.js";import{TextEffectPresets as u}from"./text-effect-presets.js";import{Effects as p}from"@polotno/core/filters";import{CurvePowerSlider as m}from"../toolbar/filters-picker.js";import{NumericInput as g}from"../primitives/numeric-input.js";import{FieldRow as f}from"../primitives/field-row.js";import{Switch as v}from"../primitives/switch.js";import{PanelHeader as C}from"../primitives/panel-header.js";import{ToggleGroup as x,ToggleGroupItem as k}from"../primitives/toggle-group.js";import{normalizeStrokeLineJoin as y}from"@polotno/core/text-html";import{defaultFade as S,insertFadeStop as w,fadePreview as j,fadeStopColor as E,FADE_CHECKERBOARD as M}from"../utils/fade-gradient.js";import{Button as O}from"../primitives/button.js";import{canRemoveStop as z,reverseStops as F}from"../utils/stops.js";import{StopTrack as V}from"../toolbar/stop-track.js";import{useFadeStopFocus as N}from"../hooks/use-fade-stop-focus.js";import{getSelectedFadeStop as R,setSelectedFadeStop as P}from"../utils/fade-overlay.js";import{readClipFade as L,writeClipFade as B}from"../utils/clip-fade.js";import{urlToBase64 as W}from"@polotno/core/svg";import{isAlive as X}from"mobx-state-tree";import{PanelScrollArea as Y}from"../primitives/panel-scroll-area.js";const $=[{value:"round",labelKey:"toolbar.joinRound"},{value:"miter",labelKey:"toolbar.joinMiter"},{value:"bevel",labelKey:"toolbar.joinBevel"}],K=({join:e})=>a("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:a("path",{d:"M7 21 L7 7 L21 7",stroke:"currentColor",strokeWidth:"9",strokeLinejoin:e,strokeLinecap:"butt"})});export{g as NumberInput};const J=(e,a,o)=>Math.max(a,Math.min(o,e)),I=(e,a)=>Math.max(e,Math.ceil(a)),T=(e,a)=>Math.min(e,Math.floor(a)),D=[["temperature","toolbar.temperature"],["contrast","toolbar.contrast"],["shadows","toolbar.shadows"],["white","toolbar.white"],["black","toolbar.black"],["vibrance","toolbar.vibrance"],["saturation","toolbar.saturation"]],q=s(({store:l,elements:t})=>{const[n,s]=r.useState(""),[d,c]=r.useState(!1),h=t.filter(e=>["image","video","gif","lottie"].includes(e.type)),u=h[0];if(!u){return null}const p=L(u.clipSrc);return o(e,{children:[a(i,{label:b("toolbar.clipFade.title"),enabled:!!p,disabled:d,onEnabledChange:e=>{(async e=>{if(!d){c(!0),s("");try{const a=await Promise.all(h.map(async a=>{var o;const r=a.clipSrc,l=L(r),t=null!==(o=null==l?void 0:l.baseSrc)&&void 0!==o?o:r,n=e&&t&&!t.startsWith("data:")?await W(t,{binary:!0}):t;return{item:a,previous:r,clipSrc:e?B(S(),n):null==l?void 0:l.baseSrc}}));l.history.transaction(()=>a.forEach(({item:e,previous:a,clipSrc:o})=>{X(e)&&e.clipSrc===a&&null!=o&&e.set({clipSrc:o})}))}catch(n){s(n instanceof Error?n.message:String(n))}finally{c(!1)}}})(e)},children:p&&a(A,{store:l,element:u,value:p.fade,onChange:e=>l.history.transaction(()=>{h.forEach(a=>{if(!X(a)){return}const o=L(a.clipSrc);o&&a.set({clipSrc:B(e,o.baseSrc)})})})},u.id)}),d&&a("div",{role:"status",children:b("toolbar.clipFade.preparing")}),n&&a("div",{role:"alert",children:n})]})}),A=s(({store:l,element:t,value:i,onChange:s})=>{const d=Math.min(R(l),i.stops.length-1),c=i.stops[d],h=r.useRef(null),u=e=>P(l,e);N(l,t.id,e=>{var a,o;return u(e),null!==(o=null===(a=h.current)||void 0===a?void 0:a.focus(e))&&void 0!==o&&o});const p=e=>{u(e.index),s(Object.assign(Object.assign({},i),{stops:e.stops}))};return o(e,{children:[a(f,{label:b("toolbar.clipFade.shape"),children:o(x,{value:[i.shape],onValueChange:e=>{const a=e[0];"linear"!==a&&"radial"!==a||a===i.shape||s(Object.assign(Object.assign({},S(a)),{stops:i.stops}))},children:[a(k,{value:"linear","aria-label":b("toolbar.clipFade.linear"),children:b("toolbar.clipFade.linear")}),a(k,{value:"radial","aria-label":b("toolbar.clipFade.radial"),children:b("toolbar.clipFade.radial")})]})}),a("p",{className:"pn:py-1 pn:text-xs pn:text-muted-foreground",children:b("toolbar.clipFade.hint")}),a("div",{className:"pn:px-3",children:a(V,{handle:h,store:l,node:t,label:b("toolbar.clipFade.stops"),stops:i.stops,selected:d,onSelect:u,onChange:p,insert:w,stopLabel:(e,a)=>`${b("toolbar.clipFade.stop")} ${a+1}: ${Math.round(100*e.alpha)}%`,swatch:e=>E(e.alpha),bar:a("div",{className:"pn:size-full",style:{background:`${j(i.stops)}, ${M}`}})})}),a(n,{label:b("toolbar.clipFade.stopOpacity"),value:Math.round(100*c.alpha),min:0,max:100,onChange:e=>s(Object.assign(Object.assign({},i),{stops:i.stops.map((a,o)=>o===d?Object.assign(Object.assign({},a),{alpha:e/100}):a)}))}),o("div",{className:"pn:flex pn:flex-wrap pn:justify-end pn:gap-1 pn:py-1",children:[a(O,{variant:"ghost",size:"sm",onClick:()=>p({stops:F(i.stops),index:i.stops.length-1-d}),children:b("toolbar.clipFade.reverse")}),a(O,{variant:"ghost",size:"sm",disabled:!z(i.stops),onClick:()=>{var e;return null===(e=h.current)||void 0===e?void 0:e.remove(d)},children:b("toolbar.clipFade.removeStop")}),a(O,{variant:"ghost",size:"sm",onClick:()=>{u(0),s(S(i.shape))},children:b("toolbar.clipFade.reset")})]})]})}),G=({store:e,color:r,onColorChange:n,value:i,onValueChange:s,min:d,max:b,sliderMax:h,gradientEnabled:u=!0})=>o("div",{style:{display:"flex",alignItems:"center",padding:"8px 0"},children:[a(c,{value:r,size:30,gradientEnabled:u,onChange:n,store:e}),a("div",{style:{flex:1,paddingLeft:"10px",paddingRight:"10px"},children:a(l,{value:[i],onValueChange:e=>s(J(Math.round(t(e)),d,b)),min:d,max:null!=h?h:b,step:1})}),a(g,{value:Math.round(i),onValueChange:e=>s(J(e,d,b)),min:d,max:b,style:{width:64}})]});export const EffectsPanel=s(({store:l})=>{var t;const s=l.selectedElements,S=s[0],w=s.map(e=>e.id).join(","),j="effects"===l.openedSidePanel;if(r.useEffect(()=>{j&&(S&&S.filters||l.restoreSidePanel())},[j,w]),!S||!S.filters){return null}const E="text"===S.type,M="image"===S.type,O="svg"===S.type,z=M||O,F=["image","video","gif","lottie"].includes(S.type),V=Math.min(S.width,S.height)/2,N=Math.min(null!==(t=S.cornerRadius)&&void 0!==t?t:0,V),R=e=>{l.history.transaction(()=>{s.forEach(a=>{a.set(e)})})},P=(e,a)=>{l.history.transaction(()=>{s.forEach(o=>{let r=Number(a);return 0==a||a||(r=o.filters.has(e)?null:1),d.includes(e)||o.set({grayscaleEnabled:"grayscale"===e&&!!a,sepiaEnabled:"sepia"===e&&!!a}),o.setFilter(e,r)})})};return o(Y,{header:a(C,{title:b("sidePanel.effects"),onClose:()=>l.restoreSidePanel()}),children:[E&&a(u,{store:l}),z&&a("div",{style:{display:"flex",flexDirection:"column",gap:"16px",marginTop:"16px"},children:o("div",{style:{display:"flex",gap:"16px",flexWrap:"wrap"},children:[a(h,{active:S.grayscaleEnabled,onClick:()=>{P("grayscale",!S.grayscaleEnabled)},title:b("toolbar.grayscale"),imageSrc:S.src,effect:p.grayscale}),a(h,{active:S.sepiaEnabled,onClick:()=>{P("sepia",!S.sepiaEnabled)},title:b("toolbar.sepia"),imageSrc:S.src,effect:p.sepia}),a(h,{active:S.filters.has("cold"),onClick:()=>{P("cold",S.filters.has("cold")?null:1)},title:b("toolbar.cold"),imageSrc:S.src,effect:p.cold}),a(h,{active:S.filters.has("natural"),onClick:()=>{P("natural",S.filters.has("natural")?null:1)},title:b("toolbar.natural"),imageSrc:S.src,effect:p.natural}),a(h,{active:S.filters.has("warm"),onClick:()=>{P("warm",S.filters.has("warm")?null:1)},title:b("toolbar.warm"),imageSrc:S.src,effect:p.warm})]})}),a(n,{label:b("toolbar.blur"),enabled:S.blurEnabled,visible:z||E,onEnabledChange:e=>{R({blurEnabled:e})},value:S.blurRadius,onChange:e=>{R({blurRadius:e})},min:0,max:100}),a(n,{label:b("toolbar.brightness"),visible:z,enabled:S.brightnessEnabled,onEnabledChange:e=>{R({brightnessEnabled:e})},value:Math.round(100*S.brightness),onChange:e=>{R({brightness:e/100})},min:-100,max:100}),D.map(([e,o])=>{var r,l;return a(n,{label:b(o),visible:z,enabled:S.filters.has(e),onEnabledChange:a=>{P(e,a?0:null)},value:Math.round(100*(null!==(l=null===(r=S.filters.get(e))||void 0===r?void 0:r.intensity)&&void 0!==l?l:0)),onChange:a=>{P(e,a/100)},min:-100,max:100},e)}),E&&o(i,{label:b("toolbar.curvedText")||"Curved text",enabled:!!S.curveEnabled,onEnabledChange:e=>R({curveEnabled:e}),children:[a(f,{label:b("toolbar.curvePower")||"Curve",className:"pn:py-2",children:a(g,{value:Math.round(100*S.curvePower),onValueChange:e=>{R({curvePower:J(e,-100,100)/100})},style:{width:64},min:-100,max:100})}),a(m,{textEl:S,eachSet:R})]}),E&&o(i,{label:b("toolbar.textStroke"),enabled:!!S.strokeWidth,onEnabledChange:e=>R({strokeWidth:e?2:0}),children:[a(G,{store:l,color:S.stroke,onColorChange:e=>{R({stroke:e})},value:S.strokeWidth,onValueChange:e=>{R({strokeWidth:e})},min:1,max:Math.max(1,Math.round(S.fontSize/2)),sliderMax:Math.max(1,S.fontSize/2)}),a(f,{label:b("toolbar.strokeLineJoin"),className:"pn:py-2",children:a(x,{variant:"outline",value:[y(S.strokeLineJoin)],onValueChange:e=>{const a=e[0];a&&R({strokeLineJoin:a})},children:$.map(({value:e,labelKey:o})=>a(k,{value:e,"aria-label":b(o),title:b(o),children:a(K,{join:e})},e))})})]}),E&&o(i,{label:b("toolbar.textBackground"),enabled:!!S.backgroundEnabled||S.borderSize>0,onEnabledChange:e=>R(e?{backgroundEnabled:!0}:{backgroundEnabled:!1,borderSize:0}),children:[a(f,{label:b("toolbar.backgroundShape"),className:"pn:py-2",children:o(x,{variant:"outline",value:["box"===S.backgroundShape?"box":"lines"],onValueChange:e=>{const a=e[0];a&&R({backgroundShape:a})},children:[a(k,{value:"lines","aria-label":b("toolbar.backgroundShapeLines"),children:b("toolbar.backgroundShapeLines")}),a(k,{value:"box","aria-label":b("toolbar.backgroundShapeBox"),children:b("toolbar.backgroundShapeBox")})]})}),a(f,{label:b("toolbar.backgroundFill"),className:"pn:py-2",children:a(v,{"aria-label":b("toolbar.backgroundFill"),checked:!!S.backgroundEnabled,onCheckedChange:e=>R({backgroundEnabled:e})})}),S.backgroundEnabled&&o(e,{children:[a(f,{label:b("toolbar.color"),className:"pn:py-2",children:a(c,{value:S.backgroundColor,size:30,onChange:e=>{R({backgroundColor:e})},store:l})}),a(n,{label:b("toolbar.opacity"),value:Math.round(100*S.backgroundOpacity),onChange:e=>R({backgroundOpacity:e/100}),min:0,max:100})]}),a(f,{label:b("toolbar.border"),className:"pn:py-2",children:a(v,{"aria-label":b("toolbar.border"),checked:S.borderSize>0,onCheckedChange:e=>R({borderSize:e?2:0})})}),S.borderSize>0&&a(G,{store:l,color:S.borderColor,onColorChange:e=>R({borderColor:e}),value:S.borderSize,onValueChange:e=>R({borderSize:e}),min:1,max:Math.max(1,Math.round(S.fontSize/2)),gradientEnabled:!1}),a(n,{label:b("toolbar.backgroundCornerRadius"),value:Math.round(100*S.backgroundCornerRadius),onChange:e=>R({backgroundCornerRadius:e/100}),min:0,max:200}),a(n,{label:b("toolbar.backgroundPadding"),value:Math.round(100*S.backgroundPadding),onChange:e=>R({backgroundPadding:e/100}),min:0,max:100})]}),z&&a(i,{label:b("toolbar.border"),enabled:!!S.borderSize,onEnabledChange:e=>R({borderSize:e?2:0}),children:a(G,{store:l,color:S.borderColor,onColorChange:e=>{R({borderColor:e})},value:S.borderSize,onValueChange:e=>{R({borderSize:e})},min:1,max:Math.max(1,Math.round(V)),sliderMax:Math.max(1,V)})}),z&&a(n,{label:b("toolbar.cornerRadius"),visible:z,enabled:0!==S.cornerRadius,onEnabledChange:e=>{R({cornerRadius:e?Math.min(S.width/4,S.height/4):0})},value:Math.round(N),sliderValue:N,onChange:e=>{R({cornerRadius:e})},min:1,max:Math.round(V),sliderMax:V}),F&&a(q,{store:l,elements:s}),o(i,{label:b("toolbar.shadow"),enabled:S.shadowEnabled,onEnabledChange:e=>R({shadowEnabled:e}),children:[a(n,{label:b("toolbar.blur"),value:Math.round(S.shadowBlur),sliderValue:S.shadowBlur,onChange:e=>{R({shadowBlur:e})},min:0,max:I(50,S.shadowBlur)}),a(n,{label:b("toolbar.offsetX"),value:Math.round(S.shadowOffsetX),sliderValue:S.shadowOffsetX,onChange:e=>{R({shadowOffsetX:e})},min:T(-50,S.shadowOffsetX),max:I(50,S.shadowOffsetX)}),a(n,{label:b("toolbar.offsetY"),value:Math.round(S.shadowOffsetY),sliderValue:S.shadowOffsetY,onChange:e=>{R({shadowOffsetY:e})},min:T(-50,S.shadowOffsetY),max:I(50,S.shadowOffsetY)}),a(n,{label:b("toolbar.opacity"),value:Math.round(100*S.shadowOpacity),onChange:e=>{R({shadowOpacity:e/100})},min:0,max:100}),a(f,{label:b("toolbar.color"),className:"pn:py-2",children:a(c,{value:S.shadowColor,size:30,onChange:e=>{R({shadowColor:e})},store:l})})]})]})});
@@ -3,6 +3,7 @@ import type { StoreType, Section } from '../ui-types.js';
3
3
  export type { Section } from '../ui-types.js';
4
4
  export { SectionTab } from './tab-button.js';
5
5
  export { ImagesGrid } from './images-grid.js';
6
+ export { VariablesSection } from './variables-panel.js';
6
7
  export declare const TemplatesSection: Section;
7
8
  export declare const TextSection: Section;
8
9
  export declare const PhotosSection: Section;
@@ -1 +1 @@
1
- import{jsx as e,jsxs as n}from"react/jsx-runtime";import*as o from"react";import{observer as a}from"mobx-react-lite";import{flags as t}from"../utils/flags.js";import{useMobile as i}from"../utils/screen.js";import{t as l}from"../utils/l10n.js";import{cn as s}from"../lib/utils.js";import{PolotnoScope as r}from"../primitives/portal-scope.js";import{SectionTab as p}from"./tab-button.js";import{TemplatesPanel as d}from"./templates-panel.js";import{TextPanel as m}from"./text-panel.js";import{PhotosPanel as c}from"./photos-panel.js";import{ElementsPanel as b}from"./elements-panel.js";import{UploadPanel as f}from"./upload-panel.js";import{BackgroundPanel as u}from"./background-panel.js";import{PagesPanel as P}from"./pages-panel.js";import{LayersPanel as x}from"./layers-panel.js";import{SizePanel as S}from"./size-panel.js";import{DrawPanel as h}from"./draw-panel.js";import{VideosPanel as g}from"./videos-panel.js";import{ImageClipPanel as v}from"./image-clip-panel.js";import{ImageEditPanel as j}from"./image-edit-panel.js";import{AnimationsPanel as w}from"./animations-panel.js";import{EffectsPanel as T}from"./effects-panel.js";import{PolotnoIcon as k}from"../icons/registry.js";export{SectionTab}from"./tab-button.js";export{ImagesGrid}from"./images-grid.js";export const TemplatesSection={name:"templates",Tab:a(n=>e(p,Object.assign({name:l("sidePanel.templates")},n,{children:e(k,{name:"sidePanel.templates"})}))),Panel:({store:n})=>e(d,{store:n})};export const TextSection={name:"text",Tab:a(n=>e(p,Object.assign({name:l("sidePanel.text")},n,{children:e(k,{name:"sidePanel.text"})}))),Panel:({store:n})=>e(m,{store:n})};export const PhotosSection={name:"photos",Tab:a(n=>e(p,Object.assign({name:l("sidePanel.photos")},n,{children:e(k,{name:"sidePanel.photos"})}))),Panel:({store:n})=>e(c,{store:n})};export const ElementsSection={name:"elements",Tab:a(n=>e(p,Object.assign({name:l("sidePanel.elements"),iconSize:16},n,{children:e(k,{name:"sidePanel.elements"})}))),Panel:({store:n})=>e(b,{store:n})};export const UploadSection={name:"upload",Tab:a(n=>e(p,Object.assign({name:l("sidePanel.upload")},n,{children:e(k,{name:"sidePanel.upload"})}))),Panel:({store:n})=>e(f,{store:n})};export const BackgroundSection={name:"background",Tab:a(n=>e(p,Object.assign({name:l("sidePanel.background")},n,{children:e(k,{name:"sidePanel.background"})}))),Panel:({store:n})=>e(u,{store:n})};export const PagesSection={name:"pages",Tab:a(n=>e(p,Object.assign({name:l("sidePanel.pages")},n,{children:e(k,{name:"sidePanel.pages"})}))),Panel:({store:n})=>e(P,{store:n}),visibleInList:!1};export const LayersSection={name:"layers",Tab:a(n=>e(p,Object.assign({name:l("sidePanel.layers")},n,{children:e(k,{name:"sidePanel.layers"})}))),Panel:({store:n})=>e(x,{store:n})};export const SizeSection={name:"size",Tab:a(n=>e(p,Object.assign({name:l("sidePanel.resize")},n,{children:e(k,{name:"sidePanel.resize"})}))),Panel:({store:n})=>e(S,{store:n})};export const DrawSection={name:"draw",Tab:a(n=>e(p,Object.assign({name:l("sidePanel.draw")},n,{children:e(k,{name:"sidePanel.draw"})}))),Panel:({store:n})=>e(h,{store:n})};export const VideosSection={name:"videos",Tab:n=>e(p,Object.assign({name:l("sidePanel.videos")},n,{children:e(k,{name:"sidePanel.videos"})})),Panel:g};export const ImageEditSection={name:"image-edit",Tab:()=>null,Panel:j,visibleInList:!1};export const DEFAULT_SECTIONS=[TemplatesSection,TextSection,PhotosSection,ElementsSection,DrawSection,UploadSection,BackgroundSection,LayersSection,SizeSection,ImageEditSection];const C={name:"image-clip",Tab:()=>null,Panel:v},E={name:"effects",Tab:()=>null,Panel:T},N={name:"animation",Tab:()=>null,Panel:w};export const INTERNAL_SECTIONS=[C,E];const I=new Set([v,T,w]),O=({onClick:o})=>n("div",{className:"pn-side-panel-hide-button pn:absolute pn:right-[-14px] pn:top-1/2 pn:z-10 pn:h-24 pn:w-[15px] pn:cursor-pointer pn:max-md:hidden pn:pn-mobile:hidden",onClick:o,children:[e("svg",{width:"15",height:"96",viewBox:"0 0 16 96",xmlns:"http://www.w3.org/2000/svg",children:e("path",{className:"pn:stroke-border pn:fill-background",d:"M 1 7 C 2 9 4 10 7.2 13.28 C 7.45 13.4625 7.6 13.6 7.7 13.8048 L 7.8 13.8 C 9.8 15.8 11.6 17.6 12.9 19.7 C 14 21.6 14.7 23.9 14.9 27 H 15 V 68 C 15 71.7 14.3 74.3 13 76.6 C 11.7 78.8 9.9 80.5 7.8 82.6344 L 7.79 82.6 C 7.6 82.8 7.4507 83 7.2729 83.2127 C 3.9102 86.5228 2 87 1 90"})}),e("div",{className:"pn:absolute pn:left-1/2 pn:top-1/2 pn:text-[0.5rem] pn:text-muted-foreground pn:hover:text-foreground",style:{transform:"translate(-50%, -50%) scaleY(2)"},children:"<"})]});export const SidePanel=a(({store:a,sections:l,defaultSection:p="photos"})=>{var d,m;(()=>{const e=o.useRef(!0);e.current&&(e.current=!1,a.openSidePanel(p))})();const c=i();o.useLayoutEffect(()=>{c?a.openSidePanel(""):a.openSidePanel(p)},[c]);const b=[...l||DEFAULT_SECTIONS],f=b.find(e=>"image-edit"===e.name),u=!!f;o.useLayoutEffect(()=>(a._setImageEditPanelAvailable(u),()=>a._setImageEditPanelAvailable(!1)),[a,u]);const P=o.useRef(p),x=(null==f?void 0:f.Panel)===j,S="expand"===(null===(d=a.activeTool)||void 0===d?void 0:d.name)||"inpaint"===(null===(m=a.activeTool)||void 0===m?void 0:m.name),h=c&&x&&S&&"image-edit"===a.openedSidePanel;if(o.useLayoutEffect(()=>{"image-edit"!==a.openedSidePanel?P.current=a.openedSidePanel:x&&!a.activeTool&&a.openSidePanel("image-edit"===P.current?"":P.current)},[a,a.openedSidePanel,a.activeTool,x]),INTERNAL_SECTIONS.forEach(e=>{b.find(n=>n.name===e.name)||b.push(e)}),t.animationsEnabled){if(!b.find(e=>"videos"===e.name)){const e=Math.floor(b.length/2);b.splice(e,0,VideosSection)}if(!b.find(e=>"animations"===e.name)){const e=Math.floor(b.length/2);b.splice(e,0,N)}}const g=b.filter(e=>{var n;return null===(n=e.visibleInList)||void 0===n||n}),v=e=>{const n=e.target,o=n.closest(".polotno-close-panel"),t=n.closest(".polotno-mobile");o&&(c||t)&&a.openSidePanel("")},w=o.useRef(null),T=o.useRef(null),k=o.useRef(new Set);return a.openedSidePanel&&k.current.add(a.openedSidePanel),e(r,{elementRef:T,children:n("div",{ref:T,className:s("polotno-side-panel pn-side-panel pn:relative pn:flex pn:h-full pn:bg-background pn:p-0 pn:text-foreground","pn:md:border-r pn:md:border-border","pn:max-md:h-auto pn:max-md:w-full pn:pn-mobile:h-auto pn:pn-mobile:w-full","pn:max-md:border-t pn:max-md:border-border pn:pn-mobile:border-t pn:pn-mobile:border-border",h&&"pn:flex-col-reverse",!a.openedSidePanel&&"collapsed"),children:[e("div",{ref:w,className:s("polotno-side-tabs-container pn:bg-background pn:max-md:w-full pn:max-md:overflow-auto pn:pn-mobile:w-full pn:pn-mobile:overflow-auto pn:md:overflow-y-auto pn:md:overflow-x-hidden pn:md:min-w-[72px]",a.openedSidePanel&&"pn:md:border-r pn:md:border-border"),children:e("div",{className:"polotno-side-tabs-inner pn:flex pn:flex-col pn:max-md:flex-row pn:max-md:min-w-min pn:pn-mobile:flex-row pn:pn-mobile:min-w-min",children:g.map(({name:n,Tab:o})=>e(o,{active:n===a.openedSidePanel,onClick:()=>{n===a.openedSidePanel&&c?a.openSidePanel(""):a.openSidePanel(n)}},n))})}),b.map(({name:n,Panel:o})=>k.current.has(n)&&e("div",{className:s("polotno-panel-container pn-side-panel-content pn:h-full pn:px-2",!I.has(o)&&"pn:pt-2.5","pn:w-[var(--pn-sidebar-width,350px)]",!a.openedSidePanel&&"pn:w-0",n!==a.openedSidePanel&&"pn:hidden","pn:max-md:w-full pn:max-md:bg-background pn:pn-mobile:w-full pn:pn-mobile:bg-background",h&&"image-edit"===n?"pn:flex pn:h-auto pn:max-h-[40dvh] pn:shrink-0 pn:flex-col pn:border-b pn:border-border":"pn:max-md:absolute pn:max-md:bottom-[54px] pn:max-md:z-[100] pn:max-md:!h-[50vh] pn:pn-mobile:absolute pn:pn-mobile:bottom-[54px] pn:pn-mobile:z-[100] pn:pn-mobile:!h-[50vh]"),onClick:v,children:e(o,{store:a})},n)),a.openedSidePanel&&c&&!S&&e("div",{className:"polotno-close-panel",style:{position:"absolute",left:0,bottom:"72px",width:"100vw",height:"100vh",zIndex:99,backgroundColor:"rgba(0,0,0,0.05)"},onClick:()=>a.openSidePanel("")}),a.openedSidePanel&&e(O,{onClick:()=>a.openSidePanel("")})]})})});SidePanel.displayName="SidePanel";export default SidePanel;
1
+ import{jsx as e,jsxs as n}from"react/jsx-runtime";import*as o from"react";import{observer as a}from"mobx-react-lite";import{flags as t}from"../utils/flags.js";import{useMobile as i}from"../utils/screen.js";import{t as l}from"../utils/l10n.js";import{cn as s}from"../lib/utils.js";import{PolotnoScope as r}from"../primitives/portal-scope.js";import{SectionTab as p}from"./tab-button.js";import{TemplatesPanel as d}from"./templates-panel.js";import{TextPanel as m}from"./text-panel.js";import{PhotosPanel as c}from"./photos-panel.js";import{ElementsPanel as b}from"./elements-panel.js";import{UploadPanel as f}from"./upload-panel.js";import{BackgroundPanel as u}from"./background-panel.js";import{PagesPanel as P}from"./pages-panel.js";import{LayersPanel as x}from"./layers-panel.js";import{SizePanel as S}from"./size-panel.js";import{DrawPanel as h}from"./draw-panel.js";import{VideosPanel as g}from"./videos-panel.js";import{ImageClipPanel as v}from"./image-clip-panel.js";import{ImageEditPanel as j}from"./image-edit-panel.js";import{AnimationsPanel as w}from"./animations-panel.js";import{EffectsPanel as T}from"./effects-panel.js";import{PolotnoIcon as k}from"../icons/registry.js";export{SectionTab}from"./tab-button.js";export{ImagesGrid}from"./images-grid.js";export{VariablesSection}from"./variables-panel.js";export const TemplatesSection={name:"templates",Tab:a(n=>e(p,Object.assign({name:l("sidePanel.templates")},n,{children:e(k,{name:"sidePanel.templates"})}))),Panel:({store:n})=>e(d,{store:n})};export const TextSection={name:"text",Tab:a(n=>e(p,Object.assign({name:l("sidePanel.text")},n,{children:e(k,{name:"sidePanel.text"})}))),Panel:({store:n})=>e(m,{store:n})};export const PhotosSection={name:"photos",Tab:a(n=>e(p,Object.assign({name:l("sidePanel.photos")},n,{children:e(k,{name:"sidePanel.photos"})}))),Panel:({store:n})=>e(c,{store:n})};export const ElementsSection={name:"elements",Tab:a(n=>e(p,Object.assign({name:l("sidePanel.elements"),iconSize:16},n,{children:e(k,{name:"sidePanel.elements"})}))),Panel:({store:n})=>e(b,{store:n})};export const UploadSection={name:"upload",Tab:a(n=>e(p,Object.assign({name:l("sidePanel.upload")},n,{children:e(k,{name:"sidePanel.upload"})}))),Panel:({store:n})=>e(f,{store:n})};export const BackgroundSection={name:"background",Tab:a(n=>e(p,Object.assign({name:l("sidePanel.background")},n,{children:e(k,{name:"sidePanel.background"})}))),Panel:({store:n})=>e(u,{store:n})};export const PagesSection={name:"pages",Tab:a(n=>e(p,Object.assign({name:l("sidePanel.pages")},n,{children:e(k,{name:"sidePanel.pages"})}))),Panel:({store:n})=>e(P,{store:n}),visibleInList:!1};export const LayersSection={name:"layers",Tab:a(n=>e(p,Object.assign({name:l("sidePanel.layers")},n,{children:e(k,{name:"sidePanel.layers"})}))),Panel:({store:n})=>e(x,{store:n})};export const SizeSection={name:"size",Tab:a(n=>e(p,Object.assign({name:l("sidePanel.resize")},n,{children:e(k,{name:"sidePanel.resize"})}))),Panel:({store:n})=>e(S,{store:n})};export const DrawSection={name:"draw",Tab:a(n=>e(p,Object.assign({name:l("sidePanel.draw")},n,{children:e(k,{name:"sidePanel.draw"})}))),Panel:({store:n})=>e(h,{store:n})};export const VideosSection={name:"videos",Tab:n=>e(p,Object.assign({name:l("sidePanel.videos")},n,{children:e(k,{name:"sidePanel.videos"})})),Panel:g};export const ImageEditSection={name:"image-edit",Tab:()=>null,Panel:j,visibleInList:!1};export const DEFAULT_SECTIONS=[TemplatesSection,TextSection,PhotosSection,ElementsSection,DrawSection,UploadSection,BackgroundSection,LayersSection,SizeSection,ImageEditSection];const C={name:"image-clip",Tab:()=>null,Panel:v},E={name:"effects",Tab:()=>null,Panel:T},N={name:"animation",Tab:()=>null,Panel:w};export const INTERNAL_SECTIONS=[C,E];const I=new Set([v,T,w]),O=({onClick:o})=>n("div",{className:"pn-side-panel-hide-button pn:absolute pn:right-[-14px] pn:top-1/2 pn:z-10 pn:h-24 pn:w-[15px] pn:cursor-pointer pn:max-md:hidden pn:pn-mobile:hidden",onClick:o,children:[e("svg",{width:"15",height:"96",viewBox:"0 0 16 96",xmlns:"http://www.w3.org/2000/svg",children:e("path",{className:"pn:stroke-border pn:fill-background",d:"M 1 7 C 2 9 4 10 7.2 13.28 C 7.45 13.4625 7.6 13.6 7.7 13.8048 L 7.8 13.8 C 9.8 15.8 11.6 17.6 12.9 19.7 C 14 21.6 14.7 23.9 14.9 27 H 15 V 68 C 15 71.7 14.3 74.3 13 76.6 C 11.7 78.8 9.9 80.5 7.8 82.6344 L 7.79 82.6 C 7.6 82.8 7.4507 83 7.2729 83.2127 C 3.9102 86.5228 2 87 1 90"})}),e("div",{className:"pn:absolute pn:left-1/2 pn:top-1/2 pn:text-[0.5rem] pn:text-muted-foreground pn:hover:text-foreground",style:{transform:"translate(-50%, -50%) scaleY(2)"},children:"<"})]});export const SidePanel=a(({store:a,sections:l,defaultSection:p="photos"})=>{var d,m;(()=>{const e=o.useRef(!0);e.current&&(e.current=!1,a.openSidePanel(p))})();const c=i();o.useLayoutEffect(()=>{c?a.openSidePanel(""):a.openSidePanel(p)},[c]);const b=[...l||DEFAULT_SECTIONS],f=b.find(e=>"image-edit"===e.name),u=!!f;o.useLayoutEffect(()=>(a._setImageEditPanelAvailable(u),()=>a._setImageEditPanelAvailable(!1)),[a,u]);const P=o.useRef(p),x=(null==f?void 0:f.Panel)===j,S="expand"===(null===(d=a.activeTool)||void 0===d?void 0:d.name)||"inpaint"===(null===(m=a.activeTool)||void 0===m?void 0:m.name),h=c&&x&&S&&"image-edit"===a.openedSidePanel;if(o.useLayoutEffect(()=>{"image-edit"!==a.openedSidePanel?P.current=a.openedSidePanel:x&&!a.activeTool&&a.openSidePanel("image-edit"===P.current?"":P.current)},[a,a.openedSidePanel,a.activeTool,x]),INTERNAL_SECTIONS.forEach(e=>{b.find(n=>n.name===e.name)||b.push(e)}),t.animationsEnabled){if(!b.find(e=>"videos"===e.name)){const e=Math.floor(b.length/2);b.splice(e,0,VideosSection)}if(!b.find(e=>"animations"===e.name)){const e=Math.floor(b.length/2);b.splice(e,0,N)}}const g=b.filter(e=>{var n;return null===(n=e.visibleInList)||void 0===n||n}),v=e=>{const n=e.target,o=n.closest(".polotno-close-panel"),t=n.closest(".polotno-mobile");o&&(c||t)&&a.openSidePanel("")},w=o.useRef(null),T=o.useRef(null),k=o.useRef(new Set);return a.openedSidePanel&&k.current.add(a.openedSidePanel),e(r,{elementRef:T,children:n("div",{ref:T,className:s("polotno-side-panel pn-side-panel pn:relative pn:flex pn:h-full pn:bg-background pn:p-0 pn:text-foreground","pn:md:border-r pn:md:border-border","pn:max-md:h-auto pn:max-md:w-full pn:pn-mobile:h-auto pn:pn-mobile:w-full","pn:max-md:border-t pn:max-md:border-border pn:pn-mobile:border-t pn:pn-mobile:border-border",h&&"pn:flex-col-reverse",!a.openedSidePanel&&"collapsed"),children:[e("div",{ref:w,className:s("polotno-side-tabs-container pn:bg-background pn:max-md:w-full pn:max-md:overflow-auto pn:pn-mobile:w-full pn:pn-mobile:overflow-auto pn:md:overflow-y-auto pn:md:overflow-x-hidden pn:md:min-w-[72px]",a.openedSidePanel&&"pn:md:border-r pn:md:border-border"),children:e("div",{className:"polotno-side-tabs-inner pn:flex pn:flex-col pn:max-md:flex-row pn:max-md:min-w-min pn:pn-mobile:flex-row pn:pn-mobile:min-w-min",children:g.map(({name:n,Tab:o})=>e(o,{active:n===a.openedSidePanel,onClick:()=>{n===a.openedSidePanel&&c?a.openSidePanel(""):a.openSidePanel(n)}},n))})}),b.map(({name:n,Panel:o})=>k.current.has(n)&&e("div",{className:s("polotno-panel-container pn-side-panel-content pn:h-full pn:px-2",!I.has(o)&&"pn:pt-2.5","pn:w-[var(--pn-sidebar-width,350px)]",!a.openedSidePanel&&"pn:w-0",n!==a.openedSidePanel&&"pn:hidden","pn:max-md:w-full pn:max-md:bg-background pn:pn-mobile:w-full pn:pn-mobile:bg-background",h&&"image-edit"===n?"pn:flex pn:h-auto pn:max-h-[40dvh] pn:shrink-0 pn:flex-col pn:border-b pn:border-border":"pn:max-md:absolute pn:max-md:bottom-[54px] pn:max-md:z-[100] pn:max-md:!h-[50vh] pn:pn-mobile:absolute pn:pn-mobile:bottom-[54px] pn:pn-mobile:z-[100] pn:pn-mobile:!h-[50vh]"),onClick:v,children:e(o,{store:a})},n)),a.openedSidePanel&&c&&!S&&e("div",{className:"polotno-close-panel",style:{position:"absolute",left:0,bottom:"72px",width:"100vw",height:"100vh",zIndex:99,backgroundColor:"rgba(0,0,0,0.05)"},onClick:()=>a.openSidePanel("")}),a.openedSidePanel&&e(O,{onClick:()=>a.openSidePanel("")})]})})});SidePanel.displayName="SidePanel";export default SidePanel;
@@ -1 +1 @@
1
- import{jsx as e,jsxs as t}from"react/jsx-runtime";import*as s from"react";import{observer as r}from"mobx-react-lite";import{nanoid as i}from"nanoid";import{forEveryChild as a}from"../model/group-model.js";import{t as o}from"../utils/l10n.js";import{ImagesGrid as n}from"./images-grid.js";import{templateList as l}from"../utils/api.js";import{useInfiniteAPI as m}from"../utils/use-api.js";import{SearchInput as p}from"../primitives/search-input.js";import{Switch as c}from"../primitives/switch.js";const h=(e,t)=>{const r=s.useRef(!0);s.useEffect(()=>{r.current?r.current=!1:e()},t)},g=r(({sizeQuery:t,query:s,store:r})=>{const{setQuery:o,loadMore:p,hasMore:c,data:g,isLoading:d,reset:u,error:f}=m({getAPI:({page:e,query:s})=>l({page:e,query:s,sizeQuery:t}),getSize:e=>e.totalPages});return h(()=>{u()},[t]),h(()=>{o(s)},[s]),e(n,{images:null==g?void 0:g.map(e=>e.items).flat(),getPreview:e=>e.preview,isLoading:d,onSelect:async e=>{const t=await fetch(e.json),s=await t.json();if(r.pages.length<=1){r.loadJSON(s,!0)}else{const e=JSON.parse(JSON.stringify(r.toJSON()));e.width===s.width&&e.height===s.height||s.pages.forEach(e=>{e.width=e.width||s.width,e.height=e.height||s.height}),a({children:s.pages},e=>{e.id=i(10)});const t=r.pages.indexOf(r.activePage);e.pages.splice(t,1,...s.pages),r.loadJSON(e,!0)}},loadMore:c&&p,error:f})});export const TemplatesPanel=r(({store:r})=>{const[i,a]=s.useState(!0),[n,l]=s.useState(""),m=i?`${r.width}x${r.height}`:"all";return t("div",{className:"pn:flex pn:h-full pn:flex-col",children:[e(p,{style:{marginBottom:"20px"},placeholder:o("sidePanel.searchPlaceholder"),onChange:e=>{l(e.target.value)}}),t("label",{className:"pn:flex pn:items-center pn:justify-between",style:{marginTop:"8px",marginBottom:"25px"},children:[t("span",{className:"pn:text-sm",children:[o("sidePanel.searchTemplatesWithSameSize")," "]}),e(c,{checked:i,onCheckedChange:e=>{a(Boolean(e))}})]}),e(g,{store:r,sizeQuery:"size="+m,query:n})]})});
1
+ import{jsx as e,jsxs as t}from"react/jsx-runtime";import*as r from"react";import{observer as o}from"mobx-react-lite";import{linkHref as a,linkPageId as s}from"@polotno/core/links";import{mapLinks as i}from"@polotno/core/page-links";import{renewIds as n}from"../model/group-model.js";import{t as l}from"../utils/l10n.js";import{ImagesGrid as p}from"./images-grid.js";import{templateList as m}from"../utils/api.js";import{useInfiniteAPI as c}from"../utils/use-api.js";import{SearchInput as u}from"../primitives/search-input.js";import{Switch as h}from"../primitives/switch.js";const d=(e,t)=>{const o=r.useRef(!0);r.useEffect(()=>{o.current?o.current=!1:e()},t)},g=o(({sizeQuery:t,query:o,store:l})=>{const{setQuery:u,loadMore:h,hasMore:g,data:f,isLoading:v,reset:w,error:x}=c({getAPI:({page:e,query:r})=>m({page:e,query:r,sizeQuery:t}),getSize:e=>e.totalPages}),[y,j]=r.useState(null),S=r.useRef(0);return d(()=>{w()},[t]),d(()=>{u(o)},[o]),e(p,{images:null==f?void 0:f.map(e=>e.items).flat(),getPreview:e=>e.preview,isLoading:v,onSelect:async e=>{const t=++S.current;j(null);try{const r=await fetch(e.json);if(!r.ok){throw new Error(`polotno: template request failed with ${r.status}`)}const o=await r.json();t===S.current&&((e,t)=>{var r;if(e.pages.length<=1){return void e.loadJSON(t,!0)}const o=JSON.parse(JSON.stringify(e.toJSON()));o.width===t.width&&o.height===t.height||t.pages.forEach(e=>{e.width=e.width||t.width,e.height=e.height||t.height});const l=t.pages.map(e=>e.id);var p,m;n({children:t.pages}),p=t.pages,m=new Map(l.map((e,r)=>[e,t.pages[r].id])),i({children:p},e=>{const t=a(e),r=t&&s(t),o=r&&m.get(r);return o?"#"+o:e}),(null===(r=t.variables)||void 0===r?void 0:r.length)&&(o.variables=((e=[],t)=>{const r=new Map(e.map(e=>[e.name,e]));for(const o of t){const e=r.get(o.name);null==(null==e?void 0:e.value)&&null==(null==e?void 0:e.default)&&r.set(o.name,o)}return[...r.values()]})(o.variables,t.variables));const c=e.pages.indexOf(e.activePage);o.pages.splice(c,1,...t.pages),e.loadJSON(o,!0)})(l,o)}catch(r){if(t!==S.current){return}console.warn("polotno: failed to load the template",r),j(r)}},loadMore:g&&h,error:x||y})});export const TemplatesPanel=o(({store:o})=>{const[a,s]=r.useState(!0),[i,n]=r.useState(""),p=a?`${o.width}x${o.height}`:"all";return t("div",{className:"pn:flex pn:h-full pn:flex-col",children:[e(u,{style:{marginBottom:"20px"},placeholder:l("sidePanel.searchPlaceholder"),onChange:e=>{n(e.target.value)}}),t("label",{className:"pn:flex pn:items-center pn:justify-between",style:{marginTop:"8px",marginBottom:"25px"},children:[t("span",{className:"pn:text-sm",children:[l("sidePanel.searchTemplatesWithSameSize")," "]}),e(h,{checked:a,onCheckedChange:e=>{s(Boolean(e))}})]}),e(g,{store:o,sizeQuery:"size="+p,query:i})]})});
@@ -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}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
+ var e=this&&this.__rest||function(e,r){var o={};for(var t in e){Object.prototype.hasOwnProperty.call(e,t)&&r.indexOf(t)<0&&(o[t]=e[t])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(t=Object.getOwnPropertySymbols(e);n<t.length;n++){r.indexOf(t[n])<0&&Object.prototype.propertyIsEnumerable.call(e,t[n])&&(o[t[n]]=e[t[n]])}}return o};import{Fragment as r,jsx as o,jsxs as t}from"react/jsx-runtime";import n from"react";import{observer as l}from"mobx-react-lite";import{t as a}from"../utils/l10n.js";import{isGradient as s,parseColor as i}from"@polotno/core/gradient";import{sameColors as c}from"@polotno/core/svg";import{formatCmykColor as p,isCmykColor as d,toDisplayColor as u}from"@polotno/core/color";import m,{cmykFromColor as h}from"./sketch.js";import{addStop as g,insertStop as f,readGradient as v,writeGradient as b}from"../utils/gradient-stops.js";import{canRemoveStop as C,reverseStops as x}from"../utils/stops.js";import{StopTrack as y}from"./stop-track.js";import{GradientCenterPad as k}from"./gradient-center-pad.js";import{UnitNumericInput as w}from"./unit-numeric-input.js";import{findRadialPaint as j,setRadialHandle as E}from"../utils/gradient-handle.js";import{ToggleGroup as N,ToggleGroupItem as O}from"../primitives/toggle-group.js";import{PolotnoIcon as P}from"../icons/registry.js";import{cn as $,firstSliderValue as F}from"../lib/utils.js";import{Slider as S}from"../primitives/slider.js";import{TooltipIconButton as R}from"../primitives/tooltip-icon-button.js";import{Popover as B,PopoverContent as z,PopoverTrigger as D}from"../primitives/popover.js";import{Tabs as A,TabsContent as L,TabsList as I,TabsTrigger as M}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 r=[];e.pages.forEach(e=>{e.children.forEach(e=>{e.shadowEnabled&&r.push(e.shadowColor),"text"===e.type&&(r.push(e.fill),e.backgroundEnabled&&r.push(e.backgroundColor),e.strokeWidth&&r.push(e.stroke)),"svg"===e.type&&r.push(...e.colorsReplace.values()),"figure"===e.type&&(r.push(e.fill),e.strokeWidth&&r.push(e.stroke)),"line"===e.type&&r.push(e.color)})});const o=[];return r.forEach(e=>{if(s(e)){const{stops:r}=v(e);o.push(...r.map(e=>e.color))}else{o.push(e)}}),[...new Set(o)]};const T=r=>{var{style:t,color:l,onChange:a}=r,s=e(r,["style","color","onChange"]);const[i,c]=n.useState(l);n.useEffect(()=>{c(l)},[l]);const d=n.useRef(void 0),u=n.useRef(void 0);return o("div",{className:"pn-color-picker-solid",style:t,onMouseDown:e=>{"INPUT"!==e.target.tagName&&e.preventDefault()},children:o(m,Object.assign({color:i},s,{onChange:e=>{const{r,g:o,b:t,a:n}=e.rgb,l=e.cmyk?p(e.cmyk):`rgba(${r},${o},${t},${n})`;c(l),u.current=l,d.current||(d.current=window.setTimeout(()=>{d.current=0,a(u.current||l)},50))}}))})},U=({value:e,onChange:l,store:s,preset:c})=>{var m,$;const{type:B,rotation:z,center:D,ending:A,stops:L}=v(e),I=n.useId(),[M,U]=n.useState(0),V=n.useRef(90);"linear"===B&&(V.current=z);const G=Math.min(M,L.length-1),H=n.useRef(null),W=n.useRef(null),q=null!==($=null!==(m=s.selectedElements[0])&&void 0!==m?m:s.activePage)&&void 0!==$?$:void 0,J={type:B,rotation:z,center:D,ending:A,stops:L},K=e=>l(b(Object.assign(Object.assign({},J),e))),Q=(e,r=z)=>K({stops:e,rotation:r}),X=e=>{U(e.index),Q(e.stops)},Y=n.useRef(l);Y.current=l,n.useEffect(()=>{const r="radial"===B&&q&&j(q,e);r&&E(s,Object.assign(Object.assign({},r),{onChange:e=>Y.current(e)}))},[s,B,q,e]),n.useEffect(()=>()=>E(s,null),[s,"radial"===B,q]);const Z=b({rotation:90,stops:L}),ee="radial"===B?`${u(b({type:"radial",rotation:0,center:D,ending:A,stops:L}))}, ${_}`:"";return n.useLayoutEffect(()=>{const e=W.current,r=e.getContext("2d"),o=r.createLinearGradient(0,0,e.width,0);i(Z).stops.forEach(({offset:e,color:r})=>o.addColorStop(e,r)),r.clearRect(0,0,e.width,1),r.fillStyle=o,r.fillRect(0,0,e.width,1)},[Z]),t("div",{className:"pn:flex pn:flex-col pn:gap-1 pn:pt-2",children:[o("div",{className:"pn:px-2.5",children:t(N,{className:"pn:w-full",value:[B],"aria-label":a("toolbar.colorPicker.gradientType"),onValueChange:e=>{const r=e[0];"linear"!==r&&"radial"!==r||(e=>{e!==B&&K("radial"===e?{type:"radial",center:{x:.5,y:.5},ending:"circle"}:{type:"linear",rotation:V.current})})(r)},children:[o(O,{value:"linear",className:"pn:flex-1","aria-label":a("toolbar.colorPicker.linear"),children:a("toolbar.colorPicker.linear")}),o(O,{value:"radial",className:"pn:flex-1","aria-label":a("toolbar.colorPicker.radial"),children:a("toolbar.colorPicker.radial")})]})}),o("div",{className:"pn:mx-2.5",children:o(y,{handle:H,store:s,node:q,label:a("toolbar.colorPicker.stops"),stops:L,selected:G,onSelect:U,onChange:X,insert:f,stopLabel:(e,r)=>`${a("toolbar.colorPicker.stop")} ${r+1}: ${Math.round(100*e.offset)}%`,swatch:e=>{const r=u(e.color);return`linear-gradient(${r}, ${r}), ${_}`},bar:o("canvas",{ref:W,width:512,height:1,"aria-hidden":!0,className:"pn:block pn:size-full",style:{backgroundImage:_}})})}),t("div",{className:"pn:flex pn:items-center pn:gap-1 pn:px-2.5",children:[o(R,{label:a("toolbar.colorPicker.addStop"),onClick:()=>X(g(L)),children:o(P,{name:"action.add",className:"pn:size-4"})}),o(R,{label:a("toolbar.colorPicker.removeStop"),disabled:!C(L),onClick:()=>{var e;return null===(e=H.current)||void 0===e?void 0:e.remove(G)},children:o(P,{name:"action.remove",className:"pn:size-4"})}),o(R,{label:a("toolbar.colorPicker.reverse"),onClick:()=>X({stops:x(L),index:L.length-1-G}),children:o(P,{name:"colorPicker.reverseGradient",className:"pn:size-4"})}),"linear"===B&&t(r,{children:[o("label",{id:`${I}-label`,className:"pn:ml-auto pn:text-sm",htmlFor:I,children:a("toolbar.colorPicker.angle")}),o(w,{id:I,unit:"°",value:z,min:0,max:360,onValueChange:e=>Q(L,e),style:{width:64}})]})]}),"linear"===B?o("div",{className:"pn:px-2.5 pn:py-1",children:o(S,{"aria-labelledby":`${I}-label`,value:[z],min:0,max:360,onValueChange:e=>Q(L,Math.round(F(e)))})}):o(k,{center:D,preview:ee,store:s,node:q,onChange:e=>K({center:e})}),o(T,{color:L[G].color,presetColors:c,onChange:e=>Q(L.map((r,o)=>{return{offset:r.offset,color:o===G?e:(t=e,n=r.color,d(t)?d(n)?n:p(h(n)):d(n)?u(n):n)};var t,n}))})]})},V=l(({value:e,onChange:r,preset:l,store:i})=>{const[c,p]=n.useState(s(e)?"gradient":"solid");return o("div",{style:{padding:"5px"},children:t(A,{value:c,onValueChange:e=>p(e),className:"pn:w-full",children:[t(I,{className:"pn:flex pn:w-full pn:flex-row",children:[o(M,{value:"solid",className:"pn:flex-1",children:a("toolbar.colorPicker.solid")}),o(M,{value:"gradient",className:"pn:flex-1",children:a("toolbar.colorPicker.gradient")})]}),o(L,{value:"solid",className:"pn:w-full",children:o(T,{color:s(e)?v(e).stops[0].color:e,onChange:r,presetColors:l,style:{padding:"0"}})}),o(L,{value:"gradient",className:"ember-panel pn:w-full",children:o(U,{value:e,onChange:r,store:i,preset: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=n.forwardRef(function(r,t){var{size:n=30,background:l,style:a={},className:s,children:i=null}=r,c=e(r,["size","background","style","className","children"]);const p="string"==typeof l?u(l):"transparent",d=p.includes("gradient")?p:`linear-gradient(${p}, ${p}), ${_}`;return o("div",Object.assign({ref:t,role:"button",tabIndex:0,"aria-label":"Pick color",onMouseDown:e=>e.preventDefault(),className:$("pn:flex pn:cursor-pointer pn:items-center pn:justify-center pn:overflow-hidden pn:rounded-md pn:border pn:border-foreground/30",s),style:Object.assign({width:n+"px",height:n+"px",backgroundImage:d},a)},c,{children:i}))});let G=e=>{const r=getUsedColors(e).slice(0,8).filter(e=>!DEFAULT_COLORS.find(r=>c(r,e)));return r.concat(DEFAULT_COLORS.slice(0,16-r.length).reverse())};export function setColorsPresetFunc(e){G=e}const H=({value:e,onChange:r,store:t,gradientEnabled:n,presetColors:l})=>n?o(V,{preset:l,value:e,onChange:r,store:t}):o("div",{style:{padding:"5px"},children:o(T,{color:e,onChange:r,presetColors:l})});let W=H;const q=e=>o(W,Object.assign({},e,{presetColors:G(e.store)}));export function setColorPickerContent(e){W=null!=e?e:H}export const ColorPicker=({value:e,onChange:r,size:l,store:a,gradientEnabled:s,children:i,style:c,onOpen:p,onClose:d})=>{const[u,m]=n.useState(!1);return t(B,{open:u,onOpenChange:e=>{m(e),e?null==p||p():null==d||d()},children:[o(D,{nativeButton:!1,render:o(ColoredBox,{size:l,background:e,style:c,children:i})}),o(z,{className:"pn:w-[280px] pn:p-0",initialFocus:!1,children:o(q,{value:e,onChange:r,store:a,gradientEnabled:!!s})})]})};export default ColorPicker;
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import type { GradientCenter } from '../utils/gradient-stops.js';
3
+ import type { StoreType } from '../ui-types.js';
4
+ import type { IAnyStateTreeNode } from 'mobx-state-tree';
5
+ export declare const GradientCenterPad: ({ center, preview, onChange, store, node, }: {
6
+ center: GradientCenter;
7
+ preview: string;
8
+ onChange: (center: GradientCenter) => void;
9
+ store: StoreType;
10
+ node?: IAnyStateTreeNode;
11
+ }) => React.JSX.Element;
@@ -0,0 +1 @@
1
+ import{jsx as e,jsxs as n}from"react/jsx-runtime";import r from"react";import{t}from"../utils/l10n.js";import{UnitNumericInput as o}from"./unit-numeric-input.js";import{usePointerDrag as i,isPrimaryDrag as a}from"../utils/pointer-drag.js";import{safe01 as s}from"../utils/stops.js";import{useHistoryGesture as l}from"../utils/history-gesture.js";const p=e=>Math.round(1e3*e)/10;export const GradientCenterPad=({center:c,preview:d,onChange:m,store:u,node:h})=>{const x=r.useRef(null),f=i(),b=l(u,h),g=r.useId(),y=r.useId(),v=(e,n)=>{const r=x.current.getBoundingClientRect();return{x:s((e-r.left)/(r.width||1)),y:s((n-r.top)/(r.height||1))}};return n("div",{className:"pn:flex pn:items-center pn:gap-2 pn:px-2.5",children:[e("div",{ref:x,role:"slider",tabIndex:0,"aria-label":t("toolbar.colorPicker.center"),"aria-valuetext":`${p(c.x)}% ${p(c.y)}%`,"data-gradient-center-pad":!0,className:"pn:relative pn:flex-1 pn:cursor-crosshair pn:touch-none pn:rounded-sm pn:border pn:border-border",style:{height:64,backgroundImage:d},onPointerDown:e=>{a(e)&&(b.begin(),m(v(e.clientX,e.clientY)),f(e,{node:h,slopX:0,onMove:e=>{b.active()&&(0!==e.buttons?m(v(e.clientX,e.clientY)):b.end())},onEnd:b.end}))},onKeyDown:e=>{const n=e.shiftKey?.1:.01,r={ArrowLeft:[-n,0],ArrowRight:[n,0],ArrowUp:[0,-n],ArrowDown:[0,n]}[e.key];r&&(e.preventDefault(),m({x:s(c.x+r[0]),y:s(c.y+r[1])}))},children:e("div",{"aria-hidden":!0,className:"pn:pointer-events-none pn:absolute pn:size-3 pn:-translate-x-1/2 pn:-translate-y-1/2 pn:rounded-full pn:border-2 pn:border-white pn:shadow-[0_0_0_1px_rgba(0,0,0,0.6)]",style:{left:100*c.x+"%",top:100*c.y+"%"}})}),e("div",{className:"pn:flex pn:flex-col pn:gap-1",children:[["x",g,t("toolbar.colorPicker.centerX")],["y",y,t("toolbar.colorPicker.centerY")]].map(([r,t,i])=>n("div",{className:"pn:flex pn:items-center pn:gap-1",children:[e("label",{htmlFor:t,className:"pn:w-4 pn:text-sm",children:r.toUpperCase()}),e(o,{id:t,"aria-label":i,unit:"%",value:p(c[r]),min:0,max:100,onValueChange:e=>m(Object.assign(Object.assign({},c),{[r]:s(e/100)})),style:{width:72}})]},r))})]})};
@@ -0,0 +1,29 @@
1
+ import React from 'react';
2
+ import type { TextPadding } from '@polotno/core/text-types';
3
+ type PaddingFields = Record<keyof TextPadding, string>;
4
+ export declare const TEXT_PADDING_FIELDS: {
5
+ readonly top: 'paddingTop';
6
+ readonly right: 'paddingRight';
7
+ readonly bottom: 'paddingBottom';
8
+ readonly left: 'paddingLeft';
9
+ };
10
+ export declare const CELL_PADDING_FIELDS: {
11
+ readonly top: 'cellPaddingTop';
12
+ readonly right: 'cellPaddingRight';
13
+ readonly bottom: 'cellPaddingBottom';
14
+ readonly left: 'cellPaddingLeft';
15
+ };
16
+ export declare const cellPaddingSides: (el: {
17
+ cellPaddingTop: number;
18
+ cellPaddingRight: number;
19
+ cellPaddingBottom: number;
20
+ cellPaddingLeft: number;
21
+ }) => TextPadding;
22
+ export declare function paddingAttrs(sides: Partial<TextPadding>, fields: PaddingFields): Record<string, number>;
23
+ export declare const PaddingControl: ({ label, value, onChange, disabled, }: {
24
+ label: string;
25
+ value: TextPadding;
26
+ onChange: (sides: Partial<TextPadding>) => void;
27
+ disabled?: boolean;
28
+ }) => React.JSX.Element;
29
+ export {};
@@ -0,0 +1 @@
1
+ import{jsx as t,jsxs as o}from"react/jsx-runtime";import i from"react";import{PolotnoIcon as e}from"../icons/registry.js";import{Button as a}from"../primitives/button.js";import{FieldRow as n}from"../primitives/field-row.js";import{NumericInput as l}from"../primitives/numeric-input.js";import{t as d}from"../utils/l10n.js";const r=["top","right","bottom","left"],p={top:"toolbar.paddingTop",right:"toolbar.paddingRight",bottom:"toolbar.paddingBottom",left:"toolbar.paddingLeft"};export const TEXT_PADDING_FIELDS={top:"paddingTop",right:"paddingRight",bottom:"paddingBottom",left:"paddingLeft"};export const CELL_PADDING_FIELDS={top:"cellPaddingTop",right:"cellPaddingRight",bottom:"cellPaddingBottom",left:"cellPaddingLeft"};export const cellPaddingSides=t=>({top:t.cellPaddingTop,right:t.cellPaddingRight,bottom:t.cellPaddingBottom,left:t.cellPaddingLeft});export function paddingAttrs(t,o){const i={};for(const e of r){const a=t[e];void 0!==a&&(i[o[e]]=a)}return i}export const PaddingControl=({label:s,value:g,onChange:m,disabled:c=!1})=>{const b=g.top===g.right&&g.right===g.bottom&&g.bottom===g.left,[h,f]=i.useState(!b),u=d("toolbar.paddingSides");return o("div",{"data-slot":"padding-control",children:[t(n,{label:s,className:"pn:py-1",children:o("div",{className:"pn:flex pn:items-center pn:gap-1",children:[!h&&t(l,{"aria-label":s,value:g.top,onValueChange:t=>m({top:t,right:t,bottom:t,left:t}),min:0,max:1e3,disabled:c,style:{width:"72px"}}),t(a,{variant:h?"secondary":"ghost",size:"icon-sm","aria-label":u,"aria-pressed":h,title:u,disabled:c,onClick:()=>f(!h),children:t(e,{name:"toolbar.paddingSides",className:"pn:size-4"})})]})}),h&&t("div",{className:"pn:grid pn:grid-cols-2 pn:gap-x-3 pn:gap-y-1 pn:pt-1",children:r.map(o=>{const i=d(p[o]);return t(n,{label:i,children:t(l,{"aria-label":`${s} ${i}`,value:g[o],onValueChange:t=>m({[o]:t}),min:0,max:1e3,disabled:c,style:{width:"64px"}})},o)})})]})};
@@ -1 +1 @@
1
- import{jsx as e,jsxs as o}from"react/jsx-runtime";import r from"react";import{observer as t}from"mobx-react-lite";import{isGradient as n,firstStopColor as l}from"@polotno/core/gradient";import{t as a}from"../utils/l10n.js";import{useSvgColorsMap as s}from"../utils/use-svg-colors.js";import{collectSelectionColors as i}from"../utils/selection-colors.js";import{Popover as p,PopoverContent as c,PopoverTrigger as m}from"../primitives/popover.js";import d,{ColoredBox as u}from"./color-picker.js";export const stripeGradient=e=>{const o=e.slice(0,8).map(l),r=o.length||1;return`linear-gradient(90deg, ${o.map((e,o)=>`${e} ${o/r*100}% ${(o+1)/r*100}%`).join(", ")})`};export const ColorRow=({value:r,onChange:t,store:l,gradientEnabled:s=!0})=>o("div",{className:"pn-svg-color-row pn:flex pn:items-center pn:gap-2",children:[e(d,{value:r,onChange:t,store:l,gradientEnabled:s}),e("span",{className:"pn:truncate pn:text-xs pn:text-muted-foreground",children:n(r)?a("toolbar.colorPicker.linear"):r})]});const g=e=>e.slots.every(e=>e.gradient),v=(e,o,r)=>{e.history.transaction(()=>{o.slots.forEach(e=>e.apply(r))})};export const SelectionColors=t(({store:t})=>{const n=t.selectedShapes,l=s(n.filter(e=>"svg"===e.type).map(e=>e.src)),h=i(n,e=>l.get(e)),[x,f]=r.useState(null);return x||h.length?x||1!==h.length?o(p,{onOpenChange:e=>f(e?{rows:h,values:h.map(e=>e.color)}:null),children:[e(m,{nativeButton:!1,render:e(u,{background:stripeGradient(x?x.values:h.map(e=>e.color)),"aria-label":a("toolbar.colorPicker.colors")})}),o(c,{className:"pn:w-[220px] pn:p-2",align:"start",children:[e("div",{className:"pn:mb-2 pn:text-xs pn:font-medium",children:a("toolbar.colorPicker.colors")}),e("div",{className:"pn:flex pn:max-h-[280px] pn:flex-col pn:gap-2 pn:overflow-y-auto",children:null==x?void 0:x.rows.map((o,r)=>e(ColorRow,{value:x.values[r],store:t,gradientEnabled:g(o),onChange:e=>{v(t,o,e),f(o=>o&&Object.assign(Object.assign({},o),{values:o.values.map((o,t)=>t===r?e:o)}))}},r))})]})]}):e(d,{value:h[0].color,onChange:e=>v(t,h[0],e),store:t,gradientEnabled:g(h[0])}):null});
1
+ import{jsx as e,jsxs as o}from"react/jsx-runtime";import r from"react";import{observer as t}from"mobx-react-lite";import{isGradient as n,isRadialGradient as l,firstStopColor as a}from"@polotno/core/gradient";import{t as s}from"../utils/l10n.js";import{useSvgColorsMap as i}from"../utils/use-svg-colors.js";import{collectSelectionColors as p}from"../utils/selection-colors.js";import{Popover as c,PopoverContent as m,PopoverTrigger as d}from"../primitives/popover.js";import u,{ColoredBox as g}from"./color-picker.js";export const stripeGradient=e=>{const o=e.slice(0,8).map(a),r=o.length||1;return`linear-gradient(90deg, ${o.map((e,o)=>`${e} ${o/r*100}% ${(o+1)/r*100}%`).join(", ")})`};export const ColorRow=({value:r,onChange:t,store:a,gradientEnabled:i=!0})=>o("div",{className:"pn-svg-color-row pn:flex pn:items-center pn:gap-2",children:[e(u,{value:r,onChange:t,store:a,gradientEnabled:i}),e("span",{className:"pn:truncate pn:text-xs pn:text-muted-foreground",children:n(r)?l(r)?s("toolbar.colorPicker.radial"):s("toolbar.colorPicker.linear"):r})]});const v=e=>e.slots.every(e=>e.gradient),h=(e,o,r)=>{e.history.transaction(()=>{o.slots.forEach(e=>e.apply(r))})};export const SelectionColors=t(({store:t})=>{const n=t.selectedShapes,l=i(n.filter(e=>"svg"===e.type).map(e=>e.src)),a=p(n,e=>l.get(e)),[x,f]=r.useState(null);return x||a.length?x||1!==a.length?o(c,{onOpenChange:e=>f(e?{rows:a,values:a.map(e=>e.color)}:null),children:[e(d,{nativeButton:!1,render:e(g,{background:stripeGradient(x?x.values:a.map(e=>e.color)),"aria-label":s("toolbar.colorPicker.colors")})}),o(m,{className:"pn:w-[220px] pn:p-2",align:"start",children:[e("div",{className:"pn:mb-2 pn:text-xs pn:font-medium",children:s("toolbar.colorPicker.colors")}),e("div",{className:"pn:flex pn:max-h-[280px] pn:flex-col pn:gap-2 pn:overflow-y-auto",children:null==x?void 0:x.rows.map((o,r)=>e(ColorRow,{value:x.values[r],store:t,gradientEnabled:v(o),onChange:e=>{h(t,o,e),f(o=>o&&Object.assign(Object.assign({},o),{values:o.values.map((o,t)=>t===r?e:o)}))}},r))})]})]}):e(u,{value:a[0].color,onChange:e=>h(t,a[0],e),store:t,gradientEnabled:v(a[0])}):null});
@@ -1 +1 @@
1
- import{jsx as e,jsxs as n}from"react/jsx-runtime";import t from"react";import{cn as r}from"../lib/utils.js";import{DRAG_SLOP_PX as o,isPrimaryDrag as s,usePointerDrag as i}from"../utils/pointer-drag.js";import{canRemoveStop as p,moveStop as l}from"../utils/stops.js";const a={ArrowLeft:-1,ArrowDown:-1,ArrowRight:1,ArrowUp:1};export function StopTrack({store:c,node:u,label:d,stops:f,selected:g,onSelect:m,onChange:b,insert:v,stopLabel:h,swatch:x,bar:y,handle:w}){const k=t.useRef(null),S=i(),j=t.useRef(!1),E=t.useRef(null),N=t.useRef(f);N.current=f;const R=()=>{j.current&&(j.current=!1,c.history.endTransaction())};t.useEffect(()=>()=>R(),[c,u]);const D=e=>{var n;const t=null===(n=k.current)||void 0===n?void 0:n.querySelectorAll("[data-stop]")[e];return!!(null==t?void 0:t.getClientRects().length)&&(t.focus({preventScroll:!0}),document.activeElement===t)};t.useLayoutEffect(()=>{null!==E.current&&(D(E.current),E.current=null)});const A=e=>{JSON.stringify(e.stops)!==JSON.stringify(N.current)&&(E.current=e.index,b(e))},z=e=>{p(f)&&A({stops:f.filter((n,t)=>t!==e),index:Math.max(0,e-1)})};t.useImperativeHandle(w,()=>({remove:z,focus:D}));const B=e=>{const n=k.current.getBoundingClientRect();return(e-n.left)/(n.width||1)},C=()=>[c.activePage,...c.selectedElements].map(e=>null==e?void 0:e.id).join();return n("div",{ref:k,role:"group","aria-label":d,className:"pn:relative pn:h-7 pn:cursor-copy pn:touch-none",onPointerDown:e=>{if(!s(e)){return}R(),c.history.addUndoState(),c.history.startTransaction(),j.current=!0;const n=e.target.closest("[data-stop]");let t={stops:f,index:Number(null==n?void 0:n.dataset.stop)};n?(m(t.index),n.focus({preventScroll:!0})):(t=v(f,B(e.clientX)),A(t));const r=C();S(e,{node:u,slopX:o,onMove:e=>{j.current&&(0!==e.buttons&&C()===r?A(l(t.stops,t.index,B(e.clientX))):R())},onEnd:R})},children:[e("div",{className:"pn:absolute pn:inset-x-0 pn:top-1.5 pn:h-4 pn:overflow-hidden pn:rounded-sm pn:ring-1 pn:ring-inset pn:ring-black/15 pn:dark:ring-white/15",children:y}),f.map((n,t)=>e("button",{type:"button","data-stop":t,"aria-label":h(n,t),"aria-pressed":t===g,onKeyDown:e=>((e,n)=>{const{key:t}=e;if(!(t in a)&&!["Home","End","Delete","Backspace"].includes(t)){return}if(e.preventDefault(),e.stopPropagation(),"Delete"===t||"Backspace"===t){return void z(n)}const r="Home"===t?0:"End"===t?1:f[n].offset+a[t]*(e.shiftKey?.1:.01);A(l(f,n,r))})(e,t),onFocus:()=>m(t),className:r("pn:group pn:absolute pn:top-0 pn:size-7 pn:-translate-x-1/2 pn:cursor-grab pn:rounded-md pn:outline-none",t===g&&"pn:z-10"),style:{left:100*n.offset+"%"},children:e("span",{className:r("pn:mx-auto pn:block pn:size-4 pn:rounded-full pn:border-2 pn:border-white pn:shadow-[0_1px_3px_rgba(0,0,0,0.4)] pn:group-focus-visible:ring-2 pn:group-focus-visible:ring-ring pn:group-focus-visible:ring-offset-2",t===g&&"pn:ring-2 pn:ring-primary"),style:{background:x(n)}})},t))]})}
1
+ import{jsx as e,jsxs as n}from"react/jsx-runtime";import t from"react";import{cn as r}from"../lib/utils.js";import{DRAG_SLOP_PX as o,isPrimaryDrag as s,usePointerDrag as i}from"../utils/pointer-drag.js";import{canRemoveStop as p,moveStop as l}from"../utils/stops.js";import{useHistoryGesture as a}from"../utils/history-gesture.js";const u={ArrowLeft:-1,ArrowDown:-1,ArrowRight:1,ArrowUp:1};export function StopTrack({store:c,node:d,label:f,stops:g,selected:m,onSelect:b,onChange:v,insert:h,stopLabel:x,swatch:w,bar:y,handle:j}){const k=t.useRef(null),N=i(),S=a(c,d),D=t.useRef(null),E=t.useRef(g);E.current=g;const R=e=>{var n;const t=null===(n=k.current)||void 0===n?void 0:n.querySelectorAll("[data-stop]")[e];return!!(null==t?void 0:t.getClientRects().length)&&(t.focus({preventScroll:!0}),document.activeElement===t)};t.useLayoutEffect(()=>{null!==D.current&&(R(D.current),D.current=null)});const A=e=>{JSON.stringify(e.stops)!==JSON.stringify(E.current)&&(D.current=e.index,v(e))},z=e=>{p(g)&&A({stops:g.filter((n,t)=>t!==e),index:Math.max(0,e-1)})};t.useImperativeHandle(j,()=>({remove:z,focus:R}));const B=e=>{const n=k.current.getBoundingClientRect();return(e-n.left)/(n.width||1)},C=()=>[c.activePage,...c.selectedElements].map(e=>null==e?void 0:e.id).join();return n("div",{ref:k,role:"group","aria-label":f,className:"pn:relative pn:h-7 pn:cursor-copy pn:touch-none",onPointerDown:e=>{if(!s(e)){return}S.begin();const n=e.target.closest("[data-stop]");let t={stops:g,index:Number(null==n?void 0:n.dataset.stop)};n?(b(t.index),n.focus({preventScroll:!0})):(t=h(g,B(e.clientX)),A(t));const r=C();N(e,{node:d,slopX:o,onMove:e=>{S.active()&&(0!==e.buttons&&C()===r?A(l(t.stops,t.index,B(e.clientX))):S.end())},onEnd:S.end})},children:[e("div",{className:"pn:absolute pn:inset-x-0 pn:top-1.5 pn:h-4 pn:overflow-hidden pn:rounded-sm pn:ring-1 pn:ring-inset pn:ring-black/15 pn:dark:ring-white/15",children:y}),g.map((n,t)=>e("button",{type:"button","data-stop":t,"aria-label":x(n,t),"aria-pressed":t===m,onKeyDown:e=>((e,n)=>{const{key:t}=e;if(!(t in u)&&!["Home","End","Delete","Backspace"].includes(t)){return}if(e.preventDefault(),e.stopPropagation(),"Delete"===t||"Backspace"===t){return void z(n)}const r="Home"===t?0:"End"===t?1:g[n].offset+u[t]*(e.shiftKey?.1:.01);A(l(g,n,r))})(e,t),onFocus:()=>b(t),className:r("pn:group pn:absolute pn:top-0 pn:size-7 pn:-translate-x-1/2 pn:cursor-grab pn:rounded-md pn:outline-none",t===m&&"pn:z-10"),style:{left:100*n.offset+"%"},children:e("span",{className:r("pn:mx-auto pn:block pn:size-4 pn:rounded-full pn:border-2 pn:border-white pn:shadow-[0_1px_3px_rgba(0,0,0,0.4)] pn:group-focus-visible:ring-2 pn:group-focus-visible:ring-ring pn:group-focus-visible:ring-offset-2",t===m&&"pn:ring-2 pn:ring-primary"),style:{background:w(n)}})},t))]})}
@@ -1 +1 @@
1
- import{Fragment as e,jsx as t,jsxs as n}from"react/jsx-runtime";import o from"react";import{observer as l}from"mobx-react-lite";import{PolotnoIcon as r}from"../icons/registry.js";import{Button as i}from"../primitives/button.js";import{SliderField as s}from"../primitives/slider-field.js";import{Popover as a,PopoverContent as c,PopoverTrigger as d}from"../primitives/popover.js";import{Tooltip as p,TooltipContent as m,TooltipTrigger as b}from"../primitives/tooltip.js";import{cn as h}from"../lib/utils.js";import{ColorPicker as u}from"./color-picker.js";import{NumberInput as y}from"./filters-picker.js";import{ElementContainer as x,extendToolbar as g}from"./element-container.js";import{cycleNext as f,StrokeWidthIcon as v}from"./toolbar-shared.js";import{VERTICAL_ALIGN_OPTIONS as C,VERTICAL_ALIGN_ICONS as k}from"./text-toolbar.js";import{PROPS_MAP as w}from"./html-toolbar.js";import{AnimationsPicker as j}from"./animations-picker.js";import{flags as O}from"../utils/flags.js";import{t as T}from"../utils/l10n.js";const B={stroke:"currentColor",strokeWidth:1,strokeOpacity:.25},N={stroke:"currentColor",strokeWidth:2},S=()=>n(e,{children:[t("rect",Object.assign({x:"2",y:"2",width:"16",height:"16",fill:"none"},B)),t("line",Object.assign({x1:"10",y1:"2",x2:"10",y2:"18"},B)),t("line",Object.assign({x1:"2",y1:"10",x2:"18",y2:"10"},B))]}),z=({children:e})=>n("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",children:[t(S,{}),e]}),F=[{key:"all",labelKey:"toolbar.borderModeAll",icon:()=>n("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",children:[t("rect",Object.assign({x:"2",y:"2",width:"16",height:"16",fill:"none"},N)),t("line",Object.assign({x1:"10",y1:"2",x2:"10",y2:"18"},N)),t("line",Object.assign({x1:"2",y1:"10",x2:"18",y2:"10"},N))]})},{key:"outer",labelKey:"toolbar.borderModeOuter",icon:()=>t(z,{children:t("rect",Object.assign({x:"2",y:"2",width:"16",height:"16",fill:"none"},N))})},{key:"inner",labelKey:"toolbar.borderModeInner",icon:()=>n(z,{children:[t("line",Object.assign({x1:"10",y1:"2",x2:"10",y2:"18"},N)),t("line",Object.assign({x1:"2",y1:"10",x2:"18",y2:"10"},N))]})},{key:"topOnly",labelKey:"toolbar.borderModeTopOnly",icon:()=>t(z,{children:t("line",Object.assign({x1:"2",y1:"2",x2:"18",y2:"2"},N))})},{key:"innerHorizontal",labelKey:"toolbar.borderModeInnerHorizontal",icon:()=>t(z,{children:t("line",Object.assign({x1:"2",y1:"10",x2:"18",y2:"10"},N))})},{key:"bottomOnly",labelKey:"toolbar.borderModeBottomOnly",icon:()=>t(z,{children:t("line",Object.assign({x1:"2",y1:"18",x2:"18",y2:"18"},N))})},{key:"leftOnly",labelKey:"toolbar.borderModeLeftOnly",icon:()=>t(z,{children:t("line",Object.assign({x1:"2",y1:"2",x2:"2",y2:"18"},N))})},{key:"innerVertical",labelKey:"toolbar.borderModeInnerVertical",icon:()=>t(z,{children:t("line",Object.assign({x1:"10",y1:"2",x2:"10",y2:"18"},N))})},{key:"rightOnly",labelKey:"toolbar.borderModeRightOnly",icon:()=>t(z,{children:t("line",Object.assign({x1:"18",y1:"2",x2:"18",y2:"18"},N))})}];export const TableBorderSettings=l(({elements:e,store:l})=>{const y=e[0],x="tablecell"===y.type,g=x?l.selectedElements[0]:y,[f,C]=o.useState("all");let k,w;if(x){const e=g.getFocusedCellRange();k=e?e.maxRow-e.minRow+1:1,w=e?e.maxCol-e.minCol+1:1}else{k=g.rows,w=g.cols}const j=k>1,O=w>1,B=e=>"innerHorizontal"===e?!j:("innerVertical"===e||"inner"===e&&!j)&&!O;o.useEffect(()=>{B(f)&&C("all")},[f,j,O]);const N={all:"top",outer:"top",topOnly:"top",topBottom:"top",bottomOnly:"bottom",innerHorizontal:"bottom",inner:"bottom",leftOnly:"left",rightOnly:"right",innerVertical:"right"}[f],S=x?y:"bottomOnly"===f?g.getCell(g.rows-1,0):"rightOnly"===f?g.getCell(0,g.cols-1):g.getCell(0,0),z=(null==S?void 0:S.getEffectiveBorder)?S.getEffectiveBorder(N):{color:g.borderColor,width:g.borderWidth,style:g.borderStyle},E=z.color,R=z.width,A=z.style,M=(t,n={})=>{var o,r;const i=R<=0||"none"===A,s=null!==(o=n.style)&&void 0!==o?o:i?"solid":A,a=void 0!==n.width?n.width:i?1:R,c={color:null!==(r=n.color)&&void 0!==r?r:E,width:a,style:s};l.history.transaction(()=>{g.applyBorderMode(t,c),"all"!==t||x||e.forEach(e=>e.set({borderColor:c.color,borderWidth:c.width,borderStyle:c.style}))})},W=e=>{M(f,{style:e})};return n(a,{children:[n(p,{children:[t(b,{render:t(d,{render:t(i,{variant:"ghost",size:"icon-sm","aria-label":T("toolbar.tableBorderSettings"),children:t(v,{})})})}),t(m,{children:T("toolbar.tableBorderSettings")})]}),t(c,{className:"pn:w-auto pn:p-3",align:"start",children:n("div",{className:"pn:flex pn:gap-3",children:[t("div",{className:"pn:grid pn:grid-cols-[repeat(3,32px)] pn:auto-rows-[32px] pn:gap-1",children:F.map(({key:e,labelKey:o,icon:l})=>{const r=B(e);return n(p,{children:[t(b,{render:t(i,{variant:"outline",size:"sm",disabled:r,className:h("pn:size-8 pn:p-0",!r&&f===e&&"pn:bg-muted"),onClick:()=>{C(e)},"aria-label":T(o),children:t(l,{})})}),t(m,{children:T(o)})]},e)})}),t("div",{className:"pn:w-px pn:bg-border"}),n("div",{className:"pn:flex pn:w-[170px] pn:flex-col pn:gap-2",children:[n("div",{className:"pn:flex pn:items-center pn:justify-between",children:[t("span",{className:"pn:text-xs",children:T("toolbar.tableBorderColor")}),t(u,{value:E,onChange:e=>{M(f,{color:e})},store:l})]}),t(s,{label:T("toolbar.tableBorderWidth"),value:R,onChange:e=>{M(f,{width:e})},min:0,max:20}),n("div",{className:"pn:flex pn:justify-between pn:gap-1",children:[t(i,{variant:"outline",size:"sm",onClick:()=>W("none"),className:h("pn:flex-1","none"===A&&"pn:bg-muted"),children:t(r,{name:"action.none",className:"pn:size-4"})}),t(i,{variant:"outline",size:"sm",onClick:()=>W("solid"),className:h("pn:flex-1","solid"===A&&"pn:bg-muted"),children:t("svg",{width:"20",height:"14",viewBox:"0 0 20 14",children:t("line",{x2:"20",y1:"7",y2:"7",stroke:"currentColor",strokeWidth:"2"})})}),t(i,{variant:"outline",size:"sm",onClick:()=>W("dashed"),className:h("pn:flex-1","dashed"===A&&"pn:bg-muted"),children:t("svg",{width:"20",height:"14",viewBox:"0 0 20 14",children:t("line",{x2:"20",y1:"7",y2:"7",stroke:"currentColor",strokeDasharray:"4 2",strokeWidth:"2"})})}),t(i,{variant:"outline",size:"sm",onClick:()=>W("dotted"),className:h("pn:flex-1","dotted"===A&&"pn:bg-muted"),children:t("svg",{width:"20",height:"14",viewBox:"0 0 20 14",children:t("line",{x2:"20",y1:"7",y2:"7",stroke:"currentColor",strokeDasharray:"2 2",strokeWidth:"2"})})})]})]})]})})]})});const E=()=>n("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:[t("rect",{x:"1",y:"1",width:"14",height:"14",rx:"1",stroke:"currentColor",strokeWidth:"1.5",fill:"none"}),t("line",{x1:"5.5",y1:"1",x2:"5.5",y2:"15",stroke:"currentColor",strokeWidth:"1"}),t("line",{x1:"10.5",y1:"1",x2:"10.5",y2:"15",stroke:"currentColor",strokeWidth:"1"}),t("line",{x1:"1",y1:"5.5",x2:"15",y2:"5.5",stroke:"currentColor",strokeWidth:"1"}),t("line",{x1:"1",y1:"10.5",x2:"15",y2:"10.5",stroke:"currentColor",strokeWidth:"1"})]});export const TableStructureMenu=l(({element:o,store:l})=>{const r=o.focusedCells[0],i=null==r?void 0:r.row,s=null==r?void 0:r.col;return n("div",{className:"pn:p-1",children:[null!=r&&n(e,{children:[t("div",{className:"pn:px-2 pn:py-1 pn:text-xs pn:font-semibold pn:text-muted-foreground",children:T("toolbar.tableRows")}),t("button",{type:"button",className:"pn:flex pn:w-full pn:items-center pn:rounded-sm pn:px-2 pn:py-1.5 pn:text-sm pn:hover:bg-muted",onClick:()=>{l.history.transaction(()=>{o.addRow(i)})},children:T("toolbar.insertRowAbove")}),t("button",{type:"button",className:"pn:flex pn:w-full pn:items-center pn:rounded-sm pn:px-2 pn:py-1.5 pn:text-sm pn:hover:bg-muted",onClick:()=>{l.history.transaction(()=>{o.addRow(i+1)})},children:T("toolbar.insertRowBelow")}),t("button",{type:"button",disabled:o.rows<=1,className:h("pn:flex pn:w-full pn:items-center pn:rounded-sm pn:px-2 pn:py-1.5 pn:text-sm pn:hover:bg-muted",o.rows<=1&&"pn:pointer-events-none pn:opacity-50"),onClick:()=>{l.history.transaction(()=>{o.removeRow(i)})},children:T("toolbar.deleteRow")}),t("div",{className:"pn:my-1 pn:border-t pn:border-border"}),t("div",{className:"pn:px-2 pn:py-1 pn:text-xs pn:font-semibold pn:text-muted-foreground",children:T("toolbar.tableColumns")}),t("button",{type:"button",className:"pn:flex pn:w-full pn:items-center pn:rounded-sm pn:px-2 pn:py-1.5 pn:text-sm pn:hover:bg-muted",onClick:()=>{l.history.transaction(()=>{o.addColumn(s)})},children:T("toolbar.insertColumnLeft")}),t("button",{type:"button",className:"pn:flex pn:w-full pn:items-center pn:rounded-sm pn:px-2 pn:py-1.5 pn:text-sm pn:hover:bg-muted",onClick:()=>{l.history.transaction(()=>{o.addColumn(s+1)})},children:T("toolbar.insertColumnRight")}),t("button",{type:"button",disabled:o.cols<=1,className:h("pn:flex pn:w-full pn:items-center pn:rounded-sm pn:px-2 pn:py-1.5 pn:text-sm pn:hover:bg-muted",o.cols<=1&&"pn:pointer-events-none pn:opacity-50"),onClick:()=>{l.history.transaction(()=>{o.removeColumn(s)})},children:T("toolbar.deleteColumn")}),t("div",{className:"pn:my-1 pn:border-t pn:border-border"})]}),t("button",{type:"button",className:"pn:flex pn:w-full pn:items-center pn:rounded-sm pn:px-2 pn:py-1.5 pn:text-sm pn:hover:bg-muted",onClick:()=>{l.history.transaction(()=>{o.distributeRowsEvenly()})},children:T("toolbar.distributeRowsEvenly")}),t("button",{type:"button",className:"pn:flex pn:w-full pn:items-center pn:rounded-sm pn:px-2 pn:py-1.5 pn:text-sm pn:hover:bg-muted",onClick:()=>{l.history.transaction(()=>{o.distributeColumnsEvenly()})},children:T("toolbar.distributeColumnsEvenly")})]})});export const TableStructure=l(({elements:e,store:o})=>{const l=e[0];return n(a,{children:[n(p,{children:[t(b,{render:t(d,{render:t(i,{variant:"ghost",size:"icon-sm","aria-label":T("toolbar.tableStructure"),children:t(E,{})})})}),t(m,{children:T("toolbar.tableStructure")})]}),t(c,{className:"pn:w-auto pn:p-0",align:"start",children:t(TableStructureMenu,{element:l,store:o})})]})});export const CellPadding=l(({elements:e,store:o})=>n(p,{children:[t(b,{render:t(y,{value:e[0].cellPadding,onValueChange:t=>o.history.transaction(()=>{e.forEach(e=>e.set({cellPadding:t}))}),style:{width:"64px"},min:0,max:50})}),t(m,{children:T("toolbar.cellPadding")})]}));export const CellBackground=l(({elements:e,store:o})=>n(p,{children:[t(b,{render:t(u,{value:e[0].cellBackground,onChange:t=>o.history.transaction(()=>{e.forEach(e=>e.set({cellBackground:t}))}),store:o})}),t(m,{children:T("toolbar.cellBackground")})]}));export const CellVerticalAlign=l(({elements:e,store:o})=>{const l=e[0];return n(p,{children:[t(b,{render:t(i,{variant:"ghost",size:"icon-sm",onClick:()=>{const t=f(C,l.verticalAlign);o.history.transaction(()=>{e.forEach(e=>e.set({verticalAlign:t}))})},"aria-label":T("toolbar.verticalAlign"),children:k[l.verticalAlign]})}),t(m,{children:T("toolbar.verticalAlign")})]})});const R={TableStructure,TableAnimations:j},{TextFontFamily:A,TextFontSize:M,TextFill:W,TextFontVariant:V,TextSpacing:K}=w,P={TextFontFamily:A,TextFontSize:M,TextFill:W,TextFontVariant:V,TextSpacing:K},H=Object.assign({TableBorderSettings,CellBackground,CellVerticalAlign},P),I=Object.assign(Object.assign({},R),H);export const TableToolbar=l(({store:e,components:n})=>{const o=e.selectedElements[0],l=o.focusedCells,r=l.length>0,i=o.textCells,s=["TableBorderSettings","CellBackground","TableStructure",...r?["TextFontFamily","TextFontSize","TextFill","TextFontVariant","CellVerticalAlign","TextSpacing"]:[],O.animationsEnabled&&"TableAnimations"],a=g({type:"table",usedItems:s,components:n});return t(x,{items:a,itemRender:s=>{const a=(null==n?void 0:n[s])||I[s],c=!!H[s],d=!(null==n?void 0:n[s])&&!!P[s];if(c&&!r&&"TableBorderSettings"!==s&&"CellBackground"!==s){return null}if(d&&0===i.length){return null}let p;return p=c?d?i:r?l:"TableBorderSettings"===s?e.selectedElements:o.cells.slice():e.selectedElements,t(a,{element:d?i[0]:o,store:e,elements:p},s)}})});export default TableToolbar;
1
+ import{Fragment as e,jsx as t,jsxs as n}from"react/jsx-runtime";import o from"react";import{observer as r}from"mobx-react-lite";import{PolotnoIcon as l}from"../icons/registry.js";import{Button as i}from"../primitives/button.js";import{SliderField as s}from"../primitives/slider-field.js";import{Popover as a,PopoverContent as c,PopoverTrigger as d}from"../primitives/popover.js";import{Tooltip as p,TooltipContent as m,TooltipTrigger as b}from"../primitives/tooltip.js";import{cn as h}from"../lib/utils.js";import{ColorPicker as u}from"./color-picker.js";import{ElementContainer as y,extendToolbar as x}from"./element-container.js";import{cycleNext as g,StrokeWidthIcon as f}from"./toolbar-shared.js";import{CELL_PADDING_FIELDS as v,PaddingControl as C,cellPaddingSides as k,paddingAttrs as w}from"./padding-control.js";import{VERTICAL_ALIGN_OPTIONS as j,VERTICAL_ALIGN_ICONS as O}from"./text-toolbar.js";import{PROPS_MAP as T}from"./html-toolbar.js";import{AnimationsPicker as B}from"./animations-picker.js";import{flags as N}from"../utils/flags.js";import{t as S}from"../utils/l10n.js";const z={stroke:"currentColor",strokeWidth:1,strokeOpacity:.25},F={stroke:"currentColor",strokeWidth:2},E=()=>n(e,{children:[t("rect",Object.assign({x:"2",y:"2",width:"16",height:"16",fill:"none"},z)),t("line",Object.assign({x1:"10",y1:"2",x2:"10",y2:"18"},z)),t("line",Object.assign({x1:"2",y1:"10",x2:"18",y2:"10"},z))]}),R=({children:e})=>n("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",children:[t(E,{}),e]}),A=[{key:"all",labelKey:"toolbar.borderModeAll",icon:()=>n("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",children:[t("rect",Object.assign({x:"2",y:"2",width:"16",height:"16",fill:"none"},F)),t("line",Object.assign({x1:"10",y1:"2",x2:"10",y2:"18"},F)),t("line",Object.assign({x1:"2",y1:"10",x2:"18",y2:"10"},F))]})},{key:"outer",labelKey:"toolbar.borderModeOuter",icon:()=>t(R,{children:t("rect",Object.assign({x:"2",y:"2",width:"16",height:"16",fill:"none"},F))})},{key:"inner",labelKey:"toolbar.borderModeInner",icon:()=>n(R,{children:[t("line",Object.assign({x1:"10",y1:"2",x2:"10",y2:"18"},F)),t("line",Object.assign({x1:"2",y1:"10",x2:"18",y2:"10"},F))]})},{key:"topOnly",labelKey:"toolbar.borderModeTopOnly",icon:()=>t(R,{children:t("line",Object.assign({x1:"2",y1:"2",x2:"18",y2:"2"},F))})},{key:"innerHorizontal",labelKey:"toolbar.borderModeInnerHorizontal",icon:()=>t(R,{children:t("line",Object.assign({x1:"2",y1:"10",x2:"18",y2:"10"},F))})},{key:"bottomOnly",labelKey:"toolbar.borderModeBottomOnly",icon:()=>t(R,{children:t("line",Object.assign({x1:"2",y1:"18",x2:"18",y2:"18"},F))})},{key:"leftOnly",labelKey:"toolbar.borderModeLeftOnly",icon:()=>t(R,{children:t("line",Object.assign({x1:"2",y1:"2",x2:"2",y2:"18"},F))})},{key:"innerVertical",labelKey:"toolbar.borderModeInnerVertical",icon:()=>t(R,{children:t("line",Object.assign({x1:"10",y1:"2",x2:"10",y2:"18"},F))})},{key:"rightOnly",labelKey:"toolbar.borderModeRightOnly",icon:()=>t(R,{children:t("line",Object.assign({x1:"18",y1:"2",x2:"18",y2:"18"},F))})}];export const TableBorderSettings=r(({elements:e,store:r})=>{const y=e[0],x="tablecell"===y.type,g=x?r.selectedElements[0]:y,[v,C]=o.useState("all");let k,w;if(x){const e=g.getFocusedCellRange();k=e?e.maxRow-e.minRow+1:1,w=e?e.maxCol-e.minCol+1:1}else{k=g.rows,w=g.cols}const j=k>1,O=w>1,T=e=>"innerHorizontal"===e?!j:("innerVertical"===e||"inner"===e&&!j)&&!O;o.useEffect(()=>{T(v)&&C("all")},[v,j,O]);const B={all:"top",outer:"top",topOnly:"top",topBottom:"top",bottomOnly:"bottom",innerHorizontal:"bottom",inner:"bottom",leftOnly:"left",rightOnly:"right",innerVertical:"right"}[v],N=x?y:"bottomOnly"===v?g.getCell(g.rows-1,0):"rightOnly"===v?g.getCell(0,g.cols-1):g.getCell(0,0),z=(null==N?void 0:N.getEffectiveBorder)?N.getEffectiveBorder(B):{color:g.borderColor,width:g.borderWidth,style:g.borderStyle},F=z.color,E=z.width,R=z.style,M=(t,n={})=>{var o,l;const i=E<=0||"none"===R,s=null!==(o=n.style)&&void 0!==o?o:i?"solid":R,a=void 0!==n.width?n.width:i?1:E,c={color:null!==(l=n.color)&&void 0!==l?l:F,width:a,style:s};r.history.transaction(()=>{g.applyBorderMode(t,c),"all"!==t||x||e.forEach(e=>e.set({borderColor:c.color,borderWidth:c.width,borderStyle:c.style}))})},W=e=>{M(v,{style:e})};return n(a,{children:[n(p,{children:[t(b,{render:t(d,{render:t(i,{variant:"ghost",size:"icon-sm","aria-label":S("toolbar.tableBorderSettings"),children:t(f,{})})})}),t(m,{children:S("toolbar.tableBorderSettings")})]}),t(c,{className:"pn:w-auto pn:p-3",align:"start",children:n("div",{className:"pn:flex pn:gap-3",children:[t("div",{className:"pn:grid pn:grid-cols-[repeat(3,32px)] pn:auto-rows-[32px] pn:gap-1",children:A.map(({key:e,labelKey:o,icon:r})=>{const l=T(e);return n(p,{children:[t(b,{render:t(i,{variant:"outline",size:"sm",disabled:l,className:h("pn:size-8 pn:p-0",!l&&v===e&&"pn:bg-muted"),onClick:()=>{C(e)},"aria-label":S(o),children:t(r,{})})}),t(m,{children:S(o)})]},e)})}),t("div",{className:"pn:w-px pn:bg-border"}),n("div",{className:"pn:flex pn:w-[170px] pn:flex-col pn:gap-2",children:[n("div",{className:"pn:flex pn:items-center pn:justify-between",children:[t("span",{className:"pn:text-xs",children:S("toolbar.tableBorderColor")}),t(u,{value:F,onChange:e=>{M(v,{color:e})},store:r})]}),t(s,{label:S("toolbar.tableBorderWidth"),value:E,onChange:e=>{M(v,{width:e})},min:0,max:20}),n("div",{className:"pn:flex pn:justify-between pn:gap-1",children:[t(i,{variant:"outline",size:"sm",onClick:()=>W("none"),className:h("pn:flex-1","none"===R&&"pn:bg-muted"),children:t(l,{name:"action.none",className:"pn:size-4"})}),t(i,{variant:"outline",size:"sm",onClick:()=>W("solid"),className:h("pn:flex-1","solid"===R&&"pn:bg-muted"),children:t("svg",{width:"20",height:"14",viewBox:"0 0 20 14",children:t("line",{x2:"20",y1:"7",y2:"7",stroke:"currentColor",strokeWidth:"2"})})}),t(i,{variant:"outline",size:"sm",onClick:()=>W("dashed"),className:h("pn:flex-1","dashed"===R&&"pn:bg-muted"),children:t("svg",{width:"20",height:"14",viewBox:"0 0 20 14",children:t("line",{x2:"20",y1:"7",y2:"7",stroke:"currentColor",strokeDasharray:"4 2",strokeWidth:"2"})})}),t(i,{variant:"outline",size:"sm",onClick:()=>W("dotted"),className:h("pn:flex-1","dotted"===R&&"pn:bg-muted"),children:t("svg",{width:"20",height:"14",viewBox:"0 0 20 14",children:t("line",{x2:"20",y1:"7",y2:"7",stroke:"currentColor",strokeDasharray:"2 2",strokeWidth:"2"})})})]})]})]})})]})});const M=()=>n("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:[t("rect",{x:"1",y:"1",width:"14",height:"14",rx:"1",stroke:"currentColor",strokeWidth:"1.5",fill:"none"}),t("line",{x1:"5.5",y1:"1",x2:"5.5",y2:"15",stroke:"currentColor",strokeWidth:"1"}),t("line",{x1:"10.5",y1:"1",x2:"10.5",y2:"15",stroke:"currentColor",strokeWidth:"1"}),t("line",{x1:"1",y1:"5.5",x2:"15",y2:"5.5",stroke:"currentColor",strokeWidth:"1"}),t("line",{x1:"1",y1:"10.5",x2:"15",y2:"10.5",stroke:"currentColor",strokeWidth:"1"})]});export const TableStructureMenu=r(({element:o,store:r})=>{const l=o.focusedCells[0],i=null==l?void 0:l.row,s=null==l?void 0:l.col;return n("div",{className:"pn:p-1",children:[null!=l&&n(e,{children:[t("div",{className:"pn:px-2 pn:py-1 pn:text-xs pn:font-semibold pn:text-muted-foreground",children:S("toolbar.tableRows")}),t("button",{type:"button",className:"pn:flex pn:w-full pn:items-center pn:rounded-sm pn:px-2 pn:py-1.5 pn:text-sm pn:hover:bg-muted",onClick:()=>{r.history.transaction(()=>{o.addRow(i)})},children:S("toolbar.insertRowAbove")}),t("button",{type:"button",className:"pn:flex pn:w-full pn:items-center pn:rounded-sm pn:px-2 pn:py-1.5 pn:text-sm pn:hover:bg-muted",onClick:()=>{r.history.transaction(()=>{o.addRow(i+1)})},children:S("toolbar.insertRowBelow")}),t("button",{type:"button",disabled:o.rows<=1,className:h("pn:flex pn:w-full pn:items-center pn:rounded-sm pn:px-2 pn:py-1.5 pn:text-sm pn:hover:bg-muted",o.rows<=1&&"pn:pointer-events-none pn:opacity-50"),onClick:()=>{r.history.transaction(()=>{o.removeRow(i)})},children:S("toolbar.deleteRow")}),t("div",{className:"pn:my-1 pn:border-t pn:border-border"}),t("div",{className:"pn:px-2 pn:py-1 pn:text-xs pn:font-semibold pn:text-muted-foreground",children:S("toolbar.tableColumns")}),t("button",{type:"button",className:"pn:flex pn:w-full pn:items-center pn:rounded-sm pn:px-2 pn:py-1.5 pn:text-sm pn:hover:bg-muted",onClick:()=>{r.history.transaction(()=>{o.addColumn(s)})},children:S("toolbar.insertColumnLeft")}),t("button",{type:"button",className:"pn:flex pn:w-full pn:items-center pn:rounded-sm pn:px-2 pn:py-1.5 pn:text-sm pn:hover:bg-muted",onClick:()=>{r.history.transaction(()=>{o.addColumn(s+1)})},children:S("toolbar.insertColumnRight")}),t("button",{type:"button",disabled:o.cols<=1,className:h("pn:flex pn:w-full pn:items-center pn:rounded-sm pn:px-2 pn:py-1.5 pn:text-sm pn:hover:bg-muted",o.cols<=1&&"pn:pointer-events-none pn:opacity-50"),onClick:()=>{r.history.transaction(()=>{o.removeColumn(s)})},children:S("toolbar.deleteColumn")}),t("div",{className:"pn:my-1 pn:border-t pn:border-border"})]}),t("button",{type:"button",className:"pn:flex pn:w-full pn:items-center pn:rounded-sm pn:px-2 pn:py-1.5 pn:text-sm pn:hover:bg-muted",onClick:()=>{r.history.transaction(()=>{o.distributeRowsEvenly()})},children:S("toolbar.distributeRowsEvenly")}),t("button",{type:"button",className:"pn:flex pn:w-full pn:items-center pn:rounded-sm pn:px-2 pn:py-1.5 pn:text-sm pn:hover:bg-muted",onClick:()=>{r.history.transaction(()=>{o.distributeColumnsEvenly()})},children:S("toolbar.distributeColumnsEvenly")})]})});export const TableStructure=r(({elements:e,store:o})=>{const r=e[0];return n(a,{children:[n(p,{children:[t(b,{render:t(d,{render:t(i,{variant:"ghost",size:"icon-sm","aria-label":S("toolbar.tableStructure"),children:t(M,{})})})}),t(m,{children:S("toolbar.tableStructure")})]}),t(c,{className:"pn:w-auto pn:p-0",align:"start",children:t(TableStructureMenu,{element:r,store:o})})]})});export const CellPadding=r(({elements:e,store:o})=>{const r=e[0],s=S("toolbar.cellPadding");return n(a,{children:[n(p,{children:[t(b,{render:t(d,{render:t(i,{variant:"ghost",size:"icon-sm","aria-label":s,children:t(l,{name:"toolbar.paddingSides",className:"pn:size-5"})})})}),t(m,{children:s})]}),t(c,{align:"start",className:"pn:w-[260px] pn:p-[15px]",children:t(C,{label:s,value:k(r),onChange:t=>o.history.transaction(()=>{const n=w(t,v);e.forEach(e=>e.set(n))})})})]})});export const CellBackground=r(({elements:e,store:o})=>n(p,{children:[t(b,{render:t(u,{value:e[0].cellBackground,onChange:t=>o.history.transaction(()=>{e.forEach(e=>e.set({cellBackground:t}))}),store:o})}),t(m,{children:S("toolbar.cellBackground")})]}));export const CellVerticalAlign=r(({elements:e,store:o})=>{const r=e[0];return n(p,{children:[t(b,{render:t(i,{variant:"ghost",size:"icon-sm",onClick:()=>{const t=g(j,r.verticalAlign);o.history.transaction(()=>{e.forEach(e=>e.set({verticalAlign:t}))})},"aria-label":S("toolbar.verticalAlign"),children:O[r.verticalAlign]})}),t(m,{children:S("toolbar.verticalAlign")})]})});const W={TableStructure,TableAnimations:B},{TextFontFamily:V,TextFontSize:K,TextFill:P,TextFontVariant:H,TextSpacing:I}=T,D={TextFontFamily:V,TextFontSize:K,TextFill:P,TextFontVariant:H,TextSpacing:I},L=Object.assign({TableBorderSettings,CellBackground,CellVerticalAlign},D),_=Object.assign(Object.assign({},W),L);export const TableToolbar=r(({store:e,components:n})=>{const o=e.selectedElements[0],r=o.focusedCells,l=r.length>0,i=o.textCells,s=["TableBorderSettings","CellBackground","TableStructure",...l?["TextFontFamily","TextFontSize","TextFill","TextFontVariant","CellVerticalAlign","TextSpacing"]:[],N.animationsEnabled&&"TableAnimations"],a=x({type:"table",usedItems:s,components:n});return t(y,{items:a,itemRender:s=>{const a=(null==n?void 0:n[s])||_[s],c=!!L[s],d=!(null==n?void 0:n[s])&&!!D[s];if(c&&!l&&"TableBorderSettings"!==s&&"CellBackground"!==s){return null}if(d&&0===i.length){return null}let p;return p=c?d?i:l?r:"TableBorderSettings"===s?e.selectedElements:o.cells.slice():e.selectedElements,t(a,{element:d?i[0]:o,store:e,elements:p},s)}})});export default TableToolbar;
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  export { NumberInput } from '../primitives/numeric-input.js';
3
3
  import type { StoreType, TextElementType } from '../ui-types.js';
4
+ import type { TableCellType } from '../model/table-model.js';
4
5
  type PageProps = {
5
6
  store: StoreType;
6
7
  components?: any;
@@ -39,8 +40,12 @@ export declare const TextTransform: (({ elements, store }: InputProps) => React.
39
40
  export declare const TextFill: (({ elements, store }: InputProps) => React.JSX.Element) & React.NamedExoticComponent<InputProps> & {
40
41
  readonly type: ({ elements, store }: InputProps) => React.JSX.Element;
41
42
  };
42
- export declare const TextSpacing: (({ elements, store }: InputProps) => React.JSX.Element) & React.NamedExoticComponent<InputProps> & {
43
- readonly type: ({ elements, store }: InputProps) => React.JSX.Element;
43
+ type SpacingProps = {
44
+ elements: Array<TextElementType | TableCellType>;
45
+ store: StoreType;
46
+ };
47
+ export declare const TextSpacing: (({ elements, store }: SpacingProps) => React.JSX.Element) & React.NamedExoticComponent<SpacingProps> & {
48
+ readonly type: ({ elements, store }: SpacingProps) => React.JSX.Element;
44
49
  };
45
50
  export declare const TextFilters: (({ element, store }: {
46
51
  element: import("../ui-types.js").ShapeType;
@@ -1 +1 @@
1
- import{jsx as e,jsxs as t}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 l,globalFonts as s,isGoogleFontChanged as c}from"../utils/fonts.js";import{getGoogleFontImage as p,getGoogleFontsListAPI as m}from"../utils/api.js";import{t as f}from"../utils/l10n.js";import{flags as d}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 y}from"../primitives/popover.js";import{Tooltip as F,TooltipContent as T,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 j}from"../lib/utils.js";import{cycleNext as w,usedFontFamilies as z}from"./toolbar-shared.js";import{isBoldWeight as E}from"@polotno/core/rich-text-html";import{cssFontFamily as D}from"@polotno/core/fonts";import{ColorPicker as A}from"./color-picker.js";import k from"./filters-picker.js";import{AnimationsPicker as O}from"./animations-picker.js";import{renderToolbarItems as I}from"./element-container.js";import{TextAiWrite as M}from"./text-ai-write.js";import{unboundWrite as L}from"../model/node-model.js";const V=l(),_=({fontFamily:t,handleClick:o,modifiers:i,store:r,isCustom:a})=>{const[l,s]=n.useState(!a);if(n.useEffect(()=>{l||r.loadFont(t)},[t,l]),"_divider"===t){return e("div",{style:{paddingTop:"10px"},children:e(C,{})})}const c=l?e("img",{src:p(t),alt:t,onError:()=>{s(!1)},className:"pn:h-5 pn:dark:invert"}):t;return e("button",{type:"button",onClick:o,disabled:i.disabled,"data-active":i.active||void 0,className:j("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:D(t)},children:c})},P=({index:t,style:n,filteredFonts:o,activeFont:i,onFontSelect:r,store:a})=>{const l=o[t];return e("div",{style:n,children:e(_,{fontFamily:l,modifiers:{active:i===l},handleClick:()=>r(l),store:a,isCustom:a.fonts.find(e=>e.fontFamily===l)||s.find(e=>e.fontFamily===l)},l)})},R=({onChange:o,defaultValue:i})=>{const r=n.useRef(null);return n.useEffect(()=>{r.current&&r.current.focus()},[]),t(x,{children:[e("span",{className:"pn:flex pn:items-center pn:pl-2 pn:pr-1 pn:text-muted-foreground",children:e(a,{name:"action.search",className:"pn:size-3.5 pn:shrink-0 pn:opacity-50"})}),e("input",{ref:r,"data-slot":"input-group-control",defaultValue:i,onChange:e=>o(e.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:l,activeFontLabel:s,onFontSelect:c,mixed:p,mixedFonts:m,open:d,onOpenChange:u})=>{const[x,g]=n.useState(""),S=r.filter(e=>(null==e?void 0:e.toLowerCase().indexOf(x.toLowerCase()))>=0);return t(v,{open:d,onOpenChange:u,children:[t(F,{children:[e(N,{render:e(y,{render:t(h,{variant:"ghost",size:"sm",className:"pn:gap-1 pn:overflow-hidden pn:whitespace-nowrap",style:{fontFamily:p?void 0:D(l),fontStyle:p?"italic":void 0,color:p?"#5c7080":void 0},"aria-label":f("toolbar.fontFamily"),children:[e("span",{className:"pn:truncate",children:p?f("toolbar.fontFamilyMixed"):s}),e(a,{name:"ui.chevronDown",className:"pn:size-3 pn:shrink-0 pn:opacity-50"})]})})}),e(T,{children:p&&m&&m.length>0?`${f("toolbar.fontsInSelection")}: ${m.join(", ")}`:f("toolbar.fontFamily")})]}),e(b,{className:"pn:w-[230px] pn:p-2",align:"start",children:t("div",{children:[e(R,{onChange:e=>g(e),defaultValue:x}),e("div",{style:{paddingTop:"5px"},children:e(i,{style:{height:Math.min(400,30*S.length)+10,width:210},rowCount:S.length,rowHeight:30,rowComponent:P,rowProps:{filteredFonts:S,activeFont:l,onFontSelect:c,store:o}})})]})})]})};const G={};export const fetcher=e=>G[e]?Promise.resolve(G[e]):fetch(e).then(e=>e.json()).then(t=>(G[e]=t,t));export const TextFontFamily=o(({elements:t,store:o})=>{const[i,a]=n.useState(!1),{data:l,mutate:p}=r(i?m():null,fetcher,{isPaused:()=>c(),fallbackData:[]});n.useEffect(()=>{p()},[c()]);const f=o.fonts.concat(s).map(e=>e.fontFamily).concat((null==l?void 0:l.length)&&!c()?l:V);let d=t[0].fontFamily;d.length>15&&(d=d.slice(0,15)+"...");const h=z(o),u=[...new Set(h.concat("_divider").concat(f))];return e(FontMenu,{fonts:u,activeFont:t[0].fontFamily,activeFontLabel:d,store:o,open:i,onOpenChange:a,onFontSelect:e=>{o.history.transaction(()=>{t.forEach(t=>{t.set({fontFamily:e})})})}})});export const TextFontSize=o(({elements:o,store:i})=>{const[r,a]=n.useState(!1),[l,s]=n.useState(!1);return t(F,{open:!l&&r,onOpenChange:e=>{l||a(e)},children:[e(N,{render:e(u,{"aria-label":f("toolbar.fontSize"),onFocus:()=>s(!0),onBlur:()=>s(!1),onValueChange:e=>{i.history.transaction(()=>{o.forEach(t=>{t.set({fontSize:e,width:Math.max(e,t.width)})})})},value:Math.round(100*o[0].fontSize)/100,style:{width:"50px"},min:5,max:4*i.height})}),e(T,{children:f("toolbar.fontSize")})]})});export const ALIGN_OPTIONS=["left","center","right","justify"];export const VERTICAL_ALIGN_OPTIONS=["top","middle","bottom"];export const VERTICAL_ALIGN_ICONS={top:e(a,{name:"text.valignTop",className:"pn:size-4"}),middle:e(a,{name:"text.valignMiddle",className:"pn:size-4"}),bottom:e(a,{name:"text.valignBottom",className:"pn:size-4"})};export const TextFontVariant=o(({elements:n,store:o})=>{const i=n[0],r=E(i.fontWeight),l="italic"===i.fontStyle,s=i.textDecoration.indexOf("underline")>=0,c=i.textDecoration.indexOf("line-through")>=0;return t("div",{className:"pn:flex pn:items-center pn:gap-0.5",children:[t(F,{children:[e(N,{render:e(h,{variant:"ghost",size:"icon-sm",onMouseDown:e=>{e.preventDefault()},onClick:()=>{const e=w(ALIGN_OPTIONS,i.align);o.history.transaction(()=>{n.forEach(t=>{t.set({align:e})})})},"aria-label":f("toolbar.textAlign"),children:"left"===i.align?e(a,{name:"text.alignLeft",className:"pn:size-4"}):"center"===i.align?e(a,{name:"text.alignCenter",className:"pn:size-4"}):"right"===i.align?e(a,{name:"text.alignRight",className:"pn:size-4"}):e(a,{name:"text.alignJustify",className:"pn:size-4"})})}),e(T,{children:f("toolbar.textAlign")})]}),d.textVerticalResizeEnabled&&t(F,{children:[e(N,{render:e(h,{variant:"ghost",size:"icon-sm",onMouseDown:e=>{e.preventDefault()},onClick:()=>{const e=w(VERTICAL_ALIGN_OPTIONS,i.verticalAlign);o.history.transaction(()=>{n.forEach(t=>{t.set({verticalAlign:e})})})},"aria-label":f("toolbar.verticalAlign"),children:VERTICAL_ALIGN_ICONS[i.verticalAlign]})}),e(T,{children:f("toolbar.verticalAlign")})]}),e(S,{label:f("toolbar.bold"),active:r,onMouseDown:e=>{e.preventDefault()},onClick:()=>{const e=E(i.fontWeight);o.history.transaction(()=>{n.forEach(t=>{t.set({fontWeight:e?"400":"700"})})})},children:e(a,{name:"text.bold",className:"pn:size-4"})}),e(S,{label:f("toolbar.italic"),active:l,onMouseDown:e=>{e.preventDefault()},onClick:()=>{const e="italic"===i.fontStyle;o.history.transaction(()=>{n.forEach(t=>{e?t.set({fontStyle:"normal"}):t.set({fontStyle:"italic"})})})},children:e(a,{name:"text.italic",className:"pn:size-4"})}),e(S,{label:f("toolbar.underline"),active:s,onMouseDown:e=>{e.preventDefault()},onClick:()=>{let e=i.textDecoration.split(" ");e.indexOf("underline")>=0?e=e.filter(e=>"underline"!==e):e.push("underline"),o.history.transaction(()=>{n.forEach(t=>{t.set({textDecoration:e.join(" ")})})})},children:e(a,{name:"text.underline",className:"pn:size-4"})}),e(S,{label:f("toolbar.strikethrough"),active:c,onMouseDown:e=>{e.preventDefault()},onClick:()=>{let e=i.textDecoration.split(" ");e.indexOf("line-through")>=0?e=e.filter(e=>"line-through"!==e):e.push("line-through"),o.history.transaction(()=>{n.forEach(t=>{t.set({textDecoration:e.join(" ")})})})},children:e(a,{name:"text.strikethrough",className:"pn:size-4"})})]})});export const TextTransform=o(({elements:t,store:n})=>{const o="uppercase"==t[0].textTransform;return e("div",{className:"pn:flex pn:items-center pn:gap-0.5",children:e(S,{label:f("toolbar.uppercase"),active:o,onMouseDown:e=>{e.preventDefault()},onClick:()=>{n.history.transaction(()=>{t.forEach(e=>{e.set({textTransform:"uppercase"===e.textTransform?"none":"uppercase"})})})},children:e(a,{name:"text.uppercase",className:"pn:size-4"})})})});export const TextFill=o(({elements:t,store:n})=>{var o;return e(A,{value:null!==(o=t[0].filled.fill)&&void 0!==o?o:t[0].fill,gradientEnabled:!0,onChange:e=>n.history.transaction(()=>{t.forEach(t=>{t.set(L(t,{fill:e}))})}),store:n})});export const TextSpacing=o(({elements:n,store:o})=>{const i=n[0],r=e=>{o.history.transaction(()=>{n.forEach(t=>{t.set(e)})})},l="number"==typeof i.lineHeight?100*i.lineHeight:120;return t(v,{children:[t(F,{children:[e(N,{render:e(y,{render:e(h,{variant:"ghost",size:"icon-sm","aria-label":f("toolbar.spacing"),children:e(a,{name:"text.spacing",className:"pn:size-5"})})})}),e(T,{children:f("toolbar.spacing")})]}),t(b,{align:"start",className:"pn:w-[230px] pn:p-[15px]",children:[e(g,{label:f("toolbar.lineHeight"),value:Math.round(l),onChange:e=>r({lineHeight:e/100}),min:50,max:250}),e(g,{label:f("toolbar.letterSpacing"),value:Math.round(100*i.letterSpacing),onChange:e=>r({letterSpacing:e/100}),min:-50,max:250})]})]})});export const TextFilters=k;export const TextAnimations=O;export const TextToolbar=o(({store:e,components:t})=>{const n=e.selectedElements;return I({type:"text",components:t,controlProps:{store:e,element:n[0],elements:n},controls:{TextFill,TextFontFamily,TextFontSize,TextFontVariant,TextSpacing,TextTransform,TextFilters:k,TextAnimations:d.animationsEnabled&&O,TextAiWrite:d.aiTextEnabled&&M}})});export default TextToolbar;
1
+ import{jsx as e,jsxs as t}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 l,globalFonts as s,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{CELL_PADDING_FIELDS as v,PaddingControl as b,TEXT_PADDING_FIELDS as y,cellPaddingSides as F,paddingAttrs as T}from"./padding-control.js";import{textPadding as N}from"@polotno/core/text-types";import{Popover as C,PopoverContent as S,PopoverTrigger as j}from"../primitives/popover.js";import{Tooltip as w,TooltipContent as z,TooltipTrigger as E}from"../primitives/tooltip.js";import{TooltipIconButton as D}from"../primitives/tooltip-icon-button.js";import{Separator as A}from"../primitives/separator.js";import{cn as k}from"../lib/utils.js";import{cycleNext as O,usedFontFamilies as I}from"./toolbar-shared.js";import{isBoldWeight as L}from"@polotno/core/rich-text-html";import{cssFontFamily as M}from"@polotno/core/fonts";import{ColorPicker as V}from"./color-picker.js";import _ from"./filters-picker.js";import{AnimationsPicker as P}from"./animations-picker.js";import{renderToolbarItems as R}from"./element-container.js";import{TextAiWrite as G}from"./text-ai-write.js";import{unboundWrite as H}from"../model/node-model.js";const B=l(),W=({fontFamily:t,handleClick:o,modifiers:i,store:r,isCustom:a})=>{const[l,s]=n.useState(!a);if(n.useEffect(()=>{l||r.loadFont(t)},[t,l]),"_divider"===t){return e("div",{style:{paddingTop:"10px"},children:e(A,{})})}const c=l?e("img",{src:p(t),alt:t,onError:()=>{s(!1)},className:"pn:h-5 pn:dark:invert"}):t;return e("button",{type:"button",onClick:o,disabled:i.disabled,"data-active":i.active||void 0,className:k("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:M(t)},children:c})},$=({index:t,style:n,filteredFonts:o,activeFont:i,onFontSelect:r,store:a})=>{const l=o[t];return e("div",{style:n,children:e(W,{fontFamily:l,modifiers:{active:i===l},handleClick:()=>r(l),store:a,isCustom:a.fonts.find(e=>e.fontFamily===l)||s.find(e=>e.fontFamily===l)},l)})},J=({onChange:o,defaultValue:i})=>{const r=n.useRef(null);return n.useEffect(()=>{r.current&&r.current.focus()},[]),t(x,{children:[e("span",{className:"pn:flex pn:items-center pn:pl-2 pn:pr-1 pn:text-muted-foreground",children:e(a,{name:"action.search",className:"pn:size-3.5 pn:shrink-0 pn:opacity-50"})}),e("input",{ref:r,"data-slot":"input-group-control",defaultValue:i,onChange:e=>o(e.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:l,activeFontLabel:s,onFontSelect:c,mixed:p,mixedFonts:m,open:f,onOpenChange:u})=>{const[x,g]=n.useState(""),v=r.filter(e=>(null==e?void 0:e.toLowerCase().indexOf(x.toLowerCase()))>=0);return t(C,{open:f,onOpenChange:u,children:[t(w,{children:[e(E,{render:e(j,{render:t(h,{variant:"ghost",size:"sm",className:"pn:gap-1 pn:overflow-hidden pn:whitespace-nowrap",style:{fontFamily:p?void 0:M(l),fontStyle:p?"italic":void 0,color:p?"#5c7080":void 0},"aria-label":d("toolbar.fontFamily"),children:[e("span",{className:"pn:truncate",children:p?d("toolbar.fontFamilyMixed"):s}),e(a,{name:"ui.chevronDown",className:"pn:size-3 pn:shrink-0 pn:opacity-50"})]})})}),e(z,{children:p&&m&&m.length>0?`${d("toolbar.fontsInSelection")}: ${m.join(", ")}`:d("toolbar.fontFamily")})]}),e(S,{className:"pn:w-[230px] pn:p-2",align:"start",children:t("div",{children:[e(J,{onChange:e=>g(e),defaultValue:x}),e("div",{style:{paddingTop:"5px"},children:e(i,{style:{height:Math.min(400,30*v.length)+10,width:210},rowCount:v.length,rowHeight:30,rowComponent:$,rowProps:{filteredFonts:v,activeFont:l,onFontSelect:c,store:o}})})]})})]})};const q={};export const fetcher=e=>q[e]?Promise.resolve(q[e]):fetch(e).then(e=>e.json()).then(t=>(q[e]=t,t));export const TextFontFamily=o(({elements:t,store:o})=>{const[i,a]=n.useState(!1),{data:l,mutate:p}=r(i?m():null,fetcher,{isPaused:()=>c(),fallbackData:[]});n.useEffect(()=>{p()},[c()]);const d=o.fonts.concat(s).map(e=>e.fontFamily).concat((null==l?void 0:l.length)&&!c()?l:B);let f=t[0].fontFamily;f.length>15&&(f=f.slice(0,15)+"...");const h=I(o),u=[...new Set(h.concat("_divider").concat(d))];return e(FontMenu,{fonts:u,activeFont:t[0].fontFamily,activeFontLabel:f,store:o,open:i,onOpenChange:a,onFontSelect:e=>{o.history.transaction(()=>{t.forEach(t=>{t.set({fontFamily:e})})})}})});export const TextFontSize=o(({elements:o,store:i})=>{const[r,a]=n.useState(!1),[l,s]=n.useState(!1);return t(w,{open:!l&&r,onOpenChange:e=>{l||a(e)},children:[e(E,{render:e(u,{"aria-label":d("toolbar.fontSize"),onFocus:()=>s(!0),onBlur:()=>s(!1),onValueChange:e=>{i.history.transaction(()=>{o.forEach(t=>{t.set({fontSize:e,width:Math.max(e,t.width)})})})},value:Math.round(100*o[0].fontSize)/100,style:{width:"50px"},min:5,max:4*i.height})}),e(z,{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:e(a,{name:"text.valignTop",className:"pn:size-4"}),middle:e(a,{name:"text.valignMiddle",className:"pn:size-4"}),bottom:e(a,{name:"text.valignBottom",className:"pn:size-4"})};export const TextFontVariant=o(({elements:n,store:o})=>{const i=n[0],r=L(i.fontWeight),l="italic"===i.fontStyle,s=i.textDecoration.indexOf("underline")>=0,c=i.textDecoration.indexOf("line-through")>=0;return t("div",{className:"pn:flex pn:items-center pn:gap-0.5",children:[t(w,{children:[e(E,{render:e(h,{variant:"ghost",size:"icon-sm",onMouseDown:e=>{e.preventDefault()},onClick:()=>{const e=O(ALIGN_OPTIONS,i.align);o.history.transaction(()=>{n.forEach(t=>{t.set({align:e})})})},"aria-label":d("toolbar.textAlign"),children:"left"===i.align?e(a,{name:"text.alignLeft",className:"pn:size-4"}):"center"===i.align?e(a,{name:"text.alignCenter",className:"pn:size-4"}):"right"===i.align?e(a,{name:"text.alignRight",className:"pn:size-4"}):e(a,{name:"text.alignJustify",className:"pn:size-4"})})}),e(z,{children:d("toolbar.textAlign")})]}),f.textVerticalResizeEnabled&&t(w,{children:[e(E,{render:e(h,{variant:"ghost",size:"icon-sm",onMouseDown:e=>{e.preventDefault()},onClick:()=>{const e=O(VERTICAL_ALIGN_OPTIONS,i.verticalAlign);o.history.transaction(()=>{n.forEach(t=>{t.set({verticalAlign:e})})})},"aria-label":d("toolbar.verticalAlign"),children:VERTICAL_ALIGN_ICONS[i.verticalAlign]})}),e(z,{children:d("toolbar.verticalAlign")})]}),e(D,{label:d("toolbar.bold"),active:r,onMouseDown:e=>{e.preventDefault()},onClick:()=>{const e=L(i.fontWeight);o.history.transaction(()=>{n.forEach(t=>{t.set({fontWeight:e?"400":"700"})})})},children:e(a,{name:"text.bold",className:"pn:size-4"})}),e(D,{label:d("toolbar.italic"),active:l,onMouseDown:e=>{e.preventDefault()},onClick:()=>{const e="italic"===i.fontStyle;o.history.transaction(()=>{n.forEach(t=>{e?t.set({fontStyle:"normal"}):t.set({fontStyle:"italic"})})})},children:e(a,{name:"text.italic",className:"pn:size-4"})}),e(D,{label:d("toolbar.underline"),active:s,onMouseDown:e=>{e.preventDefault()},onClick:()=>{let e=i.textDecoration.split(" ");e.indexOf("underline")>=0?e=e.filter(e=>"underline"!==e):e.push("underline"),o.history.transaction(()=>{n.forEach(t=>{t.set({textDecoration:e.join(" ")})})})},children:e(a,{name:"text.underline",className:"pn:size-4"})}),e(D,{label:d("toolbar.strikethrough"),active:c,onMouseDown:e=>{e.preventDefault()},onClick:()=>{let e=i.textDecoration.split(" ");e.indexOf("line-through")>=0?e=e.filter(e=>"line-through"!==e):e.push("line-through"),o.history.transaction(()=>{n.forEach(t=>{t.set({textDecoration:e.join(" ")})})})},children:e(a,{name:"text.strikethrough",className:"pn:size-4"})})]})});export const TextTransform=o(({elements:t,store:n})=>{const o="uppercase"==t[0].textTransform;return e("div",{className:"pn:flex pn:items-center pn:gap-0.5",children:e(D,{label:d("toolbar.uppercase"),active:o,onMouseDown:e=>{e.preventDefault()},onClick:()=>{n.history.transaction(()=>{t.forEach(e=>{e.set({textTransform:"uppercase"===e.textTransform?"none":"uppercase"})})})},children:e(a,{name:"text.uppercase",className:"pn:size-4"})})})});export const TextFill=o(({elements:t,store:n})=>{var o;return e(V,{value:null!==(o=t[0].filled.fill)&&void 0!==o?o:t[0].fill,gradientEnabled:!0,onChange:e=>n.history.transaction(()=>{t.forEach(t=>{t.set(H(t,{fill:e}))})}),store:n})});export const TextSpacing=o(({elements:n,store:o})=>{const i=n[0],r=i,l="tablecell"===i.type?{label:d("toolbar.cellPadding"),value:F(i),fields:v,disabled:!1}:{label:d("toolbar.textPadding"),value:N({paddingTop:r.paddingTop,paddingRight:r.paddingRight,paddingBottom:r.paddingBottom,paddingLeft:r.paddingLeft}),fields:y,disabled:!!r.curveEnabled},s=e=>{o.history.transaction(()=>{n.forEach(t=>{t.set(e)})})},c="number"==typeof i.lineHeight?100*i.lineHeight:120;return t(C,{children:[t(w,{children:[e(E,{render:e(j,{render:e(h,{variant:"ghost",size:"icon-sm","aria-label":d("toolbar.spacing"),children:e(a,{name:"text.spacing",className:"pn:size-5"})})})}),e(z,{children:d("toolbar.spacing")})]}),t(S,{align:"start",className:"pn:w-[270px] pn:p-[15px]",children:[e(g,{label:d("toolbar.lineHeight"),value:Math.round(c),onChange:e=>s({lineHeight:e/100}),min:50,max:250}),e(g,{label:d("toolbar.letterSpacing"),value:Math.round(100*i.letterSpacing),onChange:e=>s({letterSpacing:e/100}),min:-50,max:250}),e("div",{className:"pn:mt-2 pn:border-t pn:pt-2",children:e(b,{label:l.label,value:l.value,disabled:l.disabled,onChange:e=>s(T(e,l.fields))},i.id)})]})]})});export const TextFilters=_;export const TextAnimations=P;export const TextToolbar=o(({store:e,components:t})=>{const n=e.selectedElements;return R({type:"text",components:t,controlProps:{store:e,element:n[0],elements:n},controls:{TextFill,TextFontFamily,TextFontSize,TextFontVariant,TextSpacing,TextTransform,TextFilters:_,TextAnimations:f.animationsEnabled&&P,TextAiWrite:f.aiTextEnabled&&G}})});export default TextToolbar;
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ import { NumericInput } from '../primitives/numeric-input.js';
3
+ export declare const UnitNumericInput: ({ unit, ...props }: React.ComponentProps<typeof NumericInput> & {
4
+ unit: string;
5
+ }) => React.JSX.Element;
@@ -0,0 +1 @@
1
+ var t=this&&this.__rest||function(t,e){var n={};for(var r in t){Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r])}if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var p=0;for(r=Object.getOwnPropertySymbols(t);p<r.length;p++){e.indexOf(r[p])<0&&Object.prototype.propertyIsEnumerable.call(t,r[p])&&(n[r[p]]=t[r[p]])}}return n};import{jsx as e,jsxs as n}from"react/jsx-runtime";import{NumericInput as r}from"../primitives/numeric-input.js";export const UnitNumericInput=p=>{var{unit:i}=p,s=t(p,["unit"]);return n("div",{className:"pn:relative",children:[e(r,Object.assign({},s,{className:"pn:pl-1 pn:pr-8"})),e("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:i})]})};
@@ -1 +1 @@
1
- import{useEffect as e,useState as o}from"react";import{getSnapshot as t,isStateTreeNode as r}from"mobx-state-tree";import{intersect as l}from"../utils/array.js";export function copyTableCellStyles(e,o){const t=Math.min(e.rows,o.rows),r=Math.min(e.cols,o.cols);for(let l=0;l<t;l++){for(let t=0;t<r;t++){const r=e.getCell(l,t),i=o.getCell(l,t);if(!r||!i){continue}const n={};for(const e of g){n[e]=r[e]}i.set(n)}}}export function applyCopiedStyle(e,o){const i=l(f[o.type],f[e.type]).reduce((o,l)=>{const i=e[l];return Object.assign(Object.assign({},o),{[l]:r(i)?t(i):i})},{});o.type!==e.type&&h.forEach(e=>{delete i[e]}),o.set(Object.assign({},i)),"table"===e.type&&"table"===o.type&&copyTableCellStyles(e,o)}export const useCopyStyle=t=>{const[r,l]=o(null);e(()=>{const e=t.selectedElements;r&&(e.forEach(e=>applyCopiedStyle(r,e)),l(null))},[t.selectedElements[0]]);const i=1!==t.selectedElements.length;return{elementToCopy:r,disabled:i,setElementToCopy:l}};const i=["opacity","visible","height","width","shadowEnabled","shadowBlur","shadowColor","shadowOffsetX","shadowOffsetY","blurEnabled","blurRadius","brightnessEnabled","brightness","sepiaEnabled","grayscaleEnabled"],n=[...i,"fontSize","fontWeight","fontFamily","lineHeight","stroke","strokeWidth","textDecoration","fill","align","verticalAlign","letterSpacing","backgroundEnabled","backgroundColor","backgroundOpacity","backgroundCornerRadius","backgroundPadding","borderColor","borderSize"],a=[...i,"flipX","flipY","keepRatio","borderColor","borderSize","cornerRadius","cropX","cropY","cropWidth","cropHeight"],s=[...i,"flipX","flipY","keepRatio","borderColor","borderSize","cornerRadius","cropX","cropY","cropWidth","cropHeight"],c=[...i,"color","dash","endHead","startHead"],d=[...i,"dash","cornerRadius","fill","stroke","strokeWidth"],p=[...i,"cornerRadius","borderColor","borderSize","colorsReplace","cropHeight","cropWidth","cropX","cropY","flipX","flipY","keepRatio"],b=[...i,"borderColor","borderWidth","borderStyle"],g=["fontSize","fontFamily","fontWeight","fontStyle","textDecoration","fill","align","verticalAlign","lineHeight","letterSpacing","cellBackground","cellPadding","borders"],f={figure:d,image:a,line:c,svg:p,text:n,video:s,table:b},h=["width","height"];
1
+ import{useEffect as e,useState as o}from"react";import{getSnapshot as t,isStateTreeNode as r}from"mobx-state-tree";import{intersect as l}from"../utils/array.js";export function copyTableCellStyles(e,o){const t=Math.min(e.rows,o.rows),r=Math.min(e.cols,o.cols);for(let l=0;l<t;l++){for(let t=0;t<r;t++){const r=e.getCell(l,t),i=o.getCell(l,t);if(!r||!i){continue}const n={};for(const e of b){n[e]=r[e]}i.set(n)}}}export function applyCopiedStyle(e,o){const i=l(h[o.type],h[e.type]).reduce((o,l)=>{const i=e[l];return Object.assign(Object.assign({},o),{[l]:r(i)?t(i):i})},{});o.type!==e.type&&f.forEach(e=>{delete i[e]}),o.set(Object.assign({},i)),"table"===e.type&&"table"===o.type&&copyTableCellStyles(e,o)}export const useCopyStyle=t=>{const[r,l]=o(null);e(()=>{const e=t.selectedElements;r&&(e.forEach(e=>applyCopiedStyle(r,e)),l(null))},[t.selectedElements[0]]);const i=1!==t.selectedElements.length;return{elementToCopy:r,disabled:i,setElementToCopy:l}};const i=["opacity","visible","height","width","shadowEnabled","shadowBlur","shadowColor","shadowOffsetX","shadowOffsetY","blurEnabled","blurRadius","brightnessEnabled","brightness","sepiaEnabled","grayscaleEnabled"],n=[...i,"fontSize","fontWeight","fontFamily","lineHeight","stroke","strokeWidth","textDecoration","fill","align","verticalAlign","letterSpacing","backgroundEnabled","backgroundColor","backgroundOpacity","backgroundCornerRadius","backgroundPadding","backgroundShape","borderColor","borderSize","paddingTop","paddingRight","paddingBottom","paddingLeft"],a=[...i,"flipX","flipY","keepRatio","borderColor","borderSize","cornerRadius","cropX","cropY","cropWidth","cropHeight"],d=[...i,"flipX","flipY","keepRatio","borderColor","borderSize","cornerRadius","cropX","cropY","cropWidth","cropHeight"],c=[...i,"color","dash","endHead","startHead"],s=[...i,"dash","cornerRadius","fill","stroke","strokeWidth"],p=[...i,"cornerRadius","borderColor","borderSize","colorsReplace","cropHeight","cropWidth","cropX","cropY","flipX","flipY","keepRatio"],g=[...i,"borderColor","borderWidth","borderStyle"],b=["fontSize","fontFamily","fontWeight","fontStyle","textDecoration","fill","align","verticalAlign","lineHeight","letterSpacing","cellBackground","cellPaddingTop","cellPaddingRight","cellPaddingBottom","cellPaddingLeft","borders"],h={figure:s,image:a,line:c,svg:p,text:n,video:d,table:g},f=["width","height"];