polotno 3.5.2 → 3.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/blueprint/toolbar/image-toolbar.d.ts +2 -2
- package/blueprint/toolbar/sketch.js +1 -1
- package/canvas/apply-filters.d.ts +1 -1
- package/canvas/audio.js +1 -1
- package/canvas/context-menu/context-menu.d.ts +2 -2
- package/canvas/figure-element.js +1 -1
- package/canvas/image-element.d.ts +11 -0
- package/canvas/image-element.js +1 -1
- package/canvas/page-controls.d.ts +1 -1
- package/canvas/rich-editor.js +2 -2
- package/canvas/rules.d.ts +1 -1
- package/canvas/tooltip.d.ts +2 -2
- package/canvas/video-element.js +1 -1
- package/hooks/use-event.js +1 -1
- package/icons/meronex.js +1 -1
- package/icons/registry.d.ts +1 -0
- package/icons/registry.js +1 -1
- package/model/audio-model.d.ts +2 -0
- package/model/audio-model.js +1 -1
- package/model/store.d.ts +3 -0
- package/model/store.js +1 -1
- package/package.json +7 -7
- package/pages-timeline/audio-track.d.ts +3 -2
- package/pages-timeline/audio-track.js +1 -1
- package/pages-timeline/audios.js +1 -1
- package/pages-timeline/element-track.js +1 -1
- package/pages-timeline/index.d.ts +1 -1
- package/pages-timeline/index.js +1 -1
- package/pages-timeline/play-button.d.ts +1 -1
- package/pages-timeline/track-styles.d.ts +9 -0
- package/pages-timeline/track-styles.js +1 -1
- package/polotno.bundle.js +200 -201
- package/primitives/button-group.d.ts +2 -2
- package/primitives/button.d.ts +2 -2
- package/primitives/dialog.d.ts +2 -2
- package/primitives/dropdown-menu.d.ts +2 -2
- package/primitives/field-group.d.ts +1 -1
- package/primitives/field-row.d.ts +1 -1
- package/primitives/floating-control.js +2 -2
- package/primitives/index.d.ts +27 -27
- package/primitives/input-group.d.ts +2 -2
- package/primitives/input.d.ts +1 -1
- package/primitives/navbar.d.ts +5 -5
- package/primitives/numeric-input.d.ts +1 -1
- package/primitives/overflow-list.d.ts +1 -1
- package/primitives/panel-header.d.ts +1 -1
- package/primitives/popover.d.ts +2 -2
- package/primitives/portal-scope.d.ts +3 -3
- package/primitives/search-input.d.ts +1 -1
- package/primitives/select.d.ts +2 -2
- package/primitives/separator.d.ts +1 -1
- package/primitives/slider-field.d.ts +1 -1
- package/primitives/slider.d.ts +2 -2
- package/primitives/spinner.d.ts +1 -1
- package/primitives/switch.d.ts +1 -1
- package/primitives/tabs.d.ts +2 -2
- package/primitives/textarea.d.ts +1 -1
- package/primitives/toggle-group.d.ts +4 -4
- package/primitives/toggle.d.ts +3 -3
- package/primitives/tooltip-icon-button.d.ts +4 -4
- package/primitives/tooltip.d.ts +2 -2
- package/side-panel/background-panel.d.ts +2 -2
- package/side-panel/draw-panel.d.ts +2 -2
- package/side-panel/elements-panel.d.ts +2 -2
- package/side-panel/images-grid.js +1 -1
- package/side-panel/index.d.ts +35 -35
- package/side-panel/photos-panel.d.ts +1 -1
- package/side-panel/select-gif.d.ts +1 -1
- package/side-panel/side-panel.d.ts +5 -5
- package/side-panel/size-panel.d.ts +3 -3
- package/side-panel/tab-button.d.ts +1 -1
- package/side-panel/tab-button.js +2 -2
- package/side-panel/templates-panel.d.ts +2 -2
- package/side-panel/unsplash-credit.d.ts +1 -1
- package/side-panel/upload-panel.d.ts +3 -3
- package/side-panel/upload-panel.js +1 -1
- package/side-panel/videos-grid.js +1 -1
- package/themes/blueprint.css +1 -1
- package/themes/carbon.css +127 -128
- package/toolbar/download-button.d.ts +2 -2
- package/toolbar/element-container.d.ts +1 -1
- package/toolbar/filters-picker.d.ts +1 -1
- package/toolbar/group-toolbar.d.ts +2 -2
- package/toolbar/history-buttons.d.ts +1 -1
- package/toolbar/image-remove-background-button.d.ts +1 -1
- package/toolbar/image-toolbar.d.ts +1 -1
- package/toolbar/index.d.ts +34 -34
- package/toolbar/many-toolbar.d.ts +2 -2
- package/toolbar/opacity-picker.d.ts +1 -1
- package/toolbar/page-toolbar.d.ts +3 -3
- package/toolbar/toolbar.d.ts +3 -3
- package/toolbar/zoom-buttons.d.ts +1 -1
- package/ui-types.d.ts +8 -8
- package/ui.css +1 -1
- package/utils/array.js +1 -1
- package/utils/file.d.ts +3 -0
- package/utils/file.js +1 -1
- package/utils/html-to-svg/svg-builder.d.ts +1 -1
- package/utils/insert-file.d.ts +3 -2
- package/utils/insert-file.js +1 -1
- package/utils/l10n.d.ts +4 -0
- package/utils/l10n.js +1 -1
- package/utils/media.d.ts +6 -0
- package/utils/media.js +1 -0
- package/utils/validate-key.js +1 -1
package/model/store.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=this&&this.__rest||function(e,t){var i={};for(var o in e){Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(i[o]=e[o])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(o=Object.getOwnPropertySymbols(e);n<o.length;n++){t.indexOf(o[n])<0&&Object.prototype.propertyIsEnumerable.call(e,o[n])&&(i[o[n]]=e[o[n]])}}return i};import{applySnapshot as t,cast as i,destroy as o,detach as n,getSnapshot as a,onSnapshot as s,setLivelinessChecking as r,types as l}from"mobx-state-tree";import{UndoManager as d}from"./history.js";import{nanoid as p}from"nanoid";import c from"konva";import{computed as g}from"mobx";import{ZERO_BLEED as m}from"@polotno/schema";import{downloadFile as u}from"../utils/download.js";import{getJsPDF as f}from"../utils/pdf.js";import{createGIF as h}from"../utils/gif-lib.js";import{validateKey as b,setKey as v}from"../utils/validate-key.js";import*as y from"../utils/fonts.js";import{flags as P}from"../utils/flags.js";import{addDpiMetadataToImage as w}from"../utils/image-dpi.js";import{nodeToCanvas as x}from"../utils/canvas.js";import{whenLoaded as E}from"../utils/loader.js";import{polotnoError as I}from"@polotno/core/errors";import{pxToUnit as T}from"../utils/unit.js";import{deepEqual as _}from"../utils/deep-equal.js";import{waitTillAvailable as S}from"../utils/wait.js";import{jsonToHTML as O}from"@polotno/html-export";import{jsonToSVG as k}from"@polotno/svg-export";import{warnOnceDeprecated as j}from"../utils/deprecation.js";import{Page as R}from"./page-model.js";import{forEveryChild as F,forEveryNode as A}from"./group-model.js";import{Audio as V}from"./audio-model.js";r("ignore");export const Font=l.model("Font",{fontFamily:l.string,url:l.optional(l.string,""),styles:l.frozen()}).preProcessSnapshot(e=>Object.assign(Object.assign({},e),{fontFamily:e.fontFamily||e.name}));export const ROLES={ADMIN:"admin",VIEWER:"viewer"};export const Store=l.model("Store",{role:"",pages:l.array(R),fonts:l.array(Font),audios:l.array(V),width:1080,height:1080,currentTime:0,isPlaying:!1,scale:1,scaleToFit:1,unit:l.optional(l.enumeration("UnitType",["pt","mm","cm","in","px"]),"px"),dpi:72,schemaVersion:4,bleedVisible:!1,rulesVisible:!1,distanceGuidesVisible:!1,timingPreview:l.optional(l.enumeration("TimingPreview",["all","playhead"]),"all"),openedSidePanel:"",previousOpenedSidePanel:"",custom:l.frozen(),tool:l.optional(l.enumeration("Tool",["selection","draw","pan","text","eraser"]),"selection"),toolOptions:l.optional(l.model({brushType:l.optional(l.enumeration("BrushType",["brush","highlighter"]),"brush"),strokeWidth:l.optional(l.number,5),stroke:l.optional(l.string,"#000000"),opacity:l.optional(l.number,1)}),{}),selectedElementsIds:l.array(l.string),animatedElementsIds:l.array(l.string),history:l.optional(d,{targetPath:"../pages"}),_elementsPixelRatio:Math.min(2,"undefined"!=typeof window&&window.devicePixelRatio||1),_activePageId:"",_selectedPagesIds:l.array(l.string),_forceShowCredit:!1,_validated:!1}).views(e=>{const t=g(()=>{const t={};return A({children:e.pages},e=>(t[e.id]=e,!1)),t},{keepAlive:!0});return{get _idsMap(){return t.get()}}}).views(e=>({get _bleedVisible(){return console.warn("store._bleedVisible is deprecated. Please use store.bleedVisible instead."),e.bleedVisible},get selectedElements(){return e.selectedElementsIds.map(t=>e._idsMap[t]).filter(e=>!!e)},get children(){return e.pages},get selectedShapes(){const e=[];return F({children:this.selectedElements},t=>{"group"!==t.type&&e.push(t)}),e},get activePage(){return e.pages.slice().find(t=>t.id===e._activePageId)||(e.pages.length?e.pages[0]:null)},get selectedPages(){return e._selectedPagesIds.map(t=>e.pages.find(e=>e.id===t))},get duration(){let t=0;return e.pages.forEach(e=>{t+=e.duration}),t},pageAtTime(t){for(const i of e.pages){if(t>=i.startTime&&t<i.startTime+i.duration){return i}}return e.pages.length&&t>=this.duration?e.pages[e.pages.length-1]:null},get effectiveTime(){if(e.isPlaying){return e.currentTime}const t=this.activePage;return t&&this.pageAtTime(e.currentTime)!==t?t.startTime:e.currentTime},get playheadAccurate(){return e.isPlaying||"playhead"===e.timingPreview},get isEditingPaused(){var t;return!e.isPlaying&&!(null===(t=this.activePage)||void 0===t?void 0:t._exportingOrRendering)},get _hasCroppedImages(){return this.find(e=>"image"===e.type&&e._cropModeEnabled)},find(t){let i;return A({children:e.pages},e=>{if(!i&&t(e)){return i=e,!0}}),i},getElementById:t=>e._idsMap[t]})).actions(r=>{let l=0,d=null,g=!1;const v={afterCreate(){r.history.canUndo},setCurrentTime(e){r.currentTime=e},_togglePlaying(e=!r.isPlaying){r.isPlaying=e},play({animatedElementsIds:e=[],startTime:t=0,currentTime:o=0,endTime:n=r.duration,repeat:a=!1}={}){o&&(console.warn("currentTime property of store.play() is deprecated. Please use startTime instead."),t=o),r.animatedElementsIds=i(e),r.currentTime=t,r.isPlaying=!0,l=Date.now(),d=n,g=a,requestAnimationFrame(()=>v.seek())},checkActivePage(){const e=r.pageAtTime(r.currentTime);e&&v.selectPage(e.id)},seek(){if(!r.isPlaying){return}const e=Date.now(),t=e-l;l=e,r.currentTime+=t;const i=d||r.duration;r.currentTime>=i&&!g&&(r.currentTime=i),v.checkActivePage(),r.isPlaying&&r.currentTime<i?requestAnimationFrame(()=>v.seek()):r.isPlaying&&g?(r.currentTime=0,requestAnimationFrame(()=>v.seek())):v.pause()},pause(){r.isPlaying=!1,r.animatedElementsIds=i([])},stop(){v.pause(),r.currentTime=0,v.checkActivePage()},__(){r._validated||(b(r._forceShowCredit),r._validated=!0)},set(e){Object.assign(r,e)},setUnit({unit:e,dpi:t}){r.unit=e||r.unit,r.dpi=t||r.dpi},setRole(e){r.role=e},setTool(e){r.tool=e},setToolOptions(e){Object.assign(r.toolOptions,e)},addPage(e){const t=R.create(Object.assign({id:p(10)},e));return r.pages.push(t),r._activePageId=t.id,r._selectedPagesIds=i([]),t},selectPage(e){r._activePageId=e,1===r._selectedPagesIds.length&&(r._selectedPagesIds=i([e]))},selectPages(e){r._selectedPagesIds=i(e),1===r._selectedPagesIds.length&&(r._activePageId=r._selectedPagesIds[0])},selectElements(e){const t=e.map(e=>r.getElementById(e)).filter(e=>!!e);t.sort((e,t)=>{var i,o,n,a;return(null!==(o=null===(i=e.parent)||void 0===i?void 0:i.children.indexOf(e))&&void 0!==o?o:0)-(null!==(a=null===(n=t.parent)||void 0===n?void 0:n.children.indexOf(t))&&void 0!==a?a:0)}),r.selectedElementsIds=i(t.map(e=>e.id))},toggleBleed(e){r.bleedVisible=null!=e?e:!r.bleedVisible},toggleRulers(e){r.rulesVisible=null!=e?e:!r.rulesVisible},setTimingPreview(e){r.timingPreview=e},toggleDistanceGuides(e){r.distanceGuidesVisible=null!=e?e:!r.distanceGuidesVisible},openSidePanel(e){r.openedSidePanel!==e&&(r.previousOpenedSidePanel=r.openedSidePanel,r.openedSidePanel=e)},restoreSidePanel(){const e=r.previousOpenedSidePanel;e&&e!==r.openedSidePanel?r.openedSidePanel=e:r.openedSidePanel="photos"},setScale(e){r.scale=e},_setScaleToFit(e){r.scaleToFit=e},setElementsPixelRatio(e){r._elementsPixelRatio=e},setSize(e,t,i){r.pages.forEach(o=>{o.setSize({width:e,height:t,useMagic:i,softChange:!0})}),r.width=e,r.height=t},setPageZIndex(e,t){const i=r.pages.find(t=>t.id===e);i&&(n(i),r.pages.remove(i),r.pages.splice(t,0,i))},deletePages(e){const t=r.pages.indexOf(r.activePage);e.forEach(e=>{const t=r.pages.find(t=>t.id===e);o(t)});const n=r._selectedPagesIds.filter(e=>r.pages.some(t=>t.id===e)),a=Math.min(r.pages.length-1,t),s=r.pages[a];s&&(r._activePageId=s.id),v.selectPages(n),r.selectedElementsIds=i(r.selectedElementsIds.filter(e=>r.getElementById(e)))},groupElements(e,t={}){const o=e.map(e=>r.getElementById(e)).filter(e=>!!e);if(!o.length){return}const a=o[0].parent;if(!a){return}if(!o.every(e=>e.parent===a)){return void console.warn("store.groupElements: refusing to group elements that do not share a parent. Pass ids whose elements all live under the same page or the same group.")}o.forEach(e=>n(e));const s=a.children.reduce((e,t)=>{var i;if("group"===t.type){const o=null===(i=t.name)||void 0===i?void 0:i.match(/group-(\d+)/);if(o){const t=parseInt(o[1],10);return Math.max(e,t)}}return e},0),l=Object.assign({id:p(10),name:`group-${s+1}`,children:o,type:"group"},t);return a.children.push(l),r.selectedElementsIds=i([l.id]),a.children.find(e=>e.id===l.id)},ungroupElements(e){const t=e.map(e=>r.getElementById(e)),o=[];t.forEach(e=>{if(e&&"group"===e.type){const t=e.parent;if(!t){return}const i=t.children.indexOf(e);e.children.forEach(e=>{o.push(e.id)}),e.children.slice().forEach(e=>{n(e),t.children.push(e)}),t.children.splice(i,1)}}),r.selectedElementsIds=i(o)},deleteElements(e){const t=[];r.find(i=>(e.includes(i.id)&&t.push(i),!1)),t.forEach(e=>{o(e)}),r.selectedElementsIds=i(r.selectedElementsIds.filter(e=>r.getElementById(e)))},on(e,t){if("change"===e){let e=v.toJSON();return s(r,i=>{const o=v.toJSON();!_(e,o)&&(e=o,t(o))})}},async _toCanvas({pixelRatio:e,ignoreBackground:t,pageId:i,mimeType:o,includeBleed:n,_skipTimeout:a,quickMode:s=!1,_exportCanvases:l}={}){var d;const p=e||1;i=i||(null===(d=r.pages[0])||void 0===d?void 0:d.id);const g=r.pages.find(e=>e.id===i);if(!g){throw I("EXPORT_FAILED",`No page for export with id ${i}`,{reason:"page-not-found",pageId:i,availablePageIds:r.pages.map(e=>e.id)})}const u=r._elementsPixelRatio;p>r._elementsPixelRatio&&v.setElementsPixelRatio(p),s?null==g||g.set({_forceMount:!0}):null==g||g.set({_exporting:!0});const f=await S(()=>{const e=c.stages.filter(e=>e.getAttr("pageId")===i);return 0===e.length?null:e});if(!f){throw null==g||g.set({_forceMount:!1,_exporting:!1}),v.setElementsPixelRatio(u),I("EXPORT_FAILED",`Export is failed. Can not find stage for page ${i}. Looks like <Workspace /> component is not mounted, but it is required in order to process the export.`,{reason:"workspace-not-mounted",pageId:i})}f.length>1&&console.error(`Polotno error: Detected several canvas elements for page "${i}" in the document. This is not supported and will lead to incorrect export. Make sure to use unique ids for all pages and make sure you unmount <Workspace /> when it is not needed.`);const h=f[0];await v.waitLoading({_skipTimeout:a});const b=h.findOne(".page-container");if(!b){throw v.setElementsPixelRatio(u),null==g||g.set({_forceMount:!1,_exporting:!1}),I("EXPORT_FAILED","Export is failed. Canvas was unmounted.",{reason:"unmounted-during-export",pageId:i})}const y=h.position();h.position({x:0,y:0}),h.find("Transformer").forEach(e=>{e.setAttr("oldVisible",e.visible()),e.visible(!1)}),b.find(".page-background").forEach(e=>e.shadowEnabled(!1)),b.find(".page-background").forEach(e=>e.strokeEnabled(!1)),b.find(".highlighter").forEach(e=>e.visible(!1));const P=b.findOne(".page-background-group"),w=P.clip();P.clip({x:null,y:null,width:null,height:null});const E=b.findOne(".elements-container"),T=E.clip();E.clip({x:null,y:null,width:null,height:null});const _=b.find(e=>!e.visible()&&e.getAttr("editModeEnabled")&&!e.getAttr("hideInExport"));_.forEach(e=>{e.setAttr("oldVisible",e.visible()),e.show()});const O=b.find(e=>e.getAttr("hideInExport"));O.forEach(e=>{e.setAttr("oldVisible",e.visible()),e.hide()}),t&&b.find(".page-background").forEach(e=>e.hide());const k=n?g.computedBleed:m;let j=k.left,R=k.top;!r.bleedVisible&&n||(r.bleedVisible||n?r.bleedVisible&&n?(j=0,R=0):r.bleedVisible&&!n&&(j=-g.computedBleed.left,R=-g.computedBleed.top):(j=0,R=0));const F=g.computedWidth+k.left+k.right,A=g.computedHeight+k.top+k.bottom,V=b.scale();b.scale({x:1,y:1});const C=x(b,{x:b.x()-j,y:b.y()-R,width:F,height:A,pixelRatio:p,sceneCanvas:null==l?void 0:l.sceneCanvas,bufferCanvas:null==l?void 0:l.bufferCanvas});b.scale(V);const L=C._canvas;if("image/jpeg"===o){const e=L.getContext("2d");e.save(),e.globalCompositeOperation="destination-over",e.fillStyle="white",e.fillRect(0,0,L.width,L.height),e.restore()}return t&&b.find(".page-background").forEach(e=>e.show()),O.forEach(e=>{e.visible(e.getAttr("oldVisible"))}),_.forEach(e=>{e.visible(e.getAttr("oldVisible"))}),b.find(".page-background").forEach(e=>e.shadowEnabled(!0)),b.find(".page-background").forEach(e=>e.strokeEnabled(!0)),h.find("Transformer").forEach(e=>{e.visible(e.getAttr("oldVisible"))}),b.find(".highlighter").forEach(e=>e.visible(!0)),P.clip(w),E.clip(T),h.position(y),null==g||g.set({_exporting:!1,_forceMount:!1}),await Promise.resolve(),v.setElementsPixelRatio(u),L},async toDataURL(t={}){var{mimeType:i,quality:o,dpi:n,dpiMetadata:a="auto"}=t,s=e(t,["mimeType","quality","dpi","dpiMetadata"]);const l=await v._toCanvas(Object.assign({mimeType:i},s)),d=i||"image/png",p=l.toDataURL(d,o);c.Util.releaseCanvas(l);const g=null!=n?n:r.dpi;return"image/png"!==d&&"image/jpeg"!==d||"never"===a||"auto"===a&&72===g?p:w(p,d,g)},async toBlob(t={}){var{mimeType:i,quality:o}=t,n=e(t,["mimeType","quality"]);const a=await v._toCanvas(Object.assign({mimeType:i},n)),s=await new Promise(e=>{a.toBlob(e,i,o)});return c.Util.releaseCanvas(a),s},async saveAsImage(t={}){var{fileName:i}=t,o=e(t,["fileName"]);const n=(o.mimeType||"image/png").split("/")[1];u(await v.toDataURL(o),i||"polotno."+n)},async _toPDF(e){const t=e.dpi||r.dpi,i=e.parallel||1,o=e.unit||("px"===r.unit?"mm":r.unit),n=e.pixelRatio||1,a=e.pageIds||(e.pageId?[e.pageId]:r.pages.map(e=>e.id)),s=r.pages.filter(e=>a.includes(e.id)),l=await f(),d=e=>T({px:e,unit:o,dpi:t}),p=e.cropMarkSize||0,c=d(p),g=s[0]||{},u=e.includeBleed&&g.computedBleed||m,h=d(g.computedWidth+u.left+u.right+2*c),b=d(g.computedHeight+u.top+u.bottom+2*c);var y=new l({unit:o,orientation:h>b?"landscape":"portrait",format:[h,b],compress:!0,putOnlyUsedFonts:!0});y.deletePage(1);const P=((e,t)=>{const i=[];for(let o=0;o<e.length;o+=t){i.push(e.slice(o,o+t))}return i})(s,i);let w=0;for(const r of P){const t=r.map(async t=>{const i=e.includeBleed?t.computedBleed:m,o=t.computedWidth+i.left+i.right+2*p,s=t.computedHeight+i.top+i.bottom+2*p,r=d(o),l=d(s);let c=0,g=n;for(;c<10;){c+=1;const d=await v.toDataURL(Object.assign(Object.assign({},e),{pageId:t.id,pixelRatio:g,dpiMetadata:"never"}));if(d.length>20){return g!==n&&console.error(`Polotno can not export PDF with current settings. Quality is automatically reduced. pixelRatio was reduced to ${parseFloat(g.toFixed(3))}.`),e.onProgress&&e.onProgress(++w/a.length*.9),{url:d,width:r,height:l,widthPx:o,heightPx:s,cb:i}}g*=.8}});(await Promise.all(t)).filter(e=>void 0!==e).forEach(({url:e,width:t,height:i,widthPx:n,heightPx:a,cb:s})=>{y.addPage([t,i],t>i?"landscape":"portrait");const r=y.getCurrentPageInfo();var l;switch(o){case"pt":l=1;break;case"mm":l=72/25.4;break;case"cm":l=72/2.54;break;case"in":l=72;break;case"px":l=.75;break;default:throw I("EXPORT_FAILED","Invalid unit: "+o,{reason:"invalid-options",option:"unit",value:o})}if(r.pageContext.cropBox={bottomLeftX:0,bottomLeftY:0,topRightX:t*l,topRightY:i*l},r.pageContext.artBox={bottomLeftX:d(p+s.left)*l,bottomLeftY:d(p+s.bottom)*l,topRightX:d(n-p-s.right)*l,topRightY:d(a-p-s.top)*l},r.pageContext.bleedBox={bottomLeftX:d(p+s.left)*l,bottomLeftY:d(p+s.bottom)*l,topRightX:d(n-p-s.right)*l,topRightY:d(a-p-s.top)*l},c){y.setLineWidth(d(1));const e=c+d(s.left),o=c+d(s.right),n=c+d(s.top),a=c+d(s.bottom);y.line(e,0,e,c),y.line(0,n,c,n),y.line(t-o,0,t-o,c),y.line(t,n,t-c,n),y.line(0,i-a,c,i-a),y.line(e,i,e,i-c),y.line(t,i-a,t-c,i-a),y.line(t-o,i,t-o,i-c)}y.addImage(e,c,c,t-2*c,i-2*c,void 0,"FAST")})}return y},toPDFDataURL:async e=>(await v._toPDF(Object.assign({mimeType:"image/jpeg"},e))).output("datauristring"),async toGIFDataURL(e={}){const t=e.pixelRatio||1,i=e.pageIds||(e.pageId?[e.pageId]:r.pages.map(e=>e.id)),o=r.pages.filter(e=>i.includes(e.id));if(!o.length){throw I("EXPORT_FAILED","No pages found for GIF export",{reason:"page-not-found",pageId:e.pageId,availablePageIds:r.pages.map(e=>e.id)})}const n=o[0],a=await h({width:n.computedWidth*t,height:n.computedHeight*t}),s=1e3/(e.fps||10);for(const l of o){const e=Math.max(1,Math.floor(l.duration/s));for(let i=0;i<e;i++){const e=l.startTime+i*s||1;v.setCurrentTime(e);for(const t of r.pages){t.set({_rendering:t.id===l.id})}const o=await v._toCanvas({pixelRatio:t,pageId:l.id,_skipTimeout:!0});a.addFrame(o.getContext("2d"),{delay:s,copy:!0})}}for(const l of r.pages){l.set({_rendering:!1})}return v.stop(),a.render(),new Promise(e=>{a.on("finished",function(t){!function(e,t){var i=new FileReader;i.onload=function(e){t(e.target.result)},i.readAsDataURL(e)}(t,e)})})},async saveAsGIF(t={}){var{fileName:i}=t,o=e(t,["fileName"]);const n=await v.toGIFDataURL(o);u(n,i||"polotno.gif")},async toHTML({elementHook:e}={}){j("store.toHTML","store.toHTML()/saveAsHTML() are deprecated: install @polotno/html-export and call jsonToHTML(store.toJSON()) instead");const t=v.toJSON();return O(t,{elementHook:e,textOverflow:P.textOverflow,textSplitAllowed:P.textSplitAllowed})},async saveAsHTML({fileName:e,elementHook:t}={}){const i=await v.toHTML({elementHook:t}),o="data:text/html;base64,"+window.btoa(unescape(encodeURIComponent(i)));u(o,e||"polotno.html")},async toSVG({elementHook:e,pageId:t,fontEmbedding:i="inline"}={fontEmbedding:"inline"}){var o;j("store.toSVG","store.toSVG()/saveAsSVG() are deprecated: install @polotno/svg-export and call jsonToSVG(store.toJSON()) instead");const n=v.toJSON();t=t||(null===(o=n.pages[0])||void 0===o?void 0:o.id);const a=n.pages.find(e=>e.id===t);return k(Object.assign(Object.assign({},n),{pages:a?[a]:[]}),{elementHook:e,fontEmbedding:i})},async saveAsSVG({fileName:e,elementHook:t,pageId:i,fontEmbedding:o="inline"}={}){const n=await v.toSVG({elementHook:t,pageId:i,fontEmbedding:o}),a="data:text/svg;base64,"+window.btoa(unescape(encodeURIComponent(n)));u(a,e||"polotno.svg")},async saveAsPDF(t={}){var{fileName:i}=t,o=e(t,["fileName"]);(await v._toPDF(Object.assign({mimeType:"image/jpeg"},o))).save(i||"polotno.pdf")},async waitLoading({_skipTimeout:e=!1}={}){e||await new Promise(e=>setTimeout(e,50)),await E()},toJSON:()=>({width:r.width,height:r.height,fonts:a(r.fonts),pages:a(r.pages),audios:a(r.audios),unit:r.unit,dpi:r.dpi,custom:r.custom,schemaVersion:r.schemaVersion}),loadJSON(e,i=!1){var o,n,s;const l="boolean"==typeof i?i:null!==(o=null==i?void 0:i.keepHistory)&&void 0!==o&&o,d="boolean"!=typeof i&&null!==(n=null==i?void 0:i.modernizeTextBackground)&&void 0!==n&&n,p=JSON.parse(JSON.stringify(e)),c=p.schemaVersion||0;c<1&&(P.htmlRenderEnabled||P.renderTagTextEnabled)&&A({children:p.pages},e=>{if("text"===e.type){const t=16,i=e.letterSpacing*t;e.letterSpacing=i/e.fontSize}}),c<2&&A({children:p.pages},e=>{e.filters&&Object.keys(e.filters).forEach(t=>{if(["warm","cold","natural"].includes(t)){return}const i=e.filters[t];i&&"number"==typeof i.intensity&&(i.intensity=i.intensity/100)})}),c<3&&(P.htmlRenderEnabled||P.renderTagTextEnabled)&&!d&&A({children:p.pages},e=>{"text"===e.type&&e.backgroundEnabled&&(e.legacyBackground=!0)}),delete p.schemaVersion;const g=r.activePage?r.pages.indexOf(r.activePage):0;let m=null===(s=p.pages[g]||p.pages[0])||void 0===s?void 0:s.id;p._activePageId=m,p._selectedPagesIds=[];const u=Object.assign({},a(r));Object.assign(u,p),u.history=l?a(r.history):{history:[],undoIdx:-1,targetPath:""},t(r,u)},clear({keepHistory:e=!1}={}){const t=r.pages.map(e=>e.id);v.deletePages(t),r.custom=null,e||r.history.clear()},addFont(e){v.removeFont(e.fontFamily),r.fonts.push(e)},removeFont(e){r.fonts.filter(t=>t.fontFamily===e).forEach(e=>o(e))},addAudio(e){const t=V.create(Object.assign({id:p(10)},e));r.audios.push(t)},removeAudio(e){const t=r.audios.find(t=>t.id===e);t&&r.audios.remove(t)},async loadFont(e,t,i,o){const n=r.fonts.find(t=>t.fontFamily===e)||y.globalFonts.find(t=>t.fontFamily===e);let a=[{fontStyle:"normal",fontWeight:"normal"},{fontStyle:"normal",fontWeight:"bold"}];return n?(n.styles&&(a=n.styles.map(e=>({fontStyle:e.fontStyle||"normal",fontWeight:e.fontWeight||"normal"}))),y.injectCustomFont(n)):y.injectGoogleFont(e),t&&i&&!a.some(e=>e.fontStyle===t&&e.fontWeight===i)&&a.push({fontStyle:t,fontWeight:i}),Promise.all(a.map(t=>y.loadFont(e,t.fontStyle,t.fontWeight,o)))},validate:e=>Store.validate(e,[{path:"",type:Store}]).map(e=>({path:"store"+e.context.map(e=>e.path).join("."),message:e.message}))};return v});export function createStore({key:e,showCredit:t}={key:"",showCredit:!1}){return v(e),Store.create({_forceShowCredit:t})}export default createStore;
|
|
1
|
+
var e=this&&this.__rest||function(e,t){var o={};for(var i in e){Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(o[i]=e[i])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(i=Object.getOwnPropertySymbols(e);n<i.length;n++){t.indexOf(i[n])<0&&Object.prototype.propertyIsEnumerable.call(e,i[n])&&(o[i[n]]=e[i[n]])}}return o};import{applySnapshot as t,cast as o,destroy as i,detach as n,getSnapshot as a,onSnapshot as s,setLivelinessChecking as r,types as l}from"mobx-state-tree";import{UndoManager as d}from"./history.js";import{nanoid as p}from"nanoid";import c from"konva";import{computed as g}from"mobx";import{ZERO_BLEED as m,migrateDesign as u,CURRENT_SCHEMA_VERSION as f}from"@polotno/schema";import{downloadFile as h}from"../utils/download.js";import{getJsPDF as v}from"../utils/pdf.js";import{createGIF as b}from"../utils/gif-lib.js";import{validateKey as y,setKey as P}from"../utils/validate-key.js";import*as w from"../utils/fonts.js";import{flags as x}from"../utils/flags.js";import{addDpiMetadataToImage as E}from"../utils/image-dpi.js";import{nodeToCanvas as I}from"../utils/canvas.js";import{whenLoaded as T}from"../utils/loader.js";import{polotnoError as _}from"@polotno/core/errors";import{pxToUnit as O}from"../utils/unit.js";import{deepEqual as S}from"../utils/deep-equal.js";import{waitTillAvailable as k}from"../utils/wait.js";import{jsonToHTML as j}from"@polotno/html-export";import{jsonToSVG as R}from"@polotno/svg-export";import{warnOnceDeprecated as F}from"../utils/deprecation.js";import{Page as A}from"./page-model.js";import{forEveryChild as V,forEveryNode as C}from"./group-model.js";import{Audio as L}from"./audio-model.js";r("ignore");export const Font=l.model("Font",{fontFamily:l.string,url:l.optional(l.string,""),styles:l.frozen()}).preProcessSnapshot(e=>Object.assign(Object.assign({},e),{fontFamily:e.fontFamily||e.name}));export const ROLES={ADMIN:"admin",VIEWER:"viewer"};export const Store=l.model("Store",{role:"",pages:l.array(A),fonts:l.array(Font),audios:l.array(L),width:1080,height:1080,currentTime:0,isPlaying:!1,scale:1,scaleToFit:1,unit:l.optional(l.enumeration("UnitType",["pt","mm","cm","in","px"]),"px"),dpi:72,schemaVersion:f,bleedVisible:!1,rulesVisible:!1,distanceGuidesVisible:!1,timingPreview:l.optional(l.enumeration("TimingPreview",["all","playhead"]),"all"),openedSidePanel:"",previousOpenedSidePanel:"",custom:l.frozen(),tool:l.optional(l.enumeration("Tool",["selection","draw","pan","text","eraser"]),"selection"),toolOptions:l.optional(l.model({brushType:l.optional(l.enumeration("BrushType",["brush","highlighter"]),"brush"),strokeWidth:l.optional(l.number,5),stroke:l.optional(l.string,"#000000"),opacity:l.optional(l.number,1)}),{}),selectedElementsIds:l.array(l.string),animatedElementsIds:l.array(l.string),history:l.optional(d,{targetPath:"../pages"}),_elementsPixelRatio:Math.min(2,"undefined"!=typeof window&&window.devicePixelRatio||1),_activePageId:"",_selectedPagesIds:l.array(l.string),_forceShowCredit:!1,_validated:!1}).views(e=>{const t=g(()=>{const t={};return C({children:e.pages},e=>(t[e.id]=e,!1)),t},{keepAlive:!0});return{get _idsMap(){return t.get()}}}).views(e=>({get _bleedVisible(){return console.warn("store._bleedVisible is deprecated. Please use store.bleedVisible instead."),e.bleedVisible},get selectedElements(){return e.selectedElementsIds.map(t=>e._idsMap[t]).filter(e=>!!e)},get children(){return e.pages},get selectedShapes(){const e=[];return V({children:this.selectedElements},t=>{"group"!==t.type&&e.push(t)}),e},get activePage(){return e.pages.slice().find(t=>t.id===e._activePageId)||(e.pages.length?e.pages[0]:null)},get selectedPages(){return e._selectedPagesIds.map(t=>e.pages.find(e=>e.id===t))},get duration(){let t=0;return e.pages.forEach(e=>{t+=e.duration}),t},pageAtTime(t){for(const o of e.pages){if(t>=o.startTime&&t<o.startTime+o.duration){return o}}return e.pages.length&&t>=this.duration?e.pages[e.pages.length-1]:null},get effectiveTime(){if(e.isPlaying){return e.currentTime}const t=this.activePage;return t&&this.pageAtTime(e.currentTime)!==t?t.startTime:e.currentTime},get playheadAccurate(){return e.isPlaying||"playhead"===e.timingPreview},get isEditingPaused(){var t;return!e.isPlaying&&!(null===(t=this.activePage)||void 0===t?void 0:t._exportingOrRendering)},get _hasCroppedImages(){return this.find(e=>"image"===e.type&&e._cropModeEnabled)},find(t){let o;return C({children:e.pages},e=>{if(!o&&t(e)){return o=e,!0}}),o},getElementById:t=>e._idsMap[t]})).actions(r=>{let l=0,d=null,g=!1;const f={afterCreate(){r.history.canUndo},setCurrentTime(e){r.currentTime=e},_togglePlaying(e=!r.isPlaying){r.isPlaying=e},play({animatedElementsIds:e=[],startTime:t=0,currentTime:i=0,endTime:n=r.duration,repeat:a=!1}={}){i&&(console.warn("currentTime property of store.play() is deprecated. Please use startTime instead."),t=i),r.animatedElementsIds=o(e),r.currentTime=t,r.isPlaying=!0,l=Date.now(),d=n,g=a,requestAnimationFrame(()=>f.seek())},checkActivePage(){const e=r.pageAtTime(r.currentTime);e&&f.selectPage(e.id)},seek(){if(!r.isPlaying){return}const e=Date.now(),t=e-l;l=e,r.currentTime+=t;const o=d||r.duration;r.currentTime>=o&&!g&&(r.currentTime=o),f.checkActivePage(),r.isPlaying&&r.currentTime<o?requestAnimationFrame(()=>f.seek()):r.isPlaying&&g?(r.currentTime=0,requestAnimationFrame(()=>f.seek())):f.pause()},pause(){r.isPlaying=!1,r.animatedElementsIds=o([])},stop(){f.pause(),r.currentTime=0,f.checkActivePage()},__(){r._validated||(y(r._forceShowCredit),r._validated=!0)},set(e){Object.assign(r,e)},setUnit({unit:e,dpi:t}){r.unit=e||r.unit,r.dpi=t||r.dpi},setRole(e){r.role=e},setTool(e){r.tool=e},setToolOptions(e){Object.assign(r.toolOptions,e)},addPage(e){const t=A.create(Object.assign({id:p(10)},e));return r.pages.push(t),r._activePageId=t.id,r._selectedPagesIds=o([]),t},selectPage(e){r._activePageId=e,1===r._selectedPagesIds.length&&(r._selectedPagesIds=o([e]))},selectPages(e){r._selectedPagesIds=o(e),1===r._selectedPagesIds.length&&(r._activePageId=r._selectedPagesIds[0])},selectElements(e){const t=e.map(e=>r.getElementById(e)).filter(e=>!!e);t.sort((e,t)=>{var o,i,n,a;return(null!==(i=null===(o=e.parent)||void 0===o?void 0:o.children.indexOf(e))&&void 0!==i?i:0)-(null!==(a=null===(n=t.parent)||void 0===n?void 0:n.children.indexOf(t))&&void 0!==a?a:0)}),r.selectedElementsIds=o(t.map(e=>e.id))},toggleBleed(e){r.bleedVisible=null!=e?e:!r.bleedVisible},toggleRulers(e){r.rulesVisible=null!=e?e:!r.rulesVisible},setTimingPreview(e){r.timingPreview=e},toggleDistanceGuides(e){r.distanceGuidesVisible=null!=e?e:!r.distanceGuidesVisible},openSidePanel(e){r.openedSidePanel!==e&&(r.previousOpenedSidePanel=r.openedSidePanel,r.openedSidePanel=e)},restoreSidePanel(){const e=r.previousOpenedSidePanel;e&&e!==r.openedSidePanel?r.openedSidePanel=e:r.openedSidePanel="photos"},setScale(e){r.scale=e},_setScaleToFit(e){r.scaleToFit=e},setElementsPixelRatio(e){r._elementsPixelRatio=e},setSize(e,t,o){r.pages.forEach(i=>{i.setSize({width:e,height:t,useMagic:o,softChange:!0})}),r.width=e,r.height=t},setPageZIndex(e,t){const o=r.pages.find(t=>t.id===e);o&&(n(o),r.pages.remove(o),r.pages.splice(t,0,o))},deletePages(e){const t=r.pages.indexOf(r.activePage);e.forEach(e=>{const t=r.pages.find(t=>t.id===e);i(t)});const n=r._selectedPagesIds.filter(e=>r.pages.some(t=>t.id===e)),a=Math.min(r.pages.length-1,t),s=r.pages[a];s&&(r._activePageId=s.id),f.selectPages(n),r.selectedElementsIds=o(r.selectedElementsIds.filter(e=>r.getElementById(e)))},groupElements(e,t={}){const i=e.map(e=>r.getElementById(e)).filter(e=>!!e);if(!i.length){return}const a=i[0].parent;if(!a){return}if(!i.every(e=>e.parent===a)){return void console.warn("store.groupElements: refusing to group elements that do not share a parent. Pass ids whose elements all live under the same page or the same group.")}i.forEach(e=>n(e));const s=a.children.reduce((e,t)=>{var o;if("group"===t.type){const i=null===(o=t.name)||void 0===o?void 0:o.match(/group-(\d+)/);if(i){const t=parseInt(i[1],10);return Math.max(e,t)}}return e},0),l=Object.assign({id:p(10),name:`group-${s+1}`,children:i,type:"group"},t);return a.children.push(l),r.selectedElementsIds=o([l.id]),a.children.find(e=>e.id===l.id)},ungroupElements(e){const t=e.map(e=>r.getElementById(e)),i=[];t.forEach(e=>{if(e&&"group"===e.type){const t=e.parent;if(!t){return}const o=t.children.indexOf(e);e.children.forEach(e=>{i.push(e.id)}),e.children.slice().forEach(e=>{n(e),t.children.push(e)}),t.children.splice(o,1)}}),r.selectedElementsIds=o(i)},deleteElements(e){const t=[];r.find(o=>(e.includes(o.id)&&t.push(o),!1)),t.forEach(e=>{i(e)}),r.selectedElementsIds=o(r.selectedElementsIds.filter(e=>r.getElementById(e)))},on(e,t){if("change"===e){let e=f.toJSON();return s(r,o=>{const i=f.toJSON();!S(e,i)&&(e=i,t(i))})}},async _toCanvas({pixelRatio:e,ignoreBackground:t,pageId:o,mimeType:i,includeBleed:n,_skipTimeout:a,quickMode:s=!1,_exportCanvases:l}={}){var d;const p=e||1;o=o||(null===(d=r.pages[0])||void 0===d?void 0:d.id);const g=r.pages.find(e=>e.id===o);if(!g){throw _("EXPORT_FAILED",`No page for export with id ${o}`,{reason:"page-not-found",pageId:o,availablePageIds:r.pages.map(e=>e.id)})}const u=r._elementsPixelRatio;p>r._elementsPixelRatio&&f.setElementsPixelRatio(p),s?null==g||g.set({_forceMount:!0}):null==g||g.set({_exporting:!0});const h=await k(()=>{const e=c.stages.filter(e=>e.getAttr("pageId")===o);return 0===e.length?null:e});if(!h){throw null==g||g.set({_forceMount:!1,_exporting:!1}),f.setElementsPixelRatio(u),_("EXPORT_FAILED",`Export is failed. Can not find stage for page ${o}. Looks like <Workspace /> component is not mounted, but it is required in order to process the export.`,{reason:"workspace-not-mounted",pageId:o})}h.length>1&&console.error(`Polotno error: Detected several canvas elements for page "${o}" in the document. This is not supported and will lead to incorrect export. Make sure to use unique ids for all pages and make sure you unmount <Workspace /> when it is not needed.`);const v=h[0];await f.waitLoading({_skipTimeout:a});const b=v.findOne(".page-container");if(!b){throw f.setElementsPixelRatio(u),null==g||g.set({_forceMount:!1,_exporting:!1}),_("EXPORT_FAILED","Export is failed. Canvas was unmounted.",{reason:"unmounted-during-export",pageId:o})}const y=v.position();v.position({x:0,y:0}),v.find("Transformer").forEach(e=>{e.setAttr("oldVisible",e.visible()),e.visible(!1)}),b.find(".page-background").forEach(e=>e.shadowEnabled(!1)),b.find(".page-background").forEach(e=>e.strokeEnabled(!1)),b.find(".highlighter").forEach(e=>e.visible(!1));const P=b.findOne(".page-background-group"),w=P.clip();P.clip({x:null,y:null,width:null,height:null});const x=b.findOne(".elements-container"),E=x.clip();x.clip({x:null,y:null,width:null,height:null});const T=b.find(e=>!e.visible()&&e.getAttr("editModeEnabled")&&!e.getAttr("hideInExport"));T.forEach(e=>{e.setAttr("oldVisible",e.visible()),e.show()});const O=b.find(e=>e.getAttr("hideInExport"));O.forEach(e=>{e.setAttr("oldVisible",e.visible()),e.hide()}),t&&b.find(".page-background").forEach(e=>e.hide());const S=n?g.computedBleed:m;let j=S.left,R=S.top;!r.bleedVisible&&n||(r.bleedVisible||n?r.bleedVisible&&n?(j=0,R=0):r.bleedVisible&&!n&&(j=-g.computedBleed.left,R=-g.computedBleed.top):(j=0,R=0));const F=g.computedWidth+S.left+S.right,A=g.computedHeight+S.top+S.bottom,V=b.scale();b.scale({x:1,y:1});const C=I(b,{x:b.x()-j,y:b.y()-R,width:F,height:A,pixelRatio:p,sceneCanvas:null==l?void 0:l.sceneCanvas,bufferCanvas:null==l?void 0:l.bufferCanvas});b.scale(V);const L=C._canvas;if("image/jpeg"===i){const e=L.getContext("2d");e.save(),e.globalCompositeOperation="destination-over",e.fillStyle="white",e.fillRect(0,0,L.width,L.height),e.restore()}return t&&b.find(".page-background").forEach(e=>e.show()),O.forEach(e=>{e.visible(e.getAttr("oldVisible"))}),T.forEach(e=>{e.visible(e.getAttr("oldVisible"))}),b.find(".page-background").forEach(e=>e.shadowEnabled(!0)),b.find(".page-background").forEach(e=>e.strokeEnabled(!0)),v.find("Transformer").forEach(e=>{e.visible(e.getAttr("oldVisible"))}),b.find(".highlighter").forEach(e=>e.visible(!0)),P.clip(w),x.clip(E),v.position(y),null==g||g.set({_exporting:!1,_forceMount:!1}),await Promise.resolve(),f.setElementsPixelRatio(u),L},async toDataURL(t={}){var{mimeType:o,quality:i,dpi:n,dpiMetadata:a="auto"}=t,s=e(t,["mimeType","quality","dpi","dpiMetadata"]);const l=await f._toCanvas(Object.assign({mimeType:o},s)),d=o||"image/png",p=l.toDataURL(d,i);c.Util.releaseCanvas(l);const g=null!=n?n:r.dpi;return"image/png"!==d&&"image/jpeg"!==d||"never"===a||"auto"===a&&72===g?p:E(p,d,g)},async toBlob(t={}){var{mimeType:o,quality:i}=t,n=e(t,["mimeType","quality"]);const a=await f._toCanvas(Object.assign({mimeType:o},n)),s=await new Promise(e=>{a.toBlob(e,o,i)});return c.Util.releaseCanvas(a),s},async saveAsImage(t={}){var{fileName:o}=t,i=e(t,["fileName"]);const n=(i.mimeType||"image/png").split("/")[1];h(await f.toDataURL(i),o||"polotno."+n)},async _toPDF(e){const t=e.dpi||r.dpi,o=e.parallel||1,i=e.unit||("px"===r.unit?"mm":r.unit),n=e.pixelRatio||1,a=e.pageIds||(e.pageId?[e.pageId]:r.pages.map(e=>e.id)),s=r.pages.filter(e=>a.includes(e.id)),l=await v(),d=e=>O({px:e,unit:i,dpi:t}),p=e.cropMarkSize||0,c=d(p),g=s[0]||{},u=e.includeBleed&&g.computedBleed||m,h=d(g.computedWidth+u.left+u.right+2*c),b=d(g.computedHeight+u.top+u.bottom+2*c);var y=new l({unit:i,orientation:h>b?"landscape":"portrait",format:[h,b],compress:!0,putOnlyUsedFonts:!0});y.deletePage(1);const P=((e,t)=>{const o=[];for(let i=0;i<e.length;i+=t){o.push(e.slice(i,i+t))}return o})(s,o);let w=0;for(const r of P){const t=r.map(async t=>{const o=e.includeBleed?t.computedBleed:m,i=t.computedWidth+o.left+o.right+2*p,s=t.computedHeight+o.top+o.bottom+2*p,r=d(i),l=d(s);let c=0,g=n;for(;c<10;){c+=1;const d=await f.toDataURL(Object.assign(Object.assign({},e),{pageId:t.id,pixelRatio:g,dpiMetadata:"never"}));if(d.length>20){return g!==n&&console.error(`Polotno can not export PDF with current settings. Quality is automatically reduced. pixelRatio was reduced to ${parseFloat(g.toFixed(3))}.`),e.onProgress&&e.onProgress(++w/a.length*.9),{url:d,width:r,height:l,widthPx:i,heightPx:s,cb:o}}g*=.8}});(await Promise.all(t)).filter(e=>void 0!==e).forEach(({url:e,width:t,height:o,widthPx:n,heightPx:a,cb:s})=>{y.addPage([t,o],t>o?"landscape":"portrait");const r=y.getCurrentPageInfo();var l;switch(i){case"pt":l=1;break;case"mm":l=72/25.4;break;case"cm":l=72/2.54;break;case"in":l=72;break;case"px":l=.75;break;default:throw _("EXPORT_FAILED","Invalid unit: "+i,{reason:"invalid-options",option:"unit",value:i})}if(r.pageContext.cropBox={bottomLeftX:0,bottomLeftY:0,topRightX:t*l,topRightY:o*l},r.pageContext.artBox={bottomLeftX:d(p+s.left)*l,bottomLeftY:d(p+s.bottom)*l,topRightX:d(n-p-s.right)*l,topRightY:d(a-p-s.top)*l},r.pageContext.bleedBox={bottomLeftX:d(p+s.left)*l,bottomLeftY:d(p+s.bottom)*l,topRightX:d(n-p-s.right)*l,topRightY:d(a-p-s.top)*l},c){y.setLineWidth(d(1));const e=c+d(s.left),i=c+d(s.right),n=c+d(s.top),a=c+d(s.bottom);y.line(e,0,e,c),y.line(0,n,c,n),y.line(t-i,0,t-i,c),y.line(t,n,t-c,n),y.line(0,o-a,c,o-a),y.line(e,o,e,o-c),y.line(t,o-a,t-c,o-a),y.line(t-i,o,t-i,o-c)}y.addImage(e,c,c,t-2*c,o-2*c,void 0,"FAST")})}return y},toPDFDataURL:async e=>(await f._toPDF(Object.assign({mimeType:"image/jpeg"},e))).output("datauristring"),async toGIFDataURL(e={}){const t=e.pixelRatio||1,o=e.pageIds||(e.pageId?[e.pageId]:r.pages.map(e=>e.id)),i=r.pages.filter(e=>o.includes(e.id));if(!i.length){throw _("EXPORT_FAILED","No pages found for GIF export",{reason:"page-not-found",pageId:e.pageId,availablePageIds:r.pages.map(e=>e.id)})}const n=i[0],a=await b({width:n.computedWidth*t,height:n.computedHeight*t}),s=1e3/(e.fps||10);for(const l of i){const e=Math.max(1,Math.floor(l.duration/s));for(let o=0;o<e;o++){const e=l.startTime+o*s||1;f.setCurrentTime(e);for(const t of r.pages){t.set({_rendering:t.id===l.id})}const i=await f._toCanvas({pixelRatio:t,pageId:l.id,_skipTimeout:!0});a.addFrame(i.getContext("2d"),{delay:s,copy:!0})}}for(const l of r.pages){l.set({_rendering:!1})}return f.stop(),a.render(),new Promise(e=>{a.on("finished",function(t){!function(e,t){var o=new FileReader;o.onload=function(e){t(e.target.result)},o.readAsDataURL(e)}(t,e)})})},async saveAsGIF(t={}){var{fileName:o}=t,i=e(t,["fileName"]);const n=await f.toGIFDataURL(i);h(n,o||"polotno.gif")},async toHTML({elementHook:e}={}){F("store.toHTML","store.toHTML()/saveAsHTML() are deprecated: install @polotno/html-export and call jsonToHTML(store.toJSON()) instead");const t=f.toJSON();return j(t,{elementHook:e,textOverflow:x.textOverflow,textSplitAllowed:x.textSplitAllowed})},async saveAsHTML({fileName:e,elementHook:t}={}){const o=await f.toHTML({elementHook:t}),i="data:text/html;base64,"+window.btoa(unescape(encodeURIComponent(o)));h(i,e||"polotno.html")},async toSVG({elementHook:e,pageId:t,fontEmbedding:o="inline"}={fontEmbedding:"inline"}){var i;F("store.toSVG","store.toSVG()/saveAsSVG() are deprecated: install @polotno/svg-export and call jsonToSVG(store.toJSON()) instead");const n=f.toJSON();t=t||(null===(i=n.pages[0])||void 0===i?void 0:i.id);const a=n.pages.find(e=>e.id===t);return R(Object.assign(Object.assign({},n),{pages:a?[a]:[]}),{elementHook:e,fontEmbedding:o})},async saveAsSVG({fileName:e,elementHook:t,pageId:o,fontEmbedding:i="inline"}={}){const n=await f.toSVG({elementHook:t,pageId:o,fontEmbedding:i}),a="data:text/svg;base64,"+window.btoa(unescape(encodeURIComponent(n)));h(a,e||"polotno.svg")},async saveAsPDF(t={}){var{fileName:o}=t,i=e(t,["fileName"]);(await f._toPDF(Object.assign({mimeType:"image/jpeg"},i))).save(o||"polotno.pdf")},async waitLoading({_skipTimeout:e=!1}={}){e||await new Promise(e=>setTimeout(e,50)),await T()},toJSON:()=>({width:r.width,height:r.height,fonts:a(r.fonts),pages:a(r.pages),audios:a(r.audios),unit:r.unit,dpi:r.dpi,custom:r.custom,schemaVersion:r.schemaVersion}),loadJSON(e,o=!1){var i,n,s;const l="boolean"==typeof o?o:null!==(i=null==o?void 0:o.keepHistory)&&void 0!==i&&i,d="boolean"!=typeof o&&null!==(n=null==o?void 0:o.modernizeTextBackground)&&void 0!==n&&n,p=u(e,{modernTextRenderer:x.htmlRenderEnabled||x.renderTagTextEnabled,modernizeTextBackground:d});delete p.schemaVersion;const c=r.activePage?r.pages.indexOf(r.activePage):0;let g=null===(s=p.pages[c]||p.pages[0])||void 0===s?void 0:s.id;p._activePageId=g,p._selectedPagesIds=[];const m=Object.assign({},a(r));Object.assign(m,p),m.history=l?a(r.history):{history:[],undoIdx:-1,targetPath:""},t(r,m)},clear({keepHistory:e=!1}={}){const t=r.pages.map(e=>e.id);f.deletePages(t),r.custom=null,e||r.history.clear()},addFont(e){f.removeFont(e.fontFamily),r.fonts.push(e)},removeFont(e){r.fonts.filter(t=>t.fontFamily===e).forEach(e=>i(e))},addAudio(e){const t=L.create(Object.assign({id:p(10)},e));r.audios.push(t)},removeAudio(e){const t=r.audios.find(t=>t.id===e);t&&r.audios.remove(t)},async loadFont(e,t,o,i){const n=r.fonts.find(t=>t.fontFamily===e)||w.globalFonts.find(t=>t.fontFamily===e);let a=[{fontStyle:"normal",fontWeight:"normal"},{fontStyle:"normal",fontWeight:"bold"}];return n?(n.styles&&(a=n.styles.map(e=>({fontStyle:e.fontStyle||"normal",fontWeight:e.fontWeight||"normal"}))),w.injectCustomFont(n)):w.injectGoogleFont(e),t&&o&&!a.some(e=>e.fontStyle===t&&e.fontWeight===o)&&a.push({fontStyle:t,fontWeight:o}),Promise.all(a.map(t=>w.loadFont(e,t.fontStyle,t.fontWeight,i)))},validate:e=>Store.validate(e,[{path:"",type:Store}]).map(e=>({path:"store"+e.context.map(e=>e.path).join("."),message:e.message}))};return f});export function createStore({key:e,showCredit:t}={key:"",showCredit:!1}){return P(e),Store.create({_forceShowCredit:t})}export default createStore;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "polotno",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.0",
|
|
4
4
|
"description": "Design Editor Framework",
|
|
5
5
|
"author": "Anton Lavrenov",
|
|
6
6
|
"keywords": [
|
|
@@ -96,10 +96,10 @@
|
|
|
96
96
|
},
|
|
97
97
|
"dependencies": {
|
|
98
98
|
"@base-ui/react": "^1.6.0",
|
|
99
|
-
"@polotno/core": "0.
|
|
100
|
-
"@polotno/html-export": "0.
|
|
101
|
-
"@polotno/schema": "0.
|
|
102
|
-
"@polotno/svg-export": "0.
|
|
99
|
+
"@polotno/core": "0.4.0",
|
|
100
|
+
"@polotno/html-export": "0.2.0",
|
|
101
|
+
"@polotno/schema": "0.4.0",
|
|
102
|
+
"@polotno/svg-export": "0.2.0",
|
|
103
103
|
"class-variance-authority": "^0.7.1",
|
|
104
104
|
"clsx": "^2.1.1",
|
|
105
105
|
"gifuct-js": "^2.1.2",
|
|
@@ -205,11 +205,11 @@
|
|
|
205
205
|
"check:parity": "node build/structural-parity.cjs",
|
|
206
206
|
"test:parity": "pnpm run check:parity && pnpm run check:agreement && pnpm run check:css",
|
|
207
207
|
"minify": "node minify.cjs",
|
|
208
|
-
"build": "pnpm run
|
|
208
|
+
"build": "pnpm run clean && pnpm run prefix-build && pnpm run tsc && pnpm run add_version && node rename-imports.js && pnpm run minify && pnpm run build:css && pnpm run check:css && pnpm run check:agreement && pnpm run build:bundle && node blueprint-scope.js && cp ./src/fonts.css ./lib/fonts.css && mkdir -p ./lib/themes && cp ./src/themes/blueprint.css ./lib/themes/blueprint.css && cp ./src/themes/carbon.css ./lib/themes/carbon.css && node build/copy-package-json.cjs && cp ./README.md ./lib && cp ./LICENSE.md ./lib && pnpm run remove-test-from-lib",
|
|
209
209
|
"remove-test-from-lib": "find ./lib -type d -name \"__tests__\" -exec rm -rf {} + && find ./lib \\( -name \"*.test.js\" -o -name \"*.test.d.ts\" \\) -type f -delete",
|
|
210
210
|
"add_version": "sed -i.bak 's/SDK_VERSION/'$npm_package_version'/' ./lib/utils/validate-key.js && rm -f ./lib/utils/validate-key.js.bak",
|
|
211
211
|
"build:bundle": "vite build && find ./lib -name '*.js.map' -type f -delete",
|
|
212
|
-
"test": "
|
|
212
|
+
"test": "node scripts/run-tests-parallel.mjs",
|
|
213
213
|
"test:unit": "vitest run --project unit",
|
|
214
214
|
"test:browser": "node scripts/run-browser-sharded.mjs",
|
|
215
215
|
"test:serial": "vitest run"
|
|
@@ -3,11 +3,12 @@ import type { AudioType } from '../model/audio-model.js';
|
|
|
3
3
|
import type { StoreType } from '../ui-types.js';
|
|
4
4
|
export declare const AUDIO_ROW_HEIGHT = 28;
|
|
5
5
|
export declare const AUDIO_TRACK_HEIGHT = 24;
|
|
6
|
-
export declare const AudioTrack: (({ audio, scale, store,
|
|
6
|
+
export declare const AudioTrack: (({ audio, scale, store, label, row, }: {
|
|
7
7
|
audio: AudioType;
|
|
8
8
|
scale: number;
|
|
9
9
|
store: StoreType;
|
|
10
|
-
|
|
10
|
+
label: string;
|
|
11
|
+
row: number;
|
|
11
12
|
}) => React.JSX.Element) & {
|
|
12
13
|
displayName: string;
|
|
13
14
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=this&&this.__rest||function(e,t){var n={};for(var i in e){Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(i=Object.getOwnPropertySymbols(e);o<i.length;o++){t.indexOf(i[o])<0&&Object.prototype.propertyIsEnumerable.call(e,i[o])&&(n[i[o]]=e[i[o]])}}return n};import{jsx as t,jsxs as n}from"react/jsx-runtime";import i from"react";import{observer as o}from"mobx-react-lite";import{PolotnoIcon as
|
|
1
|
+
var e=this&&this.__rest||function(e,t){var n={};for(var i in e){Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(i=Object.getOwnPropertySymbols(e);o<i.length;o++){t.indexOf(i[o])<0&&Object.prototype.propertyIsEnumerable.call(e,i[o])&&(n[i[o]]=e[i[o]])}}return n};import{jsx as t,jsxs as n}from"react/jsx-runtime";import i from"react";import{observer as o}from"mobx-react-lite";import{PolotnoIcon as a}from"../icons/registry.js";import{t as s}from"../utils/l10n.js";import{firstSliderValue as r}from"../lib/utils.js";import{DropdownMenu as l,DropdownMenuContent as m,DropdownMenuItem as d,DropdownMenuSeparator as p}from"../primitives/dropdown-menu.js";import{Slider as c}from"../primitives/slider.js";import{SpeedControl as u}from"../primitives/speed-control.js";import{Spinner as h}from"./spinner.js";import{useWaveformData as v,useWaveformPath as f}from"./waveform.js";import{TrackWrapper as x,TrackContainer as y,TrackMenu as g,TrackMenuButton as M,TrackHandleLeft as T,TrackHandleRight as w,TrackInlineLabel as b,TrackNameInput as j,WaveformSvg as I}from"./track-styles.js";export const AUDIO_ROW_HEIGHT=28;export const AUDIO_TRACK_HEIGHT=24;const D=({position:e,store:t,scale:n})=>{const i=t.pages;for(const o of i){const t=o.startTime,i=o.startTime+o.duration;if(Math.abs(e-t)<10/n){return t}if(Math.abs(e-i)<10/n){return i}}return null};export const AudioTrack=o(({audio:o,scale:O,store:E,label:S,row:A})=>{const[C,L]=i.useState(1),N=i.useRef(null),[P,_]=i.useState(!1),z=0===o.volume,X=()=>{z?o.set({volume:C>0?C:1}):(L(o.volume),o.set({volume:0}))},k=(e=o.startTime,t=o.endTime,n=o.speed)=>Math.max(0,(t-e)*(o.duration||0)/n),H=e=>Math.max(0,E.duration-e),R=(e,t=k())=>Math.min(Math.max(0,e),H(t)),$=k(),B=E.duration*O-o.delay*O,V=Math.min($*O,B),Y=o.delay*O,{data:F,isLoading:G}=v(o.src),U=o.visibleDuration*O,J=f(F,20).path,K=(e,t)=>{e.stopPropagation(),e.preventDefault();const n=e.clientX,i=Y,a=V,s=o.endTime,r=o.startTime,l=o.delay,m=o.duration||1,d=o.speed,p=e=>{e.preventDefault();const p=(e.clientX-n)/O;if("start"===t){if(p>=0){const e=p*d,t=Math.max(0,s-.1-r)*m,n=Math.min(e,t);if(n<=0){return}let i=r+n/m;const a=(o.endTime-i)*m/d,c=l+n/d,u=H(a);let h=Math.min(Math.max(0,c),u);const v=D({position:h,store:E,scale:O});h=Math.min(Math.max(0,null!=v?v:h),u);const f=h-c;i=Math.min(o.endTime-.1,Math.max(0,i+f*d/m)),o.set({delay:h,startTime:i})}else{const e=-p*d,t=r*m,n=Math.min(e,t);if(n<=0){return}const i=n/m;let a=Math.max(0,r-i);const s=(o.endTime-a)*m/d,c=l-n/d,u=H(s);let h=Math.min(Math.max(0,c),u);const v=D({position:h,store:E,scale:O});h=Math.min(Math.max(0,null!=v?v:h),u);const f=h-c;a=Math.max(0,Math.min(o.endTime-.1,a+f*d/m)),o.set({delay:h,startTime:a})}}else{const e=i/O+a/O;let t=e+p;const n=D({position:t,store:E,scale:O});t=null!=n?n:t;const r=(t-e)*d/o.duration,l=Math.min(1,Math.max(o.startTime+.1,s+r));o.set({endTime:l})}},c=()=>{if(window.removeEventListener("mousemove",p),window.removeEventListener("mouseup",c),"start"===t){const e=D({position:o.delay,store:E,scale:O});if(null!=e&&e!==o.delay){const t=k(o.startTime,o.endTime),n=R(e,t),i=n-o.delay,a=Math.max(0,Math.min(o.endTime-.1,o.startTime+i*d/m));o.set({delay:n,startTime:a})}}};window.addEventListener("mousemove",p),window.addEventListener("mouseup",c)};return t(x,{ref:N,style:{left:`${Y}px`,top:28*A+"px",width:`${V}px`,height:"24px"},className:"polotno-audio-container",children:n(y,{style:{width:"100%",height:"100%"},onMouseDown:e=>{const t=e.clientX,n=Y;e.preventDefault();const i=e=>{e.preventDefault();const i=(e.clientX-t)/O;let a=n/O+i;const s=a+$,r=D({position:a,store:E,scale:O}),l=D({position:s,store:E,scale:O}),m=null!==r?Math.abs(a-r):Number.POSITIVE_INFINITY,d=null!==l?Math.abs(s-l):Number.POSITIVE_INFINITY;let p;p=R(null!==r&&m<d?r:null!==l?l-$:a),o.set({delay:R(p)})},a=()=>{window.removeEventListener("mousemove",i),window.removeEventListener("mouseup",a)};window.addEventListener("mousemove",i),window.addEventListener("mouseup",a)},children:[t("div",{style:{position:"absolute",left:"4px",top:"50%",transform:"translateY(-50%)",zIndex:10,pointerEvents:"auto"},onClick:e=>{e.stopPropagation(),X()},onMouseDown:e=>e.stopPropagation(),children:t(a,z?{name:"action.muted",className:"pn:size-3.5",style:{opacity:.7,cursor:"pointer"}}:{name:"action.unmuted",className:"pn:size-3.5",style:{opacity:.7,cursor:"pointer"}})}),t("div",{style:{position:"absolute",inset:"0 0 0 0",display:"flex",alignItems:"center",justifyContent:"center",pointerEvents:"none"},children:n("div",{style:{display:"flex",alignItems:"center",width:"100%",height:"100%",gap:"8px",paddingLeft:"22px"},children:[!P&&t(b,{children:S}),J&&t("div",{style:{flex:1,height:"14px",overflow:"hidden",opacity:z?.4:1},children:t(I,{width:U,height:"14",viewBox:`0 0 ${U} 20`,preserveAspectRatio:"none",style:{width:U+"px",height:"14px",transform:`translateX(-${o.startTime*U}px)`},children:t("path",{d:J})})}),G&&t("div",{style:{flex:1,display:"flex",justifyContent:"center",alignItems:"center"},children:t(h,{})})]})}),P&&t(j,{value:o.name,onCommit:e=>{o.set({name:e}),_(!1)},onCancel:()=>_(!1)}),t(T,{onMouseDown:e=>K(e,"start")}),t(w,{onMouseDown:e=>K(e,"end")}),t(g,{onClick:e=>{e.stopPropagation()},onMouseDown:e=>e.stopPropagation(),children:n(l,{children:[t(M,{}),n(m,{side:"top",align:"start",anchor:N,style:{width:"220px"},children:[n("div",{style:{padding:"8px 12px"},children:[n("div",{style:{fontSize:"12px",marginBottom:"6px",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t("span",{children:s("pagesTimeline.volume")}),n("span",{children:[Math.round(100*o.volume),"%"]})]}),t(c,{value:[o.volume],min:0,max:1,step:.01,onValueChange:e=>(e=>{const t=Math.max(0,Math.min(1,e));t>0&&L(t),o.set({volume:t})})(r(e))})]}),n("div",{style:{padding:"8px 12px"},children:[t("div",{style:{fontSize:"12px",marginBottom:"6px"},children:s("pagesTimeline.speed")}),t(u,{value:o.speed,onChange:e=>{const t=k(o.startTime,o.endTime,e);o.set({speed:e,delay:R(o.delay,t)})}})]}),t(p,{}),n(d,{onSelect:e=>{e.preventDefault(),_(!0)},children:[t(a,{name:"action.rename"}),s("pagesTimeline.renameAudio")]}),n(d,{onSelect:e=>{e.preventDefault(),X()},children:[t(a,z?{name:"action.unmuted"}:{name:"action.muted"}),s(z?"pagesTimeline.unmuteAudio":"pagesTimeline.muteAudio")]}),n(d,{onSelect:t=>{t.preventDefault(),(()=>{const t=o.toJSON(),n=o.visibleDuration,i=o.delay+n,a=E.duration-i;let s=o.delay;a>=n?s=i:a>0&&(s=Math.max(0,E.duration-n));const{id:r}=t,l=e(t,["id"]);E.addAudio(Object.assign(Object.assign({},l),{delay:s}))})()},children:[t(a,{name:"action.duplicate"}),s("pagesTimeline.duplicateAudio")]}),t(p,{}),n(d,{onSelect:e=>{e.preventDefault(),E.removeAudio(o.id)},children:[t(a,{name:"action.remove"}),s("pagesTimeline.removeAudio")]})]})]})})]})})});
|
package/pages-timeline/audios.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as
|
|
1
|
+
import{jsx as o}from"react/jsx-runtime";import{observer as t}from"mobx-react-lite";import{packRows as i}from"../utils/pack-rows.js";import{AudioTrack as a,AUDIO_ROW_HEIGHT as e}from"./audio-track.js";export const Audios=t(({store:t,scale:r,width:s})=>{const m=(n=t.audios,i(n.map(o=>({item:o,start:o.delay,end:o.delay+o.visibleDuration}))));var n;const d=m.reduce((o,t)=>Math.max(o,t.row),-1)+1,l=Math.max(d,1)*e;return m.length?o("div",{style:{position:"relative",minWidth:s+"px",height:l+"px",marginTop:"12px"},className:"polotno-audios-container",children:m.map(({item:i,row:e})=>o(a,{audio:i,scale:r,store:t,label:i.name||`audio-${t.audios.indexOf(i)+1}`,row:e},i.id))}):null});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e,jsxs as t}from"react/jsx-runtime";import n from"react";import{observer as o}from"mobx-react-lite";import{PolotnoIcon as i}from"../icons/registry.js";import{duplicateElements as s}from"../utils/duplicate.js";import{clamp as r}from"../lib/utils.js";import{getElementTimeRange as l,MIN_DURATION as
|
|
1
|
+
import{jsx as e,jsxs as t}from"react/jsx-runtime";import n from"react";import{observer as o}from"mobx-react-lite";import{PolotnoIcon as i}from"../icons/registry.js";import{duplicateElements as s}from"../utils/duplicate.js";import{clamp as r}from"../lib/utils.js";import{getElementTimeRange as l,MIN_DURATION as a,revealElementAtPlayhead as m}from"../utils/timeline.js";import{canSplitAtPlayhead as c,splitElementAtPlayhead as p}from"../utils/split-element.js";import{t as d}from"../utils/l10n.js";import{DropdownMenu as u,DropdownMenuContent as v,DropdownMenuItem as f}from"../primitives/dropdown-menu.js";import{TrackWrapper as w,TrackContainer as x,TrackMenu as h,TrackMenuButton as E,TrackHandleLeft as D,TrackHandleRight as j,TrackLabel as y,TrackNameInput as M}from"./track-styles.js";export const ELEMENT_ROW_HEIGHT=26;const g=o(({element:n,store:o})=>{var s;const r=o.effectiveTime-((null===(s=n.page)||void 0===s?void 0:s.startTime)||0),l=c(n,r);return t(f,{disabled:!l,onSelect:e=>{e.preventDefault();const t=p(n,r);t&&o.selectElements([t.id])},children:[e(i,{name:"action.split"}),d("contextMenu.split")]})}),L=(e,t)=>{const n=e.animations.find(e=>e.type===t);n&&n.enabled||e.setAnimation(t,{name:"none",enabled:!0})},b=(e,t,n,o)=>{const i=r(n,0,t-a),s=r(o,i+a,t);L(e,"enter"),L(e,"exit"),e.setAnimation("enter",{delay:i}),e.setAnimation("exit",{delay:Math.max(0,t-s)})};export const ElementTrack=o(({element:o,page:c,store:p,scale:L,row:S})=>{const T=c.duration,P=c.startTime,X=P+T,{start:k,end:A}=l(o.animations,T),C=(A-k)*L,H=(P+k)*L,N=o.name||o.type||d("toolbar.element"),[O,W]=n.useState(!1),[$,_]=n.useState(null),G=()=>{_(e=>null===e?S:e)},I=()=>{_(null)},R=(e,t)=>{e.preventDefault(),e.stopPropagation(),G();const n=e.clientX,i=k,s=A,l=e=>{e.preventDefault();const l=(e.clientX-n)/L;if("start"===t){const e=r(P+i+l,P,P+s-a);b(o,T,e-P,s)}else{const e=r(P+s+l,P+i+a,X);b(o,T,i,e-P)}},m=()=>{window.removeEventListener("mousemove",l),window.removeEventListener("mouseup",m),I()};window.addEventListener("mousemove",l),window.addEventListener("mouseup",m)};return e(w,{style:{left:`${H}px`,top:26*(null!=$?$:S)+"px",width:`${C}px`,minWidth:"6px",height:"22px"},children:t(x,{style:{width:"100%",height:"100%",outline:p.selectedElements.find(e=>e.id===o.id)?"2px solid var(--pn-primary, var(--primary, #137cbd))":"none",outlineOffset:"-1px"},onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),G();const t=e.clientX,n=k,i=A-n;let s=!1;const l=e=>{e.preventDefault(),s=!0;const l=(e.clientX-t)/L,a=r(P+n+l,P,X-i)-P;b(o,T,a,a+i)},a=()=>{window.removeEventListener("mousemove",l),window.removeEventListener("mouseup",a),I(),s||(p.selectElements([o.id]),m(o))};window.addEventListener("mousemove",l),window.addEventListener("mouseup",a)},children:[O?e(M,{value:o.name||"",onCommit:e=>{o.set({name:e}),W(!1)},onCancel:()=>W(!1)}):e(y,{children:N}),e(D,{onMouseDown:e=>R(e,"start")}),e(j,{onMouseDown:e=>R(e,"end")}),e(h,{onMouseDown:e=>e.stopPropagation(),onClick:e=>e.stopPropagation(),children:t(u,{children:[e(E,{}),t(v,{side:"top",className:"pn:whitespace-nowrap",children:[e(g,{element:o,store:p}),t(f,{onSelect:e=>{e.preventDefault(),W(!0)},children:[e(i,{name:"action.rename"}),d("contextMenu.rename")]}),t(f,{onSelect:e=>{e.preventDefault(),s([o],p)},children:[e(i,{name:"action.duplicate"}),d("contextMenu.duplicate")]}),t(f,{onSelect:e=>{e.preventDefault(),p.deleteElements([o.id])},children:[e(i,{name:"action.remove"}),d("contextMenu.remove")]})]})]})})]})})});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from './pages-timeline.js';
|
package/pages-timeline/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from './pages-timeline.js';
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
export declare const TrackLabel: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
|
|
3
|
+
export declare const TrackInlineLabel: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
|
|
4
|
+
export declare const TrackNameInput: {
|
|
5
|
+
({ value, onCommit, onCancel, className, ...props }: {
|
|
6
|
+
value: string;
|
|
7
|
+
onCommit: (value: string) => void;
|
|
8
|
+
onCancel: () => void;
|
|
9
|
+
} & Omit<React.InputHTMLAttributes<HTMLInputElement>, "value" | "onChange" | "onCommit">): React.JSX.Element;
|
|
10
|
+
displayName: string;
|
|
11
|
+
};
|
|
3
12
|
export declare const WaveformSvg: React.ForwardRefExoticComponent<React.SVGAttributes<SVGSVGElement> & React.RefAttributes<SVGSVGElement>>;
|
|
4
13
|
export declare const TrackWrapper: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
|
|
5
14
|
export declare const TrackContainer: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=this&&this.__rest||function(e,
|
|
1
|
+
var e=this&&this.__rest||function(e,n){var a={};for(var r in e){Object.prototype.hasOwnProperty.call(e,r)&&n.indexOf(r)<0&&(a[r]=e[r])}if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var t=0;for(r=Object.getOwnPropertySymbols(e);t<r.length;t++){n.indexOf(r[t])<0&&Object.prototype.propertyIsEnumerable.call(e,r[t])&&(a[r[t]]=e[r[t]])}}return a};import{jsx as n}from"react/jsx-runtime";import a from"react";import{PolotnoIcon as r}from"../icons/registry.js";import{cn as t}from"../lib/utils.js";import{Button as p}from"../primitives/button.js";import{DropdownMenuTrigger as o}from"../primitives/dropdown-menu.js";export const TrackLabel=a.forwardRef((a,r)=>{var{className:p}=a,o=e(a,["className"]);return n("div",Object.assign({ref:r,className:t("pn:pointer-events-none pn:absolute pn:inset-0 pn:flex pn:items-center pn:overflow-hidden pn:text-ellipsis pn:whitespace-nowrap pn:px-3 pn:text-[11px] pn:font-medium pn:text-black/75 pn:dark:text-white/[0.92]",p)},o))});TrackLabel.displayName="TrackLabel";export const TrackInlineLabel=a.forwardRef((a,r)=>{var{className:p}=a,o=e(a,["className"]);return n("div",Object.assign({ref:r,className:t("pn:pointer-events-none pn:max-w-[45%] pn:flex-none pn:overflow-hidden pn:text-ellipsis pn:whitespace-nowrap pn:text-[11px] pn:font-medium pn:text-black/75 pn:dark:text-white/[0.92]",p)},o))});TrackInlineLabel.displayName="TrackInlineLabel";export const TrackNameInput=r=>{var{value:p,onCommit:o,onCancel:s,className:i}=r,c=e(r,["value","onCommit","onCancel","className"]);const[l,m]=a.useState(p),f=a.useRef(!1);return n("input",Object.assign({autoFocus:!0,value:l,onFocus:e=>e.target.select(),onChange:e=>m(e.target.value),onBlur:()=>{f.current||(f.current=!0,o(l.trim()))},onKeyDown:e=>{e.stopPropagation(),"Enter"===e.key?(e.preventDefault(),e.target.blur()):"Escape"===e.key&&(e.preventDefault(),f.current=!0,s())},onMouseDown:e=>e.stopPropagation(),onClick:e=>e.stopPropagation(),className:t("pn:absolute pn:inset-0 pn:z-30 pn:w-full pn:rounded-[10px] pn:bg-white/85 pn:px-3 pn:outline-none pn:ring-1 pn:ring-primary pn:text-[11px] pn:font-medium pn:text-black/75 pn:dark:bg-black/70 pn:dark:text-white/[0.92]",i)},c))};TrackNameInput.displayName="TrackNameInput";export const WaveformSvg=a.forwardRef((a,r)=>{var{className:p}=a,o=e(a,["className"]);return n("svg",Object.assign({ref:r,className:t("pn:[&_path]:fill-black/50 pn:dark:[&_path]:fill-white/70",p)},o))});WaveformSvg.displayName="WaveformSvg";export const TrackWrapper=a.forwardRef((a,r)=>{var{className:p}=a,o=e(a,["className"]);return n("div",Object.assign({ref:r,className:t("pn:absolute pn:[&:hover_.polotno-track-menu]:pointer-events-auto pn:[&:hover_.polotno-track-menu]:opacity-100",p)},o))});TrackWrapper.displayName="TrackWrapper";export const TrackContainer=a.forwardRef((a,r)=>{var{className:p,style:o}=a,s=e(a,["className","style"]);return n("div",Object.assign({ref:r,className:t("pn:absolute pn:cursor-move pn:overflow-hidden pn:rounded-[10px] pn:border pn:border-primary/55 pn:bg-gradient-to-br pn:from-primary/15 pn:to-primary/35 pn:shadow-sm",p),style:o},s))});TrackContainer.displayName="TrackContainer";export const TrackMenu=a.forwardRef((a,r)=>{var{className:p}=a,o=e(a,["className"]);return n("div",Object.assign({ref:r,className:t("polotno-track-menu pn:pointer-events-none pn:absolute pn:top-1/2 pn:right-3 pn:z-20 pn:-translate-y-1/2 pn:opacity-0",p)},o))});TrackMenu.displayName="TrackMenu";export const TrackMenuButton=()=>n(o,{render:n(p,{variant:"secondary",size:"icon-sm",style:{minHeight:"20px",borderRadius:"10px"},children:n(r,{name:"action.more",className:"pn:size-4"})})});TrackMenuButton.displayName="TrackMenuButton";const s=a.forwardRef((a,r)=>{var{className:p,side:o}=a,s=e(a,["className","side"]);return n("div",Object.assign({ref:r,className:t('pn:pointer-events-auto pn:absolute pn:top-px pn:flex pn:h-[calc(100%-2px)] pn:w-3 pn:cursor-ew-resize pn:items-center pn:justify-center pn:before:h-3/4 pn:before:w-2 pn:before:rounded pn:before:border pn:before:border-white/60 pn:before:bg-black/60 pn:before:content-[""]',"left"===o?"pn:left-0":"pn:right-0",p)},s))});s.displayName="TrackHandleBase";export const TrackHandleLeft=a.forwardRef((e,a)=>n(s,Object.assign({ref:a,side:"left"},e)));TrackHandleLeft.displayName="TrackHandleLeft";export const TrackHandleRight=a.forwardRef((e,a)=>n(s,Object.assign({ref:a,side:"right"},e)));TrackHandleRight.displayName="TrackHandleRight";
|