@widgetic/canvas 0.5.45 → 0.5.47

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