polotno 4.14.1 → 4.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/blueprint/side-panel/select-video.d.ts +22 -2
- package/canvas/crop-overlay.d.ts +36 -7
- package/canvas/crop-overlay.js +1 -1
- package/canvas/drawing-layer.js +1 -1
- package/canvas/fade-overlay.js +1 -1
- package/canvas/figure-element.js +1 -1
- package/canvas/gif-element.js +1 -1
- package/canvas/hotkeys.d.ts +5 -5
- package/canvas/hotkeys.js +1 -1
- package/canvas/html-element.js +1 -1
- package/canvas/image-element.js +1 -1
- package/canvas/image-processing.d.ts +5 -0
- package/canvas/image-processing.js +1 -0
- package/canvas/image-tool-controls.d.ts +15 -0
- package/canvas/image-tool-controls.js +1 -0
- package/canvas/line-element.js +1 -1
- package/canvas/page-controls.js +1 -1
- package/canvas/page.js +1 -1
- package/canvas/parent-frame.d.ts +5 -0
- package/canvas/parent-frame.js +1 -0
- package/canvas/quill-font-formats.js +1 -1
- package/canvas/rect-control.d.ts +13 -0
- package/canvas/rect-control.js +1 -0
- package/canvas/render-tag-element.js +1 -1
- package/canvas/rich-editor.js +3 -3
- package/canvas/table-element.js +1 -1
- package/canvas/text-element/caret-color.js +1 -1
- package/canvas/text-element.js +1 -1
- package/canvas/tooltip.js +1 -1
- package/canvas/use-color.d.ts +4 -0
- package/canvas/use-color.js +1 -1
- package/canvas/video-element.js +1 -1
- package/canvas/workspace-canvas.js +1 -1
- package/config.d.ts +4 -0
- package/config.js +1 -1
- package/icons/registry.d.ts +2 -0
- package/icons/registry.js +1 -1
- package/image-tools/geometry.d.ts +20 -0
- package/image-tools/geometry.js +1 -0
- package/image-tools/host.d.ts +62 -0
- package/image-tools/host.js +1 -0
- package/image-tools/messages.d.ts +5 -0
- package/image-tools/messages.js +1 -0
- package/image-tools/operations.d.ts +22 -0
- package/image-tools/operations.js +1 -0
- package/image-tools/raster.d.ts +13 -0
- package/image-tools/raster.js +1 -0
- package/image-tools/sessions.d.ts +73 -0
- package/image-tools/sessions.js +1 -0
- package/image-tools/target.d.ts +37 -0
- package/image-tools/target.js +1 -0
- package/image-tools/types.d.ts +62 -0
- package/image-tools/types.js +1 -0
- package/model/crop-mode.d.ts +18 -20
- package/model/crop-mode.js +1 -1
- package/model/gif-model.d.ts +11 -1
- package/model/group-model.d.ts +43 -6
- package/model/group-model.js +1 -1
- package/model/history.d.ts +8 -0
- package/model/history.js +1 -1
- package/model/image-edit-state.d.ts +14 -0
- package/model/image-edit-state.js +1 -0
- package/model/image-model.d.ts +11 -1
- package/model/image-model.js +1 -1
- package/model/image-tools.d.ts +26 -0
- package/model/image-tools.js +1 -0
- package/model/page-model.d.ts +111 -12
- package/model/store.d.ts +26 -3
- package/model/store.js +1 -1
- package/model/svg-model.d.ts +2 -1
- package/model/text-model.d.ts +2 -0
- package/model/text-model.js +1 -1
- package/model/video-model.d.ts +11 -1
- package/package.json +20 -20
- package/polotno.bundle.js +165 -165
- package/primitives/toggle.js +1 -1
- package/side-panel/ai-images-panel.js +1 -1
- package/side-panel/background-panel.js +1 -1
- package/side-panel/effect-card.js +1 -1
- package/side-panel/effects-panel.js +1 -1
- package/side-panel/image-edit-panel.d.ts +11 -0
- package/side-panel/image-edit-panel.js +1 -0
- package/side-panel/photos-panel.js +1 -1
- package/side-panel/select-video.d.ts +22 -2
- package/side-panel/side-panel.d.ts +1 -0
- package/side-panel/side-panel.js +1 -1
- package/side-panel/upload-panel.js +1 -1
- package/toolbar/color-picker.js +1 -1
- package/toolbar/element-container.js +1 -1
- package/toolbar/html-toolbar.js +3 -3
- package/toolbar/image-remove-background-button.d.ts +1 -1
- package/toolbar/image-remove-background-button.js +1 -1
- package/toolbar/image-toolbar.d.ts +1 -0
- package/toolbar/image-toolbar.js +1 -1
- package/toolbar/image-tools.d.ts +43 -0
- package/toolbar/image-tools.js +1 -0
- package/toolbar/sketch.d.ts +4 -1
- package/toolbar/sketch.js +1 -1
- package/toolbar/stop-track.d.ts +28 -0
- package/toolbar/stop-track.js +1 -0
- package/toolbar/toolbar.js +1 -1
- package/toolbar/use-copy-style.js +1 -1
- package/ui.css +1 -1
- package/utils/api.d.ts +14 -0
- package/utils/api.js +1 -1
- package/utils/clipboard.d.ts +4 -0
- package/utils/errors.d.ts +1 -0
- package/utils/errors.js +1 -1
- package/utils/fade-gradient.d.ts +5 -6
- package/utils/fade-gradient.js +1 -1
- package/utils/flags.d.ts +7 -1
- package/utils/flags.js +1 -1
- package/utils/gradient-stops.d.ts +25 -0
- package/utils/gradient-stops.js +1 -0
- package/utils/image-edit.d.ts +37 -0
- package/utils/image-edit.js +1 -0
- package/utils/l10n.d.ts +35 -0
- package/utils/l10n.js +1 -1
- package/utils/luma.js +1 -1
- package/utils/px.d.ts +4 -0
- package/utils/px.js +1 -1
- package/utils/rich-text-html.d.ts +5 -0
- package/utils/rich-text-html.js +1 -1
- package/utils/stops.d.ts +17 -0
- package/utils/stops.js +1 -0
- package/utils/text-format-state.d.ts +3 -2
- package/utils/text-format-state.js +1 -1
- package/utils/text-format.d.ts +4 -1
- package/utils/text-format.js +1 -1
- package/utils/to-pptx.d.ts +1 -1
- package/utils/to-pptx.js +1 -1
- package/utils/validate-key.js +1 -1
package/primitives/toggle.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=this&&this.__rest||function(e,
|
|
1
|
+
var e=this&&this.__rest||function(e,r){var n={};for(var t in e){Object.prototype.hasOwnProperty.call(e,t)&&r.indexOf(t)<0&&(n[t]=e[t])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var a=0;for(t=Object.getOwnPropertySymbols(e);a<t.length;a++){r.indexOf(t[a])<0&&Object.prototype.propertyIsEnumerable.call(e,t[a])&&(n[t[a]]=e[t[a]])}}return n};import{jsx as r}from"react/jsx-runtime";import*as n from"react";import{cva as t}from"class-variance-authority";import{Toggle as a}from"@base-ui/react/toggle";import{cn as i}from"../lib/utils.js";const s=t("pn:inline-flex pn:items-center pn:justify-center pn:gap-2 pn:rounded-md pn:text-sm pn:font-medium pn:whitespace-nowrap pn:transition-[color,box-shadow] pn:outline-none pn:hover:bg-muted pn:hover:text-muted-foreground pn:focus-visible:border-ring pn:focus-visible:ring-[3px] pn:focus-visible:ring-ring/50 pn:disabled:pointer-events-none pn:disabled:opacity-50 pn:aria-invalid:border-destructive pn:aria-invalid:ring-destructive/20 pn:data-pressed:bg-primary pn:data-pressed:text-primary-foreground pn:data-pressed:hover:bg-primary/90 pn:data-pressed:hover:text-primary-foreground pn:dark:aria-invalid:ring-destructive/40 pn:[&_svg]:pointer-events-none pn:[&_svg]:shrink-0 pn:[&_svg:not([class*='size-'])]:size-4",{variants:{variant:{default:"pn:bg-transparent",outline:"pn:border pn:border-input pn:bg-transparent pn:shadow-xs pn:hover:bg-accent pn:hover:text-accent-foreground"},size:{default:"pn:h-9 pn:min-w-9 pn:px-2"}},defaultVariants:{variant:"default",size:"default"}}),o=n.forwardRef((n,t)=>{var{className:o,variant:p,size:d}=n,l=e(n,["className","variant","size"]);return r(a,Object.assign({ref:t,"data-slot":"toggle",className:i(s({variant:p,size:d,className:o}))},l))});o.displayName="Toggle";export{o as Toggle,s as toggleVariants};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e,jsxs as t}from"react/jsx-runtime";import i from"react";import{observer as o}from"mobx-react-lite";import{Button as r}from"../primitives/button.js";import{InputGroup as n,InputGroupInput as a}from"../primitives/input-group.js";import{getKey as
|
|
1
|
+
import{jsx as e,jsxs as t}from"react/jsx-runtime";import i from"react";import{observer as o}from"mobx-react-lite";import{Button as r}from"../primitives/button.js";import{InputGroup as n,InputGroupInput as a}from"../primitives/input-group.js";import{getKey as l}from"../utils/validate-key.js";import{getImageSize as s}from"@polotno/core/image";import{isImageLoadError as m}from"../utils/errors.js";import{ImagesGrid as p}from"./images-grid.js";import{getAPI as u}from"../utils/api.js";export const AiImagesPanel=o(({store:o})=>{const d=i.useRef(null),[c,g]=i.useState(null),[f,h]=i.useState(!1),[v,y]=i.useState(null),w=async()=>{h(!0),g(null),y(null);const e=await fetch(`${u()}/get-stable-diffusion?KEY=${l()}&prompt=${d.current.value}`);if(h(!1),!e.ok){return void alert("Something went wrong, please try again later...")}const t=await e.json();g(t.output[0])};return t("div",{className:"pn:flex pn:h-full pn:flex-col",children:[e("div",{style:{padding:"15px 0"},children:"Stable Diffusion is a latent text-to-image diffusion model capable of generating photo-realistic images given any text input"}),e(n,{style:{marginBottom:"20px"},children:e(a,{placeholder:"Type your image generation prompt here...",onKeyDown:e=>{"Enter"===e.key&&w()},ref:d})}),e(r,{onClick:w,disabled:f,style:{marginBottom:"40px"},children:"Generate"}),c&&e(p,{shadowEnabled:!1,images:c?[c]:[],getPreview:e=>e,isLoading:f,error:v,onSelect:async(e,t,i)=>{var r;y(null);const n=e;if(i&&"svg"===i.type&&i.contentEditable){return void i.set({maskSrc:n})}if(i&&"image"===i.type&&i.contentEditable){return void i.set({src:n})}const a=await s(n).catch(e=>{if(!m(e)){throw e}return console.warn("polotno: failed to add the generated image",e),y(e),null});if(!a){return}const{width:l,height:p}=a,u=((null==t?void 0:t.x)||o.width/2)-l/2,d=((null==t?void 0:t.y)||o.height/2)-p/2;null===(r=o.activePage)||void 0===r||r.addElement({type:"image",src:n,width:l,height:p,x:u,y:d})},rowsNumber:1})]})});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e,jsxs as r}from"react/jsx-runtime";import{observer as t}from"mobx-react-lite";import{observable as o}from"mobx";import{PolotnoIcon as a}from"../icons/registry.js";import{ColorPicker as
|
|
1
|
+
import{jsx as e,jsxs as r}from"react/jsx-runtime";import{observer as t}from"mobx-react-lite";import{observable as o}from"mobx";import{PolotnoIcon as a}from"../icons/registry.js";import{ColorPicker as i,ColoredBox as n}from"../toolbar/color-picker.js";import{ImagesGrid as s}from"./images-grid.js";import{unsplashCredit as l}from"./unsplash-credit.js";import{t as d}from"../utils/l10n.js";import{useInfiniteAPI as c}from"../utils/use-api.js";import{unsplashList as p,unsplashDownload as m}from"../utils/api.js";import{SearchInput as u}from"../primitives/search-input.js";let g="gradient";export const setDefaultQuery=e=>{g=e};const f=o(["white","rgb(82, 113, 255)","rgb(255, 145, 77)","rgb(126, 217, 87)","rgb(255, 222, 89)","rgb(203, 108, 230)","rgb(0, 0, 0, 0)"]);export const setBackgroundColorsPreset=e=>{f.replace(e)};export const BackgroundPanel=t(({store:t})=>{var o;const{setQuery:h,loadMore:v,isReachingEnd:b,data:x,isLoading:j,error:k}=c({defaultQuery:g,getAPI:({page:e,query:r})=>p({page:e,query:r})});return r("div",{className:"pn:flex pn:h-full pn:flex-col",children:[r("div",{style:{display:"flex",justifyContent:"space-around",paddingBottom:"10px"},children:[e(i,{value:(null===(o=t.activePage)||void 0===o?void 0:o.background)||"white",onChange:e=>{var r;null===(r=t.activePage)||void 0===r||r.set({background:e})},store:t,position:"bottom-left",gradientEnabled:!0,children:e(a,{name:"background.colorPicker",className:"pn:size-5 pn:text-white",style:{mixBlendMode:"difference"}})}),f.map(r=>e(n,{background:r,onClick:()=>{var e;null===(e=t.activePage)||void 0===e||e.set({background:r})}},r))]}),e(u,{style:{marginBottom:"20px"},placeholder:d("sidePanel.searchPlaceholder"),onChange:e=>{h(e.target.value||g)}}),r("p",{className:"pn:text-center pn:text-sm pn:text-muted-foreground",children:["Photos by"," ",e("a",{href:"https://unsplash.com/",target:"_blank",className:"pn:font-medium pn:text-foreground pn:underline pn:underline-offset-2",children:"Unsplash"})]}),e(s,{images:null==x?void 0:x.map(e=>e.results).flat().filter(Boolean),isLoading:j,getPreview:e=>e.urls.small,getAlt:e=>e.alt_description||"",loadMore:!b&&v,onSelect:e=>{var r;fetch(m(e.id)).catch(()=>{}),null===(r=t.activePage)||void 0===r||r.set({background:e.urls.regular})},error:k,getCredit:l})]})});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=this&&this.__rest||function(e,
|
|
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{jsx as r,jsxs as t,Fragment 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:n,effect:s,onClick:l,active:o})=>{const i=f(s);return t("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:[t("div",{className:"pn:relative pn:h-[90px] pn:rounded-[10px] pn:box-border",children:[r("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")}),r(i,{src:n})]}),r("span",{className:"pn:text-center",children:e})]})};const o=t=>{var{className:n,style:s}=t,l=e(t,["className","style"]);return r("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=>r(o,Object.assign({style:{filter:"sepia(1)"}},e)),c=e=>r(o,Object.assign({style:{filter:"grayscale(1)"}},e)),p=e=>{const t=l(s.warm);return r(o,Object.assign({style:{filter:null==t?void 0:t.filter}},e))},u=e=>{const a=l(s.cold),i=null==a?void 0:a.html,c=null==a?void 0:a.filter;return t(n,{children:[r("div",{style:{display:"none"},dangerouslySetInnerHTML:{__html:i||""}}),r(o,Object.assign({style:{filter:c}},e))]})},d=e=>{const t=l(s.natural);return r(o,Object.assign({style:{filter:null==t?void 0:t.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 +1 @@
|
|
|
1
|
-
import{jsx as e,Fragment as a,jsxs as t}from"react/jsx-runtime";import o from"react";import{Slider as r}from"../primitives/slider.js";import{firstSliderValue as l}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 p}from"../utils/l10n.js";import{EffectCard as u}from"./effect-card.js";import{Effects as h}from"@polotno/core/filters";import{CurvePowerSlider as b}from"../toolbar/filters-picker.js";import{NumericInput as m}from"../primitives/numeric-input.js";import{FieldRow as f}from"../primitives/field-row.js";import{PanelHeader as g}from"../primitives/panel-header.js";import{ToggleGroup as v,ToggleGroupItem as x}from"../primitives/toggle-group.js";import{normalizeStrokeLineJoin as y}from"@polotno/core/text-html";import{defaultFade as C,insertFadeStop as k,moveFadeStop as w,fadePreview as j,fadeStopColor as E,FADE_CHECKERBOARD as M}from"../utils/fade-gradient.js";import{Button as S}from"../primitives/button.js";import{usePointerDrag as O}from"../utils/pointer-drag.js";import{useEvent as R}from"../hooks/use-event.js";import{useFadeStopFocus as F}from"../hooks/use-fade-stop-focus.js";import{getSelectedFadeStop as z,setSelectedFadeStop as P}from"../utils/fade-overlay.js";import{readClipFade as N,writeClipFade as V}from"../utils/clip-fade.js";import{urlToBase64 as B}from"@polotno/core/svg";import{isAlive as L}from"mobx-state-tree";import{PanelScrollArea as D}from"../primitives/panel-scroll-area.js";const X=[{value:"round",labelKey:"toolbar.joinRound"},{value:"miter",labelKey:"toolbar.joinMiter"},{value:"bevel",labelKey:"toolbar.joinBevel"}],W=({join:a})=>e("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:e("path",{d:"M7 21 L7 7 L21 7",stroke:"currentColor",strokeWidth:"9",strokeLinejoin:a,strokeLinecap:"butt"})});export{m as NumberInput};const A=(e,a,t)=>Math.max(a,Math.min(t,e)),K=(e,a)=>Math.max(e,Math.ceil(a)),Y=(e,a)=>Math.min(e,Math.floor(a)),I=[["temperature","toolbar.temperature"],["contrast","toolbar.contrast"],["shadows","toolbar.shadows"],["white","toolbar.white"],["black","toolbar.black"],["vibrance","toolbar.vibrance"],["saturation","toolbar.saturation"]],$=s(({store:r,elements:l})=>{const[n,s]=o.useState(""),[d,c]=o.useState(!1),u=l.filter(e=>["image","video","gif"].includes(e.type)),h=u[0];if(!h){return null}const b=N(h.clipSrc);return t(a,{children:[e(i,{label:p("toolbar.clipFade.title"),enabled:!!b,disabled:d,onEnabledChange:e=>{(async e=>{if(!d){c(!0),s("");try{const a=await Promise.all(u.map(async a=>{var t;const o=a.clipSrc,r=N(o),l=null!==(t=null==r?void 0:r.baseSrc)&&void 0!==t?t:o,n=e&&l&&!l.startsWith("data:")?await B(l,{binary:!0}):l;return{item:a,previous:o,clipSrc:e?V(C(),n):null==r?void 0:r.baseSrc}}));r.history.transaction(()=>a.forEach(({item:e,previous:a,clipSrc:t})=>{L(e)&&e.clipSrc===a&&null!=t&&e.set({clipSrc:t})}))}catch(n){s(n instanceof Error?n.message:String(n))}finally{c(!1)}}})(e)},children:b&&e(T,{store:r,element:h,value:b.fade,onChange:e=>r.history.transaction(()=>{u.forEach(a=>{if(!L(a)){return}const t=N(a.clipSrc);t&&a.set({clipSrc:V(e,t.baseSrc)})})})},h.id)}),d&&e("div",{role:"status",children:p("toolbar.clipFade.preparing")}),n&&e("div",{role:"alert",children:n})]})}),T=s(({store:r,element:l,value:i,onChange:s})=>{const d=Math.min(z(r),i.stops.length-1),c=i.stops[d],u=o.useRef(null),h=O(),b=o.useRef(null),m=()=>{null!==b.current&&(b.current=null,r.history.endTransaction())};o.useEffect(()=>()=>m(),[r]);const g=e=>P(r,e),y=e=>{var a,t;const o=null===(t=null===(a=u.current)||void 0===a?void 0:a.parentElement)||void 0===t?void 0:t.querySelectorAll("[data-fade-stop]"),r=null==o?void 0:o[e];return!(!r||!r.getClientRects().length)&&(r.focus({preventScroll:!0}),document.activeElement===r)};F(r,l.id,e=>(g(e),y(e)));const N=o.useRef(null);o.useLayoutEffect(()=>{null!==N.current&&(y(N.current),N.current=null)});const V=e=>{const a=u.current.getBoundingClientRect();return Math.max(0,Math.min(1,(e-a.left)/(a.width||1)))},B=R(e=>(e=>{const a=w(i.stops,d,e);g(a.index),s(Object.assign(Object.assign({},i),{stops:a.stops}))})(V(e.clientX))),L=(e,a=!1)=>{if(i.stops.length<=2){return}const t=Math.max(0,e-1);a&&y(0===e?1:e-1),g(t),s(Object.assign(Object.assign({},i),{stops:i.stops.filter((a,t)=>t!==e)}))};return t(a,{children:[e(f,{label:p("toolbar.clipFade.shape"),children:t(v,{value:[i.shape],onValueChange:e=>{const a=e[0];"linear"!==a&&"radial"!==a||a===i.shape||s(Object.assign(Object.assign({},C(a)),{stops:i.stops}))},children:[e(x,{value:"linear",className:"pn:data-pressed:bg-primary pn:data-pressed:text-primary-foreground","aria-label":p("toolbar.clipFade.linear"),children:p("toolbar.clipFade.linear")}),e(x,{value:"radial",className:"pn:data-pressed:bg-primary pn:data-pressed:text-primary-foreground","aria-label":p("toolbar.clipFade.radial"),children:p("toolbar.clipFade.radial")})]})}),e("p",{className:"pn:py-1 pn:text-xs pn:text-muted-foreground",children:p("toolbar.clipFade.hint")}),e("div",{className:"pn:px-3",children:t("div",{role:"group","aria-label":p("toolbar.clipFade.stops"),style:{position:"relative",height:36,touchAction:"none"},onPointerDown:e=>{if(0!==e.button||null!==b.current){return}e.preventDefault();const a=e.target.closest("[data-fade-stop]");if(r.history.startTransaction(),b.current=e.pointerId,h(e,{node:l,onMove:B,onEnd:m}),a){a.focus(),g(i.stops.findIndex(e=>e.id===a.dataset.fadeStop))}else{const a=k(i.stops,V(e.clientX));g(a.index),N.current=a.index,s(Object.assign(Object.assign({},i),{stops:a.stops}))}},children:[e("div",{ref:u,"data-fade-track":!0,style:{position:"absolute",top:13,height:10,width:"100%",borderRadius:5,background:`${j(i.stops)}, ${M}`}}),i.stops.map((a,t)=>e("button",{type:"button","data-fade-stop":a.id,"aria-label":`${p("toolbar.clipFade.stop")} ${t+1}: ${Math.round(100*a.alpha)}%`,"aria-pressed":t===d,onFocus:()=>g(t),onClick:()=>g(t),onKeyDown:e=>((e,a)=>{const t={ArrowLeft:-1,ArrowDown:-1,ArrowRight:1,ArrowUp:1};if(!(e.key in t)&&!["Home","End","Delete","Backspace"].includes(e.key)){return}if(e.preventDefault(),e.stopPropagation(),g(a),"Delete"===e.key||"Backspace"===e.key){return void L(a,!0)}const o="Home"===e.key?0:"End"===e.key?1:i.stops[a].offset+t[e.key]*(e.shiftKey?.1:.01),r=w(i.stops,a,o);g(r.index),s(Object.assign(Object.assign({},i),{stops:r.stops}))})(e,t),className:"pn:absolute pn:top-1 pn:flex pn:size-7 pn:-translate-x-1/2 pn:items-center pn:justify-center pn:rounded",style:{left:100*a.offset+"%",zIndex:t===d?2:1,outline:t===d?"2px solid var(--pn-primary, #137cbd)":void 0,outlineOffset:-2},children:e("span",{style:{display:"block",width:14,height:14,borderRadius:"50%",border:"2px solid #fff",boxShadow:"0 1px 3px #0006",background:E(a.alpha)}})},a.id))]})}),e(n,{label:p("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,t)=>t===d?Object.assign(Object.assign({},a),{alpha:e/100}):a)}))}),t("div",{className:"pn:flex pn:flex-wrap pn:justify-end pn:gap-1 pn:py-1",children:[e(S,{variant:"ghost",size:"sm",onClick:()=>{g(i.stops.length-1-d),s(Object.assign(Object.assign({},i),{stops:[...i.stops].reverse().map(e=>Object.assign(Object.assign({},e),{offset:1-e.offset}))}))},children:p("toolbar.clipFade.reverse")}),e(S,{variant:"ghost",size:"sm",disabled:i.stops.length<=2,onClick:()=>L(d),children:p("toolbar.clipFade.removeStop")}),e(S,{variant:"ghost",size:"sm",onClick:()=>{g(0),s(C(i.shape))},children:p("toolbar.clipFade.reset")})]})]})}),J=({store:a,color:o,onColorChange:n,value:i,onValueChange:s,min:d,max:p,sliderMax:u})=>t("div",{style:{display:"flex",alignItems:"center",padding:"8px 0"},children:[e(c,{value:o,size:30,gradientEnabled:!0,onChange:n,store:a}),e("div",{style:{flex:1,paddingLeft:"10px",paddingRight:"10px"},children:e(r,{value:[i],onValueChange:e=>s(A(Math.round(l(e)),d,p)),min:d,max:null!=u?u:p,step:1})}),e(m,{value:Math.round(i),onValueChange:e=>s(A(e,d,p)),min:d,max:p,style:{width:64}})]});export const EffectsPanel=s(({store:a})=>{var r;const l=a.selectedElements,s=l[0],C=l.map(e=>e.id).join(","),k="effects"===a.openedSidePanel;if(o.useEffect(()=>{k&&(s&&s.filters||a.restoreSidePanel())},[k,C]),!s||!s.filters){return null}const w="text"===s.type,j="image"===s.type,E="svg"===s.type,M=j||E,S="image"===s.type||"video"===s.type||"gif"===s.type,O=Math.min(s.width,s.height)/2,R=Math.min(null!==(r=s.cornerRadius)&&void 0!==r?r:0,O),F=e=>{a.history.transaction(()=>{l.forEach(a=>{a.set(e)})})},z=(e,t)=>{a.history.transaction(()=>{l.forEach(a=>{let o=Number(t);return 0==t||t||(o=a.filters.has(e)?null:1),d.includes(e)||a.set({grayscaleEnabled:"grayscale"===e&&!!t,sepiaEnabled:"sepia"===e&&!!t}),a.setFilter(e,o)})})};return t(D,{header:e(g,{title:p("sidePanel.effects"),onClose:()=>a.restoreSidePanel()}),children:[M&&e("div",{style:{display:"flex",flexDirection:"column",gap:"16px",marginTop:"16px"},children:t("div",{style:{display:"flex",gap:"16px",flexWrap:"wrap"},children:[e(u,{active:s.grayscaleEnabled,onClick:()=>{z("grayscale",!s.grayscaleEnabled)},title:p("toolbar.grayscale"),imageSrc:s.src,effect:h.grayscale}),e(u,{active:s.sepiaEnabled,onClick:()=>{z("sepia",!s.sepiaEnabled)},title:p("toolbar.sepia"),imageSrc:s.src,effect:h.sepia}),e(u,{active:s.filters.has("cold"),onClick:()=>{z("cold",s.filters.has("cold")?null:1)},title:p("toolbar.cold"),imageSrc:s.src,effect:h.cold}),e(u,{active:s.filters.has("natural"),onClick:()=>{z("natural",s.filters.has("natural")?null:1)},title:p("toolbar.natural"),imageSrc:s.src,effect:h.natural}),e(u,{active:s.filters.has("warm"),onClick:()=>{z("warm",s.filters.has("warm")?null:1)},title:p("toolbar.warm"),imageSrc:s.src,effect:h.warm})]})}),e(n,{label:p("toolbar.blur"),enabled:s.blurEnabled,visible:M||w,onEnabledChange:e=>{F({blurEnabled:e})},value:s.blurRadius,onChange:e=>{F({blurRadius:e})},min:0,max:100}),e(n,{label:p("toolbar.brightness"),visible:M,enabled:s.brightnessEnabled,onEnabledChange:e=>{F({brightnessEnabled:e})},value:Math.round(100*s.brightness),onChange:e=>{F({brightness:e/100})},min:-100,max:100}),I.map(([a,t])=>{var o,r;return e(n,{label:p(t),visible:M,enabled:s.filters.has(a),onEnabledChange:e=>{z(a,e?0:null)},value:Math.round(100*(null!==(r=null===(o=s.filters.get(a))||void 0===o?void 0:o.intensity)&&void 0!==r?r:0)),onChange:e=>{z(a,e/100)},min:-100,max:100},a)}),w&&t(i,{label:p("toolbar.curvedText")||"Curved text",enabled:!!s.curveEnabled,onEnabledChange:e=>F({curveEnabled:e}),children:[e(f,{label:p("toolbar.curvePower")||"Curve",className:"pn:py-2",children:e(m,{value:Math.round(100*s.curvePower),onValueChange:e=>{F({curvePower:A(e,-100,100)/100})},style:{width:64},min:-100,max:100})}),e(b,{textEl:s,eachSet:F})]}),w&&t(i,{label:p("toolbar.textStroke"),enabled:!!s.strokeWidth,onEnabledChange:e=>F({strokeWidth:e?2:0}),children:[e(J,{store:a,color:s.stroke,onColorChange:e=>{F({stroke:e})},value:s.strokeWidth,onValueChange:e=>{F({strokeWidth:e})},min:1,max:Math.max(1,Math.round(s.fontSize/2)),sliderMax:Math.max(1,s.fontSize/2)}),e(f,{label:p("toolbar.strokeLineJoin"),className:"pn:py-2",children:e(v,{variant:"outline",value:[y(s.strokeLineJoin)],onValueChange:e=>{const a=e[0];a&&F({strokeLineJoin:a})},children:X.map(({value:a,labelKey:t})=>e(x,{value:a,"aria-label":p(t),title:p(t),children:e(W,{join:a})},a))})})]}),w&&t(i,{label:p("toolbar.textBackground"),enabled:!!s.backgroundEnabled,onEnabledChange:e=>F({backgroundEnabled:e}),children:[e(n,{label:p("toolbar.backgroundCornerRadius"),value:Math.round(100*s.backgroundCornerRadius),onChange:e=>F({backgroundCornerRadius:e/100}),min:0,max:100}),e(n,{label:p("toolbar.backgroundPadding"),value:Math.round(100*s.backgroundPadding),onChange:e=>F({backgroundPadding:e/100}),min:0,max:100}),e(n,{label:p("toolbar.opacity"),value:Math.round(100*s.backgroundOpacity),onChange:e=>F({backgroundOpacity:e/100}),min:0,max:100}),e(f,{label:p("toolbar.color"),className:"pn:py-2",children:e(c,{value:s.backgroundColor,size:30,onChange:e=>{F({backgroundColor:e})},store:a})})]}),M&&e(i,{label:p("toolbar.border"),enabled:!!s.borderSize,onEnabledChange:e=>F({borderSize:e?2:0}),children:e(J,{store:a,color:s.borderColor,onColorChange:e=>{F({borderColor:e})},value:s.borderSize,onValueChange:e=>{F({borderSize:e})},min:1,max:Math.max(1,Math.round(O)),sliderMax:Math.max(1,O)})}),M&&e(n,{label:p("toolbar.cornerRadius"),visible:M,enabled:0!==s.cornerRadius,onEnabledChange:e=>{F({cornerRadius:e?Math.min(s.width/4,s.height/4):0})},value:Math.round(R),sliderValue:R,onChange:e=>{F({cornerRadius:e})},min:1,max:Math.round(O),sliderMax:O}),S&&e($,{store:a,elements:l}),t(i,{label:p("toolbar.shadow"),enabled:s.shadowEnabled,onEnabledChange:e=>F({shadowEnabled:e}),children:[e(n,{label:p("toolbar.blur"),value:Math.round(s.shadowBlur),sliderValue:s.shadowBlur,onChange:e=>{F({shadowBlur:e})},min:0,max:K(50,s.shadowBlur)}),e(n,{label:p("toolbar.offsetX"),value:Math.round(s.shadowOffsetX),sliderValue:s.shadowOffsetX,onChange:e=>{F({shadowOffsetX:e})},min:Y(-50,s.shadowOffsetX),max:K(50,s.shadowOffsetX)}),e(n,{label:p("toolbar.offsetY"),value:Math.round(s.shadowOffsetY),sliderValue:s.shadowOffsetY,onChange:e=>{F({shadowOffsetY:e})},min:Y(-50,s.shadowOffsetY),max:K(50,s.shadowOffsetY)}),e(n,{label:p("toolbar.opacity"),value:Math.round(100*s.shadowOpacity),onChange:e=>{F({shadowOpacity:e/100})},min:0,max:100}),e(f,{label:p("toolbar.color"),className:"pn:py-2",children:e(c,{value:s.shadowColor,size:30,onChange:e=>{F({shadowColor:e})},store:a})})]})]})});
|
|
1
|
+
import{jsx as e,Fragment as a,jsxs as o}from"react/jsx-runtime";import r from"react";import{Slider as l}from"../primitives/slider.js";import{firstSliderValue as t}from"../lib/utils.js";import{SliderField as n}from"../primitives/slider-field.js";import{FieldGroup as i}from"../primitives/field-group.js";import{observer as s}from"mobx-react-lite";import{INDEPENDENT_FILTERS as d}from"../model/shape-model.js";import{ColorPicker as c}from"../toolbar/color-picker.js";import{t as b}from"../utils/l10n.js";import{EffectCard as h}from"./effect-card.js";import{Effects as u}from"@polotno/core/filters";import{CurvePowerSlider as p}from"../toolbar/filters-picker.js";import{NumericInput as m}from"../primitives/numeric-input.js";import{FieldRow as f}from"../primitives/field-row.js";import{PanelHeader as g}from"../primitives/panel-header.js";import{ToggleGroup as v,ToggleGroupItem as C}from"../primitives/toggle-group.js";import{normalizeStrokeLineJoin as x}from"@polotno/core/text-html";import{defaultFade as y,insertFadeStop as w,fadePreview as k,fadeStopColor as j,FADE_CHECKERBOARD as E}from"../utils/fade-gradient.js";import{Button as M}from"../primitives/button.js";import{canRemoveStop as S,reverseStops as O}from"../utils/stops.js";import{StopTrack as z}from"../toolbar/stop-track.js";import{useFadeStopFocus as F}from"../hooks/use-fade-stop-focus.js";import{getSelectedFadeStop as R,setSelectedFadeStop as V}from"../utils/fade-overlay.js";import{readClipFade as P,writeClipFade as N}from"../utils/clip-fade.js";import{urlToBase64 as L}from"@polotno/core/svg";import{isAlive as B}from"mobx-state-tree";import{PanelScrollArea as W}from"../primitives/panel-scroll-area.js";const X=[{value:"round",labelKey:"toolbar.joinRound"},{value:"miter",labelKey:"toolbar.joinMiter"},{value:"bevel",labelKey:"toolbar.joinBevel"}],Y=({join:a})=>e("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:e("path",{d:"M7 21 L7 7 L21 7",stroke:"currentColor",strokeWidth:"9",strokeLinejoin:a,strokeLinecap:"butt"})});export{m as NumberInput};const $=(e,a,o)=>Math.max(a,Math.min(o,e)),K=(e,a)=>Math.max(e,Math.ceil(a)),J=(e,a)=>Math.min(e,Math.floor(a)),I=[["temperature","toolbar.temperature"],["contrast","toolbar.contrast"],["shadows","toolbar.shadows"],["white","toolbar.white"],["black","toolbar.black"],["vibrance","toolbar.vibrance"],["saturation","toolbar.saturation"]],T=s(({store:l,elements:t})=>{const[n,s]=r.useState(""),[d,c]=r.useState(!1),h=t.filter(e=>["image","video","gif"].includes(e.type)),u=h[0];if(!u){return null}const p=P(u.clipSrc);return o(a,{children:[e(i,{label:b("toolbar.clipFade.title"),enabled:!!p,disabled:d,onEnabledChange:e=>{(async e=>{if(!d){c(!0),s("");try{const a=await Promise.all(h.map(async a=>{var o;const r=a.clipSrc,l=P(r),t=null!==(o=null==l?void 0:l.baseSrc)&&void 0!==o?o:r,n=e&&t&&!t.startsWith("data:")?await L(t,{binary:!0}):t;return{item:a,previous:r,clipSrc:e?N(y(),n):null==l?void 0:l.baseSrc}}));l.history.transaction(()=>a.forEach(({item:e,previous:a,clipSrc:o})=>{B(e)&&e.clipSrc===a&&null!=o&&e.set({clipSrc:o})}))}catch(n){s(n instanceof Error?n.message:String(n))}finally{c(!1)}}})(e)},children:p&&e(D,{store:l,element:u,value:p.fade,onChange:e=>l.history.transaction(()=>{h.forEach(a=>{if(!B(a)){return}const o=P(a.clipSrc);o&&a.set({clipSrc:N(e,o.baseSrc)})})})},u.id)}),d&&e("div",{role:"status",children:b("toolbar.clipFade.preparing")}),n&&e("div",{role:"alert",children:n})]})}),D=s(({store:l,element:t,value:i,onChange:s})=>{const d=Math.min(R(l),i.stops.length-1),c=i.stops[d],h=r.useRef(null),u=e=>V(l,e);F(l,t.id,e=>{var a,o;return u(e),null!==(o=null===(a=h.current)||void 0===a?void 0:a.focus(e))&&void 0!==o&&o});const p=e=>{u(e.index),s(Object.assign(Object.assign({},i),{stops:e.stops}))};return o(a,{children:[e(f,{label:b("toolbar.clipFade.shape"),children:o(v,{value:[i.shape],onValueChange:e=>{const a=e[0];"linear"!==a&&"radial"!==a||a===i.shape||s(Object.assign(Object.assign({},y(a)),{stops:i.stops}))},children:[e(C,{value:"linear","aria-label":b("toolbar.clipFade.linear"),children:b("toolbar.clipFade.linear")}),e(C,{value:"radial","aria-label":b("toolbar.clipFade.radial"),children:b("toolbar.clipFade.radial")})]})}),e("p",{className:"pn:py-1 pn:text-xs pn:text-muted-foreground",children:b("toolbar.clipFade.hint")}),e("div",{className:"pn:px-3",children:e(z,{handle:h,store:l,node:t,label:b("toolbar.clipFade.stops"),stops:i.stops,selected:d,onSelect:u,onChange:p,insert:w,stopLabel:(e,a)=>`${b("toolbar.clipFade.stop")} ${a+1}: ${Math.round(100*e.alpha)}%`,swatch:e=>j(e.alpha),bar:e("div",{className:"pn:size-full",style:{background:`${k(i.stops)}, ${E}`}})})}),e(n,{label:b("toolbar.clipFade.stopOpacity"),value:Math.round(100*c.alpha),min:0,max:100,onChange:e=>s(Object.assign(Object.assign({},i),{stops:i.stops.map((a,o)=>o===d?Object.assign(Object.assign({},a),{alpha:e/100}):a)}))}),o("div",{className:"pn:flex pn:flex-wrap pn:justify-end pn:gap-1 pn:py-1",children:[e(M,{variant:"ghost",size:"sm",onClick:()=>p({stops:O(i.stops),index:i.stops.length-1-d}),children:b("toolbar.clipFade.reverse")}),e(M,{variant:"ghost",size:"sm",disabled:!S(i.stops),onClick:()=>{var e;return null===(e=h.current)||void 0===e?void 0:e.remove(d)},children:b("toolbar.clipFade.removeStop")}),e(M,{variant:"ghost",size:"sm",onClick:()=>{u(0),s(y(i.shape))},children:b("toolbar.clipFade.reset")})]})]})}),q=({store:a,color:r,onColorChange:n,value:i,onValueChange:s,min:d,max:b,sliderMax:h,gradientEnabled:u=!0})=>o("div",{style:{display:"flex",alignItems:"center",padding:"8px 0"},children:[e(c,{value:r,size:30,gradientEnabled:u,onChange:n,store:a}),e("div",{style:{flex:1,paddingLeft:"10px",paddingRight:"10px"},children:e(l,{value:[i],onValueChange:e=>s($(Math.round(t(e)),d,b)),min:d,max:null!=h?h:b,step:1})}),e(m,{value:Math.round(i),onValueChange:e=>s($(e,d,b)),min:d,max:b,style:{width:64}})]});export const EffectsPanel=s(({store:a})=>{var l;const t=a.selectedElements,s=t[0],y=t.map(e=>e.id).join(","),w="effects"===a.openedSidePanel;if(r.useEffect(()=>{w&&(s&&s.filters||a.restoreSidePanel())},[w,y]),!s||!s.filters){return null}const k="text"===s.type,j="image"===s.type,E="svg"===s.type,M=j||E,S="image"===s.type||"video"===s.type||"gif"===s.type,O=Math.min(s.width,s.height)/2,z=Math.min(null!==(l=s.cornerRadius)&&void 0!==l?l:0,O),F=e=>{a.history.transaction(()=>{t.forEach(a=>{a.set(e)})})},R=(e,o)=>{a.history.transaction(()=>{t.forEach(a=>{let r=Number(o);return 0==o||o||(r=a.filters.has(e)?null:1),d.includes(e)||a.set({grayscaleEnabled:"grayscale"===e&&!!o,sepiaEnabled:"sepia"===e&&!!o}),a.setFilter(e,r)})})};return o(W,{header:e(g,{title:b("sidePanel.effects"),onClose:()=>a.restoreSidePanel()}),children:[M&&e("div",{style:{display:"flex",flexDirection:"column",gap:"16px",marginTop:"16px"},children:o("div",{style:{display:"flex",gap:"16px",flexWrap:"wrap"},children:[e(h,{active:s.grayscaleEnabled,onClick:()=>{R("grayscale",!s.grayscaleEnabled)},title:b("toolbar.grayscale"),imageSrc:s.src,effect:u.grayscale}),e(h,{active:s.sepiaEnabled,onClick:()=>{R("sepia",!s.sepiaEnabled)},title:b("toolbar.sepia"),imageSrc:s.src,effect:u.sepia}),e(h,{active:s.filters.has("cold"),onClick:()=>{R("cold",s.filters.has("cold")?null:1)},title:b("toolbar.cold"),imageSrc:s.src,effect:u.cold}),e(h,{active:s.filters.has("natural"),onClick:()=>{R("natural",s.filters.has("natural")?null:1)},title:b("toolbar.natural"),imageSrc:s.src,effect:u.natural}),e(h,{active:s.filters.has("warm"),onClick:()=>{R("warm",s.filters.has("warm")?null:1)},title:b("toolbar.warm"),imageSrc:s.src,effect:u.warm})]})}),e(n,{label:b("toolbar.blur"),enabled:s.blurEnabled,visible:M||k,onEnabledChange:e=>{F({blurEnabled:e})},value:s.blurRadius,onChange:e=>{F({blurRadius:e})},min:0,max:100}),e(n,{label:b("toolbar.brightness"),visible:M,enabled:s.brightnessEnabled,onEnabledChange:e=>{F({brightnessEnabled:e})},value:Math.round(100*s.brightness),onChange:e=>{F({brightness:e/100})},min:-100,max:100}),I.map(([a,o])=>{var r,l;return e(n,{label:b(o),visible:M,enabled:s.filters.has(a),onEnabledChange:e=>{R(a,e?0:null)},value:Math.round(100*(null!==(l=null===(r=s.filters.get(a))||void 0===r?void 0:r.intensity)&&void 0!==l?l:0)),onChange:e=>{R(a,e/100)},min:-100,max:100},a)}),k&&o(i,{label:b("toolbar.curvedText")||"Curved text",enabled:!!s.curveEnabled,onEnabledChange:e=>F({curveEnabled:e}),children:[e(f,{label:b("toolbar.curvePower")||"Curve",className:"pn:py-2",children:e(m,{value:Math.round(100*s.curvePower),onValueChange:e=>{F({curvePower:$(e,-100,100)/100})},style:{width:64},min:-100,max:100})}),e(p,{textEl:s,eachSet:F})]}),k&&o(i,{label:b("toolbar.textStroke"),enabled:!!s.strokeWidth,onEnabledChange:e=>F({strokeWidth:e?2:0}),children:[e(q,{store:a,color:s.stroke,onColorChange:e=>{F({stroke:e})},value:s.strokeWidth,onValueChange:e=>{F({strokeWidth:e})},min:1,max:Math.max(1,Math.round(s.fontSize/2)),sliderMax:Math.max(1,s.fontSize/2)}),e(f,{label:b("toolbar.strokeLineJoin"),className:"pn:py-2",children:e(v,{variant:"outline",value:[x(s.strokeLineJoin)],onValueChange:e=>{const a=e[0];a&&F({strokeLineJoin:a})},children:X.map(({value:a,labelKey:o})=>e(C,{value:a,"aria-label":b(o),title:b(o),children:e(Y,{join:a})},a))})})]}),k&&o(i,{label:b("toolbar.textBackground"),enabled:!!s.backgroundEnabled,onEnabledChange:e=>F({backgroundEnabled:e}),children:[e(n,{label:b("toolbar.opacity"),value:Math.round(100*s.backgroundOpacity),onChange:e=>F({backgroundOpacity:e/100}),min:0,max:100}),e(f,{label:b("toolbar.color"),className:"pn:py-2",children:e(c,{value:s.backgroundColor,size:30,onChange:e=>{F({backgroundColor:e})},store:a})})]}),k&&e(i,{label:b("toolbar.border"),enabled:!!s.borderSize,onEnabledChange:e=>F({borderSize:e?2:0}),children:e(q,{store:a,color:s.borderColor,onColorChange:e=>F({borderColor:e}),value:s.borderSize,onValueChange:e=>F({borderSize:e}),min:1,max:Math.max(1,Math.round(s.fontSize/2)),gradientEnabled:!1})}),k&&(s.backgroundEnabled||s.borderSize>0)&&o(i,{label:b("toolbar.textBox"),children:[e(n,{label:b("toolbar.backgroundCornerRadius"),value:Math.round(100*s.backgroundCornerRadius),onChange:e=>F({backgroundCornerRadius:e/100}),min:0,max:200}),e(n,{label:b("toolbar.backgroundPadding"),value:Math.round(100*s.backgroundPadding),onChange:e=>F({backgroundPadding:e/100}),min:0,max:100})]}),M&&e(i,{label:b("toolbar.border"),enabled:!!s.borderSize,onEnabledChange:e=>F({borderSize:e?2:0}),children:e(q,{store:a,color:s.borderColor,onColorChange:e=>{F({borderColor:e})},value:s.borderSize,onValueChange:e=>{F({borderSize:e})},min:1,max:Math.max(1,Math.round(O)),sliderMax:Math.max(1,O)})}),M&&e(n,{label:b("toolbar.cornerRadius"),visible:M,enabled:0!==s.cornerRadius,onEnabledChange:e=>{F({cornerRadius:e?Math.min(s.width/4,s.height/4):0})},value:Math.round(z),sliderValue:z,onChange:e=>{F({cornerRadius:e})},min:1,max:Math.round(O),sliderMax:O}),S&&e(T,{store:a,elements:t}),o(i,{label:b("toolbar.shadow"),enabled:s.shadowEnabled,onEnabledChange:e=>F({shadowEnabled:e}),children:[e(n,{label:b("toolbar.blur"),value:Math.round(s.shadowBlur),sliderValue:s.shadowBlur,onChange:e=>{F({shadowBlur:e})},min:0,max:K(50,s.shadowBlur)}),e(n,{label:b("toolbar.offsetX"),value:Math.round(s.shadowOffsetX),sliderValue:s.shadowOffsetX,onChange:e=>{F({shadowOffsetX:e})},min:J(-50,s.shadowOffsetX),max:K(50,s.shadowOffsetX)}),e(n,{label:b("toolbar.offsetY"),value:Math.round(s.shadowOffsetY),sliderValue:s.shadowOffsetY,onChange:e=>{F({shadowOffsetY:e})},min:J(-50,s.shadowOffsetY),max:K(50,s.shadowOffsetY)}),e(n,{label:b("toolbar.opacity"),value:Math.round(100*s.shadowOpacity),onChange:e=>{F({shadowOpacity:e/100})},min:0,max:100}),e(f,{label:b("toolbar.color"),className:"pn:py-2",children:e(c,{value:s.shadowColor,size:30,onChange:e=>{F({shadowColor:e})},store:a})})]})]})});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { StoreType } from '../model/store.js';
|
|
3
|
+
export declare const ImageEditPanel: (({ store }: {
|
|
4
|
+
store: StoreType;
|
|
5
|
+
}) => React.JSX.Element | null) & React.NamedExoticComponent<{
|
|
6
|
+
store: StoreType;
|
|
7
|
+
}> & {
|
|
8
|
+
readonly type: ({ store }: {
|
|
9
|
+
store: StoreType;
|
|
10
|
+
}) => React.JSX.Element | null;
|
|
11
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as e,jsxs as n}from"react/jsx-runtime";import a from"react";import{observer as r}from"mobx-react-lite";import{imageEditHandlers as t}from"../utils/api.js";import{reportImageEditError as i,toolLabel as p}from"../image-tools/messages.js";import{discardOnEscape as o}from"../toolbar/image-tools.js";import{contains as m,sameRect as l,UNIT as s}from"../image-tools/geometry.js";import{Button as d}from"../primitives/button.js";import{Textarea as c}from"../primitives/textarea.js";import{Spinner as g}from"../primitives/spinner.js";import{PanelHeader as u}from"../primitives/panel-header.js";import{PolotnoIcon as f}from"../icons/registry.js";import{t as x}from"../utils/l10n.js";import{useMobile as v}from"../utils/screen.js";import{cn as h}from"../lib/utils.js";const b=r(({store:r,session:b})=>{const E=v()&&"crop"!==b.name,[y,N]=a.useState(""),[j,w]=a.useState(t.replace?"replace":"remove"),C=a.useId(),k=r.getElementById(b.elementId),D="replace"!==j||t.replace?"remove"!==j||t.remove?j:"replace":"remove";if(!k){return null}const I=!(b.pending||"expand"===b.name&&l(b.frame,s)||"inpaint"===b.name&&(!b.region||"replace"===D&&!y.trim())),$=async()=>{if(I){try{"expand"===b.name?await b.run({prompt:y}):"inpaint"===b.name?await b.run("replace"===D?{operation:"replace",prompt:y}:{operation:"remove"}):await b.run()}catch(e){i(k,e)}}},K="expand"===b.name&&m(s,b.frame)&&!l(b.frame,s),P="expand"===b.name&&(E||!K)||"inpaint"===b.name&&"replace"===D,_="crop"===b.name&&b.pending,z="crop"!==b.name&&b.pending;return n("div",{className:h("pn:flex pn:flex-col pn:overflow-auto pn:px-2.5",E?"pn:h-auto":"pn:h-full"),children:[!E&&e(u,{title:p(b.name),onClose:()=>r._closeImageTool("discard")}),n("form",{className:h("polotno-image-edit-panel pn:flex pn:flex-col",E?"pn:gap-2 pn:pb-2":"pn:gap-5 pn:pb-4"),onKeyDown:o(r,b),onSubmit:e=>{e.preventDefault(),$()},children:[!E&&e("p",{className:"pn:m-0 pn:text-sm pn:leading-relaxed pn:text-muted-foreground",children:x("inpaint"===b.name?`imageEdit.${D}Description`:"remove-background"===b.name?"imageEdit.removeBackgroundDescription":`imageEdit.${b.name}Description`)}),"inpaint"===b.name&&t.replace&&t.remove&&e("div",{className:"pn:flex pn:gap-1 pn:rounded-lg pn:bg-muted pn:p-1",children:["replace","remove"].map(n=>e(d,{type:"button",className:"pn:flex-1","aria-pressed":D===n,variant:D===n?"default":"ghost",disabled:b.pending,onClick:()=>w(n),children:x(`imageEdit.${n}`)},n))}),P&&n("div",{className:"pn:flex pn:flex-col pn:gap-2",children:[e("label",{htmlFor:C,className:E?"pn:sr-only":"pn:text-xs pn:font-semibold pn:tracking-wide pn:uppercase",children:x("imageEdit.prompt")}),e(c,{id:C,className:h("pn:leading-relaxed",E?"pn:min-h-12 pn:max-h-24 pn:resize-none":"pn:min-h-32 pn:resize-y"),rows:E?2:5,placeholder:x("expand"===b.name?"imageEdit.expandPromptPlaceholder":"imageEdit.promptPlaceholder"),value:y,disabled:b.pending||K,onChange:e=>N(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.ctrlKey||e.metaKey)&&(e.preventDefault(),$())}}),"inpaint"===b.name&&!E&&e("p",{className:"pn:m-0 pn:text-sm pn:leading-relaxed pn:text-muted-foreground",children:x("imageEdit.replaceHint")})]}),"inpaint"===b.name&&(E||!b.region)&&e("p",{className:h("pn:m-0 pn:text-muted-foreground",E?"pn:text-xs":"pn:text-sm"),children:x("imageEdit.selectRegion")}),n("div",{className:E?"pn:grid pn:grid-cols-2 pn:gap-2":"pn:contents",children:[n(d,{type:z?"button":"submit",className:h("pn:h-11 pn:w-full",E&&"pn:order-2"),disabled:!z&&!I,onClick:z?e=>{var n;e.preventDefault(),null===(n=k.pendingEdit)||void 0===n||n.cancel()}:void 0,children:[_?e(g,{"aria-hidden":"true"}):z?null:e(f,{name:"crop"===b.name||K?"action.confirm":"imageEdit.ai",className:"pn:size-4"}),_?e("span",{role:"status",children:x("imageEdit.loadingImage")}):(()=>{if("crop"!==b.name&&b.pending){return x("toolbar.cropCancel")}switch(b.name){case"crop":return x("toolbar.cropDone");case"expand":return x(K?"imageEdit.applyCrop":"imageEdit.generate");case"inpaint":return x("remove"===D?"imageEdit.remove":"imageEdit.generate");default:return p(b.name)}})()]}),k._imageEditError&&e("p",{role:"alert",className:h("pn:m-0 pn:rounded-md pn:border pn:border-destructive/30 pn:bg-destructive/5 pn:p-3 pn:text-sm pn:text-destructive",E&&"pn:order-3 pn:col-span-2"),children:k._imageEditError}),e("div",{className:h("pn:flex pn:gap-2",E&&"pn:order-1 pn:[&_button]:h-11"),children:"crop"===b.name?e(d,{type:"button",variant:"outline",className:"pn:flex-1",onClick:()=>b.cancel(),children:x("toolbar.cropCancel")}):"inpaint"===b.name?e(d,{type:"button",variant:"outline",className:"pn:flex-1",disabled:b.pending||!b.region,onClick:()=>b.setRegion(null),children:x("imageEdit.clear")}):"expand"===b.name?e(d,{type:"button",variant:"outline",className:"pn:flex-1",disabled:b.pending||l(b.frame,s),onClick:()=>b.setFrame(s),children:x("imageEdit.resetFrame")}):null})]})]})]})});export const ImageEditPanel=r(({store:n})=>{const a=n.activeTool;return a?e(b,{store:n,session:a},`${a.elementId}:${a.name}`):null});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e,jsxs as r}from"react/jsx-runtime";import{
|
|
1
|
+
import{jsx as e,jsxs as r}from"react/jsx-runtime";import{useState as t}from"react";import{ImagesGrid as o}from"./images-grid.js";import{unsplashCredit as s}from"./unsplash-credit.js";import{useInfiniteAPI as l}from"../utils/use-api.js";import{t as a}from"../utils/l10n.js";import{unsplashList as i,unsplashDownload as n}from"../utils/api.js";import{selectImage as p}from"./select-image.js";import{isImageLoadError as m}from"../utils/errors.js";import{SearchInput as d}from"../primitives/search-input.js";export const PhotosPanel=({store:u})=>{const[c,f]=t(null),{setQuery:h,loadMore:g,isReachingEnd:j,data:x,isLoading:P,error:y}=l({defaultQuery:"",getAPI:({page:e,query:r})=>i({page:e,query:r})});return r("div",{className:"pn:flex pn:h-full pn:flex-col",children:[e(d,{style:{marginBottom:"20px"},placeholder:a("sidePanel.searchPlaceholder"),onChange:e=>{h(e.target.value)}}),r("p",{className:"pn:text-center pn:text-sm pn:text-muted-foreground",children:["Photos by"," ",e("a",{href:"https://unsplash.com/",target:"_blank",className:"pn:font-medium pn:text-foreground pn:underline pn:underline-offset-2",children:"Unsplash"})]}),e(o,{images:null==x?void 0:x.map(e=>e.results).flat().filter(Boolean),getPreview:e=>e.urls.small,getAlt:e=>e.alt_description||"",onSelect:(e,r,t)=>{f(null),fetch(n(e.id)).catch(()=>{}),p({src:e.urls.regular,store:u,droppedPos:r,targetElement:t}).catch(e=>{if(!m(e)){throw e}console.warn("polotno: failed to add the photo",e),f(e)})},isLoading:P,error:y||c,loadMore:!j&&g,getCredit:s})]})};
|
|
@@ -199,12 +199,22 @@ export declare const selectVideo: ({ src, droppedPos, targetElement, store, attr
|
|
|
199
199
|
setAnimation(type: any, attrs: any): void;
|
|
200
200
|
setFilter(type: any, value: any): void;
|
|
201
201
|
} & {
|
|
202
|
+
_setSourceSize(size: import("../image-tools/types.js").Size, src: string): void;
|
|
202
203
|
toggleCropMode(flag?: boolean): void;
|
|
203
204
|
cancelCropMode(): void;
|
|
204
|
-
beforeDestroy(): void;
|
|
205
205
|
} & {
|
|
206
206
|
readonly _cropModeEnabled: boolean;
|
|
207
207
|
readonly _cropEnabled: boolean;
|
|
208
|
+
readonly _sourceSize: import("../image-tools/types.js").Size | null;
|
|
209
|
+
} & {
|
|
210
|
+
_setPendingEdit(value: import("../image-tools/host.js").PendingOperation | null): void;
|
|
211
|
+
_setImageEditError(message: string | null): void;
|
|
212
|
+
beforeDestroy: () => void;
|
|
213
|
+
beforeDetach: () => void;
|
|
214
|
+
} & {
|
|
215
|
+
readonly pendingEdit: import("../image-tools/host.js").PendingEdit | null;
|
|
216
|
+
readonly _pendingEdit: import("../image-tools/host.js").PendingOperation | null;
|
|
217
|
+
readonly _imageEditError: string | null;
|
|
208
218
|
} & import("mobx-state-tree").IStateTreeNode<import("mobx-state-tree").IModelType<{
|
|
209
219
|
id: import("mobx-state-tree").ISimpleType<string>;
|
|
210
220
|
type: import("mobx-state-tree").IType<string | undefined, string, string>;
|
|
@@ -395,12 +405,22 @@ export declare const selectVideo: ({ src, droppedPos, targetElement, store, attr
|
|
|
395
405
|
setAnimation(type: any, attrs: any): void;
|
|
396
406
|
setFilter(type: any, value: any): void;
|
|
397
407
|
} & {
|
|
408
|
+
_setSourceSize(size: import("../image-tools/types.js").Size, src: string): void;
|
|
398
409
|
toggleCropMode(flag?: boolean): void;
|
|
399
410
|
cancelCropMode(): void;
|
|
400
|
-
beforeDestroy(): void;
|
|
401
411
|
} & {
|
|
402
412
|
readonly _cropModeEnabled: boolean;
|
|
403
413
|
readonly _cropEnabled: boolean;
|
|
414
|
+
readonly _sourceSize: import("../image-tools/types.js").Size | null;
|
|
415
|
+
} & {
|
|
416
|
+
_setPendingEdit(value: import("../image-tools/host.js").PendingOperation | null): void;
|
|
417
|
+
_setImageEditError(message: string | null): void;
|
|
418
|
+
beforeDestroy: () => void;
|
|
419
|
+
beforeDetach: () => void;
|
|
420
|
+
} & {
|
|
421
|
+
readonly pendingEdit: import("../image-tools/host.js").PendingEdit | null;
|
|
422
|
+
readonly _pendingEdit: import("../image-tools/host.js").PendingOperation | null;
|
|
423
|
+
readonly _imageEditError: string | null;
|
|
404
424
|
}, import("mobx-state-tree").ModelCreationType<{
|
|
405
425
|
id: string;
|
|
406
426
|
type: string | undefined;
|
|
@@ -14,6 +14,7 @@ export declare const LayersSection: Section;
|
|
|
14
14
|
export declare const SizeSection: Section;
|
|
15
15
|
export declare const DrawSection: Section;
|
|
16
16
|
export declare const VideosSection: Section;
|
|
17
|
+
export declare const ImageEditSection: Section;
|
|
17
18
|
export declare const DEFAULT_SECTIONS: Section[];
|
|
18
19
|
export declare const INTERNAL_SECTIONS: Section[];
|
|
19
20
|
export interface SidePanelProps {
|
package/side-panel/side-panel.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e,jsxs as n}from"react/jsx-runtime";import*as o from"react";import{observer as a}from"mobx-react-lite";import{flags as t}from"../utils/flags.js";import{useMobile as i}from"../utils/screen.js";import{t as l}from"../utils/l10n.js";import{cn as s}from"../lib/utils.js";import{PolotnoScope as r}from"../primitives/portal-scope.js";import{SectionTab as p}from"./tab-button.js";import{TemplatesPanel as
|
|
1
|
+
import{jsx as e,jsxs as n}from"react/jsx-runtime";import*as o from"react";import{observer as a}from"mobx-react-lite";import{flags as t}from"../utils/flags.js";import{useMobile as i}from"../utils/screen.js";import{t as l}from"../utils/l10n.js";import{cn as s}from"../lib/utils.js";import{PolotnoScope as r}from"../primitives/portal-scope.js";import{SectionTab as p}from"./tab-button.js";import{TemplatesPanel as d}from"./templates-panel.js";import{TextPanel as m}from"./text-panel.js";import{PhotosPanel as c}from"./photos-panel.js";import{ElementsPanel as b}from"./elements-panel.js";import{UploadPanel as f}from"./upload-panel.js";import{BackgroundPanel as u}from"./background-panel.js";import{PagesPanel as P}from"./pages-panel.js";import{LayersPanel as x}from"./layers-panel.js";import{SizePanel as S}from"./size-panel.js";import{DrawPanel as h}from"./draw-panel.js";import{VideosPanel as g}from"./videos-panel.js";import{ImageClipPanel as v}from"./image-clip-panel.js";import{ImageEditPanel as j}from"./image-edit-panel.js";import{AnimationsPanel as w}from"./animations-panel.js";import{EffectsPanel as T}from"./effects-panel.js";import{PolotnoIcon as k}from"../icons/registry.js";export{SectionTab}from"./tab-button.js";export{ImagesGrid}from"./images-grid.js";export const TemplatesSection={name:"templates",Tab:a(n=>e(p,Object.assign({name:l("sidePanel.templates")},n,{children:e(k,{name:"sidePanel.templates"})}))),Panel:({store:n})=>e(d,{store:n})};export const TextSection={name:"text",Tab:a(n=>e(p,Object.assign({name:l("sidePanel.text")},n,{children:e(k,{name:"sidePanel.text"})}))),Panel:({store:n})=>e(m,{store:n})};export const PhotosSection={name:"photos",Tab:a(n=>e(p,Object.assign({name:l("sidePanel.photos")},n,{children:e(k,{name:"sidePanel.photos"})}))),Panel:({store:n})=>e(c,{store:n})};export const ElementsSection={name:"elements",Tab:a(n=>e(p,Object.assign({name:l("sidePanel.elements"),iconSize:16},n,{children:e(k,{name:"sidePanel.elements"})}))),Panel:({store:n})=>e(b,{store:n})};export const UploadSection={name:"upload",Tab:a(n=>e(p,Object.assign({name:l("sidePanel.upload")},n,{children:e(k,{name:"sidePanel.upload"})}))),Panel:({store:n})=>e(f,{store:n})};export const BackgroundSection={name:"background",Tab:a(n=>e(p,Object.assign({name:l("sidePanel.background")},n,{children:e(k,{name:"sidePanel.background"})}))),Panel:({store:n})=>e(u,{store:n})};export const PagesSection={name:"pages",Tab:a(n=>e(p,Object.assign({name:l("sidePanel.pages")},n,{children:e(k,{name:"sidePanel.pages"})}))),Panel:({store:n})=>e(P,{store:n}),visibleInList:!1};export const LayersSection={name:"layers",Tab:a(n=>e(p,Object.assign({name:l("sidePanel.layers")},n,{children:e(k,{name:"sidePanel.layers"})}))),Panel:({store:n})=>e(x,{store:n})};export const SizeSection={name:"size",Tab:a(n=>e(p,Object.assign({name:l("sidePanel.resize")},n,{children:e(k,{name:"sidePanel.resize"})}))),Panel:({store:n})=>e(S,{store:n})};export const DrawSection={name:"draw",Tab:a(n=>e(p,Object.assign({name:l("sidePanel.draw")},n,{children:e(k,{name:"sidePanel.draw"})}))),Panel:({store:n})=>e(h,{store:n})};export const VideosSection={name:"videos",Tab:n=>e(p,Object.assign({name:l("sidePanel.videos")},n,{children:e(k,{name:"sidePanel.videos"})})),Panel:g};export const ImageEditSection={name:"image-edit",Tab:()=>null,Panel:j,visibleInList:!1};export const DEFAULT_SECTIONS=[TemplatesSection,TextSection,PhotosSection,ElementsSection,DrawSection,UploadSection,BackgroundSection,LayersSection,SizeSection,ImageEditSection];const C={name:"image-clip",Tab:()=>null,Panel:v},E={name:"effects",Tab:()=>null,Panel:T},N={name:"animation",Tab:()=>null,Panel:w};export const INTERNAL_SECTIONS=[C,E];const I=new Set([v,T,w]),O=({onClick:o})=>n("div",{className:"pn-side-panel-hide-button pn:absolute pn:right-[-14px] pn:top-1/2 pn:z-10 pn:h-24 pn:w-[15px] pn:cursor-pointer pn:max-md:hidden pn:pn-mobile:hidden",onClick:o,children:[e("svg",{width:"15",height:"96",viewBox:"0 0 16 96",xmlns:"http://www.w3.org/2000/svg",children:e("path",{className:"pn:stroke-border pn:fill-background",d:"M 1 7 C 2 9 4 10 7.2 13.28 C 7.45 13.4625 7.6 13.6 7.7 13.8048 L 7.8 13.8 C 9.8 15.8 11.6 17.6 12.9 19.7 C 14 21.6 14.7 23.9 14.9 27 H 15 V 68 C 15 71.7 14.3 74.3 13 76.6 C 11.7 78.8 9.9 80.5 7.8 82.6344 L 7.79 82.6 C 7.6 82.8 7.4507 83 7.2729 83.2127 C 3.9102 86.5228 2 87 1 90"})}),e("div",{className:"pn:absolute pn:left-1/2 pn:top-1/2 pn:text-[0.5rem] pn:text-muted-foreground pn:hover:text-foreground",style:{transform:"translate(-50%, -50%) scaleY(2)"},children:"<"})]});export const SidePanel=a(({store:a,sections:l,defaultSection:p="photos"})=>{var d,m;(()=>{const e=o.useRef(!0);e.current&&(e.current=!1,a.openSidePanel(p))})();const c=i();o.useLayoutEffect(()=>{c?a.openSidePanel(""):a.openSidePanel(p)},[c]);const b=[...l||DEFAULT_SECTIONS],f=b.find(e=>"image-edit"===e.name),u=!!f;o.useLayoutEffect(()=>(a._setImageEditPanelAvailable(u),()=>a._setImageEditPanelAvailable(!1)),[a,u]);const P=o.useRef(p),x=(null==f?void 0:f.Panel)===j,S="expand"===(null===(d=a.activeTool)||void 0===d?void 0:d.name)||"inpaint"===(null===(m=a.activeTool)||void 0===m?void 0:m.name),h=c&&x&&S&&"image-edit"===a.openedSidePanel;if(o.useLayoutEffect(()=>{"image-edit"!==a.openedSidePanel?P.current=a.openedSidePanel:x&&!a.activeTool&&a.openSidePanel("image-edit"===P.current?"":P.current)},[a,a.openedSidePanel,a.activeTool,x]),INTERNAL_SECTIONS.forEach(e=>{b.find(n=>n.name===e.name)||b.push(e)}),t.animationsEnabled){if(!b.find(e=>"videos"===e.name)){const e=Math.floor(b.length/2);b.splice(e,0,VideosSection)}if(!b.find(e=>"animations"===e.name)){const e=Math.floor(b.length/2);b.splice(e,0,N)}}const g=b.filter(e=>{var n;return null===(n=e.visibleInList)||void 0===n||n}),v=e=>{const n=e.target,o=n.closest(".polotno-close-panel"),t=n.closest(".polotno-mobile");o&&(c||t)&&a.openSidePanel("")},w=o.useRef(null),T=o.useRef(null),k=o.useRef(new Set);return a.openedSidePanel&&k.current.add(a.openedSidePanel),e(r,{elementRef:T,children:n("div",{ref:T,className:s("polotno-side-panel pn-side-panel pn:relative pn:flex pn:h-full pn:bg-background pn:p-0 pn:text-foreground","pn:md:border-r pn:md:border-border","pn:max-md:h-auto pn:max-md:w-full pn:pn-mobile:h-auto pn:pn-mobile:w-full","pn:max-md:border-t pn:max-md:border-border pn:pn-mobile:border-t pn:pn-mobile:border-border",h&&"pn:flex-col-reverse",!a.openedSidePanel&&"collapsed"),children:[e("div",{ref:w,className:s("polotno-side-tabs-container pn:bg-background pn:max-md:w-full pn:max-md:overflow-auto pn:pn-mobile:w-full pn:pn-mobile:overflow-auto pn:md:overflow-y-auto pn:md:overflow-x-hidden pn:md:min-w-[72px]",a.openedSidePanel&&"pn:md:border-r pn:md:border-border"),children:e("div",{className:"polotno-side-tabs-inner pn:flex pn:flex-col pn:max-md:flex-row pn:max-md:min-w-min pn:pn-mobile:flex-row pn:pn-mobile:min-w-min",children:g.map(({name:n,Tab:o})=>e(o,{active:n===a.openedSidePanel,onClick:()=>{n===a.openedSidePanel&&c?a.openSidePanel(""):a.openSidePanel(n)}},n))})}),b.map(({name:n,Panel:o})=>k.current.has(n)&&e("div",{className:s("polotno-panel-container pn-side-panel-content pn:h-full pn:px-2",!I.has(o)&&"pn:pt-2.5","pn:w-[var(--pn-sidebar-width,350px)]",!a.openedSidePanel&&"pn:w-0",n!==a.openedSidePanel&&"pn:hidden","pn:max-md:w-full pn:max-md:bg-background pn:pn-mobile:w-full pn:pn-mobile:bg-background",h&&"image-edit"===n?"pn:flex pn:h-auto pn:max-h-[40dvh] pn:shrink-0 pn:flex-col pn:border-b pn:border-border":"pn:max-md:absolute pn:max-md:bottom-[54px] pn:max-md:z-[100] pn:max-md:!h-[50vh] pn:pn-mobile:absolute pn:pn-mobile:bottom-[54px] pn:pn-mobile:z-[100] pn:pn-mobile:!h-[50vh]"),onClick:v,children:e(o,{store:a})},n)),a.openedSidePanel&&c&&!S&&e("div",{className:"polotno-close-panel",style:{position:"absolute",left:0,bottom:"72px",width:"100vw",height:"100vh",zIndex:99,backgroundColor:"rgba(0,0,0,0.05)"},onClick:()=>a.openSidePanel("")}),a.openedSidePanel&&e(O,{onClick:()=>a.openSidePanel("")})]})})});SidePanel.displayName="SidePanel";export default SidePanel;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e,jsxs as t}from"react/jsx-runtime";import*as i from"react";import{PolotnoIcon as n}from"../icons/registry.js";import{getVideoPreview as
|
|
1
|
+
import{jsx as e,jsxs as t}from"react/jsx-runtime";import*as i from"react";import{PolotnoIcon as n}from"../icons/registry.js";import{getVideoPreview as o}from"../utils/video.js";import{getMediaType as r,getUploadFunc as l,MEDIA_ACCEPT as s}from"../utils/file.js";import{insertMediaIntoPage as a}from"../utils/insert-file.js";import{isImageLoadError as p}from"../utils/errors.js";import{ImagesGrid as c}from"./images-grid.js";import{t as d}from"../utils/l10n.js";import{cn as u}from"../lib/utils.js";import{Button as m}from"../primitives/button.js";export{setUploadFunc}from"../utils/file.js";let f=[],g=0;function h(){const e=new Blob(['\n <svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100">\n <circle cx="50" cy="50" r="45" fill="#f0f0f0" stroke="#ccc" stroke-width="2"/>\n <path d="M40,35 L40,65 L55,50 L70,50 M70,35 Q80,50 70,65" fill="none" stroke="#666" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/>\n </svg>\n '],{type:"image/svg+xml"});return URL.createObjectURL(e)}async function v(e,t){if("audio"===t){return h()}const i=URL.createObjectURL(e);if("video"!==t){return i}try{return await o(i)}finally{URL.revokeObjectURL(i)}}const y=e=>{e.startsWith("blob:")&&URL.revokeObjectURL(e)};export const UploadPanel=({store:w})=>{const[x,j]=i.useState(f),[L,b]=i.useState([]),[U,k]=i.useState(null),R=i.useRef(null);i.useEffect(()=>{f=x},[x]);const P=[...L,...x];return t("div",{className:"pn:flex pn:h-full pn:flex-col",children:[e("div",{style:{height:"45px",paddingTop:"5px"},children:d("sidePanel.uploadTip")}),e("div",{style:{marginBottom:"20px"},children:t("label",{htmlFor:"input-file",children:[t(m,{variant:"outline",style:{width:"100%"},onClick:()=>{var e;null===(e=R.current)||void 0===e||e.click()},children:[e(n,{name:"action.add"}),d("sidePanel.uploadImage")]}),e("input",{type:"file",ref:R,style:{display:"none"},accept:s,onChange:async e=>{var t;const{target:i}=e,n=Array.from(null!==(t=i.files)&&void 0!==t?t:[]);i.value="",k(null);const s=[];for(const o of n){const e=r(o);e&&s.push({file:o,type:e})}s.length<n.length&&k(d("sidePanel.uploadUnsupported"));const a=await Promise.all(s.map(async({file:e,type:t})=>({id:g++,preview:await v(e,t),pending:!0})));b(e=>[...a,...e]);for(const[r,{file:p,type:c}]of s.entries()){const t=a[r];try{const e=await l()(p);let t=e;"video"===c?t=await o(e):"audio"===c&&(t=h()),j(i=>[{url:e,type:c,preview:t,name:p.name},...i])}catch(e){console.error(e),k(d("sidePanel.uploadFailed"))}finally{b(e=>e.filter(e=>e.id!==t.id)),y(t.preview)}}},multiple:!0})]})}),U&&e("div",{role:"alert",className:"pn:pb-[10px] pn:text-center pn:text-xs pn:text-muted-foreground",children:U}),e(c,{images:P,isLoading:!1,getPreview:e=>e.preview,getImageClassName:e=>"pending"in e?u("pn:animate-pulse pn:opacity-50"):"",hideNoResults:!0,onSelect:(e,t,i)=>{"pending"in e||(k(null),a({url:e.url,type:e.type,store:w,droppedPos:t,targetElement:i,name:e.name}).catch(e=>{if(!p(e)){throw e}console.warn("polotno: failed to add the uploaded file",e),k(d("sidePanel.error"))}))}})]})};
|
package/toolbar/color-picker.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=this&&this.__rest||function(e,
|
|
1
|
+
var e=this&&this.__rest||function(e,o){var r={};for(var t in e){Object.prototype.hasOwnProperty.call(e,t)&&o.indexOf(t)<0&&(r[t]=e[t])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(t=Object.getOwnPropertySymbols(e);n<t.length;n++){o.indexOf(t[n])<0&&Object.prototype.propertyIsEnumerable.call(e,t[n])&&(r[t[n]]=e[t[n]])}}return r};import{jsx as o,jsxs as r}from"react/jsx-runtime";import t from"react";import{observer as n}from"mobx-react-lite";import{t as l}from"../utils/l10n.js";import{isGradient as s,parseColor as a}from"@polotno/core/gradient";import{sameColors as i}from"@polotno/core/svg";import{formatCmykColor as c,isCmykColor as p,toDisplayColor as d}from"@polotno/core/color";import u,{cmykFromColor as m}from"./sketch.js";import{addStop as h,insertStop as f,readGradient as g,writeGradient as v}from"../utils/gradient-stops.js";import{canRemoveStop as b,reverseStops as C}from"../utils/stops.js";import{StopTrack as x}from"./stop-track.js";import{PolotnoIcon as y}from"../icons/registry.js";import{cn as k,firstSliderValue as w}from"../lib/utils.js";import{NumericInput as E}from"../primitives/numeric-input.js";import{Slider as N}from"../primitives/slider.js";import{TooltipIconButton as j}from"../primitives/tooltip-icon-button.js";import{Popover as O,PopoverContent as P,PopoverTrigger as F}from"../primitives/popover.js";import{Tabs as S,TabsContent as $,TabsList as B,TabsTrigger as R}from"../primitives/tabs.js";export const DEFAULT_COLORS=["#D0021B","#F5A623","#F8E71C","#8B572A","#7ED321","#417505","#BD10E0","#9013FE","#4A90E2","#50E3C2","#B8E986","#000000","#4A4A4A","#9B9B9B","#FFFFFF"].reverse();export const getUsedColors=e=>{const o=[];e.pages.forEach(e=>{e.children.forEach(e=>{e.shadowEnabled&&o.push(e.shadowColor),"text"===e.type&&(o.push(e.fill),e.backgroundEnabled&&o.push(e.backgroundColor),e.strokeWidth&&o.push(e.stroke)),"svg"===e.type&&o.push(...e.colorsReplace.values()),"figure"===e.type&&(o.push(e.fill),e.strokeWidth&&o.push(e.stroke)),"line"===e.type&&o.push(e.color)})});const r=[];return o.forEach(e=>{if(s(e)){const{stops:o}=g(e);r.push(...o.map(e=>e.color))}else{r.push(e)}}),[...new Set(r)]};const z=r=>{var{style:n,color:l,onChange:s}=r,a=e(r,["style","color","onChange"]);const[i,p]=t.useState(l);t.useEffect(()=>{p(l)},[l]);const d=t.useRef(void 0),m=t.useRef(void 0);return o("div",{className:"pn-color-picker-solid",style:n,onMouseDown:e=>{"INPUT"!==e.target.tagName&&e.preventDefault()},children:o(u,Object.assign({color:i},a,{onChange:e=>{const{r:o,g:r,b:t,a:n}=e.rgb,l=e.cmyk?c(e.cmyk):`rgba(${o},${r},${t},${n})`;p(l),m.current=l,d.current||(d.current=window.setTimeout(()=>{d.current=0,s(m.current||l)},50))}}))})},D=({value:e,onChange:n,store:s,preset:i})=>{var u,k;const{rotation:O,stops:P}=g(e),F=t.useId(),[S,$]=t.useState(0),B=Math.min(S,P.length-1),R=t.useRef(null),D=t.useRef(null),A=(e,o=O)=>n(v({rotation:o,stops:e})),I=e=>{$(e.index),A(e.stops)},M=v({rotation:90,stops:P});return t.useLayoutEffect(()=>{const e=D.current,o=e.getContext("2d"),r=o.createLinearGradient(0,0,e.width,0);a(M).stops.forEach(({offset:e,color:o})=>r.addColorStop(e,o)),o.clearRect(0,0,e.width,1),o.fillStyle=r,o.fillRect(0,0,e.width,1)},[M]),r("div",{className:"pn:flex pn:flex-col pn:gap-1 pn:pt-2",children:[o("div",{className:"pn:mx-2.5",children:o(x,{handle:R,store:s,node:null!==(k=null!==(u=s.selectedElements[0])&&void 0!==u?u:s.activePage)&&void 0!==k?k:void 0,label:l("toolbar.colorPicker.stops"),stops:P,selected:B,onSelect:$,onChange:I,insert:f,stopLabel:(e,o)=>`${l("toolbar.colorPicker.stop")} ${o+1}: ${Math.round(100*e.offset)}%`,swatch:e=>{const o=d(e.color);return`linear-gradient(${o}, ${o}), ${L}`},bar:o("canvas",{ref:D,width:512,height:1,"aria-hidden":!0,className:"pn:block pn:size-full",style:{backgroundImage:L}})})}),r("div",{className:"pn:flex pn:items-center pn:gap-1 pn:px-2.5",children:[o(j,{label:l("toolbar.colorPicker.addStop"),onClick:()=>I(h(P)),children:o(y,{name:"action.add",className:"pn:size-4"})}),o(j,{label:l("toolbar.colorPicker.removeStop"),disabled:!b(P),onClick:()=>{var e;return null===(e=R.current)||void 0===e?void 0:e.remove(B)},children:o(y,{name:"action.remove",className:"pn:size-4"})}),o(j,{label:l("toolbar.colorPicker.reverse"),onClick:()=>I({stops:C(P),index:P.length-1-B}),children:o(y,{name:"colorPicker.reverseGradient",className:"pn:size-4"})}),o("label",{id:`${F}-label`,className:"pn:ml-auto pn:text-sm",htmlFor:F,children:l("toolbar.colorPicker.angle")}),r("div",{className:"pn:relative",children:[o(E,{id:F,value:O,min:0,max:360,onValueChange:e=>A(P,e),style:{width:64},className:"pn:pl-1 pn:pr-8"}),o("span",{"aria-hidden":!0,className:"pn:pointer-events-none pn:absolute pn:right-6 pn:top-1/2 pn:-translate-y-1/2 pn:text-sm pn:text-muted-foreground",children:"°"})]})]}),o("div",{className:"pn:px-2.5 pn:py-1",children:o(N,{"aria-labelledby":`${F}-label`,value:[O],min:0,max:360,onValueChange:e=>A(P,Math.round(w(e)))})}),o(z,{color:P[B].color,presetColors:i,onChange:e=>A(P.map((o,r)=>{return{offset:o.offset,color:r===B?e:(t=e,n=o.color,p(t)?p(n)?n:c(m(n)):p(n)?d(n):n)};var t,n}))})]})},A=n(({value:e,onChange:n,preset:a,store:i})=>{const[c,p]=t.useState(s(e)?"gradient":"solid");return o("div",{style:{padding:"5px"},children:r(S,{value:c,onValueChange:e=>p(e),className:"pn:w-full",children:[r(B,{className:"pn:flex pn:w-full pn:flex-row",children:[o(R,{value:"solid",className:"pn:flex-1",children:l("toolbar.colorPicker.solid")}),o(R,{value:"gradient",className:"pn:flex-1",children:l("toolbar.colorPicker.linear")})]}),o($,{value:"solid",className:"pn:w-full",children:o(z,{color:s(e)?g(e).stops[0].color:e,onChange:n,presetColors:a,style:{padding:"0"}})}),o($,{value:"gradient",className:"ember-panel pn:w-full",children:o(D,{value:e,onChange:n,store:i,preset:a})})]})})}),L="url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 8 8'%3E%3Cg fill='rgba(112, 112, 116, 1)' fill-opacity='1'%3E%3Cpath fill-rule='evenodd' d='M0 0h4v4H0V0zm4 4h4v4H4V4z'/%3E%3C/g%3E%3C/svg%3E\")";export const ColoredBox=t.forwardRef(function(r,t){var{size:n=30,background:l,style:s={},className:a,children:i=null}=r,c=e(r,["size","background","style","className","children"]);const p="string"==typeof l?d(l):"transparent",u=p.includes("gradient")?p:`linear-gradient(${p}, ${p}), ${L}`;return o("div",Object.assign({ref:t,role:"button",tabIndex:0,"aria-label":"Pick color",onMouseDown:e=>e.preventDefault(),className:k("pn:flex pn:cursor-pointer pn:items-center pn:justify-center pn:overflow-hidden pn:rounded-md pn:border pn:border-foreground/30",a),style:Object.assign({width:n+"px",height:n+"px",backgroundImage:u},s)},c,{children:i}))});let I=e=>{const o=getUsedColors(e).slice(0,8).filter(e=>!DEFAULT_COLORS.find(o=>i(o,e)));return o.concat(DEFAULT_COLORS.slice(0,16-o.length).reverse())};export function setColorsPresetFunc(e){I=e}export const ColorPicker=({value:e,onChange:n,size:l,store:s,gradientEnabled:a,children:i,style:c,onOpen:p,onClose:d})=>{const u=I(s),[m,h]=t.useState(!1);return r(O,{open:m,onOpenChange:e=>{h(e),e?null==p||p():null==d||d()},children:[o(F,{nativeButton:!1,render:o(ColoredBox,{size:l,background:e,style:c,children:i})}),o(P,{className:"pn:w-[280px] pn:p-0",initialFocus:!1,children:a?o(A,{preset:u,value:e,onChange:n,store:s}):o("div",{style:{padding:"5px"},children:o(z,{color:e,onChange:n,presetColors:u})})})]})};export default ColorPicker;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e}from"react/jsx-runtime";import*as t from"react";import{OverflowList as r}from"../primitives/overflow-list.js";export const extendToolbar=({type:e,usedItems:t,components:r})=>{const n=[];return Object.keys(r||{}).forEach(o=>{0===o.toLowerCase().indexOf(e)&&o.toLowerCase()!==e&&(r[o]?t.includes(o)||n.push(o):console.error(`Polotno error: Toolbar has invalid React component "${o}"`))}),t.filter(e=>Boolean(e)).concat(n)};export const ElementContainer=({items:n,itemRender:o})=>{const[s,i]=t.useState(0),a=t.useRef(null),c=()=>{if(null===a.current){return}const e=a.current.parentElement;let t=0;e&&(Array.from(e.children).forEach(e=>{e!==a.current&&(t+=e.offsetWidth)}),i(Math.max(44,e.offsetWidth-t-10)))};return t.useLayoutEffect(()=>{c()}),t.useLayoutEffect(()=>{const e=a.current.parentElement,t=null==e?void 0:e.parentElement;if(window.ResizeObserver){const r=new ResizeObserver(c);e&&r.observe(e),t&&r.observe(t);const n=new MutationObserver(c);return e&&n.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["style","class"]}),()=>{r.disconnect(),n.disconnect()}}{const e=setInterval(c,100);return()=>clearInterval(e)}},[]),e("div",{style:{width:s+"px"},ref:a,className:"pn-element-container pn:flex pn:items-center pn:max-md:!w-auto pn:pn-mobile:!w-auto",children:e(r,{items:n,itemRender:o,gap:6})})};
|
|
1
|
+
import{jsx as e}from"react/jsx-runtime";import*as t from"react";import{OverflowList as r}from"../primitives/overflow-list.js";export const extendToolbar=({type:e,usedItems:t,components:r})=>{const n=[];return Object.keys(r||{}).forEach(o=>{"ImageToolActions"!==o&&0===o.toLowerCase().indexOf(e)&&o.toLowerCase()!==e&&(r[o]?t.includes(o)||n.push(o):console.error(`Polotno error: Toolbar has invalid React component "${o}"`))}),t.filter(e=>Boolean(e)).concat(n)};export const ElementContainer=({items:n,itemRender:o})=>{const[s,i]=t.useState(0),a=t.useRef(null),c=()=>{if(null===a.current){return}const e=a.current.parentElement;let t=0;e&&(Array.from(e.children).forEach(e=>{e!==a.current&&(t+=e.offsetWidth)}),i(Math.max(44,e.offsetWidth-t-10)))};return t.useLayoutEffect(()=>{c()}),t.useLayoutEffect(()=>{const e=a.current.parentElement,t=null==e?void 0:e.parentElement;if(window.ResizeObserver){const r=new ResizeObserver(c);e&&r.observe(e),t&&r.observe(t);const n=new MutationObserver(c);return e&&n.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["style","class"]}),()=>{r.disconnect(),n.disconnect()}}{const e=setInterval(c,100);return()=>clearInterval(e)}},[]),e("div",{style:{width:s+"px"},ref:a,className:"pn-element-container pn:flex pn:items-center pn:max-md:!w-auto pn:pn-mobile:!w-auto",children:e(r,{items:n,itemRender:o,gap:6})})};
|
package/toolbar/html-toolbar.js
CHANGED
|
@@ -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 d,extendToolbar as f}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{FontMenu as F,fetcher as S,TextSpacing as z,TextFontSize as j,
|
|
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 d,extendToolbar as f}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{FontMenu as F,fetcher as S,TextSpacing as z,TextFontSize as j,ALIGN_OPTIONS as C,VERTICAL_ALIGN_OPTIONS as N,VERTICAL_ALIGN_ICONS as w}from"./text-toolbar.js";import{cycleNext as A}from"./toolbar-shared.js";import k from"swr";import{getFontsList as E,globalFonts as D,isGoogleFontChanged as L}from"../utils/fonts.js";import{getGoogleFontsListAPI as I}from"../utils/api.js";import{quillHtmlToModelText as M,listEffectiveFontFamilies as R,isBoldWeight as O}from"../utils/rich-text-html.js";import{patchTextFormat as W,decorationTokensToString as B,isDecorationActive as H}from"../utils/text-format.js";import{useTextFormat as P,getActiveTextEditor as V,resolveSelectionScope as _,applyToLiveEditor as G,restoreEditorSelection as J}from"../utils/text-format-state.js";const Q=u("div")`
|
|
2
2
|
position: relative;
|
|
3
3
|
display: inline-block;
|
|
4
4
|
|
|
@@ -15,7 +15,7 @@ import{jsx as t,jsxs as e}from"react/jsx-runtime";import o from"react";import{ob
|
|
|
15
15
|
&:focus-within .polotno-fs-mixed-overlay {
|
|
16
16
|
display: none;
|
|
17
17
|
}
|
|
18
|
-
`,
|
|
18
|
+
`,U=u("span")`
|
|
19
19
|
position: absolute;
|
|
20
20
|
left: 11px;
|
|
21
21
|
top: 0;
|
|
@@ -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
|
-
|
|
28
|
+
`,X=t=>{const e=V();return!!e&&e.store===t&&!!e.instance};let $=null;const q=()=>{b.pendingToolbarInteraction=!0,$&&clearTimeout($),$=setTimeout(()=>{b.pendingToolbarInteraction=!1,$=null},100)},K=t=>{var e;(!(e=t.target)||"INPUT"!==e.tagName&&"TEXTAREA"!==e.tagName&&"SELECT"!==e.tagName&&!e.isContentEditable)&&t.preventDefault(),q()},Y=n(({store:e,isActive:o,toggle:n,icon:i,ariaLabel:l,tooltipContent:r})=>{const{format:a,applyTextFormat:s}=P(e);return t(c,{label:r||l||"",active:o(a),onMouseDown:t=>{t.preventDefault()},onClick:()=>n(a,s),children:i})});function Z(t,e){const o="underline"===e?"line-through":"underline",n=new Set;return H(t,e)||n.add(e),H(t,o)&&n.add(o),B(n)}const tt=(t,e,o)=>e({textDecoration:Z(t,o)},{decorationTokens:[o]});export const TextBold=n(({store:e})=>t(Y,{store:e,isActive:t=>O(t.fontWeight.value),toggle:(t,e)=>e({fontWeight:O(t.fontWeight.value)?400:700}),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(Y,{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 d=(null==p?void 0:p.TextBold)||TextBold;return e("div",{className:"pn:flex pn:items-center pn:gap-0.5",children:[t(d,{element:o,store:n}),t(Y,{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(Y,{store:n,isActive:t=>H(t,"underline"),toggle:(t,e)=>tt(t,e,"underline"),icon:t(i,{name:"text.underline",className:"pn:size-4"}),tooltipContent:h("toolbar.underline")}),t(Y,{store:n,isActive:t=>H(t,"line-through"),toggle:(t,e)=>tt(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=A(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=A(N,o.verticalAlign);n.history.transaction(()=>{o.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:()=>{var t;let e=window.__polotnoQuill;const n=!e;e=e||(({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:o.text}),n&&e.setSelection(0,e.getLength(),"api");const i=e.getSelection(!0)||(null===(t=V())||void 0===t?void 0:t.lastSelection)||{index:0,length:e.getLength()},l=e.getFormat(i);l.list?"bullet"===l.list?e.format("list","ordered"):e.format("list",!1):e.format("list","bullet"),n&&(o.set({text:M(e.root.innerHTML,{fontSize:o.fontSize,fontFamily:o.fontFamily})}),(t=>{t.root.parentElement.remove()})(e))},children:(()=>{const e=V();return"bullet"===(e&&e.store===n?e.currentFormat:{}).list?t(i,{name:"text.numberedList",className:"pn:size-5"}):t(i,{name:"text.bulletList",className:"pn:size-5"})})()})]})});export const FontColorInput=n(({element:e,store:o})=>{var n;const{format:i,applyTextFormat:l}=P(o);return t("div",{"data-polotno-keep-focus":!0,onMouseDown:K,children:t(m,{value:null!==(n=i.fill.value)&&void 0!==n?n:e.fill,gradientEnabled:!0,onClose:()=>{const t=V();(null==t?void 0:t.instance)&&t.lastSelection&&J(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=E(),nt={TextFontFamily:n(({elements:e,store:n})=>{var i;const{format:l,applyTextFormat:r}=P(n),a=X(n),s=l.fontFamily.mixed,c=s?Array.from(new Set(e.flatMap(t=>R(t.text,t.fontFamily)))).sort((t,e)=>t.localeCompare(e,void 0,{sensitivity:"base"})):void 0,[m,p]=o.useState(!1),{data:d,mutate:f}=k(m?I():null,S,{isPaused:()=>L(),fallbackData:[]});o.useEffect(()=>{f()},[L()]);const u=n.fonts.concat(D).map(t=>t.fontFamily).concat((null==d?void 0:d.length)&&!L()?d:ot),x=[];n.find(t=>("text"===t.type&&x.push(t.fontFamily),!1));const 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:K,children:b}):b}),TextFontSize:n(({elements:o,store:n})=>{const{format:i}=P(n),l=X(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=V();if(o&&o.store===n&&o.instance){const{scope:t,isEmpty:n}=_(o.instance,o.lastSelection);if("partial"===t||"collapsed"===t&&n){return void G(o.instance,{fontSize:e.fontSize},o.lastSelection)}}const{attrsToSet:i}=W(t,{fontSize:e.fontSize});t.set(Object.assign(Object.assign({},e),i))})(t,e):Reflect.get(t,e)})),c=e(Q,{className:r?"polotno-mixed":"",children:[t(j,{elements:s,store:n}),r&&t(U,{className:"polotno-fs-mixed-overlay","aria-hidden":!0,children:"—"})]});return l?t("div",{"data-polotno-keep-focus":!0,onMouseDown:q,children:c}):c}),TextFontVariant:FontStyleGroup,TextTransform:et,TextFilters:p,TextFill:FontColorInput,TextSpacing:z,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=f({type:"text",usedItems:l,components:o});return t(d,{items:r,itemRender:l=>{if("TextBold"===l){return null}const r=(null==o?void 0:o[l])||nt[l];return t(r,{element:i,elements:n,store:e,components:o},l)}})});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
export
|
|
2
|
+
export { setRemoveBackgroundFunc } from '../utils/api.js';
|
|
3
3
|
export declare const RemoveBackgroundDialog: (({ isOpen, onClose, element, }: {
|
|
4
4
|
isOpen: boolean;
|
|
5
5
|
onClose: () => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as r,jsxs as e,Fragment as
|
|
1
|
+
import{jsx as r,jsxs as e,Fragment as n}from"react/jsx-runtime";import*as o from"react";import{observer as t}from"mobx-react-lite";import{Button as i}from"../primitives/button.js";import{Spinner as s}from"../primitives/spinner.js";import{Dialog as l,DialogContent as c,DialogFooter as a,DialogHeader as m,DialogTitle as u}from"../primitives/dialog.js";import{getRemoveBackgroundFunc as d}from"../utils/api.js";export{setRemoveBackgroundFunc}from"../utils/api.js";import{t as p}from"../utils/l10n.js";export const RemoveBackgroundDialog=t(({isOpen:t,onClose:g,element:v})=>{const[h,f]=o.useState(v.src),b=o.useRef(null);o.useEffect(()=>(f(v.src),()=>{var r;null===(r=b.current)||void 0===r||r.abort(),b.current=null}),[v.src]);const[k,x]=o.useState(!1),j=o.useRef(void 0),B=()=>{var r;null===(r=b.current)||void 0===r||r.abort()},y=h!==v.src;return r(l,{open:t,onOpenChange:r=>{r||(B(),g())},children:e(c,{className:"pn:w-[80%] pn:max-w-[700px]",children:[r(m,{children:r(u,{children:p("toolbar.removeBackgroundTitle")})}),r("div",{children:r("img",{crossOrigin:"anonymous",src:h,style:{width:"100%",maxHeight:"400px",objectFit:"contain"}})}),e(a,{className:"pn:relative",children:[!y&&e(n,{children:[k&&r(i,{variant:"outline",onClick:B,children:p("toolbar.cancelRemoveBackground")}),e(i,{onClick:async()=>{const r=new AbortController;b.current=r,x(!0);try{const e=await d()(v.src,r.signal,{src:v.src,signal:r.signal});r.signal.aborted||(j.current="string"==typeof e?void 0:e.apply,f("string"==typeof e?e:e.src))}catch(e){"AbortError"!==(null==e?void 0:e.name)&&console.error(e)}finally{b.current===r&&(b.current=null),x(!1)}},disabled:k,children:[k&&r(s,{className:"pn:mr-2"}),p("toolbar.removeBackground")]})]}),y&&e(n,{children:[e(i,{variant:"outline",onClick:()=>{f(v.src),g()},disabled:k,children:[k&&r(s,{className:"pn:mr-2"}),p("toolbar.cancelRemoveBackground")]}),e(i,{onClick:()=>{const r=()=>v.set({src:h}),e=j.current;e?e({element:v,src:h,selection:null,applyDefault:r}):r(),g()},disabled:k,children:[k&&r(s,{className:"pn:mr-2"}),p("toolbar.confirmRemoveBackground")]})]})]})]})})});export const ImageRemoveBackground=({element:t})=>{const[s,l]=o.useState(!1);return e(n,{children:[r(i,{variant:"ghost",size:"sm",onClick:()=>{l(!0)},children:p("toolbar.removeBackground")}),r(RemoveBackgroundDialog,{isOpen:s,onClose:()=>{l(!1)},element:t})]})};
|
|
@@ -2,6 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import type { StoreType, ImageElementType } from '../ui-types.js';
|
|
3
3
|
import type { SVGElementType } from '../model/svg-model.js';
|
|
4
4
|
export { ImageRemoveBackground } from './image-remove-background-button.js';
|
|
5
|
+
export { ImageEdit, ImageToolActions } from './image-tools.js';
|
|
5
6
|
type Props = {
|
|
6
7
|
store: StoreType;
|
|
7
8
|
components?: any;
|
package/toolbar/image-toolbar.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e,jsxs as o}from"react/jsx-runtime";import{observer as t}from"mobx-react-lite";import{Button as r}from"../primitives/button.js";import{Tooltip as i,TooltipContent as a,TooltipTrigger as n}from"../primitives/tooltip.js";import{ElementContainer as m,extendToolbar as s}from"./element-container.js";import{PolotnoIcon as l}from"../icons/registry.js";import c from"./filters-picker.js";import{AnimationsPicker as p}from"./animations-picker.js";import g from"./flip-button.js";import{flags as d}from"../utils/flags.js";import{ImageRemoveBackground as u}from"./image-remove-background-button.js";export{ImageRemoveBackground}from"./image-remove-background-button.js";import{getCrop as h,getImageSize as
|
|
1
|
+
import{jsx as e,jsxs as o}from"react/jsx-runtime";import{observer as t}from"mobx-react-lite";import{Button as r}from"../primitives/button.js";import{Tooltip as i,TooltipContent as a,TooltipTrigger as n}from"../primitives/tooltip.js";import{ElementContainer as m,extendToolbar as s}from"./element-container.js";import{PolotnoIcon as l}from"../icons/registry.js";import c from"./filters-picker.js";import{AnimationsPicker as p}from"./animations-picker.js";import g from"./flip-button.js";import{flags as d}from"../utils/flags.js";import{ImageRemoveBackground as u}from"./image-remove-background-button.js";export{ImageRemoveBackground}from"./image-remove-background-button.js";import{getCrop as h,getImageSize as f}from"@polotno/core/image";import{t as C}from"../utils/l10n.js";import{isImageLoadError as I}from"../utils/errors.js";import{ImageEdit as b}from"./image-tools.js";export{ImageEdit,ImageToolActions}from"./image-tools.js";export const ImageFitToBackground=({element:o})=>e(r,{variant:"ghost",size:"sm",onClick:async()=>{const{page:e}=o,t=e.computedBleed,r=e.computedWidth+t.left+t.right,i=e.computedHeight+t.top+t.bottom,a=await f(o.src).catch(e=>{if(!I(e)){throw e}return console.warn("polotno: failed to fit the image to the background",e),null});if(!a){return}const n=o.stretchEnabled?{cropX:0,cropY:0,cropWidth:1,cropHeight:1}:h({width:r,height:i},a);o.set(Object.assign({x:-t.left,y:-t.top,width:r,height:i,rotation:0},n))},children:C("toolbar.fitToBackground")});export const ImageClip=t(({element:o,store:t,elements:i})=>o.contentEditable?o.clipSrc?e(r,{variant:"ghost",size:"sm",onClickCapture:()=>{i.forEach(e=>{e.set({clipSrc:""})})},children:C("toolbar.removeClip")}):e(r,{variant:"ghost",size:"sm",onClickCapture:e=>{e.stopPropagation(),t.openSidePanel("image-clip")},children:C("toolbar.clip")}):null);export const ImageCrop=t(({element:t})=>t._cropEnabled?o(i,{children:[e(n,{render:e(r,{variant:"ghost",size:"icon-sm",onClickCapture:e=>{e.stopPropagation(),t.toggleCropMode(!0)},"aria-label":C("toolbar.crop"),children:e(l,{name:"toolbar.crop",className:"pn:size-4"})})}),e(a,{children:C("toolbar.crop")})]}):null);export const CropModeBar=t(({element:t})=>o("div",{className:"pn:flex pn:items-center",children:[o(r,{variant:"ghost",size:"sm",onClickCapture:()=>{t.toggleCropMode(!1)},children:[e(l,{name:"action.confirm",className:"pn:size-4"}),C("toolbar.cropDone")]}),o(r,{variant:"ghost",size:"sm",onClickCapture:()=>{t.cancelCropMode()},children:[e(l,{name:"action.close",className:"pn:size-4"}),C("toolbar.cropCancel")]})]}));export const ImageRemoveClip=t(({element:o})=>o.clipSrc?e(r,{variant:"ghost",size:"sm",onClickCapture:()=>{o.set({clipSrc:""})},children:C("toolbar.removeClip")}):null);const k={ImageFlip:g,ImageFilters:c,ImageFitToBackground,ImageCrop,ImageEdit:b,ImageClip,ImageRemoveBackground:u,ImageAnimations:p};export const ImageToolbar=t(({store:o,components:t})=>{const r=o.selectedElements[0],i=["ImageCrop","ImageEdit","ImageFlip","ImageFilters","ImageFitToBackground","ImageClip",d.animationsEnabled&&"ImageAnimations"],a=s({type:"image",usedItems:i,components:t});return e(m,{items:a,itemRender:i=>{const a=t[i]||k[i];return e(a,{element:r,store:o,elements:o.selectedElements,components:t},i)}})});export default ImageToolbar;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ImageToolSession } from '../image-tools/sessions.js';
|
|
3
|
+
import type { ImageElementType } from '../model/image-model.js';
|
|
4
|
+
import type { StoreType } from '../model/store.js';
|
|
5
|
+
type Props = {
|
|
6
|
+
element: ImageElementType;
|
|
7
|
+
store: StoreType;
|
|
8
|
+
};
|
|
9
|
+
export declare const ImageEdit: (({ element, store, components, }: Props & {
|
|
10
|
+
components?: Record<string, React.ComponentType<Props> | null>;
|
|
11
|
+
}) => React.JSX.Element | null) & React.NamedExoticComponent<Props & {
|
|
12
|
+
components?: Record<string, React.ComponentType<Props> | null>;
|
|
13
|
+
}> & {
|
|
14
|
+
readonly type: ({ element, store, components, }: Props & {
|
|
15
|
+
components?: Record<string, React.ComponentType<Props> | null>;
|
|
16
|
+
}) => React.JSX.Element | null;
|
|
17
|
+
};
|
|
18
|
+
export declare const discardOnEscape: (store: StoreType, session: ImageToolSession) => (event: React.KeyboardEvent) => void;
|
|
19
|
+
export declare const ImageToolActions: (({ element, store, session, components, }: {
|
|
20
|
+
element: {
|
|
21
|
+
id: string;
|
|
22
|
+
};
|
|
23
|
+
store: StoreType;
|
|
24
|
+
session: ImageToolSession;
|
|
25
|
+
components?: Record<string, React.ComponentType<Props>>;
|
|
26
|
+
}) => React.JSX.Element) & React.NamedExoticComponent<{
|
|
27
|
+
element: {
|
|
28
|
+
id: string;
|
|
29
|
+
};
|
|
30
|
+
store: StoreType;
|
|
31
|
+
session: ImageToolSession;
|
|
32
|
+
components?: Record<string, React.ComponentType<Props>>;
|
|
33
|
+
}> & {
|
|
34
|
+
readonly type: ({ element, store, session, components, }: {
|
|
35
|
+
element: {
|
|
36
|
+
id: string;
|
|
37
|
+
};
|
|
38
|
+
store: StoreType;
|
|
39
|
+
session: ImageToolSession;
|
|
40
|
+
components?: Record<string, React.ComponentType<Props>>;
|
|
41
|
+
}) => React.JSX.Element;
|
|
42
|
+
};
|
|
43
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as e,jsxs as n}from"react/jsx-runtime";import o from"react";import{observer as t}from"mobx-react-lite";import{Button as a}from"../primitives/button.js";import{useMobile as i}from"../utils/screen.js";import{t as r}from"../utils/l10n.js";import{PolotnoIcon as s}from"../icons/registry.js";import{DropdownMenu as c,DropdownMenuContent as l,DropdownMenuItem as m,DropdownMenuTrigger as d}from"../primitives/dropdown-menu.js";import{reportImageEditError as p,toolLabel as g}from"../image-tools/messages.js";export const ImageEdit=t(({element:t,store:u,components:v={}})=>{var h;const f=(null===(h=u.activeTool)||void 0===h?void 0:h.elementId)===t.id?u.activeTool:null,E=o.useRef(!1),b=i(),I=e=>u.canUseTool(e,t.id),x=e=>{const n=u.setTool(e,{elementId:t.id}).run();u._closeImageTool("discard"),n.catch(e=>p(t,e))},j=void 0===v.ImageRemoveBackground&&I("remove-background"),T=I("upscale"),k=["inpaint","expand"].filter(I);return j||T||k.length?n(c,{children:[e(d,{render:n(a,{variant:"ghost",size:"sm",disabled:!!t.pendingEdit,children:[e(s,{name:"imageEdit.ai",className:"pn:size-4"}),f&&"crop"!==f.name?g(f.name):r("imageEdit.title"),e(s,{name:"ui.chevronDown",className:"pn:size-3"})]})}),n(l,{align:"start",className:"pn:min-w-48",finalFocus:()=>{const e=E.current;return E.current=!1,!(e&&!b)||document.querySelector(".polotno-image-edit-panel textarea")},children:[j&&e(m,{onSelect:()=>x("remove-background"),children:g("remove-background")}),k.map(n=>e(m,{onSelect:()=>{E.current=!0,u.setTool(n,{elementId:t.id}),u._imageEditPanelAvailable&&u.openSidePanel("image-edit")},children:g(n)},n)),T&&e(m,{onSelect:()=>x("upscale"),children:g("upscale")})]})]}):null});export const discardOnEscape=(e,n)=>o=>{"crop"===n.name||"Escape"!==o.key||o.defaultPrevented||o.nativeEvent.isComposing||(o.preventDefault(),o.stopPropagation(),e._closeImageTool("discard"))};export const ImageToolActions=t(({element:o,store:t,session:i,components:s={}})=>{const c=s.ImageEdit||ImageEdit,l=t._imageEditPanelAvailable&&"image-edit"===t.openedSidePanel;return n("div",{className:"pn:flex pn:items-center pn:gap-1",onKeyDown:discardOnEscape(t,i),children:["crop"!==i.name&&e(c,{element:o,store:t,components:s}),("crop"!==i.name||!l)&&e(a,{type:"button",variant:"ghost",size:"sm",disabled:"crop"===i.name&&i.pending,onClick:()=>"crop"===i.name?i.run().catch(()=>{}):t._closeImageTool("discard"),children:r("crop"===i.name?"toolbar.cropDone":"sidePanel.close")}),"crop"===i.name&&!l&&e(a,{variant:"ghost",size:"sm",onClick:()=>i.cancel(),children:r("toolbar.cropCancel")}),"crop"===i.name&&i.pending&&!l&&e("span",{role:"status",children:r("imageEdit.loadingImage")})]})});
|
package/toolbar/sketch.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { type CmykColor } from '@polotno/core/color';
|
|
3
|
+
export declare function cmykFromColor(color: string): CmykColor;
|
|
2
4
|
type SketchProps = {
|
|
3
5
|
color: string;
|
|
4
6
|
onChange: (colors: any, e?: any) => void;
|
|
@@ -7,7 +9,8 @@ type SketchProps = {
|
|
|
7
9
|
title?: string;
|
|
8
10
|
}>;
|
|
9
11
|
disableAlpha?: boolean;
|
|
12
|
+
cmykEnabled?: boolean;
|
|
10
13
|
className?: string;
|
|
11
14
|
};
|
|
12
|
-
export declare const Sketch: ({ color, onChange, presetColors, disableAlpha, className, }: SketchProps) => React.JSX.Element;
|
|
15
|
+
export declare const Sketch: ({ color, onChange, presetColors, disableAlpha, cmykEnabled, className, }: SketchProps) => React.JSX.Element;
|
|
13
16
|
export default Sketch;
|