page-annotation 0.1.0-alpha.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.
@@ -0,0 +1,5 @@
1
+ import type { AnnotationDocument, AnnotationItem } from "./types";
2
+ export declare function resizeCanvas(canvas: HTMLCanvasElement): number;
3
+ export declare function renderAnnotations(context: CanvasRenderingContext2D, annotations: AnnotationItem[] | AnnotationDocument, scale?: number): void;
4
+ export declare function renderAnnotation(context: CanvasRenderingContext2D, annotation: AnnotationItem): void;
5
+ //# sourceMappingURL=render.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAElE,wBAAgB,YAAY,CAAC,MAAM,EAAE,iBAAiB,GAAG,MAAM,CAS9D;AAED,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,wBAAwB,EACjC,WAAW,EAAE,cAAc,EAAE,GAAG,kBAAkB,EAClD,KAAK,SAAI,GACR,IAAI,CAQN;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,wBAAwB,EAAE,UAAU,EAAE,cAAc,GAAG,IAAI,CAqBpG"}
@@ -0,0 +1,23 @@
1
+ import type { AnnotationDocument, AnnotationItem } from "./types";
2
+ type StoreListener = () => void;
3
+ export declare class AnnotationStore {
4
+ private items;
5
+ private undoStack;
6
+ private redoStack;
7
+ private listeners;
8
+ subscribe(listener: StoreListener): () => void;
9
+ all(): AnnotationItem[];
10
+ add(annotation: AnnotationItem): void;
11
+ replaceAll(items: AnnotationItem[]): void;
12
+ removeById(id: string): boolean;
13
+ clear(): void;
14
+ undo(): void;
15
+ redo(): void;
16
+ canUndo(): boolean;
17
+ canRedo(): boolean;
18
+ toDocument(viewportWidth: number, viewportHeight: number): AnnotationDocument;
19
+ private captureUndoState;
20
+ private notify;
21
+ }
22
+ export {};
23
+ //# sourceMappingURL=store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAElE,KAAK,aAAa,GAAG,MAAM,IAAI,CAAC;AAEhC,qBAAa,eAAe;IAC1B,OAAO,CAAC,KAAK,CAAwB;IACrC,OAAO,CAAC,SAAS,CAA0B;IAC3C,OAAO,CAAC,SAAS,CAA0B;IAC3C,OAAO,CAAC,SAAS,CAA4B;IAE7C,SAAS,CAAC,QAAQ,EAAE,aAAa,GAAG,MAAM,IAAI;IAK9C,GAAG,IAAI,cAAc,EAAE;IAIvB,GAAG,CAAC,UAAU,EAAE,cAAc,GAAG,IAAI;IAOrC,UAAU,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,IAAI;IAOzC,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAY/B,KAAK,IAAI,IAAI;IAWb,IAAI,IAAI,IAAI;IAWZ,IAAI,IAAI,IAAI;IAWZ,OAAO,IAAI,OAAO;IAIlB,OAAO,IAAI,OAAO;IAIlB,UAAU,CAAC,aAAa,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,kBAAkB;IAS7E,OAAO,CAAC,gBAAgB;IAOxB,OAAO,CAAC,MAAM;CAGf"}
@@ -0,0 +1,137 @@
1
+ export type AnnotationTool = "pen" | "eraser" | "text" | "rectangle" | "arrow";
2
+ export type AnnotationPoint = {
3
+ x: number;
4
+ y: number;
5
+ };
6
+ export type PathAnnotation = {
7
+ id: string;
8
+ type: "path";
9
+ points: AnnotationPoint[];
10
+ color: string;
11
+ width: number;
12
+ };
13
+ export type RectangleAnnotation = {
14
+ id: string;
15
+ type: "rectangle";
16
+ x: number;
17
+ y: number;
18
+ width: number;
19
+ height: number;
20
+ color: string;
21
+ strokeWidth: number;
22
+ };
23
+ export type ArrowAnnotation = {
24
+ id: string;
25
+ type: "arrow";
26
+ start: AnnotationPoint;
27
+ end: AnnotationPoint;
28
+ color: string;
29
+ strokeWidth: number;
30
+ };
31
+ export type TextAnnotation = {
32
+ id: string;
33
+ type: "text";
34
+ x: number;
35
+ y: number;
36
+ text: string;
37
+ color: string;
38
+ fontSize: number;
39
+ };
40
+ export type AnnotationItem = PathAnnotation | RectangleAnnotation | ArrowAnnotation | TextAnnotation;
41
+ export type AnnotationDocument = {
42
+ version: 1;
43
+ viewportWidth: number;
44
+ viewportHeight: number;
45
+ items: AnnotationItem[];
46
+ };
47
+ export type AnnotationExport = {
48
+ png: Blob;
49
+ annotations: AnnotationDocument;
50
+ page: {
51
+ url: string;
52
+ title: string;
53
+ scrollX: number;
54
+ scrollY: number;
55
+ viewportWidth: number;
56
+ viewportHeight: number;
57
+ devicePixelRatio: number;
58
+ };
59
+ createdAt: string;
60
+ };
61
+ export type CaptureOptions = {
62
+ mode?: "dom";
63
+ backgroundColor?: string | null;
64
+ scale?: number;
65
+ ignoreSelectors?: string[];
66
+ sanitizeUnsupportedColors?: boolean;
67
+ };
68
+ export type PageAnnotatorLabels = {
69
+ launcher: string;
70
+ pen: string;
71
+ eraser: string;
72
+ text: string;
73
+ rectangle: string;
74
+ arrow: string;
75
+ undo: string;
76
+ redo: string;
77
+ clear: string;
78
+ moveToolbar: string;
79
+ copy: string;
80
+ download: string;
81
+ submit: string;
82
+ close: string;
83
+ addText: string;
84
+ cancelText: string;
85
+ color: string;
86
+ strokeWidth: string;
87
+ textPlaceholder: string;
88
+ };
89
+ export type PageAnnotatorOptions = {
90
+ target?: HTMLElement | string;
91
+ tools?: AnnotationTool[];
92
+ /**
93
+ * Controls how annotation mode is opened.
94
+ *
95
+ * - Omit or pass `false` to render no package-owned launcher and call `annotator.open()`
96
+ * from your own button, menu item, keyboard shortcut, or command palette.
97
+ * - Pass `true` to render the default floating launcher.
98
+ * - Pass an HTMLElement to bind annotation mode to an existing trigger.
99
+ * - Pass launcher options to render a configured floating launcher.
100
+ */
101
+ launcher?: boolean | HTMLElement | PageAnnotatorLauncherOptions;
102
+ capture?: CaptureOptions;
103
+ labels?: Partial<PageAnnotatorLabels>;
104
+ initialColor?: string;
105
+ initialStrokeWidth?: number;
106
+ onExport?: (result: AnnotationExport) => void | Promise<void>;
107
+ onError?: (error: unknown) => void;
108
+ };
109
+ export type PageAnnotatorLauncherOptions = {
110
+ container?: HTMLElement;
111
+ className?: string;
112
+ label?: string;
113
+ position?: PageAnnotatorLauncherPosition;
114
+ offset?: number | PageAnnotatorLauncherOffset;
115
+ };
116
+ export type PageAnnotatorLauncherPosition = "bottom-right" | "bottom-left" | "top-right" | "top-left";
117
+ export type PageAnnotatorLauncherOffset = {
118
+ x?: number;
119
+ y?: number;
120
+ };
121
+ export type PageAnnotator = {
122
+ open: () => void;
123
+ close: () => void;
124
+ destroy: () => void;
125
+ clear: () => void;
126
+ setTool: (tool: AnnotationTool) => void;
127
+ export: () => Promise<AnnotationExport>;
128
+ copyToClipboard: () => Promise<AnnotationExport>;
129
+ };
130
+ export type CapturedPage = {
131
+ canvas: HTMLCanvasElement;
132
+ };
133
+ export type CaptureProvider = (request: {
134
+ target: HTMLElement;
135
+ options: CaptureOptions;
136
+ }) => Promise<CapturedPage>;
137
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,WAAW,GAAG,OAAO,CAAC;AAE/E,MAAM,MAAM,eAAe,GAAG;IAC5B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,eAAe,EAAE,CAAC;IAC1B,KAAK,EAAE,MA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C3B,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,EAAE;IACtC,MAAM,EAAE,WAAW,CAAC;IACpB,OAAO,EAAE,cAAc,CAAC;CACzB,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "page-annotation",
3
+ "version": "0.1.0-alpha.0",
4
+ "description": "Framework-neutral browser page annotation tools for screenshot-backed feedback.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "author": "Taimoor Qureshi",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+ssh://git@github.com/taimoorq/page-annotation.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/taimoorq/page-annotation/issues"
14
+ },
15
+ "homepage": "https://github.com/taimoorq/page-annotation#readme",
16
+ "publishConfig": {
17
+ "access": "public",
18
+ "provenance": true
19
+ },
20
+ "sideEffects": [
21
+ "./dist/page-annotation.css",
22
+ "./src/styles.css"
23
+ ],
24
+ "main": "./dist/page-annotation.iife.js",
25
+ "module": "./dist/page-annotation.es.js",
26
+ "types": "./dist/index.d.ts",
27
+ "style": "./dist/page-annotation.css",
28
+ "exports": {
29
+ ".": {
30
+ "types": "./dist/index.d.ts",
31
+ "import": "./dist/page-annotation.es.js",
32
+ "default": "./dist/page-annotation.iife.js"
33
+ },
34
+ "./styles.css": "./dist/page-annotation.css"
35
+ },
36
+ "files": [
37
+ "dist",
38
+ "README.md",
39
+ "LICENSE"
40
+ ],
41
+ "scripts": {
42
+ "build": "npm run typecheck && vite build && tsc -p tsconfig.types.json",
43
+ "dev": "vite --host 127.0.0.1",
44
+ "preview": "vite preview --host 127.0.0.1",
45
+ "test": "vitest run",
46
+ "typecheck": "tsc -p tsconfig.json --noEmit"
47
+ },
48
+ "dependencies": {
49
+ "html2canvas": "^1.4.1"
50
+ },
51
+ "devDependencies": {
52
+ "jsdom": "^26.1.0",
53
+ "typescript": "^5.8.3",
54
+ "vite": "^7.0.0",
55
+ "vitest": "^3.2.0"
56
+ }
57
+ }