@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
@@ -11,24 +11,35 @@
11
11
  * hand, and scaling the line must not change how thick it is where the hand dwelled. Everything here is plain functions over
12
12
  * plain records, so the same stroke is drawn in the editor, the screenshot rasterizer and the tests.
13
13
  */
14
+ var __assign = (this && this.__assign) || function () {
15
+ __assign = Object.assign || function(t) {
16
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
17
+ s = arguments[i];
18
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
19
+ t[p] = s[p];
20
+ }
21
+ return t;
22
+ };
23
+ return __assign.apply(this, arguments);
24
+ };
14
25
  import { SHAPE_STYLE_DEFAULTS, createObjectId, createPathObject } from './defaults.js';
15
26
  import { brushOptions, brushReach, brushSizeFor, circlePathData, outlineOf, outlinePathData, outlineWithPressures, strokePointsOf, strokePointsOfLine } from './freehand.js';
16
27
  import { MIN_OBJECT_SIZE } from './types.js';
17
28
  /** The most points of a line a stroke keeps; a longer line is thinned further, so a stroke never grows without bound. */
18
- export const BRUSH_MAX_POINTS = 4000;
29
+ export var BRUSH_MAX_POINTS = 4000;
19
30
  // The points of a stroke closer together than this fraction of the brush (and than a unit of the board) add nothing the outline
20
31
  // shows: it leaves out points closer than 0.62 of the brush on both of its sides already.
21
- const POINT_GAP_OF_SIZE = 0.3;
22
- const MINIMUM_POINT_GAP = 0.75;
32
+ var POINT_GAP_OF_SIZE = 0.3;
33
+ var MINIMUM_POINT_GAP = 0.75;
23
34
  // The decimals a stored point keeps: a hundredth of a unit is far finer than a pixel at the zoom that goes up to eight.
24
- const COORDINATE_DECIMALS = 2;
35
+ var COORDINATE_DECIMALS = 2;
25
36
  // A line that never leaves this distance (in units of the board) from where it began is a click: a dot at the pointer.
26
- const DOT_REACH = 1;
37
+ var DOT_REACH = 1;
27
38
  // The pressure of a dot made with a mouse or a finger: the middle of the range, as a line drawn at an even pressure has.
28
- const DOT_PRESSURE = 0.5;
39
+ var DOT_PRESSURE = 0.5;
29
40
  /** The narrowest width the Width control may give a brush stroke. */
30
- export const MIN_BRUSH_WIDTH = 1;
31
- const roundTo = (value, decimals) => Math.round(value * 10 ** decimals) / 10 ** decimals;
41
+ export var MIN_BRUSH_WIDTH = 1;
42
+ var roundTo = function (value, decimals) { return Math.round(value * Math.pow(10, decimals)) / Math.pow(10, decimals); };
32
43
  /** Whether an object is a brush stroke (a path that was drawn with the Draw tool and holds its line). */
33
44
  export function isBrushStroke(object) {
34
45
  return object.type === 'path' && !!object.ink;
@@ -42,30 +53,37 @@ export function brushOverflow(shape) {
42
53
  }
43
54
  /** The line a brush stroke follows, in the coordinates of its box (what the shape snap measures). */
44
55
  export function brushCentreline(shape) {
45
- return shape.ink.points.map(([x, y]) => ({ x, y }));
56
+ return shape.ink.points.map(function (_a) {
57
+ var x = _a[0], y = _a[1];
58
+ return ({ x: x, y: y });
59
+ });
46
60
  }
47
61
  /**
48
62
  * The outline of a stored line, as path data: drawn again from the points and the pressures it holds, at the width of the brush.
49
63
  * Always something to draw: a line the outline cannot be made of (one point, or none) is a dot.
50
64
  */
51
65
  export function brushOutlineData(ink, strokeWidth) {
52
- const size = brushSizeFor(strokeWidth);
66
+ var _a;
67
+ var size = brushSizeFor(strokeWidth);
53
68
  // The pressure is already in the points, so it is read, whatever it came from.
54
- const options = { ...brushOptions(size, ink.pressure, true), simulatePressure: false };
55
- const points = strokePointsOfLine(ink.points.map(([x, y, pressure]) => ({ x, y, pressure })));
56
- const data = outlinePathData(outlineOf(points, options));
69
+ var options = __assign(__assign({}, brushOptions(size, ink.pressure, true)), { simulatePressure: false });
70
+ var points = strokePointsOfLine(ink.points.map(function (_a) {
71
+ var x = _a[0], y = _a[1], pressure = _a[2];
72
+ return ({ x: x, y: y, pressure: pressure });
73
+ }));
74
+ var data = outlinePathData(outlineOf(points, options));
57
75
  if (data)
58
76
  return data;
59
- const center = points[0] ?? { x: 0, y: 0 };
77
+ var center = (_a = points[0]) !== null && _a !== void 0 ? _a : { x: 0, y: 0 };
60
78
  return circlePathData(center, Math.max(0.5, size / 2));
61
79
  }
62
80
  /** The points of a smoothed line that the outline needs, with the pressure each was drawn with. */
63
81
  function keptPoints(points, pressures, size) {
64
- let gap = Math.max(MINIMUM_POINT_GAP, size * POINT_GAP_OF_SIZE);
82
+ var gap = Math.max(MINIMUM_POINT_GAP, size * POINT_GAP_OF_SIZE);
65
83
  for (;;) {
66
- const kept = [{ point: points[0], pressure: pressures[0] }];
67
- for (let index = 1; index < points.length - 1; index += 1) {
68
- const previous = kept[kept.length - 1].point;
84
+ var kept = [{ point: points[0], pressure: pressures[0] }];
85
+ for (var index = 1; index < points.length - 1; index += 1) {
86
+ var previous = kept[kept.length - 1].point;
69
87
  if (Math.hypot(points[index].x - previous.x, points[index].y - previous.y) >= gap) {
70
88
  kept.push({ point: points[index], pressure: pressures[index] });
71
89
  }
@@ -82,70 +100,76 @@ function keptPoints(points, pressures, size) {
82
100
  * The stroke for the samples of a pointer, in world units: the box of its line, the line itself with its pressure, and the
83
101
  * outline to draw. Null when there is nothing to draw.
84
102
  */
85
- export function buildBrushStroke(samples, options = {}) {
86
- const strokeWidth = options.strokeWidth ?? SHAPE_STYLE_DEFAULTS.inkStrokeWidth;
87
- const pressure = options.pressure ?? 'speed';
88
- const size = brushSizeFor(strokeWidth);
89
- const lineOptions = brushOptions(size, pressure, options.finished === true);
90
- const usable = samples.filter((sample) => Number.isFinite(sample.x) && Number.isFinite(sample.y));
103
+ export function buildBrushStroke(samples, options) {
104
+ var _a, _b, _c, _d;
105
+ if (options === void 0) { options = {}; }
106
+ var strokeWidth = (_a = options.strokeWidth) !== null && _a !== void 0 ? _a : SHAPE_STYLE_DEFAULTS.inkStrokeWidth;
107
+ var pressure = (_b = options.pressure) !== null && _b !== void 0 ? _b : 'speed';
108
+ var size = brushSizeFor(strokeWidth);
109
+ var lineOptions = brushOptions(size, pressure, options.finished === true);
110
+ var usable = samples.filter(function (sample) { return Number.isFinite(sample.x) && Number.isFinite(sample.y); });
91
111
  if (usable.length === 0)
92
112
  return null;
93
- let kept;
94
- if (usable.every((sample) => Math.hypot(sample.x - usable[0].x, sample.y - usable[0].y) < DOT_REACH)) {
113
+ var kept;
114
+ if (usable.every(function (sample) { return Math.hypot(sample.x - usable[0].x, sample.y - usable[0].y) < DOT_REACH; })) {
95
115
  // A click is a dot where the pointer went down: the line has one point, so nothing is drawn a pixel away from it.
96
- const penPressure = usable.reduce((most, sample) => Math.max(most, sample.pressure ?? 0), 0);
97
- const dotPressure = pressure === 'pen' && penPressure > 0 ? Math.min(1, penPressure) : DOT_PRESSURE;
98
- const point = { x: usable[0].x, y: usable[0].y, pressure: dotPressure, vectorX: 0, vectorY: 0, distance: 0, runningLength: 0 };
99
- kept = [{ point, pressure: dotPressure }];
116
+ var penPressure = usable.reduce(function (most, sample) { var _a; return Math.max(most, (_a = sample.pressure) !== null && _a !== void 0 ? _a : 0); }, 0);
117
+ var dotPressure = pressure === 'pen' && penPressure > 0 ? Math.min(1, penPressure) : DOT_PRESSURE;
118
+ var point = { x: usable[0].x, y: usable[0].y, pressure: dotPressure, vectorX: 0, vectorY: 0, distance: 0, runningLength: 0 };
119
+ kept = [{ point: point, pressure: dotPressure }];
100
120
  }
101
121
  else {
102
- const smoothed = strokePointsOf(usable, lineOptions);
122
+ var smoothed = strokePointsOf(usable, lineOptions);
103
123
  // The pass that works the pressure out (from the speed, or read from the pen) so that it can be kept.
104
- const { pressures } = outlineWithPressures(smoothed, lineOptions);
124
+ var pressures = outlineWithPressures(smoothed, lineOptions).pressures;
105
125
  kept = keptPoints(smoothed, pressures, size);
106
126
  }
107
- let minX = Infinity;
108
- let minY = Infinity;
109
- let maxX = -Infinity;
110
- let maxY = -Infinity;
111
- for (const { point } of kept) {
127
+ var minX = Infinity;
128
+ var minY = Infinity;
129
+ var maxX = -Infinity;
130
+ var maxY = -Infinity;
131
+ for (var _i = 0, kept_1 = kept; _i < kept_1.length; _i++) {
132
+ var point = kept_1[_i].point;
112
133
  minX = Math.min(minX, point.x);
113
134
  minY = Math.min(minY, point.y);
114
135
  maxX = Math.max(maxX, point.x);
115
136
  maxY = Math.max(maxY, point.y);
116
137
  }
117
138
  // A line that is flat on one axis (a horizontal line, a dot) gets a box one unit thick, with the line in its middle.
118
- const flatX = maxX - minX < MIN_OBJECT_SIZE;
119
- const flatY = maxY - minY < MIN_OBJECT_SIZE;
120
- const boxX = flatX ? (minX + maxX) / 2 - MIN_OBJECT_SIZE / 2 : minX;
121
- const boxY = flatY ? (minY + maxY) / 2 - MIN_OBJECT_SIZE / 2 : minY;
122
- const width = flatX ? MIN_OBJECT_SIZE : maxX - minX;
123
- const height = flatY ? MIN_OBJECT_SIZE : maxY - minY;
124
- const ink = {
125
- points: kept.map(({ point, pressure: pointPressure }) => [
126
- roundTo(point.x - boxX, COORDINATE_DECIMALS),
127
- roundTo(point.y - boxY, COORDINATE_DECIMALS),
128
- roundTo(pointPressure, COORDINATE_DECIMALS)
129
- ]),
130
- pressure
139
+ var flatX = maxX - minX < MIN_OBJECT_SIZE;
140
+ var flatY = maxY - minY < MIN_OBJECT_SIZE;
141
+ var boxX = flatX ? (minX + maxX) / 2 - MIN_OBJECT_SIZE / 2 : minX;
142
+ var boxY = flatY ? (minY + maxY) / 2 - MIN_OBJECT_SIZE / 2 : minY;
143
+ var width = flatX ? MIN_OBJECT_SIZE : maxX - minX;
144
+ var height = flatY ? MIN_OBJECT_SIZE : maxY - minY;
145
+ var ink = {
146
+ points: kept.map(function (_a) {
147
+ var point = _a.point, pointPressure = _a.pressure;
148
+ return [
149
+ roundTo(point.x - boxX, COORDINATE_DECIMALS),
150
+ roundTo(point.y - boxY, COORDINATE_DECIMALS),
151
+ roundTo(pointPressure, COORDINATE_DECIMALS)
152
+ ];
153
+ }),
154
+ pressure: pressure
131
155
  };
132
- const createId = options.createId ?? createObjectId;
156
+ var createId = (_c = options.createId) !== null && _c !== void 0 ? _c : createObjectId;
133
157
  return createPathObject({
134
158
  id: createId('obj'),
135
159
  x: boxX,
136
160
  y: boxY,
137
- width,
138
- height,
161
+ width: width,
162
+ height: height,
139
163
  d: brushOutlineData(ink, strokeWidth),
140
164
  shape: null,
141
165
  // The brush is filled: its colour is the fill of the outline, and the outline has no stroke of its own.
142
- fill: options.color ?? SHAPE_STYLE_DEFAULTS.inkStroke,
166
+ fill: (_d = options.color) !== null && _d !== void 0 ? _d : SHAPE_STYLE_DEFAULTS.inkStroke,
143
167
  fillOpacity: 1,
144
168
  stroke: 'transparent',
145
- strokeWidth,
169
+ strokeWidth: strokeWidth,
146
170
  lineCap: 'round',
147
171
  lineJoin: 'round',
148
- ink
172
+ ink: ink
149
173
  });
150
174
  }
151
175
  /**
@@ -153,21 +177,24 @@ export function buildBrushStroke(samples, options = {}) {
153
177
  * where the box goes, the brush stays as wide as it was. Only `d`, `ink`, the size of the box and `strokeWidth` are written;
154
178
  * where the box is, and how it is turned, is the caller's.
155
179
  */
156
- export function reshapeBrushStroke(shape, change = {}) {
157
- const width = Math.max(MIN_OBJECT_SIZE, change.width ?? shape.width);
158
- const height = Math.max(MIN_OBJECT_SIZE, change.height ?? shape.height);
159
- const strokeWidth = change.strokeWidth ?? shape.strokeWidth;
160
- const scaleX = shape.width > 0 ? width / shape.width : 1;
161
- const scaleY = shape.height > 0 ? height / shape.height : 1;
162
- const points = shape.ink.points.map(([x, y, pressure]) => {
163
- const scaledX = x * scaleX;
164
- const scaledY = y * scaleY;
180
+ export function reshapeBrushStroke(shape, change) {
181
+ var _a, _b, _c;
182
+ if (change === void 0) { change = {}; }
183
+ var width = Math.max(MIN_OBJECT_SIZE, (_a = change.width) !== null && _a !== void 0 ? _a : shape.width);
184
+ var height = Math.max(MIN_OBJECT_SIZE, (_b = change.height) !== null && _b !== void 0 ? _b : shape.height);
185
+ var strokeWidth = (_c = change.strokeWidth) !== null && _c !== void 0 ? _c : shape.strokeWidth;
186
+ var scaleX = shape.width > 0 ? width / shape.width : 1;
187
+ var scaleY = shape.height > 0 ? height / shape.height : 1;
188
+ var points = shape.ink.points.map(function (_a) {
189
+ var x = _a[0], y = _a[1], pressure = _a[2];
190
+ var scaledX = x * scaleX;
191
+ var scaledY = y * scaleY;
165
192
  return [
166
193
  roundTo(change.flipX ? width - scaledX : scaledX, COORDINATE_DECIMALS),
167
194
  roundTo(change.flipY ? height - scaledY : scaledY, COORDINATE_DECIMALS),
168
195
  pressure
169
196
  ];
170
197
  });
171
- const ink = { points, pressure: shape.ink.pressure };
172
- return { ...shape, width, height, strokeWidth, ink, d: brushOutlineData(ink, strokeWidth) };
198
+ var ink = { points: points, pressure: shape.ink.pressure };
199
+ return __assign(__assign({}, shape), { width: width, height: height, strokeWidth: strokeWidth, ink: ink, d: brushOutlineData(ink, strokeWidth) });
173
200
  }
@@ -4,8 +4,19 @@
4
4
  * Every factory takes only what differs from the defaults, so a tool says "a rectangle here, this big" and
5
5
  * nothing else. Ids come from `createObjectId`; a test passes its own `id` and gets the same record every time.
6
6
  */
7
+ var __assign = (this && this.__assign) || function () {
8
+ __assign = Object.assign || function(t) {
9
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
10
+ s = arguments[i];
11
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
12
+ t[p] = s[p];
13
+ }
14
+ return t;
15
+ };
16
+ return __assign.apply(this, arguments);
17
+ };
7
18
  /** The look of a shape in the wireframe mode (the default of the canvas) and outside it. */
8
- export const SHAPE_STYLE_DEFAULTS = {
19
+ export var SHAPE_STYLE_DEFAULTS = {
9
20
  wireframeFill: '#ffffff',
10
21
  wireframeStroke: '#374151',
11
22
  wireframeStrokeWidth: 2,
@@ -15,7 +26,7 @@ export const SHAPE_STYLE_DEFAULTS = {
15
26
  inkStroke: '#1f2937',
16
27
  inkStrokeWidth: 3
17
28
  };
18
- export const TEXT_DEFAULTS = {
29
+ export var TEXT_DEFAULTS = {
19
30
  fontSize: 20,
20
31
  fontFamily: 'Inter',
21
32
  color: '#111827',
@@ -30,21 +41,23 @@ export const TEXT_DEFAULTS = {
30
41
  emptyTextMeasureStandIn: 'Type here'
31
42
  };
32
43
  /** The size of a shape that is placed by a click or a button, not dragged out. */
33
- export const DEFAULT_OBJECT_SIZE = 100;
44
+ export var DEFAULT_OBJECT_SIZE = 100;
34
45
  /** A random vivid colour, for a new shape on a board that is not in the wireframe mode. */
35
- export function randomShapeFill(random = Math.random) {
36
- return `hsl(${Math.floor(random() * 360)}, 70%, 50%)`;
46
+ export function randomShapeFill(random) {
47
+ if (random === void 0) { random = Math.random; }
48
+ return "hsl(".concat(Math.floor(random() * 360), ", 70%, 50%)");
37
49
  }
38
- let idCounter = 0;
50
+ var idCounter = 0;
39
51
  /** A unique id: time, a counter and a random tail, so two tabs and two calls in one millisecond never collide. */
40
- export function createObjectId(prefix = 'obj') {
52
+ export function createObjectId(prefix) {
53
+ if (prefix === void 0) { prefix = 'obj'; }
41
54
  idCounter += 1;
42
- const randomTail = Math.random().toString(36).slice(2, 8);
43
- return `${prefix}_${Date.now().toString(36)}_${idCounter.toString(36)}${randomTail}`;
55
+ var randomTail = Math.random().toString(36).slice(2, 8);
56
+ return "".concat(prefix, "_").concat(Date.now().toString(36), "_").concat(idCounter.toString(36)).concat(randomTail);
44
57
  }
45
58
  /** The dash pattern of a stroke style. Dotted uses zero-length dashes, which a round cap turns into dots. */
46
59
  export function strokeDashArray(strokeStyle, strokeWidth) {
47
- const unit = Math.max(2, strokeWidth);
60
+ var unit = Math.max(2, strokeWidth);
48
61
  switch (strokeStyle) {
49
62
  case 'dashed':
50
63
  return [unit * 4, unit * 2];
@@ -54,7 +67,7 @@ export function strokeDashArray(strokeStyle, strokeWidth) {
54
67
  return null;
55
68
  }
56
69
  }
57
- const BOX_DEFAULTS = {
70
+ var BOX_DEFAULTS = {
58
71
  parentId: null,
59
72
  x: 0,
60
73
  y: 0,
@@ -63,96 +76,44 @@ const BOX_DEFAULTS = {
63
76
  rotation: 0,
64
77
  opacity: 1
65
78
  };
66
- const PAINT_DEFAULTS = {
79
+ var PAINT_DEFAULTS = {
67
80
  fill: SHAPE_STYLE_DEFAULTS.wireframeFill,
68
81
  fillOpacity: 1,
69
82
  stroke: SHAPE_STYLE_DEFAULTS.wireframeStroke,
70
83
  strokeWidth: SHAPE_STYLE_DEFAULTS.wireframeStrokeWidth,
71
84
  strokeStyle: 'solid'
72
85
  };
73
- export function createRectObject(fields = {}) {
74
- return { ...BOX_DEFAULTS, ...PAINT_DEFAULTS, roundness: 0, ...fields, id: fields.id ?? createObjectId(), type: 'rect' };
86
+ export function createRectObject(fields) {
87
+ var _a;
88
+ if (fields === void 0) { fields = {}; }
89
+ return __assign(__assign(__assign(__assign(__assign({}, BOX_DEFAULTS), PAINT_DEFAULTS), { roundness: 0 }), fields), { id: (_a = fields.id) !== null && _a !== void 0 ? _a : createObjectId(), type: 'rect' });
75
90
  }
76
- export function createEllipseObject(fields = {}) {
77
- return {
78
- ...BOX_DEFAULTS,
79
- ...PAINT_DEFAULTS,
80
- aspectLocked: false,
81
- ...fields,
82
- id: fields.id ?? createObjectId(),
83
- type: 'ellipse'
84
- };
91
+ export function createEllipseObject(fields) {
92
+ var _a;
93
+ if (fields === void 0) { fields = {}; }
94
+ return __assign(__assign(__assign(__assign(__assign({}, BOX_DEFAULTS), PAINT_DEFAULTS), { aspectLocked: false }), fields), { id: (_a = fields.id) !== null && _a !== void 0 ? _a : createObjectId(), type: 'ellipse' });
85
95
  }
86
- export function createPathObject(fields = {}) {
87
- return {
88
- ...BOX_DEFAULTS,
89
- ...PAINT_DEFAULTS,
90
- d: '',
91
- shape: null,
92
- roundness: 0,
93
- aspectLocked: false,
94
- flipX: false,
95
- flipY: false,
96
- lineCap: 'round',
97
- lineJoin: 'round',
98
- ink: null,
99
- arrow: null,
100
- ...fields,
101
- id: fields.id ?? createObjectId(),
102
- type: 'path'
103
- };
96
+ export function createPathObject(fields) {
97
+ var _a;
98
+ if (fields === void 0) { fields = {}; }
99
+ return __assign(__assign(__assign(__assign(__assign({}, BOX_DEFAULTS), PAINT_DEFAULTS), { d: '', shape: null, roundness: 0, aspectLocked: false, flipX: false, flipY: false, lineCap: 'round', lineJoin: 'round', ink: null, arrow: null }), fields), { id: (_a = fields.id) !== null && _a !== void 0 ? _a : createObjectId(), type: 'path' });
104
100
  }
105
- export function createTextObject(fields = {}) {
106
- return {
107
- ...BOX_DEFAULTS,
108
- width: TEXT_DEFAULTS.minimumWidth,
109
- height: Math.ceil(TEXT_DEFAULTS.fontSize * 1.2),
110
- text: '',
111
- color: TEXT_DEFAULTS.color,
112
- fontSize: TEXT_DEFAULTS.fontSize,
113
- fontFamily: TEXT_DEFAULTS.fontFamily,
114
- fontWeight: 'normal',
115
- fontStyle: 'normal',
116
- underline: false,
117
- align: 'left',
118
- lineHeight: 1.2,
119
- padding: 0,
120
- backgroundColor: 'transparent',
121
- autoWidth: true,
122
- ...fields,
123
- id: fields.id ?? createObjectId(),
124
- type: 'text'
125
- };
101
+ export function createTextObject(fields) {
102
+ var _a;
103
+ if (fields === void 0) { fields = {}; }
104
+ return __assign(__assign(__assign(__assign({}, BOX_DEFAULTS), { width: TEXT_DEFAULTS.minimumWidth, height: Math.ceil(TEXT_DEFAULTS.fontSize * 1.2), text: '', color: TEXT_DEFAULTS.color, fontSize: TEXT_DEFAULTS.fontSize, fontFamily: TEXT_DEFAULTS.fontFamily, fontWeight: 'normal', fontStyle: 'normal', underline: false, align: 'left', lineHeight: 1.2, padding: 0, backgroundColor: 'transparent', autoWidth: true }), fields), { id: (_a = fields.id) !== null && _a !== void 0 ? _a : createObjectId(), type: 'text' });
126
105
  }
127
- export function createImageObject(fields = {}) {
128
- return {
129
- ...BOX_DEFAULTS,
130
- width: 300,
131
- height: 200,
132
- src: null,
133
- imageRef: null,
134
- fileName: null,
135
- naturalWidth: 0,
136
- naturalHeight: 0,
137
- ...fields,
138
- id: fields.id ?? createObjectId(),
139
- type: 'image'
140
- };
106
+ export function createImageObject(fields) {
107
+ var _a;
108
+ if (fields === void 0) { fields = {}; }
109
+ return __assign(__assign(__assign(__assign({}, BOX_DEFAULTS), { width: 300, height: 200, src: null, imageRef: null, fileName: null, naturalWidth: 0, naturalHeight: 0 }), fields), { id: (_a = fields.id) !== null && _a !== void 0 ? _a : createObjectId(), type: 'image' });
141
110
  }
142
111
  export function createWidgetObject(fields) {
143
- return {
144
- ...BOX_DEFAULTS,
145
- width: 360,
146
- height: 268,
147
- widgetName: null,
148
- isPrimary: false,
149
- thumbnail: null,
150
- thumbnailRef: null,
151
- ...fields,
152
- id: fields.id ?? createObjectId(),
153
- type: 'widget'
154
- };
112
+ var _a;
113
+ return __assign(__assign(__assign(__assign({}, BOX_DEFAULTS), { width: 360, height: 268, widgetName: null, isPrimary: false, thumbnail: null, thumbnailRef: null }), fields), { id: (_a = fields.id) !== null && _a !== void 0 ? _a : createObjectId(), type: 'widget' });
155
114
  }
156
- export function createGroupObject(fields = {}) {
157
- return { parentId: null, ...fields, id: fields.id ?? createObjectId('group'), type: 'group' };
115
+ export function createGroupObject(fields) {
116
+ var _a;
117
+ if (fields === void 0) { fields = {}; }
118
+ return __assign(__assign({ parentId: null }, fields), { id: (_a = fields.id) !== null && _a !== void 0 ? _a : createObjectId('group'), type: 'group' });
158
119
  }