@sandemo/easy-annotator 0.1.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.
Files changed (49) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +59 -0
  3. package/dist/components/AnnotatorModal.d.ts +13 -0
  4. package/dist/components/AnnotatorModal.d.ts.map +1 -0
  5. package/dist/components/EasyAnnotatorUpload.d.ts +3 -0
  6. package/dist/components/EasyAnnotatorUpload.d.ts.map +1 -0
  7. package/dist/components/FilePreviewList.d.ts +10 -0
  8. package/dist/components/FilePreviewList.d.ts.map +1 -0
  9. package/dist/components/ImageAnnotator.d.ts +17 -0
  10. package/dist/components/ImageAnnotator.d.ts.map +1 -0
  11. package/dist/components/UploadDropzone.d.ts +10 -0
  12. package/dist/components/UploadDropzone.d.ts.map +1 -0
  13. package/dist/easy-annotator.cjs +2 -0
  14. package/dist/easy-annotator.cjs.map +1 -0
  15. package/dist/easy-annotator.css +1 -0
  16. package/dist/easy-annotator.d.ts +2 -0
  17. package/dist/easy-annotator.js +709 -0
  18. package/dist/easy-annotator.js.map +1 -0
  19. package/dist/hooks/useEasyAnnotator.d.ts +29 -0
  20. package/dist/hooks/useEasyAnnotator.d.ts.map +1 -0
  21. package/dist/hooks/useObjectUrls.d.ts +5 -0
  22. package/dist/hooks/useObjectUrls.d.ts.map +1 -0
  23. package/dist/i18n/labels.d.ts +5 -0
  24. package/dist/i18n/labels.d.ts.map +1 -0
  25. package/dist/index.d.ts +12 -0
  26. package/dist/index.d.ts.map +1 -0
  27. package/dist/markerjs3-DI_cywfl.js +2669 -0
  28. package/dist/markerjs3-DI_cywfl.js.map +1 -0
  29. package/dist/markerjs3-DiaiYpgs.cjs +57 -0
  30. package/dist/markerjs3-DiaiYpgs.cjs.map +1 -0
  31. package/dist/services/defaultPayloadBuilder.d.ts +3 -0
  32. package/dist/services/defaultPayloadBuilder.d.ts.map +1 -0
  33. package/dist/styles.cjs +2 -0
  34. package/dist/styles.cjs.map +1 -0
  35. package/dist/styles.d.ts +1 -0
  36. package/dist/styles.d.ts.map +1 -0
  37. package/dist/styles.js +2 -0
  38. package/dist/styles.js.map +1 -0
  39. package/dist/types/index.d.ts +95 -0
  40. package/dist/types/index.d.ts.map +1 -0
  41. package/dist/utils/errors.d.ts +8 -0
  42. package/dist/utils/errors.d.ts.map +1 -0
  43. package/dist/utils/file.d.ts +10 -0
  44. package/dist/utils/file.d.ts.map +1 -0
  45. package/dist/utils/id.d.ts +2 -0
  46. package/dist/utils/id.d.ts.map +1 -0
  47. package/dist/utils/image.d.ts +3 -0
  48. package/dist/utils/image.d.ts.map +1 -0
  49. package/package.json +72 -0
@@ -0,0 +1,3 @@
1
+ import { EasyAnnotatorUploadPayload } from '../types';
2
+ export declare function buildFormDataPayload(payload: EasyAnnotatorUploadPayload): FormData;
3
+ //# sourceMappingURL=defaultPayloadBuilder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaultPayloadBuilder.d.ts","sourceRoot":"","sources":["../../src/services/defaultPayloadBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,UAAU,CAAA;AAE1D,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,0BAA0B,GAAG,QAAQ,CAgBlF"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=styles.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"styles.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=styles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../src/styles.ts"],"names":[],"mappings":"AAGA,OAAO,6BAA6B,CAAA"}
package/dist/styles.js ADDED
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=styles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"styles.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,95 @@
1
+ export type EasyAnnotatorFileType = 'image' | 'pdf' | 'doc' | 'docx';
2
+ export type EasyAnnotatorStatus = 'idle' | 'uploading' | 'done' | 'error';
3
+ export interface EasyAnnotatorFile {
4
+ id: string;
5
+ originalFile: File;
6
+ fileType: EasyAnnotatorFileType;
7
+ mimeType: string;
8
+ originalFilename: string;
9
+ previewUrl?: string;
10
+ annotatedFile?: File;
11
+ annotatedPreviewUrl?: string;
12
+ annotationState?: object;
13
+ status: EasyAnnotatorStatus;
14
+ errorMessage?: string;
15
+ }
16
+ export interface EasyAnnotatorUploadPayload {
17
+ ownerType: string;
18
+ ownerId: string | number;
19
+ fieldKey: string;
20
+ originalFile: File;
21
+ annotatedFile?: File;
22
+ annotationState?: object;
23
+ fileType: EasyAnnotatorFileType;
24
+ mimeType: string;
25
+ originalFilename: string;
26
+ }
27
+ export interface EasyAnnotatorUploadedResult {
28
+ id: string;
29
+ url?: string;
30
+ annotatedUrl?: string;
31
+ fileType: EasyAnnotatorFileType;
32
+ meta?: Record<string, unknown>;
33
+ }
34
+ export type EasyAnnotatorUploadHandler = (payload: EasyAnnotatorUploadPayload) => Promise<EasyAnnotatorUploadedResult>;
35
+ export type EasyAnnotatorErrorCode = 'FILE_TYPE_REJECTED' | 'FILE_TOO_LARGE' | 'FILE_COUNT_EXCEEDED' | 'ANNOTATION_FAILED' | 'UPLOAD_FAILED';
36
+ export type EasyAnnotatorError = {
37
+ code: 'FILE_TYPE_REJECTED';
38
+ file: File;
39
+ reason: string;
40
+ } | {
41
+ code: 'FILE_TOO_LARGE';
42
+ file: File;
43
+ maxBytes: number;
44
+ } | {
45
+ code: 'FILE_COUNT_EXCEEDED';
46
+ maxFiles: number;
47
+ } | {
48
+ code: 'ANNOTATION_FAILED';
49
+ cause?: unknown;
50
+ } | {
51
+ code: 'UPLOAD_FAILED';
52
+ cause?: unknown;
53
+ file: EasyAnnotatorFile;
54
+ };
55
+ export interface LabelOverrides {
56
+ title: string;
57
+ dropzoneText: string;
58
+ dropzoneButton: string;
59
+ annotate: string;
60
+ remove: string;
61
+ upload: string;
62
+ uploading: string;
63
+ uploaded: string;
64
+ retry: string;
65
+ cancel: string;
66
+ save: string;
67
+ errorFileType: (filename: string) => string;
68
+ errorFileTooLarge: (filename: string, maxMb: number) => string;
69
+ errorFileCount: (max: number) => string;
70
+ errorAnnotationFailed: string;
71
+ errorUploadFailed: string;
72
+ modalTitle: string;
73
+ loadingAnnotator: string;
74
+ filesSelected: (count: number) => string;
75
+ }
76
+ export interface EasyAnnotatorConfig {
77
+ accept?: string[];
78
+ maxFileSize?: number;
79
+ maxFiles?: number;
80
+ multiple?: boolean;
81
+ }
82
+ export interface EasyAnnotatorUploadProps extends EasyAnnotatorConfig {
83
+ title?: string;
84
+ ownerType: string;
85
+ ownerId: string | number;
86
+ fieldKey: string;
87
+ uploadHandler: EasyAnnotatorUploadHandler;
88
+ onUploaded?: (items: EasyAnnotatorUploadedResult[]) => void;
89
+ onError?: (error: EasyAnnotatorError, file?: EasyAnnotatorFile) => void;
90
+ onChange?: (files: EasyAnnotatorFile[]) => void;
91
+ labels?: Partial<LabelOverrides>;
92
+ className?: string;
93
+ disabled?: boolean;
94
+ }
95
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,qBAAqB,GAAG,OAAO,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM,CAAA;AAEpE,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,GAAG,OAAO,CAAA;AAEzE,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAA;IACV,YAAY,EAAE,IAAI,CAAA;IAClB,QAAQ,EAAE,qBAAqB,CAAA;IAC/B,QAAQ,EAAE,MAAM,CAAA;IAChB,gBAAgB,EAAE,MAAM,CAAA;IACxB,UAAU,CAA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,SAAQ,mBAAmB;IACnE,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,MAAM,GAAG,MAAM,CAAA;IACxB,QAAQ,EAAE,MAAM,CAAA;IAChB,aAAa,EAAE,0BAA0B,CAAA;IACzC,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,2BAA2B,EAAE,KAAK,IAAI,CAAA;IAC3D,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,kBAAkB,EAAE,IAAI,CAAC,EAAE,iBAAiB,KAAK,IAAI,CAAA;IACvE,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,iBAAiB,EAAE,KAAK,IAAI,CAAA;IAC/C,MAAM,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAA;IAChC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB"}
@@ -0,0 +1,8 @@
1
+ import { EasyAnnotatorError, EasyAnnotatorFile } from '../types';
2
+ export declare function fileTypeRejected(file: File, reason: string): EasyAnnotatorError;
3
+ export declare function fileTooLarge(file: File, maxBytes: number): EasyAnnotatorError;
4
+ export declare function fileCountExceeded(maxFiles: number): EasyAnnotatorError;
5
+ export declare function annotationFailed(cause?: unknown): EasyAnnotatorError;
6
+ export declare function uploadFailed(file: EasyAnnotatorFile, cause?: unknown): EasyAnnotatorError;
7
+ export declare function devWarn(...args: unknown[]): void;
8
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAErE,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,kBAAkB,CAE/E;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,kBAAkB,CAE7E;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,kBAAkB,CAEtE;AAED,wBAAgB,gBAAgB,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,kBAAkB,CAEpE;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,iBAAiB,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,kBAAkB,CAEzF;AAID,wBAAgB,OAAO,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAShD"}
@@ -0,0 +1,10 @@
1
+ import { EasyAnnotatorFileType } from '../types';
2
+ export declare const DEFAULT_ACCEPT: string[];
3
+ export declare const DEFAULT_MAX_FILE_SIZE: number;
4
+ export declare const DEFAULT_MAX_FILES = 5;
5
+ export declare function isImageMime(mime: string): boolean;
6
+ export declare function classifyFile(file: File): EasyAnnotatorFileType;
7
+ export declare function isAccepted(file: File, accept: string[]): boolean;
8
+ export declare function bytesToMb(bytes: number): number;
9
+ export declare function withAnnotatedFilename(originalName: string): string;
10
+ //# sourceMappingURL=file.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../src/utils/file.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAA;AAErD,eAAO,MAAM,cAAc,EAAE,MAAM,EAQlC,CAAA;AAED,eAAO,MAAM,qBAAqB,QAAmB,CAAA;AACrD,eAAO,MAAM,iBAAiB,IAAI,CAAA;AAIlC,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEjD;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,GAAG,qBAAqB,CAiB9D;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAgBhE;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED,wBAAgB,qBAAqB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAKlE"}
@@ -0,0 +1,2 @@
1
+ export declare function createId(): string;
2
+ //# sourceMappingURL=id.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"id.d.ts","sourceRoot":"","sources":["../../src/utils/id.ts"],"names":[],"mappings":"AAAA,wBAAgB,QAAQ,IAAI,MAAM,CAKjC"}
@@ -0,0 +1,3 @@
1
+ export declare function canvasToFile(canvas: HTMLCanvasElement, filename: string, mime?: string, quality?: number): Promise<File>;
2
+ export declare function loadImageElement(src: string): Promise<HTMLImageElement>;
3
+ //# sourceMappingURL=image.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"image.d.ts","sourceRoot":"","sources":["../../src/utils/image.ts"],"names":[],"mappings":"AAAA,wBAAgB,YAAY,CAC1B,MAAM,EAAE,iBAAiB,EACzB,QAAQ,EAAE,MAAM,EAChB,IAAI,SAAc,EAClB,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC,CAcf;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAQvE"}
package/package.json ADDED
@@ -0,0 +1,72 @@
1
+ {
2
+ "name": "@sandemo/easy-annotator",
3
+ "version": "0.1.0",
4
+ "description": "Reusable React/Next.js image annotation + upload component. Backend-agnostic via uploadHandler.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "author": "Sandemo",
8
+ "keywords": [
9
+ "react",
10
+ "nextjs",
11
+ "image-annotation",
12
+ "markerjs",
13
+ "file-upload",
14
+ "annotation",
15
+ "typescript",
16
+ "upload"
17
+ ],
18
+ "homepage": "https://github.com/sandemoit/easy-annotator#readme",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/sandemoit/easy-annotator.git"
22
+ },
23
+ "bugs": {
24
+ "url": "https://github.com/sandemoit/easy-annotator/issues"
25
+ },
26
+ "sideEffects": [
27
+ "**/*.css"
28
+ ],
29
+ "files": [
30
+ "dist",
31
+ "README.md",
32
+ "LICENSE"
33
+ ],
34
+ "main": "./dist/easy-annotator.cjs",
35
+ "module": "./dist/easy-annotator.js",
36
+ "types": "./dist/index.d.ts",
37
+ "exports": {
38
+ ".": {
39
+ "types": "./dist/index.d.ts",
40
+ "import": "./dist/easy-annotator.js",
41
+ "require": "./dist/easy-annotator.cjs"
42
+ },
43
+ "./styles.css": "./dist/easy-annotator.css"
44
+ },
45
+ "scripts": {
46
+ "dev": "vite build --watch",
47
+ "build": "tsc --noEmit && vite build",
48
+ "typecheck": "tsc --noEmit",
49
+ "lint": "eslint src --ext .ts,.tsx"
50
+ },
51
+ "peerDependencies": {
52
+ "react": ">=18.0.0",
53
+ "react-dom": ">=18.0.0"
54
+ },
55
+ "dependencies": {
56
+ "@markerjs/markerjs3": "^3.4.0"
57
+ },
58
+ "devDependencies": {
59
+ "@types/react": "^18.3.0",
60
+ "@types/react-dom": "^18.3.0",
61
+ "@vitejs/plugin-react": "^4.3.0",
62
+ "react": "^18.3.0",
63
+ "react-dom": "^18.3.0",
64
+ "typescript": "^5.5.0",
65
+ "vite": "^5.4.0",
66
+ "vite-plugin-dts": "^4.0.0"
67
+ },
68
+ "publishConfig": {
69
+ "access": "public",
70
+ "registry": "https://registry.npmjs.org/"
71
+ }
72
+ }