@linkurious/ogma-annotations 1.1.12 → 1.1.14

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/style.css CHANGED
@@ -1 +1 @@
1
- :root{--handle-width: 2px;--point-handle-width: calc(3 * var(--handle-width));--point-handle-border: 2px;--point-handle-total: calc( var(--point-handle-width) + var(--point-handle-border) );--handle-color: #38e}svg text{-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.handle{position:absolute;background-color:var(--handle-color)}.handle.line{cursor:move}.annotation-text-handle textarea{outline:none;margin:0;border:0;width:100%;height:100%;cursor:text;padding:0;z-index:1000;resize:none;white-space:break-spaces;background:transparent;overflow:hidden}.annotation-text-handle .noevents{pointer-events:none;z-index:20}.line-handle,.point-handle{z-index:30}.line-handle.top{cursor:ns-resize;height:var(--handle-width);left:0;width:100%;top:calc(var(--handle-width) * -1)}.line-handle.bottom{cursor:ns-resize;height:var(--handle-width);width:100%;left:0;bottom:calc(var(--handle-width) * -1)}.line-handle.left{cursor:ew-resize;height:100%;top:0;left:calc(var(--handle-width) * -1);width:var(--handle-width)}.line-handle.right{cursor:ew-resize;height:100%;right:calc(var(--handle-width) * -1);top:0;width:var(--handle-width)}.line-handle.top,.line-handle.bottom,.line-handle.left,.line-handle.right{cursor:move}.point-handle{border-radius:50%;background-color:#fff;transform-origin:center;transform:translate(-50%,-50%);border:var(--point-handle-border) solid var(--handle-color);width:var(--point-handle-width);height:var(--point-handle-width)}.point-handle.top-left{transform:translate(-75%,-75%)}.point-handle.top-right{transform:translate(-25%,-75%)}.point-handle.bottom-left{transform:translate(-75%,-25%)}.point-handle.bottom-right{transform:translate(-25%,-25%)}.point-handle.top-left,.point-handle.bottom-right{cursor:nwse-resize}.point-handle.top-right,.point-handle.bottom-left{cursor:nesw-resize}.point-handle.bottom-left,.point-handle.bottom-right{top:100%}.point-handle.top-left,.point-handle.top-right{top:0}.point-handle.bottom-left,.point-handle.top-left{left:0}.point-handle.bottom-right,.point-handle.top-right{left:100%}.arrow-handle>.handle{height:var(--point-handle-width);width:var(--point-handle-width);border-radius:50%;cursor:move;transform:translate(-50%,-50%)}.arrow-handle>.line{height:var(--handle-width);border-radius:0;cursor:move}.annotations-hidden-input{position:absolute;bottom:0;left:0;visibility:hidden;display:block}.active{background-color:#38e}.annotation-text{pointer-events:visible;cursor:pointer}.annotation-text:hover>rect{stroke:var(--handle-color)}.annotation-text a{fill:var(--handle-color)}.annotation-text a:hover{text-decoration:underline}
1
+ :root{--handle-width: 2px;--point-handle-width: calc(3 * var(--handle-width));--point-handle-border: 2px;--point-handle-total: calc( var(--point-handle-width) + var(--point-handle-border) );--handle-color: #38e;--handle-background: #fff}svg text{-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.handle{position:absolute;background-color:var(--handle-color)}.handle.line{cursor:move}.annotation-text-handle textarea{outline:none;margin:0;border:0;width:100%;height:100%;cursor:text;padding:0;z-index:1000;resize:none;white-space:break-spaces;background:transparent;overflow:hidden}.annotation-text-handle .noevents{pointer-events:none;z-index:20}.line-handle,.point-handle{z-index:30}.line-handle.top{cursor:ns-resize;height:var(--handle-width);left:0;width:100%;top:calc(var(--handle-width) * -1)}.line-handle.bottom{cursor:ns-resize;height:var(--handle-width);width:100%;left:0;bottom:calc(var(--handle-width) * -1)}.line-handle.left{cursor:ew-resize;height:100%;top:0;left:calc(var(--handle-width) * -1);width:var(--handle-width)}.line-handle.right{cursor:ew-resize;height:100%;right:calc(var(--handle-width) * -1);top:0;width:var(--handle-width)}.line-handle.top,.line-handle.bottom,.line-handle.left,.line-handle.right{cursor:move}.point-handle{border-radius:50%;background-color:#fff;transform-origin:center;transform:translate(-50%,-50%);border:var(--point-handle-border) solid var(--handle-color);width:var(--point-handle-width);height:var(--point-handle-width)}.point-handle.top-left{transform:translate(-55%,-55%)}.point-handle.top-right{transform:translate(-45%,-55%)}.point-handle.bottom-left{transform:translate(-55%,-45%)}.point-handle.bottom-right{transform:translate(-45%,-45%)}.point-handle.top-left,.point-handle.bottom-right{cursor:nwse-resize}.point-handle.top-right,.point-handle.bottom-left{cursor:nesw-resize}.point-handle.bottom-left,.point-handle.bottom-right{top:100%}.point-handle.top-left,.point-handle.top-right{top:0}.point-handle.bottom-left,.point-handle.top-left{left:0}.point-handle.bottom-right,.point-handle.top-right{left:100%}.arrow-handle>.handle{height:var(--point-handle-width);width:var(--point-handle-width);border-radius:50%;cursor:move;transform:translate(-50%,-50%)}.arrow-handle>.line{height:var(--handle-width);border-radius:0;cursor:move}.arrow-handle>.point{background-color:var(--handle-background);border:2px solid var(--handle-color)}.annotations-hidden-input{position:absolute;bottom:0;left:0;visibility:hidden;display:block}.active{background-color:#38e}.annotation-text{pointer-events:visible;cursor:pointer}.annotation-text:hover>rect{stroke:var(--handle-color)}.annotation-text a{fill:var(--handle-color)}.annotation-text a:hover{text-decoration:underline}
@@ -1,7 +1,7 @@
1
1
  import Ogma, { Point } from "@linkurious/ogma";
2
2
  import { createArrow, defaultOptions, defaultStyle } from "./defaults";
3
3
  import { Arrow, ControllerOptions } from "../../types";
4
- import Editor from "../base";
4
+ import { Editor } from "../base";
5
5
  /**
6
6
  * @class Arrows
7
7
  * Draw and edit arrows
@@ -1,4 +1,4 @@
1
- import { Arrow, ArrowStyles } from '../../types';
1
+ import { Arrow, ArrowStyles } from "../../types";
2
2
  /**
3
3
  * @function getArrowHeight
4
4
  * @param arrow The arrow to measure
@@ -1,7 +1,7 @@
1
1
  import Ogma, { Point } from "@linkurious/ogma";
2
2
  import { createText, defaultControllerOptions, defaultOptions, defaultStyle } from "./defaults";
3
3
  import { ControllerOptions, Id, Text } from "../../types";
4
- import Editor from "../base";
4
+ import { Editor } from "../base";
5
5
  /**
6
6
  * @class Texts
7
7
  * Draw, update, edit texts
@@ -6,7 +6,7 @@ import { Annotation, Events, Id } from "../types";
6
6
  * Abstract class to display Texts and Arrows, provide add/remove/update and mouse events
7
7
  * Modifying annotation is handled by the child classes, it is too specific
8
8
  */
9
- export default abstract class Editor<T extends Annotation> extends eventEmmitter<Events<T>> {
9
+ export declare abstract class Editor<T extends Annotation> extends eventEmmitter<Events<T>> {
10
10
  protected ogma: Ogma;
11
11
  protected elements: T[];
12
12
  protected layer: SVGLayer;
@@ -17,7 +17,6 @@ export default abstract class Editor<T extends Annotation> extends eventEmmitter
17
17
  protected shouldDetect: boolean;
18
18
  protected isDragging: boolean;
19
19
  protected showeditorOnHover: boolean;
20
- protected maxHandleScale: number;
21
20
  constructor(ogma: Ogma, editorHtml: string);
22
21
  private _onKeyUp;
23
22
  protected _canRemove(): boolean;
@@ -34,7 +33,7 @@ export default abstract class Editor<T extends Annotation> extends eventEmmitter
34
33
  * @method update
35
34
  * Updates an annotation (position, color etc)
36
35
  * @param id Id of the annotation to update
37
- * @param new params of the annotation
36
+ * @param element params of the annotation
38
37
  */
39
38
  update(id: Id, element: Partial<T>): void;
40
39
  updateAnnotation(target: T, element: Partial<T>): void;
@@ -1,5 +1,5 @@
1
- import { Point } from '@linkurious/ogma';
2
- import { Arrow, Id, TargetType, Link, Side } from './types';
1
+ import { Point } from "@linkurious/ogma";
2
+ import { Arrow, Id, TargetType, Link, Side } from "./types";
3
3
  /**
4
4
  * Class that implements linking between annotation arrows and different items.
5
5
  * An arrow can be connected to a text or to a node. It supports double indexing
@@ -1,10 +1,9 @@
1
- import { Point } from '@linkurious/ogma';
2
- import type { Feature, FeatureCollection, Geometry, GeometryObject, LineString, Polygon } from 'geojson';
3
- import { EVT_ADD, EVT_CANCEL_DRAWING, EVT_DRAG, EVT_DRAG_END, EVT_DRAG_START, EVT_HOVER, EVT_REMOVE, EVT_SELECT, EVT_UNHOVER, EVT_UNSELECT, EVT_UPDATE, EVT_LINK } from './constants';
1
+ import type { Feature, FeatureCollection, Geometry, GeometryObject, LineString, Polygon } from "geojson";
2
+ import { EVT_ADD, EVT_CANCEL_DRAWING, EVT_DRAG, EVT_DRAG_END, EVT_DRAG_START, EVT_HOVER, EVT_REMOVE, EVT_SELECT, EVT_UNHOVER, EVT_UNSELECT, EVT_UPDATE, EVT_LINK } from "./constants";
4
3
  export declare const isArrow: (a: AnnotationFeature<Geometry, AnnotationProps>) => a is Arrow;
5
4
  export declare const isText: (a: AnnotationFeature<Geometry, AnnotationProps>) => a is Text;
6
5
  export declare const isAnnotationCollection: (a: AnnotationFeature<Geometry, AnnotationProps> | FeatureCollection) => a is AnnotationCollection;
7
- type AnnotationType = 'arrow' | 'text';
6
+ type AnnotationType = "arrow" | "text";
8
7
  export interface AnnotationProps {
9
8
  type: AnnotationType;
10
9
  style?: unknown;
@@ -17,14 +16,18 @@ export interface ArrowStyles extends StrokeOptions {
17
16
  tail?: Extremity;
18
17
  head?: Extremity;
19
18
  }
19
+ export type Point = {
20
+ x: number;
21
+ y: number;
22
+ };
20
23
  type ExportedLink = {
21
24
  id: Id;
22
- side: 'start' | 'end';
23
- type: 'node' | 'text';
25
+ side: "start" | "end";
26
+ type: "node" | "text";
24
27
  magnet?: Point;
25
28
  };
26
29
  export interface ArrowProperties extends AnnotationProps {
27
- type: 'arrow';
30
+ type: "arrow";
28
31
  style?: ArrowStyles;
29
32
  link?: Partial<Record<Side, ExportedLink>>;
30
33
  }
@@ -33,7 +36,7 @@ export interface AnnotationCollection extends FeatureCollection {
33
36
  features: (Arrow | Text)[];
34
37
  }
35
38
  export type StrokeOptions = {
36
- strokeType?: 'plain' | 'dashed' | 'none';
39
+ strokeType?: "plain" | "dashed" | "none";
37
40
  strokeColor?: string;
38
41
  strokeWidth?: number;
39
42
  };
@@ -50,19 +53,19 @@ export interface TextStyle extends StrokeOptions {
50
53
  padding?: number;
51
54
  }
52
55
  export interface TextProperties extends AnnotationProps {
53
- type: 'text';
56
+ type: "text";
54
57
  /**text to display*/
55
58
  content: string;
56
59
  style?: TextStyle;
57
60
  }
58
61
  export type Text = AnnotationFeature<Polygon, TextProperties>;
59
62
  export type Stroke = {
60
- type: 'plain' | 'dashed' | 'none';
63
+ type: "plain" | "dashed" | "none";
61
64
  color: string;
62
65
  width: number;
63
66
  };
64
67
  export type StrokeStyle = Stroke;
65
- export type Extremity = 'none' | 'arrow' | 'arrow-plain';
68
+ export type Extremity = "none" | "arrow" | "arrow-plain";
66
69
  export type AnnotationOptions = {
67
70
  handleSize: number;
68
71
  placeholder: string;
@@ -73,7 +76,7 @@ export type Events<T> = {
73
76
  [EVT_SELECT]: (evt: T) => void;
74
77
  [EVT_UNSELECT]: (evt: T) => void;
75
78
  [EVT_DRAG_START]: (evt: T) => void;
76
- [EVT_DRAG]: (evt: T, key: 'line' | 'start' | 'end' | 'text') => void;
79
+ [EVT_DRAG]: (evt: T, key: "line" | "start" | "end" | "text") => void;
77
80
  [EVT_DRAG_END]: (evt: T) => void;
78
81
  [EVT_REMOVE]: (evt: T) => void;
79
82
  [EVT_ADD]: (evt: T) => void;
@@ -120,16 +123,16 @@ export type FeatureEvents = {
120
123
  /**
121
124
  * Event trigerred when dragging an arrow or a text
122
125
  */
123
- [EVT_DRAG]: (evt: Arrow | Text, key: 'line' | 'start' | 'end' | 'text') => void;
126
+ [EVT_DRAG]: (evt: Arrow | Text, key: "line" | "start" | "end" | "text") => void;
124
127
  /**
125
128
  * Event trigerred when stopped dragging an arrow or a text
126
129
  */
127
130
  [EVT_DRAG_END]: (evt: Arrow | Text) => void;
128
131
  };
129
- export type TargetType = 'text' | 'node';
130
- export type Side = 'start' | 'end';
132
+ export type TargetType = "text" | "node";
133
+ export type Side = "start" | "end";
131
134
  export type Link = {
132
- /** arrow atteched to the text or node */
135
+ /** arrow attached to the text or node */
133
136
  arrow: Id;
134
137
  /** id of the text the arrow is attached to */
135
138
  id: Id;
@@ -146,6 +149,9 @@ export type Link = {
146
149
  connectionPoint: Point;
147
150
  };
148
151
  export type ControllerOptions = {
152
+ /**
153
+ * The color of the magnet points
154
+ */
149
155
  magnetColor: string;
150
156
  /**
151
157
  * The radius in which arrows are attracted
@@ -181,4 +187,5 @@ export type ControllerOptions = {
181
187
  maxArrowHeight: number;
182
188
  };
183
189
  export type Annotation = Arrow | Text;
190
+ export type Vector = Point;
184
191
  export {};
@@ -0,0 +1,15 @@
1
+ import { Vector } from "./types";
2
+ export declare const subtract: (a: Vector, b: Vector) => Vector;
3
+ export declare const length: (v: Vector) => number;
4
+ export declare const invert: (v: Vector) => Vector;
5
+ export declare const clone: (v: Vector) => {
6
+ x: number;
7
+ y: number;
8
+ };
9
+ export declare const normalize: (v: Vector) => Vector;
10
+ export declare const add: (a: Vector, b: Vector) => Vector;
11
+ export declare const mul: (v: Vector, s: number) => Vector;
12
+ export declare const multiply: (a: Vector, b: Vector) => Vector;
13
+ export declare const rotateRadians: (v: Vector, angle: number) => Vector;
14
+ export declare const divScalar: (v: Vector, s: number) => Vector;
15
+ export declare const dot: (a: Vector, b: Vector) => number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@linkurious/ogma-annotations",
3
- "version": "1.1.12",
3
+ "version": "1.1.14",
4
4
  "description": "Headless annotation plugin for Ogma",
5
5
  "main": "dist/index.mjs",
6
6
  "module": "dist/index.mjs",
@@ -29,8 +29,8 @@
29
29
  "scripts": {
30
30
  "prepare": "playwright install",
31
31
  "start": "npm run dev",
32
- "dev": "vite -c web/vite.config.ts",
33
- "build:ui": "vite build -c vite.config-ui.ts",
32
+ "dev": "vite -c web/vite.config.mts",
33
+ "build:demo": "vite build -c web/vite.config.mts",
34
34
  "prebuild": "rm -rf dist",
35
35
  "bump:patch": "bump2version patch && npm version --no-git-tag-version patch",
36
36
  "bump:minor": "bump2version minor && npm version --no-git-tag-version minor",
@@ -40,7 +40,9 @@
40
40
  "lint": "eslint --ext ts --ext js src",
41
41
  "types": "tsc --d -emitDeclarationOnly --outDir dist/types",
42
42
  "preview": "vite preview",
43
- "docs:build": "typedoc --plugin typedoc-plugin-markdown --out ../../docs/annotations src/index.ts",
43
+ "docs:build": "typedoc --plugin typedoc-plugin-markdown --out ../../docs/api src/index.ts",
44
+ "postdocs:build": "npm run build:demo",
45
+ "test": "npm run test:unit",
44
46
  "test:unit": "vitest run -c test/unit/vitest.config.mts",
45
47
  "test:watch": "vitest watch -c test/unit/vitest.config.mts",
46
48
  "test:e2e": "vitest run -c test/e2e/vitest.config.mts",
@@ -64,28 +66,27 @@
64
66
  "author": "Linkurious SAS",
65
67
  "license": "Apache-2.0",
66
68
  "peerDependencies": {
67
- "@linkurious/ogma": ">=5.0.4"
69
+ "@linkurious/ogma": ">=4.5.6 || ^5.0.0"
68
70
  },
69
71
  "dependencies": {
70
72
  "@borgar/textbox": "1.6.0",
71
- "eventemitter3": "5.0.1",
72
- "vector2js": "2.0.1"
73
+ "eventemitter3": "5.0.1"
73
74
  },
74
75
  "devDependencies": {
75
76
  "@linkurious/eslint-config-ogma": "^1.0.9",
76
77
  "@types/geojson": "7946.0.13",
77
- "@types/vector2js": "2.0.2",
78
78
  "canvas": "2.11.2",
79
79
  "eslint": "8.56.0",
80
80
  "get-port": "7.0.0",
81
81
  "jsdom": "24.0.0",
82
82
  "playwright": "1.42.1",
83
+ "typedoc": "^0.25.13",
84
+ "typedoc-plugin-markdown": "^3.17.1",
83
85
  "typescript": "5.3.3",
84
86
  "vite": "5.2.0",
85
87
  "vitest": "1.4.0"
86
88
  },
87
89
  "eslintConfig": {
88
- "parser": "@typescript-eslint/parser",
89
90
  "extends": [
90
91
  "@linkurious/eslint-config-ogma"
91
92
  ]