@zzalai/leafer-point-annotation 1.0.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/LICENSE +21 -0
- package/README.md +308 -0
- package/README_EN.md +308 -0
- package/docs/assets/index-DGiYiG5f.css +1 -0
- package/docs/assets/index-L8gL3x2V.js +1 -0
- package/docs/index.html +14 -0
- package/index.html +13 -0
- package/package.json +64 -0
- package/project-docs/ARCHITECTURE.md +401 -0
- package/project-docs/IMPLEMENTATION_PLAN.md +196 -0
- package/project-docs/REQUIREMENTS.md +517 -0
- package/project-docs/TODO.md +167 -0
- package/project-docs/leafer-development-guide/LEAFER_DEVELOPMENT_GUIDE.md +835 -0
- package/project-docs/leafer-development-guide/LEAFER_UNDO_REDO_GUIDE.md +329 -0
- package/project-docs/leafer-development-guide/TINYKEYS_GUIDE.md +407 -0
- package/src/App.vue +464 -0
- package/src/components/BrushSizeSlider.vue +190 -0
- package/src/components/BrushStylePanel.vue +295 -0
- package/src/components/PointAnnotation.vue +1663 -0
- package/src/elements/PointAnnotationElement.ts +155 -0
- package/src/index.ts +4 -0
- package/src/main.ts +4 -0
- package/src/types/index.ts +122 -0
- package/src/utils/BrushCommands.ts +47 -0
- package/src/utils/BrushStroke.ts +96 -0
- package/src/utils/COCOExporter.ts +90 -0
- package/src/utils/CanvasBrush.ts +179 -0
- package/src/utils/PointCommands.ts +74 -0
- package/src/utils/YOLOExporter.ts +39 -0
- package/src/vite-env.d.ts +7 -0
- package/tsconfig.json +24 -0
- package/tsconfig.node.json +10 -0
- package/vite.config.ts +42 -0
- package/vite.docs.config.ts +28 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Group } from 'leafer-ui';
|
|
2
|
+
import { ICommand } from '@zzalai/leafer-undo-redo';
|
|
3
|
+
import type { PointAnnotation } from '@/types';
|
|
4
|
+
|
|
5
|
+
export interface PointAnnotationElement extends Group {
|
|
6
|
+
data: PointAnnotation;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class AddPointCommand implements ICommand {
|
|
10
|
+
private container: Group;
|
|
11
|
+
private element: PointAnnotationElement;
|
|
12
|
+
private dataArray: PointAnnotation[];
|
|
13
|
+
private pointData: PointAnnotation;
|
|
14
|
+
|
|
15
|
+
constructor(
|
|
16
|
+
container: Group,
|
|
17
|
+
element: PointAnnotationElement,
|
|
18
|
+
dataArray: PointAnnotation[],
|
|
19
|
+
pointData: PointAnnotation
|
|
20
|
+
) {
|
|
21
|
+
this.container = container;
|
|
22
|
+
this.element = element;
|
|
23
|
+
this.dataArray = dataArray;
|
|
24
|
+
this.pointData = pointData;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
execute(): void {
|
|
28
|
+
this.container.add(this.element);
|
|
29
|
+
this.dataArray.push(this.pointData);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
undo(): void {
|
|
33
|
+
this.container.remove(this.element);
|
|
34
|
+
const index = this.dataArray.findIndex(p => p.id === this.pointData.id);
|
|
35
|
+
if (index > -1) {
|
|
36
|
+
this.dataArray.splice(index, 1);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export class RemovePointCommand implements ICommand {
|
|
42
|
+
private container: Group;
|
|
43
|
+
private element: PointAnnotationElement;
|
|
44
|
+
private dataArray: PointAnnotation[];
|
|
45
|
+
private insertIndex: number;
|
|
46
|
+
|
|
47
|
+
constructor(
|
|
48
|
+
container: Group,
|
|
49
|
+
element: PointAnnotationElement,
|
|
50
|
+
dataArray: PointAnnotation[]
|
|
51
|
+
) {
|
|
52
|
+
this.container = container;
|
|
53
|
+
this.element = element;
|
|
54
|
+
this.dataArray = dataArray;
|
|
55
|
+
this.insertIndex = dataArray.findIndex(p => p.id === element.data.id);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
execute(): void {
|
|
59
|
+
this.container.remove(this.element);
|
|
60
|
+
const index = this.dataArray.findIndex(p => p.id === this.element.data.id);
|
|
61
|
+
if (index > -1) {
|
|
62
|
+
this.dataArray.splice(index, 1);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
undo(): void {
|
|
67
|
+
this.container.add(this.element);
|
|
68
|
+
if (this.insertIndex > -1 && this.insertIndex <= this.dataArray.length) {
|
|
69
|
+
this.dataArray.splice(this.insertIndex, 0, this.element.data);
|
|
70
|
+
} else {
|
|
71
|
+
this.dataArray.push(this.element.data);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { PointAnnotation } from '@/types';
|
|
2
|
+
|
|
3
|
+
export interface YOLOExportResult {
|
|
4
|
+
annotations: string;
|
|
5
|
+
classNames: string;
|
|
6
|
+
imageWidth: number;
|
|
7
|
+
imageHeight: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function exportYOLOFormat(
|
|
11
|
+
pointAnnotations: PointAnnotation[],
|
|
12
|
+
imageWidth: number,
|
|
13
|
+
imageHeight: number,
|
|
14
|
+
options?: {
|
|
15
|
+
className?: string;
|
|
16
|
+
pointSize?: number;
|
|
17
|
+
}
|
|
18
|
+
): YOLOExportResult {
|
|
19
|
+
const className = options?.className || 'point';
|
|
20
|
+
const pointSize = options?.pointSize || 20;
|
|
21
|
+
|
|
22
|
+
const classId = 0;
|
|
23
|
+
|
|
24
|
+
const annotationsLines = pointAnnotations.map(point => {
|
|
25
|
+
const xCenter = point.normalized.x;
|
|
26
|
+
const yCenter = point.normalized.y;
|
|
27
|
+
const width = pointSize / imageWidth;
|
|
28
|
+
const height = pointSize / imageHeight;
|
|
29
|
+
|
|
30
|
+
return `${classId} ${xCenter.toFixed(6)} ${yCenter.toFixed(6)} ${width.toFixed(6)} ${height.toFixed(6)}`;
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
annotations: annotationsLines.join('\n'),
|
|
35
|
+
classNames: className,
|
|
36
|
+
imageWidth,
|
|
37
|
+
imageHeight,
|
|
38
|
+
};
|
|
39
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"useDefineForClassFields": true,
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
|
7
|
+
"skipLibCheck": true,
|
|
8
|
+
"moduleResolution": "bundler",
|
|
9
|
+
"allowImportingTsExtensions": true,
|
|
10
|
+
"resolveJsonModule": true,
|
|
11
|
+
"isolatedModules": true,
|
|
12
|
+
"noEmit": true,
|
|
13
|
+
"jsx": "preserve",
|
|
14
|
+
"strict": true,
|
|
15
|
+
"noUnusedLocals": true,
|
|
16
|
+
"noUnusedParameters": true,
|
|
17
|
+
"noFallthroughCasesInSwitch": true,
|
|
18
|
+
"paths": {
|
|
19
|
+
"@/*": ["./src/*"]
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
|
|
23
|
+
"references": [{ "path": "./tsconfig.node.json" }]
|
|
24
|
+
}
|
package/vite.config.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { defineConfig } from 'vite'
|
|
2
|
+
import vue from '@vitejs/plugin-vue'
|
|
3
|
+
import dts from 'vite-plugin-dts'
|
|
4
|
+
import path from 'path'
|
|
5
|
+
|
|
6
|
+
export default defineConfig({
|
|
7
|
+
plugins: [
|
|
8
|
+
vue(),
|
|
9
|
+
process.env.NODE_ENV === 'production' ? dts() : null
|
|
10
|
+
].filter(Boolean),
|
|
11
|
+
resolve: {
|
|
12
|
+
alias: {
|
|
13
|
+
'@': path.resolve(__dirname, 'src')
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
build: {
|
|
17
|
+
lib: {
|
|
18
|
+
entry: './src/index.ts',
|
|
19
|
+
name: 'LeaferPointAnnotation',
|
|
20
|
+
formats: ['es', 'umd'],
|
|
21
|
+
fileName: (format) => `leafer-point-annotation.${format}.js`
|
|
22
|
+
},
|
|
23
|
+
rollupOptions: {
|
|
24
|
+
external: ['vue'],
|
|
25
|
+
output: {
|
|
26
|
+
globals: {
|
|
27
|
+
vue: 'Vue'
|
|
28
|
+
},
|
|
29
|
+
exports: "named"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
minify: 'terser',
|
|
33
|
+
terserOptions: {
|
|
34
|
+
compress: {
|
|
35
|
+
drop_console: true,
|
|
36
|
+
drop_debugger: true,
|
|
37
|
+
pure_funcs: ['console.log'],
|
|
38
|
+
passes: 1
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
})
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { defineConfig } from 'vite'
|
|
2
|
+
import vue from '@vitejs/plugin-vue'
|
|
3
|
+
import { resolve } from 'path'
|
|
4
|
+
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
plugins: [vue()],
|
|
7
|
+
base: './',
|
|
8
|
+
resolve: {
|
|
9
|
+
alias: {
|
|
10
|
+
'@': resolve(__dirname, './src')
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
build: {
|
|
14
|
+
outDir: 'docs',
|
|
15
|
+
assetsDir: 'assets',
|
|
16
|
+
minify: 'terser',
|
|
17
|
+
terserOptions: {
|
|
18
|
+
compress: {
|
|
19
|
+
drop_console: true,
|
|
20
|
+
drop_debugger: true
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
server: {
|
|
25
|
+
port: 3000,
|
|
26
|
+
open: true
|
|
27
|
+
}
|
|
28
|
+
})
|