{"version":3,"file":"Ellipse.min.mjs","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';\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,\n    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   * @default\n   */\n  declare rx: number;\n\n  /**\n   * Vertical radius\n   * @type Number\n   * @default\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=\"${this.rx}\" ry=\"${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   * @static\n   * @memberOf Ellipse\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   * @static\n   * @memberOf Ellipse\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"],"names":["ellipseDefaultValues","rx","ry","ELLIPSE_PROPS","Ellipse","FabricObject","getDefaults","_objectSpread","super","ownDefaults","constructor","options","Object","assign","this","setOptions","_set","key","value","set","getRx","get","SCALE_X","getRy","SCALE_Y","toObject","propertiesToInclude","arguments","length","undefined","_toSVG","concat","_render","ctx","beginPath","save","transform","arc","twoMathPi","restore","_renderPaintInOrder","fromElement","element","cssRules","parsedAttributes","parseAttributes","ATTRIBUTE_NAMES","left","top","_defineProperty","cacheProperties","SHARED_ATTRIBUTES","classRegistry","setClass","setSVGClass"],"mappings":"4eAUO,MAAMA,EAA2D,CACtEC,GAAI,EACJC,GAAI,GAcAC,EAAgB,CAAC,KAAM,MAEtB,MAAMC,UAKHC,EAuBR,kBAAOC,GACL,OAAAC,EAAAA,EAAA,GACKC,MAAMF,eACNF,EAAQK,YAEf,CAMAC,WAAAA,CAAYC,GACVH,QACAI,OAAOC,OAAOC,KAAMV,EAAQK,aAC5BK,KAAKC,WAAWJ,EAClB,CAQAK,IAAAA,CAAKC,EAAaC,GAEhB,OADAV,MAAMQ,KAAKC,EAAKC,GACRD,GACN,IAAK,KACHH,KAAKb,GAAKiB,EACVJ,KAAKK,IAAI,QAAiB,EAARD,GAClB,MAEF,IAAK,KAC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