fabric
Version:
Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.
3 lines • 2.32 kB
JavaScript
import{_defineProperty as e}from"../../_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.min.mjs";import{config as t}from"../config.min.mjs";import{log as n}from"../util/internals/console.min.mjs";import{classRegistry as r}from"../ClassRegistry.min.mjs";import{uid as i}from"../util/internals/uid.min.mjs";import{loadImage as a}from"../util/misc/objectEnlive.min.mjs";import{pick as o}from"../util/misc/pick.min.mjs";import{toFixed as s}from"../util/misc/toFixed.min.mjs";import{escapeXml as c}from"../util/lang_string.min.mjs";import{ifNaN as l}from"../util/internals/ifNaN.min.mjs";var u=class{get type(){return`pattern`}set type(e){n(`warn`,`Setting type has no effect`,e)}constructor(t){e(this,`repeat`,`repeat`),e(this,`offsetX`,0),e(this,`offsetY`,0),e(this,`crossOrigin`,``),this.id=i(),Object.assign(this,t)}isImageSource(){return!!this.source&&typeof this.source.src==`string`}isCanvasSource(){return!!this.source&&!!this.source.toDataURL}sourceToString(){return this.isImageSource()?this.source.src:this.isCanvasSource()?this.source.toDataURL():``}toLive(e){return this.source&&(!this.isImageSource()||this.source.complete&&this.source.naturalWidth!==0&&this.source.naturalHeight!==0)?e.createPattern(this.source,this.repeat):null}toObject(e=[]){let{repeat:n,crossOrigin:r}=this;return{...o(this,e),type:`pattern`,source:this.sourceToString(),repeat:n,crossOrigin:r,offsetX:s(this.offsetX,t.NUM_FRACTION_DIGITS),offsetY:s(this.offsetY,t.NUM_FRACTION_DIGITS),patternTransform:this.patternTransform?[...this.patternTransform]:null}}toSVG({width:e,height:t}){let{source:n,repeat:r,id:i}=this,a=l(this.offsetX/e,0),o=l(this.offsetY/t,0),s=r===`repeat-y`||r===`no-repeat`?1+Math.abs(a||0):l(n.width/e,0),u=r===`repeat-x`||r===`no-repeat`?1+Math.abs(o||0):l(n.height/t,0);return[`<pattern id="SVGID_${c(i)}" x="${a}" y="${o}" width="${s}" height="${u}">`,`<image x="0" y="0" width="${n.width}" height="${n.height}" xlink:href="${c(this.sourceToString())}"></image>`,`</pattern>`,``].join(`
`)}static async fromObject({type:e,source:t,patternTransform:n,...r},i){let o=await a(t,{...i,crossOrigin:r.crossOrigin});return new this({...r,patternTransform:n&&n.slice(0),source:o})}};e(u,`type`,`Pattern`),r.setClass(u),r.setClass(u,`pattern`);export{u as Pattern};
//# sourceMappingURL=Pattern.min.mjs.map