@antcde/component-library 0.1.25-rc.1 → 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.
- package/dist/index.js +11063 -10296
- package/dist/types/src/components/BaseAntInput.types.d.ts +111 -0
- package/dist/types/src/components/BaseAntInput.vue.d.ts +2 -80
- package/dist/types/src/components/BaseAppCardSkeleton.vue.d.ts +6 -0
- package/dist/types/src/components/BaseResizePanel.vue.d.ts +19 -18
- 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/components/_BaseAntInputField.vue.d.ts +36 -0
- package/dist/types/src/components/_BaseAntInputLabel.vue.d.ts +6 -0
- package/dist/types/src/components/useResizePanel.d.ts +38 -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 +239 -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 +29 -22
|
@@ -30,7 +30,7 @@ export type { AppLike } from './components/BaseAppCard/index.vue';
|
|
|
30
30
|
export type { MentionItem } from './components/RichTextEditor/index.vue';
|
|
31
31
|
export type { StackedLabel } from './components/StackedLabels/index.vue';
|
|
32
32
|
export type { FlowChannelSubscriber } from './components/TasksFlow/composables/useTaskFlow';
|
|
33
|
-
export type { WindowSizePreset } from './components/UnifiedWindow/
|
|
33
|
+
export type { WindowSizePreset, WindowTab } from './components/UnifiedWindow/types';
|
|
34
34
|
export * from '@antcde/vue-utils';
|
|
35
35
|
export { AntTourZone, BaseAntButton, BaseAntCard, BaseAntCreateCard, BaseAntDatePicker, BaseAntInput, BaseAntLoading, BaseAppCard, BaseAppCardSkeleton, BaseClickableIcon, BaseConfirmDialog, BaseDeleteDialog, BaseDialog, BaseLimitedButton, BaseResizePanel, BulkLabelsMenu, DmsFilePicker, FilePreviewContent, FlowWindowContent, GlobalLabelBadge, LabelsMenuCard, PermissionCard, RichTextEditor, StackedLabels, TaskFlow, UnifiedWindow, VersionPublishDialog, };
|
|
36
36
|
declare const _default: {
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import type { PdfViewerLabels } from './labels'
|
|
3
|
+
import { computed, ref, watch } from 'vue'
|
|
4
|
+
import PdfToolbar from './_PdfToolbar.vue'
|
|
5
|
+
import { defaultPdfViewerLabels, pdfErrorMessage } from './labels'
|
|
6
|
+
import { usePdfDocument } from './usePdfDocument'
|
|
7
|
+
import { usePdfKeyboard } from './usePdfKeyboard'
|
|
8
|
+
import { usePdfRaster } from './usePdfRaster'
|
|
9
|
+
import { MAX_ZOOM, MIN_ZOOM, usePdfTransform } from './usePdfTransform'
|
|
10
|
+
|
|
11
|
+
const props = withDefaults(defineProps<{
|
|
12
|
+
/** Signed, already-resolved URL of the PDF. */
|
|
13
|
+
source: string | null | undefined
|
|
14
|
+
/** Host-supplied translations; anything omitted falls back to English. */
|
|
15
|
+
labels?: Partial<PdfViewerLabels>
|
|
16
|
+
/** Tighter chrome for a small pane, e.g. the bench drawing strip. */
|
|
17
|
+
compact?: boolean
|
|
18
|
+
/** Accessible name for the rendered page — usually the file name. */
|
|
19
|
+
title?: string
|
|
20
|
+
}>(), {
|
|
21
|
+
compact: false,
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
const t = computed<PdfViewerLabels>(() => ({ ...defaultPdfViewerLabels, ...props.labels }))
|
|
25
|
+
|
|
26
|
+
const source = computed(() => props.source)
|
|
27
|
+
const container = ref<HTMLElement | null>(null)
|
|
28
|
+
const canvasEl = ref<HTMLCanvasElement | null>(null)
|
|
29
|
+
|
|
30
|
+
const {
|
|
31
|
+
pageCount,
|
|
32
|
+
pageNumber,
|
|
33
|
+
pageWidth,
|
|
34
|
+
pageHeight,
|
|
35
|
+
page,
|
|
36
|
+
isLoading,
|
|
37
|
+
error,
|
|
38
|
+
selectPage,
|
|
39
|
+
rotate,
|
|
40
|
+
renderTo,
|
|
41
|
+
} = usePdfDocument(source)
|
|
42
|
+
|
|
43
|
+
const {
|
|
44
|
+
zoom,
|
|
45
|
+
tx,
|
|
46
|
+
ty,
|
|
47
|
+
isGesturing,
|
|
48
|
+
displayScale,
|
|
49
|
+
zoomByStep,
|
|
50
|
+
fitPage,
|
|
51
|
+
fitWidth,
|
|
52
|
+
clampPan,
|
|
53
|
+
handlers,
|
|
54
|
+
} = usePdfTransform({ container, pageWidth, pageHeight })
|
|
55
|
+
|
|
56
|
+
const { liveRatio, canvasStyle, schedule, invalidate } = usePdfRaster({
|
|
57
|
+
canvas: canvasEl,
|
|
58
|
+
page,
|
|
59
|
+
pageWidth,
|
|
60
|
+
pageHeight,
|
|
61
|
+
displayScale,
|
|
62
|
+
isGesturing,
|
|
63
|
+
renderTo,
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
const stageStyle = computed(() => ({
|
|
67
|
+
transform: `translate(${tx.value}px, ${ty.value}px) scale(${liveRatio.value})`,
|
|
68
|
+
transformOrigin: '0 0',
|
|
69
|
+
}))
|
|
70
|
+
|
|
71
|
+
const zoomPercent = computed(() => `${Math.round(zoom.value * 100)}%`)
|
|
72
|
+
const canZoomIn = computed(() => zoom.value < MAX_ZOOM - 0.001)
|
|
73
|
+
const canZoomOut = computed(() => zoom.value > MIN_ZOOM + 0.001)
|
|
74
|
+
const hasPages = computed(() => pageCount.value > 1)
|
|
75
|
+
const pageLabel = computed(() =>
|
|
76
|
+
t.value.pageOf.replace('{page}', String(pageNumber.value)).replace('{total}', String(pageCount.value)),
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
const errorMessage = computed(() => pdfErrorMessage(error.value, t.value))
|
|
80
|
+
|
|
81
|
+
// A new page (or a new document) starts fresh: whole page, centred.
|
|
82
|
+
watch(page, (loaded) => {
|
|
83
|
+
if (!loaded)
|
|
84
|
+
return
|
|
85
|
+
invalidate()
|
|
86
|
+
fitPage()
|
|
87
|
+
schedule(true)
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
function onRotate() {
|
|
91
|
+
rotate()
|
|
92
|
+
invalidate()
|
|
93
|
+
fitPage()
|
|
94
|
+
schedule(true)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function goToPage(delta: number) {
|
|
98
|
+
void selectPage(pageNumber.value + delta)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const onKeydown = usePdfKeyboard({
|
|
102
|
+
zoomBy: zoomByStep,
|
|
103
|
+
fitPage,
|
|
104
|
+
panBy: (dx, dy) => {
|
|
105
|
+
tx.value += dx
|
|
106
|
+
ty.value += dy
|
|
107
|
+
clampPan()
|
|
108
|
+
},
|
|
109
|
+
goToPage,
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
defineExpose({ fitPage, fitWidth, zoomByStep, rotate: onRotate })
|
|
113
|
+
</script>
|
|
114
|
+
|
|
115
|
+
<template>
|
|
116
|
+
<!-- The chrome is dark in both app themes, as every PDF reader's is: the page
|
|
117
|
+
itself is white, and a light surround costs the contrast that makes the
|
|
118
|
+
drawing's edge readable. -->
|
|
119
|
+
<div class="pdfv" :class="{ 'pdfv--compact': compact }">
|
|
120
|
+
<PdfToolbar
|
|
121
|
+
:labels="t"
|
|
122
|
+
:compact="compact"
|
|
123
|
+
:zoom-percent="zoomPercent"
|
|
124
|
+
:can-zoom-in="canZoomIn"
|
|
125
|
+
:can-zoom-out="canZoomOut"
|
|
126
|
+
:has-pages="hasPages"
|
|
127
|
+
:page-number="pageNumber"
|
|
128
|
+
:page-count="pageCount"
|
|
129
|
+
@zoom="zoomByStep"
|
|
130
|
+
@fit-page="fitPage()"
|
|
131
|
+
@fit-width="fitWidth()"
|
|
132
|
+
@rotate="onRotate"
|
|
133
|
+
@page="goToPage"
|
|
134
|
+
>
|
|
135
|
+
<template #actions>
|
|
136
|
+
<slot name="actions" />
|
|
137
|
+
</template>
|
|
138
|
+
</PdfToolbar>
|
|
139
|
+
|
|
140
|
+
<div
|
|
141
|
+
ref="container"
|
|
142
|
+
class="pdfv__stage"
|
|
143
|
+
tabindex="0"
|
|
144
|
+
role="group"
|
|
145
|
+
:aria-label="title ?? t.document"
|
|
146
|
+
@pointerdown="handlers.onPointerDown"
|
|
147
|
+
@pointermove="handlers.onPointerMove"
|
|
148
|
+
@pointerup="handlers.onPointerUp"
|
|
149
|
+
@pointercancel="handlers.onPointerUp"
|
|
150
|
+
@dblclick="handlers.onDoubleClick"
|
|
151
|
+
@keydown="onKeydown"
|
|
152
|
+
>
|
|
153
|
+
<div class="pdfv__pan" :style="stageStyle">
|
|
154
|
+
<canvas
|
|
155
|
+
ref="canvasEl"
|
|
156
|
+
class="pdfv__canvas"
|
|
157
|
+
:style="canvasStyle"
|
|
158
|
+
:aria-label="hasPages ? `${title ?? t.document} — ${pageLabel}` : (title ?? t.document)"
|
|
159
|
+
role="img"
|
|
160
|
+
/>
|
|
161
|
+
</div>
|
|
162
|
+
|
|
163
|
+
<div v-if="isLoading" class="pdfv__overlay">
|
|
164
|
+
<v-progress-circular indeterminate color="primary" size="36" width="3" />
|
|
165
|
+
<span class="pdfv__overlay-text">{{ t.loading }}</span>
|
|
166
|
+
</div>
|
|
167
|
+
|
|
168
|
+
<div v-else-if="errorMessage" class="pdfv__overlay">
|
|
169
|
+
<v-icon icon="mdi-file-alert-outline" size="40" class="pdfv__overlay-icon" />
|
|
170
|
+
<span class="pdfv__overlay-text">{{ errorMessage }}</span>
|
|
171
|
+
<!-- The last resort is still the browser's own handler: if pdf.js cannot
|
|
172
|
+
read the file, a plain tab at least gives the operator the download. -->
|
|
173
|
+
<a v-if="source" class="pdfv__fallback" :href="source" target="_blank" rel="noopener">
|
|
174
|
+
{{ t.openInNewTab }}
|
|
175
|
+
</a>
|
|
176
|
+
</div>
|
|
177
|
+
</div>
|
|
178
|
+
</div>
|
|
179
|
+
</template>
|
|
180
|
+
|
|
181
|
+
<style scoped>
|
|
182
|
+
.pdfv {
|
|
183
|
+
position: relative;
|
|
184
|
+
display: flex;
|
|
185
|
+
flex-direction: column;
|
|
186
|
+
width: 100%;
|
|
187
|
+
height: 100%;
|
|
188
|
+
min-height: 0;
|
|
189
|
+
overflow: hidden;
|
|
190
|
+
background: #3d4043;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
.pdfv__stage {
|
|
194
|
+
position: relative;
|
|
195
|
+
flex: 1 1 auto;
|
|
196
|
+
min-height: 0;
|
|
197
|
+
overflow: hidden;
|
|
198
|
+
/* Hands the whole gesture budget to the viewer: without this WebKit claims
|
|
199
|
+
pinch for its own page zoom and double-tap for its smart-zoom, and neither
|
|
200
|
+
reaches the pointer handlers. */
|
|
201
|
+
touch-action: none;
|
|
202
|
+
user-select: none;
|
|
203
|
+
cursor: grab;
|
|
204
|
+
background: #3d4043;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
.pdfv__stage:active { cursor: grabbing; }
|
|
208
|
+
.pdfv__stage:focus-visible { outline: 2px solid rgba(255, 255, 255, 0.6); outline-offset: -2px; }
|
|
209
|
+
|
|
210
|
+
.pdfv__pan {
|
|
211
|
+
position: absolute;
|
|
212
|
+
top: 0;
|
|
213
|
+
left: 0;
|
|
214
|
+
will-change: transform;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
.pdfv__canvas {
|
|
218
|
+
display: block;
|
|
219
|
+
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
|
|
220
|
+
background: #fff;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
.pdfv__overlay {
|
|
224
|
+
position: absolute;
|
|
225
|
+
inset: 0;
|
|
226
|
+
display: flex;
|
|
227
|
+
flex-direction: column;
|
|
228
|
+
align-items: center;
|
|
229
|
+
justify-content: center;
|
|
230
|
+
gap: 10px;
|
|
231
|
+
padding: 24px;
|
|
232
|
+
text-align: center;
|
|
233
|
+
background: #3d4043;
|
|
234
|
+
color: rgba(255, 255, 255, 0.75);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
.pdfv__overlay-icon { color: rgba(255, 255, 255, 0.35); }
|
|
238
|
+
.pdfv__overlay-text { font-size: 13px; }
|
|
239
|
+
|
|
240
|
+
.pdfv__fallback {
|
|
241
|
+
font-size: 13px;
|
|
242
|
+
color: #7cb7ff;
|
|
243
|
+
text-decoration: underline;
|
|
244
|
+
}
|
|
245
|
+
</style>
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import type { PdfViewerLabels } from './labels'
|
|
3
|
+
|
|
4
|
+
defineProps<{
|
|
5
|
+
labels: PdfViewerLabels
|
|
6
|
+
/** Floats the controls over the drawing instead of giving them their own row. */
|
|
7
|
+
compact: boolean
|
|
8
|
+
zoomPercent: string
|
|
9
|
+
canZoomIn: boolean
|
|
10
|
+
canZoomOut: boolean
|
|
11
|
+
hasPages: boolean
|
|
12
|
+
pageNumber: number
|
|
13
|
+
pageCount: number
|
|
14
|
+
}>()
|
|
15
|
+
|
|
16
|
+
const emit = defineEmits<{
|
|
17
|
+
zoom: [factor: number]
|
|
18
|
+
fitPage: []
|
|
19
|
+
fitWidth: []
|
|
20
|
+
rotate: []
|
|
21
|
+
page: [delta: number]
|
|
22
|
+
}>()
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<template>
|
|
26
|
+
<!-- In a short pane the controls float over the drawing instead of taking a
|
|
27
|
+
row of their own: a bench pane is a couple of hundred pixels tall, and a
|
|
28
|
+
second band of chrome costs more than the zoom buttons are worth. -->
|
|
29
|
+
<div class="pdfv__toolbar" :class="{ 'pdfv__toolbar--floating': compact }">
|
|
30
|
+
<button
|
|
31
|
+
type="button"
|
|
32
|
+
class="pdfv__btn"
|
|
33
|
+
:disabled="!canZoomOut"
|
|
34
|
+
:aria-label="labels.zoomOut"
|
|
35
|
+
:title="labels.zoomOut"
|
|
36
|
+
@click="emit('zoom', 0.8)"
|
|
37
|
+
>
|
|
38
|
+
<v-icon icon="mdi-minus" :size="compact ? 16 : 18" />
|
|
39
|
+
</button>
|
|
40
|
+
|
|
41
|
+
<span class="pdfv__zoom" aria-live="polite">{{ zoomPercent }}</span>
|
|
42
|
+
|
|
43
|
+
<button
|
|
44
|
+
type="button"
|
|
45
|
+
class="pdfv__btn"
|
|
46
|
+
:disabled="!canZoomIn"
|
|
47
|
+
:aria-label="labels.zoomIn"
|
|
48
|
+
:title="labels.zoomIn"
|
|
49
|
+
@click="emit('zoom', 1.25)"
|
|
50
|
+
>
|
|
51
|
+
<v-icon icon="mdi-plus" :size="compact ? 16 : 18" />
|
|
52
|
+
</button>
|
|
53
|
+
|
|
54
|
+
<span v-if="!compact" class="pdfv__sep" />
|
|
55
|
+
|
|
56
|
+
<button
|
|
57
|
+
type="button"
|
|
58
|
+
class="pdfv__btn"
|
|
59
|
+
:aria-label="labels.fitPage"
|
|
60
|
+
:title="labels.fitPage"
|
|
61
|
+
@click="emit('fitPage')"
|
|
62
|
+
>
|
|
63
|
+
<v-icon icon="mdi-fit-to-page-outline" :size="compact ? 16 : 18" />
|
|
64
|
+
</button>
|
|
65
|
+
|
|
66
|
+
<button
|
|
67
|
+
v-if="!compact"
|
|
68
|
+
type="button"
|
|
69
|
+
class="pdfv__btn"
|
|
70
|
+
:aria-label="labels.fitWidth"
|
|
71
|
+
:title="labels.fitWidth"
|
|
72
|
+
@click="emit('fitWidth')"
|
|
73
|
+
>
|
|
74
|
+
<v-icon icon="mdi-arrow-expand-horizontal" :size="18" />
|
|
75
|
+
</button>
|
|
76
|
+
|
|
77
|
+
<button
|
|
78
|
+
v-if="!compact"
|
|
79
|
+
type="button"
|
|
80
|
+
class="pdfv__btn"
|
|
81
|
+
:aria-label="labels.rotate"
|
|
82
|
+
:title="labels.rotate"
|
|
83
|
+
@click="emit('rotate')"
|
|
84
|
+
>
|
|
85
|
+
<v-icon icon="mdi-rotate-right" :size="18" />
|
|
86
|
+
</button>
|
|
87
|
+
|
|
88
|
+
<template v-if="hasPages">
|
|
89
|
+
<span v-if="!compact" class="pdfv__sep" />
|
|
90
|
+
<button
|
|
91
|
+
type="button"
|
|
92
|
+
class="pdfv__btn"
|
|
93
|
+
:disabled="pageNumber <= 1"
|
|
94
|
+
:aria-label="labels.previousPage"
|
|
95
|
+
:title="labels.previousPage"
|
|
96
|
+
@click="emit('page', -1)"
|
|
97
|
+
>
|
|
98
|
+
<v-icon icon="mdi-chevron-left" :size="compact ? 16 : 18" />
|
|
99
|
+
</button>
|
|
100
|
+
<span class="pdfv__pages">{{ pageNumber }} / {{ pageCount }}</span>
|
|
101
|
+
<button
|
|
102
|
+
type="button"
|
|
103
|
+
class="pdfv__btn"
|
|
104
|
+
:disabled="pageNumber >= pageCount"
|
|
105
|
+
:aria-label="labels.nextPage"
|
|
106
|
+
:title="labels.nextPage"
|
|
107
|
+
@click="emit('page', 1)"
|
|
108
|
+
>
|
|
109
|
+
<v-icon icon="mdi-chevron-right" :size="compact ? 16 : 18" />
|
|
110
|
+
</button>
|
|
111
|
+
</template>
|
|
112
|
+
|
|
113
|
+
<span v-if="!compact" class="pdfv__spacer" />
|
|
114
|
+
<slot name="actions" />
|
|
115
|
+
</div>
|
|
116
|
+
</template>
|
|
117
|
+
|
|
118
|
+
<style scoped>
|
|
119
|
+
.pdfv__toolbar {
|
|
120
|
+
display: flex;
|
|
121
|
+
align-items: center;
|
|
122
|
+
gap: 2px;
|
|
123
|
+
flex-shrink: 0;
|
|
124
|
+
padding: 4px 8px;
|
|
125
|
+
background: #2b2e30;
|
|
126
|
+
border-bottom: 1px solid rgba(255, 255, 255, 0.08);
|
|
127
|
+
color: rgba(255, 255, 255, 0.92);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.pdfv__toolbar--floating {
|
|
131
|
+
position: absolute;
|
|
132
|
+
right: 10px;
|
|
133
|
+
bottom: 10px;
|
|
134
|
+
z-index: 2;
|
|
135
|
+
gap: 0;
|
|
136
|
+
padding: 3px;
|
|
137
|
+
border: 1px solid rgba(255, 255, 255, 0.14);
|
|
138
|
+
border-radius: 12px;
|
|
139
|
+
background: rgba(30, 33, 35, 0.9);
|
|
140
|
+
backdrop-filter: blur(6px);
|
|
141
|
+
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
.pdfv__btn {
|
|
145
|
+
display: inline-flex;
|
|
146
|
+
align-items: center;
|
|
147
|
+
justify-content: center;
|
|
148
|
+
width: 40px;
|
|
149
|
+
height: 40px;
|
|
150
|
+
flex-shrink: 0;
|
|
151
|
+
border: none;
|
|
152
|
+
border-radius: 8px;
|
|
153
|
+
background: transparent;
|
|
154
|
+
color: inherit;
|
|
155
|
+
cursor: pointer;
|
|
156
|
+
transition: background 0.12s ease, opacity 0.12s ease;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/* Deliberately still a 36px target in the floating pill: the operator is often
|
|
160
|
+
wearing gloves, and the 24px icon buttons this would otherwise shrink to are
|
|
161
|
+
unusable through one. */
|
|
162
|
+
.pdfv__toolbar--floating .pdfv__btn {
|
|
163
|
+
width: 36px;
|
|
164
|
+
height: 36px;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
.pdfv__btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.12); }
|
|
168
|
+
.pdfv__btn:focus-visible { outline: 2px solid rgba(255, 255, 255, 0.7); outline-offset: -2px; }
|
|
169
|
+
.pdfv__btn:disabled { opacity: 0.3; cursor: default; }
|
|
170
|
+
|
|
171
|
+
.pdfv__zoom {
|
|
172
|
+
min-width: 52px;
|
|
173
|
+
text-align: center;
|
|
174
|
+
font-size: 12px;
|
|
175
|
+
font-variant-numeric: tabular-nums;
|
|
176
|
+
user-select: none;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
.pdfv__toolbar--floating .pdfv__zoom { min-width: 44px; }
|
|
180
|
+
|
|
181
|
+
.pdfv__pages {
|
|
182
|
+
padding: 0 6px;
|
|
183
|
+
font-size: 12px;
|
|
184
|
+
font-variant-numeric: tabular-nums;
|
|
185
|
+
user-select: none;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
.pdfv__sep {
|
|
189
|
+
width: 1px;
|
|
190
|
+
height: 20px;
|
|
191
|
+
margin: 0 6px;
|
|
192
|
+
background: rgba(255, 255, 255, 0.15);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
.pdfv__spacer { flex: 1 1 auto; }
|
|
196
|
+
</style>
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canvas size limits, per rendering engine.
|
|
3
|
+
*
|
|
4
|
+
* An over-budget canvas does not throw — WebKit silently hands back a blank
|
|
5
|
+
* backing store. A drawing that vanishes the moment the operator zooms in is a
|
|
6
|
+
* far worse failure than one that stays slightly soft, so the budget is
|
|
7
|
+
* enforced before the render rather than discovered after it.
|
|
8
|
+
*
|
|
9
|
+
* WebKit's ceiling is the binding one: iOS/iPadOS cap a canvas at roughly
|
|
10
|
+
* 4096x4096 device pixels regardless of how much memory the device has, and
|
|
11
|
+
* every browser on iOS is WebKit underneath whatever brand is on the icon.
|
|
12
|
+
*/
|
|
13
|
+
const WEBKIT_MAX_SIDE = 4096
|
|
14
|
+
const WEBKIT_MAX_AREA = 4096 * 4096
|
|
15
|
+
const DEFAULT_MAX_SIDE = 8192
|
|
16
|
+
const DEFAULT_MAX_AREA = 8192 * 8192
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Chromium and Gecko both stamp their own token into the UA string. Anything
|
|
20
|
+
* left that still claims AppleWebKit is a genuine WebKit engine — desktop
|
|
21
|
+
* Safari, or any iOS browser, since they are all WebKit-backed.
|
|
22
|
+
*/
|
|
23
|
+
export function isWebKit(): boolean {
|
|
24
|
+
if (typeof navigator === 'undefined')
|
|
25
|
+
return false
|
|
26
|
+
const ua = navigator.userAgent
|
|
27
|
+
return /AppleWebKit/.test(ua) && !/Chrome|Chromium|Edg\/|OPR\/|SamsungBrowser/.test(ua)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The largest scale factor a page of this intrinsic size can be rasterised at
|
|
32
|
+
* without exceeding the engine's canvas budget. Beyond it the viewer keeps
|
|
33
|
+
* zooming, but by stretching the last sharp raster rather than re-rendering.
|
|
34
|
+
*/
|
|
35
|
+
export function maxRenderScale(pageWidth: number, pageHeight: number): number {
|
|
36
|
+
if (pageWidth <= 0 || pageHeight <= 0)
|
|
37
|
+
return 1
|
|
38
|
+
const webkit = isWebKit()
|
|
39
|
+
const maxSide = webkit ? WEBKIT_MAX_SIDE : DEFAULT_MAX_SIDE
|
|
40
|
+
const maxArea = webkit ? WEBKIT_MAX_AREA : DEFAULT_MAX_AREA
|
|
41
|
+
return Math.min(
|
|
42
|
+
maxSide / pageWidth,
|
|
43
|
+
maxSide / pageHeight,
|
|
44
|
+
Math.sqrt(maxArea / (pageWidth * pageHeight)),
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Device pixel ratio, capped. A 3x phone screen triples the canvas area for a
|
|
50
|
+
* sharpness gain nobody can see at arm's length on a shop floor, and it is the
|
|
51
|
+
* quickest way to hit the budget above.
|
|
52
|
+
*/
|
|
53
|
+
export function renderDpr(): number {
|
|
54
|
+
if (typeof window === 'undefined')
|
|
55
|
+
return 1
|
|
56
|
+
return Math.min(window.devicePixelRatio || 1, 2)
|
|
57
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The viewer is shared by the ant-os shell and by iframe apps, which run
|
|
3
|
+
* separate vue-i18n instances with separate message catalogues. Rather than
|
|
4
|
+
* pick one and make the other wrong, it takes its strings as a prop and each
|
|
5
|
+
* host passes its own translations. English is the fallback, not the design.
|
|
6
|
+
*/
|
|
7
|
+
export interface PdfViewerLabels {
|
|
8
|
+
zoomIn: string
|
|
9
|
+
zoomOut: string
|
|
10
|
+
fitPage: string
|
|
11
|
+
fitWidth: string
|
|
12
|
+
rotate: string
|
|
13
|
+
previousPage: string
|
|
14
|
+
nextPage: string
|
|
15
|
+
pageOf: string
|
|
16
|
+
loading: string
|
|
17
|
+
loadFailed: string
|
|
18
|
+
passwordProtected: string
|
|
19
|
+
renderFailed: string
|
|
20
|
+
openInNewTab: string
|
|
21
|
+
document: string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const defaultPdfViewerLabels: PdfViewerLabels = {
|
|
25
|
+
zoomIn: 'Zoom in',
|
|
26
|
+
zoomOut: 'Zoom out',
|
|
27
|
+
fitPage: 'Fit page',
|
|
28
|
+
fitWidth: 'Fit width',
|
|
29
|
+
rotate: 'Rotate',
|
|
30
|
+
previousPage: 'Previous page',
|
|
31
|
+
nextPage: 'Next page',
|
|
32
|
+
pageOf: 'Page {page} of {total}',
|
|
33
|
+
loading: 'Loading drawing…',
|
|
34
|
+
loadFailed: 'This document could not be opened',
|
|
35
|
+
passwordProtected: 'This document is password protected',
|
|
36
|
+
renderFailed: 'This page could not be displayed',
|
|
37
|
+
openInNewTab: 'Open in a new tab',
|
|
38
|
+
document: 'Document',
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Maps a load/render failure onto the host's wording for it. */
|
|
42
|
+
export function pdfErrorMessage(
|
|
43
|
+
error: 'load_failed' | 'password_protected' | 'render_failed' | null,
|
|
44
|
+
labels: PdfViewerLabels,
|
|
45
|
+
): string | null {
|
|
46
|
+
switch (error) {
|
|
47
|
+
case 'password_protected': return labels.passwordProtected
|
|
48
|
+
case 'render_failed': return labels.renderFailed
|
|
49
|
+
case 'load_failed': return labels.loadFailed
|
|
50
|
+
default: return null
|
|
51
|
+
}
|
|
52
|
+
}
|