@antcde/component-library 0.1.25-rc.4 → 0.1.25-rc.6
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/index.js +10388 -9706
- package/dist/types/src/components/FilePreviewContent/_PreviewDetails.vue.d.ts +18 -0
- package/dist/types/src/components/FilePreviewContent/_PreviewMeta.vue.d.ts +13 -0
- package/dist/types/src/components/FilePreviewContent/_PreviewUsages.vue.d.ts +13 -0
- package/dist/types/src/components/FilePreviewContent/fileFormat.d.ts +7 -0
- package/dist/types/src/components/FilePreviewContent/index.vue.d.ts +20 -14
- package/dist/types/src/components/FilePreviewContent/types.d.ts +27 -0
- package/dist/types/src/components/FilePreviewContent/usePreviewDetails.d.ts +49 -0
- package/dist/types/src/components/UnifiedWindow/_WindowPresetMenu.vue.d.ts +11 -0
- package/dist/types/src/components/UnifiedWindow/_WindowTabs.vue.d.ts +16 -0
- package/dist/types/src/components/UnifiedWindow/index.vue.d.ts +3 -9
- package/dist/types/src/components/UnifiedWindow/types.d.ts +11 -0
- package/dist/types/src/components/UnifiedWindow/useNativeFullscreen.d.ts +18 -0
- package/dist/types/src/components/UnifiedWindow/useWindowDrag.d.ts +8 -0
- package/dist/types/src/index.d.ts +1 -1
- package/lib/PdfViewer/PdfViewer.vue +245 -0
- package/lib/PdfViewer/_PdfToolbar.vue +196 -0
- package/lib/PdfViewer/canvasBudget.ts +57 -0
- package/lib/PdfViewer/index.ts +5 -0
- package/lib/PdfViewer/labels.ts +52 -0
- package/lib/PdfViewer/usePdfDocument.ts +195 -0
- package/lib/PdfViewer/usePdfKeyboard.ts +38 -0
- package/lib/PdfViewer/usePdfRaster.ts +85 -0
- package/lib/PdfViewer/usePdfTransform.ts +238 -0
- package/lib/test/mocks/createMockContext.ts +2 -0
- package/package.json +27 -20
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import type { Ref } from 'vue'
|
|
2
|
+
import { computed, onBeforeUnmount, ref, watch } from 'vue'
|
|
3
|
+
|
|
4
|
+
export const MIN_ZOOM = 0.25
|
|
5
|
+
export const MAX_ZOOM = 8
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Zoom is expressed relative to fit-page, so `1` always means "the whole page
|
|
9
|
+
* fits the pane". A percentage relative to the PDF's paper size — what a
|
|
10
|
+
* desktop reader shows — is meaningless on a drawing that is two metres wide
|
|
11
|
+
* on paper and 900 pixels tall on the screen.
|
|
12
|
+
*/
|
|
13
|
+
export interface PdfTransformDeps {
|
|
14
|
+
/** The element gestures are bound to; also defines the visible viewport. */
|
|
15
|
+
container: Ref<HTMLElement | null>
|
|
16
|
+
/** Intrinsic page size in CSS pixels at scale 1, already rotated. */
|
|
17
|
+
pageWidth: Ref<number>
|
|
18
|
+
pageHeight: Ref<number>
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function clamp(value: number, min: number, max: number): number {
|
|
22
|
+
return Math.min(Math.max(value, min), max)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function usePdfTransform({ container, pageWidth, pageHeight }: PdfTransformDeps) {
|
|
26
|
+
const zoom = ref(1)
|
|
27
|
+
const tx = ref(0)
|
|
28
|
+
const ty = ref(0)
|
|
29
|
+
const viewportWidth = ref(0)
|
|
30
|
+
const viewportHeight = ref(0)
|
|
31
|
+
/** True while a pointer gesture is in flight — used to defer re-rendering. */
|
|
32
|
+
const isGesturing = ref(false)
|
|
33
|
+
|
|
34
|
+
/** Scale at which the whole page fits the pane; the unit `zoom` multiplies. */
|
|
35
|
+
const fitScale = computed(() => {
|
|
36
|
+
if (pageWidth.value <= 0 || pageHeight.value <= 0 || viewportWidth.value <= 0)
|
|
37
|
+
return 1
|
|
38
|
+
return Math.min(viewportWidth.value / pageWidth.value, viewportHeight.value / pageHeight.value)
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
/** The scale actually applied to the page right now. */
|
|
42
|
+
const displayScale = computed(() => fitScale.value * zoom.value)
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Keep the page anchored to the pane: centred on any axis where it is smaller
|
|
46
|
+
* than the pane, and otherwise never dragged past its own edge. Without this a
|
|
47
|
+
* single enthusiastic swipe flings the drawing off-screen and the operator has
|
|
48
|
+
* no way back except reload.
|
|
49
|
+
*/
|
|
50
|
+
function clampPan() {
|
|
51
|
+
const s = displayScale.value
|
|
52
|
+
const dw = pageWidth.value * s
|
|
53
|
+
const dh = pageHeight.value * s
|
|
54
|
+
tx.value = dw <= viewportWidth.value ? (viewportWidth.value - dw) / 2 : clamp(tx.value, viewportWidth.value - dw, 0)
|
|
55
|
+
ty.value = dh <= viewportHeight.value ? (viewportHeight.value - dh) / 2 : clamp(ty.value, viewportHeight.value - dh, 0)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Zoom by `factor`, holding the point (cx, cy) in pane coordinates still. */
|
|
59
|
+
function zoomAt(factor: number, cx: number, cy: number) {
|
|
60
|
+
const next = clamp(zoom.value * factor, MIN_ZOOM, MAX_ZOOM)
|
|
61
|
+
const ratio = next / zoom.value
|
|
62
|
+
if (ratio === 1)
|
|
63
|
+
return
|
|
64
|
+
tx.value = cx - (cx - tx.value) * ratio
|
|
65
|
+
ty.value = cy - (cy - ty.value) * ratio
|
|
66
|
+
zoom.value = next
|
|
67
|
+
clampPan()
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function zoomByStep(factor: number) {
|
|
71
|
+
zoomAt(factor, viewportWidth.value / 2, viewportHeight.value / 2)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function setZoom(next: number) {
|
|
75
|
+
zoomAt(clamp(next, MIN_ZOOM, MAX_ZOOM) / zoom.value, viewportWidth.value / 2, viewportHeight.value / 2)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function fitPage() {
|
|
79
|
+
zoom.value = 1
|
|
80
|
+
clampPan()
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Fill the pane's width — the useful default for a landscape drawing. */
|
|
84
|
+
function fitWidth() {
|
|
85
|
+
const fit = fitScale.value
|
|
86
|
+
if (fit <= 0 || pageWidth.value <= 0)
|
|
87
|
+
return
|
|
88
|
+
zoom.value = clamp((viewportWidth.value / pageWidth.value) / fit, MIN_ZOOM, MAX_ZOOM)
|
|
89
|
+
tx.value = 0
|
|
90
|
+
ty.value = 0
|
|
91
|
+
clampPan()
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// ── Pointer gestures ──
|
|
95
|
+
// Pointer events rather than separate touch and mouse handlers: one code path
|
|
96
|
+
// covers finger, stylus and mouse, and multi-touch works the same in WebKit as
|
|
97
|
+
// it does in Chromium.
|
|
98
|
+
const points = new Map<number, { x: number, y: number }>()
|
|
99
|
+
let pinchDistance = 0
|
|
100
|
+
let pinchMidX = 0
|
|
101
|
+
let pinchMidY = 0
|
|
102
|
+
|
|
103
|
+
/** Widened past PointerEvent so wheel and dblclick can share it. */
|
|
104
|
+
function paneCoords(e: { clientX: number, clientY: number }): { x: number, y: number } {
|
|
105
|
+
const rect = container.value?.getBoundingClientRect()
|
|
106
|
+
return { x: e.clientX - (rect?.left ?? 0), y: e.clientY - (rect?.top ?? 0) }
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function onPointerDown(e: PointerEvent) {
|
|
110
|
+
const el = container.value
|
|
111
|
+
if (!el)
|
|
112
|
+
return
|
|
113
|
+
el.setPointerCapture(e.pointerId)
|
|
114
|
+
points.set(e.pointerId, paneCoords(e))
|
|
115
|
+
isGesturing.value = true
|
|
116
|
+
if (points.size === 2)
|
|
117
|
+
startPinch()
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function startPinch() {
|
|
121
|
+
const [a, b] = [...points.values()]
|
|
122
|
+
pinchDistance = Math.hypot(a.x - b.x, a.y - b.y)
|
|
123
|
+
pinchMidX = (a.x + b.x) / 2
|
|
124
|
+
pinchMidY = (a.y + b.y) / 2
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function onPointerMove(e: PointerEvent) {
|
|
128
|
+
const prev = points.get(e.pointerId)
|
|
129
|
+
if (!prev)
|
|
130
|
+
return
|
|
131
|
+
const next = paneCoords(e)
|
|
132
|
+
points.set(e.pointerId, next)
|
|
133
|
+
|
|
134
|
+
if (points.size >= 2) {
|
|
135
|
+
const [a, b] = [...points.values()]
|
|
136
|
+
const distance = Math.hypot(a.x - b.x, a.y - b.y)
|
|
137
|
+
const midX = (a.x + b.x) / 2
|
|
138
|
+
const midY = (a.y + b.y) / 2
|
|
139
|
+
// Pan by however far the pinch centre travelled, then scale about it, so
|
|
140
|
+
// a two-finger drag pans and pinches at once the way a map does.
|
|
141
|
+
tx.value += midX - pinchMidX
|
|
142
|
+
ty.value += midY - pinchMidY
|
|
143
|
+
if (pinchDistance > 0)
|
|
144
|
+
zoomAt(distance / pinchDistance, midX, midY)
|
|
145
|
+
pinchDistance = distance
|
|
146
|
+
pinchMidX = midX
|
|
147
|
+
pinchMidY = midY
|
|
148
|
+
return
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
tx.value += next.x - prev.x
|
|
152
|
+
ty.value += next.y - prev.y
|
|
153
|
+
clampPan()
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function onPointerUp(e: PointerEvent) {
|
|
157
|
+
points.delete(e.pointerId)
|
|
158
|
+
container.value?.releasePointerCapture?.(e.pointerId)
|
|
159
|
+
if (points.size === 2)
|
|
160
|
+
startPinch()
|
|
161
|
+
if (points.size === 0) {
|
|
162
|
+
isGesturing.value = false
|
|
163
|
+
pinchDistance = 0
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function onWheel(e: WheelEvent) {
|
|
168
|
+
e.preventDefault()
|
|
169
|
+
const { x, y } = paneCoords(e)
|
|
170
|
+
// A trackpad pinch arrives as a wheel event with ctrlKey set; its deltas are
|
|
171
|
+
// finer-grained than a mouse wheel's, so it gets a proportional factor.
|
|
172
|
+
const factor = e.ctrlKey ? Math.exp(-e.deltaY * 0.01) : (e.deltaY > 0 ? 0.9 : 1.1)
|
|
173
|
+
zoomAt(factor, x, y)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** Double-tap toggles between the whole page and a readable close-up. */
|
|
177
|
+
function onDoubleClick(e: MouseEvent) {
|
|
178
|
+
const { x, y } = paneCoords(e)
|
|
179
|
+
if (zoom.value > 1.05)
|
|
180
|
+
fitPage()
|
|
181
|
+
else
|
|
182
|
+
zoomAt(2.5 / zoom.value, x, y)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
let observer: ResizeObserver | null = null
|
|
186
|
+
|
|
187
|
+
function measure(el: HTMLElement) {
|
|
188
|
+
viewportWidth.value = el.clientWidth
|
|
189
|
+
viewportHeight.value = el.clientHeight
|
|
190
|
+
clampPan()
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
watch(container, (el, _old, onCleanup) => {
|
|
194
|
+
observer?.disconnect()
|
|
195
|
+
observer = null
|
|
196
|
+
if (!el)
|
|
197
|
+
return
|
|
198
|
+
measure(el)
|
|
199
|
+
el.addEventListener('wheel', onWheel, { passive: false })
|
|
200
|
+
if (typeof ResizeObserver !== 'undefined') {
|
|
201
|
+
observer = new ResizeObserver(() => measure(el))
|
|
202
|
+
observer.observe(el)
|
|
203
|
+
}
|
|
204
|
+
onCleanup(() => {
|
|
205
|
+
el.removeEventListener('wheel', onWheel)
|
|
206
|
+
observer?.disconnect()
|
|
207
|
+
observer = null
|
|
208
|
+
})
|
|
209
|
+
}, { immediate: true })
|
|
210
|
+
|
|
211
|
+
onBeforeUnmount(() => {
|
|
212
|
+
observer?.disconnect()
|
|
213
|
+
observer = null
|
|
214
|
+
})
|
|
215
|
+
|
|
216
|
+
return {
|
|
217
|
+
zoom,
|
|
218
|
+
tx,
|
|
219
|
+
ty,
|
|
220
|
+
viewportWidth,
|
|
221
|
+
viewportHeight,
|
|
222
|
+
isGesturing,
|
|
223
|
+
fitScale,
|
|
224
|
+
displayScale,
|
|
225
|
+
clampPan,
|
|
226
|
+
zoomAt,
|
|
227
|
+
zoomByStep,
|
|
228
|
+
setZoom,
|
|
229
|
+
fitPage,
|
|
230
|
+
fitWidth,
|
|
231
|
+
handlers: {
|
|
232
|
+
onPointerDown,
|
|
233
|
+
onPointerMove,
|
|
234
|
+
onPointerUp,
|
|
235
|
+
onDoubleClick,
|
|
236
|
+
},
|
|
237
|
+
}
|
|
238
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antcde/component-library",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.25-rc.
|
|
4
|
+
"version": "0.1.25-rc.6",
|
|
5
5
|
"description": "Helper to use ant components in Vue 3",
|
|
6
6
|
"author": "CollaborAll",
|
|
7
7
|
"exports": {
|
|
@@ -59,6 +59,12 @@
|
|
|
59
59
|
"./lib/ForgeViewer/*": {
|
|
60
60
|
"import": "./lib/ForgeViewer/*"
|
|
61
61
|
},
|
|
62
|
+
"./lib/PdfViewer": {
|
|
63
|
+
"import": "./lib/PdfViewer/index.ts"
|
|
64
|
+
},
|
|
65
|
+
"./lib/PdfViewer/*": {
|
|
66
|
+
"import": "./lib/PdfViewer/*"
|
|
67
|
+
},
|
|
62
68
|
"./lib/GisViewer": {
|
|
63
69
|
"import": "./lib/GisViewer/index.ts"
|
|
64
70
|
},
|
|
@@ -184,45 +190,46 @@
|
|
|
184
190
|
"dependencies": {
|
|
185
191
|
"@arcgis/core": "^4.34.8",
|
|
186
192
|
"@mdi/font": "^7.4.47",
|
|
187
|
-
"@tiptap/extension-link": "^3.
|
|
188
|
-
"@tiptap/extension-mention": "^3.
|
|
189
|
-
"@tiptap/extension-placeholder": "^3.
|
|
190
|
-
"@tiptap/starter-kit": "^3.
|
|
191
|
-
"@tiptap/suggestion": "^3.
|
|
192
|
-
"@tiptap/vue-3": "^3.
|
|
193
|
+
"@tiptap/extension-link": "^3.30.3",
|
|
194
|
+
"@tiptap/extension-mention": "^3.30.3",
|
|
195
|
+
"@tiptap/extension-placeholder": "^3.30.3",
|
|
196
|
+
"@tiptap/starter-kit": "^3.30.3",
|
|
197
|
+
"@tiptap/suggestion": "^3.30.3",
|
|
198
|
+
"@tiptap/vue-3": "^3.30.3",
|
|
193
199
|
"@vue-flow/background": "^1.3.2",
|
|
194
200
|
"@vue-flow/core": "^1.48.2",
|
|
195
201
|
"@vue-flow/minimap": "^1.5.4",
|
|
196
|
-
"@vueuse/core": "^14.
|
|
202
|
+
"@vueuse/core": "^14.4.0",
|
|
203
|
+
"pdfjs-dist": "^5.7.284",
|
|
197
204
|
"qs": "^6.15.3",
|
|
198
|
-
"sanitize-html": "^2.17.
|
|
199
|
-
"vue-i18n": "^11.4.
|
|
205
|
+
"sanitize-html": "^2.17.7",
|
|
206
|
+
"vue-i18n": "^11.4.9"
|
|
200
207
|
},
|
|
201
208
|
"devDependencies": {
|
|
202
|
-
"@antcde/connect-ts": "0.4.27-rc.
|
|
203
|
-
"@antcde/vue-utils": "0.2.22-rc.
|
|
209
|
+
"@antcde/connect-ts": "0.4.27-rc.6",
|
|
210
|
+
"@antcde/vue-utils": "0.2.22-rc.6",
|
|
204
211
|
"@arcgis/core": "^4.30.9",
|
|
205
212
|
"@iconify-json/mdi": "^1.2.3",
|
|
206
213
|
"@iconify/vue": "^5.0.1",
|
|
207
|
-
"@intlify/unplugin-vue-i18n": "^11.2.
|
|
214
|
+
"@intlify/unplugin-vue-i18n": "^11.2.5",
|
|
208
215
|
"@mdi/font": "^7.2.96",
|
|
209
|
-
"@tsconfig/node22": "^22.0.
|
|
216
|
+
"@tsconfig/node22": "^22.0.6",
|
|
210
217
|
"@types/node": "^25.9.5",
|
|
211
218
|
"@types/qs": "^6.15.1",
|
|
212
219
|
"@vitejs/plugin-vue": "^6.0.8",
|
|
213
220
|
"@vue/test-utils": "^2.4.11",
|
|
214
221
|
"@vue/tsconfig": "^0.9.1",
|
|
215
|
-
"happy-dom": "^20.11.
|
|
222
|
+
"happy-dom": "^20.11.6",
|
|
216
223
|
"pinia": "^3.0.4",
|
|
217
|
-
"sass": "^1.
|
|
224
|
+
"sass": "^1.103.1",
|
|
218
225
|
"typescript": "~6.0.3",
|
|
219
226
|
"unplugin-icons": "^23.0.1",
|
|
220
|
-
"vite": "^8.
|
|
227
|
+
"vite": "^8.2.2",
|
|
221
228
|
"vite-plugin-css-injected-by-js": "^5.0.2",
|
|
222
229
|
"vite-plugin-dts": "^4.5.4",
|
|
223
230
|
"vite-plugin-vuetify": "^2.1.3",
|
|
224
|
-
"vitest": "^4.1.
|
|
225
|
-
"vue": "^3.5.
|
|
226
|
-
"vue-tsc": "^3.3.
|
|
231
|
+
"vitest": "^4.1.11",
|
|
232
|
+
"vue": "^3.5.41",
|
|
233
|
+
"vue-tsc": "^3.3.11"
|
|
227
234
|
}
|
|
228
235
|
}
|