UNPKG

fabric

Version:

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

1 lines 5.65 kB
{"version":3,"file":"config.mjs","names":[],"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 */\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 */\n maxCacheSideLimit = 4096;\n\n /**\n * Lowest pixel limit for cache canvases, set at 256PX\n * @since 1.7.14\n * @type Number\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 * @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 */\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 */\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"],"mappings":";;AAEA,IAAM,oBAAN,MAAwB;;;;;;;;;;;;;;;;;;GAetB;GAA4B;GAAE;;;;;;GAK9B;GAAM;GAAG;;;;;;;GAMT;GACE,OAAO,WAAW,cAAc,OAAO,mBAAmB;GAAE;;;;;;;;GAO9D;GAAqB;GAAQ;;;;;;;;GAO7B;GAAoB;GAAK;;;;;;;;GAOzB;GAAoB;GAAI;;;;;;;;;;GASxB;GAAwB;GAAM;;;;;;;;;;GAS9B;GAAoB;GAAK;;;;;;;;;;;;GAWzB;GAAc;GAAK;;;;;;;;;;GASnB;GAAsB;GAAM;;;;;;;;;;;GAU5B;GAAsB;GAAM;;;;;;;GAM5B;GAAwE,EAAE;GAAC;;;;;;;;GAO3E;GAAsB;GAAE;;;AAG1B,IAAa,gBAAb,cAAmC,kBAAkB;CACnD,YAAY,QAAyB;AACnC,SAAO;AACP,OAAK,UAAU,OAAO;;CAGxB,UAAU,SAAyB,EAAE,EAAE;AACrC,SAAO,OAAO,MAAM,OAAO;;;;;CAM7B,SACE,QAAoE,EAAE,EACtE;AACA,OAAK,YAAY;GACf,GAAG,KAAK;GACR,GAAG;GACJ;;CAGH,YAAY,cAAwB,EAAE,EAAE;AACtC,cAAY,SAAS,eAAe;AAClC,UAAO,KAAK,UAAU;IACtB;;CAGJ,aAAa;AACX,OAAK,YAAY,EAAE;;CAGrB,gBAA6C,MAAoB;EAC/D,MAAM,WAAW,IAAI,mBAAmB;EACxC,MAAM,UAAA,SAAA,QAAA,SAAA,KAAA,IAAA,KAAA,IACJ,KAAM,QAAQ,KAAK,QAAQ;AACzB,OAAI,OAAO,SAAS;AACpB,UAAO;KACN,EAAE,CAAM,KAAI;AACjB,OAAK,UAAU,OAAO;;;AAI1B,MAAa,SAAS,IAAI,eAAe"}