@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,18 @@
|
|
|
1
|
+
import { AntConnect } from '@antcde/connect-ts';
|
|
2
|
+
import { PreviewTabData } from './types';
|
|
3
|
+
type __VLS_Props = {
|
|
4
|
+
tab: PreviewTabData;
|
|
5
|
+
antConnect: AntConnect;
|
|
6
|
+
isDark: boolean;
|
|
7
|
+
displayTitle: string;
|
|
8
|
+
/** Drives the lazy fetch; the parent owns the open/closed transition. */
|
|
9
|
+
open: boolean;
|
|
10
|
+
};
|
|
11
|
+
declare const _default: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
|
|
12
|
+
close: () => any;
|
|
13
|
+
navigate: (taskId: string) => any;
|
|
14
|
+
}, string, import('vue').PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
15
|
+
onClose?: (() => any) | undefined;
|
|
16
|
+
onNavigate?: ((taskId: string) => any) | undefined;
|
|
17
|
+
}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, HTMLDivElement>;
|
|
18
|
+
export default _default;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PreviewFileMeta } from './types';
|
|
2
|
+
type __VLS_Props = {
|
|
3
|
+
meta: Pick<PreviewFileMeta, 'fileSize' | 'fileExtension' | 'ownerName' | 'ownerAvatar' | 'createdAt' | 'updatedAt'>;
|
|
4
|
+
fileScope: 'project' | 'license';
|
|
5
|
+
breadcrumbs: {
|
|
6
|
+
name: string;
|
|
7
|
+
is_folder: boolean;
|
|
8
|
+
}[];
|
|
9
|
+
hasMeta: boolean;
|
|
10
|
+
isLoading: boolean;
|
|
11
|
+
};
|
|
12
|
+
declare const _default: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
13
|
+
export default _default;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DmsFileUsage } from '@antcde/connect-ts';
|
|
2
|
+
type __VLS_Props = {
|
|
3
|
+
taskUsages: DmsFileUsage[];
|
|
4
|
+
tableUsages: DmsFileUsage[];
|
|
5
|
+
hasUsages: boolean;
|
|
6
|
+
isLoading: boolean;
|
|
7
|
+
};
|
|
8
|
+
declare const _default: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
|
|
9
|
+
navigate: (taskId: string) => any;
|
|
10
|
+
}, string, import('vue').PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
11
|
+
onNavigate?: ((taskId: string) => any) | undefined;
|
|
12
|
+
}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
13
|
+
export default _default;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare function getMime(ext: string): string;
|
|
2
|
+
export declare function getExtension(name: string): string;
|
|
3
|
+
export declare function iconForExtension(ext: string | undefined): string;
|
|
4
|
+
export declare function colorForExtension(ext: string | undefined): string | undefined;
|
|
5
|
+
export declare function formatFileSize(bytes: number | null | undefined): string;
|
|
6
|
+
export declare function formatDate(dateStr: string | undefined): string;
|
|
7
|
+
export declare function getOwnerInitials(name: string): string;
|
|
@@ -1,17 +1,5 @@
|
|
|
1
1
|
import { AntConnect } from '@antcde/connect-ts';
|
|
2
|
-
|
|
3
|
-
fileToken: string;
|
|
4
|
-
fileName?: string;
|
|
5
|
-
projectId?: string;
|
|
6
|
-
licenseId?: string;
|
|
7
|
-
contentUrl?: string;
|
|
8
|
-
fileSize?: number;
|
|
9
|
-
fileExtension?: string;
|
|
10
|
-
ownerName?: string;
|
|
11
|
-
ownerAvatar?: string;
|
|
12
|
-
createdAt?: string;
|
|
13
|
-
updatedAt?: string;
|
|
14
|
-
}
|
|
2
|
+
import { PreviewTabData } from './types';
|
|
15
3
|
type __VLS_Props = {
|
|
16
4
|
tab: PreviewTabData;
|
|
17
5
|
antConnect: AntConnect;
|
|
@@ -19,7 +7,19 @@ type __VLS_Props = {
|
|
|
19
7
|
showDetails?: boolean;
|
|
20
8
|
};
|
|
21
9
|
declare function download(): Promise<void>;
|
|
22
|
-
declare
|
|
10
|
+
declare function __VLS_template(): {
|
|
11
|
+
attrs: Partial<{}>;
|
|
12
|
+
slots: {
|
|
13
|
+
pdf?(_: {
|
|
14
|
+
src: string;
|
|
15
|
+
title: string;
|
|
16
|
+
}): any;
|
|
17
|
+
};
|
|
18
|
+
refs: {};
|
|
19
|
+
rootEl: HTMLDivElement;
|
|
20
|
+
};
|
|
21
|
+
type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
|
|
22
|
+
declare const __VLS_component: import('vue').DefineComponent<__VLS_Props, {
|
|
23
23
|
download: typeof download;
|
|
24
24
|
}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
|
|
25
25
|
"update:showDetails": (value: boolean) => any;
|
|
@@ -28,4 +28,10 @@ declare const _default: import('vue').DefineComponent<__VLS_Props, {
|
|
|
28
28
|
"onUpdate:showDetails"?: ((value: boolean) => any) | undefined;
|
|
29
29
|
"onNavigate:task"?: ((taskId: string) => any) | undefined;
|
|
30
30
|
}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, HTMLDivElement>;
|
|
31
|
+
declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
|
|
31
32
|
export default _default;
|
|
33
|
+
type __VLS_WithTemplateSlots<T, S> = T & {
|
|
34
|
+
new (): {
|
|
35
|
+
$slots: S;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface PreviewTabData {
|
|
2
|
+
fileToken: string;
|
|
3
|
+
fileName?: string;
|
|
4
|
+
projectId?: string;
|
|
5
|
+
licenseId?: string;
|
|
6
|
+
contentUrl?: string;
|
|
7
|
+
fileSize?: number;
|
|
8
|
+
fileExtension?: string;
|
|
9
|
+
ownerName?: string;
|
|
10
|
+
ownerAvatar?: string;
|
|
11
|
+
createdAt?: string;
|
|
12
|
+
updatedAt?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface PreviewFileMeta {
|
|
15
|
+
fileSize?: number;
|
|
16
|
+
fileExtension?: string;
|
|
17
|
+
ownerName?: string;
|
|
18
|
+
ownerAvatar?: string;
|
|
19
|
+
createdAt?: string;
|
|
20
|
+
updatedAt?: string;
|
|
21
|
+
breadcrumbs?: {
|
|
22
|
+
name: string;
|
|
23
|
+
is_folder: boolean;
|
|
24
|
+
}[];
|
|
25
|
+
projectId?: string | null;
|
|
26
|
+
licenseId?: string;
|
|
27
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { AntConnect } from '@antcde/connect-ts';
|
|
2
|
+
import { PreviewTabData } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Metadata and usage lists for the details sidebar. Both are fetched lazily —
|
|
5
|
+
* the sidebar is closed by default and neither is needed to show the file.
|
|
6
|
+
*/
|
|
7
|
+
export declare function usePreviewDetails(tab: () => PreviewTabData, antConnect: () => AntConnect): {
|
|
8
|
+
meta: import('vue').ComputedRef<{
|
|
9
|
+
fileSize: number | undefined;
|
|
10
|
+
fileExtension: string;
|
|
11
|
+
ownerName: string | undefined;
|
|
12
|
+
ownerAvatar: string | undefined;
|
|
13
|
+
createdAt: string | undefined;
|
|
14
|
+
updatedAt: string | undefined;
|
|
15
|
+
}>;
|
|
16
|
+
fileScope: import('vue').ComputedRef<"project" | "license">;
|
|
17
|
+
breadcrumbs: import('vue').ComputedRef<{
|
|
18
|
+
name: string;
|
|
19
|
+
is_folder: boolean;
|
|
20
|
+
}[]>;
|
|
21
|
+
metaIcon: import('vue').ComputedRef<string>;
|
|
22
|
+
metaIconColor: import('vue').ComputedRef<string | undefined>;
|
|
23
|
+
hasMeta: import('vue').ComputedRef<boolean>;
|
|
24
|
+
isLoadingMeta: import('vue').Ref<boolean, boolean>;
|
|
25
|
+
taskUsages: import('vue').ComputedRef<{
|
|
26
|
+
id: string;
|
|
27
|
+
type: "task" | "record_cell";
|
|
28
|
+
linkable_id: string;
|
|
29
|
+
mode: "owned" | "referenced";
|
|
30
|
+
created_at: string | null;
|
|
31
|
+
task_title?: string | null | undefined;
|
|
32
|
+
task_number?: number | null | undefined;
|
|
33
|
+
table_name?: string | null | undefined;
|
|
34
|
+
}[]>;
|
|
35
|
+
tableUsages: import('vue').ComputedRef<{
|
|
36
|
+
id: string;
|
|
37
|
+
type: "task" | "record_cell";
|
|
38
|
+
linkable_id: string;
|
|
39
|
+
mode: "owned" | "referenced";
|
|
40
|
+
created_at: string | null;
|
|
41
|
+
task_title?: string | null | undefined;
|
|
42
|
+
task_number?: number | null | undefined;
|
|
43
|
+
table_name?: string | null | undefined;
|
|
44
|
+
}[]>;
|
|
45
|
+
hasUsages: import('vue').ComputedRef<boolean>;
|
|
46
|
+
isLoadingUsages: import('vue').Ref<boolean, boolean>;
|
|
47
|
+
fetchMeta: () => Promise<void>;
|
|
48
|
+
fetchUsages: () => Promise<void>;
|
|
49
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { WindowSizePreset } from './types';
|
|
2
|
+
type __VLS_Props = {
|
|
3
|
+
currentPreset?: WindowSizePreset | null;
|
|
4
|
+
isDark: boolean;
|
|
5
|
+
};
|
|
6
|
+
declare const _default: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
|
|
7
|
+
pick: (preset: WindowSizePreset) => any;
|
|
8
|
+
}, string, import('vue').PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
9
|
+
onPick?: ((preset: WindowSizePreset) => any) | undefined;
|
|
10
|
+
}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
11
|
+
export default _default;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { WindowTab } from './types';
|
|
2
|
+
type __VLS_Props = {
|
|
3
|
+
tabs: WindowTab[];
|
|
4
|
+
activeTab: number;
|
|
5
|
+
isDark: boolean;
|
|
6
|
+
};
|
|
7
|
+
declare const _default: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
|
|
8
|
+
selectTab: (index: number) => any;
|
|
9
|
+
closeTab: (index: number) => any;
|
|
10
|
+
detachTab: (index: number) => any;
|
|
11
|
+
}, string, import('vue').PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
12
|
+
onSelectTab?: ((index: number) => any) | undefined;
|
|
13
|
+
onCloseTab?: ((index: number) => any) | undefined;
|
|
14
|
+
onDetachTab?: ((index: number) => any) | undefined;
|
|
15
|
+
}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
16
|
+
export default _default;
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export interface WindowTab {
|
|
3
|
-
id: string;
|
|
4
|
-
type: 'flow' | 'preview';
|
|
5
|
-
label: string;
|
|
6
|
-
icon: string;
|
|
7
|
-
}
|
|
1
|
+
import { WindowSizePreset, WindowTab } from './types';
|
|
8
2
|
type __VLS_Props = {
|
|
9
3
|
windowId: string;
|
|
10
4
|
tabs: WindowTab[];
|
|
@@ -39,8 +33,8 @@ declare const __VLS_component: import('vue').DefineComponent<__VLS_Props, {
|
|
|
39
33
|
setGeometry: (nx: number, ny: number, nw: number, nh: number) => void;
|
|
40
34
|
}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
|
|
41
35
|
close: () => any;
|
|
42
|
-
closeTab: (index: number) => any;
|
|
43
36
|
selectTab: (index: number) => any;
|
|
37
|
+
closeTab: (index: number) => any;
|
|
44
38
|
detachTab: (index: number) => any;
|
|
45
39
|
merge: (targetWindowId: string) => any;
|
|
46
40
|
minimize: () => any;
|
|
@@ -48,8 +42,8 @@ declare const __VLS_component: import('vue').DefineComponent<__VLS_Props, {
|
|
|
48
42
|
userGeometryChange: () => any;
|
|
49
43
|
}, string, import('vue').PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
50
44
|
onClose?: (() => any) | undefined;
|
|
51
|
-
onCloseTab?: ((index: number) => any) | undefined;
|
|
52
45
|
onSelectTab?: ((index: number) => any) | undefined;
|
|
46
|
+
onCloseTab?: ((index: number) => any) | undefined;
|
|
53
47
|
onDetachTab?: ((index: number) => any) | undefined;
|
|
54
48
|
onMerge?: ((targetWindowId: string) => any) | undefined;
|
|
55
49
|
onMinimize?: (() => any) | undefined;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lives outside index.vue so the private sub-components can import it without a
|
|
3
|
+
* circular reference back through their own parent.
|
|
4
|
+
*/
|
|
5
|
+
export type WindowSizePreset = 'fit' | 'wide' | 'compact' | 'max' | 'fullscreen';
|
|
6
|
+
export interface WindowTab {
|
|
7
|
+
id: string;
|
|
8
|
+
type: 'flow' | 'preview';
|
|
9
|
+
label: string;
|
|
10
|
+
icon: string;
|
|
11
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
/**
|
|
3
|
+
* Drives the native Fullscreen API for one window element.
|
|
4
|
+
*
|
|
5
|
+
* Best-effort by design: iPadOS Safari exposes only the webkit-prefixed call and
|
|
6
|
+
* iPhone Safari exposes neither, so where it is unavailable this quietly does
|
|
7
|
+
* nothing and the caller's zero-inset geometry remains the result. A silent
|
|
8
|
+
* no-op degrades to the next best thing; a thrown error would degrade to a
|
|
9
|
+
* broken button.
|
|
10
|
+
*
|
|
11
|
+
* @param element the window root.
|
|
12
|
+
* @param onExit fired when the browser leaves fullscreen on its own — Escape,
|
|
13
|
+
* a gesture, or another element claiming the slot.
|
|
14
|
+
*/
|
|
15
|
+
export declare function useNativeFullscreen(element: Ref<HTMLElement | null>, onExit: () => void): {
|
|
16
|
+
enter: () => void;
|
|
17
|
+
exit: () => void;
|
|
18
|
+
};
|
|
@@ -26,3 +26,11 @@ export declare function useWindowDrag(options: {
|
|
|
26
26
|
onResizeCancel: () => void;
|
|
27
27
|
};
|
|
28
28
|
};
|
|
29
|
+
/**
|
|
30
|
+
* The window whose box contains this one's centre after a drag, if any — the
|
|
31
|
+
* drop target for merging two windows into one tabbed window.
|
|
32
|
+
*
|
|
33
|
+
* Looked up through the DOM rather than through geometry state because each
|
|
34
|
+
* window owns its own position; there is no shared layout model to consult.
|
|
35
|
+
*/
|
|
36
|
+
export declare function findMergeTarget(self: HTMLElement | null, selfId: string, otherIds: string[]): string | null;
|
|
@@ -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>
|