@markerjs/markerjs3 3.6.2 → 3.6.4

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 CHANGED
@@ -1,25 +1,25 @@
1
- marker.js 3 Linkware License
2
-
3
- Copyright (c) 2024 Alan Mendelevich
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- 1. The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- 2. Link back to the Software website displayed during operation of the Software
16
- or an equivalent prominent public attribution must be retained. Alternative
17
- commercial licenses can be obtained to remove this clause.
18
-
19
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1
+ marker.js 3 Linkware License
2
+
3
+ Copyright (c) 2024 Alan Mendelevich
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ 1. The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ 2. Link back to the Software website displayed during operation of the Software
16
+ or an equivalent prominent public attribution must be retained. Alternative
17
+ commercial licenses can be obtained to remove this clause.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
25
  SOFTWARE.
package/README.md CHANGED
@@ -1,106 +1,106 @@
1
- # marker.js 3 — Add image annotation to your web apps
2
-
3
- marker.js 3 is a JavaScript browser library to enable image annotation in your web applications. Add marker.js 3 to your web app and enable users to annotate and mark up images. You can save, share or otherwise process the results.
4
-
5
- ## Installation
6
-
7
- ```bash
8
- npm install @markerjs/markerjs3
9
- ```
10
-
11
- The library includes TypeScript type definitions out of the box.
12
-
13
- ## Usage
14
-
15
- marker.js 3 is a "headless" library. In this case "headless" means that it doesn't come with any toolbars, property editors, and placement preconceptions. This way the library focuses on the core features you need, and you can make it feel totally native in the application you are building without resorting to any tricks or hacks.
16
-
17
- With that out of the way, here are the simplest usage scenarios...
18
-
19
- ### MarkerArea (The Editor)
20
-
21
- Import `MarkerArea` from `@markerjs/markerjs3`:
22
-
23
- ```js
24
- import { MarkerArea } from '@markerjs/markerjs3';
25
- ```
26
-
27
- In the code below we assume that you have an `HTMLImageElement` as `targetImage`. It can be a reference to an image you already have on the page or you can simply create it with something like this:
28
-
29
- ```js
30
- const targetImg = document.createElement('img');
31
- targetImg.src = './sample.jpg';
32
- ```
33
-
34
- Now you just need to create an instance of `MarkerArea`, set its `targetImage` property and add it to the page:
35
-
36
- ```js
37
- const markerArea = new MarkerArea();
38
- markerArea.targetImage = targetImg;
39
- editorContainerDiv.appendChild(markerArea);
40
- ```
41
-
42
- To initiate creation of a marker you just call `createMarker()` and pass it the name (or type) of the marker you want to create. So, if you have a button with id `addFrameButton` you can make it create a new `FrameMarker` with something like this:
43
-
44
- ```js
45
- document.querySelector('#addButton')?.addEventListener('click', () => {
46
- markerArea.createMarker('FrameMarker');
47
- });
48
- ```
49
-
50
- And whenever you want to save state (current annotation) you just call `getState()`:
51
-
52
- ```js
53
- document.querySelector('#saveStateButton')?.addEventListener('click', () => {
54
- const state = markerArea.getState();
55
- console.log(state);
56
- });
57
- ```
58
-
59
- ### Rendering static images
60
-
61
- To render the annotation as a static image you use `Renderer`.
62
-
63
- ```js
64
- import { MarkerArea, Renderer } from '@markerjs/markerjs3';
65
- ```
66
-
67
- Just create an instance of it and pass the annotation state to the `rasterize()` method:
68
-
69
- ```js
70
- const renderer = new Renderer();
71
- renderer.targetImage = targetImg;
72
- const dataUrl = await renderer.rasterize(markerArea.getState());
73
-
74
- const img = document.createElement('img');
75
- img.src = dataUrl;
76
-
77
- someDiv.appendChild(img);
78
- ```
79
-
80
- ### MarkerView (The Viewer)
81
-
82
- To show dynamic annotation overlays on top of the original image you use `MarkerView`.
83
-
84
- ```js
85
- import { MarkerView } from '@markerjs/markerjs3';
86
-
87
- const markerView = new MarkerView();
88
- markerView.targetImage = targetImg;
89
- viewerContainer.appendChild(markerView);
90
-
91
- markerView.show(savedState);
92
- ```
93
-
94
- ## Demos
95
-
96
- Check out the [demos on markerjs.com](https://markerjs.com/demos).
97
-
98
- ## More docs and tutorials
99
-
100
- You can find marker.js 3 reference and tutorials [here](https://markerjs.com/docs-v3/).
101
-
102
- ## License
103
-
104
- Linkware (see [LICENSE](https://github.com/ailon/markerjs3/blob/master/LICENSE) for details) - the UI displays a small link back to the marker.js 3 website which should be retained.
105
-
106
- Alternative licenses are available through the [marker.js website](https://markerjs.com).
1
+ # marker.js 3 — Add image annotation to your web apps
2
+
3
+ marker.js 3 is a JavaScript browser library to enable image annotation in your web applications. Add marker.js 3 to your web app and enable users to annotate and mark up images. You can save, share or otherwise process the results.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @markerjs/markerjs3
9
+ ```
10
+
11
+ The library includes TypeScript type definitions out of the box.
12
+
13
+ ## Usage
14
+
15
+ marker.js 3 is a "headless" library. In this case "headless" means that it doesn't come with any toolbars, property editors, and placement preconceptions. This way the library focuses on the core features you need, and you can make it feel totally native in the application you are building without resorting to any tricks or hacks.
16
+
17
+ With that out of the way, here are the simplest usage scenarios...
18
+
19
+ ### MarkerArea (The Editor)
20
+
21
+ Import `MarkerArea` from `@markerjs/markerjs3`:
22
+
23
+ ```js
24
+ import { MarkerArea } from '@markerjs/markerjs3';
25
+ ```
26
+
27
+ In the code below we assume that you have an `HTMLImageElement` as `targetImage`. It can be a reference to an image you already have on the page or you can simply create it with something like this:
28
+
29
+ ```js
30
+ const targetImg = document.createElement('img');
31
+ targetImg.src = './sample.jpg';
32
+ ```
33
+
34
+ Now you just need to create an instance of `MarkerArea`, set its `targetImage` property and add it to the page:
35
+
36
+ ```js
37
+ const markerArea = new MarkerArea();
38
+ markerArea.targetImage = targetImg;
39
+ editorContainerDiv.appendChild(markerArea);
40
+ ```
41
+
42
+ To initiate creation of a marker you just call `createMarker()` and pass it the name (or type) of the marker you want to create. So, if you have a button with id `addFrameButton` you can make it create a new `FrameMarker` with something like this:
43
+
44
+ ```js
45
+ document.querySelector('#addButton')?.addEventListener('click', () => {
46
+ markerArea.createMarker('FrameMarker');
47
+ });
48
+ ```
49
+
50
+ And whenever you want to save state (current annotation) you just call `getState()`:
51
+
52
+ ```js
53
+ document.querySelector('#saveStateButton')?.addEventListener('click', () => {
54
+ const state = markerArea.getState();
55
+ console.log(state);
56
+ });
57
+ ```
58
+
59
+ ### Rendering static images
60
+
61
+ To render the annotation as a static image you use `Renderer`.
62
+
63
+ ```js
64
+ import { MarkerArea, Renderer } from '@markerjs/markerjs3';
65
+ ```
66
+
67
+ Just create an instance of it and pass the annotation state to the `rasterize()` method:
68
+
69
+ ```js
70
+ const renderer = new Renderer();
71
+ renderer.targetImage = targetImg;
72
+ const dataUrl = await renderer.rasterize(markerArea.getState());
73
+
74
+ const img = document.createElement('img');
75
+ img.src = dataUrl;
76
+
77
+ someDiv.appendChild(img);
78
+ ```
79
+
80
+ ### MarkerView (The Viewer)
81
+
82
+ To show dynamic annotation overlays on top of the original image you use `MarkerView`.
83
+
84
+ ```js
85
+ import { MarkerView } from '@markerjs/markerjs3';
86
+
87
+ const markerView = new MarkerView();
88
+ markerView.targetImage = targetImg;
89
+ viewerContainer.appendChild(markerView);
90
+
91
+ markerView.show(savedState);
92
+ ```
93
+
94
+ ## Demos
95
+
96
+ Check out the [demos on markerjs.com](https://markerjs.com/demos).
97
+
98
+ ## More docs and tutorials
99
+
100
+ You can find marker.js 3 reference and tutorials [here](https://markerjs.com/docs-v3/).
101
+
102
+ ## License
103
+
104
+ Linkware (see [LICENSE](https://github.com/ailon/markerjs3/blob/master/LICENSE) for details) - the UI displays a small link back to the marker.js 3 website which should be retained.
105
+
106
+ Alternative licenses are available through the [marker.js website](https://markerjs.com).
package/markerjs3.d.ts CHANGED
@@ -1948,58 +1948,139 @@ declare class MarkerBaseEditor<TMarkerType extends MarkerBase = MarkerBase> {
1948
1948
 
1949
1949
  /**
1950
1950
  * Marker area custom event types.
1951
+ *
1952
+ * @summary
1953
+ * Defines the custom events that can be dispatched by the {@link MarkerArea} component.
1954
+ *
1955
+ * @remarks
1956
+ * The `MarkerAreaEventMap` interface defines the events that can be dispatched by the {@link MarkerArea} component.
1957
+ *
1958
+ * You can listen to these events using the {@link MarkerArea.addEventListener | addEventListener} method on the {@link MarkerArea} instance.
1959
+ *
1960
+ * The events can be logically grouped into two categories:
1961
+ * 1. Marker area events (start with `area`)
1962
+ * 2. Marker editor events (start with `marker`).
1963
+ *
1964
+ * The marker area events are related to the overall state of the {@link MarkerArea} component,
1965
+ * while the marker editor events are related to the individual marker editors within the area.
1966
+ *
1967
+ * Marker area events receive {@link MarkerAreaEventData} as their `event.detail`,
1968
+ * while marker editor events receive {@link MarkerEditorEventData} as their `event.detail`.
1969
+ * Both event data types contain a reference to the {@link MarkerArea} instance
1970
+ * and, for marker editor events, a reference to the specific marker editor that triggered the event.
1951
1971
  */
1952
1972
  interface MarkerAreaEventMap {
1953
1973
  /**
1954
1974
  * Marker area initialized.
1975
+ *
1976
+ * @remarks
1977
+ * This event is dispatched early in the lifecycle when the {@link MarkerArea} component is initialized
1978
+ * but none of its internal elements have been created yet.
1979
+ *
1980
+ * Use {@link areashow} to know when the component is fully initialized and ready to be used.
1955
1981
  */
1956
1982
  areainit: CustomEvent<MarkerAreaEventData>;
1957
1983
  /**
1958
1984
  * Marker area shown.
1985
+ *
1986
+ * @remarks
1987
+ * This event is dispatched when the {@link MarkerArea} component is fully initialized and ready to be used.
1959
1988
  */
1960
1989
  areashow: CustomEvent<MarkerAreaEventData>;
1961
1990
  /**
1962
1991
  * Marker area state restored.
1992
+ *
1993
+ * @remarks
1994
+ * This event is dispatched when the {@link MarkerArea} component restores its state from
1995
+ * a previously saved state.
1963
1996
  */
1964
1997
  arearestorestate: CustomEvent<MarkerAreaEventData>;
1965
1998
  /**
1966
1999
  * Marker area focused.
2000
+ *
2001
+ * @remarks
2002
+ * This event is dispatched when the {@link MarkerArea} component receives focus.
1967
2003
  */
1968
2004
  areafocus: CustomEvent<MarkerAreaEventData>;
1969
2005
  /**
1970
2006
  * Marker area lost focus.
2007
+ *
2008
+ * @remarks
2009
+ * This event is dispatched when the {@link MarkerArea} component loses focus.
1971
2010
  */
1972
2011
  areablur: CustomEvent<MarkerAreaEventData>;
1973
2012
  /**
1974
2013
  * Marker area state changed.
2014
+ *
2015
+ * @remarks
2016
+ * This event is dispatched when the {@link MarkerArea} component's state changes.
2017
+ *
2018
+ * This is a good place to implement auto-saving or update the UI based on the current state.
1975
2019
  */
1976
2020
  areastatechange: CustomEvent<MarkerAreaEventData>;
1977
2021
  /**
1978
2022
  * Marker selected.
2023
+ *
2024
+ * @remarks
2025
+ * This event is dispatched when a marker editor is selected.
2026
+ * You can use this event to update the UI or perform actions based on the selected marker editor.
1979
2027
  */
1980
2028
  markerselect: CustomEvent<MarkerEditorEventData>;
1981
2029
  /**
1982
2030
  * Marker deselected.
2031
+ *
2032
+ * @remarks
2033
+ * This event is dispatched when a marker editor is deselected.
2034
+ * You can use this event to update the UI or perform actions based on the deselected marker editor.
1983
2035
  */
1984
2036
  markerdeselect: CustomEvent<MarkerEditorEventData>;
1985
2037
  /**
1986
2038
  * Marker creating.
2039
+ *
2040
+ * @remarks
2041
+ * This event is dispatched when a marker creation has been initiated.
2042
+ * You can use this event to update the UI or perform actions based on the marker creation process.
1987
2043
  */
1988
2044
  markercreating: CustomEvent<MarkerEditorEventData>;
1989
2045
  /**
1990
2046
  * Marker created.
2047
+ *
2048
+ * @remarks
2049
+ * This event is dispatched when a marker has been created.
2050
+ * You can use this event to update the UI or perform actions based on the created marker editor.
2051
+ *
2052
+ * One common use case is implementing continuous marker creation,
2053
+ * where you create a new marker editor immediately after the previous one has been created.
2054
+ *
2055
+ * @example
2056
+ * ```js
2057
+ * // create another marker of the same type
2058
+ * markerArea.addEventListener("markercreate", (ev) => {
2059
+ * markerArea.createMarker(ev.detail.markerEditor.marker.typeName);
2060
+ * });
2061
+ * ```
1991
2062
  */
1992
2063
  markercreate: CustomEvent<MarkerEditorEventData>;
1993
2064
  /**
1994
2065
  * Marker about to be deleted.
2066
+ *
2067
+ * @remarks
2068
+ * This event is dispatched before a marker editor is deleted.
1995
2069
  */
1996
2070
  markerbeforedelete: CustomEvent<MarkerEditorEventData>;
1997
2071
  /**
1998
2072
  * Marker deleted.
2073
+ *
2074
+ * @remarks
2075
+ * This event is dispatched after a marker editor is deleted.
2076
+ * You can use this event to update the UI or perform actions based on the deleted marker editor.
1999
2077
  */
2000
2078
  markerdelete: CustomEvent<MarkerEditorEventData>;
2001
2079
  /**
2002
2080
  * Marker changed.
2081
+ *
2082
+ * @remarks
2083
+ * This event is dispatched when a marker editor's state has changed.
2003
2084
  */
2004
2085
  markerchange: CustomEvent<MarkerEditorEventData>;
2005
2086
  }
@@ -2827,7 +2908,7 @@ declare class TextBlockEditor {
2827
2908
  * Returns editor's UI,
2828
2909
  * @returns UI in a div element.
2829
2910
  */
2830
- getEditorUi(): HTMLDivElement;
2911
+ getEditorUi(): HTMLTextAreaElement;
2831
2912
  /**
2832
2913
  * Focuses text editing in the editor.
2833
2914
  */
@@ -2969,47 +3050,102 @@ declare class CurveMarkerEditor<TMarkerType extends CurveMarker = CurveMarker> e
2969
3050
  }
2970
3051
 
2971
3052
  /**
2972
- * Event map for {@link MarkerView}.
3053
+ * Marker view custom event types.
3054
+ *
3055
+ * @summary
3056
+ * Defines the custom events that can be dispatched by the {@link MarkerView} component.
3057
+ *
3058
+ * @remarks
3059
+ * The `MarkerViewEventMap` interface defines the events that can be dispatched by the {@link MarkerView} component.
3060
+ *
3061
+ * You can listen to these events using the {@link MarkerView.addEventListener | addEventListener} method on the {@link MarkerView} instance.
3062
+ *
3063
+ * The events can be logically grouped into two categories:
3064
+ * 1. Marker view events (start with `view`)
3065
+ * 2. Marker events (start with `marker`).
3066
+ *
3067
+ * The marker view events are related to the overall state of the {@link MarkerView} component,
3068
+ * while the marker events are related to the individual markers within the view.
3069
+ *
3070
+ * Marker view events receive {@link MarkerViewEventData} as their `event.detail`,
3071
+ * while marker events receive {@link MarkerEventData} as their `event.detail`.
3072
+ * Both event data types contain a reference to the {@link MarkerView} instance
3073
+ * and, for marker events, a reference to the specific marker that triggered the event.
2973
3074
  */
2974
3075
  interface MarkerViewEventMap {
2975
3076
  /**
2976
3077
  * Viewer initialized.
3078
+ *
3079
+ * @remarks
3080
+ * This event is dispatched when the {@link MarkerView} instance is created and initialized
3081
+ * but none of its internal elements have been created yet.
2977
3082
  */
2978
3083
  viewinit: CustomEvent<MarkerViewEventData>;
2979
3084
  /**
2980
3085
  * Viewer shown.
3086
+ *
3087
+ * @remarks
3088
+ * This event is dispatched when the {@link MarkerView} instance is fully initialized,
3089
+ * its internal elements are created, and the target image is loaded.
3090
+ * It indicates that the viewer is ready to display markers and annotations.
2981
3091
  */
2982
3092
  viewshow: CustomEvent<MarkerViewEventData>;
2983
3093
  /**
2984
3094
  * Viewer state restored.
3095
+ *
3096
+ * @remarks
3097
+ * This event is dispatched when the {@link MarkerView} instance has restored a previously saved state.
3098
+ * It indicates that the viewer has loaded markers and annotations from a saved state.
2985
3099
  */
2986
3100
  viewrestorestate: CustomEvent<MarkerViewEventData>;
2987
3101
  /**
2988
3102
  * Marker clicked.
3103
+ *
3104
+ * @remarks
3105
+ * This event is dispatched when a marker within the {@link MarkerView} is clicked.
3106
+ * It provides access to the clicked marker and the {@link MarkerView} instance.
2989
3107
  */
2990
3108
  markerclick: CustomEvent<MarkerEventData>;
2991
3109
  /**
2992
3110
  * Marker mouse over.
3111
+ *
3112
+ * @remarks
3113
+ * This event is dispatched when the mouse pointer hovers over a marker within the {@link MarkerView}.
2993
3114
  */
2994
3115
  markerover: CustomEvent<MarkerEventData>;
2995
3116
  /**
2996
3117
  * Marker pointer down.
3118
+ *
3119
+ * @remarks
3120
+ * This event is dispatched when a pointer (mouse, touch, etc.) is pressed down on a marker within the {@link MarkerView}.
2997
3121
  */
2998
3122
  markerpointerdown: CustomEvent<MarkerEventData>;
2999
3123
  /**
3000
3124
  * Marker pointer move.
3125
+ *
3126
+ * @remarks
3127
+ * This event is dispatched when a pointer (mouse, touch, etc.) moves while over a marker within the {@link MarkerView}.
3001
3128
  */
3002
3129
  markerpointermove: CustomEvent<MarkerEventData>;
3003
3130
  /**
3004
3131
  * Marker pointer up.
3132
+ *
3133
+ * @remarks
3134
+ * This event is dispatched when a pointer (mouse, touch, etc.) is released after being pressed down on a marker within the {@link MarkerView}.
3005
3135
  */
3006
3136
  markerpointerup: CustomEvent<MarkerEventData>;
3007
3137
  /**
3008
3138
  * Marker pointer enter.
3139
+ *
3140
+ * @remarks
3141
+ * This event is dispatched when a pointer (mouse, touch, etc.) enters the area of a marker within the {@link MarkerView}.
3009
3142
  */
3010
3143
  markerpointerenter: CustomEvent<MarkerEventData>;
3011
3144
  /**
3012
3145
  * Marker pointer leave.
3146
+ *
3147
+ * @remarks
3148
+ * This event is dispatched when a pointer (mouse, touch, etc.) leaves the area of a marker within the {@link MarkerView}.
3013
3149
  */
3014
3150
  markerpointerleave: CustomEvent<MarkerEventData>;
3015
3151
  }