@splendidlabz/svelte 4.8.3 → 4.8.5

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.
Files changed (51) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/components/Accordion/Accordion.svelte +17 -21
  3. package/components/Breadcrumbs/Breadcrumbs.svelte +8 -19
  4. package/components/Breadcrumbs/Crumb.svelte +19 -14
  5. package/components/BrowserFrame/BrowserFrame.svelte +8 -16
  6. package/components/Codepen/Codepen.svelte +2 -1
  7. package/components/ContentList/ContentList.svelte +6 -7
  8. package/components/Copyright.svelte +6 -7
  9. package/components/Disclosure/Disclosure/DisclosureContent.svelte +21 -21
  10. package/components/Disclosure/Disclosure/DisclosureTrigger.svelte +23 -22
  11. package/components/Disclosure/Drawer/DrawerCloseButton.svelte +2 -2
  12. package/components/Disclosure/Drawer/DrawerContent.svelte +20 -18
  13. package/components/Disclosure/Modal/ModalCloseButton.svelte +3 -6
  14. package/components/Disclosure/Modal/ModalContent.svelte +18 -19
  15. package/components/Disclosure/Modal/ModalTrigger.svelte +9 -11
  16. package/components/Disclosure/Popover/PopoverCloseButton.svelte +4 -5
  17. package/components/Disclosure/Popover/PopoverContent.svelte +12 -23
  18. package/components/Disclosure/Popover/PopoverTrigger.svelte +9 -13
  19. package/components/FancyList/FancyList.svelte +3 -6
  20. package/components/Form/ButtonGroup.svelte +30 -22
  21. package/components/Form/Checkbox.svelte +23 -18
  22. package/components/Form/Checkboxes.svelte +29 -27
  23. package/components/Form/Form.svelte +3 -6
  24. package/components/Form/Radio.svelte +11 -14
  25. package/components/Form/Radios.svelte +27 -27
  26. package/components/Form/Select.svelte +48 -60
  27. package/components/Form/TextInput.svelte +13 -15
  28. package/components/Form/Textarea.svelte +13 -20
  29. package/components/Image/Figure.svelte +13 -0
  30. package/components/Image/Image-old.svelte +58 -0
  31. package/components/Image/Image.svelte +41 -0
  32. package/components/Image/Picture.svelte +71 -0
  33. package/components/Image/image.js +61 -0
  34. package/components/LocalStorage/LocalStoragePush.svelte +1 -2
  35. package/components/LocalStorage/LocalStorageRemove.svelte +1 -2
  36. package/components/Markdown/Markdown.svelte +1 -1
  37. package/components/Resizer/Resizer.svelte +24 -23
  38. package/components/SVG/SVG.svelte +23 -21
  39. package/components/SVG/SVGGradient.svelte +7 -5
  40. package/components/Scrambler/Scrambler.svelte +1 -2
  41. package/components/Status.svelte +1 -3
  42. package/components/Tabs/Tablist.svelte +7 -8
  43. package/components/Tabs/Tabpanels.svelte +5 -1
  44. package/components/Tabs/Tabs.svelte +2 -3
  45. package/components/Youtube.svelte +7 -10
  46. package/package.json +2 -1
  47. package/utils/index.js +1 -0
  48. package/utils/init.js +3 -0
  49. package/utils/loadscripts.js +2 -0
  50. package/vitest.config.js +8 -0
  51. package/components/Image.svelte +0 -24
@@ -26,13 +26,14 @@
26
26
  import { toStyleString } from '@splendidlabz/utils'
27
27
  import { onMount } from 'svelte'
28
28
  import { domParser, naiveParser } from './parser.js'
29
+ import { init } from '../../utils'
29
30
  /** @type {SVGProps} */
30
31
  const {
31
32
  icon,
32
33
  style,
33
34
  parser = 'naive', // or DOM
34
35
  children, // Just to remove children slots
35
- ...p
36
+ ...rest
36
37
  } = $props()
37
38
 
38
39
  const files = {
@@ -41,33 +42,34 @@
41
42
  }
42
43
 
43
44
  // Find the SVG
44
- if (!icon) throw new Error('icon property is required')
45
-
46
- const file = Object.keys(files).find(file => {
47
- const basename = file.split('/').pop()
48
- return basename === `${icon}.svg`
45
+ const file = init(() => {
46
+ if (!icon) throw new Error('icon property is required')
47
+ const found = Object.keys(files).find(f => f.split('/').pop() === `${icon}.svg`)
48
+ if (!found) throw new Error(`${icon}.svg not found`)
49
+ return found
49
50
  })
50
51
 
51
- if (!file) {
52
- throw new Error(`${icon}.svg not found`)
53
- }
54
-
55
52
  const content = files[file].default
56
- const svgProps = {
57
- role: 'img',
58
- xmlns: 'http://www.w3.org/2000/svg',
59
- style: toStyleString(style),
60
- ...p,
53
+
54
+ function buildSvgProps() {
55
+ return {
56
+ role: 'img',
57
+ xmlns: 'http://www.w3.org/2000/svg',
58
+ style: toStyleString(style),
59
+ ...rest,
60
+ }
61
61
  }
62
62
 
63
63
  let svg = $state(null)
64
64
 
65
- if (parser === 'naive') svg = naiveParser(content, svgProps)
66
- if (parser === 'dom') {
67
- onMount(_ => {
68
- svg = domParser(content, svgProps)
69
- })
70
- }
65
+ init(() => {
66
+ if (parser === 'naive') svg = naiveParser(content, buildSvgProps())
67
+ if (parser === 'dom') {
68
+ onMount(_ => {
69
+ svg = domParser(content, buildSvgProps())
70
+ })
71
+ }
72
+ })
71
73
  </script>
72
74
 
73
75
  <!--
@@ -5,11 +5,13 @@
5
5
  stops = 2, // Or an array with the actual stop percentages
6
6
  } = $props()
7
7
 
8
- const _stops = (Array.isArray(stops) ? stops : Array(stops).fill({})).map(
9
- (stop, index) => ({
10
- offset: stop.offset || `${(index * 100) / (stops - 1)}%`,
11
- 'stop-color': stop.color || `var(--gradient-stop-${index + 1})`,
12
- }),
8
+ const _stops = $derived(
9
+ (Array.isArray(stops) ? stops : Array(stops).fill({})).map(
10
+ (stop, index) => ({
11
+ offset: stop.offset || `${(index * 100) / (stops - 1)}%`,
12
+ 'stop-color': stop.color || `var(--gradient-stop-${index + 1})`,
13
+ }),
14
+ ),
13
15
  )
14
16
  </script>
15
17
 
@@ -2,8 +2,7 @@
2
2
  import { traverseAndScramble } from '@splendidlabz/utils/dom'
3
3
  import { onMount } from 'svelte'
4
4
 
5
- let { class: klass = '', ref = $bindable(null), ...p } = $props()
6
- const { excludes = [], children, ...rest } = p
5
+ let { class: klass = '', ref = $bindable(null), excludes = [], children, ...rest } = $props()
7
6
 
8
7
  onMount(_ => {
9
8
  if (typeof window === 'undefined') return
@@ -1,7 +1,5 @@
1
1
  <script>
2
- let { status = $bindable('info'), ...p } = $props()
3
-
4
- const { class: klass = '', children, ...rest } = p
2
+ let { status = $bindable('info'), class: klass = '', children, ...rest } = $props()
5
3
 
6
4
  function getStatusString(status) {
7
5
  if (typeof status === 'string') return status
@@ -1,13 +1,10 @@
1
1
  <script>
2
2
  import { preferHorizontalScroll as preferHorizontalScrollAction } from '@splendidlabz/utils/dom'
3
3
  import { breakpointObserver } from '../../actions/breakpoint-observer.js'
4
- import { mergeOpts } from '../../utils/merge-opts.js'
4
+ import { init } from '../../utils'
5
5
  import { getTab, tablist, updatePlacement } from './tabs.svelte.js'
6
6
 
7
- let { ...p } = $props()
8
- p = mergeOpts(p)
9
-
10
- const {
7
+ let {
11
8
  class: klass = '',
12
9
  target = null,
13
10
  breakpoints,
@@ -21,13 +18,15 @@
21
18
  children,
22
19
 
23
20
  ...rest
24
- } = p
21
+ } = $props()
25
22
 
26
- let placement = initialPlacement || 'top'
23
+ let placement = $state(_ => initialPlacement || 'top')
27
24
  let tab = $derived(getTab(target))
28
25
  let tablistClasses = $derived(getTablistClasses(tab))
29
26
 
30
- if (!target) throw new Error('Tablist must have a target')
27
+ init(() => {
28
+ if (!target) throw new Error('Tablist must have a target')
29
+ })
31
30
 
32
31
  function getTablistClasses(tab) {
33
32
  if (!tab) return ''
@@ -1,8 +1,12 @@
1
1
  <script>
2
+ import { init } from '../../utils'
2
3
  import { tabpanels } from './tabs.svelte.js'
3
4
 
4
5
  const { id = null, class: klass = '', children, ...rest } = $props()
5
- if (!id) throw new Error('Tabpanels must have an id')
6
+
7
+ init(() => {
8
+ if (!id) throw new Error('Tabpanels must have an id')
9
+ })
6
10
  </script>
7
11
 
8
12
  <div {...rest} {id} class="tabpanels {klass}" use:tabpanels>
@@ -3,9 +3,8 @@
3
3
  import Tab from './Tab.svelte'
4
4
  import Tablist from './Tablist.svelte'
5
5
  import Tabpanels from './Tabpanels.svelte'
6
- const { tabs, ...p } = $props()
7
-
8
6
  const {
7
+ tabs,
9
8
  id = randomString(),
10
9
  class: klass = '',
11
10
  activeIndex = 0,
@@ -17,7 +16,7 @@
17
16
  tabpanelsOptions,
18
17
  children,
19
18
  ...rest
20
- } = p
19
+ } = $props()
21
20
  </script>
22
21
 
23
22
  <Tablist
@@ -10,16 +10,13 @@
10
10
  timestamp = 0, // alias for start
11
11
  } = $props()
12
12
 
13
- if (!id && !link)
14
- throw new Error('id or link is required for Youtube component')
15
-
16
- const _id = id || link.split('/').pop()
17
- const src = `https://www.youtube.com/embed/${_id}?vq=highres&start=${start || timestamp}&cc_load_policy=1&cc_lang_pref=en`
18
-
19
- const style = toStyleString({
20
- width: '100%',
21
- aspectRatio: short ? '9/16' : '16/9',
22
- })
13
+ const _id = $derived(id || link?.split('/').pop())
14
+ const src = $derived(
15
+ `https://www.youtube.com/embed/${_id}?vq=highres&start=${start || timestamp}&cc_load_policy=1&cc_lang_pref=en`,
16
+ )
17
+ const style = $derived(
18
+ toStyleString({ width: '100%', aspectRatio: short ? '9/16' : '16/9' }),
19
+ )
23
20
  </script>
24
21
 
25
22
  <div class="youtube {klass}">
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@splendidlabz/svelte",
3
3
  "type": "module",
4
- "version": "4.8.3",
4
+ "version": "4.8.5",
5
5
  "sideEffects": false,
6
6
  "homepage": "https://splendidlabz.com/docs/svelte",
7
7
  "scripts": {
@@ -33,6 +33,7 @@
33
33
  },
34
34
  "devDependencies": {
35
35
  "@splendidlabz/eslint-config": "2.1.3",
36
+ "@sveltejs/vite-plugin-svelte": "^6.2.4",
36
37
  "@tsconfig/svelte": "^5.0.4",
37
38
  "svelte": "^5.25.6",
38
39
  "svelte-check": "^4.2.1",
package/utils/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './accessibility.js'
2
+ export * from './init.js'
2
3
  export * from './is-slot.js'
3
4
  export * from './map-store.svelte.js'
4
5
  export * from './merge-opts.js'
package/utils/init.js ADDED
@@ -0,0 +1,3 @@
1
+ export function init(cb) {
2
+ return cb()
3
+ }
@@ -2,6 +2,8 @@ export function reloadScripts(node) {
2
2
  let scripts = []
3
3
  const scriptElements = Array.from(node.querySelectorAll('script'))
4
4
 
5
+ if (scriptElements.length === 0) return
6
+
5
7
  scriptElements.forEach(origScript => {
6
8
  const script = document.createElement('script')
7
9
  Array.from(origScript.attributes).forEach(attr => {
@@ -0,0 +1,8 @@
1
+ import { defineConfig } from 'vitest/config'
2
+ import { svelte } from '@sveltejs/vite-plugin-svelte'
3
+
4
+ export default defineConfig({
5
+ plugins: [
6
+ svelte({ configFile: false }),
7
+ ],
8
+ })
@@ -1,24 +0,0 @@
1
- <!-- TODO: Improve with Astro new image functionality -->
2
- <script>
3
- let klass = ''
4
- export { klass as class }
5
- export let src, alt, loading, caption
6
- import Markdown from './Markdown/Markdown.svelte'
7
-
8
- if (loading !== 'eager') loading = 'lazy'
9
- </script>
10
-
11
- {#if caption}
12
- <figure class={klass} aria-label={caption} {...$$restProps}>
13
- <img {src} alt={alt || caption} {loading} aria-hidden="true" />
14
- <figcaption aria-hidden="true">
15
- <Markdown content={caption} inline />
16
- </figcaption>
17
- </figure>
18
- {/if}
19
-
20
- {#if !caption}
21
- <figure class={klass} {...$$restProps}>
22
- <img {src} {alt} {loading} />
23
- </figure>
24
- {/if}