@sereno-ds/ui 0.41.3 → 0.41.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,14 +1,13 @@
1
1
  "use client";
2
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
3
  import * as React from "react";
4
4
  import { createPortal } from "react-dom";
5
- import { Camera, Check, ImagePlus, Pencil, RotateCcw, Trash2, X, ZoomIn, ZoomOut } from "lucide-react";
5
+ import { Camera, ImagePlus, Pencil, Trash2 } from "lucide-react";
6
6
  import { sx } from "../_internal/style.js";
7
7
  import { Field } from "../_internal/Field.js";
8
8
  import { fieldA11y } from "../_internal/fieldA11y.js";
9
9
  import { mergeRefs } from "../_internal/mergeRefs.js";
10
- import { Dialog } from "../feedback/Dialog.js";
11
- import { Button } from "../core/Button.js";
10
+ import { CaptureDialog } from "./_internal/AvatarCaptureDialog.js";
12
11
  const EN = {
13
12
  trigger: "Change photo",
14
13
  upload: "Upload a photo",
@@ -345,260 +344,6 @@ function MenuItem({ icon, label, onClick, danger }) {
345
344
  }
346
345
  );
347
346
  }
348
- const DEFAULT_STAGE = 280;
349
- const MODAL_WIDTH = 440;
350
- const ZOOM_ROW_HEIGHT = 24;
351
- function CropStage({ children, onPointerDown, onPointerMove, onPointerUp, onWheel, stageRef }) {
352
- return /* @__PURE__ */ jsxs(
353
- "div",
354
- {
355
- ref: stageRef,
356
- onPointerDown,
357
- onPointerMove,
358
- onPointerUp,
359
- onPointerCancel: onPointerUp,
360
- onWheel,
361
- style: sx({
362
- position: "relative",
363
- width: "100%",
364
- aspectRatio: "1",
365
- overflow: "hidden",
366
- borderRadius: "var(--radius-lg)",
367
- background: "var(--bg-sunken)",
368
- cursor: onPointerDown ? "grab" : "default",
369
- touchAction: "none"
370
- }),
371
- children: [
372
- children,
373
- /* @__PURE__ */ jsx(
374
- "span",
375
- {
376
- style: sx({
377
- position: "absolute",
378
- inset: 0,
379
- pointerEvents: "none",
380
- borderRadius: "999px",
381
- boxShadow: "0 0 0 9999px color-mix(in srgb, var(--bg-overlay) 80%, transparent)",
382
- outline: "1px solid rgba(255, 255, 255, 0.9)",
383
- outlineOffset: -1
384
- })
385
- }
386
- )
387
- ]
388
- }
389
- );
390
- }
391
- function useCamera(active, onError) {
392
- const videoRef = React.useRef(null);
393
- const streamRef = React.useRef(null);
394
- const [ready, setReady] = React.useState(false);
395
- const onErrorRef = React.useRef(onError);
396
- React.useEffect(() => {
397
- onErrorRef.current = onError;
398
- });
399
- React.useEffect(() => {
400
- if (!active) return;
401
- let cancelled = false;
402
- let started = null;
403
- const md = typeof navigator !== "undefined" ? navigator.mediaDevices : void 0;
404
- if (!md?.getUserMedia) {
405
- onErrorRef.current();
406
- return;
407
- }
408
- md.getUserMedia({ video: { facingMode: "user", width: { ideal: 1280 }, height: { ideal: 1280 } }, audio: false }).then((s) => {
409
- if (cancelled) {
410
- s.getTracks().forEach((tr) => tr.stop());
411
- return;
412
- }
413
- started = s;
414
- streamRef.current = s;
415
- if (videoRef.current) videoRef.current.srcObject = s;
416
- setReady(true);
417
- }).catch(() => onErrorRef.current());
418
- return () => {
419
- cancelled = true;
420
- started?.getTracks().forEach((tr) => tr.stop());
421
- streamRef.current = null;
422
- setReady(false);
423
- };
424
- }, [active]);
425
- const attachVideo = React.useCallback((el) => {
426
- videoRef.current = el;
427
- if (el && streamRef.current) el.srcObject = streamRef.current;
428
- }, []);
429
- const shoot = (onShot) => {
430
- const v = videoRef.current;
431
- if (!v || !v.videoWidth) return;
432
- const s = Math.min(v.videoWidth, v.videoHeight);
433
- const canvas = document.createElement("canvas");
434
- canvas.width = canvas.height = s;
435
- const ctx = canvas.getContext("2d");
436
- if (!ctx) return;
437
- ctx.translate(s, 0);
438
- ctx.scale(-1, 1);
439
- ctx.drawImage(v, (v.videoWidth - s) / 2, (v.videoHeight - s) / 2, s, s, 0, 0, s, s);
440
- canvas.toBlob((b) => b && onShot(b), "image/jpeg", 0.9);
441
- };
442
- return { attachVideo, ready, shoot };
443
- }
444
- function useCropper(src, outputSize) {
445
- const [imgEl, setImgEl] = React.useState(null);
446
- const [stageEl, setStageEl] = React.useState(null);
447
- const [V, setV] = React.useState(DEFAULT_STAGE);
448
- const prevV = React.useRef(V);
449
- const [nat, setNat] = React.useState(null);
450
- const [zoom, setZoom] = React.useState(1);
451
- const [offset, setOffset] = React.useState({ x: 0, y: 0 });
452
- const drag = React.useRef(null);
453
- const [seenSrc, setSeenSrc] = React.useState(src);
454
- if (src !== seenSrc) {
455
- setSeenSrc(src);
456
- setNat(null);
457
- setZoom(1);
458
- setOffset({ x: 0, y: 0 });
459
- }
460
- React.useEffect(() => {
461
- if (!stageEl) return;
462
- const ro = new ResizeObserver((entries) => {
463
- const w = Math.round(entries[0]?.contentRect.width ?? 0);
464
- if (!w || w === prevV.current) return;
465
- const factor = w / prevV.current;
466
- prevV.current = w;
467
- setV(w);
468
- setOffset((o) => ({ x: o.x * factor, y: o.y * factor }));
469
- });
470
- ro.observe(stageEl);
471
- return () => ro.disconnect();
472
- }, [stageEl]);
473
- const scaleMin = nat ? V / Math.min(nat.w, nat.h) : 1;
474
- const scale = scaleMin * zoom;
475
- const dispW = nat ? nat.w * scale : V;
476
- const dispH = nat ? nat.h * scale : V;
477
- const clamp = React.useCallback(
478
- (o) => ({
479
- x: Math.min(0, Math.max(V - dispW, o.x)),
480
- y: Math.min(0, Math.max(V - dispH, o.y))
481
- }),
482
- [V, dispW, dispH]
483
- );
484
- const onImgLoad = (el) => {
485
- const w = el.naturalWidth;
486
- const h = el.naturalHeight;
487
- setNat({ w, h });
488
- const s = V / Math.min(w, h);
489
- setOffset({ x: (V - w * s) / 2, y: (V - h * s) / 2 });
490
- };
491
- const setZoomAt = (nextZoom) => {
492
- const z = Math.min(3, Math.max(1, nextZoom));
493
- setZoom((prevZ) => {
494
- const oldScale = scaleMin * prevZ;
495
- const newScale = scaleMin * z;
496
- setOffset((o) => {
497
- const imgX = (V / 2 - o.x) / oldScale;
498
- const imgY = (V / 2 - o.y) / oldScale;
499
- return clamp({ x: V / 2 - imgX * newScale, y: V / 2 - imgY * newScale });
500
- });
501
- return z;
502
- });
503
- };
504
- const onPointerDown = (e) => {
505
- e.target.setPointerCapture(e.pointerId);
506
- drag.current = { x: e.clientX, y: e.clientY };
507
- };
508
- const onPointerMove = (e) => {
509
- if (!drag.current) return;
510
- const dx = e.clientX - drag.current.x;
511
- const dy = e.clientY - drag.current.y;
512
- drag.current = { x: e.clientX, y: e.clientY };
513
- setOffset((o) => clamp({ x: o.x + dx, y: o.y + dy }));
514
- };
515
- const onPointerUp = () => {
516
- drag.current = null;
517
- };
518
- const save = (onSave) => {
519
- if (!imgEl || !nat) return;
520
- const canvas = document.createElement("canvas");
521
- canvas.width = canvas.height = outputSize;
522
- const ctx = canvas.getContext("2d");
523
- if (!ctx) return;
524
- const sSize = V / scale;
525
- ctx.drawImage(imgEl, -offset.x / scale, -offset.y / scale, sSize, sSize, 0, 0, outputSize, outputSize);
526
- canvas.toBlob((b) => b && onSave(b), "image/jpeg", 0.85);
527
- };
528
- return { setImgEl, setStageEl, zoom, setZoomAt, offset, dispW, dispH, onImgLoad, onPointerDown, onPointerMove, onPointerUp, save };
529
- }
530
- function CaptureDialog({
531
- step,
532
- src,
533
- outputSize,
534
- labels,
535
- onClose,
536
- onCameraShot,
537
- onCameraError,
538
- onSave,
539
- onRetake
540
- }) {
541
- const isCamera = step === "camera";
542
- const camera = useCamera(isCamera, onCameraError);
543
- const crop = useCropper(src, outputSize);
544
- const [contentEl, setContentEl] = React.useState(null);
545
- React.useEffect(() => {
546
- contentEl?.closest('[role="dialog"]')?.focus();
547
- }, [step, contentEl]);
548
- return /* @__PURE__ */ jsxs(Dialog, { width: MODAL_WIDTH, onClose, children: [
549
- /* @__PURE__ */ jsx(Dialog.Header, { title: isCamera ? labels.cameraTitle : labels.cropTitle, description: isCamera ? labels.cameraHint : labels.cropHint }),
550
- /* @__PURE__ */ jsx(Dialog.Body, { children: /* @__PURE__ */ jsxs("div", { ref: setContentEl, children: [
551
- isCamera ? /* @__PURE__ */ jsx(CropStage, { children: /* @__PURE__ */ jsx("video", { ref: camera.attachVideo, autoPlay: true, playsInline: true, muted: true, style: sx({ width: "100%", height: "100%", objectFit: "cover", transform: "scaleX(-1)" }) }) }, "camera") : /* @__PURE__ */ jsx(
552
- CropStage,
553
- {
554
- stageRef: crop.setStageEl,
555
- onPointerDown: crop.onPointerDown,
556
- onPointerMove: crop.onPointerMove,
557
- onPointerUp: crop.onPointerUp,
558
- onWheel: (e) => crop.setZoomAt(crop.zoom - e.deltaY * 2e-3),
559
- children: src && // eslint-disable-next-line @next/next/no-img-element
560
- /* @__PURE__ */ jsx(
561
- "img",
562
- {
563
- ref: crop.setImgEl,
564
- src,
565
- alt: "",
566
- draggable: false,
567
- onLoad: (e) => crop.onImgLoad(e.currentTarget),
568
- style: sx({ position: "absolute", left: crop.offset.x, top: crop.offset.y, width: crop.dispW, height: crop.dispH, maxWidth: "none", userSelect: "none", pointerEvents: "none" })
569
- }
570
- )
571
- },
572
- "crop"
573
- ),
574
- /* @__PURE__ */ jsx("div", { style: sx({ display: "flex", alignItems: "center", gap: "var(--space-3)", marginTop: "var(--space-4)", minHeight: ZOOM_ROW_HEIGHT, color: "var(--text-muted)" }), children: !isCamera && /* @__PURE__ */ jsxs(Fragment, { children: [
575
- /* @__PURE__ */ jsx(ZoomOut, { size: 16, strokeWidth: 1.75, style: { flex: "0 0 auto" } }),
576
- /* @__PURE__ */ jsx(
577
- "input",
578
- {
579
- type: "range",
580
- min: 1,
581
- max: 3,
582
- step: 0.01,
583
- value: crop.zoom,
584
- onChange: (e) => crop.setZoomAt(Number(e.target.value)),
585
- "aria-label": labels.zoom,
586
- style: sx({ flex: 1, accentColor: "var(--interactive-primary)" })
587
- }
588
- ),
589
- /* @__PURE__ */ jsx(ZoomIn, { size: 16, strokeWidth: 1.75, style: { flex: "0 0 auto" } })
590
- ] }) })
591
- ] }) }),
592
- /* @__PURE__ */ jsx(Dialog.Footer, { fill: !isCamera && Boolean(onRetake), children: isCamera ? /* @__PURE__ */ jsxs(React.Fragment, { children: [
593
- /* @__PURE__ */ jsx(Button, { variant: "secondary", iconLeft: /* @__PURE__ */ jsx(X, { size: 16, strokeWidth: 2 }), onClick: onClose, children: labels.cancel }),
594
- /* @__PURE__ */ jsx(Button, { iconLeft: /* @__PURE__ */ jsx(Camera, { size: 16, strokeWidth: 2 }), onClick: () => camera.shoot(onCameraShot), disabled: !camera.ready, children: labels.capture })
595
- ] }, "camera") : /* @__PURE__ */ jsxs(React.Fragment, { children: [
596
- onRetake && /* @__PURE__ */ jsx(Button, { variant: "secondary", iconLeft: /* @__PURE__ */ jsx(RotateCcw, { size: 16, strokeWidth: 2 }), onClick: onRetake, children: labels.retake }),
597
- /* @__PURE__ */ jsx(Button, { variant: "secondary", iconLeft: /* @__PURE__ */ jsx(X, { size: 16, strokeWidth: 2 }), onClick: onClose, children: labels.cancel }),
598
- /* @__PURE__ */ jsx(Button, { iconLeft: /* @__PURE__ */ jsx(Check, { size: 16, strokeWidth: 2.5 }), onClick: () => crop.save(onSave), children: labels.save })
599
- ] }, "crop") })
600
- ] });
601
- }
602
347
  export {
603
348
  AvatarUpload
604
349
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/forms/AvatarUpload.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { createPortal } from 'react-dom';\nimport { Camera, Check, ImagePlus, Pencil, RotateCcw, Trash2, X, ZoomIn, ZoomOut } from 'lucide-react';\nimport { sx } from '../_internal/style';\nimport { Field } from '../_internal/Field';\nimport { fieldA11y } from '../_internal/fieldA11y';\nimport { mergeRefs } from '../_internal/mergeRefs';\nimport { Dialog } from '../feedback/Dialog';\nimport { Button } from '../core/Button';\n\n/**\n * Profile-photo picker: an avatar disc with a camera button. Pick from the\n * library (or the camera on touch), frame the face in a circular crop, and it\n * hands back a **cropped, downscaled** `File` (JPEG). For attachments / documents\n * / multiple files use `FileUpload` instead.\n *\n * Client-side only downscales and re-encodes; it does not decode HEIC (no\n * browser but Safari can) - that is a server-side job. HEIC picks are rejected\n * with a message.\n */\n/** User-facing strings - English by default; pass overrides for another locale. */\nexport interface AvatarUploadLabels {\n trigger: string;\n upload: string;\n takePhoto: string;\n remove: string;\n cropTitle: string;\n cropHint: string;\n cameraTitle: string;\n cameraHint: string;\n capture: string;\n /** On the crop step, only shown for a shot taken with the camera; reopens it directly. */\n retake: string;\n cancel: string;\n save: string;\n zoom: string;\n heicError: string;\n notImage: string;\n tooLarge: (mb: number) => string;\n unreadable: string;\n cameraError: string;\n}\n\nconst EN: AvatarUploadLabels = {\n trigger: 'Change photo',\n upload: 'Upload a photo',\n takePhoto: 'Take a photo',\n remove: 'Remove photo',\n cropTitle: 'Adjust the photo',\n cropHint: 'Drag to reposition · scroll to zoom.',\n cameraTitle: 'Take a photo',\n cameraHint: 'Line your face up with the circle.',\n capture: 'Capture',\n retake: 'Retake',\n cancel: 'Cancel',\n save: 'Save',\n zoom: 'Zoom',\n heicError: \"That format (HEIC) won't open in the browser, upload a JPG or PNG.\",\n notImage: 'Choose an image file.',\n tooLarge: (mb) => `The image is over ${mb} MB.`,\n unreadable: \"Couldn't read that image. Try a JPG or PNG.\",\n cameraError: \"Couldn't open the camera: upload a photo from your library instead.\",\n};\n\nexport interface AvatarUploadProps {\n /** Full name - drives the initials fallback and the alt text. */\n name?: string;\n /** Current photo: a `File` (freshly cropped) or an existing URL string. */\n value?: File | string | null;\n onChange?: (file: File | null) => void;\n /** Disc diameter in px. */\n size?: number;\n /** Exported square size in px - the crop is drawn to this. */\n outputSize?: number;\n /** Reject picks larger than this (before crop). */\n maxSizeMB?: number;\n /** Override the English UI strings (menu, crop dialog, messages). */\n labels?: Partial<AvatarUploadLabels>;\n label?: string;\n hint?: string;\n error?: string;\n required?: boolean;\n disabled?: boolean;\n id?: string;\n containerStyle?: React.CSSProperties;\n /** Reserve the hint/error row's height even with neither set - stops the\n * field from growing the moment a validation message appears. */\n preserveHelperSpace?: boolean;\n /**\n * Whether to allow taking a photo via camera (default true).\n * Set to `false` when picking an organization or brand logo, where taking a\n * live selfie/photo makes no sense.\n */\n allowCamera?: boolean;\n}\n\nfunction initials(name: string): string {\n return (name || '')\n .trim()\n .split(/\\s+/)\n .slice(0, 2)\n .map((w) => w[0] || '')\n .join('')\n .toUpperCase();\n}\n\nconst isHeic = (f: File) => /image\\/heic|image\\/heif/i.test(f.type) || /\\.(heic|heif)$/i.test(f.name);\n\nexport const AvatarUpload = React.forwardRef<HTMLInputElement, AvatarUploadProps>(function AvatarUpload(\n {\n name = '',\n value,\n onChange,\n size = 96,\n outputSize = 512,\n maxSizeMB = 8,\n labels: labelsProp,\n label,\n hint,\n error,\n required,\n disabled,\n id,\n containerStyle,\n preserveHelperSpace,\n allowCamera = true,\n },\n forwardedRef,\n) {\n const t = React.useMemo<AvatarUploadLabels>(() => ({ ...EN, ...labelsProp }), [labelsProp]);\n const autoId = React.useId();\n const rid = id || autoId;\n const libRef = React.useRef<HTMLInputElement>(null);\n const triggerRef = React.useRef<HTMLButtonElement>(null);\n const menuRef = React.useRef<HTMLDivElement>(null);\n\n const [menuOpen, setMenuOpen] = React.useState(false);\n const [menuPos, setMenuPos] = React.useState<{ top: number; left: number } | null>(null);\n const [rejected, setRejected] = React.useState<string | null>(null);\n const [cropSrc, setCropSrc] = React.useState<string | null>(null);\n // Whether the photo now in the crop step came from the camera. Only then does the crop\n // modal offer \"Retake\" (a library pick already has its own way to change: cancel and pick\n // another file from the system's own dialog).\n const [cropFromCamera, setCropFromCamera] = React.useState(false);\n const [cameraOpen, setCameraOpen] = React.useState(false);\n const [internal, setInternal] = React.useState<File | null>(null);\n\n const current = value !== undefined ? value : internal;\n\n // Preview URL for the current photo.\n const [preview, setPreview] = React.useState<string | null>(typeof current === 'string' ? current : null);\n React.useEffect(() => {\n if (current instanceof File) {\n const u = URL.createObjectURL(current);\n // eslint-disable-next-line react-hooks/set-state-in-effect -- syncing to an object URL\n setPreview(u);\n return () => URL.revokeObjectURL(u);\n }\n setPreview(typeof current === 'string' ? current : null);\n }, [current]);\n\n const itemCount = (allowCamera ? 1 : 0) + 1 + (current ? 1 : 0);\n\n const toggleMenu = () => {\n if (!allowCamera && !current) {\n libRef.current?.click();\n return;\n }\n if (menuOpen) {\n setMenuOpen(false);\n return;\n }\n const r = triggerRef.current?.getBoundingClientRect();\n if (r) {\n const h = itemCount * 40 + 8;\n const flipUp = r.bottom + 6 + h > window.innerHeight - 8;\n setMenuPos({\n top: flipUp ? Math.max(8, r.top - 6 - h) : r.bottom + 6,\n left: Math.max(8, Math.min(r.left, window.innerWidth - 208)),\n });\n }\n setMenuOpen(true);\n };\n\n // Close the menu on outside click / Escape / scroll - it is portalled to <body>.\n React.useEffect(() => {\n if (!menuOpen) return;\n const onDown = (e: MouseEvent) => {\n const target = e.target as Node;\n if (triggerRef.current?.contains(target) || menuRef.current?.contains(target)) return;\n setMenuOpen(false);\n };\n const close = () => setMenuOpen(false);\n const onKey = (e: KeyboardEvent) => e.key === 'Escape' && close();\n document.addEventListener('mousedown', onDown);\n document.addEventListener('keydown', onKey);\n window.addEventListener('scroll', close, true);\n window.addEventListener('resize', close);\n return () => {\n document.removeEventListener('mousedown', onDown);\n document.removeEventListener('keydown', onKey);\n window.removeEventListener('scroll', close, true);\n window.removeEventListener('resize', close);\n };\n }, [menuOpen]);\n\n // One dialog for the flow, on whichever step is current: the crop once there is a photo,\n // else the live camera. A shot or a Retake flips both at once, so the step just changes.\n // The `Dialog` it is drawn in already locks the page scroll and closes on Escape (through the\n // `onClose` handed to it below), so nothing here does: a second lock of our own used to be\n // released after the Dialog's and left the page unable to scroll (SS-402).\n const step: Step | null = cropSrc ? 'crop' : allowCamera && cameraOpen ? 'camera' : null;\n\n const pick = (files: FileList | null) => {\n const f = files?.[0];\n if (!f) return;\n if (isHeic(f)) {\n setRejected(t.heicError);\n return;\n }\n if (!f.type.startsWith('image/')) {\n setRejected(t.notImage);\n return;\n }\n if (f.size > maxSizeMB * 1048576) {\n setRejected(t.tooLarge(maxSizeMB));\n return;\n }\n const url = URL.createObjectURL(f);\n const probe = new Image();\n probe.onload = () => {\n setRejected(null);\n setCropFromCamera(false);\n setCropSrc(url);\n };\n probe.onerror = () => {\n URL.revokeObjectURL(url);\n setRejected(t.unreadable);\n };\n probe.src = url;\n };\n\n const commit = (file: File | null) => {\n if (value === undefined) setInternal(file);\n onChange?.(file);\n };\n\n const onCropSave = (blob: Blob) => {\n const file = new File([blob], 'avatar.jpg', { type: 'image/jpeg' });\n if (cropSrc) URL.revokeObjectURL(cropSrc);\n setCropSrc(null);\n commit(file);\n };\n const onCropCancel = () => {\n if (cropSrc) URL.revokeObjectURL(cropSrc);\n setCropSrc(null);\n };\n\n const onCameraShot = (blob: Blob) => {\n setCameraOpen(false);\n setRejected(null);\n setCropFromCamera(true);\n setCropSrc(URL.createObjectURL(blob));\n };\n\n // Straight back to the live camera, no menu in between: the crop modal's \"Retake\".\n const onRetake = () => {\n if (cropSrc) URL.revokeObjectURL(cropSrc);\n setCropSrc(null);\n setCameraOpen(true);\n };\n\n const cameraBtn = Math.max(30, Math.round(size * 0.34));\n\n // What `Field` shows as the error: the consumer's, or a rejected pick's (type, size, unreadable).\n const shownError = error || rejected || undefined;\n // The hidden `<input type=\"file\">` is out of the accessibility tree: the pencil is what takes focus.\n const a11y = fieldA11y(rid, { hint, error: shownError });\n\n return (\n <Field label={label} hint={hint} error={shownError} required={required} htmlFor={rid} style={containerStyle} preserveHelperSpace={preserveHelperSpace}>\n <input ref={mergeRefs(libRef, forwardedRef)} id={rid} type=\"file\" accept=\"image/*\" disabled={disabled} onChange={(e) => pick(e.target.files)} style={{ display: 'none' }} />\n\n <div style={sx({ position: 'relative', width: size, height: size, flex: '0 0 auto', opacity: disabled ? 0.6 : 1 })}>\n <span\n style={sx({\n width: size,\n height: size,\n borderRadius: '999px',\n overflow: 'hidden',\n display: 'inline-flex',\n alignItems: 'center',\n justifyContent: 'center',\n background: preview ? 'var(--bg-subtle)' : 'color-mix(in srgb, var(--brand-500) 22%, var(--bg-surface))',\n border: '1px solid ' + (preview ? 'var(--border-subtle)' : 'color-mix(in srgb, var(--brand-500) 30%, transparent)'),\n color: 'var(--text-brand)',\n fontFamily: 'var(--font-display)',\n fontWeight: 'var(--weight-bold)',\n fontSize: Math.round(size * 0.34),\n letterSpacing: 'var(--tracking-snug)',\n })}\n >\n {preview ? (\n // eslint-disable-next-line @next/next/no-img-element\n <img src={preview} alt={name} style={sx({ width: '100%', height: '100%', objectFit: 'cover' })} />\n ) : (\n initials(name) || <ImagePlus size={Math.round(size * 0.3)} strokeWidth={1.75} />\n )}\n </span>\n\n {!disabled && (\n <button\n ref={triggerRef}\n type=\"button\"\n className=\"ds-affix-btn\"\n aria-label={t.trigger}\n aria-haspopup=\"menu\"\n aria-expanded={menuOpen}\n {...a11y}\n onClick={toggleMenu}\n style={sx({\n position: 'absolute',\n right: -2,\n bottom: -2,\n width: cameraBtn,\n height: cameraBtn,\n borderRadius: '999px',\n display: 'inline-flex',\n alignItems: 'center',\n justifyContent: 'center',\n background: 'var(--bg-surface)',\n border: '1px solid var(--border-default)',\n boxShadow: 'var(--shadow-sm)',\n color: 'var(--text-secondary)',\n cursor: 'pointer',\n })}\n >\n <Pencil size={Math.round(cameraBtn * 0.46)} strokeWidth={1.75} />\n </button>\n )}\n\n </div>\n\n {menuOpen &&\n menuPos &&\n createPortal(\n <div\n ref={menuRef}\n role=\"menu\"\n style={sx({\n position: 'fixed',\n top: menuPos.top,\n left: menuPos.left,\n minWidth: 200,\n zIndex: 1000,\n padding: 'var(--space-1)',\n borderRadius: 'var(--radius-md)',\n background: 'var(--bg-surface)',\n border: '1px solid var(--border-default)',\n boxShadow: 'var(--shadow-lg)',\n display: 'flex',\n flexDirection: 'column',\n })}\n >\n <MenuItem\n icon={<ImagePlus size={16} strokeWidth={1.75} />}\n label={t.upload}\n onClick={() => {\n setMenuOpen(false);\n libRef.current?.click();\n }}\n />\n {allowCamera && (\n <MenuItem\n icon={<Camera size={16} strokeWidth={1.75} />}\n label={t.takePhoto}\n onClick={() => {\n setMenuOpen(false);\n setRejected(null);\n setCameraOpen(true);\n }}\n />\n )}\n {current && (\n <MenuItem\n icon={<Trash2 size={16} strokeWidth={1.75} />}\n label={t.remove}\n danger\n onClick={() => {\n setMenuOpen(false);\n commit(null);\n }}\n />\n )}\n </div>,\n document.body,\n )}\n\n {step && (\n <CaptureDialog\n step={step}\n src={cropSrc}\n outputSize={outputSize}\n labels={t}\n onClose={step === 'camera' ? () => setCameraOpen(false) : onCropCancel}\n onCameraShot={onCameraShot}\n onCameraError={() => {\n setCameraOpen(false);\n setRejected(t.cameraError);\n }}\n onSave={onCropSave}\n onRetake={cropFromCamera ? onRetake : undefined}\n />\n )}\n </Field>\n );\n});\n\nAvatarUpload.displayName = 'AvatarUpload';\n\nfunction MenuItem({ icon, label, onClick, danger }: { icon: React.ReactNode; label: string; onClick: () => void; danger?: boolean }) {\n const [hover, setHover] = React.useState(false);\n return (\n <button\n type=\"button\"\n role=\"menuitem\"\n onClick={onClick}\n onMouseEnter={() => setHover(true)}\n onMouseLeave={() => setHover(false)}\n style={sx({\n display: 'flex',\n alignItems: 'center',\n gap: 'var(--space-2)',\n width: '100%',\n minHeight: 40,\n padding: '0 var(--space-3)',\n border: 'none',\n borderRadius: 'var(--radius-sm)',\n background: hover ? 'var(--bg-subtle)' : 'transparent',\n cursor: 'pointer',\n fontFamily: 'var(--font-body)',\n fontSize: 'var(--text-sm)',\n color: danger ? 'var(--interactive-error)' : 'var(--text-primary)',\n textAlign: 'left',\n })}\n >\n {icon}\n {label}\n </button>\n );\n}\n\nconst DEFAULT_STAGE = 280; // crop stage's assumed size (px) before its own ResizeObserver measures it\n\n/**\n * Width of the camera and crop dialogs. They are two steps of one flow (a shot goes straight\n * to the crop), so they share it: a dialog that changed size between the steps would jump.\n * Wider than `Dialog`'s default 352: with Retake the crop footer has three real Buttons, and\n * in Portuguese (\"Tirar outra\", \"Cancelar\", \"Gravar\") they add up to 384px, more than the\n * 358px of content a 400px dialog leaves. 440 gives 398px, so they fit on one line with ~14px\n * to spare. `Dialog` already caps at `min(100%, ...)` for narrow viewports (see\n * feedback/Dialog.tsx), so a phone just gets a narrower dialog. Widening only moves the limit\n * though: the crop footer's `fill` is what keeps a longer language, or that phone, from\n * stranding the primary button.\n */\nconst MODAL_WIDTH = 440;\n\n/** Height reserved for the zoom row, so the camera step (which has none) is as tall as the crop step. */\nconst ZOOM_ROW_HEIGHT = 24;\n\n/**\n * The square viewport + circular guide, shared by the crop and camera modals.\n * `width: 100%` + `aspectRatio: 1`, not a fixed pixel box: it spans exactly the same\n * width as `Dialog.Header`'s title and `Dialog.Footer`'s buttons (both just block-level\n * or flex content inside the same padded `Dialog.Body`), instead of a fixed size\n * centered with margins of its own that didn't match theirs (SS-322 follow-up, the\n * stage read as misaligned from the rest of the dialog). Also needs no separate\n * mobile-width handling of its own: whatever width the dialog ends up at (already\n * responsive, see `feedback/Dialog.tsx`), the stage fills it exactly, staying square\n * via `aspectRatio`.\n */\nfunction CropStage({ children, onPointerDown, onPointerMove, onPointerUp, onWheel, stageRef }: {\n children: React.ReactNode;\n onPointerDown?: (e: React.PointerEvent) => void;\n onPointerMove?: (e: React.PointerEvent) => void;\n onPointerUp?: (e: React.PointerEvent) => void;\n onWheel?: (e: React.WheelEvent) => void;\n /** `useCropper` reads the live rendered size off this to drive the crop math (`V`). */\n stageRef?: React.Ref<HTMLDivElement>;\n}) {\n return (\n <div\n ref={stageRef}\n onPointerDown={onPointerDown}\n onPointerMove={onPointerMove}\n onPointerUp={onPointerUp}\n onPointerCancel={onPointerUp}\n onWheel={onWheel}\n style={sx({\n position: 'relative',\n width: '100%',\n aspectRatio: '1',\n overflow: 'hidden',\n borderRadius: 'var(--radius-lg)',\n background: 'var(--bg-sunken)',\n cursor: onPointerDown ? 'grab' : 'default',\n touchAction: 'none',\n })}\n >\n {children}\n <span\n style={sx({\n position: 'absolute',\n inset: 0,\n pointerEvents: 'none',\n borderRadius: '999px',\n boxShadow: '0 0 0 9999px color-mix(in srgb, var(--bg-overlay) 80%, transparent)',\n outline: '1px solid rgba(255, 255, 255, 0.9)',\n outlineOffset: -1,\n })}\n />\n </div>\n );\n}\n\n/** Which step of the photo flow the dialog is on. */\ntype Step = 'camera' | 'crop';\n\n/**\n * Live camera via `getUserMedia`, while `active`. A failure (no API, permission denied)\n * goes through `onError`. `ready` turns true once the stream is flowing; going inactive\n * stops the tracks, so the camera light goes off as soon as the dialog leaves this step.\n */\nfunction useCamera(active: boolean, onError: () => void) {\n const videoRef = React.useRef<HTMLVideoElement | null>(null);\n const streamRef = React.useRef<MediaStream | null>(null);\n const [ready, setReady] = React.useState(false);\n // Read through a ref so a new `onError` closure each render does not restart the camera.\n const onErrorRef = React.useRef(onError);\n React.useEffect(() => {\n onErrorRef.current = onError;\n });\n\n React.useEffect(() => {\n if (!active) return;\n let cancelled = false;\n let started: MediaStream | null = null;\n const md = typeof navigator !== 'undefined' ? navigator.mediaDevices : undefined;\n if (!md?.getUserMedia) {\n onErrorRef.current();\n return;\n }\n md.getUserMedia({ video: { facingMode: 'user', width: { ideal: 1280 }, height: { ideal: 1280 } }, audio: false })\n .then((s) => {\n if (cancelled) {\n s.getTracks().forEach((tr) => tr.stop());\n return;\n }\n started = s;\n streamRef.current = s;\n if (videoRef.current) videoRef.current.srcObject = s;\n setReady(true);\n })\n .catch(() => onErrorRef.current());\n return () => {\n cancelled = true;\n started?.getTracks().forEach((tr) => tr.stop());\n streamRef.current = null;\n setReady(false);\n };\n }, [active]);\n\n // The `<video>` may mount after the stream arrives (`Dialog` renders its children a render\n // late) or the other way round, so wire them up whichever comes last: here for the element,\n // above for the stream.\n const attachVideo = React.useCallback((el: HTMLVideoElement | null) => {\n videoRef.current = el;\n if (el && streamRef.current) el.srcObject = streamRef.current;\n }, []);\n\n /** Grabs the centred square of the current frame, mirrored like the preview, as a JPEG. */\n const shoot = (onShot: (b: Blob) => void) => {\n const v = videoRef.current;\n if (!v || !v.videoWidth) return;\n const s = Math.min(v.videoWidth, v.videoHeight);\n const canvas = document.createElement('canvas');\n canvas.width = canvas.height = s;\n const ctx = canvas.getContext('2d');\n if (!ctx) return;\n ctx.translate(s, 0);\n ctx.scale(-1, 1);\n ctx.drawImage(v, (v.videoWidth - s) / 2, (v.videoHeight - s) / 2, s, s, 0, 0, s, s);\n canvas.toBlob((b) => b && onShot(b), 'image/jpeg', 0.9);\n };\n\n return { attachVideo, ready, shoot };\n}\n\n/**\n * The crop state and math for one picked photo (`src`): pan, zoom, the stage's live size,\n * and the export. It lives above the dialog, not inside the crop step, so the header, body\n * and footer of a single `Dialog` can all read it while the camera step swaps in and out.\n * Everything resets when `src` changes, so a retaken photo starts centred at 1x.\n */\nfunction useCropper(src: string | null, outputSize: number) {\n const [imgEl, setImgEl] = React.useState<HTMLImageElement | null>(null);\n // A *callback* ref (kept as state), not a plain `useRef` + a `[]`-effect: `Dialog` renders\n // its children only from the render *after* its own `mounted` flips true (SSR-safe portal),\n // so on the stage's very first mount a `useEffect(..., [])` reading `stageRef.current` at\n // that point would still see `null` and, with no deps to fire again on, never retry, so `V`\n // would then stay stuck at the `DEFAULT_STAGE` guess forever (this exact bug, caught live:\n // the displayed image stayed 280px inside a stage CSS had already sized at ~344px, a gray\n // gap on two edges). The callback fires the moment React actually attaches the node.\n const [stageEl, setStageEl] = React.useState<HTMLDivElement | null>(null);\n // The stage's own live rendered size (it's `width: 100%` of the dialog body now, not a\n // fixed px box), read via ResizeObserver. `DEFAULT_STAGE` is only the guess for the very\n // first paint, before the observer's first callback lands.\n const [V, setV] = React.useState(DEFAULT_STAGE);\n const prevV = React.useRef(V);\n const [nat, setNat] = React.useState<{ w: number; h: number } | null>(null);\n const [zoom, setZoom] = React.useState(1);\n const [offset, setOffset] = React.useState({ x: 0, y: 0 });\n const drag = React.useRef<{ x: number; y: number } | null>(null);\n\n // A new photo starts from scratch. Adjusting state while rendering (rather than in an\n // effect) means the stale pan / zoom is never painted against the new image.\n const [seenSrc, setSeenSrc] = React.useState(src);\n if (src !== seenSrc) {\n setSeenSrc(src);\n setNat(null);\n setZoom(1);\n setOffset({ x: 0, y: 0 });\n }\n\n React.useEffect(() => {\n if (!stageEl) return;\n const ro = new ResizeObserver((entries) => {\n const w = Math.round(entries[0]?.contentRect.width ?? 0);\n if (!w || w === prevV.current) return;\n // A live resize while the dialog is open (a phone rotated, a window resized) or the\n // very first real measurement replacing `DEFAULT_STAGE`: rescale the pan offset by\n // the same factor as the viewport itself, so the framed crop doesn't jump. `scale`\n // (see below) is linear in `V`, so multiplying the offset by `newV / oldV` keeps\n // the same fraction of the image framed.\n const factor = w / prevV.current;\n prevV.current = w;\n setV(w);\n setOffset((o) => ({ x: o.x * factor, y: o.y * factor }));\n });\n ro.observe(stageEl);\n return () => ro.disconnect();\n }, [stageEl]);\n\n const scaleMin = nat ? V / Math.min(nat.w, nat.h) : 1;\n const scale = scaleMin * zoom;\n const dispW = nat ? nat.w * scale : V;\n const dispH = nat ? nat.h * scale : V;\n\n const clamp = React.useCallback(\n (o: { x: number; y: number }) => ({\n x: Math.min(0, Math.max(V - dispW, o.x)),\n y: Math.min(0, Math.max(V - dispH, o.y)),\n }),\n [V, dispW, dispH],\n );\n\n const onImgLoad = (el: HTMLImageElement) => {\n const w = el.naturalWidth;\n const h = el.naturalHeight;\n setNat({ w, h });\n const s = V / Math.min(w, h);\n setOffset({ x: (V - w * s) / 2, y: (V - h * s) / 2 });\n };\n\n const setZoomAt = (nextZoom: number) => {\n const z = Math.min(3, Math.max(1, nextZoom));\n setZoom((prevZ) => {\n const oldScale = scaleMin * prevZ;\n const newScale = scaleMin * z;\n setOffset((o) => {\n const imgX = (V / 2 - o.x) / oldScale;\n const imgY = (V / 2 - o.y) / oldScale;\n return clamp({ x: V / 2 - imgX * newScale, y: V / 2 - imgY * newScale });\n });\n return z;\n });\n };\n\n const onPointerDown = (e: React.PointerEvent) => {\n (e.target as HTMLElement).setPointerCapture(e.pointerId);\n drag.current = { x: e.clientX, y: e.clientY };\n };\n const onPointerMove = (e: React.PointerEvent) => {\n if (!drag.current) return;\n const dx = e.clientX - drag.current.x;\n const dy = e.clientY - drag.current.y;\n drag.current = { x: e.clientX, y: e.clientY };\n setOffset((o) => clamp({ x: o.x + dx, y: o.y + dy }));\n };\n const onPointerUp = () => {\n drag.current = null;\n };\n\n const save = (onSave: (b: Blob) => void) => {\n if (!imgEl || !nat) return;\n const canvas = document.createElement('canvas');\n canvas.width = canvas.height = outputSize;\n const ctx = canvas.getContext('2d');\n if (!ctx) return;\n const sSize = V / scale;\n ctx.drawImage(imgEl, -offset.x / scale, -offset.y / scale, sSize, sSize, 0, 0, outputSize, outputSize);\n canvas.toBlob((b) => b && onSave(b), 'image/jpeg', 0.85);\n };\n\n return { setImgEl, setStageEl, zoom, setZoomAt, offset, dispW, dispH, onImgLoad, onPointerDown, onPointerMove, onPointerUp, save };\n}\n\n/**\n * The one dialog for the whole photo flow: the live camera, then the crop (and back, on\n * Retake). It stays mounted across the steps and only its header text, stage and buttons\n * swap, so the panel does not close and reopen (no second pop-in, no scroll-lock or focus\n * hand-off) and it keeps one size. `Dialog.Header` / `Body` / `Footer` are direct children\n * on purpose: `Dialog` reads them off its children to pad the body and label itself, which\n * a wrapper component per step would hide from it.\n */\nfunction CaptureDialog({\n step,\n src,\n outputSize,\n labels,\n onClose,\n onCameraShot,\n onCameraError,\n onSave,\n onRetake,\n}: {\n step: Step;\n /** The photo being cropped; only set on the crop step. */\n src: string | null;\n outputSize: number;\n labels: AvatarUploadLabels;\n onClose: () => void;\n onCameraShot: (b: Blob) => void;\n onCameraError: () => void;\n onSave: (b: Blob) => void;\n /** Only set for a shot taken with the camera; shows the \"Retake\" button. */\n onRetake?: () => void;\n}) {\n const isCamera = step === 'camera';\n const camera = useCamera(isCamera, onCameraError);\n const crop = useCropper(src, outputSize);\n\n // The step's buttons unmount with it, and with them the focused one: without this, focus\n // would fall to the page behind the dialog and Tab would leave the trap. `Dialog` only\n // pulls focus in when it opens, so do it again on every step change.\n const [contentEl, setContentEl] = React.useState<HTMLDivElement | null>(null);\n React.useEffect(() => {\n contentEl?.closest<HTMLElement>('[role=\"dialog\"]')?.focus();\n }, [step, contentEl]);\n\n /* eslint-disable react-hooks/refs -- `useCamera` / `useCropper` return event handlers that reach a\n ref (`videoRef`, the drag origin), so the lint marks every property read off them; but those\n refs are only touched when a handler runs from an event, never during this render. */\n return (\n <Dialog width={MODAL_WIDTH} onClose={onClose}>\n <Dialog.Header title={isCamera ? labels.cameraTitle : labels.cropTitle} description={isCamera ? labels.cameraHint : labels.cropHint} />\n <Dialog.Body>\n <div ref={setContentEl}>\n {isCamera ? (\n <CropStage key=\"camera\">\n <video ref={camera.attachVideo} autoPlay playsInline muted style={sx({ width: '100%', height: '100%', objectFit: 'cover', transform: 'scaleX(-1)' })} />\n </CropStage>\n ) : (\n <CropStage\n key=\"crop\"\n stageRef={crop.setStageEl}\n onPointerDown={crop.onPointerDown}\n onPointerMove={crop.onPointerMove}\n onPointerUp={crop.onPointerUp}\n onWheel={(e) => crop.setZoomAt(crop.zoom - e.deltaY * 0.002)}\n >\n {src && (\n // eslint-disable-next-line @next/next/no-img-element\n <img\n ref={crop.setImgEl}\n src={src}\n alt=\"\"\n draggable={false}\n onLoad={(e) => crop.onImgLoad(e.currentTarget)}\n style={sx({ position: 'absolute', left: crop.offset.x, top: crop.offset.y, width: crop.dispW, height: crop.dispH, maxWidth: 'none', userSelect: 'none', pointerEvents: 'none' })}\n />\n )}\n </CropStage>\n )}\n\n {/* The zoom row is only there on the crop step, but the camera step keeps its room, so the dialog is the same height on both. */}\n <div style={sx({ display: 'flex', alignItems: 'center', gap: 'var(--space-3)', marginTop: 'var(--space-4)', minHeight: ZOOM_ROW_HEIGHT, color: 'var(--text-muted)' })}>\n {!isCamera && (\n <>\n <ZoomOut size={16} strokeWidth={1.75} style={{ flex: '0 0 auto' }} />\n <input\n type=\"range\"\n min={1}\n max={3}\n step={0.01}\n value={crop.zoom}\n onChange={(e) => crop.setZoomAt(Number(e.target.value))}\n aria-label={labels.zoom}\n style={sx({ flex: 1, accentColor: 'var(--interactive-primary)' })}\n />\n <ZoomIn size={16} strokeWidth={1.75} style={{ flex: '0 0 auto' }} />\n </>\n )}\n </div>\n </div>\n </Dialog.Body>\n {/* Three actions (crop after a camera shot, with Retake) share the row and each line they wrap onto; two stay right-aligned, as before. */}\n <Dialog.Footer fill={!isCamera && Boolean(onRetake)}>\n {isCamera ? (\n <React.Fragment key=\"camera\">\n <Button variant=\"secondary\" iconLeft={<X size={16} strokeWidth={2} />} onClick={onClose}>\n {labels.cancel}\n </Button>\n <Button iconLeft={<Camera size={16} strokeWidth={2} />} onClick={() => camera.shoot(onCameraShot)} disabled={!camera.ready}>\n {labels.capture}\n </Button>\n </React.Fragment>\n ) : (\n <React.Fragment key=\"crop\">\n {onRetake && (\n <Button variant=\"secondary\" iconLeft={<RotateCcw size={16} strokeWidth={2} />} onClick={onRetake}>\n {labels.retake}\n </Button>\n )}\n <Button variant=\"secondary\" iconLeft={<X size={16} strokeWidth={2} />} onClick={onClose}>\n {labels.cancel}\n </Button>\n <Button iconLeft={<Check size={16} strokeWidth={2.5} />} onClick={() => crop.save(onSave)}>\n {labels.save}\n </Button>\n </React.Fragment>\n )}\n </Dialog.Footer>\n </Dialog>\n );\n /* eslint-enable react-hooks/refs */\n}\n"],"mappings":";AA2RM,SAqgBQ,UArgBR,KAEA,YAFA;AAzRN,YAAY,WAAW;AACvB,SAAS,oBAAoB;AAC7B,SAAS,QAAQ,OAAO,WAAW,QAAQ,WAAW,QAAQ,GAAG,QAAQ,eAAe;AACxF,SAAS,UAAU;AACnB,SAAS,aAAa;AACtB,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;AAC1B,SAAS,cAAc;AACvB,SAAS,cAAc;AAmCvB,MAAM,KAAyB;AAAA,EAC7B,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,WAAW;AAAA,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C;AAAA,0BAAC,UAAO,SAAQ,aAAY,UAAU,oBAAC,KAAE,MAAM,IAAI,aAAa,GAAG,GAAI,SAAS,SAC7E,iBAAO,QACV;AAAA,MACA,oBAAC,UAAO,UAAU,oBAAC,UAAO,MAAM,IAAI,aAAa,GAAG,GAAI,SAAS,MAAM,OAAO,MAAM,YAAY,GAAG,UAAU,CAAC,OAAO,OAClH,iBAAO,SACV;AAAA,SANkB,QAOpB,IAEA,qBAAC,MAAM,UAAN,EACE;AAAA,kBACC,oBAAC,UAAO,SAAQ,aAAY,UAAU,oBAAC,aAAU,MAAM,IAAI,aAAa,GAAG,GAAI,SAAS,UACrF,iBAAO,QACV;AAAA,MAEF,oBAAC,UAAO,SAAQ,aAAY,UAAU,oBAAC,KAAE,MAAM,IAAI,aAAa,GAAG,GAAI,SAAS,SAC7E,iBAAO,QACV;AAAA,MACA,oBAAC,UAAO,UAAU,oBAAC,SAAM,MAAM,IAAI,aAAa,KAAK,GAAI,SAAS,MAAM,KAAK,KAAK,MAAM,GACrF,iBAAO,MACV;AAAA,SAXkB,MAYpB,GAEJ;AAAA,KACF;AAGJ;","names":["AvatarUpload"]}
1
+ {"version":3,"sources":["../../src/forms/AvatarUpload.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { createPortal } from 'react-dom';\nimport { Camera, ImagePlus, Pencil, Trash2 } from 'lucide-react';\nimport { sx } from '../_internal/style';\nimport { Field } from '../_internal/Field';\nimport { fieldA11y } from '../_internal/fieldA11y';\nimport { mergeRefs } from '../_internal/mergeRefs';\nimport { CaptureDialog, type Step } from './_internal/AvatarCaptureDialog';\n\n/**\n * Profile-photo picker: an avatar disc with a camera button. Pick from the\n * library (or the camera on touch), frame the face in a circular crop, and it\n * hands back a **cropped, downscaled** `File` (JPEG). For attachments / documents\n * / multiple files use `FileUpload` instead.\n *\n * Client-side only downscales and re-encodes; it does not decode HEIC (no\n * browser but Safari can) - that is a server-side job. HEIC picks are rejected\n * with a message.\n */\n/** User-facing strings - English by default; pass overrides for another locale. */\nexport interface AvatarUploadLabels {\n trigger: string;\n upload: string;\n takePhoto: string;\n remove: string;\n cropTitle: string;\n cropHint: string;\n cameraTitle: string;\n cameraHint: string;\n capture: string;\n /** On the crop step, only shown for a shot taken with the camera; reopens it directly. */\n retake: string;\n cancel: string;\n save: string;\n zoom: string;\n heicError: string;\n notImage: string;\n tooLarge: (mb: number) => string;\n unreadable: string;\n cameraError: string;\n}\n\nconst EN: AvatarUploadLabels = {\n trigger: 'Change photo',\n upload: 'Upload a photo',\n takePhoto: 'Take a photo',\n remove: 'Remove photo',\n cropTitle: 'Adjust the photo',\n cropHint: 'Drag to reposition · scroll to zoom.',\n cameraTitle: 'Take a photo',\n cameraHint: 'Line your face up with the circle.',\n capture: 'Capture',\n retake: 'Retake',\n cancel: 'Cancel',\n save: 'Save',\n zoom: 'Zoom',\n heicError: \"That format (HEIC) won't open in the browser, upload a JPG or PNG.\",\n notImage: 'Choose an image file.',\n tooLarge: (mb) => `The image is over ${mb} MB.`,\n unreadable: \"Couldn't read that image. Try a JPG or PNG.\",\n cameraError: \"Couldn't open the camera: upload a photo from your library instead.\",\n};\n\nexport interface AvatarUploadProps {\n /** Full name - drives the initials fallback and the alt text. */\n name?: string;\n /** Current photo: a `File` (freshly cropped) or an existing URL string. */\n value?: File | string | null;\n onChange?: (file: File | null) => void;\n /** Disc diameter in px. */\n size?: number;\n /** Exported square size in px - the crop is drawn to this. */\n outputSize?: number;\n /** Reject picks larger than this (before crop). */\n maxSizeMB?: number;\n /** Override the English UI strings (menu, crop dialog, messages). */\n labels?: Partial<AvatarUploadLabels>;\n label?: string;\n hint?: string;\n error?: string;\n required?: boolean;\n disabled?: boolean;\n id?: string;\n containerStyle?: React.CSSProperties;\n /** Reserve the hint/error row's height even with neither set - stops the\n * field from growing the moment a validation message appears. */\n preserveHelperSpace?: boolean;\n /**\n * Whether to allow taking a photo via camera (default true).\n * Set to `false` when picking an organization or brand logo, where taking a\n * live selfie/photo makes no sense.\n */\n allowCamera?: boolean;\n}\n\nfunction initials(name: string): string {\n return (name || '')\n .trim()\n .split(/\\s+/)\n .slice(0, 2)\n .map((w) => w[0] || '')\n .join('')\n .toUpperCase();\n}\n\nconst isHeic = (f: File) => /image\\/heic|image\\/heif/i.test(f.type) || /\\.(heic|heif)$/i.test(f.name);\n\nexport const AvatarUpload = React.forwardRef<HTMLInputElement, AvatarUploadProps>(function AvatarUpload(\n {\n name = '',\n value,\n onChange,\n size = 96,\n outputSize = 512,\n maxSizeMB = 8,\n labels: labelsProp,\n label,\n hint,\n error,\n required,\n disabled,\n id,\n containerStyle,\n preserveHelperSpace,\n allowCamera = true,\n },\n forwardedRef,\n) {\n const t = React.useMemo<AvatarUploadLabels>(() => ({ ...EN, ...labelsProp }), [labelsProp]);\n const autoId = React.useId();\n const rid = id || autoId;\n const libRef = React.useRef<HTMLInputElement>(null);\n const triggerRef = React.useRef<HTMLButtonElement>(null);\n const menuRef = React.useRef<HTMLDivElement>(null);\n\n const [menuOpen, setMenuOpen] = React.useState(false);\n const [menuPos, setMenuPos] = React.useState<{ top: number; left: number } | null>(null);\n const [rejected, setRejected] = React.useState<string | null>(null);\n const [cropSrc, setCropSrc] = React.useState<string | null>(null);\n // Whether the photo now in the crop step came from the camera. Only then does the crop\n // modal offer \"Retake\" (a library pick already has its own way to change: cancel and pick\n // another file from the system's own dialog).\n const [cropFromCamera, setCropFromCamera] = React.useState(false);\n const [cameraOpen, setCameraOpen] = React.useState(false);\n const [internal, setInternal] = React.useState<File | null>(null);\n\n const current = value !== undefined ? value : internal;\n\n // Preview URL for the current photo.\n const [preview, setPreview] = React.useState<string | null>(typeof current === 'string' ? current : null);\n React.useEffect(() => {\n if (current instanceof File) {\n const u = URL.createObjectURL(current);\n // eslint-disable-next-line react-hooks/set-state-in-effect -- syncing to an object URL\n setPreview(u);\n return () => URL.revokeObjectURL(u);\n }\n setPreview(typeof current === 'string' ? current : null);\n }, [current]);\n\n const itemCount = (allowCamera ? 1 : 0) + 1 + (current ? 1 : 0);\n\n const toggleMenu = () => {\n if (!allowCamera && !current) {\n libRef.current?.click();\n return;\n }\n if (menuOpen) {\n setMenuOpen(false);\n return;\n }\n const r = triggerRef.current?.getBoundingClientRect();\n if (r) {\n const h = itemCount * 40 + 8;\n const flipUp = r.bottom + 6 + h > window.innerHeight - 8;\n setMenuPos({\n top: flipUp ? Math.max(8, r.top - 6 - h) : r.bottom + 6,\n left: Math.max(8, Math.min(r.left, window.innerWidth - 208)),\n });\n }\n setMenuOpen(true);\n };\n\n // Close the menu on outside click / Escape / scroll - it is portalled to <body>.\n React.useEffect(() => {\n if (!menuOpen) return;\n const onDown = (e: MouseEvent) => {\n const target = e.target as Node;\n if (triggerRef.current?.contains(target) || menuRef.current?.contains(target)) return;\n setMenuOpen(false);\n };\n const close = () => setMenuOpen(false);\n const onKey = (e: KeyboardEvent) => e.key === 'Escape' && close();\n document.addEventListener('mousedown', onDown);\n document.addEventListener('keydown', onKey);\n window.addEventListener('scroll', close, true);\n window.addEventListener('resize', close);\n return () => {\n document.removeEventListener('mousedown', onDown);\n document.removeEventListener('keydown', onKey);\n window.removeEventListener('scroll', close, true);\n window.removeEventListener('resize', close);\n };\n }, [menuOpen]);\n\n // One dialog for the flow, on whichever step is current: the crop once there is a photo,\n // else the live camera. A shot or a Retake flips both at once, so the step just changes.\n // The `Dialog` it is drawn in already locks the page scroll and closes on Escape (through the\n // `onClose` handed to it below), so nothing here does: a second lock of our own used to be\n // released after the Dialog's and left the page unable to scroll (SS-402).\n const step: Step | null = cropSrc ? 'crop' : allowCamera && cameraOpen ? 'camera' : null;\n\n const pick = (files: FileList | null) => {\n const f = files?.[0];\n if (!f) return;\n if (isHeic(f)) {\n setRejected(t.heicError);\n return;\n }\n if (!f.type.startsWith('image/')) {\n setRejected(t.notImage);\n return;\n }\n if (f.size > maxSizeMB * 1048576) {\n setRejected(t.tooLarge(maxSizeMB));\n return;\n }\n const url = URL.createObjectURL(f);\n const probe = new Image();\n probe.onload = () => {\n setRejected(null);\n setCropFromCamera(false);\n setCropSrc(url);\n };\n probe.onerror = () => {\n URL.revokeObjectURL(url);\n setRejected(t.unreadable);\n };\n probe.src = url;\n };\n\n const commit = (file: File | null) => {\n if (value === undefined) setInternal(file);\n onChange?.(file);\n };\n\n const onCropSave = (blob: Blob) => {\n const file = new File([blob], 'avatar.jpg', { type: 'image/jpeg' });\n if (cropSrc) URL.revokeObjectURL(cropSrc);\n setCropSrc(null);\n commit(file);\n };\n const onCropCancel = () => {\n if (cropSrc) URL.revokeObjectURL(cropSrc);\n setCropSrc(null);\n };\n\n const onCameraShot = (blob: Blob) => {\n setCameraOpen(false);\n setRejected(null);\n setCropFromCamera(true);\n setCropSrc(URL.createObjectURL(blob));\n };\n\n // Straight back to the live camera, no menu in between: the crop modal's \"Retake\".\n const onRetake = () => {\n if (cropSrc) URL.revokeObjectURL(cropSrc);\n setCropSrc(null);\n setCameraOpen(true);\n };\n\n const cameraBtn = Math.max(30, Math.round(size * 0.34));\n\n // What `Field` shows as the error: the consumer's, or a rejected pick's (type, size, unreadable).\n const shownError = error || rejected || undefined;\n // The hidden `<input type=\"file\">` is out of the accessibility tree: the pencil is what takes focus.\n const a11y = fieldA11y(rid, { hint, error: shownError });\n\n return (\n <Field label={label} hint={hint} error={shownError} required={required} htmlFor={rid} style={containerStyle} preserveHelperSpace={preserveHelperSpace}>\n <input ref={mergeRefs(libRef, forwardedRef)} id={rid} type=\"file\" accept=\"image/*\" disabled={disabled} onChange={(e) => pick(e.target.files)} style={{ display: 'none' }} />\n\n <div style={sx({ position: 'relative', width: size, height: size, flex: '0 0 auto', opacity: disabled ? 0.6 : 1 })}>\n <span\n style={sx({\n width: size,\n height: size,\n borderRadius: '999px',\n overflow: 'hidden',\n display: 'inline-flex',\n alignItems: 'center',\n justifyContent: 'center',\n background: preview ? 'var(--bg-subtle)' : 'color-mix(in srgb, var(--brand-500) 22%, var(--bg-surface))',\n border: '1px solid ' + (preview ? 'var(--border-subtle)' : 'color-mix(in srgb, var(--brand-500) 30%, transparent)'),\n color: 'var(--text-brand)',\n fontFamily: 'var(--font-display)',\n fontWeight: 'var(--weight-bold)',\n fontSize: Math.round(size * 0.34),\n letterSpacing: 'var(--tracking-snug)',\n })}\n >\n {preview ? (\n // eslint-disable-next-line @next/next/no-img-element\n <img src={preview} alt={name} style={sx({ width: '100%', height: '100%', objectFit: 'cover' })} />\n ) : (\n initials(name) || <ImagePlus size={Math.round(size * 0.3)} strokeWidth={1.75} />\n )}\n </span>\n\n {!disabled && (\n <button\n ref={triggerRef}\n type=\"button\"\n className=\"ds-affix-btn\"\n aria-label={t.trigger}\n aria-haspopup=\"menu\"\n aria-expanded={menuOpen}\n {...a11y}\n onClick={toggleMenu}\n style={sx({\n position: 'absolute',\n right: -2,\n bottom: -2,\n width: cameraBtn,\n height: cameraBtn,\n borderRadius: '999px',\n display: 'inline-flex',\n alignItems: 'center',\n justifyContent: 'center',\n background: 'var(--bg-surface)',\n border: '1px solid var(--border-default)',\n boxShadow: 'var(--shadow-sm)',\n color: 'var(--text-secondary)',\n cursor: 'pointer',\n })}\n >\n <Pencil size={Math.round(cameraBtn * 0.46)} strokeWidth={1.75} />\n </button>\n )}\n\n </div>\n\n {menuOpen &&\n menuPos &&\n createPortal(\n <div\n ref={menuRef}\n role=\"menu\"\n style={sx({\n position: 'fixed',\n top: menuPos.top,\n left: menuPos.left,\n minWidth: 200,\n zIndex: 1000,\n padding: 'var(--space-1)',\n borderRadius: 'var(--radius-md)',\n background: 'var(--bg-surface)',\n border: '1px solid var(--border-default)',\n boxShadow: 'var(--shadow-lg)',\n display: 'flex',\n flexDirection: 'column',\n })}\n >\n <MenuItem\n icon={<ImagePlus size={16} strokeWidth={1.75} />}\n label={t.upload}\n onClick={() => {\n setMenuOpen(false);\n libRef.current?.click();\n }}\n />\n {allowCamera && (\n <MenuItem\n icon={<Camera size={16} strokeWidth={1.75} />}\n label={t.takePhoto}\n onClick={() => {\n setMenuOpen(false);\n setRejected(null);\n setCameraOpen(true);\n }}\n />\n )}\n {current && (\n <MenuItem\n icon={<Trash2 size={16} strokeWidth={1.75} />}\n label={t.remove}\n danger\n onClick={() => {\n setMenuOpen(false);\n commit(null);\n }}\n />\n )}\n </div>,\n document.body,\n )}\n\n {step && (\n <CaptureDialog\n step={step}\n src={cropSrc}\n outputSize={outputSize}\n labels={t}\n onClose={step === 'camera' ? () => setCameraOpen(false) : onCropCancel}\n onCameraShot={onCameraShot}\n onCameraError={() => {\n setCameraOpen(false);\n setRejected(t.cameraError);\n }}\n onSave={onCropSave}\n onRetake={cropFromCamera ? onRetake : undefined}\n />\n )}\n </Field>\n );\n});\n\nAvatarUpload.displayName = 'AvatarUpload';\n\nfunction MenuItem({ icon, label, onClick, danger }: { icon: React.ReactNode; label: string; onClick: () => void; danger?: boolean }) {\n const [hover, setHover] = React.useState(false);\n return (\n <button\n type=\"button\"\n role=\"menuitem\"\n onClick={onClick}\n onMouseEnter={() => setHover(true)}\n onMouseLeave={() => setHover(false)}\n style={sx({\n display: 'flex',\n alignItems: 'center',\n gap: 'var(--space-2)',\n width: '100%',\n minHeight: 40,\n padding: '0 var(--space-3)',\n border: 'none',\n borderRadius: 'var(--radius-sm)',\n background: hover ? 'var(--bg-subtle)' : 'transparent',\n cursor: 'pointer',\n fontFamily: 'var(--font-body)',\n fontSize: 'var(--text-sm)',\n color: danger ? 'var(--interactive-error)' : 'var(--text-primary)',\n textAlign: 'left',\n })}\n >\n {icon}\n {label}\n </button>\n );\n}\n"],"mappings":";AA0RM,cAEA,YAFA;AAxRN,YAAY,WAAW;AACvB,SAAS,oBAAoB;AAC7B,SAAS,QAAQ,WAAW,QAAQ,cAAc;AAClD,SAAS,UAAU;AACnB,SAAS,aAAa;AACtB,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;AAC1B,SAAS,qBAAgC;AAmCzC,MAAM,KAAyB;AAAA,EAC7B,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,QAAQ;AAAA,E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,QAC3B;AAAA,QACA,QAAQ;AAAA,QACR,UAAU,iBAAiB,WAAW;AAAA;AAAA,IACxC;AAAA,KAEJ;AAEJ,CAAC;AAED,aAAa,cAAc;AAE3B,SAAS,SAAS,EAAE,MAAM,OAAO,SAAS,OAAO,GAAoF;AACnI,QAAM,CAAC,OAAO,QAAQ,IAAI,MAAM,SAAS,KAAK;AAC9C,SACE;AAAA,IAAC;AAAA;AAAA,MACC,MAAK;AAAA,MACL,MAAK;AAAA,MACL;AAAA,MACA,cAAc,MAAM,SAAS,IAAI;AAAA,MACjC,cAAc,MAAM,SAAS,KAAK;AAAA,MAClC,OAAO,GAAG;AAAA,QACR,SAAS;AAAA,QACT,YAAY;AAAA,QACZ,KAAK;AAAA,QACL,OAAO;AAAA,QACP,WAAW;AAAA,QACX,SAAS;AAAA,QACT,QAAQ;AAAA,QACR,cAAc;AAAA,QACd,YAAY,QAAQ,qBAAqB;AAAA,QACzC,QAAQ;AAAA,QACR,YAAY;AAAA,QACZ,UAAU;AAAA,QACV,OAAO,SAAS,6BAA6B;AAAA,QAC7C,WAAW;AAAA,MACb,CAAC;AAAA,MAEA;AAAA;AAAA,QACA;AAAA;AAAA;AAAA,EACH;AAEJ;","names":["AvatarUpload"]}
@@ -0,0 +1,28 @@
1
+ import * as React from 'react';
2
+ import { AvatarUploadLabels } from '../AvatarUpload.js';
3
+
4
+ /** Which step of the photo flow the dialog is on. */
5
+ type Step = 'camera' | 'crop';
6
+ /**
7
+ * The one dialog for the whole photo flow: the live camera, then the crop (and back, on
8
+ * Retake). It stays mounted across the steps and only its header text, stage and buttons
9
+ * swap, so the panel does not close and reopen (no second pop-in, no scroll-lock or focus
10
+ * hand-off) and it keeps one size. `Dialog.Header` / `Body` / `Footer` are direct children
11
+ * on purpose: `Dialog` reads them off its children to pad the body and label itself, which
12
+ * a wrapper component per step would hide from it.
13
+ */
14
+ declare function CaptureDialog({ step, src, outputSize, labels, onClose, onCameraShot, onCameraError, onSave, onRetake, }: {
15
+ step: Step;
16
+ /** The photo being cropped; only set on the crop step. */
17
+ src: string | null;
18
+ outputSize: number;
19
+ labels: AvatarUploadLabels;
20
+ onClose: () => void;
21
+ onCameraShot: (b: Blob) => void;
22
+ onCameraError: () => void;
23
+ onSave: (b: Blob) => void;
24
+ /** Only set for a shot taken with the camera; shows the "Retake" button. */
25
+ onRetake?: () => void;
26
+ }): React.JSX.Element;
27
+
28
+ export { CaptureDialog, type Step };
@@ -0,0 +1,127 @@
1
+ "use client";
2
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
+ import * as React from "react";
4
+ import { Camera, Check, RotateCcw, X, ZoomIn, ZoomOut } from "lucide-react";
5
+ import { sx } from "../../_internal/style.js";
6
+ import { Dialog } from "../../feedback/Dialog.js";
7
+ import { Button } from "../../core/Button.js";
8
+ import { useCamera } from "./useCamera.js";
9
+ import { useCropper } from "./useCropper.js";
10
+ const MODAL_WIDTH = 440;
11
+ const ZOOM_ROW_HEIGHT = 24;
12
+ function CropStage({ children, onPointerDown, onPointerMove, onPointerUp, onWheel, stageRef }) {
13
+ return /* @__PURE__ */ jsxs(
14
+ "div",
15
+ {
16
+ ref: stageRef,
17
+ onPointerDown,
18
+ onPointerMove,
19
+ onPointerUp,
20
+ onPointerCancel: onPointerUp,
21
+ onWheel,
22
+ style: sx({
23
+ position: "relative",
24
+ width: "100%",
25
+ aspectRatio: "1",
26
+ overflow: "hidden",
27
+ borderRadius: "var(--radius-lg)",
28
+ background: "var(--bg-sunken)",
29
+ cursor: onPointerDown ? "grab" : "default",
30
+ touchAction: "none"
31
+ }),
32
+ children: [
33
+ children,
34
+ /* @__PURE__ */ jsx(
35
+ "span",
36
+ {
37
+ style: sx({
38
+ position: "absolute",
39
+ inset: 0,
40
+ pointerEvents: "none",
41
+ borderRadius: "999px",
42
+ boxShadow: "0 0 0 9999px color-mix(in srgb, var(--bg-overlay) 80%, transparent)",
43
+ outline: "1px solid rgba(255, 255, 255, 0.9)",
44
+ outlineOffset: -1
45
+ })
46
+ }
47
+ )
48
+ ]
49
+ }
50
+ );
51
+ }
52
+ function CaptureDialog({
53
+ step,
54
+ src,
55
+ outputSize,
56
+ labels,
57
+ onClose,
58
+ onCameraShot,
59
+ onCameraError,
60
+ onSave,
61
+ onRetake
62
+ }) {
63
+ const isCamera = step === "camera";
64
+ const camera = useCamera(isCamera, onCameraError);
65
+ const crop = useCropper(src, outputSize);
66
+ const [contentEl, setContentEl] = React.useState(null);
67
+ React.useEffect(() => {
68
+ contentEl?.closest('[role="dialog"]')?.focus();
69
+ }, [step, contentEl]);
70
+ return /* @__PURE__ */ jsxs(Dialog, { width: MODAL_WIDTH, onClose, children: [
71
+ /* @__PURE__ */ jsx(Dialog.Header, { title: isCamera ? labels.cameraTitle : labels.cropTitle, description: isCamera ? labels.cameraHint : labels.cropHint }),
72
+ /* @__PURE__ */ jsx(Dialog.Body, { children: /* @__PURE__ */ jsxs("div", { ref: setContentEl, children: [
73
+ isCamera ? /* @__PURE__ */ jsx(CropStage, { children: /* @__PURE__ */ jsx("video", { ref: camera.attachVideo, autoPlay: true, playsInline: true, muted: true, style: sx({ width: "100%", height: "100%", objectFit: "cover", transform: "scaleX(-1)" }) }) }, "camera") : /* @__PURE__ */ jsx(
74
+ CropStage,
75
+ {
76
+ stageRef: crop.setStageEl,
77
+ onPointerDown: crop.onPointerDown,
78
+ onPointerMove: crop.onPointerMove,
79
+ onPointerUp: crop.onPointerUp,
80
+ onWheel: (e) => crop.setZoomAt(crop.zoom - e.deltaY * 2e-3),
81
+ children: src && // eslint-disable-next-line @next/next/no-img-element
82
+ /* @__PURE__ */ jsx(
83
+ "img",
84
+ {
85
+ ref: crop.setImgEl,
86
+ src,
87
+ alt: "",
88
+ draggable: false,
89
+ onLoad: (e) => crop.onImgLoad(e.currentTarget),
90
+ style: sx({ position: "absolute", left: crop.offset.x, top: crop.offset.y, width: crop.dispW, height: crop.dispH, maxWidth: "none", userSelect: "none", pointerEvents: "none" })
91
+ }
92
+ )
93
+ },
94
+ "crop"
95
+ ),
96
+ /* @__PURE__ */ jsx("div", { style: sx({ display: "flex", alignItems: "center", gap: "var(--space-3)", marginTop: "var(--space-4)", minHeight: ZOOM_ROW_HEIGHT, color: "var(--text-muted)" }), children: !isCamera && /* @__PURE__ */ jsxs(Fragment, { children: [
97
+ /* @__PURE__ */ jsx(ZoomOut, { size: 16, strokeWidth: 1.75, style: { flex: "0 0 auto" } }),
98
+ /* @__PURE__ */ jsx(
99
+ "input",
100
+ {
101
+ type: "range",
102
+ min: 1,
103
+ max: 3,
104
+ step: 0.01,
105
+ value: crop.zoom,
106
+ onChange: (e) => crop.setZoomAt(Number(e.target.value)),
107
+ "aria-label": labels.zoom,
108
+ style: sx({ flex: 1, accentColor: "var(--interactive-primary)" })
109
+ }
110
+ ),
111
+ /* @__PURE__ */ jsx(ZoomIn, { size: 16, strokeWidth: 1.75, style: { flex: "0 0 auto" } })
112
+ ] }) })
113
+ ] }) }),
114
+ /* @__PURE__ */ jsx(Dialog.Footer, { fill: !isCamera && Boolean(onRetake), children: isCamera ? /* @__PURE__ */ jsxs(React.Fragment, { children: [
115
+ /* @__PURE__ */ jsx(Button, { variant: "secondary", iconLeft: /* @__PURE__ */ jsx(X, { size: 16, strokeWidth: 2 }), onClick: onClose, children: labels.cancel }),
116
+ /* @__PURE__ */ jsx(Button, { iconLeft: /* @__PURE__ */ jsx(Camera, { size: 16, strokeWidth: 2 }), onClick: () => camera.shoot(onCameraShot), disabled: !camera.ready, children: labels.capture })
117
+ ] }, "camera") : /* @__PURE__ */ jsxs(React.Fragment, { children: [
118
+ onRetake && /* @__PURE__ */ jsx(Button, { variant: "secondary", iconLeft: /* @__PURE__ */ jsx(RotateCcw, { size: 16, strokeWidth: 2 }), onClick: onRetake, children: labels.retake }),
119
+ /* @__PURE__ */ jsx(Button, { variant: "secondary", iconLeft: /* @__PURE__ */ jsx(X, { size: 16, strokeWidth: 2 }), onClick: onClose, children: labels.cancel }),
120
+ /* @__PURE__ */ jsx(Button, { iconLeft: /* @__PURE__ */ jsx(Check, { size: 16, strokeWidth: 2.5 }), onClick: () => crop.save(onSave), children: labels.save })
121
+ ] }, "crop") })
122
+ ] });
123
+ }
124
+ export {
125
+ CaptureDialog
126
+ };
127
+ //# sourceMappingURL=AvatarCaptureDialog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/forms/_internal/AvatarCaptureDialog.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { Camera, Check, RotateCcw, X, ZoomIn, ZoomOut } from 'lucide-react';\nimport { sx } from '../../_internal/style';\nimport { Dialog } from '../../feedback/Dialog';\nimport { Button } from '../../core/Button';\nimport type { AvatarUploadLabels } from '../AvatarUpload';\nimport { useCamera } from './useCamera';\nimport { useCropper } from './useCropper';\n\n/**\n * Width of the camera and crop dialogs. They are two steps of one flow (a shot goes straight\n * to the crop), so they share it: a dialog that changed size between the steps would jump.\n * Wider than `Dialog`'s default 352: with Retake the crop footer has three real Buttons, and\n * in Portuguese (\"Tirar outra\", \"Cancelar\", \"Gravar\") they add up to 384px, more than the\n * 358px of content a 400px dialog leaves. 440 gives 398px, so they fit on one line with ~14px\n * to spare. `Dialog` already caps at `min(100%, ...)` for narrow viewports (see\n * feedback/Dialog.tsx), so a phone just gets a narrower dialog. Widening only moves the limit\n * though: the crop footer's `fill` is what keeps a longer language, or that phone, from\n * stranding the primary button.\n */\nconst MODAL_WIDTH = 440;\n\n/** Height reserved for the zoom row, so the camera step (which has none) is as tall as the crop step. */\nconst ZOOM_ROW_HEIGHT = 24;\n\n/**\n * The square viewport + circular guide, shared by the crop and camera modals.\n * `width: 100%` + `aspectRatio: 1`, not a fixed pixel box: it spans exactly the same\n * width as `Dialog.Header`'s title and `Dialog.Footer`'s buttons (both just block-level\n * or flex content inside the same padded `Dialog.Body`), instead of a fixed size\n * centered with margins of its own that didn't match theirs (SS-322 follow-up, the\n * stage read as misaligned from the rest of the dialog). Also needs no separate\n * mobile-width handling of its own: whatever width the dialog ends up at (already\n * responsive, see `feedback/Dialog.tsx`), the stage fills it exactly, staying square\n * via `aspectRatio`.\n */\nfunction CropStage({ children, onPointerDown, onPointerMove, onPointerUp, onWheel, stageRef }: {\n children: React.ReactNode;\n onPointerDown?: (e: React.PointerEvent) => void;\n onPointerMove?: (e: React.PointerEvent) => void;\n onPointerUp?: (e: React.PointerEvent) => void;\n onWheel?: (e: React.WheelEvent) => void;\n /** `useCropper` reads the live rendered size off this to drive the crop math (`V`). */\n stageRef?: React.Ref<HTMLDivElement>;\n}) {\n return (\n <div\n ref={stageRef}\n onPointerDown={onPointerDown}\n onPointerMove={onPointerMove}\n onPointerUp={onPointerUp}\n onPointerCancel={onPointerUp}\n onWheel={onWheel}\n style={sx({\n position: 'relative',\n width: '100%',\n aspectRatio: '1',\n overflow: 'hidden',\n borderRadius: 'var(--radius-lg)',\n background: 'var(--bg-sunken)',\n cursor: onPointerDown ? 'grab' : 'default',\n touchAction: 'none',\n })}\n >\n {children}\n <span\n style={sx({\n position: 'absolute',\n inset: 0,\n pointerEvents: 'none',\n borderRadius: '999px',\n boxShadow: '0 0 0 9999px color-mix(in srgb, var(--bg-overlay) 80%, transparent)',\n outline: '1px solid rgba(255, 255, 255, 0.9)',\n outlineOffset: -1,\n })}\n />\n </div>\n );\n}\n\n/** Which step of the photo flow the dialog is on. */\nexport type Step = 'camera' | 'crop';\n\n/**\n * The one dialog for the whole photo flow: the live camera, then the crop (and back, on\n * Retake). It stays mounted across the steps and only its header text, stage and buttons\n * swap, so the panel does not close and reopen (no second pop-in, no scroll-lock or focus\n * hand-off) and it keeps one size. `Dialog.Header` / `Body` / `Footer` are direct children\n * on purpose: `Dialog` reads them off its children to pad the body and label itself, which\n * a wrapper component per step would hide from it.\n */\nexport function CaptureDialog({\n step,\n src,\n outputSize,\n labels,\n onClose,\n onCameraShot,\n onCameraError,\n onSave,\n onRetake,\n}: {\n step: Step;\n /** The photo being cropped; only set on the crop step. */\n src: string | null;\n outputSize: number;\n labels: AvatarUploadLabels;\n onClose: () => void;\n onCameraShot: (b: Blob) => void;\n onCameraError: () => void;\n onSave: (b: Blob) => void;\n /** Only set for a shot taken with the camera; shows the \"Retake\" button. */\n onRetake?: () => void;\n}) {\n const isCamera = step === 'camera';\n const camera = useCamera(isCamera, onCameraError);\n const crop = useCropper(src, outputSize);\n\n // The step's buttons unmount with it, and with them the focused one: without this, focus\n // would fall to the page behind the dialog and Tab would leave the trap. `Dialog` only\n // pulls focus in when it opens, so do it again on every step change.\n const [contentEl, setContentEl] = React.useState<HTMLDivElement | null>(null);\n React.useEffect(() => {\n contentEl?.closest<HTMLElement>('[role=\"dialog\"]')?.focus();\n }, [step, contentEl]);\n\n /* eslint-disable react-hooks/refs -- `useCamera` / `useCropper` return event handlers that reach a\n ref (`videoRef`, the drag origin), so the lint marks every property read off them; but those\n refs are only touched when a handler runs from an event, never during this render. */\n return (\n <Dialog width={MODAL_WIDTH} onClose={onClose}>\n <Dialog.Header title={isCamera ? labels.cameraTitle : labels.cropTitle} description={isCamera ? labels.cameraHint : labels.cropHint} />\n <Dialog.Body>\n <div ref={setContentEl}>\n {isCamera ? (\n <CropStage key=\"camera\">\n <video ref={camera.attachVideo} autoPlay playsInline muted style={sx({ width: '100%', height: '100%', objectFit: 'cover', transform: 'scaleX(-1)' })} />\n </CropStage>\n ) : (\n <CropStage\n key=\"crop\"\n stageRef={crop.setStageEl}\n onPointerDown={crop.onPointerDown}\n onPointerMove={crop.onPointerMove}\n onPointerUp={crop.onPointerUp}\n onWheel={(e) => crop.setZoomAt(crop.zoom - e.deltaY * 0.002)}\n >\n {src && (\n // eslint-disable-next-line @next/next/no-img-element\n <img\n ref={crop.setImgEl}\n src={src}\n alt=\"\"\n draggable={false}\n onLoad={(e) => crop.onImgLoad(e.currentTarget)}\n style={sx({ position: 'absolute', left: crop.offset.x, top: crop.offset.y, width: crop.dispW, height: crop.dispH, maxWidth: 'none', userSelect: 'none', pointerEvents: 'none' })}\n />\n )}\n </CropStage>\n )}\n\n {/* The zoom row is only there on the crop step, but the camera step keeps its room, so the dialog is the same height on both. */}\n <div style={sx({ display: 'flex', alignItems: 'center', gap: 'var(--space-3)', marginTop: 'var(--space-4)', minHeight: ZOOM_ROW_HEIGHT, color: 'var(--text-muted)' })}>\n {!isCamera && (\n <>\n <ZoomOut size={16} strokeWidth={1.75} style={{ flex: '0 0 auto' }} />\n <input\n type=\"range\"\n min={1}\n max={3}\n step={0.01}\n value={crop.zoom}\n onChange={(e) => crop.setZoomAt(Number(e.target.value))}\n aria-label={labels.zoom}\n style={sx({ flex: 1, accentColor: 'var(--interactive-primary)' })}\n />\n <ZoomIn size={16} strokeWidth={1.75} style={{ flex: '0 0 auto' }} />\n </>\n )}\n </div>\n </div>\n </Dialog.Body>\n {/* Three actions (crop after a camera shot, with Retake) share the row and each line they wrap onto; two stay right-aligned, as before. */}\n <Dialog.Footer fill={!isCamera && Boolean(onRetake)}>\n {isCamera ? (\n <React.Fragment key=\"camera\">\n <Button variant=\"secondary\" iconLeft={<X size={16} strokeWidth={2} />} onClick={onClose}>\n {labels.cancel}\n </Button>\n <Button iconLeft={<Camera size={16} strokeWidth={2} />} onClick={() => camera.shoot(onCameraShot)} disabled={!camera.ready}>\n {labels.capture}\n </Button>\n </React.Fragment>\n ) : (\n <React.Fragment key=\"crop\">\n {onRetake && (\n <Button variant=\"secondary\" iconLeft={<RotateCcw size={16} strokeWidth={2} />} onClick={onRetake}>\n {labels.retake}\n </Button>\n )}\n <Button variant=\"secondary\" iconLeft={<X size={16} strokeWidth={2} />} onClick={onClose}>\n {labels.cancel}\n </Button>\n <Button iconLeft={<Check size={16} strokeWidth={2.5} />} onClick={() => crop.save(onSave)}>\n {labels.save}\n </Button>\n </React.Fragment>\n )}\n </Dialog.Footer>\n </Dialog>\n );\n /* eslint-enable react-hooks/refs */\n}\n"],"mappings":";AAgDI,SAsHU,UAnGR,KAnBF;AA9CJ,YAAY,WAAW;AACvB,SAAS,QAAQ,OAAO,WAAW,GAAG,QAAQ,eAAe;AAC7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