@splendidlabz/svelte 4.13.0 → 4.15.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/actions/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from '../components/Populate/actions.js'
2
- export * from './resize-observer.js'
3
- export * from './scroll-observer.js'
2
+ export * from './breakpoint-observer.js'
3
+ export * from './portal.js'
4
4
  export * from './sync.svelte.js'
5
5
  export * from './use-actions.js'
@@ -30,7 +30,7 @@
30
30
  scrollObserver,
31
31
  } from '@splendidlabz/utils/dom'
32
32
  import { onMount } from 'svelte'
33
- import NestedList from '../List/NestedListItem.svelte'
33
+ import NestedList from '../List/NestedList.svelte'
34
34
  import { buildStructure, updateAriaCurrent } from './contentlist.js'
35
35
 
36
36
  let {
@@ -105,8 +105,6 @@
105
105
  {:else}
106
106
  {@render label?.()}
107
107
  {/if}
108
- <ul class={listClass}>
109
- <NestedList items={structure} />
110
- </ul>
108
+ <NestedList items={structure} class={listClass} />
111
109
  </div>
112
110
  {/if}
@@ -70,7 +70,7 @@
70
70
 
71
71
  const { newState } = event
72
72
  if (newState === 'open' && onbeforeopen) onbeforeopen(event)
73
- if (newState === 'close' && onbeforeclose) onbeforeclose(event)
73
+ if (newState === 'closed' && onbeforeclose) onbeforeclose(event)
74
74
  if (onbeforetoggle) onbeforetoggle(event)
75
75
  }
76
76
 
@@ -84,7 +84,7 @@
84
84
  }
85
85
 
86
86
  if (newState === 'open' && onopen) onopen(event)
87
- if (newState === 'close' && onclose) onclose(event)
87
+ if (newState === 'closed' && onclose) onclose(event)
88
88
  if (ontoggle) ontoggle(event)
89
89
  }
90
90
 
@@ -41,9 +41,9 @@
41
41
 
42
42
  // Allows trigger to know whether the modal is open or closed
43
43
  function handleToggle(event) {
44
- const { newState, oldState } = event.detail
44
+ const { newState } = event.detail
45
45
  if (newState === 'open') show = true
46
- if (oldState === 'closed') show = false
46
+ if (newState === 'closed') show = false
47
47
  if (ontoggle) ontoggle(event)
48
48
  }
49
49
  </script>
@@ -15,7 +15,8 @@
15
15
 
16
16
  function closeDrawer() {
17
17
  const popover =
18
- document.querySelector(`[#"${target}"]`) || ref.closest('[popover]')
18
+ (target && document.querySelector(`#${target}`)) ||
19
+ ref.closest('[popover]')
19
20
  popover.hidePopover()
20
21
  }
21
22
  </script>
@@ -14,6 +14,7 @@
14
14
  bind:this={elem}
15
15
  class="Button {klass}"
16
16
  {type}
17
+ {href}
17
18
  {...$$restProps}
18
19
  >
19
20
  <slot />
@@ -1,5 +1,5 @@
1
1
  <script>
2
- import { TextInput } from './TextInput.svelte'
2
+ import TextInput from './TextInput.svelte'
3
3
  const { ...rest } = $props()
4
4
  </script>
5
5
 
@@ -7,33 +7,16 @@
7
7
  export let ref
8
8
  export let checked = false
9
9
 
10
- let labels = {
11
- left: undefined,
12
- right: undefined,
13
- }
14
-
15
10
  const dispatch = createEventDispatcher()
16
11
 
17
12
  function change(event) {
18
13
  checked = event.target.checked
19
-
20
- // Revert Aria attributes
21
- labels.left.removeAttribute('aria-hidden')
22
- labels.right.removeAttribute('aria-hidden')
23
-
24
- // Hide labels
25
- if (checked) {
26
- labels.left.setAttribute('aria-hidden', 'true')
27
- } else {
28
- labels.right.setAttribute('aria-hidden', 'true')
29
- }
30
-
31
14
  dispatch('change', { checked })
32
15
  }
33
16
  </script>
34
17
 
35
18
  <label class="Switch {klass}">
36
- <span aria-hidden="true" bind:this={labels.left}>
19
+ <span aria-hidden={checked ? 'true' : undefined}>
37
20
  <slot name="left-label" />
38
21
  </span>
39
22
  <input
@@ -44,7 +27,7 @@
44
27
  bind:this={ref}
45
28
  bind:checked
46
29
  />
47
- <span aria-hidden="true" bind:this={labels.right}>
30
+ <span aria-hidden={checked ? undefined : 'true'}>
48
31
  <slot name="right-label" />
49
32
  </span>
50
33
  </label>
@@ -17,9 +17,18 @@ Props:
17
17
  - liClass (string): Optional CSS class for the `<li>` element.
18
18
  - aClass (string): Optional CSS class for the `<a>` element.
19
19
  - children (Object[]): Optional array of nested items to be rendered as a sublist.
20
+ - class (string): Optional CSS class for the outer `<ul>`.
21
+ - liClass (string): Default class for every `<li>`, overridden per item.
22
+ - aClass (string): Default class for every `<a>`, overridden per item.
20
23
  -->
21
24
  <script>
22
- const { items = [], liClass = '', aClass = '' } = $props()
25
+ const {
26
+ items = [],
27
+ class: klass = '',
28
+ liClass = '',
29
+ aClass = '',
30
+ ...rest
31
+ } = $props()
23
32
 
24
33
  function parseItemProps(item) {
25
34
  const {
@@ -65,4 +74,6 @@ Props:
65
74
  {/if}
66
75
  {/snippet}
67
76
 
68
- {@render nestedItems(items)}
77
+ <ul {...rest} class={klass}>
78
+ {@render nestedItems(items)}
79
+ </ul>
@@ -1,3 +1,3 @@
1
1
  import Lia from './Lia.svelte'
2
- import NestedListItem from './NestedListItem.svelte'
3
- export { Lia, NestedListItem }
2
+ import NestedList from './NestedList.svelte'
3
+ export { Lia, NestedList }
@@ -5,6 +5,5 @@
5
5
  </script>
6
6
 
7
7
  <div class="PerspectiveHover {klass}" use:perspectiveHover>
8
- <h1>Perspective Hover</h1>
9
8
  <slot />
10
9
  </div>
@@ -15,7 +15,9 @@
15
15
  const list = prop.split('.')
16
16
 
17
17
  // If source is provided, draw from source
18
- if (!isEmpty(source)) value = getValueFromSource({ source, list })
18
+ if (!isEmpty(source)) {
19
+ value = conditions[getValueFromSource({ source, list })]
20
+ }
19
21
 
20
22
  // If source is not provided, draw from localStorage, sessionstorage or query parameters (in this order) — in this case client:load is required.
21
23
  if (isEmpty(source)) {
@@ -1,5 +1,5 @@
1
1
  // Bind into <input> elements as the value — that's probably the only use case so far.
2
- import { getValueFromBrowserStorage, getValueFromSource } from './get-value'
2
+ import { getValueFromBrowserStorage, getValueFromSource } from './get-value.js'
3
3
 
4
4
  import { isEmpty } from '@splendidlabz/utils'
5
5
 
@@ -19,7 +19,10 @@ export function conditionalPopulate(node, options) {
19
19
  const list = prop.split('.')
20
20
  let value
21
21
 
22
- if (!isEmpty(source)) value = getValueFromSource({ source, list })
22
+ if (!isEmpty(source)) {
23
+ const tmp = getValueFromSource({ source, list })
24
+ value = conditions[tmp] || conditions.fallback
25
+ }
23
26
  if (isEmpty(source)) {
24
27
  const tmp = getValueFromBrowserStorage(list)
25
28
  value = conditions[tmp] || conditions.fallback
@@ -110,7 +110,7 @@ export function resizer(node, options) {
110
110
  elementToResize.style.height = `${maxHeight}px`
111
111
  break
112
112
  case !canExceedOriginal && newHeight > originalHeight:
113
- elementToResize.style.width = `${originalHeight}px`
113
+ elementToResize.style.height = `${originalHeight}px`
114
114
  break
115
115
  default:
116
116
  elementToResize.style.height = `${newHeight}px`
@@ -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 }
@@ -1,7 +1,7 @@
1
1
  // Simple regex parsing to add/adjust SVG attributes
2
2
  // Written by AI.
3
3
  export function naiveParser(content, options) {
4
- const { class: klass, width, height, attributes = {} } = options
4
+ const { class: klass, width, height, attributes = {}, ...rest } = options
5
5
 
6
6
  // Parse the opening <svg> tag
7
7
  const svgMatch = content.match(/<svg[^>]*>/i)
@@ -79,8 +79,9 @@ export function naiveParser(content, options) {
79
79
  }
80
80
  }
81
81
 
82
- // Add any additional attributes
83
- Object.entries(attributes).forEach(([key, value]) => {
82
+ // Add any additional attributes (rest props like style and role included)
83
+ Object.entries({ ...rest, ...attributes }).forEach(([key, value]) => {
84
+ if (!value) return
84
85
  if (svgTag.includes(`${key}=`)) {
85
86
  svgTag = svgTag.replace(new RegExp(`${key}="[^"]*"`), `${key}="${value}"`)
86
87
  } else {
@@ -96,7 +97,14 @@ export function naiveParser(content, options) {
96
97
  // Likely not needed.
97
98
  // Written by AI.
98
99
  export function domParser(content, options) {
99
- const { className, width, height, attributes = {}, transform } = options
100
+ const {
101
+ class: className,
102
+ width,
103
+ height,
104
+ attributes = {},
105
+ transform,
106
+ ...rest
107
+ } = options
100
108
 
101
109
  // Parse SVG content
102
110
  const parser = new DOMParser()
@@ -118,8 +126,9 @@ export function domParser(content, options) {
118
126
  if (width) svgElement.setAttribute('width', width)
119
127
  if (height) svgElement.setAttribute('height', height)
120
128
 
121
- // Add additional attributes
122
- Object.entries(attributes).forEach(([key, value]) => {
129
+ // Add additional attributes (rest props like style and role included)
130
+ Object.entries({ ...rest, ...attributes }).forEach(([key, value]) => {
131
+ if (!value) return
123
132
  svgElement.setAttribute(key, value)
124
133
  })
125
134
 
@@ -67,7 +67,7 @@
67
67
  <!-- Render children purely for their registration side effect; they emit no DOM -->
68
68
  {@render children?.()}
69
69
 
70
- <div id={tabpanelsId} {...rest} class="tabcordion {klass}">
70
+ <div id={tabcordionId} {...rest} class="tabcordion {klass}">
71
71
  <div class="accordion-stack">
72
72
  {#each items as item, i (i)}
73
73
  <Accordion
@@ -30,7 +30,7 @@
30
30
  <Tab
31
31
  class={tabClass}
32
32
  active={index === activeIndex}
33
- {tabpanelsOptions}
33
+ {...tabOptions}
34
34
  {...tabRest}
35
35
  >
36
36
  {text}
@@ -40,6 +40,6 @@
40
40
 
41
41
  {#if children}
42
42
  <Tabpanels {id} class={tabpanelsClass} {...tabpanelsOptions}>
43
- {children()}
43
+ {@render children()}
44
44
  </Tabpanels>
45
45
  {/if}
@@ -10,7 +10,19 @@
10
10
  timestamp = 0, // alias for start
11
11
  } = $props()
12
12
 
13
- const _id = $derived(id || link?.split('/').pop())
13
+ /**
14
+ * Extracts the video ID from any YouTube URL form
15
+ * (watch?v=, youtu.be, embed, shorts) or returns the value as-is
16
+ * @param {string} url - YouTube URL or bare video ID
17
+ * @returns {string|undefined} Video ID
18
+ */
19
+ function getVideoId(url) {
20
+ if (!url) return undefined
21
+ const match = url.match(/(?:v=|youtu\.be\/|embed\/|shorts\/)([\w-]{11})/)
22
+ return match ? match[1] : url.split('/').pop()
23
+ }
24
+
25
+ const _id = $derived(id || getVideoId(link))
14
26
  const src = $derived(
15
27
  `https://www.youtube.com/embed/${_id}?vq=highres&start=${start || timestamp}&cc_load_policy=1&cc_lang_pref=en`,
16
28
  )
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.15.0",
5
5
  "sideEffects": false,
6
6
  "homepage": "https://splendidlabz.com/docs/svelte",
7
7
  "scripts": {