dou-ui 0.1.0-alpha.21 → 0.1.0-alpha.22
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/components/chat-input/chat-input.vue_vue_type_script_setup_true_lang.js +19 -14
- package/dist/components/chat-input/chat-input.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/chat-input/chat-input2.js.map +1 -1
- package/dist/components/chat-list/chat-list.js.map +1 -1
- package/dist/components/chat-list/chat-list.vue_vue_type_script_setup_true_lang.js +26 -10
- package/dist/components/chat-list/chat-list.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/chat-list/chat-list2.js.map +1 -1
- package/dist/components/chat-message/chat-message.js.map +1 -1
- package/dist/components/chat-plan/chat-plan.js.map +1 -1
- package/dist/components/chat-plan/chat-plan.vue_vue_type_script_setup_true_lang.js +22 -9
- package/dist/components/chat-plan/chat-plan.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/chat-plan/chat-plan2.js.map +1 -1
- package/dist/components/code-block/code-block.js.map +1 -1
- package/dist/components/code-block/code-block.vue_vue_type_script_setup_true_lang.js +144 -7
- package/dist/components/code-block/code-block.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/dock/dock-group.js.map +1 -1
- package/dist/components/dock/dock-group.vue_vue_type_script_setup_true_lang.js +4 -2
- package/dist/components/dock/dock-group.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/dock/dock.js.map +1 -1
- package/dist/components/dock/dock.vue_vue_type_script_setup_true_lang.js +30 -4
- package/dist/components/dock/dock.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/dock/style.js +1 -0
- package/dist/components/form/form.vue_vue_type_script_setup_true_lang.js +1 -0
- package/dist/components/form/form.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/form/form2.js.map +1 -1
- package/dist/components/image/image-preview.js.map +1 -1
- package/dist/components/image/image-preview.vue_vue_type_script_setup_true_lang.js +63 -95
- package/dist/components/image/image-preview.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/image/use-preview-viewport.js +619 -0
- package/dist/components/image/use-preview-viewport.js.map +1 -0
- package/dist/components/image/viewport.js +142 -0
- package/dist/components/image/viewport.js.map +1 -0
- package/dist/components/link/link.js.map +1 -1
- package/dist/components/link/link.vue_vue_type_script_setup_true_lang.js +59 -14
- package/dist/components/link/link.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/popover/popover.js.map +1 -1
- package/dist/components/popover/popover.vue_vue_type_script_setup_true_lang.js +13 -3
- package/dist/components/popover/popover.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/splitter/splitter.js.map +1 -1
- package/dist/components/splitter/splitter.vue_vue_type_script_setup_true_lang.js +111 -41
- package/dist/components/splitter/splitter.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/tabs/style.js +1 -0
- package/dist/components/tabs/tab-button.js +6 -0
- package/dist/components/tabs/tab-button.js.map +1 -0
- package/dist/components/tabs/tab-button.vue_vue_type_script_setup_true_lang.js +108 -0
- package/dist/components/tabs/tab-button.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/components/tabs/tab-drag.js +10 -2
- package/dist/components/tabs/tab-drag.js.map +1 -1
- package/dist/components/tabs/tab-panel.js.map +1 -1
- package/dist/components/tabs/tab-panel.vue_vue_type_script_setup_true_lang.js +4 -0
- package/dist/components/tabs/tab-panel.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/tabs/tabs.js.map +1 -1
- package/dist/components/tabs/tabs.vue_vue_type_script_setup_true_lang.js +430 -181
- package/dist/components/tabs/tabs.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/tabs/tabs2.js.map +1 -1
- package/dist/components/virtual-list/virtual-list.vue_vue_type_script_setup_true_lang.js +33 -20
- package/dist/components/virtual-list/virtual-list.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/virtual-list/virtual-list2.js.map +1 -1
- package/dist/composables/use-floating.js +60 -8
- package/dist/composables/use-floating.js.map +1 -1
- package/dist/composables/use-popup.js +3 -0
- package/dist/composables/use-popup.js.map +1 -1
- package/dist/locale/en.js +1 -2
- package/dist/locale/en.js.map +1 -1
- package/dist/locale/zh-cn.js +1 -2
- package/dist/locale/zh-cn.js.map +1 -1
- package/dist/locale/zh-tw.js +1 -2
- package/dist/locale/zh-tw.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/types/components/chat-list/chat-list.d.ts +13 -0
- package/dist/types/components/chat-list/index.d.ts +2 -0
- package/dist/types/components/chat-message/chat-message.d.ts +1 -0
- package/dist/types/components/chat-plan/chat-plan.d.ts +3 -1
- package/dist/types/components/chat-plan/chat-plan.vue.d.ts +1 -0
- package/dist/types/components/chat-plan/index.d.ts +3 -0
- package/dist/types/components/code-block/code-block.d.ts +23 -0
- package/dist/types/components/code-block/code-block.vue.d.ts +8 -2
- package/dist/types/components/code-block/index.d.ts +19 -3
- package/dist/types/components/dock/dock.d.ts +6 -0
- package/dist/types/components/image/image.d.ts +1 -1
- package/dist/types/components/image/use-preview-viewport.d.ts +48 -0
- package/dist/types/components/image/viewport.d.ts +58 -0
- package/dist/types/components/link/index.d.ts +3 -0
- package/dist/types/components/link/link.d.ts +12 -3
- package/dist/types/components/link/link.vue.d.ts +1 -0
- package/dist/types/components/popover/index.d.ts +3 -0
- package/dist/types/components/popover/popover.d.ts +7 -0
- package/dist/types/components/popover/popover.vue.d.ts +1 -0
- package/dist/types/components/splitter/index.d.ts +6 -9
- package/dist/types/components/splitter/splitter.d.ts +31 -4
- package/dist/types/components/splitter/splitter.vue.d.ts +3 -4
- package/dist/types/components/tabs/index.d.ts +3 -0
- package/dist/types/components/tabs/tab-button.vue.d.ts +28 -0
- package/dist/types/components/tabs/tab-drag.d.ts +8 -0
- package/dist/types/components/tabs/tab-panel.vue.d.ts +1 -0
- package/dist/types/components/tabs/tabs.d.ts +6 -0
- package/dist/types/composables/use-floating.d.ts +1 -1
- package/dist/types/locale/types.d.ts +2 -3
- package/package.json +3 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-preview-viewport.js","names":[],"sources":["../../../src/components/image/use-preview-viewport.ts"],"sourcesContent":["import { computed, onBeforeUnmount, ref } from 'vue'\nimport type { Ref } from 'vue'\nimport { useResizeObserver } from '../../composables/use-element-size'\nimport { holdPointer } from '../../utils/pointer'\nimport type { PointerHold } from '../../utils/pointer'\nimport { clampScale, stepScale } from './preview'\nimport {\n clamp,\n clampOffset,\n formatTransformNumber,\n getDoubleTapScale,\n getPanBounds,\n isQuarterTurn,\n normalizeWheelDelta,\n rotateOffset,\n rubberbandOffset,\n rubberbandScale,\n wheelScaleFactor,\n zoomAroundPoint,\n} from './viewport'\nimport type { PanBounds, Point, Size } from './viewport'\n\nexport interface UsePreviewViewportOptions {\n stageRef: Ref<HTMLElement | null>\n imageRef: Ref<HTMLImageElement | null>\n active: () => boolean\n minScale: () => number\n maxScale: () => number\n}\n\ninterface ActivePointer {\n id: number\n x: number\n y: number\n pointerType: string\n hold: PointerHold\n capturedMouse: boolean\n sawMouseButtons: boolean\n}\n\ninterface MeasuredGeometry {\n viewportSize: Size\n imageSize: Size\n origin: Point\n}\n\ninterface SingleGestureStart {\n pointerId: number\n x: number\n y: number\n offset: Point\n time: number\n onImage: boolean\n pointerType: string\n}\n\ninterface PinchGestureStart {\n distance: number\n midpoint: Point\n rawScale: number\n displayedScale: number\n rawOffset: Point\n}\n\nconst DRAG_THRESHOLD = 4\nconst TAP_SLOP = 10\nconst TAP_MAX_DURATION = 300\nconst DOUBLE_TAP_DELAY = 300\nconst DOUBLE_TAP_DISTANCE = 32\nconst TOUCH_DBLCLICK_SUPPRESS_MS = 500\nconst WHEEL_IDLE_MS = 120\nconst WHEEL_STEP_THROTTLE_MS = 40\nconst ZOOM_EPSILON = 0.001\n\nconst parsePx = (value: string) => Number.parseFloat(value) || 0\n\nexport function usePreviewViewport(options: UsePreviewViewportOptions) {\n const scale = ref(1)\n const rotate = ref(0)\n const flip = ref({ x: 1, y: 1 })\n const offset = ref<Point>({ x: 0, y: 0 })\n const interacting = ref(false)\n const dragging = ref(false)\n\n const viewportSize = ref<Size>({ width: 0, height: 0 })\n const imageSize = ref<Size>({ width: 0, height: 0 })\n\n const safeMinScale = () => Math.max(0.05, options.minScale())\n const safeMaxScale = () => Math.max(safeMinScale(), options.maxScale())\n\n const activePointers = new Map<number, ActivePointer>()\n let mode: 'idle' | 'pending' | 'pan' | 'pinch' = 'idle'\n let singleStart: SingleGestureStart | null = null\n let pinchStart: PinchGestureStart | null = null\n let lastPinchMidpoint: Point | null = null\n let gestureGeometry: MeasuredGeometry | null = null\n let gestureRawScale = 1\n let gestureRawOffset: Point = { x: 0, y: 0 }\n let lastTouchTap: { time: number; x: number; y: number } | null = null\n let lastTouchZoomAt = 0\n let suppressMaskClick = false\n let needsSettle = false\n let wheelIdleTimer: ReturnType<typeof setTimeout> | undefined\n let lastStepWheelAt = 0\n let windowListenersAttached = false\n\n function measureGeometry(): MeasuredGeometry {\n const stage = options.stageRef.value\n const image = options.imageRef.value\n if (!stage) {\n return {\n viewportSize: { width: 0, height: 0 },\n imageSize: { width: 0, height: 0 },\n origin: { x: 0, y: 0 },\n }\n }\n\n const stageRect = stage.getBoundingClientRect()\n const style = typeof getComputedStyle === 'function' ? getComputedStyle(stage) : null\n const paddingLeft = style ? parsePx(style.paddingLeft) : 0\n const paddingRight = style ? parsePx(style.paddingRight) : 0\n const paddingTop = style ? parsePx(style.paddingTop) : 0\n const paddingBottom = style ? parsePx(style.paddingBottom) : 0\n\n const rawWidth = stage.clientWidth || stageRect.width\n const rawHeight = stage.clientHeight || stageRect.height\n const vpWidth = Math.max(0, rawWidth - paddingLeft - paddingRight)\n const vpHeight = Math.max(0, rawHeight - paddingTop - paddingBottom)\n\n let imgWidth = 0\n let imgHeight = 0\n let originX = stageRect.left + paddingLeft + vpWidth / 2\n let originY = stageRect.top + paddingTop + vpHeight / 2\n\n if (image) {\n if (image.offsetWidth > 0 && image.offsetHeight > 0) {\n imgWidth = image.offsetWidth\n imgHeight = image.offsetHeight\n originX = stageRect.left + image.offsetLeft + imgWidth / 2\n originY = stageRect.top + image.offsetTop + imgHeight / 2\n } else {\n const imgRect = image.getBoundingClientRect()\n if (imgRect.width > 0 && imgRect.height > 0) {\n const s = Math.max(scale.value, 0.01)\n const quarter = isQuarterTurn(rotate.value)\n imgWidth = (quarter ? imgRect.height : imgRect.width) / s\n imgHeight = (quarter ? imgRect.width : imgRect.height) / s\n originX = imgRect.left + imgRect.width / 2 - offset.value.x\n originY = imgRect.top + imgRect.height / 2 - offset.value.y\n }\n }\n }\n\n viewportSize.value = { width: vpWidth, height: vpHeight }\n imageSize.value = { width: imgWidth, height: imgHeight }\n return {\n viewportSize: { width: vpWidth, height: vpHeight },\n imageSize: { width: imgWidth, height: imgHeight },\n origin: { x: originX, y: originY },\n }\n }\n\n function hasMeasuredGeometry(geometry?: MeasuredGeometry | null): boolean {\n const vp = geometry?.viewportSize ?? viewportSize.value\n const img = geometry?.imageSize ?? imageSize.value\n return vp.width > 0 && vp.height > 0 && img.width > 0 && img.height > 0\n }\n\n function boundsFor(\n targetScale: number,\n geometry?: MeasuredGeometry | null,\n rot = rotate.value,\n ): PanBounds {\n const vp = geometry?.viewportSize ?? viewportSize.value\n const img = geometry?.imageSize ?? imageSize.value\n return getPanBounds(img, vp, targetScale, rot)\n }\n\n function clampToViewport(\n targetOffset: Point,\n targetScale: number,\n geometry?: MeasuredGeometry | null,\n rot = rotate.value,\n ): Point {\n if (hasMeasuredGeometry(geometry)) {\n return clampOffset(targetOffset, boundsFor(targetScale, geometry, rot))\n }\n return targetScale <= 1 + ZOOM_EPSILON ? { x: 0, y: 0 } : targetOffset\n }\n\n function toFocal(clientX: number, clientY: number, geometry: MeasuredGeometry): Point {\n return {\n x: clientX - geometry.origin.x,\n y: clientY - geometry.origin.y,\n }\n }\n\n const canPan = computed(() => {\n if (hasMeasuredGeometry()) {\n const bounds = boundsFor(scale.value)\n return bounds.maxX > 0.5 || bounds.maxY > 0.5\n }\n return scale.value > 1 + ZOOM_EPSILON\n })\n\n const isZoomed = computed(() => scale.value > 1 + ZOOM_EPSILON)\n\n const transform = computed(\n () =>\n `translate(${formatTransformNumber(offset.value.x)}px, ${formatTransformNumber(offset.value.y)}px) ` +\n `scale(${formatTransformNumber(scale.value)}) ` +\n `scale(${flip.value.x}, ${flip.value.y}) ` +\n `rotate(${rotate.value}deg)`,\n )\n\n function syncBounds() {\n if (!options.active()) return\n const geometry = measureGeometry()\n if (mode === 'idle') {\n offset.value = clampToViewport(offset.value, scale.value, geometry)\n }\n }\n\n useResizeObserver(() => options.stageRef.value, syncBounds)\n\n function clearWheelTimer() {\n if (wheelIdleTimer !== undefined) {\n clearTimeout(wheelIdleTimer)\n wheelIdleTimer = undefined\n }\n }\n\n function handleWindowPointerup(event: PointerEvent) {\n endPointer(event.pointerId, event.clientX, event.clientY, false)\n }\n\n function handleWindowPointercancel(event: PointerEvent) {\n endPointer(event.pointerId, event.clientX, event.clientY, true)\n }\n\n function attachWindowListeners() {\n if (windowListenersAttached || typeof window === 'undefined') return\n windowListenersAttached = true\n window.addEventListener('blur', handleWindowBlur)\n window.addEventListener('pointerup', handleWindowPointerup)\n window.addEventListener('pointercancel', handleWindowPointercancel)\n }\n\n function detachWindowListeners() {\n if (!windowListenersAttached || typeof window === 'undefined') return\n windowListenersAttached = false\n window.removeEventListener('blur', handleWindowBlur)\n window.removeEventListener('pointerup', handleWindowPointerup)\n window.removeEventListener('pointercancel', handleWindowPointercancel)\n }\n\n function releasePointer(entry: ActivePointer) {\n entry.hold.release()\n const stage = options.stageRef.value\n if (entry.capturedMouse && stage?.isConnected && stage.hasPointerCapture?.(entry.id)) {\n stage.releasePointerCapture(entry.id)\n }\n }\n\n function clearPointers() {\n for (const entry of activePointers.values()) releasePointer(entry)\n activePointers.clear()\n detachWindowListeners()\n mode = 'idle'\n singleStart = null\n pinchStart = null\n lastPinchMidpoint = null\n gestureGeometry = null\n gestureRawScale = scale.value\n gestureRawOffset = { ...offset.value }\n needsSettle = false\n interacting.value = false\n dragging.value = false\n }\n\n function settleViewport(geometry: MeasuredGeometry | null = gestureGeometry) {\n const measured = geometry ?? measureGeometry()\n const settledScale = clamp(scale.value, safeMinScale(), safeMaxScale())\n let nextOffset = offset.value\n if (settledScale !== scale.value) {\n const anchor = lastPinchMidpoint ?? { x: 0, y: 0 }\n nextOffset = zoomAroundPoint(\n { scale: scale.value, offset: offset.value },\n settledScale,\n anchor,\n )\n }\n scale.value = settledScale\n offset.value = clampToViewport(nextOffset, settledScale, measured)\n gestureRawScale = settledScale\n gestureRawOffset = { ...offset.value }\n lastPinchMidpoint = null\n }\n\n function handleWindowBlur() {\n const geometry = gestureGeometry\n clearPointers()\n settleViewport(geometry)\n }\n\n function reset() {\n clearWheelTimer()\n clearPointers()\n lastTouchTap = null\n lastStepWheelAt = 0\n suppressMaskClick = false\n scale.value = 1\n rotate.value = 0\n flip.value = { x: 1, y: 1 }\n offset.value = { x: 0, y: 0 }\n gestureRawScale = 1\n gestureRawOffset = { x: 0, y: 0 }\n }\n\n function zoom(direction: 1 | -1) {\n if (!options.active()) return\n clearWheelTimer()\n interacting.value = false\n lastTouchTap = null\n const geometry = measureGeometry()\n const nextScale = clampScale(stepScale(scale.value, direction), safeMinScale(), safeMaxScale())\n const nextOffset = zoomAroundPoint({ scale: scale.value, offset: offset.value }, nextScale, {\n x: 0,\n y: 0,\n })\n scale.value = nextScale\n offset.value = clampToViewport(nextOffset, nextScale, geometry)\n gestureRawScale = nextScale\n gestureRawOffset = { ...offset.value }\n }\n\n function turn(by: number) {\n if (!options.active()) return\n clearWheelTimer()\n interacting.value = false\n lastTouchTap = null\n const nextRotate = rotate.value + by\n const geometry = measureGeometry()\n const screenAngle = by * flip.value.x * flip.value.y\n rotate.value = nextRotate\n offset.value = clampToViewport(\n rotateOffset(offset.value, screenAngle),\n scale.value,\n geometry,\n nextRotate,\n )\n gestureRawOffset = { ...offset.value }\n }\n\n function mirror(axis: 'x' | 'y') {\n if (!options.active()) return\n clearWheelTimer()\n interacting.value = false\n lastTouchTap = null\n flip.value = { ...flip.value, [axis]: -flip.value[axis] }\n const nextOffset =\n axis === 'x'\n ? { x: -offset.value.x || 0, y: offset.value.y }\n : { x: offset.value.x, y: -offset.value.y || 0 }\n const geometry = measureGeometry()\n offset.value = clampToViewport(nextOffset, scale.value, geometry)\n gestureRawOffset = { ...offset.value }\n }\n\n function toggleZoomAt(clientX: number, clientY: number) {\n if (!options.active()) return\n clearWheelTimer()\n interacting.value = false\n const geometry = measureGeometry()\n const targetScale = getDoubleTapScale(scale.value, safeMinScale(), safeMaxScale())\n const fitScale = clamp(1, safeMinScale(), safeMaxScale())\n if (Math.abs(targetScale - fitScale) <= ZOOM_EPSILON) {\n scale.value = targetScale\n offset.value = { x: 0, y: 0 }\n gestureRawScale = targetScale\n gestureRawOffset = { x: 0, y: 0 }\n return\n }\n const focal = toFocal(clientX, clientY, geometry)\n const nextOffset = zoomAroundPoint(\n { scale: scale.value, offset: offset.value },\n targetScale,\n focal,\n )\n scale.value = targetScale\n offset.value = clampToViewport(nextOffset, targetScale, geometry)\n gestureRawScale = targetScale\n gestureRawOffset = { ...offset.value }\n }\n\n function beginPinch() {\n const list = [...activePointers.values()]\n const p1 = list[0]\n const p2 = list[1]\n if (!p1 || !p2) return\n const geometry = gestureGeometry ?? measureGeometry()\n gestureGeometry = geometry\n p1.hold.grab()\n p2.hold.grab()\n const distance = Math.max(Math.hypot(p1.x - p2.x, p1.y - p2.y), 1)\n const midpoint = toFocal((p1.x + p2.x) / 2, (p1.y + p2.y) / 2, geometry)\n pinchStart = {\n distance,\n midpoint,\n rawScale: gestureRawScale,\n displayedScale: scale.value,\n rawOffset: { ...gestureRawOffset },\n }\n lastPinchMidpoint = midpoint\n singleStart = null\n mode = 'pinch'\n needsSettle = true\n interacting.value = true\n dragging.value = false\n suppressMaskClick = true\n lastTouchTap = null\n }\n\n function onPointerdown(event: PointerEvent) {\n if (!options.active()) return\n if (event.pointerType === 'mouse' && event.button !== 0) return\n\n clearWheelTimer()\n\n if (event.isPrimary && activePointers.size > 0) {\n clearPointers()\n }\n\n const stage = options.stageRef.value\n const hold = holdPointer(event, stage, () =>\n endPointer(event.pointerId, event.clientX, event.clientY, true),\n )\n const entry: ActivePointer = {\n id: event.pointerId,\n x: event.clientX,\n y: event.clientY,\n pointerType: event.pointerType,\n hold,\n capturedMouse: false,\n sawMouseButtons: event.pointerType === 'mouse' && (event.buttons & 1) !== 0,\n }\n activePointers.set(event.pointerId, entry)\n attachWindowListeners()\n\n if (activePointers.size === 1) {\n gestureGeometry = measureGeometry()\n gestureRawScale = scale.value\n gestureRawOffset = { ...offset.value }\n suppressMaskClick = false\n mode = 'pending'\n singleStart = {\n pointerId: event.pointerId,\n x: event.clientX,\n y: event.clientY,\n offset: { ...gestureRawOffset },\n time: Date.now(),\n onImage: event.target === options.imageRef.value,\n pointerType: event.pointerType,\n }\n if (event.pointerType === 'mouse' && canPan.value) {\n event.preventDefault()\n }\n } else if (activePointers.size === 2) {\n beginPinch()\n } else {\n entry.hold.grab()\n }\n }\n\n function onPointermove(event: PointerEvent) {\n const entry = activePointers.get(event.pointerId)\n if (!entry) return\n if (entry.pointerType === 'mouse' && entry.sawMouseButtons && (event.buttons & 1) === 0) {\n endPointer(event.pointerId, event.clientX, event.clientY, true)\n return\n }\n\n entry.x = event.clientX\n entry.y = event.clientY\n\n if (mode === 'pinch' && activePointers.size >= 2 && pinchStart) {\n const list = [...activePointers.values()]\n const p1 = list[0]!\n const p2 = list[1]!\n const geometry = gestureGeometry ?? measureGeometry()\n const distance = Math.max(Math.hypot(p1.x - p2.x, p1.y - p2.y), 1)\n const midpoint = toFocal((p1.x + p2.x) / 2, (p1.y + p2.y) / 2, geometry)\n const nextRawScale = pinchStart.rawScale * (distance / pinchStart.distance)\n const nextScale = rubberbandScale(nextRawScale, safeMinScale(), safeMaxScale())\n const nextRawOffset = zoomAroundPoint(\n { scale: pinchStart.displayedScale, offset: pinchStart.rawOffset },\n nextScale,\n pinchStart.midpoint,\n midpoint,\n )\n gestureRawScale = nextRawScale\n gestureRawOffset = nextRawOffset\n scale.value = nextScale\n offset.value = hasMeasuredGeometry(geometry)\n ? rubberbandOffset(nextRawOffset, boundsFor(nextScale, geometry))\n : nextRawOffset\n lastPinchMidpoint = midpoint\n return\n }\n\n if (mode === 'pending' && singleStart && singleStart.pointerId === event.pointerId) {\n const dist = Math.hypot(event.clientX - singleStart.x, event.clientY - singleStart.y)\n const threshold = singleStart.pointerType === 'touch' ? TAP_SLOP : DRAG_THRESHOLD\n if (dist <= threshold) return\n suppressMaskClick = true\n lastTouchTap = null\n if (!canPan.value) return\n mode = 'pan'\n needsSettle = true\n interacting.value = true\n dragging.value = true\n entry.hold.grab()\n if (event.pointerType === 'mouse') {\n try {\n options.stageRef.value?.setPointerCapture?.(event.pointerId)\n entry.capturedMouse = true\n } catch {\n // pointer already released\n }\n }\n }\n\n if (mode === 'pan' && singleStart && singleStart.pointerId === event.pointerId) {\n const geometry = gestureGeometry ?? measureGeometry()\n const rawOffset: Point = {\n x: singleStart.offset.x + (event.clientX - singleStart.x),\n y: singleStart.offset.y + (event.clientY - singleStart.y),\n }\n gestureRawOffset = rawOffset\n offset.value = hasMeasuredGeometry(geometry)\n ? rubberbandOffset(rawOffset, boundsFor(scale.value, geometry))\n : rawOffset\n }\n }\n\n function endPointer(pointerId: number, clientX: number, clientY: number, canceled: boolean) {\n const entry = activePointers.get(pointerId)\n if (!entry) return\n releasePointer(entry)\n activePointers.delete(pointerId)\n\n if (activePointers.size >= 2) {\n beginPinch()\n return\n }\n\n if (activePointers.size === 1) {\n const remaining = [...activePointers.values()][0]!\n suppressMaskClick = true\n pinchStart = null\n if (canPan.value) {\n mode = 'pan'\n dragging.value = true\n singleStart = {\n pointerId: remaining.id,\n x: remaining.x,\n y: remaining.y,\n offset: { ...gestureRawOffset },\n time: Date.now(),\n onImage: false,\n pointerType: remaining.pointerType,\n }\n } else {\n mode = 'idle'\n dragging.value = false\n singleStart = null\n }\n return\n }\n\n detachWindowListeners()\n const endedMode = mode\n const endedSingle = singleStart\n const shouldSettle = needsSettle\n const geometry = gestureGeometry\n mode = 'idle'\n singleStart = null\n pinchStart = null\n gestureGeometry = null\n needsSettle = false\n interacting.value = false\n dragging.value = false\n\n if (\n !canceled &&\n endedMode === 'pending' &&\n endedSingle &&\n endedSingle.pointerId === pointerId &&\n endedSingle.pointerType === 'touch' &&\n endedSingle.onImage\n ) {\n const now = Date.now()\n const duration = now - endedSingle.time\n const moved = Math.hypot(clientX - endedSingle.x, clientY - endedSingle.y)\n if (duration <= TAP_MAX_DURATION && moved <= TAP_SLOP) {\n if (\n lastTouchTap &&\n now - lastTouchTap.time <= DOUBLE_TAP_DELAY &&\n Math.hypot(clientX - lastTouchTap.x, clientY - lastTouchTap.y) <= DOUBLE_TAP_DISTANCE\n ) {\n lastTouchTap = null\n lastTouchZoomAt = now\n suppressMaskClick = true\n toggleZoomAt(clientX, clientY)\n return\n }\n lastTouchTap = { time: now, x: clientX, y: clientY }\n return\n }\n lastTouchTap = null\n }\n\n if (\n shouldSettle ||\n endedMode === 'pinch' ||\n endedMode === 'pan' ||\n scale.value < safeMinScale() ||\n scale.value > safeMaxScale()\n ) {\n settleViewport(geometry)\n }\n }\n\n function onPointerup(event: PointerEvent) {\n endPointer(event.pointerId, event.clientX, event.clientY, false)\n }\n\n function onPointercancel(event: PointerEvent) {\n endPointer(event.pointerId, event.clientX, event.clientY, true)\n }\n\n function onDblclick(event: MouseEvent) {\n if (!options.active()) return\n if (Date.now() - lastTouchZoomAt < TOUCH_DBLCLICK_SUPPRESS_MS) return\n toggleZoomAt(event.clientX, event.clientY)\n }\n\n function onWheel(event: WheelEvent) {\n event.preventDefault()\n if (!options.active() || activePointers.size > 0) return\n const delta = normalizeWheelDelta(event)\n if (delta === 0) return\n\n lastTouchTap = null\n const continuous =\n event.ctrlKey ||\n (event.deltaMode === 0 && (wheelIdleTimer !== undefined || Math.abs(delta) < 40))\n const geometry =\n continuous && wheelIdleTimer !== undefined && gestureGeometry\n ? gestureGeometry\n : measureGeometry()\n\n const focal = toFocal(event.clientX, event.clientY, geometry)\n let nextScale: number\n\n if (continuous) {\n gestureGeometry = geometry\n interacting.value = true\n clearWheelTimer()\n wheelIdleTimer = setTimeout(() => {\n wheelIdleTimer = undefined\n if (activePointers.size === 0) {\n interacting.value = false\n gestureGeometry = null\n }\n }, WHEEL_IDLE_MS)\n nextScale = clamp(\n scale.value * wheelScaleFactor(delta, event.ctrlKey),\n safeMinScale(),\n safeMaxScale(),\n )\n } else {\n const now = Date.now()\n if (now - lastStepWheelAt < WHEEL_STEP_THROTTLE_MS) return\n lastStepWheelAt = now\n clearWheelTimer()\n interacting.value = false\n gestureGeometry = null\n nextScale = clampScale(\n stepScale(scale.value, delta < 0 ? 1 : -1),\n safeMinScale(),\n safeMaxScale(),\n )\n }\n\n const nextOffset = zoomAroundPoint(\n { scale: scale.value, offset: offset.value },\n nextScale,\n focal,\n )\n scale.value = nextScale\n offset.value = clampToViewport(nextOffset, nextScale, geometry)\n gestureRawScale = nextScale\n gestureRawOffset = { ...offset.value }\n }\n\n function canCloseOnMask(): boolean {\n return !isZoomed.value && !suppressMaskClick\n }\n\n function consumeMaskClick(): boolean {\n if (suppressMaskClick) {\n suppressMaskClick = false\n return false\n }\n return !isZoomed.value\n }\n\n onBeforeUnmount(() => {\n clearWheelTimer()\n clearPointers()\n })\n\n return {\n scale,\n rotate,\n flip,\n offset,\n interacting,\n dragging,\n canPan,\n isZoomed,\n transform,\n reset,\n zoom,\n turn,\n mirror,\n syncBounds,\n canCloseOnMask,\n consumeMaskClick,\n onPointerdown,\n onPointermove,\n onPointerup,\n onPointercancel,\n onDblclick,\n onWheel,\n }\n}\n"],"mappings":";;;;;;AAgEA,IAAM,iBAAiB;AACvB,IAAM,WAAW;AACjB,IAAM,mBAAmB;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AAY;GACd,kBAAkB;GAClB,YAAY,QAAQ;GACpB,gBAAgB;GAChB,iBAAiB,iBAAiB;IAChC,iBAAiB,KAAA;IACjB,IAAI,eAAe,SAAS,GAAG;KAC7B,YAAY,QAAQ;KACpB,kBAAkB;IACpB;GACF,GAAG,aAAa;GAChB,YAAY,MACV,MAAM,QAAQ,iBAAiB,OAAO,MAAM,OAAO,GACnD,aAAa,GACb,aAAa,CACf;EACF,OAAO;GACL,MAAM,MAAM,KAAK,IAAI;GACrB,IAAI,MAAM,kBAAkB,wBAAwB;GACpD,kBAAkB;GAClB,gBAAgB;GAChB,YAAY,QAAQ;GACpB,kBAAkB;GAClB,YAAY,WACV,UAAU,MAAM,OAAO,QAAQ,IAAI,IAAI,EAAE,GACzC,aAAa,GACb,aAAa,CACf;EACF;EAEA,MAAM,aAAa,gBACjB;GAAE,OAAO,MAAM;GAAO,QAAQ,OAAO;EAAM,GAC3C,WACA,KACF;EACA,MAAM,QAAQ;EACd,OAAO,QAAQ,gBAAgB,YAAY,WAAW,QAAQ;EAC9D,kBAAkB;EAClB,mBAAmB,EAAE,GAAG,OAAO,MAAM;CACvC;CAEA,SAAS,iBAA0B;EACjC,OAAO,CAAC,SAAS,SAAS,CAAC;CAC7B;CAEA,SAAS,mBAA4B;EACnC,IAAI,mBAAmB;GACrB,oBAAoB;GACpB,OAAO;EACT;EACA,OAAO,CAAC,SAAS;CACnB;CAEA,sBAAsB;EACpB,gBAAgB;EAChB,cAAc;CAChB,CAAC;CAED,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// src/components/image/viewport.ts
|
|
2
|
+
var OFFSET_RUBBERBAND_RANGE = 120;
|
|
3
|
+
var OFFSET_RUBBERBAND_RESISTANCE = .55;
|
|
4
|
+
var SCALE_RUBBERBAND_RESISTANCE = .35;
|
|
5
|
+
var SCALE_RUBBERBAND_MAX_UNDER = Math.log(2);
|
|
6
|
+
var SCALE_RUBBERBAND_MAX_OVER = Math.log(1.6);
|
|
7
|
+
var FIT_SCALE_EPSILON = .01;
|
|
8
|
+
/** Keep `value` within `[min, max]` without quantizing continuous precision. */
|
|
9
|
+
function clamp(value, min, max) {
|
|
10
|
+
return Math.min(max, Math.max(min, value));
|
|
11
|
+
}
|
|
12
|
+
/** Normalize a CSS transform number to avoid `-0` and noisy floating tails. */
|
|
13
|
+
function formatTransformNumber(value) {
|
|
14
|
+
const rounded = Math.round(value * 1e4) / 1e4;
|
|
15
|
+
return rounded === 0 ? 0 : rounded;
|
|
16
|
+
}
|
|
17
|
+
/** Whether `rotate` swaps the image's visual width and height. */
|
|
18
|
+
function isQuarterTurn(rotate) {
|
|
19
|
+
return Math.abs(Math.round(rotate / 90) % 2) === 1;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Maximum horizontal and vertical pan offsets from the centered origin so the
|
|
23
|
+
* image edges stay clamped to the viewport content area.
|
|
24
|
+
*/
|
|
25
|
+
function getPanBounds(imageSize, viewportSize, scale, rotate = 0) {
|
|
26
|
+
if (imageSize.width <= 0 || imageSize.height <= 0 || viewportSize.width <= 0 || viewportSize.height <= 0) return {
|
|
27
|
+
maxX: 0,
|
|
28
|
+
maxY: 0
|
|
29
|
+
};
|
|
30
|
+
const quarter = isQuarterTurn(rotate);
|
|
31
|
+
const scaledWidth = (quarter ? imageSize.height : imageSize.width) * scale;
|
|
32
|
+
const scaledHeight = (quarter ? imageSize.width : imageSize.height) * scale;
|
|
33
|
+
return {
|
|
34
|
+
maxX: Math.max(0, (scaledWidth - viewportSize.width) / 2),
|
|
35
|
+
maxY: Math.max(0, (scaledHeight - viewportSize.height) / 2)
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/** Clamp a pan offset to the symmetric viewport bounds. */
|
|
39
|
+
function clampOffset(offset, bounds) {
|
|
40
|
+
const x = clamp(offset.x, -bounds.maxX, bounds.maxX);
|
|
41
|
+
const y = clamp(offset.y, -bounds.maxY, bounds.maxY);
|
|
42
|
+
return {
|
|
43
|
+
x: x === 0 ? 0 : x,
|
|
44
|
+
y: y === 0 ? 0 : y
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/** Smooth asymptotic damping when `value` extends past `[min, max]`. */
|
|
48
|
+
function rubberband(value, min, max, range = OFFSET_RUBBERBAND_RANGE, resistance = OFFSET_RUBBERBAND_RESISTANCE) {
|
|
49
|
+
if (value >= min && value <= max) return value;
|
|
50
|
+
const over = value < min ? min - value : value - max;
|
|
51
|
+
const damped = range > 0 ? resistance * over * range / (resistance * over + range) : 0;
|
|
52
|
+
return value < min ? min - damped : max + damped;
|
|
53
|
+
}
|
|
54
|
+
/** Apply rubberband resistance to a pan offset beyond the viewport bounds. */
|
|
55
|
+
function rubberbandOffset(offset, bounds, range = OFFSET_RUBBERBAND_RANGE) {
|
|
56
|
+
return {
|
|
57
|
+
x: rubberband(offset.x, -bounds.maxX, bounds.maxX, range),
|
|
58
|
+
y: rubberband(offset.y, -bounds.maxY, bounds.maxY, range)
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Apply logarithmic rubberband resistance when a pinch overshoots `minScale`
|
|
63
|
+
* or `maxScale`, keeping the damped scale strictly positive and bounded.
|
|
64
|
+
*/
|
|
65
|
+
function rubberbandScale(scale, minScale, maxScale) {
|
|
66
|
+
const safeMin = Math.max(.05, minScale);
|
|
67
|
+
const safeMax = Math.max(safeMin, maxScale);
|
|
68
|
+
if (scale >= safeMin && scale <= safeMax) return scale;
|
|
69
|
+
const positive = Math.max(scale, safeMin * .05);
|
|
70
|
+
if (positive < safeMin) {
|
|
71
|
+
const over = Math.log(safeMin / positive);
|
|
72
|
+
const damped = SCALE_RUBBERBAND_RESISTANCE * over * SCALE_RUBBERBAND_MAX_UNDER / (SCALE_RUBBERBAND_RESISTANCE * over + SCALE_RUBBERBAND_MAX_UNDER);
|
|
73
|
+
return safeMin * Math.exp(-damped);
|
|
74
|
+
}
|
|
75
|
+
const over = Math.log(positive / safeMax);
|
|
76
|
+
const damped = SCALE_RUBBERBAND_RESISTANCE * over * SCALE_RUBBERBAND_MAX_OVER / (SCALE_RUBBERBAND_RESISTANCE * over + SCALE_RUBBERBAND_MAX_OVER);
|
|
77
|
+
return safeMax * Math.exp(damped);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Compute the new offset when scaling from `current.scale` to `nextScale` so
|
|
81
|
+
* the image pixel under `focal` moves to `nextFocal` (both relative to the
|
|
82
|
+
* untransformed image center).
|
|
83
|
+
*/
|
|
84
|
+
function zoomAroundPoint(current, nextScale, focal, nextFocal = focal) {
|
|
85
|
+
if (current.scale <= 0) return { ...current.offset };
|
|
86
|
+
const ratio = nextScale / current.scale;
|
|
87
|
+
const x = nextFocal.x - (focal.x - current.offset.x) * ratio;
|
|
88
|
+
const y = nextFocal.y - (focal.y - current.offset.y) * ratio;
|
|
89
|
+
return {
|
|
90
|
+
x: x === 0 ? 0 : x,
|
|
91
|
+
y: y === 0 ? 0 : y
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Target scale for double-tap / double-click: toggle between the fit scale
|
|
96
|
+
* (1, clamped to `[minScale, maxScale]`) and the zoomed scale (2x, clamped).
|
|
97
|
+
*/
|
|
98
|
+
function getDoubleTapScale(currentScale, minScale, maxScale, zoomScale = 2) {
|
|
99
|
+
const safeMin = Math.max(.05, minScale);
|
|
100
|
+
const safeMax = Math.max(safeMin, maxScale);
|
|
101
|
+
const fit = clamp(1, safeMin, safeMax);
|
|
102
|
+
if (Math.abs(currentScale - fit) <= FIT_SCALE_EPSILON) return clamp(Math.max(zoomScale, fit * 2), safeMin, safeMax);
|
|
103
|
+
return fit;
|
|
104
|
+
}
|
|
105
|
+
/** Convert line/page wheel deltas to pixel-equivalent units. */
|
|
106
|
+
function normalizeWheelDelta(event) {
|
|
107
|
+
if (event.deltaMode === 1) return event.deltaY * 16;
|
|
108
|
+
if (event.deltaMode === 2) return event.deltaY * 100;
|
|
109
|
+
return event.deltaY;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Exponential scale multiplier for continuous trackpad pinch (`ctrlKey` wheel)
|
|
113
|
+
* or smooth pixel-mode trackpad scrolling.
|
|
114
|
+
*/
|
|
115
|
+
function wheelScaleFactor(deltaY, isPinch) {
|
|
116
|
+
if (isPinch) return Math.exp(-clamp(deltaY, -80, 80) * .01);
|
|
117
|
+
return Math.exp(-clamp(deltaY, -120, 120) * .0025);
|
|
118
|
+
}
|
|
119
|
+
/** Turn a screen-space pan offset with a 90-degree step rotation. */
|
|
120
|
+
function rotateOffset(offset, degrees) {
|
|
121
|
+
const turns = (Math.round(degrees / 90) % 4 + 4) % 4;
|
|
122
|
+
const { x, y } = offset;
|
|
123
|
+
if (turns === 1) return {
|
|
124
|
+
x: -y || 0,
|
|
125
|
+
y: x || 0
|
|
126
|
+
};
|
|
127
|
+
if (turns === 2) return {
|
|
128
|
+
x: -x || 0,
|
|
129
|
+
y: -y || 0
|
|
130
|
+
};
|
|
131
|
+
if (turns === 3) return {
|
|
132
|
+
x: y || 0,
|
|
133
|
+
y: -x || 0
|
|
134
|
+
};
|
|
135
|
+
return {
|
|
136
|
+
x: x || 0,
|
|
137
|
+
y: y || 0
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
export { clamp, clampOffset, formatTransformNumber, getDoubleTapScale, getPanBounds, isQuarterTurn, normalizeWheelDelta, rotateOffset, rubberband, rubberbandOffset, rubberbandScale, wheelScaleFactor, zoomAroundPoint };
|
|
141
|
+
|
|
142
|
+
//# sourceMappingURL=viewport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"viewport.js","names":[],"sources":["../../../src/components/image/viewport.ts"],"sourcesContent":["export interface Point {\n x: number\n y: number\n}\n\nexport interface Size {\n width: number\n height: number\n}\n\nexport interface PanBounds {\n maxX: number\n maxY: number\n}\n\nexport interface ViewportTransform {\n scale: number\n offset: Point\n}\n\nconst OFFSET_RUBBERBAND_RANGE = 120\nconst OFFSET_RUBBERBAND_RESISTANCE = 0.55\nconst SCALE_RUBBERBAND_RESISTANCE = 0.35\nconst SCALE_RUBBERBAND_MAX_UNDER = Math.log(2)\nconst SCALE_RUBBERBAND_MAX_OVER = Math.log(1.6)\nconst FIT_SCALE_EPSILON = 0.01\n\n/** Keep `value` within `[min, max]` without quantizing continuous precision. */\nexport function clamp(value: number, min: number, max: number): number {\n return Math.min(max, Math.max(min, value))\n}\n\n/** Normalize a CSS transform number to avoid `-0` and noisy floating tails. */\nexport function formatTransformNumber(value: number): number {\n const rounded = Math.round(value * 10000) / 10000\n return rounded === 0 ? 0 : rounded\n}\n\n/** Whether `rotate` swaps the image's visual width and height. */\nexport function isQuarterTurn(rotate: number): boolean {\n return Math.abs(Math.round(rotate / 90) % 2) === 1\n}\n\n/**\n * Maximum horizontal and vertical pan offsets from the centered origin so the\n * image edges stay clamped to the viewport content area.\n */\nexport function getPanBounds(\n imageSize: Size,\n viewportSize: Size,\n scale: number,\n rotate = 0,\n): PanBounds {\n if (\n imageSize.width <= 0 ||\n imageSize.height <= 0 ||\n viewportSize.width <= 0 ||\n viewportSize.height <= 0\n ) {\n return { maxX: 0, maxY: 0 }\n }\n const quarter = isQuarterTurn(rotate)\n const scaledWidth = (quarter ? imageSize.height : imageSize.width) * scale\n const scaledHeight = (quarter ? imageSize.width : imageSize.height) * scale\n return {\n maxX: Math.max(0, (scaledWidth - viewportSize.width) / 2),\n maxY: Math.max(0, (scaledHeight - viewportSize.height) / 2),\n }\n}\n\n/** Clamp a pan offset to the symmetric viewport bounds. */\nexport function clampOffset(offset: Point, bounds: PanBounds): Point {\n const x = clamp(offset.x, -bounds.maxX, bounds.maxX)\n const y = clamp(offset.y, -bounds.maxY, bounds.maxY)\n return { x: x === 0 ? 0 : x, y: y === 0 ? 0 : y }\n}\n\n/** Smooth asymptotic damping when `value` extends past `[min, max]`. */\nexport function rubberband(\n value: number,\n min: number,\n max: number,\n range = OFFSET_RUBBERBAND_RANGE,\n resistance = OFFSET_RUBBERBAND_RESISTANCE,\n): number {\n if (value >= min && value <= max) return value\n const over = value < min ? min - value : value - max\n const damped = range > 0 ? (resistance * over * range) / (resistance * over + range) : 0\n return value < min ? min - damped : max + damped\n}\n\n/** Apply rubberband resistance to a pan offset beyond the viewport bounds. */\nexport function rubberbandOffset(\n offset: Point,\n bounds: PanBounds,\n range = OFFSET_RUBBERBAND_RANGE,\n): Point {\n return {\n x: rubberband(offset.x, -bounds.maxX, bounds.maxX, range),\n y: rubberband(offset.y, -bounds.maxY, bounds.maxY, range),\n }\n}\n\n/**\n * Apply logarithmic rubberband resistance when a pinch overshoots `minScale`\n * or `maxScale`, keeping the damped scale strictly positive and bounded.\n */\nexport function rubberbandScale(scale: number, minScale: number, maxScale: number): number {\n const safeMin = Math.max(0.05, minScale)\n const safeMax = Math.max(safeMin, maxScale)\n if (scale >= safeMin && scale <= safeMax) return scale\n const positive = Math.max(scale, safeMin * 0.05)\n if (positive < safeMin) {\n const over = Math.log(safeMin / positive)\n const damped =\n (SCALE_RUBBERBAND_RESISTANCE * over * SCALE_RUBBERBAND_MAX_UNDER) /\n (SCALE_RUBBERBAND_RESISTANCE * over + SCALE_RUBBERBAND_MAX_UNDER)\n return safeMin * Math.exp(-damped)\n }\n const over = Math.log(positive / safeMax)\n const damped =\n (SCALE_RUBBERBAND_RESISTANCE * over * SCALE_RUBBERBAND_MAX_OVER) /\n (SCALE_RUBBERBAND_RESISTANCE * over + SCALE_RUBBERBAND_MAX_OVER)\n return safeMax * Math.exp(damped)\n}\n\n/**\n * Compute the new offset when scaling from `current.scale` to `nextScale` so\n * the image pixel under `focal` moves to `nextFocal` (both relative to the\n * untransformed image center).\n */\nexport function zoomAroundPoint(\n current: ViewportTransform,\n nextScale: number,\n focal: Point,\n nextFocal: Point = focal,\n): Point {\n if (current.scale <= 0) return { ...current.offset }\n const ratio = nextScale / current.scale\n const x = nextFocal.x - (focal.x - current.offset.x) * ratio\n const y = nextFocal.y - (focal.y - current.offset.y) * ratio\n return { x: x === 0 ? 0 : x, y: y === 0 ? 0 : y }\n}\n\n/**\n * Target scale for double-tap / double-click: toggle between the fit scale\n * (1, clamped to `[minScale, maxScale]`) and the zoomed scale (2x, clamped).\n */\nexport function getDoubleTapScale(\n currentScale: number,\n minScale: number,\n maxScale: number,\n zoomScale = 2,\n): number {\n const safeMin = Math.max(0.05, minScale)\n const safeMax = Math.max(safeMin, maxScale)\n const fit = clamp(1, safeMin, safeMax)\n if (Math.abs(currentScale - fit) <= FIT_SCALE_EPSILON) {\n return clamp(Math.max(zoomScale, fit * 2), safeMin, safeMax)\n }\n return fit\n}\n\n/** Convert line/page wheel deltas to pixel-equivalent units. */\nexport function normalizeWheelDelta(event: Pick<WheelEvent, 'deltaY' | 'deltaMode'>): number {\n if (event.deltaMode === 1) return event.deltaY * 16\n if (event.deltaMode === 2) return event.deltaY * 100\n return event.deltaY\n}\n\n/**\n * Exponential scale multiplier for continuous trackpad pinch (`ctrlKey` wheel)\n * or smooth pixel-mode trackpad scrolling.\n */\nexport function wheelScaleFactor(deltaY: number, isPinch: boolean): number {\n if (isPinch) return Math.exp(-clamp(deltaY, -80, 80) * 0.01)\n return Math.exp(-clamp(deltaY, -120, 120) * 0.0025)\n}\n\n/** Turn a screen-space pan offset with a 90-degree step rotation. */\nexport function rotateOffset(offset: Point, degrees: number): Point {\n const turns = (((Math.round(degrees / 90) % 4) + 4) % 4) as 0 | 1 | 2 | 3\n const { x, y } = offset\n if (turns === 1) return { x: -y || 0, y: x || 0 }\n if (turns === 2) return { x: -x || 0, y: -y || 0 }\n if (turns === 3) return { x: y || 0, y: -x || 0 }\n return { x: x || 0, y: y || 0 }\n}\n"],"mappings":";AAoBA,IAAM,0BAA0B;AAChC,IAAM,+BAA+B;AACrC,IAAM,8BAA8B;AACpC,IA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gB,kBACd,cACA,UACA,UACA,YAAY,GACJ;CACR,MAAM,UAAU,KAAK,IAAI,KAAM,QAAQ;CACvC,MAAM,UAAU,KAAK,IAAI,SAAS,QAAQ;CAC1C,MAAM,MAAM,MAAM,GAAG,SAAS,OAAO;CACrC,IAAI,KAAK,IAAI,eAAe,GAAG,KAAK,mBAClC,OAAO,MAAM,KAAK,IAAI,WAAW,MAAM,CAAC,GAAG,SAAS,OAAO;CAE7D,OAAO;AACT;;AAGA,SAAgB,oBAAoB,OAAyD;CAC3F,IAAI,MAAM,cAAc,GAAG,OAAO,MAAM,SAAS;CACjD,IAAI,MAAM,cAAc,GAAG,OAAO,MAAM,SAAS;CACjD,OAAO,MAAM;AACf;;;;;AAMA,SAAgB,iBAAiB,QAAgB,SAA0B;CACzE,IAAI,SAAS,OAAO,KAAK,IAAI,CAAC,MAAM,QAAQ,KAAK,EAAE,IAAI,GAAI;CAC3D,OAAO,KAAK,IAAI,CAAC,MAAM,QAAQ,MAAM,GAAG,IAAI,KAAM;AACpD;;AAGA,SAAgB,aAAa,QAAe,SAAwB;CAClE,MAAM,SAAW,KAAK,MAAM,UAAU,EAAE,IAAI,IAAK,KAAK;CACtD,MAAM,EAAE,GAAG,MAAM;CACjB,IAAI,UAAU,GAAG,OAAO;EAAE,GAAG,CAAC,KAAK;EAAG,GAAG,KAAK;CAAE;CAChD,IAAI,UAAU,GAAG,OAAO;EAAE,GAAG,CAAC,KAAK;EAAG,GAAG,CAAC,KAAK;CAAE;CACjD,IAAI,UAAU,GAAG,OAAO;EAAE,GAAG,KAAK;EAAG,GAAG,CAAC,KAAK;CAAE;CAChD,OAAO;EAAE,GAAG,KAAK;EAAG,GAAG,KAAK;CAAE;AAChC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link.js","names":["_sfc_main"],"sources":["../../../src/components/link/link.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ArrowUpRightIcon } from '@dou-ui/icons'\nimport {\n Comment,\n Fragment,\n Text,\n computed,\n createTextVNode,\n h,\n isVNode,\n onMounted,\n useTemplateRef,\n watchEffect,\n} from 'vue'\nimport type { VNode } from 'vue'\nimport { useNamespace } from '../../utils/namespace'\nimport { filled } from '../../utils/slot'\nimport { devWarn } from '../../utils/status-check'\nimport type { LinkEmits, LinkProps, LinkSlots } from './link'\n\ndefineOptions({ name: 'DouLink' })\n\nconst props = withDefaults(defineProps<LinkProps>(), {\n tone: 'neutral',\n variant: 'text',\n underline: undefined,\n disabled: false,\n external: false,\n})\nconst emit = defineEmits<LinkEmits>()\nconst slots = defineSlots<LinkSlots>()\n\nconst ns = useNamespace('link')\n\n// Without an address there is nowhere to go: the link is an action
|
|
1
|
+
{"version":3,"file":"link.js","names":["_sfc_main"],"sources":["../../../src/components/link/link.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ArrowUpRightIcon } from '@dou-ui/icons'\nimport {\n Comment,\n Fragment,\n Text,\n computed,\n createTextVNode,\n h,\n isVNode,\n onMounted,\n useTemplateRef,\n watchEffect,\n} from 'vue'\nimport type { VNode } from 'vue'\nimport { useNamespace } from '../../utils/namespace'\nimport { filled } from '../../utils/slot'\nimport { devWarn } from '../../utils/status-check'\nimport type { LinkEmits, LinkProps, LinkSlots } from './link'\n\ndefineOptions({ name: 'DouLink' })\n\nconst props = withDefaults(defineProps<LinkProps>(), {\n tone: 'neutral',\n variant: 'text',\n wrap: false,\n underline: undefined,\n disabled: false,\n external: false,\n})\nconst emit = defineEmits<LinkEmits>()\nconst slots = defineSlots<LinkSlots>()\n\nconst ns = useNamespace('link')\n\n// Without an address there is nowhere to go: the link is an action. When it\n// needs to break across lines (`soft` or `wrap`), it cannot be a `<button>`\n// (an atomic inline box that never fragments across lines), so it renders as\n// an inline `<span role=\"button\">` with keyboard Enter/Space support.\nconst isButton = computed(() => !props.href)\nconst wraps = computed(() => props.variant === 'soft' || props.wrap)\nconst isInlineButton = computed(() => isButton.value && wraps.value)\n\nif (process.env.NODE_ENV !== 'production')\n watchEffect(() => {\n if (props.external && !props.href)\n devWarn(\n '[dou-ui] DouLink: `external` opens `href` in a new tab; without an `href` the link is a button and `external` does nothing.',\n )\n })\n\n// A button inside a button is invalid: the parser splits them apart and\n// server-rendered markup no longer matches on hydration.\nconst root = useTemplateRef<HTMLElement>('root')\nif (process.env.NODE_ENV !== 'production')\n onMounted(() => {\n if (isButton.value && root.value?.parentElement?.closest('button'))\n devWarn(\n '[dou-ui] DouLink: without an `href` the link is a button, and it sits inside another button. Pass an `href`, or move it out of the clickable element.',\n )\n })\n\n// A label written on its own lines in a template starts and ends with a\n// space, which would show under the underline or inside a soft fill. Slots\n// passed on by a wrapper come as fragments, and a `v-if` leaves a comment:\n// look through both for the first and last text. A fragment that holds\n// nothing but spaces is passed over for the next node.\n//\n// A soft link breaks with the line, and an icon must not be left alone at\n// the end of one: the first and last characters of the label are taken out\n// to sit beside the icons in a span that never breaks. A character inside\n// an element of its own (`<strong>`) stays where it is.\ntype Edge = 'start' | 'end'\ntype Walk = { nodes: unknown[]; done: boolean; char: string }\nfunction cut(text: string, edge: Edge, take: boolean): [rest: string, char: string] {\n const trimmed = edge === 'start' ? text.trimStart() : text.trimEnd()\n if (!take || !trimmed) return [trimmed, '']\n const chars = Array.from(trimmed)\n return edge === 'start'\n ? [chars.slice(1).join(''), chars[0] ?? '']\n : [chars.slice(0, -1).join(''), chars[chars.length - 1] ?? '']\n}\nfunction walk(nodes: unknown[], edge: Edge, take: boolean): Walk {\n const out = [...nodes]\n const step = edge === 'start' ? 1 : -1\n for (let index = step > 0 ? 0 : out.length - 1; index >= 0 && index < out.length; index += step) {\n const node = out[index]\n if (typeof node === 'string' || (isVNode(node) && node.type === Text)) {\n const text = typeof node === 'string' ? node : node.children\n if (typeof text !== 'string') return { nodes: out, done: true, char: '' }\n const [rest, char] = cut(text, edge, take)\n out[index] = typeof node === 'string' ? rest : createTextVNode(rest)\n if (char || rest) return { nodes: out, done: true, char }\n continue\n }\n if (!isVNode(node) || node.type === Comment) continue\n if (node.type === Fragment && Array.isArray(node.children)) {\n const inner = walk(node.children, edge, take)\n out[index] = { ...node, children: inner.nodes } as VNode\n if (inner.done) return { ...inner, nodes: out }\n continue\n }\n return { nodes: out, done: true, char: '' }\n }\n return { nodes: out, done: false, char: '' }\n}\n// Called in this component's own render, so it follows slots that come\n// and go; `Nodes` only puts the result down.\nconst parts = () => {\n const label = (slots.default?.() ?? []) as unknown[]\n const inlineFlow = wraps.value\n // a slot that renders nothing counts as not passed: no empty icon, and\n // an external link keeps its arrow\n const leading = filled(slots.leading)\n const own = filled(slots.trailing)\n const arrow = !own\n const trailing = own ?? (props.external && !isButton.value ? h(ArrowUpRightIcon) : undefined)\n const head = walk(label, 'start', inlineFlow && !!leading)\n const tail = walk(head.nodes, 'end', inlineFlow && !!trailing)\n const icon = (content: unknown, external = false) =>\n h(\n 'span',\n {\n class: [ns.e('icon'), external && ns.e('external')],\n 'aria-hidden': external ? 'true' : undefined,\n },\n content as VNode[],\n )\n const before = leading ? icon(leading) : undefined\n const after = trailing ? icon(trailing, arrow) : undefined\n const body = h('span', { class: ns.e('label') }, tail.nodes as VNode[])\n if (!inlineFlow) return [before, body, after]\n // a single character between two icons: all three break as one\n if (before && after && head.char && !tail.char)\n return [h('span', { class: [ns.e('lead'), ns.e('trail')] }, [before, head.char, body, after])]\n return [\n before && h('span', { class: ns.e('lead') }, [before, head.char]),\n body,\n after && h('span', { class: ns.e('trail') }, [tail.char, after]),\n ]\n}\nconst Nodes = (nodes: { nodes: unknown }) => nodes.nodes as VNode[]\n\nconst classes = computed(() => [\n ns.b(),\n ns.m(props.tone),\n ns.m(props.variant),\n ns.m(`underline-${props.underline ?? (props.variant === 'soft' ? 'none' : 'always')}`),\n ns.is('wrap', props.wrap),\n ns.is('disabled', props.disabled),\n])\n\nconst attrs = computed(() => {\n if (!isButton.value) {\n return {\n href: props.disabled ? undefined : props.href,\n target: props.external ? '_blank' : undefined,\n rel: props.external ? 'noopener noreferrer' : undefined,\n 'aria-disabled': props.disabled || undefined,\n }\n }\n if (isInlineButton.value) {\n return {\n role: 'button',\n tabindex: props.disabled ? undefined : 0,\n 'aria-disabled': props.disabled || undefined,\n }\n }\n return { type: 'button', disabled: props.disabled }\n})\n\nlet spacePressed = false\n\nfunction onClick(event: MouseEvent) {\n if (props.disabled) {\n event.preventDefault()\n return\n }\n // A <span> inside a <label> (such as DouCheckbox) would otherwise toggle the\n // labeled control on click; a native <button> does not.\n if (isInlineButton.value) event.preventDefault()\n emit('click', event)\n}\n\nfunction onKeydown(event: KeyboardEvent) {\n if (!isInlineButton.value || props.disabled || event.defaultPrevented) return\n if (event.target !== event.currentTarget) return\n if (event.altKey || event.ctrlKey || event.metaKey) return\n if (event.key === 'Enter') {\n event.preventDefault()\n ;(event.currentTarget as HTMLElement).click()\n } else if (event.key === ' ' || event.key === 'Spacebar') {\n // Prevent page scroll on Space down and activate on keyup, matching native buttons.\n event.preventDefault()\n spacePressed = true\n } else if (event.key === 'Escape') {\n spacePressed = false\n }\n}\n\nfunction onKeyup(event: KeyboardEvent) {\n if (!isInlineButton.value || !spacePressed) return\n if (event.key !== ' ' && event.key !== 'Spacebar') return\n spacePressed = false\n if (props.disabled || event.defaultPrevented || event.target !== event.currentTarget) return\n event.preventDefault()\n ;(event.currentTarget as HTMLElement).click()\n}\n\nfunction onBlur() {\n spacePressed = false\n}\n</script>\n\n<template>\n <component\n :is=\"isButton ? (isInlineButton ? 'span' : 'button') : 'a'\"\n ref=\"root\"\n :class=\"classes\"\n v-bind=\"attrs\"\n @click=\"onClick\"\n @keydown=\"onKeydown\"\n @keyup=\"onKeyup\"\n @blur=\"onBlur\"\n >\n <Nodes :nodes=\"parts()\" />\n </component>\n</template>\n"],"mappings":""}
|
|
@@ -11,6 +11,10 @@ var link_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompo
|
|
|
11
11
|
href: {},
|
|
12
12
|
tone: { default: "neutral" },
|
|
13
13
|
variant: { default: "text" },
|
|
14
|
+
wrap: {
|
|
15
|
+
type: Boolean,
|
|
16
|
+
default: false
|
|
17
|
+
},
|
|
14
18
|
underline: { default: void 0 },
|
|
15
19
|
disabled: {
|
|
16
20
|
type: Boolean,
|
|
@@ -28,6 +32,8 @@ var link_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompo
|
|
|
28
32
|
const slots = useSlots();
|
|
29
33
|
const ns = useNamespace("link");
|
|
30
34
|
const isButton = computed(() => !props.href);
|
|
35
|
+
const wraps = computed(() => props.variant === "soft" || props.wrap);
|
|
36
|
+
const isInlineButton = computed(() => isButton.value && wraps.value);
|
|
31
37
|
if (process.env.NODE_ENV !== "production") watchEffect(() => {
|
|
32
38
|
if (props.external && !props.href) devWarn("[dou-ui] DouLink: `external` opens `href` in a new tab; without an `href` the link is a button and `external` does nothing.");
|
|
33
39
|
});
|
|
@@ -89,13 +95,13 @@ var link_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompo
|
|
|
89
95
|
}
|
|
90
96
|
const parts = () => {
|
|
91
97
|
const label = slots.default?.() ?? [];
|
|
92
|
-
const
|
|
98
|
+
const inlineFlow = wraps.value;
|
|
93
99
|
const leading = filled(slots.leading);
|
|
94
100
|
const own = filled(slots.trailing);
|
|
95
101
|
const arrow = !own;
|
|
96
102
|
const trailing = own ?? (props.external && !isButton.value ? h(ArrowUpRightIcon) : void 0);
|
|
97
|
-
const head = walk(label, "start",
|
|
98
|
-
const tail = walk(head.nodes, "end",
|
|
103
|
+
const head = walk(label, "start", inlineFlow && !!leading);
|
|
104
|
+
const tail = walk(head.nodes, "end", inlineFlow && !!trailing);
|
|
99
105
|
const icon = (content, external = false) => h("span", {
|
|
100
106
|
class: [ns.e("icon"), external && ns.e("external")],
|
|
101
107
|
"aria-hidden": external ? "true" : void 0
|
|
@@ -103,7 +109,7 @@ var link_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompo
|
|
|
103
109
|
const before = leading ? icon(leading) : void 0;
|
|
104
110
|
const after = trailing ? icon(trailing, arrow) : void 0;
|
|
105
111
|
const body = h("span", { class: ns.e("label") }, tail.nodes);
|
|
106
|
-
if (!
|
|
112
|
+
if (!inlineFlow) return [
|
|
107
113
|
before,
|
|
108
114
|
body,
|
|
109
115
|
after
|
|
@@ -126,30 +132,69 @@ var link_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompo
|
|
|
126
132
|
ns.m(props.tone),
|
|
127
133
|
ns.m(props.variant),
|
|
128
134
|
ns.m(`underline-${props.underline ?? (props.variant === "soft" ? "none" : "always")}`),
|
|
135
|
+
ns.is("wrap", props.wrap),
|
|
129
136
|
ns.is("disabled", props.disabled)
|
|
130
137
|
]);
|
|
131
|
-
const attrs = computed(() =>
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
138
|
+
const attrs = computed(() => {
|
|
139
|
+
if (!isButton.value) return {
|
|
140
|
+
href: props.disabled ? void 0 : props.href,
|
|
141
|
+
target: props.external ? "_blank" : void 0,
|
|
142
|
+
rel: props.external ? "noopener noreferrer" : void 0,
|
|
143
|
+
"aria-disabled": props.disabled || void 0
|
|
144
|
+
};
|
|
145
|
+
if (isInlineButton.value) return {
|
|
146
|
+
role: "button",
|
|
147
|
+
tabindex: props.disabled ? void 0 : 0,
|
|
148
|
+
"aria-disabled": props.disabled || void 0
|
|
149
|
+
};
|
|
150
|
+
return {
|
|
151
|
+
type: "button",
|
|
152
|
+
disabled: props.disabled
|
|
153
|
+
};
|
|
139
154
|
});
|
|
155
|
+
let spacePressed = false;
|
|
140
156
|
function onClick(event) {
|
|
141
157
|
if (props.disabled) {
|
|
142
158
|
event.preventDefault();
|
|
143
159
|
return;
|
|
144
160
|
}
|
|
161
|
+
if (isInlineButton.value) event.preventDefault();
|
|
145
162
|
emit("click", event);
|
|
146
163
|
}
|
|
164
|
+
function onKeydown(event) {
|
|
165
|
+
if (!isInlineButton.value || props.disabled || event.defaultPrevented) return;
|
|
166
|
+
if (event.target !== event.currentTarget) return;
|
|
167
|
+
if (event.altKey || event.ctrlKey || event.metaKey) return;
|
|
168
|
+
if (event.key === "Enter") {
|
|
169
|
+
event.preventDefault();
|
|
170
|
+
event.currentTarget.click();
|
|
171
|
+
} else if (event.key === " " || event.key === "Spacebar") {
|
|
172
|
+
event.preventDefault();
|
|
173
|
+
spacePressed = true;
|
|
174
|
+
} else if (event.key === "Escape") spacePressed = false;
|
|
175
|
+
}
|
|
176
|
+
function onKeyup(event) {
|
|
177
|
+
if (!isInlineButton.value || !spacePressed) return;
|
|
178
|
+
if (event.key !== " " && event.key !== "Spacebar") return;
|
|
179
|
+
spacePressed = false;
|
|
180
|
+
if (props.disabled || event.defaultPrevented || event.target !== event.currentTarget) return;
|
|
181
|
+
event.preventDefault();
|
|
182
|
+
event.currentTarget.click();
|
|
183
|
+
}
|
|
184
|
+
function onBlur() {
|
|
185
|
+
spacePressed = false;
|
|
186
|
+
}
|
|
147
187
|
return (_ctx, _cache) => {
|
|
148
|
-
return openBlock(), createBlock(resolveDynamicComponent(isButton.value ? "button" : "a"), mergeProps({
|
|
188
|
+
return openBlock(), createBlock(resolveDynamicComponent(isButton.value ? isInlineButton.value ? "span" : "button" : "a"), mergeProps({
|
|
149
189
|
ref_key: "root",
|
|
150
190
|
ref: root,
|
|
151
191
|
class: classes.value
|
|
152
|
-
}, attrs.value, {
|
|
192
|
+
}, attrs.value, {
|
|
193
|
+
onClick,
|
|
194
|
+
onKeydown,
|
|
195
|
+
onKeyup,
|
|
196
|
+
onBlur
|
|
197
|
+
}), {
|
|
153
198
|
default: withCtx(() => [createVNode(Nodes, { nodes: parts() }, null, 8, ["nodes"])]),
|
|
154
199
|
_: 1
|
|
155
200
|
}, 16, ["class"]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link.vue_vue_type_script_setup_true_lang.js","names":["_useSlots","_openBlock","_createBlock","_resolveDynamicComponent","_mergeProps","_withCtx","_createVNode"],"sources":["../../../src/components/link/link.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ArrowUpRightIcon } from '@dou-ui/icons'\nimport {\n Comment,\n Fragment,\n Text,\n computed,\n createTextVNode,\n h,\n isVNode,\n onMounted,\n useTemplateRef,\n watchEffect,\n} from 'vue'\nimport type { VNode } from 'vue'\nimport { useNamespace } from '../../utils/namespace'\nimport { filled } from '../../utils/slot'\nimport { devWarn } from '../../utils/status-check'\nimport type { LinkEmits, LinkProps, LinkSlots } from './link'\n\ndefineOptions({ name: 'DouLink' })\n\nconst props = withDefaults(defineProps<LinkProps>(), {\n tone: 'neutral',\n variant: 'text',\n underline: undefined,\n disabled: false,\n external: false,\n})\nconst emit = defineEmits<LinkEmits>()\nconst slots = defineSlots<LinkSlots>()\n\nconst ns = useNamespace('link')\n\n// Without an address there is nowhere to go: the link is an action, so it is\n// a button, which takes focus and responds to Enter and Space.\nconst isButton = computed(() => !props.href)\n\nif (process.env.NODE_ENV !== 'production')\n watchEffect(() => {\n if (props.external && !props.href)\n devWarn(\n '[dou-ui] DouLink: `external` opens `href` in a new tab; without an `href` the link is a button and `external` does nothing.',\n )\n })\n\n// A button inside a button is invalid: the parser splits them apart and\n// server-rendered markup no longer matches on hydration.\nconst root = useTemplateRef<HTMLElement>('root')\nif (process.env.NODE_ENV !== 'production')\n onMounted(() => {\n if (isButton.value && root.value?.parentElement?.closest('button'))\n devWarn(\n '[dou-ui] DouLink: without an `href` the link is a button, and it sits inside another button. Pass an `href`, or move it out of the clickable element.',\n )\n })\n\n// A label written on its own lines in a template starts and ends with a\n// space, which would show under the underline or inside a soft fill. Slots\n// passed on by a wrapper come as fragments, and a `v-if` leaves a comment:\n// look through both for the first and last text. A fragment that holds\n// nothing but spaces is passed over for the next node.\n//\n// A soft link breaks with the line, and an icon must not be left alone at\n// the end of one: the first and last characters of the label are taken out\n// to sit beside the icons in a span that never breaks. A character inside\n// an element of its own (`<strong>`) stays where it is.\ntype Edge = 'start' | 'end'\ntype Walk = { nodes: unknown[]; done: boolean; char: string }\nfunction cut(text: string, edge: Edge, take: boolean): [rest: string, char: string] {\n const trimmed = edge === 'start' ? text.trimStart() : text.trimEnd()\n if (!take || !trimmed) return [trimmed, '']\n const chars = Array.from(trimmed)\n return edge === 'start'\n ? [chars.slice(1).join(''), chars[0] ?? '']\n : [chars.slice(0, -1).join(''), chars[chars.length - 1] ?? '']\n}\nfunction walk(nodes: unknown[], edge: Edge, take: boolean): Walk {\n const out = [...nodes]\n const step = edge === 'start' ? 1 : -1\n for (let index = step > 0 ? 0 : out.length - 1; index >= 0 && index < out.length; index += step) {\n const node = out[index]\n if (typeof node === 'string' || (isVNode(node) && node.type === Text)) {\n const text = typeof node === 'string' ? node : node.children\n if (typeof text !== 'string') return { nodes: out, done: true, char: '' }\n const [rest, char] = cut(text, edge, take)\n out[index] = typeof node === 'string' ? rest : createTextVNode(rest)\n if (char || rest) return { nodes: out, done: true, char }\n continue\n }\n if (!isVNode(node) || node.type === Comment) continue\n if (node.type === Fragment && Array.isArray(node.children)) {\n const inner = walk(node.children, edge, take)\n out[index] = { ...node, children: inner.nodes } as VNode\n if (inner.done) return { ...inner, nodes: out }\n continue\n }\n return { nodes: out, done: true, char: '' }\n }\n return { nodes: out, done: false, char: '' }\n}\n// Called in this component's own render, so it follows slots that come\n// and go; `Nodes` only puts the result down.\nconst parts = () => {\n const label = (slots.default?.() ?? []) as unknown[]\n const soft = props.variant === 'soft'\n // a slot that renders nothing counts as not passed: no empty icon, and\n // an external link keeps its arrow\n const leading = filled(slots.leading)\n const own = filled(slots.trailing)\n const arrow = !own\n const trailing = own ?? (props.external && !isButton.value ? h(ArrowUpRightIcon) : undefined)\n const head = walk(label, 'start', soft && !!leading)\n const tail = walk(head.nodes, 'end', soft && !!trailing)\n const icon = (content: unknown, external = false) =>\n h(\n 'span',\n {\n class: [ns.e('icon'), external && ns.e('external')],\n 'aria-hidden': external ? 'true' : undefined,\n },\n content as VNode[],\n )\n const before = leading ? icon(leading) : undefined\n const after = trailing ? icon(trailing, arrow) : undefined\n const body = h('span', { class: ns.e('label') }, tail.nodes as VNode[])\n if (!soft) return [before, body, after]\n // a single character between two icons: all three break as one\n if (before && after && head.char && !tail.char)\n return [h('span', { class: [ns.e('lead'), ns.e('trail')] }, [before, head.char, body, after])]\n return [\n before && h('span', { class: ns.e('lead') }, [before, head.char]),\n body,\n after && h('span', { class: ns.e('trail') }, [tail.char, after]),\n ]\n}\nconst Nodes = (nodes: { nodes: unknown }) => nodes.nodes as VNode[]\n\nconst classes = computed(() => [\n ns.b(),\n ns.m(props.tone),\n ns.m(props.variant),\n ns.m(`underline-${props.underline ?? (props.variant === 'soft' ? 'none' : 'always')}`),\n ns.is('disabled', props.disabled),\n])\n\nconst attrs = computed(() =>\n isButton.value\n ? { type: 'button', disabled: props.disabled }\n : {\n href: props.disabled ? undefined : props.href,\n target: props.external ? '_blank' : undefined,\n rel: props.external ? 'noopener noreferrer' : undefined,\n 'aria-disabled': props.disabled || undefined,\n },\n)\n\nfunction onClick(event: MouseEvent) {\n if (props.disabled) {\n event.preventDefault()\n return\n }\n emit('click', event)\n}\n</script>\n\n<template>\n <component\n :is=\"isButton ? 'button' : 'a'\"\n ref=\"root\"\n :class=\"classes\"\n v-bind=\"attrs\"\n @click=\"onClick\"\n >\n <Nodes :nodes=\"parts()\" />\n </component>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;EAsBA,MAAM,QAAQ;EAOd,MAAM,OAAO;EACb,MAAM,QAAQA,SAAA;EAEd,MAAM,KAAK,aAAa,MAAM;EAI9B,MAAM,WAAW,eAAe,CAAC,MAAM,IAAI;EAE3C,IAAA,QAAA,IAAA,aAA6B,cAC3B,kBAAkB;GAChB,IAAI,MAAM,YAAY,CAAC,MAAM,MAC3B,QACE,6HACF;EACJ,CAAC;EAIH,MAAM,OAAO,eAA4B,MAAM;EAC/C,IAAA,QAAA,IAAA,aAA6B,cAC3B,gBAAgB;GACd,IAAI,SAAS,SAAS,KAAK,OAAO,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AC;IAAQ,KAAK;IAAM;IAAM;GAAK,CAAC,CAAC;GAC/F,OAAO;IACL,UAAU,EAAE,QAAQ,EAAE,OAAO,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,QAAQ,KAAK,IAAI,CAAC;IAChE;IACA,SAAS,EAAE,QAAQ,EAAE,OAAO,GAAG,EAAE,OAAO,EAAE,GAAG,CAAC,KAAK,MAAM,KAAK,CAAC;GACjE;EACF;EACA,MAAM,SAAS,UAA8B,MAAM;EAEnD,MAAM,UAAU,eAAe;GAC7B,GAAG,EAAE;GACL,GAAG,EAAE,MAAM,IAAI;GACf,GAAG,EAAE,MAAM,OAAO;GAClB,GAAG,EAAE,aAAa,MAAM,cAAc,MAAM,YAAY,SAAS,SAAS,WAAW;GACrF,GAAG,GAAG,YAAY,MAAM,QAAQ;EAClC,CAAC;EAED,MAAM,QAAQ,eACZ,SAAS,QACL;GAAE,MAAM;GAAU,UAAU,MAAM;EAAS,IAC3C;GACE,MAAM,MAAM,WAAW,KAAA,IAAY,MAAM;GACzC,QAAQ,MAAM,WAAW,WAAW,KAAA;GACpC,KAAK,MAAM,WAAW,wBAAwB,KAAA;GAC9C,iBAAiB,MAAM,YAAY,KAAA;EACrC,CACN;EAEA,SAAS,QAAQ,OAAmB;GAClC,IAAI,MAAM,UAAU;IAClB,MAAM,eAAe;IACrB;GACF;GACA,KAAK,SAAS,KAAK;EACrB;;GAIE,OAAAC,UAAA,GAAAC,YAQYC,wBAPL,SAAA,QAAQ,WAAA,GAAA,GADfC,WAQY;IANN,SAAA;IAAJ,KAAI;IACH,OAAO,QAAA;GACA,GAAA,MAAA,OAAK,EACL,QAAO,CAAA,GAAA;IAEf,SAAAC,cAA0B,CAA1BC,YAA0B,OAAA,EAAlB,OAAO,MAAK,E"}
|
|
1
|
+
{"version":3,"file":"link.vue_vue_type_script_setup_true_lang.js","names":["_useSlots","_openBlock","_createBlock","_resolveDynamicComponent","_mergeProps","_withCtx","_createVNode"],"sources":["../../../src/components/link/link.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ArrowUpRightIcon } from '@dou-ui/icons'\nimport {\n Comment,\n Fragment,\n Text,\n computed,\n createTextVNode,\n h,\n isVNode,\n onMounted,\n useTemplateRef,\n watchEffect,\n} from 'vue'\nimport type { VNode } from 'vue'\nimport { useNamespace } from '../../utils/namespace'\nimport { filled } from '../../utils/slot'\nimport { devWarn } from '../../utils/status-check'\nimport type { LinkEmits, LinkProps, LinkSlots } from './link'\n\ndefineOptions({ name: 'DouLink' })\n\nconst props = withDefaults(defineProps<LinkProps>(), {\n tone: 'neutral',\n variant: 'text',\n wrap: false,\n underline: undefined,\n disabled: false,\n external: false,\n})\nconst emit = defineEmits<LinkEmits>()\nconst slots = defineSlots<LinkSlots>()\n\nconst ns = useNamespace('link')\n\n// Without an address there is nowhere to go: the link is an action. When it\n// needs to break across lines (`soft` or `wrap`), it cannot be a `<button>`\n// (an atomic inline box that never fragments across lines), so it renders as\n// an inline `<span role=\"button\">` with keyboard Enter/Space support.\nconst isButton = computed(() => !props.href)\nconst wraps = computed(() => props.variant === 'soft' || props.wrap)\nconst isInlineButton = computed(() => isButton.value && wraps.value)\n\nif (process.env.NODE_ENV !== 'production')\n watchEffect(() => {\n if (props.external && !props.href)\n devWarn(\n '[dou-ui] DouLink: `external` opens `href` in a new tab; without an `href` the link is a button and `external` does nothing.',\n )\n })\n\n// A button inside a button is invalid: the parser splits them apart and\n// server-rendered markup no longer matches on hydration.\nconst root = useTemplateRef<HTMLElement>('root')\nif (process.env.NODE_ENV !== 'production')\n onMounted(() => {\n if (isButton.value && root.value?.parentElement?.closest('button'))\n devWarn(\n '[dou-ui] DouLink: without an `href` the link is a button, and it sits inside another button. Pass an `href`, or move it out of the clickable element.',\n )\n })\n\n// A label written on its own lines in a template starts and ends with a\n// space, which would show under the underline or inside a soft fill. Slots\n// passed on by a wrapper come as fragments, and a `v-if` leaves a comment:\n// look through both for the first and last text. A fragment that holds\n// nothing but spaces is passed over for the next node.\n//\n// A soft link breaks with the line, and an icon must not be left alone at\n// the end of one: the first and last characters of the label are taken out\n// to sit beside the icons in a span that never breaks. A character inside\n// an element of its own (`<strong>`) stays where it is.\ntype Edge = 'start' | 'end'\ntype Walk = { nodes: unknown[]; done: boolean; char: string }\nfunction cut(text: string, edge: Edge, take: boolean): [rest: string, char: string] {\n const trimmed = edge === 'start' ? text.trimStart() : text.trimEnd()\n if (!take || !trimmed) return [trimmed, '']\n const chars = Array.from(trimmed)\n return edge === 'start'\n ? [chars.slice(1).join(''), chars[0] ?? '']\n : [chars.slice(0, -1).join(''), chars[chars.length - 1] ?? '']\n}\nfunction walk(nodes: unknown[], edge: Edge, take: boolean): Walk {\n const out = [...nodes]\n const step = edge === 'start' ? 1 : -1\n for (let index = step > 0 ? 0 : out.length - 1; index >= 0 && index < out.length; index += step) {\n const node = out[index]\n if (typeof node === 'string' || (isVNode(node) && node.type === Text)) {\n const text = typeof node === 'string' ? node : node.children\n if (typeof text !== 'string') return { nodes: out, done: true, char: '' }\n const [rest, char] = cut(text, edge, take)\n out[index] = typeof node === 'string' ? rest : createTextVNode(rest)\n if (char || rest) return { nodes: out, done: true, char }\n continue\n }\n if (!isVNode(node) || node.type === Comment) continue\n if (node.type === Fragment && Array.isArray(node.children)) {\n const inner = walk(node.children, edge, take)\n out[index] = { ...node, children: inner.nodes } as VNode\n if (inner.done) return { ...inner, nodes: out }\n continue\n }\n return { nodes: out, done: true, char: '' }\n }\n return { nodes: out, done: false, char: '' }\n}\n// Called in this component's own render, so it follows slots that come\n// and go; `Nodes` only puts the result down.\nconst parts = () => {\n const label = (slots.default?.() ?? []) as unknown[]\n const inlineFlow = wraps.value\n // a slot that renders nothing counts as not passed: no empty icon, and\n // an external link keeps its arrow\n const leading = filled(slots.leading)\n const own = filled(slots.trailing)\n const arrow = !own\n const trailing = own ?? (props.external && !isButton.value ? h(ArrowUpRightIcon) : undefined)\n const head = walk(label, 'start', inlineFlow && !!leading)\n const tail = walk(head.nodes, 'end', inlineFlow && !!trailing)\n const icon = (content: unknown, external = false) =>\n h(\n 'span',\n {\n class: [ns.e('icon'), external && ns.e('external')],\n 'aria-hidden': external ? 'true' : undefined,\n },\n content as VNode[],\n )\n const before = leading ? icon(leading) : undefined\n const after = trailing ? icon(trailing, arrow) : undefined\n const body = h('span', { class: ns.e('label') }, tail.nodes as VNode[])\n if (!inlineFlow) return [before, body, after]\n // a single character between two icons: all three break as one\n if (before && after && head.char && !tail.char)\n return [h('span', { class: [ns.e('lead'), ns.e('trail')] }, [before, head.char, body, after])]\n return [\n before && h('span', { class: ns.e('lead') }, [before, head.char]),\n body,\n after && h('span', { class: ns.e('trail') }, [tail.char, after]),\n ]\n}\nconst Nodes = (nodes: { nodes: unknown }) => nodes.nodes as VNode[]\n\nconst classes = computed(() => [\n ns.b(),\n ns.m(props.tone),\n ns.m(props.variant),\n ns.m(`underline-${props.underline ?? (props.variant === 'soft' ? 'none' : 'always')}`),\n ns.is('wrap', props.wrap),\n ns.is('disabled', props.disabled),\n])\n\nconst attrs = computed(() => {\n if (!isButton.value) {\n return {\n href: props.disabled ? undefined : props.href,\n target: props.external ? '_blank' : undefined,\n rel: props.external ? 'noopener noreferrer' : undefined,\n 'aria-disabled': props.disabled || undefined,\n }\n }\n if (isInlineButton.value) {\n return {\n role: 'button',\n tabindex: props.disabled ? undefined : 0,\n 'aria-disabled': props.disabled || undefined,\n }\n }\n return { type: 'button', disabled: props.disabled }\n})\n\nlet spacePressed = false\n\nfunction onClick(event: MouseEvent) {\n if (props.disabled) {\n event.preventDefault()\n return\n }\n // A <span> inside a <label> (such as DouCheckbox) would otherwise toggle the\n // labeled control on click; a native <button> does not.\n if (isInlineButton.value) event.preventDefault()\n emit('click', event)\n}\n\nfunction onKeydown(event: KeyboardEvent) {\n if (!isInlineButton.value || props.disabled || event.defaultPrevented) return\n if (event.target !== event.currentTarget) return\n if (event.altKey || event.ctrlKey || event.metaKey) return\n if (event.key === 'Enter') {\n event.preventDefault()\n ;(event.currentTarget as HTMLElement).click()\n } else if (event.key === ' ' || event.key === 'Spacebar') {\n // Prevent page scroll on Space down and activate on keyup, matching native buttons.\n event.preventDefault()\n spacePressed = true\n } else if (event.key === 'Escape') {\n spacePressed = false\n }\n}\n\nfunction onKeyup(event: KeyboardEvent) {\n if (!isInlineButton.value || !spacePressed) return\n if (event.key !== ' ' && event.key !== 'Spacebar') return\n spacePressed = false\n if (props.disabled || event.defaultPrevented || event.target !== event.currentTarget) return\n event.preventDefault()\n ;(event.currentTarget as HTMLElement).click()\n}\n\nfunction onBlur() {\n spacePressed = false\n}\n</script>\n\n<template>\n <component\n :is=\"isButton ? (isInlineButton ? 'span' : 'button') : 'a'\"\n ref=\"root\"\n :class=\"classes\"\n v-bind=\"attrs\"\n @click=\"onClick\"\n @keydown=\"onKeydown\"\n @keyup=\"onKeyup\"\n @blur=\"onBlur\"\n >\n <Nodes :nodes=\"parts()\" />\n </component>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAsBA,MAAM,QAAQ;EAQd,MAAM,OAAO;EACb,MAAM,QAAQA,SAAA;EAEd,MAAM,KAAK,aAAa,MAAM;EAM9B,MAAM,WAAW,eAAe,CAAC,MAAM,IAAI;EAC3C,MAAM,QAAQ,eAAe,MAAM,YAAY,UAAU,MAAM,IAAI;EACnE,MAAM,iBAAiB,eAAe,SAAS,SAAS,MAAM,KAAK;EAEnE,IAAA,QAAA,IAAA,aAA6B,cAC3B,kBAAkB;GAChB,IAAI,MAAM,YAAY,CAAC,MAAM,MAC3B,QACE,6HACF;EACJ,CAAC;EAIH,MAAM,OAAO,eAA4B,MAAM;EAC/C,IAAA,QAAA,IAAA,aAA6B,cAC3B,gBAAgB;GACd,IAAI,SAAS,SAAS,KAAK,OAAO,eAAe,QAAQ,QAAQ,GAC/D,QACE,uJACF;EACJ,CAAC;EAcH,SAAS,IAAI,MAAc,MAAY,MAA6C;GAClF,MAAM,UAAU,SAAS,UAAU,KAAK,UAAU,IAAI,KAAK,QAAQ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,OAAO,MAAM,QAAQ,YAAY;IAExD,MAAM,eAAe;IACrB,eAAe;GACjB,OAAO,IAAI,MAAM,QAAQ,UACvB,eAAe;EAEnB;EAEA,SAAS,QAAQ,OAAsB;GACrC,IAAI,CAAC,eAAe,SAAS,CAAC,cAAc;GAC5C,IAAI,MAAM,QAAQ,OAAO,MAAM,QAAQ,YAAY;GACnD,eAAe;GACf,IAAI,MAAM,YAAY,MAAM,oBAAoB,MAAM,WAAW,MAAM,eAAe;GACtF,MAAM,eAAe;GACpB,MAAO,cAA8B,MAAM;EAC9C;EAEA,SAAS,SAAS;GAChB,eAAe;EACjB;;GAIE,OAAAC,UAAA,GAAAC,YAWYC,wBAVL,SAAA,QAAY,eAAA,QAAc,SAAA,WAAA,GAAA,GADjCC,WAWY;IATN,SAAA;IAAJ,KAAI;IACH,OAAO,QAAA;GACA,GAAA,MAAA,OAAK;IACL;IACE;IACF;IACD;;IAEP,SAAAC,cAA0B,CAA1BC,YAA0B,OAAA,EAAlB,OAAO,MAAK,E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"popover.js","names":["_sfc_main"],"sources":["../../../src/components/popover/popover.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { computed, mergeProps, useId, useSlots } from 'vue'\nimport { getTabbable } from '../../composables/use-focus-trap'\nimport { usePopup } from '../../composables/use-popup'\nimport { useNamespace } from '../../utils/namespace'\nimport { OnlyChild } from '../../utils/only-child'\nimport type { PopoverExpose, PopoverProps, PopoverSlots } from './popover'\nimport { useTeleport } from '../../utils/teleport'\n\ndefineOptions({ name: 'DouPopover', inheritAttrs: false })\n\nconst props = withDefaults(defineProps<PopoverProps>(), {\n placement: 'bottom',\n trigger: 'click',\n disabled: false,\n showDelay: 100,\n hideDelay: 150,\n offset: 8,\n teleport: undefined,\n})\nconst teleportTarget = useTeleport(() => props.teleport)\nconst open = defineModel<boolean>('open', { default: false })\ndefineSlots<PopoverSlots>()\nconst slots = useSlots()\n\nconst ns = useNamespace('popover')\nconst id = `dou-popover-${useId()}`\nconst titleId = `${id}-title`\nconst hasTitle = computed(() => !!props.title || !!slots.title)\n\nconst popup = usePopup({\n open,\n trigger: () => props.trigger,\n disabled: () => props.disabled,\n placement: () => props.placement,\n offset: () => props.offset,\n showDelay: () => props.showDelay,\n hideDelay: () => props.hideDelay,\n})\nconst { triggerRef, panelRef, rendered, theme, placement, panelStyle, panelListeners } = popup\n\n// The panel lives at the end of <body>, away from the trigger in tab\n// order. `Tab` from the trigger steps into the panel, and stepping out of\n// either end of the panel lands back on the trigger, from where the\n// browser carries on as usual. Leaving the trigger any other way (`Tab`\n// with nothing to focus in the panel, or `Shift+Tab`) closes the panel, so\n// it doesn't stay open away from the focus.\nfunction onTriggerKeydown(event: KeyboardEvent) {\n if (event.key !== 'Tab' || !open.value || !panelRef.value) return\n const first = event.shiftKey ? undefined : getTabbable(panelRef.value)[0]\n if (!first) return popup.hide()\n event.preventDefault()\n first.focus()\n}\n\nfunction onPanelKeydown(event: KeyboardEvent) {\n if (event.key !== 'Tab' || !panelRef.value) return\n const tabbable = getTabbable(panelRef.value)\n const trigger = popup.reference() as HTMLElement | null\n if (event.shiftKey && document.activeElement === tabbable[0]) {\n event.preventDefault()\n trigger?.focus()\n } else if (!event.shiftKey && document.activeElement === tabbable.at(-1)) {\n trigger?.focus()\n popup.hide()\n }\n}\n\n// Hover has no keyboard of its own: Enter or Space on the trigger (a click\n// with `detail` 0) opens and closes a hover card too, so a screen reader\n// can reach it. A link trigger keeps Enter for following the link.\nfunction onTriggerClick(event: MouseEvent) {\n if (props.trigger !== 'hover' || event.detail !== 0 || props.disabled) return\n if ((event.currentTarget as Element | null)?.matches('a[href]')) return\n if (open.value) return popup.hide()\n popup.tapped.value = true\n popup.show()\n}\n\nconst triggerProps = computed(() =>\n mergeProps(popup.triggerListeners.value, {\n onKeydown: onTriggerKeydown,\n onClick: onTriggerClick,\n 'aria-haspopup': 'dialog' as const,\n // a hover card a tap or the keyboard opened stays, like a dialog\n 'aria-expanded': props.trigger === 'hover' && !popup.tapped.value ? undefined : open.value,\n 'aria-controls': rendered.value ? id : undefined,\n }),\n)\n\nconst panelClasses = computed(() => [ns.b(), 'dou-floating', ns.is('titled', hasTitle.value)])\nconst
|
|
1
|
+
{"version":3,"file":"popover.js","names":["_sfc_main"],"sources":["../../../src/components/popover/popover.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { computed, mergeProps, useId, useSlots } from 'vue'\nimport type { CSSProperties } from 'vue'\nimport { getTabbable } from '../../composables/use-focus-trap'\nimport { usePopup } from '../../composables/use-popup'\nimport { useNamespace } from '../../utils/namespace'\nimport { OnlyChild } from '../../utils/only-child'\nimport type { PopoverExpose, PopoverProps, PopoverSlots } from './popover'\nimport { useTeleport } from '../../utils/teleport'\n\ndefineOptions({ name: 'DouPopover', inheritAttrs: false })\n\nconst props = withDefaults(defineProps<PopoverProps>(), {\n placement: 'bottom',\n trigger: 'click',\n disabled: false,\n showDelay: 100,\n hideDelay: 150,\n offset: 8,\n openOnTap: true,\n teleport: undefined,\n})\nconst teleportTarget = useTeleport(() => props.teleport)\nconst open = defineModel<boolean>('open', { default: false })\ndefineSlots<PopoverSlots>()\nconst slots = useSlots()\n\nconst ns = useNamespace('popover')\nconst id = `dou-popover-${useId()}`\nconst titleId = `${id}-title`\nconst hasTitle = computed(() => !!props.title || !!slots.title)\n\nconst popup = usePopup({\n open,\n trigger: () => props.trigger,\n disabled: () => props.disabled,\n placement: () => props.placement,\n offset: () => props.offset,\n showDelay: () => props.showDelay,\n hideDelay: () => props.hideDelay,\n tap: () => props.openOnTap,\n})\nconst { triggerRef, panelRef, rendered, theme, placement, panelStyle, panelListeners } = popup\n\n// The panel lives at the end of <body>, away from the trigger in tab\n// order. `Tab` from the trigger steps into the panel, and stepping out of\n// either end of the panel lands back on the trigger, from where the\n// browser carries on as usual. Leaving the trigger any other way (`Tab`\n// with nothing to focus in the panel, or `Shift+Tab`) closes the panel, so\n// it doesn't stay open away from the focus.\nfunction onTriggerKeydown(event: KeyboardEvent) {\n if (event.key !== 'Tab' || !open.value || !panelRef.value) return\n const first = event.shiftKey ? undefined : getTabbable(panelRef.value)[0]\n if (!first) return popup.hide()\n event.preventDefault()\n first.focus()\n}\n\nfunction onPanelKeydown(event: KeyboardEvent) {\n if (event.key !== 'Tab' || !panelRef.value) return\n const tabbable = getTabbable(panelRef.value)\n const trigger = popup.reference() as HTMLElement | null\n if (event.shiftKey && document.activeElement === tabbable[0]) {\n event.preventDefault()\n trigger?.focus()\n } else if (!event.shiftKey && document.activeElement === tabbable.at(-1)) {\n trigger?.focus()\n popup.hide()\n }\n}\n\n// Hover has no keyboard of its own: Enter or Space on the trigger (a click\n// with `detail` 0) opens and closes a hover card too, so a screen reader\n// can reach it. A link trigger keeps Enter for following the link.\nfunction onTriggerClick(event: MouseEvent) {\n if (props.trigger !== 'hover' || event.detail !== 0 || props.disabled) return\n if ((event.currentTarget as Element | null)?.matches('a[href]')) return\n if (open.value) return popup.hide()\n popup.tapped.value = true\n popup.show()\n}\n\nconst triggerProps = computed(() =>\n mergeProps(popup.triggerListeners.value, {\n onKeydown: onTriggerKeydown,\n onClick: onTriggerClick,\n 'aria-haspopup': 'dialog' as const,\n // a hover card a tap or the keyboard opened stays, like a dialog\n 'aria-expanded': props.trigger === 'hover' && !popup.tapped.value ? undefined : open.value,\n 'aria-controls': rendered.value ? id : undefined,\n }),\n)\n\nconst panelClasses = computed(() => [ns.b(), 'dou-floating', ns.is('titled', hasTitle.value)])\nconst cssSize = (value: string | number | undefined) =>\n typeof value === 'number' ? `${value}px` : (value ?? undefined)\nconst panelSizeStyle = computed<CSSProperties>(() => ({\n width: cssSize(props.width),\n ...(props.maxHeight !== undefined && {\n '--dou-popover-max-height': cssSize(props.maxHeight),\n }),\n}))\n\ndefineExpose<PopoverExpose>({ open: () => popup.show(), close: () => popup.dismiss() })\n</script>\n\n<template>\n <OnlyChild ref=\"triggerRef\" v-bind=\"triggerProps\"><slot /></OnlyChild>\n <Teleport v-if=\"rendered\" :to=\"teleportTarget.to\" :disabled=\"teleportTarget.disabled\">\n <Transition appear name=\"dou-floating\">\n <div\n v-show=\"open\"\n :id=\"id\"\n ref=\"panelRef\"\n role=\"dialog\"\n :aria-labelledby=\"hasTitle ? titleId : undefined\"\n :class=\"panelClasses\"\n :style=\"[panelStyle, panelSizeStyle]\"\n :data-placement=\"placement\"\n :data-dou-theme=\"theme\"\n v-bind=\"{ ...$attrs, ...panelListeners }\"\n @keydown=\"onPanelKeydown\"\n >\n <div v-if=\"hasTitle\" :id=\"titleId\" :class=\"ns.e('title')\">\n <slot name=\"title\">{{ title }}</slot>\n </div>\n <div :class=\"ns.e('content')\">\n <slot name=\"content\" :close=\"popup.dismiss\">{{ content }}</slot>\n </div>\n </div>\n </Transition>\n </Teleport>\n</template>\n"],"mappings":""}
|
|
@@ -25,9 +25,14 @@ var popover_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCo
|
|
|
25
25
|
default: false
|
|
26
26
|
},
|
|
27
27
|
width: {},
|
|
28
|
+
maxHeight: {},
|
|
28
29
|
showDelay: { default: 100 },
|
|
29
30
|
hideDelay: { default: 150 },
|
|
30
31
|
offset: { default: 8 },
|
|
32
|
+
openOnTap: {
|
|
33
|
+
type: Boolean,
|
|
34
|
+
default: true
|
|
35
|
+
},
|
|
31
36
|
teleport: {
|
|
32
37
|
type: [String, Boolean],
|
|
33
38
|
default: void 0
|
|
@@ -56,7 +61,8 @@ var popover_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCo
|
|
|
56
61
|
placement: () => props.placement,
|
|
57
62
|
offset: () => props.offset,
|
|
58
63
|
showDelay: () => props.showDelay,
|
|
59
|
-
hideDelay: () => props.hideDelay
|
|
64
|
+
hideDelay: () => props.hideDelay,
|
|
65
|
+
tap: () => props.openOnTap
|
|
60
66
|
});
|
|
61
67
|
const { triggerRef, panelRef, rendered, theme, placement, panelStyle, panelListeners } = popup;
|
|
62
68
|
function onTriggerKeydown(event) {
|
|
@@ -97,7 +103,11 @@ var popover_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCo
|
|
|
97
103
|
"dou-floating",
|
|
98
104
|
ns.is("titled", hasTitle.value)
|
|
99
105
|
]);
|
|
100
|
-
const
|
|
106
|
+
const cssSize = (value) => typeof value === "number" ? `${value}px` : value ?? void 0;
|
|
107
|
+
const panelSizeStyle = computed(() => ({
|
|
108
|
+
width: cssSize(props.width),
|
|
109
|
+
...props.maxHeight !== void 0 && { "--dou-popover-max-height": cssSize(props.maxHeight) }
|
|
110
|
+
}));
|
|
101
111
|
__expose({
|
|
102
112
|
open: () => popup.show(),
|
|
103
113
|
close: () => popup.dismiss()
|
|
@@ -125,7 +135,7 @@ var popover_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCo
|
|
|
125
135
|
role: "dialog",
|
|
126
136
|
"aria-labelledby": hasTitle.value ? titleId : void 0,
|
|
127
137
|
class: panelClasses.value,
|
|
128
|
-
style: [unref(panelStyle),
|
|
138
|
+
style: [unref(panelStyle), panelSizeStyle.value],
|
|
129
139
|
"data-placement": unref(placement),
|
|
130
140
|
"data-dou-theme": unref(theme)
|
|
131
141
|
}, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"popover.vue_vue_type_script_setup_true_lang.js","names":["$attrs","_useModel","_openBlock","_createElementBlock","_Fragment","_createVNode","_unref","_mergeProps","_withCtx","_renderSlot","_createBlock","_Teleport","_Transition","_withDirectives","_createElementVNode","_normalizeClass","_createTextVNode","_toDisplayString","_createCommentVNode","_vShow"],"sources":["../../../src/components/popover/popover.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { computed, mergeProps, useId, useSlots } from 'vue'\nimport { getTabbable } from '../../composables/use-focus-trap'\nimport { usePopup } from '../../composables/use-popup'\nimport { useNamespace } from '../../utils/namespace'\nimport { OnlyChild } from '../../utils/only-child'\nimport type { PopoverExpose, PopoverProps, PopoverSlots } from './popover'\nimport { useTeleport } from '../../utils/teleport'\n\ndefineOptions({ name: 'DouPopover', inheritAttrs: false })\n\nconst props = withDefaults(defineProps<PopoverProps>(), {\n placement: 'bottom',\n trigger: 'click',\n disabled: false,\n showDelay: 100,\n hideDelay: 150,\n offset: 8,\n teleport: undefined,\n})\nconst teleportTarget = useTeleport(() => props.teleport)\nconst open = defineModel<boolean>('open', { default: false })\ndefineSlots<PopoverSlots>()\nconst slots = useSlots()\n\nconst ns = useNamespace('popover')\nconst id = `dou-popover-${useId()}`\nconst titleId = `${id}-title`\nconst hasTitle = computed(() => !!props.title || !!slots.title)\n\nconst popup = usePopup({\n open,\n trigger: () => props.trigger,\n disabled: () => props.disabled,\n placement: () => props.placement,\n offset: () => props.offset,\n showDelay: () => props.showDelay,\n hideDelay: () => props.hideDelay,\n})\nconst { triggerRef, panelRef, rendered, theme, placement, panelStyle, panelListeners } = popup\n\n// The panel lives at the end of <body>, away from the trigger in tab\n// order. `Tab` from the trigger steps into the panel, and stepping out of\n// either end of the panel lands back on the trigger, from where the\n// browser carries on as usual. Leaving the trigger any other way (`Tab`\n// with nothing to focus in the panel, or `Shift+Tab`) closes the panel, so\n// it doesn't stay open away from the focus.\nfunction onTriggerKeydown(event: KeyboardEvent) {\n if (event.key !== 'Tab' || !open.value || !panelRef.value) return\n const first = event.shiftKey ? undefined : getTabbable(panelRef.value)[0]\n if (!first) return popup.hide()\n event.preventDefault()\n first.focus()\n}\n\nfunction onPanelKeydown(event: KeyboardEvent) {\n if (event.key !== 'Tab' || !panelRef.value) return\n const tabbable = getTabbable(panelRef.value)\n const trigger = popup.reference() as HTMLElement | null\n if (event.shiftKey && document.activeElement === tabbable[0]) {\n event.preventDefault()\n trigger?.focus()\n } else if (!event.shiftKey && document.activeElement === tabbable.at(-1)) {\n trigger?.focus()\n popup.hide()\n }\n}\n\n// Hover has no keyboard of its own: Enter or Space on the trigger (a click\n// with `detail` 0) opens and closes a hover card too, so a screen reader\n// can reach it. A link trigger keeps Enter for following the link.\nfunction onTriggerClick(event: MouseEvent) {\n if (props.trigger !== 'hover' || event.detail !== 0 || props.disabled) return\n if ((event.currentTarget as Element | null)?.matches('a[href]')) return\n if (open.value) return popup.hide()\n popup.tapped.value = true\n popup.show()\n}\n\nconst triggerProps = computed(() =>\n mergeProps(popup.triggerListeners.value, {\n onKeydown: onTriggerKeydown,\n onClick: onTriggerClick,\n 'aria-haspopup': 'dialog' as const,\n // a hover card a tap or the keyboard opened stays, like a dialog\n 'aria-expanded': props.trigger === 'hover' && !popup.tapped.value ? undefined : open.value,\n 'aria-controls': rendered.value ? id : undefined,\n }),\n)\n\nconst panelClasses = computed(() => [ns.b(), 'dou-floating', ns.is('titled', hasTitle.value)])\nconst
|
|
1
|
+
{"version":3,"file":"popover.vue_vue_type_script_setup_true_lang.js","names":["$attrs","_useModel","_openBlock","_createElementBlock","_Fragment","_createVNode","_unref","_mergeProps","_withCtx","_renderSlot","_createBlock","_Teleport","_Transition","_withDirectives","_createElementVNode","_normalizeClass","_createTextVNode","_toDisplayString","_createCommentVNode","_vShow"],"sources":["../../../src/components/popover/popover.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { computed, mergeProps, useId, useSlots } from 'vue'\nimport type { CSSProperties } from 'vue'\nimport { getTabbable } from '../../composables/use-focus-trap'\nimport { usePopup } from '../../composables/use-popup'\nimport { useNamespace } from '../../utils/namespace'\nimport { OnlyChild } from '../../utils/only-child'\nimport type { PopoverExpose, PopoverProps, PopoverSlots } from './popover'\nimport { useTeleport } from '../../utils/teleport'\n\ndefineOptions({ name: 'DouPopover', inheritAttrs: false })\n\nconst props = withDefaults(defineProps<PopoverProps>(), {\n placement: 'bottom',\n trigger: 'click',\n disabled: false,\n showDelay: 100,\n hideDelay: 150,\n offset: 8,\n openOnTap: true,\n teleport: undefined,\n})\nconst teleportTarget = useTeleport(() => props.teleport)\nconst open = defineModel<boolean>('open', { default: false })\ndefineSlots<PopoverSlots>()\nconst slots = useSlots()\n\nconst ns = useNamespace('popover')\nconst id = `dou-popover-${useId()}`\nconst titleId = `${id}-title`\nconst hasTitle = computed(() => !!props.title || !!slots.title)\n\nconst popup = usePopup({\n open,\n trigger: () => props.trigger,\n disabled: () => props.disabled,\n placement: () => props.placement,\n offset: () => props.offset,\n showDelay: () => props.showDelay,\n hideDelay: () => props.hideDelay,\n tap: () => props.openOnTap,\n})\nconst { triggerRef, panelRef, rendered, theme, placement, panelStyle, panelListeners } = popup\n\n// The panel lives at the end of <body>, away from the trigger in tab\n// order. `Tab` from the trigger steps into the panel, and stepping out of\n// either end of the panel lands back on the trigger, from where the\n// browser carries on as usual. Leaving the trigger any other way (`Tab`\n// with nothing to focus in the panel, or `Shift+Tab`) closes the panel, so\n// it doesn't stay open away from the focus.\nfunction onTriggerKeydown(event: KeyboardEvent) {\n if (event.key !== 'Tab' || !open.value || !panelRef.value) return\n const first = event.shiftKey ? undefined : getTabbable(panelRef.value)[0]\n if (!first) return popup.hide()\n event.preventDefault()\n first.focus()\n}\n\nfunction onPanelKeydown(event: KeyboardEvent) {\n if (event.key !== 'Tab' || !panelRef.value) return\n const tabbable = getTabbable(panelRef.value)\n const trigger = popup.reference() as HTMLElement | null\n if (event.shiftKey && document.activeElement === tabbable[0]) {\n event.preventDefault()\n trigger?.focus()\n } else if (!event.shiftKey && document.activeElement === tabbable.at(-1)) {\n trigger?.focus()\n popup.hide()\n }\n}\n\n// Hover has no keyboard of its own: Enter or Space on the trigger (a click\n// with `detail` 0) opens and closes a hover card too, so a screen reader\n// can reach it. A link trigger keeps Enter for following the link.\nfunction onTriggerClick(event: MouseEvent) {\n if (props.trigger !== 'hover' || event.detail !== 0 || props.disabled) return\n if ((event.currentTarget as Element | null)?.matches('a[href]')) return\n if (open.value) return popup.hide()\n popup.tapped.value = true\n popup.show()\n}\n\nconst triggerProps = computed(() =>\n mergeProps(popup.triggerListeners.value, {\n onKeydown: onTriggerKeydown,\n onClick: onTriggerClick,\n 'aria-haspopup': 'dialog' as const,\n // a hover card a tap or the keyboard opened stays, like a dialog\n 'aria-expanded': props.trigger === 'hover' && !popup.tapped.value ? undefined : open.value,\n 'aria-controls': rendered.value ? id : undefined,\n }),\n)\n\nconst panelClasses = computed(() => [ns.b(), 'dou-floating', ns.is('titled', hasTitle.value)])\nconst cssSize = (value: string | number | undefined) =>\n typeof value === 'number' ? `${value}px` : (value ?? undefined)\nconst panelSizeStyle = computed<CSSProperties>(() => ({\n width: cssSize(props.width),\n ...(props.maxHeight !== undefined && {\n '--dou-popover-max-height': cssSize(props.maxHeight),\n }),\n}))\n\ndefineExpose<PopoverExpose>({ open: () => popup.show(), close: () => popup.dismiss() })\n</script>\n\n<template>\n <OnlyChild ref=\"triggerRef\" v-bind=\"triggerProps\"><slot /></OnlyChild>\n <Teleport v-if=\"rendered\" :to=\"teleportTarget.to\" :disabled=\"teleportTarget.disabled\">\n <Transition appear name=\"dou-floating\">\n <div\n v-show=\"open\"\n :id=\"id\"\n ref=\"panelRef\"\n role=\"dialog\"\n :aria-labelledby=\"hasTitle ? titleId : undefined\"\n :class=\"panelClasses\"\n :style=\"[panelStyle, panelSizeStyle]\"\n :data-placement=\"placement\"\n :data-dou-theme=\"theme\"\n v-bind=\"{ ...$attrs, ...panelListeners }\"\n @keydown=\"onPanelKeydown\"\n >\n <div v-if=\"hasTitle\" :id=\"titleId\" :class=\"ns.e('title')\">\n <slot name=\"title\">{{ title }}</slot>\n </div>\n <div :class=\"ns.e('content')\">\n <slot name=\"content\" :close=\"popup.dismiss\">{{ content }}</slot>\n </div>\n </div>\n </Transition>\n </Teleport>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAYA,MAAM,QAAQ;EAUd,MAAM,iBAAiB,kBAAkB,MAAM,QAAQ;EACvD,MAAM,OAAOC,SAAoB,SAAC,MAA0B;EAE5D,MAAM,QAAQ,SAAS;EAEvB,MAAM,KAAK,aAAa,SAAS;EACjC,MAAM,KAAK,eAAe,MAAM;EAChC,MAAM,UAAU,GAAG,GAAG;E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