ridgescape 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 +116 -2
- package/dist/index.cjs +1574 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +991 -0
- package/dist/index.d.ts +991 -0
- package/dist/index.js +1490 -0
- package/dist/index.js.map +1 -0
- package/dist/react.cjs +183 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +45 -0
- package/dist/react.d.ts +45 -0
- package/dist/react.js +157 -0
- package/dist/react.js.map +1 -0
- package/package.json +86 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 SelfStartDev
|
|
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,117 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ridgescape
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Layered landscape backgrounds for the web: ridges fading into the haze, generated from a seed, repeating at any width, with scroll parallax.
|
|
4
|
+
|
|
5
|
+
A layered landscape behind a hero or a footer usually means drawing each layer in a vector tool, stacking SVGs, matching colours by eye and writing scroll code, and then it stretches on wide screens. ridgescape generates the layers from a short description instead, for the element's real size. Every layer repeats seamlessly, so a wider screen shows more landscape rather than wider hills, and colours fade into the haze with depth on their own.
|
|
6
|
+
|
|
7
|
+
**[Docs and playground →](https://ridgescape.selfstartdev.com)**
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install ridgescape
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
- `ridgescape`: the core. No dependencies; runs in Node, the browser, build scripts and edge runtimes. Writes SVG strings and paints canvases.
|
|
14
|
+
- `ridgescape/react`: the `<Ridgescape>` component. React 18 or 19, an optional peer dependency.
|
|
15
|
+
|
|
16
|
+
## React
|
|
17
|
+
|
|
18
|
+
`<Ridgescape>` is a layer, not a wrapper. Put it inside the element it should sit behind, and give that element `ridgescapeParentStyle`:
|
|
19
|
+
|
|
20
|
+
```tsx
|
|
21
|
+
import { ridgescapeParentStyle } from "ridgescape";
|
|
22
|
+
import { Ridgescape } from "ridgescape/react";
|
|
23
|
+
|
|
24
|
+
<section style={{ ...ridgescapeParentStyle, background: "linear-gradient(#3d3466, #f6c49a)" }}>
|
|
25
|
+
<Ridgescape scene={{ seed: "home", palette: "dusk", layers: 5 }} parallax />
|
|
26
|
+
{children}
|
|
27
|
+
</section>
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
`ridgescapeParentStyle` is `{ position: "relative", isolation: "isolate" }`: the layer covers this element and can't slip behind its background. In development, `<Ridgescape>` warns if either is missing. Import it from `ridgescape`, not `ridgescape/react`: a React Server Component importing a plain value from a client module gets an empty reference.
|
|
31
|
+
|
|
32
|
+
The landscape is transparent above the ridges, so the element's background is the sky. Each palette has a sky gradient: `resolve(scene).palette.sky`.
|
|
33
|
+
|
|
34
|
+
| Prop | Default | Meaning |
|
|
35
|
+
|---|---|---|
|
|
36
|
+
| `scene` | | The landscape (below), or a preset: `presets.sierra`. |
|
|
37
|
+
| `renderer` | `"svg"` | `"canvas"` draws in the browser instead. |
|
|
38
|
+
| `parallax` | `false` | `true`, or `{ strength }` from 0 to 1 (default 0.3). |
|
|
39
|
+
| `attach` | `"scroll"` | `"fixed"` pins the layer to the viewport (no parallax). |
|
|
40
|
+
| `fullBleed` | `false` | Break out of the parent's width to the full viewport width. |
|
|
41
|
+
| `initialSize` | `{ width: 1440, height: 900 }` | Size rendered on the server and before measuring. |
|
|
42
|
+
| `reveal` | `"fade"` | `"none"` shows the server render without waiting for the measurement. |
|
|
43
|
+
| `className`, `style` | | On the layer. |
|
|
44
|
+
|
|
45
|
+
## A scene
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
{
|
|
49
|
+
seed: "home", // the same seed always draws the same landscape
|
|
50
|
+
palette: "dusk", // dusk, dawn, alpine, forest, desert, fog, night, mono, or { near, far, haze, sky, mist }
|
|
51
|
+
layers: 5, // a count, or layers back to front
|
|
52
|
+
height: "45%", // the band the landscape fills, from the bottom
|
|
53
|
+
haze: { strength: 0.5, curve: 1.2 },
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Lengths are px as a number or a percentage as a string (of the element's height for vertical lengths, its width for horizontal ones).
|
|
58
|
+
|
|
59
|
+
Each layer has a depth from 1 (horizon) to 0 (front), spread evenly by default, and depth sets its other defaults: further layers sit higher, are smoother, fade more into the haze and lag more in parallax. Set any field to override it:
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
layers: [
|
|
63
|
+
{ profile: "peaks", anchors: [{ at: "70%", height: "40%", width: 500 }] },
|
|
64
|
+
{ profile: "rolling", mist: 0.4 },
|
|
65
|
+
{ color: "var(--hills)" },
|
|
66
|
+
]
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
| Layer field | Meaning |
|
|
70
|
+
|---|---|
|
|
71
|
+
| `profile` | `"rolling"` (default), `"peaks"`, `"mesa"` or `"dunes"`. |
|
|
72
|
+
| `depth` | 0 (front) to 1 (horizon). |
|
|
73
|
+
| `baseline` | Height of the lowest valleys, from the bottom. |
|
|
74
|
+
| `amplitude` | How far the highest crest rises above the baseline. |
|
|
75
|
+
| `roughness` | 0 smooth to 1 craggy. |
|
|
76
|
+
| `wavelength` | Typical hill width, px. |
|
|
77
|
+
| `period` | The layer repeats every this many px. |
|
|
78
|
+
| `color` | Instead of the palette and haze; any CSS colour. |
|
|
79
|
+
| `mist` | 0–1: fade toward the haze colour in the valleys. |
|
|
80
|
+
| `anchors` | Peaks, dips or flat stretches at chosen positions: `{ at, kind?, height?, width? }`. |
|
|
81
|
+
| `trees` | A tree line along the crest: `true`, or `{ kind, height, density, cover, variation, color, seed }`. `kind` is a group (conifer, deciduous, mixed), a shape (spruce, fir, pine, cypress, maple, oak, poplar), a list, or shapes with weights. |
|
|
82
|
+
| `lakes` | Water that reflects what's behind it: `[{ at, width, level, reflection, ripples, color }]`; `reflection` and `ripples` are on/off. A lake that covers the element (`at: "50%", width: "100%"`) is water all the way across. |
|
|
83
|
+
| `seed` | Instead of one derived from the scene's seed and the layer's index. |
|
|
84
|
+
|
|
85
|
+
Ten presets are in `presets` (`sierra`, `meadow`, `misty`, `mesa`, `glacier`, `nightfall`, `pinewood`, and `summer`, `starlight` and `lakeside`, which draw their own sky); spread one and change what you like.
|
|
86
|
+
|
|
87
|
+
## Sky and clouds
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
{
|
|
91
|
+
sky: { sun: { at: ["72%", "28%"], radius: 56, glow: 0.6 }, stars: true }, // or moon: { crescent: 0.5 }; sky: true for just the gradient
|
|
92
|
+
clouds: { style: "puffy", bands: 2, cover: 0.4, top: "14%", bottom: "40%", size: 240 }, // or style: "streaks"
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
The sky is the palette's gradient (or your own, or none), with an optional sun or moon with a soft glow, and stars. Clouds come in rows at different depths and repeat horizontally like the ground. With parallax, the gradient stays put and everything else drifts by depth.
|
|
97
|
+
|
|
98
|
+
## SVG and canvas, without React
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
import { drawToCanvas, render, toSvg } from "ridgescape";
|
|
102
|
+
|
|
103
|
+
const svg = toSvg({ seed: 1 }, { width: 1440, height: 900 });
|
|
104
|
+
|
|
105
|
+
const rendered = render({ seed: 1 }, { width: 1440, height: 900 });
|
|
106
|
+
drawToCanvas(canvas.getContext("2d"), rendered, { pixelRatio: 2 });
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
`toSvg()` writes one path per layer, rounded to two decimals: the same input always gives the same bytes. `drawToCanvas()` paints the same paths. `attachParallax(element, { strength })` moves the elements inside `element` that carry a `data-depth` attribute as the page scrolls. It reads them once, so attach again after replacing them. If you build your own elements from `render()`, draw each reflection layer (one with `mirror`) as an element with `data-mirror="{mirror.depth}"` inside one with `data-depth="{depth}"` and `clip-path: clipStyle(mirror.water)`; `<Ridgescape>` does this for you. In SVG, reflections draw the shapes they mirror with `<use>`, so keep all the layers in one document.
|
|
110
|
+
|
|
111
|
+
## Stability
|
|
112
|
+
|
|
113
|
+
Output is a pure function of the scene, the element size and the package version. From 1.0, any change to generated output (presets included) is a major release; before 1.0, a minor version may change it and a patch never does.
|
|
114
|
+
|
|
115
|
+
## License
|
|
116
|
+
|
|
117
|
+
MIT
|