{"_id":"emdash-plugin-stl-viewer","_rev":"3-79791b1f11089ed8c6676525c6bc787b","name":"emdash-plugin-stl-viewer","dist-tags":{"latest":"0.3.0"},"versions":{"0.1.0":{"name":"emdash-plugin-stl-viewer","version":"0.1.0","keywords":["emdash","emdash-plugin","astro","stl","3d","three.js","portable-text"],"author":{"name":"Eric Boothe"},"license":"MIT","_id":"emdash-plugin-stl-viewer@0.1.0","maintainers":[{"name":"ebootheee","email":"eric@boothe.io"}],"homepage":"https://github.com/ebootheee/emdash-plugin-stl-viewer#readme","bugs":{"url":"https://github.com/ebootheee/emdash-plugin-stl-viewer/issues"},"dist":{"shasum":"6c9508371c0f39b06545bed2488902c5c45989aa","tarball":"https://registry.npmjs.org/emdash-plugin-stl-viewer/-/emdash-plugin-stl-viewer-0.1.0.tgz","fileCount":8,"integrity":"sha512-lodYEME9vmIZu0NqZqa0mvAVOpQmbEk21IPNtC0Jh0rAIyqls0zLDI/3p89qBCa21kcbV98Gdx28iIqpFJM2ZQ==","signatures":[{"sig":"MEQCIAOY75RI9WSSgBr2xI2kbcI+XGzWEN2Olhh/cNHM0hR5AiBcVepzfEXgVN7HCRiEWZjr4nNbQLUgD0ZmZk0Cxfyr5A==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":44818},"main":"src/index.ts","type":"module","exports":{".":"./src/index.ts","./astro":"./src/astro/index.ts","./astro/StlViewer.astro":"./src/astro/StlViewer.astro"},"gitHead":"750f289ac1accd03368e749d997ce708fd7f02bd","scripts":{"typecheck":"tsc --noEmit","generate-fixtures":"node scripts/generate-fixtures.mjs"},"_npmUser":{"name":"ebootheee","email":"eric@boothe.io"},"repository":{"url":"git+https://github.com/ebootheee/emdash-plugin-stl-viewer.git","type":"git"},"_npmVersion":"11.6.2","description":"EmDash CMS plugin: embed interactive 3D previews of STL files in Portable Text content","directories":{},"sideEffects":false,"_nodeVersion":"24.12.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.6.0","@types/three":"^0.171.0"},"peerDependencies":{"astro":">=6.0.0","three":"^0.171.0","emdash":">=0.6.0"},"_npmOperationalInternal":{"tmp":"tmp/emdash-plugin-stl-viewer_0.1.0_1778963123678_0.7282150756520405","host":"s3://npm-registry-packages-npm-production"}},"0.2.0":{"name":"emdash-plugin-stl-viewer","version":"0.2.0","keywords":["emdash","emdash-plugin","astro","stl","3mf","3d","three.js","portable-text"],"author":{"name":"Eric Boothe"},"license":"MIT","_id":"emdash-plugin-stl-viewer@0.2.0","maintainers":[{"name":"ebootheee","email":"eric@boothe.io"}],"homepage":"https://github.com/ebootheee/emdash-plugin-stl-viewer#readme","bugs":{"url":"https://github.com/ebootheee/emdash-plugin-stl-viewer/issues"},"dist":{"shasum":"072f8f9c39ac25c08eb3b5d819d3bc09e154b5f5","tarball":"https://registry.npmjs.org/emdash-plugin-stl-viewer/-/emdash-plugin-stl-viewer-0.2.0.tgz","fileCount":9,"integrity":"sha512-MsNWa7ptwKk4wKBIGTrpw+kgS3q9O0F9dBMDuhgmnQEfuT/uB88DqyUOUV3XzBb3sBQ42TglSO5MOPRT/NSoHA==","signatures":[{"sig":"MEUCIQCSfDKItzm6I8DjTK3/qUuj6oYXIOKQPJ9LcO4F3uNiLgIgZu3JlATgWfhdaHqJ9L71MvD8SvLuS6kn4WOR7LtED8w=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":56614},"main":"src/index.ts","type":"module","exports":{".":"./src/index.ts","./astro":"./src/astro/index.ts","./astro/StlViewer.astro":"./src/astro/StlViewer.astro"},"gitHead":"a49e9b15afa10d207d74a6c8e1e467e86ae2ea52","scripts":{"typecheck":"tsc --noEmit","generate-fixtures":"node scripts/generate-fixtures.mjs"},"_npmUser":{"name":"ebootheee","email":"eric@boothe.io"},"repository":{"url":"git+https://github.com/ebootheee/emdash-plugin-stl-viewer.git","type":"git"},"_npmVersion":"11.6.2","description":"EmDash CMS plugin: embed interactive 3D previews of STL or 3MF files in Portable Text content","directories":{},"sideEffects":false,"_nodeVersion":"24.12.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"fflate":"^0.8.3","typescript":"^5.6.0","@types/three":"^0.171.0"},"peerDependencies":{"astro":">=6.0.0","three":"^0.171.0","emdash":">=0.6.0"},"_npmOperationalInternal":{"tmp":"tmp/emdash-plugin-stl-viewer_0.2.0_1778991795937_0.5098732886164972","host":"s3://npm-registry-packages-npm-production"}},"0.3.0":{"name":"emdash-plugin-stl-viewer","version":"0.3.0","description":"EmDash CMS plugin: embed interactive 3D previews of STL or 3MF files in Portable Text content","keywords":["emdash","emdash-plugin","astro","stl","3mf","3d","three.js","portable-text"],"author":{"name":"Eric Boothe"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/ebootheee/emdash-plugin-stl-viewer.git"},"bugs":{"url":"https://github.com/ebootheee/emdash-plugin-stl-viewer/issues"},"homepage":"https://github.com/ebootheee/emdash-plugin-stl-viewer#readme","type":"module","main":"src/index.ts","exports":{".":"./src/index.ts","./astro":"./src/astro/index.ts","./astro/StlViewer.astro":"./src/astro/StlViewer.astro"},"scripts":{"generate-fixtures":"node scripts/generate-fixtures.mjs","typecheck":"tsc --noEmit"},"peerDependencies":{"astro":">=6.0.0","emdash":">=0.12.0","three":"^0.171.0"},"devDependencies":{"@types/three":"^0.171.0","fflate":"^0.8.3","typescript":"^5.6.0"},"publishConfig":{"access":"public"},"sideEffects":false,"gitHead":"617a2915fc28cdbdaf6bb7cadfad02fed521319c","_id":"emdash-plugin-stl-viewer@0.3.0","_nodeVersion":"24.15.0","_npmVersion":"11.12.1","dist":{"integrity":"sha512-uQ8hdyJAHxq9DYMk12p6ERRvtNn1xV+CnUhbLYMDg2gP1GebPjYp6UAd+P9/xO3qITrfSvBpm2v+3DlP4lWh3Q==","shasum":"4f395c831541637e0674a892073580b250127cb3","tarball":"https://registry.npmjs.org/emdash-plugin-stl-viewer/-/emdash-plugin-stl-viewer-0.3.0.tgz","fileCount":9,"unpackedSize":56001,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/emdash-plugin-stl-viewer@0.3.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDoQGxRZc/bvUycSJFrPQNDkv5qFliwMpiR45rbdOLYGQIhANYA00gFIGVq6bTyaVQo463z4UmHjFhm5Ky9kVUMWZx5"}]},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:f9c6a761-0053-4e84-8ae5-c3fbc0541366"}},"directories":{},"maintainers":[{"name":"ebootheee","email":"eric@boothe.io"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/emdash-plugin-stl-viewer_0.3.0_1779418579904_0.3482039873125722"},"_hasShrinkwrap":false}},"time":{"created":"2026-05-16T20:25:23.563Z","modified":"2026-05-22T02:56:20.341Z","0.1.0":"2026-05-16T20:25:23.812Z","0.2.0":"2026-05-17T04:23:16.109Z","0.3.0":"2026-05-22T02:56:20.047Z"},"bugs":{"url":"https://github.com/ebootheee/emdash-plugin-stl-viewer/issues"},"author":{"name":"Eric Boothe"},"license":"MIT","homepage":"https://github.com/ebootheee/emdash-plugin-stl-viewer#readme","keywords":["emdash","emdash-plugin","astro","stl","3mf","3d","three.js","portable-text"],"repository":{"type":"git","url":"git+https://github.com/ebootheee/emdash-plugin-stl-viewer.git"},"description":"EmDash CMS plugin: embed interactive 3D previews of STL or 3MF files in Portable Text content","maintainers":[{"name":"ebootheee","email":"eric@boothe.io"}],"readme":"# emdash-plugin-stl-viewer\n\n[![npm version](https://img.shields.io/npm/v/emdash-plugin-stl-viewer.svg)](https://www.npmjs.com/package/emdash-plugin-stl-viewer)\n[![npm downloads](https://img.shields.io/npm/dm/emdash-plugin-stl-viewer.svg)](https://www.npmjs.com/package/emdash-plugin-stl-viewer)\n[![license](https://img.shields.io/npm/l/emdash-plugin-stl-viewer.svg)](./LICENSE)\n\nAn [EmDash CMS](https://emdashcms.com) plugin that embeds interactive 3D previews of **STL** and **3MF** files inside Portable Text content. Drop a 3D Model block into any post or page, pick a file (or paste a URL), and get a touch-friendly orbit viewer that loads `three.js` lazily on viewport entry.\n\n![A rendered STL model embedded in an article](./screenshot.png)\n\n## Features\n\n- **STL and 3MF** — both formats supported. Format is auto-detected from the URL's file extension (`.stl` / `.3mf`); set an explicit override in the block form for opaque URLs.\n- **Lazy three.js** — the library (~170 KB gzipped) downloads only when a viewer is scrolled near; pages with no model embeds pay nothing.\n- **Lazy 3MF decoder** — the `3MFLoader` (plus the bundled fflate zip decoder) loads on-demand the first time a 3MF URL is encountered. Pages with STL-only content never pay the 3MF cost.\n- **Shared module** — additional viewers on the same page reuse the cached module, only paying for their own scene.\n- **Five materials** — matte plastic, glossy plastic, brushed metal, surface-normal rainbow, unlit clay. The configured material is applied uniformly to 3MF imports (the file's embedded materials are intentionally overridden so blocks render consistently with STL).\n- **Three sizes** — compact / standard / tall, all responsive.\n- **Auto-rotate on idle** — pauses on user input, resumes after a moment.\n- **Touch support** — pinch-zoom, two-finger pan, one-finger orbit.\n- **Progress UI** — bytes/total during model download, indeterminate while three.js loads.\n- **Auto Z-up detection** — many printable STLs and 3MFs ship Z-up; the viewer rotates them so Y is up.\n- **Auto-framing** — the model is recentered around the origin and the camera distance is derived from the bounding sphere and FOV.\n\n## Installation\n\n```bash\npnpm add emdash-plugin-stl-viewer three\n# (peers: astro, emdash, three)\n```\n\nRegister it in `astro.config.mjs`:\n\n```js\nimport { stlViewerPlugin } from \"emdash-plugin-stl-viewer\";\n\nexport default defineConfig({\n\tintegrations: [\n\t\temdash({\n\t\t\tplugins: [stlViewerPlugin()],\n\t\t\t// ...\n\t\t}),\n\t],\n});\n```\n\nThat's it. The block type `stl-viewer` (labeled **\"3D Model (STL or 3MF)\"** in the slash menu) is now available in the Portable Text editor.\n\n## Authoring\n\nIn the editor, type `/` and pick **3D Model (STL or 3MF)**. Fill in:\n\n| Field | Description |\n| --- | --- |\n| **Model file** | Opens the EmDash media picker filtered to `model/*` MIME types. Pick an existing asset, upload a new `.stl`/`.3mf`, or paste a URL directly into the input. |\n| **Format** | Auto-detect from URL (default) / STL / 3MF. Override when the URL has no extension. |\n| **Title** | Optional header text. |\n| **Caption** | Optional figcaption below the viewer. |\n| **Material** | Matte plastic, glossy plastic, brushed metal, normal map, or unlit clay. |\n| **Color** | Hex color for matte/glossy/metal materials. Ignored by `normal`. |\n| **Viewer height** | Compact (320 px), Standard (440 px), Tall (560 px). |\n| **Auto-rotate when idle** | Off if you'd rather have a static front view. |\n| **Show ground plane** | Subtle grid beneath the model. |\n\n### Uploading STL or 3MF files\n\nThe block's **Model file** field uses EmDash's `media_picker` with `mime_type_filter: \"model/\"`. In the popup you can:\n\n- **Select** an existing asset (filtered to `model/*` MIME types).\n- **Upload** a new `.stl` or `.3mf` — the file dialog's `accept` is scoped to `model/`, and EmDash's `/_emdash/api/media/upload-url` endpoint passes the MIME type through to R2 without a global allowlist.\n- **Paste a URL** directly into the input — the field value is a plain string, so external URLs (`https://…`) work too.\n\nBrowsers may not recognise `.stl` / `.3mf` from extension alone (the `Content-Type` arrives as `application/octet-stream`). EmDash now retains the upload's original `Content-Type` header, but if you're hosting your own asset server, set `Content-Type: model/stl` or `model/3mf` explicitly. The viewer itself does not require a particular MIME type — it sniffs the URL's extension or the explicit `format` override.\n\n## Architecture\n\nThe plugin is **native format** — that's required for Portable Text block types because they need Astro components for site-side rendering.\n\n```\nsrc/\n├── index.ts              # PluginDescriptor + definePlugin() (Native format)\n└── astro/\n    ├── index.ts          # Exports `blockComponents` map\n    ├── StlViewer.astro   # Server-rendered placeholder + scoped CSS\n    └── viewer-client.ts  # Lazy three.js + 3MF init, OrbitControls, lifecycle\n```\n\nThe Astro component renders a placeholder card with a CSS-animated phantom cube. When the wrapper enters the viewport (`IntersectionObserver`, 400 px root margin), the client script:\n\n1. Dynamically imports `three`, `three/addons/controls/OrbitControls.js`, and `three/addons/loaders/STLLoader.js` (memoised — one fetch per page).\n2. If the URL ends in `.3mf` (or `format === \"3mf\"`), additionally imports `three/addons/loaders/3MFLoader.js` lazily.\n3. Streams the model via `fetch` with a progress callback so large files show byte counts.\n4. STL: parses to a single `BufferGeometry`, recenters it, computes smooth-shaded normals.\n   3MF: parses to a `Group` (potentially multi-mesh), replaces embedded materials with the configured material, repositions the group's centroid to the origin.\n5. Mounts a `WebGLRenderer` canvas inside the stage, attaches `OrbitControls`.\n6. Hooks up `ResizeObserver` so the renderer follows container resizes, and a second `IntersectionObserver` to pause the render loop when offscreen.\n\n### A note on Astro scoped CSS\n\nThe canvas element is injected by `three.js` at runtime, so it doesn't carry the `data-astro-cid-*` attribute Astro adds to elements declared inside the component. Any selector targeting the canvas must use `:global(canvas)`, or Astro's scope rewrite will silently leave the runtime element unstyled. The viewer hits this in two places — both are wrapped accordingly in `StlViewer.astro`.\n\n### Bundle layout\n\nBuilt via Vite (Astro):\n\n| Chunk | Approx size | When loaded |\n| --- | ---: | --- |\n| `StlViewer.astro_…js` | ~7 KB | Eagerly with the page that has a viewer |\n| `three.module.js` | ~690 KB | First viewer hits viewport |\n| `OrbitControls.js` | ~19 KB | First viewer hits viewport |\n| `STLLoader.js` | ~3 KB | First viewer hits viewport |\n| `3MFLoader.js` (+ fflate) | ~50 KB | Only on the first 3MF viewer on a page |\n\n## Development\n\n```bash\npnpm install\npnpm generate-fixtures   # writes cube.stl / icosahedron.stl / torus.stl / knurled.stl to public/stls/ of the host repo\npnpm typecheck\n```\n\n## Compatibility\n\n- Astro `>= 6.0`\n- EmDash `>= 0.12` (uses Block Kit's `media_picker` element with `mime_type_filter`).\n- `three` `^0.171.0`\n\n## Changelog\n\n- **0.3.0** — Switch the Model URL field to a `media_picker` filtered to `model/*` MIME types. Authors get a unified pick/upload/paste-URL popup in the block form. Bumps the required EmDash version to `>= 0.12`. Existing content is unchanged — the field value is still a plain URL string.\n- **0.2.0** — Add 3MF support alongside STL. `3MFLoader` (plus the bundled fflate zip decoder) lazy-loads only when a 3MF URL is encountered.\n- **0.1.0** — Initial release. STL viewer block with five materials, three sizes, auto-rotate, touch support, and a lazy three.js bundle.\n\n## License\n\nMIT — see [LICENSE](./LICENSE).\n","readmeFilename":"README.md"}