@antcde/component-library 0.1.24 → 0.1.25-rc.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/dist/build/uno.js +9 -1
  2. package/dist/index.js +20683 -20066
  3. package/dist/types/src/components/BaseAntInput.types.d.ts +111 -0
  4. package/dist/types/src/components/BaseAntInput.vue.d.ts +2 -74
  5. package/dist/types/src/components/BaseAppCard/_BaseAppCardHint.vue.d.ts +17 -0
  6. package/dist/types/src/components/BaseAppCard/_BaseAppCardMedia.vue.d.ts +27 -0
  7. package/dist/types/src/components/BaseAppCard/_BaseAppCardTitle.vue.d.ts +5 -0
  8. package/dist/types/src/components/BaseAppCard/_BaseAppCardToolbar.vue.d.ts +18 -0
  9. package/dist/types/src/components/BaseAppCard/_BaseAppCardUpdate.vue.d.ts +8 -0
  10. package/dist/types/src/components/{BaseAppCard.vue.d.ts → BaseAppCard/index.vue.d.ts} +22 -7
  11. package/dist/types/src/components/BaseAppCardSkeleton.vue.d.ts +6 -0
  12. package/dist/types/src/components/BaseResizePanel.vue.d.ts +19 -18
  13. package/dist/types/src/components/DmsFilePicker/composables/usePickerNavigation.d.ts +8 -0
  14. package/dist/types/src/components/DmsFilePicker/composables/usePickerUpload.d.ts +2 -0
  15. package/dist/types/src/components/DmsFilePicker/utils/fileFormatting.d.ts +1 -0
  16. package/dist/types/src/components/FilePreviewContent/_PreviewDetails.vue.d.ts +18 -0
  17. package/dist/types/src/components/FilePreviewContent/_PreviewMeta.vue.d.ts +13 -0
  18. package/dist/types/src/components/FilePreviewContent/_PreviewUsages.vue.d.ts +13 -0
  19. package/dist/types/src/components/FilePreviewContent/fileFormat.d.ts +7 -0
  20. package/dist/types/src/components/FilePreviewContent/index.vue.d.ts +20 -14
  21. package/dist/types/src/components/FilePreviewContent/types.d.ts +27 -0
  22. package/dist/types/src/components/FilePreviewContent/usePreviewDetails.d.ts +49 -0
  23. package/dist/types/src/components/FlowWindowContent/index.vue.d.ts +5 -1
  24. package/dist/types/src/components/RichTextEditor/_MentionPanel.vue.d.ts +18 -0
  25. package/dist/types/src/components/RichTextEditor/_Toolbar.vue.d.ts +6 -0
  26. package/dist/types/src/components/RichTextEditor/_useInlineEdit.d.ts +28 -0
  27. package/dist/types/src/components/RichTextEditor/_useMentionPicker.d.ts +47 -0
  28. package/dist/types/src/components/RichTextEditor/index.vue.d.ts +20 -6
  29. package/dist/types/src/components/TasksFlow/components/_FlowBreadcrumb.vue.d.ts +11 -1
  30. package/dist/types/src/components/TasksFlow/components/_FlowEdgeDeleteDialog.vue.d.ts +11 -0
  31. package/dist/types/src/components/TasksFlow/components/_FlowEdgeLagMenu.vue.d.ts +14 -0
  32. package/dist/types/src/components/TasksFlow/components/_FlowLifecycleBar.vue.d.ts +16 -0
  33. package/dist/types/src/components/TasksFlow/components/_FlowStructureTree.vue.d.ts +14 -0
  34. package/dist/types/src/components/TasksFlow/components/_FlowToolbar.vue.d.ts +5 -2
  35. package/dist/types/src/components/TasksFlow/components/_FlowVersionBar.vue.d.ts +2 -0
  36. package/dist/types/src/components/TasksFlow/components/_flowEdge.vue.d.ts +4 -1
  37. package/dist/types/src/components/TasksFlow/components/nodes/_endpointNode.vue.d.ts +10 -0
  38. package/dist/types/src/components/TasksFlow/components/nodes/_swimlaneNode.vue.d.ts +6 -0
  39. package/dist/types/src/components/TasksFlow/components/nodes/useTaskNodeState.d.ts +5 -5
  40. package/dist/types/src/components/TasksFlow/composables/_layoutEngine.d.ts +19 -0
  41. package/dist/types/src/components/TasksFlow/composables/useAutoLayout.d.ts +6 -10
  42. package/dist/types/src/components/TasksFlow/composables/useFlowDisplayElements.d.ts +15 -0
  43. package/dist/types/src/components/TasksFlow/composables/useFlowEndpoints.d.ts +10 -0
  44. package/dist/types/src/components/TasksFlow/composables/useFlowLifecycle.d.ts +18 -0
  45. package/dist/types/src/components/TasksFlow/composables/useFlowRealtime.d.ts +3 -1
  46. package/dist/types/src/components/TasksFlow/composables/useFlowStructureTree.d.ts +19 -0
  47. package/dist/types/src/components/TasksFlow/composables/useFlowToolbarDrag.d.ts +6 -0
  48. package/dist/types/src/components/TasksFlow/composables/useFlowViewport.d.ts +1 -4
  49. package/dist/types/src/components/TasksFlow/composables/useSwimlaneLayout.d.ts +23 -0
  50. package/dist/types/src/components/TasksFlow/composables/useTaskFlow.d.ts +58 -4
  51. package/dist/types/src/components/TasksFlow/composables/useTaskFlowTypes.d.ts +4 -0
  52. package/dist/types/src/components/TasksFlow/composables/useTemplateVersioning.d.ts +53 -4
  53. package/dist/types/src/components/TasksFlow/composables/useTemplateVersioningState.d.ts +52 -4
  54. package/dist/types/src/components/TasksFlow/index.vue.d.ts +10 -0
  55. package/dist/types/src/components/UnifiedWindow/_WindowPresetMenu.vue.d.ts +11 -0
  56. package/dist/types/src/components/UnifiedWindow/_WindowTabs.vue.d.ts +16 -0
  57. package/dist/types/src/components/UnifiedWindow/index.vue.d.ts +3 -9
  58. package/dist/types/src/components/UnifiedWindow/types.d.ts +11 -0
  59. package/dist/types/src/components/UnifiedWindow/useNativeFullscreen.d.ts +18 -0
  60. package/dist/types/src/components/UnifiedWindow/useWindowDrag.d.ts +8 -0
  61. package/dist/types/src/components/_BaseAntInputField.vue.d.ts +36 -0
  62. package/dist/types/src/components/_BaseAntInputLabel.vue.d.ts +33 -0
  63. package/dist/types/src/components/useResizePanel.d.ts +38 -0
  64. package/dist/types/src/index.d.ts +3 -3
  65. package/lib/PdfViewer/PdfViewer.vue +245 -0
  66. package/lib/PdfViewer/_PdfToolbar.vue +196 -0
  67. package/lib/PdfViewer/canvasBudget.ts +57 -0
  68. package/lib/PdfViewer/index.ts +5 -0
  69. package/lib/PdfViewer/labels.ts +52 -0
  70. package/lib/PdfViewer/usePdfDocument.ts +239 -0
  71. package/lib/PdfViewer/usePdfKeyboard.ts +38 -0
  72. package/lib/PdfViewer/usePdfRaster.ts +85 -0
  73. package/lib/PdfViewer/usePdfTransform.ts +238 -0
  74. package/lib/build/uno.ts +10 -1
  75. package/lib/test/mocks/createMockContext.ts +2 -0
  76. package/lib/test/setup.ts +8 -0
  77. package/package.json +39 -28
@@ -0,0 +1,239 @@
1
+ import type { PDFDocumentLoadingTask, PDFDocumentProxy, PDFPageProxy, RenderTask } from 'pdfjs-dist'
2
+ import type { Ref } from 'vue'
3
+ // The worker is a static asset reference, not a module import — it costs a URL
4
+ // string here and is fetched only once pdf.js actually starts. Resolving it in
5
+ // this file (rather than shipping a baked path in the library bundle) is why
6
+ // PdfViewer is exported as source: every consuming app's bundler emits its own.
7
+ import PdfWorkerUrl from 'pdfjs-dist/legacy/build/pdf.worker.min.mjs?url'
8
+ import { onBeforeUnmount, ref, shallowRef, watch } from 'vue'
9
+
10
+ import { maxRenderScale, renderDpr } from './canvasBudget'
11
+
12
+ // The legacy build's declarations are `export * from "pdfjs-dist"`, so this is
13
+ // the full API surface, not a narrowed one.
14
+ type PdfJsModule = typeof import('pdfjs-dist/legacy/build/pdf.mjs')
15
+
16
+ // The legacy build, deliberately: it carries the transpilation and polyfills
17
+ // that keep pdf.js working on older WebKit. The modern build needs Safari 16.4+,
18
+ // and a shop-floor iPad is exactly the device least likely to be current.
19
+ let pdfjsPromise: Promise<PdfJsModule> | null = null
20
+
21
+ async function loadPdfJs(): Promise<PdfJsModule> {
22
+ if (!pdfjsPromise) {
23
+ pdfjsPromise = import('pdfjs-dist/legacy/build/pdf.mjs').then((mod) => {
24
+ mod.GlobalWorkerOptions.workerSrc = PdfWorkerUrl
25
+ return mod
26
+ })
27
+ }
28
+ return pdfjsPromise
29
+ }
30
+
31
+ export type PdfLoadError = 'load_failed' | 'password_protected' | 'render_failed'
32
+
33
+ export function usePdfDocument(source: Ref<string | null | undefined>) {
34
+ const doc = shallowRef<PDFDocumentProxy | null>(null)
35
+ const page = shallowRef<PDFPageProxy | null>(null)
36
+ const pageCount = ref(0)
37
+ const pageNumber = ref(1)
38
+ const rotation = ref(0)
39
+ /** Intrinsic page size in CSS pixels at scale 1, with rotation applied. */
40
+ const pageWidth = ref(0)
41
+ const pageHeight = ref(0)
42
+ const isLoading = ref(false)
43
+ const error = ref<PdfLoadError | null>(null)
44
+
45
+ let renderTask: RenderTask | null = null
46
+ /**
47
+ * Teardown happens through the loading task, not the document.
48
+ *
49
+ * pdf.js 6 removed `PDFDocumentProxy.destroy()`, which was only ever
50
+ * `return this.loadingTask.destroy()` — so this is the same call one level up,
51
+ * not a change of behaviour. Optional chaining does not save the old form:
52
+ * `doc.value?.destroy()` guards the document being null, not the method being
53
+ * gone, so on v6 it threw a TypeError out of an un-awaited path and left the
54
+ * viewer on a spinner from the second document onwards.
55
+ */
56
+ let loadingTask: PDFDocumentLoadingTask | null = null
57
+ /** Guards against a slow load resolving after the source has moved on. */
58
+ let loadToken = 0
59
+
60
+ function cancelRender() {
61
+ renderTask?.cancel()
62
+ renderTask = null
63
+ }
64
+
65
+ async function destroyDoc() {
66
+ cancelRender()
67
+ const task = loadingTask
68
+ loadingTask = null
69
+ doc.value = null
70
+ page.value = null
71
+ await task?.destroy().catch(() => { /* teardown is best-effort */ })
72
+ }
73
+
74
+ /**
75
+ * The source went empty, so nothing should end up on screen.
76
+ *
77
+ * Bumping `loadToken` is the whole point and is not optional: it is the only
78
+ * thing that stops a load still inside `await loadPdfJs()` from carrying on
79
+ * to fetch a URL that is no longer selected. Tearing down alone did not do
80
+ * it — at that moment `loadingTask` has not been assigned yet, so there is
81
+ * nothing to destroy, and the pending load went on to commit a document over
82
+ * an empty source. `onBeforeUnmount` has always bumped the token for exactly
83
+ * this reason; this path simply did not.
84
+ *
85
+ * The increment cannot live in destroyDoc(): `load()` calls that immediately
86
+ * after taking its own token, so incrementing there would invalidate every
87
+ * load the moment it started.
88
+ */
89
+ async function clear() {
90
+ loadToken++
91
+ isLoading.value = false
92
+ // An empty viewer must not keep the previous document's failure on screen.
93
+ error.value = null
94
+ await destroyDoc()
95
+ }
96
+
97
+ async function load(url: string) {
98
+ const token = ++loadToken
99
+ isLoading.value = true
100
+ error.value = null
101
+ await destroyDoc()
102
+
103
+ try {
104
+ const pdfjs = await loadPdfJs()
105
+ // Checked before getDocument, not after: the first load pays a dynamic
106
+ // import for a ~500 kB chunk, which is a wide enough window for the
107
+ // source to change underneath. Re-checking here means a superseded load
108
+ // never opens a request, rather than opening one and discarding it.
109
+ if (token !== loadToken)
110
+ return
111
+ // Range and streaming are switched off on purpose. The DMS stream endpoint
112
+ // is a Laravel StreamedResponse, which does not serve HTTP 206 — leaving
113
+ // partial loading on means pdf.js probes for it on every document and then
114
+ // has to unwind. One plain GET is both faster here and predictable.
115
+ const task = pdfjs.getDocument({ url, disableRange: true, disableStream: true })
116
+ loadingTask = task
117
+ const loaded = await task.promise
118
+ if (token !== loadToken) {
119
+ await task.destroy().catch(() => {})
120
+ if (loadingTask === task)
121
+ loadingTask = null
122
+ return
123
+ }
124
+ doc.value = loaded
125
+ pageCount.value = loaded.numPages
126
+ pageNumber.value = 1
127
+ rotation.value = 0
128
+ await selectPage(1)
129
+ }
130
+ catch (err) {
131
+ if (token !== loadToken)
132
+ return
133
+ error.value = (err as { name?: string })?.name === 'PasswordException'
134
+ ? 'password_protected'
135
+ : 'load_failed'
136
+ }
137
+ finally {
138
+ if (token === loadToken)
139
+ isLoading.value = false
140
+ }
141
+ }
142
+
143
+ async function selectPage(next: number) {
144
+ const current = doc.value
145
+ if (!current)
146
+ return
147
+ const clamped = Math.min(Math.max(next, 1), current.numPages)
148
+ pageNumber.value = clamped
149
+ cancelRender()
150
+ const loaded = await current.getPage(clamped)
151
+ page.value = loaded
152
+ measurePage()
153
+ }
154
+
155
+ function measurePage() {
156
+ const loaded = page.value
157
+ if (!loaded)
158
+ return
159
+ const viewport = loaded.getViewport({ scale: 1, rotation: rotation.value })
160
+ pageWidth.value = viewport.width
161
+ pageHeight.value = viewport.height
162
+ }
163
+
164
+ function rotate() {
165
+ rotation.value = (rotation.value + 90) % 360
166
+ measurePage()
167
+ }
168
+
169
+ /**
170
+ * Rasterise the current page to `canvas` at `scale` CSS pixels per page unit.
171
+ * The backing store is scaled by device pixel ratio for sharpness and then
172
+ * clamped to the engine's canvas budget, so zooming past the budget stretches
173
+ * the last sharp raster instead of producing a blank canvas.
174
+ */
175
+ async function renderTo(canvas: HTMLCanvasElement, scale: number): Promise<void> {
176
+ const loaded = page.value
177
+ if (!loaded || scale <= 0)
178
+ return
179
+ cancelRender()
180
+
181
+ const cap = maxRenderScale(pageWidth.value, pageHeight.value)
182
+ const viewport = loaded.getViewport({
183
+ scale: Math.min(scale * renderDpr(), cap),
184
+ rotation: rotation.value,
185
+ })
186
+
187
+ // Only the backing store is touched here. The canvas's CSS box is bound to
188
+ // the committed scale by the caller, so the box resizes in the same tick the
189
+ // transform does — the old raster stretches for a frame and is then repainted
190
+ // sharp, instead of the box and the transform disagreeing for a frame.
191
+ canvas.width = Math.max(1, Math.floor(viewport.width))
192
+ canvas.height = Math.max(1, Math.floor(viewport.height))
193
+
194
+ const task = loaded.render({ canvas, viewport })
195
+ renderTask = task
196
+ try {
197
+ await task.promise
198
+ error.value = null
199
+ }
200
+ catch (err) {
201
+ // Cancellation is the normal path whenever a newer render supersedes this
202
+ // one; only a genuine failure is worth surfacing.
203
+ if ((err as { name?: string })?.name !== 'RenderingCancelledException')
204
+ error.value = 'render_failed'
205
+ }
206
+ finally {
207
+ if (renderTask === task)
208
+ renderTask = null
209
+ }
210
+ }
211
+
212
+ watch(source, (url) => {
213
+ if (url)
214
+ void load(url)
215
+ else
216
+ void clear()
217
+ }, { immediate: true })
218
+
219
+ onBeforeUnmount(() => {
220
+ loadToken++
221
+ void destroyDoc()
222
+ })
223
+
224
+ return {
225
+ doc,
226
+ page,
227
+ pageCount,
228
+ pageNumber,
229
+ rotation,
230
+ pageWidth,
231
+ pageHeight,
232
+ isLoading,
233
+ error,
234
+ selectPage,
235
+ rotate,
236
+ renderTo,
237
+ cancelRender,
238
+ }
239
+ }
@@ -0,0 +1,38 @@
1
+ /** How far one arrow-key press nudges the page, in CSS pixels. */
2
+ const PAN_STEP = 40
3
+
4
+ export interface PdfKeyboardActions {
5
+ zoomBy: (factor: number) => void
6
+ fitPage: () => void
7
+ panBy: (dx: number, dy: number) => void
8
+ goToPage: (delta: number) => void
9
+ }
10
+
11
+ /**
12
+ * Keyboard equivalents for every pointer gesture. The stage is focusable, so a
13
+ * desktop user (and anyone driving the page from a keyboard) can reach the same
14
+ * controls the touch gestures provide.
15
+ */
16
+ export function usePdfKeyboard(actions: PdfKeyboardActions) {
17
+ const handlers: Record<string, () => void> = {
18
+ '+': () => actions.zoomBy(1.25),
19
+ '=': () => actions.zoomBy(1.25),
20
+ '-': () => actions.zoomBy(0.8),
21
+ '_': () => actions.zoomBy(0.8),
22
+ '0': () => actions.fitPage(),
23
+ 'ArrowLeft': () => actions.panBy(PAN_STEP, 0),
24
+ 'ArrowRight': () => actions.panBy(-PAN_STEP, 0),
25
+ 'ArrowUp': () => actions.panBy(0, PAN_STEP),
26
+ 'ArrowDown': () => actions.panBy(0, -PAN_STEP),
27
+ 'PageUp': () => actions.goToPage(-1),
28
+ 'PageDown': () => actions.goToPage(1),
29
+ }
30
+
31
+ return function onKeydown(e: KeyboardEvent) {
32
+ const handler = handlers[e.key]
33
+ if (!handler)
34
+ return
35
+ handler()
36
+ e.preventDefault()
37
+ }
38
+ }
@@ -0,0 +1,85 @@
1
+ import type { ComputedRef, Ref, ShallowRef } from 'vue'
2
+ import { computed, onBeforeUnmount, ref, watch } from 'vue'
3
+
4
+ /** Below this the difference is invisible and not worth a re-render. */
5
+ const RESCALE_THRESHOLD = 0.02
6
+ /** Long enough to sit out a flick or a pinch, short enough to feel immediate. */
7
+ const SETTLE_MS = 180
8
+
9
+ export interface PdfRasterDeps {
10
+ canvas: Ref<HTMLCanvasElement | null>
11
+ /** Truthy once a page is available to draw. */
12
+ page: ShallowRef<unknown>
13
+ pageWidth: Ref<number>
14
+ pageHeight: Ref<number>
15
+ /** Scale the page should appear at right now. */
16
+ displayScale: ComputedRef<number>
17
+ /** True while a pointer gesture is in flight. */
18
+ isGesturing: Ref<boolean>
19
+ renderTo: (canvas: HTMLCanvasElement, scale: number) => Promise<void>
20
+ }
21
+
22
+ /**
23
+ * Bridges the gap between how big the page *should* look and how big it was last
24
+ * actually rasterised.
25
+ *
26
+ * Re-rendering on every frame of a pinch would drop frames on a tablet for
27
+ * sharpness nobody can perceive while the drawing is still moving, so the gap is
28
+ * carried by a CSS transform — which is free — and closed by a fresh render once
29
+ * the gesture settles.
30
+ */
31
+ export function usePdfRaster(deps: PdfRasterDeps) {
32
+ const { canvas, page, pageWidth, pageHeight, displayScale, isGesturing, renderTo } = deps
33
+
34
+ /** The scale the canvas was last rasterised at. */
35
+ const committedScale = ref(0)
36
+ const liveRatio = computed(() => (committedScale.value > 0 ? displayScale.value / committedScale.value : 1))
37
+
38
+ const canvasStyle = computed(() => ({
39
+ width: `${Math.round(pageWidth.value * committedScale.value)}px`,
40
+ height: `${Math.round(pageHeight.value * committedScale.value)}px`,
41
+ }))
42
+
43
+ let settleTimer: ReturnType<typeof setTimeout> | undefined
44
+
45
+ async function commit() {
46
+ const el = canvas.value
47
+ const scale = displayScale.value
48
+ if (!el || !page.value || scale <= 0)
49
+ return
50
+ // Set first, await second: the CSS box and the transform change together, so
51
+ // the browser stretches the existing raster for the frame or two it takes the
52
+ // sharp one to arrive rather than showing a box that disagrees with itself.
53
+ committedScale.value = scale
54
+ await renderTo(el, scale)
55
+ }
56
+
57
+ function schedule(immediate = false) {
58
+ clearTimeout(settleTimer)
59
+ if (immediate) {
60
+ void commit()
61
+ return
62
+ }
63
+ settleTimer = setTimeout(() => void commit(), SETTLE_MS)
64
+ }
65
+
66
+ /** Drop back to "nothing rasterised yet" — a new page or a new rotation. */
67
+ function invalidate() {
68
+ committedScale.value = 0
69
+ }
70
+
71
+ watch([displayScale, isGesturing], ([scale, gesturing]) => {
72
+ if (gesturing || scale <= 0)
73
+ return
74
+ if (committedScale.value <= 0) {
75
+ schedule(true)
76
+ return
77
+ }
78
+ if (Math.abs(scale / committedScale.value - 1) > RESCALE_THRESHOLD)
79
+ schedule()
80
+ })
81
+
82
+ onBeforeUnmount(() => clearTimeout(settleTimer))
83
+
84
+ return { committedScale, liveRatio, canvasStyle, schedule, invalidate }
85
+ }
@@ -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/lib/build/uno.ts CHANGED
@@ -1,11 +1,13 @@
1
1
  import type { UserConfig } from 'unocss'
2
2
  import presetRemToPx from '@unocss/preset-rem-to-px'
3
+ import presetTypography from '@unocss/preset-typography'
3
4
  import presetWind4 from '@unocss/preset-wind4'
4
5
  import { defineConfig, transformerDirectives, transformerVariantGroup } from 'unocss'
5
6
 
6
7
  const antColors = {
7
8
  primary: '#125CFF',
8
9
  secondary: '#64748B',
10
+ error: '#B00020',
9
11
  info: '#2196F3',
10
12
  success: '#4CAF50',
11
13
  warning: '#FB8C00',
@@ -35,9 +37,14 @@ const antDesignTokens: NonNullable<UserConfig['rules']> = [
35
37
  ['text-body', { color: 'rgba(var(--v-theme-on-surface), 0.7)' }],
36
38
  ['text-muted', { color: 'rgba(var(--v-theme-on-surface), 0.5)' }],
37
39
  ['text-disabled', { color: 'rgba(var(--v-theme-on-surface), 0.38)' }],
40
+ ['text-warning-emphasis', { color: 'var(--ant-warning-text-emphasis)' }],
38
41
  ['border-ant', { 'border-color': 'rgba(var(--v-border-color), var(--v-border-opacity))' }],
39
42
  ]
40
43
 
44
+ const antPreflights: NonNullable<UserConfig['preflights']> = [
45
+ { getCSS: () => ':root { --ant-warning-text-emphasis: #9b5b00; }' },
46
+ ]
47
+
41
48
  /**
42
49
  * Normalizes shortcuts from either array or object form to array form.
43
50
  *
@@ -90,7 +97,7 @@ export function createAntUnoConfig(overrides: Partial<UserConfig> = {}): UserCon
90
97
  outputToCssLayers: {
91
98
  cssLayerName: (layer: string) => layer === 'properties' ? null : `uno-${layer}`,
92
99
  },
93
- preflights: preflights ?? [],
100
+ preflights: [...antPreflights, ...(preflights ?? [])],
94
101
  rules: [
95
102
  ...antDesignTokens,
96
103
  ...overrideRules,
@@ -104,6 +111,8 @@ export function createAntUnoConfig(overrides: Partial<UserConfig> = {}): UserCon
104
111
  presets: presets ?? [
105
112
  presetRemToPx,
106
113
  presetWind4({ dark: { dark: '.v-theme--dark' } }),
114
+ // Provides `prose` for markdown rendered via v-html (READMEs, release notes).
115
+ presetTypography(),
107
116
  ],
108
117
  shortcuts: [
109
118
  ...normalizeShortcuts(shortcuts),
@@ -32,6 +32,8 @@ const BASE_PROJECT: Project = {
32
32
  is_favorite: false,
33
33
  is_master: 0,
34
34
  is_archive: false,
35
+ archived_at: null,
36
+ archived_by: null,
35
37
  created_at: '2025-01-01T00:00:00.000000Z',
36
38
  user_is_admin: true,
37
39
  labels: [],
package/lib/test/setup.ts CHANGED
@@ -133,6 +133,14 @@ vi.mock('@antcde/vue-utils', async (importOriginal) => {
133
133
  return { state, isLoading, error, execute, isReady: ref(true), executeDelayed: vi.fn() }
134
134
  },
135
135
 
136
+ // Explicitly stubbed (like `useApi`) so a component that calls it at setup —
137
+ // e.g. the triggers TestDialog — mounts under the harness regardless of the
138
+ // resolved @antcde/vue-utils build. The stub just runs the dispatch callback
139
+ // once (no host round-trip); tests that assert the OAuth popup drive it directly.
140
+ useTriggerDispatch: () => ({
141
+ dispatch: vi.fn(async (run: () => Promise<unknown>) => run()),
142
+ }),
143
+
136
144
  useCommsClient: () => {
137
145
  const mocks = globalThis.__antTestMockComms
138
146
  if (!mocks)