polotno 4.22.1 → 4.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/THIRD_PARTY_NOTICES.md +7 -7
  2. package/blueprint/toolbar/color-picker.js +2 -2
  3. package/canvas/apply-filters.js +1 -1
  4. package/canvas/downscale.d.ts +1 -1
  5. package/canvas/downscale.js +1 -1
  6. package/canvas/element.js +1 -1
  7. package/canvas/fade-overlay.d.ts +5 -0
  8. package/canvas/fade-overlay.js +1 -1
  9. package/canvas/hotkeys.js +1 -1
  10. package/canvas/html-element.js +1 -1
  11. package/canvas/image-element.js +1 -1
  12. package/canvas/line-element.js +1 -1
  13. package/canvas/page.js +1 -1
  14. package/canvas/quill-font-formats.d.ts +1 -0
  15. package/canvas/quill-font-formats.js +1 -1
  16. package/canvas/radial-gradient-handle.d.ts +14 -0
  17. package/canvas/radial-gradient-handle.js +1 -0
  18. package/canvas/render-tag-element.js +1 -1
  19. package/canvas/rich-editor.d.ts +2 -0
  20. package/canvas/rich-editor.js +12 -6
  21. package/canvas/text-element/legacy-padding-warning.d.ts +6 -0
  22. package/canvas/text-element/legacy-padding-warning.js +1 -0
  23. package/canvas/text-element/max-font-size.js +1 -1
  24. package/canvas/text-element.js +1 -1
  25. package/canvas/use-color.d.ts +24 -2
  26. package/canvas/use-color.js +1 -1
  27. package/canvas/video-element.js +1 -1
  28. package/icons/registry.d.ts +1 -0
  29. package/icons/registry.js +1 -1
  30. package/image-tools/raster.js +1 -1
  31. package/model/group-model.d.ts +26 -10
  32. package/model/group-model.js +1 -1
  33. package/model/node-model.d.ts +10 -1
  34. package/model/node-model.js +1 -1
  35. package/model/page-model.d.ts +75 -33
  36. package/model/page-model.js +1 -1
  37. package/model/table-model.d.ts +29 -9
  38. package/model/table-model.js +1 -1
  39. package/model/text-model.d.ts +5 -1
  40. package/model/text-model.js +1 -1
  41. package/package.json +16 -16
  42. package/polotno.bundle.js +194 -202
  43. package/primitives/field-group.js +1 -1
  44. package/primitives/popover.d.ts +1 -1
  45. package/primitives/popover.js +1 -1
  46. package/primitives/slider-field.js +1 -1
  47. package/side-panel/effect-card.js +1 -1
  48. package/side-panel/effects-panel.js +1 -1
  49. package/side-panel/images-grid.js +1 -1
  50. package/side-panel/layers-panel.js +1 -1
  51. package/side-panel/tab-button.js +1 -3
  52. package/side-panel/templates-panel.js +1 -1
  53. package/toolbar/color-picker.js +1 -1
  54. package/toolbar/gradient-center-pad.d.ts +11 -0
  55. package/toolbar/gradient-center-pad.js +1 -0
  56. package/toolbar/html-toolbar.js +2 -2
  57. package/toolbar/padding-control.d.ts +29 -0
  58. package/toolbar/padding-control.js +1 -0
  59. package/toolbar/selection-colors.js +1 -1
  60. package/toolbar/stop-track.js +1 -1
  61. package/toolbar/table-toolbar.js +1 -1
  62. package/toolbar/text-toolbar.d.ts +7 -2
  63. package/toolbar/text-toolbar.js +1 -1
  64. package/toolbar/unit-numeric-input.d.ts +5 -0
  65. package/toolbar/unit-numeric-input.js +1 -0
  66. package/toolbar/use-copy-style.js +1 -1
  67. package/ui.css +1 -1
  68. package/utils/clipboard.d.ts +10 -2
  69. package/utils/clipboard.js +1 -1
  70. package/utils/engine.d.ts +2 -0
  71. package/utils/engine.js +3 -0
  72. package/utils/fonts.js +1 -1
  73. package/utils/gradient-handle.d.ts +18 -0
  74. package/utils/gradient-handle.js +1 -0
  75. package/utils/gradient-stops.d.ts +7 -2
  76. package/utils/gradient-stops.js +1 -1
  77. package/utils/history-gesture.d.ts +7 -0
  78. package/utils/history-gesture.js +1 -0
  79. package/utils/html2canvas.js +1 -1
  80. package/utils/l10n.d.ts +19 -1
  81. package/utils/l10n.js +1 -1
  82. package/utils/measure-text.d.ts +4 -0
  83. package/utils/measure-text.js +1 -1
  84. package/utils/px.d.ts +4 -0
  85. package/utils/px.js +1 -1
  86. package/utils/rich-text-html.d.ts +1 -0
  87. package/utils/rich-text-html.js +1 -1
  88. package/utils/selection-transform.js +1 -1
  89. package/utils/text-format.d.ts +5 -0
  90. package/utils/text-format.js +1 -1
  91. package/utils/validate-key.js +1 -1
@@ -1 +1 @@
1
- import{jsx as e,jsxs as n}from"react/jsx-runtime";import{cn as s}from"../lib/utils.js";import{Switch as l}from"./switch.js";function i({label:i,enabled:a,onEnabledChange:p,visible:t=!0,disabled:d,className:r,children:c}){if(!t){return null}const m=!p||!!a;return n("div",{className:s("pn:py-1",r),children:[n("div",{className:"pn:flex pn:items-center pn:justify-between pn:gap-2 pn:py-1",children:[e("label",{className:"pn:text-sm pn:font-medium",children:i}),p&&e(l,{checked:!!a,onCheckedChange:p,disabled:d})]}),m&&e("div",{className:"pn:mt-1.5 pn:rounded-lg pn:bg-muted/60 pn:px-3 pn:py-1",children:c})]})}export{i as FieldGroup};
1
+ import{jsx as e,jsxs as n}from"react/jsx-runtime";import*as s from"react";import{cn as l}from"../lib/utils.js";import{Switch as a}from"./switch.js";function i({label:i,enabled:r,onEnabledChange:t,visible:d=!0,disabled:p,className:c,children:m}){const o=s.useId();if(!d){return null}const b=!t||!!r;return n("div",{className:l("pn:py-1",c),children:[n("div",{className:"pn:flex pn:items-center pn:justify-between pn:gap-2 pn:py-1",children:[e("label",{id:o,className:"pn:text-sm pn:font-medium",children:i}),t&&e(a,{"aria-labelledby":o,checked:!!r,onCheckedChange:t,disabled:p})]}),b&&e("div",{className:"pn:mt-1.5 pn:rounded-lg pn:bg-muted/60 pn:px-3 pn:py-1",children:m})]})}export{i as FieldGroup};
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { Popover as PopoverPrimitive } from '@base-ui/react/popover';
3
- declare function Popover({ ...props }: React.ComponentProps<typeof PopoverPrimitive.Root>): React.JSX.Element;
3
+ declare function Popover({ onOpenChange, ...props }: React.ComponentProps<typeof PopoverPrimitive.Root>): React.JSX.Element;
4
4
  declare function PopoverTrigger({ ...props }: React.ComponentProps<typeof PopoverPrimitive.Trigger>): React.JSX.Element;
5
5
  type PositionerProps = React.ComponentProps<typeof PopoverPrimitive.Positioner>;
6
6
  declare const PopoverContent: React.ForwardRefExoticComponent<Omit<Omit<import("@base-ui/react").PopoverPopupProps, "ref"> & React.RefAttributes<HTMLDivElement> & {
@@ -1 +1 @@
1
- var e=this&&this.__rest||function(e,t){var o={};for(var n in e){Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(o[n]=e[n])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(n=Object.getOwnPropertySymbols(e);r<n.length;r++){t.indexOf(n[r])<0&&Object.prototype.propertyIsEnumerable.call(e,n[r])&&(o[n[r]]=e[n[r]])}}return o};import{jsx as t}from"react/jsx-runtime";import*as o from"react";import{Popover as n}from"@base-ui/react/popover";import{cn as r}from"../lib/utils.js";import{usePortalScope as a}from"./portal-scope.js";function i(o){var r=e(o,[]);return t(n.Root,Object.assign({"data-slot":"popover"},r))}function s(o){var r=e(o,[]);return t(n.Trigger,Object.assign({"data-slot":"popover-trigger"},r))}const p=o.forwardRef((o,i)=>{var{className:s,side:p,align:d="center",sideOffset:l=4,alignOffset:f}=o,c=e(o,["className","side","align","sideOffset","alignOffset"]);const m=a(),{container:g,className:u}=m,O=e(m,["container","className"]);return t(n.Portal,{container:g,children:t(n.Positioner,{side:p,align:d,sideOffset:l,alignOffset:f,positionMethod:"fixed",className:"pn:z-[200]",children:t(n.Popup,Object.assign({ref:i,"data-slot":"popover-content"},O,{className:r(u,"pn:z-50 pn:w-72 origin-(--transform-origin) pn:rounded-md pn:border pn:bg-popover pn:p-4 pn:text-popover-foreground pn:shadow-md pn:outline-hidden pn:data-[side=bottom]:slide-in-from-top-2 pn:data-[side=left]:slide-in-from-right-2 pn:data-[side=right]:slide-in-from-left-2 pn:data-[side=top]:slide-in-from-bottom-2 pn:data-[closed]:animate-out pn:data-[closed]:fade-out-0 pn:data-[closed]:zoom-out-95 pn:data-[open]:animate-in pn:data-[open]:fade-in-0 pn:data-[open]:zoom-in-95",s)},c))})})});p.displayName="PopoverContent";export{i as Popover,s as PopoverTrigger,p as PopoverContent};
1
+ var e=this&&this.__rest||function(e,o){var t={};for(var n in e){Object.prototype.hasOwnProperty.call(e,n)&&o.indexOf(n)<0&&(t[n]=e[n])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var a=0;for(n=Object.getOwnPropertySymbols(e);a<n.length;a++){o.indexOf(n[a])<0&&Object.prototype.propertyIsEnumerable.call(e,n[a])&&(t[n[a]]=e[n[a]])}}return t};import{jsx as o}from"react/jsx-runtime";import*as t from"react";import{Popover as n}from"@base-ui/react/popover";import{cn as a}from"../lib/utils.js";import{keepOpenForRadialHandle as r}from"../utils/gradient-handle.js";import{usePortalScope as i}from"./portal-scope.js";function s(t){var{onOpenChange:a}=t,i=e(t,["onOpenChange"]);return o(n.Root,Object.assign({"data-slot":"popover",onOpenChange:(e,o)=>{r(e,o)||null==a||a(e,o)}},i))}function p(t){var a=e(t,[]);return o(n.Trigger,Object.assign({"data-slot":"popover-trigger"},a))}const d=t.forwardRef((t,r)=>{var{className:s,side:p,align:d="center",sideOffset:l=4,alignOffset:f}=t,m=e(t,["className","side","align","sideOffset","alignOffset"]);const c=i(),{container:g,className:u}=c,O=e(c,["container","className"]);return o(n.Portal,{container:g,children:o(n.Positioner,{side:p,align:d,sideOffset:l,alignOffset:f,positionMethod:"fixed",className:"pn:z-[200]",children:o(n.Popup,Object.assign({ref:r,"data-slot":"popover-content"},O,{className:a(u,"pn:z-50 pn:w-72 origin-(--transform-origin) pn:rounded-md pn:border pn:bg-popover pn:p-4 pn:text-popover-foreground pn:shadow-md pn:outline-hidden pn:data-[side=bottom]:slide-in-from-top-2 pn:data-[side=left]:slide-in-from-right-2 pn:data-[side=right]:slide-in-from-left-2 pn:data-[side=top]:slide-in-from-bottom-2 pn:data-[closed]:animate-out pn:data-[closed]:fade-out-0 pn:data-[closed]:zoom-out-95 pn:data-[open]:animate-in pn:data-[open]:fade-in-0 pn:data-[open]:zoom-in-95",s)},m))})})});d.displayName="PopoverContent";export{s as Popover,p as PopoverTrigger,d as PopoverContent};
@@ -1 +1 @@
1
- import{jsx as e,jsxs as n}from"react/jsx-runtime";import{cn as l,firstSliderValue as a}from"../lib/utils.js";import{Slider as s}from"./slider.js";import{Switch as i}from"./switch.js";import{NumericInput as t}from"./numeric-input.js";function p({label:p,value:m,onChange:r,min:d,max:c,step:o=1,disabled:u,className:h,visible:f=!0,enabled:x,onEnabledChange:b,sliderMax:g,sliderValue:v,onCommit:N}){if(!f){return null}const j=e=>{let n=e;return"number"==typeof d&&(n=Math.max(d,n)),"number"==typeof c&&(n=Math.min(c,n)),n},y=e(t,{value:m,onValueChange:e=>r(j(e)),min:d,max:c,step:o,disabled:u,style:{width:64}}),C=e=>Number.isInteger(o)?Math.round(e):e,w=e(s,{value:[null!=v?v:m],onValueChange:e=>r(j(C(a(e)))),onValueCommitted:N?e=>N(j(C(a(e)))):void 0,min:d,max:null!=g?g:c,step:o,disabled:u});return n("div",b?{className:l("pn:py-1",h),children:[n("div",{className:"pn:flex pn:items-center pn:justify-between pn:gap-2 pn:py-1",children:[e("label",{className:"pn:text-sm pn:font-medium",children:p}),e(i,{checked:!!x,onCheckedChange:b,disabled:u})]}),x&&n("div",{className:"pn:mt-1.5 pn:flex pn:items-center pn:gap-2.5 pn:rounded-lg pn:bg-muted/60 pn:px-3 pn:py-2.5",children:[e("div",{className:"pn:flex-1",children:w}),y]})]}:{className:l("pn:flex pn:flex-col pn:gap-2 pn:py-2",h),children:[n("div",{className:"pn:flex pn:items-center pn:justify-between pn:gap-2",children:[e("label",{className:"pn:text-sm",children:p}),y]}),w]})}export{p as SliderField};
1
+ import{jsx as e,jsxs as n}from"react/jsx-runtime";import*as l from"react";import{cn as a,firstSliderValue as s}from"../lib/utils.js";import{Slider as i}from"./slider.js";import{Switch as t}from"./switch.js";import{NumericInput as p}from"./numeric-input.js";function m({label:m,value:r,onChange:d,min:o,max:c,step:u=1,disabled:h,className:b,visible:f=!0,enabled:x,onEnabledChange:g,sliderMax:v,sliderValue:y,onCommit:N}){const j=l.useId();if(!f){return null}const C=e=>{let n=e;return"number"==typeof o&&(n=Math.max(o,n)),"number"==typeof c&&(n=Math.min(c,n)),n},w=e(p,{value:r,onValueChange:e=>d(C(e)),min:o,max:c,step:u,disabled:h,style:{width:64}}),M=e=>Number.isInteger(u)?Math.round(e):e,V=e(i,{value:[null!=y?y:r],onValueChange:e=>d(C(M(s(e)))),onValueCommitted:N?e=>N(C(M(s(e)))):void 0,min:o,max:null!=v?v:c,step:u,disabled:h});return n("div",g?{className:a("pn:py-1",b),children:[n("div",{className:"pn:flex pn:items-center pn:justify-between pn:gap-2 pn:py-1",children:[e("label",{id:j,className:"pn:text-sm pn:font-medium",children:m}),e(t,{"aria-labelledby":j,checked:!!x,onCheckedChange:g,disabled:h})]}),x&&n("div",{className:"pn:mt-1.5 pn:flex pn:items-center pn:gap-2.5 pn:rounded-lg pn:bg-muted/60 pn:px-3 pn:py-2.5",children:[e("div",{className:"pn:flex-1",children:V}),w]})]}:{className:a("pn:flex pn:flex-col pn:gap-2 pn:py-2",b),children:[n("div",{className:"pn:flex pn:items-center pn:justify-between pn:gap-2",children:[e("label",{className:"pn:text-sm",children:m}),w]}),V]})}export{m as SliderField};
@@ -1 +1 @@
1
- var e=this&&this.__rest||function(e,r){var t={};for(var n in e){Object.prototype.hasOwnProperty.call(e,n)&&r.indexOf(n)<0&&(t[n]=e[n])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(n=Object.getOwnPropertySymbols(e);s<n.length;s++){r.indexOf(n[s])<0&&Object.prototype.propertyIsEnumerable.call(e,n[s])&&(t[n[s]]=e[n[s]])}}return t};import{Fragment as r,jsx as t,jsxs as n}from"react/jsx-runtime";import{Effects as s,shapeFilterToCSS as l}from"@polotno/core/filters";import{cn as a}from"../lib/utils.js";export const EffectCard=({title:e,imageSrc:r,effect:s,onClick:l,active:o})=>{const i=f(s);return n("div",{className:"pn:flex pn:flex-col pn:gap-2 pn:cursor-pointer pn:flex-grow-0 pn:w-[calc(33%-16px)]",onClick:l,children:[n("div",{className:"pn:relative pn:h-[90px] pn:rounded-[10px] pn:box-border",children:[t("div",{"data-active":o?"true":void 0,className:a("pn:absolute pn:-left-1 pn:-top-1 pn:-bottom-1 pn:-right-1 pn:flex pn:rounded-[15px] pn:p-[2px] pn:transition-[border] pn:duration-200 pn:border-2 pn:border-transparent",o&&"pn:border-white")}),t(i,{src:r})]}),t("span",{className:"pn:text-center",children:e})]})};const o=r=>{var{className:n,style:s}=r,l=e(r,["className","style"]);return t("img",Object.assign({crossOrigin:"anonymous",className:a("pn:h-full pn:w-full pn:rounded-[10px] pn:object-cover",n),style:s},l))},i=e=>t(o,Object.assign({style:{filter:"sepia(1)"}},e)),c=e=>t(o,Object.assign({style:{filter:"grayscale(1)"}},e)),p=e=>{const r=l(s.warm);return t(o,Object.assign({style:{filter:null==r?void 0:r.filter}},e))},u=e=>{const a=l(s.cold),i=null==a?void 0:a.html,c=null==a?void 0:a.filter;return n(r,{children:[t("div",{style:{display:"none"},dangerouslySetInnerHTML:{__html:i||""}}),t(o,Object.assign({style:{filter:c}},e))]})},d=e=>{const r=l(s.natural);return t(o,Object.assign({style:{filter:null==r?void 0:r.filter}},e))},f=e=>{switch(e){case s.sepia:return i;case s.grayscale:return c;case s.warm:return p;case s.cold:return u;case s.natural:return d;default:return o}};
1
+ var e=this&&this.__rest||function(e,r){var t={};for(var n in e){Object.prototype.hasOwnProperty.call(e,n)&&r.indexOf(n)<0&&(t[n]=e[n])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var l=0;for(n=Object.getOwnPropertySymbols(e);l<n.length;l++){r.indexOf(n[l])<0&&Object.prototype.propertyIsEnumerable.call(e,n[l])&&(t[n[l]]=e[n[l]])}}return t};import{Fragment as r,jsx as t,jsxs as n}from"react/jsx-runtime";import{Effects as l,shapeFilterToCSS as s}from"@polotno/core/filters";import{cn as a}from"../lib/utils.js";export const EffectCard=({title:e,imageSrc:r,effect:l,onClick:s,active:o})=>{const i=f(l);return n("div",{role:"button",tabIndex:0,"aria-pressed":!!o,className:"pn:flex pn:flex-col pn:gap-2 pn:cursor-pointer pn:flex-grow-0 pn:w-[calc(33%-16px)]",onClick:s,onKeyDown:e=>{"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),null==s||s())},children:[n("div",{className:"pn:relative pn:h-[90px] pn:rounded-[10px] pn:box-border",children:[t("div",{"data-active":o?"true":void 0,className:a("pn:absolute pn:-left-1 pn:-top-1 pn:-bottom-1 pn:-right-1 pn:flex pn:rounded-[15px] pn:p-[2px] pn:transition-[border] pn:duration-200 pn:border-2 pn:border-transparent",o&&"pn:border-white")}),t(i,{src:r})]}),t("span",{className:"pn:text-center",children:e})]})};const o=r=>{var{className:n,style:l}=r,s=e(r,["className","style"]);return t("img",Object.assign({crossOrigin:"anonymous",className:a("pn:h-full pn:w-full pn:rounded-[10px] pn:object-cover",n),style:l},s))},i=e=>t(o,Object.assign({style:{filter:"sepia(1)"}},e)),p=e=>t(o,Object.assign({style:{filter:"grayscale(1)"}},e)),c=e=>{const r=s(l.warm);return t(o,Object.assign({style:{filter:null==r?void 0:r.filter}},e))},u=e=>{const a=s(l.cold),i=null==a?void 0:a.html,p=null==a?void 0:a.filter;return n(r,{children:[t("div",{style:{display:"none"},dangerouslySetInnerHTML:{__html:i||""}}),t(o,Object.assign({style:{filter:p}},e))]})},d=e=>{const r=s(l.natural);return t(o,Object.assign({style:{filter:null==r?void 0:r.filter}},e))},f=e=>{switch(e){case l.sepia:return i;case l.grayscale:return p;case l.warm:return c;case l.cold:return u;case l.natural:return d;default:return o}};
@@ -1 +1 @@
1
- import{Fragment as e,jsx as a,jsxs as o}from"react/jsx-runtime";import r from"react";import{Slider as l}from"../primitives/slider.js";import{firstSliderValue as t}from"../lib/utils.js";import{SliderField as n}from"../primitives/slider-field.js";import{FieldGroup as i}from"../primitives/field-group.js";import{observer as s}from"mobx-react-lite";import{INDEPENDENT_FILTERS as d}from"../model/shape-model.js";import{ColorPicker as c}from"../toolbar/color-picker.js";import{t as b}from"../utils/l10n.js";import{EffectCard as h}from"./effect-card.js";import{TextEffectPresets as u}from"./text-effect-presets.js";import{Effects as p}from"@polotno/core/filters";import{CurvePowerSlider as m}from"../toolbar/filters-picker.js";import{NumericInput as f}from"../primitives/numeric-input.js";import{FieldRow as g}from"../primitives/field-row.js";import{PanelHeader as v}from"../primitives/panel-header.js";import{ToggleGroup as C,ToggleGroupItem as x}from"../primitives/toggle-group.js";import{normalizeStrokeLineJoin as y}from"@polotno/core/text-html";import{defaultFade as w,insertFadeStop as k,fadePreview as j,fadeStopColor as E,FADE_CHECKERBOARD as M}from"../utils/fade-gradient.js";import{Button as S}from"../primitives/button.js";import{canRemoveStop as O,reverseStops as z}from"../utils/stops.js";import{StopTrack as F}from"../toolbar/stop-track.js";import{useFadeStopFocus as R}from"../hooks/use-fade-stop-focus.js";import{getSelectedFadeStop as V,setSelectedFadeStop as P}from"../utils/fade-overlay.js";import{readClipFade as N,writeClipFade as L}from"../utils/clip-fade.js";import{urlToBase64 as B}from"@polotno/core/svg";import{isAlive as W}from"mobx-state-tree";import{PanelScrollArea as X}from"../primitives/panel-scroll-area.js";const Y=[{value:"round",labelKey:"toolbar.joinRound"},{value:"miter",labelKey:"toolbar.joinMiter"},{value:"bevel",labelKey:"toolbar.joinBevel"}],$=({join:e})=>a("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:a("path",{d:"M7 21 L7 7 L21 7",stroke:"currentColor",strokeWidth:"9",strokeLinejoin:e,strokeLinecap:"butt"})});export{f as NumberInput};const K=(e,a,o)=>Math.max(a,Math.min(o,e)),J=(e,a)=>Math.max(e,Math.ceil(a)),I=(e,a)=>Math.min(e,Math.floor(a)),T=[["temperature","toolbar.temperature"],["contrast","toolbar.contrast"],["shadows","toolbar.shadows"],["white","toolbar.white"],["black","toolbar.black"],["vibrance","toolbar.vibrance"],["saturation","toolbar.saturation"]],D=s(({store:l,elements:t})=>{const[n,s]=r.useState(""),[d,c]=r.useState(!1),h=t.filter(e=>["image","video","gif","lottie"].includes(e.type)),u=h[0];if(!u){return null}const p=N(u.clipSrc);return o(e,{children:[a(i,{label:b("toolbar.clipFade.title"),enabled:!!p,disabled:d,onEnabledChange:e=>{(async e=>{if(!d){c(!0),s("");try{const a=await Promise.all(h.map(async a=>{var o;const r=a.clipSrc,l=N(r),t=null!==(o=null==l?void 0:l.baseSrc)&&void 0!==o?o:r,n=e&&t&&!t.startsWith("data:")?await B(t,{binary:!0}):t;return{item:a,previous:r,clipSrc:e?L(w(),n):null==l?void 0:l.baseSrc}}));l.history.transaction(()=>a.forEach(({item:e,previous:a,clipSrc:o})=>{W(e)&&e.clipSrc===a&&null!=o&&e.set({clipSrc:o})}))}catch(n){s(n instanceof Error?n.message:String(n))}finally{c(!1)}}})(e)},children:p&&a(q,{store:l,element:u,value:p.fade,onChange:e=>l.history.transaction(()=>{h.forEach(a=>{if(!W(a)){return}const o=N(a.clipSrc);o&&a.set({clipSrc:L(e,o.baseSrc)})})})},u.id)}),d&&a("div",{role:"status",children:b("toolbar.clipFade.preparing")}),n&&a("div",{role:"alert",children:n})]})}),q=s(({store:l,element:t,value:i,onChange:s})=>{const d=Math.min(V(l),i.stops.length-1),c=i.stops[d],h=r.useRef(null),u=e=>P(l,e);R(l,t.id,e=>{var a,o;return u(e),null!==(o=null===(a=h.current)||void 0===a?void 0:a.focus(e))&&void 0!==o&&o});const p=e=>{u(e.index),s(Object.assign(Object.assign({},i),{stops:e.stops}))};return o(e,{children:[a(g,{label:b("toolbar.clipFade.shape"),children:o(C,{value:[i.shape],onValueChange:e=>{const a=e[0];"linear"!==a&&"radial"!==a||a===i.shape||s(Object.assign(Object.assign({},w(a)),{stops:i.stops}))},children:[a(x,{value:"linear","aria-label":b("toolbar.clipFade.linear"),children:b("toolbar.clipFade.linear")}),a(x,{value:"radial","aria-label":b("toolbar.clipFade.radial"),children:b("toolbar.clipFade.radial")})]})}),a("p",{className:"pn:py-1 pn:text-xs pn:text-muted-foreground",children:b("toolbar.clipFade.hint")}),a("div",{className:"pn:px-3",children:a(F,{handle:h,store:l,node:t,label:b("toolbar.clipFade.stops"),stops:i.stops,selected:d,onSelect:u,onChange:p,insert:k,stopLabel:(e,a)=>`${b("toolbar.clipFade.stop")} ${a+1}: ${Math.round(100*e.alpha)}%`,swatch:e=>E(e.alpha),bar:a("div",{className:"pn:size-full",style:{background:`${j(i.stops)}, ${M}`}})})}),a(n,{label:b("toolbar.clipFade.stopOpacity"),value:Math.round(100*c.alpha),min:0,max:100,onChange:e=>s(Object.assign(Object.assign({},i),{stops:i.stops.map((a,o)=>o===d?Object.assign(Object.assign({},a),{alpha:e/100}):a)}))}),o("div",{className:"pn:flex pn:flex-wrap pn:justify-end pn:gap-1 pn:py-1",children:[a(S,{variant:"ghost",size:"sm",onClick:()=>p({stops:z(i.stops),index:i.stops.length-1-d}),children:b("toolbar.clipFade.reverse")}),a(S,{variant:"ghost",size:"sm",disabled:!O(i.stops),onClick:()=>{var e;return null===(e=h.current)||void 0===e?void 0:e.remove(d)},children:b("toolbar.clipFade.removeStop")}),a(S,{variant:"ghost",size:"sm",onClick:()=>{u(0),s(w(i.shape))},children:b("toolbar.clipFade.reset")})]})]})}),A=({store:e,color:r,onColorChange:n,value:i,onValueChange:s,min:d,max:b,sliderMax:h,gradientEnabled:u=!0})=>o("div",{style:{display:"flex",alignItems:"center",padding:"8px 0"},children:[a(c,{value:r,size:30,gradientEnabled:u,onChange:n,store:e}),a("div",{style:{flex:1,paddingLeft:"10px",paddingRight:"10px"},children:a(l,{value:[i],onValueChange:e=>s(K(Math.round(t(e)),d,b)),min:d,max:null!=h?h:b,step:1})}),a(f,{value:Math.round(i),onValueChange:e=>s(K(e,d,b)),min:d,max:b,style:{width:64}})]});export const EffectsPanel=s(({store:e})=>{var l;const t=e.selectedElements,s=t[0],w=t.map(e=>e.id).join(","),k="effects"===e.openedSidePanel;if(r.useEffect(()=>{k&&(s&&s.filters||e.restoreSidePanel())},[k,w]),!s||!s.filters){return null}const j="text"===s.type,E="image"===s.type,M="svg"===s.type,S=E||M,O=["image","video","gif","lottie"].includes(s.type),z=Math.min(s.width,s.height)/2,F=Math.min(null!==(l=s.cornerRadius)&&void 0!==l?l:0,z),R=a=>{e.history.transaction(()=>{t.forEach(e=>{e.set(a)})})},V=(a,o)=>{e.history.transaction(()=>{t.forEach(e=>{let r=Number(o);return 0==o||o||(r=e.filters.has(a)?null:1),d.includes(a)||e.set({grayscaleEnabled:"grayscale"===a&&!!o,sepiaEnabled:"sepia"===a&&!!o}),e.setFilter(a,r)})})};return o(X,{header:a(v,{title:b("sidePanel.effects"),onClose:()=>e.restoreSidePanel()}),children:[j&&a(u,{store:e}),S&&a("div",{style:{display:"flex",flexDirection:"column",gap:"16px",marginTop:"16px"},children:o("div",{style:{display:"flex",gap:"16px",flexWrap:"wrap"},children:[a(h,{active:s.grayscaleEnabled,onClick:()=>{V("grayscale",!s.grayscaleEnabled)},title:b("toolbar.grayscale"),imageSrc:s.src,effect:p.grayscale}),a(h,{active:s.sepiaEnabled,onClick:()=>{V("sepia",!s.sepiaEnabled)},title:b("toolbar.sepia"),imageSrc:s.src,effect:p.sepia}),a(h,{active:s.filters.has("cold"),onClick:()=>{V("cold",s.filters.has("cold")?null:1)},title:b("toolbar.cold"),imageSrc:s.src,effect:p.cold}),a(h,{active:s.filters.has("natural"),onClick:()=>{V("natural",s.filters.has("natural")?null:1)},title:b("toolbar.natural"),imageSrc:s.src,effect:p.natural}),a(h,{active:s.filters.has("warm"),onClick:()=>{V("warm",s.filters.has("warm")?null:1)},title:b("toolbar.warm"),imageSrc:s.src,effect:p.warm})]})}),a(n,{label:b("toolbar.blur"),enabled:s.blurEnabled,visible:S||j,onEnabledChange:e=>{R({blurEnabled:e})},value:s.blurRadius,onChange:e=>{R({blurRadius:e})},min:0,max:100}),a(n,{label:b("toolbar.brightness"),visible:S,enabled:s.brightnessEnabled,onEnabledChange:e=>{R({brightnessEnabled:e})},value:Math.round(100*s.brightness),onChange:e=>{R({brightness:e/100})},min:-100,max:100}),T.map(([e,o])=>{var r,l;return a(n,{label:b(o),visible:S,enabled:s.filters.has(e),onEnabledChange:a=>{V(e,a?0:null)},value:Math.round(100*(null!==(l=null===(r=s.filters.get(e))||void 0===r?void 0:r.intensity)&&void 0!==l?l:0)),onChange:a=>{V(e,a/100)},min:-100,max:100},e)}),j&&o(i,{label:b("toolbar.curvedText")||"Curved text",enabled:!!s.curveEnabled,onEnabledChange:e=>R({curveEnabled:e}),children:[a(g,{label:b("toolbar.curvePower")||"Curve",className:"pn:py-2",children:a(f,{value:Math.round(100*s.curvePower),onValueChange:e=>{R({curvePower:K(e,-100,100)/100})},style:{width:64},min:-100,max:100})}),a(m,{textEl:s,eachSet:R})]}),j&&o(i,{label:b("toolbar.textStroke"),enabled:!!s.strokeWidth,onEnabledChange:e=>R({strokeWidth:e?2:0}),children:[a(A,{store:e,color:s.stroke,onColorChange:e=>{R({stroke:e})},value:s.strokeWidth,onValueChange:e=>{R({strokeWidth:e})},min:1,max:Math.max(1,Math.round(s.fontSize/2)),sliderMax:Math.max(1,s.fontSize/2)}),a(g,{label:b("toolbar.strokeLineJoin"),className:"pn:py-2",children:a(C,{variant:"outline",value:[y(s.strokeLineJoin)],onValueChange:e=>{const a=e[0];a&&R({strokeLineJoin:a})},children:Y.map(({value:e,labelKey:o})=>a(x,{value:e,"aria-label":b(o),title:b(o),children:a($,{join:e})},e))})})]}),j&&o(i,{label:b("toolbar.textBackground"),enabled:!!s.backgroundEnabled,onEnabledChange:e=>R({backgroundEnabled:e}),children:[a(n,{label:b("toolbar.opacity"),value:Math.round(100*s.backgroundOpacity),onChange:e=>R({backgroundOpacity:e/100}),min:0,max:100}),a(g,{label:b("toolbar.color"),className:"pn:py-2",children:a(c,{value:s.backgroundColor,size:30,onChange:e=>{R({backgroundColor:e})},store:e})})]}),j&&a(i,{label:b("toolbar.border"),enabled:!!s.borderSize,onEnabledChange:e=>R({borderSize:e?2:0}),children:a(A,{store:e,color:s.borderColor,onColorChange:e=>R({borderColor:e}),value:s.borderSize,onValueChange:e=>R({borderSize:e}),min:1,max:Math.max(1,Math.round(s.fontSize/2)),gradientEnabled:!1})}),j&&(s.backgroundEnabled||s.borderSize>0)&&o(i,{label:b("toolbar.textBox"),children:[a(n,{label:b("toolbar.backgroundCornerRadius"),value:Math.round(100*s.backgroundCornerRadius),onChange:e=>R({backgroundCornerRadius:e/100}),min:0,max:200}),a(n,{label:b("toolbar.backgroundPadding"),value:Math.round(100*s.backgroundPadding),onChange:e=>R({backgroundPadding:e/100}),min:0,max:100})]}),S&&a(i,{label:b("toolbar.border"),enabled:!!s.borderSize,onEnabledChange:e=>R({borderSize:e?2:0}),children:a(A,{store:e,color:s.borderColor,onColorChange:e=>{R({borderColor:e})},value:s.borderSize,onValueChange:e=>{R({borderSize:e})},min:1,max:Math.max(1,Math.round(z)),sliderMax:Math.max(1,z)})}),S&&a(n,{label:b("toolbar.cornerRadius"),visible:S,enabled:0!==s.cornerRadius,onEnabledChange:e=>{R({cornerRadius:e?Math.min(s.width/4,s.height/4):0})},value:Math.round(F),sliderValue:F,onChange:e=>{R({cornerRadius:e})},min:1,max:Math.round(z),sliderMax:z}),O&&a(D,{store:e,elements:t}),o(i,{label:b("toolbar.shadow"),enabled:s.shadowEnabled,onEnabledChange:e=>R({shadowEnabled:e}),children:[a(n,{label:b("toolbar.blur"),value:Math.round(s.shadowBlur),sliderValue:s.shadowBlur,onChange:e=>{R({shadowBlur:e})},min:0,max:J(50,s.shadowBlur)}),a(n,{label:b("toolbar.offsetX"),value:Math.round(s.shadowOffsetX),sliderValue:s.shadowOffsetX,onChange:e=>{R({shadowOffsetX:e})},min:I(-50,s.shadowOffsetX),max:J(50,s.shadowOffsetX)}),a(n,{label:b("toolbar.offsetY"),value:Math.round(s.shadowOffsetY),sliderValue:s.shadowOffsetY,onChange:e=>{R({shadowOffsetY:e})},min:I(-50,s.shadowOffsetY),max:J(50,s.shadowOffsetY)}),a(n,{label:b("toolbar.opacity"),value:Math.round(100*s.shadowOpacity),onChange:e=>{R({shadowOpacity:e/100})},min:0,max:100}),a(g,{label:b("toolbar.color"),className:"pn:py-2",children:a(c,{value:s.shadowColor,size:30,onChange:e=>{R({shadowColor:e})},store:e})})]})]})});
1
+ import{Fragment as e,jsx as a,jsxs as o}from"react/jsx-runtime";import r from"react";import{Slider as l}from"../primitives/slider.js";import{firstSliderValue as t}from"../lib/utils.js";import{SliderField as n}from"../primitives/slider-field.js";import{FieldGroup as i}from"../primitives/field-group.js";import{observer as s}from"mobx-react-lite";import{INDEPENDENT_FILTERS as d}from"../model/shape-model.js";import{ColorPicker as c}from"../toolbar/color-picker.js";import{t as b}from"../utils/l10n.js";import{EffectCard as h}from"./effect-card.js";import{TextEffectPresets as u}from"./text-effect-presets.js";import{Effects as p}from"@polotno/core/filters";import{CurvePowerSlider as m}from"../toolbar/filters-picker.js";import{NumericInput as g}from"../primitives/numeric-input.js";import{FieldRow as f}from"../primitives/field-row.js";import{Switch as v}from"../primitives/switch.js";import{PanelHeader as C}from"../primitives/panel-header.js";import{ToggleGroup as x,ToggleGroupItem as k}from"../primitives/toggle-group.js";import{normalizeStrokeLineJoin as y}from"@polotno/core/text-html";import{defaultFade as S,insertFadeStop as w,fadePreview as j,fadeStopColor as E,FADE_CHECKERBOARD as M}from"../utils/fade-gradient.js";import{Button as O}from"../primitives/button.js";import{canRemoveStop as z,reverseStops as F}from"../utils/stops.js";import{StopTrack as V}from"../toolbar/stop-track.js";import{useFadeStopFocus as N}from"../hooks/use-fade-stop-focus.js";import{getSelectedFadeStop as R,setSelectedFadeStop as P}from"../utils/fade-overlay.js";import{readClipFade as L,writeClipFade as B}from"../utils/clip-fade.js";import{urlToBase64 as W}from"@polotno/core/svg";import{isAlive as X}from"mobx-state-tree";import{PanelScrollArea as Y}from"../primitives/panel-scroll-area.js";const $=[{value:"round",labelKey:"toolbar.joinRound"},{value:"miter",labelKey:"toolbar.joinMiter"},{value:"bevel",labelKey:"toolbar.joinBevel"}],K=({join:e})=>a("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:a("path",{d:"M7 21 L7 7 L21 7",stroke:"currentColor",strokeWidth:"9",strokeLinejoin:e,strokeLinecap:"butt"})});export{g as NumberInput};const J=(e,a,o)=>Math.max(a,Math.min(o,e)),I=(e,a)=>Math.max(e,Math.ceil(a)),T=(e,a)=>Math.min(e,Math.floor(a)),D=[["temperature","toolbar.temperature"],["contrast","toolbar.contrast"],["shadows","toolbar.shadows"],["white","toolbar.white"],["black","toolbar.black"],["vibrance","toolbar.vibrance"],["saturation","toolbar.saturation"]],q=s(({store:l,elements:t})=>{const[n,s]=r.useState(""),[d,c]=r.useState(!1),h=t.filter(e=>["image","video","gif","lottie"].includes(e.type)),u=h[0];if(!u){return null}const p=L(u.clipSrc);return o(e,{children:[a(i,{label:b("toolbar.clipFade.title"),enabled:!!p,disabled:d,onEnabledChange:e=>{(async e=>{if(!d){c(!0),s("");try{const a=await Promise.all(h.map(async a=>{var o;const r=a.clipSrc,l=L(r),t=null!==(o=null==l?void 0:l.baseSrc)&&void 0!==o?o:r,n=e&&t&&!t.startsWith("data:")?await W(t,{binary:!0}):t;return{item:a,previous:r,clipSrc:e?B(S(),n):null==l?void 0:l.baseSrc}}));l.history.transaction(()=>a.forEach(({item:e,previous:a,clipSrc:o})=>{X(e)&&e.clipSrc===a&&null!=o&&e.set({clipSrc:o})}))}catch(n){s(n instanceof Error?n.message:String(n))}finally{c(!1)}}})(e)},children:p&&a(A,{store:l,element:u,value:p.fade,onChange:e=>l.history.transaction(()=>{h.forEach(a=>{if(!X(a)){return}const o=L(a.clipSrc);o&&a.set({clipSrc:B(e,o.baseSrc)})})})},u.id)}),d&&a("div",{role:"status",children:b("toolbar.clipFade.preparing")}),n&&a("div",{role:"alert",children:n})]})}),A=s(({store:l,element:t,value:i,onChange:s})=>{const d=Math.min(R(l),i.stops.length-1),c=i.stops[d],h=r.useRef(null),u=e=>P(l,e);N(l,t.id,e=>{var a,o;return u(e),null!==(o=null===(a=h.current)||void 0===a?void 0:a.focus(e))&&void 0!==o&&o});const p=e=>{u(e.index),s(Object.assign(Object.assign({},i),{stops:e.stops}))};return o(e,{children:[a(f,{label:b("toolbar.clipFade.shape"),children:o(x,{value:[i.shape],onValueChange:e=>{const a=e[0];"linear"!==a&&"radial"!==a||a===i.shape||s(Object.assign(Object.assign({},S(a)),{stops:i.stops}))},children:[a(k,{value:"linear","aria-label":b("toolbar.clipFade.linear"),children:b("toolbar.clipFade.linear")}),a(k,{value:"radial","aria-label":b("toolbar.clipFade.radial"),children:b("toolbar.clipFade.radial")})]})}),a("p",{className:"pn:py-1 pn:text-xs pn:text-muted-foreground",children:b("toolbar.clipFade.hint")}),a("div",{className:"pn:px-3",children:a(V,{handle:h,store:l,node:t,label:b("toolbar.clipFade.stops"),stops:i.stops,selected:d,onSelect:u,onChange:p,insert:w,stopLabel:(e,a)=>`${b("toolbar.clipFade.stop")} ${a+1}: ${Math.round(100*e.alpha)}%`,swatch:e=>E(e.alpha),bar:a("div",{className:"pn:size-full",style:{background:`${j(i.stops)}, ${M}`}})})}),a(n,{label:b("toolbar.clipFade.stopOpacity"),value:Math.round(100*c.alpha),min:0,max:100,onChange:e=>s(Object.assign(Object.assign({},i),{stops:i.stops.map((a,o)=>o===d?Object.assign(Object.assign({},a),{alpha:e/100}):a)}))}),o("div",{className:"pn:flex pn:flex-wrap pn:justify-end pn:gap-1 pn:py-1",children:[a(O,{variant:"ghost",size:"sm",onClick:()=>p({stops:F(i.stops),index:i.stops.length-1-d}),children:b("toolbar.clipFade.reverse")}),a(O,{variant:"ghost",size:"sm",disabled:!z(i.stops),onClick:()=>{var e;return null===(e=h.current)||void 0===e?void 0:e.remove(d)},children:b("toolbar.clipFade.removeStop")}),a(O,{variant:"ghost",size:"sm",onClick:()=>{u(0),s(S(i.shape))},children:b("toolbar.clipFade.reset")})]})]})}),G=({store:e,color:r,onColorChange:n,value:i,onValueChange:s,min:d,max:b,sliderMax:h,gradientEnabled:u=!0})=>o("div",{style:{display:"flex",alignItems:"center",padding:"8px 0"},children:[a(c,{value:r,size:30,gradientEnabled:u,onChange:n,store:e}),a("div",{style:{flex:1,paddingLeft:"10px",paddingRight:"10px"},children:a(l,{value:[i],onValueChange:e=>s(J(Math.round(t(e)),d,b)),min:d,max:null!=h?h:b,step:1})}),a(g,{value:Math.round(i),onValueChange:e=>s(J(e,d,b)),min:d,max:b,style:{width:64}})]});export const EffectsPanel=s(({store:l})=>{var t;const s=l.selectedElements,S=s[0],w=s.map(e=>e.id).join(","),j="effects"===l.openedSidePanel;if(r.useEffect(()=>{j&&(S&&S.filters||l.restoreSidePanel())},[j,w]),!S||!S.filters){return null}const E="text"===S.type,M="image"===S.type,O="svg"===S.type,z=M||O,F=["image","video","gif","lottie"].includes(S.type),V=Math.min(S.width,S.height)/2,N=Math.min(null!==(t=S.cornerRadius)&&void 0!==t?t:0,V),R=e=>{l.history.transaction(()=>{s.forEach(a=>{a.set(e)})})},P=(e,a)=>{l.history.transaction(()=>{s.forEach(o=>{let r=Number(a);return 0==a||a||(r=o.filters.has(e)?null:1),d.includes(e)||o.set({grayscaleEnabled:"grayscale"===e&&!!a,sepiaEnabled:"sepia"===e&&!!a}),o.setFilter(e,r)})})};return o(Y,{header:a(C,{title:b("sidePanel.effects"),onClose:()=>l.restoreSidePanel()}),children:[E&&a(u,{store:l}),z&&a("div",{style:{display:"flex",flexDirection:"column",gap:"16px",marginTop:"16px"},children:o("div",{style:{display:"flex",gap:"16px",flexWrap:"wrap"},children:[a(h,{active:S.grayscaleEnabled,onClick:()=>{P("grayscale",!S.grayscaleEnabled)},title:b("toolbar.grayscale"),imageSrc:S.src,effect:p.grayscale}),a(h,{active:S.sepiaEnabled,onClick:()=>{P("sepia",!S.sepiaEnabled)},title:b("toolbar.sepia"),imageSrc:S.src,effect:p.sepia}),a(h,{active:S.filters.has("cold"),onClick:()=>{P("cold",S.filters.has("cold")?null:1)},title:b("toolbar.cold"),imageSrc:S.src,effect:p.cold}),a(h,{active:S.filters.has("natural"),onClick:()=>{P("natural",S.filters.has("natural")?null:1)},title:b("toolbar.natural"),imageSrc:S.src,effect:p.natural}),a(h,{active:S.filters.has("warm"),onClick:()=>{P("warm",S.filters.has("warm")?null:1)},title:b("toolbar.warm"),imageSrc:S.src,effect:p.warm})]})}),a(n,{label:b("toolbar.blur"),enabled:S.blurEnabled,visible:z||E,onEnabledChange:e=>{R({blurEnabled:e})},value:S.blurRadius,onChange:e=>{R({blurRadius:e})},min:0,max:100}),a(n,{label:b("toolbar.brightness"),visible:z,enabled:S.brightnessEnabled,onEnabledChange:e=>{R({brightnessEnabled:e})},value:Math.round(100*S.brightness),onChange:e=>{R({brightness:e/100})},min:-100,max:100}),D.map(([e,o])=>{var r,l;return a(n,{label:b(o),visible:z,enabled:S.filters.has(e),onEnabledChange:a=>{P(e,a?0:null)},value:Math.round(100*(null!==(l=null===(r=S.filters.get(e))||void 0===r?void 0:r.intensity)&&void 0!==l?l:0)),onChange:a=>{P(e,a/100)},min:-100,max:100},e)}),E&&o(i,{label:b("toolbar.curvedText")||"Curved text",enabled:!!S.curveEnabled,onEnabledChange:e=>R({curveEnabled:e}),children:[a(f,{label:b("toolbar.curvePower")||"Curve",className:"pn:py-2",children:a(g,{value:Math.round(100*S.curvePower),onValueChange:e=>{R({curvePower:J(e,-100,100)/100})},style:{width:64},min:-100,max:100})}),a(m,{textEl:S,eachSet:R})]}),E&&o(i,{label:b("toolbar.textStroke"),enabled:!!S.strokeWidth,onEnabledChange:e=>R({strokeWidth:e?2:0}),children:[a(G,{store:l,color:S.stroke,onColorChange:e=>{R({stroke:e})},value:S.strokeWidth,onValueChange:e=>{R({strokeWidth:e})},min:1,max:Math.max(1,Math.round(S.fontSize/2)),sliderMax:Math.max(1,S.fontSize/2)}),a(f,{label:b("toolbar.strokeLineJoin"),className:"pn:py-2",children:a(x,{variant:"outline",value:[y(S.strokeLineJoin)],onValueChange:e=>{const a=e[0];a&&R({strokeLineJoin:a})},children:$.map(({value:e,labelKey:o})=>a(k,{value:e,"aria-label":b(o),title:b(o),children:a(K,{join:e})},e))})})]}),E&&o(i,{label:b("toolbar.textBackground"),enabled:!!S.backgroundEnabled||S.borderSize>0,onEnabledChange:e=>R(e?{backgroundEnabled:!0}:{backgroundEnabled:!1,borderSize:0}),children:[a(f,{label:b("toolbar.backgroundShape"),className:"pn:py-2",children:o(x,{variant:"outline",value:["box"===S.backgroundShape?"box":"lines"],onValueChange:e=>{const a=e[0];a&&R({backgroundShape:a})},children:[a(k,{value:"lines","aria-label":b("toolbar.backgroundShapeLines"),children:b("toolbar.backgroundShapeLines")}),a(k,{value:"box","aria-label":b("toolbar.backgroundShapeBox"),children:b("toolbar.backgroundShapeBox")})]})}),a(f,{label:b("toolbar.backgroundFill"),className:"pn:py-2",children:a(v,{"aria-label":b("toolbar.backgroundFill"),checked:!!S.backgroundEnabled,onCheckedChange:e=>R({backgroundEnabled:e})})}),S.backgroundEnabled&&o(e,{children:[a(f,{label:b("toolbar.color"),className:"pn:py-2",children:a(c,{value:S.backgroundColor,size:30,onChange:e=>{R({backgroundColor:e})},store:l})}),a(n,{label:b("toolbar.opacity"),value:Math.round(100*S.backgroundOpacity),onChange:e=>R({backgroundOpacity:e/100}),min:0,max:100})]}),a(f,{label:b("toolbar.border"),className:"pn:py-2",children:a(v,{"aria-label":b("toolbar.border"),checked:S.borderSize>0,onCheckedChange:e=>R({borderSize:e?2:0})})}),S.borderSize>0&&a(G,{store:l,color:S.borderColor,onColorChange:e=>R({borderColor:e}),value:S.borderSize,onValueChange:e=>R({borderSize:e}),min:1,max:Math.max(1,Math.round(S.fontSize/2)),gradientEnabled:!1}),a(n,{label:b("toolbar.backgroundCornerRadius"),value:Math.round(100*S.backgroundCornerRadius),onChange:e=>R({backgroundCornerRadius:e/100}),min:0,max:200}),a(n,{label:b("toolbar.backgroundPadding"),value:Math.round(100*S.backgroundPadding),onChange:e=>R({backgroundPadding:e/100}),min:0,max:100})]}),z&&a(i,{label:b("toolbar.border"),enabled:!!S.borderSize,onEnabledChange:e=>R({borderSize:e?2:0}),children:a(G,{store:l,color:S.borderColor,onColorChange:e=>{R({borderColor:e})},value:S.borderSize,onValueChange:e=>{R({borderSize:e})},min:1,max:Math.max(1,Math.round(V)),sliderMax:Math.max(1,V)})}),z&&a(n,{label:b("toolbar.cornerRadius"),visible:z,enabled:0!==S.cornerRadius,onEnabledChange:e=>{R({cornerRadius:e?Math.min(S.width/4,S.height/4):0})},value:Math.round(N),sliderValue:N,onChange:e=>{R({cornerRadius:e})},min:1,max:Math.round(V),sliderMax:V}),F&&a(q,{store:l,elements:s}),o(i,{label:b("toolbar.shadow"),enabled:S.shadowEnabled,onEnabledChange:e=>R({shadowEnabled:e}),children:[a(n,{label:b("toolbar.blur"),value:Math.round(S.shadowBlur),sliderValue:S.shadowBlur,onChange:e=>{R({shadowBlur:e})},min:0,max:I(50,S.shadowBlur)}),a(n,{label:b("toolbar.offsetX"),value:Math.round(S.shadowOffsetX),sliderValue:S.shadowOffsetX,onChange:e=>{R({shadowOffsetX:e})},min:T(-50,S.shadowOffsetX),max:I(50,S.shadowOffsetX)}),a(n,{label:b("toolbar.offsetY"),value:Math.round(S.shadowOffsetY),sliderValue:S.shadowOffsetY,onChange:e=>{R({shadowOffsetY:e})},min:T(-50,S.shadowOffsetY),max:I(50,S.shadowOffsetY)}),a(n,{label:b("toolbar.opacity"),value:Math.round(100*S.shadowOpacity),onChange:e=>{R({shadowOpacity:e/100})},min:0,max:100}),a(f,{label:b("toolbar.color"),className:"pn:py-2",children:a(c,{value:S.shadowColor,size:30,onChange:e=>{R({shadowColor:e})},store:l})})]})]})});
@@ -1 +1 @@
1
- import{jsx as e,jsxs as n}from"react/jsx-runtime";import t from"react";import{registerNextDomDrop as r}from"../canvas/page.js";import{t as l}from"../utils/l10n.js";import{cn as o}from"../lib/utils.js";import{Spinner as a}from"../primitives/spinner.js";const s=({url:t,credit:l,onSelect:s,crossOrigin:p,shadowEnabled:i,itemHeight:c,className:d,onLoad:u,alt:m,pending:g})=>{const h=null==i||i;return e("div",{role:"button",onClick:()=>{s()},className:"polotno-close-panel pn:group/img-wrap pn:p-[5px] pn:w-full pn:md:[&_.credit]:opacity-0 pn:md:hover:[&_.credit]:opacity-100 pn:[&_.credit]:opacity-100",children:n("div",{"data-shadowenabled":h,className:o("pn:relative pn:overflow-hidden pn:rounded-[5px]",h?"pn:shadow-[0_0_5px_rgba(16,22,26,0.3),0_0_0_1px_rgba(16,22,26,0.12)] pn:dark:shadow-[0_0_0_1px_rgba(255,255,255,0.16)]":""),children:[e("img",{className:o("pn:block pn:max-h-[300px] pn:min-h-[50px] pn:w-full pn:cursor-pointer pn:object-contain",d),style:{height:null!=c?c:"auto"},src:t,draggable:!0,loading:"lazy",crossOrigin:p,alt:m,onDragStart:()=>{r(({x:e,y:n},t,r)=>{s({x:e,y:n},t,r)})},onDragEnd:()=>{r(null)},onLoad:u}),g&&e("div",{className:"pn:absolute pn:inset-0 pn:flex pn:items-center pn:justify-center pn:bg-background/70",children:e(a,{className:"pn:size-5 pn:text-muted-foreground"})}),l&&e("div",{className:"credit pn:absolute pn:bottom-0 pn:left-0 pn:w-full pn:bg-gradient-to-b pn:from-transparent pn:via-black/40 pn:to-black/60 pn:p-[3px] pn:pt-[10px] pn:text-center pn:text-[10px] pn:text-white pn:[&_a]:text-white pn:[&_a]:underline",children:l})]})})};export const ImagesGrid=({images:r,onSelect:o,isLoading:p,getPreview:i,loadMore:c,getCredit:d,getAlt:u,getImageClassName:m,getIsLoading:g,rowsNumber:h,crossOrigin:f="anonymous",shadowEnabled:x,itemHeight:b,error:v,hideNoResults:w=!1})=>{const N=h||2,_=t.useRef(null),y=[];for(var j=0;j<N;j++){y.push((r||[]).filter((e,n)=>n%N===j))}const H=t.useRef(null),k=()=>{var e;const n=_.current,t=!!n&&n.scrollHeight>n.offsetHeight+5,l=r&&r.length,o=Array.from(null!==(e=null==n?void 0:n.querySelectorAll("img"))&&void 0!==e?e:[]).every(e=>e.complete);!t&&c&&!p&&l&&o&&(H.current||(H.current=window.setTimeout(()=>{H.current=null,c&&c()},100)))},S=()=>{k()};return t.useEffect(()=>(k(),()=>{null!==H.current&&window.clearTimeout(H.current),H.current=null}),[r&&r.length,p]),n("div",{onScroll:e=>{const n=e.target.scrollHeight-e.target.scrollTop-e.target.offsetHeight;c&&!p&&n<200&&c()},ref:_,className:"pn:h-full pn:overflow-auto",children:[y.map((n,t)=>e("div",{className:"pn:float-left",style:{width:100/N+"%"},children:n.map((n,t)=>e(s,{url:i(n),onSelect:(e,t,r)=>o(n,e,t,r),credit:d&&d(n),crossOrigin:f,shadowEnabled:x,itemHeight:b,className:m&&m(n),onLoad:S,alt:u&&u(n)||"",pending:null==g?void 0:g(n)},t))},t)),p&&e("div",{className:"pn:clear-both pn:flex pn:justify-center pn:p-[30px]",children:e(a,{className:"pn:size-5 pn:text-muted-foreground"})}),!p&&(!r||!r.length)&&!v&&!w&&e("p",{className:"pn:p-[30px] pn:text-center",children:l("sidePanel.noResults")}),v&&e("p",{className:"pn:clear-both pn:p-[30px] pn:text-center",children:l("sidePanel.error")})]})};
1
+ import{jsx as e,jsxs as n}from"react/jsx-runtime";import t from"react";import{registerNextDomDrop as r}from"../canvas/page.js";import{t as l}from"../utils/l10n.js";import{cn as a}from"../lib/utils.js";import{Spinner as o}from"../primitives/spinner.js";const s=({url:t,credit:l,onSelect:s,crossOrigin:p,shadowEnabled:i,itemHeight:c,className:d,onLoad:u,alt:m,pending:g})=>{const h=null==i||i;return e("div",{role:"button",tabIndex:0,onClick:()=>{s()},onKeyDown:e=>{e.target===e.currentTarget&&("Enter"!==e.key&&" "!==e.key||(e.preventDefault(),s()))},className:"polotno-close-panel pn:group/img-wrap pn:p-[5px] pn:w-full pn:md:[&_.credit]:opacity-0 pn:md:hover:[&_.credit]:opacity-100 pn:[&_.credit]:opacity-100",children:n("div",{"data-shadowenabled":h,className:a("pn:relative pn:overflow-hidden pn:rounded-[5px]",h?"pn:shadow-[0_0_5px_rgba(16,22,26,0.3),0_0_0_1px_rgba(16,22,26,0.12)] pn:dark:shadow-[0_0_0_1px_rgba(255,255,255,0.16)]":""),children:[e("img",{className:a("pn:block pn:max-h-[300px] pn:min-h-[50px] pn:w-full pn:cursor-pointer pn:object-contain",d),style:{height:null!=c?c:"auto"},src:t,draggable:!0,loading:"lazy",crossOrigin:p,alt:m,onDragStart:e=>{e.dataTransfer.setData("text/plain",t),r(({x:e,y:n},t,r)=>{s({x:e,y:n},t,r)})},onDragEnd:()=>{r(null)},onLoad:u}),g&&e("div",{className:"pn:absolute pn:inset-0 pn:flex pn:items-center pn:justify-center pn:bg-background/70",children:e(o,{className:"pn:size-5 pn:text-muted-foreground"})}),l&&e("div",{className:"credit pn:absolute pn:bottom-0 pn:left-0 pn:w-full pn:bg-gradient-to-b pn:from-transparent pn:via-black/40 pn:to-black/60 pn:p-[3px] pn:pt-[10px] pn:text-center pn:text-[10px] pn:text-white pn:[&_a]:text-white pn:[&_a]:underline",children:l})]})})};export const ImagesGrid=({images:r,onSelect:a,isLoading:p,getPreview:i,loadMore:c,getCredit:d,getAlt:u,getImageClassName:m,getIsLoading:g,rowsNumber:h,crossOrigin:f="anonymous",shadowEnabled:x,itemHeight:b,error:v,hideNoResults:w=!1})=>{const y=h||2,N=t.useRef(null),_=[];for(var j=0;j<y;j++){_.push((r||[]).filter((e,n)=>n%y===j))}const k=t.useRef(null),H=()=>{var e;const n=N.current,t=!!n&&n.scrollHeight>n.offsetHeight+5,l=r&&r.length,a=Array.from(null!==(e=null==n?void 0:n.querySelectorAll("img"))&&void 0!==e?e:[]).every(e=>e.complete);!t&&c&&!p&&l&&a&&(k.current||(k.current=window.setTimeout(()=>{k.current=null,c&&c()},100)))},E=()=>{H()};return t.useEffect(()=>(H(),()=>{null!==k.current&&window.clearTimeout(k.current),k.current=null}),[r&&r.length,p]),n("div",{onScroll:e=>{const n=e.target.scrollHeight-e.target.scrollTop-e.target.offsetHeight;c&&!p&&n<200&&c()},ref:N,className:"pn:h-full pn:overflow-auto",children:[_.map((n,t)=>e("div",{className:"pn:float-left",style:{width:100/y+"%"},children:n.map((n,t)=>e(s,{url:i(n),onSelect:(e,t,r)=>a(n,e,t,r),credit:d&&d(n),crossOrigin:f,shadowEnabled:x,itemHeight:b,className:m&&m(n),onLoad:E,alt:u&&u(n)||"",pending:null==g?void 0:g(n)},t))},t)),p&&e("div",{className:"pn:clear-both pn:flex pn:justify-center pn:p-[30px]",children:e(o,{className:"pn:size-5 pn:text-muted-foreground"})}),!p&&(!r||!r.length)&&!v&&!w&&e("p",{className:"pn:p-[30px] pn:text-center",children:l("sidePanel.noResults")}),v&&e("p",{className:"pn:clear-both pn:p-[30px] pn:text-center",children:l("sidePanel.error")})]})};
@@ -1 +1 @@
1
- import{jsx as e,jsxs as n}from"react/jsx-runtime";import t from"react";import{action as i,observable as l,reaction as o}from"mobx";import{observer as s}from"mobx-react-lite";import{Button as r}from"../primitives/button.js";import{Input as a}from"../primitives/input.js";import{ROLES as d}from"../model/store.js";import{unboundWrite as c}from"../model/node-model.js";import{t as m}from"../utils/l10n.js";import{isMobile as p}from"../utils/screen.js";import{ReactSortable as h}from"react-sortablejs";import{removeTags as u}from"@polotno/core/text";import{PolotnoIcon as g}from"../icons/registry.js";import{cn as f}from"../lib/utils.js";import{PanelScrollArea as v}from"../primitives/panel-scroll-area.js";import{getLayerClickSelection as x,getLayerRows as y}from"./layer-selection.js";import{getParentGroupId as b}from"../utils/selection.js";const E=(e,n)=>!!n.selectable||e.role===d.ADMIN,k=e=>e.stopPropagation(),j=s(({element:i,ctx:l})=>{var o;const{store:s,expandedIds:d}=l,p=s.selectedElements.indexOf(i)>=0,h="group"===i.type,v=null!==(o=i.filled.visible)&&void 0!==o?o:i.visible,x=h&&d.has(i.id),[y,b]=t.useState(!1),j=()=>b(!1),I=t.useRef(null),N=p&&1===s.selectedElements.length;t.useEffect(()=>{var e,n;N&&(null===(n=null===(e=I.current)||void 0===e?void 0:e.scrollIntoView)||void 0===n||n.call(e,{block:"nearest"}))},[N]);const P=()=>{s.highlightedElementId===i.id&&s.highlightElement(null)};t.useEffect(()=>P,[s,i.id]);const z=y?i.name:i.name||("text"in i?u(i.text):"")||`#${i.id}`;return n("div",{style:{display:E(s,i)?"auto":"none"},children:[e("div",{ref:I,"data-layer-id":i.id,onMouseDown:e=>{l.onRowMouseDown(i.id,e)},onPointerEnter:e=>{"mouse"===e.pointerType&&s.highlightElement(i.id)},onPointerLeave:P,className:f("pn:rounded-md pn:border pn:bg-card pn:p-[5px] pn:mx-[1px] pn:mb-[5px] pn:shadow-sm",p&&"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(g,{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:h?e(r,{variant:"ghost",size:"icon-sm",className:"pn:size-5","aria-expanded":x,onMouseDown:k,onClick:()=>l.toggleExpanded(i.id),children:e(g,{name:x?"ui.chevronDown":"ui.chevronRight",className:"pn:size-4"})}):null}),e("div",{style:{padding:"0 7px",opacity:.5,width:"60px"},children:m("sidePanel.layerTypes."+i.type)}),e("div",{className:"pn:min-w-0 pn:flex-1",children:e(a,{value:z,onFocus:()=>b(!0),onBlur:j,placeholder:m("sidePanel.namePlaceholder"),onChange:e=>{i.set({name:e.target.value})},onKeyDown:e=>{"Enter"!==e.key&&"Escape"!==e.key||(j(),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:k,children:[e(r,{variant:"ghost",size:"icon-sm",onClick:()=>{i.set(c(i,{visible:!v}))},children:e(g,v?{name:"action.visible"}:{name:"action.hidden"})}),e(r,{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(g,{name:"action.lock"}):e(g,{name:"action.unlock"})}),e(r,{variant:"ghost",size:"icon-sm",disabled:!i.removable,onClick:()=>{s.deleteElements([i.id])},style:{marginLeft:"auto"},children:e(g,{name:"action.remove"})})]})]})}),x?e(w,{container:i,ctx:l}):null]})}),w=s(({container:n,ctx:t})=>{const{store:i}=t,l=n.children.slice().reverse(),o=l.map(e=>({id:e.id})),s=p(),r=n!==i.activePage;return e(h,{list:o,setList:e=>{const t=e.filter(e=>null!=e&&null!=e.id);t.forEach((e,l)=>{const o=t.length-l-1,s=i.getElementById(e.id);s&&n.children.indexOf(s)!==o&&n.setElementZIndex(s.id,o)})},group:n.id,direction:"horizontal",handle:s?".drag-handle":void 0,className:r?"pn:ml-4":void 0,children:l.map(n=>e(j,{element:n,ctx:t},n.id))})});export const LayersPanel=s(({store:s})=>{const r=s.activePage,[a]=t.useState(()=>l.map()),d=t.useRef(null);t.useEffect(()=>o(()=>{const e=[];return s.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}),[s,a]);const c=t.useMemo(()=>({store:s,expandedIds:a,toggleExpanded:i(e=>{a.delete(e)||a.set(e,!0)}),onRowMouseDown:(e,n)=>{const t=s.activePage;if(!t){return}const i=x({clickedId:e,selectedIds:s.selectedElementsIds,anchorId:d.current,rows:y(t,a,e=>E(s,e)),modifiers:n,getParentId:e=>b(s,e)});d.current=i.anchorId,s.selectElements(i.selectedIds)}}),[s,a]);return n(v,{children:[e("div",{style:{height:"40px",paddingTop:"5px"},children:m("sidePanel.layersTip")}),n("div",{children:[r&&0!==r.children.length?null:e("div",{children:m("sidePanel.noLayers")}),r?e(w,{container:r,ctx:c}):null]})]})});
1
+ import{jsx as e,jsxs as n}from"react/jsx-runtime";import t from"react";import{action as r,observable as i,reaction as l}from"mobx";import{observer as s}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{unboundWrite as c}from"../model/node-model.js";import{t as p}from"../utils/l10n.js";import{isMobile as m}from"../utils/screen.js";import{ReactSortable as h}from"react-sortablejs";import{removeTags as u}from"@polotno/core/text";import{PolotnoIcon as f}from"../icons/registry.js";import{cn as g}from"../lib/utils.js";import{PanelScrollArea as v}from"../primitives/panel-scroll-area.js";import{getLayerClickSelection as x,getLayerRows as b}from"./layer-selection.js";import{getParentGroupId as y}from"../utils/selection.js";const k=(e,n)=>!!n.selectable||e.role===d.ADMIN,w=e=>e.stopPropagation(),E=s(({element:r,ctx:i})=>{var l;const{store:s,expandedIds:d}=i,m=s.selectedElements.indexOf(r)>=0,h="group"===r.type,v=null!==(l=r.filled.visible)&&void 0!==l?l:r.visible,x=h&&d.has(r.id),[b,y]=t.useState(!1),E=()=>y(!1),I=t.useRef(null),P=m&&1===s.selectedElements.length;t.useEffect(()=>{var e,n;P&&(null===(n=null===(e=I.current)||void 0===e?void 0:e.scrollIntoView)||void 0===n||n.call(e,{block:"nearest"}))},[P]);const N=()=>{s.highlightedElementId===r.id&&s.highlightElement(null)};t.useEffect(()=>N,[s,r.id]);const D=e=>{const n=r.parent;if(!n){return}const t=n.children;let i=t.indexOf(r)+e;for(;t[i]&&!k(s,t[i]);){i+=e}t[i]&&n.setElementZIndex(r.id,i)},z=b?r.name:r.name||("text"in r?u(r.text):"")||`#${r.id}`;return n("div",{style:{display:k(s,r)?"auto":"none"},children:[e("div",{ref:I,"data-layer-id":r.id,tabIndex:0,onMouseDown:e=>{i.onRowMouseDown(r.id,e)},onClick:e=>{e.currentTarget.matches(":focus-visible")||e.currentTarget.blur()},onKeyDown:e=>{if(e.target===e.currentTarget){switch(e.key){case"Enter":case" ":i.onRowMouseDown(r.id,e);break;case"ArrowUp":D(1);break;case"ArrowDown":D(-1);break;case"ArrowLeft":case"ArrowRight":break;default:return}e.preventDefault(),e.stopPropagation()}},onPointerEnter:e=>{"mouse"===e.pointerType&&s.highlightElement(r.id)},onPointerLeave:N,className:g("pn:rounded-md pn:border pn:bg-card pn:p-[5px] pn:mx-[1px] pn:mb-[5px] pn:shadow-sm",m&&"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(f,{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:h?e(o,{variant:"ghost",size:"icon-sm",className:"pn:size-5","aria-expanded":x,onMouseDown:w,onClick:()=>i.toggleExpanded(r.id),children:e(f,{name:x?"ui.chevronDown":"ui.chevronRight",className:"pn:size-4"})}):null}),e("div",{style:{padding:"0 7px",opacity:.5,width:"60px"},children:p("sidePanel.layerTypes."+r.type)}),e("div",{className:"pn:min-w-0 pn:flex-1",children:e(a,{value:z,onFocus:()=>y(!0),onBlur:E,placeholder:p("sidePanel.namePlaceholder"),onChange:e=>{r.set({name:e.target.value})},onKeyDown:e=>{"Enter"!==e.key&&"Escape"!==e.key||(E(),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:w,children:[e(o,{variant:"ghost",size:"icon-sm","aria-label":p("sidePanel.hideLayer"),"aria-pressed":!v,onClick:()=>{r.set(c(r,{visible:!v}))},children:e(f,v?{name:"action.visible"}:{name:"action.hidden"})}),e(o,{variant:"ghost",size:"icon-sm","aria-label":p("sidePanel.lockLayer"),"aria-pressed":!!r.locked,onClick:()=>{r.set({draggable:r.locked,contentEditable:r.locked,styleEditable:r.locked,resizable:r.locked,removable:r.locked})},children:(null==r?void 0:r.locked)?e(f,{name:"action.lock"}):e(f,{name:"action.unlock"})}),e(o,{variant:"ghost",size:"icon-sm","aria-label":p("sidePanel.deleteLayer"),disabled:!r.removable,onClick:()=>{s.deleteElements([r.id])},style:{marginLeft:"auto"},children:e(f,{name:"action.remove"})})]})]})}),x?e(j,{container:r,ctx:i}):null]})}),j=s(({container:n,ctx:t})=>{const{store:r}=t,i=n.children.slice().reverse(),l=i.map(e=>({id:e.id})),s=m(),o=n!==r.activePage;return e(h,{list:l,setList:e=>{const t=e.filter(e=>null!=e&&null!=e.id);t.forEach((e,i)=>{const l=t.length-i-1,s=r.getElementById(e.id);s&&n.children.indexOf(s)!==l&&n.setElementZIndex(s.id,l)})},group:n.id,direction:"horizontal",handle:s?".drag-handle":void 0,className:o?"pn:ml-4":void 0,children:i.map(n=>e(E,{element:n,ctx:t},n.id))})});export const LayersPanel=s(({store:s})=>{const o=s.activePage,[a]=t.useState(()=>i.map()),d=t.useRef(null);t.useEffect(()=>l(()=>{const e=[];return s.selectedElements.forEach(n=>{for(let t=n.parent;t&&"group"===t.type;t=t.parent){e.push(t.id)}}),e},r(e=>{e.forEach(e=>a.set(e,!0))}),{equals:(e,n)=>e.length===n.length&&e.every((e,t)=>e===n[t]),fireImmediately:!0}),[s,a]);const c=t.useMemo(()=>({store:s,expandedIds:a,toggleExpanded:r(e=>{a.delete(e)||a.set(e,!0)}),onRowMouseDown:(e,n)=>{const t=s.activePage;if(!t){return}const r=x({clickedId:e,selectedIds:s.selectedElementsIds,anchorId:d.current,rows:b(t,a,e=>k(s,e)),modifiers:n,getParentId:e=>y(s,e)});d.current=r.anchorId,s.selectElements(r.selectedIds)}}),[s,a]);return n(v,{children:[e("div",{style:{height:"40px",paddingTop:"5px"},children:p("sidePanel.layersTip")}),n("div",{children:[o&&0!==o.children.length?null:e("div",{children:p("sidePanel.noLayers")}),o?e(j,{container:o,ctx:c}):null]})]})});
@@ -1,3 +1 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { cn } from '../lib/utils.js';
3
- export const SectionTab = ({ children, name, onClick, active, iconSize, }) => (_jsxs("div", { role: "button", onClick: onClick, className: cn('polotno-side-panel-tab pn-section-tab pn:w-full pn:cursor-pointer pn:whitespace-pre pn:text-center pn:text-[12px]', 'pn:pt-[15px] pn:pl-[5px] pn:pr-[5px] pn:h-[72px]', 'pn:max-md:h-[54px] pn:max-md:pt-[9px] pn:max-md:min-w-[72px] pn:max-md:w-min', 'pn:pn-mobile:h-[54px] pn:pn-mobile:pt-[9px] pn:pn-mobile:min-w-[72px] pn:pn-mobile:w-min', 'pn:hover:bg-sidebar-accent pn:hover:text-sidebar-accent-foreground', active && 'active pn:bg-sidebar-accent pn:text-sidebar-accent-foreground'), children: [_jsx("div", { style: { fontSize: (iconSize || 14) + 'px' }, children: children }), _jsx("div", { style: { paddingTop: '5px' }, children: name })] }));
1
+ import{jsx as n,jsxs as e}from"react/jsx-runtime";import{cn as p}from"../lib/utils.js";export const SectionTab=({children:t,name:i,onClick:r,active:o,iconSize:a})=>e("div",{role:"button",tabIndex:0,onClick:r,onKeyDown:n=>{"Enter"!==n.key&&" "!==n.key||(n.preventDefault(),n.currentTarget.click())},className:p("polotno-side-panel-tab pn-section-tab pn:w-full pn:cursor-pointer pn:whitespace-pre pn:text-center pn:text-[12px]","pn:pt-[15px] pn:pl-[5px] pn:pr-[5px] pn:h-[72px]","pn:max-md:h-[54px] pn:max-md:pt-[9px] pn:max-md:min-w-[72px] pn:max-md:w-min","pn:pn-mobile:h-[54px] pn:pn-mobile:pt-[9px] pn:pn-mobile:min-w-[72px] pn:pn-mobile:w-min","pn:hover:bg-sidebar-accent pn:hover:text-sidebar-accent-foreground",o&&"active pn:bg-sidebar-accent pn:text-sidebar-accent-foreground"),children:[n("div",{style:{fontSize:(a||14)+"px"},children:t}),n("div",{style:{paddingTop:"5px"},children:i})]});
@@ -1 +1 @@
1
- import{jsx as e,jsxs as t}from"react/jsx-runtime";import*as s from"react";import{observer as r}from"mobx-react-lite";import{nanoid as i}from"nanoid";import{forEveryChild as a}from"../model/group-model.js";import{t as o}from"../utils/l10n.js";import{ImagesGrid as n}from"./images-grid.js";import{templateList as l}from"../utils/api.js";import{useInfiniteAPI as m}from"../utils/use-api.js";import{SearchInput as p}from"../primitives/search-input.js";import{Switch as c}from"../primitives/switch.js";const h=(e,t)=>{const r=s.useRef(!0);s.useEffect(()=>{r.current?r.current=!1:e()},t)},g=r(({sizeQuery:t,query:s,store:r})=>{const{setQuery:o,loadMore:p,hasMore:c,data:g,isLoading:d,reset:u,error:f}=m({getAPI:({page:e,query:s})=>l({page:e,query:s,sizeQuery:t}),getSize:e=>e.totalPages});return h(()=>{u()},[t]),h(()=>{o(s)},[s]),e(n,{images:null==g?void 0:g.map(e=>e.items).flat(),getPreview:e=>e.preview,isLoading:d,onSelect:async e=>{const t=await fetch(e.json),s=await t.json();if(r.pages.length<=1){r.loadJSON(s,!0)}else{const e=JSON.parse(JSON.stringify(r.toJSON()));e.width===s.width&&e.height===s.height||s.pages.forEach(e=>{e.width=e.width||s.width,e.height=e.height||s.height}),a({children:s.pages},e=>{e.id=i(10)});const t=r.pages.indexOf(r.activePage);e.pages.splice(t,1,...s.pages),r.loadJSON(e,!0)}},loadMore:c&&p,error:f})});export const TemplatesPanel=r(({store:r})=>{const[i,a]=s.useState(!0),[n,l]=s.useState(""),m=i?`${r.width}x${r.height}`:"all";return t("div",{className:"pn:flex pn:h-full pn:flex-col",children:[e(p,{style:{marginBottom:"20px"},placeholder:o("sidePanel.searchPlaceholder"),onChange:e=>{l(e.target.value)}}),t("label",{className:"pn:flex pn:items-center pn:justify-between",style:{marginTop:"8px",marginBottom:"25px"},children:[t("span",{className:"pn:text-sm",children:[o("sidePanel.searchTemplatesWithSameSize")," "]}),e(c,{checked:i,onCheckedChange:e=>{a(Boolean(e))}})]}),e(g,{store:r,sizeQuery:"size="+m,query:n})]})});
1
+ import{jsx as e,jsxs as t}from"react/jsx-runtime";import*as r from"react";import{observer as o}from"mobx-react-lite";import{linkHref as a,linkPageId as s}from"@polotno/core/links";import{mapLinks as i}from"@polotno/core/page-links";import{renewIds as n}from"../model/group-model.js";import{t as l}from"../utils/l10n.js";import{ImagesGrid as p}from"./images-grid.js";import{templateList as m}from"../utils/api.js";import{useInfiniteAPI as c}from"../utils/use-api.js";import{SearchInput as u}from"../primitives/search-input.js";import{Switch as h}from"../primitives/switch.js";const d=(e,t)=>{const o=r.useRef(!0);r.useEffect(()=>{o.current?o.current=!1:e()},t)},g=o(({sizeQuery:t,query:o,store:l})=>{const{setQuery:u,loadMore:h,hasMore:g,data:f,isLoading:v,reset:w,error:x}=c({getAPI:({page:e,query:r})=>m({page:e,query:r,sizeQuery:t}),getSize:e=>e.totalPages}),[y,j]=r.useState(null),S=r.useRef(0);return d(()=>{w()},[t]),d(()=>{u(o)},[o]),e(p,{images:null==f?void 0:f.map(e=>e.items).flat(),getPreview:e=>e.preview,isLoading:v,onSelect:async e=>{const t=++S.current;j(null);try{const r=await fetch(e.json);if(!r.ok){throw new Error(`polotno: template request failed with ${r.status}`)}const o=await r.json();t===S.current&&((e,t)=>{var r;if(e.pages.length<=1){return void e.loadJSON(t,!0)}const o=JSON.parse(JSON.stringify(e.toJSON()));o.width===t.width&&o.height===t.height||t.pages.forEach(e=>{e.width=e.width||t.width,e.height=e.height||t.height});const l=t.pages.map(e=>e.id);var p,m;n({children:t.pages}),p=t.pages,m=new Map(l.map((e,r)=>[e,t.pages[r].id])),i({children:p},e=>{const t=a(e),r=t&&s(t),o=r&&m.get(r);return o?"#"+o:e}),(null===(r=t.variables)||void 0===r?void 0:r.length)&&(o.variables=((e=[],t)=>{const r=new Map(e.map(e=>[e.name,e]));for(const o of t){const e=r.get(o.name);null==(null==e?void 0:e.value)&&null==(null==e?void 0:e.default)&&r.set(o.name,o)}return[...r.values()]})(o.variables,t.variables));const c=e.pages.indexOf(e.activePage);o.pages.splice(c,1,...t.pages),e.loadJSON(o,!0)})(l,o)}catch(r){if(t!==S.current){return}console.warn("polotno: failed to load the template",r),j(r)}},loadMore:g&&h,error:x||y})});export const TemplatesPanel=o(({store:o})=>{const[a,s]=r.useState(!0),[i,n]=r.useState(""),p=a?`${o.width}x${o.height}`:"all";return t("div",{className:"pn:flex pn:h-full pn:flex-col",children:[e(u,{style:{marginBottom:"20px"},placeholder:l("sidePanel.searchPlaceholder"),onChange:e=>{n(e.target.value)}}),t("label",{className:"pn:flex pn:items-center pn:justify-between",style:{marginTop:"8px",marginBottom:"25px"},children:[t("span",{className:"pn:text-sm",children:[l("sidePanel.searchTemplatesWithSameSize")," "]}),e(h,{checked:a,onCheckedChange:e=>{s(Boolean(e))}})]}),e(g,{store:o,sizeQuery:"size="+p,query:i})]})});
@@ -1 +1 @@
1
- var e=this&&this.__rest||function(e,o){var r={};for(var t in e){Object.prototype.hasOwnProperty.call(e,t)&&o.indexOf(t)<0&&(r[t]=e[t])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(t=Object.getOwnPropertySymbols(e);n<t.length;n++){o.indexOf(t[n])<0&&Object.prototype.propertyIsEnumerable.call(e,t[n])&&(r[t[n]]=e[t[n]])}}return r};import{jsx as o,jsxs as r}from"react/jsx-runtime";import t from"react";import{observer as n}from"mobx-react-lite";import{t as l}from"../utils/l10n.js";import{isGradient as s,parseColor as a}from"@polotno/core/gradient";import{sameColors as i}from"@polotno/core/svg";import{formatCmykColor as c,isCmykColor as p,toDisplayColor as d}from"@polotno/core/color";import u,{cmykFromColor as m}from"./sketch.js";import{addStop as h,insertStop as f,readGradient as g,writeGradient as v}from"../utils/gradient-stops.js";import{canRemoveStop as b,reverseStops as C}from"../utils/stops.js";import{StopTrack as x}from"./stop-track.js";import{PolotnoIcon as y}from"../icons/registry.js";import{cn as k,firstSliderValue as w}from"../lib/utils.js";import{NumericInput as E}from"../primitives/numeric-input.js";import{Slider as N}from"../primitives/slider.js";import{TooltipIconButton as j}from"../primitives/tooltip-icon-button.js";import{Popover as O,PopoverContent as P,PopoverTrigger as F}from"../primitives/popover.js";import{Tabs as S,TabsContent as $,TabsList as B,TabsTrigger as R}from"../primitives/tabs.js";export const DEFAULT_COLORS=["#D0021B","#F5A623","#F8E71C","#8B572A","#7ED321","#417505","#BD10E0","#9013FE","#4A90E2","#50E3C2","#B8E986","#000000","#4A4A4A","#9B9B9B","#FFFFFF"].reverse();export const getUsedColors=e=>{const o=[];e.pages.forEach(e=>{e.children.forEach(e=>{e.shadowEnabled&&o.push(e.shadowColor),"text"===e.type&&(o.push(e.fill),e.backgroundEnabled&&o.push(e.backgroundColor),e.strokeWidth&&o.push(e.stroke)),"svg"===e.type&&o.push(...e.colorsReplace.values()),"figure"===e.type&&(o.push(e.fill),e.strokeWidth&&o.push(e.stroke)),"line"===e.type&&o.push(e.color)})});const r=[];return o.forEach(e=>{if(s(e)){const{stops:o}=g(e);r.push(...o.map(e=>e.color))}else{r.push(e)}}),[...new Set(r)]};const z=r=>{var{style:n,color:l,onChange:s}=r,a=e(r,["style","color","onChange"]);const[i,p]=t.useState(l);t.useEffect(()=>{p(l)},[l]);const d=t.useRef(void 0),m=t.useRef(void 0);return o("div",{className:"pn-color-picker-solid",style:n,onMouseDown:e=>{"INPUT"!==e.target.tagName&&e.preventDefault()},children:o(u,Object.assign({color:i},a,{onChange:e=>{const{r:o,g:r,b:t,a:n}=e.rgb,l=e.cmyk?c(e.cmyk):`rgba(${o},${r},${t},${n})`;p(l),m.current=l,d.current||(d.current=window.setTimeout(()=>{d.current=0,s(m.current||l)},50))}}))})},D=({value:e,onChange:n,store:s,preset:i})=>{var u,k;const{rotation:O,stops:P}=g(e),F=t.useId(),[S,$]=t.useState(0),B=Math.min(S,P.length-1),R=t.useRef(null),D=t.useRef(null),A=(e,o=O)=>n(v({rotation:o,stops:e})),I=e=>{$(e.index),A(e.stops)},M=v({rotation:90,stops:P});return t.useLayoutEffect(()=>{const e=D.current,o=e.getContext("2d"),r=o.createLinearGradient(0,0,e.width,0);a(M).stops.forEach(({offset:e,color:o})=>r.addColorStop(e,o)),o.clearRect(0,0,e.width,1),o.fillStyle=r,o.fillRect(0,0,e.width,1)},[M]),r("div",{className:"pn:flex pn:flex-col pn:gap-1 pn:pt-2",children:[o("div",{className:"pn:mx-2.5",children:o(x,{handle:R,store:s,node:null!==(k=null!==(u=s.selectedElements[0])&&void 0!==u?u:s.activePage)&&void 0!==k?k:void 0,label:l("toolbar.colorPicker.stops"),stops:P,selected:B,onSelect:$,onChange:I,insert:f,stopLabel:(e,o)=>`${l("toolbar.colorPicker.stop")} ${o+1}: ${Math.round(100*e.offset)}%`,swatch:e=>{const o=d(e.color);return`linear-gradient(${o}, ${o}), ${L}`},bar:o("canvas",{ref:D,width:512,height:1,"aria-hidden":!0,className:"pn:block pn:size-full",style:{backgroundImage:L}})})}),r("div",{className:"pn:flex pn:items-center pn:gap-1 pn:px-2.5",children:[o(j,{label:l("toolbar.colorPicker.addStop"),onClick:()=>I(h(P)),children:o(y,{name:"action.add",className:"pn:size-4"})}),o(j,{label:l("toolbar.colorPicker.removeStop"),disabled:!b(P),onClick:()=>{var e;return null===(e=R.current)||void 0===e?void 0:e.remove(B)},children:o(y,{name:"action.remove",className:"pn:size-4"})}),o(j,{label:l("toolbar.colorPicker.reverse"),onClick:()=>I({stops:C(P),index:P.length-1-B}),children:o(y,{name:"colorPicker.reverseGradient",className:"pn:size-4"})}),o("label",{id:`${F}-label`,className:"pn:ml-auto pn:text-sm",htmlFor:F,children:l("toolbar.colorPicker.angle")}),r("div",{className:"pn:relative",children:[o(E,{id:F,value:O,min:0,max:360,onValueChange:e=>A(P,e),style:{width:64},className:"pn:pl-1 pn:pr-8"}),o("span",{"aria-hidden":!0,className:"pn:pointer-events-none pn:absolute pn:right-6 pn:top-1/2 pn:-translate-y-1/2 pn:text-sm pn:text-muted-foreground",children:"°"})]})]}),o("div",{className:"pn:px-2.5 pn:py-1",children:o(N,{"aria-labelledby":`${F}-label`,value:[O],min:0,max:360,onValueChange:e=>A(P,Math.round(w(e)))})}),o(z,{color:P[B].color,presetColors:i,onChange:e=>A(P.map((o,r)=>{return{offset:o.offset,color:r===B?e:(t=e,n=o.color,p(t)?p(n)?n:c(m(n)):p(n)?d(n):n)};var t,n}))})]})},A=n(({value:e,onChange:n,preset:a,store:i})=>{const[c,p]=t.useState(s(e)?"gradient":"solid");return o("div",{style:{padding:"5px"},children:r(S,{value:c,onValueChange:e=>p(e),className:"pn:w-full",children:[r(B,{className:"pn:flex pn:w-full pn:flex-row",children:[o(R,{value:"solid",className:"pn:flex-1",children:l("toolbar.colorPicker.solid")}),o(R,{value:"gradient",className:"pn:flex-1",children:l("toolbar.colorPicker.linear")})]}),o($,{value:"solid",className:"pn:w-full",children:o(z,{color:s(e)?g(e).stops[0].color:e,onChange:n,presetColors:a,style:{padding:"0"}})}),o($,{value:"gradient",className:"ember-panel pn:w-full",children:o(D,{value:e,onChange:n,store:i,preset:a})})]})})}),L="url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 8 8'%3E%3Cg fill='rgba(112, 112, 116, 1)' fill-opacity='1'%3E%3Cpath fill-rule='evenodd' d='M0 0h4v4H0V0zm4 4h4v4H4V4z'/%3E%3C/g%3E%3C/svg%3E\")";export const ColoredBox=t.forwardRef(function(r,t){var{size:n=30,background:l,style:s={},className:a,children:i=null}=r,c=e(r,["size","background","style","className","children"]);const p="string"==typeof l?d(l):"transparent",u=p.includes("gradient")?p:`linear-gradient(${p}, ${p}), ${L}`;return o("div",Object.assign({ref:t,role:"button",tabIndex:0,"aria-label":"Pick color",onMouseDown:e=>e.preventDefault(),className:k("pn:flex pn:cursor-pointer pn:items-center pn:justify-center pn:overflow-hidden pn:rounded-md pn:border pn:border-foreground/30",a),style:Object.assign({width:n+"px",height:n+"px",backgroundImage:u},s)},c,{children:i}))});let I=e=>{const o=getUsedColors(e).slice(0,8).filter(e=>!DEFAULT_COLORS.find(o=>i(o,e)));return o.concat(DEFAULT_COLORS.slice(0,16-o.length).reverse())};export function setColorsPresetFunc(e){I=e}const M=({value:e,onChange:r,store:t,gradientEnabled:n,presetColors:l})=>n?o(A,{preset:l,value:e,onChange:r,store:t}):o("div",{style:{padding:"5px"},children:o(z,{color:e,onChange:r,presetColors:l})});let U=M;const T=e=>o(U,Object.assign({},e,{presetColors:I(e.store)}));export function setColorPickerContent(e){U=null!=e?e:M}export const ColorPicker=({value:e,onChange:n,size:l,store:s,gradientEnabled:a,children:i,style:c,onOpen:p,onClose:d})=>{const[u,m]=t.useState(!1);return r(O,{open:u,onOpenChange:e=>{m(e),e?null==p||p():null==d||d()},children:[o(F,{nativeButton:!1,render:o(ColoredBox,{size:l,background:e,style:c,children:i})}),o(P,{className:"pn:w-[280px] pn:p-0",initialFocus:!1,children:o(T,{value:e,onChange:n,store:s,gradientEnabled:!!a})})]})};export default ColorPicker;
1
+ var e=this&&this.__rest||function(e,r){var o={};for(var t in e){Object.prototype.hasOwnProperty.call(e,t)&&r.indexOf(t)<0&&(o[t]=e[t])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(t=Object.getOwnPropertySymbols(e);n<t.length;n++){r.indexOf(t[n])<0&&Object.prototype.propertyIsEnumerable.call(e,t[n])&&(o[t[n]]=e[t[n]])}}return o};import{Fragment as r,jsx as o,jsxs as t}from"react/jsx-runtime";import n from"react";import{observer as l}from"mobx-react-lite";import{t as a}from"../utils/l10n.js";import{isGradient as s,parseColor as i}from"@polotno/core/gradient";import{sameColors as c}from"@polotno/core/svg";import{formatCmykColor as p,isCmykColor as d,toDisplayColor as u}from"@polotno/core/color";import m,{cmykFromColor as h}from"./sketch.js";import{addStop as g,insertStop as f,readGradient as v,writeGradient as b}from"../utils/gradient-stops.js";import{canRemoveStop as C,reverseStops as x}from"../utils/stops.js";import{StopTrack as y}from"./stop-track.js";import{GradientCenterPad as k}from"./gradient-center-pad.js";import{UnitNumericInput as w}from"./unit-numeric-input.js";import{findRadialPaint as j,setRadialHandle as E}from"../utils/gradient-handle.js";import{ToggleGroup as N,ToggleGroupItem as O}from"../primitives/toggle-group.js";import{PolotnoIcon as P}from"../icons/registry.js";import{cn as $,firstSliderValue as F}from"../lib/utils.js";import{Slider as S}from"../primitives/slider.js";import{TooltipIconButton as R}from"../primitives/tooltip-icon-button.js";import{Popover as B,PopoverContent as z,PopoverTrigger as D}from"../primitives/popover.js";import{Tabs as A,TabsContent as L,TabsList as I,TabsTrigger as M}from"../primitives/tabs.js";export const DEFAULT_COLORS=["#D0021B","#F5A623","#F8E71C","#8B572A","#7ED321","#417505","#BD10E0","#9013FE","#4A90E2","#50E3C2","#B8E986","#000000","#4A4A4A","#9B9B9B","#FFFFFF"].reverse();export const getUsedColors=e=>{const r=[];e.pages.forEach(e=>{e.children.forEach(e=>{e.shadowEnabled&&r.push(e.shadowColor),"text"===e.type&&(r.push(e.fill),e.backgroundEnabled&&r.push(e.backgroundColor),e.strokeWidth&&r.push(e.stroke)),"svg"===e.type&&r.push(...e.colorsReplace.values()),"figure"===e.type&&(r.push(e.fill),e.strokeWidth&&r.push(e.stroke)),"line"===e.type&&r.push(e.color)})});const o=[];return r.forEach(e=>{if(s(e)){const{stops:r}=v(e);o.push(...r.map(e=>e.color))}else{o.push(e)}}),[...new Set(o)]};const T=r=>{var{style:t,color:l,onChange:a}=r,s=e(r,["style","color","onChange"]);const[i,c]=n.useState(l);n.useEffect(()=>{c(l)},[l]);const d=n.useRef(void 0),u=n.useRef(void 0);return o("div",{className:"pn-color-picker-solid",style:t,onMouseDown:e=>{"INPUT"!==e.target.tagName&&e.preventDefault()},children:o(m,Object.assign({color:i},s,{onChange:e=>{const{r,g:o,b:t,a:n}=e.rgb,l=e.cmyk?p(e.cmyk):`rgba(${r},${o},${t},${n})`;c(l),u.current=l,d.current||(d.current=window.setTimeout(()=>{d.current=0,a(u.current||l)},50))}}))})},U=({value:e,onChange:l,store:s,preset:c})=>{var m,$;const{type:B,rotation:z,center:D,ending:A,stops:L}=v(e),I=n.useId(),[M,U]=n.useState(0),V=n.useRef(90);"linear"===B&&(V.current=z);const G=Math.min(M,L.length-1),H=n.useRef(null),W=n.useRef(null),q=null!==($=null!==(m=s.selectedElements[0])&&void 0!==m?m:s.activePage)&&void 0!==$?$:void 0,J={type:B,rotation:z,center:D,ending:A,stops:L},K=e=>l(b(Object.assign(Object.assign({},J),e))),Q=(e,r=z)=>K({stops:e,rotation:r}),X=e=>{U(e.index),Q(e.stops)},Y=n.useRef(l);Y.current=l,n.useEffect(()=>{const r="radial"===B&&q&&j(q,e);r&&E(s,Object.assign(Object.assign({},r),{onChange:e=>Y.current(e)}))},[s,B,q,e]),n.useEffect(()=>()=>E(s,null),[s,"radial"===B,q]);const Z=b({rotation:90,stops:L}),ee="radial"===B?`${u(b({type:"radial",rotation:0,center:D,ending:A,stops:L}))}, ${_}`:"";return n.useLayoutEffect(()=>{const e=W.current,r=e.getContext("2d"),o=r.createLinearGradient(0,0,e.width,0);i(Z).stops.forEach(({offset:e,color:r})=>o.addColorStop(e,r)),r.clearRect(0,0,e.width,1),r.fillStyle=o,r.fillRect(0,0,e.width,1)},[Z]),t("div",{className:"pn:flex pn:flex-col pn:gap-1 pn:pt-2",children:[o("div",{className:"pn:px-2.5",children:t(N,{className:"pn:w-full",value:[B],"aria-label":a("toolbar.colorPicker.gradientType"),onValueChange:e=>{const r=e[0];"linear"!==r&&"radial"!==r||(e=>{e!==B&&K("radial"===e?{type:"radial",center:{x:.5,y:.5},ending:"circle"}:{type:"linear",rotation:V.current})})(r)},children:[o(O,{value:"linear",className:"pn:flex-1","aria-label":a("toolbar.colorPicker.linear"),children:a("toolbar.colorPicker.linear")}),o(O,{value:"radial",className:"pn:flex-1","aria-label":a("toolbar.colorPicker.radial"),children:a("toolbar.colorPicker.radial")})]})}),o("div",{className:"pn:mx-2.5",children:o(y,{handle:H,store:s,node:q,label:a("toolbar.colorPicker.stops"),stops:L,selected:G,onSelect:U,onChange:X,insert:f,stopLabel:(e,r)=>`${a("toolbar.colorPicker.stop")} ${r+1}: ${Math.round(100*e.offset)}%`,swatch:e=>{const r=u(e.color);return`linear-gradient(${r}, ${r}), ${_}`},bar:o("canvas",{ref:W,width:512,height:1,"aria-hidden":!0,className:"pn:block pn:size-full",style:{backgroundImage:_}})})}),t("div",{className:"pn:flex pn:items-center pn:gap-1 pn:px-2.5",children:[o(R,{label:a("toolbar.colorPicker.addStop"),onClick:()=>X(g(L)),children:o(P,{name:"action.add",className:"pn:size-4"})}),o(R,{label:a("toolbar.colorPicker.removeStop"),disabled:!C(L),onClick:()=>{var e;return null===(e=H.current)||void 0===e?void 0:e.remove(G)},children:o(P,{name:"action.remove",className:"pn:size-4"})}),o(R,{label:a("toolbar.colorPicker.reverse"),onClick:()=>X({stops:x(L),index:L.length-1-G}),children:o(P,{name:"colorPicker.reverseGradient",className:"pn:size-4"})}),"linear"===B&&t(r,{children:[o("label",{id:`${I}-label`,className:"pn:ml-auto pn:text-sm",htmlFor:I,children:a("toolbar.colorPicker.angle")}),o(w,{id:I,unit:"°",value:z,min:0,max:360,onValueChange:e=>Q(L,e),style:{width:64}})]})]}),"linear"===B?o("div",{className:"pn:px-2.5 pn:py-1",children:o(S,{"aria-labelledby":`${I}-label`,value:[z],min:0,max:360,onValueChange:e=>Q(L,Math.round(F(e)))})}):o(k,{center:D,preview:ee,store:s,node:q,onChange:e=>K({center:e})}),o(T,{color:L[G].color,presetColors:c,onChange:e=>Q(L.map((r,o)=>{return{offset:r.offset,color:o===G?e:(t=e,n=r.color,d(t)?d(n)?n:p(h(n)):d(n)?u(n):n)};var t,n}))})]})},V=l(({value:e,onChange:r,preset:l,store:i})=>{const[c,p]=n.useState(s(e)?"gradient":"solid");return o("div",{style:{padding:"5px"},children:t(A,{value:c,onValueChange:e=>p(e),className:"pn:w-full",children:[t(I,{className:"pn:flex pn:w-full pn:flex-row",children:[o(M,{value:"solid",className:"pn:flex-1",children:a("toolbar.colorPicker.solid")}),o(M,{value:"gradient",className:"pn:flex-1",children:a("toolbar.colorPicker.gradient")})]}),o(L,{value:"solid",className:"pn:w-full",children:o(T,{color:s(e)?v(e).stops[0].color:e,onChange:r,presetColors:l,style:{padding:"0"}})}),o(L,{value:"gradient",className:"ember-panel pn:w-full",children:o(U,{value:e,onChange:r,store:i,preset:l})})]})})}),_="url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 8 8'%3E%3Cg fill='rgba(112, 112, 116, 1)' fill-opacity='1'%3E%3Cpath fill-rule='evenodd' d='M0 0h4v4H0V0zm4 4h4v4H4V4z'/%3E%3C/g%3E%3C/svg%3E\")";export const ColoredBox=n.forwardRef(function(r,t){var{size:n=30,background:l,style:a={},className:s,children:i=null}=r,c=e(r,["size","background","style","className","children"]);const p="string"==typeof l?u(l):"transparent",d=p.includes("gradient")?p:`linear-gradient(${p}, ${p}), ${_}`;return o("div",Object.assign({ref:t,role:"button",tabIndex:0,"aria-label":"Pick color",onMouseDown:e=>e.preventDefault(),className:$("pn:flex pn:cursor-pointer pn:items-center pn:justify-center pn:overflow-hidden pn:rounded-md pn:border pn:border-foreground/30",s),style:Object.assign({width:n+"px",height:n+"px",backgroundImage:d},a)},c,{children:i}))});let G=e=>{const r=getUsedColors(e).slice(0,8).filter(e=>!DEFAULT_COLORS.find(r=>c(r,e)));return r.concat(DEFAULT_COLORS.slice(0,16-r.length).reverse())};export function setColorsPresetFunc(e){G=e}const H=({value:e,onChange:r,store:t,gradientEnabled:n,presetColors:l})=>n?o(V,{preset:l,value:e,onChange:r,store:t}):o("div",{style:{padding:"5px"},children:o(T,{color:e,onChange:r,presetColors:l})});let W=H;const q=e=>o(W,Object.assign({},e,{presetColors:G(e.store)}));export function setColorPickerContent(e){W=null!=e?e:H}export const ColorPicker=({value:e,onChange:r,size:l,store:a,gradientEnabled:s,children:i,style:c,onOpen:p,onClose:d})=>{const[u,m]=n.useState(!1);return t(B,{open:u,onOpenChange:e=>{m(e),e?null==p||p():null==d||d()},children:[o(D,{nativeButton:!1,render:o(ColoredBox,{size:l,background:e,style:c,children:i})}),o(z,{className:"pn:w-[280px] pn:p-0",initialFocus:!1,children:o(q,{value:e,onChange:r,store:a,gradientEnabled:!!s})})]})};export default ColorPicker;
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import type { GradientCenter } from '../utils/gradient-stops.js';
3
+ import type { StoreType } from '../ui-types.js';
4
+ import type { IAnyStateTreeNode } from 'mobx-state-tree';
5
+ export declare const GradientCenterPad: ({ center, preview, onChange, store, node, }: {
6
+ center: GradientCenter;
7
+ preview: string;
8
+ onChange: (center: GradientCenter) => void;
9
+ store: StoreType;
10
+ node?: IAnyStateTreeNode;
11
+ }) => React.JSX.Element;
@@ -0,0 +1 @@
1
+ import{jsx as e,jsxs as n}from"react/jsx-runtime";import r from"react";import{t}from"../utils/l10n.js";import{UnitNumericInput as o}from"./unit-numeric-input.js";import{usePointerDrag as i,isPrimaryDrag as a}from"../utils/pointer-drag.js";import{safe01 as s}from"../utils/stops.js";import{useHistoryGesture as l}from"../utils/history-gesture.js";const p=e=>Math.round(1e3*e)/10;export const GradientCenterPad=({center:c,preview:d,onChange:m,store:u,node:h})=>{const x=r.useRef(null),f=i(),b=l(u,h),g=r.useId(),y=r.useId(),v=(e,n)=>{const r=x.current.getBoundingClientRect();return{x:s((e-r.left)/(r.width||1)),y:s((n-r.top)/(r.height||1))}};return n("div",{className:"pn:flex pn:items-center pn:gap-2 pn:px-2.5",children:[e("div",{ref:x,role:"slider",tabIndex:0,"aria-label":t("toolbar.colorPicker.center"),"aria-valuetext":`${p(c.x)}% ${p(c.y)}%`,"data-gradient-center-pad":!0,className:"pn:relative pn:flex-1 pn:cursor-crosshair pn:touch-none pn:rounded-sm pn:border pn:border-border",style:{height:64,backgroundImage:d},onPointerDown:e=>{a(e)&&(b.begin(),m(v(e.clientX,e.clientY)),f(e,{node:h,slopX:0,onMove:e=>{b.active()&&(0!==e.buttons?m(v(e.clientX,e.clientY)):b.end())},onEnd:b.end}))},onKeyDown:e=>{const n=e.shiftKey?.1:.01,r={ArrowLeft:[-n,0],ArrowRight:[n,0],ArrowUp:[0,-n],ArrowDown:[0,n]}[e.key];r&&(e.preventDefault(),m({x:s(c.x+r[0]),y:s(c.y+r[1])}))},children:e("div",{"aria-hidden":!0,className:"pn:pointer-events-none pn:absolute pn:size-3 pn:-translate-x-1/2 pn:-translate-y-1/2 pn:rounded-full pn:border-2 pn:border-white pn:shadow-[0_0_0_1px_rgba(0,0,0,0.6)]",style:{left:100*c.x+"%",top:100*c.y+"%"}})}),e("div",{className:"pn:flex pn:flex-col pn:gap-1",children:[["x",g,t("toolbar.colorPicker.centerX")],["y",y,t("toolbar.colorPicker.centerY")]].map(([r,t,i])=>n("div",{className:"pn:flex pn:items-center pn:gap-1",children:[e("label",{htmlFor:t,className:"pn:w-4 pn:text-sm",children:r.toUpperCase()}),e(o,{id:t,"aria-label":i,unit:"%",value:p(c[r]),min:0,max:100,onValueChange:e=>m(Object.assign(Object.assign({},c),{[r]:s(e/100)})),style:{width:72}})]},r))})]})};
@@ -1,4 +1,4 @@
1
- import{jsx as t,jsxs as e}from"react/jsx-runtime";import o from"react";import{observer as n}from"mobx-react-lite";import{PolotnoIcon as i}from"../icons/registry.js";import{Button as l}from"../primitives/button.js";import{Tooltip as r,TooltipContent as a,TooltipTrigger as s}from"../primitives/tooltip.js";import{TooltipIconButton as c}from"../primitives/tooltip-icon-button.js";import{ColorPicker as m}from"./color-picker.js";import p from"./filters-picker.js";import{ElementContainer as f,extendToolbar as d}from"./element-container.js";import u from"../utils/styled.js";import{AnimationsPicker as x}from"./animations-picker.js";import{flags as g}from"../utils/flags.js";import{TextAiWrite as v}from"./text-ai-write.js";import{t as h}from"../utils/l10n.js";import{quillRef as b,createQuill as T,setQuillContent as y}from"../canvas/html-element.js";import{editorHtml as S}from"../canvas/rich-editor.js";import{FontMenu as F,fetcher as z,TextSpacing as j,TextFontSize as A,ALIGN_OPTIONS as C,VERTICAL_ALIGN_OPTIONS as N,VERTICAL_ALIGN_ICONS as w}from"./text-toolbar.js";import{cycleNext as E,usedFontFamilies as k}from"./toolbar-shared.js";import D from"swr";import{getFontsList as L,globalFonts as M,isGoogleFontChanged as P}from"../utils/fonts.js";import{getGoogleFontsListAPI as I}from"../utils/api.js";import{quillHtmlToModelText as R,listEffectiveFontFamilies as O,isBoldWeight as W}from"../utils/rich-text-html.js";import{patchTextFormat as B,decorationTokensToString as H,isDecorationActive as V}from"../utils/text-format.js";import{activeFor as _,useTextFormat as G,resolveSelectionScope as J,applyToLiveEditor as U,restoreEditorSelection as X}from"../utils/text-format-state.js";const $=u("div")`
1
+ import{jsx as t,jsxs as e}from"react/jsx-runtime";import o from"react";import{observer as n}from"mobx-react-lite";import{PolotnoIcon as i}from"../icons/registry.js";import{Button as l}from"../primitives/button.js";import{Tooltip as r,TooltipContent as a,TooltipTrigger as s}from"../primitives/tooltip.js";import{TooltipIconButton as c}from"../primitives/tooltip-icon-button.js";import{ColorPicker as m}from"./color-picker.js";import p from"./filters-picker.js";import{ElementContainer as f,extendToolbar as d}from"./element-container.js";import u from"../utils/styled.js";import{AnimationsPicker as x}from"./animations-picker.js";import{flags as g}from"../utils/flags.js";import{TextAiWrite as v}from"./text-ai-write.js";import{t as h}from"../utils/l10n.js";import{quillRef as b,createQuill as T,setQuillContent as y}from"../canvas/html-element.js";import{editorHtml as F}from"../canvas/rich-editor.js";import{FontMenu as S,fetcher as z,TextSpacing as j,TextFontSize as A,ALIGN_OPTIONS as C,VERTICAL_ALIGN_OPTIONS as N,VERTICAL_ALIGN_ICONS as E}from"./text-toolbar.js";import{cycleNext as w,usedFontFamilies as k}from"./toolbar-shared.js";import D from"swr";import{getFontsList as L,globalFonts as M,isGoogleFontChanged as P}from"../utils/fonts.js";import{getGoogleFontsListAPI as I}from"../utils/api.js";import{quillHtmlToModelText as R,listEffectiveFontFamilies as O,isBoldWeight as B}from"../utils/rich-text-html.js";import{patchTextFormat as H,isDecorationActive as V,formatToggle as W}from"../utils/text-format.js";import{activeFor as _,useTextFormat as G,resolveSelectionScope as J,applyToLiveEditor as U,restoreEditorSelection as X}from"../utils/text-format-state.js";const $=u("div")`
2
2
  position: relative;
3
3
  display: inline-block;
4
4
 
@@ -25,4 +25,4 @@ import{jsx as t,jsxs as e}from"react/jsx-runtime";import o from"react";import{ob
25
25
  pointer-events: none;
26
26
  font-size: inherit;
27
27
  color: inherit;
28
- `;let K=null;const Q=()=>{b.pendingToolbarInteraction=!0,K&&clearTimeout(K),K=setTimeout(()=>{b.pendingToolbarInteraction=!1,K=null},100)},Y=t=>{var e;(!(e=t.target)||"INPUT"!==e.tagName&&"TEXTAREA"!==e.tagName&&"SELECT"!==e.tagName&&!e.isContentEditable)&&t.preventDefault(),Q()},Z=n(({store:e,isActive:o,toggle:n,icon:i,ariaLabel:l,tooltipContent:r})=>{const{format:a,applyTextFormat:s}=G(e);return t(c,{label:r||l||"",active:o(a),onMouseDown:t=>{t.preventDefault()},onClick:()=>n(a,s),children:i})});function tt(t,e){const o="underline"===e?"line-through":"underline",n=new Set;return V(t,e)||n.add(e),V(t,o)&&n.add(o),H(n)}const et=(t,e,o)=>e({textDecoration:tt(t,o)},{decorationTokens:[o]});export const TextBold=n(({store:e})=>t(Z,{store:e,isActive:t=>W(t.fontWeight.value),toggle:(t,e)=>e({fontWeight:W(t.fontWeight.value)?400:700}),icon:t(i,{name:"text.bold",className:"pn:size-4"}),tooltipContent:h("toolbar.bold")}));const ot=n(({store:e})=>t("div",{className:"pn:flex pn:items-center pn:gap-0.5",children:t(Z,{store:e,isActive:t=>"uppercase"===t.textTransform.value,toggle:(t,e)=>e({textTransform:"uppercase"===t.textTransform.value?"none":"uppercase"}),icon:t(i,{name:"text.uppercase",className:"pn:size-4"}),tooltipContent:h("toolbar.uppercase")})}));export const FontStyleGroup=n(({element:o,store:n,elements:m,components:p})=>{const f=(null==p?void 0:p.TextBold)||TextBold;return e("div",{className:"pn:flex pn:items-center pn:gap-0.5",children:[t(f,{element:o,store:n}),t(Z,{store:n,isActive:t=>"italic"===t.fontStyle.value,toggle:(t,e)=>e({fontStyle:"italic"===t.fontStyle.value?"normal":"italic"}),icon:t(i,{name:"text.italic",className:"pn:size-4"}),tooltipContent:h("toolbar.italic")}),t(Z,{store:n,isActive:t=>V(t,"underline"),toggle:(t,e)=>et(t,e,"underline"),icon:t(i,{name:"text.underline",className:"pn:size-4"}),tooltipContent:h("toolbar.underline")}),t(Z,{store:n,isActive:t=>V(t,"line-through"),toggle:(t,e)=>et(t,e,"line-through"),icon:t(i,{name:"text.strikethrough",className:"pn:size-4"}),tooltipContent:h("toolbar.strikethrough")}),t(c,{label:h("toolbar.textAlign"),onClick:()=>{const t=E(C,o.align);n.history.transaction(()=>{m.forEach(e=>{e.set({align:t})})})},children:"left"===o.align?t(i,{name:"text.alignLeft",className:"pn:size-4"}):"center"===o.align?t(i,{name:"text.alignCenter",className:"pn:size-4"}):"right"===o.align?t(i,{name:"text.alignRight",className:"pn:size-4"}):t(i,{name:"text.alignJustify",className:"pn:size-4"})}),g.textVerticalResizeEnabled&&e(r,{children:[t(s,{render:t(l,{variant:"ghost",size:"icon-sm",onClick:()=>{const t=E(N,o.verticalAlign);n.history.transaction(()=>{m.forEach(e=>{e.set({verticalAlign:t})})})},"aria-label":h("toolbar.verticalAlign"),children:w[o.verticalAlign]})}),t(a,{children:h("toolbar.verticalAlign")})]}),t(c,{label:h("toolbar.listFormat"),onMouseDown:t=>{t.preventDefault()},onClick:()=>{const t=t=>t?"bullet"===t&&"ordered":"bullet",e=_(n);if(e){const o=e.instance,n=o.getSelection(!0)||e.lastSelection||{index:0,length:o.getLength()};return void o.format("list",t(o.getFormat(n).list))}const o=(({html:t})=>{const e=document.createElement("div");document.body.appendChild(e),e.style.display="none",e.style.whiteSpace="pre-wrap";const o=T(e);return y(o,t),o})({html:S(m[0])});try{const e=t(o.getFormat(0,o.getLength()).list);n.history.transaction(()=>{m.forEach((t,n)=>{n>0&&y(o,S(t)),o.formatLine(0,o.getLength(),"list",e),t.set({text:R(o.root.innerHTML,{fontSize:t.fontSize,fontFamily:t.fontFamily})})})})}finally{(t=>{t.root.parentElement.remove()})(o)}},children:"bullet"===(null!==(u=null===(d=_(n))||void 0===d?void 0:d.currentFormat)&&void 0!==u?u:{}).list?t(i,{name:"text.numberedList",className:"pn:size-5"}):t(i,{name:"text.bulletList",className:"pn:size-5"})})]});var d,u});export const FontColorInput=n(({element:e,store:o})=>{var n;const{format:i,applyTextFormat:l}=G(o);return t("div",{"data-polotno-keep-focus":!0,onMouseDown:Y,children:t(m,{value:null!==(n=i.fill.value)&&void 0!==n?n:e.fill,gradientEnabled:!0,onClose:()=>{const t=_(o);(null==t?void 0:t.lastSelection)&&X(t.instance,t.lastSelection)},onChange:t=>l({fill:t}),store:o})})});export const DirectionInput=n(({element:e})=>{const o="rtl"===e.dir,n=h("toolbar.textDirection");return t(c,{label:n,onClick:()=>{e.set({dir:o?"ltr":"rtl"})},children:t(i,o?{name:"text.paragraph",className:"pn:size-5 pn:-scale-x-100"}:{name:"text.richText",className:"pn:size-5"})})});const nt=L(),it=n(({elements:e,store:n})=>{var i;const{format:l,applyTextFormat:r}=G(n),a=!!_(n),s=l.fontFamily.mixed,c=s?Array.from(new Set(e.flatMap(t=>O(t.text,t.fontFamily)))).sort((t,e)=>t.localeCompare(e,void 0,{sensitivity:"base"})):void 0,[m,p]=o.useState(!1),{data:f,mutate:d}=D(m?I():null,z,{isPaused:()=>P(),fallbackData:[]});o.useEffect(()=>{d()},[P()]);const u=n.fonts.concat(M).map(t=>t.fontFamily).concat((null==f?void 0:f.length)&&!P()?f:nt),x=k(n),g=[...new Set(x.concat("_divider").concat(u))],v=null!==(i=l.fontFamily.value)&&void 0!==i?i:e[0].fontFamily;let h=v;h.length>15&&(h=h.slice(0,15)+"...");const b=t(F,{fonts:g,activeFont:v,activeFontLabel:h,store:n,mixed:s,mixedFonts:c,open:m,onOpenChange:p,onFontSelect:t=>r({fontFamily:t})});return a?t("div",{"data-polotno-keep-focus":!0,onMouseDown:Y,children:b}):b}),lt=n(({elements:o,store:n})=>{const{format:i}=G(n),l=!!_(n),r=i.fontSize.mixed,a=i.fontSize.value,s=o.map(t=>new Proxy(t,{get:(t,e)=>"fontSize"===e?null!=a?a:t.fontSize:"set"===e?e=>((t,e)=>{if(!e.fontSize){return void t.set(e)}const o=_(n);if(o){const{scope:t,isEmpty:n}=J(o.instance,o.lastSelection);if("partial"===t||"collapsed"===t&&n){return void U(o.instance,{fontSize:e.fontSize},o.lastSelection)}}const{attrsToSet:i}=B(t,{fontSize:e.fontSize});t.set(Object.assign(Object.assign({},e),i))})(t,e):Reflect.get(t,e)})),c=e($,{className:r?"polotno-mixed":"",children:[t(A,{elements:s,store:n}),r&&t(q,{className:"polotno-fs-mixed-overlay","aria-hidden":!0,children:"—"})]});return l?t("div",{"data-polotno-keep-focus":!0,onMouseDown:Q,children:c}):c});export const PROPS_MAP={TextFontFamily:it,TextFontSize:lt,TextFontVariant:FontStyleGroup,TextTransform:ot,TextFilters:p,TextFill:FontColorInput,TextSpacing:j,TextDirection:DirectionInput,TextAnimations:x,TextAiWrite:v};export const HtmlToolbar=n(({store:e,components:o})=>{const n=e.selectedElements,i=e.selectedElements[0],l=["TextFill","TextFontFamily","TextFontSize","TextFontVariant","TextSpacing","TextTransform","TextFilters",g.animationsEnabled&&"TextAnimations",g.aiTextEnabled&&"TextAiWrite"],r=d({type:"text",usedItems:l,components:o});return t(f,{items:r,itemRender:l=>{if("TextBold"===l){return null}const r=(null==o?void 0:o[l])||PROPS_MAP[l];return t(r,{element:i,elements:n,store:e,components:o},l)}})});
28
+ `;let K=null;const Q=()=>{b.pendingToolbarInteraction=!0,K&&clearTimeout(K),K=setTimeout(()=>{b.pendingToolbarInteraction=!1,K=null},100)},Y=t=>{var e;(!(e=t.target)||"INPUT"!==e.tagName&&"TEXTAREA"!==e.tagName&&"SELECT"!==e.tagName&&!e.isContentEditable)&&t.preventDefault(),Q()},Z=n(({store:e,isActive:o,toggle:n,icon:i,ariaLabel:l,tooltipContent:r})=>{const{format:a,applyTextFormat:s}=G(e);return t(c,{label:r||l||"",active:o(a),onMouseDown:t=>{t.preventDefault()},onClick:()=>n(a,s),children:i})}),tt=t=>(e,o)=>{const{attrs:n,opts:i}=W(e,t);o(n,i)};export const TextBold=n(({store:e})=>t(Z,{store:e,isActive:t=>B(t.fontWeight.value),toggle:tt("bold"),icon:t(i,{name:"text.bold",className:"pn:size-4"}),tooltipContent:h("toolbar.bold")}));const et=n(({store:e})=>t("div",{className:"pn:flex pn:items-center pn:gap-0.5",children:t(Z,{store:e,isActive:t=>"uppercase"===t.textTransform.value,toggle:(t,e)=>e({textTransform:"uppercase"===t.textTransform.value?"none":"uppercase"}),icon:t(i,{name:"text.uppercase",className:"pn:size-4"}),tooltipContent:h("toolbar.uppercase")})}));export const FontStyleGroup=n(({element:o,store:n,elements:m,components:p})=>{const f=(null==p?void 0:p.TextBold)||TextBold;return e("div",{className:"pn:flex pn:items-center pn:gap-0.5",children:[t(f,{element:o,store:n}),t(Z,{store:n,isActive:t=>"italic"===t.fontStyle.value,toggle:tt("italic"),icon:t(i,{name:"text.italic",className:"pn:size-4"}),tooltipContent:h("toolbar.italic")}),t(Z,{store:n,isActive:t=>V(t,"underline"),toggle:tt("underline"),icon:t(i,{name:"text.underline",className:"pn:size-4"}),tooltipContent:h("toolbar.underline")}),t(Z,{store:n,isActive:t=>V(t,"line-through"),toggle:tt("line-through"),icon:t(i,{name:"text.strikethrough",className:"pn:size-4"}),tooltipContent:h("toolbar.strikethrough")}),t(c,{label:h("toolbar.textAlign"),onClick:()=>{const t=w(C,o.align);n.history.transaction(()=>{m.forEach(e=>{e.set({align:t})})})},children:"left"===o.align?t(i,{name:"text.alignLeft",className:"pn:size-4"}):"center"===o.align?t(i,{name:"text.alignCenter",className:"pn:size-4"}):"right"===o.align?t(i,{name:"text.alignRight",className:"pn:size-4"}):t(i,{name:"text.alignJustify",className:"pn:size-4"})}),g.textVerticalResizeEnabled&&e(r,{children:[t(s,{render:t(l,{variant:"ghost",size:"icon-sm",onClick:()=>{const t=w(N,o.verticalAlign);n.history.transaction(()=>{m.forEach(e=>{e.set({verticalAlign:t})})})},"aria-label":h("toolbar.verticalAlign"),children:E[o.verticalAlign]})}),t(a,{children:h("toolbar.verticalAlign")})]}),t(c,{label:h("toolbar.listFormat"),onMouseDown:t=>{t.preventDefault()},onClick:()=>{const t=t=>t?"bullet"===t&&"ordered":"bullet",e=_(n);if(e){const o=e.instance,n=o.getSelection(!0)||e.lastSelection||{index:0,length:o.getLength()};return void o.format("list",t(o.getFormat(n).list))}const o=(({html:t})=>{const e=document.createElement("div");document.body.appendChild(e),e.style.display="none",e.style.whiteSpace="pre-wrap";const o=T(e);return y(o,t),o})({html:F(m[0])});try{const e=t(o.getFormat(0,o.getLength()).list);n.history.transaction(()=>{m.forEach((t,n)=>{n>0&&y(o,F(t)),o.formatLine(0,o.getLength(),"list",e),t.set({text:R(o.root.innerHTML,{fontSize:t.fontSize,fontFamily:t.fontFamily})})})})}finally{(t=>{t.root.parentElement.remove()})(o)}},children:"bullet"===(null!==(u=null===(d=_(n))||void 0===d?void 0:d.currentFormat)&&void 0!==u?u:{}).list?t(i,{name:"text.numberedList",className:"pn:size-5"}):t(i,{name:"text.bulletList",className:"pn:size-5"})})]});var d,u});export const FontColorInput=n(({element:e,store:o})=>{var n;const{format:i,applyTextFormat:l}=G(o);return t("div",{"data-polotno-keep-focus":!0,onMouseDown:Y,children:t(m,{value:null!==(n=i.fill.value)&&void 0!==n?n:e.fill,gradientEnabled:!0,onClose:()=>{const t=_(o);(null==t?void 0:t.lastSelection)&&X(t.instance,t.lastSelection)},onChange:t=>l({fill:t}),store:o})})});export const DirectionInput=n(({element:e})=>{const o="rtl"===e.dir,n=h("toolbar.textDirection");return t(c,{label:n,onClick:()=>{e.set({dir:o?"ltr":"rtl"})},children:t(i,o?{name:"text.paragraph",className:"pn:size-5 pn:-scale-x-100"}:{name:"text.richText",className:"pn:size-5"})})});const ot=L(),nt=n(({elements:e,store:n})=>{var i;const{format:l,applyTextFormat:r}=G(n),a=!!_(n),s=l.fontFamily.mixed,c=s?Array.from(new Set(e.flatMap(t=>O(t.text,t.fontFamily)))).sort((t,e)=>t.localeCompare(e,void 0,{sensitivity:"base"})):void 0,[m,p]=o.useState(!1),{data:f,mutate:d}=D(m?I():null,z,{isPaused:()=>P(),fallbackData:[]});o.useEffect(()=>{d()},[P()]);const u=n.fonts.concat(M).map(t=>t.fontFamily).concat((null==f?void 0:f.length)&&!P()?f:ot),x=k(n),g=[...new Set(x.concat("_divider").concat(u))],v=null!==(i=l.fontFamily.value)&&void 0!==i?i:e[0].fontFamily;let h=v;h.length>15&&(h=h.slice(0,15)+"...");const b=t(S,{fonts:g,activeFont:v,activeFontLabel:h,store:n,mixed:s,mixedFonts:c,open:m,onOpenChange:p,onFontSelect:t=>r({fontFamily:t})});return a?t("div",{"data-polotno-keep-focus":!0,onMouseDown:Y,children:b}):b}),it=n(({elements:o,store:n})=>{const{format:i}=G(n),l=!!_(n),r=i.fontSize.mixed,a=i.fontSize.value,s=o.map(t=>new Proxy(t,{get:(t,e)=>"fontSize"===e?null!=a?a:t.fontSize:"set"===e?e=>((t,e)=>{if(!e.fontSize){return void t.set(e)}const o=_(n);if(o){const{scope:t,isEmpty:n}=J(o.instance,o.lastSelection);if("partial"===t||"collapsed"===t&&n){return void U(o.instance,{fontSize:e.fontSize},o.lastSelection)}}const{attrsToSet:i}=H(t,{fontSize:e.fontSize});t.set(Object.assign(Object.assign({},e),i))})(t,e):Reflect.get(t,e)})),c=e($,{className:r?"polotno-mixed":"",children:[t(A,{elements:s,store:n}),r&&t(q,{className:"polotno-fs-mixed-overlay","aria-hidden":!0,children:"—"})]});return l?t("div",{"data-polotno-keep-focus":!0,onMouseDown:Q,children:c}):c});export const PROPS_MAP={TextFontFamily:nt,TextFontSize:it,TextFontVariant:FontStyleGroup,TextTransform:et,TextFilters:p,TextFill:FontColorInput,TextSpacing:j,TextDirection:DirectionInput,TextAnimations:x,TextAiWrite:v};export const HtmlToolbar=n(({store:e,components:o})=>{const n=e.selectedElements,i=e.selectedElements[0],l=["TextFill","TextFontFamily","TextFontSize","TextFontVariant","TextSpacing","TextTransform","TextFilters",g.animationsEnabled&&"TextAnimations",g.aiTextEnabled&&"TextAiWrite"],r=d({type:"text",usedItems:l,components:o});return t(f,{items:r,itemRender:l=>{if("TextBold"===l){return null}const r=(null==o?void 0:o[l])||PROPS_MAP[l];return t(r,{element:i,elements:n,store:e,components:o},l)}})});
@@ -0,0 +1,29 @@
1
+ import React from 'react';
2
+ import type { TextPadding } from '@polotno/core/text-types';
3
+ type PaddingFields = Record<keyof TextPadding, string>;
4
+ export declare const TEXT_PADDING_FIELDS: {
5
+ readonly top: 'paddingTop';
6
+ readonly right: 'paddingRight';
7
+ readonly bottom: 'paddingBottom';
8
+ readonly left: 'paddingLeft';
9
+ };
10
+ export declare const CELL_PADDING_FIELDS: {
11
+ readonly top: 'cellPaddingTop';
12
+ readonly right: 'cellPaddingRight';
13
+ readonly bottom: 'cellPaddingBottom';
14
+ readonly left: 'cellPaddingLeft';
15
+ };
16
+ export declare const cellPaddingSides: (el: {
17
+ cellPaddingTop: number;
18
+ cellPaddingRight: number;
19
+ cellPaddingBottom: number;
20
+ cellPaddingLeft: number;
21
+ }) => TextPadding;
22
+ export declare function paddingAttrs(sides: Partial<TextPadding>, fields: PaddingFields): Record<string, number>;
23
+ export declare const PaddingControl: ({ label, value, onChange, disabled, }: {
24
+ label: string;
25
+ value: TextPadding;
26
+ onChange: (sides: Partial<TextPadding>) => void;
27
+ disabled?: boolean;
28
+ }) => React.JSX.Element;
29
+ export {};
@@ -0,0 +1 @@
1
+ import{jsx as t,jsxs as o}from"react/jsx-runtime";import i from"react";import{PolotnoIcon as e}from"../icons/registry.js";import{Button as a}from"../primitives/button.js";import{FieldRow as n}from"../primitives/field-row.js";import{NumericInput as l}from"../primitives/numeric-input.js";import{t as d}from"../utils/l10n.js";const r=["top","right","bottom","left"],p={top:"toolbar.paddingTop",right:"toolbar.paddingRight",bottom:"toolbar.paddingBottom",left:"toolbar.paddingLeft"};export const TEXT_PADDING_FIELDS={top:"paddingTop",right:"paddingRight",bottom:"paddingBottom",left:"paddingLeft"};export const CELL_PADDING_FIELDS={top:"cellPaddingTop",right:"cellPaddingRight",bottom:"cellPaddingBottom",left:"cellPaddingLeft"};export const cellPaddingSides=t=>({top:t.cellPaddingTop,right:t.cellPaddingRight,bottom:t.cellPaddingBottom,left:t.cellPaddingLeft});export function paddingAttrs(t,o){const i={};for(const e of r){const a=t[e];void 0!==a&&(i[o[e]]=a)}return i}export const PaddingControl=({label:s,value:g,onChange:m,disabled:c=!1})=>{const b=g.top===g.right&&g.right===g.bottom&&g.bottom===g.left,[h,f]=i.useState(!b),u=d("toolbar.paddingSides");return o("div",{"data-slot":"padding-control",children:[t(n,{label:s,className:"pn:py-1",children:o("div",{className:"pn:flex pn:items-center pn:gap-1",children:[!h&&t(l,{"aria-label":s,value:g.top,onValueChange:t=>m({top:t,right:t,bottom:t,left:t}),min:0,max:1e3,disabled:c,style:{width:"72px"}}),t(a,{variant:h?"secondary":"ghost",size:"icon-sm","aria-label":u,"aria-pressed":h,title:u,disabled:c,onClick:()=>f(!h),children:t(e,{name:"toolbar.paddingSides",className:"pn:size-4"})})]})}),h&&t("div",{className:"pn:grid pn:grid-cols-2 pn:gap-x-3 pn:gap-y-1 pn:pt-1",children:r.map(o=>{const i=d(p[o]);return t(n,{label:i,children:t(l,{"aria-label":`${s} ${i}`,value:g[o],onValueChange:t=>m({[o]:t}),min:0,max:1e3,disabled:c,style:{width:"64px"}})},o)})})]})};
@@ -1 +1 @@
1
- import{jsx as e,jsxs as o}from"react/jsx-runtime";import r from"react";import{observer as t}from"mobx-react-lite";import{isGradient as n,firstStopColor as l}from"@polotno/core/gradient";import{t as a}from"../utils/l10n.js";import{useSvgColorsMap as s}from"../utils/use-svg-colors.js";import{collectSelectionColors as i}from"../utils/selection-colors.js";import{Popover as p,PopoverContent as c,PopoverTrigger as m}from"../primitives/popover.js";import d,{ColoredBox as u}from"./color-picker.js";export const stripeGradient=e=>{const o=e.slice(0,8).map(l),r=o.length||1;return`linear-gradient(90deg, ${o.map((e,o)=>`${e} ${o/r*100}% ${(o+1)/r*100}%`).join(", ")})`};export const ColorRow=({value:r,onChange:t,store:l,gradientEnabled:s=!0})=>o("div",{className:"pn-svg-color-row pn:flex pn:items-center pn:gap-2",children:[e(d,{value:r,onChange:t,store:l,gradientEnabled:s}),e("span",{className:"pn:truncate pn:text-xs pn:text-muted-foreground",children:n(r)?a("toolbar.colorPicker.linear"):r})]});const g=e=>e.slots.every(e=>e.gradient),v=(e,o,r)=>{e.history.transaction(()=>{o.slots.forEach(e=>e.apply(r))})};export const SelectionColors=t(({store:t})=>{const n=t.selectedShapes,l=s(n.filter(e=>"svg"===e.type).map(e=>e.src)),h=i(n,e=>l.get(e)),[x,f]=r.useState(null);return x||h.length?x||1!==h.length?o(p,{onOpenChange:e=>f(e?{rows:h,values:h.map(e=>e.color)}:null),children:[e(m,{nativeButton:!1,render:e(u,{background:stripeGradient(x?x.values:h.map(e=>e.color)),"aria-label":a("toolbar.colorPicker.colors")})}),o(c,{className:"pn:w-[220px] pn:p-2",align:"start",children:[e("div",{className:"pn:mb-2 pn:text-xs pn:font-medium",children:a("toolbar.colorPicker.colors")}),e("div",{className:"pn:flex pn:max-h-[280px] pn:flex-col pn:gap-2 pn:overflow-y-auto",children:null==x?void 0:x.rows.map((o,r)=>e(ColorRow,{value:x.values[r],store:t,gradientEnabled:g(o),onChange:e=>{v(t,o,e),f(o=>o&&Object.assign(Object.assign({},o),{values:o.values.map((o,t)=>t===r?e:o)}))}},r))})]})]}):e(d,{value:h[0].color,onChange:e=>v(t,h[0],e),store:t,gradientEnabled:g(h[0])}):null});
1
+ import{jsx as e,jsxs as o}from"react/jsx-runtime";import r from"react";import{observer as t}from"mobx-react-lite";import{isGradient as n,isRadialGradient as l,firstStopColor as a}from"@polotno/core/gradient";import{t as s}from"../utils/l10n.js";import{useSvgColorsMap as i}from"../utils/use-svg-colors.js";import{collectSelectionColors as p}from"../utils/selection-colors.js";import{Popover as c,PopoverContent as m,PopoverTrigger as d}from"../primitives/popover.js";import u,{ColoredBox as g}from"./color-picker.js";export const stripeGradient=e=>{const o=e.slice(0,8).map(a),r=o.length||1;return`linear-gradient(90deg, ${o.map((e,o)=>`${e} ${o/r*100}% ${(o+1)/r*100}%`).join(", ")})`};export const ColorRow=({value:r,onChange:t,store:a,gradientEnabled:i=!0})=>o("div",{className:"pn-svg-color-row pn:flex pn:items-center pn:gap-2",children:[e(u,{value:r,onChange:t,store:a,gradientEnabled:i}),e("span",{className:"pn:truncate pn:text-xs pn:text-muted-foreground",children:n(r)?l(r)?s("toolbar.colorPicker.radial"):s("toolbar.colorPicker.linear"):r})]});const v=e=>e.slots.every(e=>e.gradient),h=(e,o,r)=>{e.history.transaction(()=>{o.slots.forEach(e=>e.apply(r))})};export const SelectionColors=t(({store:t})=>{const n=t.selectedShapes,l=i(n.filter(e=>"svg"===e.type).map(e=>e.src)),a=p(n,e=>l.get(e)),[x,f]=r.useState(null);return x||a.length?x||1!==a.length?o(c,{onOpenChange:e=>f(e?{rows:a,values:a.map(e=>e.color)}:null),children:[e(d,{nativeButton:!1,render:e(g,{background:stripeGradient(x?x.values:a.map(e=>e.color)),"aria-label":s("toolbar.colorPicker.colors")})}),o(m,{className:"pn:w-[220px] pn:p-2",align:"start",children:[e("div",{className:"pn:mb-2 pn:text-xs pn:font-medium",children:s("toolbar.colorPicker.colors")}),e("div",{className:"pn:flex pn:max-h-[280px] pn:flex-col pn:gap-2 pn:overflow-y-auto",children:null==x?void 0:x.rows.map((o,r)=>e(ColorRow,{value:x.values[r],store:t,gradientEnabled:v(o),onChange:e=>{h(t,o,e),f(o=>o&&Object.assign(Object.assign({},o),{values:o.values.map((o,t)=>t===r?e:o)}))}},r))})]})]}):e(u,{value:a[0].color,onChange:e=>h(t,a[0],e),store:t,gradientEnabled:v(a[0])}):null});
@@ -1 +1 @@
1
- import{jsx as e,jsxs as n}from"react/jsx-runtime";import t from"react";import{cn as r}from"../lib/utils.js";import{DRAG_SLOP_PX as o,isPrimaryDrag as s,usePointerDrag as i}from"../utils/pointer-drag.js";import{canRemoveStop as p,moveStop as l}from"../utils/stops.js";const a={ArrowLeft:-1,ArrowDown:-1,ArrowRight:1,ArrowUp:1};export function StopTrack({store:c,node:u,label:d,stops:f,selected:g,onSelect:m,onChange:b,insert:v,stopLabel:h,swatch:x,bar:y,handle:w}){const k=t.useRef(null),S=i(),j=t.useRef(!1),E=t.useRef(null),N=t.useRef(f);N.current=f;const R=()=>{j.current&&(j.current=!1,c.history.endTransaction())};t.useEffect(()=>()=>R(),[c,u]);const D=e=>{var n;const t=null===(n=k.current)||void 0===n?void 0:n.querySelectorAll("[data-stop]")[e];return!!(null==t?void 0:t.getClientRects().length)&&(t.focus({preventScroll:!0}),document.activeElement===t)};t.useLayoutEffect(()=>{null!==E.current&&(D(E.current),E.current=null)});const A=e=>{JSON.stringify(e.stops)!==JSON.stringify(N.current)&&(E.current=e.index,b(e))},z=e=>{p(f)&&A({stops:f.filter((n,t)=>t!==e),index:Math.max(0,e-1)})};t.useImperativeHandle(w,()=>({remove:z,focus:D}));const B=e=>{const n=k.current.getBoundingClientRect();return(e-n.left)/(n.width||1)},C=()=>[c.activePage,...c.selectedElements].map(e=>null==e?void 0:e.id).join();return n("div",{ref:k,role:"group","aria-label":d,className:"pn:relative pn:h-7 pn:cursor-copy pn:touch-none",onPointerDown:e=>{if(!s(e)){return}R(),c.history.addUndoState(),c.history.startTransaction(),j.current=!0;const n=e.target.closest("[data-stop]");let t={stops:f,index:Number(null==n?void 0:n.dataset.stop)};n?(m(t.index),n.focus({preventScroll:!0})):(t=v(f,B(e.clientX)),A(t));const r=C();S(e,{node:u,slopX:o,onMove:e=>{j.current&&(0!==e.buttons&&C()===r?A(l(t.stops,t.index,B(e.clientX))):R())},onEnd:R})},children:[e("div",{className:"pn:absolute pn:inset-x-0 pn:top-1.5 pn:h-4 pn:overflow-hidden pn:rounded-sm pn:ring-1 pn:ring-inset pn:ring-black/15 pn:dark:ring-white/15",children:y}),f.map((n,t)=>e("button",{type:"button","data-stop":t,"aria-label":h(n,t),"aria-pressed":t===g,onKeyDown:e=>((e,n)=>{const{key:t}=e;if(!(t in a)&&!["Home","End","Delete","Backspace"].includes(t)){return}if(e.preventDefault(),e.stopPropagation(),"Delete"===t||"Backspace"===t){return void z(n)}const r="Home"===t?0:"End"===t?1:f[n].offset+a[t]*(e.shiftKey?.1:.01);A(l(f,n,r))})(e,t),onFocus:()=>m(t),className:r("pn:group pn:absolute pn:top-0 pn:size-7 pn:-translate-x-1/2 pn:cursor-grab pn:rounded-md pn:outline-none",t===g&&"pn:z-10"),style:{left:100*n.offset+"%"},children:e("span",{className:r("pn:mx-auto pn:block pn:size-4 pn:rounded-full pn:border-2 pn:border-white pn:shadow-[0_1px_3px_rgba(0,0,0,0.4)] pn:group-focus-visible:ring-2 pn:group-focus-visible:ring-ring pn:group-focus-visible:ring-offset-2",t===g&&"pn:ring-2 pn:ring-primary"),style:{background:x(n)}})},t))]})}
1
+ import{jsx as e,jsxs as n}from"react/jsx-runtime";import t from"react";import{cn as r}from"../lib/utils.js";import{DRAG_SLOP_PX as o,isPrimaryDrag as s,usePointerDrag as i}from"../utils/pointer-drag.js";import{canRemoveStop as p,moveStop as l}from"../utils/stops.js";import{useHistoryGesture as a}from"../utils/history-gesture.js";const u={ArrowLeft:-1,ArrowDown:-1,ArrowRight:1,ArrowUp:1};export function StopTrack({store:c,node:d,label:f,stops:g,selected:m,onSelect:b,onChange:v,insert:h,stopLabel:x,swatch:w,bar:y,handle:j}){const k=t.useRef(null),N=i(),S=a(c,d),D=t.useRef(null),E=t.useRef(g);E.current=g;const R=e=>{var n;const t=null===(n=k.current)||void 0===n?void 0:n.querySelectorAll("[data-stop]")[e];return!!(null==t?void 0:t.getClientRects().length)&&(t.focus({preventScroll:!0}),document.activeElement===t)};t.useLayoutEffect(()=>{null!==D.current&&(R(D.current),D.current=null)});const A=e=>{JSON.stringify(e.stops)!==JSON.stringify(E.current)&&(D.current=e.index,v(e))},z=e=>{p(g)&&A({stops:g.filter((n,t)=>t!==e),index:Math.max(0,e-1)})};t.useImperativeHandle(j,()=>({remove:z,focus:R}));const B=e=>{const n=k.current.getBoundingClientRect();return(e-n.left)/(n.width||1)},C=()=>[c.activePage,...c.selectedElements].map(e=>null==e?void 0:e.id).join();return n("div",{ref:k,role:"group","aria-label":f,className:"pn:relative pn:h-7 pn:cursor-copy pn:touch-none",onPointerDown:e=>{if(!s(e)){return}S.begin();const n=e.target.closest("[data-stop]");let t={stops:g,index:Number(null==n?void 0:n.dataset.stop)};n?(b(t.index),n.focus({preventScroll:!0})):(t=h(g,B(e.clientX)),A(t));const r=C();N(e,{node:d,slopX:o,onMove:e=>{S.active()&&(0!==e.buttons&&C()===r?A(l(t.stops,t.index,B(e.clientX))):S.end())},onEnd:S.end})},children:[e("div",{className:"pn:absolute pn:inset-x-0 pn:top-1.5 pn:h-4 pn:overflow-hidden pn:rounded-sm pn:ring-1 pn:ring-inset pn:ring-black/15 pn:dark:ring-white/15",children:y}),g.map((n,t)=>e("button",{type:"button","data-stop":t,"aria-label":x(n,t),"aria-pressed":t===m,onKeyDown:e=>((e,n)=>{const{key:t}=e;if(!(t in u)&&!["Home","End","Delete","Backspace"].includes(t)){return}if(e.preventDefault(),e.stopPropagation(),"Delete"===t||"Backspace"===t){return void z(n)}const r="Home"===t?0:"End"===t?1:g[n].offset+u[t]*(e.shiftKey?.1:.01);A(l(g,n,r))})(e,t),onFocus:()=>b(t),className:r("pn:group pn:absolute pn:top-0 pn:size-7 pn:-translate-x-1/2 pn:cursor-grab pn:rounded-md pn:outline-none",t===m&&"pn:z-10"),style:{left:100*n.offset+"%"},children:e("span",{className:r("pn:mx-auto pn:block pn:size-4 pn:rounded-full pn:border-2 pn:border-white pn:shadow-[0_1px_3px_rgba(0,0,0,0.4)] pn:group-focus-visible:ring-2 pn:group-focus-visible:ring-ring pn:group-focus-visible:ring-offset-2",t===m&&"pn:ring-2 pn:ring-primary"),style:{background:w(n)}})},t))]})}
@@ -1 +1 @@
1
- import{Fragment as e,jsx as t,jsxs as n}from"react/jsx-runtime";import o from"react";import{observer as l}from"mobx-react-lite";import{PolotnoIcon as r}from"../icons/registry.js";import{Button as i}from"../primitives/button.js";import{SliderField as s}from"../primitives/slider-field.js";import{Popover as a,PopoverContent as c,PopoverTrigger as d}from"../primitives/popover.js";import{Tooltip as p,TooltipContent as m,TooltipTrigger as b}from"../primitives/tooltip.js";import{cn as h}from"../lib/utils.js";import{ColorPicker as u}from"./color-picker.js";import{NumberInput as y}from"./filters-picker.js";import{ElementContainer as x,extendToolbar as g}from"./element-container.js";import{cycleNext as f,StrokeWidthIcon as v}from"./toolbar-shared.js";import{VERTICAL_ALIGN_OPTIONS as C,VERTICAL_ALIGN_ICONS as k}from"./text-toolbar.js";import{PROPS_MAP as w}from"./html-toolbar.js";import{AnimationsPicker as j}from"./animations-picker.js";import{flags as O}from"../utils/flags.js";import{t as T}from"../utils/l10n.js";const B={stroke:"currentColor",strokeWidth:1,strokeOpacity:.25},N={stroke:"currentColor",strokeWidth:2},S=()=>n(e,{children:[t("rect",Object.assign({x:"2",y:"2",width:"16",height:"16",fill:"none"},B)),t("line",Object.assign({x1:"10",y1:"2",x2:"10",y2:"18"},B)),t("line",Object.assign({x1:"2",y1:"10",x2:"18",y2:"10"},B))]}),z=({children:e})=>n("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",children:[t(S,{}),e]}),F=[{key:"all",labelKey:"toolbar.borderModeAll",icon:()=>n("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",children:[t("rect",Object.assign({x:"2",y:"2",width:"16",height:"16",fill:"none"},N)),t("line",Object.assign({x1:"10",y1:"2",x2:"10",y2:"18"},N)),t("line",Object.assign({x1:"2",y1:"10",x2:"18",y2:"10"},N))]})},{key:"outer",labelKey:"toolbar.borderModeOuter",icon:()=>t(z,{children:t("rect",Object.assign({x:"2",y:"2",width:"16",height:"16",fill:"none"},N))})},{key:"inner",labelKey:"toolbar.borderModeInner",icon:()=>n(z,{children:[t("line",Object.assign({x1:"10",y1:"2",x2:"10",y2:"18"},N)),t("line",Object.assign({x1:"2",y1:"10",x2:"18",y2:"10"},N))]})},{key:"topOnly",labelKey:"toolbar.borderModeTopOnly",icon:()=>t(z,{children:t("line",Object.assign({x1:"2",y1:"2",x2:"18",y2:"2"},N))})},{key:"innerHorizontal",labelKey:"toolbar.borderModeInnerHorizontal",icon:()=>t(z,{children:t("line",Object.assign({x1:"2",y1:"10",x2:"18",y2:"10"},N))})},{key:"bottomOnly",labelKey:"toolbar.borderModeBottomOnly",icon:()=>t(z,{children:t("line",Object.assign({x1:"2",y1:"18",x2:"18",y2:"18"},N))})},{key:"leftOnly",labelKey:"toolbar.borderModeLeftOnly",icon:()=>t(z,{children:t("line",Object.assign({x1:"2",y1:"2",x2:"2",y2:"18"},N))})},{key:"innerVertical",labelKey:"toolbar.borderModeInnerVertical",icon:()=>t(z,{children:t("line",Object.assign({x1:"10",y1:"2",x2:"10",y2:"18"},N))})},{key:"rightOnly",labelKey:"toolbar.borderModeRightOnly",icon:()=>t(z,{children:t("line",Object.assign({x1:"18",y1:"2",x2:"18",y2:"18"},N))})}];export const TableBorderSettings=l(({elements:e,store:l})=>{const y=e[0],x="tablecell"===y.type,g=x?l.selectedElements[0]:y,[f,C]=o.useState("all");let k,w;if(x){const e=g.getFocusedCellRange();k=e?e.maxRow-e.minRow+1:1,w=e?e.maxCol-e.minCol+1:1}else{k=g.rows,w=g.cols}const j=k>1,O=w>1,B=e=>"innerHorizontal"===e?!j:("innerVertical"===e||"inner"===e&&!j)&&!O;o.useEffect(()=>{B(f)&&C("all")},[f,j,O]);const N={all:"top",outer:"top",topOnly:"top",topBottom:"top",bottomOnly:"bottom",innerHorizontal:"bottom",inner:"bottom",leftOnly:"left",rightOnly:"right",innerVertical:"right"}[f],S=x?y:"bottomOnly"===f?g.getCell(g.rows-1,0):"rightOnly"===f?g.getCell(0,g.cols-1):g.getCell(0,0),z=(null==S?void 0:S.getEffectiveBorder)?S.getEffectiveBorder(N):{color:g.borderColor,width:g.borderWidth,style:g.borderStyle},E=z.color,R=z.width,A=z.style,M=(t,n={})=>{var o,r;const i=R<=0||"none"===A,s=null!==(o=n.style)&&void 0!==o?o:i?"solid":A,a=void 0!==n.width?n.width:i?1:R,c={color:null!==(r=n.color)&&void 0!==r?r:E,width:a,style:s};l.history.transaction(()=>{g.applyBorderMode(t,c),"all"!==t||x||e.forEach(e=>e.set({borderColor:c.color,borderWidth:c.width,borderStyle:c.style}))})},W=e=>{M(f,{style:e})};return n(a,{children:[n(p,{children:[t(b,{render:t(d,{render:t(i,{variant:"ghost",size:"icon-sm","aria-label":T("toolbar.tableBorderSettings"),children:t(v,{})})})}),t(m,{children:T("toolbar.tableBorderSettings")})]}),t(c,{className:"pn:w-auto pn:p-3",align:"start",children:n("div",{className:"pn:flex pn:gap-3",children:[t("div",{className:"pn:grid pn:grid-cols-[repeat(3,32px)] pn:auto-rows-[32px] pn:gap-1",children:F.map(({key:e,labelKey:o,icon:l})=>{const r=B(e);return n(p,{children:[t(b,{render:t(i,{variant:"outline",size:"sm",disabled:r,className:h("pn:size-8 pn:p-0",!r&&f===e&&"pn:bg-muted"),onClick:()=>{C(e)},"aria-label":T(o),children:t(l,{})})}),t(m,{children:T(o)})]},e)})}),t("div",{className:"pn:w-px pn:bg-border"}),n("div",{className:"pn:flex pn:w-[170px] pn:flex-col pn:gap-2",children:[n("div",{className:"pn:flex pn:items-center pn:justify-between",children:[t("span",{className:"pn:text-xs",children:T("toolbar.tableBorderColor")}),t(u,{value:E,onChange:e=>{M(f,{color:e})},store:l})]}),t(s,{label:T("toolbar.tableBorderWidth"),value:R,onChange:e=>{M(f,{width:e})},min:0,max:20}),n("div",{className:"pn:flex pn:justify-between pn:gap-1",children:[t(i,{variant:"outline",size:"sm",onClick:()=>W("none"),className:h("pn:flex-1","none"===A&&"pn:bg-muted"),children:t(r,{name:"action.none",className:"pn:size-4"})}),t(i,{variant:"outline",size:"sm",onClick:()=>W("solid"),className:h("pn:flex-1","solid"===A&&"pn:bg-muted"),children:t("svg",{width:"20",height:"14",viewBox:"0 0 20 14",children:t("line",{x2:"20",y1:"7",y2:"7",stroke:"currentColor",strokeWidth:"2"})})}),t(i,{variant:"outline",size:"sm",onClick:()=>W("dashed"),className:h("pn:flex-1","dashed"===A&&"pn:bg-muted"),children:t("svg",{width:"20",height:"14",viewBox:"0 0 20 14",children:t("line",{x2:"20",y1:"7",y2:"7",stroke:"currentColor",strokeDasharray:"4 2",strokeWidth:"2"})})}),t(i,{variant:"outline",size:"sm",onClick:()=>W("dotted"),className:h("pn:flex-1","dotted"===A&&"pn:bg-muted"),children:t("svg",{width:"20",height:"14",viewBox:"0 0 20 14",children:t("line",{x2:"20",y1:"7",y2:"7",stroke:"currentColor",strokeDasharray:"2 2",strokeWidth:"2"})})})]})]})]})})]})});const E=()=>n("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:[t("rect",{x:"1",y:"1",width:"14",height:"14",rx:"1",stroke:"currentColor",strokeWidth:"1.5",fill:"none"}),t("line",{x1:"5.5",y1:"1",x2:"5.5",y2:"15",stroke:"currentColor",strokeWidth:"1"}),t("line",{x1:"10.5",y1:"1",x2:"10.5",y2:"15",stroke:"currentColor",strokeWidth:"1"}),t("line",{x1:"1",y1:"5.5",x2:"15",y2:"5.5",stroke:"currentColor",strokeWidth:"1"}),t("line",{x1:"1",y1:"10.5",x2:"15",y2:"10.5",stroke:"currentColor",strokeWidth:"1"})]});export const TableStructureMenu=l(({element:o,store:l})=>{const r=o.focusedCells[0],i=null==r?void 0:r.row,s=null==r?void 0:r.col;return n("div",{className:"pn:p-1",children:[null!=r&&n(e,{children:[t("div",{className:"pn:px-2 pn:py-1 pn:text-xs pn:font-semibold pn:text-muted-foreground",children:T("toolbar.tableRows")}),t("button",{type:"button",className:"pn:flex pn:w-full pn:items-center pn:rounded-sm pn:px-2 pn:py-1.5 pn:text-sm pn:hover:bg-muted",onClick:()=>{l.history.transaction(()=>{o.addRow(i)})},children:T("toolbar.insertRowAbove")}),t("button",{type:"button",className:"pn:flex pn:w-full pn:items-center pn:rounded-sm pn:px-2 pn:py-1.5 pn:text-sm pn:hover:bg-muted",onClick:()=>{l.history.transaction(()=>{o.addRow(i+1)})},children:T("toolbar.insertRowBelow")}),t("button",{type:"button",disabled:o.rows<=1,className:h("pn:flex pn:w-full pn:items-center pn:rounded-sm pn:px-2 pn:py-1.5 pn:text-sm pn:hover:bg-muted",o.rows<=1&&"pn:pointer-events-none pn:opacity-50"),onClick:()=>{l.history.transaction(()=>{o.removeRow(i)})},children:T("toolbar.deleteRow")}),t("div",{className:"pn:my-1 pn:border-t pn:border-border"}),t("div",{className:"pn:px-2 pn:py-1 pn:text-xs pn:font-semibold pn:text-muted-foreground",children:T("toolbar.tableColumns")}),t("button",{type:"button",className:"pn:flex pn:w-full pn:items-center pn:rounded-sm pn:px-2 pn:py-1.5 pn:text-sm pn:hover:bg-muted",onClick:()=>{l.history.transaction(()=>{o.addColumn(s)})},children:T("toolbar.insertColumnLeft")}),t("button",{type:"button",className:"pn:flex pn:w-full pn:items-center pn:rounded-sm pn:px-2 pn:py-1.5 pn:text-sm pn:hover:bg-muted",onClick:()=>{l.history.transaction(()=>{o.addColumn(s+1)})},children:T("toolbar.insertColumnRight")}),t("button",{type:"button",disabled:o.cols<=1,className:h("pn:flex pn:w-full pn:items-center pn:rounded-sm pn:px-2 pn:py-1.5 pn:text-sm pn:hover:bg-muted",o.cols<=1&&"pn:pointer-events-none pn:opacity-50"),onClick:()=>{l.history.transaction(()=>{o.removeColumn(s)})},children:T("toolbar.deleteColumn")}),t("div",{className:"pn:my-1 pn:border-t pn:border-border"})]}),t("button",{type:"button",className:"pn:flex pn:w-full pn:items-center pn:rounded-sm pn:px-2 pn:py-1.5 pn:text-sm pn:hover:bg-muted",onClick:()=>{l.history.transaction(()=>{o.distributeRowsEvenly()})},children:T("toolbar.distributeRowsEvenly")}),t("button",{type:"button",className:"pn:flex pn:w-full pn:items-center pn:rounded-sm pn:px-2 pn:py-1.5 pn:text-sm pn:hover:bg-muted",onClick:()=>{l.history.transaction(()=>{o.distributeColumnsEvenly()})},children:T("toolbar.distributeColumnsEvenly")})]})});export const TableStructure=l(({elements:e,store:o})=>{const l=e[0];return n(a,{children:[n(p,{children:[t(b,{render:t(d,{render:t(i,{variant:"ghost",size:"icon-sm","aria-label":T("toolbar.tableStructure"),children:t(E,{})})})}),t(m,{children:T("toolbar.tableStructure")})]}),t(c,{className:"pn:w-auto pn:p-0",align:"start",children:t(TableStructureMenu,{element:l,store:o})})]})});export const CellPadding=l(({elements:e,store:o})=>n(p,{children:[t(b,{render:t(y,{value:e[0].cellPadding,onValueChange:t=>o.history.transaction(()=>{e.forEach(e=>e.set({cellPadding:t}))}),style:{width:"64px"},min:0,max:50})}),t(m,{children:T("toolbar.cellPadding")})]}));export const CellBackground=l(({elements:e,store:o})=>n(p,{children:[t(b,{render:t(u,{value:e[0].cellBackground,onChange:t=>o.history.transaction(()=>{e.forEach(e=>e.set({cellBackground:t}))}),store:o})}),t(m,{children:T("toolbar.cellBackground")})]}));export const CellVerticalAlign=l(({elements:e,store:o})=>{const l=e[0];return n(p,{children:[t(b,{render:t(i,{variant:"ghost",size:"icon-sm",onClick:()=>{const t=f(C,l.verticalAlign);o.history.transaction(()=>{e.forEach(e=>e.set({verticalAlign:t}))})},"aria-label":T("toolbar.verticalAlign"),children:k[l.verticalAlign]})}),t(m,{children:T("toolbar.verticalAlign")})]})});const R={TableStructure,TableAnimations:j},{TextFontFamily:A,TextFontSize:M,TextFill:W,TextFontVariant:V,TextSpacing:K}=w,P={TextFontFamily:A,TextFontSize:M,TextFill:W,TextFontVariant:V,TextSpacing:K},H=Object.assign({TableBorderSettings,CellBackground,CellVerticalAlign},P),I=Object.assign(Object.assign({},R),H);export const TableToolbar=l(({store:e,components:n})=>{const o=e.selectedElements[0],l=o.focusedCells,r=l.length>0,i=o.textCells,s=["TableBorderSettings","CellBackground","TableStructure",...r?["TextFontFamily","TextFontSize","TextFill","TextFontVariant","CellVerticalAlign","TextSpacing"]:[],O.animationsEnabled&&"TableAnimations"],a=g({type:"table",usedItems:s,components:n});return t(x,{items:a,itemRender:s=>{const a=(null==n?void 0:n[s])||I[s],c=!!H[s],d=!(null==n?void 0:n[s])&&!!P[s];if(c&&!r&&"TableBorderSettings"!==s&&"CellBackground"!==s){return null}if(d&&0===i.length){return null}let p;return p=c?d?i:r?l:"TableBorderSettings"===s?e.selectedElements:o.cells.slice():e.selectedElements,t(a,{element:d?i[0]:o,store:e,elements:p},s)}})});export default TableToolbar;
1
+ import{Fragment as e,jsx as t,jsxs as n}from"react/jsx-runtime";import o from"react";import{observer as r}from"mobx-react-lite";import{PolotnoIcon as l}from"../icons/registry.js";import{Button as i}from"../primitives/button.js";import{SliderField as s}from"../primitives/slider-field.js";import{Popover as a,PopoverContent as c,PopoverTrigger as d}from"../primitives/popover.js";import{Tooltip as p,TooltipContent as m,TooltipTrigger as b}from"../primitives/tooltip.js";import{cn as h}from"../lib/utils.js";import{ColorPicker as u}from"./color-picker.js";import{ElementContainer as y,extendToolbar as x}from"./element-container.js";import{cycleNext as g,StrokeWidthIcon as f}from"./toolbar-shared.js";import{CELL_PADDING_FIELDS as v,PaddingControl as C,cellPaddingSides as k,paddingAttrs as w}from"./padding-control.js";import{VERTICAL_ALIGN_OPTIONS as j,VERTICAL_ALIGN_ICONS as O}from"./text-toolbar.js";import{PROPS_MAP as T}from"./html-toolbar.js";import{AnimationsPicker as B}from"./animations-picker.js";import{flags as N}from"../utils/flags.js";import{t as S}from"../utils/l10n.js";const z={stroke:"currentColor",strokeWidth:1,strokeOpacity:.25},F={stroke:"currentColor",strokeWidth:2},E=()=>n(e,{children:[t("rect",Object.assign({x:"2",y:"2",width:"16",height:"16",fill:"none"},z)),t("line",Object.assign({x1:"10",y1:"2",x2:"10",y2:"18"},z)),t("line",Object.assign({x1:"2",y1:"10",x2:"18",y2:"10"},z))]}),R=({children:e})=>n("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",children:[t(E,{}),e]}),A=[{key:"all",labelKey:"toolbar.borderModeAll",icon:()=>n("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",children:[t("rect",Object.assign({x:"2",y:"2",width:"16",height:"16",fill:"none"},F)),t("line",Object.assign({x1:"10",y1:"2",x2:"10",y2:"18"},F)),t("line",Object.assign({x1:"2",y1:"10",x2:"18",y2:"10"},F))]})},{key:"outer",labelKey:"toolbar.borderModeOuter",icon:()=>t(R,{children:t("rect",Object.assign({x:"2",y:"2",width:"16",height:"16",fill:"none"},F))})},{key:"inner",labelKey:"toolbar.borderModeInner",icon:()=>n(R,{children:[t("line",Object.assign({x1:"10",y1:"2",x2:"10",y2:"18"},F)),t("line",Object.assign({x1:"2",y1:"10",x2:"18",y2:"10"},F))]})},{key:"topOnly",labelKey:"toolbar.borderModeTopOnly",icon:()=>t(R,{children:t("line",Object.assign({x1:"2",y1:"2",x2:"18",y2:"2"},F))})},{key:"innerHorizontal",labelKey:"toolbar.borderModeInnerHorizontal",icon:()=>t(R,{children:t("line",Object.assign({x1:"2",y1:"10",x2:"18",y2:"10"},F))})},{key:"bottomOnly",labelKey:"toolbar.borderModeBottomOnly",icon:()=>t(R,{children:t("line",Object.assign({x1:"2",y1:"18",x2:"18",y2:"18"},F))})},{key:"leftOnly",labelKey:"toolbar.borderModeLeftOnly",icon:()=>t(R,{children:t("line",Object.assign({x1:"2",y1:"2",x2:"2",y2:"18"},F))})},{key:"innerVertical",labelKey:"toolbar.borderModeInnerVertical",icon:()=>t(R,{children:t("line",Object.assign({x1:"10",y1:"2",x2:"10",y2:"18"},F))})},{key:"rightOnly",labelKey:"toolbar.borderModeRightOnly",icon:()=>t(R,{children:t("line",Object.assign({x1:"18",y1:"2",x2:"18",y2:"18"},F))})}];export const TableBorderSettings=r(({elements:e,store:r})=>{const y=e[0],x="tablecell"===y.type,g=x?r.selectedElements[0]:y,[v,C]=o.useState("all");let k,w;if(x){const e=g.getFocusedCellRange();k=e?e.maxRow-e.minRow+1:1,w=e?e.maxCol-e.minCol+1:1}else{k=g.rows,w=g.cols}const j=k>1,O=w>1,T=e=>"innerHorizontal"===e?!j:("innerVertical"===e||"inner"===e&&!j)&&!O;o.useEffect(()=>{T(v)&&C("all")},[v,j,O]);const B={all:"top",outer:"top",topOnly:"top",topBottom:"top",bottomOnly:"bottom",innerHorizontal:"bottom",inner:"bottom",leftOnly:"left",rightOnly:"right",innerVertical:"right"}[v],N=x?y:"bottomOnly"===v?g.getCell(g.rows-1,0):"rightOnly"===v?g.getCell(0,g.cols-1):g.getCell(0,0),z=(null==N?void 0:N.getEffectiveBorder)?N.getEffectiveBorder(B):{color:g.borderColor,width:g.borderWidth,style:g.borderStyle},F=z.color,E=z.width,R=z.style,M=(t,n={})=>{var o,l;const i=E<=0||"none"===R,s=null!==(o=n.style)&&void 0!==o?o:i?"solid":R,a=void 0!==n.width?n.width:i?1:E,c={color:null!==(l=n.color)&&void 0!==l?l:F,width:a,style:s};r.history.transaction(()=>{g.applyBorderMode(t,c),"all"!==t||x||e.forEach(e=>e.set({borderColor:c.color,borderWidth:c.width,borderStyle:c.style}))})},W=e=>{M(v,{style:e})};return n(a,{children:[n(p,{children:[t(b,{render:t(d,{render:t(i,{variant:"ghost",size:"icon-sm","aria-label":S("toolbar.tableBorderSettings"),children:t(f,{})})})}),t(m,{children:S("toolbar.tableBorderSettings")})]}),t(c,{className:"pn:w-auto pn:p-3",align:"start",children:n("div",{className:"pn:flex pn:gap-3",children:[t("div",{className:"pn:grid pn:grid-cols-[repeat(3,32px)] pn:auto-rows-[32px] pn:gap-1",children:A.map(({key:e,labelKey:o,icon:r})=>{const l=T(e);return n(p,{children:[t(b,{render:t(i,{variant:"outline",size:"sm",disabled:l,className:h("pn:size-8 pn:p-0",!l&&v===e&&"pn:bg-muted"),onClick:()=>{C(e)},"aria-label":S(o),children:t(r,{})})}),t(m,{children:S(o)})]},e)})}),t("div",{className:"pn:w-px pn:bg-border"}),n("div",{className:"pn:flex pn:w-[170px] pn:flex-col pn:gap-2",children:[n("div",{className:"pn:flex pn:items-center pn:justify-between",children:[t("span",{className:"pn:text-xs",children:S("toolbar.tableBorderColor")}),t(u,{value:F,onChange:e=>{M(v,{color:e})},store:r})]}),t(s,{label:S("toolbar.tableBorderWidth"),value:E,onChange:e=>{M(v,{width:e})},min:0,max:20}),n("div",{className:"pn:flex pn:justify-between pn:gap-1",children:[t(i,{variant:"outline",size:"sm",onClick:()=>W("none"),className:h("pn:flex-1","none"===R&&"pn:bg-muted"),children:t(l,{name:"action.none",className:"pn:size-4"})}),t(i,{variant:"outline",size:"sm",onClick:()=>W("solid"),className:h("pn:flex-1","solid"===R&&"pn:bg-muted"),children:t("svg",{width:"20",height:"14",viewBox:"0 0 20 14",children:t("line",{x2:"20",y1:"7",y2:"7",stroke:"currentColor",strokeWidth:"2"})})}),t(i,{variant:"outline",size:"sm",onClick:()=>W("dashed"),className:h("pn:flex-1","dashed"===R&&"pn:bg-muted"),children:t("svg",{width:"20",height:"14",viewBox:"0 0 20 14",children:t("line",{x2:"20",y1:"7",y2:"7",stroke:"currentColor",strokeDasharray:"4 2",strokeWidth:"2"})})}),t(i,{variant:"outline",size:"sm",onClick:()=>W("dotted"),className:h("pn:flex-1","dotted"===R&&"pn:bg-muted"),children:t("svg",{width:"20",height:"14",viewBox:"0 0 20 14",children:t("line",{x2:"20",y1:"7",y2:"7",stroke:"currentColor",strokeDasharray:"2 2",strokeWidth:"2"})})})]})]})]})})]})});const M=()=>n("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:[t("rect",{x:"1",y:"1",width:"14",height:"14",rx:"1",stroke:"currentColor",strokeWidth:"1.5",fill:"none"}),t("line",{x1:"5.5",y1:"1",x2:"5.5",y2:"15",stroke:"currentColor",strokeWidth:"1"}),t("line",{x1:"10.5",y1:"1",x2:"10.5",y2:"15",stroke:"currentColor",strokeWidth:"1"}),t("line",{x1:"1",y1:"5.5",x2:"15",y2:"5.5",stroke:"currentColor",strokeWidth:"1"}),t("line",{x1:"1",y1:"10.5",x2:"15",y2:"10.5",stroke:"currentColor",strokeWidth:"1"})]});export const TableStructureMenu=r(({element:o,store:r})=>{const l=o.focusedCells[0],i=null==l?void 0:l.row,s=null==l?void 0:l.col;return n("div",{className:"pn:p-1",children:[null!=l&&n(e,{children:[t("div",{className:"pn:px-2 pn:py-1 pn:text-xs pn:font-semibold pn:text-muted-foreground",children:S("toolbar.tableRows")}),t("button",{type:"button",className:"pn:flex pn:w-full pn:items-center pn:rounded-sm pn:px-2 pn:py-1.5 pn:text-sm pn:hover:bg-muted",onClick:()=>{r.history.transaction(()=>{o.addRow(i)})},children:S("toolbar.insertRowAbove")}),t("button",{type:"button",className:"pn:flex pn:w-full pn:items-center pn:rounded-sm pn:px-2 pn:py-1.5 pn:text-sm pn:hover:bg-muted",onClick:()=>{r.history.transaction(()=>{o.addRow(i+1)})},children:S("toolbar.insertRowBelow")}),t("button",{type:"button",disabled:o.rows<=1,className:h("pn:flex pn:w-full pn:items-center pn:rounded-sm pn:px-2 pn:py-1.5 pn:text-sm pn:hover:bg-muted",o.rows<=1&&"pn:pointer-events-none pn:opacity-50"),onClick:()=>{r.history.transaction(()=>{o.removeRow(i)})},children:S("toolbar.deleteRow")}),t("div",{className:"pn:my-1 pn:border-t pn:border-border"}),t("div",{className:"pn:px-2 pn:py-1 pn:text-xs pn:font-semibold pn:text-muted-foreground",children:S("toolbar.tableColumns")}),t("button",{type:"button",className:"pn:flex pn:w-full pn:items-center pn:rounded-sm pn:px-2 pn:py-1.5 pn:text-sm pn:hover:bg-muted",onClick:()=>{r.history.transaction(()=>{o.addColumn(s)})},children:S("toolbar.insertColumnLeft")}),t("button",{type:"button",className:"pn:flex pn:w-full pn:items-center pn:rounded-sm pn:px-2 pn:py-1.5 pn:text-sm pn:hover:bg-muted",onClick:()=>{r.history.transaction(()=>{o.addColumn(s+1)})},children:S("toolbar.insertColumnRight")}),t("button",{type:"button",disabled:o.cols<=1,className:h("pn:flex pn:w-full pn:items-center pn:rounded-sm pn:px-2 pn:py-1.5 pn:text-sm pn:hover:bg-muted",o.cols<=1&&"pn:pointer-events-none pn:opacity-50"),onClick:()=>{r.history.transaction(()=>{o.removeColumn(s)})},children:S("toolbar.deleteColumn")}),t("div",{className:"pn:my-1 pn:border-t pn:border-border"})]}),t("button",{type:"button",className:"pn:flex pn:w-full pn:items-center pn:rounded-sm pn:px-2 pn:py-1.5 pn:text-sm pn:hover:bg-muted",onClick:()=>{r.history.transaction(()=>{o.distributeRowsEvenly()})},children:S("toolbar.distributeRowsEvenly")}),t("button",{type:"button",className:"pn:flex pn:w-full pn:items-center pn:rounded-sm pn:px-2 pn:py-1.5 pn:text-sm pn:hover:bg-muted",onClick:()=>{r.history.transaction(()=>{o.distributeColumnsEvenly()})},children:S("toolbar.distributeColumnsEvenly")})]})});export const TableStructure=r(({elements:e,store:o})=>{const r=e[0];return n(a,{children:[n(p,{children:[t(b,{render:t(d,{render:t(i,{variant:"ghost",size:"icon-sm","aria-label":S("toolbar.tableStructure"),children:t(M,{})})})}),t(m,{children:S("toolbar.tableStructure")})]}),t(c,{className:"pn:w-auto pn:p-0",align:"start",children:t(TableStructureMenu,{element:r,store:o})})]})});export const CellPadding=r(({elements:e,store:o})=>{const r=e[0],s=S("toolbar.cellPadding");return n(a,{children:[n(p,{children:[t(b,{render:t(d,{render:t(i,{variant:"ghost",size:"icon-sm","aria-label":s,children:t(l,{name:"toolbar.paddingSides",className:"pn:size-5"})})})}),t(m,{children:s})]}),t(c,{align:"start",className:"pn:w-[260px] pn:p-[15px]",children:t(C,{label:s,value:k(r),onChange:t=>o.history.transaction(()=>{const n=w(t,v);e.forEach(e=>e.set(n))})})})]})});export const CellBackground=r(({elements:e,store:o})=>n(p,{children:[t(b,{render:t(u,{value:e[0].cellBackground,onChange:t=>o.history.transaction(()=>{e.forEach(e=>e.set({cellBackground:t}))}),store:o})}),t(m,{children:S("toolbar.cellBackground")})]}));export const CellVerticalAlign=r(({elements:e,store:o})=>{const r=e[0];return n(p,{children:[t(b,{render:t(i,{variant:"ghost",size:"icon-sm",onClick:()=>{const t=g(j,r.verticalAlign);o.history.transaction(()=>{e.forEach(e=>e.set({verticalAlign:t}))})},"aria-label":S("toolbar.verticalAlign"),children:O[r.verticalAlign]})}),t(m,{children:S("toolbar.verticalAlign")})]})});const W={TableStructure,TableAnimations:B},{TextFontFamily:V,TextFontSize:K,TextFill:P,TextFontVariant:H,TextSpacing:I}=T,D={TextFontFamily:V,TextFontSize:K,TextFill:P,TextFontVariant:H,TextSpacing:I},L=Object.assign({TableBorderSettings,CellBackground,CellVerticalAlign},D),_=Object.assign(Object.assign({},W),L);export const TableToolbar=r(({store:e,components:n})=>{const o=e.selectedElements[0],r=o.focusedCells,l=r.length>0,i=o.textCells,s=["TableBorderSettings","CellBackground","TableStructure",...l?["TextFontFamily","TextFontSize","TextFill","TextFontVariant","CellVerticalAlign","TextSpacing"]:[],N.animationsEnabled&&"TableAnimations"],a=x({type:"table",usedItems:s,components:n});return t(y,{items:a,itemRender:s=>{const a=(null==n?void 0:n[s])||_[s],c=!!L[s],d=!(null==n?void 0:n[s])&&!!D[s];if(c&&!l&&"TableBorderSettings"!==s&&"CellBackground"!==s){return null}if(d&&0===i.length){return null}let p;return p=c?d?i:l?r:"TableBorderSettings"===s?e.selectedElements:o.cells.slice():e.selectedElements,t(a,{element:d?i[0]:o,store:e,elements:p},s)}})});export default TableToolbar;
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  export { NumberInput } from '../primitives/numeric-input.js';
3
3
  import type { StoreType, TextElementType } from '../ui-types.js';
4
+ import type { TableCellType } from '../model/table-model.js';
4
5
  type PageProps = {
5
6
  store: StoreType;
6
7
  components?: any;
@@ -39,8 +40,12 @@ export declare const TextTransform: (({ elements, store }: InputProps) => React.
39
40
  export declare const TextFill: (({ elements, store }: InputProps) => React.JSX.Element) & React.NamedExoticComponent<InputProps> & {
40
41
  readonly type: ({ elements, store }: InputProps) => React.JSX.Element;
41
42
  };
42
- export declare const TextSpacing: (({ elements, store }: InputProps) => React.JSX.Element) & React.NamedExoticComponent<InputProps> & {
43
- readonly type: ({ elements, store }: InputProps) => React.JSX.Element;
43
+ type SpacingProps = {
44
+ elements: Array<TextElementType | TableCellType>;
45
+ store: StoreType;
46
+ };
47
+ export declare const TextSpacing: (({ elements, store }: SpacingProps) => React.JSX.Element) & React.NamedExoticComponent<SpacingProps> & {
48
+ readonly type: ({ elements, store }: SpacingProps) => React.JSX.Element;
44
49
  };
45
50
  export declare const TextFilters: (({ element, store }: {
46
51
  element: import("../ui-types.js").ShapeType;