{"version":3,"file":"ngwr-image-cropper.mjs","sources":["../../../projects/lib/image-cropper/image-cropper.ts","../../../projects/lib/image-cropper/image-cropper.html","../../../projects/lib/image-cropper/ngwr-image-cropper.ts"],"sourcesContent":["/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nimport { coerceNumberProperty } from '@angular/cdk/coercion';\nimport {\n  Component,\n  DestroyRef,\n  type ElementRef,\n  ViewEncapsulation,\n  computed,\n  effect,\n  inject,\n  input,\n  output,\n  signal,\n  viewChild,\n} from '@angular/core';\n\nimport { clamp } from 'ngwr/utils';\n\nimport type { WrCropHandle, WrCropRect, WrImageOutputType } from './interfaces';\n\ninterface RectPx {\n  x: number;\n  y: number;\n  w: number;\n  h: number;\n}\n\n/**\n * Image crop UI. Pass `[src]` (URL, `File`, or `Blob`); the user drags\n * the crop window or any of its eight handles. Optionally lock the crop\n * to a fixed `[aspectRatio]`.\n *\n * `(cropped)` fires after each drag end with a freshly-rendered `Blob`\n * of the cropped region. For one-off reads use `toBlob()` / `toDataUrl()`.\n *\n * @example\n * ```html\n * <wr-image-cropper\n *   [src]=\"file\"\n *   [aspectRatio]=\"1\"\n *   (cropped)=\"onBlob($event)\"\n * />\n * ```\n *\n * @see https://ngwr.dev/components/image-cropper\n */\n@Component({\n  selector: 'wr-image-cropper',\n  templateUrl: './image-cropper.html',\n  encapsulation: ViewEncapsulation.None,\n  host: { class: 'wr-image-cropper' },\n})\nexport class WrImageCropper {\n  /** Image source — URL string, `File`, or `Blob`. */\n  readonly src = input<string | File | Blob | null>(null);\n\n  /** Aspect ratio (width / height). `null` = free. @default null */\n  readonly aspectRatio = input<number | null>(null);\n\n  /** Minimum crop width in display pixels. @default 32 */\n  readonly minWidth = input(32, { transform: (v: unknown): number => Math.max(8, coerceNumberProperty(v, 32)) });\n\n  /** Minimum crop height in display pixels. @default 32 */\n  readonly minHeight = input(32, { transform: (v: unknown): number => Math.max(8, coerceNumberProperty(v, 32)) });\n\n  /** Default output type for `(cropped)`. @default 'image/png' */\n  readonly outputType = input<WrImageOutputType>('image/png');\n\n  /** JPEG / WebP quality for `(cropped)` in [0, 1]. @default 0.92 */\n  readonly outputQuality = input(0.92);\n\n  /** Emits a Blob after each drag end. */\n  readonly cropped = output<Blob>();\n\n  protected readonly imgEl = viewChild.required<ElementRef<HTMLImageElement>>('img');\n\n  /** Resolved object URL for `src` (so File / Blob render in `<img>`). */\n  protected readonly objectUrl = signal<string | null>(null);\n\n  /** Previous object URL we created — kept off-signal so the resolve\n   *  effect doesn't depend on its own writes (which would loop). */\n  private previousObjectUrl: string | null = null;\n\n  /** Natural (source) pixel dimensions. */\n  protected readonly natural = signal<{ w: number; h: number }>({ w: 0, h: 0 });\n\n  /** Display (rendered) pixel dimensions. */\n  protected readonly display = signal<{ w: number; h: number }>({ w: 0, h: 0 });\n\n  /** Crop rect in display coordinates. */\n  protected readonly cropDisplay = signal<RectPx>({ x: 0, y: 0, w: 0, h: 0 });\n\n  /** Currently active drag handle. */\n  private active: WrCropHandle | null = null;\n  private startPointer: { x: number; y: number } = { x: 0, y: 0 };\n  private startRect: RectPx = { x: 0, y: 0, w: 0, h: 0 };\n\n  private readonly destroyRef = inject(DestroyRef);\n\n  /** Resolved crop rect in natural (source) pixel coordinates. */\n  readonly cropRect = computed<WrCropRect>(() => {\n    const display = this.display();\n    const natural = this.natural();\n    const c = this.cropDisplay();\n    if (display.w === 0 || display.h === 0) return { x: 0, y: 0, width: 0, height: 0 };\n    const sx = natural.w / display.w;\n    const sy = natural.h / display.h;\n    return {\n      x: Math.round(c.x * sx),\n      y: Math.round(c.y * sy),\n      width: Math.round(c.w * sx),\n      height: Math.round(c.h * sy),\n    };\n  });\n\n  constructor() {\n    // Resolve the source into a usable URL the <img> can render.\n    // We only read `src()` here — `previousObjectUrl` is a plain field, so\n    // writing to `objectUrl` doesn't re-trigger this effect (and hang the\n    // tab on file upload).\n    effect(() => {\n      const src = this.src();\n      if (this.previousObjectUrl) {\n        URL.revokeObjectURL(this.previousObjectUrl);\n        this.previousObjectUrl = null;\n      }\n      if (!src) {\n        this.objectUrl.set(null);\n        return;\n      }\n      if (typeof src === 'string') {\n        this.objectUrl.set(src);\n      } else {\n        const url = URL.createObjectURL(src);\n        this.previousObjectUrl = url;\n        this.objectUrl.set(url);\n      }\n    });\n\n    this.destroyRef.onDestroy(() => {\n      if (this.previousObjectUrl) URL.revokeObjectURL(this.previousObjectUrl);\n    });\n  }\n\n  // Image load\n\n  protected onImageLoad(): void {\n    const img = this.imgEl().nativeElement;\n    const rect = img.getBoundingClientRect();\n    const display = { w: rect.width, h: rect.height };\n    // Some SVGs and odd images report zero natural dimensions — fall back\n    // to the rendered size so the crop math stays well-defined.\n    const natural = {\n      w: img.naturalWidth || display.w,\n      h: img.naturalHeight || display.h,\n    };\n    this.natural.set(natural);\n    this.display.set(display);\n    this.cropDisplay.set(this.initialCrop(display));\n  }\n\n  /** Compute a sensible initial crop — centered, respecting aspectRatio. */\n  private initialCrop(display: { w: number; h: number }): RectPx {\n    const ratio = this.aspectRatio();\n    let w = display.w * 0.6;\n    let h = display.h * 0.6;\n    if (ratio && ratio > 0) {\n      const candidate = w / ratio;\n      if (candidate > h) w = h * ratio;\n      else h = w / ratio;\n    }\n    return {\n      x: (display.w - w) / 2,\n      y: (display.h - h) / 2,\n      w,\n      h,\n    };\n  }\n\n  // Drag handlers\n\n  protected readonly handles: readonly WrCropHandle[] = ['n', 's', 'e', 'w', 'ne', 'nw', 'se', 'sw'];\n\n  protected onPointerDown(handle: WrCropHandle, event: PointerEvent): void {\n    event.preventDefault();\n    event.stopPropagation();\n    this.active = handle;\n    this.startPointer = { x: event.clientX, y: event.clientY };\n    this.startRect = { ...this.cropDisplay() };\n    (event.currentTarget as HTMLElement).setPointerCapture(event.pointerId);\n  }\n\n  protected onPointerMove(event: PointerEvent): void {\n    if (!this.active) return;\n    const dx = event.clientX - this.startPointer.x;\n    const dy = event.clientY - this.startPointer.y;\n    if (this.active === 'move') this.applyMove(dx, dy);\n    else this.applyResize(this.active, dx, dy);\n  }\n\n  protected onPointerUp(event: PointerEvent): void {\n    if (!this.active) return;\n    (event.currentTarget as HTMLElement).releasePointerCapture(event.pointerId);\n    this.active = null;\n    void this.emitCropped();\n  }\n\n  private applyMove(dx: number, dy: number): void {\n    const display = this.display();\n    const r = this.startRect;\n    const next = {\n      x: clamp(r.x + dx, 0, display.w - r.w),\n      y: clamp(r.y + dy, 0, display.h - r.h),\n      w: r.w,\n      h: r.h,\n    };\n    this.cropDisplay.set(next);\n  }\n\n  private applyResize(handle: WrCropHandle, dx: number, dy: number): void {\n    const display = this.display();\n    const min = { w: this.minWidth(), h: this.minHeight() };\n    const ratio = this.aspectRatio();\n    const r = this.startRect;\n    let x = r.x;\n    let y = r.y;\n    let w = r.w;\n    let h = r.h;\n\n    if (handle.includes('e')) w = clamp(r.w + dx, min.w, display.w - r.x);\n    if (handle.includes('w')) {\n      const nextW = clamp(r.w - dx, min.w, r.x + r.w);\n      x = r.x + (r.w - nextW);\n      w = nextW;\n    }\n    if (handle.includes('s')) h = clamp(r.h + dy, min.h, display.h - r.y);\n    if (handle.includes('n')) {\n      const nextH = clamp(r.h - dy, min.h, r.y + r.h);\n      y = r.y + (r.h - nextH);\n      h = nextH;\n    }\n\n    if (ratio && ratio > 0) {\n      // Lock the orthogonal axis to maintain ratio. For corner handles,\n      // pick whichever delta drives the larger change so we don't bounce.\n      if (handle === 'e' || handle === 'w') {\n        const newH = w / ratio;\n        const dh = newH - r.h;\n        if (handle === 'e' || handle === 'w') {\n          y = r.y - dh / 2;\n          h = newH;\n        }\n      } else if (handle === 'n' || handle === 's') {\n        const newW = h * ratio;\n        const dw = newW - r.w;\n        x = r.x - dw / 2;\n        w = newW;\n      } else {\n        // Corner — drive by width, then derive height.\n        const newH = w / ratio;\n        if (handle.includes('n')) y = r.y + r.h - newH;\n        h = newH;\n      }\n      // Re-clamp after ratio adjustment so we never spill out of the canvas.\n      x = clamp(x, 0, display.w - w);\n      y = clamp(y, 0, display.h - h);\n      w = clamp(w, min.w, display.w - x);\n      h = clamp(h, min.h, display.h - y);\n    }\n\n    this.cropDisplay.set({ x, y, w, h });\n  }\n\n  // Public API\n\n  /** Render the current crop as a Blob. */\n  async toBlob(type: WrImageOutputType = this.outputType(), quality: number = this.outputQuality()): Promise<Blob> {\n    const canvas = this.toCanvas();\n    return new Promise<Blob>((resolve, reject) => {\n      canvas.toBlob(\n        blob => {\n          if (blob) resolve(blob);\n          else reject(new Error('toBlob returned null'));\n        },\n        type,\n        quality\n      );\n    });\n  }\n\n  /** Render the current crop as a data URL. */\n  toDataUrl(type: WrImageOutputType = this.outputType(), quality: number = this.outputQuality()): string {\n    return this.toCanvas().toDataURL(type, quality);\n  }\n\n  /** Re-emit the crop without waiting for a drag (e.g. after a programmatic change). */\n  async refresh(): Promise<void> {\n    await this.emitCropped();\n  }\n\n  // Internals\n\n  private toCanvas(): HTMLCanvasElement {\n    const img = this.imgEl().nativeElement;\n    const c = this.cropRect();\n    const canvas = document.createElement('canvas');\n    canvas.width = Math.max(1, c.width);\n    canvas.height = Math.max(1, c.height);\n    const ctx = canvas.getContext('2d');\n    if (ctx) ctx.drawImage(img, c.x, c.y, c.width, c.height, 0, 0, canvas.width, canvas.height);\n    return canvas;\n  }\n\n  private async emitCropped(): Promise<void> {\n    try {\n      const blob = await this.toBlob();\n      this.cropped.emit(blob);\n    } catch {\n      // Swallow — invalid state (image not loaded, crop empty, etc.).\n    }\n  }\n}\n","@if (objectUrl(); as url) {\n  <div class=\"wr-image-cropper__canvas\">\n    <img #img class=\"wr-image-cropper__image\" [src]=\"url\" alt=\"\" draggable=\"false\" (load)=\"onImageLoad()\" />\n\n    @if (display().w > 0) {\n      <!-- Semi-transparent backdrop with a cut-out for the crop window. -->\n      <div\n        class=\"wr-image-cropper__backdrop\"\n        [style.clip-path]=\"`polygon(0 0, 100% 0, 100% 100%, 0 100%, 0 ${cropDisplay().y}px, ${cropDisplay().x}px ${cropDisplay().y}px, ${cropDisplay().x}px ${cropDisplay().y + cropDisplay().h}px, ${cropDisplay().x + cropDisplay().w}px ${cropDisplay().y + cropDisplay().h}px, ${cropDisplay().x + cropDisplay().w}px ${cropDisplay().y}px, 0 ${cropDisplay().y}px)`\"\n      ></div>\n\n      <!-- Crop window — drag to move, with eight resize handles. -->\n      <div\n        class=\"wr-image-cropper__window\"\n        [style.left.px]=\"cropDisplay().x\"\n        [style.top.px]=\"cropDisplay().y\"\n        [style.width.px]=\"cropDisplay().w\"\n        [style.height.px]=\"cropDisplay().h\"\n        (pointerdown)=\"onPointerDown('move', $event)\"\n        (pointermove)=\"onPointerMove($event)\"\n        (pointerup)=\"onPointerUp($event)\"\n        (pointercancel)=\"onPointerUp($event)\"\n      >\n        @for (h of handles; track h) {\n          <span\n            [class]=\"`wr-image-cropper__handle wr-image-cropper__handle--${h}`\"\n            (pointerdown)=\"onPointerDown(h, $event)\"\n            (pointermove)=\"onPointerMove($event)\"\n            (pointerup)=\"onPointerUp($event)\"\n            (pointercancel)=\"onPointerUp($event)\"\n          ></span>\n        }\n      </div>\n    }\n  </div>\n} @else {\n  <div class=\"wr-image-cropper__empty\">No image</div>\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;AAAA;;;;;AAKG;AA4BH;;;;;;;;;;;;;;;;;;AAkBG;MAOU,cAAc,CAAA;;IAEhB,GAAG,GAAG,KAAK,CAA8B,IAAI;4EAAC;;IAG9C,WAAW,GAAG,KAAK,CAAgB,IAAI;oFAAC;;IAGxC,QAAQ,GAAG,KAAK,CAAC,EAAE,EAAA,EAAA,IAAA,SAAA,GAAA,EAAA,SAAA,EAAA,UAAA,EAAA,8BAAA,EAAA,CAAA,EAAI,SAAS,EAAE,CAAC,CAAU,KAAa,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,oBAAoB,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAA,CA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