@markerjs/markerjs3 3.0.0-alpha.3 → 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 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 early pre-release stage of its lifecycle and will have many additions and breaking changes before the official 3.0 release.
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 instantly enable users to annotate and mark up images. You can save, share or otherwise process the results.
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
- *coming soon...*
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
- *coming soon...*
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
- *coming soon...*
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
- get fillColor(): string;
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;
@@ -959,6 +963,34 @@ declare class CalloutMarker extends TextMarker {
959
963
  scale(scaleX: number, scaleY: number): void;
960
964
  }
961
965
 
966
+ declare class EllipseFrameMarker extends ShapeOutlineMarkerBase {
967
+ /**
968
+ * String type name of the marker type.
969
+ */
970
+ static typeName: string;
971
+ /**
972
+ * Marker type title (display name) used for accessibility and other attributes.
973
+ */
974
+ static title: string;
975
+ constructor(container: SVGGElement);
976
+ protected getPath(width?: number, height?: number): string;
977
+ getState(): ShapeOutlineMarkerBaseState;
978
+ }
979
+
980
+ declare class EllipseMarker extends ShapeMarkerBase {
981
+ /**
982
+ * String type name of the marker type.
983
+ */
984
+ static typeName: string;
985
+ /**
986
+ * Marker type title (display name) used for accessibility and other attributes.
987
+ */
988
+ static title: string;
989
+ constructor(container: SVGGElement);
990
+ protected getPath(width?: number, height?: number): string;
991
+ getState(): ShapeMarkerBaseState;
992
+ }
993
+
962
994
  interface MarkerEditorProperties<TMarkerType extends MarkerBase = MarkerBase> {
963
995
  /**
964
996
  * SVG container for the marker and editor elements.
@@ -1702,6 +1734,12 @@ declare class FreehandMarkerEditor<TMarkerType extends FreehandMarker = Freehand
1702
1734
  declare class TextMarkerEditor<TMarkerType extends TextMarker = TextMarker> extends RectangularBoxMarkerBaseEditor<TMarkerType> {
1703
1735
  private textBlockEditorContainer;
1704
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;
1705
1743
  constructor(properties: MarkerEditorProperties<TMarkerType>);
1706
1744
  private _pointerDownTime;
1707
1745
  private _pointerDownPoint;
@@ -1830,6 +1868,7 @@ declare class MarkerView extends HTMLElement {
1830
1868
  declare class Renderer {
1831
1869
  private _mainCanvas?;
1832
1870
  private _editingTarget?;
1871
+ private _renderHelperContainer?;
1833
1872
  private _targetWidth;
1834
1873
  get targetWidth(): number;
1835
1874
  set targetWidth(value: number);
@@ -1888,4 +1927,4 @@ declare class Renderer {
1888
1927
  rasterize(state: AnnotationState, targetCanvas?: HTMLCanvasElement): Promise<string>;
1889
1928
  }
1890
1929
 
1891
- export { type AnnotationState, ArrowMarker, ArrowMarkerEditor, type ArrowMarkerState, type ArrowType, CalloutMarker, CalloutMarkerEditor, type CalloutMarkerState, type ColorType, CoverMarker, 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 };