polotno 3.15.3 → 3.16.1

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 (86) hide show
  1. package/blueprint/side-panel/select-video.d.ts +2 -0
  2. package/canvas/element.js +1 -1
  3. package/canvas/figure-element.js +1 -1
  4. package/canvas/gif-element.js +1 -1
  5. package/canvas/html-element.js +1 -1
  6. package/canvas/image-element.js +1 -1
  7. package/canvas/page.js +1 -1
  8. package/canvas/render-tag-element.js +1 -1
  9. package/canvas/rich-editor.d.ts +3 -1
  10. package/canvas/rich-editor.js +2 -2
  11. package/canvas/text-element.js +1 -1
  12. package/canvas/use-color.d.ts +2 -2
  13. package/canvas/video-element.js +1 -1
  14. package/model/figure-model.d.ts +1 -0
  15. package/model/gif-model.d.ts +1 -0
  16. package/model/group-model.d.ts +12 -0
  17. package/model/image-model.d.ts +1 -0
  18. package/model/line-model.d.ts +1 -0
  19. package/model/node-model.d.ts +1 -0
  20. package/model/node-model.js +1 -1
  21. package/model/page-model.d.ts +36 -0
  22. package/model/page-model.js +1 -1
  23. package/model/shape-model.d.ts +1 -0
  24. package/model/store.d.ts +6 -0
  25. package/model/store.js +1 -1
  26. package/model/svg-model.d.ts +1 -0
  27. package/model/table-model.d.ts +1 -0
  28. package/model/text-model.d.ts +5 -0
  29. package/model/text-model.js +1 -1
  30. package/model/video-model.d.ts +1 -0
  31. package/package.json +21 -21
  32. package/polotno.bundle.js +166 -165
  33. package/primitives/numeric-input-delayed.d.ts +12 -0
  34. package/primitives/numeric-input-delayed.js +1 -0
  35. package/primitives/popover.js +1 -1
  36. package/side-panel/effects-panel.js +1 -1
  37. package/side-panel/layer-selection.d.ts +26 -0
  38. package/side-panel/layer-selection.js +1 -0
  39. package/side-panel/layers-panel.js +1 -1
  40. package/side-panel/select-video.d.ts +2 -0
  41. package/side-panel/size-panel.js +1 -1
  42. package/side-panel/text-effect-presets.d.ts +11 -0
  43. package/side-panel/text-effect-presets.js +1 -0
  44. package/toolbar/group-toolbar.js +1 -1
  45. package/toolbar/image-toolbar.d.ts +3 -2
  46. package/toolbar/image-toolbar.js +1 -1
  47. package/toolbar/many-toolbar.js +1 -1
  48. package/toolbar/opacity-picker.d.ts +3 -2
  49. package/toolbar/opacity-picker.js +1 -1
  50. package/toolbar/position-picker.js +1 -1
  51. package/toolbar/selection-colors.d.ts +18 -0
  52. package/toolbar/selection-colors.js +1 -0
  53. package/toolbar/selection-size.d.ts +12 -0
  54. package/toolbar/selection-size.js +1 -0
  55. package/toolbar/svg-toolbar.js +1 -1
  56. package/ui.css +1 -1
  57. package/utils/alignment.d.ts +16 -0
  58. package/utils/alignment.js +1 -1
  59. package/utils/array.d.ts +1 -0
  60. package/utils/array.js +1 -0
  61. package/utils/clipboard.d.ts +10 -0
  62. package/utils/duplicate.d.ts +2 -0
  63. package/utils/duplicate.js +1 -1
  64. package/utils/file.d.ts +1 -1
  65. package/utils/flags.d.ts +1 -1
  66. package/utils/l10n.d.ts +13 -0
  67. package/utils/l10n.js +1 -1
  68. package/utils/measure-text.d.ts +6 -3
  69. package/utils/measure-text.js +1 -1
  70. package/utils/px.d.ts +11 -18
  71. package/utils/px.js +1 -1
  72. package/utils/rich-text-html.d.ts +5 -0
  73. package/utils/rich-text-html.js +1 -1
  74. package/utils/selection-colors.d.ts +15 -0
  75. package/utils/selection-colors.js +1 -0
  76. package/utils/selection-transform.d.ts +19 -0
  77. package/utils/selection-transform.js +1 -0
  78. package/utils/selection.d.ts +3 -0
  79. package/utils/selection.js +1 -0
  80. package/utils/text-sizing.d.ts +5 -0
  81. package/utils/text-sizing.js +1 -0
  82. package/utils/use-svg-colors.d.ts +1 -0
  83. package/utils/use-svg-colors.js +1 -1
  84. package/utils/validate-key.js +1 -1
  85. package/canvas/text-element/fit-font-size.d.ts +0 -5
  86. package/canvas/text-element/fit-font-size.js +0 -1
@@ -0,0 +1,12 @@
1
+ import * as React from 'react';
2
+ import { Input } from './input.js';
3
+ type NumericInputDelayedProps = Omit<React.ComponentProps<typeof Input>, 'value' | 'onChange' | 'min' | 'max' | 'step'> & {
4
+ value: number | string;
5
+ onChange: (value: number) => void;
6
+ min?: number;
7
+ max?: number;
8
+ step?: number;
9
+ stepper?: boolean;
10
+ };
11
+ export declare const NumericInputDelayed: ({ value, onChange, min, max, step, stepper, className, ...rest }: NumericInputDelayedProps) => React.JSX.Element;
12
+ export {};
@@ -0,0 +1 @@
1
+ var e=this&&this.__rest||function(e,n){var t={};for(var r in e){Object.prototype.hasOwnProperty.call(e,r)&&n.indexOf(r)<0&&(t[r]=e[r])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var a=0;for(r=Object.getOwnPropertySymbols(e);a<r.length;a++){n.indexOf(r[a])<0&&Object.prototype.propertyIsEnumerable.call(e,r[a])&&(t[r[a]]=e[r[a]])}}return t};import{jsx as n,jsxs as t}from"react/jsx-runtime";import*as r from"react";import{PolotnoIcon as a}from"../icons/registry.js";import{cn as p}from"../lib/utils.js";import{Input as o}from"./input.js";export const NumericInputDelayed=s=>{var{value:i,onChange:l,min:c,max:u,step:m=1,stepper:b=!0,className:f}=s,d=e(s,["value","onChange","min","max","step","stepper","className"]);const[x,g]=r.useState(String(i)),y=()=>{const e=parseFloat(x);g(String(i)),Number.isNaN(e)||l(Math.max(null!=c?c:-1/0,e))};r.useEffect(()=>{g(String(i))},[i]);const h=e=>{const n=parseFloat(x),t=Number.isNaN(n)?Number(i)||0:n,r=Math.min(null!=u?u:1/0,Math.max(null!=c?c:-1/0,t+e*m)),a=parseFloat(r.toFixed(4));g(String(a)),l(a)};return t("div",{className:"pn:relative",children:[n(o,Object.assign({},d,{min:c,max:u,step:m,type:"number",value:x,className:p(b&&"pn:pr-6","pn:[appearance:textfield] pn:[&::-webkit-inner-spin-button]:appearance-none pn:[&::-webkit-outer-spin-button]:appearance-none",f),onChange:e=>{const n=e.target.value;""!==n&&Number.isNaN(parseFloat(n))||g(n)},onBlur:y,onFocus:e=>e.target.select(),onKeyDown:e=>{"Enter"===e.key&&y(),"ArrowUp"!==e.key&&"ArrowDown"!==e.key||(e.preventDefault(),h(("ArrowUp"===e.key?1:-1)*(e.shiftKey?10:1)))}})),b&&t("div",{className:"pn:absolute pn:inset-y-0 pn:right-0 pn:flex pn:w-5 pn:flex-col pn:border-l pn:border-input",children:[n("button",{type:"button",tabIndex:-1,"aria-label":"Increment",className:"pn:flex pn:flex-1 pn:appearance-none pn:cursor-pointer pn:items-center pn:justify-center pn:border-0 pn:bg-transparent pn:text-muted-foreground pn:hover:bg-muted pn:hover:text-foreground",onClick:()=>h(1),children:n(a,{name:"ui.chevronUp",className:"pn:size-3"})}),n("button",{type:"button",tabIndex:-1,"aria-label":"Decrement",className:"pn:flex pn:flex-1 pn:appearance-none pn:cursor-pointer pn:items-center pn:justify-center pn:border-0 pn:border-t pn:border-input pn:bg-transparent pn:text-muted-foreground pn:hover:bg-muted pn:hover:text-foreground",onClick:()=>h(-1),children:n(a,{name:"ui.chevronDown",className:"pn:size-3"})})]})]})};
@@ -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-50",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,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 +1 @@
1
- import{jsx as e,Fragment 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{Effects as u}from"@polotno/core/filters";import{CurvePowerSlider as p}from"../toolbar/filters-picker.js";import{NumericInput as m}from"../primitives/numeric-input.js";import{FieldRow as f}from"../primitives/field-row.js";import{PanelHeader as g}from"../primitives/panel-header.js";import{ToggleGroup as v,ToggleGroupItem as C}from"../primitives/toggle-group.js";import{normalizeStrokeLineJoin as x}from"@polotno/core/text-html";import{defaultFade as y,insertFadeStop as w,fadePreview as k,fadeStopColor as j,FADE_CHECKERBOARD as E}from"../utils/fade-gradient.js";import{Button as M}from"../primitives/button.js";import{canRemoveStop as S,reverseStops as O}from"../utils/stops.js";import{StopTrack as z}from"../toolbar/stop-track.js";import{useFadeStopFocus as F}from"../hooks/use-fade-stop-focus.js";import{getSelectedFadeStop as R,setSelectedFadeStop as V}from"../utils/fade-overlay.js";import{readClipFade as P,writeClipFade as N}from"../utils/clip-fade.js";import{urlToBase64 as L}from"@polotno/core/svg";import{isAlive as B}from"mobx-state-tree";import{PanelScrollArea as W}from"../primitives/panel-scroll-area.js";const X=[{value:"round",labelKey:"toolbar.joinRound"},{value:"miter",labelKey:"toolbar.joinMiter"},{value:"bevel",labelKey:"toolbar.joinBevel"}],Y=({join:a})=>e("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:e("path",{d:"M7 21 L7 7 L21 7",stroke:"currentColor",strokeWidth:"9",strokeLinejoin:a,strokeLinecap:"butt"})});export{m as NumberInput};const $=(e,a,o)=>Math.max(a,Math.min(o,e)),K=(e,a)=>Math.max(e,Math.ceil(a)),J=(e,a)=>Math.min(e,Math.floor(a)),I=[["temperature","toolbar.temperature"],["contrast","toolbar.contrast"],["shadows","toolbar.shadows"],["white","toolbar.white"],["black","toolbar.black"],["vibrance","toolbar.vibrance"],["saturation","toolbar.saturation"]],T=s(({store:l,elements:t})=>{const[n,s]=r.useState(""),[d,c]=r.useState(!1),h=t.filter(e=>["image","video","gif"].includes(e.type)),u=h[0];if(!u){return null}const p=P(u.clipSrc);return o(a,{children:[e(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=P(r),t=null!==(o=null==l?void 0:l.baseSrc)&&void 0!==o?o:r,n=e&&t&&!t.startsWith("data:")?await L(t,{binary:!0}):t;return{item:a,previous:r,clipSrc:e?N(y(),n):null==l?void 0:l.baseSrc}}));l.history.transaction(()=>a.forEach(({item:e,previous:a,clipSrc:o})=>{B(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&&e(D,{store:l,element:u,value:p.fade,onChange:e=>l.history.transaction(()=>{h.forEach(a=>{if(!B(a)){return}const o=P(a.clipSrc);o&&a.set({clipSrc:N(e,o.baseSrc)})})})},u.id)}),d&&e("div",{role:"status",children:b("toolbar.clipFade.preparing")}),n&&e("div",{role:"alert",children:n})]})}),D=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=>V(l,e);F(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(a,{children:[e(f,{label:b("toolbar.clipFade.shape"),children:o(v,{value:[i.shape],onValueChange:e=>{const a=e[0];"linear"!==a&&"radial"!==a||a===i.shape||s(Object.assign(Object.assign({},y(a)),{stops:i.stops}))},children:[e(C,{value:"linear","aria-label":b("toolbar.clipFade.linear"),children:b("toolbar.clipFade.linear")}),e(C,{value:"radial","aria-label":b("toolbar.clipFade.radial"),children:b("toolbar.clipFade.radial")})]})}),e("p",{className:"pn:py-1 pn:text-xs pn:text-muted-foreground",children:b("toolbar.clipFade.hint")}),e("div",{className:"pn:px-3",children:e(z,{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=>j(e.alpha),bar:e("div",{className:"pn:size-full",style:{background:`${k(i.stops)}, ${E}`}})})}),e(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:[e(M,{variant:"ghost",size:"sm",onClick:()=>p({stops:O(i.stops),index:i.stops.length-1-d}),children:b("toolbar.clipFade.reverse")}),e(M,{variant:"ghost",size:"sm",disabled:!S(i.stops),onClick:()=>{var e;return null===(e=h.current)||void 0===e?void 0:e.remove(d)},children:b("toolbar.clipFade.removeStop")}),e(M,{variant:"ghost",size:"sm",onClick:()=>{u(0),s(y(i.shape))},children:b("toolbar.clipFade.reset")})]})]})}),q=({store:a,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:[e(c,{value:r,size:30,gradientEnabled:u,onChange:n,store:a}),e("div",{style:{flex:1,paddingLeft:"10px",paddingRight:"10px"},children:e(l,{value:[i],onValueChange:e=>s($(Math.round(t(e)),d,b)),min:d,max:null!=h?h:b,step:1})}),e(m,{value:Math.round(i),onValueChange:e=>s($(e,d,b)),min:d,max:b,style:{width:64}})]});export const EffectsPanel=s(({store:a})=>{var l;const t=a.selectedElements,s=t[0],y=t.map(e=>e.id).join(","),w="effects"===a.openedSidePanel;if(r.useEffect(()=>{w&&(s&&s.filters||a.restoreSidePanel())},[w,y]),!s||!s.filters){return null}const k="text"===s.type,j="image"===s.type,E="svg"===s.type,M=j||E,S="image"===s.type||"video"===s.type||"gif"===s.type,O=Math.min(s.width,s.height)/2,z=Math.min(null!==(l=s.cornerRadius)&&void 0!==l?l:0,O),F=e=>{a.history.transaction(()=>{t.forEach(a=>{a.set(e)})})},R=(e,o)=>{a.history.transaction(()=>{t.forEach(a=>{let r=Number(o);return 0==o||o||(r=a.filters.has(e)?null:1),d.includes(e)||a.set({grayscaleEnabled:"grayscale"===e&&!!o,sepiaEnabled:"sepia"===e&&!!o}),a.setFilter(e,r)})})};return o(W,{header:e(g,{title:b("sidePanel.effects"),onClose:()=>a.restoreSidePanel()}),children:[M&&e("div",{style:{display:"flex",flexDirection:"column",gap:"16px",marginTop:"16px"},children:o("div",{style:{display:"flex",gap:"16px",flexWrap:"wrap"},children:[e(h,{active:s.grayscaleEnabled,onClick:()=>{R("grayscale",!s.grayscaleEnabled)},title:b("toolbar.grayscale"),imageSrc:s.src,effect:u.grayscale}),e(h,{active:s.sepiaEnabled,onClick:()=>{R("sepia",!s.sepiaEnabled)},title:b("toolbar.sepia"),imageSrc:s.src,effect:u.sepia}),e(h,{active:s.filters.has("cold"),onClick:()=>{R("cold",s.filters.has("cold")?null:1)},title:b("toolbar.cold"),imageSrc:s.src,effect:u.cold}),e(h,{active:s.filters.has("natural"),onClick:()=>{R("natural",s.filters.has("natural")?null:1)},title:b("toolbar.natural"),imageSrc:s.src,effect:u.natural}),e(h,{active:s.filters.has("warm"),onClick:()=>{R("warm",s.filters.has("warm")?null:1)},title:b("toolbar.warm"),imageSrc:s.src,effect:u.warm})]})}),e(n,{label:b("toolbar.blur"),enabled:s.blurEnabled,visible:M||k,onEnabledChange:e=>{F({blurEnabled:e})},value:s.blurRadius,onChange:e=>{F({blurRadius:e})},min:0,max:100}),e(n,{label:b("toolbar.brightness"),visible:M,enabled:s.brightnessEnabled,onEnabledChange:e=>{F({brightnessEnabled:e})},value:Math.round(100*s.brightness),onChange:e=>{F({brightness:e/100})},min:-100,max:100}),I.map(([a,o])=>{var r,l;return e(n,{label:b(o),visible:M,enabled:s.filters.has(a),onEnabledChange:e=>{R(a,e?0:null)},value:Math.round(100*(null!==(l=null===(r=s.filters.get(a))||void 0===r?void 0:r.intensity)&&void 0!==l?l:0)),onChange:e=>{R(a,e/100)},min:-100,max:100},a)}),k&&o(i,{label:b("toolbar.curvedText")||"Curved text",enabled:!!s.curveEnabled,onEnabledChange:e=>F({curveEnabled:e}),children:[e(f,{label:b("toolbar.curvePower")||"Curve",className:"pn:py-2",children:e(m,{value:Math.round(100*s.curvePower),onValueChange:e=>{F({curvePower:$(e,-100,100)/100})},style:{width:64},min:-100,max:100})}),e(p,{textEl:s,eachSet:F})]}),k&&o(i,{label:b("toolbar.textStroke"),enabled:!!s.strokeWidth,onEnabledChange:e=>F({strokeWidth:e?2:0}),children:[e(q,{store:a,color:s.stroke,onColorChange:e=>{F({stroke:e})},value:s.strokeWidth,onValueChange:e=>{F({strokeWidth:e})},min:1,max:Math.max(1,Math.round(s.fontSize/2)),sliderMax:Math.max(1,s.fontSize/2)}),e(f,{label:b("toolbar.strokeLineJoin"),className:"pn:py-2",children:e(v,{variant:"outline",value:[x(s.strokeLineJoin)],onValueChange:e=>{const a=e[0];a&&F({strokeLineJoin:a})},children:X.map(({value:a,labelKey:o})=>e(C,{value:a,"aria-label":b(o),title:b(o),children:e(Y,{join:a})},a))})})]}),k&&o(i,{label:b("toolbar.textBackground"),enabled:!!s.backgroundEnabled,onEnabledChange:e=>F({backgroundEnabled:e}),children:[e(n,{label:b("toolbar.opacity"),value:Math.round(100*s.backgroundOpacity),onChange:e=>F({backgroundOpacity:e/100}),min:0,max:100}),e(f,{label:b("toolbar.color"),className:"pn:py-2",children:e(c,{value:s.backgroundColor,size:30,onChange:e=>{F({backgroundColor:e})},store:a})})]}),k&&e(i,{label:b("toolbar.border"),enabled:!!s.borderSize,onEnabledChange:e=>F({borderSize:e?2:0}),children:e(q,{store:a,color:s.borderColor,onColorChange:e=>F({borderColor:e}),value:s.borderSize,onValueChange:e=>F({borderSize:e}),min:1,max:Math.max(1,Math.round(s.fontSize/2)),gradientEnabled:!1})}),k&&(s.backgroundEnabled||s.borderSize>0)&&o(i,{label:b("toolbar.textBox"),children:[e(n,{label:b("toolbar.backgroundCornerRadius"),value:Math.round(100*s.backgroundCornerRadius),onChange:e=>F({backgroundCornerRadius:e/100}),min:0,max:200}),e(n,{label:b("toolbar.backgroundPadding"),value:Math.round(100*s.backgroundPadding),onChange:e=>F({backgroundPadding:e/100}),min:0,max:100})]}),M&&e(i,{label:b("toolbar.border"),enabled:!!s.borderSize,onEnabledChange:e=>F({borderSize:e?2:0}),children:e(q,{store:a,color:s.borderColor,onColorChange:e=>{F({borderColor:e})},value:s.borderSize,onValueChange:e=>{F({borderSize:e})},min:1,max:Math.max(1,Math.round(O)),sliderMax:Math.max(1,O)})}),M&&e(n,{label:b("toolbar.cornerRadius"),visible:M,enabled:0!==s.cornerRadius,onEnabledChange:e=>{F({cornerRadius:e?Math.min(s.width/4,s.height/4):0})},value:Math.round(z),sliderValue:z,onChange:e=>{F({cornerRadius:e})},min:1,max:Math.round(O),sliderMax:O}),S&&e(T,{store:a,elements:t}),o(i,{label:b("toolbar.shadow"),enabled:s.shadowEnabled,onEnabledChange:e=>F({shadowEnabled:e}),children:[e(n,{label:b("toolbar.blur"),value:Math.round(s.shadowBlur),sliderValue:s.shadowBlur,onChange:e=>{F({shadowBlur:e})},min:0,max:K(50,s.shadowBlur)}),e(n,{label:b("toolbar.offsetX"),value:Math.round(s.shadowOffsetX),sliderValue:s.shadowOffsetX,onChange:e=>{F({shadowOffsetX:e})},min:J(-50,s.shadowOffsetX),max:K(50,s.shadowOffsetX)}),e(n,{label:b("toolbar.offsetY"),value:Math.round(s.shadowOffsetY),sliderValue:s.shadowOffsetY,onChange:e=>{F({shadowOffsetY:e})},min:J(-50,s.shadowOffsetY),max:K(50,s.shadowOffsetY)}),e(n,{label:b("toolbar.opacity"),value:Math.round(100*s.shadowOpacity),onChange:e=>{F({shadowOpacity:e/100})},min:0,max:100}),e(f,{label:b("toolbar.color"),className:"pn:py-2",children:e(c,{value:s.shadowColor,size:30,onChange:e=>{F({shadowColor:e})},store:a})})]})]})});
1
+ import{jsx as e,Fragment 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:a})=>e("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:e("path",{d:"M7 21 L7 7 L21 7",stroke:"currentColor",strokeWidth:"9",strokeLinejoin:a,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"].includes(e.type)),u=h[0];if(!u){return null}const p=N(u.clipSrc);return o(a,{children:[e(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&&e(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&&e("div",{role:"status",children:b("toolbar.clipFade.preparing")}),n&&e("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(a,{children:[e(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:[e(x,{value:"linear","aria-label":b("toolbar.clipFade.linear"),children:b("toolbar.clipFade.linear")}),e(x,{value:"radial","aria-label":b("toolbar.clipFade.radial"),children:b("toolbar.clipFade.radial")})]})}),e("p",{className:"pn:py-1 pn:text-xs pn:text-muted-foreground",children:b("toolbar.clipFade.hint")}),e("div",{className:"pn:px-3",children:e(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:e("div",{className:"pn:size-full",style:{background:`${j(i.stops)}, ${M}`}})})}),e(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:[e(S,{variant:"ghost",size:"sm",onClick:()=>p({stops:z(i.stops),index:i.stops.length-1-d}),children:b("toolbar.clipFade.reverse")}),e(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")}),e(S,{variant:"ghost",size:"sm",onClick:()=>{u(0),s(w(i.shape))},children:b("toolbar.clipFade.reset")})]})]})}),A=({store:a,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:[e(c,{value:r,size:30,gradientEnabled:u,onChange:n,store:a}),e("div",{style:{flex:1,paddingLeft:"10px",paddingRight:"10px"},children:e(l,{value:[i],onValueChange:e=>s(K(Math.round(t(e)),d,b)),min:d,max:null!=h?h:b,step:1})}),e(f,{value:Math.round(i),onValueChange:e=>s(K(e,d,b)),min:d,max:b,style:{width:64}})]});export const EffectsPanel=s(({store:a})=>{var l;const t=a.selectedElements,s=t[0],w=t.map(e=>e.id).join(","),k="effects"===a.openedSidePanel;if(r.useEffect(()=>{k&&(s&&s.filters||a.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"===s.type||"video"===s.type||"gif"===s.type,z=Math.min(s.width,s.height)/2,F=Math.min(null!==(l=s.cornerRadius)&&void 0!==l?l:0,z),R=e=>{a.history.transaction(()=>{t.forEach(a=>{a.set(e)})})},V=(e,o)=>{a.history.transaction(()=>{t.forEach(a=>{let r=Number(o);return 0==o||o||(r=a.filters.has(e)?null:1),d.includes(e)||a.set({grayscaleEnabled:"grayscale"===e&&!!o,sepiaEnabled:"sepia"===e&&!!o}),a.setFilter(e,r)})})};return o(X,{header:e(v,{title:b("sidePanel.effects"),onClose:()=>a.restoreSidePanel()}),children:[j&&e(u,{store:a}),S&&e("div",{style:{display:"flex",flexDirection:"column",gap:"16px",marginTop:"16px"},children:o("div",{style:{display:"flex",gap:"16px",flexWrap:"wrap"},children:[e(h,{active:s.grayscaleEnabled,onClick:()=>{V("grayscale",!s.grayscaleEnabled)},title:b("toolbar.grayscale"),imageSrc:s.src,effect:p.grayscale}),e(h,{active:s.sepiaEnabled,onClick:()=>{V("sepia",!s.sepiaEnabled)},title:b("toolbar.sepia"),imageSrc:s.src,effect:p.sepia}),e(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}),e(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}),e(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})]})}),e(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}),e(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(([a,o])=>{var r,l;return e(n,{label:b(o),visible:S,enabled:s.filters.has(a),onEnabledChange:e=>{V(a,e?0:null)},value:Math.round(100*(null!==(l=null===(r=s.filters.get(a))||void 0===r?void 0:r.intensity)&&void 0!==l?l:0)),onChange:e=>{V(a,e/100)},min:-100,max:100},a)}),j&&o(i,{label:b("toolbar.curvedText")||"Curved text",enabled:!!s.curveEnabled,onEnabledChange:e=>R({curveEnabled:e}),children:[e(g,{label:b("toolbar.curvePower")||"Curve",className:"pn:py-2",children:e(f,{value:Math.round(100*s.curvePower),onValueChange:e=>{R({curvePower:K(e,-100,100)/100})},style:{width:64},min:-100,max:100})}),e(m,{textEl:s,eachSet:R})]}),j&&o(i,{label:b("toolbar.textStroke"),enabled:!!s.strokeWidth,onEnabledChange:e=>R({strokeWidth:e?2:0}),children:[e(A,{store:a,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)}),e(g,{label:b("toolbar.strokeLineJoin"),className:"pn:py-2",children:e(C,{variant:"outline",value:[y(s.strokeLineJoin)],onValueChange:e=>{const a=e[0];a&&R({strokeLineJoin:a})},children:Y.map(({value:a,labelKey:o})=>e(x,{value:a,"aria-label":b(o),title:b(o),children:e($,{join:a})},a))})})]}),j&&o(i,{label:b("toolbar.textBackground"),enabled:!!s.backgroundEnabled,onEnabledChange:e=>R({backgroundEnabled:e}),children:[e(n,{label:b("toolbar.opacity"),value:Math.round(100*s.backgroundOpacity),onChange:e=>R({backgroundOpacity:e/100}),min:0,max:100}),e(g,{label:b("toolbar.color"),className:"pn:py-2",children:e(c,{value:s.backgroundColor,size:30,onChange:e=>{R({backgroundColor:e})},store:a})})]}),j&&e(i,{label:b("toolbar.border"),enabled:!!s.borderSize,onEnabledChange:e=>R({borderSize:e?2:0}),children:e(A,{store:a,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:[e(n,{label:b("toolbar.backgroundCornerRadius"),value:Math.round(100*s.backgroundCornerRadius),onChange:e=>R({backgroundCornerRadius:e/100}),min:0,max:200}),e(n,{label:b("toolbar.backgroundPadding"),value:Math.round(100*s.backgroundPadding),onChange:e=>R({backgroundPadding:e/100}),min:0,max:100})]}),S&&e(i,{label:b("toolbar.border"),enabled:!!s.borderSize,onEnabledChange:e=>R({borderSize:e?2:0}),children:e(A,{store:a,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&&e(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&&e(D,{store:a,elements:t}),o(i,{label:b("toolbar.shadow"),enabled:s.shadowEnabled,onEnabledChange:e=>R({shadowEnabled:e}),children:[e(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)}),e(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)}),e(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)}),e(n,{label:b("toolbar.opacity"),value:Math.round(100*s.shadowOpacity),onChange:e=>{R({shadowOpacity:e/100})},min:0,max:100}),e(g,{label:b("toolbar.color"),className:"pn:py-2",children:e(c,{value:s.shadowColor,size:30,onChange:e=>{R({shadowColor:e})},store:a})})]})]})});
@@ -0,0 +1,26 @@
1
+ export type LayerNode = {
2
+ id: string;
3
+ selectable: boolean;
4
+ children?: ReadonlyArray<LayerNode>;
5
+ };
6
+ export type LayerClickModifiers = {
7
+ shiftKey: boolean;
8
+ ctrlKey: boolean;
9
+ metaKey: boolean;
10
+ };
11
+ export declare function getLayerRows(container: {
12
+ children: ReadonlyArray<LayerNode>;
13
+ }, expandedIds: {
14
+ has(id: string): boolean;
15
+ }, isShown: (node: LayerNode) => boolean): string[];
16
+ export declare function getLayerClickSelection({ clickedId, selectedIds, anchorId, rows, modifiers, getParentId, }: {
17
+ clickedId: string;
18
+ selectedIds: ReadonlyArray<string>;
19
+ anchorId: string | null;
20
+ rows: ReadonlyArray<string>;
21
+ modifiers: LayerClickModifiers;
22
+ getParentId: (id: string) => string | null;
23
+ }): {
24
+ selectedIds: string[];
25
+ anchorId: string | null;
26
+ };
@@ -0,0 +1 @@
1
+ import{union as e}from"../utils/array.js";import{withoutDescendants as n}from"../utils/selection.js";export function getLayerRows(e,n,t){const r=[],c=e=>{for(let s=e.length-1;s>=0;s--){const d=e[s];t(d)&&(r.push(d.id),d.children&&n.has(d.id)&&c(d.children))}};return c(e.children),r}export function getLayerClickSelection({clickedId:t,selectedIds:r,anchorId:c,rows:s,modifiers:d,getParentId:i}){const l=d.ctrlKey||d.metaKey,o=()=>n(e(r,[t]),i);if(d.shiftKey){const d=function(e,n,t){return null!==e&&t.includes(e)&&n.includes(e)?e:1===n.length&&t.includes(n[0])?n[0]:null}(c,r,s);if(null!==d&&s.includes(t)){const c=s.indexOf(d),o=s.indexOf(t),u=s.slice(Math.min(c,o),Math.max(c,o)+1);return{selectedIds:n(e(l?r:[],u),i),anchorId:d}}return{selectedIds:o(),anchorId:t}}if(l){if(r.includes(t)){return{selectedIds:r.filter(e=>e!==t),anchorId:c}}const e=o();return{selectedIds:e,anchorId:e.includes(t)?t:c}}return{selectedIds:[t],anchorId:t}}
@@ -1 +1 @@
1
- import{jsx as e,jsxs as n}from"react/jsx-runtime";import i from"react";import{observer as t}from"mobx-react-lite";import{Button as l}from"../primitives/button.js";import{Input as r}from"../primitives/input.js";import{t as s}from"../utils/l10n.js";import{isMobile as a}from"../utils/screen.js";import{ReactSortable as o}from"react-sortablejs";import{removeTags as d}from"@polotno/core/text";import{PolotnoIcon as c}from"../icons/registry.js";import{cn as m}from"../lib/utils.js";import{PanelScrollArea as p}from"../primitives/panel-scroll-area.js";const h=t(({element:t,store:a})=>{const o=a.selectedElements.indexOf(t)>=0,[p,h]=i.useState(!1),v=()=>h(!1),u=p?t.name:t.name||d(t.text)||`#${t.id}`;return e("div",{onMouseDown:e=>{const n=e.ctrlKey||e.metaKey||e.shiftKey?[...a.selectedElementsIds]:[];n.indexOf(t.id)<0&&n.push(t.id),a.selectElements(n)},className:m("pn:rounded-md pn:border pn:bg-card pn:p-[5px] pn:mx-[1px] pn:mb-[5px] pn:shadow-sm",o&&"selected pn:border-primary pn:bg-primary/10"),style:{display:t.selectable||"admin"===a.role?"auto":"none"},children:n("div",{className:"pn:flex pn:items-center pn:justify-between",children:[n("div",{className:"pn:flex pn:min-w-0 pn:flex-1 pn:items-center",style:{lineHeight:"30px"},children:[e("div",{className:"drag-handle",style:{display:"flex",justifyContent:"center",alignItems:"center",cursor:"move",height:"30px"},children:e(c,{name:"action.dragHandle",className:"pn:size-4"})}),e("div",{style:{padding:"0 7px",opacity:.5,width:"60px"},children:s("sidePanel.layerTypes."+t.type)}),e("div",{className:"pn:min-w-0 pn:flex-1",children:e(r,{value:u,onFocus:()=>h(!0),onBlur:v,placeholder:s("sidePanel.namePlaceholder"),onChange:e=>{t.set({name:e.target.value})},onKeyDown:e=>{"Enter"!==e.key&&"Escape"!==e.key||(v(),e.target.blur())},className:"pn:h-7 pn:border-none pn:bg-transparent pn:dark:bg-transparent pn:px-1 pn:shadow-none pn:focus-visible:ring-1"})})]}),n("div",{className:"pn:flex pn:shrink-0",children:[e(l,{variant:"ghost",size:"icon-sm",onClick:()=>{t.set({visible:!t.visible})},children:(null==t?void 0:t.visible)?e(c,{name:"action.visible"}):e(c,{name:"action.hidden"})}),e(l,{variant:"ghost",size:"icon-sm",onClick:()=>{t.set({draggable:t.locked,contentEditable:t.locked,styleEditable:t.locked,resizable:t.locked,removable:t.locked})},children:(null==t?void 0:t.locked)?e(c,{name:"action.lock"}):e(c,{name:"action.unlock"})}),e(l,{variant:"ghost",size:"icon-sm",disabled:!t.removable,onClick:()=>{a.deleteElements([t.id])},style:{marginLeft:"auto"},children:e(c,{name:"action.remove"})})]})]})})});export const LayersPanel=t(({store:i})=>{var t;const l=(null===(t=i.activePage)||void 0===t?void 0:t.children.map(e=>({id:e.id})))||[];l.reverse();const r=a();return n(p,{children:[e("div",{style:{height:"40px",paddingTop:"5px"},children:s("sidePanel.layersTip")}),n("div",{children:[0===l.length?e("div",{children:s("sidePanel.noLayers")}):null,e(o,{list:l,setList:e=>{const n=e.filter(e=>null!=e&&null!=e.id);n.forEach((e,t)=>{var l,r;const s=n.length-t-1,a=String(e.id),o=i.getElementById(a),d=null===(l=i.activePage)||void 0===l?void 0:l.children.indexOf(o);o&&d!==s&&(null===(r=i.activePage)||void 0===r||r.setElementZIndex(o.id,s))})},direction:"horizontal",handle:r?".drag-handle":void 0,children:l.map(({id:n})=>{const t=i.getElementById(n);return e(h,{element:t,store:i},n)})})]})]})});
1
+ import{jsx as e,jsxs as n}from"react/jsx-runtime";import t from"react";import{action as i,observable as l,reaction as s}from"mobx";import{observer as r}from"mobx-react-lite";import{Button as o}from"../primitives/button.js";import{Input as a}from"../primitives/input.js";import{ROLES as d}from"../model/store.js";import{t as c}from"../utils/l10n.js";import{isMobile as m}from"../utils/screen.js";import{ReactSortable as p}from"react-sortablejs";import{removeTags as h}from"@polotno/core/text";import{PolotnoIcon as u}from"../icons/registry.js";import{cn as g}from"../lib/utils.js";import{PanelScrollArea as f}from"../primitives/panel-scroll-area.js";import{getLayerClickSelection as v,getLayerRows as x}from"./layer-selection.js";import{getParentGroupId as y}from"../utils/selection.js";const b=(e,n)=>!!n.selectable||e.role===d.ADMIN,E=e=>e.stopPropagation(),k=r(({element:i,ctx:l})=>{const{store:s,expandedIds:r}=l,d=s.selectedElements.indexOf(i)>=0,m="group"===i.type,p=m&&r.has(i.id),[f,v]=t.useState(!1),x=()=>v(!1),y=t.useRef(null),k=d&&1===s.selectedElements.length;t.useEffect(()=>{var e,n;k&&(null===(n=null===(e=y.current)||void 0===e?void 0:e.scrollIntoView)||void 0===n||n.call(e,{block:"nearest"}))},[k]);const w=()=>{s.highlightedElementId===i.id&&s.highlightElement(null)};t.useEffect(()=>w,[s,i.id]);const I=f?i.name:i.name||("text"in i?h(i.text):"")||`#${i.id}`;return n("div",{style:{display:b(s,i)?"auto":"none"},children:[e("div",{ref:y,"data-layer-id":i.id,onMouseDown:e=>{l.onRowMouseDown(i.id,e)},onPointerEnter:e=>{"mouse"===e.pointerType&&s.highlightElement(i.id)},onPointerLeave:w,className:g("pn:rounded-md pn:border pn:bg-card pn:p-[5px] pn:mx-[1px] pn:mb-[5px] pn:shadow-sm",d&&"selected pn:border-primary pn:bg-primary/10"),children:n("div",{className:"pn:flex pn:items-center pn:justify-between",children:[n("div",{className:"pn:flex pn:min-w-0 pn:flex-1 pn:items-center",style:{lineHeight:"30px"},children:[e("div",{className:"drag-handle",style:{display:"flex",justifyContent:"center",alignItems:"center",cursor:"move",height:"30px"},children:e(u,{name:"action.dragHandle",className:"pn:size-4"})}),e("div",{className:"pn:flex pn:size-5 pn:shrink-0 pn:items-center pn:justify-center",children:m?e(o,{variant:"ghost",size:"icon-sm",className:"pn:size-5","aria-expanded":p,onMouseDown:E,onClick:()=>l.toggleExpanded(i.id),children:e(u,{name:p?"ui.chevronDown":"ui.chevronRight",className:"pn:size-4"})}):null}),e("div",{style:{padding:"0 7px",opacity:.5,width:"60px"},children:c("sidePanel.layerTypes."+i.type)}),e("div",{className:"pn:min-w-0 pn:flex-1",children:e(a,{value:I,onFocus:()=>v(!0),onBlur:x,placeholder:c("sidePanel.namePlaceholder"),onChange:e=>{i.set({name:e.target.value})},onKeyDown:e=>{"Enter"!==e.key&&"Escape"!==e.key||(x(),e.target.blur())},className:"pn:h-7 pn:border-none pn:bg-transparent pn:dark:bg-transparent pn:px-1 pn:shadow-none pn:focus-visible:ring-1"})})]}),n("div",{className:"pn:flex pn:shrink-0",onMouseDown:E,children:[e(o,{variant:"ghost",size:"icon-sm",onClick:()=>{i.set({visible:!i.visible})},children:(null==i?void 0:i.visible)?e(u,{name:"action.visible"}):e(u,{name:"action.hidden"})}),e(o,{variant:"ghost",size:"icon-sm",onClick:()=>{i.set({draggable:i.locked,contentEditable:i.locked,styleEditable:i.locked,resizable:i.locked,removable:i.locked})},children:(null==i?void 0:i.locked)?e(u,{name:"action.lock"}):e(u,{name:"action.unlock"})}),e(o,{variant:"ghost",size:"icon-sm",disabled:!i.removable,onClick:()=>{s.deleteElements([i.id])},style:{marginLeft:"auto"},children:e(u,{name:"action.remove"})})]})]})}),p?e(j,{container:i,ctx:l}):null]})}),j=r(({container:n,ctx:t})=>{const{store:i}=t,l=n.children.slice().reverse(),s=l.map(e=>({id:e.id})),r=m(),o=n!==i.activePage;return e(p,{list:s,setList:e=>{const t=e.filter(e=>null!=e&&null!=e.id);t.forEach((e,l)=>{const s=t.length-l-1,r=i.getElementById(e.id);r&&n.children.indexOf(r)!==s&&n.setElementZIndex(r.id,s)})},group:n.id,direction:"horizontal",handle:r?".drag-handle":void 0,className:o?"pn:ml-4":void 0,children:l.map(n=>e(k,{element:n,ctx:t},n.id))})});export const LayersPanel=r(({store:r})=>{const o=r.activePage,[a]=t.useState(()=>l.map()),d=t.useRef(null);t.useEffect(()=>s(()=>{const e=[];return r.selectedElements.forEach(n=>{for(let t=n.parent;t&&"group"===t.type;t=t.parent){e.push(t.id)}}),e},i(e=>{e.forEach(e=>a.set(e,!0))}),{equals:(e,n)=>e.length===n.length&&e.every((e,t)=>e===n[t]),fireImmediately:!0}),[r,a]);const m=t.useMemo(()=>({store:r,expandedIds:a,toggleExpanded:i(e=>{a.delete(e)||a.set(e,!0)}),onRowMouseDown:(e,n)=>{const t=r.activePage;if(!t){return}const i=v({clickedId:e,selectedIds:r.selectedElementsIds,anchorId:d.current,rows:x(t,a,e=>b(r,e)),modifiers:n,getParentId:e=>y(r,e)});d.current=i.anchorId,r.selectElements(i.selectedIds)}}),[r,a]);return n(f,{children:[e("div",{style:{height:"40px",paddingTop:"5px"},children:c("sidePanel.layersTip")}),n("div",{children:[o&&0!==o.children.length?null:e("div",{children:c("sidePanel.noLayers")}),o?e(j,{container:o,ctx:m}):null]})]})});
@@ -147,6 +147,7 @@ export declare const selectVideo: ({ src, droppedPos, targetElement, store, attr
147
147
  showInExport: boolean;
148
148
  }>>;
149
149
  readonly parent: any;
150
+ readonly isHighlighted: boolean;
150
151
  readonly zIndex: any;
151
152
  } & {
152
153
  toJSON(): {
@@ -353,6 +354,7 @@ export declare const selectVideo: ({ src, droppedPos, targetElement, store, attr
353
354
  showInExport: boolean;
354
355
  }>>;
355
356
  readonly parent: any;
357
+ readonly isHighlighted: boolean;
356
358
  readonly zIndex: any;
357
359
  } & {
358
360
  toJSON(): {
@@ -1 +1 @@
1
- var e=this&&this.__rest||function(e,n){var i={};for(var t in e){Object.prototype.hasOwnProperty.call(e,t)&&n.indexOf(t)<0&&(i[t]=e[t])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var a=0;for(t=Object.getOwnPropertySymbols(e);a<t.length;a++){n.indexOf(t[a])<0&&Object.prototype.propertyIsEnumerable.call(e,t[a])&&(i[t[a]]=e[t[a]])}}return i};import{jsx as n,jsxs as i,Fragment as t}from"react/jsx-runtime";import*as a from"react";import{observer as s}from"mobx-react-lite";import{PolotnoIcon as p}from"../icons/registry.js";import{t as r}from"../utils/l10n.js";import{cn as o}from"../lib/utils.js";import{pxToUnit as l,pxToUnitRounded as d,unitToPx as c}from"../utils/unit.js";import{Button as m}from"../primitives/button.js";import{Input as u}from"../primitives/input.js";import{Switch as h}from"../primitives/switch.js";import{Select as x,SelectContent as v,SelectItem as b,SelectTrigger as g,SelectValue as f}from"../primitives/select.js";import{Tooltip as z,TooltipContent as N,TooltipTrigger as w}from"../primitives/tooltip.js";import{PanelScrollArea as y}from"../primitives/panel-scroll-area.js";export const SIZE_CATEGORIES=[{name:"Instagram",icon:n(p,{name:"size.instagram"}),sizes:[["Post",1080,1080,"px",n(p,{name:"size.instagram"})],["Story",1080,1920,"px",n(p,{name:"size.instagram"})],["Ad",1080,1080,"px",n(p,{name:"size.instagram"})]]},{name:"Facebook",icon:n(p,{name:"size.facebook"}),sizes:[["Post (Landscape)",1200,630,"px",n(p,{name:"size.facebook"})],["Post (Square)",1080,1080,"px",n(p,{name:"size.facebook"})],["Cover",851,315,"px",n(p,{name:"size.facebook"})]]},{name:"Youtube",icon:n(p,{name:"size.youtube"}),sizes:[["Thumbnail",1280,720,"px",n(p,{name:"size.youtube"})],["Channel",2560,1440,"px",n(p,{name:"size.youtube"})],["Short",1080,1920,"px",n(p,{name:"size.youtube"})]]},{name:"LinkedIn",icon:n(p,{name:"size.linkedin"}),sizes:[["Post",1200,627,"px",n(p,{name:"size.linkedin"})],["Banner",1584,396,"px",n(p,{name:"size.linkedin"})],["Square",1080,1080,"px",n(p,{name:"size.linkedin"})]]},{name:"Twitter",icon:n(p,{name:"size.twitter"}),sizes:[["Post",1600,900,"px",n(p,{name:"size.twitter"})],["Header",1500,500,"px",n(p,{name:"size.twitter"})],["Square",1080,1080,"px",n(p,{name:"size.twitter"})]]},{name:"Video",icon:n(p,{name:"size.video"}),sizes:[["Full HD",1920,1080,"px",n(p,{name:"size.video"})],["4K UHD",3840,2160,"px",n(p,{name:"size.video"})],["Vertical HD",1080,1920,"px",n(p,{name:"size.video"})],["Square HD",1080,1080,"px",n(p,{name:"size.video"})]]},{name:"Print",icon:n(p,{name:"size.print"}),sizes:[["Invitation",14,14,"cm",n(p,{name:"size.print"})],["A4 Portrait",21,29.7,"cm",n(p,{name:"size.print"})],["A4 Landscape",29.7,21,"cm",n(p,{name:"size.print"})],["A3",29.7,42,"cm",n(p,{name:"size.print"})],["Letter Portrait",8.5,11,"in",n(p,{name:"size.print"})],["Letter Landscape",11,8.5,"in",n(p,{name:"size.print"})],["Business card",3.5,2,"in",n(p,{name:"size.businessCard"})],["Poster",18,24,"in",n(p,{name:"size.print"})]]}];const k=t=>{var{value:s,onChange:r}=t,l=e(t,["value","onChange"]);const[d,c]=a.useState(s.toString()),m=a.useRef(s);m.current=d;const h=()=>{r(Math.max(l.min||0,parseFloat(m.current)))};a.useEffect(()=>{c(String(s))},[s]);const x=Number(l.step)||1,v=e=>{const n=parseFloat(m.current);let i=(Number.isNaN(n)?Number(s)||0:n)+e*x;"number"==typeof l.min&&(i=Math.max(l.min,i)),"number"==typeof l.max&&(i=Math.min(l.max,i)),i=parseFloat(i.toFixed(4)),c(String(i)),r(i)},{className:b}=l,g=e(l,["className"]);return i("div",{className:"pn:relative",children:[n(u,Object.assign({},g,{type:"number",value:d.toString(),className:o("pn:pr-6 pn:[appearance:textfield] pn:[&::-webkit-inner-spin-button]:appearance-none pn:[&::-webkit-outer-spin-button]:appearance-none",b),onChange:e=>{const n=e.target.value;Number.isNaN(parseFloat(n))?""===n&&c(n):c(n)},onBlur:h,onFocus:e=>e.target.select(),onKeyDown:e=>{"Enter"===e.key&&h()}})),i("div",{className:"pn:absolute pn:inset-y-0 pn:right-0 pn:flex pn:w-5 pn:flex-col pn:border-l pn:border-input",children:[n("button",{type:"button",tabIndex:-1,"aria-label":"Increment",className:"pn:flex pn:flex-1 pn:appearance-none pn:cursor-pointer pn:items-center pn:justify-center pn:border-0 pn:bg-transparent pn:text-muted-foreground pn:hover:bg-muted pn:hover:text-foreground",onClick:()=>v(1),children:n(p,{name:"ui.chevronUp",className:"pn:size-3"})}),n("button",{type:"button",tabIndex:-1,"aria-label":"Decrement",className:"pn:flex pn:flex-1 pn:appearance-none pn:cursor-pointer pn:items-center pn:justify-center pn:border-0 pn:border-t pn:border-input pn:bg-transparent pn:text-muted-foreground pn:hover:bg-muted pn:hover:text-foreground",onClick:()=>v(-1),children:n(p,{name:"ui.chevronDown",className:"pn:size-3"})})]})]})},P=({width:e,height:i})=>{const t=e/i,a=t>=1?18:Math.max(4,18*t),s=t>=1?Math.max(4,18/t):18;return n("span",{className:"pn:flex pn:size-5 pn:shrink-0 pn:items-center pn:justify-center pn:text-muted-foreground",children:n("span",{className:"pn:rounded-[2px] pn:border pn:border-current",style:{width:a,height:s}})})};export const SizePanel=s(({store:e})=>{var s,o,u,j;const[S,C]=a.useState(!0),[B,E]=a.useState(!1),[O,F]=a.useState(e.width),[I,D]=a.useState(e.height),V=l({px:10,unit:e.unit,dpi:e.dpi}),L=(null===(s=e.activePage)||void 0===s?void 0:s.computedWidth)||e.width;a.useEffect(()=>{F(d({px:L,unit:e.unit,dpi:e.dpi}))},[L,e.unit,e.dpi]);const R=(null===(o=e.activePage)||void 0===o?void 0:o.computedHeight)||e.height;a.useEffect(()=>{D(d({px:R,unit:e.unit,dpi:e.dpi}))},[R,e.unit,e.dpi]);const A=(n,i,t)=>{var a,s,p,r;e.setSize(n,i,t),"auto"!==(null===(a=e.activePage)||void 0===a?void 0:a.width)&&(null===(s=e.activePage)||void 0===s||s.set({width:n})),"auto"!==(null===(p=e.activePage)||void 0===p?void 0:p.height)&&(null===(r=e.activePage)||void 0===r||r.set({height:i}))},H=d({px:null!==(j=null===(u=e.activePage)||void 0===u?void 0:u.computedBleed.top)&&void 0!==j?j:0,unit:e.unit,dpi:e.dpi});return i(y,{children:[i("div",{style:{paddingBottom:"15px"},children:[i("label",{className:"pn:flex pn:items-center pn:justify-between",style:{marginTop:"8px",marginBottom:"25px"},children:[i("span",{className:"pn:flex pn:items-center pn:gap-1.5",children:[r("sidePanel.useMagicResize")," ",i(z,{children:[n(w,{render:n("span",{className:"pn:inline-flex",children:n(p,{name:"action.help",className:"pn:size-4"})})}),n(N,{children:r("sidePanel.magicResizeDescription")})]})]}),n(h,{checked:S,onCheckedChange:e=>{C(Boolean(e))}})]}),i("div",{className:"pn:inline-block pn:w-1/2",children:[r("sidePanel.width")," (",e.unit,")"]}),n("div",{className:"pn:inline-block pn:w-1/2",children:n(k,{value:O,onChange:e=>{e||(e=V),F(e)},min:V,max:1e4,step:"px"===e.unit?1:.1})})]}),i("div",{style:{paddingBottom:"15px"},children:[i("div",{className:"pn:inline-block pn:w-1/2",children:[r("sidePanel.height")," (",e.unit,")"]}),n("div",{className:"pn:inline-block pn:w-1/2",children:n(k,{value:I,onChange:e=>{e||(e=V),D(e)},min:V,max:1e4,step:"px"===e.unit?1:.1})})]}),i("div",{style:{paddingBottom:"15px"},children:[n("div",{className:"pn:inline-block pn:w-1/2",children:r("sidePanel.units")}),n("div",{className:"pn:inline-block pn:w-1/2",children:i(x,{value:e.unit,onValueChange:n=>{const i=n;e.setUnit({unit:i,dpi:e.dpi})},children:[n(g,{className:"pn:w-full",children:n(f,{})}),i(v,{children:[n(b,{value:"px",children:"px"}),n(b,{value:"cm",children:"cm"}),n(b,{value:"in",children:"in"})]})]})})]}),n("div",{style:{paddingBottom:"15px"},children:n(m,{className:"pn:w-full",variant:"default",onClick:()=>{const n=c({unitVal:O,dpi:e.dpi,unit:e.unit}),i=c({unitVal:I,dpi:e.dpi,unit:e.unit});A(n,i,S)},children:r("sidePanel.resize")})}),i(m,{variant:"ghost",className:"pn:mb-1.5 pn:w-full pn:justify-start pn:gap-1 pn:px-2 pn:text-[13px] pn:font-normal pn:text-muted-foreground",onClick:()=>E(!B),children:[n(p,{name:B?"ui.chevronDown":"ui.chevronRight",className:"pn:size-3"}),r("sidePanel.advanced")]}),B&&i(t,{children:[i("div",{style:{paddingBottom:"15px"},children:[i("div",{className:"pn:inline-block pn:w-1/2",children:[r("sidePanel.bleed")," (",e.unit,")"]}),n("div",{className:"pn:inline-block pn:w-1/2",children:n(k,{"aria-label":"bleed",value:H,onChange:n=>{if(!Number.isFinite(n)){return}const i=c({unitVal:n,dpi:e.dpi,unit:e.unit});e.pages.forEach(e=>{e.set({bleed:i,bleedTop:void 0,bleedRight:void 0,bleedBottom:void 0,bleedLeft:void 0})}),i>0&&e.toggleBleed(!0)},min:0,max:1e3,step:"px"===e.unit?1:.1})})]}),i("label",{className:"pn:flex pn:items-center pn:justify-between",style:{paddingBottom:"15px"},children:[n("span",{children:r("sidePanel.showBleed")}),n(h,{"aria-label":"show bleed",checked:e.bleedVisible,onCheckedChange:n=>{e.toggleBleed(Boolean(n))}})]})]}),SIZE_CATEGORIES.map(({name:t,icon:s,sizes:p})=>i(a.Fragment,{children:[i("div",{className:"pn:flex pn:items-center pn:gap-1.5 pn:pt-3 pn:pb-1 pn:text-[13px] pn:font-semibold",children:[s,t]}),n("div",{className:"pn:mb-1.5 pn:flex pn:flex-col",children:p.map(([t,a,s,p])=>i(m,{variant:"ghost",className:"pn:h-9 pn:w-full pn:justify-start pn:gap-2.5 pn:px-2 pn:text-[13px] pn:font-normal",onClick:()=>{const n=c({unitVal:a,dpi:e.dpi,unit:p}),i=c({unitVal:s,dpi:e.dpi,unit:p});e.setUnit({unit:p,dpi:e.dpi}),A(n,i,S)},children:[n(P,{width:a,height:s}),n("span",{className:"pn:truncate",children:t}),i("span",{className:"pn:ml-auto pn:shrink-0 pn:text-xs pn:text-muted-foreground",children:[a,"×",s," ",p]})]},t))})]},t))]})});
1
+ import{jsx as e,jsxs as i,Fragment as n}from"react/jsx-runtime";import*as t from"react";import{observer as a}from"mobx-react-lite";import{PolotnoIcon as s}from"../icons/registry.js";import{t as p}from"../utils/l10n.js";import{pxToUnit as l,pxToUnitRounded as d,unitToPx as o}from"../utils/unit.js";import{Button as r}from"../primitives/button.js";import{Switch as m}from"../primitives/switch.js";import{Select as c,SelectContent as u,SelectItem as h,SelectTrigger as x,SelectValue as v}from"../primitives/select.js";import{Tooltip as g,TooltipContent as z,TooltipTrigger as f}from"../primitives/tooltip.js";import{PanelScrollArea as b}from"../primitives/panel-scroll-area.js";import{NumericInputDelayed as w}from"../primitives/numeric-input-delayed.js";export const SIZE_CATEGORIES=[{name:"Instagram",icon:e(s,{name:"size.instagram"}),sizes:[["Post",1080,1080,"px",e(s,{name:"size.instagram"})],["Story",1080,1920,"px",e(s,{name:"size.instagram"})],["Ad",1080,1080,"px",e(s,{name:"size.instagram"})]]},{name:"Facebook",icon:e(s,{name:"size.facebook"}),sizes:[["Post (Landscape)",1200,630,"px",e(s,{name:"size.facebook"})],["Post (Square)",1080,1080,"px",e(s,{name:"size.facebook"})],["Cover",851,315,"px",e(s,{name:"size.facebook"})]]},{name:"Youtube",icon:e(s,{name:"size.youtube"}),sizes:[["Thumbnail",1280,720,"px",e(s,{name:"size.youtube"})],["Channel",2560,1440,"px",e(s,{name:"size.youtube"})],["Short",1080,1920,"px",e(s,{name:"size.youtube"})]]},{name:"LinkedIn",icon:e(s,{name:"size.linkedin"}),sizes:[["Post",1200,627,"px",e(s,{name:"size.linkedin"})],["Banner",1584,396,"px",e(s,{name:"size.linkedin"})],["Square",1080,1080,"px",e(s,{name:"size.linkedin"})]]},{name:"Twitter",icon:e(s,{name:"size.twitter"}),sizes:[["Post",1600,900,"px",e(s,{name:"size.twitter"})],["Header",1500,500,"px",e(s,{name:"size.twitter"})],["Square",1080,1080,"px",e(s,{name:"size.twitter"})]]},{name:"Video",icon:e(s,{name:"size.video"}),sizes:[["Full HD",1920,1080,"px",e(s,{name:"size.video"})],["4K UHD",3840,2160,"px",e(s,{name:"size.video"})],["Vertical HD",1080,1920,"px",e(s,{name:"size.video"})],["Square HD",1080,1080,"px",e(s,{name:"size.video"})]]},{name:"Print",icon:e(s,{name:"size.print"}),sizes:[["Invitation",14,14,"cm",e(s,{name:"size.print"})],["A4 Portrait",21,29.7,"cm",e(s,{name:"size.print"})],["A4 Landscape",29.7,21,"cm",e(s,{name:"size.print"})],["A3",29.7,42,"cm",e(s,{name:"size.print"})],["Letter Portrait",8.5,11,"in",e(s,{name:"size.print"})],["Letter Landscape",11,8.5,"in",e(s,{name:"size.print"})],["Business card",3.5,2,"in",e(s,{name:"size.businessCard"})],["Poster",18,24,"in",e(s,{name:"size.print"})]]}];const k=({width:i,height:n})=>{const t=i/n,a=t>=1?18:Math.max(4,18*t),s=t>=1?Math.max(4,18/t):18;return e("span",{className:"pn:flex pn:size-5 pn:shrink-0 pn:items-center pn:justify-center pn:text-muted-foreground",children:e("span",{className:"pn:rounded-[2px] pn:border pn:border-current",style:{width:a,height:s}})})};export const SizePanel=a(({store:a})=>{var P,N,y,j;const[B,C]=t.useState(!0),[S,E]=t.useState(!1),[V,I]=t.useState(a.width),[L,A]=t.useState(a.height),D=l({px:10,unit:a.unit,dpi:a.dpi}),H=(null===(P=a.activePage)||void 0===P?void 0:P.computedWidth)||a.width;t.useEffect(()=>{I(d({px:H,unit:a.unit,dpi:a.dpi}))},[H,a.unit,a.dpi]);const R=(null===(N=a.activePage)||void 0===N?void 0:N.computedHeight)||a.height;t.useEffect(()=>{A(d({px:R,unit:a.unit,dpi:a.dpi}))},[R,a.unit,a.dpi]);const T=(e,i,n)=>{var t,s,p,l;a.setSize(e,i,n),"auto"!==(null===(t=a.activePage)||void 0===t?void 0:t.width)&&(null===(s=a.activePage)||void 0===s||s.set({width:e})),"auto"!==(null===(p=a.activePage)||void 0===p?void 0:p.height)&&(null===(l=a.activePage)||void 0===l||l.set({height:i}))},F=d({px:null!==(j=null===(y=a.activePage)||void 0===y?void 0:y.computedBleed.top)&&void 0!==j?j:0,unit:a.unit,dpi:a.dpi});return i(b,{children:[i("div",{style:{paddingBottom:"15px"},children:[i("label",{className:"pn:flex pn:items-center pn:justify-between",style:{marginTop:"8px",marginBottom:"25px"},children:[i("span",{className:"pn:flex pn:items-center pn:gap-1.5",children:[p("sidePanel.useMagicResize")," ",i(g,{children:[e(f,{render:e("span",{className:"pn:inline-flex",children:e(s,{name:"action.help",className:"pn:size-4"})})}),e(z,{children:p("sidePanel.magicResizeDescription")})]})]}),e(m,{checked:B,onCheckedChange:e=>{C(Boolean(e))}})]}),i("div",{className:"pn:inline-block pn:w-1/2",children:[p("sidePanel.width")," (",a.unit,")"]}),e("div",{className:"pn:inline-block pn:w-1/2",children:e(w,{value:V,onChange:e=>{e||(e=D),I(e)},min:D,max:1e4,step:"px"===a.unit?1:.1})})]}),i("div",{style:{paddingBottom:"15px"},children:[i("div",{className:"pn:inline-block pn:w-1/2",children:[p("sidePanel.height")," (",a.unit,")"]}),e("div",{className:"pn:inline-block pn:w-1/2",children:e(w,{value:L,onChange:e=>{e||(e=D),A(e)},min:D,max:1e4,step:"px"===a.unit?1:.1})})]}),i("div",{style:{paddingBottom:"15px"},children:[e("div",{className:"pn:inline-block pn:w-1/2",children:p("sidePanel.units")}),e("div",{className:"pn:inline-block pn:w-1/2",children:i(c,{value:a.unit,onValueChange:e=>{const i=e;a.setUnit({unit:i,dpi:a.dpi})},children:[e(x,{className:"pn:w-full",children:e(v,{})}),i(u,{children:[e(h,{value:"px",children:"px"}),e(h,{value:"cm",children:"cm"}),e(h,{value:"in",children:"in"})]})]})})]}),e("div",{style:{paddingBottom:"15px"},children:e(r,{className:"pn:w-full",variant:"default",onClick:()=>{const e=o({unitVal:V,dpi:a.dpi,unit:a.unit}),i=o({unitVal:L,dpi:a.dpi,unit:a.unit});T(e,i,B)},children:p("sidePanel.resize")})}),i(r,{variant:"ghost",className:"pn:mb-1.5 pn:w-full pn:justify-start pn:gap-1 pn:px-2 pn:text-[13px] pn:font-normal pn:text-muted-foreground",onClick:()=>E(!S),children:[e(s,{name:S?"ui.chevronDown":"ui.chevronRight",className:"pn:size-3"}),p("sidePanel.advanced")]}),S&&i(n,{children:[i("div",{style:{paddingBottom:"15px"},children:[i("div",{className:"pn:inline-block pn:w-1/2",children:[p("sidePanel.bleed")," (",a.unit,")"]}),e("div",{className:"pn:inline-block pn:w-1/2",children:e(w,{"aria-label":"bleed",value:F,onChange:e=>{if(!Number.isFinite(e)){return}const i=o({unitVal:e,dpi:a.dpi,unit:a.unit});a.pages.forEach(e=>{e.set({bleed:i,bleedTop:void 0,bleedRight:void 0,bleedBottom:void 0,bleedLeft:void 0})}),i>0&&a.toggleBleed(!0)},min:0,max:1e3,step:"px"===a.unit?1:.1})})]}),i("label",{className:"pn:flex pn:items-center pn:justify-between",style:{paddingBottom:"15px"},children:[e("span",{children:p("sidePanel.showBleed")}),e(m,{"aria-label":"show bleed",checked:a.bleedVisible,onCheckedChange:e=>{a.toggleBleed(Boolean(e))}})]})]}),SIZE_CATEGORIES.map(({name:n,icon:s,sizes:p})=>i(t.Fragment,{children:[i("div",{className:"pn:flex pn:items-center pn:gap-1.5 pn:pt-3 pn:pb-1 pn:text-[13px] pn:font-semibold",children:[s,n]}),e("div",{className:"pn:mb-1.5 pn:flex pn:flex-col",children:p.map(([n,t,s,p])=>i(r,{variant:"ghost",className:"pn:h-9 pn:w-full pn:justify-start pn:gap-2.5 pn:px-2 pn:text-[13px] pn:font-normal",onClick:()=>{const e=o({unitVal:t,dpi:a.dpi,unit:p}),i=o({unitVal:s,dpi:a.dpi,unit:p});a.setUnit({unit:p,dpi:a.dpi}),T(e,i,B)},children:[e(k,{width:t,height:s}),e("span",{className:"pn:truncate",children:n}),i("span",{className:"pn:ml-auto pn:shrink-0 pn:text-xs pn:text-muted-foreground",children:[t,"×",s," ",p]})]},n))})]},n))]})});
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import type { StoreType } from '../ui-types.js';
3
+ export declare const TextEffectPresets: (({ store }: {
4
+ store: StoreType;
5
+ }) => React.JSX.Element | null) & React.NamedExoticComponent<{
6
+ store: StoreType;
7
+ }> & {
8
+ readonly type: ({ store }: {
9
+ store: StoreType;
10
+ }) => React.JSX.Element | null;
11
+ };
@@ -0,0 +1 @@
1
+ import{jsx as t,jsxs as e}from"react/jsx-runtime";import{observer as o}from"mobx-react-lite";import n from"tinycolor2";import{firstStopColor as r}from"@polotno/core/gradient";import{toDisplayColor as s}from"@polotno/core/color";import{elementDropShadow as a}from"@polotno/core/filters";import{applyOpacityToColor as i}from"@polotno/core/svg";import{cn as d}from"../lib/utils.js";import{t as c}from"../utils/l10n.js";const l={strokeWidth:0,shadowEnabled:!1,backgroundEnabled:!1},b=t=>Math.round(100*t)/100,p=t=>s(r(t.fill)),f=(t,e)=>{const o=p(t),r=n(o).getLuminance()>.5;return n.mix(o,r?"black":"white",e).toHexString()},g=t=>{const e=p(t),o=n(e).getLuminance()<.05;return n.mix(e,o?"white":"black",55).toHexString()},u=(t,e)=>({stroke:t,strokeWidth:b(e),strokeLineJoin:"round"}),k=(t,e,o,n,r)=>({shadowEnabled:!0,shadowColor:t,shadowOpacity:e,shadowBlur:b(o),shadowOffsetX:b(n),shadowOffsetY:b(r)}),m={fill:"#2563eb",fontSize:28},h=t=>{var e,o,n,r,s,d,c;const l={color:p(m),fontSize:m.fontSize};if(t.strokeWidth&&t.stroke&&(l.WebkitTextStroke=`${t.strokeWidth}px ${t.stroke}`,l.paintOrder="stroke fill"),t.shadowEnabled&&(l.filter=a({shadowOffsetX:null!==(e=t.shadowOffsetX)&&void 0!==e?e:0,shadowOffsetY:null!==(o=t.shadowOffsetY)&&void 0!==o?o:0,shadowBlur:null!==(n=t.shadowBlur)&&void 0!==n?n:0,shadowColor:null!==(r=t.shadowColor)&&void 0!==r?r:"black",shadowOpacity:t.shadowOpacity})),t.backgroundEnabled&&t.backgroundColor){const e=1.2*m.fontSize/2;l.background=i(t.backgroundColor,null!==(s=t.backgroundOpacity)&&void 0!==s?s:1),l.borderRadius=(null!==(d=t.backgroundCornerRadius)&&void 0!==d?d:0)*e,l.padding=`0 ${(null!==(c=t.backgroundPadding)&&void 0!==c?c:0)*e}px`}return l},O=[{key:"none",attrs:()=>l},{key:"shadow",attrs:({fontSize:t})=>Object.assign(Object.assign({},l),k("black",.4,.05*t,.05*t,.05*t))},{key:"lift",attrs:({fontSize:t})=>Object.assign(Object.assign({},l),k("black",.35,.2*t,0,.04*t))},{key:"glow",attrs:t=>Object.assign(Object.assign({},l),k(p(t),1,.25*t.fontSize,0,0))},{key:"outline",attrs:t=>Object.assign(Object.assign({},l),u(g(t),.12*t.fontSize))},{key:"sticker",attrs:t=>Object.assign(Object.assign(Object.assign({},l),u(f(t,90),.24*t.fontSize)),k("black",.3,.12*t.fontSize,0,.04*t.fontSize))},{key:"pop",attrs:t=>{const e=g(t),o=t.fontSize;return Object.assign(Object.assign(Object.assign({},l),u(e,.1*o)),k(e,1,0,.06*o,.06*o))}},{key:"background",attrs:t=>Object.assign(Object.assign({},l),{backgroundEnabled:!0,backgroundColor:f(t,75),backgroundOpacity:1,backgroundCornerRadius:.5,backgroundPadding:.5})}].map(t=>Object.assign(Object.assign({},t),{preview:h(t.attrs(m))})),w=(t,e)=>Object.entries(e).every(([e,o])=>t[e]===o);export const TextEffectPresets=o(({store:o})=>{const n=o.selectedElements.filter(t=>"text"===t.type),r=n[0];return r&&n.length===o.selectedElements.length?t("div",{className:"pn:mt-4 pn:mb-2 pn:grid pn:grid-cols-3 pn:gap-2",children:O.map(({key:s,attrs:a,preview:i})=>e("button",{type:"button",className:"pn:flex pn:flex-col pn:items-center pn:gap-1 pn:text-sm",onClick:()=>{o.history.transaction(()=>{n.forEach(t=>t.set(a(t)))})},children:[t("span",{"data-active":w(r,a(r))?"true":void 0,className:d("pn:flex pn:h-16 pn:w-full pn:items-center pn:justify-center pn:rounded-md pn:border-2 pn:border-border pn:bg-white pn:font-bold","pn:data-[active=true]:border-primary"),children:t("span",{style:i,"aria-hidden":"true",children:"Aa"})}),c(`toolbar.textEffect.${s}`)]},s))}):null});
@@ -1 +1 @@
1
- import{jsx as e}from"react/jsx-runtime";import{observer as o}from"mobx-react-lite";import{ElementContainer as t,extendToolbar as r}from"./element-container.js";import{AnimationsPicker as n}from"./animations-picker.js";import{flags as s}from"../utils/flags.js";const m={GroupAnimations:n};export const GroupToolbar=o(({store:o,components:n})=>{const i=o.selectedElements,p=[s.animationsEnabled&&"GroupAnimations"],a=r({type:"group",usedItems:p,components:n});return e(t,{items:a,itemRender:t=>{const r=n[t]||m[t];return e(r,{elements:i,element:i[0],store:o},t)}})});export default GroupToolbar;
1
+ import{jsx as o}from"react/jsx-runtime";import{observer as e}from"mobx-react-lite";import{ElementContainer as t,extendToolbar as r}from"./element-container.js";import{AnimationsPicker as s}from"./animations-picker.js";import{SelectionColors as m}from"./selection-colors.js";import{FitToPageButton as n}from"./selection-size.js";import{flags as i}from"../utils/flags.js";const p={GroupColors:m,GroupFitToPage:n,GroupAnimations:s};export const GroupToolbar=e(({store:e,components:s})=>{const m=e.selectedElements,n=["GroupColors","GroupFitToPage",i.animationsEnabled&&"GroupAnimations"],a=r({type:"group",usedItems:n,components:s});return o(t,{items:a,itemRender:t=>{const r=s[t]||p[t];return o(r,{elements:m,element:m[0],store:e},t)}})});export default GroupToolbar;
@@ -7,9 +7,10 @@ type Props = {
7
7
  store: StoreType;
8
8
  components?: any;
9
9
  };
10
- export declare const ImageFitToBackground: ({ element, }: {
10
+ export declare const ImageFitToBackground: ({ element, elements, }: {
11
11
  element: ImageElementType;
12
- }) => React.JSX.Element;
12
+ elements?: ImageElementType[];
13
+ }) => React.JSX.Element | null;
13
14
  export declare const ImageClip: (({ element, store, elements, }: {
14
15
  element: ImageElementType;
15
16
  store: StoreType;
@@ -1 +1 @@
1
- import{jsx as e,jsxs as o}from"react/jsx-runtime";import{observer as t}from"mobx-react-lite";import{Button as r}from"../primitives/button.js";import{Tooltip as i,TooltipContent as a,TooltipTrigger as n}from"../primitives/tooltip.js";import{ElementContainer as m,extendToolbar as s}from"./element-container.js";import{PolotnoIcon as l}from"../icons/registry.js";import c from"./filters-picker.js";import{AnimationsPicker as p}from"./animations-picker.js";import g from"./flip-button.js";import{flags as d}from"../utils/flags.js";import{ImageRemoveBackground as u}from"./image-remove-background-button.js";export{ImageRemoveBackground}from"./image-remove-background-button.js";import{getCrop as h,getImageSize as f}from"@polotno/core/image";import{t as C}from"../utils/l10n.js";import{isImageLoadError as I}from"../utils/errors.js";import{ImageEdit as b}from"./image-tools.js";export{ImageEdit,ImageToolActions}from"./image-tools.js";export const ImageFitToBackground=({element:o})=>e(r,{variant:"ghost",size:"sm",onClick:async()=>{const{page:e}=o,t=e.computedBleed,r=e.computedWidth+t.left+t.right,i=e.computedHeight+t.top+t.bottom,a=await f(o.src).catch(e=>{if(!I(e)){throw e}return console.warn("polotno: failed to fit the image to the background",e),null});if(!a){return}const n=o.stretchEnabled?{cropX:0,cropY:0,cropWidth:1,cropHeight:1}:h({width:r,height:i},a);o.set(Object.assign({x:-t.left,y:-t.top,width:r,height:i,rotation:0},n))},children:C("toolbar.fitToBackground")});export const ImageClip=t(({element:o,store:t,elements:i})=>o.contentEditable?o.clipSrc?e(r,{variant:"ghost",size:"sm",onClickCapture:()=>{i.forEach(e=>{e.set({clipSrc:""})})},children:C("toolbar.removeClip")}):e(r,{variant:"ghost",size:"sm",onClickCapture:e=>{e.stopPropagation(),t.openSidePanel("image-clip")},children:C("toolbar.clip")}):null);export const ImageCrop=t(({element:t})=>t._cropEnabled?o(i,{children:[e(n,{render:e(r,{variant:"ghost",size:"icon-sm",onClickCapture:e=>{e.stopPropagation(),t.toggleCropMode(!0)},"aria-label":C("toolbar.crop"),children:e(l,{name:"toolbar.crop",className:"pn:size-4"})})}),e(a,{children:C("toolbar.crop")})]}):null);export const CropModeBar=t(({element:t})=>o("div",{className:"pn:flex pn:items-center",children:[o(r,{variant:"ghost",size:"sm",onClickCapture:()=>{t.toggleCropMode(!1)},children:[e(l,{name:"action.confirm",className:"pn:size-4"}),C("toolbar.cropDone")]}),o(r,{variant:"ghost",size:"sm",onClickCapture:()=>{t.cancelCropMode()},children:[e(l,{name:"action.close",className:"pn:size-4"}),C("toolbar.cropCancel")]})]}));export const ImageRemoveClip=t(({element:o})=>o.clipSrc?e(r,{variant:"ghost",size:"sm",onClickCapture:()=>{o.set({clipSrc:""})},children:C("toolbar.removeClip")}):null);const k={ImageFlip:g,ImageFilters:c,ImageFitToBackground,ImageCrop,ImageEdit:b,ImageClip,ImageRemoveBackground:u,ImageAnimations:p};export const ImageToolbar=t(({store:o,components:t})=>{const r=o.selectedElements[0],i=["ImageCrop","ImageEdit","ImageFlip","ImageFilters","ImageFitToBackground","ImageClip",d.animationsEnabled&&"ImageAnimations"],a=s({type:"image",usedItems:i,components:t});return e(m,{items:a,itemRender:i=>{const a=t[i]||k[i];return e(a,{element:r,store:o,elements:o.selectedElements,components:t},i)}})});export default ImageToolbar;
1
+ import{jsx as e,jsxs as o}from"react/jsx-runtime";import{observer as t}from"mobx-react-lite";import{Button as r}from"../primitives/button.js";import{Tooltip as i,TooltipContent as a,TooltipTrigger as n}from"../primitives/tooltip.js";import{ElementContainer as m,extendToolbar as s}from"./element-container.js";import{PolotnoIcon as l}from"../icons/registry.js";import c from"./filters-picker.js";import{AnimationsPicker as p}from"./animations-picker.js";import g from"./flip-button.js";import{flags as d}from"../utils/flags.js";import{ImageRemoveBackground as u}from"./image-remove-background-button.js";export{ImageRemoveBackground}from"./image-remove-background-button.js";import{getCrop as h,getImageSize as f}from"@polotno/core/image";import{t as I}from"../utils/l10n.js";import{isImageLoadError as C}from"../utils/errors.js";import{FitToPageButton as b}from"./selection-size.js";import{ImageEdit as j}from"./image-tools.js";export{ImageEdit,ImageToolActions}from"./image-tools.js";export const ImageFitToBackground=({element:o,elements:t})=>t&&t.length>1?null:e(r,{variant:"ghost",size:"sm",onClick:async()=>{const{page:e}=o,t=e.computedBleed,r=e.computedWidth+t.left+t.right,i=e.computedHeight+t.top+t.bottom,a=await f(o.src).catch(e=>{if(!C(e)){throw e}return console.warn("polotno: failed to fit the image to the background",e),null});if(!a){return}const n=o.stretchEnabled?{cropX:0,cropY:0,cropWidth:1,cropHeight:1}:h({width:r,height:i},a);o.set(Object.assign({x:-t.left,y:-t.top,width:r,height:i,rotation:0},n))},children:I("toolbar.fitToBackground")});export const ImageClip=t(({element:o,store:t,elements:i})=>o.contentEditable?o.clipSrc?e(r,{variant:"ghost",size:"sm",onClickCapture:()=>{i.forEach(e=>{e.set({clipSrc:""})})},children:I("toolbar.removeClip")}):e(r,{variant:"ghost",size:"sm",onClickCapture:e=>{e.stopPropagation(),t.openSidePanel("image-clip")},children:I("toolbar.clip")}):null);export const ImageCrop=t(({element:t})=>t._cropEnabled?o(i,{children:[e(n,{render:e(r,{variant:"ghost",size:"icon-sm",onClickCapture:e=>{e.stopPropagation(),t.toggleCropMode(!0)},"aria-label":I("toolbar.crop"),children:e(l,{name:"toolbar.crop",className:"pn:size-4"})})}),e(a,{children:I("toolbar.crop")})]}):null);export const CropModeBar=t(({element:t})=>o("div",{className:"pn:flex pn:items-center",children:[o(r,{variant:"ghost",size:"sm",onClickCapture:()=>{t.toggleCropMode(!1)},children:[e(l,{name:"action.confirm",className:"pn:size-4"}),I("toolbar.cropDone")]}),o(r,{variant:"ghost",size:"sm",onClickCapture:()=>{t.cancelCropMode()},children:[e(l,{name:"action.close",className:"pn:size-4"}),I("toolbar.cropCancel")]})]}));export const ImageRemoveClip=t(({element:o})=>o.clipSrc?e(r,{variant:"ghost",size:"sm",onClickCapture:()=>{o.set({clipSrc:""})},children:I("toolbar.removeClip")}):null);const k={ImageFlip:g,ImageFilters:c,ImageFitToBackground,ImageFitToPage:t(({store:o,elements:t})=>!t||t.length<=1?null:e(b,{store:o})),ImageCrop,ImageEdit:j,ImageClip,ImageRemoveBackground:u,ImageAnimations:p};export const ImageToolbar=t(({store:o,components:t})=>{const r=o.selectedElements[0],i=["ImageCrop","ImageEdit","ImageFlip","ImageFilters","ImageFitToPage","ImageFitToBackground","ImageClip",d.animationsEnabled&&"ImageAnimations"],a=s({type:"image",usedItems:i,components:t});return e(m,{items:a,itemRender:i=>{const a=t[i]||k[i];return e(a,{element:r,store:o,elements:o.selectedElements,components:t},i)}})});export default ImageToolbar;
@@ -1 +1 @@
1
- import{jsx as e}from"react/jsx-runtime";import{observer as t}from"mobx-react-lite";import{ElementContainer as n,extendToolbar as o}from"./element-container.js";import{AnimationsPicker as m}from"./animations-picker.js";import{flags as r}from"../utils/flags.js";const s={ManyAnimations:m};export const ManyToolbar=t(({store:t,components:m})=>{const a=t.selectedElements,i=[r.animationsEnabled&&"ManyAnimations"],l=o({type:"many",usedItems:i,components:m});return e(n,{items:l,itemRender:n=>{const o=m[n]||s[n];return e(o,{elements:a,element:a[0],store:t},n)}})});export default ManyToolbar;
1
+ import{jsx as o}from"react/jsx-runtime";import{observer as e}from"mobx-react-lite";import{ElementContainer as t,extendToolbar as n}from"./element-container.js";import{AnimationsPicker as s}from"./animations-picker.js";import{SelectionColors as r}from"./selection-colors.js";import{FitToPageButton as m}from"./selection-size.js";import{flags as i}from"../utils/flags.js";const a={ManyColors:r,ManyFitToPage:m,ManyAnimations:s};export const ManyToolbar=e(({store:e,components:s})=>{const r=e.selectedElements,m=["ManyColors","ManyFitToPage",i.animationsEnabled&&"ManyAnimations"],l=n({type:"many",usedItems:m,components:s});return o(t,{items:l,itemRender:t=>{const n=s[t]||a[t];return o(n,{elements:r,element:r[0],store:e},t)}})});export default ManyToolbar;
@@ -1,10 +1,11 @@
1
+ import * as React from 'react';
1
2
  import type { StoreType } from '../ui-types.js';
2
3
  export declare const OpacityPicker: (({ store }: {
3
4
  store: StoreType;
4
- }) => import("react").JSX.Element) & import("react").NamedExoticComponent<{
5
+ }) => React.JSX.Element) & React.NamedExoticComponent<{
5
6
  store: StoreType;
6
7
  }> & {
7
8
  readonly type: ({ store }: {
8
9
  store: StoreType;
9
- }) => import("react").JSX.Element;
10
+ }) => React.JSX.Element;
10
11
  };
@@ -1 +1 @@
1
- import{jsx as e,jsxs as t}from"react/jsx-runtime";import{observer as r}from"mobx-react-lite";import{BLEND_MODES as n,GROUP_BLEND_MODES as o}from"@polotno/schema/defaults";import{PolotnoIcon as i}from"../icons/registry.js";import{Button as l}from"../primitives/button.js";import{Slider as s}from"../primitives/slider.js";import{NumericInput as a}from"../primitives/numeric-input.js";import{Select as m,SelectContent as p,SelectItem as c,SelectTrigger as d}from"../primitives/select.js";import{firstSliderValue as h}from"../lib/utils.js";import{Popover as u,PopoverContent as b,PopoverTrigger as v}from"../primitives/popover.js";import{Tooltip as f,TooltipContent as g,TooltipTrigger as x}from"../primitives/tooltip.js";import{t as y}from"../utils/l10n.js";export const OpacityPicker=r(({store:r})=>{var j,E,M;const N=r.selectedElements.length>0,w=r.selectedElements.every(e=>"group"===e.type)?o:n,z=null===(j=r.selectedElements[0])||void 0===j?void 0:j.blendMode,C=z&&w.includes(z)?z:"normal",V=e=>{e=Math.max(0,Math.min(e,100)),r.selectedElements.forEach(t=>{t.set({opacity:e/100})})},F=Math.round(100*(null!==(M=null===(E=r.selectedElements[0])||void 0===E?void 0:E.opacity)&&void 0!==M?M:0));return t(u,{children:[t(f,{children:[e(x,{render:e(v,{render:e(l,{variant:"ghost",size:"icon-sm",disabled:!N,"aria-label":y("toolbar.transparency"),children:e(i,{name:"toolbar.opacity",className:"pn:size-4"})})})}),N&&e(g,{children:y("toolbar.transparency")})]}),t(b,{side:"bottom",className:"pn:w-auto pn:px-4 pn:py-3",initialFocus:!1,children:[e("div",{className:"pn:mb-2 pn:text-sm",children:y("toolbar.transparency")}),t("div",{className:"pn:flex pn:items-center pn:gap-4",children:[e(s,{style:{width:150},value:[F],onValueChange:e=>V(h(e)),min:0,max:100,step:1}),e(a,{value:F,onValueChange:e=>V(e),min:0,max:100,style:{width:"64px"},onFocus:e=>e.currentTarget.select()})]}),t(m,{value:C,onValueChange:e=>{e&&r.history.transaction(()=>{r.selectedElements.forEach(t=>t.set({blendMode:e}))})},children:[t(d,{"aria-label":y("toolbar.blendMode"),size:"sm",className:"pn:mt-3 pn:-mx-2 pn:w-[calc(100%+1rem)] pn:border-none pn:px-2 pn:shadow-none pn:hover:bg-accent",children:[e("span",{className:"pn:text-muted-foreground",children:y("toolbar.blendMode")}),e("span",{className:"pn:ml-auto",children:y(`toolbar.blend.${C}`)})]}),e(p,{alignItemWithTrigger:!1,align:"end",children:w.map(t=>e(c,{value:t,children:y(`toolbar.blend.${t}`)},t))})]})]})]})});
1
+ import{jsx as e,jsxs as n}from"react/jsx-runtime";import*as r from"react";import{observer as t}from"mobx-react-lite";import{BLEND_MODES as o,GROUP_BLEND_MODES as i}from"@polotno/schema/defaults";import{PolotnoIcon as l}from"../icons/registry.js";import{Button as a}from"../primitives/button.js";import{Slider as s}from"../primitives/slider.js";import{NumericInput as m}from"../primitives/numeric-input.js";import{Select as c,SelectContent as d,SelectItem as p,SelectTrigger as u}from"../primitives/select.js";import{firstSliderValue as h}from"../lib/utils.js";import{Popover as v,PopoverContent as b,PopoverTrigger as f}from"../primitives/popover.js";import{Tooltip as g,TooltipContent as y,TooltipTrigger as x}from"../primitives/tooltip.js";import{t as E}from"../utils/l10n.js";export const OpacityPicker=t(({store:t})=>{var j,M,N;const w=t.selectedElements.length>0,C=t.selectedElements.every(e=>"group"===e.type)?i:o,T=null===(j=t.selectedElements[0])||void 0===j?void 0:j.blendMode,z=T&&C.includes(T)?T:"normal",P=e=>{e=Math.max(0,Math.min(e,100)),t.selectedElements.forEach(n=>{n.set({opacity:e/100})})},V=Math.round(100*(null!==(N=null===(M=t.selectedElements[0])||void 0===M?void 0:M.opacity)&&void 0!==N?N:0)),F=r.useRef(null),I=e=>{F.current||(F.current=new Map(t.selectedElements.map(e=>[e.id,e.blendMode])),t.history.startTransaction()),t.selectedElements.forEach(n=>n.set({blendMode:e}))},O=()=>{var e;return null===(e=F.current)||void 0===e?void 0:e.forEach((e,n)=>{var r;return null===(r=t.getElementById(n))||void 0===r?void 0:r.set({blendMode:e})})},$=(e=!1)=>{F.current&&(e||O(),F.current=null,t.history.endTransaction(!e))};return r.useEffect(()=>()=>{$()},[]),n(v,{children:[n(g,{children:[e(x,{render:e(f,{render:e(a,{variant:"ghost",size:"icon-sm",disabled:!w,"aria-label":E("toolbar.transparency"),children:e(l,{name:"toolbar.opacity",className:"pn:size-4"})})})}),w&&e(y,{children:E("toolbar.transparency")})]}),n(b,{side:"bottom",className:"pn:w-auto pn:px-4 pn:py-3",initialFocus:!1,children:[e("div",{className:"pn:mb-2 pn:text-sm",children:E("toolbar.transparency")}),n("div",{className:"pn:flex pn:items-center pn:gap-4",children:[e(s,{style:{width:150},value:[V],onValueChange:e=>P(h(e)),min:0,max:100,step:1}),e(m,{value:V,onValueChange:e=>P(e),min:0,max:100,style:{width:"64px"},onFocus:e=>e.currentTarget.select()})]}),n(c,{value:z,onOpenChange:e=>{e||$()},onValueChange:e=>{e&&(I(e),$(!0))},children:[n(u,{"aria-label":E("toolbar.blendMode"),size:"sm",className:"pn:mt-3 pn:-mx-2 pn:w-[calc(100%+1rem)] pn:border-none pn:px-2 pn:shadow-none pn:hover:bg-accent",children:[e("span",{className:"pn:text-muted-foreground",children:E("toolbar.blendMode")}),e("span",{className:"pn:ml-auto",children:E(`toolbar.blend.${z}`)})]}),e(d,{alignItemWithTrigger:!1,align:"end",onPointerLeave:O,children:C.map(n=>e(p,{value:n,onPointerEnter:()=>I(n),children:E(`toolbar.blend.${n}`)},n))})]})]})]})});
@@ -1 +1 @@
1
- import{jsx as e,jsxs as t,Fragment as n}from"react/jsx-runtime";import{observer as o}from"mobx-react-lite";import{PolotnoIcon as i}from"../icons/registry.js";import{Button as l}from"../primitives/button.js";import{Popover as a,PopoverContent as r,PopoverTrigger as s}from"../primitives/popover.js";import{getClientRect as c}from"../utils/math.js";import{t as d}from"../utils/l10n.js";import{alignBottom as p,alignCenter as m,alignLeft as h,alignMiddle as x,alignRight as v,alignTop as g}from"../utils/alignment.js";const b=e=>{if("group"!==e.type){return c(e)}let t=1/0,n=1/0,o=-1/0,i=-1/0;return e.children.forEach(e=>{const l=b(e);t=Math.min(t,l.x),n=Math.min(n,l.y),o=Math.max(o,l.x+l.width),i=Math.max(i,l.y+l.height)}),{x:t,y:n,width:o-t,height:i-n}},u=(e,t,n)=>{if("group"!==e.type){const o=c(e),i=t-o.x,l=n-o.y;e.set({x:e.x+i,y:e.y+l})}else{const o=t-b(e).x,i=n-b(e).y;e.children.forEach(e=>{const t=b(e);u(e,t.x+o,t.y+i)})}},f=({icon:n,text:o,disabled:i,onClick:l})=>t("button",{type:"button",disabled:i,onClick:l,className:"pn:flex pn:w-full pn:appearance-none pn:cursor-pointer pn:items-center pn:gap-2 pn:rounded-none pn:border-0 pn:bg-transparent pn:px-[7px] pn:py-[5px] pn:text-left pn:text-sm pn:outline-hidden pn:hover:bg-accent pn:hover:text-accent-foreground pn:disabled:pointer-events-none pn:disabled:cursor-default pn:disabled:opacity-50 pn:[&_svg]:size-4 pn:[&_svg]:shrink-0",children:[n,e("span",{children:o})]}),E=({title:t})=>e("div",{className:"pn:-mx-1 pn:mt-1 pn:border-t pn:border-border pn:pt-2 pn:pb-1 pn:px-2 pn:text-xs pn:font-semibold pn:text-foreground pn:first:mt-0 pn:first:border-t-0 pn:first:pt-1",children:t});export const PositionPicker=o(({store:o})=>{const c=o.selectedElements.length>0,y=o.selectedElements.every(e=>e.draggable),w=y&&o.selectedElements.length>1;return t(a,{children:[e(s,{disabled:!c,render:t(l,{variant:"ghost",size:"sm",className:"polotno-position",disabled:!c,"aria-label":d("toolbar.position"),children:[e(i,{name:"layering.menu",className:"pn:size-4"}),d("toolbar.position")]})}),t(r,{className:"pn:w-[280px] pn:p-1 pn:gap-0",align:"start",children:[e(E,{title:d("toolbar.layering")}),t("div",{className:"pn:flex",children:[t("div",{className:"pn:w-1/2",children:[e(f,{icon:e(i,{name:"layering.up"}),text:d("toolbar.up"),disabled:!o.selectedElements.some(e=>{var t;return null===(t=e.parent)||void 0===t?void 0:t.canMoveElementsUp([e.id])}),onClick:()=>{o.selectedElements.forEach(e=>e.moveUp())}}),e(f,{icon:e(i,{name:"layering.top"}),text:d("toolbar.toForward"),disabled:!o.selectedElements.some(e=>{var t;return null===(t=e.parent)||void 0===t?void 0:t.canMoveElementsTop([e.id])}),onClick:()=>{o.selectedElements.forEach(e=>e.moveTop())}})]}),t("div",{className:"pn:w-1/2",children:[e(f,{icon:e(i,{name:"layering.down"}),text:d("toolbar.down"),disabled:!o.selectedElements.some(e=>{var t;return null===(t=e.parent)||void 0===t?void 0:t.canMoveElementsDown([e.id])}),onClick:()=>{o.selectedElements.forEach(e=>e.moveDown())}}),e(f,{icon:e(i,{name:"layering.bottom"}),text:d("toolbar.toBottom"),disabled:!o.selectedElements.some(e=>{var t;return null===(t=e.parent)||void 0===t?void 0:t.canMoveElementsBottom([e.id])}),onClick:()=>{o.selectedElements.forEach(e=>e.moveBottom())}})]})]}),y&&t(n,{children:[e(E,{title:d("toolbar.position")}),t("div",{className:"pn:flex",children:[t("div",{className:"pn:w-1/2",children:[e(f,{icon:e(i,{name:"position.alignLeft"}),text:d("toolbar.alignLeft"),onClick:()=>{h(o)}}),e(f,{icon:e(i,{name:"position.alignCenter"}),text:d("toolbar.alignCenter"),onClick:()=>{m(o)}}),e(f,{icon:e(i,{name:"position.alignRight"}),text:d("toolbar.alignRight"),onClick:()=>{v(o)}})]}),t("div",{className:"pn:w-1/2",children:[e(f,{icon:e(i,{name:"position.alignTop"}),text:d("toolbar.alignTop"),onClick:()=>{g(o)}}),e(f,{icon:e(i,{name:"position.alignMiddle"}),text:d("toolbar.alignMiddle"),onClick:()=>{x(o)}}),e(f,{icon:e(i,{name:"position.alignBottom"}),text:d("toolbar.alignBottom"),onClick:()=>{p(o)}})]})]})]}),w&&t(n,{children:[e(E,{title:d("toolbar.spaceEvenly")}),t("div",{className:"pn:flex",children:[e("div",{className:"pn:w-1/2",children:e(f,{icon:e(i,{name:"position.distributeVertical"}),text:d("toolbar.verticalDistribution"),onClick:()=>{var e;let t=null===(e=o.activePage)||void 0===e?void 0:e.computedHeight,n=0,i=0;o.selectedElements.forEach(e=>{const o=b(e);t=Math.min(t,o.y),n=Math.max(n,o.y+o.height),i+=o.height});const l=(n-t-i)/(o.selectedElements.length-1),a=o.selectedElements.slice().sort((e,t)=>{const n=b(e),o=b(t);return n.y-o.y});let r=0;a.forEach(e=>{const n=b(e);u(e,n.x,t+r),r+=n.height+l})}})}),e("div",{className:"pn:w-1/2",children:e(f,{icon:e(i,{name:"position.distributeHorizontal"}),text:d("toolbar.horizontalDistribution"),onClick:()=>{var e;let t=null===(e=o.activePage)||void 0===e?void 0:e.computedWidth,n=0,i=0;o.selectedElements.forEach(e=>{const o=b(e);t=Math.min(t,o.x),n=Math.max(n,o.x+o.width),i+=o.width});const l=(n-t-i)/(o.selectedElements.length-1),a=o.selectedElements.slice().sort((e,t)=>{const n=b(e),o=b(t);return n.x-o.x});let r=0;a.forEach(e=>{const n=b(e);u(e,t+r,n.y),r+=n.width+l})}})})]})]})]})]})});
1
+ import{jsx as e,jsxs as t,Fragment as n}from"react/jsx-runtime";import{observer as o}from"mobx-react-lite";import{PolotnoIcon as i}from"../icons/registry.js";import{Button as l}from"../primitives/button.js";import{Popover as s,PopoverContent as a,PopoverTrigger as r}from"../primitives/popover.js";import{t as c}from"../utils/l10n.js";import{alignBottom as d,alignCenter as p,alignLeft as m,alignMiddle as h,alignRight as v,alignTop as b,getBoundingBox as g,setElementPosition as x}from"../utils/alignment.js";import{SelectionSize as u}from"./selection-size.js";const f=({icon:n,text:o,disabled:i,onClick:l})=>t("button",{type:"button",disabled:i,onClick:l,className:"pn:flex pn:w-full pn:appearance-none pn:cursor-pointer pn:items-center pn:gap-2 pn:rounded-none pn:border-0 pn:bg-transparent pn:px-[7px] pn:py-[5px] pn:text-left pn:text-sm pn:outline-hidden pn:hover:bg-accent pn:hover:text-accent-foreground pn:disabled:pointer-events-none pn:disabled:cursor-default pn:disabled:opacity-50 pn:[&_svg]:size-4 pn:[&_svg]:shrink-0",children:[n,e("span",{children:o})]}),E=({title:t})=>e("div",{className:"pn:-mx-1 pn:mt-1 pn:border-t pn:border-border pn:pt-2 pn:pb-1 pn:px-2 pn:text-xs pn:font-semibold pn:text-foreground pn:first:mt-0 pn:first:border-t-0 pn:first:pt-1",children:t});export const PositionPicker=o(({store:o})=>{const y=o.selectedElements.length>0,k=o.selectedElements.every(e=>e.draggable),w=k&&o.selectedElements.length>1;return t(s,{children:[e(r,{disabled:!y,render:t(l,{variant:"ghost",size:"sm",className:"polotno-position",disabled:!y,"aria-label":c("toolbar.position"),children:[e(i,{name:"layering.menu",className:"pn:size-4"}),c("toolbar.position")]})}),t(a,{className:"pn:w-[280px] pn:p-1 pn:gap-0",align:"start",children:[e(E,{title:c("toolbar.layering")}),t("div",{className:"pn:flex",children:[t("div",{className:"pn:w-1/2",children:[e(f,{icon:e(i,{name:"layering.up"}),text:c("toolbar.up"),disabled:!o.selectedElements.some(e=>{var t;return null===(t=e.parent)||void 0===t?void 0:t.canMoveElementsUp([e.id])}),onClick:()=>{o.selectedElements.forEach(e=>e.moveUp())}}),e(f,{icon:e(i,{name:"layering.top"}),text:c("toolbar.toForward"),disabled:!o.selectedElements.some(e=>{var t;return null===(t=e.parent)||void 0===t?void 0:t.canMoveElementsTop([e.id])}),onClick:()=>{o.selectedElements.forEach(e=>e.moveTop())}})]}),t("div",{className:"pn:w-1/2",children:[e(f,{icon:e(i,{name:"layering.down"}),text:c("toolbar.down"),disabled:!o.selectedElements.some(e=>{var t;return null===(t=e.parent)||void 0===t?void 0:t.canMoveElementsDown([e.id])}),onClick:()=>{o.selectedElements.forEach(e=>e.moveDown())}}),e(f,{icon:e(i,{name:"layering.bottom"}),text:c("toolbar.toBottom"),disabled:!o.selectedElements.some(e=>{var t;return null===(t=e.parent)||void 0===t?void 0:t.canMoveElementsBottom([e.id])}),onClick:()=>{o.selectedElements.forEach(e=>e.moveBottom())}})]})]}),k&&t(n,{children:[e(E,{title:c("toolbar.position")}),t("div",{className:"pn:flex",children:[t("div",{className:"pn:w-1/2",children:[e(f,{icon:e(i,{name:"position.alignLeft"}),text:c("toolbar.alignLeft"),onClick:()=>{m(o)}}),e(f,{icon:e(i,{name:"position.alignCenter"}),text:c("toolbar.alignCenter"),onClick:()=>{p(o)}}),e(f,{icon:e(i,{name:"position.alignRight"}),text:c("toolbar.alignRight"),onClick:()=>{v(o)}})]}),t("div",{className:"pn:w-1/2",children:[e(f,{icon:e(i,{name:"position.alignTop"}),text:c("toolbar.alignTop"),onClick:()=>{b(o)}}),e(f,{icon:e(i,{name:"position.alignMiddle"}),text:c("toolbar.alignMiddle"),onClick:()=>{h(o)}}),e(f,{icon:e(i,{name:"position.alignBottom"}),text:c("toolbar.alignBottom"),onClick:()=>{d(o)}})]})]})]}),w&&t(n,{children:[e(E,{title:c("toolbar.spaceEvenly")}),t("div",{className:"pn:flex",children:[e("div",{className:"pn:w-1/2",children:e(f,{icon:e(i,{name:"position.distributeVertical"}),text:c("toolbar.verticalDistribution"),onClick:()=>{var e;let t=null===(e=o.activePage)||void 0===e?void 0:e.computedHeight,n=0,i=0;o.selectedElements.forEach(e=>{const o=g(e);t=Math.min(t,o.y),n=Math.max(n,o.y+o.height),i+=o.height});const l=(n-t-i)/(o.selectedElements.length-1),s=o.selectedElements.slice().sort((e,t)=>{const n=g(e),o=g(t);return n.y-o.y});let a=0;s.forEach(e=>{const n=g(e);x(e,n.x,t+a),a+=n.height+l})}})}),e("div",{className:"pn:w-1/2",children:e(f,{icon:e(i,{name:"position.distributeHorizontal"}),text:c("toolbar.horizontalDistribution"),onClick:()=>{var e;let t=null===(e=o.activePage)||void 0===e?void 0:e.computedWidth,n=0,i=0;o.selectedElements.forEach(e=>{const o=g(e);t=Math.min(t,o.x),n=Math.max(n,o.x+o.width),i+=o.width});const l=(n-t-i)/(o.selectedElements.length-1),s=o.selectedElements.slice().sort((e,t)=>{const n=g(e),o=g(t);return n.x-o.x});let a=0;s.forEach(e=>{const n=g(e);x(e,t+a,n.y),a+=n.width+l})}})})]})]}),e(E,{title:"px"===o.unit?"":o.unit}),e(u,{store:o})]})]})});
@@ -0,0 +1,18 @@
1
+ import React from 'react';
2
+ import type { StoreType } from '../ui-types.js';
3
+ export declare const stripeGradient: (colors: string[]) => string;
4
+ export declare const ColorRow: ({ value, onChange, store, gradientEnabled, }: {
5
+ value: string;
6
+ onChange: (color: string) => void;
7
+ store: StoreType;
8
+ gradientEnabled?: boolean;
9
+ }) => React.JSX.Element;
10
+ export declare const SelectionColors: (({ store }: {
11
+ store: StoreType;
12
+ }) => React.JSX.Element | null) & React.NamedExoticComponent<{
13
+ store: StoreType;
14
+ }> & {
15
+ readonly type: ({ store }: {
16
+ store: StoreType;
17
+ }) => React.JSX.Element | null;
18
+ };
@@ -0,0 +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});
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import type { StoreType } from '../ui-types.js';
3
+ type ButtonProps = {
4
+ store: StoreType;
5
+ };
6
+ export declare const FitToPageButton: (({ store }: ButtonProps) => React.JSX.Element) & React.NamedExoticComponent<ButtonProps> & {
7
+ readonly type: ({ store }: ButtonProps) => React.JSX.Element;
8
+ };
9
+ export declare const SelectionSize: (({ store }: ButtonProps) => React.JSX.Element | null) & React.NamedExoticComponent<ButtonProps> & {
10
+ readonly type: ({ store }: ButtonProps) => React.JSX.Element | null;
11
+ };
12
+ export {};
@@ -0,0 +1 @@
1
+ import{jsx as t,jsxs as e}from"react/jsx-runtime";import{observer as i}from"mobx-react-lite";import{t as o}from"../utils/l10n.js";import{pxToUnitRounded as n,unitToPx as a}from"../utils/unit.js";import{canFitSelectionToPage as s,canMoveSelection as r,canResizeSelection as l,fitSelectionToPage as p,getSelectionBox as m,moveSelection as d,resizeSelection as u}from"../utils/selection-transform.js";import{Button as b}from"../primitives/button.js";import{NumericInputDelayed as c}from"../primitives/numeric-input-delayed.js";export const FitToPageButton=i(({store:e})=>t(b,{variant:"ghost",size:"sm",className:"polotno-fit-to-page",disabled:!s(e),onClick:()=>p(e),children:o("toolbar.fitToPage")}));const h=({label:i,ariaLabel:o=i,value:s,min:r,disabled:l,store:p,onCommit:m})=>{const{unit:d,dpi:u}=p,b=n({px:s,unit:d,dpi:u});return e("label",{className:"pn:flex pn:items-center pn:gap-1.5 pn:text-xs pn:text-muted-foreground",children:[t("span",{className:"pn:w-3 pn:shrink-0",children:i}),t(c,{value:b,"aria-label":o,disabled:l,min:r,stepper:!1,step:"px"===d?1:.1,className:"pn:h-8 pn:text-sm pn:text-foreground",onChange:t=>{t!==b&&m(a({unitVal:t,unit:d,dpi:u}))}})]})};export const SelectionSize=i(({store:i})=>{const a=m(i);if(!a){return null}const s=l(i),p=r(i),b=n({px:1,unit:i.unit,dpi:i.dpi})||.01;return e("div",{className:"pn:grid pn:grid-cols-2 pn:gap-2 pn:px-2 pn:pb-1",children:[t(h,{label:o("toolbar.widthShort"),ariaLabel:o("sidePanel.width"),value:a.width,min:b,disabled:!s,store:i,onCommit:t=>u(i,"x",t)}),t(h,{label:o("toolbar.heightShort"),ariaLabel:o("sidePanel.height"),value:a.height,min:b,disabled:!s,store:i,onCommit:t=>u(i,"y",t)}),t(h,{label:"X",value:a.x,disabled:!p,store:i,onCommit:t=>d(i,"x",t)}),t(h,{label:"Y",value:a.y,disabled:!p,store:i,onCommit:t=>d(i,"y",t)})]})});
@@ -1 +1 @@
1
- import{jsx as e,jsxs as r}from"react/jsx-runtime";import{observer as o}from"mobx-react-lite";import*as t from"@polotno/core/svg";import{useSvgColors as n}from"../utils/use-svg-colors.js";import{t as s}from"../utils/l10n.js";import{isGradient as l,firstStopColor as i}from"@polotno/core/gradient";import{ElementContainer as a,extendToolbar as p}from"./element-container.js";import{ImageCrop as m}from"./image-toolbar.js";import{Popover as c,PopoverContent as g,PopoverTrigger as d}from"../primitives/popover.js";import{Button as f}from"../primitives/button.js";import v from"./filters-picker.js";import u,{ColoredBox as b}from"./color-picker.js";import x from"./flip-button.js";import{AnimationsPicker as h}from"./animations-picker.js";import{flags as j}from"../utils/flags.js";const S=(e,r)=>Array.from(e.keys()).find(e=>t.sameColors(e,r)),k=(e,r)=>{const o=S(e,r);return e.get(o||"")||r},C=e=>e.colorsReplace,N=(e,r,o)=>{const t=S(C(e),r)||r;e.replaceColor(t,o)},E=o(({element:o,color:t,store:n})=>{const i=k(C(o),t);return r("div",{className:"pn-svg-color-row pn:flex pn:items-center pn:gap-2",children:[e(u,{value:i,onChange:e=>N(o,t,e),store:n,gradientEnabled:!0}),e("span",{className:"pn:truncate pn:text-xs pn:text-muted-foreground",children:l(i)?s("toolbar.colorPicker.linear"):i})]})}),y={SvgFlip:x,SvgFilters:v,SvgColors:o(({element:o,store:t})=>{const l=n(o.src),a=C(o);if(o.maskSrc||0===l.length){return null}if(1===l.length){const r=l[0];return e(u,{value:k(a,r),onChange:e=>N(o,r,e),store:t,gradientEnabled:!0})}const p=(e=>{const r=e.slice(0,8),o=r.length||1;return`linear-gradient(90deg, ${r.map((e,r)=>`${e} ${r/o*100}% ${(r+1)/o*100}%`).join(", ")})`})(l.map(e=>i(k(a,e)))),m=a.size>0;return r(c,{children:[e(d,{nativeButton:!1,render:e(b,{background:p,"aria-label":s("toolbar.colorPicker.colors")})}),r(g,{className:"pn:w-[220px] pn:p-2",align:"start",children:[r("div",{className:"pn:mb-2 pn:flex pn:items-center pn:justify-between",children:[e("span",{className:"pn:text-xs pn:font-medium",children:s("toolbar.colorPicker.colors")}),m&&e(f,{variant:"ghost",size:"sm","data-pn-reset-colors":"",onClick:()=>o.resetColors(),children:s("toolbar.colorPicker.resetColors")})]}),r("div",{className:"pn:mb-2 pn:flex pn:items-center pn:gap-2 pn:border-b pn:pb-2",children:[e(u,{value:k(a,l[0]),onChange:e=>l.forEach(r=>N(o,r,e)),store:t,gradientEnabled:!0}),e("span",{className:"pn:text-xs",children:s("toolbar.colorPicker.recolorAll")})]}),e("div",{className:"pn:flex pn:max-h-[280px] pn:flex-col pn:gap-2 pn:overflow-y-auto",children:l.map(r=>e(E,{element:o,color:r,store:t},r))})]})]})}),SvgCrop:m,SvgAnimations:h};export const SvgToolbar=o(({store:r,hideSvgEffects:o,components:t})=>{const n=r.selectedElements,s=["SvgFlip",!o&&"SvgFilters","SvgColors","SvgCrop",j.animationsEnabled&&"SvgAnimations"].filter(e=>!!e),l=p({type:"svg",usedItems:s,components:t});return e(a,{items:l,itemRender:o=>{const s=t[o]||y[o];return e(s,{elements:n,element:n[0],store:r},o)}})});export default SvgToolbar;
1
+ import{jsx as e,jsxs as o}from"react/jsx-runtime";import{observer as r}from"mobx-react-lite";import{useSvgColors as t}from"../utils/use-svg-colors.js";import{t as s}from"../utils/l10n.js";import{getColorsReplace as n,getSvgColor as i,replaceSvgColor as l}from"../utils/selection-colors.js";import{ElementContainer as m,extendToolbar as a}from"./element-container.js";import{ColorRow as p,SelectionColors as c,stripeGradient as g}from"./selection-colors.js";import{FitToPageButton as f}from"./selection-size.js";import{ImageCrop as v}from"./image-toolbar.js";import{Popover as d,PopoverContent as u,PopoverTrigger as b}from"../primitives/popover.js";import{Button as h}from"../primitives/button.js";import j from"./filters-picker.js";import x,{ColoredBox as S}from"./color-picker.js";import k from"./flip-button.js";import{AnimationsPicker as C}from"./animations-picker.js";import{flags as E}from"../utils/flags.js";const F=r(({element:r,store:m})=>{const a=t(r.src),c=n(r);if(r.maskSrc||0===a.length){return null}if(1===a.length){const o=a[0];return e(x,{value:i(c,o),onChange:e=>l(r,o,e),store:m,gradientEnabled:!0})}const f=g(a.map(e=>i(c,e))),v=c.size>0;return o(d,{children:[e(b,{nativeButton:!1,render:e(S,{background:f,"aria-label":s("toolbar.colorPicker.colors")})}),o(u,{className:"pn:w-[220px] pn:p-2",align:"start",children:[o("div",{className:"pn:mb-2 pn:flex pn:items-center pn:justify-between",children:[e("span",{className:"pn:text-xs pn:font-medium",children:s("toolbar.colorPicker.colors")}),v&&e(h,{variant:"ghost",size:"sm","data-pn-reset-colors":"",onClick:()=>r.resetColors(),children:s("toolbar.colorPicker.resetColors")})]}),o("div",{className:"pn:mb-2 pn:flex pn:items-center pn:gap-2 pn:border-b pn:pb-2",children:[e(x,{value:i(c,a[0]),onChange:e=>a.forEach(o=>l(r,o,e)),store:m,gradientEnabled:!0}),e("span",{className:"pn:text-xs",children:s("toolbar.colorPicker.recolorAll")})]}),e("div",{className:"pn:flex pn:max-h-[280px] pn:flex-col pn:gap-2 pn:overflow-y-auto",children:a.map(o=>e(p,{value:i(c,o),onChange:e=>l(r,o,e),store:m},o))})]})]})}),N={SvgFlip:k,SvgFilters:j,SvgColors:r(({element:o,elements:r,store:t})=>r.length>1?e(c,{store:t}):e(F,{element:o,store:t})),SvgCrop:v,SvgFitToPage:f,SvgAnimations:C};export const SvgToolbar=r(({store:o,hideSvgEffects:r,components:t})=>{const s=o.selectedElements,n=["SvgFlip",!r&&"SvgFilters","SvgColors","SvgCrop","SvgFitToPage",E.animationsEnabled&&"SvgAnimations"].filter(e=>!!e),i=a({type:"svg",usedItems:n,components:t});return e(m,{items:i,itemRender:r=>{const n=t[r]||N[r];return e(n,{elements:s,element:s[0],store:o},r)}})});export default SvgToolbar;