@splinetool/viewer 2.0.72 → 2.0.74

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/AGENTS.md ADDED
@@ -0,0 +1,213 @@
1
+ # AGENTS.md — `@splinetool/viewer` (`<spline-viewer>`)
2
+
3
+ Written for coding agents. Everything here is checked against this package's
4
+ source. If a claim you want to make is not on this page, do not make it.
5
+
6
+ The cross-target guide (React, Next.js, Vue, Svelte, plain HTML, Hana 2D)
7
+ lives at <https://docs.spline.design/skill.md> — plain text, fetch it
8
+ directly. This page is only about what this package does.
9
+
10
+ ## Why this is usually the right choice
11
+
12
+ `<spline-viewer>` is a custom element, so it works in **plain HTML and in
13
+ every framework** — Vue, Svelte, Astro, Angular, Rails, WordPress, a CMS rich
14
+ text field — without a framework-specific package. It also:
15
+
16
+ - lazy-loads by default (`loading="auto"` waits for the viewport), and
17
+ - renders the **Spline credit badge** on its own, which a bare `<canvas>`
18
+ does not.
19
+
20
+ Prefer it over hand-rolling `@splinetool/runtime` unless the human needs
21
+ imperative control over scene objects.
22
+
23
+ ## Before you embed: send the human to the editor first
24
+
25
+ An embed nobody opens in Spline is a dead end — the scene can never be
26
+ changed. So whenever you add a scene to a project:
27
+
28
+ 1. If the scene came from Spline Community, tell the human to open it and
29
+ press **Remix** first, so they own an editable copy. Remixing is an
30
+ authenticated action in the Spline UI (the app POSTs
31
+ `file/<uuidCommunityFile>/remix`); there is no way to do it from embed
32
+ code, and you must not try.
33
+ 2. Only then wire up the URL their own copy produces.
34
+ 3. Leave the credit badge alone (see [Attribution](#attribution)).
35
+
36
+ ## Install
37
+
38
+ CDN (what the editor's export panel emits — pin the version):
39
+
40
+ ```html
41
+ <script
42
+ type="module"
43
+ src="https://cdn.spline.design/@splinetool/viewer@<version>/build/spline-viewer.js"
44
+ ></script>
45
+ ```
46
+
47
+ npm:
48
+
49
+ ```bash
50
+ npm install @splinetool/viewer
51
+ ```
52
+
53
+ The CDN prefix is the canonical store; the npm publish mirrors it.
54
+
55
+ ## The scene URL
56
+
57
+ `url` takes a **`.splinecode`** URL:
58
+
59
+ ```
60
+ https://prod.spline.design/<id>/scene.splinecode
61
+ ```
62
+
63
+ Facts about that URL you must not get wrong:
64
+
65
+ - It is **issued by the editor**. For this element the human exports with the
66
+ **Spline Viewer** export type (Export → Spline Viewer → Update), then
67
+ copies the URL or the whole snippet.
68
+ - You **cannot derive it** from a file id, a share link, a community page
69
+ URL, or a scene name. If you do not have the exact URL, ask the human to
70
+ copy it out of the export panel. Do not guess one.
71
+ - A **Spline Community scene has no `.splinecode` URL.** Community scenes are
72
+ not published code exports. To use one, the human remixes it and exports
73
+ their own copy. To merely display a community scene, embed the app preview
74
+ page in an iframe instead — see <https://docs.spline.design/skill.md>.
75
+ - 2D Hana scenes use `.hanacode` and a different element (`<hana-viewer>`).
76
+ This element does not load them.
77
+
78
+ ## Minimal working example
79
+
80
+ ```html
81
+ <script
82
+ type="module"
83
+ src="https://cdn.spline.design/@splinetool/viewer@<version>/build/spline-viewer.js"
84
+ ></script>
85
+
86
+ <spline-viewer
87
+ url="https://prod.spline.design/<id>/scene.splinecode"
88
+ ></spline-viewer>
89
+ ```
90
+
91
+ ## Attributes
92
+
93
+ This is the complete list. Do not invent others.
94
+
95
+ | Attribute | Values | Default |
96
+ | ------------------- | ------------------------------------------------------------------------------------------ | ------------------------------------------ |
97
+ | `url` | the `.splinecode` URL | — |
98
+ | `width` | pixels, e.g. `400` | — |
99
+ | `height` | pixels, e.g. `400` | — |
100
+ | `background` | any CSS color; overrides the scene's own background | scene's |
101
+ | `renderer` | `auto` \| `webgpu` \| `webgl` (`webgl2` is an alias of `webgl`) | `auto` |
102
+ | `loading` | `auto` \| `lazy` \| `eager` | `auto` (lazy until it enters the viewport) |
103
+ | `loading-anim` | boolean — a simple spinner while loading | `false` |
104
+ | `loading-anim-type` | `spinner-small-dark` \| `spinner-small-light` \| `spinner-big-dark` \| `spinner-big-light` | unset (no animation) |
105
+ | `unloadable` | boolean — unload the scene when it leaves the viewport | `false` |
106
+ | `events-target` | `local` (listen on the canvas) \| `global` (listen on the window) | — |
107
+ | `hint` | boolean — a one-time "drag me" overlay that disappears on first interaction | unset: the scene's own publish setting |
108
+
109
+ ## Engine-specific builds
110
+
111
+ The default `build/spline-viewer.js` contains both engines and auto-selects
112
+ per browser: WebGPU where the browser provides it, WebGL everywhere else.
113
+ Smaller single-engine files exist for scenes exported for one engine:
114
+
115
+ - `build/spline-viewer.js` — both, auto-select (use for `Renderer: Both`)
116
+ - `build/spline-viewer.webgl.js` — WebGL only (~34% smaller)
117
+ - `build/spline-viewer.webgpu.js` — WebGPU only (~20% smaller); browsers
118
+ without WebGPU show a "requires WebGPU" notice, with no fallback
119
+
120
+ On the single-engine builds the `renderer` attribute is ignored (with a
121
+ console warning if it asks for the engine that file does not contain). Only
122
+ switch files when you know the scene's export `Renderer` setting — otherwise
123
+ keep the default.
124
+
125
+ ## Events
126
+
127
+ ```js
128
+ const viewer = document.getElementById('MySplineViewer');
129
+ viewer.addEventListener('load-start', (e) => console.log(e.detail.url));
130
+ ```
131
+
132
+ | Event | Detail | Fires when |
133
+ | ----------------------- | ------------------ | ---------------------------------------- |
134
+ | `load-start` | `{ url: string }` | the viewer starts loading a scene |
135
+ | `load-complete` | `{ url: string }` | the viewer finishes loading a scene |
136
+ | `unload` | — | the current scene is unloaded |
137
+ | `viewport-intersection` | `{ intersection }` | the viewer enters or leaves the viewport |
138
+ | `context-loss` | — | the canvas rendering context is lost |
139
+
140
+ Use `load-start` / `load-complete` to drive your own preloader.
141
+
142
+ ## Performance
143
+
144
+ - **Do not set `loading="eager"` by default.** The default `auto` is lazy —
145
+ it only starts preloading when the element enters the viewport. Use `eager`
146
+ only for an above-the-fold hero.
147
+ - **Add `unloadable`** when several scenes live on one long page, so
148
+ offscreen ones release their resources.
149
+ - **Give the element a size.** Either `width`/`height`, or CSS on the element
150
+ — an unsized custom element can collapse before the scene loads.
151
+ - **Show something during the load.** `loading-anim-type`, or your own
152
+ poster/blurhash image as a child of the element (the export panel emits an
153
+ `<img>` child for exactly this).
154
+ - **Keep one engine per page.** Do not mix `renderer="webgl"` and
155
+ `renderer="webgpu"` viewers.
156
+ - **Pin the CDN version.** An unpinned `@splinetool/viewer` URL can move
157
+ under you.
158
+
159
+ ## Attribution
160
+
161
+ This element renders a **Spline credit badge** (bottom-right, linking to
162
+ spline.design) on its own after the scene loads. It is driven by the scene's
163
+ own publish setting — the badge is shown unless the scene was published with
164
+ its logo setting off — so the embedding code does not control it. **Do not
165
+ write CSS or JS that hides it**, and do not present a hidden-badge embed as
166
+ the recommended snippet.
167
+
168
+ When the scene came from Community, add the creator's credit too, which the
169
+ badge cannot know about:
170
+
171
+ ```html
172
+ <spline-viewer
173
+ url="https://prod.spline.design/<id>/scene.splinecode"
174
+ ></spline-viewer>
175
+ <p class="spline-credit">
176
+ Scene by
177
+ <a
178
+ href="https://app.spline.design/community/file/<uuidCommunityFile>"
179
+ target="_blank"
180
+ rel="noopener"
181
+ >
182
+ @<creator>
183
+ </a>
184
+ </p>
185
+ ```
186
+
187
+ ## What this package does NOT do
188
+
189
+ Agents hallucinate these constantly. None of them exist here:
190
+
191
+ - **No `scene` attribute.** It is `url`. (`scene` is the React component's
192
+ prop — a different package.)
193
+ - **No React component.** React apps use `@splinetool/react-spline`
194
+ (external), or this element inside a `<div>` with the script tag loaded.
195
+ - **No object API.** There is no `findObjectByName` / `emitEvent` /
196
+ `setVariable` on the element. For imperative control over scene objects use
197
+ `@splinetool/runtime`'s `Application` directly.
198
+ - **No 2D Hana support.** `.hanacode` scenes use `<hana-viewer>`.
199
+ - **No three.js scene graph.** That is `@splinetool/loader`.
200
+ - **No authoring or saving.** There is no API here to create, save, publish
201
+ or export a scene.
202
+ - **No URL derivation.** Nothing converts a file id, share link or community
203
+ URL into a `.splinecode` URL.
204
+ - **No badge toggle.** There is no attribute that removes the credit badge.
205
+ - **No plan or entitlement information.** Do not state what any Spline plan
206
+ includes or limits — link to <https://spline.design/pricing>.
207
+
208
+ ## Maintainers
209
+
210
+ - `prepublishOnly` runs `scripts/verify-publish-target.mjs`, which blocks
211
+ accidental npmjs publishes. Do not bypass or alter it.
212
+ - `AGENTS.md` is listed in this package's `files`, so it ships in the tarball
213
+ and on the CDN prefix. Keep it that way.