Skip to content

Commit ac44db0

Browse files
authored
Merge pull request #509 from embedpdf/feature/annotation-comment
Feature/annotation comment
2 parents 74747be + 4cd672a commit ac44db0

46 files changed

Lines changed: 944 additions & 73 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@embedpdf/plugin-annotation': minor
3+
---
4+
5+
Implement noZoom and noRotate annotation flag rendering. Annotations with noZoom now maintain a constant screen-pixel size regardless of zoom level, and annotations with noRotate stay visually upright regardless of page rotation.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@embedpdf/plugin-annotation': minor
3+
---
4+
5+
Add Text (comment) annotation tool with handler, tool definition, and renderer support. thanks to @JoackimPennerup
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@embedpdf/snippet': minor
3+
---
4+
5+
Add comment annotation toolbar button with message icon, command, and UI schema entry.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@embedpdf/plugin-annotation': patch
3+
---
4+
5+
Fix group selection box outline when selected annotations use `noZoom` and/or `noRotate` flags. The multi-select group outline now correctly encloses mixed selections (flagged + normal annotations), including rotated pages and non-square noRotate annotations.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<script lang="ts">
2+
import type { SVGAttributes } from 'svelte/elements';
3+
4+
interface Props extends SVGAttributes<SVGSVGElement> {
5+
title?: string;
6+
}
7+
8+
let { class: className, title, ...rest }: Props = $props();
9+
</script>
10+
11+
<svg
12+
class={className}
13+
fill="none"
14+
stroke="currentColor"
15+
viewBox="0 0 24 24"
16+
stroke-width={2}
17+
stroke-linecap="round"
18+
stroke-linejoin="round"
19+
aria-hidden={!title}
20+
role={title ? 'img' : 'presentation'}
21+
{...rest}
22+
>
23+
{#if title}
24+
<title>{title}</title>
25+
{/if}
26+
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
27+
<path d="M8 9h8" />
28+
<path d="M8 13h6" />
29+
<path
30+
d="M18 4a3 3 0 0 1 3 3v8a3 3 0 0 1 -3 3h-5l-5 3v-3h-2a3 3 0 0 1 -3 -3v-8a3 3 0 0 1 3 -3h12"
31+
/>
32+
</svg>

examples/svelte-tailwind/src/lib/components/icons/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,4 @@ export { default as GroupIcon } from './GroupIcon.svelte';
6464
export { default as UngroupIcon } from './UngroupIcon.svelte';
6565
export { default as InsertTextIcon } from './InsertTextIcon.svelte';
6666
export { default as ReplaceTextIcon } from './ReplaceTextIcon.svelte';
67+
export { default as MessageIcon } from './MessageIcon.svelte';

examples/svelte-tailwind/src/lib/components/icons/registry.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ import GroupIcon from './GroupIcon.svelte';
6565
import UngroupIcon from './UngroupIcon.svelte';
6666
import InsertTextIcon from './InsertTextIcon.svelte';
6767
import ReplaceTextIcon from './ReplaceTextIcon.svelte';
68+
import MessageIcon from './MessageIcon.svelte';
6869

6970
// Define the standard Prop type for your icons for consistency
7071
export interface IconProps extends SVGAttributes<SVGSVGElement> {
@@ -136,6 +137,7 @@ export const iconRegistry = {
136137
ungroup: UngroupIcon,
137138
'insert-text': InsertTextIcon,
138139
'replace-text': ReplaceTextIcon,
140+
message: MessageIcon,
139141
} as const;
140142

141143
// Extract valid keys for Type Safety

examples/svelte-tailwind/src/lib/config/commands.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,34 @@ export const commands: Record<string, Command<State>> = {
791791
},
792792
},
793793

794+
'annotation:add-comment': {
795+
id: 'annotation:add-comment',
796+
labelKey: 'annotation.comment',
797+
icon: 'message',
798+
iconProps: ({ state }) => ({
799+
primaryColor: getToolDefaultsById(state.plugins.annotation, 'textComment')?.strokeColor,
800+
}),
801+
categories: ['annotation'],
802+
action: ({ registry, documentId }) => {
803+
const annotation = registry.getPlugin<AnnotationPlugin>(ANNOTATION_PLUGIN_ID)?.provides();
804+
const annotationScope = annotation?.forDocument(documentId);
805+
if (!annotationScope) return;
806+
807+
if (annotationScope.getActiveTool()?.id === 'textComment') {
808+
annotationScope.setActiveTool(null);
809+
} else {
810+
annotationScope.setActiveTool('textComment');
811+
}
812+
},
813+
active: ({ state, documentId }) => {
814+
const annotation = state.plugins[ANNOTATION_PLUGIN_ID]?.documents[documentId];
815+
return annotation?.activeToolId === 'textComment';
816+
},
817+
disabled: ({ state, documentId }) => {
818+
return lacksPermission(state, documentId, PdfPermissionFlag.ModifyAnnotations);
819+
},
820+
},
821+
794822
'annotation:add-highlight': {
795823
id: 'annotation:add-highlight',
796824
labelKey: 'annotation.highlight',

examples/svelte-tailwind/src/lib/config/ui-schema.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,12 @@ export const viewerUISchema: UISchema = {
296296
commandId: 'annotation:add-replace-text',
297297
variant: 'icon',
298298
},
299+
{
300+
type: 'command-button',
301+
id: 'add-comment',
302+
commandId: 'annotation:add-comment',
303+
variant: 'icon',
304+
},
299305
{
300306
type: 'command-button',
301307
id: 'add-stamp',
@@ -662,6 +668,11 @@ export const viewerUISchema: UISchema = {
662668
id: 'annotation:add-replace-text',
663669
commandId: 'annotation:add-replace-text',
664670
},
671+
{
672+
type: 'command',
673+
id: 'annotation:add-comment',
674+
commandId: 'annotation:add-comment',
675+
},
665676
{
666677
type: 'command',
667678
id: 'annotation:add-highlight',
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<script setup lang="ts">
2+
defineProps<{
3+
className?: string;
4+
title?: string;
5+
style?: Record<string, any>;
6+
}>();
7+
</script>
8+
9+
<template>
10+
<svg
11+
:class="className"
12+
:style="style"
13+
fill="none"
14+
stroke="currentColor"
15+
viewBox="0 0 24 24"
16+
:stroke-width="2"
17+
stroke-linecap="round"
18+
stroke-linejoin="round"
19+
:aria-hidden="!title"
20+
:role="title ? 'img' : 'presentation'"
21+
>
22+
<title v-if="title">{{ title }}</title>
23+
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
24+
<path d="M8 9h8" />
25+
<path d="M8 13h6" />
26+
<path
27+
d="M18 4a3 3 0 0 1 3 3v8a3 3 0 0 1 -3 3h-5l-5 3v-3h-2a3 3 0 0 1 -3 -3v-8a3 3 0 0 1 3 -3h12"
28+
/>
29+
</svg>
30+
</template>

0 commit comments

Comments
 (0)