@createthebox/scroll-scene 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +80 -2
- package/dist/scroll-scene.d.ts +113 -0
- package/dist/scroll-scene.js +16739 -0
- package/package.json +42 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Create the Box, LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,81 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @createthebox/scroll-scene
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The `<scroll-scene>` web component that plays scroll-scene exports from
|
|
4
|
+
[Create the Box STUDIO](https://studio.createthebox.com): a 3D scene whose camera moves as the page scrolls.
|
|
5
|
+
three.js is bundled in, so there is nothing else to install.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @createthebox/scroll-scene
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Load it once in the browser. It registers the `<scroll-scene>` element:
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
import '@createthebox/scroll-scene'
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
In Next.js or another server-rendering framework, load it on the client only:
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
'use client'
|
|
23
|
+
import { useEffect } from 'react'
|
|
24
|
+
|
|
25
|
+
export function ScrollSceneRuntime() {
|
|
26
|
+
useEffect(() => { import('@createthebox/scroll-scene') }, [])
|
|
27
|
+
return null
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Without a bundler, use a CDN:
|
|
32
|
+
|
|
33
|
+
```html
|
|
34
|
+
<script type="module" src="https://cdn.jsdelivr.net/npm/@createthebox/scroll-scene@0.1.0/dist/scroll-scene.js"></script>
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Use
|
|
38
|
+
|
|
39
|
+
Put the exported folder (`timeline.json`, `scene.glb`, `poster.webp`, `shots/`) on your site and point `src` at it:
|
|
40
|
+
|
|
41
|
+
```html
|
|
42
|
+
<div data-scroll-track style="height: 400vh">
|
|
43
|
+
<scroll-scene src="/scroll-scene/" pin></scroll-scene>
|
|
44
|
+
<section data-stop="features">Text the camera pauses on</section>
|
|
45
|
+
</div>
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Files hosted separately (a CMS, a CDN) go in `files`, a map of export path → URL:
|
|
49
|
+
|
|
50
|
+
```js
|
|
51
|
+
document.querySelector('scroll-scene').files = {
|
|
52
|
+
'timeline.json': 'https://cdn.example.com/abc.json',
|
|
53
|
+
'scene.glb': 'https://cdn.example.com/def.glb',
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Attributes
|
|
58
|
+
|
|
59
|
+
| Attribute | What it does |
|
|
60
|
+
| --- | --- |
|
|
61
|
+
| `src` | Folder with the export (default `./`). Changing it reloads the scene. |
|
|
62
|
+
| `files` | JSON map of export path → URL, the same as the `files` property. |
|
|
63
|
+
| `pin` | Sticky and full-viewport. Put it first inside a tall `[data-scroll-track]` element. |
|
|
64
|
+
| `track` | CSS selector of the element whose scroll drives the scene (default: the closest `[data-scroll-track]`). |
|
|
65
|
+
| `driven` | Ignore page scroll; set `progress` yourself (GSAP ScrollTrigger, Lenis, a carousel). |
|
|
66
|
+
| `reduced-motion` | Always show the stills. Visitors who prefer reduced motion get them anyway. |
|
|
67
|
+
|
|
68
|
+
### Content on shots and web points
|
|
69
|
+
|
|
70
|
+
- `data-stop="<slug>"`: the camera parks on that shot while the element crosses the middle of the screen. The element gets `--stop-t` (−1 → 0 moving in, 0 → 1 holding, 1 → 2 moving on) for CSS animation.
|
|
71
|
+
- `data-point="<slug>"`: the element follows a web point on screen through `--px`, `--py`, `--pz` and `--p-on`.
|
|
72
|
+
|
|
73
|
+
### API
|
|
74
|
+
|
|
75
|
+
`ready` (a promise), `progress`, `shots`, `files`, `goTo(shot)`, `refresh()`, `points`, `pointPosition(slug)`,
|
|
76
|
+
and the `ready` / `error` events. TypeScript types ship with the package, including the JSX tag for React.
|
|
77
|
+
|
|
78
|
+
## Versions
|
|
79
|
+
|
|
80
|
+
The player reads the `timeline.json` that STUDIO exports. Use the package version that matches the STUDIO
|
|
81
|
+
release you exported from, or newer: newer players keep reading older exports.
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for the <scroll-scene> web component (scroll-scene.js).
|
|
3
|
+
* Copy this file into your project (or reference it) for autocompletion:
|
|
4
|
+
* /// <reference path="./scroll-scene/scroll-scene.d.ts" />
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export interface ScrollSceneShot {
|
|
8
|
+
/** Position in scroll order, from 0. */
|
|
9
|
+
index: number
|
|
10
|
+
/** Stable id of the shot in timeline.json (doc.keys[].id). */
|
|
11
|
+
id: string
|
|
12
|
+
/** Name of the camera the shot looks through. */
|
|
13
|
+
camera: string
|
|
14
|
+
/** data-shot slug of the page section the shot is tied to, or null. */
|
|
15
|
+
section: string | null
|
|
16
|
+
/** data-stop slug for content on this shot (timeline.json "stops"), or null in older exports. */
|
|
17
|
+
stop: string | null
|
|
18
|
+
/** Where the shot lands, 0..1 of the scroll track (after measuring the page). Same as start. */
|
|
19
|
+
at: number
|
|
20
|
+
/** The pause on this shot, 0..1 of the track, measured from the page's data-stop element when there is one. */
|
|
21
|
+
start: number
|
|
22
|
+
end: number
|
|
23
|
+
/** end − start (0 when the shot doesn't pause). */
|
|
24
|
+
hold: number
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface ScrollSceneEventMap {
|
|
28
|
+
/** The 3D scene (or the reduced-motion stills) is showing. */
|
|
29
|
+
ready: CustomEvent<{ mode: '3d' | 'stills' }>
|
|
30
|
+
/** timeline.json or scene.glb failed to load. The poster or stills stay up. */
|
|
31
|
+
error: CustomEvent<{ message: string; cause?: unknown }>
|
|
32
|
+
/** The shot nearest to the current progress changed. */
|
|
33
|
+
shotchange: CustomEvent<{ index: number; shot: ScrollSceneShot; section: string | null }>
|
|
34
|
+
/** Progress shown on screen (eased), at most once per animation frame. */
|
|
35
|
+
progress: CustomEvent<{ progress: number }>
|
|
36
|
+
/** The camera arrived at a pause: its data-stop content is in the middle of the screen. */
|
|
37
|
+
stopenter: CustomEvent<{ index: number; shot: ScrollSceneShot; stop: string | null }>
|
|
38
|
+
/** The camera left a pause. */
|
|
39
|
+
stopleave: CustomEvent<{ index: number; shot: ScrollSceneShot; stop: string | null }>
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export declare class ScrollSceneElement extends HTMLElement {
|
|
43
|
+
/** Resolves once the scene (or stills) is showing; rejects if loading fails. */
|
|
44
|
+
readonly ready: Promise<void>
|
|
45
|
+
/** Scroll progress 0..1. Set it only when the element has the `driven` attribute. */
|
|
46
|
+
progress: number
|
|
47
|
+
/** The shots in scroll order, with timing measured from the page. */
|
|
48
|
+
readonly shots: ScrollSceneShot[]
|
|
49
|
+
/**
|
|
50
|
+
* Load each exported file from its own URL instead of the src folder (e.g. assets in a CMS).
|
|
51
|
+
* Keys are paths inside the export: 'timeline.json', 'scene.glb', 'poster.webp', 'shots/01-hero.webp'…
|
|
52
|
+
* Paths not in the map load from src. Setting it reloads the scene.
|
|
53
|
+
*/
|
|
54
|
+
files: Record<string, string> | string | null
|
|
55
|
+
/** Scroll the page to a shot: its index, its section's data-shot slug, its data-stop slug, or its camera name. */
|
|
56
|
+
goTo(shot: number | string, opts?: { behavior?: ScrollBehavior }): void
|
|
57
|
+
/** Re-measure page sections after a layout change that doesn't resize the track. */
|
|
58
|
+
refresh(): void
|
|
59
|
+
/** Web points (STUDIO: an object's Web point): spots page content can follow. */
|
|
60
|
+
readonly points: { name: string; slug: string }[]
|
|
61
|
+
/** Where a web point is now, in this element's pixels; visible is false behind the camera or out of frame. */
|
|
62
|
+
pointPosition(slug: string): { x: number; y: number; visible: boolean } | null
|
|
63
|
+
|
|
64
|
+
addEventListener<K extends keyof ScrollSceneEventMap>(type: K, listener: (this: ScrollSceneElement, ev: ScrollSceneEventMap[K]) => void, options?: boolean | AddEventListenerOptions): void
|
|
65
|
+
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void
|
|
66
|
+
removeEventListener<K extends keyof ScrollSceneEventMap>(type: K, listener: (this: ScrollSceneElement, ev: ScrollSceneEventMap[K]) => void, options?: boolean | EventListenerOptions): void
|
|
67
|
+
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Attributes:
|
|
72
|
+
* src folder with timeline.json, scene.glb, poster (default "./"); changing it reloads
|
|
73
|
+
* files JSON object of export path → URL, the same as the `files` property
|
|
74
|
+
* pin sticky, full-viewport (put it first inside a tall [data-scroll-track] element)
|
|
75
|
+
* track CSS selector of the element whose scroll drives the scene (default: closest [data-scroll-track])
|
|
76
|
+
* driven ignore page scroll; you set `progress` (GSAP ScrollTrigger, Lenis, a carousel…)
|
|
77
|
+
* reduced-motion always show stills
|
|
78
|
+
*
|
|
79
|
+
* Content on shots: put the content for a shot in an element with data-stop="<slug>" (every shot is in
|
|
80
|
+
* timeline.json "stops") inside the track. The camera parks on that shot while the element crosses the middle of
|
|
81
|
+
* the screen, so taller content means a longer pause, and the rest of the timeline stretches to fit.
|
|
82
|
+
* Each data-stop element also gets --stop-t: -1 → 0 while the camera moves in, 0 → 1 while it holds, 1 → 2 while
|
|
83
|
+
* it moves on, for animating the content in step with the camera from CSS; and data-stop-on while that is
|
|
84
|
+
* between -1 and 2. Once stops are measured the track gets data-stops-live: content can then leave the flow
|
|
85
|
+
* (e.g. position: fixed, held on screen and animated by --stop-t) while its data-stop element keeps the pause's
|
|
86
|
+
* length.
|
|
87
|
+
*
|
|
88
|
+
* Web points: an element with data-point="<slug>" (timeline.json "points") inside the track follows that point on
|
|
89
|
+
* screen. It gets --px / --py (viewport px: use position: fixed; left: var(--px); top: var(--py)), --pz (depth,
|
|
90
|
+
* 0 near … 1 far), --p-on (1 while the point is in front of the camera and in frame) and data-pinned once placed.
|
|
91
|
+
*/
|
|
92
|
+
declare global {
|
|
93
|
+
interface HTMLElementTagNameMap {
|
|
94
|
+
'scroll-scene': ScrollSceneElement
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** For JSX (React / Next.js): `<scroll-scene src="/scroll-scene/" pin />` */
|
|
99
|
+
declare module 'react' {
|
|
100
|
+
namespace JSX {
|
|
101
|
+
interface IntrinsicElements {
|
|
102
|
+
'scroll-scene': React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement> & {
|
|
103
|
+
src?: string
|
|
104
|
+
/** JSON string of export path → URL. */
|
|
105
|
+
files?: string
|
|
106
|
+
pin?: boolean | ''
|
|
107
|
+
track?: string
|
|
108
|
+
driven?: boolean | ''
|
|
109
|
+
'reduced-motion'?: boolean | ''
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|