@tioniq/sceniq 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1328 @@
1
+ // src/geo/point.ts
2
+ var Point = class _Point {
3
+ constructor(x, y) {
4
+ this.x = x;
5
+ this.y = y;
6
+ }
7
+ x;
8
+ y;
9
+ get isZero() {
10
+ return this.x === 0 && this.y === 0;
11
+ }
12
+ get isOne() {
13
+ return this.x === 1 && this.y === 1;
14
+ }
15
+ get length() {
16
+ return Math.sqrt(this.x * this.x + this.y * this.y);
17
+ }
18
+ add(point) {
19
+ return new _Point(this.x + point.x, this.y + point.y);
20
+ }
21
+ subtract(point) {
22
+ return new _Point(this.x - point.x, this.y - point.y);
23
+ }
24
+ multiply(scalar) {
25
+ if (typeof scalar === "number") {
26
+ return new _Point(this.x * scalar, this.y * scalar);
27
+ }
28
+ return new _Point(this.x * scalar.x, this.y * scalar.y);
29
+ }
30
+ divide(scalar) {
31
+ if (typeof scalar === "number") {
32
+ return new _Point(this.x / scalar, this.y / scalar);
33
+ }
34
+ return new _Point(this.x / scalar.x, this.y / scalar.y);
35
+ }
36
+ distance(point) {
37
+ return Math.sqrt((this.x - point.x) ** 2 + (this.y - point.y) ** 2);
38
+ }
39
+ /** The point mirrored through the origin: `(-x, -y)`. */
40
+ negate() {
41
+ return new _Point(-this.x, -this.y);
42
+ }
43
+ /** The point with its coordinates swapped: `(y, x)`. */
44
+ swap() {
45
+ return new _Point(this.y, this.x);
46
+ }
47
+ shift(x, y) {
48
+ if (typeof x === "number") {
49
+ return new _Point(this.x + x, this.y + (y ?? Number.NaN));
50
+ }
51
+ return new _Point(this.x + x.x, this.y + x.y);
52
+ }
53
+ shiftTowards(point, distance) {
54
+ const direction = point.subtract(this);
55
+ const length = direction.distance(_Point.zero);
56
+ if (length === 0) {
57
+ return this;
58
+ }
59
+ return this.add(direction.divide(length).multiply(distance));
60
+ }
61
+ floor() {
62
+ return new _Point(Math.floor(this.x), Math.floor(this.y));
63
+ }
64
+ ceil() {
65
+ return new _Point(Math.ceil(this.x), Math.ceil(this.y));
66
+ }
67
+ with(overrides) {
68
+ if (!overrides) {
69
+ return new _Point(this.x, this.y);
70
+ }
71
+ return new _Point(overrides.x ?? this.x, overrides.y ?? this.y);
72
+ }
73
+ distanceTo(other) {
74
+ return Math.sqrt((this.x - other.x) ** 2 + (this.y - other.y) ** 2);
75
+ }
76
+ normalize() {
77
+ const length = this.length;
78
+ if (length === 0) {
79
+ return _Point.zero;
80
+ }
81
+ return this.divide(length);
82
+ }
83
+ dot(point) {
84
+ return this.x * point.x + this.y * point.y;
85
+ }
86
+ equals(point) {
87
+ return this.x === point.x && this.y === point.y;
88
+ }
89
+ toString() {
90
+ return `(${this.x}, ${this.y})`;
91
+ }
92
+ static zero = /* @__PURE__ */ new _Point(0, 0);
93
+ static one = /* @__PURE__ */ new _Point(1, 1);
94
+ static fromDomPoint(domPoint) {
95
+ return new _Point(domPoint.x, domPoint.y);
96
+ }
97
+ static from(data) {
98
+ return new _Point(data.x, data.y);
99
+ }
100
+ };
101
+
102
+ // src/geo/size.ts
103
+ var Size = class _Size {
104
+ constructor(width, height) {
105
+ this.width = width;
106
+ this.height = height;
107
+ }
108
+ width;
109
+ height;
110
+ get aspectRatio() {
111
+ return this.width / this.height;
112
+ }
113
+ get isLandscape() {
114
+ return this.width > this.height;
115
+ }
116
+ get isPortrait() {
117
+ return this.height > this.width;
118
+ }
119
+ get isSquare() {
120
+ return this.width === this.height;
121
+ }
122
+ get isWide() {
123
+ return this.width > this.height;
124
+ }
125
+ get isTall() {
126
+ return this.height > this.width;
127
+ }
128
+ get isZero() {
129
+ return this.width === 0 || this.height === 0;
130
+ }
131
+ equals(other) {
132
+ return this.width === other.width && this.height === other.height;
133
+ }
134
+ scale(factorX, factorY) {
135
+ if (typeof factorX === "object") {
136
+ return new _Size(this.width * factorX.x, this.height * factorX.y);
137
+ }
138
+ if (factorY == void 0) {
139
+ factorY = factorX;
140
+ }
141
+ return new _Size(this.width * factorX, this.height * factorY);
142
+ }
143
+ add(size) {
144
+ return new _Size(this.width + size.width, this.height + size.height);
145
+ }
146
+ subtract(size) {
147
+ return new _Size(this.width - size.width, this.height - size.height);
148
+ }
149
+ toPoint() {
150
+ return new Point(this.width, this.height);
151
+ }
152
+ with(overrides) {
153
+ if (!overrides) {
154
+ return new _Size(this.width, this.height);
155
+ }
156
+ return new _Size(overrides.width ?? this.width, overrides.height ?? this.height);
157
+ }
158
+ round() {
159
+ return new _Size(Math.round(this.width), Math.round(this.height));
160
+ }
161
+ withPadding(vertical, horizontal) {
162
+ if (horizontal === void 0) {
163
+ horizontal = vertical;
164
+ }
165
+ return new _Size(this.width + horizontal * 2, this.height + vertical * 2);
166
+ }
167
+ toString() {
168
+ return `Size(${this.width}, ${this.height})`;
169
+ }
170
+ static zero = /* @__PURE__ */ new _Size(0, 0);
171
+ static fromPoint(point) {
172
+ return new _Size(point.x, point.y);
173
+ }
174
+ static fromPoints(p1, p2) {
175
+ const width = Math.abs(p2.x - p1.x);
176
+ const height = Math.abs(p2.y - p1.y);
177
+ return new _Size(width, height);
178
+ }
179
+ static from(values) {
180
+ return new _Size(values.width, values.height);
181
+ }
182
+ static square(size) {
183
+ return new _Size(size, size);
184
+ }
185
+ };
186
+
187
+ // src/graphics/rect-bounds.ts
188
+ var RectBounds = class _RectBounds {
189
+ constructor(x, y, width, height) {
190
+ this.x = x;
191
+ this.y = y;
192
+ this.width = width;
193
+ this.height = height;
194
+ }
195
+ x;
196
+ y;
197
+ width;
198
+ height;
199
+ get left() {
200
+ return this.x;
201
+ }
202
+ get right() {
203
+ return this.x + this.width;
204
+ }
205
+ get top() {
206
+ return this.y;
207
+ }
208
+ get bottom() {
209
+ return this.y + this.height;
210
+ }
211
+ get size() {
212
+ return new Size(this.width, this.height);
213
+ }
214
+ get area() {
215
+ return this.width * this.height;
216
+ }
217
+ get centerX() {
218
+ return this.x + this.width / 2;
219
+ }
220
+ get centerY() {
221
+ return this.y + this.height / 2;
222
+ }
223
+ get center() {
224
+ return new Point(this.centerX, this.centerY);
225
+ }
226
+ get topLeft() {
227
+ return new Point(this.x, this.y);
228
+ }
229
+ get topRight() {
230
+ return new Point(this.right, this.y);
231
+ }
232
+ get bottomLeft() {
233
+ return new Point(this.x, this.bottom);
234
+ }
235
+ get bottomRight() {
236
+ return new Point(this.right, this.bottom);
237
+ }
238
+ contains(x, y) {
239
+ if (typeof x === "object") {
240
+ return this.contains(x.x, x.y);
241
+ }
242
+ if (y === void 0) {
243
+ return false;
244
+ }
245
+ return x >= this.x && x <= this.right && y >= this.y && y <= this.bottom;
246
+ }
247
+ intersects(other) {
248
+ return this.x < other.right && this.right > other.x && this.y < other.bottom && this.bottom > other.y;
249
+ }
250
+ union(other) {
251
+ const x = Math.min(this.x, other.x);
252
+ const y = Math.min(this.y, other.y);
253
+ const right = Math.max(this.right, other.right);
254
+ const bottom = Math.max(this.bottom, other.bottom);
255
+ return new _RectBounds(x, y, right - x, bottom - y);
256
+ }
257
+ limit(bounds) {
258
+ if (!this.intersects(bounds)) {
259
+ return _RectBounds.zero;
260
+ }
261
+ const x = Math.max(this.x, bounds.x);
262
+ const y = Math.max(this.y, bounds.y);
263
+ const right = Math.min(this.right, bounds.right);
264
+ const bottom = Math.min(this.bottom, bounds.bottom);
265
+ return new _RectBounds(x, y, right - x, bottom - y);
266
+ }
267
+ shift(x, y) {
268
+ if (x instanceof Point) {
269
+ return new _RectBounds(this.x + x.x, this.y + x.y, this.width, this.height);
270
+ }
271
+ return new _RectBounds(this.x + x, this.y + (y ?? Number.NaN), this.width, this.height);
272
+ }
273
+ scale(factor, yFactor) {
274
+ if (yFactor === void 0) {
275
+ yFactor = factor;
276
+ }
277
+ return new _RectBounds(this.x * factor, this.y * yFactor, this.width * factor, this.height * yFactor);
278
+ }
279
+ withPadding(vertical, horizontal) {
280
+ if (typeof vertical === "object") {
281
+ return new _RectBounds(
282
+ this.x - vertical.left,
283
+ this.y - vertical.top,
284
+ this.width + vertical.left + vertical.right,
285
+ this.height + vertical.top + vertical.bottom
286
+ );
287
+ }
288
+ if (horizontal === void 0) {
289
+ horizontal = vertical;
290
+ }
291
+ return new _RectBounds(
292
+ this.x - horizontal,
293
+ this.y - vertical,
294
+ this.width + horizontal * 2,
295
+ this.height + vertical * 2
296
+ );
297
+ }
298
+ withSize(size) {
299
+ return new _RectBounds(this.x, this.y, size.width, size.height);
300
+ }
301
+ addSize(size) {
302
+ return new _RectBounds(this.x, this.y, this.width + size.width, this.height + size.height);
303
+ }
304
+ equals(other) {
305
+ return this.x === other.x && this.y === other.y && this.width === other.width && this.height === other.height;
306
+ }
307
+ toString() {
308
+ return `RectBounds(x=${this.x}, y=${this.y}, width=${this.width}, height=${this.height})`;
309
+ }
310
+ static zero = /* @__PURE__ */ new _RectBounds(0, 0, 0, 0);
311
+ static fromPoints(x1, y1, x2, y2) {
312
+ const x = Math.min(x1, x2);
313
+ const y = Math.min(y1, y2);
314
+ const width = Math.abs(x1 - x2);
315
+ const height = Math.abs(y1 - y2);
316
+ return new _RectBounds(x, y, width, height);
317
+ }
318
+ static fromTwoPoints(point1, point2) {
319
+ const x = Math.min(point1.x, point2.x);
320
+ const y = Math.min(point1.y, point2.y);
321
+ const width = Math.abs(point1.x - point2.x);
322
+ const height = Math.abs(point1.y - point2.y);
323
+ return new _RectBounds(x, y, width, height);
324
+ }
325
+ static fromCenter(centerX, centerY, width, height) {
326
+ const x = centerX - width / 2;
327
+ const y = centerY - height / 2;
328
+ return new _RectBounds(x, y, width, height);
329
+ }
330
+ static fromBounds(bounds) {
331
+ return new _RectBounds(bounds.x, bounds.y, bounds.width, bounds.height);
332
+ }
333
+ static from(location, size) {
334
+ return new _RectBounds(location.x, location.y, size.width, size.height);
335
+ }
336
+ static fromSize(size) {
337
+ return new _RectBounds(0, 0, size.width, size.height);
338
+ }
339
+ };
340
+
341
+ // src/utils/math.ts
342
+ function clamp(value, min, max) {
343
+ if (value < min) {
344
+ return min;
345
+ }
346
+ if (value > max) {
347
+ return max;
348
+ }
349
+ return value;
350
+ }
351
+
352
+ // src/layouts/view-box.ts
353
+ var ViewBox = class _ViewBox {
354
+ static min = /* @__PURE__ */ new _ViewBox("min", "min", 0, 0, Infinity, Infinity);
355
+ static max = /* @__PURE__ */ new _ViewBox("max", "max", 0, 0, Infinity, Infinity);
356
+ static zero = /* @__PURE__ */ new _ViewBox(0, 0, 0, 0, 0, 0);
357
+ minWidth;
358
+ minHeight;
359
+ width;
360
+ height;
361
+ maxWidth;
362
+ maxHeight;
363
+ constructor(width, height, minWidth, minHeight, maxWidth, maxHeight) {
364
+ this.width = width;
365
+ this.height = height;
366
+ this.minWidth = minWidth;
367
+ this.minHeight = minHeight;
368
+ this.maxWidth = maxWidth;
369
+ this.maxHeight = maxHeight;
370
+ }
371
+ getRealWidth(preferred) {
372
+ if (this.width === "max") {
373
+ return this.maxWidth;
374
+ }
375
+ if (this.width === "min") {
376
+ return clamp(preferred ?? 0, this.minWidth, this.maxWidth);
377
+ }
378
+ return this.width;
379
+ }
380
+ getRealHeight(preferred) {
381
+ if (this.height === "max") {
382
+ return this.maxHeight;
383
+ }
384
+ if (this.height === "min") {
385
+ return clamp(preferred ?? 0, this.minHeight, this.maxHeight);
386
+ }
387
+ return this.height;
388
+ }
389
+ getRealSize(preferred) {
390
+ return new Size(this.getRealWidth(preferred?.width), this.getRealHeight(preferred?.height));
391
+ }
392
+ cut(width, height) {
393
+ return new _ViewBox(
394
+ typeof this.width === "number" ? Math.max(0, this.width - width) : this.width,
395
+ typeof this.height === "number" ? Math.max(0, this.height - height) : this.height,
396
+ Math.max(0, this.minWidth - width),
397
+ Math.max(0, this.minHeight - height),
398
+ Math.max(0, this.maxWidth - width),
399
+ Math.max(0, this.maxHeight - height)
400
+ );
401
+ }
402
+ with(overrides) {
403
+ return new _ViewBox(
404
+ overrides.width ?? this.width,
405
+ overrides.height ?? this.height,
406
+ overrides.minWidth ?? this.minWidth,
407
+ overrides.minHeight ?? this.minHeight,
408
+ overrides.maxWidth ?? this.maxWidth,
409
+ overrides.maxHeight ?? this.maxHeight
410
+ );
411
+ }
412
+ constrainBy(container) {
413
+ const width = constrainBy(
414
+ {
415
+ value: this.width,
416
+ min: this.minWidth,
417
+ max: this.maxWidth
418
+ },
419
+ {
420
+ value: container.width,
421
+ min: container.minWidth,
422
+ max: container.maxWidth
423
+ }
424
+ );
425
+ const height = constrainBy(
426
+ {
427
+ value: this.height,
428
+ min: this.minHeight,
429
+ max: this.maxHeight
430
+ },
431
+ {
432
+ value: container.height,
433
+ min: container.minHeight,
434
+ max: container.maxHeight
435
+ }
436
+ );
437
+ return new _ViewBox(width.value, height.value, width.min, height.min, width.max, height.max);
438
+ }
439
+ equals(other) {
440
+ return this.width === other.width && this.height === other.height && this.minWidth === other.minWidth && this.minHeight === other.minHeight && this.maxWidth === other.maxWidth && this.maxHeight === other.maxHeight;
441
+ }
442
+ static strict(width, height) {
443
+ if (typeof width === "number" && typeof height === "number") {
444
+ return new _ViewBox(width, height, width, height, width, height);
445
+ }
446
+ return new _ViewBox(width, height, 0, 0, Infinity, Infinity);
447
+ }
448
+ //
449
+ // static lenient(width: ViewSize, height: ViewSize): ViewBox {
450
+ // return new ViewBox(width, height, "min", "min", "max", "max")
451
+ // }
452
+ static stretch(minWidth, minHeight) {
453
+ return new _ViewBox("max", "max", minWidth ?? 0, minHeight ?? 0, Infinity, Infinity);
454
+ }
455
+ static wrap(minWidth, minHeight) {
456
+ return new _ViewBox("min", "min", minWidth ?? 0, minHeight ?? 0, Infinity, Infinity);
457
+ }
458
+ static strictSize(size) {
459
+ return new _ViewBox(size.width, size.height, size.width, size.height, size.width, size.height);
460
+ }
461
+ static wrapSize(size) {
462
+ return new _ViewBox("min", "min", size.width, size.height, Infinity, Infinity);
463
+ }
464
+ static simple(width, height) {
465
+ return new _ViewBox(width, height, 0, 0, Infinity, Infinity);
466
+ }
467
+ static fromOptionalObject(box) {
468
+ return _ViewBox.fromOptional(box.width, box.height, box.minWidth, box.minHeight, box.maxWidth, box.maxHeight);
469
+ }
470
+ static fromOptional(width, height, minWidth, minHeight, maxWidth, maxHeight) {
471
+ if (minWidth == void 0) {
472
+ minWidth = typeof width === "number" ? width : 0;
473
+ } else {
474
+ if (typeof width === "number" && width < minWidth) {
475
+ width = minWidth;
476
+ }
477
+ }
478
+ if (minHeight == void 0) {
479
+ minHeight = typeof height === "number" ? height : 0;
480
+ } else {
481
+ if (typeof height === "number" && height < minHeight) {
482
+ height = minHeight;
483
+ }
484
+ }
485
+ if (maxWidth == void 0) {
486
+ maxWidth = typeof width === "number" ? width : Infinity;
487
+ } else {
488
+ if (typeof width === "number" && width > maxWidth) {
489
+ width = maxWidth;
490
+ }
491
+ }
492
+ if (maxHeight == void 0) {
493
+ maxHeight = typeof height === "number" ? height : Infinity;
494
+ } else {
495
+ if (typeof height === "number" && height > maxHeight) {
496
+ height = maxHeight;
497
+ }
498
+ }
499
+ return new _ViewBox(width, height, minWidth, minHeight, maxWidth, maxHeight);
500
+ }
501
+ };
502
+ function constrainBy(viewSize, containerSize) {
503
+ if (viewSize.value === "min") {
504
+ const containerMax = typeof containerSize.value === "number" ? Math.min(viewSize.max, containerSize.value, containerSize.max) : Math.min(viewSize.max, containerSize.max);
505
+ return {
506
+ value: "min",
507
+ min: viewSize.min,
508
+ max: Math.max(containerMax, viewSize.min)
509
+ };
510
+ }
511
+ if (viewSize.value === "max") {
512
+ if (containerSize.value === "min") {
513
+ const containerMax = Math.min(viewSize.max, containerSize.max);
514
+ return {
515
+ value: "min",
516
+ min: viewSize.min,
517
+ max: Math.max(containerMax, viewSize.min)
518
+ };
519
+ }
520
+ if (containerSize.value === "max") {
521
+ return {
522
+ value: "max",
523
+ min: Math.max(viewSize.min, containerSize.min),
524
+ max: Math.min(viewSize.max, containerSize.max)
525
+ };
526
+ }
527
+ return {
528
+ value: "max",
529
+ min: Math.max(viewSize.min, containerSize.min),
530
+ max: Math.min(viewSize.max, containerSize.value, containerSize.max)
531
+ };
532
+ }
533
+ if (containerSize.value === "min") {
534
+ const max2 = Math.max(viewSize.min, Math.min(viewSize.max, containerSize.max));
535
+ const min2 = Math.min(max2, Math.max(viewSize.min, containerSize.min));
536
+ const value2 = clamp(viewSize.value, min2, max2);
537
+ return {
538
+ value: value2,
539
+ min: min2,
540
+ max: max2
541
+ };
542
+ }
543
+ if (containerSize.value === "max") {
544
+ const max2 = Math.max(viewSize.min, Math.min(viewSize.max, containerSize.max));
545
+ const min2 = Math.min(max2, Math.max(viewSize.min, containerSize.min));
546
+ const value2 = clamp(viewSize.value, min2, max2);
547
+ return {
548
+ value: value2,
549
+ min: min2,
550
+ max: max2
551
+ };
552
+ }
553
+ const max = Math.max(viewSize.min, Math.min(viewSize.max, containerSize.max));
554
+ const min = Math.min(max, Math.max(viewSize.min, containerSize.min));
555
+ const value = clamp(viewSize.value, min, max);
556
+ return {
557
+ value,
558
+ min,
559
+ max
560
+ };
561
+ }
562
+
563
+ // src/live-object.ts
564
+ import {
565
+ DisposableAction,
566
+ DisposableStore,
567
+ toDisposable
568
+ } from "@tioniq/disposiq";
569
+ import {
570
+ FuncVar,
571
+ isVariableOf,
572
+ LazyEventDispatcher,
573
+ Vary
574
+ } from "@tioniq/eventiq";
575
+ var LiveObject = class {
576
+ /**
577
+ * What raises onChanged while the object is live: variables (followed silently) and events. Kept as
578
+ * the objects themselves, with one shared callback, rather than two closures each: a view has a
579
+ * dozen variables and there may be tens of thousands of views.
580
+ */
581
+ _vars = [];
582
+ _events = [];
583
+ _custom = [];
584
+ _invalidatorDisposables = new DisposableStore();
585
+ _onChanged;
586
+ _dispatch = () => this.invalidate();
587
+ constructor() {
588
+ this._onChanged = new LazyEventDispatcher(() => {
589
+ const store = this._invalidatorDisposables;
590
+ const dispatch = this._dispatch;
591
+ for (const variable of this._vars) {
592
+ store.add(variable.subscribeSilent(dispatch));
593
+ }
594
+ for (const event of this._events) {
595
+ store.add(event.subscribe(dispatch));
596
+ }
597
+ for (const custom of this._custom) {
598
+ store.add(custom());
599
+ }
600
+ const subscription = this.handleSubscribed();
601
+ if (subscription) {
602
+ this._invalidatorDisposables.add(toDisposable(subscription));
603
+ }
604
+ return new DisposableAction(() => {
605
+ this._invalidatorDisposables.disposeCurrent();
606
+ this.handleUnsubscribed();
607
+ });
608
+ });
609
+ }
610
+ /** Raised when any registered variable or event changes. Subscribing makes the object live. */
611
+ get onChanged() {
612
+ return this._onChanged;
613
+ }
614
+ invalidate() {
615
+ this._onChanged.dispatch();
616
+ }
617
+ handleSubscribed() {
618
+ }
619
+ handleUnsubscribed() {
620
+ }
621
+ /** Follows an existing variable: a change of it raises {@link onChanged}. */
622
+ registerVar(variable) {
623
+ this._addVar(variable);
624
+ return variable;
625
+ }
626
+ createVar(value, equalityComparer) {
627
+ const comparer = equalityComparer === true ? equalsMethodEqualityComparer : equalityComparer;
628
+ const vary = new Vary(value, comparer);
629
+ this._addVar(vary);
630
+ return vary;
631
+ }
632
+ createVary(value, equalityComparer) {
633
+ const comparer = equalityComparer === true ? equalsMethodEqualityComparer : equalityComparer;
634
+ if (isVariableOf(value)) {
635
+ const funcVary = new FuncVar(
636
+ (vary2) => value.subscribe((v) => {
637
+ vary2.value = v;
638
+ }),
639
+ () => value.value,
640
+ comparer
641
+ );
642
+ this._addVar(funcVary);
643
+ return funcVary;
644
+ }
645
+ const vary = new Vary(value, comparer);
646
+ this._addVar(vary);
647
+ return vary;
648
+ }
649
+ registerEvent(event) {
650
+ const observer = event;
651
+ this._events.push(observer);
652
+ if (this._onChanged.hasSubscription) {
653
+ this._invalidatorDisposables.add(observer.subscribe(this._dispatch));
654
+ }
655
+ return event;
656
+ }
657
+ registerTempEvent(event) {
658
+ const invalidatorDisposables = new DisposableStore();
659
+ const invalidator = () => {
660
+ const subscription = event.subscribe(() => this.invalidate());
661
+ invalidatorDisposables.add(subscription);
662
+ return new DisposableAction(() => {
663
+ subscription.dispose();
664
+ invalidatorDisposables.remove(subscription);
665
+ });
666
+ };
667
+ const subscriptions = new DisposableStore();
668
+ this._custom.push(invalidator);
669
+ subscriptions.add(() => {
670
+ const index = this._custom.indexOf(invalidator);
671
+ if (index >= 0) {
672
+ this._custom.splice(index, 1);
673
+ }
674
+ });
675
+ if (this._onChanged.hasSubscription) {
676
+ const subscription = invalidator();
677
+ this._invalidatorDisposables.add(subscription);
678
+ subscriptions.add(() => {
679
+ this._invalidatorDisposables.remove(subscription);
680
+ });
681
+ }
682
+ subscriptions.add(invalidatorDisposables);
683
+ return subscriptions;
684
+ }
685
+ _addVar(variable) {
686
+ this._vars.push(variable);
687
+ if (this._onChanged.hasSubscription) {
688
+ this._invalidatorDisposables.add(variable.subscribeSilent(this._dispatch));
689
+ }
690
+ }
691
+ };
692
+ function equalsMethodEqualityComparer(a, b) {
693
+ if (a === b) {
694
+ return true;
695
+ }
696
+ if (!a || !b) {
697
+ return false;
698
+ }
699
+ return a.equals(b);
700
+ }
701
+
702
+ // src/view.ts
703
+ import { createVar, EventSafeDispatcher, isVariableOf as isVariableOf2, Vary as Vary2 } from "@tioniq/eventiq";
704
+
705
+ // src/paint-scope.ts
706
+ var depth = 0;
707
+ function isPainting() {
708
+ return depth > 0;
709
+ }
710
+ function beginPaint() {
711
+ depth++;
712
+ }
713
+ function endPaint() {
714
+ depth--;
715
+ }
716
+
717
+ // src/view.ts
718
+ var View = class extends LiveObject {
719
+ _onMounted;
720
+ _onClick;
721
+ _visible;
722
+ _enabled;
723
+ _hovered;
724
+ _pressed;
725
+ _location;
726
+ // Rarely bound properties are plain fields until one is bound to a variable or read as one: a
727
+ // variable costs a few hundred bytes, and there may be tens of thousands of views.
728
+ _alphaValue = 1;
729
+ _alphaVar = null;
730
+ _rotationValue = 0;
731
+ _rotationVar = null;
732
+ _scaleValue = 1;
733
+ _scaleVar = null;
734
+ _hoverScaleValue = 1;
735
+ _hoverScaleVar = null;
736
+ _hoverCursorValue = null;
737
+ _hoverCursorVar = null;
738
+ _hittableValue = true;
739
+ _hittableVar = null;
740
+ _viewBox;
741
+ _attached = createVar(false);
742
+ /** Whether hover and press changes repaint the view; see {@link repaintOnPointerState}. */
743
+ _pointerStateRepaints = false;
744
+ constructor(options) {
745
+ super();
746
+ this._onMounted = options?.onMounted;
747
+ this._onClick = this.registerEvent(new EventSafeDispatcher());
748
+ if (options?.onClick) {
749
+ this._onClick.subscribe(options.onClick);
750
+ }
751
+ this._visible = this.createVary(options?.visible ?? true);
752
+ this._enabled = this.createVary(options?.enabled ?? true);
753
+ this._location = this.createVary(options?.location ?? Point.zero, true);
754
+ const rotation = options?.rotation;
755
+ if (isVariableOf2(rotation)) this._rotationVar = this.createVary(rotation);
756
+ else if (rotation !== void 0) this._rotationValue = rotation;
757
+ const scale = options?.scale;
758
+ if (isVariableOf2(scale)) this._scaleVar = this.createVary(scale);
759
+ else if (scale !== void 0) this._scaleValue = scale;
760
+ const hoverScaleOption = options?.hoverScale;
761
+ if (isVariableOf2(hoverScaleOption)) this._hoverScaleVar = this.createVary(hoverScaleOption);
762
+ else if (hoverScaleOption !== void 0) this._hoverScaleValue = hoverScaleOption;
763
+ const hoverCursor = options?.hoverCursor;
764
+ if (isVariableOf2(hoverCursor)) this._hoverCursorVar = this.createVary(hoverCursor);
765
+ else if (hoverCursor !== void 0) this._hoverCursorValue = hoverCursor;
766
+ const hittable = options?.hittable;
767
+ if (isVariableOf2(hittable)) this._hittableVar = this.createVary(hittable);
768
+ else if (hittable !== void 0) this._hittableValue = hittable;
769
+ this._hovered = new Vary2(false);
770
+ this._pressed = new Vary2(false);
771
+ const alpha = options?.alpha;
772
+ if (isVariableOf2(alpha)) this._alphaVar = this.createVary(alpha.map(clampAlpha));
773
+ else if (alpha !== void 0) this._alphaValue = clampAlpha(alpha);
774
+ this._viewBox = this.createVar(
775
+ options?.viewBox ?? (options?.size ? ViewBox.strictSize(options.size) : ViewBox.min),
776
+ true
777
+ );
778
+ const hoverScale = options?.hoverScale;
779
+ if (hoverScale !== void 0 && (isVariableOf2(hoverScale) || hoverScale !== 1)) {
780
+ this.repaintOnPointerState();
781
+ }
782
+ }
783
+ /**
784
+ * Makes changes of {@link hovered} and {@link pressed} repaint the view's layer. Without it, hovering
785
+ * a view costs nothing to draw. It is turned on by itself for a view with a `hoverScale`, and for one
786
+ * whose layout or drawing reads `hovered` or `pressed`; call it from a subclass that draws its hover
787
+ * state some other way.
788
+ */
789
+ repaintOnPointerState() {
790
+ if (this._pointerStateRepaints) {
791
+ return;
792
+ }
793
+ this._pointerStateRepaints = true;
794
+ this.registerVar(this._hovered);
795
+ this.registerVar(this._pressed);
796
+ }
797
+ handleSubscribed() {
798
+ this._attached.value = true;
799
+ return this._onMounted?.();
800
+ }
801
+ handleUnsubscribed() {
802
+ this._attached.value = false;
803
+ this._hovered.value = false;
804
+ this._pressed.value = false;
805
+ this._downAction = null;
806
+ }
807
+ get visible() {
808
+ return this._visible;
809
+ }
810
+ set visible(value) {
811
+ this._visible.value = value;
812
+ }
813
+ get enabled() {
814
+ return this._enabled;
815
+ }
816
+ set enabled(value) {
817
+ this._enabled.value = value;
818
+ }
819
+ get location() {
820
+ return this._location;
821
+ }
822
+ set location(value) {
823
+ this._location.value = value;
824
+ }
825
+ get viewBox() {
826
+ return this._viewBox;
827
+ }
828
+ set viewBox(value) {
829
+ this._viewBox.value = value;
830
+ }
831
+ /** Opacity from 0 to 1, multiplied into the parent's; values outside are clamped. */
832
+ get alpha() {
833
+ this._alphaVar ??= this.createVary(this._alphaValue);
834
+ return this._alphaVar;
835
+ }
836
+ set alpha(value) {
837
+ value = clampAlpha(value);
838
+ if (this._alphaVar) this._alphaVar.value = value;
839
+ else if (this._alphaValue !== value) {
840
+ this._alphaValue = value;
841
+ this.invalidate();
842
+ }
843
+ }
844
+ /** Rotation in radians about the centre of the view's bounds. */
845
+ get rotation() {
846
+ this._rotationVar ??= this.createVary(this._rotationValue);
847
+ return this._rotationVar;
848
+ }
849
+ set rotation(value) {
850
+ if (this._rotationVar) this._rotationVar.value = value;
851
+ else if (this._rotationValue !== value) {
852
+ this._rotationValue = value;
853
+ this.invalidate();
854
+ }
855
+ }
856
+ /** Uniform scale about the centre of the view's bounds. */
857
+ get scale() {
858
+ this._scaleVar ??= this.createVary(this._scaleValue);
859
+ return this._scaleVar;
860
+ }
861
+ set scale(value) {
862
+ if (this._scaleVar) this._scaleVar.value = value;
863
+ else if (this._scaleValue !== value) {
864
+ this._scaleValue = value;
865
+ this.invalidate();
866
+ }
867
+ }
868
+ /** The scale applied on top of {@link scale} while hovered. */
869
+ get hoverScale() {
870
+ this._hoverScaleVar ??= this.createVary(this._hoverScaleValue);
871
+ return this._hoverScaleVar;
872
+ }
873
+ set hoverScale(value) {
874
+ if (value !== 1) {
875
+ this.repaintOnPointerState();
876
+ }
877
+ if (this._hoverScaleVar) this._hoverScaleVar.value = value;
878
+ else if (this._hoverScaleValue !== value) {
879
+ this._hoverScaleValue = value;
880
+ this.invalidate();
881
+ }
882
+ }
883
+ /** Whether the view takes pointer input. */
884
+ get hittable() {
885
+ this._hittableVar ??= this.createVary(this._hittableValue);
886
+ return this._hittableVar;
887
+ }
888
+ set hittable(value) {
889
+ if (this._hittableVar) this._hittableVar.value = value;
890
+ else if (this._hittableValue !== value) {
891
+ this._hittableValue = value;
892
+ this.invalidate();
893
+ }
894
+ }
895
+ /** The cursor shown while the pointer is over the view; null leaves it to the scene. */
896
+ get hoverCursor() {
897
+ this._hoverCursorVar ??= this.createVary(this._hoverCursorValue);
898
+ return this._hoverCursorVar;
899
+ }
900
+ set hoverCursor(value) {
901
+ if (this._hoverCursorVar) this._hoverCursorVar.value = value;
902
+ else if (this._hoverCursorValue !== value) {
903
+ this._hoverCursorValue = value;
904
+ this.invalidate();
905
+ }
906
+ }
907
+ get _alphaNow() {
908
+ return this._alphaVar ? this._alphaVar.value : this._alphaValue;
909
+ }
910
+ get _rotationNow() {
911
+ return this._rotationVar ? this._rotationVar.value : this._rotationValue;
912
+ }
913
+ get _scaleNow() {
914
+ return this._scaleVar ? this._scaleVar.value : this._scaleValue;
915
+ }
916
+ get _hoverScaleNow() {
917
+ return this._hoverScaleVar ? this._hoverScaleVar.value : this._hoverScaleValue;
918
+ }
919
+ /** Whether the pointer is over the view. Read while laying out or drawing, its changes repaint the view. */
920
+ get hovered() {
921
+ if (!this._pointerStateRepaints && isPainting()) {
922
+ this.repaintOnPointerState();
923
+ }
924
+ return this._hovered;
925
+ }
926
+ /** Whether the primary button is down on the view. Read while laying out or drawing, its changes repaint the view. */
927
+ get pressed() {
928
+ if (!this._pointerStateRepaints && isPainting()) {
929
+ this.repaintOnPointerState();
930
+ }
931
+ return this._pressed;
932
+ }
933
+ get attached() {
934
+ return this._attached;
935
+ }
936
+ get onClick() {
937
+ return this._onClick;
938
+ }
939
+ /**
940
+ * Lays the view out in `context`: its bounds in its parent's coordinates and whether it is on
941
+ * screen. Null when the view is hidden. Layouts override this to place their children.
942
+ */
943
+ getDrawState(context) {
944
+ if (!this._visible.value) {
945
+ return null;
946
+ }
947
+ const measuredBox = this._viewBox.value.constrainBy(context.viewBox);
948
+ const bounds = this._getDrawBounds(measuredBox);
949
+ const visibleInScreen = context.isVisible(bounds);
950
+ return new DrawStateImpl(this, context.offset, bounds, measuredBox, visibleInScreen, context.screenBounds);
951
+ }
952
+ getDrawBounds(measuredBox) {
953
+ return this._getDrawBounds(measuredBox);
954
+ }
955
+ _getDrawBounds(viewBox) {
956
+ const visibleBounds = this.doGetDrawBounds(viewBox);
957
+ const location = this._location.value;
958
+ if (location.isZero) {
959
+ return visibleBounds;
960
+ }
961
+ return visibleBounds.shift(location);
962
+ }
963
+ /** The view's size within the box its parent offers, before its location is added. */
964
+ doGetDrawBounds(measuredBox) {
965
+ return RectBounds.fromSize(
966
+ new Size(
967
+ measuredBox.width === "min" ? measuredBox.minWidth : measuredBox.width === "max" ? measuredBox.maxWidth : measuredBox.width,
968
+ measuredBox.height === "min" ? measuredBox.minHeight : measuredBox.height === "max" ? measuredBox.maxHeight : measuredBox.height
969
+ )
970
+ );
971
+ }
972
+ /**
973
+ * Draws the view as laid out in `state`: applies its location, scale, rotation and alpha, calls
974
+ * {@link doDraw}, and restores the context.
975
+ */
976
+ draw(context, state) {
977
+ if (!this._visible.value) {
978
+ return;
979
+ }
980
+ const viewAlpha = this._alphaNow;
981
+ if (viewAlpha === 0) {
982
+ return;
983
+ }
984
+ const rotation = this._rotationNow;
985
+ const baseScale = this._scaleNow;
986
+ if (!this._pointerStateRepaints && this._hoverScaleNow !== 1) {
987
+ this.repaintOnPointerState();
988
+ }
989
+ const hoverScale = this._hovered.value ? this._hoverScaleNow : 1;
990
+ const effectiveScale = baseScale * hoverScale;
991
+ const location = this._location.value;
992
+ const innerState = addOffsetToDrawState(state, location);
993
+ const transformed = effectiveScale !== 1 || rotation !== 0;
994
+ const saved = transformed ? context.getTransform() : null;
995
+ context.translate(location.x, location.y);
996
+ if (effectiveScale !== 1) {
997
+ const centerX = state.localBounds.size.width / 2;
998
+ const centerY = state.localBounds.size.height / 2;
999
+ context.translate(centerX, centerY);
1000
+ context.scale(effectiveScale, effectiveScale);
1001
+ context.translate(-centerX, -centerY);
1002
+ }
1003
+ if (rotation !== 0) {
1004
+ context.translate(state.localBounds.size.width / 2, state.localBounds.size.height / 2);
1005
+ context.rotate(rotation);
1006
+ context.translate(-state.localBounds.size.width / 2, -state.localBounds.size.height / 2);
1007
+ }
1008
+ if (viewAlpha === 1) {
1009
+ this.doDraw(context, innerState);
1010
+ } else {
1011
+ const globalAlpha = context.globalAlpha;
1012
+ context.globalAlpha = globalAlpha * viewAlpha;
1013
+ this.doDraw(context, innerState);
1014
+ context.globalAlpha = globalAlpha;
1015
+ }
1016
+ if (saved) {
1017
+ context.setTransform(saved);
1018
+ return;
1019
+ }
1020
+ context.translate(-location.x, -location.y);
1021
+ }
1022
+ _downAction = null;
1023
+ handleMouseLeave() {
1024
+ if (this._downAction) {
1025
+ this._downAction = null;
1026
+ }
1027
+ this._hovered.value = false;
1028
+ this._pressed.value = false;
1029
+ }
1030
+ /**
1031
+ * The event with its position mapped into this view's untransformed frame: undoes the scale
1032
+ * (including the hover scale while hovered) and the rotation that {@link draw} applies about the
1033
+ * centre of the view's bounds. The same event when the view is not transformed.
1034
+ */
1035
+ toLocalAction(action, state) {
1036
+ const rotation = this._rotationNow;
1037
+ const scale = this._scaleNow * (this._hovered.value ? this._hoverScaleNow : 1);
1038
+ if (rotation === 0 && scale === 1) {
1039
+ return action;
1040
+ }
1041
+ const bounds = state.localBounds;
1042
+ const pivotX = state.globalOffset.x + bounds.x + bounds.width / 2;
1043
+ const pivotY = state.globalOffset.y + bounds.y + bounds.height / 2;
1044
+ const position = inverseRotateScale(action.position, pivotX, pivotY, rotation, scale);
1045
+ return action.with({ position });
1046
+ }
1047
+ handleMouseAction(action, state) {
1048
+ if (!this._visible.value) {
1049
+ return false;
1050
+ }
1051
+ if (!this._enabled.value) {
1052
+ return false;
1053
+ }
1054
+ if (action.type === "leave") {
1055
+ this._hovered.value = false;
1056
+ this._pressed.value = false;
1057
+ if (this._downAction) {
1058
+ this._downAction = null;
1059
+ }
1060
+ return false;
1061
+ }
1062
+ if (!state.visibleInScreen) {
1063
+ return false;
1064
+ }
1065
+ if (!(this._hittableVar ? this._hittableVar.value : this._hittableValue)) {
1066
+ return false;
1067
+ }
1068
+ const localAction = this.toLocalAction(action, state);
1069
+ const actionPosition = localAction.position.subtract(state.globalOffset);
1070
+ const bounds = state.localBounds;
1071
+ const slop = this.hitSlop(localAction);
1072
+ if (!(slop > 0 ? bounds.withPadding(slop) : bounds).contains(actionPosition)) {
1073
+ this._hovered.value = false;
1074
+ this._pressed.value = false;
1075
+ if (this._downAction) {
1076
+ this._downAction = null;
1077
+ }
1078
+ return false;
1079
+ }
1080
+ const context = {
1081
+ context: action.context,
1082
+ viewportPosition: action.viewportPosition,
1083
+ position: actionPosition,
1084
+ localBounds: bounds
1085
+ };
1086
+ const hit = this.hitTest(context);
1087
+ if (!hit) {
1088
+ if (this._downAction !== null) {
1089
+ this._downAction = null;
1090
+ }
1091
+ this._hovered.value = false;
1092
+ this._pressed.value = false;
1093
+ return false;
1094
+ }
1095
+ action.target = this;
1096
+ this._hovered.value = true;
1097
+ if (this._downAction !== null) {
1098
+ if (this._downAction.viewportPosition.distance(action.viewportPosition) > action.clickSlop) {
1099
+ this._downAction = null;
1100
+ this._pressed.value = false;
1101
+ }
1102
+ }
1103
+ if (action.type === "down") {
1104
+ if (action.button === 0) {
1105
+ this._downAction = action;
1106
+ this._pressed.value = true;
1107
+ }
1108
+ } else if (action.type === "up") {
1109
+ const downAction = this._downAction;
1110
+ this._downAction = null;
1111
+ this._pressed.value = false;
1112
+ if (downAction !== null && downAction.button === 0 && action.button === 0) {
1113
+ const event = {
1114
+ target: this,
1115
+ position: action.position,
1116
+ viewportPosition: action.viewportPosition,
1117
+ localBounds: bounds,
1118
+ localPosition: actionPosition
1119
+ };
1120
+ action.deliverClick(() => this._onClick.dispatch(event, console.error));
1121
+ }
1122
+ }
1123
+ const cursor = this._hoverCursorVar ? this._hoverCursorVar.value : this._hoverCursorValue;
1124
+ if (cursor != null) {
1125
+ action.cursor = cursor;
1126
+ }
1127
+ return true;
1128
+ }
1129
+ /**
1130
+ * Draws the view's content in its own coordinates: `(0, 0)` is its top-left corner and
1131
+ * `state.localBounds.size` its size. Override this in a custom view.
1132
+ */
1133
+ doDraw(_context, _state) {
1134
+ }
1135
+ /**
1136
+ * Whether a pointer inside the view's bounds hits it; `context.position` is relative to the view's
1137
+ * parent, like its location. Default true: the whole rectangle.
1138
+ */
1139
+ hitTest(_context) {
1140
+ return true;
1141
+ }
1142
+ /**
1143
+ * How far outside its bounds, in its own units, a pointer may still reach {@link hitTest}: room for
1144
+ * a hit tolerance around thin shapes. Default 0.
1145
+ */
1146
+ hitSlop(_action) {
1147
+ return 0;
1148
+ }
1149
+ };
1150
+ function clampAlpha(value) {
1151
+ return value < 0 ? 0 : Math.min(value, 1);
1152
+ }
1153
+ function inverseRotateScale(point, pivotX, pivotY, rotation, scale) {
1154
+ let dx = point.x - pivotX;
1155
+ let dy = point.y - pivotY;
1156
+ if (scale !== 1 && scale !== 0) {
1157
+ dx /= scale;
1158
+ dy /= scale;
1159
+ }
1160
+ if (rotation !== 0) {
1161
+ const cos = Math.cos(-rotation);
1162
+ const sin = Math.sin(-rotation);
1163
+ const rx = dx * cos - dy * sin;
1164
+ const ry = dx * sin + dy * cos;
1165
+ dx = rx;
1166
+ dy = ry;
1167
+ }
1168
+ return new Point(pivotX + dx, pivotY + dy);
1169
+ }
1170
+ function updateOptions(options, change) {
1171
+ if (!options) {
1172
+ if (typeof change === "function") {
1173
+ return void 0;
1174
+ }
1175
+ return change;
1176
+ }
1177
+ if (typeof change === "function") {
1178
+ return {
1179
+ ...options,
1180
+ ...change(options)
1181
+ };
1182
+ }
1183
+ return {
1184
+ ...options,
1185
+ ...change
1186
+ };
1187
+ }
1188
+ var DrawStateImpl = class {
1189
+ constructor(view, globalOffset, localBounds, measuredBox, visibleInScreen, screenBounds, children, childrenOffsets, _shiftGlobal) {
1190
+ this.view = view;
1191
+ this.globalOffset = globalOffset;
1192
+ this.localBounds = localBounds;
1193
+ this.measuredBox = measuredBox;
1194
+ this.visibleInScreen = visibleInScreen;
1195
+ this.screenBounds = screenBounds;
1196
+ this.children = children;
1197
+ this.childrenOffsets = childrenOffsets;
1198
+ this._shiftGlobal = _shiftGlobal;
1199
+ }
1200
+ view;
1201
+ globalOffset;
1202
+ localBounds;
1203
+ measuredBox;
1204
+ visibleInScreen;
1205
+ screenBounds;
1206
+ children;
1207
+ childrenOffsets;
1208
+ _shiftGlobal;
1209
+ shiftGlobal(offset) {
1210
+ if (this._shiftGlobal) {
1211
+ return this._shiftGlobal(offset);
1212
+ }
1213
+ return new ShiftedDrawState(this, offset);
1214
+ }
1215
+ };
1216
+ var ShiftedDrawState = class _ShiftedDrawState {
1217
+ constructor(_base, _offset) {
1218
+ this._base = _base;
1219
+ this._offset = _offset;
1220
+ this.globalOffset = _base.globalOffset.add(_offset);
1221
+ }
1222
+ _base;
1223
+ _offset;
1224
+ globalOffset;
1225
+ _visibleInScreen;
1226
+ _children;
1227
+ _childrenShifted = false;
1228
+ get view() {
1229
+ return this._base.view;
1230
+ }
1231
+ get localBounds() {
1232
+ return this._base.localBounds;
1233
+ }
1234
+ get measuredBox() {
1235
+ return this._base.measuredBox;
1236
+ }
1237
+ get screenBounds() {
1238
+ return this._base.screenBounds;
1239
+ }
1240
+ get childrenOffsets() {
1241
+ return this._base.childrenOffsets;
1242
+ }
1243
+ get visibleInScreen() {
1244
+ if (this._visibleInScreen === void 0) {
1245
+ this._visibleInScreen = this._base.screenBounds.intersects(this._base.localBounds.shift(this.globalOffset));
1246
+ }
1247
+ return this._visibleInScreen;
1248
+ }
1249
+ get children() {
1250
+ if (!this._childrenShifted) {
1251
+ this._childrenShifted = true;
1252
+ const offset = this._offset;
1253
+ this._children = this._base.children?.map((child) => child.shiftGlobal(offset));
1254
+ }
1255
+ return this._children;
1256
+ }
1257
+ shiftGlobal(offset) {
1258
+ return new _ShiftedDrawState(this._base, this._offset.add(offset));
1259
+ }
1260
+ };
1261
+ function addOffsetToDrawState(state, offset) {
1262
+ if (offset.isZero) {
1263
+ return state;
1264
+ }
1265
+ return new DrawStateImpl(
1266
+ state.view,
1267
+ state.globalOffset.add(offset),
1268
+ state.localBounds.shift(offset.negate()),
1269
+ state.measuredBox,
1270
+ state.visibleInScreen,
1271
+ state.screenBounds,
1272
+ state.children,
1273
+ state.childrenOffsets
1274
+ );
1275
+ }
1276
+ function retargetDrawState(state, view) {
1277
+ return new DrawStateImpl(
1278
+ view,
1279
+ state.globalOffset,
1280
+ state.localBounds,
1281
+ state.measuredBox,
1282
+ state.visibleInScreen,
1283
+ state.screenBounds,
1284
+ state.children,
1285
+ state.childrenOffsets
1286
+ );
1287
+ }
1288
+
1289
+ // src/utils/dom.ts
1290
+ function createCanvasElement() {
1291
+ const document = globalThis.document;
1292
+ if (!document) {
1293
+ throw new Error("sceniq needs a DOM document to create canvases");
1294
+ }
1295
+ return document.createElement("canvas");
1296
+ }
1297
+ var measureContext;
1298
+ function getMeasureContext() {
1299
+ if (measureContext !== void 0) {
1300
+ return measureContext;
1301
+ }
1302
+ if (typeof globalThis.OffscreenCanvas === "function") {
1303
+ measureContext = new OffscreenCanvas(1, 1).getContext("2d");
1304
+ }
1305
+ if (!measureContext && globalThis.document) {
1306
+ measureContext = globalThis.document.createElement("canvas").getContext("2d");
1307
+ }
1308
+ measureContext ??= null;
1309
+ return measureContext;
1310
+ }
1311
+
1312
+ export {
1313
+ Point,
1314
+ Size,
1315
+ RectBounds,
1316
+ createCanvasElement,
1317
+ getMeasureContext,
1318
+ beginPaint,
1319
+ endPaint,
1320
+ clamp,
1321
+ ViewBox,
1322
+ LiveObject,
1323
+ View,
1324
+ inverseRotateScale,
1325
+ updateOptions,
1326
+ DrawStateImpl,
1327
+ retargetDrawState
1328
+ };