From b71489098c83fba144d5ebebff0313210c395362 Mon Sep 17 00:00:00 2001 From: Tom Beach Date: Sun, 17 Nov 2024 06:47:19 +0000 Subject: [PATCH 1/2] Fix Pathing --- examples/viewer/web-ifc-viewer.ts | 2 +- src/ts/web-ifc-api.ts | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/examples/viewer/web-ifc-viewer.ts b/examples/viewer/web-ifc-viewer.ts index 9ffb8262..355cbe3f 100644 --- a/examples/viewer/web-ifc-viewer.ts +++ b/examples/viewer/web-ifc-viewer.ts @@ -8,7 +8,7 @@ import * as ts from "typescript"; import { exampleCode } from './example'; let ifcAPI = new IfcAPI(); -ifcAPI.SetWasmPath("./",true) +ifcAPI.SetWasmPath("./") let ifcThree = new IfcThree(ifcAPI); let timeout = undefined; diff --git a/src/ts/web-ifc-api.ts b/src/ts/web-ifc-api.ts index e371f317..b62cc150 100644 --- a/src/ts/web-ifc-api.ts +++ b/src/ts/web-ifc-api.ts @@ -26,7 +26,11 @@ declare var __WASM_PATH__:string; let WebIFCWasm: any; - +let currentScriptPath: string; +if (document !== undefined && document.currentScript !==undefined) { + const currentScriptData = (document?.currentScript as HTMLScriptElement); + currentScriptPath = currentScriptData.src.substring(0, currentScriptData.src.lastIndexOf("/") + 1) ; +} export * from "./ifc-schema"; import { Properties } from "./helpers/properties"; @@ -193,10 +197,10 @@ export class IfcAPI { return this.wasmPath + path; } - return prefix + this.wasmPath + path; + return (currentScriptPath !== undefined ? currentScriptPath : prefix) + this.wasmPath + path; } // otherwise use the default path - return prefix + path; + return (currentScriptPath !== undefined ? currentScriptPath : prefix) + path; } //@ts-ignore From aa1346d812844c6e4fb989374d8693d97201f80b Mon Sep 17 00:00:00 2001 From: Tom Beach Date: Sun, 17 Nov 2024 07:09:40 +0000 Subject: [PATCH 2/2] Update web-ifc-api.ts --- src/ts/web-ifc-api.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ts/web-ifc-api.ts b/src/ts/web-ifc-api.ts index b62cc150..778b3aeb 100644 --- a/src/ts/web-ifc-api.ts +++ b/src/ts/web-ifc-api.ts @@ -27,8 +27,8 @@ declare var __WASM_PATH__:string; let WebIFCWasm: any; let currentScriptPath: string; -if (document !== undefined && document.currentScript !==undefined) { - const currentScriptData = (document?.currentScript as HTMLScriptElement); +if (typeof document !== 'undefined') { + const currentScriptData = (document.currentScript as HTMLScriptElement); currentScriptPath = currentScriptData.src.substring(0, currentScriptData.src.lastIndexOf("/") + 1) ; }