From bb9495e69c523b6966d422a2655cacc6713e4164 Mon Sep 17 00:00:00 2001 From: DiamondThree Date: Wed, 17 Aug 2022 17:01:59 +0800 Subject: [PATCH 1/2] fix delete Regex --- libs/components/board-state/src/tldraw-app.ts | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/libs/components/board-state/src/tldraw-app.ts b/libs/components/board-state/src/tldraw-app.ts index 366b7c67f5..32e170e668 100644 --- a/libs/components/board-state/src/tldraw-app.ts +++ b/libs/components/board-state/src/tldraw-app.ts @@ -15,13 +15,13 @@ import { TLPointerEventHandler, TLShapeCloneHandler, TLWheelEventHandler, - Utils, + Utils } from '@tldraw/core'; import { Vec } from '@tldraw/vec'; import { clearPrevSize, defaultStyle, - shapeUtils, + shapeUtils } from '@toeverything/components/board-shapes'; import { AlignType, @@ -54,7 +54,7 @@ import { TDUser, TldrawCommand, USER_COLORS, - VIDEO_EXTENSIONS, + VIDEO_EXTENSIONS } from '@toeverything/components/board-types'; import { MIN_PAGE_WIDTH } from '@toeverything/components/editor-core'; import { @@ -67,7 +67,7 @@ import { migrate, openAssetFromFileSystem, openFromFileSystem, - saveToFileSystem, + saveToFileSystem } from './data'; import { getClipboard, setClipboard } from './idb-clipboard'; import { StateManager } from './manager/state-manager'; @@ -3779,7 +3779,7 @@ export class TldrawApp extends StateManager { const svgString = await fileToText(file); const viewBoxAttribute = this.get_viewbox_from_svg(svgString); - + if (viewBoxAttribute) { viewBox = viewBoxAttribute.split(' '); size[0] = parseFloat(viewBox[2]); @@ -3840,12 +3840,10 @@ export class TldrawApp extends StateManager { }; private get_viewbox_from_svg = (svgStr: string | ArrayBuffer | null) => { - const viewBoxRegex = - /.*?viewBox=["'](-?[\d.]+[, ]+-?[\d.]+[, ][\d.]+[, ][\d.]+)["']/; - + if (typeof svgStr === 'string') { - const matches = svgStr.match(viewBoxRegex); - return matches && matches.length >= 2 ? matches[1] : null; + let viewBox = (new DOMParser()).parseFromString(svgStr, "text/xml") + return viewBox.children[0].getAttribute('viewBox') } console.warn('could not get viewbox from svg string'); From eb20ce01b9a1118889440ba2f27e6d013b7a8278 Mon Sep 17 00:00:00 2001 From: DiamondThree Date: Wed, 17 Aug 2022 17:06:32 +0800 Subject: [PATCH 2/2] fix delete Regex --- libs/components/board-state/src/tldraw-app.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/libs/components/board-state/src/tldraw-app.ts b/libs/components/board-state/src/tldraw-app.ts index 32e170e668..e4b7a8a34f 100644 --- a/libs/components/board-state/src/tldraw-app.ts +++ b/libs/components/board-state/src/tldraw-app.ts @@ -15,13 +15,13 @@ import { TLPointerEventHandler, TLShapeCloneHandler, TLWheelEventHandler, - Utils + Utils, } from '@tldraw/core'; import { Vec } from '@tldraw/vec'; import { clearPrevSize, defaultStyle, - shapeUtils + shapeUtils, } from '@toeverything/components/board-shapes'; import { AlignType, @@ -54,7 +54,7 @@ import { TDUser, TldrawCommand, USER_COLORS, - VIDEO_EXTENSIONS + VIDEO_EXTENSIONS, } from '@toeverything/components/board-types'; import { MIN_PAGE_WIDTH } from '@toeverything/components/editor-core'; import { @@ -67,7 +67,7 @@ import { migrate, openAssetFromFileSystem, openFromFileSystem, - saveToFileSystem + saveToFileSystem, } from './data'; import { getClipboard, setClipboard } from './idb-clipboard'; import { StateManager } from './manager/state-manager'; @@ -3779,7 +3779,7 @@ export class TldrawApp extends StateManager { const svgString = await fileToText(file); const viewBoxAttribute = this.get_viewbox_from_svg(svgString); - + if (viewBoxAttribute) { viewBox = viewBoxAttribute.split(' '); size[0] = parseFloat(viewBox[2]); @@ -3840,10 +3840,9 @@ export class TldrawApp extends StateManager { }; private get_viewbox_from_svg = (svgStr: string | ArrayBuffer | null) => { - if (typeof svgStr === 'string') { - let viewBox = (new DOMParser()).parseFromString(svgStr, "text/xml") - return viewBox.children[0].getAttribute('viewBox') + let viewBox = new DOMParser().parseFromString(svgStr, 'text/xml'); + return viewBox.children[0].getAttribute('viewBox'); } console.warn('could not get viewbox from svg string');