@tscircuit/3d-viewer 0.0.625 → 0.0.626
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/index.js +88 -68
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -18978,6 +18978,41 @@ var useHiddenCadComponents = (circuitKey) => {
|
|
|
18978
18978
|
};
|
|
18979
18979
|
};
|
|
18980
18980
|
|
|
18981
|
+
// src/utils/configure-runtime-font.ts
|
|
18982
|
+
import { configureTextBuilder } from "troika-three-text";
|
|
18983
|
+
|
|
18984
|
+
// src/utils/get-runtime-asset-url.ts
|
|
18985
|
+
function getRuntimeAssetUrl(packageName, version, path) {
|
|
18986
|
+
const baseUrl = typeof window !== "undefined" ? window.TSCIRCUIT_JSCDN_BASE_URL : void 0;
|
|
18987
|
+
if (!baseUrl) {
|
|
18988
|
+
return `https://cdn.jsdelivr.net/npm/${packageName}@${version}/${path}`;
|
|
18989
|
+
}
|
|
18990
|
+
return new URL(
|
|
18991
|
+
`${baseUrl.replace(/\/+$/, "")}/${packageName}/${version}/${path}`,
|
|
18992
|
+
window.location.href
|
|
18993
|
+
).href;
|
|
18994
|
+
}
|
|
18995
|
+
|
|
18996
|
+
// src/utils/configure-runtime-font.ts
|
|
18997
|
+
var configured = false;
|
|
18998
|
+
function configureRuntimeFont() {
|
|
18999
|
+
if (configured || typeof window === "undefined" || !window.TSCIRCUIT_JSCDN_BASE_URL)
|
|
19000
|
+
return;
|
|
19001
|
+
configureTextBuilder({
|
|
19002
|
+
defaultFontURL: getRuntimeAssetUrl(
|
|
19003
|
+
"three",
|
|
19004
|
+
"0.165.0",
|
|
19005
|
+
"examples/fonts/ttf/kenpixel.ttf"
|
|
19006
|
+
),
|
|
19007
|
+
unicodeFontsURL: getRuntimeAssetUrl(
|
|
19008
|
+
"troika-three-text",
|
|
19009
|
+
"0.52.5",
|
|
19010
|
+
"unicode-fonts/"
|
|
19011
|
+
)
|
|
19012
|
+
});
|
|
19013
|
+
configured = true;
|
|
19014
|
+
}
|
|
19015
|
+
|
|
18981
19016
|
// src/CadViewer.tsx
|
|
18982
19017
|
import { useCallback as useCallback25, useContext as useContext11, useEffect as useEffect51, useRef as useRef29, useState as useState42 } from "react";
|
|
18983
19018
|
import * as THREE57 from "three";
|
|
@@ -20129,7 +20164,6 @@ function occtMeshesToGroup(meshes) {
|
|
|
20129
20164
|
// src/three-components/StepModel.tsx
|
|
20130
20165
|
import { jsx as jsx9 } from "react/jsx-runtime";
|
|
20131
20166
|
var occtImportPromise;
|
|
20132
|
-
var OCCT_CDN_BASE_URL = "https://cdn.jsdelivr.net/npm/occt-import-js@0.0.23/dist";
|
|
20133
20167
|
function resolveOcctFactory(candidate) {
|
|
20134
20168
|
if (typeof candidate === "function") {
|
|
20135
20169
|
return candidate;
|
|
@@ -20141,13 +20175,19 @@ function resolveOcctFactory(candidate) {
|
|
|
20141
20175
|
}
|
|
20142
20176
|
async function loadOcctImport() {
|
|
20143
20177
|
if (!occtImportPromise) {
|
|
20144
|
-
|
|
20145
|
-
|
|
20146
|
-
|
|
20147
|
-
|
|
20148
|
-
|
|
20149
|
-
|
|
20150
|
-
|
|
20178
|
+
occtImportPromise = (async () => {
|
|
20179
|
+
const imported = await import(
|
|
20180
|
+
/* @vite-ignore */
|
|
20181
|
+
/* webpackIgnore: true */
|
|
20182
|
+
getRuntimeAssetUrl("occt-import-js", "0.0.23", "+esm")
|
|
20183
|
+
);
|
|
20184
|
+
const factory = resolveOcctFactory(imported);
|
|
20185
|
+
return factory({
|
|
20186
|
+
locateFile: (path) => getRuntimeAssetUrl("occt-import-js", "0.0.23", `dist/${path}`)
|
|
20187
|
+
});
|
|
20188
|
+
})().catch((error) => {
|
|
20189
|
+
occtImportPromise = void 0;
|
|
20190
|
+
throw error;
|
|
20151
20191
|
});
|
|
20152
20192
|
}
|
|
20153
20193
|
return occtImportPromise;
|
|
@@ -20951,7 +20991,7 @@ import * as THREE27 from "three";
|
|
|
20951
20991
|
// package.json
|
|
20952
20992
|
var package_default = {
|
|
20953
20993
|
name: "@tscircuit/3d-viewer",
|
|
20954
|
-
version: "0.0.
|
|
20994
|
+
version: "0.0.625",
|
|
20955
20995
|
repository: {
|
|
20956
20996
|
type: "git",
|
|
20957
20997
|
url: "https://github.com/tscircuit/3d-viewer"
|
|
@@ -30173,6 +30213,33 @@ function createGeometryMeshes(geoms) {
|
|
|
30173
30213
|
return meshes;
|
|
30174
30214
|
}
|
|
30175
30215
|
|
|
30216
|
+
// src/utils/manifold/load-manifold.ts
|
|
30217
|
+
var manifoldPromise;
|
|
30218
|
+
function loadManifold() {
|
|
30219
|
+
if (!manifoldPromise) {
|
|
30220
|
+
manifoldPromise = (async () => {
|
|
30221
|
+
const existing = window.ManifoldModule ?? window.MANIFOLD ?? window.MANIFOLD_MODULE;
|
|
30222
|
+
if (existing && typeof existing === "object" && existing.setup) {
|
|
30223
|
+
window.ManifoldModule = existing;
|
|
30224
|
+
return existing;
|
|
30225
|
+
}
|
|
30226
|
+
const factory = existing ?? (await import(
|
|
30227
|
+
/* @vite-ignore */
|
|
30228
|
+
/* webpackIgnore: true */
|
|
30229
|
+
getRuntimeAssetUrl("manifold-3d", "3.2.1", "manifold.js")
|
|
30230
|
+
)).default;
|
|
30231
|
+
const module = await factory();
|
|
30232
|
+
module.setup();
|
|
30233
|
+
window.ManifoldModule = module;
|
|
30234
|
+
return module;
|
|
30235
|
+
})().catch((error) => {
|
|
30236
|
+
manifoldPromise = void 0;
|
|
30237
|
+
throw error;
|
|
30238
|
+
});
|
|
30239
|
+
}
|
|
30240
|
+
return manifoldPromise;
|
|
30241
|
+
}
|
|
30242
|
+
|
|
30176
30243
|
// src/CadViewerManifold.tsx
|
|
30177
30244
|
import { jsx as jsx19, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
30178
30245
|
var BoardMeshes = ({
|
|
@@ -30247,7 +30314,6 @@ var BoardMeshes = ({
|
|
|
30247
30314
|
}, [rootObject, textureMeshes]);
|
|
30248
30315
|
return null;
|
|
30249
30316
|
};
|
|
30250
|
-
var MANIFOLD_CDN_BASE_URL = "https://cdn.jsdelivr.net/npm/manifold-3d@3.2.1";
|
|
30251
30317
|
var CadViewerManifold = ({
|
|
30252
30318
|
circuitJson: circuitJsonProp,
|
|
30253
30319
|
foldPcbs,
|
|
@@ -30269,65 +30335,18 @@ var CadViewerManifold = ({
|
|
|
30269
30335
|
const [manifoldLoadingError, setManifoldLoadingError] = useState19(null);
|
|
30270
30336
|
const { visibility } = useLayerVisibility();
|
|
30271
30337
|
useEffect31(() => {
|
|
30272
|
-
|
|
30273
|
-
|
|
30274
|
-
|
|
30275
|
-
}
|
|
30276
|
-
|
|
30277
|
-
|
|
30278
|
-
|
|
30279
|
-
|
|
30280
|
-
|
|
30281
|
-
|
|
30282
|
-
} catch (error) {
|
|
30283
|
-
console.error("Failed to initialize Manifold:", error);
|
|
30284
|
-
setManifoldLoadingError(
|
|
30285
|
-
`Failed to initialize Manifold: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
30286
|
-
);
|
|
30287
|
-
}
|
|
30288
|
-
};
|
|
30289
|
-
const existingManifold = window.ManifoldModule ?? window.MANIFOLD ?? window.MANIFOLD_MODULE;
|
|
30290
|
-
if (existingManifold) {
|
|
30291
|
-
window.ManifoldModule = existingManifold;
|
|
30292
|
-
initManifold(window.ManifoldModule);
|
|
30293
|
-
return;
|
|
30294
|
-
}
|
|
30295
|
-
const eventName = "manifoldLoaded";
|
|
30296
|
-
const handleLoad = () => {
|
|
30297
|
-
const loadedManifold = window.ManifoldModule ?? window.MANIFOLD ?? window.MANIFOLD_MODULE;
|
|
30298
|
-
if (loadedManifold) {
|
|
30299
|
-
window.ManifoldModule = loadedManifold;
|
|
30300
|
-
initManifold(window.ManifoldModule);
|
|
30301
|
-
} else {
|
|
30302
|
-
const errText = "ManifoldModule not found on window after script load.";
|
|
30303
|
-
console.error(errText);
|
|
30304
|
-
setManifoldLoadingError(errText);
|
|
30305
|
-
}
|
|
30306
|
-
};
|
|
30307
|
-
window.addEventListener(eventName, handleLoad, { once: true });
|
|
30308
|
-
const script = document.createElement("script");
|
|
30309
|
-
script.type = "module";
|
|
30310
|
-
script.innerHTML = `
|
|
30311
|
-
try {
|
|
30312
|
-
const { default: ManifoldModule } = await import('${MANIFOLD_CDN_BASE_URL}/manifold.js');
|
|
30313
|
-
window.ManifoldModule = ManifoldModule;
|
|
30314
|
-
} catch (e) {
|
|
30315
|
-
console.error('Error importing manifold in dynamic script:', e);
|
|
30316
|
-
} finally {
|
|
30317
|
-
window.dispatchEvent(new CustomEvent('${eventName}'));
|
|
30318
|
-
}
|
|
30319
|
-
`.trim();
|
|
30320
|
-
const scriptError = (err) => {
|
|
30321
|
-
const errText = "Failed to load Manifold loader script.";
|
|
30322
|
-
console.error(errText, err);
|
|
30323
|
-
setManifoldLoadingError(errText);
|
|
30324
|
-
window.removeEventListener(eventName, handleLoad);
|
|
30325
|
-
};
|
|
30326
|
-
script.addEventListener("error", scriptError);
|
|
30327
|
-
document.body.appendChild(script);
|
|
30338
|
+
let isActive = true;
|
|
30339
|
+
loadManifold().then((module) => {
|
|
30340
|
+
if (isActive) setManifoldJSModule(module);
|
|
30341
|
+
}).catch((error) => {
|
|
30342
|
+
if (!isActive) return;
|
|
30343
|
+
console.error("Failed to initialize Manifold:", error);
|
|
30344
|
+
setManifoldLoadingError(
|
|
30345
|
+
`Failed to initialize Manifold: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
30346
|
+
);
|
|
30347
|
+
});
|
|
30328
30348
|
return () => {
|
|
30329
|
-
|
|
30330
|
-
script.removeEventListener("error", scriptError);
|
|
30349
|
+
isActive = false;
|
|
30331
30350
|
};
|
|
30332
30351
|
}, []);
|
|
30333
30352
|
const {
|
|
@@ -38827,6 +38846,7 @@ var CadViewerInner = (props) => {
|
|
|
38827
38846
|
);
|
|
38828
38847
|
};
|
|
38829
38848
|
var CadViewer = (props) => {
|
|
38849
|
+
configureRuntimeFont();
|
|
38830
38850
|
const sceneRef = useRef29(null);
|
|
38831
38851
|
return /* @__PURE__ */ jsx38(SchematicNavigationContext.Provider, { value: sceneRef, children: /* @__PURE__ */ jsx38(
|
|
38832
38852
|
CameraControllerProvider,
|