@splendidlabz/svelte 4.13.0 → 4.14.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.
@@ -0,0 +1,102 @@
1
+ <script>
2
+ // This is the Svelte twin of packages/astro/components/SVG/Displace.astro.
3
+ // Same component, same props, same output — one for each framework. Keep them in sync.
4
+
5
+ import { displaceSettings } from '@splendidlabz/utils'
6
+
7
+ let {
8
+ class: klass = '',
9
+ preset = 'wet-ink',
10
+ type,
11
+ frequency,
12
+ octaves,
13
+ scale,
14
+ seed,
15
+ animate = false,
16
+ duration,
17
+ margin = 30,
18
+ children,
19
+ ...rest
20
+ } = $props()
21
+
22
+ // Warps its children by reading a noise field as a per-pixel x/y offset.
23
+ // Unlike Noise, the noise is never drawn — only the displacement it produces.
24
+ //
25
+ // preset — supplies defaults for everything below.
26
+ // wet-ink, letterpress, heat-haze, bad-tape, shred
27
+ //
28
+ // frequency — wavelength of the distortion, roughly (1 / frequency) px.
29
+ // Pass [x, y] for directional distortion.
30
+ //
31
+ // scale — how far each pixel moves. Keep it under a quarter of the
32
+ // wavelength to warp rather than shred.
33
+ //
34
+ // animate — emits SMIL, so it runs with no JS. Only does anything on
35
+ // presets carrying animateTo.
36
+ //
37
+ // margin — filter region expansion in %. Too low and displaced pixels clip.
38
+
39
+ // Displacement has to hit real DOM, so unlike Noise it can't inline itself
40
+ // as a data URI — every instance needs its own filter id in the document.
41
+ const uid = $props.id()
42
+ const id = `displace-${uid}`
43
+
44
+ const fx = $derived(
45
+ displaceSettings({ preset, type, frequency, octaves, scale, seed, duration }),
46
+ )
47
+
48
+ const offset = $derived(-margin)
49
+ const size = $derived(100 + margin * 2)
50
+ </script>
51
+
52
+ <span style:filter={`url(#${id})`} class="displace {klass}" {...rest}>
53
+ {@render children?.()}
54
+ </span>
55
+
56
+ <svg class="displace-defs" aria-hidden="true" focusable="false">
57
+ <filter
58
+ {id}
59
+ color-interpolation-filters="sRGB"
60
+ height="{size}%"
61
+ width="{size}%"
62
+ x="{offset}%"
63
+ y="{offset}%"
64
+ >
65
+ <feTurbulence
66
+ baseFrequency={fx.frequency}
67
+ numOctaves={fx.octaves}
68
+ result="noise"
69
+ seed={fx.seed}
70
+ type={fx.type}
71
+ >
72
+ {#if animate && fx.animateTo}
73
+ <animate
74
+ attributeName="baseFrequency"
75
+ dur="{fx.duration}s"
76
+ repeatCount="indefinite"
77
+ values="{fx.frequency};{fx.animateTo};{fx.frequency}"
78
+ />
79
+ {/if}
80
+ </feTurbulence>
81
+ <feDisplacementMap
82
+ in="SourceGraphic"
83
+ in2="noise"
84
+ scale={fx.scale}
85
+ xChannelSelector="R"
86
+ yChannelSelector="G"
87
+ />
88
+ </filter>
89
+ </svg>
90
+
91
+ <style>
92
+ .displace {
93
+ display: inline-block;
94
+ }
95
+
96
+ .displace-defs {
97
+ position: absolute;
98
+ width: 0;
99
+ height: 0;
100
+ overflow: hidden;
101
+ }
102
+ </style>
@@ -1,37 +1,33 @@
1
1
  <script>
2
+ // This is the Svelte twin of packages/astro/components/SVG/Noise.astro.
3
+ // Same component, same props, same output — one for each framework. Keep them in sync.
4
+
5
+ import { noiseColorMatrix } from '@splendidlabz/utils'
6
+
2
7
  let {
3
8
  class: klass = '',
4
9
  frequency = 0.9,
5
- octaves = 2,
6
- alpha = 0.6,
7
- opacity = 0.18,
10
+ strength = 0.1,
8
11
  blend = 'overlay',
9
- seed,
12
+ color = 'rainbow',
10
13
  } = $props()
11
14
 
12
15
  // frequency — how zoomed in the noise is.
13
16
  // low (0.01–0.1): large blobs, clouds, smoke
14
17
  // high (0.5–1): fine grain, film noise, static
15
- //
16
- // octaves — layers of noise stacked on top of each other.
17
- // Each octave adds finer detail at double the frequency (costs render perf).
18
- // low (1): smooth, soft, single frequency
19
- // high (4–8): complex, detailed texture
20
- //
21
- // Combinations:
22
- // frequency: 0.05, octaves: 6 → realistic cloudy smoke
23
- // frequency: 0.9, octaves: 2 → subtle film grain overlay (default)
24
- // frequency: 0.3, octaves: 4 → mid-range crumpled paper texture
25
-
26
- // seed — omit to let the browser pick. Pass a number to lock noise across
27
- // renders or to get a different pattern per instance.
28
- const seedAttr = $derived(seed != null ? ` seed='${seed}'` : '')
18
+
19
+ // color — 'rainbow' (default) for coloured static. A preset name
20
+ // ('black', 'sepia', 'synthwave') or any hex for a single-colour tint.
21
+
22
+ // strength — 0–1 fades the grain; above 1 it saturates into denser grain.
23
+ // Need the whole overlay dimmer? Add CSS opacity via class.
24
+ const matrix = $derived(noiseColorMatrix(color, strength))
29
25
 
30
26
  const svg = $derived(
31
27
  "<svg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'>" +
32
28
  "<filter id='n'>" +
33
- `<feTurbulence type='fractalNoise' baseFrequency='${frequency}' numOctaves='${octaves}' stitchTiles='stitch'${seedAttr}/>` +
34
- `<feColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ${alpha} 0'/>` +
29
+ `<feTurbulence type='fractalNoise' baseFrequency='${frequency}' numOctaves='2' stitchTiles='stitch'/>` +
30
+ `<feColorMatrix values='${matrix}'/>` +
35
31
  '</filter>' +
36
32
  "<rect width='100%' height='100%' filter='url(%23n)'/>" +
37
33
  '</svg>',
@@ -42,7 +38,6 @@
42
38
 
43
39
  <div
44
40
  style:background-image={bg}
45
- style:opacity
46
41
  style:mix-blend-mode={blend}
47
42
  class="Noise {klass}"
48
43
  aria-hidden="true"
@@ -1,4 +1,5 @@
1
1
  import SVG from './SVG.svelte'
2
2
  import SVGGradient from './SVGGradient.svelte'
3
3
  import Noise from './Noise.svelte'
4
- export { SVG, SVGGradient, Noise }
4
+ import Displace from './Displace.svelte'
5
+ export { SVG, SVGGradient, Noise, Displace }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@splendidlabz/svelte",
3
3
  "type": "module",
4
- "version": "4.13.0",
4
+ "version": "4.14.0",
5
5
  "sideEffects": false,
6
6
  "homepage": "https://splendidlabz.com/docs/svelte",
7
7
  "scripts": {