UNPKG

fabric

Version:

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

1 lines 7.28 kB
{"version":3,"file":"StaticCanvasOptions.mjs","sources":["../../../src/canvas/StaticCanvasOptions.ts"],"sourcesContent":["import { iMatrix } from '../constants';\nimport type { FabricObject } from '../shapes/Object/FabricObject';\nimport type { TFiller, TMat2D, TOptions } from '../typedefs';\n\ninterface CanvasDrawableOptions {\n /**\n * if set to false background image is not affected by viewport transform\n * @since 1.6.3\n * @type Boolean\n * @todo we should really find a different way to do this\n * @default\n */\n backgroundVpt: boolean;\n\n /**\n * Background color of canvas instance.\n * @type {(String|TFiller)}\n * @default\n */\n backgroundColor: TFiller | string;\n\n /**\n * Background image of canvas instance.\n * since 2.4.0 image caching is active, please when putting an image as background, add to the\n * canvas property a reference to the canvas it is on. Otherwise the image cannot detect the zoom\n * vale. As an alternative you can disable image objectCaching\n * @type FabricObject\n * @default\n */\n backgroundImage?: FabricObject;\n\n /**\n * if set to false overlay image is not affected by viewport transform\n * @since 1.6.3\n * @type Boolean\n * @todo we should really find a different way to do this\n * @default\n */\n overlayVpt: boolean;\n\n /**\n * Overlay color of canvas instance.\n * @since 1.3.9\n * @type {(String|TFiller)}\n * @default\n */\n overlayColor: TFiller | string;\n\n /**\n * Overlay image of canvas instance.\n * since 2.4.0 image caching is active, please when putting an image as overlay, add to the\n * canvas property a reference to the canvas it is on. Otherwise the image cannot detect the zoom\n * vale. As an alternative you can disable image objectCaching\n * @type FabricObject\n * @default\n */\n overlayImage?: FabricObject;\n}\n\ninterface CanvasRenderingOptions {\n /**\n * Indicates whether {@link StaticCanvas#add}, {@link StaticCanvas#insertAt} and {@link StaticCanvas#remove},\n * {@link StaticCanvas#moveTo}, {@link StaticCanvas#clear} and many more, should also re-render canvas.\n * Disabling this option will not give a performance boost when adding/removing a lot of objects to/from canvas at once\n * since the renders are queued and executed one per frame.\n * Disabling is suggested anyway and managing the renders of the app manually is not a big effort ( canvas.requestRenderAll() )\n * Left default to true to do not break documentation and old app, fiddles.\n * @type Boolean\n * @default\n */\n renderOnAddRemove: boolean;\n\n /**\n * Based on vptCoords and object.aCoords, skip rendering of objects that\n * are not included in current viewport.\n * May greatly help in applications with crowded canvas and use of zoom/pan\n * If One of the corner of the bounding box of the object is on the canvas\n * the objects get rendered.\n * @type Boolean\n * @default true\n */\n skipOffscreen: boolean;\n\n /**\n * When true, canvas is scaled by devicePixelRatio for better rendering on retina screens\n * @type Boolean\n * @default\n */\n enableRetinaScaling: boolean;\n\n /**\n * Indicates whether this canvas will use image smoothing, this is on by default in browsers\n * @type Boolean\n * @default\n */\n imageSmoothingEnabled: boolean;\n\n /**\n * a fabricObject that, without stroke define a clipping area with their shape. filled in black\n * the clipPath object gets used when the canvas has rendered, and the context is placed in the\n * top left corner of the canvas.\n * clipPath will clip away controls, if you do not want this to happen use controlsAboveOverlay = true\n * @type FabricObject\n */\n clipPath?: FabricObject;\n}\n\nexport interface CanvasExportOptions {\n /**\n * Indicates whether toObject/toDatalessObject should include default values\n * if set to false, takes precedence over the object value.\n * @type Boolean\n * @default\n */\n includeDefaultValues: boolean;\n\n /**\n * When true, getSvgTransform() will apply the StaticCanvas.viewportTransform to the SVG transformation. When true,\n * a zoomed canvas will then produce zoomed SVG output.\n * @type Boolean\n * @default\n */\n svgViewportTransformation: boolean;\n}\n\nexport interface StaticCanvasOptions\n extends CanvasDrawableOptions,\n CanvasRenderingOptions,\n CanvasExportOptions {\n /**\n * Width in virtual/logical pixels of the canvas.\n * The canvas can be larger than width if retina scaling is active\n * @type number\n */\n width: number;\n\n /**\n * Height in virtual/logical pixels of the canvas.\n * The canvas can be taller than width if retina scaling is active\n * @type height\n */\n height: number;\n\n /**\n * Indicates whether object controls (borders/controls) are rendered above overlay image\n * @type Boolean\n * @default\n *\n * @todo move to Canvas\n */\n controlsAboveOverlay: boolean;\n\n /**\n * Indicates whether the browser can be scrolled when using a touchscreen and dragging on the canvas\n * It gives PRIORITY to DOM scrolling, it doesn't make it always possible.\n * If is true, when using a touch event on the canvas, the canvas will scroll if scroll is possible.\n * If we are in drawing mode or if we are selecting an object the canvas preventDefault and so it won't scroll\n * @type Boolean\n * @default\n *\n * @todo move to Canvas\n */\n allowTouchScrolling: boolean;\n\n /**\n * The transformation (a Canvas 2D API transform matrix) which focuses the viewport\n * @type Array\n * @example <caption>Default transform</caption>\n * canvas.viewportTransform = [1, 0, 0, 1, 0, 0];\n * @example <caption>Scale by 70% and translate toward bottom-right by 50, without skewing</caption>\n * canvas.viewportTransform = [0.7, 0, 0, 0.7, 50, 50];\n * @default\n */\n viewportTransform: TMat2D;\n}\n\nexport const staticCanvasDefaults: TOptions<StaticCanvasOptions> = {\n backgroundVpt: true,\n backgroundColor: '',\n overlayVpt: true,\n overlayColor: '',\n\n includeDefaultValues: true,\n svgViewportTransformation: true,\n\n renderOnAddRemove: true,\n skipOffscreen: true,\n enableRetinaScaling: true,\n imageSmoothingEnabled: true,\n\n /**\n * @todo move to Canvas\n */\n controlsAboveOverlay: false,\n /**\n * @todo move to Canvas\n */\n allowTouchScrolling: false,\n\n viewportTransform: [...iMatrix],\n};\n"],"names":["staticCanvasDefaults","backgroundVpt","backgroundColor","overlayVpt","overlayColor","includeDefaultValues","svgViewportTransformation","renderOnAddRemove","skipOffscreen","enableRetinaScaling","imageSmoothingEnabled","controlsAboveOverlay","allowTouchScrolling","viewportTransform","iMatrix"],"mappings":";;AAgLO,MAAMA,oBAAmD,GAAG;AACjEC,EAAAA,aAAa,EAAE,IAAI;AACnBC,EAAAA,eAAe,EAAE,EAAE;AACnBC,EAAAA,UAAU,EAAE,IAAI;AAChBC,EAAAA,YAAY,EAAE,EAAE;AAEhBC,EAAAA,oBAAoB,EAAE,IAAI;AAC1BC,EAAAA,yBAAyB,EAAE,IAAI;AAE/BC,EAAAA,iBAAiB,EAAE,IAAI;AACvBC,EAAAA,aAAa,EAAE,IAAI;AACnBC,EAAAA,mBAAmB,EAAE,IAAI;AACzBC,EAAAA,qBAAqB,EAAE,IAAI;AAE3B;AACF;AACA;AACEC,EAAAA,oBAAoB,EAAE,KAAK;AAC3B;AACF;AACA;AACEC,EAAAA,mBAAmB,EAAE,KAAK;EAE1BC,iBAAiB,EAAE,CAAC,GAAGC,OAAO,CAAA;AAChC;;;;"}