From e37514ed78280a6aa022457408884697dd4a525d Mon Sep 17 00:00:00 2001 From: kruschdev Date: Fri, 4 Dec 2026 21:02:17 -0800 Subject: [PATCH] docs: document bundled asset licences, sources, and commercial-use status Add ASSETS.md at the repository root and link it from README.md, apps/editor/README.md, and packages/viewer/README.md to clarify how the root MIT licence relates to static assets under apps/editor/public: - Document verified open-licensed assets and commercial/SaaS permissions: Poly Haven venice_sunset_1k.hdr (CC0 1.0), Plus Jakarta Sans, Geist, Geist Mono, and Liberation Sans fonts (SIL OFL 1.1), the 9 ffmpeg- synthesized UI/switch/turn sound cues (MIT), procedural items/urinal outputs (MIT), and Pascal Next demo media (CC BY 4.0). - Explicitly mark unverified bundled and hosted groups (remaining item models, KTX2/WebP/JPG/PNG PBR material textures, recorded/DAW sound cues and audio, UI icons, and demo_1.json) as not covered by the repository MIT licence pending an owner licence notice, alongside brand trademark reservations and test IFC restrictions. - Detail how commercial and self-hosted @pascal-app/viewer and @pascal-app/editor hosts override default asset, storage, sound, icon, and decoder origins via configureViewer(), including the NEXT_PUBLIC_* fallback boundary for sfxBaseUrl and iconsBaseUrl. - Add apps/editor/lib/bundled-assets-policy.test.ts to guard link and GitHub heading-slug resolution, npm-safe viewer README links, exact public/ folder and root-file boundaries, scripted SFX parity, map-less MATERIAL_CATALOG finishes, and getViewerConfig() env-var fallbacks. --- ASSETS.md | 105 +++++++ README.md | 7 +- apps/editor/README.md | 6 + apps/editor/lib/bundled-assets-policy.test.ts | 291 ++++++++++++++++++ packages/viewer/README.md | 2 +- 5 files changed, 408 insertions(+), 3 deletions(-) create mode 100644 ASSETS.md create mode 100644 apps/editor/lib/bundled-assets-policy.test.ts diff --git a/ASSETS.md b/ASSETS.md new file mode 100644 index 0000000000..f731d0d1d7 --- /dev/null +++ b/ASSETS.md @@ -0,0 +1,105 @@ +# Bundled Assets Licence and Provenance (`ASSETS.md`) + +The root [`LICENSE`](LICENSE) (**MIT License**) covers the source code in this repository, including `@pascal-app/*` packages, `apps/editor`, `apps/ifc-converter`, the CLI, the MCP server, procedural node geometry (walls, slabs, roofs, stairs, openings, cabinets, and procedural items), and the deterministic asset generator scripts under [`scripts/`](scripts). + +**Bundled 3D models, PBR textures, icons, demo scenes, and recorded audio files under [`apps/editor/public/`](apps/editor/public) (as well as remote catalog assets served from `editor.pascal.app` and Pascal's public storage bucket) are not covered by the code's MIT licence unless an asset group below explicitly states MIT or another open licence.** Until Pascal Group Inc. records a standalone licence grant for an unverified group, do not treat those files as MIT-licensed and do not redistribute them in third-party or commercial products. + +## Summary by asset group + +| Asset group | Location | Licence | Commercial / SaaS use | Original source | Attribution / conditions | +|---|---|---|---|---|---| +| Source code & procedural geometry | `packages/*`, `apps/*` source, `scripts/*` | [MIT](LICENSE) | Yes | Pascal Group Inc. and contributors | Retain copyright and MIT permission notice | +| Environment HDRI | `apps/editor/public/hdri/venice_sunset_1k.hdr` | [CC0 1.0](https://creativecommons.org/publicdomain/zero/1.0/) | Yes | [Poly Haven (`venice_sunset`)](https://polyhaven.com/a/venice_sunset) by Greg Zaal, mirrored via `@react-three/drei` | None required | +| Web, app & PDF fonts | `apps/editor/public/fonts/*.ttf`, `apps/editor/app/fonts/*.woff`, `packages/editor/src/lib/floorplan/pdf-fonts/*.ttf` | [SIL OFL 1.1](https://openfontlicense.org/) | Yes (bundling, web serving, and PDF embedding allowed; font files may not be sold standalone) | Tokotype (`Plus Jakarta Sans`), Vercel & basement.studio (`Geist`, `Geist Mono`), Google & Red Hat (`Liberation Sans`) | Retain copyright notices and OFL-1.1 text; respect Reserved Font Names on modified derivatives | +| Synthesized UI, switch & turn sound cues (9 `.mp3` files) | `apps/editor/public/audios/sfx/{turn_done,turn_failed,turn_needs_input,viewer_hover,viewer_select,viewer_deselect,switch_on,switch_off,door_swing}.mp3` | [MIT](LICENSE) | Yes | Generated deterministically by [`scripts/synth-turn-cues.ts`](scripts/synth-turn-cues.ts) and [`scripts/synth-viewer-cues.ts`](scripts/synth-viewer-cues.ts) (using Raphael Salaja's MIT "Minimal" UI sound kit recipes for the five viewer/switch cues) | Retain MIT copyright and permission notices | +| Recorded / authored sound effects & audio | All other files in `apps/editor/public/audios/**` and `editor.pascal.app/audios/**` | **No licence recorded yet** (owner notice pending) | Not granted yet | Pascal-authored Logic Pro exports and recordings from the Pascal `/next` house | Do not redistribute without Pascal permission; override via `configureViewer({ sfxBaseUrl })` | +| Procedural urinal item | `apps/editor/public/items/urinal/{model.glb,thumbnail.png,floor-plan.png}` | [MIT](apps/editor/public/items/urinal/README.md) | Yes | Generated procedurally by [`scripts/generate-urinal.py`](scripts/generate-urinal.py) | Retain MIT copyright and permission notice | +| Bundled & hosted 3D item catalog | All other `apps/editor/public/items//` directories and Pascal storage `items/system//*` | **No licence recorded yet** (owner notice and per-model provenance pending) | Not granted yet | Synced from Pascal system catalog storage and Blender / glTF authoring pipelines | Do not redistribute without Pascal permission; supply custom catalog items and `configureViewer({ assetsBaseUrl, storageUrl })` | +| Material & PBR texture library | `apps/editor/public/material/{concrete,fabric,flooring,leather,metal,roofing,siding,wood}/` and `editor.pascal.app/material/*` | **No licence recorded yet** (owner notice and per-material source attribution pending) | Not granted yet | KTX2, WebP, JPG, and PNG PBR maps and swatches built from raw texture sources kept outside git | Do not redistribute without Pascal permission; untextured `colorPreset` / `sceneTheme` and map-less `MATERIAL_CATALOG` finishes are MIT code | +| Editor & viewer UI icons | `apps/editor/public/icons/**` (`.webp`, `.svg`), `apps/editor/public/cursor.svg`, `public/icons/spawn-point.svg`, and `editor.pascal.app/icons/*` | **No licence recorded yet** (owner notice pending) | Not granted yet | Pascal-authored and AI-generated isometric WebP and SVG UI icons | Do not redistribute without Pascal permission; override viewer UI icons via `configureViewer({ iconsBaseUrl })` | +| Bundled demo scene | `apps/editor/public/demos/demo_1.json` | **No licence recorded yet** (owner notice pending) | Not granted yet | Pascal sample scene graph referencing `/items//model.glb` | Referenced models remain subject to the `items/` status above | +| Brand logos & scaffold SVGs | `apps/editor/public/pascal*.svg`, `assets/pascal-mark*.{svg,png}`, `skills/.claude-plugin/icon.png`, `skills/.cursor-plugin/pascal-mark-plate.svg`, `apps/editor/public/{next,vercel,turborepo-dark,turborepo-light,file-text,globe,window}.svg` | Trademarks reserved / `create-turbo` starter assets | Trademark use restricted | Pascal Group Inc. (`pascal*` and plugin listing icons), Vercel Inc. (`next`, `vercel`, `turborepo-*`, starter icons) | The MIT code licence does not grant trademark rights in Pascal or Vercel marks | +| Pascal Next demo recordings & GIFs | `docs/media/next-demo/*.gif` and release MP4s | [CC BY 4.0](docs/media/next-demo/LICENSE.md) | Yes | Pascal Group Inc. | Credit Pascal Group Inc., link CC BY 4.0, and indicate changes; no trademark grant | +| IFC converter test fixtures | `apps/ifc-converter/public/test-ifc-files/*.ifc` and remote test bucket objects | **Unlicensed / conflicting** ([`test-ifc-files/README.md`](apps/ifc-converter/public/test-ifc-files/README.md)) | No (local converter testing only) | Public BIM sample repositories (`xeokit-sdk`, `youshengCode/IfcSampleFiles`, NIBS, Autodesk) | Keep conversions and renders internal; do not redistribute models or derivatives | + +--- + +## Group details + +### 1. Environment HDRI (`apps/editor/public/hdri/`) + +- **File**: `venice_sunset_1k.hdr` (1024x512 Radiance RGBE). +- **Source & licence**: Originally [**Venice Sunset**](https://polyhaven.com/a/venice_sunset) on Poly Haven, photographed by Greg Zaal and released into the public domain under [**CC0 1.0 Universal**](https://creativecommons.org/publicdomain/zero/1.0/). Self-hosted in `apps/editor/public/hdri/` from `@react-three/drei`'s `sunset` preset (`#473`) to avoid runtime third-party CDN fetches. +- **Runtime note**: `@pascal-app/viewer`'s [`SceneEnvironment`](packages/viewer/src/components/viewer/scene-environment.tsx) now generates a procedural gradient sky (or uses Three.js's built-in `RoomEnvironment`) at runtime rather than fetching `venice_sunset_1k.hdr`. +- **Commercial / SaaS & attribution**: Permitted for any purpose, including commercial SaaS products, with no attribution required. + +### 2. Fonts (`apps/editor/public/fonts/`, `apps/editor/app/fonts/`, `packages/editor/src/lib/floorplan/pdf-fonts/`) + +All bundled font files carry embedded OpenType `name` table notices or adjacent licence text placing them under the [**SIL Open Font License, Version 1.1 (OFL-1.1)**](https://openfontlicense.org/): + +- `apps/editor/public/fonts/PlusJakartaSans-SemiBold.ttf`: Copyright 2020 The Plus Jakarta Sans Project Authors ([`tokotype/PlusJakartaSans`](https://github.com/tokotype/PlusJakartaSans)), designed by Gumpita Rahayu / Tokotype. +- `apps/editor/public/fonts/geist-regular.ttf` and `apps/editor/app/fonts/{GeistVF.woff,GeistMonoVF.woff}`: Copyright 2024 The Geist Project Authors ([`vercel/geist-font`](https://github.com/vercel/geist-font)), by Vercel and basement.studio. +- `packages/editor/src/lib/floorplan/pdf-fonts/{GeistMono-Regular.ttf,GeistMono-Bold.ttf}`: Licensed under OFL-1.1; full text in [`LICENSE-GeistMono.txt`](packages/editor/src/lib/floorplan/pdf-fonts/LICENSE-GeistMono.txt). +- `packages/editor/src/lib/floorplan/pdf-fonts/{LiberationSans-Regular.ttf,LiberationSans-Bold.ttf}`: Digitized data Copyright 2010 Google Corporation and Copyright 2012 Red Hat, Inc. ([`liberationfonts/liberation-fonts`](https://github.com/liberationfonts/liberation-fonts)), with Reserved Font Names `Arimo`, `Tinos`, `Cousine`, and `Liberation`; full text in [`LICENSE-LiberationSans.txt`](packages/editor/src/lib/floorplan/pdf-fonts/LICENSE-LiberationSans.txt). + +**Commercial / SaaS & attribution**: OFL-1.1 permits bundling, web font serving, and PDF embedding in commercial and SaaS software, provided the font files are not sold by themselves, copyright and OFL-1.1 notices are preserved when redistributing font files, and modified font derivatives do not use Reserved Font Names without permission. + +### 3. Sound effects & audio (`apps/editor/public/audios/`) + +- **MIT-licensed procedurally synthesized cues (9 `.mp3` files)**: + - `turn_done.mp3`, `turn_failed.mp3`, `turn_needs_input.mp3`: Rendered deterministically from sine partials with `ffmpeg` by [`scripts/synth-turn-cues.ts`](scripts/synth-turn-cues.ts) (`#1056`). + - `viewer_hover.mp3`, `viewer_select.mp3`, `viewer_deselect.mp3`, `switch_on.mp3`, `switch_off.mp3`: Rendered deterministically with `ffmpeg` by [`scripts/synth-viewer-cues.ts`](scripts/synth-viewer-cues.ts) (`#1227`) from the MIT-licensed "Minimal" UI sound kit recipes by Raphael Salaja. + - `door_swing.mp3`: Rendered deterministically from band-passed noise with `ffmpeg` by [`scripts/synth-viewer-cues.ts`](scripts/synth-viewer-cues.ts) (`#1227`). + - These nine files are covered by the repository's [MIT licence](LICENSE) (together with Raphael Salaja's MIT notice for the Minimal UI recipes) and may be used in commercial and SaaS applications. +- **Recorded and DAW-authored audio (all other files in `apps/editor/public/audios/**`, licence notice pending)**: + - Every other audio or project file under `apps/editor/public/audios/` (and hosted `editor.pascal.app/audios/`), including the `/next` house door, garage, and shutter recordings (`door_close.mp3`, `door_open.mp3`, `garage_door.mp3`, `shutters_close.mp3`, `shutters_open.mp3`), the editor UI/tool/terrain cues and Logic Pro sidecar (`grid_snap*.mp3`, `grid_snap.mamd`, `item_*.mp3`, `menu_*.mp3`, `paint_apply.mp3`, `resize_*.mp3`, `snapshot_capture.mp3`, `structure_*.mp3`, `success.mp3`, `terrain_*.mp3`), and any hosted community radio streams. + - No standalone redistribution licence has been recorded yet for these files. Do not treat them as covered by the code's MIT licence. + +### 4. 3D item models (`apps/editor/public/items/`) + +- **`apps/editor/public/items/urinal/` (`model.glb`, `thumbnail.png`, `floor-plan.png`)**: Procedurally generated in Blender from [`scripts/generate-urinal.py`](scripts/generate-urinal.py) with no external meshes or textures, and explicitly placed under the repository's **MIT licence** in [`apps/editor/public/items/urinal/README.md`](apps/editor/public/items/urinal/README.md) (`#889`). Commercial and SaaS use is permitted under MIT. +- **All other `apps/editor/public/items//` directories (licence notice pending)**: Synced from Pascal's system catalog storage (`items/system//model.glb`, `bfcb0397`) and authoring pipelines (`glTF-Transform`, Blender glTF I/O, `obj2gltf`, `FBX2glTF`), with unreferenced authoring files (such as `piano/Fireplace_13.glb`) pruned when staging the portable CLI runtime via [`packages/cli/scripts/stage-runtime.ts`](packages/cli/scripts/stage-runtime.ts). None of the `.glb` headers embed `asset.copyright` metadata, and per-model upstream provenance and licensing have not yet been published. Until Pascal Group Inc. publishes an item-catalog licence notice, treat both the committed files under `apps/editor/public/items/` (other than `urinal/`) and the mirrored objects served from Pascal's Supabase storage bucket as **not covered by the repository MIT licence**. +- **Built-in parametric nodes vs. GLB items**: Structural and architectural geometry generated at runtime by `@pascal-app/core`, `@pascal-app/nodes`, and `@pascal-app/viewer` (walls, slabs, roofs, stairs, railings, doors, windows, kitchen cabinetry and built-in appliances in `packages/nodes/src/cabinet/`, and procedural item recipes) is pure TypeScript geometry code covered by [`LICENSE`](LICENSE) (MIT). + +### 5. Materials & PBR textures (`apps/editor/public/material/`) + +- **Files & remote catalog**: `apps/editor/public/material/` spans eight subdirectories (`concrete`, `fabric`, `flooring`, `leather`, `metal`, `roofing`, `siding`, `wood`) containing `.ktx2` Basis GPU-compressed maps, `.webp`, `.jpg`, and `.png` PBR texture channels (`basecolor`/`diffuse`, `normal`, `roughness`, `ao`/`ambientocclusion`, `metallic`, `specular`, `bump`, `displacement`), and `*_thumb.webp` picker swatches. Additional `/material/*` presets declared in `MATERIAL_CATALOG` ([`packages/core/src/material-library.ts`](packages/core/src/material-library.ts)) resolve remotely from `https://editor.pascal.app/material/` unless `assetsBaseUrl` is overridden. +- **Status**: Encoded from raw PBR sources kept outside git (cf. `042f8555`). Individual upstream source attributions and a redistribution licence grant for the compiled and hosted texture maps have not yet been recorded in the repository; do not treat `apps/editor/public/material/` or `editor.pascal.app/material/` as covered by the code's MIT licence until that notice lands. +- **MIT alternative in code**: Flat colour palettes (`colorPreset`), lighting/colour themes (`sceneTheme`), procedural runtime textures (such as `createSolarPanelTexture` in [`packages/viewer/src/lib/materials.ts`](packages/viewer/src/lib/materials.ts)), and map-less entries in `MATERIAL_CATALOG` (`preset-glass`, `preset-glass-frosted`, `preset-glass-tinted`, `metal-chrome`, `metal-brass`, `metal-black`, `metal-bronze`, `preset-metal`, and the flat `preset-*` paint swatches) are procedural material definitions in MIT-licensed code and load no files from `apps/editor/public/material/`. + +### 6. UI icons, demo scene, brand marks & repository test fixtures + +- **Pascal brand marks** (`apps/editor/public/pascal.svg`, `pascal-logo-full.svg`, `pascal-logo-shape.svg`, `assets/pascal-mark*.{svg,png}`, `skills/.claude-plugin/icon.png`, and `skills/.cursor-plugin/pascal-mark-plate.svg`): Copyright Pascal Group Inc. All trademark and brand rights are reserved; the MIT code licence grants no right to use the Pascal name or logos to imply endorsement or affiliation. +- **Scaffold & third-party marks** (`apps/editor/public/next.svg`, `vercel.svg`, `turborepo-dark.svg`, `turborepo-light.svg`, `file-text.svg`, `globe.svg`, `window.svg`): Inherited from the initial `create-turbo` / Next.js template (`d5f4648c`). Next.js, Vercel, and Turborepo marks remain subject to Vercel Inc.'s trademark guidelines. +- **UI icons (`apps/editor/public/icons/**` `.webp`/`.svg` files, `apps/editor/public/cursor.svg`, `public/icons/spawn-point.svg`, and `editor.pascal.app/icons/*`)**: Pascal-authored and AI-generated tool, node, fitting, and preset thumbnails (documented in [`apps/editor/public/icons/fittings/README.md`](apps/editor/public/icons/fittings/README.md) and [`wiki/design/kitchen-thumbnails.md`](wiki/design/kitchen-thumbnails.md)). No standalone licence grant has been recorded yet. +- **Demo scene (`apps/editor/public/demos/demo_1.json`)**: Example scene document referencing `/items//model.glb` paths; no standalone content licence has been recorded yet, and referenced item models follow Section 4 above. +- **Documentation images & unit-test fixtures outside `apps/editor/public/`**: Architecture/wiki reference images (`docs/images/*`, `wiki/images/*`) accompany repository documentation, and minimal synthetic automated-test inputs (`fixtures/viewer-live/public/cube.gltf`, `packages/geometry-script/src/__fixtures__/blender/cabinet.glb`, and `packages/ifc-converter/tests/fixtures/*.ifc`) are repository test fixtures covered by [`LICENSE`](LICENSE) (distinct from the real-world sample BIM models restricted under [`apps/ifc-converter/public/test-ifc-files/README.md`](apps/ifc-converter/public/test-ifc-files/README.md)). + +--- + +## Using Pascal packages in commercial or SaaS products + +Published npm packages (`@pascal-app/core`, `@pascal-app/nodes`, `@pascal-app/viewer`, `@pascal-app/editor`, `@pascal-app/mcp`, `@pascal-app/ifc-converter`, `@pascal-app/geometry-script`) are MIT-licensed code packages and do **not** include `apps/editor/public/` inside their npm tarballs (only `@pascal-app/editor` embeds the OFL-1.1 PDF fonts listed in Section 2, while `@pascal-app/cli` downloads the full standalone web runtime archive when running `pascal editor`). + +However, when unconfigured, `@pascal-app/viewer` resolves relative asset, icon, and sound URLs against `https://editor.pascal.app` ([`packages/viewer/src/lib/viewer-config.ts`](packages/viewer/src/lib/viewer-config.ts)), and `@pascal-app/editor`'s default item picker ([`packages/editor/src/components/ui/item-catalog/catalog-items.tsx`](packages/editor/src/components/ui/item-catalog/catalog-items.tsx)) references Pascal's public Supabase storage bucket. + +If you embed `@pascal-app/viewer` or `@pascal-app/editor` in a commercial or SaaS product, configure all four asset origins at bootstrap (and supply your own item catalog when mounting `@pascal-app/editor`) so your host serves only assets you have licensed or authored: + +```ts +import { configureViewer } from '@pascal-app/viewer' + +configureViewer({ + assetsBaseUrl: 'https://assets.example.com', + storageUrl: 'https://storage.example.com', + sfxBaseUrl: 'https://assets.example.com/audios/sfx', + iconsBaseUrl: 'https://assets.example.com/icons', + // Optional self-hosted Draco (Apache-2.0) and Basis Universal (Apache-2.0) decoders: + decoders: { + dracoPath: '/decoders/draco/', + basisPath: '/decoders/basis/', + }, +}) +``` + +> [!IMPORTANT] +> Setting `NEXT_PUBLIC_ASSETS_CDN_URL` and `NEXT_PUBLIC_SUPABASE_URL` in a Next.js host only configures the fallback `assetsBaseUrl` and `storageUrl` in [`getViewerConfig()`](packages/viewer/src/lib/viewer-config.ts). It does **not** redirect `sfxBaseUrl` (`https://editor.pascal.app/audios/sfx`), `iconsBaseUrl` (`https://editor.pascal.app/icons`), or the hardcoded storage URLs in `@pascal-app/editor`'s built-in `CATALOG_ITEMS`. Always pass explicit `sfxBaseUrl` and `iconsBaseUrl` values to `configureViewer(...)` (as [`apps/editor/lib/bootstrap.ts`](apps/editor/lib/bootstrap.ts) does) or avoid initializing `@pascal-app/viewer/sfx` and `@pascal-app/viewer/ui` against Pascal's default CDN. diff --git a/README.md b/README.md index e5c0776eea..7a55b868a4 100644 --- a/README.md +++ b/README.md @@ -295,8 +295,11 @@ runs in the browser, locally through its CLI, or self-hosted, and exposes the sa agents over MCP. **Is it free and open source?** -Yes. The editor, packages, CLI, and MCP server in this repository are MIT-licensed. Hosted -services at editor.pascal.app are separate from the open-source release and have their own +Yes. The source code for the editor, packages, CLI, and MCP server in this repository is +[MIT-licensed](LICENSE). Bundled 3D models, PBR textures, icons, fonts, HDRI, and sound effects +under `apps/editor/public` are **not** covered by the code's MIT licence unless noted otherwise; +see [ASSETS.md](ASSETS.md) for the licence, source, and commercial-use status of each asset group. +Hosted services at editor.pascal.app are separate from the open-source release and have their own account terms. **Does it work offline?** diff --git a/apps/editor/README.md b/apps/editor/README.md index 1329ad6609..dad62a16f6 100644 --- a/apps/editor/README.md +++ b/apps/editor/README.md @@ -361,3 +361,9 @@ pnpm dev | `packages/viewer/src/components/viewer/` | Main Viewer component | | `apps/editor/components/tools/` | Editor tools | | `apps/editor/store/` | Editor-specific state | + +--- + +## Bundled Static Assets (`public/`) + +Static assets under `apps/editor/public/` (3D item GLBs, KTX2/WebP/JPG/PNG PBR materials, UI icons, HDRI, fonts, demo scenes, and sound effects) have separate licence and provenance terms and are **not** covered as a blanket group by the repository's MIT code licence. See [`ASSETS.md`](../../ASSETS.md) at the repository root before redistributing or reusing bundled assets. diff --git a/apps/editor/lib/bundled-assets-policy.test.ts b/apps/editor/lib/bundled-assets-policy.test.ts new file mode 100644 index 0000000000..0115de96ed --- /dev/null +++ b/apps/editor/lib/bundled-assets-policy.test.ts @@ -0,0 +1,291 @@ +import { afterEach, beforeEach, describe, expect, it } from 'bun:test' +import { existsSync, readdirSync, readFileSync } from 'node:fs' +import { dirname, join, resolve } from 'node:path' +import { fileURLToPath } from 'node:url' +import { MATERIAL_CATALOG } from '../../../packages/core/src/material-library' +import { + ASSETS_CDN_URL, + configureViewer, + getViewerConfig, +} from '../../../packages/viewer/src/lib/viewer-config' +import { isPathInside } from '../../../scripts/path-containment' + +const repoRoot = resolve(dirname(fileURLToPath(import.meta.url)), '../../..') +const originalEnv = { ...process.env } + +function resetViewerTestState(): void { + configureViewer({}) + for (const key of ['NEXT_PUBLIC_ASSETS_CDN_URL', 'NEXT_PUBLIC_SUPABASE_URL'] as const) { + if (originalEnv[key] === undefined) delete process.env[key] + else process.env[key] = originalEnv[key] + } +} + +beforeEach(resetViewerTestState) +afterEach(resetViewerTestState) + +function stripCodeFences(markdown: string): string { + const out: string[] = [] + let insideFence = false + for (const line of markdown.split('\n')) { + if (/^\s*(?:```|~~~)/u.test(line)) { + insideFence = !insideFence + continue + } + if (!insideFence) out.push(line) + } + return out.join('\n') +} + +export function extractMarkdownLinks(markdown: string): string[] { + const withoutFences = stripCodeFences(markdown) + const links: string[] = [] + // Single-pass alternation: standalone inline code spans (`...`) are consumed first so + // examples like `[label](not-a-link)` inside backticks are ignored, while real links whose + // labels contain backticks (`[`LICENSE`](LICENSE)`) or nested badge images (`[![alt](img)](dst)`) + // match the second branch cleanly. + const tokenPattern = /`[^`\n]+`|\[(?:!\[[^\]]*\]\([^)]*\)|[^\]]+)\]\(([^)\s]+)(?:\s+"[^"]*")?\)/gu + for (const match of withoutFences.matchAll(tokenPattern)) { + if (match[1]) links.push(match[1].trim()) + } + return links +} + +export function headingSlugs(markdown: string): Set { + const slugs = new Set() + const occurrences = new Map() + for (const line of stripCodeFences(markdown).split('\n')) { + const heading = line.match(/^#{1,6}\s+(.+?)\s*$/u) + if (!heading) continue + const base = heading[1]! + .replace(/\[([^\]]*)\]\([^)]*\)/gu, '$1') + .replace(/[`*~]/gu, '') + .trim() + .toLowerCase() + .replace(/[^\p{L}\p{N} _-]+/gu, '') + .replace(/ /gu, '-') + if (!base) continue + const seen = occurrences.get(base) ?? 0 + occurrences.set(base, seen + 1) + slugs.add(seen === 0 ? base : `${base}-${seen}`) + } + return slugs +} + +function escapeRegExp(value: string): string { + return value.replace(/[.*+?^${}()|[\]\\]/gu, '\\$&') +} + +describe('bundled assets licence notice (ASSETS.md)', () => { + const assetsDocPath = join(repoRoot, 'ASSETS.md') + const assetsDoc = readFileSync(assetsDocPath, 'utf8') + + it('resolves every relative link and local/cross-file anchor in ASSETS.md and cross-linked READMEs', () => { + const slugCache = new Map>() + const getSlugs = (absPath: string) => { + let cached = slugCache.get(absPath) + if (!cached) { + cached = headingSlugs(readFileSync(absPath, 'utf8')) + slugCache.set(absPath, cached) + } + return cached + } + + const checkedCounts = new Map() + for (const relPath of [ + 'ASSETS.md', + 'README.md', + 'apps/editor/README.md', + 'packages/viewer/README.md', + ]) { + const fullPath = join(repoRoot, relPath) + const content = readFileSync(fullPath, 'utf8') + + for (const target of extractMarkdownLinks(content)) { + if (/^(?:https?:|mailto:)/u.test(target)) continue + checkedCounts.set(relPath, (checkedCounts.get(relPath) ?? 0) + 1) + + const hashIndex = target.indexOf('#') + const pathPart = hashIndex === -1 ? target : target.slice(0, hashIndex) + const fragment = hashIndex === -1 ? '' : target.slice(hashIndex + 1) + const resolvedTarget = pathPart ? resolve(dirname(fullPath), pathPart) : fullPath + + expect([relPath, target, isPathInside(repoRoot, resolvedTarget)]).toEqual([ + relPath, + target, + true, + ]) + expect([relPath, target, existsSync(resolvedTarget)]).toEqual([relPath, target, true]) + + if (fragment) { + expect(resolvedTarget.endsWith('.md')).toBe(true) + expect([relPath, target, getSlugs(resolvedTarget).has(fragment)]).toEqual([ + relPath, + target, + true, + ]) + } + } + } + + // Ensure code-formatted links like [`LICENSE`](LICENSE) and [`ASSETS.md`](../../ASSETS.md) were not skipped. + expect(checkedCounts.get('ASSETS.md') ?? 0).toBeGreaterThanOrEqual(15) + expect(checkedCounts.get('apps/editor/README.md') ?? 0).toBeGreaterThanOrEqual(1) + }) + + it('matches GitHub heading slug rules and ignores links inside inline code spans', () => { + const slugs = headingSlugs(assetsDoc) + expect(slugs.has('5-materials--pbr-textures-appseditorpublicmaterial')).toBe(true) + expect(slugs.has('6-ui-icons-demo-scene-brand-marks--repository-test-fixtures')).toBe(true) + + const sample = [ + 'Inline code `[ignored](missing.md)` stays inert.', + 'Code-label link [`LICENSE`](LICENSE) and badge [![MIT](badge.svg)](ASSETS.md#group-details "Notice") resolve.', + ].join('\n') + expect(extractMarkdownLinks(sample)).toEqual(['LICENSE', 'ASSETS.md#group-details']) + }) + + it('uses npm-safe canonical links for repo-root asset docs in @pascal-app/viewer README', () => { + const viewerReadme = readFileSync(join(repoRoot, 'packages/viewer/README.md'), 'utf8') + const licenseSection = viewerReadme.slice(viewerReadme.lastIndexOf('## License')) + expect(licenseSection).toContain('[`LICENSE`](LICENSE)') + expect(licenseSection).toContain('https://github.com/pascalorg/editor/blob/main/ASSETS.md') + expect(licenseSection).not.toContain('(../../ASSETS.md)') + expect(licenseSection).not.toContain('(../../apps/editor/public)') + }) + + it('covers every top-level folder and root file under apps/editor/public on exact path boundaries', () => { + const publicRoot = join(repoRoot, 'apps/editor/public') + const entries = readdirSync(publicRoot, { withFileTypes: true }) + + const documentedRootFiles = new Set() + for (const match of assetsDoc.matchAll( + /apps\/editor\/public\/([A-Za-z0-9._-]+\.[A-Za-z0-9]+)/gu, + )) { + documentedRootFiles.add(match[1]!) + } + for (const match of assetsDoc.matchAll(/apps\/editor\/public\/\{([^}]+)\}(\.[A-Za-z0-9]+)/gu)) { + const ext = match[2]! + for (const stem of match[1]!.split(',')) { + documentedRootFiles.add(`${stem.trim()}${ext}`) + } + } + + for (const entry of entries) { + if (entry.isDirectory()) { + const boundary = new RegExp( + `apps/editor/public/${escapeRegExp(entry.name)}(?=[/\`\\s*)]|$)`, + 'u', + ) + expect([entry.name, boundary.test(assetsDoc)]).toEqual([entry.name, true]) + } else if (entry.isFile()) { + const coveredByPascalWildcard = + /^pascal[A-Za-z0-9._-]*\.svg$/u.test(entry.name) && + assetsDoc.includes('apps/editor/public/pascal*.svg') + expect([ + entry.name, + documentedRootFiles.has(entry.name) || coveredByPascalWildcard, + ]).toEqual([entry.name, true]) + } + } + + for (const audioEntry of readdirSync(join(publicRoot, 'audios'), { withFileTypes: true })) { + if (!audioEntry.isDirectory()) continue + const audioBoundary = new RegExp( + `apps/editor/public/audios/${escapeRegExp(audioEntry.name)}(?=[/\`\\s*)]|$)`, + 'u', + ) + const covered = + audioBoundary.test(assetsDoc) || assetsDoc.includes('apps/editor/public/audios/**') + expect([`audios/${audioEntry.name}`, covered]).toEqual([`audios/${audioEntry.name}`, true]) + } + }) + + it('keeps the MIT synthesized SFX list in sync with scripts/synth-*.ts and public/audios/sfx', () => { + const turnScript = readFileSync(join(repoRoot, 'scripts/synth-turn-cues.ts'), 'utf8') + const viewerScript = readFileSync(join(repoRoot, 'scripts/synth-viewer-cues.ts'), 'utf8') + const scriptedFiles = [ + ...new Set( + [...`${turnScript}\n${viewerScript}`.matchAll(/file:\s*'([^']+\.mp3)'/gu)].map( + (match) => match[1]!, + ), + ), + ].sort() + + expect(scriptedFiles).toEqual([ + 'door_swing.mp3', + 'switch_off.mp3', + 'switch_on.mp3', + 'turn_done.mp3', + 'turn_failed.mp3', + 'turn_needs_input.mp3', + 'viewer_deselect.mp3', + 'viewer_hover.mp3', + 'viewer_select.mp3', + ]) + + for (const cue of scriptedFiles) { + expect(existsSync(join(repoRoot, 'apps/editor/public/audios/sfx', cue))).toBe(true) + expect(assetsDoc).toContain(`\`${cue}\``) + } + }) + + it('lists only genuinely map-less MATERIAL_CATALOG presets as procedural MIT finishes', () => { + const byId = new Map(MATERIAL_CATALOG.map((item) => [item.id, item])) + + // Verify the blanket `preset-*` claim in ASSETS.md holds for every preset-* entry in core. + const presetItems = MATERIAL_CATALOG.filter((item) => item.id.startsWith('preset-')) + expect(presetItems.length).toBeGreaterThan(0) + for (const item of presetItems) { + expect([item.id, Object.keys(item.preset.maps ?? {})]).toEqual([item.id, []]) + } + + // Verify every catalog ID named inside the "MIT alternative in code" bullet has zero maps. + const mitAlternativeLine = assetsDoc + .split('\n') + .find((line) => line.includes('**MIT alternative in code**:')) + expect(mitAlternativeLine).toBeDefined() + const mentionedCatalogIds = [...mitAlternativeLine!.matchAll(/`([a-z0-9-]+)`/gu)] + .map((match) => match[1]!) + .filter((token) => byId.has(token)) + + expect(mentionedCatalogIds.sort()).toEqual([ + 'metal-black', + 'metal-brass', + 'metal-bronze', + 'metal-chrome', + 'preset-glass', + 'preset-glass-frosted', + 'preset-glass-tinted', + 'preset-metal', + ]) + for (const id of mentionedCatalogIds) { + expect([id, Object.keys(byId.get(id)!.preset.maps ?? {})]).toEqual([id, []]) + } + }) + + it('matches getViewerConfig() behavior where NEXT_PUBLIC_ASSETS_CDN_URL leaves sfxBaseUrl and iconsBaseUrl on editor.pascal.app unless configured', () => { + // Simulate prior module-level bootstrap state before beforeEach/reset safety. + configureViewer({ sfxBaseUrl: '/audios/sfx', iconsBaseUrl: '/icons' }) + resetViewerTestState() + + process.env.NEXT_PUBLIC_ASSETS_CDN_URL = 'https://assets.example.com' + process.env.NEXT_PUBLIC_SUPABASE_URL = 'https://storage.example.com' + + const envOnly = getViewerConfig() + expect(envOnly.assetsBaseUrl).toBe('https://assets.example.com') + expect(envOnly.storageUrl).toBe('https://storage.example.com') + expect(envOnly.sfxBaseUrl).toBe(`${ASSETS_CDN_URL}/audios/sfx`) + expect(envOnly.iconsBaseUrl).toBe(`${ASSETS_CDN_URL}/icons`) + + configureViewer({ + assetsBaseUrl: 'https://assets.example.com', + storageUrl: 'https://storage.example.com', + sfxBaseUrl: 'https://assets.example.com/audios/sfx', + iconsBaseUrl: 'https://assets.example.com/icons', + }) + const explicit = getViewerConfig() + expect(explicit.sfxBaseUrl).toBe('https://assets.example.com/audios/sfx') + expect(explicit.iconsBaseUrl).toBe('https://assets.example.com/icons') + }) +}) diff --git a/packages/viewer/README.md b/packages/viewer/README.md index ac331ac0f1..f868ac532b 100644 --- a/packages/viewer/README.md +++ b/packages/viewer/README.md @@ -492,4 +492,4 @@ const externalUrl = resolveCdnUrl('https://example.com/model.glb') ## License -MIT +MIT for package source code (see [`LICENSE`](LICENSE)). Default remote assets, icons, and sound effects served from `editor.pascal.app` or [`apps/editor/public`](https://github.com/pascalorg/editor/tree/main/apps/editor/public) have separate licence terms; see [`ASSETS.md`](https://github.com/pascalorg/editor/blob/main/ASSETS.md).