@tldraw/editor 3.16.0-canary.3fbab9bfb8e0 → 3.16.0-canary.460bdab3938b
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.
- package/dist-cjs/index.d.ts +14 -0
- package/dist-cjs/index.js +1 -1
- package/dist-cjs/lib/TldrawEditor.js +5 -1
- package/dist-cjs/lib/TldrawEditor.js.map +2 -2
- package/dist-cjs/lib/components/Shape.js +7 -10
- package/dist-cjs/lib/components/Shape.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js +2 -21
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js.map +2 -2
- package/dist-cjs/lib/editor/Editor.js +17 -0
- package/dist-cjs/lib/editor/Editor.js.map +2 -2
- package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js +4 -1
- package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js.map +2 -2
- package/dist-cjs/version.js +3 -3
- package/dist-cjs/version.js.map +1 -1
- package/dist-esm/index.d.mts +14 -0
- package/dist-esm/index.mjs +1 -1
- package/dist-esm/lib/TldrawEditor.mjs +5 -1
- package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
- package/dist-esm/lib/components/Shape.mjs +7 -10
- package/dist-esm/lib/components/Shape.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs +2 -21
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs.map +2 -2
- package/dist-esm/lib/editor/Editor.mjs +17 -0
- package/dist-esm/lib/editor/Editor.mjs.map +2 -2
- package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs +4 -1
- package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs.map +2 -2
- package/dist-esm/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/package.json +7 -7
- package/src/lib/TldrawEditor.tsx +6 -1
- package/src/lib/components/Shape.tsx +6 -12
- package/src/lib/components/default-components/DefaultCanvas.tsx +2 -21
- package/src/lib/editor/Editor.ts +18 -0
- package/src/lib/hooks/usePassThroughWheelEvents.ts +6 -1
- package/src/version.ts +3 -3
- package/dist-cjs/lib/utils/nearestMultiple.js +0 -34
- package/dist-cjs/lib/utils/nearestMultiple.js.map +0 -7
- package/dist-esm/lib/utils/nearestMultiple.mjs +0 -14
- package/dist-esm/lib/utils/nearestMultiple.mjs.map +0 -7
- package/src/lib/utils/nearestMultiple.ts +0 -13
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { useEffect } from "react";
|
|
2
2
|
import { preventDefault } from "../utils/dom.mjs";
|
|
3
3
|
import { useContainer } from "./useContainer.mjs";
|
|
4
|
+
import { useMaybeEditor } from "./useEditor.mjs";
|
|
4
5
|
function usePassThroughWheelEvents(ref) {
|
|
5
6
|
if (!ref) throw Error("usePassThroughWheelEvents must be passed a ref");
|
|
6
7
|
const container = useContainer();
|
|
8
|
+
const editor = useMaybeEditor();
|
|
7
9
|
useEffect(() => {
|
|
8
10
|
function onWheel(e) {
|
|
11
|
+
if (!editor?.getInstanceState().isFocused) return;
|
|
9
12
|
if (e.isSpecialRedispatchedEvent) return;
|
|
10
13
|
const elm2 = ref.current;
|
|
11
14
|
if (elm2 && elm2.scrollHeight > elm2.clientHeight) {
|
|
@@ -24,7 +27,7 @@ function usePassThroughWheelEvents(ref) {
|
|
|
24
27
|
return () => {
|
|
25
28
|
elm.removeEventListener("wheel", onWheel);
|
|
26
29
|
};
|
|
27
|
-
}, [container, ref]);
|
|
30
|
+
}, [container, editor, ref]);
|
|
28
31
|
}
|
|
29
32
|
export {
|
|
30
33
|
usePassThroughWheelEvents
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/lib/hooks/usePassThroughWheelEvents.ts"],
|
|
4
|
-
"sourcesContent": ["import { RefObject, useEffect } from 'react'\nimport { preventDefault } from '../utils/dom'\nimport { useContainer } from './useContainer'\n\n/** @public */\nexport function usePassThroughWheelEvents(ref: RefObject<HTMLElement>) {\n\tif (!ref) throw Error('usePassThroughWheelEvents must be passed a ref')\n\tconst container = useContainer()\n\n\tuseEffect(() => {\n\t\tfunction onWheel(e: WheelEvent) {\n\t\t\tif ((e as any).isSpecialRedispatchedEvent) return\n\n\t\t\t// if the element is scrollable, don't redispatch the event\n\t\t\tconst elm = ref.current\n\t\t\tif (elm && elm.scrollHeight > elm.clientHeight) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tpreventDefault(e)\n\t\t\tconst cvs = container.querySelector('.tl-canvas')\n\t\t\tif (!cvs) return\n\t\t\tconst newEvent = new WheelEvent('wheel', e as any)\n\t\t\t;(newEvent as any).isSpecialRedispatchedEvent = true\n\t\t\tcvs.dispatchEvent(newEvent)\n\t\t}\n\n\t\tconst elm = ref.current\n\t\tif (!elm) return\n\n\t\telm.addEventListener('wheel', onWheel, { passive: false })\n\t\treturn () => {\n\t\t\telm.removeEventListener('wheel', onWheel)\n\t\t}\n\t}, [container, ref])\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAoB,iBAAiB;AACrC,SAAS,sBAAsB;AAC/B,SAAS,oBAAoB;
|
|
4
|
+
"sourcesContent": ["import { RefObject, useEffect } from 'react'\nimport { preventDefault } from '../utils/dom'\nimport { useContainer } from './useContainer'\nimport { useMaybeEditor } from './useEditor'\n\n/** @public */\nexport function usePassThroughWheelEvents(ref: RefObject<HTMLElement>) {\n\tif (!ref) throw Error('usePassThroughWheelEvents must be passed a ref')\n\tconst container = useContainer()\n\tconst editor = useMaybeEditor()\n\n\tuseEffect(() => {\n\t\tfunction onWheel(e: WheelEvent) {\n\t\t\t// Only pass through wheel events if the editor is focused\n\t\t\tif (!editor?.getInstanceState().isFocused) return\n\n\t\t\tif ((e as any).isSpecialRedispatchedEvent) return\n\n\t\t\t// if the element is scrollable, don't redispatch the event\n\t\t\tconst elm = ref.current\n\t\t\tif (elm && elm.scrollHeight > elm.clientHeight) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tpreventDefault(e)\n\t\t\tconst cvs = container.querySelector('.tl-canvas')\n\t\t\tif (!cvs) return\n\t\t\tconst newEvent = new WheelEvent('wheel', e as any)\n\t\t\t;(newEvent as any).isSpecialRedispatchedEvent = true\n\t\t\tcvs.dispatchEvent(newEvent)\n\t\t}\n\n\t\tconst elm = ref.current\n\t\tif (!elm) return\n\n\t\telm.addEventListener('wheel', onWheel, { passive: false })\n\t\treturn () => {\n\t\t\telm.removeEventListener('wheel', onWheel)\n\t\t}\n\t}, [container, editor, ref])\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAoB,iBAAiB;AACrC,SAAS,sBAAsB;AAC/B,SAAS,oBAAoB;AAC7B,SAAS,sBAAsB;AAGxB,SAAS,0BAA0B,KAA6B;AACtE,MAAI,CAAC,IAAK,OAAM,MAAM,gDAAgD;AACtE,QAAM,YAAY,aAAa;AAC/B,QAAM,SAAS,eAAe;AAE9B,YAAU,MAAM;AACf,aAAS,QAAQ,GAAe;AAE/B,UAAI,CAAC,QAAQ,iBAAiB,EAAE,UAAW;AAE3C,UAAK,EAAU,2BAA4B;AAG3C,YAAMA,OAAM,IAAI;AAChB,UAAIA,QAAOA,KAAI,eAAeA,KAAI,cAAc;AAC/C;AAAA,MACD;AAEA,qBAAe,CAAC;AAChB,YAAM,MAAM,UAAU,cAAc,YAAY;AAChD,UAAI,CAAC,IAAK;AACV,YAAM,WAAW,IAAI,WAAW,SAAS,CAAQ;AAChD,MAAC,SAAiB,6BAA6B;AAChD,UAAI,cAAc,QAAQ;AAAA,IAC3B;AAEA,UAAM,MAAM,IAAI;AAChB,QAAI,CAAC,IAAK;AAEV,QAAI,iBAAiB,SAAS,SAAS,EAAE,SAAS,MAAM,CAAC;AACzD,WAAO,MAAM;AACZ,UAAI,oBAAoB,SAAS,OAAO;AAAA,IACzC;AAAA,EACD,GAAG,CAAC,WAAW,QAAQ,GAAG,CAAC;AAC5B;",
|
|
6
6
|
"names": ["elm"]
|
|
7
7
|
}
|
package/dist-esm/version.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const version = "3.16.0-canary.
|
|
1
|
+
const version = "3.16.0-canary.460bdab3938b";
|
|
2
2
|
const publishDates = {
|
|
3
3
|
major: "2024-09-13T14:36:29.063Z",
|
|
4
|
-
minor: "2025-08-
|
|
5
|
-
patch: "2025-08-
|
|
4
|
+
minor: "2025-08-25T21:07:26.119Z",
|
|
5
|
+
patch: "2025-08-25T21:07:26.119Z"
|
|
6
6
|
};
|
|
7
7
|
export {
|
|
8
8
|
publishDates,
|
package/dist-esm/version.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/version.ts"],
|
|
4
|
-
"sourcesContent": ["// This file is automatically generated by internal/scripts/refresh-assets.ts.\n// Do not edit manually. Or do, I'm a comment, not a cop.\n\nexport const version = '3.16.0-canary.
|
|
4
|
+
"sourcesContent": ["// This file is automatically generated by internal/scripts/refresh-assets.ts.\n// Do not edit manually. Or do, I'm a comment, not a cop.\n\nexport const version = '3.16.0-canary.460bdab3938b'\nexport const publishDates = {\n\tmajor: '2024-09-13T14:36:29.063Z',\n\tminor: '2025-08-25T21:07:26.119Z',\n\tpatch: '2025-08-25T21:07:26.119Z',\n}\n"],
|
|
5
5
|
"mappings": "AAGO,MAAM,UAAU;AAChB,MAAM,eAAe;AAAA,EAC3B,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AACR;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tldraw/editor",
|
|
3
3
|
"description": "tldraw infinite canvas SDK (editor).",
|
|
4
|
-
"version": "3.16.0-canary.
|
|
4
|
+
"version": "3.16.0-canary.460bdab3938b",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "tldraw Inc.",
|
|
7
7
|
"email": "hello@tldraw.com"
|
|
@@ -50,12 +50,12 @@
|
|
|
50
50
|
"@tiptap/core": "^2.9.1",
|
|
51
51
|
"@tiptap/pm": "^2.9.1",
|
|
52
52
|
"@tiptap/react": "^2.9.1",
|
|
53
|
-
"@tldraw/state": "3.16.0-canary.
|
|
54
|
-
"@tldraw/state-react": "3.16.0-canary.
|
|
55
|
-
"@tldraw/store": "3.16.0-canary.
|
|
56
|
-
"@tldraw/tlschema": "3.16.0-canary.
|
|
57
|
-
"@tldraw/utils": "3.16.0-canary.
|
|
58
|
-
"@tldraw/validate": "3.16.0-canary.
|
|
53
|
+
"@tldraw/state": "3.16.0-canary.460bdab3938b",
|
|
54
|
+
"@tldraw/state-react": "3.16.0-canary.460bdab3938b",
|
|
55
|
+
"@tldraw/store": "3.16.0-canary.460bdab3938b",
|
|
56
|
+
"@tldraw/tlschema": "3.16.0-canary.460bdab3938b",
|
|
57
|
+
"@tldraw/utils": "3.16.0-canary.460bdab3938b",
|
|
58
|
+
"@tldraw/validate": "3.16.0-canary.460bdab3938b",
|
|
59
59
|
"@types/core-js": "^2.5.8",
|
|
60
60
|
"@use-gesture/react": "^10.3.1",
|
|
61
61
|
"classnames": "^2.5.1",
|
package/src/lib/TldrawEditor.tsx
CHANGED
|
@@ -586,8 +586,13 @@ function TldrawEditorWithReadyStore({
|
|
|
586
586
|
if (editor !== fontLoadingState?.editor) {
|
|
587
587
|
fontLoadingState = null
|
|
588
588
|
}
|
|
589
|
-
|
|
589
|
+
useLayoutEffect(() => {
|
|
590
590
|
if (!editor) return
|
|
591
|
+
if (editor.options.maxFontsToLoadBeforeRender === 0) {
|
|
592
|
+
setFontLoadingState({ editor, isLoaded: true })
|
|
593
|
+
return
|
|
594
|
+
}
|
|
595
|
+
|
|
591
596
|
let isCancelled = false
|
|
592
597
|
|
|
593
598
|
setFontLoadingState({ editor, isLoaded: false })
|
|
@@ -28,7 +28,6 @@ export const Shape = memo(function Shape({
|
|
|
28
28
|
index,
|
|
29
29
|
backgroundIndex,
|
|
30
30
|
opacity,
|
|
31
|
-
dprMultiple,
|
|
32
31
|
}: {
|
|
33
32
|
id: TLShapeId
|
|
34
33
|
shape: TLShape
|
|
@@ -36,7 +35,6 @@ export const Shape = memo(function Shape({
|
|
|
36
35
|
index: number
|
|
37
36
|
backgroundIndex: number
|
|
38
37
|
opacity: number
|
|
39
|
-
dprMultiple: number
|
|
40
38
|
}) {
|
|
41
39
|
const editor = useEditor()
|
|
42
40
|
|
|
@@ -91,18 +89,14 @@ export const Shape = memo(function Shape({
|
|
|
91
89
|
}
|
|
92
90
|
|
|
93
91
|
// Width / Height
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const widthRemainder = bounds.w % dprMultiple
|
|
97
|
-
const heightRemainder = bounds.h % dprMultiple
|
|
98
|
-
const width = widthRemainder === 0 ? bounds.w : bounds.w + (dprMultiple - widthRemainder)
|
|
99
|
-
const height = heightRemainder === 0 ? bounds.h : bounds.h + (dprMultiple - heightRemainder)
|
|
92
|
+
const width = Math.max(bounds.width, 1)
|
|
93
|
+
const height = Math.max(bounds.height, 1)
|
|
100
94
|
|
|
101
95
|
if (width !== prev.width || height !== prev.height) {
|
|
102
|
-
setStyleProperty(containerRef.current, 'width',
|
|
103
|
-
setStyleProperty(containerRef.current, 'height',
|
|
104
|
-
setStyleProperty(bgContainerRef.current, 'width',
|
|
105
|
-
setStyleProperty(bgContainerRef.current, 'height',
|
|
96
|
+
setStyleProperty(containerRef.current, 'width', width + 'px')
|
|
97
|
+
setStyleProperty(containerRef.current, 'height', height + 'px')
|
|
98
|
+
setStyleProperty(bgContainerRef.current, 'width', width + 'px')
|
|
99
|
+
setStyleProperty(bgContainerRef.current, 'height', height + 'px')
|
|
106
100
|
prev.width = width
|
|
107
101
|
prev.height = height
|
|
108
102
|
}
|
|
@@ -22,7 +22,6 @@ import { Vec } from '../../primitives/Vec'
|
|
|
22
22
|
import { toDomPrecision } from '../../primitives/utils'
|
|
23
23
|
import { debugFlags } from '../../utils/debug-flags'
|
|
24
24
|
import { setStyleProperty } from '../../utils/dom'
|
|
25
|
-
import { nearestMultiple } from '../../utils/nearestMultiple'
|
|
26
25
|
import { GeometryDebuggingView } from '../GeometryDebuggingView'
|
|
27
26
|
import { LiveCollaborators } from '../LiveCollaborators'
|
|
28
27
|
import { MenuClickCapture } from '../MenuClickCapture'
|
|
@@ -390,18 +389,9 @@ function ShapesWithSVGs() {
|
|
|
390
389
|
|
|
391
390
|
const renderingShapes = useValue('rendering shapes', () => editor.getRenderingShapes(), [editor])
|
|
392
391
|
|
|
393
|
-
const dprMultiple = useValue(
|
|
394
|
-
'dpr multiple',
|
|
395
|
-
() =>
|
|
396
|
-
// dprMultiple is the smallest number we can multiply dpr by to get an integer
|
|
397
|
-
// it's usually 1, 2, or 4 (for e.g. dpr of 2, 2.5 and 2.25 respectively)
|
|
398
|
-
nearestMultiple(Math.floor(editor.getInstanceState().devicePixelRatio * 100) / 100),
|
|
399
|
-
[editor]
|
|
400
|
-
)
|
|
401
|
-
|
|
402
392
|
return renderingShapes.map((result) => (
|
|
403
393
|
<Fragment key={result.id + '_fragment'}>
|
|
404
|
-
<Shape {...result}
|
|
394
|
+
<Shape {...result} />
|
|
405
395
|
<DebugSvgCopy id={result.id} mode="iframe" />
|
|
406
396
|
</Fragment>
|
|
407
397
|
))
|
|
@@ -436,19 +426,10 @@ function ShapesToDisplay() {
|
|
|
436
426
|
|
|
437
427
|
const renderingShapes = useValue('rendering shapes', () => editor.getRenderingShapes(), [editor])
|
|
438
428
|
|
|
439
|
-
const dprMultiple = useValue(
|
|
440
|
-
'dpr multiple',
|
|
441
|
-
() =>
|
|
442
|
-
// dprMultiple is the smallest number we can multiply dpr by to get an integer
|
|
443
|
-
// it's usually 1, 2, or 4 (for e.g. dpr of 2, 2.5 and 2.25 respectively)
|
|
444
|
-
nearestMultiple(Math.floor(editor.getInstanceState().devicePixelRatio * 100) / 100),
|
|
445
|
-
[editor]
|
|
446
|
-
)
|
|
447
|
-
|
|
448
429
|
return (
|
|
449
430
|
<>
|
|
450
431
|
{renderingShapes.map((result) => (
|
|
451
|
-
<Shape key={result.id + '_shape'} {...result}
|
|
432
|
+
<Shape key={result.id + '_shape'} {...result} />
|
|
452
433
|
))}
|
|
453
434
|
{tlenv.isSafari && <ReflowIfNeeded />}
|
|
454
435
|
</>
|
package/src/lib/editor/Editor.ts
CHANGED
|
@@ -9519,6 +9519,24 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
9519
9519
|
}
|
|
9520
9520
|
}
|
|
9521
9521
|
|
|
9522
|
+
/**
|
|
9523
|
+
* Get an exported image of the given shapes as a data URL.
|
|
9524
|
+
*
|
|
9525
|
+
* @param shapes - The shapes (or shape ids) to export.
|
|
9526
|
+
* @param opts - Options for the export.
|
|
9527
|
+
*
|
|
9528
|
+
* @returns A data URL of the image.
|
|
9529
|
+
* @public
|
|
9530
|
+
*/
|
|
9531
|
+
async toImageDataUrl(shapes: TLShapeId[] | TLShape[], opts: TLImageExportOptions = {}) {
|
|
9532
|
+
const { blob, width, height } = await this.toImage(shapes, opts)
|
|
9533
|
+
return {
|
|
9534
|
+
url: await FileHelpers.blobToDataUrl(blob),
|
|
9535
|
+
width,
|
|
9536
|
+
height,
|
|
9537
|
+
}
|
|
9538
|
+
}
|
|
9539
|
+
|
|
9522
9540
|
/* --------------------- Events --------------------- */
|
|
9523
9541
|
|
|
9524
9542
|
/**
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
import { RefObject, useEffect } from 'react'
|
|
2
2
|
import { preventDefault } from '../utils/dom'
|
|
3
3
|
import { useContainer } from './useContainer'
|
|
4
|
+
import { useMaybeEditor } from './useEditor'
|
|
4
5
|
|
|
5
6
|
/** @public */
|
|
6
7
|
export function usePassThroughWheelEvents(ref: RefObject<HTMLElement>) {
|
|
7
8
|
if (!ref) throw Error('usePassThroughWheelEvents must be passed a ref')
|
|
8
9
|
const container = useContainer()
|
|
10
|
+
const editor = useMaybeEditor()
|
|
9
11
|
|
|
10
12
|
useEffect(() => {
|
|
11
13
|
function onWheel(e: WheelEvent) {
|
|
14
|
+
// Only pass through wheel events if the editor is focused
|
|
15
|
+
if (!editor?.getInstanceState().isFocused) return
|
|
16
|
+
|
|
12
17
|
if ((e as any).isSpecialRedispatchedEvent) return
|
|
13
18
|
|
|
14
19
|
// if the element is scrollable, don't redispatch the event
|
|
@@ -32,5 +37,5 @@ export function usePassThroughWheelEvents(ref: RefObject<HTMLElement>) {
|
|
|
32
37
|
return () => {
|
|
33
38
|
elm.removeEventListener('wheel', onWheel)
|
|
34
39
|
}
|
|
35
|
-
}, [container, ref])
|
|
40
|
+
}, [container, editor, ref])
|
|
36
41
|
}
|
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.
|
|
4
|
+
export const version = '3.16.0-canary.460bdab3938b'
|
|
5
5
|
export const publishDates = {
|
|
6
6
|
major: '2024-09-13T14:36:29.063Z',
|
|
7
|
-
minor: '2025-08-
|
|
8
|
-
patch: '2025-08-
|
|
7
|
+
minor: '2025-08-25T21:07:26.119Z',
|
|
8
|
+
patch: '2025-08-25T21:07:26.119Z',
|
|
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
|
-
}
|