{"version":3,"file":"draw.mjs","names":[],"sources":["../../../extensions/aligning_guidelines/util/draw.ts"],"sourcesContent":["import { Point } from 'fabric';\nimport type { AligningGuidelines } from '..';\n\nexport function drawLine(\n  this: AligningGuidelines,\n  origin: Point,\n  target: Point,\n) {\n  const ctx = this.canvas.getTopContext();\n  const viewportTransform = this.canvas.viewportTransform;\n  const zoom = this.canvas.getZoom();\n  ctx.save();\n  ctx.transform(...viewportTransform);\n  ctx.lineWidth = this.width / zoom;\n  if (this.lineDash) ctx.setLineDash(this.lineDash);\n  ctx.strokeStyle = this.color;\n  ctx.beginPath();\n  ctx.moveTo(origin.x, origin.y);\n  ctx.lineTo(target.x, target.y);\n  ctx.stroke();\n  if (this.lineDash) ctx.setLineDash([]);\n\n  this.drawX(origin, -1);\n  this.drawX(target, 1);\n  ctx.restore();\n}\n\nexport function drawX(this: AligningGuidelines, point: Point, _: number) {\n  const ctx = this.canvas.getTopContext();\n  const zoom = this.canvas.getZoom();\n  const size = this.xSize / zoom;\n  ctx.save();\n  ctx.translate(point.x, point.y);\n  ctx.beginPath();\n  ctx.moveTo(-size, -size);\n  ctx.lineTo(size, size);\n  ctx.moveTo(size, -size);\n  ctx.lineTo(-size, size);\n  ctx.stroke();\n  ctx.restore();\n}\nfunction drawPoint(this: AligningGuidelines, arr: Point[]) {\n  const ctx = this.canvas.getTopContext();\n  const viewportTransform = this.canvas.viewportTransform;\n  const zoom = this.canvas.getZoom();\n  ctx.save();\n  ctx.transform(...viewportTransform);\n  ctx.lineWidth = this.width / zoom;\n  ctx.strokeStyle = this.color;\n  for (const item of arr) this.drawX(item, 0);\n  ctx.restore();\n}\n\nexport function drawPointList(this: AligningGuidelines) {\n  const list = [];\n  if (!this.closeVLine) {\n    for (const v of this.verticalLines) list.push(JSON.parse(v));\n  }\n  if (!this.closeHLine) {\n    for (const h of this.horizontalLines) list.push(JSON.parse(h));\n  }\n  const arr = list.map((item) => item.target);\n  drawPoint.call(this, arr);\n}\n\nexport function drawVerticalLine(this: AligningGuidelines) {\n  if (this.closeVLine) return;\n\n  for (const v of this.verticalLines) {\n    const { origin, target } = JSON.parse(v);\n    const o = new Point(target.x, origin.y);\n    this.drawLine(o, target);\n  }\n}\n\nexport function drawHorizontalLine(this: AligningGuidelines) {\n  if (this.closeHLine) return;\n\n  for (const v of this.horizontalLines) {\n    const { origin, target } = JSON.parse(v);\n    const o = new Point(origin.x, target.y);\n    this.drawLine(o, target);\n  }\n}\n"],"mappings":";;AAGA,SAAgB,SAEd,QACA,QACA;CACA,MAAM,MAAM,KAAK,OAAO,eAAe;CACvC,MAAM,oBAAoB,KAAK,OAAO;CACtC,MAAM,OAAO,KAAK,OAAO,SAAS;AAClC,KAAI,MAAM;AACV,KAAI,UAAU,GAAG,kBAAkB;AACnC,KAAI,YAAY,KAAK,QAAQ;AAC7B,KAAI,KAAK,SAAU,KAAI,YAAY,KAAK,SAAS;AACjD,KAAI,cAAc,KAAK;AACvB,KAAI,WAAW;AACf,KAAI,OAAO,OAAO,GAAG,OAAO,EAAE;AAC9B,KAAI,OAAO,OAAO,GAAG,OAAO,EAAE;AAC9B,KAAI,QAAQ;AACZ,KAAI,KAAK,SAAU,KAAI,YAAY,EAAE,CAAC;AAEtC,MAAK,MAAM,QAAQ,GAAG;AACtB,MAAK,MAAM,QAAQ,EAAE;AACrB,KAAI,SAAS;;AAGf,SAAgB,MAAgC,OAAc,GAAW;CACvE,MAAM,MAAM,KAAK,OAAO,eAAe;CACvC,MAAM,OAAO,KAAK,OAAO,SAAS;CAClC,MAAM,OAAO,KAAK,QAAQ;AAC1B,KAAI,MAAM;AACV,KAAI,UAAU,MAAM,GAAG,MAAM,EAAE;AAC/B,KAAI,WAAW;AACf,KAAI,OAAO,CAAC,MAAM,CAAC,KAAK;AACxB,KAAI,OAAO,MAAM,KAAK;AACtB,KAAI,OAAO,MAAM,CAAC,KAAK;AACvB,KAAI,OAAO,CAAC,MAAM,KAAK;AACvB,KAAI,QAAQ;AACZ,KAAI,SAAS;;AAE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