@m3ui-vue/m3ui-vue 1.2.2 → 1.3.0
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/API.md +2776 -351
- package/dist/MButton-CuNzpoxm.js +172 -0
- package/dist/MButton-CuNzpoxm.js.map +1 -0
- package/dist/MDialog-HxEL-m58.js +173 -0
- package/dist/MDialog-HxEL-m58.js.map +1 -0
- package/dist/MIconButton-DoNotQ9v.js +282 -0
- package/dist/MIconButton-DoNotQ9v.js.map +1 -0
- package/dist/MListItem-DnPtv-hY.js +824 -0
- package/dist/MListItem-DnPtv-hY.js.map +1 -0
- package/dist/MLoadingIndicator-BQMNX6Dx.js +115 -0
- package/dist/MLoadingIndicator-BQMNX6Dx.js.map +1 -0
- package/dist/MMenuItem-Bih0h4-n.js +604 -0
- package/dist/MMenuItem-Bih0h4-n.js.map +1 -0
- package/dist/MProgressBar-BCoruxA-.js +184 -0
- package/dist/MProgressBar-BCoruxA-.js.map +1 -0
- package/dist/MSeekBar-LURE1Ah7.js +435 -0
- package/dist/MSeekBar-LURE1Ah7.js.map +1 -0
- package/dist/MSegmentedButton-DL9JtJFX.js +65 -0
- package/dist/MSegmentedButton-DL9JtJFX.js.map +1 -0
- package/dist/MSlider-_J4IS2_z.js +691 -0
- package/dist/MSlider-_J4IS2_z.js.map +1 -0
- package/dist/MSpinner-BhkMYKOM.js +65 -0
- package/dist/MSpinner-BhkMYKOM.js.map +1 -0
- package/dist/MTextField-CkzwNBWS.js +296 -0
- package/dist/MTextField-CkzwNBWS.js.map +1 -0
- package/dist/MTooltip-B67ZDSGp.js +756 -0
- package/dist/MTooltip-B67ZDSGp.js.map +1 -0
- package/dist/_storageKeys-CYXsUBwK.js +18 -0
- package/dist/_storageKeys-CYXsUBwK.js.map +1 -0
- package/dist/_useEscapeStack-CjndQhqg.js +19 -0
- package/dist/_useEscapeStack-CjndQhqg.js.map +1 -0
- package/dist/api.json +1 -1
- package/dist/chart.js +1 -1
- package/dist/code-editor.js +1 -1
- package/dist/components/MAudioPlayer.vue.d.ts +115 -0
- package/dist/components/MBadge.vue.d.ts +1 -1
- package/dist/components/MBottomSheetScaffold.vue.d.ts +1 -1
- package/dist/components/MBox.vue.d.ts +1 -1
- package/dist/components/MButton.vue.d.ts +1 -1
- package/dist/components/MConfirmDialog.vue.d.ts +1 -1
- package/dist/components/MCopyButton.vue.d.ts +2 -2
- package/dist/components/MDataTable.vue.d.ts +2 -2
- package/dist/components/MDialog.vue.d.ts +2 -2
- package/dist/components/MDivider.vue.d.ts +1 -1
- package/dist/components/MDragHandle.vue.d.ts +1 -1
- package/dist/components/MDrawCanvas.vue.d.ts +148 -0
- package/dist/components/MDrawLayers.vue.d.ts +3 -0
- package/dist/components/MDrawToolbar.vue.d.ts +34 -0
- package/dist/components/MExportButton.vue.d.ts +1 -1
- package/dist/components/MFab.vue.d.ts +2 -2
- package/dist/components/MFabMenu.vue.d.ts +2 -2
- package/dist/components/MFixed.vue.d.ts +1 -1
- package/dist/components/MFlex.vue.d.ts +2 -2
- package/dist/components/MFloorPlan.vue.d.ts +160 -0
- package/dist/components/MFlow.vue.d.ts +305 -0
- package/dist/components/MFlowControls.vue.d.ts +33 -0
- package/dist/components/MFlowHandle.vue.d.ts +16 -0
- package/dist/components/MFlowMinimap.vue.d.ts +22 -0
- package/dist/components/MFlowNode.vue.d.ts +35 -0
- package/dist/components/MGantt.vue.d.ts +141 -0
- package/dist/components/MGanttControls.vue.d.ts +32 -0
- package/dist/components/MIconButton.vue.d.ts +3 -1
- package/dist/components/MImageCropper.vue.d.ts +110 -0
- package/dist/components/MInfiniteScroll.vue.d.ts +1 -1
- package/dist/components/MLightbox.vue.d.ts +2 -2
- package/dist/components/MList.vue.d.ts +1 -1
- package/dist/components/MLoadingOverlay.vue.d.ts +1 -1
- package/dist/components/MMapControl.vue.d.ts +1 -1
- package/dist/components/MMapSearch.vue.d.ts +1 -1
- package/dist/components/MMaskField.vue.d.ts +12 -1
- package/dist/components/MMenu.vue.d.ts +1 -1
- package/dist/components/MNavigationDrawer.vue.d.ts +1 -1
- package/dist/components/MNumberField.vue.d.ts +11 -2
- package/dist/components/MPdfViewer.vue.d.ts +174 -0
- package/dist/components/MPullToRefresh.vue.d.ts +1 -1
- package/dist/components/MResourceTimeline.vue.d.ts +149 -0
- package/dist/components/MScheduler.vue.d.ts +3 -3
- package/dist/components/MScheme.vue.d.ts +1 -1
- package/dist/components/MSearchField.vue.d.ts +1 -1
- package/dist/components/MSeekBar.vue.d.ts +1 -1
- package/dist/components/MSimpleCarousel.vue.d.ts +1 -1
- package/dist/components/MSkeleton.vue.d.ts +1 -1
- package/dist/components/MSlider.vue.d.ts +2 -2
- package/dist/components/MSparkline.vue.d.ts +1 -1
- package/dist/components/MSplitter.vue.d.ts +1 -1
- package/dist/components/MStack.vue.d.ts +2 -2
- package/dist/components/MSwipeToDismiss.vue.d.ts +1 -1
- package/dist/components/MSwitch.vue.d.ts +1 -1
- package/dist/components/MTable.vue.d.ts +1 -1
- package/dist/components/MTagInput.vue.d.ts +12 -1
- package/dist/components/MTextField.vue.d.ts +13 -2
- package/dist/components/MToolbar.vue.d.ts +1 -1
- package/dist/components/MTree.vue.d.ts +2 -2
- package/dist/components/MVideoPlayer.vue.d.ts +253 -0
- package/dist/components/MVirtualTable.vue.d.ts +1 -1
- package/dist/components/MWindow.vue.d.ts +3 -3
- package/dist/components/_MFlowEdge.vue.d.ts +9 -0
- package/dist/components/_MFlowEdgeLabel.vue.d.ts +9 -0
- package/dist/components/_MFlowNodeShell.vue.d.ts +9 -0
- package/dist/components/_MPdfPage.vue.d.ts +76 -0
- package/dist/components/_MTimeBackground.vue.d.ts +14 -0
- package/dist/components/_MTimeHeader.vue.d.ts +20 -0
- package/dist/composables/_flowPanel.d.ts +2 -0
- package/dist/composables/_flowSlot.d.ts +5 -0
- package/dist/composables/_ganttTime.d.ts +41 -0
- package/dist/composables/_useTimeAxis.d.ts +90 -0
- package/dist/composables/drawGeometry.d.ts +119 -0
- package/dist/composables/flowFormats.d.ts +79 -0
- package/dist/composables/flowLayout.d.ts +45 -0
- package/dist/composables/flowPaths.d.ts +53 -0
- package/dist/composables/ganttFormats.d.ts +52 -0
- package/dist/composables/ganttSchedule.d.ts +99 -0
- package/dist/composables/useDrawing.d.ts +44 -0
- package/dist/composables/useFlow.d.ts +266 -0
- package/dist/composables/useGantt.d.ts +87 -0
- package/dist/composables/useLocale.d.ts +163 -0
- package/dist/composables/useMediaPlayer.d.ts +101 -0
- package/dist/composables/usePdf.d.ts +119 -0
- package/dist/composables/useResourceTimeline.d.ts +70 -0
- package/dist/draw.d.ts +7 -0
- package/dist/draw.js +1700 -0
- package/dist/draw.js.map +1 -0
- package/dist/flow.d.ts +14 -0
- package/dist/flow.js +3542 -0
- package/dist/flow.js.map +1 -0
- package/dist/flowPaths-CUc6X373.js +161 -0
- package/dist/flowPaths-CUc6X373.js.map +1 -0
- package/dist/gantt.d.ts +12 -0
- package/dist/gantt.js +3575 -0
- package/dist/gantt.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/locales/index.js +1148 -7
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +7286 -7654
- package/dist/m3ui.js.map +1 -1
- package/dist/map.js +113 -108
- package/dist/map.js.map +1 -1
- package/dist/media.d.ts +5 -0
- package/dist/media.js +1311 -0
- package/dist/media.js.map +1 -0
- package/dist/pdf.d.ts +4 -0
- package/dist/pdf.js +1871 -0
- package/dist/pdf.js.map +1 -0
- package/dist/rich-text-editor.js +28 -26
- package/dist/rich-text-editor.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/{useLocale-JYxDDeXC.js → useLocale-BpGxplLV.js} +165 -2
- package/dist/useLocale-BpGxplLV.js.map +1 -0
- package/dist/{useThemeTokens-y0HZpyhL.js → useThemeTokens-DQQcaWbE.js} +40 -54
- package/dist/useThemeTokens-DQQcaWbE.js.map +1 -0
- package/package.json +29 -5
- package/src/__tests__/MAudioPlayer.test.ts +75 -0
- package/src/__tests__/MDrawCanvas.test.ts +110 -0
- package/src/__tests__/MFloorPlan.test.ts +97 -0
- package/src/__tests__/MFlow.test.ts +575 -0
- package/src/__tests__/MGantt.test.ts +130 -0
- package/src/__tests__/MImageCropper.test.ts +89 -0
- package/src/__tests__/MPdfViewer.test.ts +235 -0
- package/src/__tests__/MResourceTimeline.test.ts +102 -0
- package/src/__tests__/MVideoPlayer.test.ts +201 -0
- package/src/__tests__/drawGeometry.test.ts +58 -0
- package/src/__tests__/fieldExpose.test.ts +30 -0
- package/src/__tests__/flowFormats.test.ts +185 -0
- package/src/__tests__/flowLayout.test.ts +113 -0
- package/src/__tests__/ganttFormats.test.ts +76 -0
- package/src/__tests__/ganttSchedule.test.ts +136 -0
- package/src/__tests__/pdfMock.ts +83 -0
- package/src/__tests__/useMediaPlayer.test.ts +182 -0
- package/src/__tests__/usePdf.test.ts +102 -0
- package/src/components/MAudioPlayer.vue +319 -0
- package/src/components/MDrawCanvas.vue +813 -0
- package/src/components/MDrawLayers.vue +114 -0
- package/src/components/MDrawToolbar.vue +171 -0
- package/src/components/MFloorPlan.vue +581 -0
- package/src/components/MFlow.vue +2049 -0
- package/src/components/MFlowControls.vue +110 -0
- package/src/components/MFlowHandle.vue +60 -0
- package/src/components/MFlowMinimap.vue +134 -0
- package/src/components/MFlowNode.vue +98 -0
- package/src/components/MGantt.vue +1609 -0
- package/src/components/MGanttControls.vue +77 -0
- package/src/components/MIconButton.vue +3 -1
- package/src/components/MImageCropper.vue +507 -0
- package/src/components/MMaskField.vue +13 -0
- package/src/components/MNumberField.vue +13 -0
- package/src/components/MPdfViewer.vue +1269 -0
- package/src/components/MResourceTimeline.vue +1020 -0
- package/src/components/MTagInput.vue +13 -0
- package/src/components/MTextField.vue +16 -0
- package/src/components/MVideoPlayer.vue +839 -0
- package/src/components/_MFlowEdge.vue +100 -0
- package/src/components/_MFlowEdgeLabel.vue +56 -0
- package/src/components/_MFlowNodeShell.vue +111 -0
- package/src/components/_MPdfPage.vue +456 -0
- package/src/components/_MTimeBackground.vue +16 -0
- package/src/components/_MTimeHeader.vue +31 -0
- package/src/composables/_flowPanel.ts +13 -0
- package/src/composables/_flowSlot.ts +6 -0
- package/src/composables/_ganttTime.ts +200 -0
- package/src/composables/_useTimeAxis.ts +224 -0
- package/src/composables/drawGeometry.ts +405 -0
- package/src/composables/flowFormats.ts +916 -0
- package/src/composables/flowLayout.ts +297 -0
- package/src/composables/flowPaths.ts +239 -0
- package/src/composables/ganttFormats.ts +366 -0
- package/src/composables/ganttSchedule.ts +403 -0
- package/src/composables/useDrawing.ts +53 -0
- package/src/composables/useFlow.ts +250 -0
- package/src/composables/useGantt.ts +92 -0
- package/src/composables/useLocale.ts +328 -0
- package/src/composables/useMediaPlayer.ts +406 -0
- package/src/composables/usePdf.ts +456 -0
- package/src/composables/useResourceTimeline.ts +76 -0
- package/src/draw.ts +25 -0
- package/src/flow.ts +26 -0
- package/src/gantt.ts +12 -0
- package/src/index.ts +4 -0
- package/src/locales/de.ts +163 -0
- package/src/locales/es.ts +163 -0
- package/src/locales/fr.ts +163 -0
- package/src/locales/ja.ts +163 -0
- package/src/locales/ko.ts +163 -0
- package/src/locales/pt.ts +163 -0
- package/src/locales/zh.ts +163 -0
- package/src/media.ts +5 -0
- package/src/pdf.ts +15 -0
- package/dist/MMenuItem-D4Gx_l3F.js +0 -929
- package/dist/MMenuItem-D4Gx_l3F.js.map +0 -1
- package/dist/MSlider-Dx_S3vJ9.js +0 -1506
- package/dist/MSlider-Dx_S3vJ9.js.map +0 -1
- package/dist/MTextField-Bz8JIsnl.js +0 -633
- package/dist/MTextField-Bz8JIsnl.js.map +0 -1
- package/dist/useLocale-JYxDDeXC.js.map +0 -1
- package/dist/useThemeTokens-y0HZpyhL.js.map +0 -1
|
@@ -0,0 +1,1269 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
/** One annotation, in PDF points (origin at the page's bottom left), so it survives zoom, rotation and reflows */
|
|
3
|
+
export interface PdfAnnotation {
|
|
4
|
+
id: string
|
|
5
|
+
type: 'highlight' | 'note' | 'ink'
|
|
6
|
+
/** 1-based page */
|
|
7
|
+
page: number
|
|
8
|
+
/** Any CSS color */
|
|
9
|
+
color: string
|
|
10
|
+
/** highlight: the selected lines, `[x1, y1, x2, y2]` each */
|
|
11
|
+
rects?: [number, number, number, number][]
|
|
12
|
+
/** highlight: the text it covers */
|
|
13
|
+
quote?: string
|
|
14
|
+
/** note: where its icon sits */
|
|
15
|
+
at?: [number, number]
|
|
16
|
+
/** ink: strokes, each a list of points */
|
|
17
|
+
paths?: [number, number][][]
|
|
18
|
+
/** ink: stroke width in points */
|
|
19
|
+
width?: number
|
|
20
|
+
/** A note's text, or a comment on a highlight or drawing */
|
|
21
|
+
text?: string
|
|
22
|
+
author?: string
|
|
23
|
+
/** ISO date */
|
|
24
|
+
createdAt: string
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type PdfTool = 'select' | 'highlight' | 'note' | 'ink' | 'eraser'
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* What's left of an annotation after the eraser passed over `at` (PDF points, radius `r`): an ink stroke is cut
|
|
31
|
+
* where it passes (null once nothing is left), a highlight or a note it touches goes entirely. The same object
|
|
32
|
+
* back means it wasn't touched
|
|
33
|
+
*/
|
|
34
|
+
export function eraseFrom(a: PdfAnnotation, at: { x: number; y: number; r: number }): PdfAnnotation | null {
|
|
35
|
+
const { x, y, r } = at
|
|
36
|
+
if (a.type === 'note') {
|
|
37
|
+
const [nx, ny] = a.at ?? [0, 0]
|
|
38
|
+
return Math.hypot(nx - x, ny - y) <= r + 10 ? null : a
|
|
39
|
+
}
|
|
40
|
+
if (a.type === 'highlight') {
|
|
41
|
+
const hit = (a.rects ?? []).some(([x1, y1, x2, y2]) =>
|
|
42
|
+
x >= Math.min(x1, x2) - r && x <= Math.max(x1, x2) + r && y >= Math.min(y1, y2) - r && y <= Math.max(y1, y2) + r)
|
|
43
|
+
return hit ? null : a
|
|
44
|
+
}
|
|
45
|
+
const reach = r + (a.width ?? 2) / 2
|
|
46
|
+
// Distance from the eraser to a segment
|
|
47
|
+
const near = (p: [number, number], q: [number, number]) => {
|
|
48
|
+
const dx = q[0] - p[0]
|
|
49
|
+
const dy = q[1] - p[1]
|
|
50
|
+
const len = dx * dx + dy * dy
|
|
51
|
+
const t = len ? Math.max(0, Math.min(1, ((x - p[0]) * dx + (y - p[1]) * dy) / len)) : 0
|
|
52
|
+
return Math.hypot(p[0] + t * dx - x, p[1] + t * dy - y) <= reach
|
|
53
|
+
}
|
|
54
|
+
let touched = false
|
|
55
|
+
const paths: [number, number][][] = []
|
|
56
|
+
for (const path of a.paths ?? []) {
|
|
57
|
+
let run: [number, number][] = []
|
|
58
|
+
path.forEach((p, i) => {
|
|
59
|
+
const prev = path[i - 1]
|
|
60
|
+
const gone = Math.hypot(p[0] - x, p[1] - y) <= reach
|
|
61
|
+
const crossed = !!prev && run.length > 0 && near(prev, p)
|
|
62
|
+
if (gone || crossed) {
|
|
63
|
+
touched = true
|
|
64
|
+
if (run.length > 1) paths.push(run)
|
|
65
|
+
run = gone ? [] : [p]
|
|
66
|
+
} else run.push(p)
|
|
67
|
+
})
|
|
68
|
+
if (run.length > 1) paths.push(run)
|
|
69
|
+
}
|
|
70
|
+
if (!touched) return a
|
|
71
|
+
return paths.length ? { ...a, paths } : null
|
|
72
|
+
}
|
|
73
|
+
export type PdfZoom = number | 'fit-width' | 'fit-page'
|
|
74
|
+
</script>
|
|
75
|
+
|
|
76
|
+
<script setup lang="ts">
|
|
77
|
+
/**
|
|
78
|
+
* A PDF viewer on pdf.js (not an M3 spec component; after androidx.pdf's `PdfView` and Google Drive's viewer). The
|
|
79
|
+
* pages scroll continuously, each rendered only near the viewport, with selectable text and working links. Zoom:
|
|
80
|
+
* fit to width (the default) or the page, a percentage, Ctrl + wheel or a trackpad pinch, a pinch on touch, and a
|
|
81
|
+
* double click or double tap (zooms in there, or back to the width). A top bar with the page, zoom, search (hits
|
|
82
|
+
* marked in the text), and download, print, rotate and full screen; a side panel with thumbnails and the outline;
|
|
83
|
+
* a page indicator while scrolling (a draggable thumb on touch). With `annotate`, an edit button opens a floating
|
|
84
|
+
* toolbar to highlight text, place notes and draw, kept in `v-model:annotations` as JSON (not written into the file).
|
|
85
|
+
*
|
|
86
|
+
* Needs the `pdfjs-dist` package. Set its worker once with `setPdfWorker()` (or `worker-src`); without it pdf.js
|
|
87
|
+
* runs on the main thread.
|
|
88
|
+
*
|
|
89
|
+
* @slot actions Extra buttons at the end of the top bar. Props: `{ pdf }`
|
|
90
|
+
* @slot empty Shown without a `src`
|
|
91
|
+
* @event loaded The document loaded, with its pdf.js proxy
|
|
92
|
+
* @event error The document failed to load
|
|
93
|
+
* @event link A link was followed: `{ url }` (opens in a new tab) or `{ page }` (scrolled to)
|
|
94
|
+
* @event annotation-click An annotation was clicked with the select tool
|
|
95
|
+
*/
|
|
96
|
+
import { computed, nextTick, onBeforeUnmount, onMounted, reactive, ref, shallowRef, watch } from 'vue'
|
|
97
|
+
import { usePdf, type PdfDocument, type PdfSource } from '../composables/usePdf'
|
|
98
|
+
import { useLocale } from '../composables/useLocale'
|
|
99
|
+
import PdfPageView from './_MPdfPage.vue'
|
|
100
|
+
import MIconButton from './MIconButton.vue'
|
|
101
|
+
import MIcon from './MIcon.vue'
|
|
102
|
+
import MMenu from './MMenu.vue'
|
|
103
|
+
import MMenuItem from './MMenuItem.vue'
|
|
104
|
+
import MProgressBar from './MProgressBar.vue'
|
|
105
|
+
import MTextField from './MTextField.vue'
|
|
106
|
+
import MButton from './MButton.vue'
|
|
107
|
+
import MLoadingIndicator from './MLoadingIndicator.vue'
|
|
108
|
+
|
|
109
|
+
defineOptions({ inheritAttrs: false })
|
|
110
|
+
|
|
111
|
+
const props = withDefaults(defineProps<{
|
|
112
|
+
/** The PDF: a URL, its bytes, or a `File`/`Blob` */
|
|
113
|
+
src?: PdfSource | null
|
|
114
|
+
/** Shown in the top bar; default the document's own title */
|
|
115
|
+
title?: string
|
|
116
|
+
/** Current page, 1-based (v-model) */
|
|
117
|
+
page?: number
|
|
118
|
+
/** `fit-width`, `fit-page`, or a zoom where 1 is 100% (v-model) */
|
|
119
|
+
zoom?: PdfZoom
|
|
120
|
+
/** Extra rotation in degrees, a multiple of 90 (v-model) */
|
|
121
|
+
rotation?: number
|
|
122
|
+
/** Annotations to draw (v-model) */
|
|
123
|
+
annotations?: PdfAnnotation[]
|
|
124
|
+
/** Shows the edit button and the annotation toolbar */
|
|
125
|
+
annotate?: boolean
|
|
126
|
+
/** The active tool (v-model) */
|
|
127
|
+
tool?: PdfTool
|
|
128
|
+
/** Colors offered for annotations */
|
|
129
|
+
colors?: string[]
|
|
130
|
+
/** The pen's widths offered in the toolbar, in PDF points (the first one is the default) */
|
|
131
|
+
inkWidths?: number[]
|
|
132
|
+
/** Written into new annotations' `author` */
|
|
133
|
+
author?: string
|
|
134
|
+
/** The side panel: thumbnails, the outline, or closed (v-model) */
|
|
135
|
+
sidebar?: 'thumbnails' | 'outline' | null
|
|
136
|
+
/** Shows the top bar */
|
|
137
|
+
toolbar?: boolean
|
|
138
|
+
/** Shows download and print */
|
|
139
|
+
downloadable?: boolean
|
|
140
|
+
/** File name for downloads; default the URL's or the document's title */
|
|
141
|
+
fileName?: string
|
|
142
|
+
/** A password to try first */
|
|
143
|
+
password?: string
|
|
144
|
+
/** The pdf.js worker URL (or `setPdfWorker()` once for the app) */
|
|
145
|
+
workerSrc?: string
|
|
146
|
+
minZoom?: number
|
|
147
|
+
maxZoom?: number
|
|
148
|
+
}>(), {
|
|
149
|
+
src: null,
|
|
150
|
+
page: undefined,
|
|
151
|
+
zoom: 'fit-width',
|
|
152
|
+
rotation: 0,
|
|
153
|
+
annotations: () => [],
|
|
154
|
+
annotate: false,
|
|
155
|
+
tool: 'select',
|
|
156
|
+
colors: () => ['#FFE14D', '#7ED957', '#5EB8FF', '#FF7EB6', '#B388FF', '#1F1F1F'],
|
|
157
|
+
inkWidths: () => [1, 2, 4, 8],
|
|
158
|
+
sidebar: null,
|
|
159
|
+
toolbar: true,
|
|
160
|
+
downloadable: true,
|
|
161
|
+
minZoom: 0.25,
|
|
162
|
+
maxZoom: 8,
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
const emit = defineEmits<{
|
|
166
|
+
'update:page': [number]
|
|
167
|
+
'update:zoom': [PdfZoom]
|
|
168
|
+
'update:rotation': [number]
|
|
169
|
+
'update:annotations': [PdfAnnotation[]]
|
|
170
|
+
'update:tool': [PdfTool]
|
|
171
|
+
'update:sidebar': ['thumbnails' | 'outline' | null]
|
|
172
|
+
loaded: [PdfDocument]
|
|
173
|
+
error: [Error]
|
|
174
|
+
link: [{ url?: string; page?: number }]
|
|
175
|
+
'annotation-click': [PdfAnnotation]
|
|
176
|
+
}>()
|
|
177
|
+
|
|
178
|
+
const locale = useLocale()
|
|
179
|
+
const pdf = usePdf(() => props.src, { password: () => props.password, workerSrc: props.workerSrc })
|
|
180
|
+
watch(pdf.doc, (d) => { if (d) emit('loaded', d) })
|
|
181
|
+
watch(pdf.error, (e) => { if (e) emit('error', e) })
|
|
182
|
+
|
|
183
|
+
const root = ref<HTMLElement>()
|
|
184
|
+
const scroller = ref<HTMLElement>()
|
|
185
|
+
const viewW = ref(800)
|
|
186
|
+
const viewH = ref(600)
|
|
187
|
+
const rootW = ref(800)
|
|
188
|
+
const compact = computed(() => rootW.value < 600)
|
|
189
|
+
|
|
190
|
+
// ── Layout: CSS px per PDF point at 100% (pdf.js's and the browser's 100%), page gap and padding ─────────
|
|
191
|
+
const PT = 96 / 72
|
|
192
|
+
const GAP = 8
|
|
193
|
+
const PAD = 16
|
|
194
|
+
const rotation = ref(((props.rotation % 360) + 360) % 360)
|
|
195
|
+
watch(() => props.rotation, (r) => { rotation.value = ((r % 360) + 360) % 360 })
|
|
196
|
+
|
|
197
|
+
const sizes = computed(() => {
|
|
198
|
+
const swap = rotation.value % 180 !== 0
|
|
199
|
+
return pdf.pageSizes.value.map((s) => (swap ? { width: s.height, height: s.width } : s))
|
|
200
|
+
})
|
|
201
|
+
const zoomMode = ref<PdfZoom>(props.zoom)
|
|
202
|
+
watch(() => props.zoom, (z) => { if (z !== zoomMode.value) setZoom(z) })
|
|
203
|
+
|
|
204
|
+
const refSize = computed(() => sizes.value[Math.max(0, currentPage.value - 1)] ?? sizes.value[0] ?? { width: 612, height: 792 })
|
|
205
|
+
function fitScale(mode: 'fit-width' | 'fit-page') {
|
|
206
|
+
const w = (viewW.value - 2 * (compact.value ? 8 : PAD)) / refSize.value.width
|
|
207
|
+
if (mode === 'fit-width') return w
|
|
208
|
+
return Math.min(w, (viewH.value - 2 * PAD) / refSize.value.height)
|
|
209
|
+
}
|
|
210
|
+
// The scale actually used (px per point); a numeric zoom is relative to 100%
|
|
211
|
+
const scale = computed(() => {
|
|
212
|
+
const z = zoomMode.value
|
|
213
|
+
const s = typeof z === 'number' ? z * PT : fitScale(z)
|
|
214
|
+
return Math.max(props.minZoom * PT, Math.min(props.maxZoom * PT, s || PT))
|
|
215
|
+
})
|
|
216
|
+
const zoomPercent = computed(() => Math.round((scale.value / PT) * 100))
|
|
217
|
+
|
|
218
|
+
const layout = computed(() => {
|
|
219
|
+
const pad = compact.value ? 8 : PAD
|
|
220
|
+
let y = pad
|
|
221
|
+
let maxW = 0
|
|
222
|
+
const boxes = sizes.value.map((s) => {
|
|
223
|
+
const w = Math.floor(s.width * scale.value)
|
|
224
|
+
const h = Math.floor(s.height * scale.value)
|
|
225
|
+
const box = { top: y, width: w, height: h }
|
|
226
|
+
y += h + GAP
|
|
227
|
+
maxW = Math.max(maxW, w)
|
|
228
|
+
return box
|
|
229
|
+
})
|
|
230
|
+
return { boxes, height: y - GAP + pad, width: maxW + 2 * pad, pad }
|
|
231
|
+
})
|
|
232
|
+
|
|
233
|
+
// ── Scroll position → current page and the pages to render ──────────────────────────────────────────────
|
|
234
|
+
const scrollTop = ref(0)
|
|
235
|
+
function pageAt(y: number) {
|
|
236
|
+
const boxes = layout.value.boxes
|
|
237
|
+
let lo = 0
|
|
238
|
+
let hi = boxes.length - 1
|
|
239
|
+
while (lo < hi) {
|
|
240
|
+
const mid = (lo + hi + 1) >> 1
|
|
241
|
+
if (boxes[mid]!.top <= y) lo = mid
|
|
242
|
+
else hi = mid - 1
|
|
243
|
+
}
|
|
244
|
+
return lo
|
|
245
|
+
}
|
|
246
|
+
const currentPage = ref(1)
|
|
247
|
+
function updateCurrent() {
|
|
248
|
+
if (!layout.value.boxes.length) return
|
|
249
|
+
// The page under a third of the way down the view
|
|
250
|
+
const p = pageAt(scrollTop.value + viewH.value / 3) + 1
|
|
251
|
+
if (p !== currentPage.value) {
|
|
252
|
+
currentPage.value = p
|
|
253
|
+
emit('update:page', p)
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
const activePages = computed(() => {
|
|
257
|
+
const boxes = layout.value.boxes
|
|
258
|
+
if (!boxes.length) return new Set<number>()
|
|
259
|
+
const a = pageAt(Math.max(0, scrollTop.value - viewH.value))
|
|
260
|
+
const b = pageAt(scrollTop.value + viewH.value * 2)
|
|
261
|
+
const set = new Set<number>()
|
|
262
|
+
for (let i = a; i <= b; i++) set.add(i + 1)
|
|
263
|
+
return set
|
|
264
|
+
})
|
|
265
|
+
|
|
266
|
+
let scrollingTimer: ReturnType<typeof setTimeout> | undefined
|
|
267
|
+
const scrolling = ref(false)
|
|
268
|
+
// A scroll we made to keep the reading point through a resize: no page indicator for it
|
|
269
|
+
let keptTop: number | null = null
|
|
270
|
+
function onScroll() {
|
|
271
|
+
const el = scroller.value!
|
|
272
|
+
scrollTop.value = el.scrollTop
|
|
273
|
+
updateCurrent()
|
|
274
|
+
if (keptTop !== null && Math.abs(el.scrollTop - keptTop) < 1) {
|
|
275
|
+
keptTop = null
|
|
276
|
+
return
|
|
277
|
+
}
|
|
278
|
+
keptTop = null
|
|
279
|
+
scrolling.value = true
|
|
280
|
+
clearTimeout(scrollingTimer)
|
|
281
|
+
scrollingTimer = setTimeout(() => (scrolling.value = false), 1200)
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function goTo(page: number, top?: number, smooth = false) {
|
|
285
|
+
const el = scroller.value
|
|
286
|
+
const box = layout.value.boxes[page - 1]
|
|
287
|
+
if (!el || !box) return
|
|
288
|
+
// A destination's `top` is in PDF points from the page's bottom (unrotated pages only)
|
|
289
|
+
const size = sizes.value[page - 1]!
|
|
290
|
+
const within = top !== undefined && rotation.value === 0 ? Math.max(0, (size.height - top) * scale.value) : 0
|
|
291
|
+
el.scrollTo({ top: box.top + within - (within ? 8 : layout.value.pad), behavior: smooth ? 'smooth' : 'auto' })
|
|
292
|
+
currentPage.value = page
|
|
293
|
+
emit('update:page', page)
|
|
294
|
+
}
|
|
295
|
+
watch(() => props.page, (p) => { if (p && p !== currentPage.value) goTo(p) })
|
|
296
|
+
|
|
297
|
+
// ── Zoom about a point, keeping what's under it in place ────────────────────────────────────────────────
|
|
298
|
+
function setZoom(z: PdfZoom, anchor?: { x: number; y: number }) {
|
|
299
|
+
const el = scroller.value
|
|
300
|
+
const nextScale = typeof z === 'number' ? Math.max(props.minZoom, Math.min(props.maxZoom, z)) : z
|
|
301
|
+
if (!el || !layout.value.boxes.length) {
|
|
302
|
+
zoomMode.value = nextScale
|
|
303
|
+
emit('update:zoom', nextScale)
|
|
304
|
+
return
|
|
305
|
+
}
|
|
306
|
+
const r = el.getBoundingClientRect()
|
|
307
|
+
const ax = anchor ? anchor.x - r.left : el.clientWidth / 2
|
|
308
|
+
const ay = anchor ? anchor.y - r.top : el.clientHeight / 2
|
|
309
|
+
const docY = el.scrollTop + ay
|
|
310
|
+
const i = pageAt(docY)
|
|
311
|
+
const box = layout.value.boxes[i]!
|
|
312
|
+
const fy = (docY - box.top) / box.height
|
|
313
|
+
const contentW = Math.max(layout.value.width, el.clientWidth)
|
|
314
|
+
const left = (contentW - box.width) / 2
|
|
315
|
+
const fx = (el.scrollLeft + ax - left) / box.width
|
|
316
|
+
zoomMode.value = nextScale
|
|
317
|
+
emit('update:zoom', nextScale)
|
|
318
|
+
nextTick(() => {
|
|
319
|
+
const nb = layout.value.boxes[i]!
|
|
320
|
+
const nContentW = Math.max(layout.value.width, el.clientWidth)
|
|
321
|
+
el.scrollTop = nb.top + fy * nb.height - ay
|
|
322
|
+
el.scrollLeft = (nContentW - nb.width) / 2 + fx * nb.width - ax
|
|
323
|
+
onScroll()
|
|
324
|
+
})
|
|
325
|
+
}
|
|
326
|
+
const zoomBy = (f: number, anchor?: { x: number; y: number }) => setZoom((scale.value / PT) * f, anchor)
|
|
327
|
+
const ZOOM_STEPS = [0.5, 0.75, 1, 1.25, 1.5, 2, 3, 4]
|
|
328
|
+
function stepZoom(dir: 1 | -1) {
|
|
329
|
+
const z = scale.value / PT
|
|
330
|
+
const next = dir > 0 ? ZOOM_STEPS.find((s) => s > z + 0.01) ?? props.maxZoom : [...ZOOM_STEPS].reverse().find((s) => s < z - 0.01) ?? props.minZoom
|
|
331
|
+
setZoom(next)
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// Ctrl + wheel (a trackpad pinch arrives as one too)
|
|
335
|
+
function onWheel(e: WheelEvent) {
|
|
336
|
+
if (!e.ctrlKey && !e.metaKey) return
|
|
337
|
+
e.preventDefault()
|
|
338
|
+
zoomBy(Math.exp(-e.deltaY * (e.deltaMode === 1 ? 0.05 : 0.0025)), { x: e.clientX, y: e.clientY })
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// Double click / double tap: zoom in there, or back to the width (androidx.pdf's double tap)
|
|
342
|
+
function onDblClick(e: MouseEvent) {
|
|
343
|
+
if (props.tool !== 'select' || (e.target as HTMLElement).closest('button, a, input, textarea')) return
|
|
344
|
+
const fit = fitScale('fit-width')
|
|
345
|
+
if (scale.value > fit * 1.05) setZoom('fit-width', { x: e.clientX, y: e.clientY })
|
|
346
|
+
else setZoom(Math.min(props.maxZoom, (fit * 2) / PT), { x: e.clientX, y: e.clientY })
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
// Pinch on touch: pdf.js's TouchManager owns two-finger gestures (one finger still scrolls natively)
|
|
350
|
+
let touchAC: AbortController | null = null
|
|
351
|
+
let pinchFrame = 0
|
|
352
|
+
let pinchFactor = 1
|
|
353
|
+
let pinchOrigin = { x: 0, y: 0 }
|
|
354
|
+
function setupPinch() {
|
|
355
|
+
const lib = pdf.pdfjs.value
|
|
356
|
+
const el = scroller.value
|
|
357
|
+
if (!lib || !el || touchAC) return
|
|
358
|
+
touchAC = new AbortController()
|
|
359
|
+
new lib.TouchManager({
|
|
360
|
+
container: el,
|
|
361
|
+
isPinchingDisabled: () => props.tool === 'ink',
|
|
362
|
+
onPinching: (origin: [number, number], prevDistance: number, distance: number) => {
|
|
363
|
+
pinchFactor *= distance / (prevDistance || distance)
|
|
364
|
+
pinchOrigin = { x: origin[0], y: origin[1] }
|
|
365
|
+
pinchFrame ||= requestAnimationFrame(() => {
|
|
366
|
+
pinchFrame = 0
|
|
367
|
+
const f = pinchFactor
|
|
368
|
+
pinchFactor = 1
|
|
369
|
+
zoomBy(f, pinchOrigin)
|
|
370
|
+
})
|
|
371
|
+
},
|
|
372
|
+
signal: touchAC.signal,
|
|
373
|
+
})
|
|
374
|
+
}
|
|
375
|
+
watch(() => pdf.pdfjs.value, setupPinch)
|
|
376
|
+
|
|
377
|
+
// ── Fit modes follow the size; a new document starts at the top ─────────────────────────────────────────
|
|
378
|
+
let ro: ResizeObserver | undefined
|
|
379
|
+
watch(pdf.doc, async (d) => {
|
|
380
|
+
if (!d) return
|
|
381
|
+
await nextTick()
|
|
382
|
+
const p = props.page && props.page <= d.numPages ? props.page : 1
|
|
383
|
+
currentPage.value = p
|
|
384
|
+
if (p > 1) goTo(p)
|
|
385
|
+
else if (scroller.value) scroller.value.scrollTop = 0
|
|
386
|
+
setupPinch()
|
|
387
|
+
})
|
|
388
|
+
|
|
389
|
+
// ── Rotation ────────────────────────────────────────────────────────────────────────────────────────────
|
|
390
|
+
function rotate() {
|
|
391
|
+
const page = currentPage.value
|
|
392
|
+
rotation.value = (rotation.value + 90) % 360
|
|
393
|
+
emit('update:rotation', rotation.value)
|
|
394
|
+
nextTick(() => goTo(page))
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// ── Search ──────────────────────────────────────────────────────────────────────────────────────────────
|
|
398
|
+
const searchOpen = ref(false)
|
|
399
|
+
const query = ref('')
|
|
400
|
+
const matches = shallowRef<{ page: number; start: number; end: number }[]>([])
|
|
401
|
+
const matchIndex = ref(-1)
|
|
402
|
+
const searching = ref(false)
|
|
403
|
+
let searchAC: AbortController | null = null
|
|
404
|
+
let searchTimer: ReturnType<typeof setTimeout> | undefined
|
|
405
|
+
watch(query, (q) => {
|
|
406
|
+
clearTimeout(searchTimer)
|
|
407
|
+
searchTimer = setTimeout(() => runSearch(q), 250)
|
|
408
|
+
})
|
|
409
|
+
async function runSearch(q: string) {
|
|
410
|
+
searchAC?.abort()
|
|
411
|
+
matches.value = []
|
|
412
|
+
matchIndex.value = -1
|
|
413
|
+
if (!q.trim() || !pdf.doc.value) return
|
|
414
|
+
const ac = (searchAC = new AbortController())
|
|
415
|
+
searching.value = true
|
|
416
|
+
const found = await pdf.search(q, { signal: ac.signal })
|
|
417
|
+
if (ac.signal.aborted) return
|
|
418
|
+
searching.value = false
|
|
419
|
+
matches.value = found
|
|
420
|
+
// The first hit at or after the current page
|
|
421
|
+
const i = found.findIndex((m) => m.page >= currentPage.value)
|
|
422
|
+
if (found.length) showMatch(i < 0 ? 0 : i)
|
|
423
|
+
}
|
|
424
|
+
function showMatch(i: number) {
|
|
425
|
+
const n = matches.value.length
|
|
426
|
+
if (!n) return
|
|
427
|
+
matchIndex.value = ((i % n) + n) % n
|
|
428
|
+
const m = matches.value[matchIndex.value]!
|
|
429
|
+
// Scroll its page in, then the hit itself once marked
|
|
430
|
+
if (!activePages.value.has(m.page) || Math.abs(m.page - currentPage.value) > 0) goTo(m.page)
|
|
431
|
+
pendingHitScroll = true
|
|
432
|
+
}
|
|
433
|
+
let pendingHitScroll = false
|
|
434
|
+
const hitsByPage = computed(() => {
|
|
435
|
+
const map = new Map<number, { start: number; end: number; current: boolean }[]>()
|
|
436
|
+
matches.value.forEach((m, i) => {
|
|
437
|
+
const list = map.get(m.page) ?? []
|
|
438
|
+
list.push({ start: m.start, end: m.end, current: i === matchIndex.value })
|
|
439
|
+
map.set(m.page, list)
|
|
440
|
+
})
|
|
441
|
+
return map
|
|
442
|
+
})
|
|
443
|
+
const NO_HITS: { start: number; end: number; current: boolean }[] = []
|
|
444
|
+
const pageRefs = reactive(new Map<number, InstanceType<typeof PdfPageView>>())
|
|
445
|
+
function setPageRef(n: number, el: unknown) {
|
|
446
|
+
if (el) pageRefs.set(n, el as InstanceType<typeof PdfPageView>)
|
|
447
|
+
else pageRefs.delete(n)
|
|
448
|
+
}
|
|
449
|
+
// Once the focused hit is marked in its page's text layer, bring it to the middle of the view
|
|
450
|
+
watch(() => {
|
|
451
|
+
const m = matches.value[matchIndex.value]
|
|
452
|
+
return m ? pageRefs.get(m.page)?.currentHit : null
|
|
453
|
+
}, (el) => {
|
|
454
|
+
if (!el || !pendingHitScroll || !scroller.value) return
|
|
455
|
+
pendingHitScroll = false
|
|
456
|
+
const r = (el as HTMLElement).getBoundingClientRect()
|
|
457
|
+
const s = scroller.value.getBoundingClientRect()
|
|
458
|
+
scroller.value.scrollBy({ top: r.top - s.top - s.height / 2, left: r.left < s.left || r.right > s.right ? r.left - s.left - s.width / 2 : 0 })
|
|
459
|
+
})
|
|
460
|
+
function openSearch() {
|
|
461
|
+
searchOpen.value = true
|
|
462
|
+
nextTick(() => root.value?.querySelector<HTMLInputElement>('.m3-pdf-search input')?.focus())
|
|
463
|
+
}
|
|
464
|
+
function closeSearch() {
|
|
465
|
+
searchOpen.value = false
|
|
466
|
+
query.value = ''
|
|
467
|
+
searchAC?.abort()
|
|
468
|
+
matches.value = []
|
|
469
|
+
matchIndex.value = -1
|
|
470
|
+
}
|
|
471
|
+
const matchText = computed(() =>
|
|
472
|
+
!query.value.trim() ? '' : searching.value ? '…' : matches.value.length ? locale.pdfMatchCount.replace('{current}', String(matchIndex.value + 1)).replace('{total}', String(matches.value.length)) : locale.pdfNoMatches,
|
|
473
|
+
)
|
|
474
|
+
|
|
475
|
+
// ── Side panel: thumbnails and outline ──────────────────────────────────────────────────────────────────
|
|
476
|
+
const panel = ref<'thumbnails' | 'outline' | null>(props.sidebar)
|
|
477
|
+
watch(() => props.sidebar, (v) => { panel.value = v })
|
|
478
|
+
function setPanel(v: 'thumbnails' | 'outline' | null) {
|
|
479
|
+
panel.value = v
|
|
480
|
+
emit('update:sidebar', v)
|
|
481
|
+
}
|
|
482
|
+
const thumbs = reactive(new Map<number, string>())
|
|
483
|
+
const thumbList = ref<HTMLElement>()
|
|
484
|
+
let thumbObserver: IntersectionObserver | null = null
|
|
485
|
+
function observeThumb(el: unknown, n: number) {
|
|
486
|
+
if (!(el instanceof HTMLElement)) return
|
|
487
|
+
el.dataset.page = String(n)
|
|
488
|
+
thumbObserver?.observe(el)
|
|
489
|
+
}
|
|
490
|
+
watch([panel, pdf.doc], async ([p, d]) => {
|
|
491
|
+
thumbObserver?.disconnect()
|
|
492
|
+
thumbs.clear()
|
|
493
|
+
if (p !== 'thumbnails' || !d || typeof IntersectionObserver === 'undefined') return
|
|
494
|
+
await nextTick()
|
|
495
|
+
thumbObserver = new IntersectionObserver((entries) => {
|
|
496
|
+
for (const e of entries) {
|
|
497
|
+
if (!e.isIntersecting) continue
|
|
498
|
+
const n = Number((e.target as HTMLElement).dataset.page)
|
|
499
|
+
if (thumbs.has(n)) continue
|
|
500
|
+
thumbs.set(n, '')
|
|
501
|
+
pdf.thumbnail(n, 120).then((url) => thumbs.set(n, url), () => {})
|
|
502
|
+
}
|
|
503
|
+
}, { root: thumbList.value, rootMargin: '200px' })
|
|
504
|
+
thumbList.value?.querySelectorAll<HTMLElement>('[data-page]').forEach((el) => thumbObserver!.observe(el))
|
|
505
|
+
thumbList.value?.querySelector(`[data-page="${currentPage.value}"]`)?.scrollIntoView({ block: 'center' })
|
|
506
|
+
})
|
|
507
|
+
function pickFromPanel(page: number, top?: number) {
|
|
508
|
+
goTo(page, top)
|
|
509
|
+
if (compact.value) setPanel(null)
|
|
510
|
+
}
|
|
511
|
+
const outlineOpen = reactive(new Set<string>())
|
|
512
|
+
type FlatOutline = { key: string; title: string; page?: number; top?: number; url?: string; depth: number; hasChildren: boolean }
|
|
513
|
+
const flatOutline = computed(() => {
|
|
514
|
+
const out: FlatOutline[] = []
|
|
515
|
+
const walk = (items: typeof pdf.outline.value, depth: number, prefix: string) => {
|
|
516
|
+
items.forEach((it, i) => {
|
|
517
|
+
const key = `${prefix}${i}`
|
|
518
|
+
out.push({ key, title: it.title, page: it.page, top: it.top, url: it.url, depth, hasChildren: it.children.length > 0 })
|
|
519
|
+
if (it.children.length && outlineOpen.has(key)) walk(it.children, depth + 1, `${key}.`)
|
|
520
|
+
})
|
|
521
|
+
}
|
|
522
|
+
walk(pdf.outline.value, 0, '')
|
|
523
|
+
return out
|
|
524
|
+
})
|
|
525
|
+
function toggleOutline(key: string) {
|
|
526
|
+
if (outlineOpen.has(key)) outlineOpen.delete(key)
|
|
527
|
+
else outlineOpen.add(key)
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
// ── Links ───────────────────────────────────────────────────────────────────────────────────────────────
|
|
531
|
+
async function onLink(l: { url?: string; dest?: unknown }) {
|
|
532
|
+
if (l.url) {
|
|
533
|
+
emit('link', { url: l.url })
|
|
534
|
+
return
|
|
535
|
+
}
|
|
536
|
+
const at = await pdf.resolveDest(l.dest)
|
|
537
|
+
if (!at) return
|
|
538
|
+
goTo(at.page, at.top)
|
|
539
|
+
emit('link', { page: at.page })
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
// ── Annotations ─────────────────────────────────────────────────────────────────────────────────────────
|
|
543
|
+
const tool = ref<PdfTool>(props.tool)
|
|
544
|
+
watch(() => props.tool, (t) => { tool.value = t })
|
|
545
|
+
function setTool(t: PdfTool) {
|
|
546
|
+
tool.value = t
|
|
547
|
+
emit('update:tool', t)
|
|
548
|
+
selection.value = null
|
|
549
|
+
selected.value = null
|
|
550
|
+
}
|
|
551
|
+
const color = ref(props.colors[0]!)
|
|
552
|
+
const inkWidth = ref(props.inkWidths[1] ?? props.inkWidths[0] ?? 2)
|
|
553
|
+
const editing = ref(false)
|
|
554
|
+
watch(() => props.annotate, (on) => { if (!on) closeEditing() })
|
|
555
|
+
function openEditing() {
|
|
556
|
+
editing.value = true
|
|
557
|
+
setTool('highlight')
|
|
558
|
+
}
|
|
559
|
+
function closeEditing() {
|
|
560
|
+
editing.value = false
|
|
561
|
+
setTool('select')
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
const byPage = computed(() => {
|
|
565
|
+
const map = new Map<number, PdfAnnotation[]>()
|
|
566
|
+
for (const a of props.annotations) {
|
|
567
|
+
const list = map.get(a.page) ?? []
|
|
568
|
+
list.push(a)
|
|
569
|
+
map.set(a.page, list)
|
|
570
|
+
}
|
|
571
|
+
return map
|
|
572
|
+
})
|
|
573
|
+
const NO_ANNOTATIONS: PdfAnnotation[] = []
|
|
574
|
+
const history: PdfAnnotation[][] = []
|
|
575
|
+
function commit(next: PdfAnnotation[]) {
|
|
576
|
+
history.push(props.annotations)
|
|
577
|
+
if (history.length > 50) history.shift()
|
|
578
|
+
canUndo.value = true
|
|
579
|
+
emit('update:annotations', next)
|
|
580
|
+
}
|
|
581
|
+
const canUndo = ref(false)
|
|
582
|
+
function undo() {
|
|
583
|
+
const prev = history.pop()
|
|
584
|
+
canUndo.value = history.length > 0
|
|
585
|
+
if (prev) emit('update:annotations', prev)
|
|
586
|
+
selected.value = null
|
|
587
|
+
}
|
|
588
|
+
function add(a: PdfAnnotation) {
|
|
589
|
+
if (props.author) a.author = props.author
|
|
590
|
+
commit([...props.annotations, a])
|
|
591
|
+
// A new note opens for its text
|
|
592
|
+
if (a.type === 'note') nextTick(() => selectById(a.id))
|
|
593
|
+
}
|
|
594
|
+
function erase(id: string) {
|
|
595
|
+
commit(props.annotations.filter((a) => a.id !== id))
|
|
596
|
+
if (selected.value?.id === id) selected.value = null
|
|
597
|
+
}
|
|
598
|
+
// The eraser dragged across a page: one undo step per stroke of it
|
|
599
|
+
function eraseStart() {
|
|
600
|
+
history.push(props.annotations)
|
|
601
|
+
if (history.length > 50) history.shift()
|
|
602
|
+
canUndo.value = true
|
|
603
|
+
}
|
|
604
|
+
function eraseAt(page: number, at: { x: number; y: number; r: number }) {
|
|
605
|
+
let changed = false
|
|
606
|
+
const next: PdfAnnotation[] = []
|
|
607
|
+
for (const a of props.annotations) {
|
|
608
|
+
const kept = a.page === page ? eraseFrom(a, at) : a
|
|
609
|
+
if (kept !== a) changed = true
|
|
610
|
+
if (kept) next.push(kept)
|
|
611
|
+
}
|
|
612
|
+
if (!changed) return
|
|
613
|
+
if (selected.value && !next.some((a) => a.id === selected.value!.id)) selected.value = null
|
|
614
|
+
emit('update:annotations', next)
|
|
615
|
+
}
|
|
616
|
+
function update(id: string, patch: Partial<PdfAnnotation>) {
|
|
617
|
+
emit('update:annotations', props.annotations.map((a) => (a.id === id ? { ...a, ...patch } : a)))
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
// The selected annotation's card, and the popup over a text selection, placed near what they're about
|
|
621
|
+
const selected = ref<{ id: string; x: number; y: number } | null>(null)
|
|
622
|
+
const selectedAnnotation = computed(() => props.annotations.find((a) => a.id === selected.value?.id) ?? null)
|
|
623
|
+
function place(anchor: DOMRect) {
|
|
624
|
+
const r = root.value!.getBoundingClientRect()
|
|
625
|
+
return { x: Math.min(Math.max(8, anchor.left - r.left + anchor.width / 2), r.width - 8), y: anchor.bottom - r.top + 8 }
|
|
626
|
+
}
|
|
627
|
+
function onSelect(s: { id: string; anchor: DOMRect } | null) {
|
|
628
|
+
if (!s) {
|
|
629
|
+
selected.value = null
|
|
630
|
+
return
|
|
631
|
+
}
|
|
632
|
+
selection.value = null
|
|
633
|
+
selected.value = { id: s.id, ...place(s.anchor) }
|
|
634
|
+
const a = props.annotations.find((x) => x.id === s.id)
|
|
635
|
+
if (a) emit('annotation-click', a)
|
|
636
|
+
}
|
|
637
|
+
function selectById(id: string) {
|
|
638
|
+
const el = root.value?.querySelector(`.m3-pdf-note[aria-label]`)
|
|
639
|
+
const a = props.annotations.find((x) => x.id === id)
|
|
640
|
+
if (!a) return
|
|
641
|
+
const page = pageRefs.get(a.page)?.root as HTMLElement | undefined
|
|
642
|
+
const target = [...(page?.querySelectorAll<HTMLElement>('.m3-pdf-note') ?? [])].pop() ?? el
|
|
643
|
+
if (target) selected.value = { id, ...place(target.getBoundingClientRect()) }
|
|
644
|
+
}
|
|
645
|
+
const cardStyle = computed(() => {
|
|
646
|
+
const s = selected.value ?? selection.value
|
|
647
|
+
if (!s) return {}
|
|
648
|
+
const w = Math.min(300, rootW.value - 16)
|
|
649
|
+
return { left: `${Math.min(Math.max(8, s.x - w / 2), rootW.value - w - 8)}px`, top: `${s.y}px`, width: `${w}px` }
|
|
650
|
+
})
|
|
651
|
+
|
|
652
|
+
const selection = ref<{ page: number; rects: [number, number, number, number][]; quote: string; x: number; y: number } | null>(null)
|
|
653
|
+
function onTextSelection(s: { page: number; rects: [number, number, number, number][]; quote: string; anchor: DOMRect } | null) {
|
|
654
|
+
if (!s || !props.annotate) {
|
|
655
|
+
selection.value = null
|
|
656
|
+
return
|
|
657
|
+
}
|
|
658
|
+
selected.value = null
|
|
659
|
+
selection.value = { page: s.page, rects: s.rects, quote: s.quote, ...place(s.anchor) }
|
|
660
|
+
}
|
|
661
|
+
function highlightSelection() {
|
|
662
|
+
const s = selection.value
|
|
663
|
+
if (!s) return
|
|
664
|
+
add({ id: crypto.randomUUID?.() ?? String(Date.now()), type: 'highlight', page: s.page, color: color.value, rects: s.rects, quote: s.quote, text: '', createdAt: new Date().toISOString() })
|
|
665
|
+
window.getSelection()?.removeAllRanges()
|
|
666
|
+
selection.value = null
|
|
667
|
+
}
|
|
668
|
+
async function copySelection() {
|
|
669
|
+
const s = selection.value
|
|
670
|
+
if (s) await navigator.clipboard?.writeText(s.quote).catch(() => {})
|
|
671
|
+
window.getSelection()?.removeAllRanges()
|
|
672
|
+
selection.value = null
|
|
673
|
+
}
|
|
674
|
+
// Scrolling moves the anchors away: close the floating cards
|
|
675
|
+
watch(scrollTop, () => {
|
|
676
|
+
selection.value = null
|
|
677
|
+
if (selectedAnnotation.value?.type !== 'note') selected.value = null
|
|
678
|
+
})
|
|
679
|
+
|
|
680
|
+
// ── Fast scroll (touch): a thumb on the edge while scrolling, with the page ─────────────────────────────
|
|
681
|
+
const coarse = typeof window !== 'undefined' && !!window.matchMedia?.('(pointer: coarse)').matches
|
|
682
|
+
const thumbTop = computed(() => {
|
|
683
|
+
const el = scroller.value
|
|
684
|
+
const max = layout.value.height - viewH.value
|
|
685
|
+
void scrollTop.value
|
|
686
|
+
return el && max > 0 ? (scrollTop.value / max) * (viewH.value - 48) : 0
|
|
687
|
+
})
|
|
688
|
+
const dragging = ref(false)
|
|
689
|
+
function onThumbDown(e: PointerEvent) {
|
|
690
|
+
e.preventDefault()
|
|
691
|
+
dragging.value = true
|
|
692
|
+
;(e.currentTarget as Element).setPointerCapture(e.pointerId)
|
|
693
|
+
const startY = e.clientY
|
|
694
|
+
const start = scroller.value!.scrollTop
|
|
695
|
+
const max = layout.value.height - viewH.value
|
|
696
|
+
const move = (ev: PointerEvent) => {
|
|
697
|
+
scroller.value!.scrollTop = start + ((ev.clientY - startY) / Math.max(1, viewH.value - 48)) * max
|
|
698
|
+
}
|
|
699
|
+
const up = () => {
|
|
700
|
+
dragging.value = false
|
|
701
|
+
window.removeEventListener('pointermove', move)
|
|
702
|
+
window.removeEventListener('pointerup', up)
|
|
703
|
+
}
|
|
704
|
+
window.addEventListener('pointermove', move)
|
|
705
|
+
window.addEventListener('pointerup', up)
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
// ── Full screen ─────────────────────────────────────────────────────────────────────────────────────────
|
|
709
|
+
const fullscreen = ref(false)
|
|
710
|
+
async function toggleFullscreen() {
|
|
711
|
+
if (document.fullscreenElement) await document.exitFullscreen().catch(() => {})
|
|
712
|
+
else await root.value?.requestFullscreen?.().catch(() => {})
|
|
713
|
+
}
|
|
714
|
+
const onFullscreenChange = () => { fullscreen.value = document.fullscreenElement === root.value }
|
|
715
|
+
|
|
716
|
+
// ── Keys ────────────────────────────────────────────────────────────────────────────────────────────────
|
|
717
|
+
function onKey(e: KeyboardEvent) {
|
|
718
|
+
const t = e.target as HTMLElement
|
|
719
|
+
const typing = !!t.closest('input, textarea, [contenteditable]')
|
|
720
|
+
const mod = e.ctrlKey || e.metaKey
|
|
721
|
+
if (mod && e.key.toLowerCase() === 'f') {
|
|
722
|
+
e.preventDefault()
|
|
723
|
+
openSearch()
|
|
724
|
+
} else if (mod && (e.key === '=' || e.key === '+')) {
|
|
725
|
+
e.preventDefault()
|
|
726
|
+
stepZoom(1)
|
|
727
|
+
} else if (mod && e.key === '-') {
|
|
728
|
+
e.preventDefault()
|
|
729
|
+
stepZoom(-1)
|
|
730
|
+
} else if (mod && e.key === '0') {
|
|
731
|
+
e.preventDefault()
|
|
732
|
+
setZoom('fit-width')
|
|
733
|
+
} else if (mod && e.key.toLowerCase() === 'z' && !typing && props.annotate) {
|
|
734
|
+
e.preventDefault()
|
|
735
|
+
undo()
|
|
736
|
+
} else if (e.key === 'Escape') {
|
|
737
|
+
if (selected.value || selection.value) {
|
|
738
|
+
selected.value = null
|
|
739
|
+
selection.value = null
|
|
740
|
+
} else if (searchOpen.value) closeSearch()
|
|
741
|
+
else if (editing.value) closeEditing()
|
|
742
|
+
else return
|
|
743
|
+
e.stopPropagation()
|
|
744
|
+
} else if (!typing && (e.key === 'Delete' || e.key === 'Backspace') && selected.value) {
|
|
745
|
+
erase(selected.value.id)
|
|
746
|
+
} else if (!typing && !mod && (e.key === 'PageDown' || e.key === 'PageUp')) {
|
|
747
|
+
e.preventDefault()
|
|
748
|
+
goTo(Math.max(1, Math.min(pdf.numPages.value, currentPage.value + (e.key === 'PageDown' ? 1 : -1))))
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
// ── Page field ──────────────────────────────────────────────────────────────────────────────────────────
|
|
753
|
+
const pageInput = ref('')
|
|
754
|
+
watch(currentPage, (p) => { pageInput.value = String(p) }, { immediate: true })
|
|
755
|
+
function commitPageInput() {
|
|
756
|
+
const n = Math.round(Number(pageInput.value))
|
|
757
|
+
if (n >= 1 && n <= pdf.numPages.value) goTo(n)
|
|
758
|
+
else pageInput.value = String(currentPage.value)
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
// ── Password ────────────────────────────────────────────────────────────────────────────────────────────
|
|
762
|
+
const passwordInput = ref('')
|
|
763
|
+
function submitPassword() {
|
|
764
|
+
pdf.submitPassword(passwordInput.value)
|
|
765
|
+
passwordInput.value = ''
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
const docTitle = computed(() => props.title ?? pdf.metadata.value.title ?? '')
|
|
769
|
+
|
|
770
|
+
onMounted(() => {
|
|
771
|
+
const el = scroller.value!
|
|
772
|
+
el.addEventListener('wheel', onWheel, { passive: false })
|
|
773
|
+
ro = new ResizeObserver(() => {
|
|
774
|
+
// A fit mode rescales every page when the size changes (the side panel opening, a rotated phone):
|
|
775
|
+
// keep the point being read, a third of the way down like the current page, where it was
|
|
776
|
+
const boxes = layout.value.boxes
|
|
777
|
+
const ay = viewH.value / 3
|
|
778
|
+
const i = boxes.length ? pageAt(el.scrollTop + ay) : -1
|
|
779
|
+
const fy = i >= 0 ? (el.scrollTop + ay - boxes[i]!.top) / boxes[i]!.height : 0
|
|
780
|
+
viewW.value = el.clientWidth
|
|
781
|
+
viewH.value = el.clientHeight
|
|
782
|
+
rootW.value = root.value?.clientWidth ?? rootW.value
|
|
783
|
+
if (i < 0) return
|
|
784
|
+
nextTick(() => {
|
|
785
|
+
const nb = layout.value.boxes[i]
|
|
786
|
+
if (!nb) return
|
|
787
|
+
const top = Math.round(nb.top + fy * nb.height - ay)
|
|
788
|
+
if (Math.abs(top - el.scrollTop) < 1) return
|
|
789
|
+
el.scrollTop = top
|
|
790
|
+
scrollTop.value = el.scrollTop
|
|
791
|
+
updateCurrent()
|
|
792
|
+
keptTop = el.scrollTop
|
|
793
|
+
})
|
|
794
|
+
})
|
|
795
|
+
ro.observe(el)
|
|
796
|
+
ro.observe(root.value!)
|
|
797
|
+
viewW.value = el.clientWidth || viewW.value
|
|
798
|
+
viewH.value = el.clientHeight || viewH.value
|
|
799
|
+
rootW.value = root.value!.clientWidth || rootW.value
|
|
800
|
+
document.addEventListener('fullscreenchange', onFullscreenChange)
|
|
801
|
+
})
|
|
802
|
+
onBeforeUnmount(() => {
|
|
803
|
+
ro?.disconnect()
|
|
804
|
+
touchAC?.abort()
|
|
805
|
+
thumbObserver?.disconnect()
|
|
806
|
+
searchAC?.abort()
|
|
807
|
+
cancelAnimationFrame(pinchFrame)
|
|
808
|
+
clearTimeout(scrollingTimer)
|
|
809
|
+
clearTimeout(searchTimer)
|
|
810
|
+
document.removeEventListener('fullscreenchange', onFullscreenChange)
|
|
811
|
+
})
|
|
812
|
+
|
|
813
|
+
defineExpose({
|
|
814
|
+
pdf,
|
|
815
|
+
goToPage: (p: number) => goTo(p),
|
|
816
|
+
setZoom: (z: PdfZoom) => setZoom(z),
|
|
817
|
+
search: (q: string) => { openSearch(); query.value = q },
|
|
818
|
+
undo,
|
|
819
|
+
})
|
|
820
|
+
|
|
821
|
+
const TOOLS = computed(() => [
|
|
822
|
+
{ id: 'select' as const, icon: 'arrow_selector_tool', label: locale.pdfSelect },
|
|
823
|
+
{ id: 'highlight' as const, icon: 'ink_highlighter', label: locale.pdfHighlight },
|
|
824
|
+
{ id: 'note' as const, icon: 'sticky_note_2', label: locale.pdfNote },
|
|
825
|
+
{ id: 'ink' as const, icon: 'draw', label: locale.pdfDraw },
|
|
826
|
+
{ id: 'eraser' as const, icon: 'ink_eraser', label: locale.pdfEraser },
|
|
827
|
+
])
|
|
828
|
+
</script>
|
|
829
|
+
|
|
830
|
+
<template>
|
|
831
|
+
<div
|
|
832
|
+
ref="root"
|
|
833
|
+
v-bind="$attrs"
|
|
834
|
+
role="region"
|
|
835
|
+
:aria-label="docTitle || locale.pdfViewer"
|
|
836
|
+
class="m3-pdf bg-surface-container text-on-surface"
|
|
837
|
+
@keydown="onKey"
|
|
838
|
+
>
|
|
839
|
+
<!-- Top bar -->
|
|
840
|
+
<div v-if="toolbar" class="relative z-10 flex h-16 shrink-0 items-center gap-1 bg-surface-container px-1 sm:px-2">
|
|
841
|
+
<MIconButton
|
|
842
|
+
:icon="panel ? 'left_panel_close' : 'left_panel_open'"
|
|
843
|
+
:label="locale.pdfThumbnails"
|
|
844
|
+
:disabled="!pdf.doc.value"
|
|
845
|
+
@click="setPanel(panel ? null : 'thumbnails')"
|
|
846
|
+
/>
|
|
847
|
+
<p class="min-w-0 flex-1 truncate px-1 text-title-medium">{{ docTitle }}</p>
|
|
848
|
+
|
|
849
|
+
<template v-if="pdf.doc.value">
|
|
850
|
+
<div v-if="!compact" class="flex items-center gap-1 text-body-medium text-on-surface-variant">
|
|
851
|
+
<input
|
|
852
|
+
v-model="pageInput"
|
|
853
|
+
inputmode="numeric"
|
|
854
|
+
class="h-8 w-11 rounded-sm bg-surface-container-highest text-center text-body-medium text-on-surface tabular-nums outline-none focus:ring-2 focus:ring-primary"
|
|
855
|
+
:aria-label="locale.pdfPage"
|
|
856
|
+
@keydown.enter="commitPageInput"
|
|
857
|
+
@blur="commitPageInput"
|
|
858
|
+
/>
|
|
859
|
+
<span class="tabular-nums">/ {{ pdf.numPages.value }}</span>
|
|
860
|
+
</div>
|
|
861
|
+
<div v-if="!compact" class="mx-1 flex items-center">
|
|
862
|
+
<MIconButton icon="remove" :label="locale.pdfZoomOut" size="xs" @click="stepZoom(-1)" />
|
|
863
|
+
<MMenu align="right">
|
|
864
|
+
<template #trigger>
|
|
865
|
+
<button type="button" class="h-8 min-w-14 cursor-pointer rounded-full px-2 text-label-large tabular-nums hover:bg-on-surface/8" :aria-label="locale.pdfZoom">{{ zoomPercent }}%</button>
|
|
866
|
+
</template>
|
|
867
|
+
<MMenuItem icon="fit_width" :selected="zoomMode === 'fit-width'" @click="setZoom('fit-width')">{{ locale.pdfFitWidth }}</MMenuItem>
|
|
868
|
+
<MMenuItem icon="fit_page" :selected="zoomMode === 'fit-page'" @click="setZoom('fit-page')">{{ locale.pdfFitPage }}</MMenuItem>
|
|
869
|
+
<MMenuItem v-for="z in ZOOM_STEPS" :key="z" :selected="zoomMode === z" @click="setZoom(z)">{{ z * 100 }}%</MMenuItem>
|
|
870
|
+
</MMenu>
|
|
871
|
+
<MIconButton icon="add" :label="locale.pdfZoomIn" size="xs" @click="stepZoom(1)" />
|
|
872
|
+
</div>
|
|
873
|
+
<MIconButton icon="search" :label="locale.pdfSearch" :checked="searchOpen" @update:checked="(v: boolean) => (v ? openSearch() : closeSearch())" />
|
|
874
|
+
<slot name="actions" :pdf="pdf" />
|
|
875
|
+
<MMenu align="right">
|
|
876
|
+
<template #trigger>
|
|
877
|
+
<MIconButton icon="more_vert" :label="locale.pdfMore" />
|
|
878
|
+
</template>
|
|
879
|
+
<template v-if="compact">
|
|
880
|
+
<MMenuItem icon="zoom_in" @click="stepZoom(1)">{{ locale.pdfZoomIn }}</MMenuItem>
|
|
881
|
+
<MMenuItem icon="zoom_out" @click="stepZoom(-1)">{{ locale.pdfZoomOut }}</MMenuItem>
|
|
882
|
+
<MMenuItem icon="fit_width" @click="setZoom('fit-width')">{{ locale.pdfFitWidth }}</MMenuItem>
|
|
883
|
+
</template>
|
|
884
|
+
<MMenuItem icon="list" :disabled="!pdf.outline.value.length" @click="setPanel('outline')">{{ locale.pdfOutline }}</MMenuItem>
|
|
885
|
+
<MMenuItem icon="rotate_right" @click="rotate">{{ locale.pdfRotate }}</MMenuItem>
|
|
886
|
+
<MMenuItem v-if="downloadable" icon="download" @click="pdf.download(fileName)">{{ locale.pdfDownload }}</MMenuItem>
|
|
887
|
+
<MMenuItem v-if="downloadable" icon="print" @click="pdf.print()">{{ locale.pdfPrint }}</MMenuItem>
|
|
888
|
+
<MMenuItem :icon="fullscreen ? 'fullscreen_exit' : 'fullscreen'" @click="toggleFullscreen">{{ fullscreen ? locale.pdfExitFullscreen : locale.pdfFullscreen }}</MMenuItem>
|
|
889
|
+
</MMenu>
|
|
890
|
+
</template>
|
|
891
|
+
<MProgressBar v-if="pdf.loading.value" :value="pdf.progress.value ? pdf.progress.value * 100 : undefined" :indeterminate="!pdf.progress.value" class="absolute inset-x-0 bottom-0" />
|
|
892
|
+
</div>
|
|
893
|
+
|
|
894
|
+
<!-- Search -->
|
|
895
|
+
<Transition name="m3-pdf-drop">
|
|
896
|
+
<div v-if="searchOpen" class="m3-pdf-search z-10 flex shrink-0 items-center gap-1 bg-surface-container px-2 pb-2">
|
|
897
|
+
<div class="flex h-12 min-w-0 flex-1 items-center gap-2 rounded-full bg-surface-container-highest pr-1 pl-4">
|
|
898
|
+
<MIcon name="search" :size="20" class="text-on-surface-variant" />
|
|
899
|
+
<input
|
|
900
|
+
v-model="query"
|
|
901
|
+
type="search"
|
|
902
|
+
class="min-w-0 flex-1 bg-transparent text-body-large outline-none placeholder:text-on-surface-variant"
|
|
903
|
+
:placeholder="locale.pdfSearch"
|
|
904
|
+
:aria-label="locale.pdfSearch"
|
|
905
|
+
@keydown.enter.prevent="showMatch(matchIndex + ((($event as KeyboardEvent).shiftKey) ? -1 : 1))"
|
|
906
|
+
/>
|
|
907
|
+
<span class="shrink-0 text-label-medium whitespace-nowrap text-on-surface-variant tabular-nums" aria-live="polite">{{ matchText }}</span>
|
|
908
|
+
<MIconButton icon="keyboard_arrow_up" :label="locale.pdfSearchPrevious" size="xs" :disabled="!matches.length" @click="showMatch(matchIndex - 1)" />
|
|
909
|
+
<MIconButton icon="keyboard_arrow_down" :label="locale.pdfSearchNext" size="xs" :disabled="!matches.length" @click="showMatch(matchIndex + 1)" />
|
|
910
|
+
</div>
|
|
911
|
+
<MIconButton icon="close" :label="locale.close" @click="closeSearch" />
|
|
912
|
+
</div>
|
|
913
|
+
</Transition>
|
|
914
|
+
|
|
915
|
+
<div class="relative flex min-h-0 flex-1">
|
|
916
|
+
<!-- Side panel: inline on wide screens, over the pages on narrow ones -->
|
|
917
|
+
<Transition name="m3-pdf-fade">
|
|
918
|
+
<div v-if="panel && compact" class="absolute inset-0 z-20 bg-scrim/32" @click="setPanel(null)" />
|
|
919
|
+
</Transition>
|
|
920
|
+
<Transition name="m3-pdf-panel">
|
|
921
|
+
<aside
|
|
922
|
+
v-if="panel && pdf.doc.value"
|
|
923
|
+
class="flex w-56 shrink-0 flex-col bg-surface-container"
|
|
924
|
+
:class="compact ? 'absolute inset-y-0 left-0 z-30 rounded-r-lg shadow-elevation-2' : 'relative'"
|
|
925
|
+
>
|
|
926
|
+
<div class="flex shrink-0 gap-1 px-3 pt-1 pb-2">
|
|
927
|
+
<button
|
|
928
|
+
v-for="tab in (['thumbnails', 'outline'] as const)"
|
|
929
|
+
:key="tab"
|
|
930
|
+
type="button"
|
|
931
|
+
class="h-8 flex-1 cursor-pointer rounded-full text-label-large transition-colors"
|
|
932
|
+
:class="panel === tab ? 'bg-secondary-container text-on-secondary-container' : 'text-on-surface-variant hover:bg-on-surface/8'"
|
|
933
|
+
:disabled="tab === 'outline' && !pdf.outline.value.length"
|
|
934
|
+
@click="setPanel(tab)"
|
|
935
|
+
>{{ tab === 'thumbnails' ? locale.pdfThumbnails : locale.pdfOutline }}</button>
|
|
936
|
+
</div>
|
|
937
|
+
<div v-if="panel === 'thumbnails'" ref="thumbList" class="min-h-0 flex-1 overflow-y-auto px-3 pb-3">
|
|
938
|
+
<div class="flex flex-col items-center gap-3">
|
|
939
|
+
<button
|
|
940
|
+
v-for="n in pdf.numPages.value"
|
|
941
|
+
:key="n"
|
|
942
|
+
:ref="(el) => observeThumb(el, n)"
|
|
943
|
+
type="button"
|
|
944
|
+
class="group flex cursor-pointer flex-col items-center gap-1 outline-none"
|
|
945
|
+
:aria-label="`${locale.pdfPage} ${n}`"
|
|
946
|
+
:aria-current="n === currentPage ? 'page' : undefined"
|
|
947
|
+
@click="pickFromPanel(n)"
|
|
948
|
+
>
|
|
949
|
+
<span
|
|
950
|
+
class="block w-30 overflow-hidden rounded-sm bg-white shadow-elevation-1 ring-offset-2 ring-offset-surface-container transition-shadow group-focus-visible:ring-2 group-focus-visible:ring-secondary"
|
|
951
|
+
:class="n === currentPage && 'ring-3 ring-primary'"
|
|
952
|
+
:style="{ aspectRatio: `${sizes[n - 1]?.width ?? 3} / ${sizes[n - 1]?.height ?? 4}` }"
|
|
953
|
+
>
|
|
954
|
+
<img v-if="thumbs.get(n)" :src="thumbs.get(n)" alt="" class="h-full w-full object-contain" :style="{ transform: rotation ? `rotate(${rotation}deg)` : undefined }" />
|
|
955
|
+
</span>
|
|
956
|
+
<span class="text-label-medium tabular-nums" :class="n === currentPage ? 'text-primary' : 'text-on-surface-variant'">{{ n }}</span>
|
|
957
|
+
</button>
|
|
958
|
+
</div>
|
|
959
|
+
</div>
|
|
960
|
+
<nav v-else class="min-h-0 flex-1 overflow-y-auto px-2 pb-3" :aria-label="locale.pdfOutline">
|
|
961
|
+
<div v-for="o in flatOutline" :key="o.key" class="flex items-center" :style="{ paddingLeft: `${o.depth * 12}px` }">
|
|
962
|
+
<button
|
|
963
|
+
v-if="o.hasChildren"
|
|
964
|
+
type="button"
|
|
965
|
+
class="flex size-8 shrink-0 cursor-pointer items-center justify-center rounded-full text-on-surface-variant hover:bg-on-surface/8"
|
|
966
|
+
:aria-label="outlineOpen.has(o.key) ? locale.collapse : locale.expand"
|
|
967
|
+
@click="toggleOutline(o.key)"
|
|
968
|
+
><MIcon :name="outlineOpen.has(o.key) ? 'expand_more' : 'chevron_right'" :size="20" /></button>
|
|
969
|
+
<span v-else class="w-8 shrink-0" />
|
|
970
|
+
<component
|
|
971
|
+
:is="o.url ? 'a' : 'button'"
|
|
972
|
+
:href="o.url"
|
|
973
|
+
:target="o.url ? '_blank' : undefined"
|
|
974
|
+
:type="o.url ? undefined : 'button'"
|
|
975
|
+
class="flex min-h-10 min-w-0 flex-1 cursor-pointer items-center gap-2 rounded-full px-3 text-left text-label-large hover:bg-on-surface/8"
|
|
976
|
+
@click="o.page && pickFromPanel(o.page, o.top)"
|
|
977
|
+
>
|
|
978
|
+
<span class="min-w-0 flex-1 truncate">{{ o.title }}</span>
|
|
979
|
+
<span v-if="o.page" class="text-label-small text-on-surface-variant tabular-nums">{{ o.page }}</span>
|
|
980
|
+
</component>
|
|
981
|
+
</div>
|
|
982
|
+
</nav>
|
|
983
|
+
</aside>
|
|
984
|
+
</Transition>
|
|
985
|
+
|
|
986
|
+
<!-- Pages -->
|
|
987
|
+
<div class="relative min-w-0 flex-1">
|
|
988
|
+
<div
|
|
989
|
+
ref="scroller"
|
|
990
|
+
class="m3-pdf-scroller absolute inset-0 overflow-auto overscroll-contain bg-surface-container-highest outline-none"
|
|
991
|
+
:class="[tool === 'select' ? '' : 'm3-pdf-annotating', coarse && 'scrollbar-none']"
|
|
992
|
+
tabindex="0"
|
|
993
|
+
@scroll="onScroll"
|
|
994
|
+
@dblclick="onDblClick"
|
|
995
|
+
>
|
|
996
|
+
<div
|
|
997
|
+
v-if="pdf.doc.value"
|
|
998
|
+
class="relative mx-auto"
|
|
999
|
+
:style="{ width: `${layout.width}px`, height: `${layout.height}px` }"
|
|
1000
|
+
>
|
|
1001
|
+
<div
|
|
1002
|
+
v-for="(box, i) in layout.boxes"
|
|
1003
|
+
:key="i"
|
|
1004
|
+
class="absolute left-1/2 -translate-x-1/2"
|
|
1005
|
+
:style="{ top: `${box.top}px`, width: `${box.width}px`, height: `${box.height}px` }"
|
|
1006
|
+
>
|
|
1007
|
+
<PdfPageView
|
|
1008
|
+
:ref="(el) => setPageRef(i + 1, el)"
|
|
1009
|
+
:pdf="pdf"
|
|
1010
|
+
:page="i + 1"
|
|
1011
|
+
:scale="scale"
|
|
1012
|
+
:rotation="rotation"
|
|
1013
|
+
:active="activePages.has(i + 1)"
|
|
1014
|
+
:hits="hitsByPage.get(i + 1) ?? NO_HITS"
|
|
1015
|
+
:annotations="byPage.get(i + 1) ?? NO_ANNOTATIONS"
|
|
1016
|
+
:tool="tool"
|
|
1017
|
+
:color="color"
|
|
1018
|
+
:ink-width="inkWidth"
|
|
1019
|
+
:selected-id="selected?.id ?? null"
|
|
1020
|
+
class="h-full w-full"
|
|
1021
|
+
@link="onLink"
|
|
1022
|
+
@add="add"
|
|
1023
|
+
@erase="erase"
|
|
1024
|
+
@erase-start="eraseStart"
|
|
1025
|
+
@erase-at="(at: { x: number; y: number; r: number }) => eraseAt(i + 1, at)"
|
|
1026
|
+
@select="onSelect"
|
|
1027
|
+
@text-selection="onTextSelection"
|
|
1028
|
+
/>
|
|
1029
|
+
</div>
|
|
1030
|
+
</div>
|
|
1031
|
+
|
|
1032
|
+
<div v-else-if="pdf.needsPassword.value" class="flex h-full items-center justify-center p-6">
|
|
1033
|
+
<form class="flex w-full max-w-sm flex-col items-center gap-4 rounded-xl bg-surface-container-low p-6 text-center shadow-elevation-1" @submit.prevent="submitPassword">
|
|
1034
|
+
<MIcon name="lock" :size="32" class="text-primary" />
|
|
1035
|
+
<p class="text-title-medium">{{ locale.pdfPassword }}</p>
|
|
1036
|
+
<MTextField
|
|
1037
|
+
v-model="passwordInput"
|
|
1038
|
+
type="password"
|
|
1039
|
+
:label="locale.pdfPasswordLabel"
|
|
1040
|
+
:error="pdf.wrongPassword.value"
|
|
1041
|
+
:error-label="pdf.wrongPassword.value ? locale.pdfWrongPassword : undefined"
|
|
1042
|
+
autocomplete="off"
|
|
1043
|
+
class="w-full"
|
|
1044
|
+
/>
|
|
1045
|
+
<MButton type="submit" :disabled="!passwordInput" class="self-end">{{ locale.pdfOpen }}</MButton>
|
|
1046
|
+
</form>
|
|
1047
|
+
</div>
|
|
1048
|
+
<div v-else-if="pdf.error.value" class="flex h-full flex-col items-center justify-center gap-2 p-6 text-center text-on-surface-variant">
|
|
1049
|
+
<MIcon name="error" :size="32" class="text-error" />
|
|
1050
|
+
<p class="text-title-medium text-on-surface">{{ locale.pdfError }}</p>
|
|
1051
|
+
<p class="text-body-medium">{{ pdf.error.value.message }}</p>
|
|
1052
|
+
</div>
|
|
1053
|
+
<div v-else-if="pdf.loading.value" class="flex h-full items-center justify-center">
|
|
1054
|
+
<MLoadingIndicator :label="locale.pdfLoading" />
|
|
1055
|
+
</div>
|
|
1056
|
+
<div v-else class="flex h-full items-center justify-center p-6">
|
|
1057
|
+
<slot name="empty" />
|
|
1058
|
+
</div>
|
|
1059
|
+
</div>
|
|
1060
|
+
|
|
1061
|
+
<!-- Page indicator while scrolling; a draggable thumb on touch (androidx.pdf's fast scroller) -->
|
|
1062
|
+
<Transition name="m3-pdf-fade">
|
|
1063
|
+
<div v-if="pdf.doc.value && (scrolling || dragging) && pdf.numPages.value > 1" class="pointer-events-none absolute inset-y-0 right-0 w-full">
|
|
1064
|
+
<div class="absolute right-1 flex items-center gap-2" :style="{ top: `${coarse ? thumbTop : Math.min(viewH - 40, Math.max(8, thumbTop))}px` }">
|
|
1065
|
+
<span class="rounded-full bg-inverse-surface px-3 py-1 text-label-large text-inverse-on-surface tabular-nums shadow-elevation-1">{{ currentPage }} / {{ pdf.numPages.value }}</span>
|
|
1066
|
+
<span v-if="coarse" class="pointer-events-auto flex h-12 w-6 touch-none items-center justify-center" @pointerdown="onThumbDown">
|
|
1067
|
+
<span class="h-12 w-1.5 rounded-full bg-on-surface-variant" />
|
|
1068
|
+
</span>
|
|
1069
|
+
<span v-else class="w-3" />
|
|
1070
|
+
</div>
|
|
1071
|
+
</div>
|
|
1072
|
+
</Transition>
|
|
1073
|
+
|
|
1074
|
+
<!-- Edit button, and the annotation toolbar (androidx.pdf's edit FAB) -->
|
|
1075
|
+
<Transition name="m3-pdf-fade">
|
|
1076
|
+
<button
|
|
1077
|
+
v-if="annotate && pdf.doc.value && !editing"
|
|
1078
|
+
type="button"
|
|
1079
|
+
class="absolute right-4 bottom-4 flex size-14 cursor-pointer items-center justify-center rounded-lg bg-primary-container text-on-primary-container shadow-elevation-3 transition-shadow outline-none hover:shadow-elevation-4 focus-visible:ring-2 focus-visible:ring-primary"
|
|
1080
|
+
:aria-label="locale.pdfAnnotate"
|
|
1081
|
+
@click="openEditing"
|
|
1082
|
+
><MIcon name="edit" :size="24" /></button>
|
|
1083
|
+
</Transition>
|
|
1084
|
+
<Transition name="m3-pdf-rise">
|
|
1085
|
+
<div v-if="annotate && editing" class="absolute inset-x-0 bottom-4 z-10 flex justify-center px-2">
|
|
1086
|
+
<div class="flex max-w-full items-center gap-1 overflow-x-auto rounded-full bg-surface-container-high p-2 shadow-elevation-3 scrollbar-none" role="toolbar" :aria-label="locale.pdfAnnotate">
|
|
1087
|
+
<MIconButton
|
|
1088
|
+
v-for="t in TOOLS"
|
|
1089
|
+
:key="t.id"
|
|
1090
|
+
:icon="t.icon"
|
|
1091
|
+
:label="t.label"
|
|
1092
|
+
:checked="tool === t.id"
|
|
1093
|
+
variant="standard"
|
|
1094
|
+
@update:checked="setTool(t.id)"
|
|
1095
|
+
/>
|
|
1096
|
+
<span class="mx-1 h-6 w-px shrink-0 bg-outline-variant" />
|
|
1097
|
+
<button
|
|
1098
|
+
v-for="c in colors"
|
|
1099
|
+
:key="c"
|
|
1100
|
+
type="button"
|
|
1101
|
+
class="flex size-10 shrink-0 cursor-pointer items-center justify-center rounded-full outline-none focus-visible:ring-2 focus-visible:ring-primary"
|
|
1102
|
+
:aria-label="`${locale.pdfColor} ${c}`"
|
|
1103
|
+
:aria-pressed="color === c"
|
|
1104
|
+
@click="color = c"
|
|
1105
|
+
>
|
|
1106
|
+
<span class="size-6 rounded-full border border-outline-variant transition-transform" :class="color === c && 'scale-125 ring-2 ring-on-surface ring-offset-2 ring-offset-surface-container-high'" :style="{ backgroundColor: c }" />
|
|
1107
|
+
</button>
|
|
1108
|
+
<!-- The pen's widths, drawn as dots of their size -->
|
|
1109
|
+
<template v-if="tool === 'ink' && inkWidths.length > 1">
|
|
1110
|
+
<span class="mx-1 h-6 w-px shrink-0 bg-outline-variant" />
|
|
1111
|
+
<button
|
|
1112
|
+
v-for="w in inkWidths"
|
|
1113
|
+
:key="w"
|
|
1114
|
+
type="button"
|
|
1115
|
+
class="flex size-10 shrink-0 cursor-pointer items-center justify-center rounded-full outline-none hover:bg-on-surface/8 focus-visible:ring-2 focus-visible:ring-primary"
|
|
1116
|
+
:class="inkWidth === w && 'bg-secondary-container'"
|
|
1117
|
+
:aria-label="locale.pdfInkWidth.replace('{n}', String(w))"
|
|
1118
|
+
:aria-pressed="inkWidth === w"
|
|
1119
|
+
@click="inkWidth = w"
|
|
1120
|
+
>
|
|
1121
|
+
<span class="rounded-full" :style="{ width: `${Math.min(22, 3 + w * 2)}px`, height: `${Math.min(22, 3 + w * 2)}px`, backgroundColor: color }" />
|
|
1122
|
+
</button>
|
|
1123
|
+
</template>
|
|
1124
|
+
<span class="mx-1 h-6 w-px shrink-0 bg-outline-variant" />
|
|
1125
|
+
<MIconButton icon="undo" :label="locale.pdfUndo" :disabled="!canUndo" @click="undo" />
|
|
1126
|
+
<MIconButton icon="close" :label="locale.close" @click="closeEditing" />
|
|
1127
|
+
</div>
|
|
1128
|
+
</div>
|
|
1129
|
+
</Transition>
|
|
1130
|
+
</div>
|
|
1131
|
+
</div>
|
|
1132
|
+
|
|
1133
|
+
<!-- A text selection: copy, or highlight it -->
|
|
1134
|
+
<div v-if="selection" class="absolute z-40 flex justify-center" :style="cardStyle">
|
|
1135
|
+
<div class="flex items-center gap-1 rounded-full bg-surface-container-high p-1 shadow-elevation-2">
|
|
1136
|
+
<MButton variant="text" icon="content_copy" size="sm" @click="copySelection">{{ locale.pdfCopy }}</MButton>
|
|
1137
|
+
<MButton variant="text" icon="ink_highlighter" size="sm" @click="highlightSelection">{{ locale.pdfHighlight }}</MButton>
|
|
1138
|
+
</div>
|
|
1139
|
+
</div>
|
|
1140
|
+
|
|
1141
|
+
<!-- The selected annotation -->
|
|
1142
|
+
<div v-if="selected && selectedAnnotation" class="absolute z-40" :style="cardStyle" @keydown.stop="(e: KeyboardEvent) => e.key === 'Escape' && (selected = null)">
|
|
1143
|
+
<div class="flex flex-col gap-3 rounded-lg bg-surface-container-high p-3 shadow-elevation-2">
|
|
1144
|
+
<p v-if="selectedAnnotation.quote" class="line-clamp-3 border-l-4 pl-2 text-body-medium text-on-surface-variant" :style="{ borderColor: selectedAnnotation.color }">{{ selectedAnnotation.quote }}</p>
|
|
1145
|
+
<MTextField
|
|
1146
|
+
:model-value="selectedAnnotation.text ?? ''"
|
|
1147
|
+
:label="selectedAnnotation.type === 'note' ? locale.pdfNotePlaceholder : locale.pdfAddComment"
|
|
1148
|
+
multiline
|
|
1149
|
+
auto-grow
|
|
1150
|
+
:rows="2"
|
|
1151
|
+
:max-rows="6"
|
|
1152
|
+
variant="outlined"
|
|
1153
|
+
field-bg="var(--color-surface-container-high)"
|
|
1154
|
+
@update:model-value="(v: string | number) => update(selectedAnnotation!.id, { text: String(v) })"
|
|
1155
|
+
/>
|
|
1156
|
+
<div class="flex items-center gap-1">
|
|
1157
|
+
<button
|
|
1158
|
+
v-for="c in colors"
|
|
1159
|
+
:key="c"
|
|
1160
|
+
type="button"
|
|
1161
|
+
class="flex size-8 cursor-pointer items-center justify-center rounded-full outline-none focus-visible:ring-2 focus-visible:ring-primary"
|
|
1162
|
+
:aria-label="`${locale.pdfColor} ${c}`"
|
|
1163
|
+
:aria-pressed="selectedAnnotation.color === c"
|
|
1164
|
+
@click="update(selectedAnnotation!.id, { color: c })"
|
|
1165
|
+
>
|
|
1166
|
+
<span class="size-5 rounded-full border border-outline-variant" :class="selectedAnnotation.color === c && 'ring-2 ring-on-surface ring-offset-1 ring-offset-surface-container-high'" :style="{ backgroundColor: c }" />
|
|
1167
|
+
</button>
|
|
1168
|
+
<span class="flex-1" />
|
|
1169
|
+
<MIconButton icon="delete" :label="locale.pdfDelete" size="xs" @click="erase(selectedAnnotation!.id)" />
|
|
1170
|
+
<MIconButton icon="check" :label="locale.close" size="xs" @click="selected = null" />
|
|
1171
|
+
</div>
|
|
1172
|
+
</div>
|
|
1173
|
+
</div>
|
|
1174
|
+
</div>
|
|
1175
|
+
</template>
|
|
1176
|
+
|
|
1177
|
+
<style>
|
|
1178
|
+
/* Root defaults in the base layer, so any class the consumer gives (absolute inset-0, hidden…) wins */
|
|
1179
|
+
@layer base {
|
|
1180
|
+
.m3-pdf {
|
|
1181
|
+
position: relative;
|
|
1182
|
+
display: flex;
|
|
1183
|
+
flex-direction: column;
|
|
1184
|
+
overflow: hidden;
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
/* pdf.js's text layer (from pdfjs-dist's pdf_viewer.css, Apache-2.0), for selectable text over the canvas */
|
|
1189
|
+
.m3-pdf .textLayer {
|
|
1190
|
+
position: absolute;
|
|
1191
|
+
inset: 0;
|
|
1192
|
+
overflow: clip;
|
|
1193
|
+
line-height: 1;
|
|
1194
|
+
text-align: initial;
|
|
1195
|
+
text-size-adjust: none;
|
|
1196
|
+
forced-color-adjust: none;
|
|
1197
|
+
transform-origin: 0 0;
|
|
1198
|
+
caret-color: CanvasText;
|
|
1199
|
+
z-index: 0;
|
|
1200
|
+
--min-font-size: 1;
|
|
1201
|
+
--text-scale-factor: calc(var(--total-scale-factor) * var(--min-font-size));
|
|
1202
|
+
--min-font-size-inv: calc(1 / var(--min-font-size));
|
|
1203
|
+
}
|
|
1204
|
+
.m3-pdf .textLayer :is(span, br) {
|
|
1205
|
+
color: transparent;
|
|
1206
|
+
position: absolute;
|
|
1207
|
+
white-space: pre;
|
|
1208
|
+
cursor: text;
|
|
1209
|
+
transform-origin: 0% 0%;
|
|
1210
|
+
user-select: text;
|
|
1211
|
+
}
|
|
1212
|
+
.m3-pdf .textLayer > :not(.markedContent),
|
|
1213
|
+
.m3-pdf .textLayer .markedContent span:not(.markedContent) {
|
|
1214
|
+
z-index: 1;
|
|
1215
|
+
--font-height: 0;
|
|
1216
|
+
font-size: calc(var(--text-scale-factor) * var(--font-height));
|
|
1217
|
+
--scale-x: 1;
|
|
1218
|
+
--rotate: 0deg;
|
|
1219
|
+
transform: rotate(var(--rotate)) scaleX(var(--scale-x)) scale(var(--min-font-size-inv));
|
|
1220
|
+
}
|
|
1221
|
+
.m3-pdf .textLayer .markedContent { display: contents; }
|
|
1222
|
+
.m3-pdf .textLayer span.m3-pdf-hit {
|
|
1223
|
+
position: static;
|
|
1224
|
+
margin: -1px;
|
|
1225
|
+
padding: 1px;
|
|
1226
|
+
border-radius: 3px;
|
|
1227
|
+
background-color: color-mix(in srgb, var(--color-tertiary) 30%, transparent);
|
|
1228
|
+
}
|
|
1229
|
+
.m3-pdf .textLayer span.m3-pdf-hit-current { background-color: color-mix(in srgb, var(--color-primary) 45%, transparent); }
|
|
1230
|
+
.m3-pdf .textLayer ::selection { background: color-mix(in srgb, var(--color-primary) 30%, transparent); color: transparent; }
|
|
1231
|
+
.m3-pdf .textLayer br::selection { background: transparent; }
|
|
1232
|
+
.m3-pdf .textLayer .endOfContent {
|
|
1233
|
+
display: block;
|
|
1234
|
+
position: absolute;
|
|
1235
|
+
inset: 100% 0 0;
|
|
1236
|
+
z-index: 0;
|
|
1237
|
+
cursor: default;
|
|
1238
|
+
user-select: none;
|
|
1239
|
+
}
|
|
1240
|
+
.m3-pdf .textLayer.selecting .endOfContent { top: 0; }
|
|
1241
|
+
.m3-pdf [data-main-rotation='90'] { transform: rotate(90deg) translateY(-100%); }
|
|
1242
|
+
.m3-pdf [data-main-rotation='180'] { transform: rotate(180deg) translate(-100%, -100%); }
|
|
1243
|
+
.m3-pdf [data-main-rotation='270'] { transform: rotate(270deg) translateX(-100%); }
|
|
1244
|
+
|
|
1245
|
+
/* Highlights tint the text under them, like a marker */
|
|
1246
|
+
.m3-pdf .m3-pdf-highlight { mix-blend-mode: multiply; opacity: 0.45; }
|
|
1247
|
+
.m3-pdf .m3-pdf-annotating .m3-pdf-highlight,
|
|
1248
|
+
.m3-pdf .m3-pdf-annotating .m3-pdf-ink { cursor: inherit; }
|
|
1249
|
+
.m3-pdf .m3-pdf-scroller:not(.m3-pdf-annotating) :is(.m3-pdf-highlight, .m3-pdf-ink) { pointer-events: auto; cursor: pointer; }
|
|
1250
|
+
.m3-pdf .m3-pdf-scroller.m3-pdf-annotating :is(.m3-pdf-highlight, .m3-pdf-ink) { pointer-events: none; }
|
|
1251
|
+
.m3-pdf .m3-pdf-selected { filter: drop-shadow(0 0 2px var(--color-primary)); opacity: 0.7; }
|
|
1252
|
+
|
|
1253
|
+
.m3-pdf-fade-enter-active,
|
|
1254
|
+
.m3-pdf-fade-leave-active { transition: opacity 200ms cubic-bezier(0.2, 0, 0, 1); }
|
|
1255
|
+
.m3-pdf-fade-enter-from,
|
|
1256
|
+
.m3-pdf-fade-leave-to { opacity: 0; }
|
|
1257
|
+
.m3-pdf-drop-enter-active,
|
|
1258
|
+
.m3-pdf-drop-leave-active { transition: opacity 200ms cubic-bezier(0.2, 0, 0, 1), transform 250ms cubic-bezier(0.2, 0, 0, 1); }
|
|
1259
|
+
.m3-pdf-drop-enter-from,
|
|
1260
|
+
.m3-pdf-drop-leave-to { opacity: 0; transform: translateY(-8px); }
|
|
1261
|
+
.m3-pdf-rise-enter-active,
|
|
1262
|
+
.m3-pdf-rise-leave-active { transition: opacity 200ms cubic-bezier(0.2, 0, 0, 1), transform 300ms cubic-bezier(0.05, 0.7, 0.1, 1); }
|
|
1263
|
+
.m3-pdf-rise-enter-from,
|
|
1264
|
+
.m3-pdf-rise-leave-to { opacity: 0; transform: translateY(24px); }
|
|
1265
|
+
.m3-pdf-panel-enter-active,
|
|
1266
|
+
.m3-pdf-panel-leave-active { transition: margin 300ms cubic-bezier(0.2, 0, 0, 1), opacity 200ms; }
|
|
1267
|
+
.m3-pdf-panel-enter-from,
|
|
1268
|
+
.m3-pdf-panel-leave-to { margin-left: -14rem; opacity: 0; }
|
|
1269
|
+
</style>
|