UNPKG

fabric

Version:

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

1 lines 6.05 kB
{"version":3,"file":"config.min.mjs","sources":["../../src/config.ts"],"sourcesContent":["export type TConfiguration = Partial<BaseConfiguration>;\n\nclass BaseConfiguration {\n /**\n * Browser-specific constant to adjust CanvasRenderingContext2D.shadowBlur value,\n * which is unitless and not rendered equally across browsers.\n *\n * Values that work quite well (as of October 2017) are:\n * - Chrome: 1.5\n * - Edge: 1.75\n * - Firefox: 0.9\n * - Safari: 0.95\n *\n * @since 2.0.0\n * @type Number\n * @default 1\n */\n browserShadowBlurConstant = 1;\n\n /**\n * Pixel per Inch as a default value set to 96. Can be changed for more realistic conversion.\n */\n DPI = 96;\n\n /**\n * Device Pixel Ratio\n * @see https://developer.apple.com/library/safari/documentation/AudioVideo/Conceptual/HTML-canvas-guide/SettingUptheCanvas/SettingUptheCanvas.html\n */\n devicePixelRatio =\n typeof window !== 'undefined' ? window.devicePixelRatio : 1; // eslint-disable-line no-restricted-globals\n\n /**\n * Pixel limit for cache canvases. 1Mpx , 4Mpx should be fine.\n * @since 1.7.14\n * @type Number\n * @default\n */\n perfLimitSizeTotal = 2097152;\n\n /**\n * Pixel limit for cache canvases width or height. IE fixes the maximum at 5000\n * @since 1.7.14\n * @type Number\n * @default\n */\n maxCacheSideLimit = 4096;\n\n /**\n * Lowest pixel limit for cache canvases, set at 256PX\n * @since 1.7.14\n * @type Number\n * @default\n */\n minCacheSideLimit = 256;\n\n /**\n * When 'true', style information is not retained when copy/pasting text, making\n * pasted text use destination style.\n * Defaults to 'false'.\n * @type Boolean\n * @default\n * @deprecated\n */\n disableStyleCopyPaste = false;\n\n /**\n * Enable webgl for filtering picture is available\n * A filtering backend will be initialized, this will both take memory and\n * time since a default 2048x2048 canvas will be created for the gl context\n * @since 2.0.0\n * @type Boolean\n * @default\n */\n enableGLFiltering = true;\n\n /**\n * if webgl is enabled and available, textureSize will determine the size\n * of the canvas backend\n *\n * In order to support old hardware set to `2048` to avoid OOM\n *\n * @since 2.0.0\n * @type Number\n * @default\n */\n textureSize = 4096;\n\n /**\n * Skip performance testing of setupGLContext and force the use of putImageData that seems to be the one that works best on\n * Chrome + old hardware. if your users are experiencing empty images after filtering you may try to force this to true\n * this has to be set before instantiating the filtering backend ( before filtering the first image )\n * @type Boolean\n * @default false\n */\n forceGLPutImageData = false;\n\n /**\n * If disabled boundsOfCurveCache is not used. For apps that make heavy usage of pencil drawing probably disabling it is better\n * With the standard behaviour of fabric to translate all curves in absolute commands and by not subtracting the starting point from\n * the curve is very hard to hit any cache.\n * Enable only if you know why it could be useful.\n * Candidate for removal/simplification\n * @default false\n */\n cachesBoundsOfCurve = false;\n\n /**\n * Map of font files\n * Map<fontFamily, pathToFile> of font files\n */\n fontPaths: Record</** fontFamily */ string, /** pathToFile */ string> = {};\n\n /**\n * Defines the number of fraction digits to use when serializing object values.\n * Used in exporting methods (`toObject`, `toJSON`, `toSVG`)\n * You can use it to increase/decrease precision of such values like left, top, scaleX, scaleY, etc.\n */\n NUM_FRACTION_DIGITS = 4;\n}\n\nexport class Configuration extends BaseConfiguration {\n constructor(config?: TConfiguration) {\n super();\n this.configure(config);\n }\n\n configure(config: TConfiguration = {}) {\n Object.assign(this, config);\n }\n\n /**\n * Map<fontFamily, pathToFile> of font files\n */\n addFonts(\n paths: Record</** fontFamily */ string, /** pathToFile */ string> = {},\n ) {\n this.fontPaths = {\n ...this.fontPaths,\n ...paths,\n };\n }\n\n removeFonts(fontFamilys: string[] = []) {\n fontFamilys.forEach((fontFamily) => {\n delete this.fontPaths[fontFamily];\n });\n }\n\n clearFonts() {\n this.fontPaths = {};\n }\n\n restoreDefaults<T extends BaseConfiguration>(keys?: (keyof T)[]) {\n const defaults = new BaseConfiguration() as T;\n const config =\n keys?.reduce((acc, key) => {\n acc[key] = defaults[key];\n return acc;\n }, {} as T) || defaults;\n this.configure(config);\n }\n}\n\nexport const config = new Configuration();\n"],"names":["BaseConfiguration","constructor","_defineProperty","this","window","devicePixelRatio","Configuration","config","super","configure","arguments","length","undefined","Object","assign","addFonts","paths","fontPaths","_objectSpread","removeFonts","forEach","fontFamily","clearFonts","restoreDefaults","keys","defaults","reduce","acc","key"],"mappings":"kGAEA,MAAMA,EAAkBC,WAAAA,GACtBC,mCAc4B,GAE5BA,aAGM,IAENA,EAAAC,KAAA,mBAKoB,oBAAXC,OAAyBA,OAAOC,iBAAmB,GAE5DH,4BAMqB,SAErBA,2BAMoB,MAEpBA,2BAMoB,KAEpBA,gCAQwB,GAExBA,4BAQoB,GAEpBA,qBAUc,MAEdA,8BAOsB,GAEtBA,8BAQsB,GAEtBA,EAAAC,KAAA,YAIwE,CAAA,GAExED,6BAKsB,EAAC,EAGlB,MAAMI,UAAsBN,EACjCC,WAAAA,CAAYM,GACVC,QACAL,KAAKM,UAAUF,EACjB,CAEAE,SAAAA,GAAuC,IAA7BF,EAAsBG,UAAAC,OAAA,QAAAC,IAAAF,UAAA,GAAAA,UAAA,GAAG,CAAA,EACjCG,OAAOC,OAAOX,KAAMI,EACtB,CAKAQ,QAAAA,GAEE,IADAC,EAAiEN,UAAAC,OAAA,QAAAC,IAAAF,UAAA,GAAAA,UAAA,GAAG,CAAA,EAEpEP,KAAKc,UAASC,EAAAA,EACT,CAAA,EAAAf,KAAKc,WACLD,EAEP,CAEAG,WAAAA,IAAiCT,UAAAC,OAAA,QAAAC,IAAAF,UAAA,GAAAA,UAAA,GAAG,IACtBU,SAASC,WACZlB,KAAKc,UAAUI,EAAW,GAErC,CAEAC,UAAAA,GACEnB,KAAKc,UAAY,EACnB,CAEAM,eAAAA,CAA6CC,GAC3C,MAAMC,EAAW,IAAIzB,EACfO,GACJiB,aAAI,EAAJA,EAAME,QAAO,CAACC,EAAKC,KACjBD,EAAIC,GAAOH,EAASG,GACbD,IACN,CAAA,KAAYF,EACjBtB,KAAKM,UAAUF,EACjB,QAGWA,EAAS,IAAID"}