@widgetic/canvas 0.5.40 → 0.5.41

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 (120) hide show
  1. package/README.md +7 -3
  2. package/dist/canvas/DomCanvas.svelte +4 -0
  3. package/dist/canvas/DomCanvas.svelte.d.ts +8 -0
  4. package/dist/canvas/autosaveScheduler.js +89 -37
  5. package/dist/canvas/boardFrame.js +1 -1
  6. package/dist/canvas/boardSurface.js +1 -1
  7. package/dist/canvas/canvasLogger.js +19 -7
  8. package/dist/canvas/chromeLayout.js +18 -17
  9. package/dist/canvas/eventScope.js +14 -10
  10. package/dist/canvas/host/CanvasHost.d.ts +6 -0
  11. package/dist/canvas/host/CanvasHost.js +1556 -1267
  12. package/dist/canvas/host/CanvasHostApi.d.ts +2 -2
  13. package/dist/canvas/host/CanvasHostApi.js +25 -4
  14. package/dist/canvas/host/browserServices.js +116 -65
  15. package/dist/canvas/host/conversion.js +170 -82
  16. package/dist/canvas/host/hostObject.js +7 -7
  17. package/dist/canvas/host/pageEvents.js +4 -4
  18. package/dist/canvas/host/screenRects.js +31 -28
  19. package/dist/canvas/host/strokeSnap.js +143 -88
  20. package/dist/canvas/openMarks.js +2 -2
  21. package/dist/canvas/outsideClickDeselect.js +7 -6
  22. package/dist/canvas/panZoomPosition.js +2 -2
  23. package/dist/canvas/preferredTextFont.js +25 -13
  24. package/dist/canvas/shapes/ShapeLibrary.js +148 -138
  25. package/dist/canvas/shapes/shapeImageStore.js +3 -3
  26. package/dist/canvas/shapes/strokeShapeSnap.js +233 -188
  27. package/dist/canvas/toolbarPosition.js +2 -2
  28. package/dist/canvas/ui/CanvasHint.svelte +16 -3
  29. package/dist/canvas/ui/CanvasHint.svelte.d.ts +2 -17
  30. package/dist/canvas/ui/CanvasToolbar.svelte +7 -7
  31. package/dist/canvas/ui/ToolButton.svelte +11 -3
  32. package/dist/canvas/ui/ToolButton.svelte.d.ts +2 -0
  33. package/dist/canvas/ui/colorModel.js +32 -21
  34. package/dist/canvas/ui/colorPickerMessages.js +5 -5
  35. package/dist/canvas/ui/floatingCard.js +18 -18
  36. package/dist/canvas/ui/floatingLayer.js +6 -5
  37. package/dist/canvas/ui/keyHints.js +11 -9
  38. package/dist/canvas/ui/popoverSide.js +3 -2
  39. package/dist/canvas/ui/selectionTraits.js +40 -34
  40. package/dist/canvas/ui/sizeLabelVisibility.d.ts +1 -1
  41. package/dist/canvas/ui/sizeLabelVisibility.js +1 -1
  42. package/dist/canvas/view/SelectionOverlay.svelte +33 -14
  43. package/dist/canvas/view/erasingMarks.js +7 -7
  44. package/dist/canvas/view/geometry.d.ts +14 -4
  45. package/dist/canvas/view/geometry.js +103 -77
  46. package/dist/components/preferenceStorage.js +2 -2
  47. package/dist/engine/EngineCore.d.ts +4 -1
  48. package/dist/engine/EngineCore.js +801 -695
  49. package/dist/engine/codec/canvasDocument.js +173 -173
  50. package/dist/engine/codec/hostReadableKeys.js +1 -1
  51. package/dist/engine/core/arrange.js +38 -26
  52. package/dist/engine/core/arrow.d.ts +10 -3
  53. package/dist/engine/core/arrow.js +96 -75
  54. package/dist/engine/core/arrowBinding.d.ts +69 -0
  55. package/dist/engine/core/arrowBinding.js +344 -0
  56. package/dist/engine/core/arrowBindingRecords.d.ts +43 -0
  57. package/dist/engine/core/arrowBindingRecords.js +141 -0
  58. package/dist/engine/core/brush.js +94 -67
  59. package/dist/engine/core/defaults.js +51 -90
  60. package/dist/engine/core/freehand.js +163 -147
  61. package/dist/engine/core/geometry.js +54 -47
  62. package/dist/engine/core/history.js +50 -33
  63. package/dist/engine/core/hitTest.d.ts +3 -0
  64. package/dist/engine/core/hitTest.js +83 -69
  65. package/dist/engine/core/matrix.js +20 -18
  66. package/dist/engine/core/pathData.js +210 -183
  67. package/dist/engine/core/rotationReset.js +6 -5
  68. package/dist/engine/core/scene.d.ts +3 -0
  69. package/dist/engine/core/scene.js +192 -129
  70. package/dist/engine/core/scribble.js +84 -59
  71. package/dist/engine/core/shapePaths.js +15 -12
  72. package/dist/engine/core/shapeTools.js +63 -72
  73. package/dist/engine/core/snapping.js +117 -65
  74. package/dist/engine/core/style.js +64 -31
  75. package/dist/engine/core/transform.js +94 -83
  76. package/dist/engine/core/types.d.ts +29 -0
  77. package/dist/engine/core/types.js +4 -4
  78. package/dist/engine/core/viewport.js +36 -23
  79. package/dist/engine/input/PointerController.js +476 -447
  80. package/dist/engine/input/arrowHandles.js +12 -12
  81. package/dist/engine/input/gestures.d.ts +12 -1
  82. package/dist/engine/input/gestures.js +342 -251
  83. package/dist/engine/input/hoverCursor.js +1 -1
  84. package/dist/engine/input/keyboard.d.ts +9 -1
  85. package/dist/engine/input/keyboard.js +46 -27
  86. package/dist/engine/input/selectionHandles.js +50 -45
  87. package/dist/engine/input/types.js +1 -1
  88. package/dist/engine/render/rasterize.js +158 -86
  89. package/dist/engine/state.d.ts +6 -1
  90. package/dist/engine/state.js +17 -5
  91. package/dist/engine/text/layoutText.js +62 -43
  92. package/dist/engine/text/textMetrics.js +10 -8
  93. package/dist/engine/widgets.js +137 -101
  94. package/dist/fonts/interFont.js +68 -17
  95. package/dist/fonts/workspaceFonts.js +90 -32
  96. package/dist/i18n/labels.js +4 -4
  97. package/dist/i18n/language.js +4 -4
  98. package/dist/i18n/messages.js +1 -1
  99. package/dist/i18n/shortcuts.d.ts +12 -0
  100. package/dist/i18n/shortcuts.js +32 -18
  101. package/dist/settings/workspaceToolSettings.js +48 -32
  102. package/dist/tools/components/catalog.d.ts +11 -0
  103. package/dist/tools/components/catalog.js +270 -0
  104. package/dist/tools/components/grouping.d.ts +9 -0
  105. package/dist/tools/components/grouping.js +33 -0
  106. package/dist/tools/definitions.d.ts +19 -0
  107. package/dist/tools/definitions.js +147 -0
  108. package/dist/tools/executors.d.ts +7 -0
  109. package/dist/tools/executors.js +324 -0
  110. package/dist/tools/hostAdapter.d.ts +14 -0
  111. package/dist/tools/hostAdapter.js +40 -0
  112. package/dist/tools/index.d.ts +6 -0
  113. package/dist/tools/index.js +6 -0
  114. package/dist/tools/sceneSummary.d.ts +24 -0
  115. package/dist/tools/sceneSummary.js +170 -0
  116. package/dist/tools/sketchIntent.d.ts +17 -0
  117. package/dist/tools/sketchIntent.js +166 -0
  118. package/dist/tools/types.d.ts +54 -0
  119. package/dist/tools/types.js +11 -0
  120. package/package.json +7 -2
@@ -19,33 +19,45 @@
19
19
  * Pure functions on plain numbers: they run in Node as they do in the browser, and the editor, the eraser's trail and the
20
20
  * rasterizer all draw from the same outline.
21
21
  */
22
+ var __assign = (this && this.__assign) || function () {
23
+ __assign = Object.assign || function(t) {
24
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
25
+ s = arguments[i];
26
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
27
+ t[p] = s[p];
28
+ }
29
+ return t;
30
+ };
31
+ return __assign.apply(this, arguments);
32
+ };
22
33
  // How fast a simulated pressure follows the speed of the hand.
23
- const RATE_OF_PRESSURE_CHANGE = 0.275;
34
+ var RATE_OF_PRESSURE_CHANGE = 0.275;
24
35
  // A half turn that is a hair more than π: a cap built from exactly π leaves a visible seam in browsers.
25
- const HALF_TURN = Math.PI + 0.0001;
36
+ var HALF_TURN = Math.PI + 0.0001;
26
37
  // The outline of a corner is built from this many steps of a half turn, and a round end cap from this many of one and a half.
27
- const CORNER_STEPS = 13;
28
- const END_CAP_STEPS = 29;
38
+ var CORNER_STEPS = 13;
39
+ var END_CAP_STEPS = 29;
29
40
  // A turn sharper than this (the dot product of two directions) is a corner that gets a round join.
30
- const SHARP_CORNER = 0;
41
+ var SHARP_CORNER = 0;
31
42
  // The end of a line within this distance of its last point is dropped from the outline: it is only noise.
32
- const END_NOISE_DISTANCE = 3;
43
+ var END_NOISE_DISTANCE = 3;
33
44
  // ───────────────────────────────────────────────────────────────────────── easings
34
- export const EASE_LINEAR = (progress) => progress;
35
- export const EASE_OUT_SINE = (progress) => Math.sin((progress * Math.PI) / 2);
45
+ export var EASE_LINEAR = function (progress) { return progress; };
46
+ export var EASE_OUT_SINE = function (progress) { return Math.sin((progress * Math.PI) / 2); };
36
47
  /** The easing of a pen's pressure: mostly linear, with a little of the sine's softness. */
37
- export const EASE_PEN = (progress) => progress * 0.65 + Math.sin((progress * Math.PI) / 2) * 0.35;
38
- const EASE_OUT_QUADRATIC = (progress) => progress * (2 - progress);
39
- const EASE_OUT_CUBIC = (progress) => (progress - 1) * (progress - 1) * (progress - 1) + 1;
48
+ export var EASE_PEN = function (progress) { return progress * 0.65 + Math.sin((progress * Math.PI) / 2) * 0.35; };
49
+ var EASE_OUT_QUADRATIC = function (progress) { return progress * (2 - progress); };
50
+ var EASE_OUT_CUBIC = function (progress) { return (progress - 1) * (progress - 1) * (progress - 1) + 1; };
40
51
  // ───────────────────────────────────────────────────────────────────────── the line of points
41
52
  /** The samples that can be used: finite coordinates, and a pressure that is either 0 to 1 or negative for unknown. */
42
53
  function usableSamples(samples) {
43
- const usable = [];
44
- for (const sample of samples) {
54
+ var usable = [];
55
+ for (var _i = 0, samples_1 = samples; _i < samples_1.length; _i++) {
56
+ var sample = samples_1[_i];
45
57
  if (!Number.isFinite(sample.x) || !Number.isFinite(sample.y))
46
58
  continue;
47
- const pressure = sample.pressure !== undefined && Number.isFinite(sample.pressure) && sample.pressure >= 0 ? Math.min(1, sample.pressure) : -1;
48
- usable.push({ x: sample.x, y: sample.y, pressure });
59
+ var pressure = sample.pressure !== undefined && Number.isFinite(sample.pressure) && sample.pressure >= 0 ? Math.min(1, sample.pressure) : -1;
60
+ usable.push({ x: sample.x, y: sample.y, pressure: pressure });
49
61
  }
50
62
  return usable;
51
63
  }
@@ -56,20 +68,21 @@ function usableSamples(samples) {
56
68
  * A finished line (`last`) ends exactly on the last sample.
57
69
  */
58
70
  export function strokePointsOf(samples, options) {
59
- const size = options.size;
60
- const streamline = options.streamline ?? 0.5;
61
- const finished = options.last === true;
62
- let line = usableSamples(samples);
71
+ var _a;
72
+ var size = options.size;
73
+ var streamline = (_a = options.streamline) !== null && _a !== void 0 ? _a : 0.5;
74
+ var finished = options.last === true;
75
+ var line = usableSamples(samples);
63
76
  if (line.length === 0)
64
77
  return [];
65
78
  // How far a point moves towards the next sample: 1 would follow the hand exactly.
66
- const follow = 0.15 + (1 - streamline) * 0.85;
79
+ var follow = 0.15 + (1 - streamline) * 0.85;
67
80
  if (line.length === 2) {
68
81
  // Two samples are a straight line: points are put between them so that it is drawn as a longer line is.
69
- const [first, second] = line;
82
+ var first = line[0], second = line[1];
70
83
  line = [first];
71
- for (let step = 1; step < 5; step += 1) {
72
- const progress = step / 4;
84
+ for (var step = 1; step < 5; step += 1) {
85
+ var progress = step / 4;
73
86
  line.push({
74
87
  x: first.x + (second.x - first.x) * progress,
75
88
  y: first.y + (second.y - first.y) * progress,
@@ -79,23 +92,23 @@ export function strokePointsOf(samples, options) {
79
92
  }
80
93
  if (line.length === 1) {
81
94
  // A click is a dot: a second point a pixel away gives it a direction.
82
- line = [line[0], { ...line[0], x: line[0].x + 1, y: line[0].y + 1 }];
95
+ line = [line[0], __assign(__assign({}, line[0]), { x: line[0].x + 1, y: line[0].y + 1 })];
83
96
  }
84
- const points = [
97
+ var points = [
85
98
  { x: line[0].x, y: line[0].y, pressure: line[0].pressure >= 0 ? line[0].pressure : 0.25, vectorX: 1, vectorY: 1, distance: 0, runningLength: 0 }
86
99
  ];
87
- let reachedMinimumLength = false;
88
- let runningLength = 0;
89
- let previous = points[0];
90
- const lastIndex = line.length - 1;
91
- for (let index = 1; index < line.length; index += 1) {
92
- const sample = line[index];
93
- const atEnd = finished && index === lastIndex;
94
- const x = atEnd ? sample.x : previous.x + (sample.x - previous.x) * follow;
95
- const y = atEnd ? sample.y : previous.y + (sample.y - previous.y) * follow;
100
+ var reachedMinimumLength = false;
101
+ var runningLength = 0;
102
+ var previous = points[0];
103
+ var lastIndex = line.length - 1;
104
+ for (var index = 1; index < line.length; index += 1) {
105
+ var sample = line[index];
106
+ var atEnd = finished && index === lastIndex;
107
+ var x = atEnd ? sample.x : previous.x + (sample.x - previous.x) * follow;
108
+ var y = atEnd ? sample.y : previous.y + (sample.y - previous.y) * follow;
96
109
  if (x === previous.x && y === previous.y)
97
110
  continue;
98
- const distance = Math.hypot(x - previous.x, y - previous.y);
111
+ var distance = Math.hypot(x - previous.x, y - previous.y);
99
112
  runningLength += distance;
100
113
  // The start of the line, shorter than the brush is wide, only makes it wobble.
101
114
  if (index < lastIndex && !reachedMinimumLength) {
@@ -103,14 +116,14 @@ export function strokePointsOf(samples, options) {
103
116
  continue;
104
117
  reachedMinimumLength = true;
105
118
  }
106
- const next = {
107
- x,
108
- y,
119
+ var next = {
120
+ x: x,
121
+ y: y,
109
122
  pressure: sample.pressure >= 0 ? sample.pressure : 0.5,
110
123
  vectorX: (previous.x - x) / distance,
111
124
  vectorY: (previous.y - y) / distance,
112
- distance,
113
- runningLength
125
+ distance: distance,
126
+ runningLength: runningLength
114
127
  };
115
128
  points.push(next);
116
129
  previous = next;
@@ -128,15 +141,15 @@ function radiusFor(size, thinning, pressure, easing) {
128
141
  /** A pressure that follows the speed of the hand: a point close to the one before presses, a far one lifts. */
129
142
  function simulatedPressure(previousPressure, distance, size) {
130
143
  // How fast the hand moves, in brush widths per point, and what is left of the stillness.
131
- const speed = Math.min(1, distance / size);
132
- const stillness = Math.min(1, 1 - speed);
144
+ var speed = Math.min(1, distance / size);
145
+ var stillness = Math.min(1, 1 - speed);
133
146
  return Math.min(1, previousPressure + (stillness - previousPressure) * (speed * RATE_OF_PRESSURE_CHANGE));
134
147
  }
135
148
  function rotateAbout(point, center, angle) {
136
- const cosine = Math.cos(angle);
137
- const sine = Math.sin(angle);
138
- const offsetX = point.x - center.x;
139
- const offsetY = point.y - center.y;
149
+ var cosine = Math.cos(angle);
150
+ var sine = Math.sin(angle);
151
+ var offsetX = point.x - center.x;
152
+ var offsetY = point.y - center.y;
140
153
  return { x: center.x + offsetX * cosine - offsetY * sine, y: center.y + offsetX * sine + offsetY * cosine };
141
154
  }
142
155
  /** The length a tapered end narrows over. */
@@ -159,43 +172,45 @@ export function outlineOf(points, options) {
159
172
  * from these (with `simulatePressure` off) and come out the same, whatever size its points are later scaled to.
160
173
  */
161
174
  export function outlineWithPressures(points, options) {
162
- const size = options.size;
163
- const thinning = options.thinning ?? 0.5;
164
- const smoothing = options.smoothing ?? 0.5;
165
- const simulate = options.simulatePressure ?? true;
166
- const easing = options.easing ?? EASE_LINEAR;
167
- const finished = options.last === true;
168
- const startCap = options.start?.cap ?? true;
169
- const endCap = options.end?.cap ?? true;
170
- const startEasing = options.start?.easing ?? EASE_OUT_QUADRATIC;
171
- const endEasing = options.end?.easing ?? EASE_OUT_CUBIC;
175
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
176
+ var size = options.size;
177
+ var thinning = (_a = options.thinning) !== null && _a !== void 0 ? _a : 0.5;
178
+ var smoothing = (_b = options.smoothing) !== null && _b !== void 0 ? _b : 0.5;
179
+ var simulate = (_c = options.simulatePressure) !== null && _c !== void 0 ? _c : true;
180
+ var easing = (_d = options.easing) !== null && _d !== void 0 ? _d : EASE_LINEAR;
181
+ var finished = options.last === true;
182
+ var startCap = (_f = (_e = options.start) === null || _e === void 0 ? void 0 : _e.cap) !== null && _f !== void 0 ? _f : true;
183
+ var endCap = (_h = (_g = options.end) === null || _g === void 0 ? void 0 : _g.cap) !== null && _h !== void 0 ? _h : true;
184
+ var startEasing = (_k = (_j = options.start) === null || _j === void 0 ? void 0 : _j.easing) !== null && _k !== void 0 ? _k : EASE_OUT_QUADRATIC;
185
+ var endEasing = (_m = (_l = options.end) === null || _l === void 0 ? void 0 : _l.easing) !== null && _m !== void 0 ? _m : EASE_OUT_CUBIC;
172
186
  if (points.length === 0 || !(size > 0))
173
187
  return { outline: [], pressures: [] };
174
- const pressures = points.map((point) => point.pressure);
175
- const totalLength = points[points.length - 1].runningLength;
176
- const taperStart = taperLength(options.start?.taper, size, totalLength);
177
- const taperEnd = taperLength(options.end?.taper, size, totalLength);
188
+ var pressures = points.map(function (point) { return point.pressure; });
189
+ var totalLength = points[points.length - 1].runningLength;
190
+ var taperStart = taperLength((_o = options.start) === null || _o === void 0 ? void 0 : _o.taper, size, totalLength);
191
+ var taperEnd = taperLength((_p = options.end) === null || _p === void 0 ? void 0 : _p.taper, size, totalLength);
178
192
  // The least distance between two points of one side of the outline (squared): closer points add a wobble and nothing else.
179
- const minimumGapSquared = (size * smoothing) ** 2;
180
- const left = [];
181
- const right = [];
193
+ var minimumGapSquared = Math.pow((size * smoothing), 2);
194
+ var left = [];
195
+ var right = [];
182
196
  // The pressure the line starts from: the mean of its first ten points.
183
- let previousPressure = points[0].pressure;
184
- for (const point of points.slice(0, 10)) {
185
- const pressure = simulate ? simulatedPressure(previousPressure, point.distance, size) : point.pressure;
197
+ var previousPressure = points[0].pressure;
198
+ for (var _i = 0, _q = points.slice(0, 10); _i < _q.length; _i++) {
199
+ var point = _q[_i];
200
+ var pressure = simulate ? simulatedPressure(previousPressure, point.distance, size) : point.pressure;
186
201
  previousPressure = (previousPressure + pressure) / 2;
187
202
  }
188
- let radius = radiusFor(size, thinning, points[points.length - 1].pressure, easing);
189
- let firstRadius;
190
- let previousVectorX = points[0].vectorX;
191
- let previousVectorY = points[0].vectorY;
192
- let previousLeft = { x: points[0].x, y: points[0].y };
193
- let previousRight = previousLeft;
194
- let previousWasSharpCorner = false;
195
- for (let index = 0; index < points.length; index += 1) {
196
- const point = points[index];
197
- let pressure = point.pressure;
198
- const isLast = index === points.length - 1;
203
+ var radius = radiusFor(size, thinning, points[points.length - 1].pressure, easing);
204
+ var firstRadius;
205
+ var previousVectorX = points[0].vectorX;
206
+ var previousVectorY = points[0].vectorY;
207
+ var previousLeft = { x: points[0].x, y: points[0].y };
208
+ var previousRight = previousLeft;
209
+ var previousWasSharpCorner = false;
210
+ for (var index = 0; index < points.length; index += 1) {
211
+ var point = points[index];
212
+ var pressure = point.pressure;
213
+ var isLast = index === points.length - 1;
199
214
  // The very end of a line is noise: leave it out and let the last point finish the line.
200
215
  if (!isLast && totalLength - point.runningLength < END_NOISE_DISTANCE) {
201
216
  pressures[index] = previousPressure;
@@ -214,25 +229,25 @@ export function outlineWithPressures(points, options) {
214
229
  if (firstRadius === undefined)
215
230
  firstRadius = radius;
216
231
  // A tapered end narrows over its length, and the narrower of the two ends wins where they meet.
217
- const startTaper = point.runningLength < taperStart ? startEasing(point.runningLength / taperStart) : 1;
218
- const endTaper = totalLength - point.runningLength < taperEnd ? endEasing((totalLength - point.runningLength) / taperEnd) : 1;
232
+ var startTaper = point.runningLength < taperStart ? startEasing(point.runningLength / taperStart) : 1;
233
+ var endTaper = totalLength - point.runningLength < taperEnd ? endEasing((totalLength - point.runningLength) / taperEnd) : 1;
219
234
  radius = Math.max(0.01, radius * Math.min(startTaper, endTaper));
220
- const next = isLast ? point : points[index + 1];
221
- const nextDot = isLast ? 1 : point.vectorX * next.vectorX + point.vectorY * next.vectorY;
222
- const previousDot = point.vectorX * previousVectorX + point.vectorY * previousVectorY;
223
- const isSharpCorner = previousDot < SHARP_CORNER && !previousWasSharpCorner;
224
- const nextIsSharpCorner = nextDot < SHARP_CORNER;
235
+ var next = isLast ? point : points[index + 1];
236
+ var nextDot = isLast ? 1 : point.vectorX * next.vectorX + point.vectorY * next.vectorY;
237
+ var previousDot = point.vectorX * previousVectorX + point.vectorY * previousVectorY;
238
+ var isSharpCorner = previousDot < SHARP_CORNER && !previousWasSharpCorner;
239
+ var nextIsSharpCorner = nextDot < SHARP_CORNER;
225
240
  if (isSharpCorner || nextIsSharpCorner) {
226
241
  // A sharp corner is a half turn round the point, on both sides, and the line goes on from there.
227
- const offsetX = previousVectorY * radius;
228
- const offsetY = -previousVectorX * radius;
229
- let lastLeft = previousLeft;
230
- let lastRight = previousRight;
231
- for (let step = 0; step <= CORNER_STEPS; step += 1) {
232
- const turn = HALF_TURN * (step / CORNER_STEPS);
233
- lastLeft = rotateAbout({ x: point.x - offsetX, y: point.y - offsetY }, point, turn);
242
+ var offsetX_1 = previousVectorY * radius;
243
+ var offsetY_1 = -previousVectorX * radius;
244
+ var lastLeft = previousLeft;
245
+ var lastRight = previousRight;
246
+ for (var step = 0; step <= CORNER_STEPS; step += 1) {
247
+ var turn = HALF_TURN * (step / CORNER_STEPS);
248
+ lastLeft = rotateAbout({ x: point.x - offsetX_1, y: point.y - offsetY_1 }, point, turn);
234
249
  left.push(lastLeft);
235
- lastRight = rotateAbout({ x: point.x + offsetX, y: point.y + offsetY }, point, -turn);
250
+ lastRight = rotateAbout({ x: point.x + offsetX_1, y: point.y + offsetY_1 }, point, -turn);
236
251
  right.push(lastRight);
237
252
  }
238
253
  previousLeft = lastLeft;
@@ -244,24 +259,24 @@ export function outlineWithPressures(points, options) {
244
259
  previousWasSharpCorner = false;
245
260
  if (isLast) {
246
261
  // The last point: straight out to both sides of the way the line was going.
247
- const offsetX = point.vectorY * radius;
248
- const offsetY = -point.vectorX * radius;
249
- left.push({ x: point.x - offsetX, y: point.y - offsetY });
250
- right.push({ x: point.x + offsetX, y: point.y + offsetY });
262
+ var offsetX_2 = point.vectorY * radius;
263
+ var offsetY_2 = -point.vectorX * radius;
264
+ left.push({ x: point.x - offsetX_2, y: point.y - offsetY_2 });
265
+ right.push({ x: point.x + offsetX_2, y: point.y + offsetY_2 });
251
266
  continue;
252
267
  }
253
268
  // An ordinary point: out to both sides along the middle of the way in and the way out.
254
- const middleX = next.vectorX + (point.vectorX - next.vectorX) * nextDot;
255
- const middleY = next.vectorY + (point.vectorY - next.vectorY) * nextDot;
256
- const offsetX = middleY * radius;
257
- const offsetY = -middleX * radius;
258
- const leftPoint = { x: point.x - offsetX, y: point.y - offsetY };
259
- if (index <= 1 || (leftPoint.x - previousLeft.x) ** 2 + (leftPoint.y - previousLeft.y) ** 2 > minimumGapSquared) {
269
+ var middleX = next.vectorX + (point.vectorX - next.vectorX) * nextDot;
270
+ var middleY = next.vectorY + (point.vectorY - next.vectorY) * nextDot;
271
+ var offsetX = middleY * radius;
272
+ var offsetY = -middleX * radius;
273
+ var leftPoint = { x: point.x - offsetX, y: point.y - offsetY };
274
+ if (index <= 1 || Math.pow((leftPoint.x - previousLeft.x), 2) + Math.pow((leftPoint.y - previousLeft.y), 2) > minimumGapSquared) {
260
275
  left.push(leftPoint);
261
276
  previousLeft = leftPoint;
262
277
  }
263
- const rightPoint = { x: point.x + offsetX, y: point.y + offsetY };
264
- if (index <= 1 || (rightPoint.x - previousRight.x) ** 2 + (rightPoint.y - previousRight.y) ** 2 > minimumGapSquared) {
278
+ var rightPoint = { x: point.x + offsetX, y: point.y + offsetY };
279
+ if (index <= 1 || Math.pow((rightPoint.x - previousRight.x), 2) + Math.pow((rightPoint.y - previousRight.y), 2) > minimumGapSquared) {
265
280
  right.push(rightPoint);
266
281
  previousRight = rightPoint;
267
282
  }
@@ -269,22 +284,22 @@ export function outlineWithPressures(points, options) {
269
284
  previousVectorX = point.vectorX;
270
285
  previousVectorY = point.vectorY;
271
286
  }
272
- const first = { x: points[0].x, y: points[0].y };
273
- const last = points.length > 1 ? { x: points[points.length - 1].x, y: points[points.length - 1].y } : { x: points[0].x + 1, y: points[0].y + 1 };
274
- const startCapPoints = [];
275
- const endCapPoints = [];
287
+ var first = { x: points[0].x, y: points[0].y };
288
+ var last = points.length > 1 ? { x: points[points.length - 1].x, y: points[points.length - 1].y } : { x: points[0].x + 1, y: points[0].y + 1 };
289
+ var startCapPoints = [];
290
+ var endCapPoints = [];
276
291
  if (points.length === 1) {
277
292
  // A lone point is a dot, unless its taper would make it nothing and the stroke is not finished.
278
293
  if (!(taperStart || taperEnd) || finished) {
279
- const around = { x: first.x - last.x, y: first.y - last.y };
280
- const length = Math.hypot(around.x, around.y) || 1;
281
- const dotRadius = firstRadius ?? radius;
294
+ var around = { x: first.x - last.x, y: first.y - last.y };
295
+ var length = Math.hypot(around.x, around.y) || 1;
296
+ var dotRadius = firstRadius !== null && firstRadius !== void 0 ? firstRadius : radius;
282
297
  // A point a radius away, at right angles to the (arbitrary) direction of the dot, turned a full circle.
283
- const start = { x: first.x - (around.y / length) * dotRadius, y: first.y + (around.x / length) * dotRadius };
284
- const dot = [];
285
- for (let step = 1; step <= CORNER_STEPS; step += 1)
298
+ var start = { x: first.x - (around.y / length) * dotRadius, y: first.y + (around.x / length) * dotRadius };
299
+ var dot = [];
300
+ for (var step = 1; step <= CORNER_STEPS; step += 1)
286
301
  dot.push(rotateAbout(start, first, HALF_TURN * 2 * (step / CORNER_STEPS)));
287
- return { outline: dot, pressures };
302
+ return { outline: dot, pressures: pressures };
288
303
  }
289
304
  }
290
305
  else {
@@ -293,25 +308,25 @@ export function outlineWithPressures(points, options) {
293
308
  }
294
309
  else if (startCap) {
295
310
  // A round cap: the right side's first point turned half a circle about the start, to the left side's.
296
- for (let step = 1; step <= CORNER_STEPS; step += 1)
311
+ for (var step = 1; step <= CORNER_STEPS; step += 1)
297
312
  startCapPoints.push(rotateAbout(right[0], first, HALF_TURN * (step / CORNER_STEPS)));
298
313
  }
299
314
  else {
300
- const cornersX = left[0].x - right[0].x;
301
- const cornersY = left[0].y - right[0].y;
315
+ var cornersX = left[0].x - right[0].x;
316
+ var cornersY = left[0].y - right[0].y;
302
317
  startCapPoints.push({ x: first.x - cornersX * 0.5, y: first.y - cornersY * 0.5 }, { x: first.x - cornersX * 0.51, y: first.y - cornersY * 0.51 }, { x: first.x + cornersX * 0.51, y: first.y + cornersY * 0.51 }, { x: first.x + cornersX * 0.5, y: first.y + cornersY * 0.5 });
303
318
  }
304
- const lastPoint = points[points.length - 1];
319
+ var lastPoint = points[points.length - 1];
305
320
  // At right angles to the way the line was going when it ended (its vector points back along it).
306
- const directionX = -lastPoint.vectorY;
307
- const directionY = lastPoint.vectorX;
321
+ var directionX = -lastPoint.vectorY;
322
+ var directionY = lastPoint.vectorX;
308
323
  if (taperEnd || (taperStart && points.length === 1)) {
309
324
  endCapPoints.push(last);
310
325
  }
311
326
  else if (endCap) {
312
327
  // A round end cap goes a turn and a half round the last point, so that a sharp turn at the end is not cut short.
313
- const start = { x: last.x + directionX * radius, y: last.y + directionY * radius };
314
- for (let step = 1; step < END_CAP_STEPS; step += 1)
328
+ var start = { x: last.x + directionX * radius, y: last.y + directionY * radius };
329
+ for (var step = 1; step < END_CAP_STEPS; step += 1)
315
330
  endCapPoints.push(rotateAbout(start, last, HALF_TURN * 3 * (step / END_CAP_STEPS)));
316
331
  }
317
332
  else {
@@ -319,7 +334,7 @@ export function outlineWithPressures(points, options) {
319
334
  }
320
335
  }
321
336
  // Up the left, round the end, down the right, round the start.
322
- return { outline: left.concat(endCapPoints, right.reverse(), startCapPoints), pressures };
337
+ return { outline: left.concat(endCapPoints, right.reverse(), startCapPoints), pressures: pressures };
323
338
  }
324
339
  /**
325
340
  * Points that are already smooth (the line a stroke was stored as) with what the outline is made from: the way back along the
@@ -327,27 +342,28 @@ export function outlineWithPressures(points, options) {
327
342
  * given; a point on the one before it adds nothing and is left out.
328
343
  */
329
344
  export function strokePointsOfLine(line) {
330
- const points = [];
331
- let runningLength = 0;
332
- for (const sample of usableSamples(line)) {
333
- const pressure = sample.pressure >= 0 ? sample.pressure : 0.5;
334
- const previous = points[points.length - 1];
345
+ var points = [];
346
+ var runningLength = 0;
347
+ for (var _i = 0, _a = usableSamples(line); _i < _a.length; _i++) {
348
+ var sample = _a[_i];
349
+ var pressure = sample.pressure >= 0 ? sample.pressure : 0.5;
350
+ var previous = points[points.length - 1];
335
351
  if (!previous) {
336
- points.push({ x: sample.x, y: sample.y, pressure, vectorX: 1, vectorY: 1, distance: 0, runningLength: 0 });
352
+ points.push({ x: sample.x, y: sample.y, pressure: pressure, vectorX: 1, vectorY: 1, distance: 0, runningLength: 0 });
337
353
  continue;
338
354
  }
339
- const distance = Math.hypot(sample.x - previous.x, sample.y - previous.y);
355
+ var distance = Math.hypot(sample.x - previous.x, sample.y - previous.y);
340
356
  if (distance === 0)
341
357
  continue;
342
358
  runningLength += distance;
343
359
  points.push({
344
360
  x: sample.x,
345
361
  y: sample.y,
346
- pressure,
362
+ pressure: pressure,
347
363
  vectorX: (previous.x - sample.x) / distance,
348
364
  vectorY: (previous.y - sample.y) / distance,
349
- distance,
350
- runningLength
365
+ distance: distance,
366
+ runningLength: runningLength
351
367
  });
352
368
  }
353
369
  // The first point looks the way the second one does.
@@ -366,12 +382,12 @@ export function freehandOutline(samples, options) {
366
382
  return outlineOf(strokePointsOf(samples, options), options);
367
383
  }
368
384
  // ───────────────────────────────────────────────────────────────────────── as path data
369
- const FIXED_DECIMALS = 2;
370
- const fixed = (value) => (Math.round(value * 10 ** FIXED_DECIMALS) / 10 ** FIXED_DECIMALS).toString();
385
+ var FIXED_DECIMALS = 2;
386
+ var fixed = function (value) { return (Math.round(value * Math.pow(10, FIXED_DECIMALS)) / Math.pow(10, FIXED_DECIMALS)).toString(); };
371
387
  /** The path data of a circle: two arcs, so that it fills as a dot. */
372
388
  export function circlePathData(center, radius) {
373
- const r = Math.max(radius, 0.01);
374
- return `M${fixed(center.x - r)},${fixed(center.y)}a${fixed(r)},${fixed(r)} 0 1,0 ${fixed(r * 2)},0a${fixed(r)},${fixed(r)} 0 1,0 ${fixed(-r * 2)},0Z`;
389
+ var r = Math.max(radius, 0.01);
390
+ return "M".concat(fixed(center.x - r), ",").concat(fixed(center.y), "a").concat(fixed(r), ",").concat(fixed(r), " 0 1,0 ").concat(fixed(r * 2), ",0a").concat(fixed(r), ",").concat(fixed(r), " 0 1,0 ").concat(fixed(-r * 2), ",0Z");
375
391
  }
376
392
  /**
377
393
  * The path data of a closed outline, smoothed: a quadratic curve through the midpoints of the polygon's sides, with the
@@ -380,19 +396,19 @@ export function circlePathData(center, radius) {
380
396
  export function outlinePathData(outline) {
381
397
  if (outline.length < 4)
382
398
  return '';
383
- const [first, second, third] = outline;
384
- let data = `M${fixed(first.x)},${fixed(first.y)}Q${fixed(second.x)},${fixed(second.y)} ${fixed((second.x + third.x) / 2)},${fixed((second.y + third.y) / 2)}T`;
385
- for (let index = 2; index < outline.length - 1; index += 1) {
386
- const current = outline[index];
387
- const next = outline[index + 1];
388
- data += `${fixed((current.x + next.x) / 2)},${fixed((current.y + next.y) / 2)} `;
399
+ var first = outline[0], second = outline[1], third = outline[2];
400
+ var data = "M".concat(fixed(first.x), ",").concat(fixed(first.y), "Q").concat(fixed(second.x), ",").concat(fixed(second.y), " ").concat(fixed((second.x + third.x) / 2), ",").concat(fixed((second.y + third.y) / 2), "T");
401
+ for (var index = 2; index < outline.length - 1; index += 1) {
402
+ var current = outline[index];
403
+ var next = outline[index + 1];
404
+ data += "".concat(fixed((current.x + next.x) / 2), ",").concat(fixed((current.y + next.y) / 2), " ");
389
405
  }
390
- return `${data.trimEnd()}Z`;
406
+ return "".concat(data.trimEnd(), "Z");
391
407
  }
392
408
  // ───────────────────────────────────────────────────────────────────────── the brush
393
409
  /** Maps a value from one range to another, held inside it. */
394
410
  function modulate(value, from, to) {
395
- const progress = Math.min(1, Math.max(0, (value - from[0]) / (from[1] - from[0])));
411
+ var progress = Math.min(1, Math.max(0, (value - from[0]) / (from[1] - from[0])));
396
412
  return to[0] + (to[1] - to[0]) * progress;
397
413
  }
398
414
  /**
@@ -404,7 +420,7 @@ export function brushOptions(size, pressure, finished) {
404
420
  return { size: 1 + size * 1.2, thinning: 0.62, streamline: 0.62, smoothing: 0.62, simulatePressure: false, easing: EASE_PEN, last: finished };
405
421
  }
406
422
  return {
407
- size,
423
+ size: size,
408
424
  thinning: 0.5,
409
425
  streamline: modulate(size, [9, 16], [0.64, 0.74]),
410
426
  smoothing: 0.62,