UNPKG

fabric

Version:

Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.

3 lines (2 loc) 2.29 kB
import{defineProperty as t}from"../../_virtual/_rollupPluginBabelHelpers.min.mjs";import{config as e}from"../config.min.mjs";import{ifNaN as s}from"../util/internals/ifNaN.min.mjs";import{uid as r}from"../util/internals/uid.min.mjs";import{loadImage as i}from"../util/misc/objectEnlive.min.mjs";import{pick as o}from"../util/misc/pick.min.mjs";import{toFixed as n}from"../util/misc/toFixed.min.mjs";import{classRegistry as a}from"../ClassRegistry.min.mjs";import{log as h}from"../util/internals/console.min.mjs";class c{get type(){return"pattern"}set type(t){h("warn","Setting type has no effect",t)}constructor(e){t(this,"repeat","repeat"),t(this,"offsetX",0),t(this,"offsetY",0),t(this,"crossOrigin",""),this.id=r(),Object.assign(this,e)}isImageSource(){return!!this.source&&"string"==typeof this.source.src}isCanvasSource(){return!!this.source&&!!this.source.toDataURL}sourceToString(){return this.isImageSource()?this.source.src:this.isCanvasSource()?this.source.toDataURL():""}toLive(t){return this.source&&(!this.isImageSource()||this.source.complete&&0!==this.source.naturalWidth&&0!==this.source.naturalHeight)?t.createPattern(this.source,this.repeat):null}toObject(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];const{repeat:s,crossOrigin:r}=this;return{...o(this,t),type:"pattern",source:this.sourceToString(),repeat:s,crossOrigin:r,offsetX:n(this.offsetX,e.NUM_FRACTION_DIGITS),offsetY:n(this.offsetY,e.NUM_FRACTION_DIGITS),patternTransform:this.patternTransform?[...this.patternTransform]:null}}toSVG(t){let{width:e,height:r}=t;const{source:i,repeat:o,id:n}=this,a=s(this.offsetX/e,0),h=s(this.offsetY/r,0);return[`<pattern id="SVGID_${n}" x="${a}" y="${h}" width="${"repeat-y"===o||"no-repeat"===o?1+Math.abs(a||0):s(i.width/e,0)}" height="${"repeat-x"===o||"no-repeat"===o?1+Math.abs(h||0):s(i.height/r,0)}">`,`<image x="0" y="0" width="${i.width}" height="${i.height}" xlink:href="${this.sourceToString()}"></image>`,"</pattern>",""].join("\n")}static async fromObject(t,e){let{type:s,source:r,patternTransform:o,...n}=t;const a=await i(r,{...e,crossOrigin:n.crossOrigin});return new this({...n,patternTransform:o&&o.slice(0),source:a})}}t(c,"type","Pattern"),a.setClass(c),a.setClass(c,"pattern");export{c as Pattern}; //# sourceMappingURL=Pattern.min.mjs.map