@joewinke/jatui 0.1.25 → 0.1.26
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/actions/collapse.d.ts +80 -0
- package/dist/actions/collapse.js +134 -0
- package/dist/actions/railNav.d.ts +167 -0
- package/dist/actions/railNav.js +351 -0
- package/dist/components/AnnotationLayer.svelte +108 -0
- package/dist/components/AnnotationLayer.svelte.d.ts +12 -0
- package/dist/components/AnnotationPanel.svelte +319 -0
- package/dist/components/AnnotationPanel.svelte.d.ts +13 -0
- package/dist/components/AudioWaveform.svelte +701 -0
- package/dist/components/AudioWaveform.svelte.d.ts +19 -0
- package/dist/components/AvailabilityModal.svelte +177 -0
- package/dist/components/AvailabilityModal.svelte.d.ts +14 -0
- package/dist/components/AvatarUpload.svelte +234 -0
- package/dist/components/AvatarUpload.svelte.d.ts +23 -0
- package/dist/components/Badge.svelte +38 -0
- package/dist/components/Badge.svelte.d.ts +14 -0
- package/dist/components/BookingForm.svelte +278 -0
- package/dist/components/BookingForm.svelte.d.ts +37 -0
- package/dist/components/BurndownChart.svelte +778 -0
- package/dist/components/BurndownChart.svelte.d.ts +17 -0
- package/dist/components/Button.svelte +81 -0
- package/dist/components/Button.svelte.d.ts +21 -0
- package/dist/components/CalendarPicker.svelte +284 -0
- package/dist/components/CalendarPicker.svelte.d.ts +22 -0
- package/dist/components/Card.svelte +67 -0
- package/dist/components/Card.svelte.d.ts +17 -0
- package/dist/components/CharacterCounter.svelte +82 -0
- package/dist/components/CharacterCounter.svelte.d.ts +10 -0
- package/dist/components/ChipInput.svelte +609 -0
- package/dist/components/ChipInput.svelte.d.ts +55 -0
- package/dist/components/Collapse.svelte +91 -0
- package/dist/components/Collapse.svelte.d.ts +18 -0
- package/dist/components/ColorSelector.svelte +167 -0
- package/dist/components/ColorSelector.svelte.d.ts +9 -0
- package/dist/components/CommentThread.svelte +773 -0
- package/dist/components/CommentThread.svelte.d.ts +32 -0
- package/dist/components/ConfirmDialog.svelte +348 -0
- package/dist/components/ConfirmDialog.svelte.d.ts +3 -0
- package/dist/components/ConfirmModal.svelte +142 -0
- package/dist/components/ConfirmModal.svelte.d.ts +15 -0
- package/dist/components/ContextMenu.svelte +188 -0
- package/dist/components/ContextMenu.svelte.d.ts +31 -0
- package/dist/components/CountdownTimer.svelte +94 -0
- package/dist/components/CountdownTimer.svelte.d.ts +10 -0
- package/dist/components/DateRangePicker.svelte +194 -0
- package/dist/components/DateRangePicker.svelte.d.ts +10 -0
- package/dist/components/Drawer.svelte +143 -0
- package/dist/components/Drawer.svelte.d.ts +33 -0
- package/dist/components/EmojiPicker.svelte +159 -0
- package/dist/components/EmojiPicker.svelte.d.ts +8 -0
- package/dist/components/EntityPreviewCard.svelte +104 -0
- package/dist/components/EntityPreviewCard.svelte.d.ts +9 -0
- package/dist/components/FileDropzone.svelte +493 -0
- package/dist/components/FileDropzone.svelte.d.ts +40 -0
- package/dist/components/FilePicker.svelte +488 -0
- package/dist/components/FilePicker.svelte.d.ts +20 -0
- package/dist/components/FileThumbnail.svelte +80 -0
- package/dist/components/FileThumbnail.svelte.d.ts +12 -0
- package/dist/components/FilterDropdown.svelte +203 -0
- package/dist/components/FilterDropdown.svelte.d.ts +48 -0
- package/dist/components/FloatingActionBar.svelte +354 -0
- package/dist/components/FloatingActionBar.svelte.d.ts +51 -0
- package/dist/components/GPSTracker.svelte +202 -0
- package/dist/components/GPSTracker.svelte.d.ts +34 -0
- package/dist/components/HunkDiffView.svelte +348 -0
- package/dist/components/HunkDiffView.svelte.d.ts +9 -0
- package/dist/components/ImageLightbox.svelte +274 -0
- package/dist/components/ImageLightbox.svelte.d.ts +25 -0
- package/dist/components/ImageUpload.svelte +147 -0
- package/dist/components/ImageUpload.svelte.d.ts +10 -0
- package/dist/components/InlineEdit.svelte +291 -0
- package/dist/components/InlineEdit.svelte.d.ts +45 -0
- package/dist/components/InputDialog.svelte +327 -0
- package/dist/components/InputDialog.svelte.d.ts +3 -0
- package/dist/components/KeyboardShortcutsOverlay.svelte +296 -0
- package/dist/components/KeyboardShortcutsOverlay.svelte.d.ts +42 -0
- package/dist/components/LazyImage.svelte +123 -0
- package/dist/components/LazyImage.svelte.d.ts +14 -0
- package/dist/components/LinkShortener.svelte +274 -0
- package/dist/components/LinkShortener.svelte.d.ts +27 -0
- package/dist/components/LoadingSpinner.svelte +106 -0
- package/dist/components/LoadingSpinner.svelte.d.ts +21 -0
- package/dist/components/LocationMap.svelte +186 -0
- package/dist/components/LocationMap.svelte.d.ts +11 -0
- package/dist/components/MapView.svelte +341 -0
- package/dist/components/MapView.svelte.d.ts +20 -0
- package/dist/components/MarkupEditor.svelte +485 -0
- package/dist/components/MarkupEditor.svelte.d.ts +10 -0
- package/dist/components/MarkupOverlay.svelte +55 -0
- package/dist/components/MarkupOverlay.svelte.d.ts +8 -0
- package/dist/components/MediaWorkbench.svelte +871 -0
- package/dist/components/MediaWorkbench.svelte.d.ts +9 -0
- package/dist/components/MilestoneCard.svelte +98 -0
- package/dist/components/MilestoneCard.svelte.d.ts +16 -0
- package/dist/components/MilestoneTimeline.svelte +91 -0
- package/dist/components/MilestoneTimeline.svelte.d.ts +15 -0
- package/dist/components/Modal.svelte +244 -0
- package/dist/components/Modal.svelte.d.ts +35 -0
- package/dist/components/PDFViewer.svelte +105 -0
- package/dist/components/PDFViewer.svelte.d.ts +9 -0
- package/dist/components/PdfThumbnail.svelte +63 -0
- package/dist/components/PdfThumbnail.svelte.d.ts +9 -0
- package/dist/components/PhoneInput.svelte +212 -0
- package/dist/components/PhoneInput.svelte.d.ts +25 -0
- package/dist/components/ResizableDivider.svelte +307 -0
- package/dist/components/ResizableDivider.svelte.d.ts +26 -0
- package/dist/components/ResizablePanel.svelte +305 -0
- package/dist/components/ResizablePanel.svelte.d.ts +18 -0
- package/dist/components/SearchDropdown.svelte +421 -0
- package/dist/components/SearchDropdown.svelte.d.ts +24 -0
- package/dist/components/SelectInput.svelte +237 -0
- package/dist/components/SelectInput.svelte.d.ts +26 -0
- package/dist/components/SidebarUserFooter.svelte +34 -0
- package/dist/components/SidebarUserFooter.svelte.d.ts +16 -0
- package/dist/components/SignaturePad.svelte +175 -0
- package/dist/components/SignaturePad.svelte.d.ts +17 -0
- package/dist/components/SmartImageEditor.svelte +720 -0
- package/dist/components/SmartImageEditor.svelte.d.ts +24 -0
- package/dist/components/SortDropdown.svelte +156 -0
- package/dist/components/SortDropdown.svelte.d.ts +40 -0
- package/dist/components/Sparkline.svelte +116 -0
- package/dist/components/Sparkline.svelte.d.ts +12 -0
- package/dist/components/SpeechForm.svelte +114 -0
- package/dist/components/SpeechForm.svelte.d.ts +17 -0
- package/dist/components/StatusBadge.svelte +157 -0
- package/dist/components/StatusBadge.svelte.d.ts +24 -0
- package/dist/components/TaskTypeIcon.svelte +54 -0
- package/dist/components/TaskTypeIcon.svelte.d.ts +17 -0
- package/dist/components/TextArea.svelte +162 -0
- package/dist/components/TextArea.svelte.d.ts +30 -0
- package/dist/components/TextInput.svelte +131 -0
- package/dist/components/TextInput.svelte.d.ts +29 -0
- package/dist/components/ThemeSelector.svelte +206 -0
- package/dist/components/ThemeSelector.svelte.d.ts +14 -0
- package/dist/components/TimeSlotPicker.svelte +162 -0
- package/dist/components/TimeSlotPicker.svelte.d.ts +18 -0
- package/dist/components/UserAvatar.svelte +72 -0
- package/dist/components/UserAvatar.svelte.d.ts +11 -0
- package/dist/components/VariablePicker.svelte +170 -0
- package/dist/components/VariablePicker.svelte.d.ts +40 -0
- package/dist/components/VoicePlayer.svelte +422 -0
- package/dist/components/VoicePlayer.svelte.d.ts +18 -0
- package/dist/components/linked-columns/LinkedColumns.svelte +526 -0
- package/dist/components/linked-columns/LinkedColumns.svelte.d.ts +130 -0
- package/dist/components/markup.d.ts +47 -0
- package/dist/components/markup.js +201 -0
- package/dist/components/messaging/Avatar.svelte +81 -0
- package/dist/components/messaging/Avatar.svelte.d.ts +11 -0
- package/dist/components/messaging/ChannelInfoModal.svelte +163 -0
- package/dist/components/messaging/ChannelInfoModal.svelte.d.ts +18 -0
- package/dist/components/messaging/ChannelList.svelte +107 -0
- package/dist/components/messaging/ChannelList.svelte.d.ts +11 -0
- package/dist/components/messaging/ChannelMemberAvatarStack.svelte +69 -0
- package/dist/components/messaging/ChannelMemberAvatarStack.svelte.d.ts +11 -0
- package/dist/components/messaging/ChannelMembersModal.svelte +182 -0
- package/dist/components/messaging/ChannelMembersModal.svelte.d.ts +16 -0
- package/dist/components/messaging/CreateChannelModal.svelte +190 -0
- package/dist/components/messaging/CreateChannelModal.svelte.d.ts +14 -0
- package/dist/components/messaging/DirectMessageList.svelte +145 -0
- package/dist/components/messaging/DirectMessageList.svelte.d.ts +12 -0
- package/dist/components/messaging/EmojiSelector.svelte +261 -0
- package/dist/components/messaging/EmojiSelector.svelte.d.ts +19 -0
- package/dist/components/messaging/MentionAutocomplete.svelte +193 -0
- package/dist/components/messaging/MentionAutocomplete.svelte.d.ts +17 -0
- package/dist/components/messaging/MessageAttachment.svelte +273 -0
- package/dist/components/messaging/MessageAttachment.svelte.d.ts +13 -0
- package/dist/components/messaging/MessageAttachmentUpload.svelte +243 -0
- package/dist/components/messaging/MessageAttachmentUpload.svelte.d.ts +19 -0
- package/dist/components/messaging/MessageInput.svelte +452 -0
- package/dist/components/messaging/MessageInput.svelte.d.ts +28 -0
- package/dist/components/messaging/MessageItem.svelte +341 -0
- package/dist/components/messaging/MessageItem.svelte.d.ts +41 -0
- package/dist/components/messaging/MessageThread.svelte +306 -0
- package/dist/components/messaging/MessageThread.svelte.d.ts +30 -0
- package/dist/components/messaging/NotificationSettingsModal.svelte +234 -0
- package/dist/components/messaging/NotificationSettingsModal.svelte.d.ts +13 -0
- package/dist/components/messaging/QuotedMessageDisplay.svelte +123 -0
- package/dist/components/messaging/QuotedMessageDisplay.svelte.d.ts +10 -0
- package/dist/components/messaging/StartDMModal.svelte +100 -0
- package/dist/components/messaging/StartDMModal.svelte.d.ts +14 -0
- package/dist/components/messaging/ThreadPanel.svelte +153 -0
- package/dist/components/messaging/ThreadPanel.svelte.d.ts +16 -0
- package/dist/components/pipeline/DESIGN.md +361 -0
- package/dist/components/pipeline/Pipeline.svelte +391 -0
- package/dist/components/pipeline/Pipeline.svelte.d.ts +28 -0
- package/dist/components/pipeline/PipelineCard.svelte +94 -0
- package/dist/components/pipeline/PipelineCard.svelte.d.ts +13 -0
- package/dist/components/pipeline/PipelineColumn.svelte +163 -0
- package/dist/components/pipeline/PipelineColumn.svelte.d.ts +30 -0
- package/dist/components/replay/ChapterTimeline.svelte +326 -0
- package/dist/components/replay/ChapterTimeline.svelte.d.ts +39 -0
- package/dist/components/session-nav/transcriptModel.d.ts +132 -0
- package/dist/components/session-nav/transcriptModel.js +285 -0
- package/dist/data/emojis.d.ts +18 -0
- package/dist/data/emojis.js +1196 -0
- package/dist/index.d.ts +142 -0
- package/dist/index.js +142 -0
- package/dist/stores/confirmDialog.svelte.d.ts +21 -0
- package/dist/stores/confirmDialog.svelte.js +31 -0
- package/dist/stores/inputDialog.svelte.d.ts +24 -0
- package/dist/stores/inputDialog.svelte.js +32 -0
- package/dist/styles/rail.css +63 -0
- package/dist/types/annotation.d.ts +32 -0
- package/dist/types/annotation.js +3 -0
- package/dist/types/booking.d.ts +115 -0
- package/dist/types/booking.js +24 -0
- package/dist/types/comments.d.ts +65 -0
- package/dist/types/comments.js +22 -0
- package/dist/types/entityPreview.d.ts +42 -0
- package/dist/types/entityPreview.js +10 -0
- package/dist/types/filePicker.d.ts +15 -0
- package/dist/types/filePicker.js +1 -0
- package/dist/types/googleMaps.d.ts +51 -0
- package/dist/types/maps.d.ts +43 -0
- package/dist/types/maps.js +4 -0
- package/dist/types/messaging.d.ts +282 -0
- package/dist/types/messaging.js +100 -0
- package/dist/types/milestone.d.ts +20 -0
- package/dist/types/milestone.js +7 -0
- package/dist/types/pipeline.d.ts +115 -0
- package/dist/types/pipeline.js +15 -0
- package/dist/types/smartImageEditor.d.ts +42 -0
- package/dist/types/smartImageEditor.js +1 -0
- package/dist/types/templateVars.d.ts +34 -0
- package/dist/types/templateVars.js +12 -0
- package/dist/utils/currency.d.ts +8 -0
- package/dist/utils/currency.js +17 -0
- package/dist/utils/daisyuiColors.d.ts +37 -0
- package/dist/utils/daisyuiColors.js +152 -0
- package/dist/utils/dateFormatters.d.ts +69 -0
- package/dist/utils/dateFormatters.js +199 -0
- package/dist/utils/googleMapsLoader.d.ts +19 -0
- package/dist/utils/googleMapsLoader.js +121 -0
- package/dist/utils/mentionParser.d.ts +67 -0
- package/dist/utils/mentionParser.js +132 -0
- package/dist/utils/phone.d.ts +13 -0
- package/dist/utils/phone.js +67 -0
- package/dist/utils/phoneFormat.d.ts +26 -0
- package/dist/utils/phoneFormat.js +69 -0
- package/dist/utils/taskUtils.d.ts +37 -0
- package/dist/utils/taskUtils.js +71 -0
- package/package.json +3 -2
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
type $$ComponentProps = {
|
|
2
|
+
value?: string | null;
|
|
3
|
+
uploadEndpoint?: string;
|
|
4
|
+
onComplete?: (url: string) => void;
|
|
5
|
+
accept?: string;
|
|
6
|
+
};
|
|
7
|
+
declare const MediaWorkbench: import("svelte").Component<$$ComponentProps, {}, "value">;
|
|
8
|
+
type MediaWorkbench = ReturnType<typeof MediaWorkbench>;
|
|
9
|
+
export default MediaWorkbench;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Milestone, MilestoneStatus } from '../types/milestone'
|
|
3
|
+
|
|
4
|
+
interface LinkedTask {
|
|
5
|
+
id: string
|
|
6
|
+
title: string
|
|
7
|
+
status: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface Props {
|
|
11
|
+
milestone: Milestone
|
|
12
|
+
tasks?: LinkedTask[]
|
|
13
|
+
isCurrent?: boolean
|
|
14
|
+
currency?: string
|
|
15
|
+
onAcceptAndPay?: (milestone: Milestone) => void
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
let { milestone, tasks = [], isCurrent = false, currency = 'USD', onAcceptAndPay }: Props = $props()
|
|
19
|
+
|
|
20
|
+
const statusConfig: Record<MilestoneStatus, { label: string; class: string; icon: string }> = {
|
|
21
|
+
pending: { label: 'Pending', class: 'badge-ghost', icon: '○' },
|
|
22
|
+
delivered: { label: 'Delivered', class: 'badge-info', icon: '◉' },
|
|
23
|
+
accepted: { label: 'Accepted', class: 'badge-warning', icon: '◉' },
|
|
24
|
+
paid: { label: 'Paid', class: 'badge-success', icon: '●' }
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const config = $derived(statusConfig[milestone.status])
|
|
28
|
+
|
|
29
|
+
function formatCurrency(amount: number) {
|
|
30
|
+
return new Intl.NumberFormat('en-US', { style: 'currency', currency }).format(amount)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function formatDate(dateStr: string | null) {
|
|
34
|
+
if (!dateStr) return null
|
|
35
|
+
return new Date(dateStr).toLocaleDateString('en-US', {
|
|
36
|
+
month: 'short',
|
|
37
|
+
day: 'numeric',
|
|
38
|
+
year: 'numeric'
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
</script>
|
|
42
|
+
|
|
43
|
+
<div
|
|
44
|
+
class="card bg-base-100 border border-base-300 {isCurrent
|
|
45
|
+
? 'ring-2 ring-primary/50'
|
|
46
|
+
: ''}"
|
|
47
|
+
>
|
|
48
|
+
<div class="card-body p-4 gap-2">
|
|
49
|
+
<div class="flex items-start justify-between gap-2">
|
|
50
|
+
<div class="flex-1 min-w-0">
|
|
51
|
+
<h4 class="font-semibold text-base-content text-sm">{milestone.name}</h4>
|
|
52
|
+
{#if milestone.description}
|
|
53
|
+
<p class="text-xs text-base-content/60 mt-0.5">{milestone.description}</p>
|
|
54
|
+
{/if}
|
|
55
|
+
</div>
|
|
56
|
+
<div class="flex items-center gap-2 flex-shrink-0">
|
|
57
|
+
<span class="font-semibold text-sm">{formatCurrency(milestone.amount)}</span>
|
|
58
|
+
<span class="badge badge-sm {config.class}">{config.icon} {config.label}</span>
|
|
59
|
+
</div>
|
|
60
|
+
</div>
|
|
61
|
+
|
|
62
|
+
{#if milestone.acceptance_criteria}
|
|
63
|
+
<div class="text-xs text-base-content/50 mt-1">
|
|
64
|
+
<span class="font-medium">Acceptance:</span>
|
|
65
|
+
{milestone.acceptance_criteria}
|
|
66
|
+
</div>
|
|
67
|
+
{/if}
|
|
68
|
+
|
|
69
|
+
{#if tasks.length > 0}
|
|
70
|
+
<div class="flex flex-wrap gap-1 mt-2">
|
|
71
|
+
{#each tasks as task}
|
|
72
|
+
<span class="badge badge-xs badge-outline gap-1">
|
|
73
|
+
<span class="w-1.5 h-1.5 rounded-full {task.status === 'deployed' || task.status === 'accepted' || task.status === 'closed' ? 'bg-success' : task.status === 'in_progress' || task.status === 'submitted' ? 'bg-warning' : 'bg-base-300'}"></span>
|
|
74
|
+
{task.title}
|
|
75
|
+
</span>
|
|
76
|
+
{/each}
|
|
77
|
+
</div>
|
|
78
|
+
{/if}
|
|
79
|
+
|
|
80
|
+
<div class="flex items-center gap-3 text-xs text-base-content/40 mt-1">
|
|
81
|
+
<span>{milestone.percentage}% of total</span>
|
|
82
|
+
{#if milestone.delivered_at}
|
|
83
|
+
<span>Delivered {formatDate(milestone.delivered_at)}</span>
|
|
84
|
+
{/if}
|
|
85
|
+
{#if milestone.paid_at}
|
|
86
|
+
<span>Paid {formatDate(milestone.paid_at)}</span>
|
|
87
|
+
{/if}
|
|
88
|
+
</div>
|
|
89
|
+
|
|
90
|
+
{#if isCurrent && milestone.status === 'delivered' && onAcceptAndPay}
|
|
91
|
+
<div class="mt-2">
|
|
92
|
+
<button class="btn btn-primary btn-sm" onclick={() => onAcceptAndPay(milestone)}>
|
|
93
|
+
Accept & Pay {formatCurrency(milestone.amount)}
|
|
94
|
+
</button>
|
|
95
|
+
</div>
|
|
96
|
+
{/if}
|
|
97
|
+
</div>
|
|
98
|
+
</div>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Milestone } from '../types/milestone';
|
|
2
|
+
interface LinkedTask {
|
|
3
|
+
id: string;
|
|
4
|
+
title: string;
|
|
5
|
+
status: string;
|
|
6
|
+
}
|
|
7
|
+
interface Props {
|
|
8
|
+
milestone: Milestone;
|
|
9
|
+
tasks?: LinkedTask[];
|
|
10
|
+
isCurrent?: boolean;
|
|
11
|
+
currency?: string;
|
|
12
|
+
onAcceptAndPay?: (milestone: Milestone) => void;
|
|
13
|
+
}
|
|
14
|
+
declare const MilestoneCard: import("svelte").Component<Props, {}, "">;
|
|
15
|
+
type MilestoneCard = ReturnType<typeof MilestoneCard>;
|
|
16
|
+
export default MilestoneCard;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Milestone } from '../types/milestone'
|
|
3
|
+
import MilestoneCard from './MilestoneCard.svelte'
|
|
4
|
+
|
|
5
|
+
interface LinkedTask {
|
|
6
|
+
id: string
|
|
7
|
+
title: string
|
|
8
|
+
status: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface Props {
|
|
12
|
+
milestones: Milestone[]
|
|
13
|
+
linkedTasks?: Record<string, LinkedTask[]>
|
|
14
|
+
currency?: string
|
|
15
|
+
onAcceptAndPay?: (milestone: Milestone) => void
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
let { milestones, linkedTasks = {}, currency = 'USD', onAcceptAndPay }: Props = $props()
|
|
19
|
+
|
|
20
|
+
const sorted = $derived([...milestones].sort((a, b) => a.sort_order - b.sort_order))
|
|
21
|
+
|
|
22
|
+
const currentIndex = $derived(sorted.findIndex((m) => m.status !== 'paid'))
|
|
23
|
+
|
|
24
|
+
const paidCount = $derived(sorted.filter((m) => m.status === 'paid').length)
|
|
25
|
+
const totalAmount = $derived(sorted.reduce((sum, m) => sum + m.amount, 0))
|
|
26
|
+
const paidAmount = $derived(
|
|
27
|
+
sorted.filter((m) => m.status === 'paid').reduce((sum, m) => sum + m.amount, 0)
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
function formatCurrency(amount: number) {
|
|
31
|
+
return new Intl.NumberFormat('en-US', { style: 'currency', currency }).format(amount)
|
|
32
|
+
}
|
|
33
|
+
</script>
|
|
34
|
+
|
|
35
|
+
<div class="space-y-1">
|
|
36
|
+
<!-- Progress summary -->
|
|
37
|
+
<div class="flex items-center justify-between text-[0.9375rem] mb-4">
|
|
38
|
+
<span class="text-base-content/60">
|
|
39
|
+
{paidCount} of {sorted.length} milestones paid
|
|
40
|
+
</span>
|
|
41
|
+
<span class="font-semibold">
|
|
42
|
+
{formatCurrency(paidAmount)} / {formatCurrency(totalAmount)}
|
|
43
|
+
</span>
|
|
44
|
+
</div>
|
|
45
|
+
|
|
46
|
+
<!-- Progress bar -->
|
|
47
|
+
{#if totalAmount > 0}
|
|
48
|
+
<div class="w-full bg-base-300 rounded-full h-2 mb-6">
|
|
49
|
+
<div
|
|
50
|
+
class="bg-success h-2 rounded-full transition-all duration-500"
|
|
51
|
+
style="width: {(paidAmount / totalAmount) * 100}%"
|
|
52
|
+
></div>
|
|
53
|
+
</div>
|
|
54
|
+
{/if}
|
|
55
|
+
|
|
56
|
+
<!-- Timeline -->
|
|
57
|
+
<div class="relative">
|
|
58
|
+
{#each sorted as milestone, i (milestone.id)}
|
|
59
|
+
<div class="flex gap-4">
|
|
60
|
+
<!-- Timeline connector -->
|
|
61
|
+
<div class="flex flex-col items-center w-6 flex-shrink-0">
|
|
62
|
+
<div
|
|
63
|
+
class="w-3 h-3 rounded-full border-2 {milestone.status === 'paid'
|
|
64
|
+
? 'bg-success border-success'
|
|
65
|
+
: i === currentIndex
|
|
66
|
+
? 'bg-primary border-primary'
|
|
67
|
+
: 'bg-base-300 border-base-300'}"
|
|
68
|
+
></div>
|
|
69
|
+
{#if i < sorted.length - 1}
|
|
70
|
+
<div
|
|
71
|
+
class="w-0.5 flex-1 min-h-4 {milestone.status === 'paid'
|
|
72
|
+
? 'bg-success/50'
|
|
73
|
+
: 'bg-base-300'}"
|
|
74
|
+
></div>
|
|
75
|
+
{/if}
|
|
76
|
+
</div>
|
|
77
|
+
|
|
78
|
+
<!-- Card -->
|
|
79
|
+
<div class="flex-1 pb-4">
|
|
80
|
+
<MilestoneCard
|
|
81
|
+
{milestone}
|
|
82
|
+
tasks={linkedTasks[milestone.id] || []}
|
|
83
|
+
isCurrent={i === currentIndex}
|
|
84
|
+
{currency}
|
|
85
|
+
{onAcceptAndPay}
|
|
86
|
+
/>
|
|
87
|
+
</div>
|
|
88
|
+
</div>
|
|
89
|
+
{/each}
|
|
90
|
+
</div>
|
|
91
|
+
</div>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Milestone } from '../types/milestone';
|
|
2
|
+
interface LinkedTask {
|
|
3
|
+
id: string;
|
|
4
|
+
title: string;
|
|
5
|
+
status: string;
|
|
6
|
+
}
|
|
7
|
+
interface Props {
|
|
8
|
+
milestones: Milestone[];
|
|
9
|
+
linkedTasks?: Record<string, LinkedTask[]>;
|
|
10
|
+
currency?: string;
|
|
11
|
+
onAcceptAndPay?: (milestone: Milestone) => void;
|
|
12
|
+
}
|
|
13
|
+
declare const MilestoneTimeline: import("svelte").Component<Props, {}, "">;
|
|
14
|
+
type MilestoneTimeline = ReturnType<typeof MilestoneTimeline>;
|
|
15
|
+
export default MilestoneTimeline;
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* Modal Component
|
|
4
|
+
*
|
|
5
|
+
* Overlay dialog with focus trap, backdrop click, escape key, and body scroll lock.
|
|
6
|
+
* Converted from Svelte 4 to Svelte 5 runes.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { onMount } from 'svelte';
|
|
10
|
+
import { fly, fade } from 'svelte/transition';
|
|
11
|
+
import { cubicOut } from 'svelte/easing';
|
|
12
|
+
|
|
13
|
+
interface Props {
|
|
14
|
+
open?: boolean;
|
|
15
|
+
title?: string;
|
|
16
|
+
size?: 'sm' | 'md' | 'lg' | 'xl' | 'full';
|
|
17
|
+
showCloseButton?: boolean;
|
|
18
|
+
closeOnBackdrop?: boolean;
|
|
19
|
+
closeOnEscape?: boolean;
|
|
20
|
+
showHeader?: boolean;
|
|
21
|
+
showFooter?: boolean;
|
|
22
|
+
class?: string;
|
|
23
|
+
contentClass?: string;
|
|
24
|
+
ariaLabel?: string;
|
|
25
|
+
dismissible?: boolean;
|
|
26
|
+
zIndex?: number;
|
|
27
|
+
/**
|
|
28
|
+
* When true (default), keydown events fired inside the modal are stopped
|
|
29
|
+
* from propagating to window — preventing page-level list/keyboard
|
|
30
|
+
* navigation handlers (listNav-style) from receiving arrow keys, j/k,
|
|
31
|
+
* vim chords, digit counts, etc. while the modal is open.
|
|
32
|
+
*
|
|
33
|
+
* Free-text fields (INPUT, TEXTAREA, contentEditable) are intentionally
|
|
34
|
+
* excluded so normal typing still works. Set to false only when the
|
|
35
|
+
* consumer needs custom window-level key handling even while the modal
|
|
36
|
+
* is open.
|
|
37
|
+
*/
|
|
38
|
+
trapKeys?: boolean;
|
|
39
|
+
onclose?: () => void;
|
|
40
|
+
onopen?: () => void;
|
|
41
|
+
header?: import('svelte').Snippet;
|
|
42
|
+
footer?: import('svelte').Snippet;
|
|
43
|
+
children?: import('svelte').Snippet;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
let {
|
|
47
|
+
open = $bindable(false),
|
|
48
|
+
title = '',
|
|
49
|
+
size = 'md',
|
|
50
|
+
showCloseButton = true,
|
|
51
|
+
closeOnBackdrop = true,
|
|
52
|
+
closeOnEscape = true,
|
|
53
|
+
showHeader = true,
|
|
54
|
+
showFooter = false,
|
|
55
|
+
class: className = '',
|
|
56
|
+
contentClass = '',
|
|
57
|
+
ariaLabel = '',
|
|
58
|
+
dismissible = true,
|
|
59
|
+
zIndex = 1000,
|
|
60
|
+
trapKeys = true,
|
|
61
|
+
onclose,
|
|
62
|
+
onopen,
|
|
63
|
+
header,
|
|
64
|
+
footer,
|
|
65
|
+
children
|
|
66
|
+
}: Props = $props();
|
|
67
|
+
|
|
68
|
+
let modalElement: HTMLDialogElement | undefined = $state();
|
|
69
|
+
let previousFocus: HTMLElement | null = null;
|
|
70
|
+
|
|
71
|
+
// Respect prefers-reduced-motion: skip the entrance/exit transitions.
|
|
72
|
+
const reducedMotion =
|
|
73
|
+
typeof window !== 'undefined' &&
|
|
74
|
+
window.matchMedia?.('(prefers-reduced-motion: reduce)').matches;
|
|
75
|
+
|
|
76
|
+
const sizeClass = $derived(
|
|
77
|
+
{ sm: 'max-w-sm', md: 'max-w-md', lg: 'max-w-lg', xl: 'max-w-xl', full: 'max-w-full h-full' }[size]
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
const modalClass = $derived(['modal', open ? 'modal-open' : '', className].filter(Boolean).join(' '));
|
|
81
|
+
|
|
82
|
+
const contentClasses = $derived(
|
|
83
|
+
[
|
|
84
|
+
'modal-box relative bg-base-100 text-base-content',
|
|
85
|
+
sizeClass,
|
|
86
|
+
size === 'full' ? 'h-full rounded-none' : '',
|
|
87
|
+
contentClass
|
|
88
|
+
]
|
|
89
|
+
.filter(Boolean)
|
|
90
|
+
.join(' ')
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
$effect(() => {
|
|
94
|
+
if (typeof document === 'undefined') return;
|
|
95
|
+
if (open) {
|
|
96
|
+
previousFocus = document.activeElement as HTMLElement;
|
|
97
|
+
document.body.style.overflow = 'hidden';
|
|
98
|
+
requestAnimationFrame(() => modalElement?.focus());
|
|
99
|
+
onopen?.();
|
|
100
|
+
} else {
|
|
101
|
+
document.body.style.overflow = '';
|
|
102
|
+
previousFocus?.focus();
|
|
103
|
+
previousFocus = null;
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
function close() {
|
|
108
|
+
if (dismissible) {
|
|
109
|
+
open = false;
|
|
110
|
+
onclose?.();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function handleBackdropClick(event: Event) {
|
|
115
|
+
if (closeOnBackdrop && event.target === event.currentTarget) {
|
|
116
|
+
close();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function handleKeyDown(event: KeyboardEvent) {
|
|
121
|
+
// Stop keydown events from bubbling to window while the modal is open.
|
|
122
|
+
// This prevents page-level keyboard navigation (listNav-style handlers
|
|
123
|
+
// on window) from reacting to arrow keys, j/k, vim chords, digit counts,
|
|
124
|
+
// etc. typed inside the modal.
|
|
125
|
+
//
|
|
126
|
+
// Free-text fields are excluded: page-level handlers already ignore them,
|
|
127
|
+
// and we must not interfere with normal typing or textarea shortcuts.
|
|
128
|
+
if (trapKeys) {
|
|
129
|
+
const el = document.activeElement as HTMLElement | null;
|
|
130
|
+
const tag = el?.tagName;
|
|
131
|
+
const isTextField =
|
|
132
|
+
!!el && (tag === 'INPUT' || tag === 'TEXTAREA' || el.isContentEditable === true);
|
|
133
|
+
if (!isTextField) event.stopPropagation();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (event.key === 'Tab') {
|
|
137
|
+
trapFocus(event);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function handleWindowKeyDown(event: KeyboardEvent) {
|
|
142
|
+
if (open && event.key === 'Escape' && closeOnEscape) {
|
|
143
|
+
event.preventDefault();
|
|
144
|
+
event.stopImmediatePropagation();
|
|
145
|
+
close();
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function trapFocus(event: KeyboardEvent) {
|
|
150
|
+
if (!modalElement) return;
|
|
151
|
+
const focusableElements = modalElement.querySelectorAll(
|
|
152
|
+
'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
|
|
153
|
+
);
|
|
154
|
+
const firstFocusable = focusableElements[0] as HTMLElement;
|
|
155
|
+
const lastFocusable = focusableElements[focusableElements.length - 1] as HTMLElement;
|
|
156
|
+
|
|
157
|
+
if (event.shiftKey) {
|
|
158
|
+
if (document.activeElement === firstFocusable) {
|
|
159
|
+
event.preventDefault();
|
|
160
|
+
lastFocusable.focus();
|
|
161
|
+
}
|
|
162
|
+
} else {
|
|
163
|
+
if (document.activeElement === lastFocusable) {
|
|
164
|
+
event.preventDefault();
|
|
165
|
+
firstFocusable.focus();
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
onMount(() => {
|
|
171
|
+
return () => {
|
|
172
|
+
if (typeof document !== 'undefined') {
|
|
173
|
+
document.body.style.overflow = '';
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
});
|
|
177
|
+
</script>
|
|
178
|
+
|
|
179
|
+
<svelte:window onkeydown={handleWindowKeyDown} />
|
|
180
|
+
|
|
181
|
+
{#if open}
|
|
182
|
+
<!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
|
|
183
|
+
<dialog
|
|
184
|
+
bind:this={modalElement}
|
|
185
|
+
class={modalClass}
|
|
186
|
+
style="z-index: {zIndex}"
|
|
187
|
+
aria-modal="true"
|
|
188
|
+
aria-label={ariaLabel || title}
|
|
189
|
+
open
|
|
190
|
+
onkeydown={handleKeyDown}
|
|
191
|
+
tabindex="-1"
|
|
192
|
+
>
|
|
193
|
+
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
194
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
195
|
+
<div class="modal-backdrop" onclick={handleBackdropClick} transition:fade={{ duration: reducedMotion ? 0 : 200 }}>
|
|
196
|
+
<div class={contentClasses} in:fly={{ y: reducedMotion ? 0 : 12, duration: reducedMotion ? 0 : 220, easing: cubicOut }} out:fade={{ duration: reducedMotion ? 0 : 150 }}>
|
|
197
|
+
{#if showHeader && (title || showCloseButton || header)}
|
|
198
|
+
<div class="flex items-center justify-between mb-4">
|
|
199
|
+
{#if header}
|
|
200
|
+
{@render header()}
|
|
201
|
+
{:else if title}
|
|
202
|
+
<h2 class="text-lg font-semibold">{title}</h2>
|
|
203
|
+
{/if}
|
|
204
|
+
|
|
205
|
+
{#if showCloseButton && dismissible}
|
|
206
|
+
<button type="button" class="btn btn-sm btn-circle btn-ghost" onclick={close} aria-label="Close modal">
|
|
207
|
+
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
208
|
+
<path
|
|
209
|
+
stroke-linecap="round"
|
|
210
|
+
stroke-linejoin="round"
|
|
211
|
+
stroke-width="2"
|
|
212
|
+
d="M6 18L18 6M6 6l12 12"
|
|
213
|
+
/>
|
|
214
|
+
</svg>
|
|
215
|
+
</button>
|
|
216
|
+
{/if}
|
|
217
|
+
</div>
|
|
218
|
+
{/if}
|
|
219
|
+
|
|
220
|
+
<div class="modal-content">
|
|
221
|
+
{#if children}
|
|
222
|
+
{@render children()}
|
|
223
|
+
{/if}
|
|
224
|
+
</div>
|
|
225
|
+
|
|
226
|
+
{#if footer}
|
|
227
|
+
<div class="modal-action mt-6">
|
|
228
|
+
{@render footer()}
|
|
229
|
+
</div>
|
|
230
|
+
{/if}
|
|
231
|
+
</div>
|
|
232
|
+
</div>
|
|
233
|
+
</dialog>
|
|
234
|
+
{/if}
|
|
235
|
+
|
|
236
|
+
<style>
|
|
237
|
+
.modal-backdrop {
|
|
238
|
+
position: absolute;
|
|
239
|
+
inset: 0;
|
|
240
|
+
display: flex;
|
|
241
|
+
align-items: center;
|
|
242
|
+
justify-content: center;
|
|
243
|
+
}
|
|
244
|
+
</style>
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
interface Props {
|
|
2
|
+
open?: boolean;
|
|
3
|
+
title?: string;
|
|
4
|
+
size?: 'sm' | 'md' | 'lg' | 'xl' | 'full';
|
|
5
|
+
showCloseButton?: boolean;
|
|
6
|
+
closeOnBackdrop?: boolean;
|
|
7
|
+
closeOnEscape?: boolean;
|
|
8
|
+
showHeader?: boolean;
|
|
9
|
+
showFooter?: boolean;
|
|
10
|
+
class?: string;
|
|
11
|
+
contentClass?: string;
|
|
12
|
+
ariaLabel?: string;
|
|
13
|
+
dismissible?: boolean;
|
|
14
|
+
zIndex?: number;
|
|
15
|
+
/**
|
|
16
|
+
* When true (default), keydown events fired inside the modal are stopped
|
|
17
|
+
* from propagating to window — preventing page-level list/keyboard
|
|
18
|
+
* navigation handlers (listNav-style) from receiving arrow keys, j/k,
|
|
19
|
+
* vim chords, digit counts, etc. while the modal is open.
|
|
20
|
+
*
|
|
21
|
+
* Free-text fields (INPUT, TEXTAREA, contentEditable) are intentionally
|
|
22
|
+
* excluded so normal typing still works. Set to false only when the
|
|
23
|
+
* consumer needs custom window-level key handling even while the modal
|
|
24
|
+
* is open.
|
|
25
|
+
*/
|
|
26
|
+
trapKeys?: boolean;
|
|
27
|
+
onclose?: () => void;
|
|
28
|
+
onopen?: () => void;
|
|
29
|
+
header?: import('svelte').Snippet;
|
|
30
|
+
footer?: import('svelte').Snippet;
|
|
31
|
+
children?: import('svelte').Snippet;
|
|
32
|
+
}
|
|
33
|
+
declare const Modal: import("svelte").Component<Props, {}, "open">;
|
|
34
|
+
type Modal = ReturnType<typeof Modal>;
|
|
35
|
+
export default Modal;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onMount } from "svelte"
|
|
3
|
+
|
|
4
|
+
interface Props {
|
|
5
|
+
fileId: string
|
|
6
|
+
fileName?: string
|
|
7
|
+
pdfUrl?: string
|
|
8
|
+
class?: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
let { fileId, fileName = "document.pdf", class: className = "" }: Props = $props()
|
|
12
|
+
|
|
13
|
+
let pageCount = $state(0)
|
|
14
|
+
let currentPage = $state(1)
|
|
15
|
+
let loading = $state(true)
|
|
16
|
+
let pageLoading = $state(false)
|
|
17
|
+
let error = $state<string | null>(null)
|
|
18
|
+
let imgSrc = $state<string | null>(null)
|
|
19
|
+
|
|
20
|
+
onMount(async () => {
|
|
21
|
+
try {
|
|
22
|
+
const res = await fetch(`/api/files/${fileId}/pdf-info`)
|
|
23
|
+
if (!res.ok) throw new Error(`Failed to load PDF info: ${res.status}`)
|
|
24
|
+
const data = await res.json()
|
|
25
|
+
pageCount = data.pageCount ?? 1
|
|
26
|
+
} catch (err) {
|
|
27
|
+
error = err instanceof Error ? err.message : "Failed to load PDF"
|
|
28
|
+
} finally {
|
|
29
|
+
loading = false
|
|
30
|
+
}
|
|
31
|
+
if (!error) loadPage(1)
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
async function loadPage(page: number) {
|
|
35
|
+
pageLoading = true
|
|
36
|
+
imgSrc = null
|
|
37
|
+
try {
|
|
38
|
+
const res = await fetch(`/api/files/${fileId}/pdf-page/${page}?scale=2`)
|
|
39
|
+
if (!res.ok) throw new Error(`Failed to render page ${page}`)
|
|
40
|
+
const blob = await res.blob()
|
|
41
|
+
imgSrc = URL.createObjectURL(blob)
|
|
42
|
+
currentPage = page
|
|
43
|
+
} catch (err) {
|
|
44
|
+
error = err instanceof Error ? err.message : "Failed to load page"
|
|
45
|
+
} finally {
|
|
46
|
+
pageLoading = false
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function prevPage() {
|
|
51
|
+
if (currentPage > 1) loadPage(currentPage - 1)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function nextPage() {
|
|
55
|
+
if (currentPage < pageCount) loadPage(currentPage + 1)
|
|
56
|
+
}
|
|
57
|
+
</script>
|
|
58
|
+
|
|
59
|
+
<div class="flex flex-col h-full {className}">
|
|
60
|
+
{#if loading}
|
|
61
|
+
<div class="flex-1 flex items-center justify-center text-base-content/40 text-sm">
|
|
62
|
+
Loading PDF…
|
|
63
|
+
</div>
|
|
64
|
+
{:else if error}
|
|
65
|
+
<div class="flex-1 flex items-center justify-center">
|
|
66
|
+
<p class="text-error text-sm text-center px-4">{error}</p>
|
|
67
|
+
</div>
|
|
68
|
+
{:else}
|
|
69
|
+
<!-- Viewer area -->
|
|
70
|
+
<div class="flex-1 min-h-0 flex items-center justify-center bg-base-200/30 p-4 overflow-auto">
|
|
71
|
+
{#if pageLoading}
|
|
72
|
+
<div class="text-base-content/40 text-sm">Rendering page…</div>
|
|
73
|
+
{:else if imgSrc}
|
|
74
|
+
<img
|
|
75
|
+
src={imgSrc}
|
|
76
|
+
alt="Page {currentPage} of {fileName}"
|
|
77
|
+
class="max-w-full max-h-full object-contain shadow-md rounded"
|
|
78
|
+
/>
|
|
79
|
+
{/if}
|
|
80
|
+
</div>
|
|
81
|
+
|
|
82
|
+
<!-- Pagination controls -->
|
|
83
|
+
{#if pageCount > 1}
|
|
84
|
+
<div class="flex items-center justify-center gap-3 py-2 border-t border-base-300 text-sm">
|
|
85
|
+
<button
|
|
86
|
+
type="button"
|
|
87
|
+
class="btn btn-ghost btn-xs"
|
|
88
|
+
onclick={prevPage}
|
|
89
|
+
disabled={currentPage <= 1}
|
|
90
|
+
aria-label="Previous page"
|
|
91
|
+
>‹</button>
|
|
92
|
+
<span class="text-base-content/60 tabular-nums">
|
|
93
|
+
{currentPage} / {pageCount}
|
|
94
|
+
</span>
|
|
95
|
+
<button
|
|
96
|
+
type="button"
|
|
97
|
+
class="btn btn-ghost btn-xs"
|
|
98
|
+
onclick={nextPage}
|
|
99
|
+
disabled={currentPage >= pageCount}
|
|
100
|
+
aria-label="Next page"
|
|
101
|
+
>›</button>
|
|
102
|
+
</div>
|
|
103
|
+
{/if}
|
|
104
|
+
{/if}
|
|
105
|
+
</div>
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onMount } from "svelte"
|
|
3
|
+
|
|
4
|
+
interface Props {
|
|
5
|
+
/** URL or path to the PDF file */
|
|
6
|
+
src: string
|
|
7
|
+
/** CSS class for the container */
|
|
8
|
+
class?: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
let { src, class: className = "" }: Props = $props()
|
|
12
|
+
let canvas = $state<HTMLCanvasElement | null>(null)
|
|
13
|
+
let loading = $state(true)
|
|
14
|
+
let failed = $state(false)
|
|
15
|
+
|
|
16
|
+
onMount(async () => {
|
|
17
|
+
if (!canvas) return
|
|
18
|
+
try {
|
|
19
|
+
const pdfjsLib = await import("pdfjs-dist")
|
|
20
|
+
pdfjsLib.GlobalWorkerOptions.workerSrc = new URL(
|
|
21
|
+
"pdfjs-dist/build/pdf.worker.mjs",
|
|
22
|
+
import.meta.url,
|
|
23
|
+
).toString()
|
|
24
|
+
|
|
25
|
+
const response = await fetch(src)
|
|
26
|
+
const buffer = await response.arrayBuffer()
|
|
27
|
+
const pdf = await pdfjsLib.getDocument({ data: buffer }).promise
|
|
28
|
+
const page = await pdf.getPage(1)
|
|
29
|
+
|
|
30
|
+
const containerWidth = canvas.parentElement?.clientWidth || 300
|
|
31
|
+
const viewport = page.getViewport({ scale: 1 })
|
|
32
|
+
const scale = containerWidth / viewport.width
|
|
33
|
+
const scaled = page.getViewport({ scale })
|
|
34
|
+
|
|
35
|
+
canvas.width = scaled.width
|
|
36
|
+
canvas.height = scaled.height
|
|
37
|
+
|
|
38
|
+
await page.render({
|
|
39
|
+
canvasContext: canvas.getContext("2d")!,
|
|
40
|
+
canvas,
|
|
41
|
+
viewport: scaled,
|
|
42
|
+
}).promise
|
|
43
|
+
|
|
44
|
+
loading = false
|
|
45
|
+
} catch {
|
|
46
|
+
failed = true
|
|
47
|
+
loading = false
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
</script>
|
|
51
|
+
|
|
52
|
+
{#if failed}
|
|
53
|
+
<div class={className}>
|
|
54
|
+
<svg class="h-14 w-14 text-error/60" fill="currentColor" viewBox="0 0 24 24">
|
|
55
|
+
<path d="M14,2H6A2,2 0 0,0 4,4V20A2,2 0 0,0 6,22H18A2,2 0 0,0 20,20V8L14,2M18,20H6V4H13V9H18V20M10.92,12.31C10.68,11.54 10.15,9.08 11.55,9.04C12.95,9 12.03,12.16 12.03,12.16C12.42,13.65 14.05,14.72 14.05,14.72C14.55,14.57 17.4,14.24 17,15.72C16.57,17.2 13.5,15.81 13.5,15.81C11.55,15.95 10.09,16.47 10.09,16.47C8.96,18.58 7.64,19.5 7.1,18.61C6.43,17.5 9.23,16.07 9.23,16.07C10.68,13.67 10.92,12.31 10.92,12.31Z" />
|
|
56
|
+
</svg>
|
|
57
|
+
</div>
|
|
58
|
+
{:else}
|
|
59
|
+
{#if loading}
|
|
60
|
+
<span class="loading loading-spinner loading-sm text-base-content/30"></span>
|
|
61
|
+
{/if}
|
|
62
|
+
<canvas bind:this={canvas} class="w-full h-full object-cover {className}" class:hidden={loading}></canvas>
|
|
63
|
+
{/if}
|