@itwin/core-markup 4.0.0-dev.8 → 4.0.0-dev.81

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.
Files changed (49) hide show
  1. package/CHANGELOG.md +41 -1
  2. package/lib/cjs/Markup.d.ts +323 -310
  3. package/lib/cjs/Markup.d.ts.map +1 -1
  4. package/lib/cjs/Markup.js +451 -420
  5. package/lib/cjs/Markup.js.map +1 -1
  6. package/lib/cjs/MarkupTool.d.ts +38 -38
  7. package/lib/cjs/MarkupTool.js +88 -88
  8. package/lib/cjs/MarkupTool.js.map +1 -1
  9. package/lib/cjs/RedlineTool.d.ts +145 -145
  10. package/lib/cjs/RedlineTool.d.ts.map +1 -1
  11. package/lib/cjs/RedlineTool.js +498 -512
  12. package/lib/cjs/RedlineTool.js.map +1 -1
  13. package/lib/cjs/SelectTool.d.ts +126 -126
  14. package/lib/cjs/SelectTool.js +741 -741
  15. package/lib/cjs/SelectTool.js.map +1 -1
  16. package/lib/cjs/SvgJsExt.d.ts +85 -85
  17. package/lib/cjs/SvgJsExt.js +185 -185
  18. package/lib/cjs/TextEdit.d.ts +43 -43
  19. package/lib/cjs/TextEdit.js +196 -196
  20. package/lib/cjs/TextEdit.js.map +1 -1
  21. package/lib/cjs/Undo.d.ts +46 -46
  22. package/lib/cjs/Undo.js +168 -168
  23. package/lib/cjs/core-markup.d.ts +18 -18
  24. package/lib/cjs/core-markup.js +38 -34
  25. package/lib/cjs/core-markup.js.map +1 -1
  26. package/lib/esm/Markup.d.ts +323 -310
  27. package/lib/esm/Markup.d.ts.map +1 -1
  28. package/lib/esm/Markup.js +447 -415
  29. package/lib/esm/Markup.js.map +1 -1
  30. package/lib/esm/MarkupTool.d.ts +38 -38
  31. package/lib/esm/MarkupTool.js +85 -84
  32. package/lib/esm/MarkupTool.js.map +1 -1
  33. package/lib/esm/RedlineTool.d.ts +145 -145
  34. package/lib/esm/RedlineTool.d.ts.map +1 -1
  35. package/lib/esm/RedlineTool.js +494 -498
  36. package/lib/esm/RedlineTool.js.map +1 -1
  37. package/lib/esm/SelectTool.d.ts +126 -126
  38. package/lib/esm/SelectTool.js +735 -734
  39. package/lib/esm/SelectTool.js.map +1 -1
  40. package/lib/esm/SvgJsExt.d.ts +85 -85
  41. package/lib/esm/SvgJsExt.js +180 -180
  42. package/lib/esm/TextEdit.d.ts +43 -43
  43. package/lib/esm/TextEdit.js +193 -191
  44. package/lib/esm/TextEdit.js.map +1 -1
  45. package/lib/esm/Undo.d.ts +46 -46
  46. package/lib/esm/Undo.js +164 -164
  47. package/lib/esm/core-markup.d.ts +18 -18
  48. package/lib/esm/core-markup.js +22 -22
  49. package/package.json +19 -19
package/lib/esm/Markup.js CHANGED
@@ -1,416 +1,448 @@
1
- /*---------------------------------------------------------------------------------------------
2
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
- * See LICENSE.md in the project root for license terms and full copyright notice.
4
- *--------------------------------------------------------------------------------------------*/
5
- /** @packageDocumentation
6
- * @module MarkupApp
7
- */
8
- import { BentleyError, Logger } from "@itwin/core-bentley";
9
- import { Point3d } from "@itwin/core-geometry";
10
- import { ImageSource, ImageSourceFormat } from "@itwin/core-common";
11
- import { FrontendLoggerCategory, imageElementFromImageSource, IModelApp, ScreenViewport } from "@itwin/core-frontend";
12
- import { adopt, create, Matrix, Point, SVG } from "@svgdotjs/svg.js";
13
- import * as redlineTool from "./RedlineTool";
14
- import { MarkupSelected, SelectTool } from "./SelectTool";
15
- import * as textTool from "./TextEdit";
16
- import { UndoManager } from "./Undo";
17
- /**
18
- * The main object for the Markup package. It is a singleton that stores the state of the Markup application.
19
- * It has only static members and methods. Applications may customize and control the behavior of the Markup by
20
- * setting members of [[MarkupApp.props]]. When [[MarkupApp.start]] is first called, it registers a set of "Markup.xxx"
21
- * tools that may be invoked from UI controls.
22
- * @public
23
- */
24
- export class MarkupApp {
25
- /** @internal */
26
- static screenToVbMtx() {
27
- var _a, _b;
28
- const matrix = (_b = (_a = this.markup) === null || _a === void 0 ? void 0 : _a.svgMarkup) === null || _b === void 0 ? void 0 : _b.screenCTM().inverse();
29
- return (undefined !== matrix ? matrix : new Matrix());
30
- }
31
- /** @internal */
32
- static getVpToScreenMtx() {
33
- const rect = this.markup.markupDiv.getBoundingClientRect();
34
- return (new Matrix()).translateO(rect.left, rect.top);
35
- }
36
- /** @internal */
37
- static getVpToVbMtx() { return this.getVpToScreenMtx().lmultiplyO(this.screenToVbMtx()); }
38
- /** @internal */
39
- static convertVpToVb(pt) {
40
- const pt0 = new Point(pt.x, pt.y);
41
- pt0.transformO(this.getVpToVbMtx());
42
- return new Point3d(pt0.x, pt0.y, 0);
43
- }
44
- /** determine whether there's a markup session currently active */
45
- static get isActive() { return undefined !== this.markup; }
46
- static createMarkup(view, markupData) { return new Markup(view, markupData); }
47
- static lockViewportSize(view, markupData) {
48
- const parentDiv = view.vpDiv;
49
- const rect = parentDiv.getBoundingClientRect();
50
- let width = rect.width;
51
- let height = rect.height;
52
- if (markupData) {
53
- const aspect = markupData.rect.height / markupData.rect.width;
54
- if ((width * aspect) > height)
55
- width = Math.floor(height / aspect);
56
- else
57
- height = Math.floor(width * aspect);
58
- }
59
- const style = parentDiv.style;
60
- style.width = `${width}px`;
61
- style.height = `${height}px`;
62
- }
63
- /** @internal */
64
- static getActionName(action) { return IModelApp.localization.getLocalizedString(`${this.namespace}:actions.${action}`); }
65
- /** Start a markup session */
66
- static async start(view, markupData) {
67
- if (this.markup)
68
- return; // a markup session is already active.
69
- await this.initialize();
70
- // first, lock the viewport to its current size while the markup session is running
71
- this.lockViewportSize(view, markupData);
72
- this.markup = this.createMarkup(view, markupData); // start a markup against the provided view.
73
- if (!this.markup.svgMarkup) {
74
- ScreenViewport.setToParentSize(this.markup.vp.vpDiv);
75
- this.markup.markupDiv.remove();
76
- return;
77
- }
78
- IModelApp.toolAdmin.markupView = view; // so viewing tools won't operate on the view.
79
- // set the markup Select tool as the default tool and start it, saving current default tool
80
- this._saveDefaultToolId = IModelApp.toolAdmin.defaultToolId;
81
- IModelApp.toolAdmin.defaultToolId = this.markupSelectToolId;
82
- return IModelApp.toolAdmin.startDefaultTool();
83
- }
84
- /** Read the result of a Markup session, then stop the session.
85
- * @note see [MarkupApp.props.result] for options.
86
- */
87
- static async stop() {
88
- const data = await this.readMarkup();
89
- if (!this.markup)
90
- return data;
91
- // restore original size for vp.
92
- ScreenViewport.setToParentSize(this.markup.vp.vpDiv);
93
- IModelApp.toolAdmin.markupView = undefined; // re-enable viewing tools for the view being marked-up
94
- this.markup.destroy();
95
- this.markup = undefined;
96
- // now restore the default tool and start it
97
- IModelApp.toolAdmin.defaultToolId = this._saveDefaultToolId;
98
- this._saveDefaultToolId = "";
99
- await IModelApp.toolAdmin.startDefaultTool();
100
- return data;
101
- }
102
- /** Call this method to initialize the Markup system.
103
- * It asynchronously loads the MarkupTools namespace for the prompts and tool names for the Markup system, and
104
- * also registers all of the Markup tools.
105
- * @return a Promise that may be awaited to ensure that the MarkupTools namespace had been loaded.
106
- * @note This method is automatically called every time you call [[start]]. Since the Markup tools cannot
107
- * start unless there is a Markup active, there's really no need to call this method directly.
108
- * The only virtue in doing so is to pre-load the Markup namespace if you have an opportunity to do so earlier in your
109
- * startup code.
110
- * @note This method may be called multiple times, but only the first time initiates the loading/registering. Subsequent
111
- * calls return the same Promise.
112
- */
113
- static async initialize() {
114
- if (undefined === this.namespace) { // only need to do this once
115
- this.namespace = "MarkupTools";
116
- const namespacePromise = IModelApp.localization.registerNamespace(this.namespace);
117
- IModelApp.tools.register(SelectTool, this.namespace);
118
- IModelApp.tools.registerModule(redlineTool, this.namespace);
119
- IModelApp.tools.registerModule(textTool, this.namespace);
120
- return namespacePromise;
121
- }
122
- return IModelApp.localization.getNamespacePromise(this.namespace); // so caller can make sure localized messages are ready.
123
- }
124
- /** convert the current markup SVG into a string, but don't include decorations or dynamics
125
- * @internal
126
- */
127
- static readMarkupSvg() {
128
- const markup = this.markup;
129
- if (!markup || !markup.svgContainer)
130
- return undefined;
131
- markup.svgDecorations.remove(); // we don't want the decorations or dynamics to be included
132
- markup.svgDynamics.remove();
133
- void IModelApp.toolAdmin.startDefaultTool();
134
- return markup.svgContainer.svg(); // string-ize the SVG data
135
- }
136
- /** convert the current markup SVG into a string (after calling readMarkupSvg) making sure width and height are specified.
137
- * @internal
138
- */
139
- static readMarkupSvgForDrawImage() {
140
- const markup = this.markup;
141
- if (!markup || !markup.svgContainer)
142
- return undefined;
143
- // Firefox requires width and height on top-level svg or drawImage does nothing, passing width/height to drawImage doesn't work.
144
- const rect = markup.markupDiv.getBoundingClientRect();
145
- markup.svgContainer.width(rect.width);
146
- markup.svgContainer.height(rect.height);
147
- return markup.svgContainer.svg(); // string-ize the SVG data
148
- }
149
- /** @internal */
150
- static async readMarkup() {
151
- const result = this.props.result;
152
- let canvas = this.markup.vp.readImageToCanvas();
153
- let svg, image;
154
- try {
155
- svg = this.readMarkupSvg(); // read the current svg data for the markup
156
- const svgForImage = (svg && result.imprintSvgOnImage ? this.readMarkupSvgForDrawImage() : undefined);
157
- if (svgForImage) {
158
- const svgImage = await imageElementFromImageSource(new ImageSource(svgForImage, ImageSourceFormat.Svg));
159
- canvas.getContext("2d").drawImage(svgImage, 0, 0); // draw markup svg onto view's canvas2d
160
- }
161
- // is the source view too wide? If so, we need to scale the image down.
162
- if (canvas.width > result.maxWidth) {
163
- // yes, we have to scale it down, create a new canvas and set the new canvas' size
164
- const newCanvas = document.createElement("canvas");
165
- newCanvas.width = result.maxWidth;
166
- newCanvas.height = canvas.height * (result.maxWidth / canvas.width);
167
- newCanvas.getContext("2d").drawImage(canvas, 0, 0, canvas.width, canvas.height, 0, 0, newCanvas.width, newCanvas.height);
168
- canvas = newCanvas; // return the image from adjusted canvas, not view canvas.
169
- }
170
- // return the markup data to be saved by the application.
171
- image = (!result.imageFormat ? undefined : canvas.toDataURL(result.imageFormat));
172
- }
173
- catch (e) {
174
- Logger.logError(`${FrontendLoggerCategory.Package}.markup`, "Error creating image from svg", BentleyError.getErrorProps(e));
175
- }
176
- return { rect: { width: canvas.width, height: canvas.height }, svg, image };
177
- }
178
- /** @internal */
179
- static get dropShadowId() { return `${this.markupPrefix}dropShadow`; } // this is referenced in the markup Svg to apply the drop-shadow filter to all markup elements.
180
- /** @internal */
181
- static get cornerId() { return `${this.markupPrefix}photoCorner`; }
182
- /** @internal */
183
- static get containerClass() { return `${this.markupPrefix}container`; }
184
- /** @internal */
185
- static get dynamicsClass() { return `${this.markupPrefix}dynamics`; }
186
- /** @internal */
187
- static get decorationsClass() { return `${this.markupPrefix}decorations`; }
188
- /** @internal */
189
- static get markupSvgClass() { return `${this.markupPrefix}svg`; }
190
- /** @internal */
191
- static get boxedTextClass() { return `${this.markupPrefix}boxedText`; }
192
- /** @internal */
193
- static get textClass() { return `${this.markupPrefix}text`; }
194
- /** @internal */
195
- static get stretchHandleClass() { return `${this.markupPrefix}stretchHandle`; }
196
- /** @internal */
197
- static get rotateLineClass() { return `${this.markupPrefix}rotateLine`; }
198
- /** @internal */
199
- static get rotateHandleClass() { return `${this.markupPrefix}rotateHandle`; }
200
- /** @internal */
201
- static get vertexHandleClass() { return `${this.markupPrefix}vertexHandle`; }
202
- /** @internal */
203
- static get moveHandleClass() { return `${this.markupPrefix}moveHandle`; }
204
- /** @internal */
205
- static get textOutlineClass() { return `${this.markupPrefix}textOutline`; }
206
- /** @internal */
207
- static get textEditorClass() { return `${this.markupPrefix}textEditor`; }
208
- }
209
- /** By setting members of this object, applications can control the appearance and behavior of various parts of MarkupApp. */
210
- MarkupApp.props = {
211
- /** the UI controls displayed on Elements by the Select Tool to allow users to modify them. */
212
- handles: {
213
- /** The diameter of the circles for the handles. */
214
- size: 10,
215
- /** The attributes of the stretch handles */
216
- stretch: { "fill-opacity": .85, "stroke": "black", "fill": "white" },
217
- /** The attributes of the line that connects the top-center stretch handle to the rotate handle. */
218
- rotateLine: { "stroke": "grey", "fill-opacity": .85 },
219
- /** The attributes of the rotate handle. */
220
- rotate: { "cursor": `url(${IModelApp.publicPath}Markup/rotate.png) 12 12, auto`, "fill-opacity": .85, "stroke": "black", "fill": "lightBlue" },
221
- /** The attributes of box around the element. */
222
- moveOutline: { "cursor": "move", "stroke-dasharray": "6,6", "fill": "none", "stroke-opacity": .85, "stroke": "white" },
223
- /** The attributes of box that provides the move cursor. */
224
- move: { "cursor": "move", "opacity": 0, "stroke-width": 10, "stroke": "white" },
225
- /** The attributes of handles on the vertices of lines. */
226
- vertex: { "cursor": `url(${IModelApp.publicPath}cursors/crosshair.cur), crosshair`, "fill-opacity": .85, "stroke": "black", "fill": "white" },
227
- },
228
- /** properties for providing feedback about selected elements. */
229
- hilite: {
230
- /** the color of selected elements */
231
- color: "magenta",
232
- /** the color of an element as the cursor passes over it */
233
- flash: "cyan",
234
- },
235
- /** optionally, show a drop-shadow behind all markup elements. */
236
- dropShadow: {
237
- /** if false, no drop shadow */
238
- enable: true,
239
- /** the attributes of the drop shadow. See https://developer.mozilla.org/en-US/docs/Web/SVG/Element/feDropShadow */
240
- attr: {
241
- "stdDeviation": 2,
242
- "dx": 1.2,
243
- "dy": 1.4,
244
- "flood-color": "#1B3838",
245
- },
246
- },
247
- /** The "active placement" parameters. New elements are created with these parameters, so UI controls should set them. */
248
- active: {
249
- /** the CSS style properties of new text elements. */
250
- text: {
251
- "font-family": "sans-serif",
252
- "font-size": "30px",
253
- "stroke": "none",
254
- "fill": "red",
255
- },
256
- /** the CSS style properties of new elements. */
257
- element: {
258
- "stroke": "red",
259
- "stroke-opacity": 0.8,
260
- "stroke-width": 3,
261
- "stroke-dasharray": 0,
262
- "stroke-linecap": "round",
263
- "stroke-linejoin": "round",
264
- "fill": "blue",
265
- "fill-opacity": 0.2,
266
- },
267
- arrow: {
268
- length: 7,
269
- width: 6,
270
- },
271
- cloud: {
272
- path: "M3.0,2.5 C3.9,.78 5.6,-.4 8.1,1.0 C9.1,0 11.3,-.2 12.5,.5 C14.2,-.5 17,.16 17.9,2.5 C21,3 20.2,7.3 17.6,7.5 C16.5,9.2 14.4,9.8 12.7,8.9 C11.6,10 9.5,10.3 8.1,9.4 C5.7,10.8 3.3,9.4 2.6,7.5 C-.9,7.7 .6,1.7 3.0,2.5z",
273
- },
274
- },
275
- /** Values for placing and editing Text. */
276
- text: {
277
- /** A default string for the Markup.Text.Place command. Applications can turn this off, or supply the user's initials, for example. */
278
- startValue: "Note: ",
279
- /** Parameters for the size and appearance of the text editor */
280
- edit: {
281
- background: "blanchedalmond",
282
- /** Starting size, will be updated if user stretches the box */
283
- size: { width: "25%", height: "4em" },
284
- /** font size of the text editor */
285
- fontSize: "14pt",
286
- /** A background box drawn around text so user can tell what's being selected */
287
- textBox: { "fill": "lightGrey", "fill-opacity": .1, "stroke-opacity": .85, "stroke": "lightBlue" },
288
- },
289
- },
290
- /** Used to draw the border outline around the view while it is being marked up so the user can tell Markup is active */
291
- borderOutline: {
292
- "stroke": "gold",
293
- "stroke-width": 6,
294
- "stroke-opacity": 0.4,
295
- "fill": "none",
296
- },
297
- /** Used to draw the border corner symbols for the view while it is being marked up so the user can tell Markup is active */
298
- borderCorners: {
299
- "stroke": "black",
300
- "stroke-width": 2,
301
- "stroke-opacity": 0.2,
302
- "fill": "gold",
303
- "fill-opacity": 0.2,
304
- },
305
- /** Determines what is returned by MarkupApp.stop */
306
- result: {
307
- /** The format for the image data. */
308
- imageFormat: "image/png",
309
- /** If true, the markup graphics will be imprinted in the returned image. */
310
- imprintSvgOnImage: true,
311
- /** the maximum width for the returned image. If the source view width is larger than this, it will be scaled down to this size. */
312
- maxWidth: 2048,
313
- },
314
- };
315
- MarkupApp._saveDefaultToolId = "";
316
- MarkupApp.markupSelectToolId = "Markup.Select";
317
- /** @internal */
318
- MarkupApp.markupPrefix = "markup-";
319
- const removeSvgNamespace = (svg) => {
320
- svg.node.removeAttribute("xmlns:svgjs");
321
- return svg;
322
- };
323
- const newSvgElement = (name) => adopt(create(name));
324
- /**
325
- * The current markup being created/edited. Holds the SVG elements, plus the active [[MarkupTool]].
326
- * When starting a Markup, a new Div is added as a child of the ScreenViewport's vpDiv.
327
- * @public
328
- */
329
- export class Markup {
330
- /** Create a new Markup for the supplied ScreenViewport. Adds a new "overlay-markup" div into the "vpDiv"
331
- * of the viewport.
332
- * @note you must call destroy on this object at end of markup to remove the markup div.
333
- */
334
- constructor(vp, markupData) {
335
- this.vp = vp;
336
- /** @internal */
337
- this.undo = new UndoManager();
338
- this.markupDiv = vp.addNewDiv("overlay-markup", true, 20); // this div goes on top of the canvas, but behind UI layers
339
- const rect = this.markupDiv.getBoundingClientRect();
340
- // First, see if there is a markup passed in as an argument
341
- if (markupData && markupData.svg) {
342
- this.markupDiv.innerHTML = markupData.svg; // make it a child of the markupDiv
343
- this.svgContainer = SVG(`.${MarkupApp.containerClass}`); // get it in svg.js format
344
- this.svgMarkup = SVG(`.${MarkupApp.markupSvgClass}`);
345
- if (!this.svgContainer || !this.svgMarkup) // if either isn't present, its not a valid markup
346
- return;
347
- removeSvgNamespace(this.svgContainer); // the SVG call above adds this - remove it
348
- this.svgMarkup.each(() => { }, true); // create an SVG.Element for each entry in the supplied markup.
349
- }
350
- else {
351
- // create the container that will be returned as the "svg" data for this markup
352
- this.svgContainer = SVG().addTo(this.markupDiv).addClass(MarkupApp.containerClass).viewbox(0, 0, rect.width, rect.height);
353
- removeSvgNamespace(this.svgContainer);
354
- this.svgMarkup = this.addNested(MarkupApp.markupSvgClass);
355
- }
356
- if (MarkupApp.props.dropShadow.enable) {
357
- this.createDropShadow(this.svgContainer);
358
- this.svgContainer.attr("filter", `url(#${MarkupApp.dropShadowId})`);
359
- }
360
- /** add two nested groups for providing feedback during the markup session. These Svgs are removed before the data is returned. */
361
- this.svgDynamics = this.addNested(MarkupApp.dynamicsClass); // only for tool dynamics of SVG graphics.
362
- this.svgDecorations = this.addNested(MarkupApp.decorationsClass); // only for temporary decorations of SVG graphics.
363
- this.addBorder();
364
- this.selected = new MarkupSelected(this.svgDecorations);
365
- }
366
- /** create the drop-shadow filter in the Defs section of the supplied svg element */
367
- createDropShadow(svg) {
368
- const filter = SVG(`#${MarkupApp.dropShadowId}`); // see if we already have one?
369
- if (filter)
370
- filter.remove(); // yes, remove it. This must be someone modifying the drop shadow properties
371
- // create a new filter, and add it to the Defs of the supplied svg
372
- svg.defs()
373
- .add(newSvgElement("filter").id(MarkupApp.dropShadowId)
374
- .add(newSvgElement("feDropShadow").attr(MarkupApp.props.dropShadow.attr)));
375
- }
376
- addNested(className) { return this.svgContainer.group().addClass(className); }
377
- addBorder() {
378
- const rect = this.svgContainer.viewbox();
379
- const inset = MarkupApp.props.borderOutline["stroke-width"];
380
- const cornerSize = inset * 6;
381
- const cornerPts = [0, 0, cornerSize, 0, cornerSize * .7, cornerSize * .3, cornerSize * .3, cornerSize * .3, cornerSize * .3, cornerSize * .7, 0, cornerSize];
382
- const decorations = this.svgDecorations;
383
- const photoCorner = decorations.symbol().polygon(cornerPts).attr(MarkupApp.props.borderCorners).id(MarkupApp.cornerId);
384
- const cornerGroup = decorations.group();
385
- cornerGroup.rect(rect.width - inset, rect.height - inset).move(inset / 2, inset / 2).attr(MarkupApp.props.borderOutline);
386
- cornerGroup.use(photoCorner);
387
- cornerGroup.use(photoCorner).rotate(90).translate(rect.width - cornerSize, 0);
388
- cornerGroup.use(photoCorner).rotate(180).translate(rect.width - cornerSize, rect.height - cornerSize);
389
- cornerGroup.use(photoCorner).rotate(270).translate(0, rect.height - cornerSize);
390
- }
391
- /** Called when the Markup is destroyed */
392
- destroy() { this.markupDiv.remove(); }
393
- /** Turn on picking the markup elements in the markup view */
394
- enablePick() { this.markupDiv.style.pointerEvents = "auto"; }
395
- /** Turn off picking the markup elements in the markup view */
396
- disablePick() { this.markupDiv.style.pointerEvents = "none"; }
397
- /** Change the default cursor for the markup view */
398
- setCursor(cursor) { this.markupDiv.style.cursor = cursor; }
399
- /** Delete all the entries in the selection set, then empty it. */
400
- deleteSelected() { this.selected.deleteAll(this.undo); }
401
- /** Bring all the entries in the selection set to the front. */
402
- bringToFront() { this.selected.reposition(MarkupApp.getActionName("toFront"), this.undo, (el) => el.front()); }
403
- /** Send all the entries in the selection set to the back. */
404
- sendToBack() { this.selected.reposition(MarkupApp.getActionName("toBack"), this.undo, (el) => el.back()); }
405
- /** Group all the entries in the selection set, then select the group. */
406
- groupSelected() {
407
- if (undefined !== this.svgMarkup)
408
- this.selected.groupAll(this.undo);
409
- }
410
- /** Ungroup all the group entries in the selection set. */
411
- ungroupSelected() {
412
- if (undefined !== this.svgMarkup)
413
- this.selected.ungroupAll(this.undo);
414
- }
415
- }
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ /** @packageDocumentation
6
+ * @module MarkupApp
7
+ */
8
+ import { BentleyError, Logger } from "@itwin/core-bentley";
9
+ import { Point3d } from "@itwin/core-geometry";
10
+ import { ImageSource, ImageSourceFormat } from "@itwin/core-common";
11
+ import { FrontendLoggerCategory, imageElementFromImageSource, IModelApp, ScreenViewport } from "@itwin/core-frontend";
12
+ import { adopt, create, Matrix, Point, SVG } from "@svgdotjs/svg.js";
13
+ import * as redlineTool from "./RedlineTool";
14
+ import { MarkupSelected, SelectTool } from "./SelectTool";
15
+ import * as textTool from "./TextEdit";
16
+ import { UndoManager } from "./Undo";
17
+ /**
18
+ * The main object for the Markup package. It is a singleton that stores the state of the Markup application.
19
+ * It has only static members and methods. Applications may customize and control the behavior of the Markup by
20
+ * setting members of [[MarkupApp.props]]. When [[MarkupApp.start]] is first called, it registers a set of "Markup.xxx"
21
+ * tools that may be invoked from UI controls.
22
+ * @public
23
+ */
24
+ class MarkupApp {
25
+ /** @internal */
26
+ static screenToVbMtx() {
27
+ const matrix = this.markup?.svgMarkup?.screenCTM().inverse();
28
+ return (undefined !== matrix ? matrix : new Matrix());
29
+ }
30
+ /** @internal */
31
+ static getVpToScreenMtx() {
32
+ const rect = this.markup.markupDiv.getBoundingClientRect();
33
+ return (new Matrix()).translateO(rect.left, rect.top);
34
+ }
35
+ /** @internal */
36
+ static getVpToVbMtx() { return this.getVpToScreenMtx().lmultiplyO(this.screenToVbMtx()); }
37
+ /** @internal */
38
+ static convertVpToVb(pt) {
39
+ const pt0 = new Point(pt.x, pt.y);
40
+ pt0.transformO(this.getVpToVbMtx());
41
+ return new Point3d(pt0.x, pt0.y, 0);
42
+ }
43
+ /** determine whether there's a markup session currently active */
44
+ static get isActive() { return undefined !== this.markup; }
45
+ static createMarkup(view, markupData) { return new Markup(view, markupData); }
46
+ static lockViewportSize(view, markupData) {
47
+ const parentDiv = view.vpDiv;
48
+ const rect = parentDiv.getBoundingClientRect();
49
+ let width = rect.width;
50
+ let height = rect.height;
51
+ if (markupData) {
52
+ const aspect = markupData.rect.height / markupData.rect.width;
53
+ if ((width * aspect) > height)
54
+ width = Math.floor(height / aspect);
55
+ else
56
+ height = Math.floor(width * aspect);
57
+ }
58
+ const style = parentDiv.style;
59
+ style.width = `${width}px`;
60
+ style.height = `${height}px`;
61
+ }
62
+ /** @internal */
63
+ static getActionName(action) { return IModelApp.localization.getLocalizedString(`${this.namespace}:actions.${action}`); }
64
+ /** Start a markup session */
65
+ static async start(view, markupData) {
66
+ if (this.markup)
67
+ return; // a markup session is already active.
68
+ await this.initialize();
69
+ // first, lock the viewport to its current size while the markup session is running
70
+ this.lockViewportSize(view, markupData);
71
+ this.markup = this.createMarkup(view, markupData); // start a markup against the provided view.
72
+ if (!this.markup.svgMarkup) {
73
+ ScreenViewport.setToParentSize(this.markup.vp.vpDiv);
74
+ this.markup.markupDiv.remove();
75
+ return;
76
+ }
77
+ IModelApp.toolAdmin.markupView = view; // so viewing tools won't operate on the view.
78
+ // set the markup Select tool as the default tool and start it, saving current default tool
79
+ this._saveDefaultToolId = IModelApp.toolAdmin.defaultToolId;
80
+ IModelApp.toolAdmin.defaultToolId = this.markupSelectToolId;
81
+ return IModelApp.toolAdmin.startDefaultTool();
82
+ }
83
+ /** Read the result of a Markup session, then stop the session.
84
+ * @note see [MarkupApp.props.result] for options.
85
+ */
86
+ static async stop() {
87
+ const data = await this.readMarkup();
88
+ if (!this.markup)
89
+ return data;
90
+ // restore original size for vp.
91
+ ScreenViewport.setToParentSize(this.markup.vp.vpDiv);
92
+ IModelApp.toolAdmin.markupView = undefined; // re-enable viewing tools for the view being marked-up
93
+ this.markup.destroy();
94
+ this.markup = undefined;
95
+ // now restore the default tool and start it
96
+ IModelApp.toolAdmin.defaultToolId = this._saveDefaultToolId;
97
+ this._saveDefaultToolId = "";
98
+ await IModelApp.toolAdmin.startDefaultTool();
99
+ return data;
100
+ }
101
+ /** Call this method to initialize the Markup system.
102
+ * It asynchronously loads the MarkupTools namespace for the prompts and tool names for the Markup system, and
103
+ * also registers all of the Markup tools.
104
+ * @return a Promise that may be awaited to ensure that the MarkupTools namespace had been loaded.
105
+ * @note This method is automatically called every time you call [[start]]. Since the Markup tools cannot
106
+ * start unless there is a Markup active, there's really no need to call this method directly.
107
+ * The only virtue in doing so is to pre-load the Markup namespace if you have an opportunity to do so earlier in your
108
+ * startup code.
109
+ * @note This method may be called multiple times, but only the first time initiates the loading/registering. Subsequent
110
+ * calls return the same Promise.
111
+ */
112
+ static async initialize() {
113
+ if (undefined === this.namespace) { // only need to do this once
114
+ this.namespace = "MarkupTools";
115
+ const namespacePromise = IModelApp.localization.registerNamespace(this.namespace);
116
+ IModelApp.tools.register(SelectTool, this.namespace);
117
+ IModelApp.tools.registerModule(redlineTool, this.namespace);
118
+ IModelApp.tools.registerModule(textTool, this.namespace);
119
+ return namespacePromise;
120
+ }
121
+ return IModelApp.localization.getNamespacePromise(this.namespace); // so caller can make sure localized messages are ready.
122
+ }
123
+ /** convert the current markup SVG into a string, but don't include decorations or dynamics
124
+ * @internal
125
+ */
126
+ static readMarkupSvg() {
127
+ const markup = this.markup;
128
+ if (!markup || !markup.svgContainer)
129
+ return undefined;
130
+ markup.svgDecorations.remove(); // we don't want the decorations or dynamics to be included
131
+ markup.svgDynamics.remove();
132
+ void IModelApp.toolAdmin.startDefaultTool();
133
+ return markup.svgContainer.svg(); // string-ize the SVG data
134
+ }
135
+ /** convert the current markup SVG into a string (after calling readMarkupSvg) making sure width and height are specified.
136
+ * @internal
137
+ */
138
+ static readMarkupSvgForDrawImage() {
139
+ const markup = this.markup;
140
+ if (!markup || !markup.svgContainer)
141
+ return undefined;
142
+ // Firefox requires width and height on top-level svg or drawImage does nothing, passing width/height to drawImage doesn't work.
143
+ const rect = markup.markupDiv.getBoundingClientRect();
144
+ markup.svgContainer.width(rect.width);
145
+ markup.svgContainer.height(rect.height);
146
+ return markup.svgContainer.svg(); // string-ize the SVG data
147
+ }
148
+ /** @internal */
149
+ static async readMarkup() {
150
+ const result = this.props.result;
151
+ let canvas = this.markup.vp.readImageToCanvas();
152
+ let svg, image;
153
+ try {
154
+ svg = this.readMarkupSvg(); // read the current svg data for the markup
155
+ const svgForImage = (svg && result.imprintSvgOnImage ? this.readMarkupSvgForDrawImage() : undefined);
156
+ if (svgForImage) {
157
+ const svgImage = await imageElementFromImageSource(new ImageSource(svgForImage, ImageSourceFormat.Svg));
158
+ canvas.getContext("2d").drawImage(svgImage, 0, 0); // draw markup svg onto view's canvas2d
159
+ }
160
+ // is the source view too wide? If so, we need to scale the image down.
161
+ if (canvas.width > result.maxWidth) {
162
+ // yes, we have to scale it down, create a new canvas and set the new canvas' size
163
+ const newCanvas = document.createElement("canvas");
164
+ newCanvas.width = result.maxWidth;
165
+ newCanvas.height = canvas.height * (result.maxWidth / canvas.width);
166
+ newCanvas.getContext("2d").drawImage(canvas, 0, 0, canvas.width, canvas.height, 0, 0, newCanvas.width, newCanvas.height);
167
+ canvas = newCanvas; // return the image from adjusted canvas, not view canvas.
168
+ }
169
+ // return the markup data to be saved by the application.
170
+ image = (!result.imageFormat ? undefined : canvas.toDataURL(result.imageFormat));
171
+ }
172
+ catch (e) {
173
+ Logger.logError(`${FrontendLoggerCategory.Package}.markup`, "Error creating image from svg", BentleyError.getErrorProps(e));
174
+ }
175
+ return { rect: { width: canvas.width, height: canvas.height }, svg, image };
176
+ }
177
+ /** @internal */
178
+ static get dropShadowId() { return `${this.markupPrefix}dropShadow`; } // this is referenced in the markup Svg to apply the drop-shadow filter to all markup elements.
179
+ /** @internal */
180
+ static get cornerId() { return `${this.markupPrefix}photoCorner`; }
181
+ /** @internal */
182
+ static get containerClass() { return `${this.markupPrefix}container`; }
183
+ /** @internal */
184
+ static get dynamicsClass() { return `${this.markupPrefix}dynamics`; }
185
+ /** @internal */
186
+ static get decorationsClass() { return `${this.markupPrefix}decorations`; }
187
+ /** @internal */
188
+ static get markupSvgClass() { return `${this.markupPrefix}svg`; }
189
+ /** @internal */
190
+ static get boxedTextClass() { return `${this.markupPrefix}boxedText`; }
191
+ /** @internal */
192
+ static get textClass() { return `${this.markupPrefix}text`; }
193
+ /** @internal */
194
+ static get stretchHandleClass() { return `${this.markupPrefix}stretchHandle`; }
195
+ /** @internal */
196
+ static get rotateLineClass() { return `${this.markupPrefix}rotateLine`; }
197
+ /** @internal */
198
+ static get rotateHandleClass() { return `${this.markupPrefix}rotateHandle`; }
199
+ /** @internal */
200
+ static get vertexHandleClass() { return `${this.markupPrefix}vertexHandle`; }
201
+ /** @internal */
202
+ static get moveHandleClass() { return `${this.markupPrefix}moveHandle`; }
203
+ /** @internal */
204
+ static get textOutlineClass() { return `${this.markupPrefix}textOutline`; }
205
+ /** @internal */
206
+ static get textEditorClass() { return `${this.markupPrefix}textEditor`; }
207
+ }
208
+ /** By setting members of this object, applications can control the appearance and behavior of various parts of MarkupApp. */
209
+ MarkupApp.props = {
210
+ /** the UI controls displayed on Elements by the Select Tool to allow users to modify them. */
211
+ handles: {
212
+ /** The diameter of the circles for the handles. */
213
+ size: 10,
214
+ /** The attributes of the stretch handles */
215
+ stretch: { "fill-opacity": .85, "stroke": "black", "fill": "white" },
216
+ /** The attributes of the line that connects the top-center stretch handle to the rotate handle. */
217
+ rotateLine: { "stroke": "grey", "fill-opacity": .85 },
218
+ /** The attributes of the rotate handle. */
219
+ rotate: { "cursor": `url(${IModelApp.publicPath}Markup/rotate.png) 12 12, auto`, "fill-opacity": .85, "stroke": "black", "fill": "lightBlue" },
220
+ /** The attributes of box around the element. */
221
+ moveOutline: { "cursor": "move", "stroke-dasharray": "6,6", "fill": "none", "stroke-opacity": .85, "stroke": "white" },
222
+ /** The attributes of box that provides the move cursor. */
223
+ move: { "cursor": "move", "opacity": 0, "stroke-width": 10, "stroke": "white" },
224
+ /** The attributes of handles on the vertices of lines. */
225
+ vertex: { "cursor": `url(${IModelApp.publicPath}cursors/crosshair.cur), crosshair`, "fill-opacity": .85, "stroke": "black", "fill": "white" },
226
+ },
227
+ /** properties for providing feedback about selected elements. */
228
+ hilite: {
229
+ /** the color of selected elements */
230
+ color: "magenta",
231
+ /** the color of an element as the cursor passes over it */
232
+ flash: "cyan",
233
+ },
234
+ /** optionally, show a drop-shadow behind all markup elements. */
235
+ dropShadow: {
236
+ /** if false, no drop shadow */
237
+ enable: true,
238
+ /** the attributes of the drop shadow. See https://developer.mozilla.org/en-US/docs/Web/SVG/Element/feDropShadow */
239
+ attr: {
240
+ "stdDeviation": 2,
241
+ "dx": 1.2,
242
+ "dy": 1.4,
243
+ "flood-color": "#1B3838",
244
+ },
245
+ },
246
+ /** The "active placement" parameters. New elements are created with these parameters, so UI controls should set them. */
247
+ active: {
248
+ /** the CSS style properties of new text elements. */
249
+ text: {
250
+ "font-family": "sans-serif",
251
+ "font-size": "30px",
252
+ "stroke": "none",
253
+ "fill": "red",
254
+ },
255
+ /** the CSS style properties of new elements. */
256
+ element: {
257
+ "stroke": "red",
258
+ "stroke-opacity": 0.8,
259
+ "stroke-width": 3,
260
+ "stroke-dasharray": 0,
261
+ "stroke-linecap": "round",
262
+ "stroke-linejoin": "round",
263
+ "fill": "blue",
264
+ "fill-opacity": 0.2,
265
+ },
266
+ arrow: {
267
+ length: 7,
268
+ width: 6,
269
+ },
270
+ cloud: {
271
+ path: "M3.0,2.5 C3.9,.78 5.6,-.4 8.1,1.0 C9.1,0 11.3,-.2 12.5,.5 C14.2,-.5 17,.16 17.9,2.5 C21,3 20.2,7.3 17.6,7.5 C16.5,9.2 14.4,9.8 12.7,8.9 C11.6,10 9.5,10.3 8.1,9.4 C5.7,10.8 3.3,9.4 2.6,7.5 C-.9,7.7 .6,1.7 3.0,2.5z",
272
+ },
273
+ },
274
+ /** Values for placing and editing Text. */
275
+ text: {
276
+ /** A default string for the Markup.Text.Place command. Applications can turn this off, or supply the user's initials, for example. */
277
+ startValue: "Note: ",
278
+ /** Parameters for the size and appearance of the text editor */
279
+ edit: {
280
+ background: "blanchedalmond",
281
+ /** Starting size, will be updated if user stretches the box */
282
+ size: { width: "25%", height: "4em" },
283
+ /** font size of the text editor */
284
+ fontSize: "14pt",
285
+ /** A background box drawn around text so user can tell what's being selected */
286
+ textBox: { "fill": "lightGrey", "fill-opacity": .1, "stroke-opacity": .85, "stroke": "lightBlue" },
287
+ },
288
+ },
289
+ /** Used to draw the border outline around the view while it is being marked up so the user can tell Markup is active */
290
+ borderOutline: {
291
+ "stroke": "gold",
292
+ "stroke-width": 6,
293
+ "stroke-opacity": 0.4,
294
+ "fill": "none",
295
+ },
296
+ /** Used to draw the border corner symbols for the view while it is being marked up so the user can tell Markup is active */
297
+ borderCorners: {
298
+ "stroke": "black",
299
+ "stroke-width": 2,
300
+ "stroke-opacity": 0.2,
301
+ "fill": "gold",
302
+ "fill-opacity": 0.2,
303
+ },
304
+ /** Determines what is returned by MarkupApp.stop */
305
+ result: {
306
+ /** The format for the image data. */
307
+ imageFormat: "image/png",
308
+ /** If true, the markup graphics will be imprinted in the returned image. */
309
+ imprintSvgOnImage: true,
310
+ /** the maximum width for the returned image. If the source view width is larger than this, it will be scaled down to this size. */
311
+ maxWidth: 2048,
312
+ },
313
+ };
314
+ MarkupApp._saveDefaultToolId = "";
315
+ MarkupApp.markupSelectToolId = "Markup.Select";
316
+ /** @internal */
317
+ MarkupApp.markupPrefix = "markup-";
318
+ export { MarkupApp };
319
+ const removeSvgNamespace = (svg) => {
320
+ svg.node.removeAttribute("xmlns:svgjs");
321
+ return svg;
322
+ };
323
+ const newSvgElement = (name) => adopt(create(name));
324
+ /**
325
+ * The current markup being created/edited. Holds the SVG elements, plus the active [[MarkupTool]].
326
+ * When starting a Markup, a new Div is added as a child of the ScreenViewport's vpDiv.
327
+ * @public
328
+ */
329
+ export class Markup {
330
+ /** create the drop-shadow filter in the Defs section of the supplied svg element */
331
+ createDropShadow(svg) {
332
+ const filter = SVG(`#${MarkupApp.dropShadowId}`); // see if we already have one?
333
+ if (filter)
334
+ filter.remove(); // yes, remove it. This must be someone modifying the drop shadow properties
335
+ // create a new filter, and add it to the Defs of the supplied svg
336
+ svg.defs()
337
+ .add(newSvgElement("filter").id(MarkupApp.dropShadowId)
338
+ .add(newSvgElement("feDropShadow").attr(MarkupApp.props.dropShadow.attr)));
339
+ }
340
+ addNested(className) { return this.svgContainer.group().addClass(className); }
341
+ addBorder() {
342
+ const rect = this.svgContainer.viewbox();
343
+ const inset = MarkupApp.props.borderOutline["stroke-width"];
344
+ const cornerSize = inset * 6;
345
+ const cornerPts = [0, 0, cornerSize, 0, cornerSize * .7, cornerSize * .3, cornerSize * .3, cornerSize * .3, cornerSize * .3, cornerSize * .7, 0, cornerSize];
346
+ const decorations = this.svgDecorations;
347
+ const photoCorner = decorations.symbol().polygon(cornerPts).attr(MarkupApp.props.borderCorners).id(MarkupApp.cornerId);
348
+ const cornerGroup = decorations.group();
349
+ cornerGroup.rect(rect.width - inset, rect.height - inset).move(inset / 2, inset / 2).attr(MarkupApp.props.borderOutline);
350
+ cornerGroup.use(photoCorner);
351
+ cornerGroup.use(photoCorner).rotate(90).translate(rect.width - cornerSize, 0);
352
+ cornerGroup.use(photoCorner).rotate(180).translate(rect.width - cornerSize, rect.height - cornerSize);
353
+ cornerGroup.use(photoCorner).rotate(270).translate(0, rect.height - cornerSize);
354
+ }
355
+ /** Create a new Markup for the supplied ScreenViewport. Adds a new "overlay-markup" div into the "vpDiv"
356
+ * of the viewport.
357
+ * @note you must call destroy on this object at end of markup to remove the markup div.
358
+ */
359
+ constructor(vp, markupData) {
360
+ this.vp = vp;
361
+ /** Support undo/redo of markup operations */
362
+ this.undo = new UndoManager();
363
+ this.markupDiv = vp.addNewDiv("overlay-markup", true, 20); // this div goes on top of the canvas, but behind UI layers
364
+ const rect = this.markupDiv.getBoundingClientRect();
365
+ // First, see if there is a markup passed in as an argument
366
+ if (markupData && markupData.svg) {
367
+ this.markupDiv.innerHTML = markupData.svg; // make it a child of the markupDiv
368
+ this.svgContainer = SVG(`.${MarkupApp.containerClass}`); // get it in svg.js format
369
+ this.svgMarkup = SVG(`.${MarkupApp.markupSvgClass}`);
370
+ if (!this.svgContainer || !this.svgMarkup) // if either isn't present, its not a valid markup
371
+ return;
372
+ removeSvgNamespace(this.svgContainer); // the SVG call above adds this - remove it
373
+ this.svgMarkup.each(() => { }, true); // create an SVG.Element for each entry in the supplied markup.
374
+ }
375
+ else {
376
+ // create the container that will be returned as the "svg" data for this markup
377
+ this.svgContainer = SVG().addTo(this.markupDiv).addClass(MarkupApp.containerClass).viewbox(0, 0, rect.width, rect.height);
378
+ removeSvgNamespace(this.svgContainer);
379
+ this.svgMarkup = this.addNested(MarkupApp.markupSvgClass);
380
+ }
381
+ if (MarkupApp.props.dropShadow.enable) {
382
+ this.createDropShadow(this.svgContainer);
383
+ this.svgContainer.attr("filter", `url(#${MarkupApp.dropShadowId})`);
384
+ }
385
+ /** add two nested groups for providing feedback during the markup session. These Svgs are removed before the data is returned. */
386
+ this.svgDynamics = this.addNested(MarkupApp.dynamicsClass); // only for tool dynamics of SVG graphics.
387
+ this.svgDecorations = this.addNested(MarkupApp.decorationsClass); // only for temporary decorations of SVG graphics.
388
+ this.addBorder();
389
+ this.selected = new MarkupSelected(this.svgDecorations);
390
+ }
391
+ /** Called when the Markup is destroyed */
392
+ destroy() { this.markupDiv.remove(); }
393
+ /** Turn on picking the markup elements in the markup view */
394
+ enablePick() { this.markupDiv.style.pointerEvents = "auto"; }
395
+ /** Turn off picking the markup elements in the markup view */
396
+ disablePick() { this.markupDiv.style.pointerEvents = "none"; }
397
+ /** Change the default cursor for the markup view */
398
+ setCursor(cursor) { this.markupDiv.style.cursor = cursor; }
399
+ /** Delete all the entries in the selection set, then empty it. */
400
+ deleteSelected() { this.selected.deleteAll(this.undo); }
401
+ /** Bring all the entries in the selection set to the front. */
402
+ bringToFront() { this.selected.reposition(MarkupApp.getActionName("toFront"), this.undo, (el) => el.front()); }
403
+ /** Send all the entries in the selection set to the back. */
404
+ sendToBack() { this.selected.reposition(MarkupApp.getActionName("toBack"), this.undo, (el) => el.back()); }
405
+ /** Group all the entries in the selection set, then select the group. */
406
+ groupSelected() {
407
+ if (undefined !== this.svgMarkup)
408
+ this.selected.groupAll(this.undo);
409
+ }
410
+ /** Ungroup all the group entries in the selection set. */
411
+ ungroupSelected() {
412
+ if (undefined !== this.svgMarkup)
413
+ this.selected.ungroupAll(this.undo);
414
+ }
415
+ /** Check if the supplied MarkupElement is a group of MarkupText and the MarkupText's outline Rect.
416
+ * @param el the markup element to check
417
+ * @returns true if boxed text
418
+ */
419
+ isBoxedText(el) {
420
+ return el.type === "g" &&
421
+ el.node.classList.length > 0 &&
422
+ el.node.classList[0] === MarkupApp.boxedTextClass &&
423
+ el.children().length === 2;
424
+ }
425
+ /** Get an existing or create a new reusable symbol representing an arrow head.
426
+ * If a Marker for the supplied color and size already exists it is returned, otherwise a new Marker is created.
427
+ * @param color the arrow head color
428
+ * @param length the arrow head length
429
+ * @param width the arrow head width
430
+ * @note Flashing doesn't currently affect markers, need support for "context-stroke" and "context-fill". For now encode color in name...
431
+ */
432
+ createArrowMarker(color, length, width) {
433
+ length = Math.ceil(length); // Don't allow "." in selector string...
434
+ width = Math.ceil(width);
435
+ const arrowMarkerId = `ArrowMarker${length}x${width}-${color}`;
436
+ let marker = SVG(`#${arrowMarkerId}`);
437
+ if (null === marker) {
438
+ marker = this.svgMarkup.marker(length, width).id(arrowMarkerId);
439
+ marker.polygon([0, 0, length, width * 0.5, 0, width]);
440
+ marker.attr("orient", "auto-start-reverse");
441
+ marker.attr("overflow", "visible"); // Don't clip the stroke that is being applied to allow the specified start/end to be used directly while hiding the arrow tail fully under the arrow head...
442
+ marker.attr("refX", length);
443
+ marker.css({ stroke: color, fill: color });
444
+ }
445
+ return marker;
446
+ }
447
+ }
416
448
  //# sourceMappingURL=Markup.js.map