@markerjs/markerjs3 3.0.0-alpha.4 → 3.0.0-beta.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/README.md +89 -7
- package/markerjs3.d.ts +14 -3
- package/markerjs3.js +1 -1
- package/markerjs3.js.map +1 -1
- package/package.json +1 -1
- package/umd/markerjs3.js +1 -1
- package/umd/markerjs3.js.map +1 -1
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# marker.js 3 — Add image annotation to your web apps
|
|
2
2
|
|
|
3
|
-
> **Note**: marker.js 3 is in the
|
|
3
|
+
> **Note**: marker.js 3 is in the pre-release stage of its lifecycle and will have many additions and, potentially, breaking changes before the official 3.0 release.
|
|
4
4
|
>
|
|
5
5
|
> If you need a stable image annotation library, consider using [marker.js 2](https://markerjs.com) for now.
|
|
6
6
|
|
|
7
|
-
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
|
|
7
|
+
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.
|
|
8
8
|
|
|
9
9
|
## Installation
|
|
10
10
|
|
|
@@ -12,7 +12,7 @@ marker.js 3 is a JavaScript browser library to enable image annotation in your w
|
|
|
12
12
|
npm install @markerjs/markerjs3
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
or
|
|
15
|
+
or
|
|
16
16
|
|
|
17
17
|
```
|
|
18
18
|
yarn add @markerjs/markerjs3
|
|
@@ -20,17 +20,99 @@ yarn add @markerjs/markerjs3
|
|
|
20
20
|
|
|
21
21
|
## Usage
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
Unlike the previous version, marker.js 3 is a "headless" (sort of) 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.
|
|
24
|
+
|
|
25
|
+
With that out of the way, here are the simplest usage scenarios...
|
|
26
|
+
|
|
27
|
+
### MarkerArea (The Editor)
|
|
28
|
+
|
|
29
|
+
Import `MarkerArea` from `@markerjs/markerjs3`:
|
|
30
|
+
|
|
31
|
+
```js
|
|
32
|
+
import { MarkerArea } from '@markerjs/markerjs3';
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
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:
|
|
36
|
+
|
|
37
|
+
```js
|
|
38
|
+
const targetImg = document.createElement('img');
|
|
39
|
+
targetImg.src = './sample.jpg';
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Now you just need to create an instance of `MarkerArea`, set its `targetImage` property and add it to the page:
|
|
43
|
+
|
|
44
|
+
```js
|
|
45
|
+
const markerArea = new MarkerArea();
|
|
46
|
+
markerArea.targetImage = targetImg;
|
|
47
|
+
editorContainerDiv.appendChild(markerArea);
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
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:
|
|
51
|
+
|
|
52
|
+
```js
|
|
53
|
+
document.querySelector("#addButton")!.addEventListener("click", () => {
|
|
54
|
+
markerArea.createMarker("FrameMarker");
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
And whenever you want to save state (current annotation) you just call `getState()`:
|
|
59
|
+
|
|
60
|
+
```js
|
|
61
|
+
document.querySelector("#saveStateButton")!.addEventListener("click", () => {
|
|
62
|
+
const state = markerArea.getState();
|
|
63
|
+
console.log(state);
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Rendering static images
|
|
68
|
+
|
|
69
|
+
To render the annotation as a static image you use `Renderer`.
|
|
70
|
+
|
|
71
|
+
```js
|
|
72
|
+
import { MarkerArea, Renderer } from '@markerjs/markerjs3';
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Just create an instance of it and pass the annotation state to the `rasterize()` method:
|
|
76
|
+
|
|
77
|
+
```js
|
|
78
|
+
const renderer = new Renderer();
|
|
79
|
+
renderer.targetImage = targetImg;
|
|
80
|
+
const dataUrl = await renderer.rasterize(markerArea.getState());
|
|
81
|
+
|
|
82
|
+
const img = document.createElement('img');
|
|
83
|
+
img.src = dataUrl;
|
|
84
|
+
|
|
85
|
+
someDiv.appendChild(img);
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### MarkerView (The Viewer)
|
|
89
|
+
|
|
90
|
+
To show dynamic annotation overlays on top of the original image you use `MarkerView`.
|
|
91
|
+
|
|
92
|
+
```js
|
|
93
|
+
import { MarkerView } from '@markerjs/markerjs3';
|
|
94
|
+
|
|
95
|
+
const markerView = new MarkerView();
|
|
96
|
+
markerView.targetImage = targetImg;
|
|
97
|
+
viewerContainer.appendChild(markerView);
|
|
98
|
+
|
|
99
|
+
markerView.show(savedState);
|
|
100
|
+
```
|
|
24
101
|
|
|
25
102
|
## Demos
|
|
26
103
|
|
|
27
|
-
|
|
104
|
+
Check out the "work-in-progress" demo [here](https://github.com/ailon/markerjs3-wip-demo). It covers most of the available features with no extra bells or whistles.
|
|
105
|
+
|
|
106
|
+
While it's made with React it is purposefully light on React-specific stuff and "best practices" to just focus on marker.js 3 related things.
|
|
107
|
+
|
|
108
|
+
_more demos coming soon..._
|
|
28
109
|
|
|
29
110
|
## More docs and tutorials
|
|
30
111
|
|
|
31
|
-
|
|
112
|
+
_coming soon..._
|
|
32
113
|
|
|
33
114
|
## License
|
|
115
|
+
|
|
34
116
|
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.
|
|
35
117
|
|
|
36
|
-
Alternative licenses are available through the [marker.js website](https://markerjs.com).
|
|
118
|
+
Alternative licenses are available through the [marker.js website](https://markerjs.com).
|
package/markerjs3.d.ts
CHANGED
|
@@ -403,8 +403,7 @@ interface ShapeMarkerBaseState extends ShapeOutlineMarkerBaseState {
|
|
|
403
403
|
declare abstract class ShapeMarkerBase extends ShapeOutlineMarkerBase {
|
|
404
404
|
static title: string;
|
|
405
405
|
protected _fillColor: string;
|
|
406
|
-
|
|
407
|
-
set fillColor(value: string);
|
|
406
|
+
protected applyFillColor(): void;
|
|
408
407
|
constructor(container: SVGGElement);
|
|
409
408
|
createVisual(): void;
|
|
410
409
|
/**
|
|
@@ -949,6 +948,11 @@ declare class CalloutMarker extends TextMarker {
|
|
|
949
948
|
private tipBase2Position;
|
|
950
949
|
private _calloutVisual;
|
|
951
950
|
constructor(container: SVGGElement);
|
|
951
|
+
protected applyStrokeColor(): void;
|
|
952
|
+
protected applyStrokeWidth(): void;
|
|
953
|
+
protected applyStrokeDasharray(): void;
|
|
954
|
+
protected applyOpacity(): void;
|
|
955
|
+
protected applyFillColor(): void;
|
|
952
956
|
protected getPath(): string;
|
|
953
957
|
private setTipPoints;
|
|
954
958
|
createVisual(): void;
|
|
@@ -1730,6 +1734,12 @@ declare class FreehandMarkerEditor<TMarkerType extends FreehandMarker = Freehand
|
|
|
1730
1734
|
declare class TextMarkerEditor<TMarkerType extends TextMarker = TextMarker> extends RectangularBoxMarkerBaseEditor<TMarkerType> {
|
|
1731
1735
|
private textBlockEditorContainer;
|
|
1732
1736
|
private textBlockEditor;
|
|
1737
|
+
set color(color: string);
|
|
1738
|
+
get color(): string;
|
|
1739
|
+
set fontFamily(font: string);
|
|
1740
|
+
get fontFamily(): string;
|
|
1741
|
+
set fontSize(size: FontSize);
|
|
1742
|
+
get fontSize(): FontSize;
|
|
1733
1743
|
constructor(properties: MarkerEditorProperties<TMarkerType>);
|
|
1734
1744
|
private _pointerDownTime;
|
|
1735
1745
|
private _pointerDownPoint;
|
|
@@ -1858,6 +1868,7 @@ declare class MarkerView extends HTMLElement {
|
|
|
1858
1868
|
declare class Renderer {
|
|
1859
1869
|
private _mainCanvas?;
|
|
1860
1870
|
private _editingTarget?;
|
|
1871
|
+
private _renderHelperContainer?;
|
|
1861
1872
|
private _targetWidth;
|
|
1862
1873
|
get targetWidth(): number;
|
|
1863
1874
|
set targetWidth(value: number);
|
|
@@ -1916,4 +1927,4 @@ declare class Renderer {
|
|
|
1916
1927
|
rasterize(state: AnnotationState, targetCanvas?: HTMLCanvasElement): Promise<string>;
|
|
1917
1928
|
}
|
|
1918
1929
|
|
|
1919
|
-
export { type AnnotationState, ArrowMarker, ArrowMarkerEditor, type ArrowMarkerState, type ArrowType, CalloutMarker, CalloutMarkerEditor, type CalloutMarkerState, type ColorType, CoverMarker, EllipseFrameMarker, EllipseMarker, FrameMarker, FreehandMarker, FreehandMarkerEditor, type FreehandMarkerState, Grip, HighlightMarker, type IPoint, LineMarker, LinearMarkerBase, type LinearMarkerBaseState, LinearMarkerEditor, MarkerArea, type MarkerAreaEventData, type MarkerAreaEventMap, MarkerBase, MarkerBaseEditor, type MarkerBaseState, type MarkerEditorProperties, type MarkerEditorState, MarkerView, type MarkerViewEventData, type MarkerViewEventMap, MeasurementMarker, PolygonMarker, PolygonMarkerEditor, type PolygonMarkerState, RectangularBoxMarkerBase, type RectangularBoxMarkerBaseState, Renderer, ResizeGrip, RotateGrip, ShapeMarkerBase, type ShapeMarkerBaseState, ShapeMarkerEditor, ShapeOutlineMarkerBase, type ShapeOutlineMarkerBaseState, ShapeOutlineMarkerEditor, SvgHelper, TextMarker, TextMarkerEditor, type TextMarkerState };
|
|
1930
|
+
export { type AnnotationState, ArrowMarker, ArrowMarkerEditor, type ArrowMarkerState, type ArrowType, CalloutMarker, CalloutMarkerEditor, type CalloutMarkerState, type ColorType, CoverMarker, EllipseFrameMarker, EllipseMarker, type FontSize, FrameMarker, FreehandMarker, FreehandMarkerEditor, type FreehandMarkerState, Grip, HighlightMarker, type IPoint, LineMarker, LinearMarkerBase, type LinearMarkerBaseState, LinearMarkerEditor, MarkerArea, type MarkerAreaEventData, type MarkerAreaEventMap, MarkerBase, MarkerBaseEditor, type MarkerBaseState, type MarkerEditorProperties, type MarkerEditorState, MarkerView, type MarkerViewEventData, type MarkerViewEventMap, MeasurementMarker, PolygonMarker, PolygonMarkerEditor, type PolygonMarkerState, RectangularBoxMarkerBase, type RectangularBoxMarkerBaseState, Renderer, ResizeGrip, RotateGrip, ShapeMarkerBase, type ShapeMarkerBaseState, ShapeMarkerEditor, ShapeOutlineMarkerBase, type ShapeOutlineMarkerBaseState, ShapeOutlineMarkerEditor, SvgHelper, TextMarker, TextMarkerEditor, type TextMarkerState };
|