@tldraw/editor 3.16.0-canary.d04b7fc312b4 → 3.16.0-canary.d3f0c2d5313c

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 (129) hide show
  1. package/dist-cjs/index.d.ts +53 -0
  2. package/dist-cjs/index.js +1 -1
  3. package/dist-cjs/index.js.map +2 -2
  4. package/dist-cjs/lib/TldrawEditor.js +5 -1
  5. package/dist-cjs/lib/TldrawEditor.js.map +2 -2
  6. package/dist-cjs/lib/components/Shape.js +7 -10
  7. package/dist-cjs/lib/components/Shape.js.map +2 -2
  8. package/dist-cjs/lib/components/default-components/DefaultCanvas.js +4 -23
  9. package/dist-cjs/lib/components/default-components/DefaultCanvas.js.map +2 -2
  10. package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js +1 -1
  11. package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js.map +2 -2
  12. package/dist-cjs/lib/config/TLUserPreferences.js +1 -1
  13. package/dist-cjs/lib/config/TLUserPreferences.js.map +2 -2
  14. package/dist-cjs/lib/editor/Editor.js +38 -11
  15. package/dist-cjs/lib/editor/Editor.js.map +2 -2
  16. package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js +1 -1
  17. package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js.map +2 -2
  18. package/dist-cjs/lib/editor/shapes/ShapeUtil.js +13 -0
  19. package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
  20. package/dist-cjs/lib/exports/getSvgJsx.js +34 -14
  21. package/dist-cjs/lib/exports/getSvgJsx.js.map +2 -2
  22. package/dist-cjs/lib/hooks/useCanvasEvents.js +7 -5
  23. package/dist-cjs/lib/hooks/useCanvasEvents.js.map +2 -2
  24. package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js +4 -1
  25. package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js.map +2 -2
  26. package/dist-cjs/lib/license/LicenseManager.js +17 -22
  27. package/dist-cjs/lib/license/LicenseManager.js.map +2 -2
  28. package/dist-cjs/lib/license/LicenseProvider.js +5 -0
  29. package/dist-cjs/lib/license/LicenseProvider.js.map +2 -2
  30. package/dist-cjs/lib/license/useLicenseManagerState.js.map +2 -2
  31. package/dist-cjs/lib/options.js +6 -0
  32. package/dist-cjs/lib/options.js.map +2 -2
  33. package/dist-cjs/lib/primitives/Box.js +3 -0
  34. package/dist-cjs/lib/primitives/Box.js.map +2 -2
  35. package/dist-cjs/lib/primitives/geometry/Geometry2d.js +26 -0
  36. package/dist-cjs/lib/primitives/geometry/Geometry2d.js.map +2 -2
  37. package/dist-cjs/lib/primitives/geometry/Group2d.js +3 -0
  38. package/dist-cjs/lib/primitives/geometry/Group2d.js.map +2 -2
  39. package/dist-cjs/lib/utils/reparenting.js +2 -35
  40. package/dist-cjs/lib/utils/reparenting.js.map +3 -3
  41. package/dist-cjs/version.js +3 -3
  42. package/dist-cjs/version.js.map +1 -1
  43. package/dist-esm/index.d.mts +53 -0
  44. package/dist-esm/index.mjs +1 -1
  45. package/dist-esm/index.mjs.map +2 -2
  46. package/dist-esm/lib/TldrawEditor.mjs +5 -1
  47. package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
  48. package/dist-esm/lib/components/Shape.mjs +7 -10
  49. package/dist-esm/lib/components/Shape.mjs.map +2 -2
  50. package/dist-esm/lib/components/default-components/DefaultCanvas.mjs +4 -23
  51. package/dist-esm/lib/components/default-components/DefaultCanvas.mjs.map +2 -2
  52. package/dist-esm/lib/components/default-components/DefaultErrorFallback.mjs +1 -1
  53. package/dist-esm/lib/components/default-components/DefaultErrorFallback.mjs.map +2 -2
  54. package/dist-esm/lib/config/TLUserPreferences.mjs +1 -1
  55. package/dist-esm/lib/config/TLUserPreferences.mjs.map +2 -2
  56. package/dist-esm/lib/editor/Editor.mjs +38 -11
  57. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  58. package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs +1 -1
  59. package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs.map +2 -2
  60. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs +13 -0
  61. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
  62. package/dist-esm/lib/exports/getSvgJsx.mjs +34 -14
  63. package/dist-esm/lib/exports/getSvgJsx.mjs.map +2 -2
  64. package/dist-esm/lib/hooks/useCanvasEvents.mjs +7 -5
  65. package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +2 -2
  66. package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs +4 -1
  67. package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs.map +2 -2
  68. package/dist-esm/lib/license/LicenseManager.mjs +17 -22
  69. package/dist-esm/lib/license/LicenseManager.mjs.map +2 -2
  70. package/dist-esm/lib/license/LicenseProvider.mjs +5 -0
  71. package/dist-esm/lib/license/LicenseProvider.mjs.map +2 -2
  72. package/dist-esm/lib/license/useLicenseManagerState.mjs.map +2 -2
  73. package/dist-esm/lib/options.mjs +6 -0
  74. package/dist-esm/lib/options.mjs.map +2 -2
  75. package/dist-esm/lib/primitives/Box.mjs +4 -1
  76. package/dist-esm/lib/primitives/Box.mjs.map +2 -2
  77. package/dist-esm/lib/primitives/geometry/Geometry2d.mjs +29 -1
  78. package/dist-esm/lib/primitives/geometry/Geometry2d.mjs.map +2 -2
  79. package/dist-esm/lib/primitives/geometry/Group2d.mjs +3 -0
  80. package/dist-esm/lib/primitives/geometry/Group2d.mjs.map +2 -2
  81. package/dist-esm/lib/utils/reparenting.mjs +3 -40
  82. package/dist-esm/lib/utils/reparenting.mjs.map +2 -2
  83. package/dist-esm/version.mjs +3 -3
  84. package/dist-esm/version.mjs.map +1 -1
  85. package/editor.css +8 -0
  86. package/package.json +14 -37
  87. package/src/index.ts +1 -0
  88. package/src/lib/TldrawEditor.tsx +6 -1
  89. package/src/lib/components/Shape.tsx +6 -12
  90. package/src/lib/components/default-components/DefaultCanvas.tsx +5 -22
  91. package/src/lib/components/default-components/DefaultErrorFallback.tsx +1 -1
  92. package/src/lib/config/TLUserPreferences.ts +1 -1
  93. package/src/lib/editor/Editor.test.ts +12 -11
  94. package/src/lib/editor/Editor.ts +48 -22
  95. package/src/lib/editor/managers/ClickManager/ClickManager.test.ts +15 -14
  96. package/src/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.test.ts +16 -15
  97. package/src/lib/editor/managers/FocusManager/FocusManager.test.ts +49 -48
  98. package/src/lib/editor/managers/FontManager/FontManager.test.ts +24 -23
  99. package/src/lib/editor/managers/HistoryManager/HistoryManager.test.ts +7 -6
  100. package/src/lib/editor/managers/ScribbleManager/ScribbleManager.test.ts +12 -11
  101. package/src/lib/editor/managers/SnapManager/SnapManager.test.ts +57 -50
  102. package/src/lib/editor/managers/TextManager/TextManager.test.ts +51 -26
  103. package/src/lib/editor/managers/TickManager/TickManager.test.ts +14 -13
  104. package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.test.ts +21 -26
  105. package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.ts +1 -1
  106. package/src/lib/editor/shapes/ShapeUtil.ts +35 -0
  107. package/src/lib/exports/getSvgJsx.test.ts +868 -0
  108. package/src/lib/exports/getSvgJsx.tsx +76 -19
  109. package/src/lib/hooks/useCanvasEvents.ts +6 -6
  110. package/src/lib/hooks/usePassThroughWheelEvents.ts +6 -1
  111. package/src/lib/license/LicenseManager.test.ts +61 -52
  112. package/src/lib/license/LicenseManager.ts +32 -24
  113. package/src/lib/license/LicenseProvider.tsx +8 -0
  114. package/src/lib/license/Watermark.test.tsx +2 -1
  115. package/src/lib/license/useLicenseManagerState.ts +2 -2
  116. package/src/lib/options.ts +6 -0
  117. package/src/lib/primitives/Box.test.ts +126 -0
  118. package/src/lib/primitives/Box.ts +10 -1
  119. package/src/lib/primitives/geometry/Geometry2d.ts +49 -0
  120. package/src/lib/primitives/geometry/Group2d.ts +4 -0
  121. package/src/lib/utils/reparenting.ts +3 -69
  122. package/src/lib/utils/sync/LocalIndexedDb.test.ts +2 -1
  123. package/src/lib/utils/sync/TLLocalSyncClient.test.ts +15 -15
  124. package/src/version.ts +3 -3
  125. package/dist-cjs/lib/utils/nearestMultiple.js +0 -34
  126. package/dist-cjs/lib/utils/nearestMultiple.js.map +0 -7
  127. package/dist-esm/lib/utils/nearestMultiple.mjs +0 -14
  128. package/dist-esm/lib/utils/nearestMultiple.mjs.map +0 -7
  129. package/src/lib/utils/nearestMultiple.ts +0 -13
@@ -9,6 +9,8 @@ import {
9
9
  intersectLineSegmentPolyline,
10
10
  intersectPolys,
11
11
  linesIntersect,
12
+ polygonIntersectsPolyline,
13
+ polygonsIntersect,
12
14
  } from '../intersect'
13
15
  import { approximately, pointInPolygon } from '../utils'
14
16
 
@@ -256,6 +258,53 @@ export abstract class Geometry2d {
256
258
  )
257
259
  }
258
260
 
261
+ overlapsPolygon(_polygon: VecLike[]): boolean {
262
+ const polygon = _polygon.map((v) => Vec.From(v))
263
+
264
+ // Otherwise, check if the geometry itself overlaps the polygon
265
+ const { vertices, center, isFilled, isEmptyLabel, isClosed } = this
266
+
267
+ // We'll do things in order of cheapest to most expensive checks
268
+
269
+ // Skip empty labels
270
+ if (isEmptyLabel) return false
271
+
272
+ // If any of the geometry's vertices are inside the polygon, it's inside
273
+ if (vertices.some((v) => pointInPolygon(v, polygon))) {
274
+ return true
275
+ }
276
+
277
+ // If the geometry is filled and closed and its center is inside the polygon, it's inside
278
+ if (isClosed) {
279
+ if (isFilled) {
280
+ // If closed and filled, check if the center is inside the polygon
281
+ if (pointInPolygon(center, polygon)) {
282
+ return true
283
+ }
284
+
285
+ // ..then, slightly more expensive check, see the geometry covers the entire polygon but not its center
286
+ if (polygon.every((v) => pointInPolygon(v, vertices))) {
287
+ return true
288
+ }
289
+ }
290
+
291
+ // If any the geometry's vertices intersect the edge of the polygon, it's inside.
292
+ // for example when a rotated rectangle is moved over the corner of a parent rectangle
293
+ // If the geometry is closed, intersect as a polygon
294
+ if (polygonsIntersect(polygon, vertices)) {
295
+ return true
296
+ }
297
+ } else {
298
+ // If the geometry is not closed, intersect as a polyline
299
+ if (polygonIntersectsPolyline(polygon, vertices)) {
300
+ return true
301
+ }
302
+ }
303
+
304
+ // If none of the above checks passed, the geometry is outside the polygon
305
+ return false
306
+ }
307
+
259
308
  transform(transform: MatModel, opts?: TransformedGeometry2dOptions): Geometry2d {
260
309
  return new TransformedGeometry2d(this, transform, opts)
261
310
  }
@@ -236,4 +236,8 @@ export class Group2d extends Geometry2d {
236
236
  getSvgPathData(): string {
237
237
  return this.children.map((c, i) => (c.isLabel ? '' : c.getSvgPathData(i === 0))).join(' ')
238
238
  }
239
+
240
+ overlapsPolygon(polygon: VecLike[]): boolean {
241
+ return this.children.some((child) => child.overlapsPolygon(polygon))
242
+ }
239
243
  }
@@ -2,15 +2,7 @@ import { EMPTY_ARRAY } from '@tldraw/state'
2
2
  import { TLGroupShape, TLParentId, TLShape, TLShapeId } from '@tldraw/tlschema'
3
3
  import { IndexKey, compact, getIndexAbove, getIndexBetween } from '@tldraw/utils'
4
4
  import { Editor } from '../editor/Editor'
5
- import { Vec } from '../primitives/Vec'
6
- import { Geometry2d } from '../primitives/geometry/Geometry2d'
7
- import { Group2d } from '../primitives/geometry/Group2d'
8
- import {
9
- intersectPolygonPolygon,
10
- polygonIntersectsPolyline,
11
- polygonsIntersect,
12
- } from '../primitives/intersect'
13
- import { pointInPolygon } from '../primitives/utils'
5
+ import { intersectPolygonPolygon } from '../primitives/intersect'
14
6
 
15
7
  /**
16
8
  * Reparents shapes that are no longer contained within their parent shapes.
@@ -189,68 +181,10 @@ function getOverlappingShapes<T extends TLShape[] | TLShapeId[]>(
189
181
 
190
182
  const geometry = editor.getShapeGeometry(childId)
191
183
 
192
- return doesGeometryOverlapPolygon(geometry, parentPolygonInShapeShape)
184
+ return geometry.overlapsPolygon(parentPolygonInShapeShape)
193
185
  })
194
186
  }
195
187
 
196
- /**
197
- * @public
198
- */
199
- export function doesGeometryOverlapPolygon(
200
- geometry: Geometry2d,
201
- parentCornersInShapeSpace: Vec[]
202
- ): boolean {
203
- // If the child is a group, check if any of its children overlap the box
204
- if (geometry instanceof Group2d) {
205
- return geometry.children.some((childGeometry) =>
206
- doesGeometryOverlapPolygon(childGeometry, parentCornersInShapeSpace)
207
- )
208
- }
209
-
210
- // Otherwise, check if the geometry overlaps the box
211
- const { vertices, center, isFilled, isEmptyLabel, isClosed } = geometry
212
-
213
- // We'll do things in order of cheapest to most expensive checks
214
-
215
- // Skip empty labels
216
- if (isEmptyLabel) return false
217
-
218
- // If any of the shape's vertices are inside the occluder, it's inside
219
- if (vertices.some((v) => pointInPolygon(v, parentCornersInShapeSpace))) {
220
- return true
221
- }
222
-
223
- // If the shape is filled and closed and its center is inside the parent, it's inside
224
- if (isClosed) {
225
- if (isFilled) {
226
- // If closed and filled, check if the center is inside the parent
227
- if (pointInPolygon(center, parentCornersInShapeSpace)) {
228
- return true
229
- }
230
-
231
- // ..then, slightly more expensive check, see the shape covers the entire parent but not its center
232
- if (parentCornersInShapeSpace.every((v) => pointInPolygon(v, vertices))) {
233
- return true
234
- }
235
- }
236
-
237
- // If any the shape's vertices intersect the edge of the occluder, it's inside.
238
- // for example when a rotated rectangle is moved over the corner of a parent rectangle
239
- // If the child shape is closed, intersect as a polygon
240
- if (polygonsIntersect(parentCornersInShapeSpace, vertices)) {
241
- return true
242
- }
243
- } else {
244
- // if the child shape is not closed, intersect as a polyline
245
- if (polygonIntersectsPolyline(parentCornersInShapeSpace, vertices)) {
246
- return true
247
- }
248
- }
249
-
250
- // If none of the above checks passed, the shape is outside the parent
251
- return false
252
- }
253
-
254
188
  /**
255
189
  * Get the shapes that will be reparented to new parents when the shapes are dropped.
256
190
  *
@@ -354,7 +288,7 @@ export function getDroppedShapesToNewParents(
354
288
  .applyToPoints(parentPagePolygon)
355
289
 
356
290
  // If the shape overlaps the parent polygon, reparent it to that parent
357
- if (doesGeometryOverlapPolygon(editor.getShapeGeometry(shape), parentPolygonInShapeSpace)) {
291
+ if (editor.getShapeGeometry(shape).overlapsPolygon(parentPolygonInShapeSpace)) {
358
292
  // Use the util to check if the shape can be reparented to the parent
359
293
  if (
360
294
  !editor.getShapeUtil(parentShape).canReceiveNewChildrenOfType?.(parentShape, shape.type)
@@ -1,12 +1,13 @@
1
1
  import { createTLSchema } from '@tldraw/tlschema'
2
2
  import { openDB } from 'idb'
3
+ import { vi } from 'vitest'
3
4
  import { hardReset } from './hardReset'
4
5
  import { getAllIndexDbNames, LocalIndexedDb } from './LocalIndexedDb'
5
6
 
6
7
  const schema = createTLSchema({ shapes: {}, bindings: {} })
7
8
  describe('LocalIndexedDb', () => {
8
9
  beforeEach(() => {
9
- jest.useRealTimers()
10
+ vi.useRealTimers()
10
11
  })
11
12
  afterEach(async () => {
12
13
  await hardReset({ shouldReload: false })
@@ -1,6 +1,6 @@
1
1
  import { PageRecordType } from '@tldraw/tlschema'
2
2
  import { IndexKey, promiseWithResolve } from '@tldraw/utils'
3
- import { afterEach } from 'node:test'
3
+ import { Mock, vi } from 'vitest'
4
4
  import { createTLStore } from '../../config/createTLStore'
5
5
  import { TLLocalSyncClient } from './TLLocalSyncClient'
6
6
  import { hardReset } from './hardReset'
@@ -10,20 +10,20 @@ class BroadcastChannelMock {
10
10
  constructor(_name: string) {
11
11
  // noop
12
12
  }
13
- postMessage = jest.fn((_msg: any) => {
13
+ postMessage = vi.fn((_msg: any) => {
14
14
  // noop
15
15
  })
16
- close = jest.fn(() => {
16
+ close = vi.fn(() => {
17
17
  // noop
18
18
  })
19
19
  }
20
20
 
21
21
  function testClient(channel = new BroadcastChannelMock('test')) {
22
22
  const store = createTLStore({ shapeUtils: [], bindingUtils: [] })
23
- const onLoad = jest.fn(() => {
23
+ const onLoad = vi.fn(() => {
24
24
  return
25
25
  })
26
- const onLoadError = jest.fn(() => {
26
+ const onLoadError = vi.fn(() => {
27
27
  return
28
28
  })
29
29
  const client = new TLLocalSyncClient(
@@ -36,26 +36,26 @@ function testClient(channel = new BroadcastChannelMock('test')) {
36
36
  channel
37
37
  )
38
38
 
39
- client.db.storeSnapshot = jest.fn(() => Promise.resolve())
40
- client.db.storeChanges = jest.fn(() => Promise.resolve())
39
+ client.db.storeSnapshot = vi.fn(() => Promise.resolve())
40
+ client.db.storeChanges = vi.fn(() => Promise.resolve())
41
41
 
42
42
  return {
43
- client: client as { db: { storeSnapshot: jest.Mock; storeChanges: jest.Mock } } & typeof client,
43
+ client: client as { db: { storeSnapshot: Mock; storeChanges: Mock } } & typeof client,
44
44
  store,
45
45
  onLoad,
46
46
  onLoadError,
47
47
  channel,
48
48
  tick: async () => {
49
- jest.advanceTimersByTime(500)
49
+ vi.advanceTimersByTime(500)
50
50
  await Promise.resolve()
51
51
  await client.db.pending()
52
- jest.advanceTimersByTime(500)
52
+ vi.advanceTimersByTime(500)
53
53
  await Promise.resolve()
54
54
  },
55
55
  }
56
56
  }
57
57
 
58
- const reloadMock = jest.fn()
58
+ const reloadMock = vi.fn()
59
59
 
60
60
  beforeAll(() => {
61
61
  Object.defineProperty(window, 'location', {
@@ -65,14 +65,14 @@ beforeAll(() => {
65
65
  })
66
66
 
67
67
  beforeEach(() => {
68
- jest.clearAllMocks()
68
+ vi.clearAllMocks()
69
69
  })
70
70
 
71
71
  afterEach(async () => {
72
72
  await hardReset({ shouldReload: false })
73
73
  })
74
74
 
75
- jest.useFakeTimers()
75
+ vi.useFakeTimers()
76
76
 
77
77
  test('the client connects on instantiation, announcing its schema', async () => {
78
78
  const { channel, tick } = testClient()
@@ -86,7 +86,7 @@ test('the client connects on instantiation, announcing its schema', async () =>
86
86
  test('when a client receives an announce with a newer schema version it reloads itself', async () => {
87
87
  const { client, channel, onLoadError, tick } = testClient()
88
88
  await tick()
89
- jest.advanceTimersByTime(10000)
89
+ vi.advanceTimersByTime(10000)
90
90
  expect(reloadMock).not.toHaveBeenCalled()
91
91
  channel.onmessage?.({
92
92
  data: {
@@ -104,7 +104,7 @@ test('when a client receives an announce with a newer schema version it reloads
104
104
  test('when a client receives an announce with a newer schema version shortly after loading it does not reload but instead reports a loadError', async () => {
105
105
  const { client, channel, onLoadError, tick } = testClient()
106
106
  await tick()
107
- jest.advanceTimersByTime(1000)
107
+ vi.advanceTimersByTime(1000)
108
108
  expect(reloadMock).not.toHaveBeenCalled()
109
109
  channel.onmessage?.({
110
110
  data: {
package/src/version.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  // This file is automatically generated by internal/scripts/refresh-assets.ts.
2
2
  // Do not edit manually. Or do, I'm a comment, not a cop.
3
3
 
4
- export const version = '3.16.0-canary.d04b7fc312b4'
4
+ export const version = '3.16.0-canary.d3f0c2d5313c'
5
5
  export const publishDates = {
6
6
  major: '2024-09-13T14:36:29.063Z',
7
- minor: '2025-08-14T09:26:55.295Z',
8
- patch: '2025-08-14T09:26:55.295Z',
7
+ minor: '2025-09-01T15:21:11.358Z',
8
+ patch: '2025-09-01T15:21:11.358Z',
9
9
  }
@@ -1,34 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var nearestMultiple_exports = {};
20
- __export(nearestMultiple_exports, {
21
- nearestMultiple: () => nearestMultiple
22
- });
23
- module.exports = __toCommonJS(nearestMultiple_exports);
24
- function gcd(a, b) {
25
- return b === 0 ? a : gcd(b, a % b);
26
- }
27
- function nearestMultiple(float) {
28
- const decimal = float.toString().split(".")[1];
29
- if (!decimal) return 1;
30
- const denominator = Math.pow(10, decimal.length);
31
- const numerator = parseInt(decimal, 10);
32
- return denominator / gcd(numerator, denominator);
33
- }
34
- //# sourceMappingURL=nearestMultiple.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/lib/utils/nearestMultiple.ts"],
4
- "sourcesContent": ["// Euclidean algorithm to find the GCD\nfunction gcd(a: number, b: number): number {\n\treturn b === 0 ? a : gcd(b, a % b)\n}\n\n// Returns the lowest value that the given number can be multiplied by to reach an integer\nexport function nearestMultiple(float: number) {\n\tconst decimal = float.toString().split('.')[1]\n\tif (!decimal) return 1\n\tconst denominator = Math.pow(10, decimal.length)\n\tconst numerator = parseInt(decimal, 10)\n\treturn denominator / gcd(numerator, denominator)\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,SAAS,IAAI,GAAW,GAAmB;AAC1C,SAAO,MAAM,IAAI,IAAI,IAAI,GAAG,IAAI,CAAC;AAClC;AAGO,SAAS,gBAAgB,OAAe;AAC9C,QAAM,UAAU,MAAM,SAAS,EAAE,MAAM,GAAG,EAAE,CAAC;AAC7C,MAAI,CAAC,QAAS,QAAO;AACrB,QAAM,cAAc,KAAK,IAAI,IAAI,QAAQ,MAAM;AAC/C,QAAM,YAAY,SAAS,SAAS,EAAE;AACtC,SAAO,cAAc,IAAI,WAAW,WAAW;AAChD;",
6
- "names": []
7
- }
@@ -1,14 +0,0 @@
1
- function gcd(a, b) {
2
- return b === 0 ? a : gcd(b, a % b);
3
- }
4
- function nearestMultiple(float) {
5
- const decimal = float.toString().split(".")[1];
6
- if (!decimal) return 1;
7
- const denominator = Math.pow(10, decimal.length);
8
- const numerator = parseInt(decimal, 10);
9
- return denominator / gcd(numerator, denominator);
10
- }
11
- export {
12
- nearestMultiple
13
- };
14
- //# sourceMappingURL=nearestMultiple.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/lib/utils/nearestMultiple.ts"],
4
- "sourcesContent": ["// Euclidean algorithm to find the GCD\nfunction gcd(a: number, b: number): number {\n\treturn b === 0 ? a : gcd(b, a % b)\n}\n\n// Returns the lowest value that the given number can be multiplied by to reach an integer\nexport function nearestMultiple(float: number) {\n\tconst decimal = float.toString().split('.')[1]\n\tif (!decimal) return 1\n\tconst denominator = Math.pow(10, decimal.length)\n\tconst numerator = parseInt(decimal, 10)\n\treturn denominator / gcd(numerator, denominator)\n}\n"],
5
- "mappings": "AACA,SAAS,IAAI,GAAW,GAAmB;AAC1C,SAAO,MAAM,IAAI,IAAI,IAAI,GAAG,IAAI,CAAC;AAClC;AAGO,SAAS,gBAAgB,OAAe;AAC9C,QAAM,UAAU,MAAM,SAAS,EAAE,MAAM,GAAG,EAAE,CAAC;AAC7C,MAAI,CAAC,QAAS,QAAO;AACrB,QAAM,cAAc,KAAK,IAAI,IAAI,QAAQ,MAAM;AAC/C,QAAM,YAAY,SAAS,SAAS,EAAE;AACtC,SAAO,cAAc,IAAI,WAAW,WAAW;AAChD;",
6
- "names": []
7
- }
@@ -1,13 +0,0 @@
1
- // Euclidean algorithm to find the GCD
2
- function gcd(a: number, b: number): number {
3
- return b === 0 ? a : gcd(b, a % b)
4
- }
5
-
6
- // Returns the lowest value that the given number can be multiplied by to reach an integer
7
- export function nearestMultiple(float: number) {
8
- const decimal = float.toString().split('.')[1]
9
- if (!decimal) return 1
10
- const denominator = Math.pow(10, decimal.length)
11
- const numerator = parseInt(decimal, 10)
12
- return denominator / gcd(numerator, denominator)
13
- }