@bettercms-ai/kit 4.2.0-next.0 → 4.2.0

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.
Files changed (39) hide show
  1. package/dist/adapters/lossy.d.ts +1 -1
  2. package/dist/adapters/lossy.js +1 -1
  3. package/dist/adapters/lossy.js.map +1 -1
  4. package/dist/adapters/schema.js +1 -1
  5. package/dist/adapters/schema.js.map +1 -1
  6. package/dist/controls/index.js +2 -2
  7. package/dist/controls/media-v16.d.ts +3 -1
  8. package/dist/controls/media-v16.js +3 -1
  9. package/dist/controls/media-v16.js.map +1 -1
  10. package/dist/controls/media.d.ts +5 -1
  11. package/dist/controls/media.js +25 -7
  12. package/dist/controls/media.js.map +1 -1
  13. package/dist/controls/rich-text/codec.d.ts +6 -0
  14. package/dist/controls/rich-text/codec.js.map +1 -1
  15. package/dist/controls/rich-text/control.js +2 -1
  16. package/dist/controls/rich-text/control.js.map +1 -1
  17. package/dist/controls/rich-text/editor.d.ts +3 -1
  18. package/dist/controls/rich-text/editor.js +128 -38
  19. package/dist/controls/rich-text/editor.js.map +1 -1
  20. package/dist/controls/rich-text/table-grid.js +2 -0
  21. package/dist/controls/rich-text/table-grid.js.map +1 -1
  22. package/dist/controls/rich-text/toolbar.d.ts +6 -2
  23. package/dist/controls/rich-text/toolbar.js +204 -4
  24. package/dist/controls/rich-text/toolbar.js.map +1 -1
  25. package/dist/controls/text.d.ts +1 -1
  26. package/dist/controls/text.js +9 -6
  27. package/dist/controls/text.js.map +1 -1
  28. package/dist/engine/frame.js +6 -0
  29. package/dist/engine/frame.js.map +1 -1
  30. package/dist/index.js +2 -2
  31. package/dist/styles.css +1 -1
  32. package/dist/theme.css +1 -0
  33. package/dist/tokens.css +3 -0
  34. package/dist/ui/inspector.d.ts +1 -1
  35. package/dist/ui/inspector.js +3 -3
  36. package/dist/ui/inspector.js.map +1 -1
  37. package/dist/ui/overlay.js +2 -2
  38. package/dist/ui/overlay.js.map +1 -1
  39. package/package.json +1 -1
@@ -18,7 +18,7 @@ import { FormPickerControl, isFormOnly } from "./form-picker.js";
18
18
  import { IconControl, IconPicker, IconValueGlyph } from "./icon.js";
19
19
  import { LocationControl, locationFromDraft } from "./location.js";
20
20
  import { V16ImageField, V16_IMAGE_ACCEPT } from "./media-v16.js";
21
- import { FileControl, GalleryControl, ImageControl, ImageDetails, MediaPicker, NO_CROP_OUTSIDE_LIBRARY, VideoControl, VideoPreview, acceptsFile, cropChoice, fileNameFromUrl, formatBytes, fromAsset, isVideoUrl, normImage, useUpload, videoProvider, withCrop, youTubeId } from "./media.js";
21
+ import { FileControl, GalleryControl, ImageControl, ImageDetails, MediaPicker, NO_CROP_OUTSIDE_LIBRARY, NO_CROP_SIZELESS, VideoControl, VideoPreview, acceptsFile, cropChoice, fileNameFromUrl, formatBytes, fromAsset, isVideoUrl, normImage, useUpload, videoProvider, withCrop, youTubeId } from "./media.js";
22
22
  import { ComponentSlotControl, SlotDepthContext, SlotPicker } from "./slot.js";
23
23
  import { RT_PROSE, RichTextEditor } from "./rich-text/editor.js";
24
24
  import { RichTextControl, RichTextExpandAction } from "./rich-text/control.js";
@@ -35,6 +35,6 @@ function registerKitControls() {
35
35
  CONTROLS.button = ButtonControl;
36
36
  }
37
37
  //#endregion
38
- export { BUTTON_ICONS, BooleanControl, ButtonControl, ButtonIconPicker, ButtonLinkEditor, ButtonPreview, ButtonScreen, ButtonStyleGrid, C1_ACTIONS, C1_CONTROLS, C2_CONTROLS, CodeControl, CodeDialogField, CodeSurface, ColorControl, ComponentSlotControl, DateControl, EmailControl, FileControl, FormPickerControl, GalleryControl, HEX_COLOR, IconControl, IconPicker, IconValueGlyph, ImageControl, ImageDetails, JsonControl, LINK_TYPES, LinkControl, LinkField, LinkForm, LinkLine, LinkOptions, LinkPicker, LinkPopoverBody, LinkQuickEdit, LocationControl, MediaPicker, MiniCalendar, MultiSelectControl, NO_CROP_OUTSIDE_LIBRARY, NUMBER_SCALE, NumberControl, PlainNumber, PrefixedInput, REL_ITEMS, RT_PROSE, RatingControl, RefThumb, ReferenceControl, ReferencesControl, RichTextControl, RichTextEditor, RichTextExpandAction, STYLE_ITEMS, ScaleControl, ScaleSlider, SectionAnchorsProvider, SelectControl, SlotDepthContext, SlotPicker, SlugControl, SlugGenerate, StringControl, StyleGlyph, TARGET_KEYS, TEXT_FOCUS, TableControl, TableFrame, TableFullScreenAction, TagsControl, TextControl, UnknownValueNote, UnreadableValue, UrlControl, V16ImageField, V16_IMAGE_ACCEPT, V16_TEXT_SURFACE, VideoControl, VideoPreview, acceptsFile, cropChoice, describeLink, detectType, fileNameFromUrl, fileTarget, finalizeLink, findTarget, formatBytes, fromAsset, hasLink, hrefOf, isFormOnly, isVideoUrl, jsonProblem, linkIcon, linkProblem, linkShapeOf, linkText, locationFromDraft, lookLabel, lookOf, nextButton, normImage, normLink, optionIcons, pickerHex, ratingScale, referenceNoun, registerC1Controls, registerC2Controls, registerKitControls, slugSource, slugTidy, slugTyping, snapRating, storedLink, str, tagRefusal, toNum, ungroupNumber, useLinkTargets, useOwnDescription, useReferenceRecords, useUpload, videoProvider, withCrop, withTarget, withText, youTubeId };
38
+ export { BUTTON_ICONS, BooleanControl, ButtonControl, ButtonIconPicker, ButtonLinkEditor, ButtonPreview, ButtonScreen, ButtonStyleGrid, C1_ACTIONS, C1_CONTROLS, C2_CONTROLS, CodeControl, CodeDialogField, CodeSurface, ColorControl, ComponentSlotControl, DateControl, EmailControl, FileControl, FormPickerControl, GalleryControl, HEX_COLOR, IconControl, IconPicker, IconValueGlyph, ImageControl, ImageDetails, JsonControl, LINK_TYPES, LinkControl, LinkField, LinkForm, LinkLine, LinkOptions, LinkPicker, LinkPopoverBody, LinkQuickEdit, LocationControl, MediaPicker, MiniCalendar, MultiSelectControl, NO_CROP_OUTSIDE_LIBRARY, NO_CROP_SIZELESS, NUMBER_SCALE, NumberControl, PlainNumber, PrefixedInput, REL_ITEMS, RT_PROSE, RatingControl, RefThumb, ReferenceControl, ReferencesControl, RichTextControl, RichTextEditor, RichTextExpandAction, STYLE_ITEMS, ScaleControl, ScaleSlider, SectionAnchorsProvider, SelectControl, SlotDepthContext, SlotPicker, SlugControl, SlugGenerate, StringControl, StyleGlyph, TARGET_KEYS, TEXT_FOCUS, TableControl, TableFrame, TableFullScreenAction, TagsControl, TextControl, UnknownValueNote, UnreadableValue, UrlControl, V16ImageField, V16_IMAGE_ACCEPT, V16_TEXT_SURFACE, VideoControl, VideoPreview, acceptsFile, cropChoice, describeLink, detectType, fileNameFromUrl, fileTarget, finalizeLink, findTarget, formatBytes, fromAsset, hasLink, hrefOf, isFormOnly, isVideoUrl, jsonProblem, linkIcon, linkProblem, linkShapeOf, linkText, locationFromDraft, lookLabel, lookOf, nextButton, normImage, normLink, optionIcons, pickerHex, ratingScale, referenceNoun, registerC1Controls, registerC2Controls, registerKitControls, slugSource, slugTidy, slugTyping, snapRating, storedLink, str, tagRefusal, toNum, ungroupNumber, useLinkTargets, useOwnDescription, useReferenceRecords, useUpload, videoProvider, withCrop, withTarget, withText, youTubeId };
39
39
 
40
40
  //# sourceMappingURL=index.js.map
@@ -23,5 +23,7 @@ export interface V16ImageFieldProps {
23
23
  onRemove: () => void;
24
24
  /** the media library, where the host has one (offered beside the upload when there is no upload service) */
25
25
  onLibrary?: () => void;
26
+ /** the preview's own size as it loads (`loaded`: its load event fired), so the crop can be cut or say why not */
27
+ onNatural?: (img: HTMLImageElement | null, loaded: boolean) => void;
26
28
  }
27
- export declare function V16ImageField({ id, label, readOnly, image, upload, alt, onAlt, onCrop, onRemove, onLibrary }: V16ImageFieldProps): import("react/jsx-runtime").JSX.Element;
29
+ export declare function V16ImageField({ id, label, readOnly, image, upload, alt, onAlt, onCrop, onRemove, onLibrary, onNatural }: V16ImageFieldProps): import("react/jsx-runtime").JSX.Element;
@@ -21,7 +21,7 @@ var V16_IMAGE_ACCEPT = "image/png,image/jpeg,image/webp";
21
21
  var OK_TYPE = /^image\/(png|jpe?g|webp)$/;
22
22
  var MAX_BYTES = 10485760;
23
23
  var BTN = "grid size-7 shrink-0 place-items-center rounded-[6px] text-kit-insp-label outline-none transition-colors hover:bg-kit-insp-card hover:text-kit-insp-tip-title data-[popup-open]:bg-kit-insp-card data-[popup-open]:text-kit-insp-tip-title focus-visible:shadow-[0_0_0_2px_var(--kit-insp-accent)] [&_svg]:size-3.5";
24
- function V16ImageField({ id, label, readOnly, image, upload, alt, onAlt, onCrop, onRemove, onLibrary }) {
24
+ function V16ImageField({ id, label, readOnly, image, upload, alt, onAlt, onCrop, onRemove, onLibrary, onNatural }) {
25
25
  const { toast } = useKitServices();
26
26
  const file = React.useRef(null);
27
27
  const [over, setOver] = React.useState(false);
@@ -73,6 +73,8 @@ function V16ImageField({ id, label, readOnly, image, upload, alt, onAlt, onCrop,
73
73
  children: /* @__PURE__ */ jsx("img", {
74
74
  src: image.src,
75
75
  alt: alt ?? "",
76
+ ref: (n) => onNatural?.(n, false),
77
+ onLoad: (e) => onNatural?.(e.currentTarget, true),
76
78
  className: "size-full object-cover"
77
79
  })
78
80
  }), /* @__PURE__ */ jsxs("div", {
@@ -1 +1 @@
1
- {"version":3,"file":"media-v16.js","names":[],"sources":["../../src/controls/media-v16.tsx"],"sourcesContent":["/**\n * Look \"v16\": the image control as prototype editor-v16 `MediaField` (inspector.jsx:1080-1136, media.css; REQ-5-6\n * group C, F1369-F1385). The image control (media.tsx ImageControl) draws this inside `KitLookProvider look=\"v16\"`:\n * no image → a 164 high dashed zone (\"Drag and drop to upload or select\", \"PNG, JPG or WEBP · up to 10 MB\"),\n * drag-over \"Drop to upload\", a type / size refusal for 2.6s, the upload's progress round the zone with\n * a % pill, then \"Uploaded successfully!\" for 0.8s;\n * an image → a card (168 thumb, name, \"W × H · size\", Replace, ⋯ Replace image / Crop and focal point / Copy image\n * URL / Remove from section);\n * then the \"Alternative text\" field (where the placement stores alt text).\n * Every action is the real one: the upload goes through `KitServices.uploadMedia`, the crop through the control's own\n * details popover. A service the host does not provide is not offered, in words.\n */\nimport * as React from \"react\";\nimport { IconDots, IconLink, IconScan, IconTrash, IconUpload } from \"@tabler/icons-react\";\nimport { cn } from \"../lib/cn\";\nimport { useKitServices } from \"../context\";\nimport { Menu, MenuContent, MenuItem, MenuSeparator, MenuTrigger, Tooltip } from \"../ui/overlay\";\n\nexport const V16_IMAGE_ACCEPT = \"image/png,image/jpeg,image/webp\";\nconst OK_TYPE = /^image\\/(png|jpe?g|webp)$/;\nconst MAX_BYTES = 10 * 1024 * 1024;\n\nexport interface V16ImageFieldProps {\n id: string;\n label: string;\n readOnly?: boolean;\n /** the image, or none */\n image: { src: string; url: string; name: string; meta?: string } | null;\n /** media.tsx useUpload: `run` absent = no upload service */\n upload: { run?: (files: File[]) => void; progress: number | null; error: string | null };\n /** the stored alt text; undefined = this placement keeps no alt text (no field is drawn) */\n alt?: string;\n onAlt?: (alt: string) => void;\n onCrop?: () => void;\n onRemove: () => void;\n /** the media library, where the host has one (offered beside the upload when there is no upload service) */\n onLibrary?: () => void;\n}\n\nconst BTN =\n \"grid size-7 shrink-0 place-items-center rounded-[6px] text-kit-insp-label outline-none transition-colors hover:bg-kit-insp-card hover:text-kit-insp-tip-title data-[popup-open]:bg-kit-insp-card data-[popup-open]:text-kit-insp-tip-title focus-visible:shadow-[0_0_0_2px_var(--kit-insp-accent)] [&_svg]:size-3.5\";\n\nexport function V16ImageField({ id, label, readOnly, image, upload, alt, onAlt, onCrop, onRemove, onLibrary }: V16ImageFieldProps) {\n const { toast } = useKitServices();\n const file = React.useRef<HTMLInputElement>(null);\n const [over, setOver] = React.useState(false);\n const [refusal, setRefusal] = React.useState<string | null>(null);\n const [done, setDone] = React.useState(false);\n const busy = upload.progress != null;\n const wasBusy = React.useRef(false);\n React.useEffect(() => {\n // F1377: the finished upload says so for 800ms before the card replaces the zone\n if (wasBusy.current && !busy && !upload.error) {\n setDone(true);\n const t = window.setTimeout(() => setDone(false), 800);\n wasBusy.current = busy;\n return () => window.clearTimeout(t);\n }\n wasBusy.current = busy;\n }, [busy, upload.error]);\n React.useEffect(() => {\n if (!refusal) return;\n const t = window.setTimeout(() => setRefusal(null), 2600);\n return () => window.clearTimeout(t);\n }, [refusal]);\n\n const take = (f: File | undefined) => {\n if (!f || !upload.run || busy) return;\n if (!OK_TYPE.test(f.type)) return setRefusal(\"Only PNG, JPG or WEBP files are supported\");\n if (f.size > MAX_BYTES) return setRefusal(\"That image is over 10 MB\");\n setRefusal(null);\n upload.run([f]);\n };\n const pick = () => (upload.run ? file.current?.click() : onLibrary?.());\n const input = (\n <input\n ref={file}\n type=\"file\"\n hidden\n accept={V16_IMAGE_ACCEPT}\n onChange={(e) => {\n take(e.target.files?.[0]);\n e.target.value = \"\";\n }}\n />\n );\n\n const showCard = image && !done && !busy;\n const pct = upload.progress ?? 0;\n return (\n <div className=\"flex flex-col gap-4\">\n {showCard ? (\n <div className=\"flex flex-col gap-2 rounded-[10px] border border-kit-insp-line bg-kit-insp-tip-bg p-2\">\n <div className=\"h-[168px] w-full overflow-hidden rounded-[6px] bg-kit-insp-card\">\n <img src={image.src} alt={alt ?? \"\"} className=\"size-full object-cover\" />\n </div>\n <div className=\"flex items-center gap-1\">\n <div className=\"flex min-w-0 flex-1 flex-col gap-0.5\">\n <span className=\"truncate text-[13px] font-medium leading-4 text-kit-insp-tip-title\">{image.name || \"image\"}</span>\n {image.meta ? <span className=\"truncate text-[12px] leading-[15px] text-kit-fg-3 tabular-nums\">{image.meta}</span> : null}\n </div>\n {readOnly ? null : (\n <>\n {upload.run || onLibrary ? (\n <Tooltip content=\"Replace image\">\n <button type=\"button\" aria-label=\"Replace image\" className={BTN} onClick={pick}>\n <IconUpload stroke={1.2} aria-hidden />\n </button>\n </Tooltip>\n ) : null}\n <Menu>\n <MenuTrigger aria-label=\"Image actions\" className={BTN}>\n <IconDots stroke={1.5} aria-hidden />\n </MenuTrigger>\n <MenuContent align=\"end\" className=\"w-[240px] min-w-[240px]\">\n {upload.run || onLibrary ? (\n <MenuItem icon={<IconUpload stroke={1.5} />} onClick={pick}>\n Replace image\n </MenuItem>\n ) : null}\n {onCrop ? (\n <MenuItem icon={<IconScan stroke={1.5} />} onClick={onCrop}>\n Crop and focal point\n </MenuItem>\n ) : null}\n <MenuItem\n icon={<IconLink stroke={1.5} />}\n onClick={() => {\n const w = navigator.clipboard?.writeText(image.url);\n if (!w) return toast?.(\"Copy is not available in this browser\");\n w.then(() => toast?.(\"Image URL copied\"), () => toast?.(\"The browser refused to copy the address\"));\n }}\n >\n Copy image URL\n </MenuItem>\n <MenuSeparator />\n <MenuItem danger icon={<IconTrash stroke={1.5} />} onClick={onRemove}>\n Remove from section\n </MenuItem>\n </MenuContent>\n </Menu>\n </>\n )}\n </div>\n </div>\n ) : (\n <div\n id={id}\n role=\"button\"\n tabIndex={readOnly ? -1 : 0}\n aria-busy={busy || undefined}\n aria-disabled={readOnly || (!upload.run && !onLibrary) || undefined}\n aria-label={`${label}: drag and drop to upload or select`}\n onKeyDown={(e) => {\n if (e.target !== e.currentTarget || busy || readOnly) return;\n if (e.key === \"Enter\" || e.key === \" \") {\n e.preventDefault();\n pick();\n }\n }}\n onDragOver={(e) => {\n if (readOnly || busy || !upload.run || !e.dataTransfer.types.includes(\"Files\")) return;\n e.preventDefault();\n setOver(true);\n }}\n onDragLeave={() => setOver(false)}\n onDrop={(e) => {\n if (readOnly || !upload.run) return;\n e.preventDefault();\n setOver(false);\n take(e.dataTransfer.files[0]);\n }}\n className={cn(\n \"relative flex h-[164px] w-full flex-col items-center justify-center rounded-[16px] border-2 border-dashed border-kit-insp-line-strong bg-kit-insp-card text-center outline-none transition-[background-color,border-color] duration-150 ease-out focus-visible:border-kit-insp-accent\",\n over && \"border-kit-insp-accent bg-kit-insp-zone-over\",\n refusal && \"border-kit-insp-error\",\n busy && \"border-transparent bg-kit-insp-tip-bg\",\n )}\n >\n {busy ? (\n <>\n <svg aria-hidden className=\"pointer-events-none absolute -inset-0.5 h-[calc(100%+4px)] w-[calc(100%+4px)] overflow-visible\">\n <rect x=\"1\" y=\"1\" rx=\"16\" style={{ width: \"calc(100% - 2px)\", height: \"calc(100% - 2px)\" }} fill=\"none\" stroke=\"var(--kit-insp-line)\" strokeWidth=\"1.5\" />\n <rect x=\"1\" y=\"1\" rx=\"16\" style={{ width: \"calc(100% - 2px)\", height: \"calc(100% - 2px)\" }} fill=\"none\" stroke=\"var(--kit-insp-accent)\" strokeWidth=\"1.5\" pathLength={100} strokeDasharray={`${pct} 100`} className=\"transition-[stroke-dasharray] duration-[60ms] ease-linear\" />\n </svg>\n <span className=\"absolute -top-[11px] left-1/2 h-[18px] min-w-[38px] -translate-x-1/2 rounded-full bg-kit-insp-accent px-1.5 text-[11px] font-semibold leading-[18px] text-white tabular-nums\">{pct}%</span>\n </>\n ) : null}\n <span className={cn(\"mb-3.5 grid size-10 place-items-center rounded-full bg-kit-insp-zone-over text-kit-insp-accent-fg\", busy && \"border border-kit-insp-line bg-kit-insp-tip-bg\")}>\n <IconUpload className=\"size-5\" stroke={1.5} aria-hidden />\n </span>\n <span className={cn(\"text-[13px] font-medium leading-4 text-kit-insp-tip-body\", refusal && \"text-kit-insp-count-over\")}>\n {refusal ?? (over ? \"Drop to upload\" : busy ? \"Uploading…\" : (\n <>\n Drag and drop to upload or{\" \"}\n <button\n type=\"button\"\n tabIndex={-1}\n disabled={readOnly || (!upload.run && !onLibrary)}\n onClick={(e) => {\n e.stopPropagation();\n pick();\n }}\n className=\"font-medium text-kit-insp-zone-link hover:underline disabled:no-underline\"\n >\n select\n </button>\n </>\n ))}\n </span>\n <span className={cn(\"mt-1.5 text-[12px] leading-[15px] text-kit-fg-3\", done && \"text-kit-insp-zone-done\")}>\n {done ? \"Uploaded successfully!\" : upload.run ? \"PNG, JPG or WEBP · up to 10 MB\" : onLibrary ? \"Pick one from the media library\" : \"Uploading is not available here\"}\n </span>\n </div>\n )}\n {upload.error ? (\n <p role=\"alert\" className=\"-mt-2 text-[12px] leading-4 text-kit-insp-error\">\n {upload.error}\n </p>\n ) : null}\n {input}\n {alt !== undefined && onAlt ? (\n <div className=\"flex flex-col gap-2\">\n <label htmlFor={`${id}-alt`} className=\"text-[13px] font-medium leading-4 text-kit-insp-tip-body\">\n Alternative text\n </label>\n <input\n id={`${id}-alt`}\n value={alt}\n readOnly={readOnly}\n placeholder=\"Describe the image for screen readers\"\n onChange={(e) => onAlt(e.target.value)}\n className=\"h-[34px] w-full rounded-[6px] border border-transparent bg-kit-insp-card px-2.5 text-[13px] leading-[18px] tracking-[-0.1625px] text-kit-insp-tip-title outline-none transition-[background-color,border-color] duration-[120ms] ease-out placeholder:text-kit-fg-3 focus:border-kit-insp-accent focus:bg-kit-insp-card-focus\"\n />\n </div>\n ) : null}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAkBA,IAAa,mBAAmB;AAChC,IAAM,UAAU;AAChB,IAAM,YAAY;AAmBlB,IAAM,MACJ;AAEF,SAAgB,cAAc,EAAE,IAAI,OAAO,UAAU,OAAO,QAAQ,KAAK,OAAO,QAAQ,UAAU,aAAiC;CACjI,MAAM,EAAE,UAAU,eAAe;CACjC,MAAM,OAAO,MAAM,OAAyB,IAAI;CAChD,MAAM,CAAC,MAAM,WAAW,MAAM,SAAS,KAAK;CAC5C,MAAM,CAAC,SAAS,cAAc,MAAM,SAAwB,IAAI;CAChE,MAAM,CAAC,MAAM,WAAW,MAAM,SAAS,KAAK;CAC5C,MAAM,OAAO,OAAO,YAAY;CAChC,MAAM,UAAU,MAAM,OAAO,KAAK;CAClC,MAAM,gBAAgB;EAEpB,IAAI,QAAQ,WAAW,CAAC,QAAQ,CAAC,OAAO,OAAO;GAC7C,QAAQ,IAAI;GACZ,MAAM,IAAI,OAAO,iBAAiB,QAAQ,KAAK,GAAG,GAAG;GACrD,QAAQ,UAAU;GAClB,aAAa,OAAO,aAAa,CAAC;EACpC;EACA,QAAQ,UAAU;CACpB,GAAG,CAAC,MAAM,OAAO,KAAK,CAAC;CACvB,MAAM,gBAAgB;EACpB,IAAI,CAA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UAAA,oBAAC,YAAD;OAAY,WAAU;OAAS,QAAQ;OAAK,eAAA;MAAa,CAAA;KACrD,CAAA;KACN,oBAAC,QAAD;MAAM,WAAW,GAAG,4DAA4D,WAAW,0BAA0B;MAClH,UAAA,YAAY,OAAO,mBAAmB,OAAO,eAC5C,qBAAA,UAAA,EAAA,UAAA;OAAE;OAC2B;OAC3B,oBAAC,UAAD;QACE,MAAK;QACL,UAAU;QACV,UAAU,YAAa,CAAC,OAAO,OAAO,CAAC;QACvC,UAAU,MAAM;SACd,EAAE,gBAAgB;SAClB,KAAK;QACP;QACA,WAAU;QACX,UAAA;OAEO,CAAA;MACR,EAAA,CAAA;KAEA,CAAA;KACN,oBAAC,QAAD;MAAM,WAAW,GAAG,mDAAmD,QAAQ,yBAAyB;MACrG,UAAA,OAAO,2BAA2B,OAAO,MAAM,mCAAmC,YAAY,oCAAoC;KAC/H,CAAA;IACH;;GAEN,OAAO,QACN,oBAAC,KAAD;IAAG,MAAK;IAAQ,WAAU;IACvB,UAAA,OAAO;GACP,CAAA,IACD;GACH;GACA,QAAQ,KAAA,KAAa,QACpB,qBAAC,OAAD;IAAK,WAAU;IAAf,UAAA,CACE,oBAAC,SAAD;KAAO,SAAS,GAAG,GAAG;KAAO,WAAU;KAA2D,UAAA;IAE3F,CAAA,GACP,oBAAC,SAAD;KACE,IAAI,GAAG,GAAG;KACV,OAAO;KACG;KACV,aAAY;KACZ,WAAW,MAAM,MAAM,EAAE,OAAO,KAAK;KACrC,WAAU;IACX,CAAA,CACE;GACH,CAAA,IAAA;EACD;;AAET"}
1
+ {"version":3,"file":"media-v16.js","names":[],"sources":["../../src/controls/media-v16.tsx"],"sourcesContent":["/**\n * Look \"v16\": the image control as prototype editor-v16 `MediaField` (inspector.jsx:1080-1136, media.css; REQ-5-6\n * group C, F1369-F1385). The image control (media.tsx ImageControl) draws this inside `KitLookProvider look=\"v16\"`:\n * no image → a 164 high dashed zone (\"Drag and drop to upload or select\", \"PNG, JPG or WEBP · up to 10 MB\"),\n * drag-over \"Drop to upload\", a type / size refusal for 2.6s, the upload's progress round the zone with\n * a % pill, then \"Uploaded successfully!\" for 0.8s;\n * an image → a card (168 thumb, name, \"W × H · size\", Replace, ⋯ Replace image / Crop and focal point / Copy image\n * URL / Remove from section);\n * then the \"Alternative text\" field (where the placement stores alt text).\n * Every action is the real one: the upload goes through `KitServices.uploadMedia`, the crop through the control's own\n * details popover. A service the host does not provide is not offered, in words.\n */\nimport * as React from \"react\";\nimport { IconDots, IconLink, IconScan, IconTrash, IconUpload } from \"@tabler/icons-react\";\nimport { cn } from \"../lib/cn\";\nimport { useKitServices } from \"../context\";\nimport { Menu, MenuContent, MenuItem, MenuSeparator, MenuTrigger, Tooltip } from \"../ui/overlay\";\n\nexport const V16_IMAGE_ACCEPT = \"image/png,image/jpeg,image/webp\";\nconst OK_TYPE = /^image\\/(png|jpe?g|webp)$/;\nconst MAX_BYTES = 10 * 1024 * 1024;\n\nexport interface V16ImageFieldProps {\n id: string;\n label: string;\n readOnly?: boolean;\n /** the image, or none */\n image: { src: string; url: string; name: string; meta?: string } | null;\n /** media.tsx useUpload: `run` absent = no upload service */\n upload: { run?: (files: File[]) => void; progress: number | null; error: string | null };\n /** the stored alt text; undefined = this placement keeps no alt text (no field is drawn) */\n alt?: string;\n onAlt?: (alt: string) => void;\n onCrop?: () => void;\n onRemove: () => void;\n /** the media library, where the host has one (offered beside the upload when there is no upload service) */\n onLibrary?: () => void;\n /** the preview's own size as it loads (`loaded`: its load event fired), so the crop can be cut or say why not */\n onNatural?: (img: HTMLImageElement | null, loaded: boolean) => void;\n}\n\nconst BTN =\n \"grid size-7 shrink-0 place-items-center rounded-[6px] text-kit-insp-label outline-none transition-colors hover:bg-kit-insp-card hover:text-kit-insp-tip-title data-[popup-open]:bg-kit-insp-card data-[popup-open]:text-kit-insp-tip-title focus-visible:shadow-[0_0_0_2px_var(--kit-insp-accent)] [&_svg]:size-3.5\";\n\nexport function V16ImageField({ id, label, readOnly, image, upload, alt, onAlt, onCrop, onRemove, onLibrary, onNatural }: V16ImageFieldProps) {\n const { toast } = useKitServices();\n const file = React.useRef<HTMLInputElement>(null);\n const [over, setOver] = React.useState(false);\n const [refusal, setRefusal] = React.useState<string | null>(null);\n const [done, setDone] = React.useState(false);\n const busy = upload.progress != null;\n const wasBusy = React.useRef(false);\n React.useEffect(() => {\n // F1377: the finished upload says so for 800ms before the card replaces the zone\n if (wasBusy.current && !busy && !upload.error) {\n setDone(true);\n const t = window.setTimeout(() => setDone(false), 800);\n wasBusy.current = busy;\n return () => window.clearTimeout(t);\n }\n wasBusy.current = busy;\n }, [busy, upload.error]);\n React.useEffect(() => {\n if (!refusal) return;\n const t = window.setTimeout(() => setRefusal(null), 2600);\n return () => window.clearTimeout(t);\n }, [refusal]);\n\n const take = (f: File | undefined) => {\n if (!f || !upload.run || busy) return;\n if (!OK_TYPE.test(f.type)) return setRefusal(\"Only PNG, JPG or WEBP files are supported\");\n if (f.size > MAX_BYTES) return setRefusal(\"That image is over 10 MB\");\n setRefusal(null);\n upload.run([f]);\n };\n const pick = () => (upload.run ? file.current?.click() : onLibrary?.());\n const input = (\n <input\n ref={file}\n type=\"file\"\n hidden\n accept={V16_IMAGE_ACCEPT}\n onChange={(e) => {\n take(e.target.files?.[0]);\n e.target.value = \"\";\n }}\n />\n );\n\n const showCard = image && !done && !busy;\n const pct = upload.progress ?? 0;\n return (\n <div className=\"flex flex-col gap-4\">\n {showCard ? (\n <div className=\"flex flex-col gap-2 rounded-[10px] border border-kit-insp-line bg-kit-insp-tip-bg p-2\">\n <div className=\"h-[168px] w-full overflow-hidden rounded-[6px] bg-kit-insp-card\">\n <img src={image.src} alt={alt ?? \"\"} ref={(n) => onNatural?.(n, false)} onLoad={(e) => onNatural?.(e.currentTarget, true)} className=\"size-full object-cover\" />\n </div>\n <div className=\"flex items-center gap-1\">\n <div className=\"flex min-w-0 flex-1 flex-col gap-0.5\">\n <span className=\"truncate text-[13px] font-medium leading-4 text-kit-insp-tip-title\">{image.name || \"image\"}</span>\n {image.meta ? <span className=\"truncate text-[12px] leading-[15px] text-kit-fg-3 tabular-nums\">{image.meta}</span> : null}\n </div>\n {readOnly ? null : (\n <>\n {upload.run || onLibrary ? (\n <Tooltip content=\"Replace image\">\n <button type=\"button\" aria-label=\"Replace image\" className={BTN} onClick={pick}>\n <IconUpload stroke={1.2} aria-hidden />\n </button>\n </Tooltip>\n ) : null}\n <Menu>\n <MenuTrigger aria-label=\"Image actions\" className={BTN}>\n <IconDots stroke={1.5} aria-hidden />\n </MenuTrigger>\n <MenuContent align=\"end\" className=\"w-[240px] min-w-[240px]\">\n {upload.run || onLibrary ? (\n <MenuItem icon={<IconUpload stroke={1.5} />} onClick={pick}>\n Replace image\n </MenuItem>\n ) : null}\n {onCrop ? (\n <MenuItem icon={<IconScan stroke={1.5} />} onClick={onCrop}>\n Crop and focal point\n </MenuItem>\n ) : null}\n <MenuItem\n icon={<IconLink stroke={1.5} />}\n onClick={() => {\n const w = navigator.clipboard?.writeText(image.url);\n if (!w) return toast?.(\"Copy is not available in this browser\");\n w.then(() => toast?.(\"Image URL copied\"), () => toast?.(\"The browser refused to copy the address\"));\n }}\n >\n Copy image URL\n </MenuItem>\n <MenuSeparator />\n <MenuItem danger icon={<IconTrash stroke={1.5} />} onClick={onRemove}>\n Remove from section\n </MenuItem>\n </MenuContent>\n </Menu>\n </>\n )}\n </div>\n </div>\n ) : (\n <div\n id={id}\n role=\"button\"\n tabIndex={readOnly ? -1 : 0}\n aria-busy={busy || undefined}\n aria-disabled={readOnly || (!upload.run && !onLibrary) || undefined}\n aria-label={`${label}: drag and drop to upload or select`}\n onKeyDown={(e) => {\n if (e.target !== e.currentTarget || busy || readOnly) return;\n if (e.key === \"Enter\" || e.key === \" \") {\n e.preventDefault();\n pick();\n }\n }}\n onDragOver={(e) => {\n if (readOnly || busy || !upload.run || !e.dataTransfer.types.includes(\"Files\")) return;\n e.preventDefault();\n setOver(true);\n }}\n onDragLeave={() => setOver(false)}\n onDrop={(e) => {\n if (readOnly || !upload.run) return;\n e.preventDefault();\n setOver(false);\n take(e.dataTransfer.files[0]);\n }}\n className={cn(\n \"relative flex h-[164px] w-full flex-col items-center justify-center rounded-[16px] border-2 border-dashed border-kit-insp-line-strong bg-kit-insp-card text-center outline-none transition-[background-color,border-color] duration-150 ease-out focus-visible:border-kit-insp-accent\",\n over && \"border-kit-insp-accent bg-kit-insp-zone-over\",\n refusal && \"border-kit-insp-error\",\n busy && \"border-transparent bg-kit-insp-tip-bg\",\n )}\n >\n {busy ? (\n <>\n <svg aria-hidden className=\"pointer-events-none absolute -inset-0.5 h-[calc(100%+4px)] w-[calc(100%+4px)] overflow-visible\">\n <rect x=\"1\" y=\"1\" rx=\"16\" style={{ width: \"calc(100% - 2px)\", height: \"calc(100% - 2px)\" }} fill=\"none\" stroke=\"var(--kit-insp-line)\" strokeWidth=\"1.5\" />\n <rect x=\"1\" y=\"1\" rx=\"16\" style={{ width: \"calc(100% - 2px)\", height: \"calc(100% - 2px)\" }} fill=\"none\" stroke=\"var(--kit-insp-accent)\" strokeWidth=\"1.5\" pathLength={100} strokeDasharray={`${pct} 100`} className=\"transition-[stroke-dasharray] duration-[60ms] ease-linear\" />\n </svg>\n <span className=\"absolute -top-[11px] left-1/2 h-[18px] min-w-[38px] -translate-x-1/2 rounded-full bg-kit-insp-accent px-1.5 text-[11px] font-semibold leading-[18px] text-white tabular-nums\">{pct}%</span>\n </>\n ) : null}\n <span className={cn(\"mb-3.5 grid size-10 place-items-center rounded-full bg-kit-insp-zone-over text-kit-insp-accent-fg\", busy && \"border border-kit-insp-line bg-kit-insp-tip-bg\")}>\n <IconUpload className=\"size-5\" stroke={1.5} aria-hidden />\n </span>\n <span className={cn(\"text-[13px] font-medium leading-4 text-kit-insp-tip-body\", refusal && \"text-kit-insp-count-over\")}>\n {refusal ?? (over ? \"Drop to upload\" : busy ? \"Uploading…\" : (\n <>\n Drag and drop to upload or{\" \"}\n <button\n type=\"button\"\n tabIndex={-1}\n disabled={readOnly || (!upload.run && !onLibrary)}\n onClick={(e) => {\n e.stopPropagation();\n pick();\n }}\n className=\"font-medium text-kit-insp-zone-link hover:underline disabled:no-underline\"\n >\n select\n </button>\n </>\n ))}\n </span>\n <span className={cn(\"mt-1.5 text-[12px] leading-[15px] text-kit-fg-3\", done && \"text-kit-insp-zone-done\")}>\n {done ? \"Uploaded successfully!\" : upload.run ? \"PNG, JPG or WEBP · up to 10 MB\" : onLibrary ? \"Pick one from the media library\" : \"Uploading is not available here\"}\n </span>\n </div>\n )}\n {upload.error ? (\n <p role=\"alert\" className=\"-mt-2 text-[12px] leading-4 text-kit-insp-error\">\n {upload.error}\n </p>\n ) : null}\n {input}\n {alt !== undefined && onAlt ? (\n <div className=\"flex flex-col gap-2\">\n <label htmlFor={`${id}-alt`} className=\"text-[13px] font-medium leading-4 text-kit-insp-tip-body\">\n Alternative text\n </label>\n <input\n id={`${id}-alt`}\n value={alt}\n readOnly={readOnly}\n placeholder=\"Describe the image for screen readers\"\n onChange={(e) => onAlt(e.target.value)}\n className=\"h-[34px] w-full rounded-[6px] border border-transparent bg-kit-insp-card px-2.5 text-[13px] leading-[18px] tracking-[-0.1625px] text-kit-insp-tip-title outline-none transition-[background-color,border-color] duration-[120ms] ease-out placeholder:text-kit-fg-3 focus:border-kit-insp-accent focus:bg-kit-insp-card-focus\"\n />\n </div>\n ) : null}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAkBA,IAAa,mBAAmB;AAChC,IAAM,UAAU;AAChB,IAAM,YAAY;AAqBlB,IAAM,MACJ;AAEF,SAAgB,cAAc,EAAE,IAAI,OAAO,UAAU,OAAO,QAAQ,KAAK,OAAO,QAAQ,UAAU,WAAW,aAAiC;CAC5I,MAAM,EAAE,UAAU,eAAe;CACjC,MAAM,OAAO,MAAM,OAAyB,IAAI;CAChD,MAAM,CAAC,MAAM,WAAW,MAAM,SAAS,KAAK;CAC5C,MAAM,CAAC,SAAS,cAAc,MAAM,SAA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UAAA,CACE,oBAAC,SAAD;KAAO,SAAS,GAAG,GAAG;KAAO,WAAU;KAA2D,UAAA;IAE3F,CAAA,GACP,oBAAC,SAAD;KACE,IAAI,GAAG,GAAG;KACV,OAAO;KACG;KACV,aAAY;KACZ,WAAW,MAAM,MAAM,EAAE,OAAO,KAAK;KACrC,WAAU;IACX,CAAA,CACE;GACH,CAAA,IAAA;EACD;;AAET"}
@@ -72,7 +72,9 @@ export declare function withCrop(v: ImageValue, choice: V2ImageCrop, size: {
72
72
  }): ImageValue;
73
73
  /** RP-047: why a picture from outside the media library offers no crop (its URL cannot carry one). */
74
74
  export declare const NO_CROP_OUTSIDE_LIBRARY = "This picture isn't in your media library, so it can't be cropped here. The focal point still applies.";
75
- export declare function ImageDetails({ v, onChange, readOnly, label, urlOnly, altOnly, framingOnly, canCrop, size, asset, fit, }: {
75
+ /** A picture that loaded with no size of its own (an SVG with no width and height): a crop is cut from a size. */
76
+ export declare const NO_CROP_SIZELESS = "SVGs can't be cropped: this one has no size of its own. The focal point still applies.";
77
+ export declare function ImageDetails({ v, onChange, readOnly, label, urlOnly, altOnly, framingOnly, canCrop, size, sizeless, asset, fit, }: {
76
78
  v: ImageValue;
77
79
  onChange: (n: ImageValue) => void;
78
80
  readOnly?: boolean;
@@ -88,6 +90,8 @@ export declare function ImageDetails({ v, onChange, readOnly, label, urlOnly, al
88
90
  w: number;
89
91
  h: number;
90
92
  };
93
+ /** the picture finished loading with no size of its own (an SVG): the crop is off and says why, never "still loading" */
94
+ sizeless?: boolean;
91
95
  asset?: KitMediaAsset;
92
96
  /** fitOf's answer for this picture: a logo or an icon field sits whole in the pad, on the checker */
93
97
  fit?: "contain" | "cover";
@@ -355,7 +355,9 @@ function withCrop(v, choice, size) {
355
355
  }
356
356
  /** RP-047: why a picture from outside the media library offers no crop (its URL cannot carry one). */
357
357
  var NO_CROP_OUTSIDE_LIBRARY = "This picture isn't in your media library, so it can't be cropped here. The focal point still applies.";
358
- function ImageDetails({ v, onChange, readOnly, label, urlOnly, altOnly = false, framingOnly = false, canCrop = true, size, asset, fit = "cover" }) {
358
+ /** A picture that loaded with no size of its own (an SVG with no width and height): a crop is cut from a size. */
359
+ var NO_CROP_SIZELESS = "SVGs can't be cropped: this one has no size of its own. The focal point still applies.";
360
+ function ImageDetails({ v, onChange, readOnly, label, urlOnly, altOnly = false, framingOnly = false, canCrop = true, size, sizeless = false, asset, fit = "cover" }) {
359
361
  const { src } = useMedia();
360
362
  const focal = v.focal ?? {
361
363
  x: 50,
@@ -485,6 +487,9 @@ function ImageDetails({ v, onChange, readOnly, label, urlOnly, altOnly = false,
485
487
  !canCrop ? /* @__PURE__ */ jsx(Reason, {
486
488
  tone: "muted",
487
489
  children: NO_CROP_OUTSIDE_LIBRARY
490
+ }) : !size && sizeless ? /* @__PURE__ */ jsx(Reason, {
491
+ tone: "muted",
492
+ children: NO_CROP_SIZELESS
488
493
  }) : !size && !readOnly ? /* @__PURE__ */ jsx("span", {
489
494
  className: "text-kit-2xs text-kit-fg-3",
490
495
  children: "The crop is cut from the picture's size, which is still loading."
@@ -661,12 +666,21 @@ function ImageControl({ field, value, onChange: write, readOnly, id, path }) {
661
666
  const accept = field.svgOnly ? "image/svg+xml" : "image/*";
662
667
  const kinds = field.svgOnly ? ["svg"] : ["image", "svg"];
663
668
  const [loaded, setLoaded] = React.useState();
664
- const natural = loaded && v && loaded.url === v.url ? {
669
+ const natural = loaded && v && loaded.url === v.url && loaded.w > 0 ? {
665
670
  w: loaded.w,
666
671
  h: loaded.h
667
672
  } : void 0;
668
- const readNatural = (img) => {
669
- if (!img || !v || !img.complete || !img.naturalWidth || !img.naturalHeight) return;
673
+ /** `onLoad`: the load event fired, so a missing size is the picture's own (an SVG with none), not a load in progress */
674
+ const readNatural = (img, onLoad = false) => {
675
+ if (!img || !v || !img.complete && !onLoad) return;
676
+ if (!img.naturalWidth || !img.naturalHeight) {
677
+ if (onLoad) setLoaded((prev) => prev && prev.url === v.url && prev.w === 0 ? prev : {
678
+ url: v.url,
679
+ w: 0,
680
+ h: 0
681
+ });
682
+ return;
683
+ }
670
684
  const next = {
671
685
  url: v.url,
672
686
  w: img.naturalWidth,
@@ -679,6 +693,7 @@ function ImageControl({ field, value, onChange: write, readOnly, id, path }) {
679
693
  w: asset.width,
680
694
  h: asset.height
681
695
  } : stored ?? natural;
696
+ const sizeless = !size && !!v && loaded?.url === v.url && loaded.w === 0;
682
697
  const fit = fitOf(value, field);
683
698
  const onChange = (n) => {
684
699
  if (!n) return write(urlOnly ? "" : null);
@@ -773,7 +788,8 @@ function ImageControl({ field, value, onChange: write, readOnly, id, path }) {
773
788
  }) : void 0,
774
789
  onCrop: v && !urlOnly && !altOnly ? () => window.setTimeout(() => setDetails(true), 0) : void 0,
775
790
  onRemove: () => onChange(null),
776
- onLibrary: library
791
+ onLibrary: library,
792
+ onNatural: readNatural
777
793
  })
778
794
  }),
779
795
  v ? /* @__PURE__ */ jsx(PopoverContent, {
@@ -788,6 +804,7 @@ function ImageControl({ field, value, onChange: write, readOnly, id, path }) {
788
804
  urlOnly,
789
805
  altOnly,
790
806
  size,
807
+ sizeless,
791
808
  asset,
792
809
  fit
793
810
  })
@@ -897,7 +914,7 @@ function ImageControl({ field, value, onChange: write, readOnly, id, path }) {
897
914
  src: src(v.url),
898
915
  alt: alt ?? "",
899
916
  ref: readNatural,
900
- onLoad: (e) => readNatural(e.currentTarget),
917
+ onLoad: (e) => readNatural(e.currentTarget, true),
901
918
  className: fit === "contain" ? "size-full object-contain" : "size-full object-cover",
902
919
  style: fit === "contain" ? void 0 : { objectPosition: `${focal.x}% ${focal.y}%` }
903
920
  })
@@ -1021,6 +1038,7 @@ function ImageControl({ field, value, onChange: write, readOnly, id, path }) {
1021
1038
  urlOnly,
1022
1039
  altOnly,
1023
1040
  size,
1041
+ sizeless,
1024
1042
  asset,
1025
1043
  fit
1026
1044
  })
@@ -1521,6 +1539,6 @@ function VideoControl({ field, value, onChange, readOnly, id, onBlur }) {
1521
1539
  });
1522
1540
  }
1523
1541
  //#endregion
1524
- export { FileControl, GalleryControl, ImageControl, ImageDetails, MediaPicker, NO_CROP_OUTSIDE_LIBRARY, VideoControl, VideoPreview, acceptsFile, cropChoice, fileNameFromUrl, formatBytes, fromAsset, isVideoUrl, normImage, useUpload, videoProvider, withCrop, youTubeId };
1542
+ export { FileControl, GalleryControl, ImageControl, ImageDetails, MediaPicker, NO_CROP_OUTSIDE_LIBRARY, NO_CROP_SIZELESS, VideoControl, VideoPreview, acceptsFile, cropChoice, fileNameFromUrl, formatBytes, fromAsset, isVideoUrl, normImage, useUpload, videoProvider, withCrop, youTubeId };
1525
1543
 
1526
1544
  //# sourceMappingURL=media.js.map