@pascal-app/viewer 0.1.3 → 0.1.6

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.
@@ -1 +1 @@
1
- {"version":3,"file":"item-renderer.d.ts","sourceRoot":"","sources":["../../../../src/components/renderers/item/item-renderer.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,QAAQ,EAAyB,MAAM,kBAAkB,CAAA;AAiCvF,eAAO,MAAM,YAAY,GAAI,UAAU;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,4CAYxD,CAAA"}
1
+ {"version":3,"file":"item-renderer.d.ts","sourceRoot":"","sources":["../../../../src/components/renderers/item/item-renderer.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,QAAQ,EAAyB,MAAM,kBAAkB,CAAA;AAkCvF,eAAO,MAAM,YAAY,GAAI,UAAU;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,4CAYxD,CAAA"}
@@ -4,6 +4,7 @@ import { Clone } from '@react-three/drei/core/Clone';
4
4
  import { useGLTF } from '@react-three/drei/core/Gltf';
5
5
  import { Suspense, useEffect, useMemo, useRef } from 'react';
6
6
  import { DoubleSide, MeshStandardNodeMaterial } from 'three/webgpu';
7
+ import { resolveCdnUrl } from '../../../lib/asset-url';
7
8
  import { useNodeEvents } from '../../../hooks/use-node-events';
8
9
  // Shared materials to avoid creating new instances for every mesh
9
10
  const defaultMaterial = new MeshStandardNodeMaterial({
@@ -33,7 +34,7 @@ export const ItemRenderer = ({ node }) => {
33
34
  return (_jsx("group", { position: node.position, rotation: node.rotation, ref: ref, visible: node.visible, children: _jsx(Suspense, { children: _jsx(ModelRenderer, { node: node }) }) }));
34
35
  };
35
36
  const ModelRenderer = ({ node }) => {
36
- const { scene, nodes } = useGLTF(node.asset.src);
37
+ const { scene, nodes } = useGLTF(resolveCdnUrl(node.asset.src) || '');
37
38
  if (nodes.cutout) {
38
39
  nodes.cutout.visible = false;
39
40
  }
@@ -55,7 +56,7 @@ const ModelRenderer = ({ node }) => {
55
56
  // Handle both single material and material array cases
56
57
  if (Array.isArray(mesh.material)) {
57
58
  mesh.material = mesh.material.map((mat) => getMaterialForOriginal(mat));
58
- hasGlass = mesh.material.some(mat => mat.name === 'glass');
59
+ hasGlass = mesh.material.some((mat) => mat.name === 'glass');
59
60
  }
60
61
  else {
61
62
  mesh.material = getMaterialForOriginal(mesh.material);
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { default as Viewer } from './components/viewer';
2
2
  export { useGridEvents } from './hooks/use-grid-events';
3
3
  export { default as useViewer } from './store/use-viewer';
4
+ export { ASSETS_CDN_URL, resolveAssetUrl, resolveCdnUrl } from './lib/asset-url';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AACvD,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,oBAAoB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AACvD,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,oBAAoB,CAAA;AACzD,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA"}
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export { default as Viewer } from './components/viewer';
2
2
  export { useGridEvents } from './hooks/use-grid-events';
3
3
  export { default as useViewer } from './store/use-viewer';
4
+ export { ASSETS_CDN_URL, resolveAssetUrl, resolveCdnUrl } from './lib/asset-url';
@@ -0,0 +1,15 @@
1
+ export declare const ASSETS_CDN_URL = "https://pascal-cdn.wawasensei.dev";
2
+ /**
3
+ * Resolves an asset URL to the appropriate format:
4
+ * - If URL starts with http:// or https://, return as-is (external URL)
5
+ * - If URL starts with asset://, resolve from IndexedDB storage
6
+ * - If URL starts with /, prepend CDN URL (absolute path)
7
+ * - Otherwise, prepend CDN URL (relative path)
8
+ */
9
+ export declare function resolveAssetUrl(url: string | undefined | null): Promise<string | null>;
10
+ /**
11
+ * Synchronous version for URLs that don't need IndexedDB resolution
12
+ * Only use this if you're sure the URL is not an asset:// URL
13
+ */
14
+ export declare function resolveCdnUrl(url: string | undefined | null): string | null;
15
+ //# sourceMappingURL=asset-url.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asset-url.d.ts","sourceRoot":"","sources":["../../src/lib/asset-url.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,cAAc,sCAAsC,CAAA;AAEjE;;;;;;GAMG;AACH,wBAAsB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAgB5F;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CAiB3E"}
@@ -0,0 +1,44 @@
1
+ import { loadAssetUrl } from '@pascal-app/core';
2
+ export const ASSETS_CDN_URL = 'https://pascal-cdn.wawasensei.dev';
3
+ /**
4
+ * Resolves an asset URL to the appropriate format:
5
+ * - If URL starts with http:// or https://, return as-is (external URL)
6
+ * - If URL starts with asset://, resolve from IndexedDB storage
7
+ * - If URL starts with /, prepend CDN URL (absolute path)
8
+ * - Otherwise, prepend CDN URL (relative path)
9
+ */
10
+ export async function resolveAssetUrl(url) {
11
+ if (!url)
12
+ return null;
13
+ // External URL - use as-is
14
+ if (url.startsWith('http://') || url.startsWith('https://')) {
15
+ return url;
16
+ }
17
+ // IndexedDB asset - resolve from storage
18
+ if (url.startsWith('asset://')) {
19
+ return loadAssetUrl(url);
20
+ }
21
+ // Absolute or relative path - prepend CDN URL
22
+ const normalizedPath = url.startsWith('/') ? url : `/${url}`;
23
+ return `${ASSETS_CDN_URL}${normalizedPath}`;
24
+ }
25
+ /**
26
+ * Synchronous version for URLs that don't need IndexedDB resolution
27
+ * Only use this if you're sure the URL is not an asset:// URL
28
+ */
29
+ export function resolveCdnUrl(url) {
30
+ if (!url)
31
+ return null;
32
+ // External URL - use as-is
33
+ if (url.startsWith('http://') || url.startsWith('https://')) {
34
+ return url;
35
+ }
36
+ // Don't use this for asset:// URLs - use resolveAssetUrl instead
37
+ if (url.startsWith('asset://')) {
38
+ console.warn('Use resolveAssetUrl() for asset:// URLs, not resolveCdnUrl()');
39
+ return null;
40
+ }
41
+ // Absolute or relative path - prepend CDN URL
42
+ const normalizedPath = url.startsWith('/') ? url : `/${url}`;
43
+ return `${ASSETS_CDN_URL}${normalizedPath}`;
44
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pascal-app/viewer",
3
- "version": "0.1.3",
3
+ "version": "0.1.6",
4
4
  "description": "3D viewer component for Pascal building editor",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -18,10 +18,11 @@
18
18
  ],
19
19
  "scripts": {
20
20
  "build": "tsc --declaration --emitDeclarationOnly && tsc",
21
+ "dev": "tsc --declaration --emitDeclarationOnly --watch & tsc --watch",
21
22
  "prepublishOnly": "npm run build"
22
23
  },
23
24
  "peerDependencies": {
24
- "@pascal-app/core": "^0.1.3",
25
+ "@pascal-app/core": "^0.1.4",
25
26
  "@react-three/drei": "^10",
26
27
  "@react-three/fiber": "^9",
27
28
  "react": "^18 || ^19",