{"version":3,"file":"Ellipse.min.mjs","names":[],"sources":["../../../src/shapes/Ellipse.ts"],"sourcesContent":["import { SCALE_X, SCALE_Y, twoMathPi } from '../constants';\nimport { SHARED_ATTRIBUTES } from '../parser/attributes';\nimport { parseAttributes } from '../parser/parseAttributes';\nimport type { Abortable, TClassProperties, TOptions } from '../typedefs';\nimport { classRegistry } from '../ClassRegistry';\nimport { FabricObject, cacheProperties } from './Object/FabricObject';\nimport type { FabricObjectProps, SerializedObjectProps } from './Object/types';\nimport type { ObjectEvents } from '../EventTypeDefs';\nimport type { CSSRules } from '../parser/typedefs';\nimport { escapeXml } from '../util/lang_string';\n\nexport const ellipseDefaultValues: Partial<TClassProperties<Ellipse>> = {\n  rx: 0,\n  ry: 0,\n};\n\ninterface UniqueEllipseProps {\n  rx: number;\n  ry: number;\n}\n\nexport interface SerializedEllipseProps\n  extends SerializedObjectProps, UniqueEllipseProps {}\n\nexport interface EllipseProps extends FabricObjectProps, UniqueEllipseProps {}\n\nconst ELLIPSE_PROPS = ['rx', 'ry'] as const;\n\nexport class Ellipse<\n  Props extends TOptions<EllipseProps> = Partial<EllipseProps>,\n  SProps extends SerializedEllipseProps = SerializedEllipseProps,\n  EventSpec extends ObjectEvents = ObjectEvents,\n>\n  extends FabricObject<Props, SProps, EventSpec>\n  implements EllipseProps\n{\n  /**\n   * Horizontal radius\n   * @type Number\n   */\n  declare rx: number;\n\n  /**\n   * Vertical radius\n   * @type Number\n   */\n  declare ry: number;\n\n  static type = 'Ellipse';\n\n  static cacheProperties = [...cacheProperties, ...ELLIPSE_PROPS];\n\n  static ownDefaults = ellipseDefaultValues;\n\n  static getDefaults(): Record<string, any> {\n    return {\n      ...super.getDefaults(),\n      ...Ellipse.ownDefaults,\n    };\n  }\n\n  /**\n   * Constructor\n   * @param {Object} [options] Options object\n   */\n  constructor(options?: Props) {\n    super();\n    Object.assign(this, Ellipse.ownDefaults);\n    this.setOptions(options);\n  }\n\n  /**\n   * @private\n   * @param {String} key\n   * @param {*} value\n   * @return {Ellipse} thisArg\n   */\n  _set(key: string, value: any) {\n    super._set(key, value);\n    switch (key) {\n      case 'rx':\n        this.rx = value;\n        this.set('width', value * 2);\n        break;\n\n      case 'ry':\n        this.ry = value;\n        this.set('height', value * 2);\n        break;\n    }\n    return this;\n  }\n\n  /**\n   * Returns horizontal radius of an object (according to how an object is scaled)\n   * @return {Number}\n   */\n  getRx() {\n    return this.get('rx') * this.get(SCALE_X);\n  }\n\n  /**\n   * Returns Vertical radius of an object (according to how an object is scaled)\n   * @return {Number}\n   */\n  getRy() {\n    return this.get('ry') * this.get(SCALE_Y);\n  }\n\n  /**\n   * Returns object representation of an instance\n   * @param {Array} [propertiesToInclude] Any properties that you might want to additionally include in the output\n   * @return {Object} object representation of an instance\n   */\n  toObject<\n    T extends Omit<Props & TClassProperties<this>, keyof SProps>,\n    K extends keyof T = never,\n  >(propertiesToInclude: K[] = []): Pick<T, K> & SProps {\n    return super.toObject([...ELLIPSE_PROPS, ...propertiesToInclude]);\n  }\n\n  /**\n   * Returns svg representation of an instance\n   * @return {Array} an array of strings with the specific svg representation\n   * of the instance\n   */\n  _toSVG(): string[] {\n    return [\n      '<ellipse ',\n      'COMMON_PARTS',\n      `cx=\"0\" cy=\"0\" rx=\"${escapeXml(this.rx)}\" ry=\"${escapeXml(this.ry)}\" />\\n`,\n    ];\n  }\n\n  /**\n   * @private\n   * @param {CanvasRenderingContext2D} ctx context to render on\n   */\n  _render(ctx: CanvasRenderingContext2D) {\n    ctx.beginPath();\n    ctx.save();\n    ctx.transform(1, 0, 0, this.ry / this.rx, 0, 0);\n    ctx.arc(0, 0, this.rx, 0, twoMathPi, false);\n    ctx.restore();\n    this._renderPaintInOrder(ctx);\n  }\n\n  /* _FROM_SVG_START_ */\n\n  /**\n   * List of attribute names to account for when parsing SVG element (used by {@link Ellipse.fromElement})\n   * @see http://www.w3.org/TR/SVG/shapes.html#EllipseElement\n   */\n  static ATTRIBUTE_NAMES = [...SHARED_ATTRIBUTES, 'cx', 'cy', 'rx', 'ry'];\n\n  /**\n   * Returns {@link Ellipse} instance from an SVG element\n   * @param {HTMLElement} element Element to parse\n   * @return {Ellipse}\n   */\n  static async fromElement(\n    element: HTMLElement,\n    options?: Abortable,\n    cssRules?: CSSRules,\n  ) {\n    const parsedAttributes = parseAttributes(\n      element,\n      this.ATTRIBUTE_NAMES,\n      cssRules,\n    );\n\n    parsedAttributes.left = (parsedAttributes.left || 0) - parsedAttributes.rx;\n    parsedAttributes.top = (parsedAttributes.top || 0) - parsedAttributes.ry;\n    return new this(parsedAttributes);\n  }\n\n  /* _FROM_SVG_END_ */\n}\n\nclassRegistry.setClass(Ellipse);\nclassRegistry.setSVGClass(Ellipse);\n"],"mappings":"6iBAWA,MAeM,EAAgB,CAAC,KAAM,KAAA,CAE7B,IAAa,EAAb,MAAa,UAKH,CAAA,CAqBR,OAAA,aAAO,CACL,MAAO,CAAA,GACF,MAAM,aAAA,CAAA,GACN,EAAQ,YAAA,CAQf,YAAY,EAAA,CACV,OAAA,CACA,OAAO,OAAO,KAAM,EAAQ,YAAA,CAC5B,KAAK,WAAW,EAAA,CASlB,KAAK,EAAa,EAAA,CAEhB,OADA,MAAM,KAAK,EAAK,EAAA,CACR,EAAR,CACE,IAAK,KACH,KAAK,GAAK,EACV,KAAK,IAAI,QAAiB,EAAR,EAAA,CAClB,MAEF,IAAK,KACH,KAAK,GAAK,EACV,KAAK,IAAI,SAAkB,EAAR,EAAA,CAGvB,OAAO,KAOT,OAAA,CACE,OAAO,KAAK,IAAI,KAAA,CAAQ,KAAK,IAAI,EAAA,CAOnC,OAAA,CACE,OAAO,KAAK,IAAI,KAAA,CAAQ,KAAK,IAAI,EAAA,CAQnC,SAGE,EAA2B,EAAA,CAAA,CAC3B,OAAO,MAAM,SAAS,CAAA,GAAI,EAAA,GAAkB,EAAA,CAAA,CAQ9C,QAAA,CACE,MAAO,CACL,YACA,eACA,qBAAqB,EAAU,KAAK,GAAA,CAAA,QAAY,EAAU,KAAK,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