polotno 4.14.0 → 4.15.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/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/panel-scroll-area.js +1 -1
- package/primitives/slider.js +1 -1
- 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/layers-panel.js +1 -1
- 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
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export type GradientStop = {
|
|
2
|
+
color: string;
|
|
3
|
+
offset: number;
|
|
4
|
+
};
|
|
5
|
+
export type EditableGradient = {
|
|
6
|
+
rotation: number;
|
|
7
|
+
stops: GradientStop[];
|
|
8
|
+
};
|
|
9
|
+
export declare const readGradient: (value: string) => EditableGradient;
|
|
10
|
+
export declare const writeGradient: ({ rotation, stops }: EditableGradient) => string;
|
|
11
|
+
export declare const colorAt: (stops: GradientStop[], offset: number) => string;
|
|
12
|
+
export declare const insertStop: (stops: GradientStop[], offset: number) => {
|
|
13
|
+
stops: {
|
|
14
|
+
offset: number;
|
|
15
|
+
color: string;
|
|
16
|
+
}[];
|
|
17
|
+
index: number;
|
|
18
|
+
};
|
|
19
|
+
export declare const addStop: (stops: GradientStop[]) => {
|
|
20
|
+
stops: {
|
|
21
|
+
offset: number;
|
|
22
|
+
color: string;
|
|
23
|
+
}[];
|
|
24
|
+
index: number;
|
|
25
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import o from"tinycolor2";import{parseColor as t,parseCmykGradient as r}from"@polotno/core/gradient";import{formatCmykColor as e,isCmykColor as n,parseCmykColor as s}from"@polotno/core/color";import{flags as f}from"./flags.js";import{byOffset as c,placeStop as l,safe01 as a}from"./stops.js";export const readGradient=o=>{const s=r(o);return s?{rotation:s.rotation,stops:s.stops.map(({offset:o,color:t})=>({offset:o,color:e(t)}))}:f.cmykInputEnabled&&n(o)?{rotation:0,stops:[{offset:0,color:o},{offset:1,color:o}]}:t(o)};export const writeGradient=({rotation:o,stops:t})=>`linear-gradient(${o}deg, ${c(t).map(o=>`${o.color} ${Number((100*o.offset).toFixed(4))}%`).join(",")})`;const i=(o,t,r)=>o+(t-o)*r;export const colorAt=(t,r)=>{var n;const f=c(t),l=f.find(o=>o.offset>=r),a=[...f].reverse().find(o=>o.offset<=r);if(!a||!l){return(null!==(n=null!=a?a:l)&&void 0!==n?n:f[0]).color}if(l.offset===a.offset){return a.color}const p=(r-a.offset)/(l.offset-a.offset),m=s(a.color),d=s(l.color);if(m&&d){return e({c:i(m.c,d.c,p),m:i(m.m,d.m,p),y:i(m.y,d.y,p),k:i(m.k,d.k,p),alpha:i(m.alpha,d.alpha,p)})}const u=o(a.color).toRgb(),g=o(l.color).toRgb();return`rgba(${Math.round(i(u.r,g.r,p))},${Math.round(i(u.g,g.g,p))},${Math.round(i(u.b,g.b,p))},${Number(i(u.a,g.a,p).toFixed(4))})`};export const insertStop=(o,t)=>l(o,{offset:t,color:colorAt(o,a(t))});export const addStop=o=>{const t=[0,...c(o).map(o=>o.offset),1];let r=.5,e=0;for(let n=1;n<t.length;n++){const o=t[n]-t[n-1];o>e&&(e=o,r=(t[n]+t[n-1])/2)}return insertStop(o,r)};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ImageInput, Rect, Size } from '../image-tools/types.js';
|
|
2
|
+
export type { ImageInput, Rect, Size } from '../image-tools/types.js';
|
|
3
|
+
interface PrepareOptions {
|
|
4
|
+
maxSide?: number;
|
|
5
|
+
roundTo?: number;
|
|
6
|
+
}
|
|
7
|
+
interface Padding {
|
|
8
|
+
left: number;
|
|
9
|
+
top: number;
|
|
10
|
+
right: number;
|
|
11
|
+
bottom: number;
|
|
12
|
+
}
|
|
13
|
+
export interface PreparedExpand extends ImageInput {
|
|
14
|
+
padding: Padding;
|
|
15
|
+
canvas: Size;
|
|
16
|
+
}
|
|
17
|
+
export interface PreparedInpaint extends ImageInput {
|
|
18
|
+
mask: Blob;
|
|
19
|
+
}
|
|
20
|
+
export declare function prepareImageInput(input: ImageInput & {
|
|
21
|
+
frame: Rect;
|
|
22
|
+
}, options?: PrepareOptions): Promise<PreparedExpand>;
|
|
23
|
+
export declare function prepareImageInput(input: ImageInput & {
|
|
24
|
+
mask: Blob;
|
|
25
|
+
}, options?: PrepareOptions): Promise<PreparedInpaint>;
|
|
26
|
+
export declare function prepareImageInput(input: ImageInput, options?: PrepareOptions): Promise<ImageInput>;
|
|
27
|
+
export declare function padImageForFrame(prepared: PreparedExpand): Promise<{
|
|
28
|
+
image: Blob;
|
|
29
|
+
mask: Blob;
|
|
30
|
+
size: {
|
|
31
|
+
width: number;
|
|
32
|
+
height: number;
|
|
33
|
+
};
|
|
34
|
+
}>;
|
|
35
|
+
export declare function formatMask(mask: Blob, { selection }: {
|
|
36
|
+
selection: 'white' | 'black' | 'transparent';
|
|
37
|
+
}): Promise<Blob>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{contains as t,matchesAspect as i,UNIT as e,validRect as a}from"../image-tools/geometry.js";import{encodeRaster as h,rasterCanvas as r,withBlobImage as n,WORKING_MAX_SIDE as o}from"../image-tools/raster.js";const s=t=>new TypeError(`Invalid image preparation option: ${t}`),g=()=>new RangeError("The image cannot fit this pixel layout.");function m(t){let i=!1;for(let e=0;e<t.length;e+=4){if(0!==t[e]&&255!==t[e]||t[e]!==t[e+1]||t[e]!==t[e+2]||255!==t[e+3]){throw s("mask")}i||(i=255===t[e])}return i}async function c(t,i,e=!1){return n(t,async t=>{const{canvas:a,ctx:n}=r(i,e?"resize-mask":"resize");if(n.imageSmoothingEnabled=!e,n.drawImage(t,0,0,i.width,i.height),e&&!m(n.getImageData(0,0,i.width,i.height).data)){throw g()}return h(a,"resize")})}export async function prepareImageInput(h,{maxSide:r=o,roundTo:n=1}={}){if(!Number.isInteger(r)||r<=0){throw s("maxSide")}if(!Number.isInteger(n)||n<=0){throw s("roundTo")}if(![h.size.width,h.size.height].every(t=>Number.isSafeInteger(t)&&t>0)){throw s("size")}const m=Math.min(r,o);if(n>m){throw g()}if(h.frame){const r=function(h,r,n,o){if(!a(r)||!t(r,e)){throw s("frame")}const m={width:h.width*r.width,height:h.height*r.height},c=Math.min(1,n/Math.max(m.width,m.height)),d=Math.max(h.width,h.height);for(let t=Math.floor(d*c);t>0;t--){const e=t/d,a={width:Math.floor(h.width*e),height:Math.floor(h.height*e)};if(!a.width||!a.height){break}const s=Math.max(0,Math.round(-r.x*a.width)),g=Math.max(0,Math.round(-r.y*a.height)),c=Math.max(0,Math.round((r.x+r.width-1)*a.width)),w=Math.max(0,Math.round((r.y+r.height-1)*a.height)),f={width:Math.ceil((s+a.width+c)/o)*o,height:Math.ceil((g+a.height+w)/o)*o};if(Math.max(f.width,f.height)<=n&&i(f,m)){return{size:a,canvas:f,padding:{left:s,top:g,right:f.width-s-a.width,bottom:f.height-g-a.height}}}}throw g()}(h.size,h.frame,m,n);return Object.assign(Object.assign({},r),{image:await c(h.image,r.size)})}const d=Math.max(h.size.width,h.size.height),w=Math.min(h.size.width,h.size.height);for(let t=Math.floor(Math.min(m,d)/n)*n;t>0;t-=n){const e=w*t/d,a=[Math.floor(e/n)*n,Math.ceil(e/n)*n].sort((t,i)=>Math.abs(t-e)-Math.abs(i-e));for(const r of a){if(!r||r>w){continue}const e=h.size.width>=h.size.height?{width:t,height:r}:{width:r,height:t};if(!i(e,h.size)){continue}const a=await c(h.image,e);return h.mask?{image:a,size:e,mask:await c(h.mask,e,!0)}:{image:a,size:e}}}throw g()}export async function padImageForFrame(t){const{size:i,padding:e,canvas:a}=t;if(!Object.values(e).every(t=>Number.isInteger(t)&&t>=0)||e.left+i.width+e.right!==a.width||e.top+i.height+e.bottom!==a.height){throw s("padding")}return n(t.image,async t=>{if(t.naturalWidth!==i.width||t.naturalHeight!==i.height){throw s("size")}const{canvas:n,ctx:o}=r(a,"pad");o.drawImage(t,e.left,e.top);const g=r(a,"padding-mask");return g.ctx.fillStyle="white",g.ctx.fillRect(0,0,a.width,a.height),g.ctx.fillStyle="black",g.ctx.fillRect(e.left,e.top,i.width,i.height),{image:await h(n,"pad"),mask:await h(g.canvas,"padding-mask"),size:Object.assign({},a)}})}export async function formatMask(t,{selection:i}){if(!["white","black","transparent"].includes(i)){throw s("selection")}return n(t,async t=>{const{canvas:e,ctx:a}=r({width:t.naturalWidth,height:t.naturalHeight},"format-mask");a.drawImage(t,0,0);const n=a.getImageData(0,0,e.width,e.height),o=n.data;m(o);for(let h=0;h<o.length;h+=4){const t=255===o[h],e="black"===i?t?0:255:o[h];o[h]=o[h+1]=o[h+2]=e,o[h+3]="transparent"===i&&t?0:255}return a.putImageData(n,0,0),h(e,"format-mask")})}
|
package/utils/l10n.d.ts
CHANGED
|
@@ -2,6 +2,35 @@ export declare const setTranslations: (json: any, { validate }?: {
|
|
|
2
2
|
validate?: boolean | undefined;
|
|
3
3
|
}) => void;
|
|
4
4
|
export declare const getTranslations: () => {
|
|
5
|
+
imageEdit: {
|
|
6
|
+
title: string;
|
|
7
|
+
expand: string;
|
|
8
|
+
upscale: string;
|
|
9
|
+
inpaint: string;
|
|
10
|
+
replace: string;
|
|
11
|
+
remove: string;
|
|
12
|
+
prompt: string;
|
|
13
|
+
promptPlaceholder: string;
|
|
14
|
+
expandPromptPlaceholder: string;
|
|
15
|
+
replaceDescription: string;
|
|
16
|
+
replaceHint: string;
|
|
17
|
+
removeDescription: string;
|
|
18
|
+
expandDescription: string;
|
|
19
|
+
cropDescription: string;
|
|
20
|
+
upscaleDescription: string;
|
|
21
|
+
removeBackgroundDescription: string;
|
|
22
|
+
applyCrop: string;
|
|
23
|
+
generate: string;
|
|
24
|
+
clear: string;
|
|
25
|
+
resetFrame: string;
|
|
26
|
+
processing: string;
|
|
27
|
+
loadingImage: string;
|
|
28
|
+
upscaling: string;
|
|
29
|
+
removingBackground: string;
|
|
30
|
+
failed: string;
|
|
31
|
+
rasterFailed: string;
|
|
32
|
+
selectRegion: string;
|
|
33
|
+
};
|
|
5
34
|
toolbar: {
|
|
6
35
|
duration: string;
|
|
7
36
|
opacity: string;
|
|
@@ -17,6 +46,7 @@ export declare const getTranslations: () => {
|
|
|
17
46
|
black: string;
|
|
18
47
|
vibrance: string;
|
|
19
48
|
textBackground: string;
|
|
49
|
+
textBox: string;
|
|
20
50
|
backgroundCornerRadius: string;
|
|
21
51
|
backgroundOpacity: string;
|
|
22
52
|
backgroundPadding: string;
|
|
@@ -172,6 +202,11 @@ export declare const getTranslations: () => {
|
|
|
172
202
|
solid: string;
|
|
173
203
|
linear: string;
|
|
174
204
|
angle: string;
|
|
205
|
+
stops: string;
|
|
206
|
+
stop: string;
|
|
207
|
+
addStop: string;
|
|
208
|
+
removeStop: string;
|
|
209
|
+
reverse: string;
|
|
175
210
|
colors: string;
|
|
176
211
|
resetColors: string;
|
|
177
212
|
recolorAll: string;
|
package/utils/l10n.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{observable as e,action as o,toJS as
|
|
1
|
+
import{observable as e,action as o,toJS as a}from"mobx";const r=e({imageEdit:{title:"AI edit",expand:"Expand",upscale:"Upscale",inpaint:"Generative fill",replace:"Replace",remove:"Remove",prompt:"Your prompt",promptPlaceholder:"Describe what should be there",expandPromptPlaceholder:"Describe the new area (optional)",replaceDescription:"Select an area on the image, then describe what you want to change.",replaceHint:"Describe what should replace the selection, such as “plain wall” or “open sky”.",removeDescription:"Select an object to remove. The surrounding image will fill the selected area.",expandDescription:"Drag the frame beyond the image edges to make room for new content.",cropDescription:"Drag the frame to crop the image.",upscaleDescription:"Increase the image resolution.",removeBackgroundDescription:"Remove the image background.",applyCrop:"Apply crop",generate:"Generate",clear:"Clear selection",resetFrame:"Reset frame",processing:"Generating…",loadingImage:"Loading image…",upscaling:"Upscaling…",removingBackground:"Removing background…",failed:"The image could not be edited. Please try again.",rasterFailed:"This device could not prepare the image. Try a smaller image.",selectRegion:"Drag on the image to select an area."},toolbar:{duration:"Duration",opacity:"Opacity",effects:"Effects",blur:"Blur",curvedText:"Curved text",curvePower:"Power",temperature:"Temperature",saturation:"Saturation",contrast:"Contrast",shadows:"Shadows",white:"White",black:"Black",vibrance:"Vibrance",textBackground:"Background",textBox:"Text box",backgroundCornerRadius:"Corner radius",backgroundOpacity:"Opacity",backgroundPadding:"Padding",brightness:"Brightness",filters:"Filters",sepia:"Sepia",grayscale:"Grayscale",cold:"Cold",natural:"Natural",warm:"Warm",textStroke:"Text Stroke",blendMode:"Blending",blend:{"pass-through":"Pass Through",normal:"Normal",multiply:"Multiply",screen:"Screen",overlay:"Overlay",darken:"Darken",lighten:"Lighten","color-dodge":"Color Dodge","color-burn":"Color Burn","hard-light":"Hard Light","soft-light":"Soft Light",difference:"Difference",exclusion:"Exclusion",hue:"Hue",saturation:"Saturation",color:"Color",luminosity:"Luminosity"},strokeLineJoin:"Corners",joinRound:"Round",joinMiter:"Miter",joinBevel:"Bevel",shadow:"Shadow",border:"Border",cornerRadius:"Corner Radius",copyStyle:"Copy style",uppercase:"Uppercase",position:"Position",layering:"Layering",toForward:"To Front",up:"Forward",down:"Backward",toBottom:"To back",alignLeft:"Align left",alignCenter:"Align center",alignRight:"Align right",alignTop:"Align top",alignMiddle:"Align middle",alignBottom:"Align bottom",flip:"Flip",flipHorizontally:"Flip horizontally",flipVertically:"Flip vertically",fitToBackground:"Fit to page",removeBackground:"Remove background",removeBackgroundTitle:"Remove background from image",cancelRemoveBackground:"Cancel",confirmRemoveBackground:"Confirm",crop:"Crop",cropDone:"Done",cropCancel:"Cancel",clip:"Apply mask",removeClip:"Remove mask",removeMask:"Remove mask",transparency:"Transparency",lockedDescription:"Object is locked. Unlock it to allow changes from canvas.",unlockedDescription:"Object is unlocked. Lock it to prevent changes from canvas.",removeElements:"Remove elements",duplicateElements:"Duplicate elements",download:"Download",saveAsImage:"Save as image",saveAsPDF:"Save as PDF",lineHeight:"Line height",letterSpacing:"Letter spacing",offsetX:"Offset X",offsetY:"Offset Y",color:"Color",selectable:"Selectable",draggable:"Draggable",removable:"Removable",resizable:"Resizable",contentEditable:"Can change content",styleEditable:"Can change style",alwaysOnTop:"Always on top",showInExport:"Show in export",ungroupElements:"Ungroup",groupElements:"Group",lineSize:"Line size",fade:"Fade",move:"Move",zoom:"Zoom",animate:"Animate",rotate:"Rotate",none:"None",bounce:"Bounce",blink:"Blink",strength:"Strength",spaceEvenly:"Space evenly",horizontalDistribution:"Horizontally",verticalDistribution:"Vertically",strokeWidth:"Stroke Width",strokeSettings:"Stroke settings",spacing:"Spacing",volume:"Volume",speed:"Speed",seconds:"sec",lineStyle:"Line style",lineStartHead:"Line start",lineEndHead:"Line end",textDirection:"Text direction",fontSize:"Font size",fontFamily:"Font family",fontFamilyMixed:"Mixed",fontsInSelection:"Fonts in selection",textAlign:"Text align",verticalAlign:"Vertical align",bold:"Bold",italic:"Italic",underline:"Underline",strikethrough:"Strikethrough",cellBackground:"Cell background",tableBorderSettings:"Border settings",tableBorderColor:"Border color",tableBorderWidth:"Border width",tableBorderStyle:"Border style",borderModeAll:"All borders",borderModeOuter:"Outer borders",borderModeInner:"Inner borders",borderModeBottomOnly:"Bottom only",borderModeTopOnly:"Top only",borderModeLeftOnly:"Left only",borderModeRightOnly:"Right only",borderModeInnerHorizontal:"Inner horizontal",borderModeInnerVertical:"Inner vertical",tableStructure:"Table structure",tableRows:"Rows",tableColumns:"Columns",insertRowAbove:"Insert row above",insertRowBelow:"Insert row below",deleteRow:"Delete row",insertColumnLeft:"Insert column left",insertColumnRight:"Insert column right",deleteColumn:"Delete column",deleteRows:"Delete rows",deleteColumns:"Delete columns",distributeRowsEvenly:"Distribute rows evenly",distributeColumnsEvenly:"Distribute columns evenly",cellPadding:"Cell padding",listFormat:"List",colorPicker:{solid:"Solid",linear:"Linear",angle:"Angle",stops:"Gradient stops",stop:"Stop",addStop:"Add stop",removeStop:"Remove stop",reverse:"Reverse gradient",colors:"Colors",resetColors:"Reset",recolorAll:"Recolor all"},clipFade:{title:"Fade",preparing:"Preparing mask…",shape:"Shape",linear:"Linear",radial:"Radial",stopOpacity:"Stop opacity",stops:"Fade stops",stop:"Stop",start:"Fade start",end:"Fade end",center:"Fade center",radius:"Fade radius",reverse:"Reverse",removeStop:"Remove stop",addStop:"Add stop",reset:"Reset",hint:"Drag the handles on the image to position the fade."},aiText:{aiWrite:"AI write",rewrite:"Rewrite",shorten:"Shorten",continue:"Continue writing",proofread:"Proofread",tones:"Tones",friendly:"Friendly",professional:"Professional",humorous:"Humorous",formal:"Formal",customPrompt:"Custom prompt",generatedResult:"Generated result",cancel:"Cancel",generate:"Generate",back:"Back",tryAgain:"Try Again",insert:"Insert",promptPlaceholder:"Describe what you want to generate"}},workspace:{noPages:"There are no pages yet...",addPage:"Add page",removePage:"Remove page",duplicatePage:"Duplicate page",moveUp:"Move up",moveDown:"Move down",moveLeft:"Move left",moveRight:"Move right"},scale:{reset:"Reset"},error:{removeBackground:"Ops! Something went wrong. Background can not be removed."},sidePanel:{close:"Close",templates:"Templates",searchTemplatesWithSameSize:"Show templates with the same size",searchPlaceholder:"Search...",otherFormats:"Other formats",noResults:"No results",error:"Loading is failed...",text:"Text",uploadFont:"Upload font",myFonts:"My fonts",photos:"Photos",videos:"Videos",animations:"Animations",effects:"Effects",elements:"Elements",shapes:"Shapes",tables:"Tables",lines:"Lines",draw:"Draw",drawTool:"Tool",drawSelection:"Selection",drawBrush:"Brush",drawHighlighter:"Highlighter",upload:"Upload",uploadImage:"Add file",uploadTip:"Upload your assets",uploadUnsupported:"Skipped some files. You can add images, video and audio.",uploadFailed:"Upload failed. Please try again.",background:"Background",resize:"Resize",layers:"Layers",animate:"Animate",layerTypes:{image:"Image",text:"Text",svg:"SVG",line:"Line",figure:"Figure",group:"Group"},layersTip:"Elements on your active page:",noLayers:"No elements on the page...",namePlaceholder:"Type element name...",useMagicResize:"Use magic resize",advanced:"Advanced",bleed:"Bleed",showBleed:"Show bleed",clipImage:"Mask image",width:"Width",height:"Height",units:"Units",magicResizeDescription:"Magic resize will automatically resize and move all elements on the canvas",headerText:"Header",createHeader:"Create header",subHeaderText:"Sub Header",createSubHeader:"Create sub header",bodyText:"Body text",createBody:"Create body text"},pagesTimeline:{pages:"Pages",removePage:"Remove page",addPage:"Add page",duplicatePage:"Duplicate page",removeAudio:"Remove audio",duplicateAudio:"Duplicate audio",renameAudio:"Rename audio",muteAudio:"Mute",unmuteAudio:"Unmute",volume:"Volume",speed:"Speed",rewind:"Rewind to start",editAsVideo:"Edit as video",editAsVideoHint:"On: preview the frame at the playhead — timed elements hide outside their range. Off: show all elements while editing."},contextMenu:{duplicate:"Duplicate",split:"Split at playhead",rename:"Rename",remove:"Remove",lock:"Lock",unlock:"Unlock",copy:"Copy",paste:"Paste",copyStyle:"Copy style",moveUp:"Move up",moveDown:"Move down",moveBack:"Move back",moveForward:"Move forward"}}),n=e=>e&&"object"==typeof e;function i(e,o){Object.keys(o).forEach(a=>{const r=e[a],l=o[a];n(l)&&n(r)?i(r,l):e[a]=l})}function l(e,o,a=""){Object.keys(o).forEach(r=>{const i=o[r],s=a?`${a}.${r}`:r;n(i)?n(e[r])?l(e[r],i,s):console.warn(`Missing nested translation object at '${s}'`):void 0===e[r]&&console.warn(`Missing translation '${s}'`)})}export const setTranslations=o((e,{validate:o=!1}={})=>{o&&l(e,r),i(r,e)});export const getTranslations=()=>a(r);const s={};export const t=e=>{const o=function(e,o){var a,r=o.split("."),n=e;for(a=0;a<r.length;++a){if(null==n[r[a]]){return}n=n[r[a]]}return n}(r,e);if(void 0!==o){return o}s[e]||(s[e]=!0,console.warn(`Missing translation '${e}'`));const a=e.split("."),n=a[a.length-1]||" ";return n.charAt(0).toUpperCase()+n.slice(1)};
|
package/utils/luma.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import t from"konva";import{isGradient as
|
|
1
|
+
import t from"konva";import{isGradient as o,parseColor as r}from"@polotno/core/gradient";import{toDisplayColor as n}from"@polotno/core/color";export function getGradientBrightness(o){try{const{stops:e}=r(o);if(0===e.length){return 127.5}let i=0,c=0;for(const o of e){try{const r=t.Util.colorToRGBA(o.color);if(!r){continue}if(r.a<.5){continue}i+=(299*r.r+587*r.g+114*r.b)/1e3,c++}catch(n){continue}}return 0===c?127.5:i/c}catch(e){return console.warn("Error calculating gradient brightness:",e),127.5}}export function getBrightness(r){if(o(r)){return getGradientBrightness(r)}const e=t.Util.colorToRGBA(n(r));if(!e){return 127.5}const{r:i,g:c,b:s}=e;return(299*i+587*c+114*s)/1e3}
|
package/utils/px.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ export declare const roundedBoxStyleAttrs: (element: BoxStyleSource) => {
|
|
|
30
30
|
type TextStyleSource = {
|
|
31
31
|
fontSize: number;
|
|
32
32
|
strokeWidth: number;
|
|
33
|
+
borderSize: number;
|
|
33
34
|
shadowBlur: number;
|
|
34
35
|
shadowOffsetX: number;
|
|
35
36
|
shadowOffsetY: number;
|
|
@@ -37,6 +38,7 @@ type TextStyleSource = {
|
|
|
37
38
|
export declare const scaledFontSizeAttrs: (element: TextStyleSource, fontSize: number) => {
|
|
38
39
|
fontSize: number;
|
|
39
40
|
strokeWidth: number;
|
|
41
|
+
borderSize: number;
|
|
40
42
|
shadowBlur: number;
|
|
41
43
|
shadowOffsetX: number;
|
|
42
44
|
shadowOffsetY: number;
|
|
@@ -64,12 +66,14 @@ export declare const roundedGeometryAttrs: (element: GeometrySource) => {
|
|
|
64
66
|
export declare const roundedFontSizeAttrs: (element: TextStyleSource, fontSize: number) => {
|
|
65
67
|
fontSize: number;
|
|
66
68
|
strokeWidth: number;
|
|
69
|
+
borderSize: number;
|
|
67
70
|
shadowBlur: number;
|
|
68
71
|
shadowOffsetX: number;
|
|
69
72
|
shadowOffsetY: number;
|
|
70
73
|
};
|
|
71
74
|
export declare const roundedTextDecorationAttrs: (element: TextStyleSource) => {
|
|
72
75
|
strokeWidth: number;
|
|
76
|
+
borderSize: number;
|
|
73
77
|
shadowBlur: number;
|
|
74
78
|
shadowOffsetX: number;
|
|
75
79
|
shadowOffsetY: number;
|
package/utils/px.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var t=this&&this.__rest||function(t,
|
|
1
|
+
var t=this&&this.__rest||function(t,e){var o={};for(var r in t){Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(o[r]=t[r])}if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(r=Object.getOwnPropertySymbols(t);n<r.length;n++){e.indexOf(r[n])<0&&Object.prototype.propertyIsEnumerable.call(t,r[n])&&(o[r[n]]=t[r[n]])}}return o};import{htmlInflatesMinContentWidth as e}from"./rich-text-html.js";export const roundEnabledPx=t=>t>0?Math.max(1,Math.round(t)):0;export const MAIN_TRANSFORMER_NAME="main-transformer";export const activeAnchorOf=t=>{var e,o;const r=null===(e=t.getStage())||void 0===e?void 0:e.findOne(".main-transformer");return null!==(o=null==r?void 0:r.getActiveAnchor())&&void 0!==o?o:""};export const isCornerAnchor=t=>!(t.includes("middle")||t.includes("center"));export const textMinResizeWidth=(t,e)=>t<e?1:e;export const textMinWidthIsMeasured=t=>{var o;return!!t.curveEnabled||0!==(null!==(o=t.letterSpacing)&&void 0!==o?o:0)||e(t.text)};export const scaledBoxStyleAttrs=(t,e)=>{var o;return{cornerRadius:(null!==(o=t.cornerRadius)&&void 0!==o?o:0)*e,shadowBlur:t.shadowBlur*e,shadowOffsetX:t.shadowOffsetX*e,shadowOffsetY:t.shadowOffsetY*e}};export const roundedBoxStyleAttrs=t=>{var e;return{cornerRadius:roundEnabledPx(null!==(e=t.cornerRadius)&&void 0!==e?e:0),shadowBlur:Math.round(t.shadowBlur),shadowOffsetX:Math.round(t.shadowOffsetX),shadowOffsetY:Math.round(t.shadowOffsetY)}};export const scaledFontSizeAttrs=(t,e)=>{const o=t.fontSize>0?e/t.fontSize:1;return{fontSize:e,strokeWidth:t.strokeWidth*o,borderSize:t.borderSize*o,shadowBlur:t.shadowBlur*o,shadowOffsetX:t.shadowOffsetX*o,shadowOffsetY:t.shadowOffsetY*o}};export const roundedGeometryPx=t=>Math.round(1e6*t)/1e6+0;export const roundedCropFraction=t=>Math.round(1e9*t)/1e9+0;export const roundedPosition=t=>({x:roundedGeometryPx(t.x()),y:roundedGeometryPx(t.y())});export const roundedGeometryAttrs=t=>({x:roundedGeometryPx(t.x),y:roundedGeometryPx(t.y),width:roundedGeometryPx(t.width),height:roundedGeometryPx(t.height),rotation:roundedGeometryPx(t.rotation)});export const roundedFontSizeAttrs=(t,e)=>{const o=scaledFontSizeAttrs(t,e);return{fontSize:Math.round(o.fontSize),strokeWidth:roundEnabledPx(o.strokeWidth),borderSize:roundEnabledPx(o.borderSize),shadowBlur:Math.round(o.shadowBlur),shadowOffsetX:Math.round(o.shadowOffsetX),shadowOffsetY:Math.round(o.shadowOffsetY)}};export const roundedTextDecorationAttrs=e=>{const o=roundedFontSizeAttrs(e,e.fontSize),{fontSize:r}=o;return t(o,["fontSize"])};
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
export * from '@polotno/core/rich-text-html';
|
|
2
|
+
export declare function nativeColorAttribute(property: string): string;
|
|
3
|
+
export declare function readNativeColor(el: Element, property: string): string;
|
|
4
|
+
export declare function detachNativeColorsInHtml(html: string): string;
|
|
5
|
+
export declare function attachNativeColorsInHtml(html: string): string;
|
|
6
|
+
export declare function scaleRichTextFontSizesInHtml(html: string, factor: number): string;
|
|
2
7
|
export declare function htmlInflatesMinContentWidth(html: string): boolean;
|
|
3
8
|
export declare function quillHtmlToModelText(html: string, defaults: {
|
|
4
9
|
fontSize: number;
|
package/utils/rich-text-html.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export*from"@polotno/core/rich-text-html";import{parseHtmlRoot as t,cleanupInlineWrappers as e,extractFontFamiliesFromHtml as r,normalizeRichTextHtml as o}from"@polotno/core/rich-text-html";import{LRUCache as
|
|
1
|
+
export*from"@polotno/core/rich-text-html";import{parseHtmlRoot as t,cleanupInlineWrappers as e,extractFontFamiliesFromHtml as r,normalizeRichTextHtml as o,scaleRichTextFontSizesInHtml as n}from"@polotno/core/rich-text-html";import{containsCmykColor as i,isCmykColor as l,toDisplayColor as s}from"@polotno/core/color";import{buildStyleAttribute as c,parseStyleAttribute as u}from"@polotno/core/style-attribute";import{sameColors as f}from"@polotno/core/svg";import{isGradient as a,parseColor as p}from"@polotno/core/gradient";import{LRUCache as y}from"./lru-cache.js";const m="data-native-";export function nativeColorAttribute(t){return m+t}const d=t=>l(t)||a(t)&&i(t);export function readNativeColor(t,e){var r;const o=t.getAttribute(nativeColorAttribute(e));if(null!==o){const n=null===(r=t.style)||void 0===r?void 0:r.getPropertyValue(e);return d(o)&&n&&function(t,e,r){const o=s(r);if(!a(o)){return f(e,o)}const n=function(t,e){if("undefined"==typeof document){return null}const r=document.createElement("span");return r.style.setProperty(t,e),r.style.getPropertyValue(t)||null}(t,o);if(null!==n){return n===e}if(!a(e)){return!1}const i=p(e),l=p(o);return i.rotation===l.rotation&&i.stops.length===l.stops.length&&i.stops.every((t,e)=>Math.abs(t.offset-l.stops[e].offset)<.001&&f(t.color,l.stops[e].color))}(e,n,o)?o:""}const n=u(t.getAttribute("style"))[e];return n&&d(n)?n:""}export function detachNativeColorsInHtml(e){if(!i(e)){return e}const r=t(e);return r?(function(t){for(const e of Array.from(t.querySelectorAll("[style]"))){const t=e.getAttribute("style");if(!i(t)){continue}const r=u(t);for(const[o,n]of Object.entries(r)){d(n)&&(e.setAttribute(nativeColorAttribute(o),n),r[o]=s(n))}e.setAttribute("style",c(r))}}(r),r.innerHTML):e}export function attachNativeColorsInHtml(r){if(!r||!r.includes(m)){return r}const o=t(r);if(!o){return r}let n=!1;for(const t of Array.from(o.querySelectorAll("*"))){for(const{name:e}of Array.from(t.attributes)){if(!e.startsWith(m)){continue}const r=e.slice(12),o=readNativeColor(t,r);if(t.removeAttribute(e),!o){n=!0;continue}const i=u(t.getAttribute("style"));i[r]=o,t.setAttribute("style",c(i))}}return n&&e(o),o.innerHTML}function b(t,e){if(!i(t)){return e(t)}const r=detachNativeColorsInHtml(t),o=e(r);return o===r?t:attachNativeColorsInHtml(o)}export function scaleRichTextFontSizesInHtml(t,e){return b(t,t=>n(t,e))}const v=new y(500);export function htmlInflatesMinContentWidth(e){if(!e||!e.includes("<")){return!1}let r=v.get(e);if(void 0===r){r=!1;const o=t(e);if(o){if(o.querySelector("ol, ul")){r=!0}else{for(const t of o.querySelectorAll("[style]")){if(t.style.fontSize||t.style.letterSpacing){r=!0;break}}}}v.set(e,r)}return r}export function quillHtmlToModelText(t,e){return attachNativeColorsInHtml(o(function(t){const e=(t||"").trim();if("<p><br></p>"===e||"<p></p>"===e){return""}if(e.startsWith("<p>")&&e.endsWith("</p>")){const t=e.slice(3,-4);if(!/(<\/?(p|div|h[1-6]|ul|ol|li|table|thead|tbody|tr|td|blockquote)\b)/i.test(t)){return t}}return t}(t),e))}export function shrinkParagraphStrutForRaster(e){var r;if(!e||!e.includes("<p")){return e}const o=t(e);if(!o){return e}for(const t of Array.from(o.querySelectorAll("p"))){let e=!1;const n=[],i=o.ownerDocument.createTreeWalker(t,NodeFilter.SHOW_TEXT);let l=i.nextNode();for(;l;){if((l.textContent||"").length>0){let o=l.parentElement,i=null;for(;o&&o!==t;){const t=null===(r=o.style)||void 0===r?void 0:r.fontSize;if(t){const e=parseFloat(t);if(!Number.isNaN(e)){i=e;break}}o=o.parentElement}if(null==i){e=!0;break}n.push(i)}l=i.nextNode()}!e&&n.length>0&&(t.style.fontSize=`${Math.min(...n)}px`)}return o.innerHTML}const h={bold:["STRONG","B"],italic:["EM","I"],underline:["U"],strike:["S","DEL"]};export function isClipGradientSpan(t){return!!(null==t?void 0:t.style)&&("text"===(t.style.getPropertyValue("-webkit-background-clip")||t.style.getPropertyValue("background-clip"))&&(t.style.backgroundImage.includes("gradient")||!!readNativeColor(t,"background-image")))}const g={bold:t=>t.style.removeProperty("font-weight"),italic:t=>t.style.removeProperty("font-style"),color:t=>{!function(t){if(isClipGradientSpan(t)){for(const e of["background-image","background-size","-webkit-background-clip","background-clip","-webkit-text-fill-color"]){t.style.removeProperty(e)}}}(t),t.style.removeProperty("color")},underline:t=>{const e=t.style.textDecoration.replace(/\bunderline\b/g,"").trim();e?t.style.textDecoration=e:t.style.removeProperty("text-decoration")},strike:t=>{const e=t.style.textDecoration.replace(/\bline-through\b/g,"").trim();e?t.style.textDecoration=e:t.style.removeProperty("text-decoration")},"text-transform":t=>t.style.removeProperty("text-transform")};export function stripInlineFormat(r,o){return b(r,r=>function(r,o){var n,i;if(!r||!r.includes("<")){return r}const l=t(r);if(!l){return r}const s=h[o]||[],c=g[o];for(const t of s){let e;for(;e=l.querySelector(t);){const t=e.parentNode;c&&c(e);const r=null===(n=e.getAttribute("style"))||void 0===n?void 0:n.trim();if(r){const o=l.ownerDocument.createElement("span");o.setAttribute("style",r);for(const{name:t,value:r}of Array.from(e.attributes)){t.startsWith(m)&&o.setAttribute(t,r)}for(;e.firstChild;){o.appendChild(e.firstChild)}t.insertBefore(o,e)}else{for(;e.firstChild;){t.insertBefore(e.firstChild,e)}}t.removeChild(e)}}if(c){for(const t of Array.from(l.querySelectorAll("[style]"))){c(t),(null===(i=t.getAttribute("style"))||void 0===i?void 0:i.trim())||t.removeAttribute("style")}}return e(l),l.innerHTML}(r,o))}const A=Symbol("unset");export function isQuillFormatMixed(t,e){var r;let o=A;for(const n of t.ops){if("string"!=typeof n.insert||"\n"===n.insert){continue}const t=null===(r=n.attributes)||void 0===r?void 0:r[e];if(o===A){o=t}else if(t!==o){return!0}}return!1}export function stripInlineFontSizes(t){return b(t,x)}function x(r){var o;if(!r||!r.includes("font-size")){return r}const n=t(r);if(!n){return r}const i=n.querySelectorAll("[style]");for(let t=0;t<i.length;t++){const e=i[t];e.style.fontSize&&(e.style.removeProperty("font-size"),(null===(o=e.getAttribute("style"))||void 0===o?void 0:o.trim())||e.removeAttribute("style"))}return e(n),n.innerHTML}export function stripInlineFontFamilies(t){return b(t,S)}function S(r){var o;if(!r||!r.includes("font-family")&&!r.includes("ql-font-")){return r}const n=t(r);if(!n){return r}for(const t of Array.from(n.querySelectorAll("[style]"))){t.style.fontFamily&&(t.style.removeProperty("font-family"),(null===(o=t.getAttribute("style"))||void 0===o?void 0:o.trim())||t.removeAttribute("style"))}for(const t of Array.from(n.querySelectorAll("[class]"))){const e=t.getAttribute("class")||"",r=e.split(/\s+/).filter(t=>t&&!t.startsWith("ql-font-"));r.length!==e.split(/\s+/).filter(Boolean).length&&(r.length?t.setAttribute("class",r.join(" ")):t.removeAttribute("class"))}return e(n),n.innerHTML}export function hasMultipleDistinctInlineFontSizes(e){if(!e||!e.includes("<")){return!1}const r=t(e);if(!r){return!1}const o=new Set;for(const t of r.querySelectorAll("[style]")){const e=t.style.fontSize;if(e){const t=e.match(/^(\d+(?:\.\d+)?)px$/i);if(t&&(o.add(parseFloat(t[1])),o.size>1)){return!0}}}return!1}export function listEffectiveFontFamilies(t,e){const o=[];e&&o.push(e),o.push(...r(t||""));const n=new Set,i=[];for(const r of o){n.has(r)||(n.add(r),i.push(r))}return i.sort((t,e)=>t.localeCompare(e,void 0,{sensitivity:"base"})),i}
|
package/utils/stops.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type Stop = {
|
|
2
|
+
offset: number;
|
|
3
|
+
};
|
|
4
|
+
export declare const safe01: (value: number) => number;
|
|
5
|
+
export declare const byOffset: <T extends Stop>(stops: T[]) => T[];
|
|
6
|
+
export declare const placeStop: <T extends Stop>(others: T[], stop: T) => {
|
|
7
|
+
stops: T[];
|
|
8
|
+
index: number;
|
|
9
|
+
};
|
|
10
|
+
export declare const moveStop: <T extends Stop>(stops: T[], index: number, offset: number) => {
|
|
11
|
+
stops: T[];
|
|
12
|
+
index: number;
|
|
13
|
+
};
|
|
14
|
+
export declare const canRemoveStop: (stops: Stop[]) => boolean;
|
|
15
|
+
export declare const reverseStops: <T extends Stop>(stops: T[]) => (T & {
|
|
16
|
+
offset: number;
|
|
17
|
+
})[];
|
package/utils/stops.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const safe01=e=>Number.isFinite(e)?Math.min(1,Math.max(0,e)):0;export const byOffset=e=>[...e].sort((e,t)=>e.offset-t.offset);export const placeStop=(e,t)=>{const s=Object.assign(Object.assign({},t),{offset:safe01(t.offset)}),o=byOffset([...e,s]);return{stops:o,index:o.indexOf(s)}};export const moveStop=(e,t,s)=>{const o=Object.assign(Object.assign({},e[t]),{offset:safe01(s)}),f=byOffset(e.map((e,s)=>s===t?o:e));return{stops:f,index:f.indexOf(o)}};export const canRemoveStop=e=>e.length>2;export const reverseStops=e=>byOffset([...e].reverse().map(e=>Object.assign(Object.assign({},e),{offset:1-e.offset})));
|
|
@@ -32,10 +32,11 @@ export interface TextDefaults {
|
|
|
32
32
|
fontWeight: string;
|
|
33
33
|
fontStyle: string;
|
|
34
34
|
textDecoration: string;
|
|
35
|
+
textTransform?: string;
|
|
35
36
|
}
|
|
36
37
|
export declare const ALL_QUILL_MIXED_KEYS: string[];
|
|
37
38
|
export declare function quillToTextFormat(fmt: QuillFormat, mixed: QuillMixed, defaults: TextDefaults): TextFormat;
|
|
38
|
-
export declare function attrsToQuillOps(attrs: TextFormatAttrs, opts?: ApplyTextFormatOptions): Array<[string, any]>;
|
|
39
|
+
export declare function attrsToQuillOps(attrs: TextFormatAttrs, opts?: ApplyTextFormatOptions, elementTransform?: string): Array<[string, any]>;
|
|
39
40
|
export type TextFormatState = {
|
|
40
41
|
format: TextFormat;
|
|
41
42
|
applyTextFormat: (attrs: TextFormatAttrs, opts?: ApplyTextFormatOptions) => void;
|
|
@@ -56,7 +57,7 @@ export declare function resolveSelectionScope(quill: any, fallbackSelection: {
|
|
|
56
57
|
export declare function applyToLiveEditor(quill: any, attrs: TextFormatAttrs, fallbackSelection?: {
|
|
57
58
|
index: number;
|
|
58
59
|
length: number;
|
|
59
|
-
} | null, opts?: ApplyTextFormatOptions): void;
|
|
60
|
+
} | null, opts?: ApplyTextFormatOptions, elementTransform?: string): void;
|
|
60
61
|
export declare function getTextFormatState(store: any): TextFormatState;
|
|
61
62
|
export declare function observeTextFormatState(store: any, cb: (state: TextFormatState) => void): () => void;
|
|
62
63
|
export declare function useTextFormat(store: any): TextFormatState;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as t from"react";import*as e from"mobx";import{parseFontSizeToPx as o,toNumericWeight as n}from"@polotno/core/rich-text-html";import{isGradient as i}from"@polotno/core/gradient";import{getTextFormat as r,applyTextFormat as l,FORMAT_KEYS as
|
|
1
|
+
import*as t from"react";import*as e from"mobx";import{parseFontSizeToPx as o,toNumericWeight as n}from"@polotno/core/rich-text-html";import{isGradient as i}from"@polotno/core/gradient";import{getTextFormat as r,applyTextFormat as l,FORMAT_KEYS as a,DECORATION_TOKENS as c,decorationTokensOf as s,decorationTokensToString as f,decorationToQuillKey as u}from"./text-format.js";const m=e.observable({active:null},{},{deep:!1});export function getActiveTextEditor(){return m.active}export function setActiveTextEditor(t){e.runInAction(()=>{m.active=Object.assign(Object.assign({},t),{currentFormat:{},mixedFormats:{},lastSelection:null})})}export function updateActiveTextFormat(t,o,n){e.runInAction(()=>{m.active&&(m.active=Object.assign(Object.assign({},m.active),{currentFormat:t,mixedFormats:o,lastSelection:n||m.active.lastSelection}))})}export function clearActiveTextEditor(t){e.runInAction(()=>{var e;t&&(null===(e=m.active)||void 0===e?void 0:e.instance)!==t||(m.active=null)})}const x={fontSize:["size"],fontFamily:["font"],fill:["color","gradient"],fontWeight:["font-weight"],fontStyle:["italic"],textDecoration:["underline","strike"],textTransform:["text-transform"]};export const ALL_QUILL_MIXED_KEYS=Array.from(new Set(a.flatMap(t=>x[t])));function d(t,e,i){var r,l;switch(t){case"fontSize":return null!==(r=o(e.size,i.fontSize))&&void 0!==r?r:i.fontSize;case"fontFamily":return e.font?String(e.font):i.fontFamily;case"fill":return e.gradient||(null!==(l=e.color)&&void 0!==l?l:i.fill);case"fontWeight":return null!=e["font-weight"]?n(e["font-weight"]):n(i.fontWeight);case"fontStyle":return e.italic?"italic":i.fontStyle;case"textDecoration":return f(s(i.textDecoration));case"textTransform":return e["text-transform"]||i.textTransform||"none"}}function p(t,e,o){const n=s(o.textDecoration),i=(o,i)=>n.has(o)?"on":e[i]?"mixed":t[i]?"on":"off",r=function(t,e){const o=t=>"on"===t?[!0]:"off"===t?[!1]:[!0,!1],n=[];for(const i of o(t)){for(const t of o(e)){const e=new Set;i&&e.add("underline"),t&&e.add("line-through"),n.push(f(e))}}return n}(i("underline","underline"),i("line-through","strike"));return{value:1===r.length?r[0]:void 0,mixed:r.length>1,values:r}}export function quillToTextFormat(t,e,o){const n={};for(const i of a){if("textDecoration"!==i){if(x[i].some(t=>!0===e[t])){n[i]={value:void 0,mixed:!0,values:[]}}else{const e=d(i,t,o);n[i]={value:e,mixed:!1,values:[e]}}}else{n.textDecoration=p(t,e,o)}}return n}export function attrsToQuillOps(t,e,o){var r;const l=[];if(void 0!==t.fontFamily&&l.push(["font",t.fontFamily]),void 0!==t.fontSize&&l.push(["size",`${t.fontSize}px`]),void 0!==t.fill&&(i(String(t.fill))?l.push(["color",!1],["gradient",t.fill]):l.push(["gradient",!1],["color",t.fill])),void 0!==t.fontWeight&&l.push(["font-weight",String(n(t.fontWeight))]),void 0!==t.fontStyle&&l.push(["italic","italic"===t.fontStyle]),void 0!==t.textDecoration){const o=null!==(r=null==e?void 0:e.decorationTokens)&&void 0!==r?r:c,n=s(t.textDecoration);for(const t of c){o.includes(t)&&l.push([u(t),n.has(t)])}}return void 0!==t.textTransform&&l.push(["text-transform",t.textTransform!==o&&t.textTransform]),l}function v(t){return((null==t?void 0:t.selectedElements)||[]).filter(t=>"text"===t.type)}function g(t){const e=getActiveTextEditor();return e&&e.instance&&e.store===t?e:null}export function restoreEditorSelection(t,e){t.composition.isComposing||(t.update(),t.setSelection(e))}export function resolveSelectionScope(t,e){const o=t.getSelection()||e||{index:0,length:0},n="function"==typeof t.getLength?t.getLength():0,i=n<=1;return o.length<=0?{scope:"collapsed",sel:o,isEmpty:i}:{scope:o.length>=n-1?"full":"partial",sel:o,isEmpty:i}}export function applyToLiveEditor(t,e,o,n,i){const r=attrsToQuillOps(e,n,i);if(!r.length){return}const{scope:l,sel:a}=resolveSelectionScope(t,null!=o?o:null);for(const[c,s]of r){"collapsed"===l?t.format(c,s,"user"):t.formatText(a.index,a.length,c,s,"user")}"collapsed"===l&&updateActiveTextFormat(t.getFormat(a.index,0),{},a)}function h(t,e){const o="function"==typeof t.getLength?t.getLength():0;t.formatText(0,o,e,!0,"api")}export function getTextFormatState(t){const e=g(t),o=v(t),n=!!e||o.length>0;var i;return{format:e?quillToTextFormat(e.currentFormat||{},e.mixedFormats||{},{fontSize:(i=e.element).fontSize,fontFamily:i.fontFamily,fill:i.fill,fontWeight:i.fontWeight,fontStyle:i.fontStyle,textDecoration:i.textDecoration,textTransform:i.textTransform}):r(o),enabled:n,applyTextFormat:(e,o)=>function(t,e,o){const n=g(t);if(!n){return void l(v(t),e,o)}const{scope:i,sel:r,isEmpty:a}=resolveSelectionScope(n.instance,n.lastSelection);"full"===i||"collapsed"===i&&!a?l([n.element],e,o):function(t,e,o,n){var i,r;const l=t.instance,a=t.element;let m=!1;if(n.length>0){if(void 0!==e.fontStyle&&"italic"!==e.fontStyle&&"italic"===a.fontStyle&&(h(l,"italic"),a.set({fontStyle:"normal"}),m=!0),void 0!==e.textDecoration){const t=null!==(i=null==o?void 0:o.decorationTokens)&&void 0!==i?i:c,n=s(e.textDecoration),r=s(a.textDecoration),x=t.filter(t=>!n.has(t)&&r.has(t));for(const e of x){h(l,u(e)),r.delete(e)}x.length&&(a.set({textDecoration:f(r)}),m=!0)}m&&"function"==typeof(null===(r=l.history)||void 0===r?void 0:r.clear)&&l.history.clear()}applyToLiveEditor(l,e,n,o,a.textTransform)}(n,e,o,r)}(t,e,o)}}export function observeTextFormatState(t,o){return e.reaction(()=>getTextFormatState(t),t=>o(t),{fireImmediately:!0})}export function useTextFormat(e){const[o,n]=t.useState(()=>getTextFormatState(e));return t.useEffect(()=>observeTextFormatState(e,n),[e]),o}
|
package/utils/text-format.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const FORMAT_KEYS: readonly ["fontSize", "fontFamily", "fill", "fontWeight", "fontStyle", "textDecoration"];
|
|
1
|
+
export declare const FORMAT_KEYS: readonly ["fontSize", "fontFamily", "fill", "fontWeight", "fontStyle", "textDecoration", "textTransform"];
|
|
2
2
|
export type FormatKey = (typeof FORMAT_KEYS)[number];
|
|
3
3
|
export type FormatValue<T> = {
|
|
4
4
|
value: T | undefined;
|
|
@@ -12,6 +12,7 @@ export type TextFormat = {
|
|
|
12
12
|
fontWeight: FormatValue<number>;
|
|
13
13
|
fontStyle: FormatValue<string>;
|
|
14
14
|
textDecoration: FormatValue<string>;
|
|
15
|
+
textTransform: FormatValue<string>;
|
|
15
16
|
};
|
|
16
17
|
export type TextFormatAttrs = Partial<{
|
|
17
18
|
fontSize: number;
|
|
@@ -20,6 +21,7 @@ export type TextFormatAttrs = Partial<{
|
|
|
20
21
|
fontWeight: number | 'bold' | 'normal' | string;
|
|
21
22
|
fontStyle: string;
|
|
22
23
|
textDecoration: string;
|
|
24
|
+
textTransform: string;
|
|
23
25
|
}>;
|
|
24
26
|
export type DecorationToken = 'underline' | 'line-through';
|
|
25
27
|
export declare const DECORATION_TOKENS: DecorationToken[];
|
|
@@ -39,6 +41,7 @@ export interface TextFormatElement {
|
|
|
39
41
|
fontWeight: string;
|
|
40
42
|
fontStyle: string;
|
|
41
43
|
textDecoration: string;
|
|
44
|
+
textTransform?: string;
|
|
42
45
|
set(attrs: Record<string, any>): void;
|
|
43
46
|
store?: {
|
|
44
47
|
history?: {
|
package/utils/text-format.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{parsePrimaryFontFamily as t,parseFontSizeToPx as e,parseHtmlRoot as o,stripInlineFontSizes as n,stripInlineFontFamilies as r,stripInlineFormat as i,toNumericWeight as s,qlClassToFontFamilyName as
|
|
1
|
+
import{parsePrimaryFontFamily as t,parseFontSizeToPx as e,parseHtmlRoot as o,stripInlineFontSizes as n,stripInlineFontFamilies as r,stripInlineFormat as i,toNumericWeight as s,qlClassToFontFamilyName as a,isClipGradientSpan as c,readNativeColor as f}from"./rich-text-html.js";export const FORMAT_KEYS=["fontSize","fontFamily","fill","fontWeight","fontStyle","textDecoration","textTransform"];export const DECORATION_TOKENS=["underline","line-through"];export function decorationTokensOf(t){const e=new Set;for(const o of(t||"").split(/\s+/)){"underline"!==o&&"line-through"!==o||e.add(o)}return e}export function decorationTokensToString(t){return DECORATION_TOKENS.filter(e=>t.has(e)).join(" ")}export function isDecorationActive(t,e){const o=t.textDecoration.values;return o.length>0&&o.every(t=>decorationTokensOf(t).has(e))}export const decorationToQuillKey=t=>"underline"===t?"underline":"strike";function l(o,n,r){switch(n){case"fontSize":return e(o.style.fontSize,r.fontSize);case"fontFamily":{if(o.style.fontFamily){return t(o.style.fontFamily)||void 0}const e=(o.getAttribute("class")||"").split(/\s+/).find(t=>t.startsWith("ql-font-"));return e&&a(e)||void 0}case"fill":return c(o)?f(o,"background-image")||o.style.backgroundImage:f(o,"color")||o.style.color||void 0;case"fontWeight":return o.style.fontWeight?s(o.style.fontWeight):"STRONG"===o.tagName||"B"===o.tagName?700:void 0;case"fontStyle":return o.style.fontStyle?o.style.fontStyle:"EM"===o.tagName||"I"===o.tagName?"italic":void 0;case"textDecoration":return o.style.textDecoration?o.style.textDecoration:"U"===o.tagName?"underline":"S"===o.tagName||"DEL"===o.tagName?"line-through":void 0;case"textTransform":return o.style.textTransform||void 0}}function u(t,e){return"fontWeight"===e?s(t.fontWeight):"textTransform"===e?t.textTransform||"none":t[e]}function d(t,e,o){const n={},r=new Set,i=decorationTokensOf(o.textDecoration);let s=t.parentElement;for(;s&&s!==e;){for(const t of FORMAT_KEYS){if("textDecoration"===t){const t=l(s,"textDecoration",o);if("string"==typeof t){for(const e of decorationTokensOf(t)){i.add(e)}}continue}if(r.has(t)){continue}const e=l(s,t,o);void 0!==e&&(n[t]=e,r.add(t))}s=s.parentElement}for(const a of FORMAT_KEYS){"textDecoration"===a||r.has(a)||(n[a]=u(o,a))}return n.textDecoration=decorationTokensToString(i),n}function h(t,e){return 0===t.length?{value:e,mixed:!1,values:void 0===e?[]:[e]}:1===t.length?{value:t[0],mixed:!1,values:t}:{value:void 0,mixed:!0,values:t}}function x(t){const e=function(t){const e=t.text||"";if(!e.includes("<")){if(0===e.trim().length){return[]}const o={};for(const e of FORMAT_KEYS){o[e]=u(t,e)}return[o]}const n=o(e);if(!n){return[]}const r=[],i=n.ownerDocument.createTreeWalker(n,NodeFilter.SHOW_TEXT);let s=i.nextNode();for(;s;){const e=s;(e.textContent||"").trim().length>0&&r.push(d(e,n,t)),s=i.nextNode()}return r}(t),n={};for(const o of FORMAT_KEYS){const r=[];for(const t of e){const e=t[o];void 0===e||r.includes(e)||r.push(e)}const i=0===r.length?u(t,o):void 0;n[o]=h(r,i)}return n}export function getTextFormat(t){return Array.isArray(t)?function(t){const e={};for(const o of FORMAT_KEYS){const n=[];for(const e of t){for(const t of e[o].values){n.includes(t)||n.push(t)}}e[o]=h(n,void 0)}return e}(t.map(x)):x(t)}function T(t,e){switch(e){case"fontSize":return n(t);case"fontFamily":return r(t);case"fill":return i(t,"color");case"fontWeight":return i(t,"bold");case"fontStyle":return i(t,"italic");case"textDecoration":return i(i(t,"underline"),"strike");case"textTransform":return i(t,"text-transform")}}let g=!1;function m(t){return"string"!=typeof t||/^\d+$/.test(t.trim())||g||(g=!0,console.warn("[polotno] applyTextFormat({ fontWeight }) with a string such as 'bold'/'normal' is deprecated; pass a number (100–900), e.g. 700.")),s(t)}export function patchTextFormat(t,e,o){var n;const r=FORMAT_KEYS.filter(t=>void 0!==e[t]);if(0===r.length){return{attrsToSet:{}}}const s=null!==(n=null==o?void 0:o.decorationTokens)&&void 0!==n?n:DECORATION_TOKENS,a={};let c=t.text||"";for(const f of r){if("textDecoration"===f){const o=decorationTokensOf(e.textDecoration),n=decorationTokensOf(t.textDecoration);for(const t of s){o.has(t)?n.add(t):n.delete(t),c=i(c,decorationToQuillKey(t))}a.textDecoration=decorationTokensToString(n);continue}a[f]="fontWeight"===f?String(m(e.fontWeight)):e[f],c=T(c,f)}return c!==(t.text||"")&&(a.text=c),{attrsToSet:a}}export function applyTextFormat(t,e,o){var n;const r=Array.isArray(t)?t:[t];if(0===r.length){return}const i=t=>{const{attrsToSet:n}=patchTextFormat(t,e,o);Object.keys(n).length&&t.set(n)};if(1===r.length){return void i(r[0])}const s=new Map;for(const a of r){const t=a.store,e=s.get(t)||[];e.push(a),s.set(t,e)}for(const[a,c]of s){(null===(n=null==a?void 0:a.history)||void 0===n?void 0:n.transaction)?a.history.transaction(()=>c.forEach(i)):c.forEach(i)}}
|
package/utils/to-pptx.d.ts
CHANGED
package/utils/to-pptx.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{loadImage as t,cropImage as e}from"@polotno/core/image";import*as o from"@polotno/core/svg";import{figureToSvg as a}from"@polotno/core/figure-to-svg";import{removeTags as i}from"@polotno/core/text";import{isBoldWeight as n}from"@polotno/core/rich-text-html";import{
|
|
1
|
+
import{loadImage as t,cropImage as e}from"@polotno/core/image";import*as o from"@polotno/core/svg";import{figureToSvg as a}from"@polotno/core/figure-to-svg";import{removeTags as i}from"@polotno/core/text";import{isBoldWeight as n}from"@polotno/core/rich-text-html";import{toDisplayDesign as r}from"@polotno/core/color";import{pxToUnit as s}from"./unit.js";import d from"konva";console.warn('"polotno/utils/to-pptx" is deprecated, use the "@polotno/pptx-export" package instead');const c=t=>s({px:t,unit:"in",dpi:100}),l=t=>Math.round(100*(1-t)),h=t=>{const{dx:e,dy:o}=((t,e,o)=>{const a=(o%360+360)%360;if(0===a){return{dx:0,dy:0}}const i=a*Math.PI/180,n=t/2,r=e/2;return{dx:n*Math.cos(i)-r*Math.sin(i)-n,dy:n*Math.sin(i)+r*Math.cos(i)-r}})(t.width,t.height,t.rotation);return{x:c(t.x+e),y:c(t.y+o)}},g=t=>{if(!t){return"000000"}if(t.includes("gradient")){return console.warn("PPTX export: gradient fill is not supported, using black"),"000000"}if(/^[0-9a-fA-F]{6}$/.test(t)){return t.toLowerCase()}let e=d.Util.colorToRGBA(t);return!e&&/^[0-9a-fA-F]{3,6}$/.test(t)&&(e=d.Util.colorToRGBA("#"+t)),e?d.Util._rgbToHex(e.r,e.g,e.b).replace("#","").toLowerCase():t.replace("#","").toLowerCase()||"000000"};let p=null;export function getPptxGen(){return window.PptxGenJS?Promise.resolve(window.PptxGenJS):p||(p=new Promise(t=>{var e=document.createElement("script");e.onload=function(){t(window.PptxGenJS)},e.src="https://cdn.jsdelivr.net/gh/gitbrent/pptxgenjs/dist/pptxgen.bundle.js",document.head.appendChild(e)}),p)}const w=async({element:a,slide:i})=>{let{src:n}=a;if("svg"===a.type&&Object.keys(a.colorsReplace).length){const t=await o.urlToString(n);n=o.replaceColors(t,new Map(Object.entries(a.colorsReplace)))}const r=await t(n),s=r.width*a.cropWidth,d=r.height*a.cropHeight,p=a.width/a.height;let w,u;const f=s/d;"svg"===a.type?(w=s,u=d):p>=f?(w=s,u=s/p):(w=d*p,u=d);let m=await e(n,Object.assign(Object.assign({},a),{cropWidth:w/r.width,cropHeight:u/r.height}));(a.cornerRadius||a.borderSize)&&(m=await(async(e,{width:o,height:a,cornerRadius:i,borderSize:n,borderColor:r})=>{if(!i&&!n){return e}const s=await t(e),d=document.createElement("canvas");d.width=Math.max(1,Math.round(o)),d.height=Math.max(1,Math.round(a));const c=d.getContext("2d"),l=Math.max(0,i),h=d.width,p=d.height,w=(t=!1)=>{const e=Math.min(l,Math.min(h,p)/2);c.beginPath(),c.moveTo(e,0),c.lineTo(h-e,0),c.quadraticCurveTo(h,0,h,e),c.lineTo(h,p-e),c.quadraticCurveTo(h,p,h-e,p),c.lineTo(e,p),c.quadraticCurveTo(0,p,0,p-e),c.lineTo(0,e),c.quadraticCurveTo(0,0,e,0),c.closePath(),t&&n>0&&(c.lineWidth=n,c.strokeStyle="#"+g(r),c.stroke())};return w(!1),c.save(),c.clip(),c.drawImage(s,0,0,h,p),c.restore(),n>0&&w(!0),d.toDataURL("image/png")})(m,{width:a.width,height:a.height,cornerRadius:a.cornerRadius,borderSize:a.borderSize,borderColor:a.borderColor}));const b=Object.assign(Object.assign({},h(a)),{w:c(a.width),h:c(a.height),rotate:a.rotation,flipH:a.flipX,flipV:a.flipY,transparency:l(a.opacity)});if(a.shadowEnabled){const t=Math.hypot(a.shadowOffsetX,a.shadowOffsetY)/2,e=180*Math.atan2(a.shadowOffsetY,a.shadowOffsetX)/Math.PI;b.shadow={type:"outer",blur:a.shadowBlur/2,offset:t,angle:e,color:g(a.shadowColor),opacity:a.shadowOpacity}}await i.addImage(Object.assign({path:m},b))},u=t=>"arrow"===t?"arrow":"triangle"===t?"triangle":"circle"===t?"oval":"square"===t?"diamond":"none",f=t=>{if(t&&t.length){return t.length<=2?"dash":"dashDot"}},m={image:w,svg:w,gif:w,text:async({element:t,slide:e})=>{let o=i(t.text||"");"uppercase"===t.textTransform&&(o=o.toUpperCase());const a=Object.assign(Object.assign(Object.assign(Object.assign({},h(t)),{w:c(t.width),h:c(t.height),fontSize:Math.round(.75*t.fontSize),fontFace:t.fontFamily,color:g(t.fill),align:t.align,bold:n(t.fontWeight),italic:"italic"===t.fontStyle}),"underline"===t.textDecoration?{underline:{style:"sng",color:g(t.fill)}}:{}),{lineSpacingMultiple:t.lineHeight,rotate:t.rotation,fit:"shrink",transparency:l(t.opacity),margin:0});if("middle"===t.verticalAlign?a.valign="middle":"bottom"===t.verticalAlign?a.valign="bottom":a.valign="top",t.letterSpacing&&(a.charSpacing=t.letterSpacing*a.fontSize),t.strokeWidth>0&&(a.outline={size:.75*t.strokeWidth,color:g(t.stroke)}),t.shadowEnabled){const e=.75*Math.hypot(t.shadowOffsetX,t.shadowOffsetY)/2,o=180*Math.atan2(t.shadowOffsetY,t.shadowOffsetX)/Math.PI;a.shadow={type:"outer",blur:.75*t.shadowBlur,offset:e,angle:o,color:g(t.shadowColor),opacity:t.shadowOpacity}}if(t.backgroundEnabled&&(a.fill={color:g(t.backgroundColor)}),t.borderSize>0&&(a.line={color:g(t.borderColor),width:.75*t.borderSize},t.backgroundEnabled||(a.fill={type:"none"})),t.backgroundEnabled||t.borderSize>0){const e=t.backgroundCornerRadius*(t.fontSize*t.lineHeight*.5);a.rectRadius=c(e);const o=t.backgroundPadding*(t.fontSize*t.lineHeight);a.margin=Math.max(0,Math.round(.75*o))}await e.addText(o,a)},line:async({element:t,slide:e})=>{const o=Object.assign(Object.assign({},h(t)),{w:c(t.width),h:c(t.height),line:{color:g(t.color),width:t.height,beginArrowType:u(t.startHead),endArrowType:u(t.endHead),dashType:f(t.dash),transparency:l(t.opacity)},rotate:t.rotation,transparency:l(t.opacity)});await e.addShape("line",o)},figure:async({element:e,slide:o})=>{const i=a(e),n=await(async(e,o,a)=>{const i="data:image/svg+xml;base64,"+btoa(e),n=await t(i),r=document.createElement("canvas");return r.width=Math.max(1,Math.round(o)),r.height=Math.max(1,Math.round(a)),r.getContext("2d").drawImage(n,0,0,r.width,r.height),r.toDataURL("image/png")})(i,e.width,e.height),r=Object.assign(Object.assign({},h(e)),{w:c(e.width),h:c(e.height),rotate:e.rotation,transparency:l(e.opacity)});await o.addImage(Object.assign({path:n},r))},group:async({element:t,slide:e})=>{for(const o of t.children||[]){await b({element:o,slide:e})}},video:async({element:t,slide:e})=>{const o=Object.assign(Object.assign({},h(t)),{w:c(t.width),h:c(t.height),rotate:t.rotation});await e.addMedia(Object.assign({type:"video",path:t.src},o))}},b=async({element:t,slide:e})=>{if(!t.visible||!t.showInExport){return}const o=m[t.type];o?await o({element:t,slide:e}):console.warn(`PPTX export doesn't support ${t.type} type`)};export async function jsonToPPTX({json:t}){const e=r(t),o=new(await getPptxGen());o.defineLayout({name:"CUSTOM",width:c(e.width),height:c(e.height)}),o.layout="CUSTOM";for(const a of e.pages){const t=o.addSlide();if(/\.(jpg|jpeg|png|gif)$/i.test(a.background)||a.background.startsWith("data:image")||a.background.startsWith("http")){await t.addImage({path:a.background,x:0,y:0,w:o.width,h:o.height,sizing:{type:"contain"}})}else{const e=d.Util.colorToRGBA(a.background),o=d.Util._rgbToHex(e.r,e.g,e.b).replace("#","");t.background={color:o}}for(const e of a.children){await b({element:e,slide:t})}}return o.writeFile("test.pptx"),o}
|
package/utils/validate-key.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as e from"mobx";import{getAPI as o}from"./api.js";import{
|
|
1
|
+
import*as e from"mobx";import{getAPI as o}from"./api.js";import{removeBackgroundState as t}from"./flags.js";const n=e.observable({value:!1}),a=e.observable({value:"v1"});export const ___=()=>a.value;const i=e.observable({value:0});export const ____=()=>i.value;export const isCreditVisible=()=>n.value;const r=e.action(()=>{n.value=!0});let s="";export const getKey=()=>s||"";export const setKey=e=>{s=e||""};let l="undefined"!=typeof window?window.location.origin:"";const c="undefined"!=typeof navigator&&navigator.userAgent.indexOf("Headless")>-1,d="undefined"!=typeof navigator&&navigator.userAgent.indexOf("Electron")>-1;"file://"===l&&c&&(l="headless"),"file://"===l&&d&&(l="electron");const u=`%cPolotno error! Current domain is not allowed. It may lead to unexpected behavior and stop working. Please add "${l}" here: https://polotno.com/cabinet`;let p=fetch;export const __=e=>{p=e};export async function isKeyPaid(n){for(let s=0;s<5;s++){try{const r=await p(o()+"/validate-key",{method:"POST",body:JSON.stringify({key:n,site:location.host,skdVersion:"4.15.0"})});if(e.runInAction(()=>{a.value=r.headers.get("x-api-version")||""}),!n){return console.error("Polotno API is initialized without API key. It may lead to unexpected behavior and stop working. Please create API key here: https://polotno.com/cabinet"),e.runInAction(()=>{i.value=1}),!1}if(200!==r.status){await new Promise(e=>setTimeout(e,3e3));continue}const s=await r.json();return s.is_valid||(console.error("Polotno API key is not valid. Please get new API key here: https://polotno.com/cabinet"),e.runInAction(()=>{i.value=1})),s.is_paid||(console.log("%cPolotno Free Version. For development usage only. https://polotno.com/","background: rgb(0, 161, 255); color: white; padding: 5px; margin: 5px;"),e.runInAction(()=>{0===i.value&&(i.value=2)})),s.is_domain_valid||console.log(u,"background: rgba(247, 101, 68, 1); color: white; padding: 5px; margin: 5px;"),e.runInAction(()=>{t.defaultEnabled=s.remove_background_enabled}),s.is_paid||!1}catch(r){await new Promise(e=>setTimeout(e,3e3))}}return console.error("Can not validate Polotno API key. Please report to anton@polotno.com immediately."),!0}export async function validateKey(e){await isKeyPaid(s)&&!e||r()}
|