fabric
Version:
Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.
1 lines • 2.06 MB
Source Map (JSON)
{"version":3,"file":"index.mjs","sources":["../src/config.ts","../src/util/internals/console.ts","../src/filters/GLProbes/GLProbe.ts","../src/filters/GLProbes/WebGLProbe.ts","../src/env/browser.ts","../src/env/index.ts","../src/cache.ts","../src/constants.ts","../src/ClassRegistry.ts","../src/util/animation/AnimationRegistry.ts","../src/Observable.ts","../src/util/internals/removeFromArray.ts","../src/util/misc/cos.ts","../src/util/misc/sin.ts","../src/Point.ts","../src/Collection.ts","../src/CommonMethods.ts","../src/util/animation/AnimationFrameProvider.ts","../src/util/internals/uid.ts","../src/util/misc/dom.ts","../src/util/misc/radiansDegreesConversion.ts","../src/util/misc/matrix.ts","../src/util/misc/objectEnlive.ts","../src/util/misc/pick.ts","../src/util/misc/toFixed.ts","../src/util/misc/svgExport.ts","../src/util/typeAssertions.ts","../src/util/dom_misc.ts","../src/canvas/DOMManagers/util.ts","../src/canvas/DOMManagers/StaticCanvasDOMManager.ts","../src/canvas/StaticCanvasOptions.ts","../src/canvas/StaticCanvas.ts","../src/util/dom_event.ts","../src/util/misc/boundingBoxFromPoints.ts","../src/util/misc/objectTransforms.ts","../src/util/misc/planeChange.ts","../src/controls/fireEvent.ts","../src/util/misc/resolveOrigin.ts","../src/controls/util.ts","../src/controls/drag.ts","../src/color/color_map.ts","../src/color/constants.ts","../src/color/util.ts","../src/color/Color.ts","../src/util/misc/svgParsing.ts","../src/shapes/Object/FabricObjectSVGExportMixin.ts","../src/parser/getSvgRegex.ts","../src/shapes/Text/constants.ts","../src/parser/constants.ts","../src/util/misc/vectors.ts","../src/Shadow.ts","../src/util/misc/capValue.ts","../src/shapes/Object/defaultValues.ts","../src/util/animation/easing.ts","../src/util/animation/AnimationBase.ts","../src/util/animation/ValueAnimation.ts","../src/util/animation/ArrayAnimation.ts","../src/util/animation/ColorAnimation.ts","../src/util/animation/animate.ts","../src/Intersection.ts","../src/shapes/Object/ObjectGeometry.ts","../src/shapes/Object/Object.ts","../src/controls/wrapWithFireEvent.ts","../src/controls/wrapWithFixedAnchor.ts","../src/controls/changeWidth.ts","../src/controls/controlRendering.ts","../src/controls/Control.ts","../src/controls/rotate.ts","../src/controls/scale.ts","../src/controls/skew.ts","../src/controls/scaleSkew.ts","../src/controls/commonControls.ts","../src/shapes/Object/InteractiveObject.ts","../src/util/applyMixins.ts","../src/shapes/Object/FabricObject.ts","../src/util/misc/isTransparent.ts","../src/util/misc/rotatePoint.ts","../src/util/internals/findRight.ts","../src/util/misc/projectStroke/StrokeProjectionsBase.ts","../src/util/misc/projectStroke/StrokeLineJoinProjections.ts","../src/util/misc/projectStroke/StrokeLineCapProjections.ts","../src/util/misc/projectStroke/index.ts","../src/util/internals/cloneStyles.ts","../src/util/lang_string.ts","../src/util/misc/textStyles.ts","../src/parser/attributes.ts","../src/parser/selectorMatches.ts","../src/parser/doesSomeParentMatch.ts","../src/parser/elementMatchesRule.ts","../src/parser/getGlobalStylesForElement.ts","../src/parser/normalizeAttr.ts","../src/util/internals/cleanupSvgAttribute.ts","../src/parser/parseTransformAttribute.ts","../src/parser/normalizeValue.ts","../src/parser/parseFontDeclaration.ts","../src/parser/parseStyleObject.ts","../src/parser/parseStyleString.ts","../src/parser/parseStyleAttribute.ts","../src/parser/setStrokeFillOpacity.ts","../src/parser/parseAttributes.ts","../src/shapes/Rect.ts","../src/LayoutManager/constants.ts","../src/LayoutManager/LayoutStrategies/utils.ts","../src/LayoutManager/LayoutStrategies/LayoutStrategy.ts","../src/LayoutManager/LayoutStrategies/FitContentLayout.ts","../src/LayoutManager/LayoutManager.ts","../src/shapes/Group.ts","../src/util/misc/groupSVGElements.ts","../src/util/misc/findScaleTo.ts","../src/util/path/regex.ts","../src/util/path/index.ts","../src/util/dom_style.ts","../src/util/misc/mergeClipPaths.ts","../src/util/internals/getRandomInt.ts","../src/util/internals/dom_request.ts","../src/util/transform_matrix_removal.ts","../src/canvas/DOMManagers/CanvasDOMManager.ts","../src/canvas/CanvasOptions.ts","../src/canvas/SelectableCanvas.ts","../src/canvas/TextEditingManager.ts","../src/canvas/Canvas.ts","../src/gradient/constants.ts","../src/util/internals/ifNaN.ts","../src/parser/percent.ts","../src/gradient/parser/parseColorStops.ts","../src/gradient/parser/misc.ts","../src/gradient/parser/parseCoords.ts","../src/gradient/Gradient.ts","../src/Pattern/Pattern.ts","../src/brushes/BaseBrush.ts","../src/shapes/Path.ts","../src/brushes/PencilBrush.ts","../src/shapes/Circle.ts","../src/brushes/CircleBrush.ts","../src/brushes/SprayBrush.ts","../src/brushes/PatternBrush.ts","../src/shapes/Line.ts","../src/shapes/Triangle.ts","../src/shapes/Ellipse.ts","../src/parser/parsePointsAttribute.ts","../src/shapes/Polyline.ts","../src/shapes/Polygon.ts","../src/shapes/Text/StyledText.ts","../src/shapes/Text/TextSVGExportMixin.ts","../src/shapes/Text/Text.ts","../src/shapes/IText/DraggableTextDelegate.ts","../src/shapes/IText/ITextBehavior.ts","../src/shapes/IText/ITextKeyBehavior.ts","../src/shapes/IText/ITextClickBehavior.ts","../src/shapes/IText/constants.ts","../src/util/internals/applyCanvasTransform.ts","../src/shapes/IText/IText.ts","../src/shapes/Textbox.ts","../src/LayoutManager/LayoutStrategies/ClipPathLayout.ts","../src/LayoutManager/LayoutStrategies/FixedLayout.ts","../src/LayoutManager/ActiveSelectionLayoutManager.ts","../src/shapes/ActiveSelection.ts","../src/filters/Canvas2dFilterBackend.ts","../src/filters/WebGLFilterBackend.ts","../src/filters/FilterBackend.ts","../src/shapes/Image.ts","../src/parser/applyViewboxTransform.ts","../src/parser/getTagName.ts","../src/parser/hasInvalidAncestor.ts","../src/parser/getMultipleNodes.ts","../src/parser/parseUseDirectives.ts","../src/parser/recursivelyParseGradientsXlink.ts","../src/parser/getGradientDefs.ts","../src/parser/getCSSRules.ts","../src/parser/elements_parser.ts","../src/parser/parseSVGDocument.ts","../src/parser/loadSVGFromString.ts","../src/parser/loadSVGFromURL.ts","../src/controls/polyControl.ts","../src/controls/pathControl.ts","../src/filters/utils.ts","../src/filters/shaders/baseFilter.ts","../src/filters/BaseFilter.ts","../src/filters/shaders/blendColor.ts","../src/filters/BlendColor.ts","../src/filters/shaders/blendImage.ts","../src/filters/BlendImage.ts","../src/filters/shaders/blur.ts","../src/filters/Blur.ts","../src/filters/shaders/brightness.ts","../src/filters/Brightness.ts","../src/filters/shaders/colorMatrix.ts","../src/filters/ColorMatrix.ts","../src/filters/ColorMatrixFilters.ts","../src/filters/Composed.ts","../src/filters/shaders/constrast.ts","../src/filters/Contrast.ts","../src/filters/shaders/convolute.ts","../src/filters/Convolute.ts","../src/filters/shaders/gamma.ts","../src/filters/Gamma.ts","../src/filters/shaders/grayscale.ts","../src/filters/Grayscale.ts","../src/filters/HueRotation.ts","../src/filters/shaders/invert.ts","../src/filters/Invert.ts","../src/filters/shaders/noise.ts","../src/filters/Noise.ts","../src/filters/shaders/pixelate.ts","../src/filters/Pixelate.ts","../src/filters/shaders/removeColor.ts","../src/filters/RemoveColor.ts","../src/filters/Resize.ts","../src/filters/shaders/saturation.ts","../src/filters/Saturation.ts","../src/filters/shaders/vibrance.ts","../src/filters/Vibrance.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","export const log = (\n severity: 'log' | 'warn' | 'error',\n ...optionalParams: any[]\n) =>\n // eslint-disable-next-line no-restricted-syntax\n console[severity]('fabric', ...optionalParams);\n\nexport class FabricError extends Error {\n constructor(message?: string, options?: ErrorOptions) {\n super(`fabric: ${message}`, options);\n }\n}\n\nexport class SignalAbortedError extends FabricError {\n constructor(context: string) {\n super(`${context} 'options.signal' is in 'aborted' state`);\n }\n}\n","export type GLPrecision = 'lowp' | 'mediump' | 'highp';\n\nexport abstract class GLProbe {\n declare GLPrecision: GLPrecision | undefined;\n abstract queryWebGL(canvas: HTMLCanvasElement): void;\n abstract isSupported(textureSize: number): boolean;\n}\n","import { log } from '../../util/internals/console';\nimport { GLProbe } from './GLProbe';\nimport type { GLPrecision } from './GLProbe';\n\n/**\n * Lazy initialize WebGL constants\n */\nexport class WebGLProbe extends GLProbe {\n declare maxTextureSize?: number;\n\n /**\n * Tests if webgl supports certain precision\n * @param {WebGL} Canvas WebGL context to test on\n * @param {GLPrecision} Precision to test can be any of following\n * @returns {Boolean} Whether the user's browser WebGL supports given precision.\n */\n private testPrecision(\n gl: WebGLRenderingContext,\n precision: GLPrecision,\n ): boolean {\n const fragmentSource = `precision ${precision} float;\\nvoid main(){}`;\n const fragmentShader = gl.createShader(gl.FRAGMENT_SHADER);\n if (!fragmentShader) {\n return false;\n }\n gl.shaderSource(fragmentShader, fragmentSource);\n gl.compileShader(fragmentShader);\n return !!gl.getShaderParameter(fragmentShader, gl.COMPILE_STATUS);\n }\n\n /**\n * query browser for WebGL\n */\n queryWebGL(canvas: HTMLCanvasElement) {\n const gl = canvas.getContext('webgl');\n if (gl) {\n this.maxTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE);\n this.GLPrecision = (['highp', 'mediump', 'lowp'] as const).find(\n (precision) => this.testPrecision(gl, precision),\n );\n gl.getExtension('WEBGL_lose_context')!.loseContext();\n log('log', `WebGL: max texture size ${this.maxTextureSize}`);\n }\n }\n\n isSupported(textureSize: number) {\n return !!this.maxTextureSize && this.maxTextureSize >= textureSize;\n }\n}\n","/* eslint-disable no-restricted-globals */\nimport { WebGLProbe } from '../filters/GLProbes/WebGLProbe';\nimport type { TCopyPasteData, TFabricEnv } from './types';\n\nconst copyPasteData: TCopyPasteData = {};\n\nexport const getEnv = (): TFabricEnv => {\n return {\n document,\n window,\n isTouchSupported:\n 'ontouchstart' in window ||\n 'ontouchstart' in document ||\n (window && window.navigator && window.navigator.maxTouchPoints > 0),\n WebGLProbe: new WebGLProbe(),\n dispose() {\n // noop\n },\n copyPasteData,\n };\n};\n","/**\n * This file is consumed by fabric.\n * The `./node` and `./browser` files define the env variable that is used by this module.\n * The `./browser` module is defined to be the default env and doesn't set the env at all.\n * This is done in order to support isomorphic usage for browser and node applications\n * since window and document aren't defined at time of import in SSR, we can't set env so we avoid it by deferring to the default env.\n */\n\nimport { config } from '../config';\nimport { getEnv as getBrowserEnv } from './browser';\nimport type { TFabricEnv } from './types';\nimport type { DOMWindow } from 'jsdom';\n\nlet env: TFabricEnv;\n\n/**\n * Sets the environment variables used by fabric.\\\n * This is exposed for special cases, such as configuring a test environment, and should be used with care.\n *\n * **CAUTION**: Must be called before using the package.\n *\n * @example\n * <caption>Passing `window` and `document` objects to fabric (in case they are mocked or something)</caption>\n * import { getEnv, setEnv } from 'fabric';\n * // we want fabric to use the `window` and `document` objects exposed by the environment we are running in.\n * setEnv({ ...getEnv(), window, document });\n * // done with setup, using fabric is now safe\n */\nexport const setEnv = (value: TFabricEnv) => {\n env = value;\n};\n\n/**\n * In order to support SSR we **MUST** access the browser env only after the window has loaded\n */\nexport const getEnv = () => env || (env = getBrowserEnv());\n\nexport const getFabricDocument = (): Document => getEnv().document;\n\nexport const getFabricWindow = (): (Window & typeof globalThis) | DOMWindow =>\n getEnv().window;\n\n/**\n * @returns the config value if defined, fallbacks to the environment value\n */\nexport const getDevicePixelRatio = () =>\n Math.max(config.devicePixelRatio ?? getFabricWindow().devicePixelRatio, 1);\n","import { config } from './config';\nimport type { TRectBounds } from './typedefs';\n\nexport class Cache {\n /**\n * Cache of widths of chars in text rendering.\n */\n charWidthsCache: Record<\n /** fontFamily */ string,\n Record<\n /** fontStyleCacheKey */ string,\n Record</** char */ string, /** width */ number>\n >\n > = {};\n\n /**\n * @return {Object} reference to cache\n */\n getFontCache({\n fontFamily,\n fontStyle,\n fontWeight,\n }: {\n fontFamily: string;\n fontStyle: string;\n fontWeight: string | number;\n }) {\n fontFamily = fontFamily.toLowerCase();\n if (!this.charWidthsCache[fontFamily]) {\n this.charWidthsCache[fontFamily] = {};\n }\n const fontCache = this.charWidthsCache[fontFamily];\n const cacheKey = `${fontStyle.toLowerCase()}_${(\n fontWeight + ''\n ).toLowerCase()}`;\n if (!fontCache[cacheKey]) {\n fontCache[cacheKey] = {};\n }\n return fontCache[cacheKey];\n }\n\n /**\n * Clear char widths cache for the given font family or all the cache if no\n * fontFamily is specified.\n * Use it if you know you are loading fonts in a lazy way and you are not waiting\n * for custom fonts to load properly when adding text objects to the canvas.\n * If a text object is added when its own font is not loaded yet, you will get wrong\n * measurement and so wrong bounding boxes.\n * After the font cache is cleared, either change the textObject text content or call\n * initDimensions() to trigger a recalculation\n * @param {String} [fontFamily] font family to clear\n */\n clearFontCache(fontFamily?: string) {\n fontFamily = (fontFamily || '').toLowerCase();\n if (!fontFamily) {\n this.charWidthsCache = {};\n } else if (this.charWidthsCache[fontFamily]) {\n delete this.charWidthsCache[fontFamily];\n }\n }\n\n /**\n * Given current aspect ratio, determines the max width and height that can\n * respect the total allowed area for the cache.\n * @param {number} ar aspect ratio\n * @return {number[]} Limited dimensions X and Y\n */\n limitDimsByArea(ar: number) {\n const { perfLimitSizeTotal } = config;\n const roughWidth = Math.sqrt(perfLimitSizeTotal * ar);\n // we are not returning a point on purpose, to avoid circular dependencies\n // this is an internal utility\n return [\n Math.floor(roughWidth),\n Math.floor(perfLimitSizeTotal / roughWidth),\n ];\n }\n\n /**\n * This object keeps the results of the boundsOfCurve calculation mapped by the joined arguments necessary to calculate it.\n * It does speed up calculation, if you parse and add always the same paths, but in case of heavy usage of freedrawing\n * you do not get any speed benefit and you get a big object in memory.\n * The object was a private variable before, while now is appended to the lib so that you have access to it and you\n * can eventually clear it.\n * It was an internal variable, is accessible since version 2.3.4\n */\n boundsOfCurveCache: Record<string, TRectBounds> = {};\n}\n\nexport const cache = new Cache();\n","import type { TMat2D } from './typedefs';\n// use this syntax so babel plugin see this import here\nimport { version } from '../package.json';\n\nexport const VERSION = version;\n// eslint-disable-next-line @typescript-eslint/no-empty-function\nexport function noop() {}\n\nexport const halfPI = Math.PI / 2;\nexport const twoMathPi = Math.PI * 2;\nexport const PiBy180 = Math.PI / 180;\n\nexport const iMatrix = Object.freeze([1, 0, 0, 1, 0, 0]) as TMat2D;\nexport const DEFAULT_SVG_FONT_SIZE = 16;\nexport const ALIASING_LIMIT = 2;\n\n/* \"magic number\" for bezier approximations of arcs (http://itc.ktu.lt/itc354/Riskus354.pdf) */\nexport const kRect = 1 - 0.5522847498;\n\nexport const CENTER = 'center';\nexport const LEFT = 'left';\nexport const TOP = 'top';\nexport const BOTTOM = 'bottom';\nexport const RIGHT = 'right';\nexport const NONE = 'none';\n\nexport const reNewline = /\\r?\\n/;\n\nexport const MOVING = 'moving';\nexport const SCALING = 'scaling';\nexport const ROTATING = 'rotating';\nexport const ROTATE = 'rotate';\nexport const SKEWING = 'skewing';\nexport const RESIZING = 'resizing';\nexport const MODIFY_POLY = 'modifyPoly';\nexport const MODIFY_PATH = 'modifyPath';\nexport const CHANGED = 'changed';\nexport const SCALE = 'scale';\nexport const SCALE_X = 'scaleX';\nexport const SCALE_Y = 'scaleY';\nexport const SKEW_X = 'skewX';\nexport const SKEW_Y = 'skewY';\nexport const FILL = 'fill';\nexport const STROKE = 'stroke';\nexport const MODIFIED = 'modified';\n","import { FabricError } from './util/internals/console';\n\n/*\n * This Map connects the objects type value with their\n * class implementation. It used from any object to understand which are\n * the classes to enlive when requesting a object.type = 'path' for example.\n * Objects uses it for clipPath, Canvas uses it for everything.\n * This is necessary for generic code to run and enlive instances from serialized representation.\n * You can customize which classes get enlived from SVG parsing using this classRegistry.\n * The Registry start empty and gets filled in depending which files you import.\n * If you want to be able to parse arbitrary SVGs or JSON representation of canvases, coming from\n * different sources you will need to import all fabric because you may need all classes.\n */\n\nexport const JSON = 'json';\nexport const SVG = 'svg';\n\nexport class ClassRegistry {\n declare [JSON]: Map<string, any>;\n declare [SVG]: Map<string, any>;\n\n constructor() {\n this[JSON] = new Map();\n this[SVG] = new Map();\n }\n\n has(classType: string): boolean {\n return this[JSON].has(classType);\n }\n\n getClass<T>(classType: string): T {\n const constructor = this[JSON].get(classType);\n if (!constructor) {\n throw new FabricError(`No class registered for ${classType}`);\n }\n return constructor;\n }\n\n setClass(classConstructor: any, classType?: string) {\n if (classType) {\n this[JSON].set(classType, classConstructor);\n } else {\n this[JSON].set(classConstructor.type, classConstructor);\n // legacy\n // @TODO: needs to be removed in fabric 7 or 8\n this[JSON].set(classConstructor.type.toLowerCase(), classConstructor);\n }\n }\n\n getSVGClass(SVGTagName: string): any {\n return this[SVG].get(SVGTagName);\n }\n\n setSVGClass(classConstructor: any, SVGTagName?: string) {\n this[SVG].set(\n SVGTagName ?? classConstructor.type.toLowerCase(),\n classConstructor,\n );\n }\n}\n\nexport const classRegistry = new ClassRegistry();\n","import type { StaticCanvas } from '../../canvas/StaticCanvas';\nimport type { FabricObject } from '../../shapes/Object/FabricObject';\nimport type { AnimationBase } from './AnimationBase';\n\n/**\n * Array holding all running animations\n */\nclass AnimationRegistry extends Array<AnimationBase> {\n /**\n * Remove a single animation using an animation context\n * @param {AnimationBase} context\n */\n remove(context: AnimationBase) {\n const index = this.indexOf(context);\n index > -1 && this.splice(index, 1);\n }\n\n /**\n * Cancel all running animations on the next frame\n */\n cancelAll() {\n const animations = this.splice(0);\n animations.forEach((animation) => animation.abort());\n return animations;\n }\n\n /**\n * Cancel all running animations attached to a canvas on the next frame\n * @param {StaticCanvas} canvas\n */\n cancelByCanvas(canvas: StaticCanvas) {\n if (!canvas) {\n return [];\n }\n const animations = this.filter(\n (animation) =>\n animation.target === canvas ||\n (typeof animation.target === 'object' &&\n (animation.target as FabricObject)?.canvas === canvas),\n );\n animations.forEach((animation) => animation.abort());\n return animations;\n }\n\n /**\n * Cancel all running animations for target on the next frame\n * @param target\n */\n cancelByTarget(target: AnimationBase['target']) {\n if (!target) {\n return [];\n }\n const animations = this.filter((animation) => animation.target === target);\n animations.forEach((animation) => animation.abort());\n return animations;\n }\n}\n\nexport const runningAnimations = new AnimationRegistry();\n","export type TEventCallback<T = any> = (options: T) => any;\n\ntype EventRegistryObject<E> = {\n [K in keyof E]?: TEventCallback<E[K]>;\n};\n\n/**\n * @tutorial {@link http://fabricjs.com/fabric-intro-part-2#events}\n * @see {@link http://fabricjs.com/events|Events demo}\n */\nexport class Observable<EventSpec> {\n private __eventListeners: Record<keyof EventSpec, TEventCallback[]> =\n {} as Record<keyof EventSpec, TEventCallback[]>;\n\n /**\n * Observes specified event\n * @alias on\n * @param {string} eventName Event name (eg. 'after:render')\n * @param {EventRegistryObject} handlers key/value pairs (eg. {'after:render': handler, 'selection:cleared': handler})\n * @param {Function} handler Function that receives a notification when an event of the specified type occurs\n * @return {Function} disposer\n */\n on<K extends keyof EventSpec, E extends EventSpec[K]>(\n eventName: K,\n handler: TEventCallback<E>,\n ): VoidFunction;\n on(handlers: EventRegistryObject<EventSpec>): VoidFunction;\n on<K extends keyof EventSpec, E extends EventSpec[K]>(\n arg0: K | EventRegistryObject<EventSpec>,\n handler?: TEventCallback<E>,\n ): VoidFunction {\n if (!this.__eventListeners) {\n this.__eventListeners = {} as Record<keyof EventSpec, TEventCallback[]>;\n }\n if (typeof arg0 === 'object') {\n // one object with key/value pairs was passed\n Object.entries(arg0).forEach(([eventName, handler]) => {\n this.on(eventName as K, handler as TEventCallback);\n });\n return () => this.off(arg0);\n } else if (handler) {\n const eventName = arg0;\n if (!this.__eventListeners[eventName]) {\n this.__eventListeners[eventName] = [];\n }\n this.__eventListeners[eventName].push(handler);\n return () => this.off(eventName, handler);\n } else {\n // noop\n return () => false;\n }\n }\n\n /**\n * Observes specified event **once**\n * @alias once\n * @param {string} eventName Event name (eg. 'after:render')\n * @param {EventRegistryObject} handlers key/value pairs (eg. {'after:render': handler, 'selection:cleared': handler})\n * @param {Function} handler Function that receives a notification when an event of the specified type occurs\n * @return {Function} disposer\n */\n once<K extends keyof EventSpec, E extends EventSpec[K]>(\n eventName: K,\n handler: TEventCallback<E>,\n ): VoidFunction;\n once(handlers: EventRegistryObject<EventSpec>): VoidFunction;\n once<K extends keyof EventSpec, E extends EventSpec[K]>(\n arg0: K | EventRegistryObject<EventSpec>,\n handler?: TEventCallback<E>,\n ): VoidFunction {\n if (typeof arg0 === 'object') {\n // one object with key/value pairs was passed\n const disposers: VoidFunction[] = [];\n Object.entries(arg0).forEach(([eventName, handler]) => {\n disposers.push(this.once(eventName as K, handler as TEventCallback));\n });\n return () => disposers.forEach((d) => d());\n } else if (handler) {\n const disposer = this.on<K, E>(\n arg0,\n function onceHandler(this: Observable<EventSpec>, ...args) {\n handler.call(this, ...args);\n disposer();\n },\n );\n return disposer;\n } else {\n // noop\n return () => false;\n }\n }\n\n /**\n * @private\n * @param {string} eventName\n * @param {Function} [handler]\n */\n private _removeEventListener<K extends keyof EventSpec>(\n eventName: K,\n handler?: TEventCallback,\n ) {\n if (!this.__eventListeners[eventName]) {\n return;\n }\n\n if (handler) {\n const eventListener = this.__eventListeners[eventName];\n const index = eventListener.indexOf(handler);\n index > -1 && eventListener.splice(index, 1);\n } else {\n this.__eventListeners[eventName] = [];\n }\n }\n\n /**\n * Unsubscribe all event listeners for eventname.\n * Do not use this pattern. You could kill internal fabricJS events.\n * We know we should have protected events for internal flows, but we don't have yet\n * @deprecated\n * @param {string} eventName event name (eg. 'after:render')\n */\n off<K extends keyof EventSpec>(eventName: K): void;\n /**\n * unsubscribe an event listener\n * @param {string} eventName event name (eg. 'after:render')\n * @param {TEventCallback} handler event listener to unsubscribe\n */\n off<K extends keyof EventSpec>(eventName: K, handler: TEventCallback): void;\n /**\n * unsubscribe event listeners\n * @param handlers handlers key/value pairs (eg. {'after:render': handler, 'selection:cleared': handler})\n */\n off(handlers: EventRegistryObject<EventSpec>): void;\n /**\n * unsubscribe all event listeners\n */\n off(): void;\n off<K extends keyof EventSpec>(\n arg0?: K | EventRegistryObject<EventSpec>,\n handler?: TEventCallback,\n ) {\n if (!this.__eventListeners) {\n return;\n }\n\n // remove all key/value pairs (event name -> event handler)\n if (typeof arg0 === 'undefined') {\n for (const eventName in this.__eventListeners) {\n this._removeEventListener(eventName);\n }\n }\n // one object with key/value pairs was passed\n else if (typeof arg0 === 'object') {\n Object.entries(arg0).forEach(([eventName, handler]) => {\n this._removeEventListener(eventName as K, handler as TEventCallback);\n });\n } else {\n this._removeEventListener(arg0, handler);\n }\n }\n\n /**\n * Fires event with an optional options object\n * @param {String} eventName Event name to fire\n * @param {Object} [options] Options object\n */\n fire<K extends keyof EventSpec>(eventName: K, options?: EventSpec[K]) {\n if (!this.__eventListeners) {\n return;\n }\n\n const listenersForEvent = this.__eventListeners[eventName]?.concat();\n if (listenersForEvent) {\n for (let i = 0; i < listenersForEvent.length; i++) {\n listenersForEvent[i].call(this, options || {});\n }\n }\n }\n}\n","/**\n * Removes value from an array.\n * Presence of value (and its position in an array) is determined via `Array.prototype.indexOf`\n * @param {Array} array\n * @param {*} value\n * @return {Array} original array\n */\nexport const removeFromArray = <T>(array: T[], value: T): T[] => {\n const idx = array.indexOf(value);\n if (idx !== -1) {\n array.splice(idx, 1);\n }\n return array;\n};\n","import type { TRadian } from '../../typedefs';\nimport { halfPI } from '../../constants';\n\n/**\n * Calculate the cos of an angle, avoiding returning floats for known results\n * This function is here just to avoid getting 0.999999999999999 when dealing\n * with numbers that are really 1 or 0.\n * @param {TRadian} angle the angle\n * @return {Number} the cosin value for angle.\n */\nexport const cos = (angle: TRadian): number => {\n if (angle === 0) {\n return 1;\n }\n const angleSlice = Math.abs(angle) / halfPI;\n switch (angleSlice) {\n case 1:\n case 3:\n return 0;\n case 2:\n return -1;\n }\n return Math.cos(angle);\n};\n","import type { TRadian } from '../../typedefs';\nimport { halfPI } from '../../constants';\n\n/**\n * Calculate the cos of an angle, avoiding returning floats for known results\n * This function is here just to avoid getting 0.999999999999999 when dealing\n * with numbers that are really 1 or 0.\n * @param {TRadian} angle the angle\n * @return {Number} the sin value for angle.\n */\nexport const sin = (angle: TRadian): number => {\n if (angle === 0) {\n return 0;\n }\n const angleSlice = angle / halfPI;\n const value = Math.sign(angle);\n switch (angleSlice) {\n case 1:\n return value;\n case 2:\n return 0;\n case 3:\n return -value;\n }\n return Math.sin(angle);\n};\n","import type { TMat2D, TRadian } from './typedefs';\nimport { cos } from './util/misc/cos';\nimport { sin } from './util/misc/sin';\n\nexport interface XY {\n x: number;\n y: number;\n}\n\n/**\n * Adaptation of work of Kevin Lindsey(kevin@kevlindev.com)\n */\nexport class Point implements XY {\n declare x: number;\n\n declare y: number;\n\n constructor();\n constructor(x: number, y: number);\n constructor(point?: XY);\n constructor(arg0: number | XY = 0, y = 0) {\n if (typeof arg0 === 'object') {\n this.x = arg0.x;\n this.y = arg0.y;\n } else {\n this.x = arg0;\n this.y = y;\n }\n }\n\n /**\n * Adds another point to this one and returns another one\n * @param {XY} that\n * @return {Point} new Point instance with added values\n */\n add(that: XY): Point {\n return new Point(this.x + that.x, this.y + that.y);\n }\n\n /**\n * Adds another point to this one\n * @param {XY} that\n * @return {Point} thisArg\n * @chainable\n * @deprecated\n */\n addEquals(that: XY): Point {\n this.x += that.x;\n this.y += that.y;\n return this;\n }\n\n /**\n * Adds value to this point and returns a new one\n * @param {Number} scalar\n * @return {Point} new Point with added value\n */\n scalarAdd(scalar: number): Point {\n return new Point(this.x + scalar, this.y + scalar);\n }\n\n /**\n * Adds value to this point\n * @param {Number} scalar\n * @return {Point} thisArg\n * @chainable\n * @deprecated\n */\n scalarAddEquals(scalar: number): Point {\n this.x += scalar;\n this.y += scalar;\n return this;\n }\n\n /**\n * Subtracts another point from this point and returns a new one\n * @param {XY} that\n * @return {Point} new Point object with subtracted values\n */\n subtract(that: XY): Point {\n return new Point(this.x - that.x, this.y - that.y);\n }\n\n /**\n * Subtracts another point from this point\n * @param {XY} that\n * @return {Point} thisArg\n * @chainable\n * @deprecated\n */\n subtractEquals(that: XY): Point {\n this.x -= that.x;\n this.y -= that.y;\n return this;\n }\n\n /**\n * Subtracts value from this point and returns a new one\n * @param {Number} scalar\n * @return {Point}\n */\n scalarSubtract(scalar: number): Point {\n return new Point(this.x - scalar, this.y - scalar);\n }\n\n /**\n * Subtracts value from this point\n * @param {Number} scalar\n * @return {Point} thisArg\n * @chainable\n * @deprecated\n */\n scalarSubtractEquals(scalar: number): Point {\n this.x -= scalar;\n this.y -= scalar;\n return this;\n }\n\n /**\n * Multiplies this point by another value and returns a new one\n * @param {XY} that\n * @return {Point}\n */\n multiply(that: XY): Point {\n return new Point(this.x * that.x, this.y * that.y);\n }\n\n /**\n * Multiplies this point by a value and returns a new one\n * @param {Number} scalar\n * @return {Point}\n */\n scalarMultiply(scalar: number): Point {\n return new Point(this.x * scalar, this.y * scalar);\n }\n\n /**\n * Multiplies this point by a value\n * @param {Number} scalar\n * @return {Point} thisArg\n * @chainable\n * @deprecated\n */\n scalarMultiplyEquals(scalar: number): Point {\n this.x *= scalar;\n this.y *= scalar;\n return this;\n }\n\n /**\n * Divides this point by another and returns a new one\n * @param {XY} that\n * @return {Point}\n */\n divide(that: XY): Point {\n return new Point(this.x / that.x, this.y / that.y);\n }\n\n /**\n * Divides this point by a value and returns a new one\n * @param {Number} scalar\n * @return {Point}\n */\n scalarDivide(scalar: number): Point {\n return new Point(this.x / scalar, this.y / scalar);\n }\n\n /**\n * Divides this point by a value\n * @param {Number} scalar\n * @return {Point} thisArg\n * @chainable\n * @deprecated\n */\n scalarDivideEquals(scalar: number): Point {\n this.x /= scalar;\n this.y /= scalar;\n return this;\n }\n\n /**\n * Returns true if this point is equal to another one\n * @param {XY} that\n * @return {Boolean}\n */\n eq(that: XY): boolean {\n return this.x === that.x && this.y === that.y;\n }\n\n /**\n * Returns true if this point is less than another one\n * @param {XY} that\n * @return {Boolean}\n */\n lt(that: XY): boolean {\n return this.x < that.x && this.y < that.y;\n }\n\n /**\n * Returns true if this point is less than or equal to another one\n * @param {XY} that\n * @return {Boolean}\n */\n lte(that: XY): boolean {\n return this.x <= that.x && this.y <= that.y;\n }\n\n /**\n\n * Returns true if this point is greater another one\n * @param {XY} that\n * @return {Boolean}\n */\n gt(that: XY): boolean {\n return this.x > that.x && this.y > that.y;\n }\n\n /**\n * Returns true if this point is greater than or equal to another one\n * @param {XY} that\n * @return {Boolean}\n */\n gte(that: XY): boolean {\n return this.x >= that.x && this.y >= that.y;\n }\n\n /**\n * Returns new point which is the result of linear interpolation with this one and another one\n * @param {XY} that\n * @param {Number} t , position of interpolation, between 0 and 1 default 0.5\n * @return {Point}\n */\n lerp(that: XY, t = 0.5): Point {\n t = Math.max(Math.min(1, t), 0);\n return new Point(\n this.x + (that.x - this.x) * t,\n this.y + (that.y - this.y) * t,\n );\n }\n\n /**\n * Returns distance from this point and another one\n * @param {XY} that\n * @return {Number}\n */\n distanceFrom(that: XY): number {\n const dx = this.x - that.x,\n dy = this.y - that.y;\n return Math.sqrt(dx * dx + dy * dy);\n }\n\n /**\n * Returns the point between this point and another one\n * @param {XY} that\n * @return {Point}\n */\n midPointFrom(that: XY): Point {\n return this.lerp(that);\n }\n\n /**\n * Returns a new point which is the min of this and another one\n * @param {XY} that\n * @return {Point}\n */\n min(that: XY): Point {\n return new Point(Math.min(this.x, that.x), Math.min(this.y, that.y));\n }\n\n /**\n * Returns a new point which is the max of this and another one\n * @param {XY} that\n * @return {Point}\n */\n max(that: XY): Point {\n return new Point(Math.max(this.x, that.x), Math.max(this.y, that.y));\n }\n\n /**\n * Returns string representation of this point\n * @return {String}\n */\n toString(): string {\n return `${this.x},${this.y}`;\n }\n\n /**\n * Sets x/y of this point\n * @param {Number} x\n * @param {Number} y\n * @chainable\n */\n setXY(x: number, y: number) {\n this.x = x;\n this.y = y;\n return this;\n }\n\n /**\n * Sets x of this point\n * @param {Number} x\n * @chainable\n */\n setX(x: number) {\n this.x = x;\n return this;\n }\n\n /**\n * Sets y of this point\n * @param {Number} y\n * @chainable\n */\n setY(y: number) {\n this.y = y;\n return this;\n }\n\n /**\n * Sets x/y of this point from another point\n * @param {XY} that\n * @chainable\n */\n setFromPoint(that: XY) {\n this.x = that.x;\n this.y = that.y;\n return this;\n }\n\n /**\n * Swaps x/y of this point and another point\n * @param {XY} that\n */\n swap(that: XY) {\n const x = this.x,\n y = this.y;\n this.x = that.x;\n this.y = that.y;\n that.x = x;\n that.y = y;\n }\n\n /**\n * return a cloned instance of the point\n * @return {Point}\n */\n clone(): Point {\n return new Point(this.x, this.y);\n }\n\n /**\n * Rotates `point` around `origin` with `radians`\n * @static\n * @memberOf fabric.util\n * @param {XY} origin The origin of the rotation\n * @param {TRadian} radians The radians of the angle for the rotation\n * @return {Point} The new rotated point\n */\n rotate(radians: TRadian, origin: XY = ZERO): Point {\n // TODO benchmark and verify the add and subtract how much cost\n // and then in case early return if no origin is passed\n const sinus = sin(radians),\n cosinus = cos(radians);\n const p = this.subtract(origin);\n const rotated = new Point(\n p.x * cosinus - p.y * sinus,\n p.x * sinus + p.y * cosinus,\n );\n return rotated.add(origin);\n }\n\n /**\n * Apply transform t to point p\n * @static\n * @memberOf fabric.util\n * @param {TMat2D} t The transform\n * @param {Boolean} [ignoreOffset] Indicates that the offset should not be applied\n * @return {Point} The transformed point\n */\n transform(t: TMat2D, ignoreOffset = false): Point {\n return new Point(\n t[0] * this.x + t[2] * this.y + (ignoreOffset ? 0 : t[4]),\n t[1] * this.x + t[3] * this.y + (ignoreOffset ? 0 : t[5]),\n );\n }\n}\n\nexport const ZERO = new Point(0, 0);\n","import type { Constructor, TBBox } from './typedefs';\nimport { removeFromArray } from './util/internals/removeFromArray';\nimport { Point } from './Point';\nimport type { ActiveSelection } from './shapes/ActiveSelection';\nimport type { Group } from './shapes/Group';\nimport type { InteractiveFabricObject } from './shapes/Object/InteractiveObject';\nimport type { FabricObject } from './shapes/Object/FabricObject';\n\nexport const isCollection = (\n fabricObject?: FabricObject,\n): fabricObject is Group | ActiveSelection => {\n return !!fabricObject && Array.isArray((fabricObject as Group)._objects);\n};\n\nexport function createCollectionMixin<TBase extends Constructor>(Base: TBase) {\n class Collection extends Base {\n /**\n * @type {FabricObject[]}\n * @TODO needs to end up in the constructor too\n */\n _objects: FabricObject[] = [];\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _onObjectAdded(object: FabricObject) {\n // subclasses should override this method\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _onObjectRemoved(object: FabricObject) {\n // subclasses should override this method\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _onStackOrderChanged(object: FabricObject) {\n // subclasses should override this method\n }\n\n /**\n * Adds objects to collection\n * Objects should be instances of (or inherit from) FabricObject\n * @param {...FabricObject[]} objects to add\n * @returns {number} new array length\n */\n add(...objects: FabricObject[]): number {\n const size = this._objects.push(...objects);\n objects.forEach((object) => this._onObjectAdded(object));\n return size;\n }\n\n /**\n * Inserts an object into collection at specified index\n * @param {number} index Index to insert object at\n * @param {...FabricObject[]} objects Object(s) to insert\n * @returns {number} new array length\n */\n insertAt(index: number, ...objects: FabricObject[]) {\n this._objects.splice(index, 0, ...objects);\n objects.forEach((object) => this._onObjectAdded(object));\n return this._objects.length;\n }\n\n /**\n * Removes objects from a collection, then renders canvas (if `renderOnAddRemove` is not `false`)\n * @private\n * @param {...FabricObject[]} objects objects to remove\n * @returns {FabricObject[]} removed objects\n */\n remove(...objects: FabricObject[]) {\n const array = this._objects,\n removed: FabricObject[] = [];\n objects.forEach((object) => {\n const index = array.indexOf(object);\n // only call onObjectRemoved if an object was actually removed\n if (index !== -1) {\n array.splice(index, 1);\n removed.push(object);\n this._onObjectRemoved(object);\n }\n });\n return removed;\n }\n\n /**\n * Executes given function for each object in this group\n * A simple shortcut for getObjects().forEach, before es6 was more complicated,\n * now is just a shortcut.\n * @param {Function} callback\n * Callback invoked with current object as first argument,\n * index - as second and an array of all objects - as third.\n */\n forEachObject(\n callback: (\n object: FabricObject,\n index: number,\n array: FabricObject[],\n ) => any,\n ) {\n this.getObjects().forEach((object, index, objects) =>\n callback(object, index, objects),\n );\n }\n\n /**\n * Returns an array of children objects of this instance\n * @param {...String} [types] When specified, only objects of these types are returned\n * @return {Array}\n */\n getObjects(...types: string[]) {\n if (types.length === 0) {\n return [...this._objects];\n }\n return this._objects.filter((o) => o.isType(...types));\n }\n\n /**\n * Returns object at specified index\n * @param {Number} index\n * @return {Object} object at index\n */\n item(index: number) {\n return this._objects[index];\n }\n\n /**\n * Returns true if collection contains no objects\n * @return {Boolean} true if collection is empty\n */\n isEmpty() {\n return this._objects.length === 0;\n }\n\n /**\n * Returns a size of a collection (i.e: length of an array containing its objects)\n * @return {Number} Collection size\n */\n size() {\n return this._objects.length;\n }\n\n /**\n * Returns true if collection contains an object.\\\n * **Prefer using {@link FabricObject#isDescendantOf} for performance reasons**\n * instead of `a.contains(b)` use `b.isDescendantOf(a)`\n * @param {Object} object Object to check against\n * @param {Boolean} [deep=false] `true` to check all descendants, `false` to check only `_objects`\n * @return {Boolean} `true` if collection contains an object\n */\n contains(object: FabricObject, deep?: boolean): boolean {\n if (this._objects.includes(object)) {\n return true;\n } else if (deep) {\n return this._objects.some(\n (obj) =>\n obj instanceof Collection &&\n (obj as unknown as Collection).contains(object, true),\n );\n }\n return false;\n }\n\n /**\n * Returns number representation of a collection complexity\n * @return {Number} complexity\n */\n complexity() {\n return this._objects.reduce((memo, current) => {\n memo += current.complexity ? current.complexity() : 0;\n return memo;\n }, 0);\n }\n\n /**\n * Moves an object or the objects of a multiple selection\n * to the bottom of the stack of drawn objects\n * @param {fabric.Object} object Object to send to back\n * @returns {boolean} true if change occurred\n */\n sendObjectToBack(object: FabricObject) {\n if (!object || object === this._objects[0]) {\n return false;\n }\n removeFromArray(this._objects, object);\n this._objects.unshift(object);\n this._onStackOrderChanged(object);\n return true;\n }\n\n /**\n * Moves an object or the objects of a multiple selection\n * to the top of the stack of drawn objects\n * @param {fabric.Object} object Object to send\n * @returns {boolean} true if change occurred\n */\n bringObjectToFront(object: FabricObject) {\n if (!object || object === this._objects[this._objects.length - 1]) {\n return false;\n }\n removeFromArray(this._objects, object);\n this._objects.push(object);\n this._onStackOrderChanged(object);\n return true;\n }\n\n /**\n * Moves an object or a selection down in stack of drawn objects\n * An optional parameter, `intersecting` allows to move the object in behind\n * the first intersecting object. Where intersection is calculated with\n * bounding box. If no intersection is found, there will not be change in the\n * stack.\n * @param {fabric.Object} object Object to send\n * @param {boolean} [intersecting] If `true`, send object behind next lower intersecting object\n * @returns {boolean} true if change occurred\n */\n sendObjectBackwards(object: FabricObject, intersecting?: boolean) {\n if (!object) {\n return false;\n }\n const idx = this._objects.indexOf(object);\n if (idx !== 0) {\n // if object is not on the bottom of stack\n const newIdx = this.findNewLowerIndex(object, idx, intersecting);\n removeFromArray(this._objects, object);\n this._objects.splice(newIdx, 0, object);\n this._