{"version":3,"file":"XURL.min.mjs","sources":["../../../../../src/shapes/canvasx/XURL/XURL.ts"],"sourcesContent":["import { classRegistry } from '../../../ClassRegistry';\nimport { Shadow } from '../../../Shadow';\nimport { getFabricWindow } from '../../../env';\nimport { loadImage } from '../../../util/misc/objectEnlive';\n\nimport { ImageProps } from '../../Image';\nimport { FabricObject } from '../../Object/FabricObject';\nimport { Rect } from '../../Rect';\nimport { FileObject } from '../type/file';\n\nimport { WidgetURLInterface, EntityKeys } from '../type/widget.entity.url';\nimport { WidgetType } from '../type/widget.type';\n\nexport type XURLProps = ImageProps & WidgetURLInterface;\n\nexport const XURLDefaultValues: Partial<XURLProps> = {\n  originX: 'center',\n  originY: 'center',\n  cornerColor: 'white',\n  cornerStrokeColor: 'gray',\n  cornerSize: 10,\n  cornerStyle: 'circle',\n  transparentCorners: false,\n};\n\nexport class XURL extends FabricObject implements WidgetURLInterface {\n  static objType = 'XURL';\n  static type = 'XURL';\n  transcription: string;\n\n  _previewImage: HTMLImageElement | null = null;\n\n  public extendedProperties = [\n    'id',\n    'objType',\n    'fileName',\n    'transcription',\n    'vectorSrc',\n    'fileSrc',\n    'previewImage',\n    'description',\n    'userId',\n    'clientId',\n    'zIndex',\n    'locked',\n    'boardId',\n  ];\n  constructor(url: any, options: Partial<XURLProps>) {\n    super(options);\n\n    const previewImageURL = options.previewImage?.tmpPath\n      ? options.previewImage?.tmpPath\n      : '/boardxstatic/fileIcons/weblink.png';\n\n    Object.assign(this, options);\n\n    this.on('mousedblclick', this.onDoubleClick.bind(this));\n    this.objType = 'XURL';\n\n    (this.cornerColor = 'white'),\n      (this.cornerStrokeColor = 'gray'),\n      (this.cornerSize = 15),\n      (this.cornerStyle = 'circle'),\n      (this.transparentCorners = false),\n      (this.shadow = new Shadow({\n        color: 'rgba(217, 161, 177, 0.54)',\n        offsetX: 1,\n        offsetY: 2,\n        blur: 4,\n        id: 310,\n      }));\n    this.clipPath = new Rect({\n      left: 0,\n      top: 0,\n      rx: 8,\n      ry: 8,\n      width: 230,\n      height: 248,\n      fill: '#000000',\n    });\n    this.width = 230;\n    this.height = 248;\n    this.loadPreviewImage(previewImageURL!);\n  }\n  url: string;\n  updatedBy: string;\n  updatedByName: string;\n\n  createdByName: string;\n  vectorSrc: FileObject;\n  fileSrc: FileObject;\n  fileName: string;\n  previewImage: FileObject;\n  boardId: string;\n  objType: WidgetType;\n  userId: string;\n  zIndex: number;\n  version: string;\n  updatedAt: number;\n\n  createdAt: number;\n  createdBy: string;\n\n  getObject() {\n    const entityKeys: string[] = EntityKeys;\n    const result: Record<string, any> = {};\n\n    entityKeys.forEach((key) => {\n      if (key in this) {\n        result[key] = (this as any)[key];\n      }\n    });\n\n    return result;\n  }\n\n  toObject(propertiesToInclude: Array<any>): any {\n    return super.toObject([...this.extendedProperties, ...propertiesToInclude]);\n  }\n  onDoubleClick() {\n    getFabricWindow().open(this.url, '_blank');\n  }\n\n  drawObject(ctx: CanvasRenderingContext2D) {\n    // Draw solid background to eliminate transparency\n    ctx.beginPath();\n    ctx.fillStyle = '#FFFFFF'; // Set to white or any preferred color\n    ctx.fillRect(-this.width / 2, -this.height / 2, this.width, this.height);\n    ctx.lineWidth = 0;\n    ctx.strokeStyle = '#ffffff';\n    ctx.moveTo(-this.width / 2, -this.height / 2);\n    ctx.stroke();\n\n    const imgWidth = 230;\n    const imgHeight = 160;\n\n    if (this._previewImage) {\n      this.drawPreviewImage(ctx, imgWidth, imgHeight);\n    }\n\n    this.renderTitle(ctx, this.fileName);\n    this._renderStroke(ctx);\n  }\n\n  private drawPreviewImage(\n    ctx: CanvasRenderingContext2D,\n    imgWidth: number,\n    imgHeight: number\n  ) {\n    const previewImage = this._previewImage!;\n    const imageWidth = previewImage.width;\n    const imageHeight = previewImage.height;\n\n    // Calculate aspect ratios\n    const imageAspect = imageWidth / imageHeight;\n    const canvasAspect = imgWidth / imgHeight;\n\n    let drawWidth, drawHeight, offsetX, offsetY;\n\n    if (imageAspect > canvasAspect) {\n      // Image is wider than canvas aspect ratio\n      drawHeight = imgHeight;\n      drawWidth = imageAspect * imgHeight;\n      offsetX = (imgWidth - drawWidth) / 2;\n      offsetY = 0;\n    } else {\n      // Image is taller than canvas aspect ratio\n      drawWidth = imgWidth;\n      drawHeight = imgWidth / imageAspect;\n      offsetX = 0;\n      offsetY = (imgHeight - drawHeight) / 2;\n    }\n\n    ctx.save();\n\n    // Set clipping region to the image area\n    ctx.beginPath();\n    ctx.rect(-this.width / 2, -this.height / 2, imgWidth, imgHeight);\n    ctx.clip();\n\n    // Draw the image within the clipping region\n    ctx.drawImage(\n      previewImage,\n      -this.width / 2 + offsetX,\n      -this.height / 2 + offsetY,\n      drawWidth,\n      drawHeight\n    );\n\n    ctx.restore();\n  }\n\n  renderTitle(ctx: any, title: string) {\n    const maxWidth = this.width;\n    const x = -this.width / 2;\n    const y = this.height / 2 - 60;\n\n    // Set font styles\n    ctx.font = '16px Arial';\n    ctx.fillStyle = 'rgba(255, 255, 255, 1)';\n\n    // White background behind the title\n    ctx.fillRect(x, y - 29, maxWidth, 90);\n    ctx.fillStyle = '#190FA1';\n\n    // Handle null or empty title\n    if (!title && this.fileSrc?.tmpPath) {\n      const firstChar = this.fileSrc?.tmpPath.indexOf('.');\n      const lastChar = this.fileSrc?.tmpPath.indexOf('.', firstChar + 1);\n      title = this.fileSrc?.tmpPath.substring(firstChar + 1, lastChar);\n    }\n\n    // Title rendering\n    this.wrapText(ctx, title, x + 15, y - 5, maxWidth - 20, 23);\n\n    // URL rendering\n    const newurl = this.fileSrc && this.fileSrc?.tmpPath\n      ? `${this.fileSrc?.tmpPath.split('/')[0]}/${this.fileSrc.tmpPath.split('/')[1]\n      }/${this.fileSrc?.tmpPath.split('/')[2]}`\n      : '';\n    ctx.font = '12px Inter';\n    ctx.fillStyle = 'rgba(35, 41, 48, 0.65)';\n    this.wrapText(ctx, newurl, x + 15, y + 45, maxWidth - 20, 25);\n  }\n\n  wrapText(\n    context: any,\n    text: string,\n    x: number,\n    y: number,\n    maxWidth: number,\n    lineHeight: number\n  ) {\n    let line = '';\n    let lineCount = 0;\n    const chars = text.split('');\n    for (let n = 0; n < chars.length; n++) {\n      const testLine = line + chars[n];\n      const metrics = context.measureText(testLine);\n      const testWidth = metrics.width;\n\n      if (testWidth > maxWidth && n > 0) {\n        if (lineCount === 2) {\n          line = line.substring(0, line.length - 3) + '...';\n          context.fillText(line, x, y);\n          return;\n        }\n        context.fillText(line, x, y);\n        line = chars[n];\n        y += lineHeight;\n        lineCount++;\n      } else {\n        line = testLine;\n      }\n    }\n    context.fillText(line, x, y);\n  }\n\n  async loadPreviewImage(previewImage: string) {\n    const url = previewImage;\n\n    const loadedImg = await loadImage(url, {\n      crossOrigin: 'anonymous',\n    });\n    this._previewImage = loadedImg;\n    this.dirty = true;\n    this.canvas?.requestRenderAll();\n  }\n}\n\nclassRegistry.setClass(XURL);\n"],"names":["XURL","FabricObject","constructor","url","options","_options$previewImage","_options$previewImage2","super","_defineProperty","this","previewImageURL","previewImage","tmpPath","Object","assign","on","onDoubleClick","bind","objType","cornerColor","cornerStrokeColor","cornerSize","cornerStyle","transparentCorners","shadow","Shadow","color","offsetX","offsetY","blur","id","clipPath","Rect","left","top","rx","ry","width","height","fill","loadPreviewImage","getObject","result","EntityKeys","forEach","key","toObject","propertiesToInclude","extendedProperties","getFabricWindow","open","drawObject","ctx","beginPath","fillStyle","fillRect","lineWidth","strokeStyle","moveTo","stroke","_previewImage","drawPreviewImage","renderTitle","fileName","_renderStroke","imgWidth","imgHeight","imageAspect","drawWidth","drawHeight","save","rect","clip","drawImage","restore","title","_this$fileSrc","_this$fileSrc5","_this$fileSrc6","_this$fileSrc7","maxWidth","x","y","font","fileSrc","_this$fileSrc2","_this$fileSrc3","_this$fileSrc4","firstChar","indexOf","lastChar","substring","wrapText","newurl","concat","split","context","text","lineHeight","line","lineCount","chars","n","length","testLine","measureText","fillText","_this$canvas","loadedImg","loadImage","crossOrigin","dirty","canvas","requestRenderAll","classRegistry","setClass"],"mappings":"m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