@splendidlabz/svelte 4.14.0 → 4.15.2

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.md ADDED
@@ -0,0 +1,95 @@
1
+ Copyright (c) 2024-present Splendid Labz Pte. Ltd.
2
+
3
+ Elastic License 2.0
4
+
5
+ URL: https://www.elastic.co/licensing/elastic-license
6
+
7
+ ## Acceptance
8
+
9
+ By using the software, you agree to all of the terms and conditions below.
10
+
11
+ ## Copyright License
12
+
13
+ The licensor grants you a non-exclusive, royalty-free, worldwide,
14
+ non-sublicensable, non-transferable license to use, copy, distribute, make
15
+ available, and prepare derivative works of the software, in each case subject to
16
+ the limitations and conditions below.
17
+
18
+ ## Limitations
19
+
20
+ You may not provide the software to third parties as a hosted or managed
21
+ service, where the service provides users with access to any substantial set of
22
+ the features or functionality of the software.
23
+
24
+ You may not move, change, disable, or circumvent the license key functionality
25
+ in the software, and you may not remove or obscure any functionality in the
26
+ software that is protected by the license key.
27
+
28
+ You may not alter, remove, or obscure any licensing, copyright, or other notices
29
+ of the licensor in the software. Any use of the licensor’s trademarks is subject
30
+ to applicable law.
31
+
32
+ ## Patents
33
+
34
+ The licensor grants you a license, under any patent claims the licensor can
35
+ license, or becomes able to license, to make, have made, use, sell, offer for
36
+ sale, import and have imported the software, in each case subject to the
37
+ limitations and conditions in this license. This license does not cover any
38
+ patent claims that you cause to be infringed by modifications or additions to
39
+ the software. If you or your company make any written claim that the software
40
+ infringes or contributes to infringement of any patent, your patent license for
41
+ the software granted under these terms ends immediately. If your company makes
42
+ such a claim, your patent license ends immediately for work on behalf of your
43
+ company.
44
+
45
+ ## Notices
46
+
47
+ You must ensure that anyone who gets a copy of any part of the software from you
48
+ also gets a copy of these terms.
49
+
50
+ If you modify the software, you must include in any modified copies of the
51
+ software prominent notices stating that you have modified the software.
52
+
53
+ ## No Other Rights
54
+
55
+ These terms do not imply any licenses other than those expressly granted in
56
+ these terms.
57
+
58
+ ## Termination
59
+
60
+ If you use the software in violation of these terms, such use is not licensed,
61
+ and your licenses will automatically terminate. If the licensor provides you
62
+ with a notice of your violation, and you cease all violation of this license no
63
+ later than 30 days after you receive that notice, your licenses will be
64
+ reinstated retroactively. However, if you violate these terms after such
65
+ reinstatement, any additional violation of these terms will cause your licenses
66
+ to terminate automatically and permanently.
67
+
68
+ ## No Liability
69
+
70
+ _As far as the law allows, the software comes as is, without any warranty or
71
+ condition, and the licensor will not be liable to you for any damages arising
72
+ out of these terms or the use or nature of the software, under any kind of
73
+ legal claim._
74
+
75
+ ## Definitions
76
+
77
+ The **licensor** is the entity offering these terms, and the **software** is the
78
+ software the licensor makes available under these terms, including any portion
79
+ of it.
80
+
81
+ **you** refers to the individual or entity agreeing to these terms.
82
+
83
+ **your company** is any legal entity, sole proprietorship, or other kind of
84
+ organization that you work for, plus all organizations that have control over,
85
+ are under the control of, or are under common control with that
86
+ organization. **control** means ownership of substantially all the assets of an
87
+ entity, or the power to direct its management and policies by vote, contract, or
88
+ otherwise. Control can be direct or indirect.
89
+
90
+ **your licenses** are all the licenses granted to you for the software under
91
+ these terms.
92
+
93
+ **use** means anything you do with the software requiring one of your licenses.
94
+
95
+ **trademark** means trademarks, service marks, and similar rights.
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 />
@@ -9,4 +9,11 @@
9
9
  } = $props()
10
10
  </script>
11
11
 
12
- <TextInput {...rest} {name} class="form-field-helper {klass}" bind:value />
12
+ <!-- `autocomplete="off"` keeps the browser from filling a field named after a real one, which would reject a real person as a bot. -->
13
+ <TextInput
14
+ {...rest}
15
+ {name}
16
+ class="form-field-helper {klass}"
17
+ autocomplete="off"
18
+ bind:value
19
+ />
@@ -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`
@@ -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,8 @@
1
1
  {
2
2
  "name": "@splendidlabz/svelte",
3
3
  "type": "module",
4
- "version": "4.14.0",
4
+ "version": "4.15.2",
5
+ "license": "Elastic-2.0",
5
6
  "sideEffects": false,
6
7
  "homepage": "https://splendidlabz.com/docs/svelte",
7
8
  "scripts": {
@@ -37,7 +38,7 @@
37
38
  "autosuggest-highlight": "^3.3.4"
38
39
  },
39
40
  "devDependencies": {
40
- "@splendidlabz/eslint-config": "2.1.6",
41
+ "@splendidlabz/eslint-config": "2.2.0",
41
42
  "@sveltejs/vite-plugin-svelte": "^7.0.0",
42
43
  "happy-dom": "^20.9.0",
43
44
  "svelte": "^5.55.4",