@vielzeug/refine 1.5.1 → 1.5.2
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.
- package/dist/async.cjs +9 -9
- package/dist/async.cjs.map +1 -1
- package/dist/async.js +30 -31
- package/dist/async.js.map +1 -1
- package/dist/button.cjs +6 -6
- package/dist/button.cjs.map +1 -1
- package/dist/button.js +29 -30
- package/dist/button.js.map +1 -1
- package/dist/calendar.cjs +44 -44
- package/dist/calendar.cjs.map +1 -1
- package/dist/calendar.js +115 -117
- package/dist/calendar.js.map +1 -1
- package/dist/checkbox-group.cjs +7 -7
- package/dist/checkbox-group.cjs.map +1 -1
- package/dist/checkbox-group.js +71 -73
- package/dist/checkbox-group.js.map +1 -1
- package/dist/checkbox.cjs +3 -3
- package/dist/checkbox.cjs.map +1 -1
- package/dist/checkbox.js +28 -29
- package/dist/checkbox.js.map +1 -1
- package/dist/code-window.cjs +7 -7
- package/dist/code-window.cjs.map +1 -1
- package/dist/code-window.js +17 -18
- package/dist/code-window.js.map +1 -1
- package/dist/combobox.cjs +1 -1
- package/dist/combobox.cjs.map +1 -1
- package/dist/combobox.js +11 -12
- package/dist/combobox.js.map +1 -1
- package/dist/custom-elements.json +5267 -5267
- package/dist/datagrid.cjs +66 -66
- package/dist/datagrid.cjs.map +1 -1
- package/dist/datagrid.js +267 -268
- package/dist/datagrid.js.map +1 -1
- package/dist/date-picker.cjs +11 -11
- package/dist/date-picker.cjs.map +1 -1
- package/dist/date-picker.js +8 -9
- package/dist/date-picker.js.map +1 -1
- package/dist/file-input.cjs +6 -6
- package/dist/file-input.cjs.map +1 -1
- package/dist/file-input.js +50 -51
- package/dist/file-input.js.map +1 -1
- package/dist/grid.cjs +1 -1
- package/dist/grid.cjs.map +1 -1
- package/dist/grid.js +47 -48
- package/dist/grid.js.map +1 -1
- package/dist/icon.cjs +1 -1
- package/dist/icon.cjs.map +1 -1
- package/dist/icon.js +26 -27
- package/dist/icon.js.map +1 -1
- package/dist/input.cjs +20 -20
- package/dist/input.cjs.map +1 -1
- package/dist/input.js +98 -100
- package/dist/input.js.map +1 -1
- package/dist/message-composer.cjs +18 -18
- package/dist/message-composer.cjs.map +1 -1
- package/dist/message-composer.js +113 -115
- package/dist/message-composer.js.map +1 -1
- package/dist/navbar.cjs +11 -11
- package/dist/navbar.cjs.map +1 -1
- package/dist/navbar.js +78 -79
- package/dist/navbar.js.map +1 -1
- package/dist/otp-input.cjs +4 -4
- package/dist/otp-input.cjs.map +1 -1
- package/dist/otp-input.js +31 -32
- package/dist/otp-input.js.map +1 -1
- package/dist/progress.cjs +13 -13
- package/dist/progress.cjs.map +1 -1
- package/dist/progress.js +45 -46
- package/dist/progress.js.map +1 -1
- package/dist/radio-group.cjs +5 -5
- package/dist/radio-group.cjs.map +1 -1
- package/dist/radio-group.js +83 -85
- package/dist/radio-group.js.map +1 -1
- package/dist/radio.cjs +3 -3
- package/dist/radio.cjs.map +1 -1
- package/dist/radio.js +27 -28
- package/dist/radio.js.map +1 -1
- package/dist/rating.cjs +4 -4
- package/dist/rating.cjs.map +1 -1
- package/dist/rating.js +30 -31
- package/dist/rating.js.map +1 -1
- package/dist/select.cjs +4 -4
- package/dist/select.cjs.map +1 -1
- package/dist/select.js +88 -89
- package/dist/select.js.map +1 -1
- package/dist/sidebar.cjs +11 -11
- package/dist/sidebar.cjs.map +1 -1
- package/dist/sidebar.js +97 -98
- package/dist/sidebar.js.map +1 -1
- package/dist/skeleton.cjs +3 -3
- package/dist/skeleton.cjs.map +1 -1
- package/dist/skeleton.js +23 -24
- package/dist/skeleton.js.map +1 -1
- package/dist/slider.cjs +3 -3
- package/dist/slider.cjs.map +1 -1
- package/dist/slider.js +65 -66
- package/dist/slider.js.map +1 -1
- package/dist/switch.cjs +3 -3
- package/dist/switch.cjs.map +1 -1
- package/dist/switch.js +23 -24
- package/dist/switch.js.map +1 -1
- package/dist/tab-panel.cjs +7 -7
- package/dist/tab-panel.cjs.map +1 -1
- package/dist/tab-panel.js +21 -23
- package/dist/tab-panel.js.map +1 -1
- package/dist/testing.cjs +1 -1
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.js +4 -5
- package/dist/testing.js.map +1 -1
- package/dist/textarea.cjs +13 -13
- package/dist/textarea.cjs.map +1 -1
- package/dist/textarea.js +92 -94
- package/dist/textarea.js.map +1 -1
- package/dist/time-picker.cjs +9 -9
- package/dist/time-picker.cjs.map +1 -1
- package/dist/time-picker.js +47 -48
- package/dist/time-picker.js.map +1 -1
- package/package.json +1 -1
- package/dist/ore/dist/_dev.cjs +0 -2
- package/dist/ore/dist/_dev.cjs.map +0 -1
- package/dist/ore/dist/_dev.js +0 -12
- package/dist/ore/dist/_dev.js.map +0 -1
- package/dist/ore/dist/base-element.cjs +0 -2
- package/dist/ore/dist/base-element.cjs.map +0 -1
- package/dist/ore/dist/base-element.js +0 -158
- package/dist/ore/dist/base-element.js.map +0 -1
- package/dist/ore/dist/context.cjs +0 -2
- package/dist/ore/dist/context.cjs.map +0 -1
- package/dist/ore/dist/context.js +0 -11
- package/dist/ore/dist/context.js.map +0 -1
- package/dist/ore/dist/define.cjs +0 -2
- package/dist/ore/dist/define.cjs.map +0 -1
- package/dist/ore/dist/define.js +0 -27
- package/dist/ore/dist/define.js.map +0 -1
- package/dist/ore/dist/directives/classMap.cjs +0 -1
- package/dist/ore/dist/directives/classMap.js +0 -1
- package/dist/ore/dist/directives/each.cjs +0 -1
- package/dist/ore/dist/directives/each.js +0 -5
- package/dist/ore/dist/directives/live.cjs +0 -2
- package/dist/ore/dist/directives/live.cjs.map +0 -1
- package/dist/ore/dist/directives/live.js +0 -6
- package/dist/ore/dist/directives/live.js.map +0 -1
- package/dist/ore/dist/directives/model.cjs +0 -1
- package/dist/ore/dist/directives/model.js +0 -3
- package/dist/ore/dist/directives/raw.cjs +0 -2
- package/dist/ore/dist/directives/raw.cjs.map +0 -1
- package/dist/ore/dist/directives/raw.js +0 -38
- package/dist/ore/dist/directives/raw.js.map +0 -1
- package/dist/ore/dist/directives/styleMap.cjs +0 -2
- package/dist/ore/dist/directives/styleMap.cjs.map +0 -1
- package/dist/ore/dist/directives/styleMap.js +0 -20
- package/dist/ore/dist/directives/styleMap.js.map +0 -1
- package/dist/ore/dist/directives/when.cjs +0 -2
- package/dist/ore/dist/directives/when.cjs.map +0 -1
- package/dist/ore/dist/directives/when.js +0 -38
- package/dist/ore/dist/directives/when.js.map +0 -1
- package/dist/ore/dist/directives.cjs +0 -1
- package/dist/ore/dist/directives.js +0 -8
- package/dist/ore/dist/errors.cjs +0 -3
- package/dist/ore/dist/errors.cjs.map +0 -1
- package/dist/ore/dist/errors.js +0 -50
- package/dist/ore/dist/errors.js.map +0 -1
- package/dist/ore/dist/forms/context.cjs +0 -2
- package/dist/ore/dist/forms/context.cjs.map +0 -1
- package/dist/ore/dist/forms/context.js +0 -6
- package/dist/ore/dist/forms/context.js.map +0 -1
- package/dist/ore/dist/forms/field.cjs +0 -2
- package/dist/ore/dist/forms/field.cjs.map +0 -1
- package/dist/ore/dist/forms/field.js +0 -42
- package/dist/ore/dist/forms/field.js.map +0 -1
- package/dist/ore/dist/forms.cjs +0 -1
- package/dist/ore/dist/forms.js +0 -3
- package/dist/ore/dist/observers/intersection-observe.cjs +0 -2
- package/dist/ore/dist/observers/intersection-observe.cjs.map +0 -1
- package/dist/ore/dist/observers/intersection-observe.js +0 -12
- package/dist/ore/dist/observers/intersection-observe.js.map +0 -1
- package/dist/ore/dist/observers/media-observe.cjs +0 -1
- package/dist/ore/dist/observers/media-observe.js +0 -1
- package/dist/ore/dist/observers/mutation-observe.cjs +0 -1
- package/dist/ore/dist/observers/mutation-observe.js +0 -1
- package/dist/ore/dist/observers/resize-observe.cjs +0 -2
- package/dist/ore/dist/observers/resize-observe.cjs.map +0 -1
- package/dist/ore/dist/observers/resize-observe.js +0 -20
- package/dist/ore/dist/observers/resize-observe.js.map +0 -1
- package/dist/ore/dist/observers.cjs +0 -1
- package/dist/ore/dist/observers.js +0 -5
- package/dist/ore/dist/props.cjs +0 -2
- package/dist/ore/dist/props.cjs.map +0 -1
- package/dist/ore/dist/props.js +0 -56
- package/dist/ore/dist/props.js.map +0 -1
- package/dist/ore/dist/runtime.cjs +0 -2
- package/dist/ore/dist/runtime.cjs.map +0 -1
- package/dist/ore/dist/runtime.js +0 -25
- package/dist/ore/dist/runtime.js.map +0 -1
- package/dist/ore/dist/testing/flush.cjs +0 -2
- package/dist/ore/dist/testing/flush.cjs.map +0 -1
- package/dist/ore/dist/testing/flush.js +0 -11
- package/dist/ore/dist/testing/flush.js.map +0 -1
- package/dist/ore/dist/testing/mount.cjs +0 -2
- package/dist/ore/dist/testing/mount.cjs.map +0 -1
- package/dist/ore/dist/testing/mount.js +0 -94
- package/dist/ore/dist/testing/mount.js.map +0 -1
- package/dist/ore/dist/testing/query.cjs +0 -2
- package/dist/ore/dist/testing/query.cjs.map +0 -1
- package/dist/ore/dist/testing/query.js +0 -12
- package/dist/ore/dist/testing/query.js.map +0 -1
- package/dist/ore/dist/testing/render-hook.cjs +0 -1
- package/dist/ore/dist/testing/render-hook.js +0 -3
- package/dist/ore/dist/testing/testing.cjs +0 -1
- package/dist/ore/dist/testing/testing.js +0 -4
- package/dist/ore/dist/testing/wait.cjs +0 -1
- package/dist/ore/dist/testing/wait.js +0 -1
- package/dist/ore/dist/testing.cjs +0 -1
- package/dist/ore/dist/testing.js +0 -6
- package/dist/ore/dist/types/bindings.cjs +0 -2
- package/dist/ore/dist/types/bindings.cjs.map +0 -1
- package/dist/ore/dist/types/bindings.js +0 -15
- package/dist/ore/dist/types/bindings.js.map +0 -1
- package/dist/ore/dist/types.cjs +0 -2
- package/dist/ore/dist/types.cjs.map +0 -1
- package/dist/ore/dist/types.js +0 -15
- package/dist/ore/dist/types.js.map +0 -1
- package/dist/ore/dist/utils/css.cjs +0 -2
- package/dist/ore/dist/utils/css.cjs.map +0 -1
- package/dist/ore/dist/utils/css.js +0 -18
- package/dist/ore/dist/utils/css.js.map +0 -1
- package/dist/ore/dist/utils/dom.cjs +0 -2
- package/dist/ore/dist/utils/dom.cjs.map +0 -1
- package/dist/ore/dist/utils/dom.js +0 -43
- package/dist/ore/dist/utils/dom.js.map +0 -1
- package/dist/ore/dist/utils/id.cjs +0 -2
- package/dist/ore/dist/utils/id.cjs.map +0 -1
- package/dist/ore/dist/utils/id.js +0 -4
- package/dist/ore/dist/utils/id.js.map +0 -1
package/dist/file-input.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-input.cjs","names":[],"sources":["../src/inputs/file-input/file-input.ts"],"sourcesContent":["import { createDropZone, matchesAccept } from '@vielzeug/dnd';\nimport {\n createStableId,\n define,\n html,\n inject,\n prop,\n ref,\n bind,\n onCleanup,\n onElement,\n onEvent,\n onMounted,\n useEmit,\n} from '@vielzeug/ore';\nimport { useField } from '@vielzeug/ore/forms';\nimport { computed, signal, watch } from '@vielzeug/ripple';\n\nimport { createInteraction } from '../../headless';\nimport { FILE_INPUT_SIZE_PRESET } from '../../shared';\nimport { fieldMixins, forcedColorsFocusMixin, sizeVariantMixin } from '../../styles';\nimport { FORM_CTX, useFormContext } from '../shared/form-context';\nimport componentStyles from './file-input.css?inline';\n\nconst formatBytes = (bytes: number) => {\n if (bytes === 0) return '0 B';\n\n const k = 1024;\n const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];\n const i = Math.floor(Math.log(bytes) / Math.log(k));\n\n return parseFloat((bytes / Math.pow(k, i)).toFixed(1)) + ' ' + sizes[i];\n};\n\nconst isFileSizeAllowed = (file: File, maxSize?: number) => !maxSize || file.size <= maxSize;\n\nconst isImageFile = (file: File): boolean => file.type.startsWith('image/');\n\n/** File input component properties */\nexport type OreFileInputProps = {\n /** Accepted file types (comma-separated, e.g. '.jpg, .png, image/*') */\n accept?: string;\n /** Theme color tint */\n color?: string;\n /** Disabled state */\n disabled?: boolean;\n /** Error message text */\n error?: string;\n /**\n * Render selected files as a grid of image thumbnails/previews instead of the default\n * single-column list. Non-image files fall back to a generic file icon in the same grid.\n */\n gallery?: boolean;\n /** Helper text displayed below the input */\n helper?: string;\n /** Input label text */\n label?: string;\n /** Max number of files allowed (only used if multiple is true) */\n 'max-files'?: number;\n /** Max size of a single file in bytes */\n 'max-size'?: number;\n /** Allow multiple files selection */\n multiple?: boolean;\n /** Form field name */\n name?: string;\n /**\n * JS-only callback fired with the inner `<input type=\"file\">` element when it\n * mounts, and with `null` when it unmounts. Intended for composed components\n * that need imperative access to the raw element.\n * Set as a JS property: `bitFileInput.ref = (el) => { ... }`.\n */\n ref?: ((el: HTMLInputElement | null) => void) | null;\n /** Required field */\n required?: boolean;\n /** Field size preset */\n size?: string;\n};\n\n/** Events emitted by the file-input component */\nexport type OreFileInputEvents = {\n /** Emitted when files are added or removed */\n change: { files: File[]; originalEvent?: Event; value: File[] };\n /** Emitted when a specific file is removed */\n remove: { file: File; files: File[]; originalEvent?: Event; value: File[] };\n};\n\n/**\n * A file upload field with drag-and-drop support and built-in validation messaging.\n *\n * @element ore-file-input\n *\n * @attr {string} accept - Comma-separated file extensions or MIME types\n * @attr {boolean} multiple - Enable multiple files selection\n * @attr {boolean} gallery - Show selected files as an image thumbnail/preview grid\n * @attr {number} max-files - Max number of files allowed\n * @attr {number} max-size - Max size of each file in bytes\n * @attr {boolean} disabled - Disable interaction\n * @attr {string} error - Show an error state/message\n * @attr {string} helper - Provide helper context below the dropzone\n *\n * @fires change - detail: { files: File[], value: File[] }\n * @fires remove - detail: { file: File, files: File[] }\n *\n * @cssprop --file-input-bg - Dropzone background color\n * @cssprop --file-input-border-color - Dropzone border color\n * @cssprop --file-input-font-size - Font size\n * @cssprop --file-input-radius - Dropzone border radius\n * @cssprop --file-input-min-height - Minimum dropzone height\n * @cssprop --file-input-hover-bg - Dropzone background on hover (flat/ghost variants)\n * @cssprop --file-input-hover-border-color - Dropzone border on hover (flat/bordered variants)\n * @cssprop --file-input-focus-bg - Dropzone background when focused/drag-over (flat variant)\n * @cssprop --file-input-focus-border-color - Dropzone border when focused/drag-over (flat variant)\n * @cssprop --file-input-thumb-size - Gallery thumbnail width/height\n * @part wrapper - Root wrapper around the file input field\n * @part label - Visible label rendered above the dropzone\n * @part dropzone - Interactive drag-and-drop target\n * @part input - Native file input element\n * @part gallery - Gallery grid container (rendered instead of `file-list` when `gallery` is set)\n * @part helper - Helper text shown beneath the dropzone\n * @part error - Error message shown beneath the field\n * @example\n * ```html\n * <ore-file-input label=\"Upload files\" accept=\"image/*\" multiple />\n * <ore-file-input label=\"Photos\" accept=\"image/*\" multiple gallery />\n * <ore-file-input label=\"Resume\" accept=\".pdf,.doc,.docx\" max-size=\"5242880\" />\n * <ore-file-input variant=\"bordered\" color=\"primary\" />\n * ```\n */\nexport const FILE_INPUT_TAG = 'ore-file-input' as const;\ndefine<OreFileInputProps>(FILE_INPUT_TAG, {\n formAssociated: true,\n props: {\n accept: prop.string(),\n color: prop.string(),\n disabled: prop.bool(false),\n error: prop.string(),\n gallery: prop.bool(false),\n helper: prop.string(),\n label: prop.string(),\n 'max-files': prop.number(0),\n 'max-size': prop.number(0),\n multiple: prop.bool(false),\n name: prop.string(),\n ref: prop.json(undefined as ((el: HTMLInputElement | null) => void) | null | undefined),\n required: prop.bool(false),\n size: prop.string(),\n },\n setup(props) {\n const emit = useEmit<OreFileInputEvents>();\n\n // ============================================\n // State\n // ============================================\n\n const files = signal<File[]>([]);\n const isDragging = signal(false);\n const formCtx = inject(FORM_CTX);\n const fCtxProps = useFormContext(props, formCtx);\n const isDisabled = fCtxProps.disabled;\n const maxFilesLimit = computed(() => props['max-files'].value ?? 0);\n const maxSizeLimit = computed(() => props['max-size'].value ?? 0);\n\n // ============================================\n // Form Integration\n // ============================================\n\n useField({\n disabled: isDisabled,\n toFormValue: (fi: File[]) => {\n if (fi.length === 0) return null;\n\n const name = props.name.value || 'file';\n const fd = new FormData();\n\n for (const file of fi) fd.append(name, file);\n\n return fd;\n },\n value: files,\n });\n\n // Sync host attributes for CSS selectors\n const isInvalid = computed(() => Boolean(props.error.value));\n\n bind({\n attr: {\n 'drag-over': () => (isDragging.value ? true : undefined),\n invalid: () => (isInvalid.value ? true : undefined),\n size: fCtxProps.size,\n },\n });\n\n // ============================================\n // IDs\n // ============================================\n const fileInputId = createStableId('file-input');\n const labelId = `label-${fileInputId}`;\n const helperId = `helper-${fileInputId}`;\n const errorId = `error-${fileInputId}`;\n\n // ============================================\n // Refs\n // ============================================\n const dropzoneRef = ref<HTMLDivElement>();\n const inputRef = ref<HTMLInputElement>();\n const hintText = computed(() => {\n const parts: string[] = [];\n\n if (props.accept.value) {\n parts.push(\n props.accept.value\n .split(',')\n .map((s: string) => s.trim())\n .join(', '),\n );\n }\n\n const maxSize = maxSizeLimit.value;\n\n if (maxSize > 0) parts.push(`max ${formatBytes(maxSize)}`);\n\n const maxFiles = maxFilesLimit.value;\n\n if (maxFiles > 0) parts.push(`up to ${maxFiles} file${maxFiles !== 1 ? 's' : ''}`);\n\n return parts.join(' · ');\n });\n\n // ============================================\n // File Management\n // ============================================\n function addFiles(newFiles: File[], originalEvent?: Event): void {\n if (isDisabled.value) return;\n\n const acceptVal = props.accept.value;\n const isMultiple = Boolean(props.multiple.value);\n let incoming = Array.from(newFiles);\n\n if (!isMultiple) incoming = incoming.slice(0, 1);\n\n incoming = incoming.filter(\n (f) =>\n matchesAccept(f, acceptVal ? acceptVal.split(',').map((t) => t.trim()) : []) &&\n isFileSizeAllowed(f, maxSizeLimit.value),\n );\n\n let updated: File[] = isMultiple ? [...files.value] : [];\n\n for (const f of incoming) {\n if (!updated.includes(f)) updated.push(f);\n }\n\n if (maxFilesLimit.value > 0 && updated.length > maxFilesLimit.value) {\n updated = updated.slice(0, maxFilesLimit.value);\n }\n\n files.value = updated;\n emit('change', { files: files.value, originalEvent, value: files.value });\n }\n function removeFile(file: File, originalEvent?: Event): void {\n files.value = files.value.filter((f) => f !== file);\n emit('remove', { file, files: files.value, originalEvent, value: files.value });\n emit('change', { files: files.value, originalEvent, value: files.value });\n }\n\n // ============================================\n // Gallery Preview URLs\n // ============================================\n // Object URLs are created lazily (only while `gallery` is enabled) and revoked as soon\n // as their file is no longer selected, plus unconditionally on disconnect — otherwise\n // each preview leaks its backing blob for the life of the page.\n const previewUrls = new Map<File, string>();\n\n function getPreviewUrl(file: File): string {\n let url = previewUrls.get(file);\n\n if (!url) {\n url = URL.createObjectURL(file);\n previewUrls.set(file, url);\n }\n\n return url;\n }\n\n function revokeStalePreviewUrls(activeFiles: File[]): void {\n const keep = new Set(activeFiles);\n\n for (const [file, url] of previewUrls) {\n if (!keep.has(file)) {\n URL.revokeObjectURL(url);\n previewUrls.delete(file);\n }\n }\n }\n\n watch(files, revokeStalePreviewUrls);\n\n onCleanup(() => {\n for (const url of previewUrls.values()) URL.revokeObjectURL(url);\n\n previewUrls.clear();\n });\n\n // ============================================\n // Mount\n // ============================================\n // ============================================\n // Template\n // ============================================\n onElement(inputRef, (inp) => {\n props.ref.value?.(inp);\n\n const sub = watch(props.ref, (cb) => {\n cb?.(inp);\n });\n\n return () => {\n sub.dispose();\n props.ref.value?.(null);\n };\n });\n\n onMounted(() => {\n const inp = inputRef.value!;\n const dz = dropzoneRef.value!;\n let skipNextClick = false;\n const pressControl = createInteraction({\n disabled: isDisabled,\n onPress: () => {\n inp.click();\n },\n });\n\n // Native input → add files\n onEvent(inp, 'change', (e: Event) => {\n const input = e.target as HTMLInputElement;\n\n if (input.files?.length) addFiles(Array.from(input.files), e);\n\n input.value = ''; // reset so the same file triggers change again\n });\n // Click dropzone → open file picker\n onEvent(dz, 'click', (e: MouseEvent) => {\n if (e.target === inp) return;\n\n if (skipNextClick) {\n skipNextClick = false;\n\n return;\n }\n\n if (!isDisabled.value) inp.click();\n });\n // Keyboard: Enter / Space → open picker\n onEvent(dz, 'keydown', (e: KeyboardEvent) => {\n skipNextClick = pressControl.handleKeydown(e) && e.key === 'Enter';\n });\n\n const dropZone = createDropZone({\n disabled: isDisabled.value,\n element: dz,\n onDrop: (droppedFiles) => addFiles(droppedFiles),\n onHoverChange: (hovered) => {\n isDragging.value = hovered;\n },\n });\n\n onCleanup(() => dropZone.dispose());\n });\n\n return html`\n <div class=\"file-input-wrapper\" part=\"wrapper\">\n <label class=\"label-outside\" id=\"${labelId}\" part=\"label\" ?hidden=${() => !props.label.value}\n >${props.label}</label\n >\n <div\n class=\"dropzone\"\n part=\"dropzone\"\n ref=${dropzoneRef}\n role=\"button\"\n :tabindex=\"${() => (isDisabled.value ? '-1' : '0')}\"\n :aria-disabled=\"${() => String(isDisabled.value)}\"\n :aria-label=\"${() => (!props.label.value ? 'File upload drop zone' : null)}\"\n :aria-labelledby=\"${() => (props.label.value ? labelId : null)}\"\n aria-describedby=\"${helperId}\">\n <input\n type=\"file\"\n ref=${inputRef}\n part=\"input\"\n id=\"${fileInputId}\"\n :accept=\"${props.accept}\"\n ?multiple=\"${props.multiple}\"\n ?required=\"${props.required}\"\n ?disabled=\"${isDisabled}\"\n :name=\"${props.name}\"\n hidden\n inert\n tabindex=\"-1\" />\n <div class=\"dropzone-content\">\n <span class=\"dropzone-icon\" aria-hidden=\"true\">\n <ore-icon name=\"upload\" size=\"36\" stroke-width=\"1.5\" aria-hidden=\"true\"></ore-icon>\n </span>\n <span class=\"dropzone-title\">Drop files here or <u>click to browse</u></span>\n <span class=\"dropzone-hint\" ?hidden=${() => !hintText.value}>${hintText}</span>\n </div>\n </div>\n <ul\n class=\"${() => (props.gallery.value ? 'file-grid' : 'file-list')}\"\n part=\"${() => (props.gallery.value ? 'gallery' : null)}\"\n role=\"list\"\n aria-label=\"Selected files\"\n ?hidden=${() => files.value.length === 0}>\n ${() =>\n files.value.map((file: File) =>\n props.gallery.value\n ? html`\n <li class=\"file-card\">\n ${\n // Decorative: the file name is already announced via the visible\n // `.file-card-name` caption below — repeating it as `alt` text would\n // duplicate it (and often trips redundant-alt checks, since real\n // filenames commonly contain words like \"photo\" or \"image\").\n isImageFile(file)\n ? // Object URLs use the `blob:` scheme, which ore's attribute-level\n // XSS guard blocks unconditionally on `src` (and other\n // URL-accepting attributes) — set it as a DOM property via `ref`\n // instead, bypassing that string-based check. Safe here: the value\n // comes from `URL.createObjectURL(file)` on a real `File` object we\n // control, never from untrusted text.\n html`<img\n class=\"file-thumb\"\n alt=\"\"\n ref=\"${(el: HTMLImageElement | null) => {\n if (el) el.src = getPreviewUrl(file);\n }}\" />`\n : html`<span class=\"file-thumb file-thumb-generic\" aria-hidden=\"true\">\n <ore-icon name=\"file\" size=\"28\" stroke-width=\"1.5\" aria-hidden=\"true\"></ore-icon>\n </span>`\n }\n <span class=\"file-card-name\" title=\"${file.name}\">${file.name}</span>\n <button\n class=\"file-card-remove\"\n type=\"button\"\n aria-label=\"${`Remove ${file.name}`}\"\n @click=${(e: Event) => removeFile(file, e)}>\n <ore-icon name=\"x\" size=\"12\" stroke-width=\"2.5\" aria-hidden=\"true\"></ore-icon>\n </button>\n </li>\n `\n : html`\n <li class=\"file-item\">\n <span class=\"file-icon\" aria-hidden=\"true\">\n <ore-icon name=\"file\" size=\"18\" stroke-width=\"1.75\" aria-hidden=\"true\"></ore-icon>\n </span>\n <span class=\"file-meta\">\n <span class=\"file-name\" title=\"${file.name}\">${file.name}</span>\n <span class=\"file-size\">${formatBytes(file.size)}</span>\n </span>\n <button\n class=\"file-remove\"\n type=\"button\"\n aria-label=\"${`Remove ${file.name}`}\"\n @click=${(e: Event) => removeFile(file, e)}>\n <ore-icon name=\"x\" size=\"12\" stroke-width=\"2.5\" aria-hidden=\"true\"></ore-icon>\n </button>\n </li>\n `,\n )}\n </ul>\n <div class=\"helper-text\" id=\"${helperId}\" part=\"helper\" ?hidden=${() => isInvalid.value || !props.helper.value}>\n ${props.helper}\n </div>\n <div\n class=\"helper-text helper-text-error\"\n id=\"${errorId}\"\n role=\"alert\"\n part=\"error\"\n ?hidden=${() => !isInvalid.value}>\n ${() => props.error.value ?? ''}\n </div>\n </div>\n `;\n },\n shadow: { delegatesFocus: true },\n styles: [\n ...fieldMixins,\n sizeVariantMixin(FILE_INPUT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AM,MAAM,OAAS,GAAG;;;KAIxC,EACA,OAAQ,CAAE,eAAgB,EAAK,EAC/B,OAAQ,CACN,GAAG,EAAA,YACH,EAAA,iBAAiB,EAAA,sBAAsB,EACvC,EAAA,uBAAuB,WAAW,EAClC,EAAA,OACF,CACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"file-input.cjs","names":[],"sources":["../src/inputs/file-input/file-input.ts"],"sourcesContent":["import { createDropZone, matchesAccept } from '@vielzeug/dnd';\nimport {\n createStableId,\n define,\n html,\n inject,\n prop,\n ref,\n bind,\n onCleanup,\n onElement,\n onEvent,\n onMounted,\n useEmit,\n} from '@vielzeug/ore';\nimport { useField } from '@vielzeug/ore/forms';\nimport { computed, signal, watch } from '@vielzeug/ripple';\n\nimport { createInteraction } from '../../headless';\nimport { FILE_INPUT_SIZE_PRESET } from '../../shared';\nimport { fieldMixins, forcedColorsFocusMixin, sizeVariantMixin } from '../../styles';\nimport { FORM_CTX, useFormContext } from '../shared/form-context';\nimport componentStyles from './file-input.css?inline';\n\nconst formatBytes = (bytes: number) => {\n if (bytes === 0) return '0 B';\n\n const k = 1024;\n const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];\n const i = Math.floor(Math.log(bytes) / Math.log(k));\n\n return parseFloat((bytes / Math.pow(k, i)).toFixed(1)) + ' ' + sizes[i];\n};\n\nconst isFileSizeAllowed = (file: File, maxSize?: number) => !maxSize || file.size <= maxSize;\n\nconst isImageFile = (file: File): boolean => file.type.startsWith('image/');\n\n/** File input component properties */\nexport type OreFileInputProps = {\n /** Accepted file types (comma-separated, e.g. '.jpg, .png, image/*') */\n accept?: string;\n /** Theme color tint */\n color?: string;\n /** Disabled state */\n disabled?: boolean;\n /** Error message text */\n error?: string;\n /**\n * Render selected files as a grid of image thumbnails/previews instead of the default\n * single-column list. Non-image files fall back to a generic file icon in the same grid.\n */\n gallery?: boolean;\n /** Helper text displayed below the input */\n helper?: string;\n /** Input label text */\n label?: string;\n /** Max number of files allowed (only used if multiple is true) */\n 'max-files'?: number;\n /** Max size of a single file in bytes */\n 'max-size'?: number;\n /** Allow multiple files selection */\n multiple?: boolean;\n /** Form field name */\n name?: string;\n /**\n * JS-only callback fired with the inner `<input type=\"file\">` element when it\n * mounts, and with `null` when it unmounts. Intended for composed components\n * that need imperative access to the raw element.\n * Set as a JS property: `bitFileInput.ref = (el) => { ... }`.\n */\n ref?: ((el: HTMLInputElement | null) => void) | null;\n /** Required field */\n required?: boolean;\n /** Field size preset */\n size?: string;\n};\n\n/** Events emitted by the file-input component */\nexport type OreFileInputEvents = {\n /** Emitted when files are added or removed */\n change: { files: File[]; originalEvent?: Event; value: File[] };\n /** Emitted when a specific file is removed */\n remove: { file: File; files: File[]; originalEvent?: Event; value: File[] };\n};\n\n/**\n * A file upload field with drag-and-drop support and built-in validation messaging.\n *\n * @element ore-file-input\n *\n * @attr {string} accept - Comma-separated file extensions or MIME types\n * @attr {boolean} multiple - Enable multiple files selection\n * @attr {boolean} gallery - Show selected files as an image thumbnail/preview grid\n * @attr {number} max-files - Max number of files allowed\n * @attr {number} max-size - Max size of each file in bytes\n * @attr {boolean} disabled - Disable interaction\n * @attr {string} error - Show an error state/message\n * @attr {string} helper - Provide helper context below the dropzone\n *\n * @fires change - detail: { files: File[], value: File[] }\n * @fires remove - detail: { file: File, files: File[] }\n *\n * @cssprop --file-input-bg - Dropzone background color\n * @cssprop --file-input-border-color - Dropzone border color\n * @cssprop --file-input-font-size - Font size\n * @cssprop --file-input-radius - Dropzone border radius\n * @cssprop --file-input-min-height - Minimum dropzone height\n * @cssprop --file-input-hover-bg - Dropzone background on hover (flat/ghost variants)\n * @cssprop --file-input-hover-border-color - Dropzone border on hover (flat/bordered variants)\n * @cssprop --file-input-focus-bg - Dropzone background when focused/drag-over (flat variant)\n * @cssprop --file-input-focus-border-color - Dropzone border when focused/drag-over (flat variant)\n * @cssprop --file-input-thumb-size - Gallery thumbnail width/height\n * @part wrapper - Root wrapper around the file input field\n * @part label - Visible label rendered above the dropzone\n * @part dropzone - Interactive drag-and-drop target\n * @part input - Native file input element\n * @part gallery - Gallery grid container (rendered instead of `file-list` when `gallery` is set)\n * @part helper - Helper text shown beneath the dropzone\n * @part error - Error message shown beneath the field\n * @example\n * ```html\n * <ore-file-input label=\"Upload files\" accept=\"image/*\" multiple />\n * <ore-file-input label=\"Photos\" accept=\"image/*\" multiple gallery />\n * <ore-file-input label=\"Resume\" accept=\".pdf,.doc,.docx\" max-size=\"5242880\" />\n * <ore-file-input variant=\"bordered\" color=\"primary\" />\n * ```\n */\nexport const FILE_INPUT_TAG = 'ore-file-input' as const;\ndefine<OreFileInputProps>(FILE_INPUT_TAG, {\n formAssociated: true,\n props: {\n accept: prop.string(),\n color: prop.string(),\n disabled: prop.bool(false),\n error: prop.string(),\n gallery: prop.bool(false),\n helper: prop.string(),\n label: prop.string(),\n 'max-files': prop.number(0),\n 'max-size': prop.number(0),\n multiple: prop.bool(false),\n name: prop.string(),\n ref: prop.json(undefined as ((el: HTMLInputElement | null) => void) | null | undefined),\n required: prop.bool(false),\n size: prop.string(),\n },\n setup(props) {\n const emit = useEmit<OreFileInputEvents>();\n\n // ============================================\n // State\n // ============================================\n\n const files = signal<File[]>([]);\n const isDragging = signal(false);\n const formCtx = inject(FORM_CTX);\n const fCtxProps = useFormContext(props, formCtx);\n const isDisabled = fCtxProps.disabled;\n const maxFilesLimit = computed(() => props['max-files'].value ?? 0);\n const maxSizeLimit = computed(() => props['max-size'].value ?? 0);\n\n // ============================================\n // Form Integration\n // ============================================\n\n useField({\n disabled: isDisabled,\n toFormValue: (fi: File[]) => {\n if (fi.length === 0) return null;\n\n const name = props.name.value || 'file';\n const fd = new FormData();\n\n for (const file of fi) fd.append(name, file);\n\n return fd;\n },\n value: files,\n });\n\n // Sync host attributes for CSS selectors\n const isInvalid = computed(() => Boolean(props.error.value));\n\n bind({\n attr: {\n 'drag-over': () => (isDragging.value ? true : undefined),\n invalid: () => (isInvalid.value ? true : undefined),\n size: fCtxProps.size,\n },\n });\n\n // ============================================\n // IDs\n // ============================================\n const fileInputId = createStableId('file-input');\n const labelId = `label-${fileInputId}`;\n const helperId = `helper-${fileInputId}`;\n const errorId = `error-${fileInputId}`;\n\n // ============================================\n // Refs\n // ============================================\n const dropzoneRef = ref<HTMLDivElement>();\n const inputRef = ref<HTMLInputElement>();\n const hintText = computed(() => {\n const parts: string[] = [];\n\n if (props.accept.value) {\n parts.push(\n props.accept.value\n .split(',')\n .map((s: string) => s.trim())\n .join(', '),\n );\n }\n\n const maxSize = maxSizeLimit.value;\n\n if (maxSize > 0) parts.push(`max ${formatBytes(maxSize)}`);\n\n const maxFiles = maxFilesLimit.value;\n\n if (maxFiles > 0) parts.push(`up to ${maxFiles} file${maxFiles !== 1 ? 's' : ''}`);\n\n return parts.join(' · ');\n });\n\n // ============================================\n // File Management\n // ============================================\n function addFiles(newFiles: File[], originalEvent?: Event): void {\n if (isDisabled.value) return;\n\n const acceptVal = props.accept.value;\n const isMultiple = Boolean(props.multiple.value);\n let incoming = Array.from(newFiles);\n\n if (!isMultiple) incoming = incoming.slice(0, 1);\n\n incoming = incoming.filter(\n (f) =>\n matchesAccept(f, acceptVal ? acceptVal.split(',').map((t) => t.trim()) : []) &&\n isFileSizeAllowed(f, maxSizeLimit.value),\n );\n\n let updated: File[] = isMultiple ? [...files.value] : [];\n\n for (const f of incoming) {\n if (!updated.includes(f)) updated.push(f);\n }\n\n if (maxFilesLimit.value > 0 && updated.length > maxFilesLimit.value) {\n updated = updated.slice(0, maxFilesLimit.value);\n }\n\n files.value = updated;\n emit('change', { files: files.value, originalEvent, value: files.value });\n }\n function removeFile(file: File, originalEvent?: Event): void {\n files.value = files.value.filter((f) => f !== file);\n emit('remove', { file, files: files.value, originalEvent, value: files.value });\n emit('change', { files: files.value, originalEvent, value: files.value });\n }\n\n // ============================================\n // Gallery Preview URLs\n // ============================================\n // Object URLs are created lazily (only while `gallery` is enabled) and revoked as soon\n // as their file is no longer selected, plus unconditionally on disconnect — otherwise\n // each preview leaks its backing blob for the life of the page.\n const previewUrls = new Map<File, string>();\n\n function getPreviewUrl(file: File): string {\n let url = previewUrls.get(file);\n\n if (!url) {\n url = URL.createObjectURL(file);\n previewUrls.set(file, url);\n }\n\n return url;\n }\n\n function revokeStalePreviewUrls(activeFiles: File[]): void {\n const keep = new Set(activeFiles);\n\n for (const [file, url] of previewUrls) {\n if (!keep.has(file)) {\n URL.revokeObjectURL(url);\n previewUrls.delete(file);\n }\n }\n }\n\n watch(files, revokeStalePreviewUrls);\n\n onCleanup(() => {\n for (const url of previewUrls.values()) URL.revokeObjectURL(url);\n\n previewUrls.clear();\n });\n\n // ============================================\n // Mount\n // ============================================\n // ============================================\n // Template\n // ============================================\n onElement(inputRef, (inp) => {\n props.ref.value?.(inp);\n\n const sub = watch(props.ref, (cb) => {\n cb?.(inp);\n });\n\n return () => {\n sub.dispose();\n props.ref.value?.(null);\n };\n });\n\n onMounted(() => {\n const inp = inputRef.value!;\n const dz = dropzoneRef.value!;\n let skipNextClick = false;\n const pressControl = createInteraction({\n disabled: isDisabled,\n onPress: () => {\n inp.click();\n },\n });\n\n // Native input → add files\n onEvent(inp, 'change', (e: Event) => {\n const input = e.target as HTMLInputElement;\n\n if (input.files?.length) addFiles(Array.from(input.files), e);\n\n input.value = ''; // reset so the same file triggers change again\n });\n // Click dropzone → open file picker\n onEvent(dz, 'click', (e: MouseEvent) => {\n if (e.target === inp) return;\n\n if (skipNextClick) {\n skipNextClick = false;\n\n return;\n }\n\n if (!isDisabled.value) inp.click();\n });\n // Keyboard: Enter / Space → open picker\n onEvent(dz, 'keydown', (e: KeyboardEvent) => {\n skipNextClick = pressControl.handleKeydown(e) && e.key === 'Enter';\n });\n\n const dropZone = createDropZone({\n disabled: isDisabled.value,\n element: dz,\n onDrop: (droppedFiles) => addFiles(droppedFiles),\n onHoverChange: (hovered) => {\n isDragging.value = hovered;\n },\n });\n\n onCleanup(() => dropZone.dispose());\n });\n\n return html`\n <div class=\"file-input-wrapper\" part=\"wrapper\">\n <label class=\"label-outside\" id=\"${labelId}\" part=\"label\" ?hidden=${() => !props.label.value}\n >${props.label}</label\n >\n <div\n class=\"dropzone\"\n part=\"dropzone\"\n ref=${dropzoneRef}\n role=\"button\"\n :tabindex=\"${() => (isDisabled.value ? '-1' : '0')}\"\n :aria-disabled=\"${() => String(isDisabled.value)}\"\n :aria-label=\"${() => (!props.label.value ? 'File upload drop zone' : null)}\"\n :aria-labelledby=\"${() => (props.label.value ? labelId : null)}\"\n aria-describedby=\"${helperId}\">\n <input\n type=\"file\"\n ref=${inputRef}\n part=\"input\"\n id=\"${fileInputId}\"\n :accept=\"${props.accept}\"\n ?multiple=\"${props.multiple}\"\n ?required=\"${props.required}\"\n ?disabled=\"${isDisabled}\"\n :name=\"${props.name}\"\n hidden\n inert\n tabindex=\"-1\" />\n <div class=\"dropzone-content\">\n <span class=\"dropzone-icon\" aria-hidden=\"true\">\n <ore-icon name=\"upload\" size=\"36\" stroke-width=\"1.5\" aria-hidden=\"true\"></ore-icon>\n </span>\n <span class=\"dropzone-title\">Drop files here or <u>click to browse</u></span>\n <span class=\"dropzone-hint\" ?hidden=${() => !hintText.value}>${hintText}</span>\n </div>\n </div>\n <ul\n class=\"${() => (props.gallery.value ? 'file-grid' : 'file-list')}\"\n part=\"${() => (props.gallery.value ? 'gallery' : null)}\"\n role=\"list\"\n aria-label=\"Selected files\"\n ?hidden=${() => files.value.length === 0}>\n ${() =>\n files.value.map((file: File) =>\n props.gallery.value\n ? html`\n <li class=\"file-card\">\n ${\n // Decorative: the file name is already announced via the visible\n // `.file-card-name` caption below — repeating it as `alt` text would\n // duplicate it (and often trips redundant-alt checks, since real\n // filenames commonly contain words like \"photo\" or \"image\").\n isImageFile(file)\n ? // Object URLs use the `blob:` scheme, which ore's attribute-level\n // XSS guard blocks unconditionally on `src` (and other\n // URL-accepting attributes) — set it as a DOM property via `ref`\n // instead, bypassing that string-based check. Safe here: the value\n // comes from `URL.createObjectURL(file)` on a real `File` object we\n // control, never from untrusted text.\n html`<img\n class=\"file-thumb\"\n alt=\"\"\n ref=\"${(el: HTMLImageElement | null) => {\n if (el) el.src = getPreviewUrl(file);\n }}\" />`\n : html`<span class=\"file-thumb file-thumb-generic\" aria-hidden=\"true\">\n <ore-icon name=\"file\" size=\"28\" stroke-width=\"1.5\" aria-hidden=\"true\"></ore-icon>\n </span>`\n }\n <span class=\"file-card-name\" title=\"${file.name}\">${file.name}</span>\n <button\n class=\"file-card-remove\"\n type=\"button\"\n aria-label=\"${`Remove ${file.name}`}\"\n @click=${(e: Event) => removeFile(file, e)}>\n <ore-icon name=\"x\" size=\"12\" stroke-width=\"2.5\" aria-hidden=\"true\"></ore-icon>\n </button>\n </li>\n `\n : html`\n <li class=\"file-item\">\n <span class=\"file-icon\" aria-hidden=\"true\">\n <ore-icon name=\"file\" size=\"18\" stroke-width=\"1.75\" aria-hidden=\"true\"></ore-icon>\n </span>\n <span class=\"file-meta\">\n <span class=\"file-name\" title=\"${file.name}\">${file.name}</span>\n <span class=\"file-size\">${formatBytes(file.size)}</span>\n </span>\n <button\n class=\"file-remove\"\n type=\"button\"\n aria-label=\"${`Remove ${file.name}`}\"\n @click=${(e: Event) => removeFile(file, e)}>\n <ore-icon name=\"x\" size=\"12\" stroke-width=\"2.5\" aria-hidden=\"true\"></ore-icon>\n </button>\n </li>\n `,\n )}\n </ul>\n <div class=\"helper-text\" id=\"${helperId}\" part=\"helper\" ?hidden=${() => isInvalid.value || !props.helper.value}>\n ${props.helper}\n </div>\n <div\n class=\"helper-text helper-text-error\"\n id=\"${errorId}\"\n role=\"alert\"\n part=\"error\"\n ?hidden=${() => !isInvalid.value}>\n ${() => props.error.value ?? ''}\n </div>\n </div>\n `;\n },\n shadow: { delegatesFocus: true },\n styles: [\n ...fieldMixins,\n sizeVariantMixin(FILE_INPUT_SIZE_PRESET),\n forcedColorsFocusMixin('.dropzone'),\n componentStyles,\n ],\n});\n"],"mappings":"seAwBA,IAAM,EAAe,GAAkB,CACrC,GAAI,IA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AA,iBAAiB,EAAA,sBAAsB,EACvC,EAAA,uBAAuB,WAAW,EAClC,EAAA,OACF,CACF,CAAC"}
|
package/dist/file-input.js
CHANGED
|
@@ -3,12 +3,11 @@ import { forcedColorsFocusMixin as t } from "./styles/mixins/theme.css.js";
|
|
|
3
3
|
import { fieldMixins as n } from "./styles/index.js";
|
|
4
4
|
import { FILE_INPUT_SIZE_PRESET as r } from "./shared/size-presets.js";
|
|
5
5
|
import { createInteraction as i } from "./headless/keyboard.js";
|
|
6
|
-
import {
|
|
7
|
-
import "./
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
10
|
-
import {
|
|
11
|
-
import { computed as x, signal as S, watch as C } from "@vielzeug/ripple";
|
|
6
|
+
import { FORM_CTX as a, useFormContext as o } from "./inputs/shared/form-context.js";
|
|
7
|
+
import s from "./inputs/file-input/file-input.css.js";
|
|
8
|
+
import { bind as c, createStableId as l, define as u, html as d, inject as f, onCleanup as p, onElement as m, onEvent as h, onMounted as g, prop as _, ref as v, useEmit as y } from "@vielzeug/ore";
|
|
9
|
+
import { computed as b, signal as x, watch as S } from "@vielzeug/ripple";
|
|
10
|
+
import { useField as C } from "@vielzeug/ore/forms";
|
|
12
11
|
import { createDropZone as w, matchesAccept as T } from "@vielzeug/dnd";
|
|
13
12
|
//#region src/inputs/file-input/file-input.ts
|
|
14
13
|
var E = (e) => {
|
|
@@ -22,28 +21,28 @@ var E = (e) => {
|
|
|
22
21
|
], r = Math.floor(Math.log(e) / Math.log(t));
|
|
23
22
|
return parseFloat((e / t ** r).toFixed(1)) + " " + n[r];
|
|
24
23
|
}, D = (e, t) => !t || e.size <= t, O = (e) => e.type.startsWith("image/"), k = "ore-file-input";
|
|
25
|
-
|
|
24
|
+
u(k, {
|
|
26
25
|
formAssociated: !0,
|
|
27
26
|
props: {
|
|
28
|
-
accept:
|
|
29
|
-
color:
|
|
30
|
-
disabled:
|
|
31
|
-
error:
|
|
32
|
-
gallery:
|
|
33
|
-
helper:
|
|
34
|
-
label:
|
|
35
|
-
"max-files":
|
|
36
|
-
"max-size":
|
|
37
|
-
multiple:
|
|
38
|
-
name:
|
|
39
|
-
ref:
|
|
40
|
-
required:
|
|
41
|
-
size:
|
|
27
|
+
accept: _.string(),
|
|
28
|
+
color: _.string(),
|
|
29
|
+
disabled: _.bool(!1),
|
|
30
|
+
error: _.string(),
|
|
31
|
+
gallery: _.bool(!1),
|
|
32
|
+
helper: _.string(),
|
|
33
|
+
label: _.string(),
|
|
34
|
+
"max-files": _.number(0),
|
|
35
|
+
"max-size": _.number(0),
|
|
36
|
+
multiple: _.bool(!1),
|
|
37
|
+
name: _.string(),
|
|
38
|
+
ref: _.json(void 0),
|
|
39
|
+
required: _.bool(!1),
|
|
40
|
+
size: _.string()
|
|
42
41
|
},
|
|
43
42
|
setup(e) {
|
|
44
|
-
let t =
|
|
45
|
-
|
|
46
|
-
disabled:
|
|
43
|
+
let t = y(), n = x([]), r = x(!1), s = o(e, f(a)), u = s.disabled, _ = b(() => e["max-files"].value ?? 0), k = b(() => e["max-size"].value ?? 0);
|
|
44
|
+
C({
|
|
45
|
+
disabled: u,
|
|
47
46
|
toFormValue: (t) => {
|
|
48
47
|
if (t.length === 0) return null;
|
|
49
48
|
let n = e.name.value || "file", r = new FormData();
|
|
@@ -52,27 +51,27 @@ d(k, {
|
|
|
52
51
|
},
|
|
53
52
|
value: n
|
|
54
53
|
});
|
|
55
|
-
let A =
|
|
56
|
-
|
|
54
|
+
let A = b(() => !!e.error.value);
|
|
55
|
+
c({ attr: {
|
|
57
56
|
"drag-over": () => r.value ? !0 : void 0,
|
|
58
57
|
invalid: () => A.value ? !0 : void 0,
|
|
59
|
-
size:
|
|
58
|
+
size: s.size
|
|
60
59
|
} });
|
|
61
|
-
let j =
|
|
60
|
+
let j = l("file-input"), M = `label-${j}`, N = `helper-${j}`, P = `error-${j}`, F = v(), I = v(), L = b(() => {
|
|
62
61
|
let t = [];
|
|
63
62
|
e.accept.value && t.push(e.accept.value.split(",").map((e) => e.trim()).join(", "));
|
|
64
63
|
let n = k.value;
|
|
65
64
|
n > 0 && t.push(`max ${E(n)}`);
|
|
66
|
-
let r =
|
|
65
|
+
let r = _.value;
|
|
67
66
|
return r > 0 && t.push(`up to ${r} file${r === 1 ? "" : "s"}`), t.join(" · ");
|
|
68
67
|
});
|
|
69
68
|
function R(r, i) {
|
|
70
|
-
if (
|
|
69
|
+
if (u.value) return;
|
|
71
70
|
let a = e.accept.value, o = !!e.multiple.value, s = Array.from(r);
|
|
72
71
|
o || (s = s.slice(0, 1)), s = s.filter((e) => T(e, a ? a.split(",").map((e) => e.trim()) : []) && D(e, k.value));
|
|
73
72
|
let c = o ? [...n.value] : [];
|
|
74
73
|
for (let e of s) c.includes(e) || c.push(e);
|
|
75
|
-
|
|
74
|
+
_.value > 0 && c.length > _.value && (c = c.slice(0, _.value)), n.value = c, t("change", {
|
|
76
75
|
files: n.value,
|
|
77
76
|
originalEvent: i,
|
|
78
77
|
value: n.value
|
|
@@ -99,48 +98,48 @@ d(k, {
|
|
|
99
98
|
let t = new Set(e);
|
|
100
99
|
for (let [e, n] of B) t.has(e) || (URL.revokeObjectURL(n), B.delete(e));
|
|
101
100
|
}
|
|
102
|
-
return
|
|
101
|
+
return S(n, H), p(() => {
|
|
103
102
|
for (let e of B.values()) URL.revokeObjectURL(e);
|
|
104
103
|
B.clear();
|
|
105
|
-
}),
|
|
104
|
+
}), m(I, (t) => {
|
|
106
105
|
e.ref.value?.(t);
|
|
107
|
-
let n =
|
|
106
|
+
let n = S(e.ref, (e) => {
|
|
108
107
|
e?.(t);
|
|
109
108
|
});
|
|
110
109
|
return () => {
|
|
111
110
|
n.dispose(), e.ref.value?.(null);
|
|
112
111
|
};
|
|
113
|
-
}),
|
|
112
|
+
}), g(() => {
|
|
114
113
|
let e = I.value, t = F.value, n = !1, a = i({
|
|
115
|
-
disabled:
|
|
114
|
+
disabled: u,
|
|
116
115
|
onPress: () => {
|
|
117
116
|
e.click();
|
|
118
117
|
}
|
|
119
118
|
});
|
|
120
|
-
|
|
119
|
+
h(e, "change", (e) => {
|
|
121
120
|
let t = e.target;
|
|
122
121
|
t.files?.length && R(Array.from(t.files), e), t.value = "";
|
|
123
|
-
}),
|
|
122
|
+
}), h(t, "click", (t) => {
|
|
124
123
|
if (t.target !== e) {
|
|
125
124
|
if (n) {
|
|
126
125
|
n = !1;
|
|
127
126
|
return;
|
|
128
127
|
}
|
|
129
|
-
|
|
128
|
+
u.value || e.click();
|
|
130
129
|
}
|
|
131
|
-
}),
|
|
130
|
+
}), h(t, "keydown", (e) => {
|
|
132
131
|
n = a.handleKeydown(e) && e.key === "Enter";
|
|
133
132
|
});
|
|
134
133
|
let o = w({
|
|
135
|
-
disabled:
|
|
134
|
+
disabled: u.value,
|
|
136
135
|
element: t,
|
|
137
136
|
onDrop: (e) => R(e),
|
|
138
137
|
onHoverChange: (e) => {
|
|
139
138
|
r.value = e;
|
|
140
139
|
}
|
|
141
140
|
});
|
|
142
|
-
|
|
143
|
-
}),
|
|
141
|
+
p(() => o.dispose());
|
|
142
|
+
}), d`
|
|
144
143
|
<div class="file-input-wrapper" part="wrapper">
|
|
145
144
|
<label class="label-outside" id="${M}" part="label" ?hidden=${() => !e.label.value}
|
|
146
145
|
>${e.label}</label
|
|
@@ -150,8 +149,8 @@ d(k, {
|
|
|
150
149
|
part="dropzone"
|
|
151
150
|
ref=${F}
|
|
152
151
|
role="button"
|
|
153
|
-
:tabindex="${() =>
|
|
154
|
-
:aria-disabled="${() => String(
|
|
152
|
+
:tabindex="${() => u.value ? "-1" : "0"}"
|
|
153
|
+
:aria-disabled="${() => String(u.value)}"
|
|
155
154
|
:aria-label="${() => e.label.value ? null : "File upload drop zone"}"
|
|
156
155
|
:aria-labelledby="${() => e.label.value ? M : null}"
|
|
157
156
|
aria-describedby="${N}">
|
|
@@ -163,7 +162,7 @@ d(k, {
|
|
|
163
162
|
:accept="${e.accept}"
|
|
164
163
|
?multiple="${e.multiple}"
|
|
165
164
|
?required="${e.required}"
|
|
166
|
-
?disabled="${
|
|
165
|
+
?disabled="${u}"
|
|
167
166
|
:name="${e.name}"
|
|
168
167
|
hidden
|
|
169
168
|
inert
|
|
@@ -182,14 +181,14 @@ d(k, {
|
|
|
182
181
|
role="list"
|
|
183
182
|
aria-label="Selected files"
|
|
184
183
|
?hidden=${() => n.value.length === 0}>
|
|
185
|
-
${() => n.value.map((t) => e.gallery.value ?
|
|
184
|
+
${() => n.value.map((t) => e.gallery.value ? d`
|
|
186
185
|
<li class="file-card">
|
|
187
|
-
${O(t) ?
|
|
186
|
+
${O(t) ? d`<img
|
|
188
187
|
class="file-thumb"
|
|
189
188
|
alt=""
|
|
190
189
|
ref="${(e) => {
|
|
191
190
|
e && (e.src = V(t));
|
|
192
|
-
}}" />` :
|
|
191
|
+
}}" />` : d`<span class="file-thumb file-thumb-generic" aria-hidden="true">
|
|
193
192
|
<ore-icon name="file" size="28" stroke-width="1.5" aria-hidden="true"></ore-icon>
|
|
194
193
|
</span>`}
|
|
195
194
|
<span class="file-card-name" title="${t.name}">${t.name}</span>
|
|
@@ -201,7 +200,7 @@ d(k, {
|
|
|
201
200
|
<ore-icon name="x" size="12" stroke-width="2.5" aria-hidden="true"></ore-icon>
|
|
202
201
|
</button>
|
|
203
202
|
</li>
|
|
204
|
-
` :
|
|
203
|
+
` : d`
|
|
205
204
|
<li class="file-item">
|
|
206
205
|
<span class="file-icon" aria-hidden="true">
|
|
207
206
|
<ore-icon name="file" size="18" stroke-width="1.75" aria-hidden="true"></ore-icon>
|
|
@@ -239,7 +238,7 @@ d(k, {
|
|
|
239
238
|
...n,
|
|
240
239
|
e(r),
|
|
241
240
|
t(".dropzone"),
|
|
242
|
-
|
|
241
|
+
s
|
|
243
242
|
]
|
|
244
243
|
});
|
|
245
244
|
//#endregion
|
package/dist/file-input.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-input.js","names":[],"sources":["../src/inputs/file-input/file-input.ts"],"sourcesContent":["import { createDropZone, matchesAccept } from '@vielzeug/dnd';\nimport {\n createStableId,\n define,\n html,\n inject,\n prop,\n ref,\n bind,\n onCleanup,\n onElement,\n onEvent,\n onMounted,\n useEmit,\n} from '@vielzeug/ore';\nimport { useField } from '@vielzeug/ore/forms';\nimport { computed, signal, watch } from '@vielzeug/ripple';\n\nimport { createInteraction } from '../../headless';\nimport { FILE_INPUT_SIZE_PRESET } from '../../shared';\nimport { fieldMixins, forcedColorsFocusMixin, sizeVariantMixin } from '../../styles';\nimport { FORM_CTX, useFormContext } from '../shared/form-context';\nimport componentStyles from './file-input.css?inline';\n\nconst formatBytes = (bytes: number) => {\n if (bytes === 0) return '0 B';\n\n const k = 1024;\n const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];\n const i = Math.floor(Math.log(bytes) / Math.log(k));\n\n return parseFloat((bytes / Math.pow(k, i)).toFixed(1)) + ' ' + sizes[i];\n};\n\nconst isFileSizeAllowed = (file: File, maxSize?: number) => !maxSize || file.size <= maxSize;\n\nconst isImageFile = (file: File): boolean => file.type.startsWith('image/');\n\n/** File input component properties */\nexport type OreFileInputProps = {\n /** Accepted file types (comma-separated, e.g. '.jpg, .png, image/*') */\n accept?: string;\n /** Theme color tint */\n color?: string;\n /** Disabled state */\n disabled?: boolean;\n /** Error message text */\n error?: string;\n /**\n * Render selected files as a grid of image thumbnails/previews instead of the default\n * single-column list. Non-image files fall back to a generic file icon in the same grid.\n */\n gallery?: boolean;\n /** Helper text displayed below the input */\n helper?: string;\n /** Input label text */\n label?: string;\n /** Max number of files allowed (only used if multiple is true) */\n 'max-files'?: number;\n /** Max size of a single file in bytes */\n 'max-size'?: number;\n /** Allow multiple files selection */\n multiple?: boolean;\n /** Form field name */\n name?: string;\n /**\n * JS-only callback fired with the inner `<input type=\"file\">` element when it\n * mounts, and with `null` when it unmounts. Intended for composed components\n * that need imperative access to the raw element.\n * Set as a JS property: `bitFileInput.ref = (el) => { ... }`.\n */\n ref?: ((el: HTMLInputElement | null) => void) | null;\n /** Required field */\n required?: boolean;\n /** Field size preset */\n size?: string;\n};\n\n/** Events emitted by the file-input component */\nexport type OreFileInputEvents = {\n /** Emitted when files are added or removed */\n change: { files: File[]; originalEvent?: Event; value: File[] };\n /** Emitted when a specific file is removed */\n remove: { file: File; files: File[]; originalEvent?: Event; value: File[] };\n};\n\n/**\n * A file upload field with drag-and-drop support and built-in validation messaging.\n *\n * @element ore-file-input\n *\n * @attr {string} accept - Comma-separated file extensions or MIME types\n * @attr {boolean} multiple - Enable multiple files selection\n * @attr {boolean} gallery - Show selected files as an image thumbnail/preview grid\n * @attr {number} max-files - Max number of files allowed\n * @attr {number} max-size - Max size of each file in bytes\n * @attr {boolean} disabled - Disable interaction\n * @attr {string} error - Show an error state/message\n * @attr {string} helper - Provide helper context below the dropzone\n *\n * @fires change - detail: { files: File[], value: File[] }\n * @fires remove - detail: { file: File, files: File[] }\n *\n * @cssprop --file-input-bg - Dropzone background color\n * @cssprop --file-input-border-color - Dropzone border color\n * @cssprop --file-input-font-size - Font size\n * @cssprop --file-input-radius - Dropzone border radius\n * @cssprop --file-input-min-height - Minimum dropzone height\n * @cssprop --file-input-hover-bg - Dropzone background on hover (flat/ghost variants)\n * @cssprop --file-input-hover-border-color - Dropzone border on hover (flat/bordered variants)\n * @cssprop --file-input-focus-bg - Dropzone background when focused/drag-over (flat variant)\n * @cssprop --file-input-focus-border-color - Dropzone border when focused/drag-over (flat variant)\n * @cssprop --file-input-thumb-size - Gallery thumbnail width/height\n * @part wrapper - Root wrapper around the file input field\n * @part label - Visible label rendered above the dropzone\n * @part dropzone - Interactive drag-and-drop target\n * @part input - Native file input element\n * @part gallery - Gallery grid container (rendered instead of `file-list` when `gallery` is set)\n * @part helper - Helper text shown beneath the dropzone\n * @part error - Error message shown beneath the field\n * @example\n * ```html\n * <ore-file-input label=\"Upload files\" accept=\"image/*\" multiple />\n * <ore-file-input label=\"Photos\" accept=\"image/*\" multiple gallery />\n * <ore-file-input label=\"Resume\" accept=\".pdf,.doc,.docx\" max-size=\"5242880\" />\n * <ore-file-input variant=\"bordered\" color=\"primary\" />\n * ```\n */\nexport const FILE_INPUT_TAG = 'ore-file-input' as const;\ndefine<OreFileInputProps>(FILE_INPUT_TAG, {\n formAssociated: true,\n props: {\n accept: prop.string(),\n color: prop.string(),\n disabled: prop.bool(false),\n error: prop.string(),\n gallery: prop.bool(false),\n helper: prop.string(),\n label: prop.string(),\n 'max-files': prop.number(0),\n 'max-size': prop.number(0),\n multiple: prop.bool(false),\n name: prop.string(),\n ref: prop.json(undefined as ((el: HTMLInputElement | null) => void) | null | undefined),\n required: prop.bool(false),\n size: prop.string(),\n },\n setup(props) {\n const emit = useEmit<OreFileInputEvents>();\n\n // ============================================\n // State\n // ============================================\n\n const files = signal<File[]>([]);\n const isDragging = signal(false);\n const formCtx = inject(FORM_CTX);\n const fCtxProps = useFormContext(props, formCtx);\n const isDisabled = fCtxProps.disabled;\n const maxFilesLimit = computed(() => props['max-files'].value ?? 0);\n const maxSizeLimit = computed(() => props['max-size'].value ?? 0);\n\n // ============================================\n // Form Integration\n // ============================================\n\n useField({\n disabled: isDisabled,\n toFormValue: (fi: File[]) => {\n if (fi.length === 0) return null;\n\n const name = props.name.value || 'file';\n const fd = new FormData();\n\n for (const file of fi) fd.append(name, file);\n\n return fd;\n },\n value: files,\n });\n\n // Sync host attributes for CSS selectors\n const isInvalid = computed(() => Boolean(props.error.value));\n\n bind({\n attr: {\n 'drag-over': () => (isDragging.value ? true : undefined),\n invalid: () => (isInvalid.value ? true : undefined),\n size: fCtxProps.size,\n },\n });\n\n // ============================================\n // IDs\n // ============================================\n const fileInputId = createStableId('file-input');\n const labelId = `label-${fileInputId}`;\n const helperId = `helper-${fileInputId}`;\n const errorId = `error-${fileInputId}`;\n\n // ============================================\n // Refs\n // ============================================\n const dropzoneRef = ref<HTMLDivElement>();\n const inputRef = ref<HTMLInputElement>();\n const hintText = computed(() => {\n const parts: string[] = [];\n\n if (props.accept.value) {\n parts.push(\n props.accept.value\n .split(',')\n .map((s: string) => s.trim())\n .join(', '),\n );\n }\n\n const maxSize = maxSizeLimit.value;\n\n if (maxSize > 0) parts.push(`max ${formatBytes(maxSize)}`);\n\n const maxFiles = maxFilesLimit.value;\n\n if (maxFiles > 0) parts.push(`up to ${maxFiles} file${maxFiles !== 1 ? 's' : ''}`);\n\n return parts.join(' · ');\n });\n\n // ============================================\n // File Management\n // ============================================\n function addFiles(newFiles: File[], originalEvent?: Event): void {\n if (isDisabled.value) return;\n\n const acceptVal = props.accept.value;\n const isMultiple = Boolean(props.multiple.value);\n let incoming = Array.from(newFiles);\n\n if (!isMultiple) incoming = incoming.slice(0, 1);\n\n incoming = incoming.filter(\n (f) =>\n matchesAccept(f, acceptVal ? acceptVal.split(',').map((t) => t.trim()) : []) &&\n isFileSizeAllowed(f, maxSizeLimit.value),\n );\n\n let updated: File[] = isMultiple ? [...files.value] : [];\n\n for (const f of incoming) {\n if (!updated.includes(f)) updated.push(f);\n }\n\n if (maxFilesLimit.value > 0 && updated.length > maxFilesLimit.value) {\n updated = updated.slice(0, maxFilesLimit.value);\n }\n\n files.value = updated;\n emit('change', { files: files.value, originalEvent, value: files.value });\n }\n function removeFile(file: File, originalEvent?: Event): void {\n files.value = files.value.filter((f) => f !== file);\n emit('remove', { file, files: files.value, originalEvent, value: files.value });\n emit('change', { files: files.value, originalEvent, value: files.value });\n }\n\n // ============================================\n // Gallery Preview URLs\n // ============================================\n // Object URLs are created lazily (only while `gallery` is enabled) and revoked as soon\n // as their file is no longer selected, plus unconditionally on disconnect — otherwise\n // each preview leaks its backing blob for the life of the page.\n const previewUrls = new Map<File, string>();\n\n function getPreviewUrl(file: File): string {\n let url = previewUrls.get(file);\n\n if (!url) {\n url = URL.createObjectURL(file);\n previewUrls.set(file, url);\n }\n\n return url;\n }\n\n function revokeStalePreviewUrls(activeFiles: File[]): void {\n const keep = new Set(activeFiles);\n\n for (const [file, url] of previewUrls) {\n if (!keep.has(file)) {\n URL.revokeObjectURL(url);\n previewUrls.delete(file);\n }\n }\n }\n\n watch(files, revokeStalePreviewUrls);\n\n onCleanup(() => {\n for (const url of previewUrls.values()) URL.revokeObjectURL(url);\n\n previewUrls.clear();\n });\n\n // ============================================\n // Mount\n // ============================================\n // ============================================\n // Template\n // ============================================\n onElement(inputRef, (inp) => {\n props.ref.value?.(inp);\n\n const sub = watch(props.ref, (cb) => {\n cb?.(inp);\n });\n\n return () => {\n sub.dispose();\n props.ref.value?.(null);\n };\n });\n\n onMounted(() => {\n const inp = inputRef.value!;\n const dz = dropzoneRef.value!;\n let skipNextClick = false;\n const pressControl = createInteraction({\n disabled: isDisabled,\n onPress: () => {\n inp.click();\n },\n });\n\n // Native input → add files\n onEvent(inp, 'change', (e: Event) => {\n const input = e.target as HTMLInputElement;\n\n if (input.files?.length) addFiles(Array.from(input.files), e);\n\n input.value = ''; // reset so the same file triggers change again\n });\n // Click dropzone → open file picker\n onEvent(dz, 'click', (e: MouseEvent) => {\n if (e.target === inp) return;\n\n if (skipNextClick) {\n skipNextClick = false;\n\n return;\n }\n\n if (!isDisabled.value) inp.click();\n });\n // Keyboard: Enter / Space → open picker\n onEvent(dz, 'keydown', (e: KeyboardEvent) => {\n skipNextClick = pressControl.handleKeydown(e) && e.key === 'Enter';\n });\n\n const dropZone = createDropZone({\n disabled: isDisabled.value,\n element: dz,\n onDrop: (droppedFiles) => addFiles(droppedFiles),\n onHoverChange: (hovered) => {\n isDragging.value = hovered;\n },\n });\n\n onCleanup(() => dropZone.dispose());\n });\n\n return html`\n <div class=\"file-input-wrapper\" part=\"wrapper\">\n <label class=\"label-outside\" id=\"${labelId}\" part=\"label\" ?hidden=${() => !props.label.value}\n >${props.label}</label\n >\n <div\n class=\"dropzone\"\n part=\"dropzone\"\n ref=${dropzoneRef}\n role=\"button\"\n :tabindex=\"${() => (isDisabled.value ? '-1' : '0')}\"\n :aria-disabled=\"${() => String(isDisabled.value)}\"\n :aria-label=\"${() => (!props.label.value ? 'File upload drop zone' : null)}\"\n :aria-labelledby=\"${() => (props.label.value ? labelId : null)}\"\n aria-describedby=\"${helperId}\">\n <input\n type=\"file\"\n ref=${inputRef}\n part=\"input\"\n id=\"${fileInputId}\"\n :accept=\"${props.accept}\"\n ?multiple=\"${props.multiple}\"\n ?required=\"${props.required}\"\n ?disabled=\"${isDisabled}\"\n :name=\"${props.name}\"\n hidden\n inert\n tabindex=\"-1\" />\n <div class=\"dropzone-content\">\n <span class=\"dropzone-icon\" aria-hidden=\"true\">\n <ore-icon name=\"upload\" size=\"36\" stroke-width=\"1.5\" aria-hidden=\"true\"></ore-icon>\n </span>\n <span class=\"dropzone-title\">Drop files here or <u>click to browse</u></span>\n <span class=\"dropzone-hint\" ?hidden=${() => !hintText.value}>${hintText}</span>\n </div>\n </div>\n <ul\n class=\"${() => (props.gallery.value ? 'file-grid' : 'file-list')}\"\n part=\"${() => (props.gallery.value ? 'gallery' : null)}\"\n role=\"list\"\n aria-label=\"Selected files\"\n ?hidden=${() => files.value.length === 0}>\n ${() =>\n files.value.map((file: File) =>\n props.gallery.value\n ? html`\n <li class=\"file-card\">\n ${\n // Decorative: the file name is already announced via the visible\n // `.file-card-name` caption below — repeating it as `alt` text would\n // duplicate it (and often trips redundant-alt checks, since real\n // filenames commonly contain words like \"photo\" or \"image\").\n isImageFile(file)\n ? // Object URLs use the `blob:` scheme, which ore's attribute-level\n // XSS guard blocks unconditionally on `src` (and other\n // URL-accepting attributes) — set it as a DOM property via `ref`\n // instead, bypassing that string-based check. Safe here: the value\n // comes from `URL.createObjectURL(file)` on a real `File` object we\n // control, never from untrusted text.\n html`<img\n class=\"file-thumb\"\n alt=\"\"\n ref=\"${(el: HTMLImageElement | null) => {\n if (el) el.src = getPreviewUrl(file);\n }}\" />`\n : html`<span class=\"file-thumb file-thumb-generic\" aria-hidden=\"true\">\n <ore-icon name=\"file\" size=\"28\" stroke-width=\"1.5\" aria-hidden=\"true\"></ore-icon>\n </span>`\n }\n <span class=\"file-card-name\" title=\"${file.name}\">${file.name}</span>\n <button\n class=\"file-card-remove\"\n type=\"button\"\n aria-label=\"${`Remove ${file.name}`}\"\n @click=${(e: Event) => removeFile(file, e)}>\n <ore-icon name=\"x\" size=\"12\" stroke-width=\"2.5\" aria-hidden=\"true\"></ore-icon>\n </button>\n </li>\n `\n : html`\n <li class=\"file-item\">\n <span class=\"file-icon\" aria-hidden=\"true\">\n <ore-icon name=\"file\" size=\"18\" stroke-width=\"1.75\" aria-hidden=\"true\"></ore-icon>\n </span>\n <span class=\"file-meta\">\n <span class=\"file-name\" title=\"${file.name}\">${file.name}</span>\n <span class=\"file-size\">${formatBytes(file.size)}</span>\n </span>\n <button\n class=\"file-remove\"\n type=\"button\"\n aria-label=\"${`Remove ${file.name}`}\"\n @click=${(e: Event) => removeFile(file, e)}>\n <ore-icon name=\"x\" size=\"12\" stroke-width=\"2.5\" aria-hidden=\"true\"></ore-icon>\n </button>\n </li>\n `,\n )}\n </ul>\n <div class=\"helper-text\" id=\"${helperId}\" part=\"helper\" ?hidden=${() => isInvalid.value || !props.helper.value}>\n ${props.helper}\n </div>\n <div\n class=\"helper-text helper-text-error\"\n id=\"${errorId}\"\n role=\"alert\"\n part=\"error\"\n ?hidden=${() => !isInvalid.value}>\n ${() => props.error.value ?? ''}\n </div>\n </div>\n `;\n },\n shadow: { delegatesFocus: true },\n styles: [\n ...fieldMixins,\n sizeVariantMixin(FILE_INPUT_SIZE_PRESET),\n forcedColorsFocusMixin('.dropzone'),\n componentStyles,\n ],\n});\n"],"mappings":";;;;;;;;;;;;;AAwBA,IAAM,KAAe,MAAkB;CACrC,IAAI,MAAU,GAAG,OAAO;CAExB,IAAM,IAAI,MACJ,IAAQ;EAAC;EAAK;EAAM;EAAM;EAAM;CAAI,GACpC,IAAI,KAAK,MAAM,KAAK,IAAI,CAAK,IAAI,KAAK,IAAI,CAAC,CAAC;CAElD,OAAO,YAAY,IAAiB,KAAG,EAAC,CAAG,QAAQ,CAAC,CAAC,IAAI,MAAM,EAAM;AACvE,GAEM,KAAqB,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,EAAK,KAAK;;;;sCAI9C,UAAU,EAAK,OAAO;kCAC1B,MAAa,EAAW,GAAM,CAAC,EAAE;;;;sBAKjD,CAAI;;;;;;yDAMmC,EAAK,KAAK,IAAI,EAAK,KAAK;kDAC/B,EAAY,EAAK,IAAI,EAAE;;;;;sCAKnC,UAAU,EAAK,OAAO;kCAC1B,MAAa,EAAW,GAAM,CAAC,EAAE;;;;mBAKvD,EAAE;;uCAEyB,EAAS,gCAAgC,EAAU,SAAS,CAAC,EAAM,OAAO,MAAM;YAC3G,EAAM,OAAO;;;;gBAIT,EAAQ;;;0BAGE,CAAC,EAAU,MAAM;kBACzB,EAAM,MAAM,SAAS,GAAG;;;;CAIxC;CACA,QAAQ,EAAE,gBAAgB,GAAK;CAC/B,QAAQ;EACN,GAAG;EACH,EAAiB,CAAsB;EACvC,EAAuB,WAAW;EAClC;CACF;AACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"file-input.js","names":[],"sources":["../src/inputs/file-input/file-input.ts"],"sourcesContent":["import { createDropZone, matchesAccept } from '@vielzeug/dnd';\nimport {\n createStableId,\n define,\n html,\n inject,\n prop,\n ref,\n bind,\n onCleanup,\n onElement,\n onEvent,\n onMounted,\n useEmit,\n} from '@vielzeug/ore';\nimport { useField } from '@vielzeug/ore/forms';\nimport { computed, signal, watch } from '@vielzeug/ripple';\n\nimport { createInteraction } from '../../headless';\nimport { FILE_INPUT_SIZE_PRESET } from '../../shared';\nimport { fieldMixins, forcedColorsFocusMixin, sizeVariantMixin } from '../../styles';\nimport { FORM_CTX, useFormContext } from '../shared/form-context';\nimport componentStyles from './file-input.css?inline';\n\nconst formatBytes = (bytes: number) => {\n if (bytes === 0) return '0 B';\n\n const k = 1024;\n const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];\n const i = Math.floor(Math.log(bytes) / Math.log(k));\n\n return parseFloat((bytes / Math.pow(k, i)).toFixed(1)) + ' ' + sizes[i];\n};\n\nconst isFileSizeAllowed = (file: File, maxSize?: number) => !maxSize || file.size <= maxSize;\n\nconst isImageFile = (file: File): boolean => file.type.startsWith('image/');\n\n/** File input component properties */\nexport type OreFileInputProps = {\n /** Accepted file types (comma-separated, e.g. '.jpg, .png, image/*') */\n accept?: string;\n /** Theme color tint */\n color?: string;\n /** Disabled state */\n disabled?: boolean;\n /** Error message text */\n error?: string;\n /**\n * Render selected files as a grid of image thumbnails/previews instead of the default\n * single-column list. Non-image files fall back to a generic file icon in the same grid.\n */\n gallery?: boolean;\n /** Helper text displayed below the input */\n helper?: string;\n /** Input label text */\n label?: string;\n /** Max number of files allowed (only used if multiple is true) */\n 'max-files'?: number;\n /** Max size of a single file in bytes */\n 'max-size'?: number;\n /** Allow multiple files selection */\n multiple?: boolean;\n /** Form field name */\n name?: string;\n /**\n * JS-only callback fired with the inner `<input type=\"file\">` element when it\n * mounts, and with `null` when it unmounts. Intended for composed components\n * that need imperative access to the raw element.\n * Set as a JS property: `bitFileInput.ref = (el) => { ... }`.\n */\n ref?: ((el: HTMLInputElement | null) => void) | null;\n /** Required field */\n required?: boolean;\n /** Field size preset */\n size?: string;\n};\n\n/** Events emitted by the file-input component */\nexport type OreFileInputEvents = {\n /** Emitted when files are added or removed */\n change: { files: File[]; originalEvent?: Event; value: File[] };\n /** Emitted when a specific file is removed */\n remove: { file: File; files: File[]; originalEvent?: Event; value: File[] };\n};\n\n/**\n * A file upload field with drag-and-drop support and built-in validation messaging.\n *\n * @element ore-file-input\n *\n * @attr {string} accept - Comma-separated file extensions or MIME types\n * @attr {boolean} multiple - Enable multiple files selection\n * @attr {boolean} gallery - Show selected files as an image thumbnail/preview grid\n * @attr {number} max-files - Max number of files allowed\n * @attr {number} max-size - Max size of each file in bytes\n * @attr {boolean} disabled - Disable interaction\n * @attr {string} error - Show an error state/message\n * @attr {string} helper - Provide helper context below the dropzone\n *\n * @fires change - detail: { files: File[], value: File[] }\n * @fires remove - detail: { file: File, files: File[] }\n *\n * @cssprop --file-input-bg - Dropzone background color\n * @cssprop --file-input-border-color - Dropzone border color\n * @cssprop --file-input-font-size - Font size\n * @cssprop --file-input-radius - Dropzone border radius\n * @cssprop --file-input-min-height - Minimum dropzone height\n * @cssprop --file-input-hover-bg - Dropzone background on hover (flat/ghost variants)\n * @cssprop --file-input-hover-border-color - Dropzone border on hover (flat/bordered variants)\n * @cssprop --file-input-focus-bg - Dropzone background when focused/drag-over (flat variant)\n * @cssprop --file-input-focus-border-color - Dropzone border when focused/drag-over (flat variant)\n * @cssprop --file-input-thumb-size - Gallery thumbnail width/height\n * @part wrapper - Root wrapper around the file input field\n * @part label - Visible label rendered above the dropzone\n * @part dropzone - Interactive drag-and-drop target\n * @part input - Native file input element\n * @part gallery - Gallery grid container (rendered instead of `file-list` when `gallery` is set)\n * @part helper - Helper text shown beneath the dropzone\n * @part error - Error message shown beneath the field\n * @example\n * ```html\n * <ore-file-input label=\"Upload files\" accept=\"image/*\" multiple />\n * <ore-file-input label=\"Photos\" accept=\"image/*\" multiple gallery />\n * <ore-file-input label=\"Resume\" accept=\".pdf,.doc,.docx\" max-size=\"5242880\" />\n * <ore-file-input variant=\"bordered\" color=\"primary\" />\n * ```\n */\nexport const FILE_INPUT_TAG = 'ore-file-input' as const;\ndefine<OreFileInputProps>(FILE_INPUT_TAG, {\n formAssociated: true,\n props: {\n accept: prop.string(),\n color: prop.string(),\n disabled: prop.bool(false),\n error: prop.string(),\n gallery: prop.bool(false),\n helper: prop.string(),\n label: prop.string(),\n 'max-files': prop.number(0),\n 'max-size': prop.number(0),\n multiple: prop.bool(false),\n name: prop.string(),\n ref: prop.json(undefined as ((el: HTMLInputElement | null) => void) | null | undefined),\n required: prop.bool(false),\n size: prop.string(),\n },\n setup(props) {\n const emit = useEmit<OreFileInputEvents>();\n\n // ============================================\n // State\n // ============================================\n\n const files = signal<File[]>([]);\n const isDragging = signal(false);\n const formCtx = inject(FORM_CTX);\n const fCtxProps = useFormContext(props, formCtx);\n const isDisabled = fCtxProps.disabled;\n const maxFilesLimit = computed(() => props['max-files'].value ?? 0);\n const maxSizeLimit = computed(() => props['max-size'].value ?? 0);\n\n // ============================================\n // Form Integration\n // ============================================\n\n useField({\n disabled: isDisabled,\n toFormValue: (fi: File[]) => {\n if (fi.length === 0) return null;\n\n const name = props.name.value || 'file';\n const fd = new FormData();\n\n for (const file of fi) fd.append(name, file);\n\n return fd;\n },\n value: files,\n });\n\n // Sync host attributes for CSS selectors\n const isInvalid = computed(() => Boolean(props.error.value));\n\n bind({\n attr: {\n 'drag-over': () => (isDragging.value ? true : undefined),\n invalid: () => (isInvalid.value ? true : undefined),\n size: fCtxProps.size,\n },\n });\n\n // ============================================\n // IDs\n // ============================================\n const fileInputId = createStableId('file-input');\n const labelId = `label-${fileInputId}`;\n const helperId = `helper-${fileInputId}`;\n const errorId = `error-${fileInputId}`;\n\n // ============================================\n // Refs\n // ============================================\n const dropzoneRef = ref<HTMLDivElement>();\n const inputRef = ref<HTMLInputElement>();\n const hintText = computed(() => {\n const parts: string[] = [];\n\n if (props.accept.value) {\n parts.push(\n props.accept.value\n .split(',')\n .map((s: string) => s.trim())\n .join(', '),\n );\n }\n\n const maxSize = maxSizeLimit.value;\n\n if (maxSize > 0) parts.push(`max ${formatBytes(maxSize)}`);\n\n const maxFiles = maxFilesLimit.value;\n\n if (maxFiles > 0) parts.push(`up to ${maxFiles} file${maxFiles !== 1 ? 's' : ''}`);\n\n return parts.join(' · ');\n });\n\n // ============================================\n // File Management\n // ============================================\n function addFiles(newFiles: File[], originalEvent?: Event): void {\n if (isDisabled.value) return;\n\n const acceptVal = props.accept.value;\n const isMultiple = Boolean(props.multiple.value);\n let incoming = Array.from(newFiles);\n\n if (!isMultiple) incoming = incoming.slice(0, 1);\n\n incoming = incoming.filter(\n (f) =>\n matchesAccept(f, acceptVal ? acceptVal.split(',').map((t) => t.trim()) : []) &&\n isFileSizeAllowed(f, maxSizeLimit.value),\n );\n\n let updated: File[] = isMultiple ? [...files.value] : [];\n\n for (const f of incoming) {\n if (!updated.includes(f)) updated.push(f);\n }\n\n if (maxFilesLimit.value > 0 && updated.length > maxFilesLimit.value) {\n updated = updated.slice(0, maxFilesLimit.value);\n }\n\n files.value = updated;\n emit('change', { files: files.value, originalEvent, value: files.value });\n }\n function removeFile(file: File, originalEvent?: Event): void {\n files.value = files.value.filter((f) => f !== file);\n emit('remove', { file, files: files.value, originalEvent, value: files.value });\n emit('change', { files: files.value, originalEvent, value: files.value });\n }\n\n // ============================================\n // Gallery Preview URLs\n // ============================================\n // Object URLs are created lazily (only while `gallery` is enabled) and revoked as soon\n // as their file is no longer selected, plus unconditionally on disconnect — otherwise\n // each preview leaks its backing blob for the life of the page.\n const previewUrls = new Map<File, string>();\n\n function getPreviewUrl(file: File): string {\n let url = previewUrls.get(file);\n\n if (!url) {\n url = URL.createObjectURL(file);\n previewUrls.set(file, url);\n }\n\n return url;\n }\n\n function revokeStalePreviewUrls(activeFiles: File[]): void {\n const keep = new Set(activeFiles);\n\n for (const [file, url] of previewUrls) {\n if (!keep.has(file)) {\n URL.revokeObjectURL(url);\n previewUrls.delete(file);\n }\n }\n }\n\n watch(files, revokeStalePreviewUrls);\n\n onCleanup(() => {\n for (const url of previewUrls.values()) URL.revokeObjectURL(url);\n\n previewUrls.clear();\n });\n\n // ============================================\n // Mount\n // ============================================\n // ============================================\n // Template\n // ============================================\n onElement(inputRef, (inp) => {\n props.ref.value?.(inp);\n\n const sub = watch(props.ref, (cb) => {\n cb?.(inp);\n });\n\n return () => {\n sub.dispose();\n props.ref.value?.(null);\n };\n });\n\n onMounted(() => {\n const inp = inputRef.value!;\n const dz = dropzoneRef.value!;\n let skipNextClick = false;\n const pressControl = createInteraction({\n disabled: isDisabled,\n onPress: () => {\n inp.click();\n },\n });\n\n // Native input → add files\n onEvent(inp, 'change', (e: Event) => {\n const input = e.target as HTMLInputElement;\n\n if (input.files?.length) addFiles(Array.from(input.files), e);\n\n input.value = ''; // reset so the same file triggers change again\n });\n // Click dropzone → open file picker\n onEvent(dz, 'click', (e: MouseEvent) => {\n if (e.target === inp) return;\n\n if (skipNextClick) {\n skipNextClick = false;\n\n return;\n }\n\n if (!isDisabled.value) inp.click();\n });\n // Keyboard: Enter / Space → open picker\n onEvent(dz, 'keydown', (e: KeyboardEvent) => {\n skipNextClick = pressControl.handleKeydown(e) && e.key === 'Enter';\n });\n\n const dropZone = createDropZone({\n disabled: isDisabled.value,\n element: dz,\n onDrop: (droppedFiles) => addFiles(droppedFiles),\n onHoverChange: (hovered) => {\n isDragging.value = hovered;\n },\n });\n\n onCleanup(() => dropZone.dispose());\n });\n\n return html`\n <div class=\"file-input-wrapper\" part=\"wrapper\">\n <label class=\"label-outside\" id=\"${labelId}\" part=\"label\" ?hidden=${() => !props.label.value}\n >${props.label}</label\n >\n <div\n class=\"dropzone\"\n part=\"dropzone\"\n ref=${dropzoneRef}\n role=\"button\"\n :tabindex=\"${() => (isDisabled.value ? '-1' : '0')}\"\n :aria-disabled=\"${() => String(isDisabled.value)}\"\n :aria-label=\"${() => (!props.label.value ? 'File upload drop zone' : null)}\"\n :aria-labelledby=\"${() => (props.label.value ? labelId : null)}\"\n aria-describedby=\"${helperId}\">\n <input\n type=\"file\"\n ref=${inputRef}\n part=\"input\"\n id=\"${fileInputId}\"\n :accept=\"${props.accept}\"\n ?multiple=\"${props.multiple}\"\n ?required=\"${props.required}\"\n ?disabled=\"${isDisabled}\"\n :name=\"${props.name}\"\n hidden\n inert\n tabindex=\"-1\" />\n <div class=\"dropzone-content\">\n <span class=\"dropzone-icon\" aria-hidden=\"true\">\n <ore-icon name=\"upload\" size=\"36\" stroke-width=\"1.5\" aria-hidden=\"true\"></ore-icon>\n </span>\n <span class=\"dropzone-title\">Drop files here or <u>click to browse</u></span>\n <span class=\"dropzone-hint\" ?hidden=${() => !hintText.value}>${hintText}</span>\n </div>\n </div>\n <ul\n class=\"${() => (props.gallery.value ? 'file-grid' : 'file-list')}\"\n part=\"${() => (props.gallery.value ? 'gallery' : null)}\"\n role=\"list\"\n aria-label=\"Selected files\"\n ?hidden=${() => files.value.length === 0}>\n ${() =>\n files.value.map((file: File) =>\n props.gallery.value\n ? html`\n <li class=\"file-card\">\n ${\n // Decorative: the file name is already announced via the visible\n // `.file-card-name` caption below — repeating it as `alt` text would\n // duplicate it (and often trips redundant-alt checks, since real\n // filenames commonly contain words like \"photo\" or \"image\").\n isImageFile(file)\n ? // Object URLs use the `blob:` scheme, which ore's attribute-level\n // XSS guard blocks unconditionally on `src` (and other\n // URL-accepting attributes) — set it as a DOM property via `ref`\n // instead, bypassing that string-based check. Safe here: the value\n // comes from `URL.createObjectURL(file)` on a real `File` object we\n // control, never from untrusted text.\n html`<img\n class=\"file-thumb\"\n alt=\"\"\n ref=\"${(el: HTMLImageElement | null) => {\n if (el) el.src = getPreviewUrl(file);\n }}\" />`\n : html`<span class=\"file-thumb file-thumb-generic\" aria-hidden=\"true\">\n <ore-icon name=\"file\" size=\"28\" stroke-width=\"1.5\" aria-hidden=\"true\"></ore-icon>\n </span>`\n }\n <span class=\"file-card-name\" title=\"${file.name}\">${file.name}</span>\n <button\n class=\"file-card-remove\"\n type=\"button\"\n aria-label=\"${`Remove ${file.name}`}\"\n @click=${(e: Event) => removeFile(file, e)}>\n <ore-icon name=\"x\" size=\"12\" stroke-width=\"2.5\" aria-hidden=\"true\"></ore-icon>\n </button>\n </li>\n `\n : html`\n <li class=\"file-item\">\n <span class=\"file-icon\" aria-hidden=\"true\">\n <ore-icon name=\"file\" size=\"18\" stroke-width=\"1.75\" aria-hidden=\"true\"></ore-icon>\n </span>\n <span class=\"file-meta\">\n <span class=\"file-name\" title=\"${file.name}\">${file.name}</span>\n <span class=\"file-size\">${formatBytes(file.size)}</span>\n </span>\n <button\n class=\"file-remove\"\n type=\"button\"\n aria-label=\"${`Remove ${file.name}`}\"\n @click=${(e: Event) => removeFile(file, e)}>\n <ore-icon name=\"x\" size=\"12\" stroke-width=\"2.5\" aria-hidden=\"true\"></ore-icon>\n </button>\n </li>\n `,\n )}\n </ul>\n <div class=\"helper-text\" id=\"${helperId}\" part=\"helper\" ?hidden=${() => isInvalid.value || !props.helper.value}>\n ${props.helper}\n </div>\n <div\n class=\"helper-text helper-text-error\"\n id=\"${errorId}\"\n role=\"alert\"\n part=\"error\"\n ?hidden=${() => !isInvalid.value}>\n ${() => props.error.value ?? ''}\n </div>\n </div>\n `;\n },\n shadow: { delegatesFocus: true },\n styles: [\n ...fieldMixins,\n sizeVariantMixin(FILE_INPUT_SIZE_PRESET),\n forcedColorsFocusMixin('.dropzone'),\n componentStyles,\n ],\n});\n"],"mappings":";;;;;;;;;;;;AAwBA,IAAM,KAAe,MAAkB;CACrC,IAAI,MAAU,GAAG,OAAO;CAExB,IAAM,IAAI,MACJ,IAAQ;EAAC;EAAK;EAAM;EAAM;EAAM;CAAI,GACpC,IAAI,KAAK,MAAM,KAAK,IAAI,CAAK,IAAI,KAAK,IAAI,CAAC,CAAC;CAElD,OAAO,YAAY,IAAiB,KAAG,EAAC,CAAG,QAAQ,CAAC,CAAC,IAAI,MAAM,EAAM;AACvE,GAEM,KAAqB,GAAY,MAAqB,CAAC,KAAW,EAAK,QAAQ,GAE/E,KAAe,MAAwB,EAAK,KAAK,WAAW,QAAQ,GA4F7D,IAAiB;AAC9B,EAA0B,GAAgB;CACxC,gBAAgB;CAChB,OAAO;EACL,QAAQ,EAAK,OAAO;EACpB,OAAO,EAAK,OAAO;EACnB,UAAU,EAAK,KAAK,EAAK;EACzB,OAAO,EAAK,OAAO;EACnB,SAAS,EAAK,KAAK,EAAK;EACxB,QAAQ,EAAK,OAAO;EACpB,OAAO,EAAK,OAAO;EACnB,aAAa,EAAK,OAAO,CAAC;EAC1B,YAAY,EAAK,OAAO,CAAC;EACzB,UAAU,EAAK,KAAK,EAAK;EACzB,MAAM,EAAK,OAAO;EAClB,KAAK,EAAK,KAAK,KAAA,CAAuE;EACtF,UAAU,EAAK,KAAK,EAAK;EACzB,MAAM,EAAK,OAAO;CACpB;CACA,MAAM,GAAO;EACX,IAAM,IAAO,EAA4B,GAMnC,IAAQ,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|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./layout/grid/grid.css.cjs");let t=require("@vielzeug/ore"),n=require("@vielzeug/ore/observers");var r=[[`cols2xl`,`--size-screen-2xl`],[`colsXl`,`--size-screen-xl`],[`colsLg`,`--size-screen-lg`],[`colsMd`,`--size-screen-md`],[`colsSm`,`--size-screen-sm`]],i=[[`areas2xl`,`--size-screen-2xl`],[`areasXl`,`--size-screen-xl`],[`areasLg`,`--size-screen-lg`],[`areasMd`,`--size-screen-md`],[`areasSm`,`--size-screen-sm`]],a=(e,t,n)=>{let r=getComputedStyle(e).getPropertyValue(t).trim(),i=Number.parseFloat(r);return Number.isFinite(i)?i:n},o={"--size-screen-2xl":1536,"--size-screen-lg":1024,"--size-screen-md":768,"--size-screen-sm":640,"--size-screen-xl":1280},s=`ore-grid`;(0,t.define)(s,{props:{align:t.prop.string(),areas:t.prop.string(),areas2xl:t.prop.string(),areasLg:t.prop.string(),areasMd:t.prop.string(),areasSm:t.prop.string(),areasXl:t.prop.string(),cols:t.prop.string(),cols2xl:t.prop.string(),colsLg:t.prop.string(),colsMd:t.prop.string(),colsSm:t.prop.string(),colsXl:t.prop.string(),flow:t.prop.string(),fullwidth:t.prop.bool(!1),gap:t.prop.string(),justify:t.prop.string(),minColWidth:t.prop.string(),responsive:t.prop.bool(!1),rows:t.prop.string()},setup(e){let s=(0,t.getHost)(),c=t.watchEffect,l=(e,t,n)=>e===`auto`||!e&&t?`repeat(auto-fit, minmax(${n||`250px`}, 1fr))`:e?`repeat(${e}, 1fr)`:null,u=()=>{let t=s.offsetWidth,n=!!e.responsive.value,i=e.minColWidth.value??``,c;for(let[n,i]of r)if(t>=a(s,i,o[i])&&e[n].value){c=e[n].value;break}c||=e.cols.value||void 0;let u=l(c,n,i);u?s.style.setProperty(`--_cols`,u):s.style.removeProperty(`--_cols`)};c(()=>{e.cols.value,e.colsSm.value,e.colsMd.value,e.colsLg.value,e.colsXl.value,e.cols2xl.value,e.responsive.value,e.minColWidth.value,u()});let d=()=>{let t=s.offsetWidth,n=``;for(let[r,c]of i)if(t>=a(s,c,o[c])&&e[r].value){n=e[r].value;break}n||=e.areas.value||``,n?s.style.setProperty(`grid-template-areas`,n):s.style.removeProperty(`grid-template-areas`)};return c(()=>{let t=e.rows.value;t&&t!==`auto`?s.style.setProperty(`--_rows`,`repeat(${t}, 1fr)`):s.style.removeProperty(`--_rows`)}),c(()=>{e.areas.value,e.areasSm.value,e.areasMd.value,e.areasLg.value,e.areasXl.value,e.areas2xl.value,d()}),(0,t.onMounted)(()=>{let e=(0,n.resizeObserver)(s);c(()=>{e.value,u(),d()})}),t.html`<slot></slot>`},styles:[e.default]}),exports.GRID_TAG=s;
|
|
2
2
|
//# sourceMappingURL=grid.cjs.map
|
package/dist/grid.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grid.cjs","names":[],"sources":["../src/layout/grid/grid.ts"],"sourcesContent":["import { define, html, prop, getHost, onMounted, watchEffect } from '@vielzeug/ore';\nimport { resizeObserver } from '@vielzeug/ore/observers';\n\nimport styles from './grid.css?inline';\n\nconst BREAKPOINTS: ['cols2xl' | 'colsXl' | 'colsLg' | 'colsMd' | 'colsSm', string][] = [\n ['cols2xl', '--size-screen-2xl'],\n ['colsXl', '--size-screen-xl'],\n ['colsLg', '--size-screen-lg'],\n ['colsMd', '--size-screen-md'],\n ['colsSm', '--size-screen-sm'],\n];\n\nconst AREAS_BREAKPOINTS: ['areas2xl' | 'areasXl' | 'areasLg' | 'areasMd' | 'areasSm', string][] = [\n ['areas2xl', '--size-screen-2xl'],\n ['areasXl', '--size-screen-xl'],\n ['areasLg', '--size-screen-lg'],\n ['areasMd', '--size-screen-md'],\n ['areasSm', '--size-screen-sm'],\n];\n\nconst resolveBp = (host: HTMLElement, varName: string, fallback: number): number => {\n const raw = getComputedStyle(host).getPropertyValue(varName).trim();\n const parsed = Number.parseFloat(raw);\n\n return Number.isFinite(parsed) ? parsed : fallback;\n};\n\nconst BP_FALLBACKS: Record<string, number> = {\n '--size-screen-2xl': 1536,\n '--size-screen-lg': 1024,\n '--size-screen-md': 768,\n '--size-screen-sm': 640,\n '--size-screen-xl': 1280,\n};\n\ntype ColCount = '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | '10' | '11' | '12' | 'auto';\n\n/** Grid component properties */\nexport type OreGridProps = {\n /** Align items vertically */\n align?: 'start' | 'center' | 'end' | 'stretch' | 'baseline';\n /** CSS grid-template-areas value */\n areas?: string;\n /** grid-template-areas at 2xl breakpoint (≥1536px) */\n areas2xl?: string;\n /** grid-template-areas at lg breakpoint (≥1024px) */\n areasLg?: string;\n /** grid-template-areas at md breakpoint (≥768px) */\n areasMd?: string;\n /** grid-template-areas at sm breakpoint (≥640px) */\n areasSm?: string;\n /** grid-template-areas at xl breakpoint (≥1280px) */\n areasXl?: string;\n /** Number of columns: '1'-'12' | 'auto' */\n cols?: ColCount;\n /** Columns at 2xl breakpoint (≥1536px) */\n cols2xl?: ColCount;\n /** Columns at lg breakpoint (≥1024px) */\n colsLg?: ColCount;\n /** Columns at md breakpoint (≥768px) */\n colsMd?: ColCount;\n /** Columns at sm breakpoint (≥640px) */\n colsSm?: ColCount;\n /** Columns at xl breakpoint (≥1280px) */\n colsXl?: ColCount;\n /** Grid auto flow direction */\n flow?: 'row' | 'column' | 'row-dense' | 'column-dense';\n /** Stretch the grid to fill its container's full width */\n fullwidth?: boolean;\n /** Gap between items */\n gap?: 'none' | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl';\n /** Justify items horizontally */\n justify?: 'start' | 'center' | 'end' | 'stretch';\n /** Minimum column width for responsive mode (default: 250px) */\n minColWidth?: string;\n /** Use auto-fit responsive columns */\n responsive?: boolean;\n /** Number of rows: '1'-'12' | 'auto' */\n rows?: '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | '10' | '11' | '12' | 'auto';\n};\n\n/**\n * ore-grid — Flexible grid layout with responsive column control.\n *\n * Columns are computed in JS and applied as `--_cols` inline, so they respond\n * to the element's own width via ResizeObserver. CSS custom properties\n * `--grid-cols`, `--grid-rows`, `--grid-gap`, `--grid-row-gap`, `--grid-col-gap`\n * are honoured as fallbacks when no attribute is set.\n *\n * @element ore-grid\n *\n * @attr {string} cols - Column count: '1'–'12' | 'auto'\n * @attr {string} cols-sm - Columns when width ≥ 640px\n * @attr {string} cols-md - Columns when width ≥ 768px\n * @attr {string} cols-lg - Columns when width ≥ 1024px\n * @attr {string} cols-xl - Columns when width ≥ 1280px\n * @attr {string} cols-2xl - Columns when width ≥ 1536px\n * @attr {string} rows - Row count: '1'–'12' | 'auto'\n * @attr {string} gap - Gap token: 'none' | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl'\n * @attr {string} align - align-items: 'start' | 'center' | 'end' | 'stretch' | 'baseline'\n * @attr {string} justify - justify-items: 'start' | 'center' | 'end' | 'stretch'\n * @attr {string} flow - grid-auto-flow: 'row' | 'column' | 'row-dense' | 'column-dense'\n * @attr {boolean} responsive - Enables auto-fit columns without a fixed count\n * @attr {string} min-col-width - Min column width for responsive mode (default: 250px)\n * @attr {boolean} fullwidth - Stretch the grid to fill its container's full width\n * @attr {string} areas - CSS grid-template-areas value (e.g. \"'header header' 'nav main'\")\n * @attr {string} areas-sm - grid-template-areas when width ≥ 640px\n * @attr {string} areas-md - grid-template-areas when width ≥ 768px\n * @attr {string} areas-lg - grid-template-areas when width ≥ 1024px\n * @attr {string} areas-xl - grid-template-areas when width ≥ 1280px\n * @attr {string} areas-2xl - grid-template-areas when width ≥ 1536px\n *\n * @slot - Grid items\n *\n * @cssprop --grid-cols - Fallback column template (used when no cols attr is set)\n * @cssprop --grid-rows - Fallback row template\n * @cssprop --grid-gap - Fallback gap\n * @cssprop --grid-row-gap - Fallback row gap\n * @cssprop --grid-col-gap - Fallback column gap\n *\n * @example\n * <ore-grid cols=\"1\" cols-sm=\"2\" cols-lg=\"4\" gap=\"md\">\n * <div>Item</div>\n * </ore-grid>\n *\n * @example\n * <!-- Responsive auto-fit -->\n * <ore-grid responsive min-col-width=\"200px\" gap=\"sm\">\n * <div>Card</div>\n * </ore-grid>\n *\n * @example\n * <!-- Named grid areas -->\n * <ore-grid cols=\"2\" rows=\"2\" areas=\"'header header' 'nav main'\">\n * <header style=\"grid-area: header\">Header</header>\n * <nav style=\"grid-area: nav\">Nav</nav>\n * <main style=\"grid-area: main\">Main</main>\n * </ore-grid>\n */\nexport const GRID_TAG = 'ore-grid' as const;\ndefine<OreGridProps>(GRID_TAG, {\n props: {\n align: prop.string<'start' | 'center' | 'end' | 'stretch' | 'baseline'>(),\n areas: prop.string(),\n areas2xl: prop.string(),\n areasLg: prop.string(),\n areasMd: prop.string(),\n areasSm: prop.string(),\n areasXl: prop.string(),\n cols: prop.string<ColCount>(),\n cols2xl: prop.string<ColCount>(),\n colsLg: prop.string<ColCount>(),\n colsMd: prop.string<ColCount>(),\n colsSm: prop.string<ColCount>(),\n colsXl: prop.string<ColCount>(),\n flow: prop.string<'row' | 'column' | 'row-dense' | 'column-dense'>(),\n fullwidth: prop.bool(false),\n gap: prop.string<'none' | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl'>(),\n justify: prop.string<'start' | 'center' | 'end' | 'stretch'>(),\n minColWidth: prop.string(),\n responsive: prop.bool(false),\n rows: prop.string<'1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | '10' | '11' | '12' | 'auto'>(),\n },\n\n setup(props) {\n const el = getHost();\n const watch = watchEffect;\n\n const computeCols = (activeCols: string | undefined, responsive: boolean, minW: string): string | null => {\n if (activeCols === 'auto' || (!activeCols && responsive)) {\n return `repeat(auto-fit, minmax(${minW || '250px'}, 1fr))`;\n }\n\n return activeCols ? `repeat(${activeCols}, 1fr)` : null;\n };\n const updateCols = () => {\n const w = el.offsetWidth;\n const responsive = Boolean(props.responsive.value);\n const minW = props.minColWidth.value ?? '';\n let activeCols: string | undefined;\n\n for (const [key, cssVar] of BREAKPOINTS) {\n if (w >= resolveBp(el, cssVar, BP_FALLBACKS[cssVar]) && props[key].value) {\n activeCols = props[key].value!;\n break;\n }\n }\n activeCols ||= props.cols.value || undefined;\n\n const colsValue = computeCols(activeCols, responsive, minW);\n\n if (colsValue) {\n el.style.setProperty('--_cols', colsValue);\n } else {\n el.style.removeProperty('--_cols');\n }\n };\n\n // Re-run cols whenever any responsive prop changes\n watch(() => {\n void [\n props.cols.value,\n props.colsSm.value,\n props.colsMd.value,\n props.colsLg.value,\n props.colsXl.value,\n props.cols2xl.value,\n props.responsive.value,\n props.minColWidth.value,\n ];\n updateCols();\n });\n\n const updateAreas = () => {\n const w = el.offsetWidth;\n let active = '';\n\n for (const [key, cssVar] of AREAS_BREAKPOINTS) {\n if (w >= resolveBp(el, cssVar, BP_FALLBACKS[cssVar]) && props[key].value) {\n active = props[key].value!;\n break;\n }\n }\n active ||= props.areas.value || '';\n\n if (active) {\n el.style.setProperty('grid-template-areas', active);\n } else {\n el.style.removeProperty('grid-template-areas');\n }\n };\n\n // Rows\n watch(() => {\n const rows = props.rows.value;\n\n if (rows && rows !== 'auto') {\n el.style.setProperty('--_rows', `repeat(${rows}, 1fr)`);\n } else {\n el.style.removeProperty('--_rows');\n }\n });\n // Grid template areas (responsive)\n watch(() => {\n void [\n props.areas.value,\n props.areasSm.value,\n props.areasMd.value,\n props.areasLg.value,\n props.areasXl.value,\n props.areas2xl.value,\n ];\n updateAreas();\n });\n\n // Also, update on element resize (drives breakpoint switching)\n onMounted(() => {\n const size = resizeObserver(el);\n\n watch(() => {\n void size.value;\n updateCols();\n updateAreas();\n });\n });\n\n return html`<slot></slot>`;\n },\n\n styles: [styles],\n});\n"],"mappings":"+OAKA,IAAM,EAAiF,CACrF,CAAC,UAAW,mBAAmB,EAC/B,CAAC,SAAU,kBAAkB,EAC7B,CAAC,SAAU,kBAAkB,EAC7B,CAAC,SAAU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Q,MAAM,MACZ,EAAM,QAAQ,MACd,EAAM,QAAQ,MACd,EAAM,QAAQ,MACd,EAAM,QAAQ,MACd,EAAM,SAAS,MAEjB,EAAY,CACd,CAAC,GAGD,EAAA,EAAA,UAAA,KAAgB,CACd,IAAM,EAAO,EAAA,eAAe,CAAE,EAE9B,MAAY,CACV,EAAU,MACV,EAAW,EACX,EAAY,CACd,CAAC,CACH,CAAC,EAEM,EAAA,IAAI,eACb,EAEA,OAAQ,CAAC,EAAA,OAAM,CACjB,CAAC"}
|
|
1
|
+
{"version":3,"file":"grid.cjs","names":[],"sources":["../src/layout/grid/grid.ts"],"sourcesContent":["import { define, html, prop, getHost, onMounted, watchEffect } from '@vielzeug/ore';\nimport { resizeObserver } from '@vielzeug/ore/observers';\n\nimport styles from './grid.css?inline';\n\nconst BREAKPOINTS: ['cols2xl' | 'colsXl' | 'colsLg' | 'colsMd' | 'colsSm', string][] = [\n ['cols2xl', '--size-screen-2xl'],\n ['colsXl', '--size-screen-xl'],\n ['colsLg', '--size-screen-lg'],\n ['colsMd', '--size-screen-md'],\n ['colsSm', '--size-screen-sm'],\n];\n\nconst AREAS_BREAKPOINTS: ['areas2xl' | 'areasXl' | 'areasLg' | 'areasMd' | 'areasSm', string][] = [\n ['areas2xl', '--size-screen-2xl'],\n ['areasXl', '--size-screen-xl'],\n ['areasLg', '--size-screen-lg'],\n ['areasMd', '--size-screen-md'],\n ['areasSm', '--size-screen-sm'],\n];\n\nconst resolveBp = (host: HTMLElement, varName: string, fallback: number): number => {\n const raw = getComputedStyle(host).getPropertyValue(varName).trim();\n const parsed = Number.parseFloat(raw);\n\n return Number.isFinite(parsed) ? parsed : fallback;\n};\n\nconst BP_FALLBACKS: Record<string, number> = {\n '--size-screen-2xl': 1536,\n '--size-screen-lg': 1024,\n '--size-screen-md': 768,\n '--size-screen-sm': 640,\n '--size-screen-xl': 1280,\n};\n\ntype ColCount = '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | '10' | '11' | '12' | 'auto';\n\n/** Grid component properties */\nexport type OreGridProps = {\n /** Align items vertically */\n align?: 'start' | 'center' | 'end' | 'stretch' | 'baseline';\n /** CSS grid-template-areas value */\n areas?: string;\n /** grid-template-areas at 2xl breakpoint (≥1536px) */\n areas2xl?: string;\n /** grid-template-areas at lg breakpoint (≥1024px) */\n areasLg?: string;\n /** grid-template-areas at md breakpoint (≥768px) */\n areasMd?: string;\n /** grid-template-areas at sm breakpoint (≥640px) */\n areasSm?: string;\n /** grid-template-areas at xl breakpoint (≥1280px) */\n areasXl?: string;\n /** Number of columns: '1'-'12' | 'auto' */\n cols?: ColCount;\n /** Columns at 2xl breakpoint (≥1536px) */\n cols2xl?: ColCount;\n /** Columns at lg breakpoint (≥1024px) */\n colsLg?: ColCount;\n /** Columns at md breakpoint (≥768px) */\n colsMd?: ColCount;\n /** Columns at sm breakpoint (≥640px) */\n colsSm?: ColCount;\n /** Columns at xl breakpoint (≥1280px) */\n colsXl?: ColCount;\n /** Grid auto flow direction */\n flow?: 'row' | 'column' | 'row-dense' | 'column-dense';\n /** Stretch the grid to fill its container's full width */\n fullwidth?: boolean;\n /** Gap between items */\n gap?: 'none' | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl';\n /** Justify items horizontally */\n justify?: 'start' | 'center' | 'end' | 'stretch';\n /** Minimum column width for responsive mode (default: 250px) */\n minColWidth?: string;\n /** Use auto-fit responsive columns */\n responsive?: boolean;\n /** Number of rows: '1'-'12' | 'auto' */\n rows?: '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | '10' | '11' | '12' | 'auto';\n};\n\n/**\n * ore-grid — Flexible grid layout with responsive column control.\n *\n * Columns are computed in JS and applied as `--_cols` inline, so they respond\n * to the element's own width via ResizeObserver. CSS custom properties\n * `--grid-cols`, `--grid-rows`, `--grid-gap`, `--grid-row-gap`, `--grid-col-gap`\n * are honoured as fallbacks when no attribute is set.\n *\n * @element ore-grid\n *\n * @attr {string} cols - Column count: '1'–'12' | 'auto'\n * @attr {string} cols-sm - Columns when width ≥ 640px\n * @attr {string} cols-md - Columns when width ≥ 768px\n * @attr {string} cols-lg - Columns when width ≥ 1024px\n * @attr {string} cols-xl - Columns when width ≥ 1280px\n * @attr {string} cols-2xl - Columns when width ≥ 1536px\n * @attr {string} rows - Row count: '1'–'12' | 'auto'\n * @attr {string} gap - Gap token: 'none' | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl'\n * @attr {string} align - align-items: 'start' | 'center' | 'end' | 'stretch' | 'baseline'\n * @attr {string} justify - justify-items: 'start' | 'center' | 'end' | 'stretch'\n * @attr {string} flow - grid-auto-flow: 'row' | 'column' | 'row-dense' | 'column-dense'\n * @attr {boolean} responsive - Enables auto-fit columns without a fixed count\n * @attr {string} min-col-width - Min column width for responsive mode (default: 250px)\n * @attr {boolean} fullwidth - Stretch the grid to fill its container's full width\n * @attr {string} areas - CSS grid-template-areas value (e.g. \"'header header' 'nav main'\")\n * @attr {string} areas-sm - grid-template-areas when width ≥ 640px\n * @attr {string} areas-md - grid-template-areas when width ≥ 768px\n * @attr {string} areas-lg - grid-template-areas when width ≥ 1024px\n * @attr {string} areas-xl - grid-template-areas when width ≥ 1280px\n * @attr {string} areas-2xl - grid-template-areas when width ≥ 1536px\n *\n * @slot - Grid items\n *\n * @cssprop --grid-cols - Fallback column template (used when no cols attr is set)\n * @cssprop --grid-rows - Fallback row template\n * @cssprop --grid-gap - Fallback gap\n * @cssprop --grid-row-gap - Fallback row gap\n * @cssprop --grid-col-gap - Fallback column gap\n *\n * @example\n * <ore-grid cols=\"1\" cols-sm=\"2\" cols-lg=\"4\" gap=\"md\">\n * <div>Item</div>\n * </ore-grid>\n *\n * @example\n * <!-- Responsive auto-fit -->\n * <ore-grid responsive min-col-width=\"200px\" gap=\"sm\">\n * <div>Card</div>\n * </ore-grid>\n *\n * @example\n * <!-- Named grid areas -->\n * <ore-grid cols=\"2\" rows=\"2\" areas=\"'header header' 'nav main'\">\n * <header style=\"grid-area: header\">Header</header>\n * <nav style=\"grid-area: nav\">Nav</nav>\n * <main style=\"grid-area: main\">Main</main>\n * </ore-grid>\n */\nexport const GRID_TAG = 'ore-grid' as const;\ndefine<OreGridProps>(GRID_TAG, {\n props: {\n align: prop.string<'start' | 'center' | 'end' | 'stretch' | 'baseline'>(),\n areas: prop.string(),\n areas2xl: prop.string(),\n areasLg: prop.string(),\n areasMd: prop.string(),\n areasSm: prop.string(),\n areasXl: prop.string(),\n cols: prop.string<ColCount>(),\n cols2xl: prop.string<ColCount>(),\n colsLg: prop.string<ColCount>(),\n colsMd: prop.string<ColCount>(),\n colsSm: prop.string<ColCount>(),\n colsXl: prop.string<ColCount>(),\n flow: prop.string<'row' | 'column' | 'row-dense' | 'column-dense'>(),\n fullwidth: prop.bool(false),\n gap: prop.string<'none' | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl'>(),\n justify: prop.string<'start' | 'center' | 'end' | 'stretch'>(),\n minColWidth: prop.string(),\n responsive: prop.bool(false),\n rows: prop.string<'1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | '10' | '11' | '12' | 'auto'>(),\n },\n\n setup(props) {\n const el = getHost();\n const watch = watchEffect;\n\n const computeCols = (activeCols: string | undefined, responsive: boolean, minW: string): string | null => {\n if (activeCols === 'auto' || (!activeCols && responsive)) {\n return `repeat(auto-fit, minmax(${minW || '250px'}, 1fr))`;\n }\n\n return activeCols ? `repeat(${activeCols}, 1fr)` : null;\n };\n const updateCols = () => {\n const w = el.offsetWidth;\n const responsive = Boolean(props.responsive.value);\n const minW = props.minColWidth.value ?? '';\n let activeCols: string | undefined;\n\n for (const [key, cssVar] of BREAKPOINTS) {\n if (w >= resolveBp(el, cssVar, BP_FALLBACKS[cssVar]) && props[key].value) {\n activeCols = props[key].value!;\n break;\n }\n }\n activeCols ||= props.cols.value || undefined;\n\n const colsValue = computeCols(activeCols, responsive, minW);\n\n if (colsValue) {\n el.style.setProperty('--_cols', colsValue);\n } else {\n el.style.removeProperty('--_cols');\n }\n };\n\n // Re-run cols whenever any responsive prop changes\n watch(() => {\n void [\n props.cols.value,\n props.colsSm.value,\n props.colsMd.value,\n props.colsLg.value,\n props.colsXl.value,\n props.cols2xl.value,\n props.responsive.value,\n props.minColWidth.value,\n ];\n updateCols();\n });\n\n const updateAreas = () => {\n const w = el.offsetWidth;\n let active = '';\n\n for (const [key, cssVar] of AREAS_BREAKPOINTS) {\n if (w >= resolveBp(el, cssVar, BP_FALLBACKS[cssVar]) && props[key].value) {\n active = props[key].value!;\n break;\n }\n }\n active ||= props.areas.value || '';\n\n if (active) {\n el.style.setProperty('grid-template-areas', active);\n } else {\n el.style.removeProperty('grid-template-areas');\n }\n };\n\n // Rows\n watch(() => {\n const rows = props.rows.value;\n\n if (rows && rows !== 'auto') {\n el.style.setProperty('--_rows', `repeat(${rows}, 1fr)`);\n } else {\n el.style.removeProperty('--_rows');\n }\n });\n // Grid template areas (responsive)\n watch(() => {\n void [\n props.areas.value,\n props.areasSm.value,\n props.areasMd.value,\n props.areasLg.value,\n props.areasXl.value,\n props.areas2xl.value,\n ];\n updateAreas();\n });\n\n // Also, update on element resize (drives breakpoint switching)\n onMounted(() => {\n const size = resizeObserver(el);\n\n watch(() => {\n void size.value;\n updateCols();\n updateAreas();\n });\n });\n\n return html`<slot></slot>`;\n },\n\n styles: [styles],\n});\n"],"mappings":"qLAKA,IAAM,EAAiF,CACrF,CAAC,UAAW,mBAAmB,EAC/B,CAAC,SAAU,kBAAkB,EAC7B,CAAC,SAAU,kBAAkB,EAC7B,CAAC,SAAU,kBAAkB,EAC7B,CAAC,SAAU,kBAAkB,CAC/B,EAEM,EAA4F,CAChG,CAAC,WAAY,mBAAmB,EAChC,CAAC,UAAW,kBAAkB,EAC9B,CAAC,UAAW,kBAAkB,EAC9B,CAAC,UAAW,kBAAkB,EAC9B,CAAC,UAAW,kBAAkB,CAChC,EAEM,GAAa,EAAmB,EAAiB,IAA6B,CAClF,IAAM,EAAM,iBAAiB,CAAI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