@splendidlabz/svelte 4.1.0 → 4.2.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.
Files changed (30) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/components/Breadcrumbs/Breadcrumbs.svelte +10 -10
  3. package/components/Codepen/Codepen.svelte +11 -14
  4. package/components/Codepen/index.js +0 -1
  5. package/components/Disclosure/Disclosure/DisclosureContent.svelte +2 -2
  6. package/components/Disclosure/Drawer/DrawerCloseButton.svelte +2 -2
  7. package/components/Disclosure/DrawerNew/{DrawerClose.svelte → DrawerCloseButton.svelte} +8 -4
  8. package/components/Disclosure/DrawerNew/{Drawer.svelte → DrawerContent.svelte} +10 -8
  9. package/components/Disclosure/DrawerNew/index.js +8 -3
  10. package/components/Disclosure/ModalNew/{Modal.svelte → ModalContent.svelte} +23 -7
  11. package/components/Disclosure/ModalNew/index.js +2 -2
  12. package/components/Disclosure/PopoverNew/PopoverContent.svelte +119 -0
  13. package/components/Disclosure/PopoverNew/PopoverTrigger.svelte +15 -5
  14. package/components/Disclosure/PopoverNew/floating.js +3 -0
  15. package/components/Disclosure/PopoverNew/index.js +2 -1
  16. package/components/Form/Combobox/TimepickerOptions.svelte +3 -4
  17. package/components/Form/Form.svelte +2 -4
  18. package/components/Form/Honeypot.svelte +1 -23
  19. package/components/PushToLocalStorage.svelte +9 -18
  20. package/components/SVG/SVG.svelte +49 -0
  21. package/components/SVG/index.js +2 -0
  22. package/components/SVG/parser.js +133 -0
  23. package/components/Status.svelte +8 -1
  24. package/components/Tabs/Tablist.svelte +2 -0
  25. package/components/Tabs/Tabpanels.svelte +1 -0
  26. package/components/Vimeo.svelte +3 -3
  27. package/components/Youtube.svelte +18 -7
  28. package/index.js +7 -7
  29. package/package.json +3 -3
  30. package/components/Codepen/Codepen.astro +0 -29
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @splendidlabz/svelte
2
2
 
3
+ ## 4.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Many changes! Woo
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [2c149fc]
12
+ - Updated dependencies
13
+ - @splendidlabz/utils@1.7.0
14
+ - @splendidlabz/styles@4.2.0
15
+
3
16
  ## 4.1.0
4
17
 
5
18
  ### Minor Changes
@@ -1,7 +1,7 @@
1
1
  <script>
2
2
  import { onMount } from 'svelte'
3
3
  import { mergeOpts } from '../../utils'
4
- import { Snippet } from '../_Shared/Snippet.svelte'
4
+ import Icon from '../Icon/Icon.svelte'
5
5
  import Crumb from './Crumb.svelte'
6
6
 
7
7
  const { ...p } = $props()
@@ -36,7 +36,9 @@
36
36
  if (!pathname) {
37
37
  const { pathname } = window.location
38
38
  const trailingSlash = hasTrailingSlash(pathname)
39
- crumbs = constructCrumbs(getURLArray(pathname), { trailingSlash })
39
+ crumbs = constructCrumbs(getURLArray(pathname), { trailingSlash }).slice(
40
+ startingDepth,
41
+ )
40
42
  }
41
43
  })
42
44
 
@@ -46,14 +48,9 @@
46
48
  }
47
49
 
48
50
  function getURLArray(pathname) {
49
- return pathname
50
- .split('/')
51
- .filter(str => str)
52
- .slice(startingDepth)
51
+ return pathname.split('/').filter(str => str)
53
52
  }
54
53
 
55
- // TODO: Breadcrumbs URL currently return a wrong address.
56
- // This needs to be fixed before breadcrumbs are usable.
57
54
  function constructCrumbs(urlArray, { trailingSlash = true } = {}) {
58
55
  return urlArray.map((crumb, index) => {
59
56
  return {
@@ -73,7 +70,10 @@
73
70
  <nav class={`breadcrumbs ${klass}`} aria-label="Breadcrumbs">
74
71
  <ul>
75
72
  {#if before}
76
- {@render before()}
73
+ {@render before?.()}
74
+ <span class="crumb-divider">
75
+ <Icon icon={opts.divider} />
76
+ </span>
77
77
  {/if}
78
78
 
79
79
  {#if children}
@@ -87,6 +87,6 @@
87
87
  />
88
88
  {/each}
89
89
  {/if}
90
- {@render Snippet.block(after)}
90
+ {@render after?.()}
91
91
  </ul>
92
92
  </nav>
@@ -1,24 +1,21 @@
1
1
  <script>
2
- let klass = ''
3
- export { klass as class }
4
- export let user, themeId, hash, title
5
- export let height = 300
6
- export let defaultTab = 'result'
2
+ const { title, link, height = 300, tabs = 'result', themeID } = $props()
3
+ const [, , , user, , hash] = link.split('/')
7
4
  </script>
8
5
 
9
6
  <div
10
- class="Codepen {klass}"
7
+ style="height: ${height}px;"
8
+ class="codepen"
9
+ data-default-tab={tabs}
11
10
  data-height={height}
12
- data-theme-id={themeId}
13
- data-default-tab={defaultTab}
14
- data-user={user}
15
- data-slug-hash={hash}
16
- style={`height: ${height}px;`}
17
11
  data-pen-title={title}
12
+ data-slug-hash={hash}
13
+ data-theme-id={themeID}
14
+ data-user={user}
18
15
  >
19
16
  <!-- prettier-ignore -->
20
- <span>See the Pen
21
- <a href={`https://codepen.io/${user}/pen/${hash}`}>{title}</a> by {user} (<a href={`https://codepen.io/${user}`}> @{user}</a>) on <a href="https://codepen.io">CodePen</a>.
17
+ <span>
18
+ See the Pen <a href={link}>{title}</a>by <a href={`https://codepen.io/${user}`}>@{user}</a> on<a href="https://codepen.io">CodePen</a>.
22
19
  </span>
23
- <script async src="https://static.codepen.io/assets/embed/ei.js"></script>
20
+ <script async src="https://public.codepenassets.com/embed/index.js"></script>
24
21
  </div>
@@ -1,3 +1,2 @@
1
1
  import Codepen from './Codepen.svelte'
2
-
3
2
  export { Codepen }
@@ -1,9 +1,9 @@
1
1
  <script>
2
2
  import { splitObject } from '@splendidlabz/utils'
3
3
  import {
4
- goToElement,
5
4
  hasAccessibleName,
6
5
  markActiveAnchorIn,
6
+ scrollToElement,
7
7
  } from '@splendidlabz/utils/dom'
8
8
  import {
9
9
  TRANSITION_OPT_KEYS,
@@ -62,7 +62,7 @@
62
62
  $effect(_ => {
63
63
  if (show && ref && scrollToAnchor) {
64
64
  const anchor = markActiveAnchorIn(ref)
65
- goToElement(anchor)
65
+ scrollToElement(anchor)
66
66
  }
67
67
  })
68
68
  </script>
@@ -23,10 +23,10 @@
23
23
  </script>
24
24
 
25
25
  <button
26
- aria-label="Close dialog"
26
+ bind:this={button}
27
27
  class="drawer-close-button {klass}"
28
+ aria-label="Close dialog"
28
29
  {...rest}
29
- bind:this={button}
30
30
  onclick={closeDrawer}
31
31
  >
32
32
  {#if children}
@@ -3,15 +3,19 @@
3
3
  import ModalClose from '../ModalNew/ModalClose.svelte'
4
4
  import PopoverClose from '../PopoverNew/PopoverClose.svelte'
5
5
 
6
- const { target, ...p } = $props()
6
+ const { class: klass = '', target, ...p } = $props()
7
7
 
8
8
  let sync = $derived(getEntry(target))
9
9
  let type = $derived(sync?.type)
10
+
11
+ const propsToPass = {
12
+ target,
13
+ class: `drawer-close-button ${klass}`,
14
+ }
10
15
  </script>
11
16
 
12
- <!-- FUCK THIS DOESN'T WORK -->
13
17
  {#if type === 'popover'}
14
- <PopoverClose {...p} {target} />
18
+ <PopoverClose {...propsToPass} {...p} />
15
19
  {:else}
16
- <ModalClose {...p} {target} />
20
+ <ModalClose {...propsToPass} {...p} />
17
21
  {/if}
@@ -3,8 +3,8 @@
3
3
  import { getParentElement } from '@splendidlabz/utils/dom'
4
4
  import { onMount } from 'svelte'
5
5
  import { mergeEntry, setEntry } from '../../../actions/sync.svelte.js'
6
- import Modal from '../ModalNew/Modal.svelte'
7
- import Popover from '../PopoverNew/Popover.svelte'
6
+ import ModalContent from '../ModalNew/ModalContent.svelte'
7
+ import PopoverContent from '../PopoverNew/PopoverContent.svelte'
8
8
 
9
9
  let {
10
10
  class: klass = '',
@@ -16,9 +16,6 @@
16
16
  const { id, ...rest } = p
17
17
  const useReferenceBoundaries = type === 'popover'
18
18
 
19
- const localRef = $state(null)
20
- if (!ref) ref = () => localRef
21
-
22
19
  let referenceNode = $state(null)
23
20
  setEntry(id, { type })
24
21
 
@@ -32,12 +29,17 @@
32
29
  id,
33
30
  ...rest,
34
31
  componentName: 'Drawer',
35
- class: `drawer ${klass}`,
32
+ class: `drawer-content ${klass}`,
36
33
  }
37
34
  </script>
38
35
 
39
36
  {#if type === 'modal'}
40
- <Modal bind:ref {...propsToPass} />
37
+ <ModalContent bind:ref {...propsToPass} />
41
38
  {:else}
42
- <Popover {referenceNode} {useReferenceBoundaries} bind:ref {...propsToPass} />
39
+ <PopoverContent
40
+ {referenceNode}
41
+ {useReferenceBoundaries}
42
+ bind:ref
43
+ {...propsToPass}
44
+ />
43
45
  {/if}
@@ -1,5 +1,10 @@
1
- import Drawer from './Drawer.svelte'
2
- import DrawerClose from './DrawerClose.svelte'
1
+ import DrawerCloseButton from './DrawerCloseButton.svelte'
2
+ import DrawerContent from './DrawerContent.svelte'
3
3
  import DrawerTrigger from './DrawerTrigger.svelte'
4
4
 
5
- export { Drawer, DrawerClose, DrawerTrigger }
5
+ export {
6
+ DrawerContent as Drawer,
7
+ DrawerCloseButton,
8
+ DrawerContent,
9
+ DrawerTrigger,
10
+ }
@@ -1,5 +1,9 @@
1
1
  <script>
2
- import { checkForAccessibleName } from '@splendidlabz/utils/dom'
2
+ import {
3
+ checkForAccessibleName,
4
+ markActiveAnchorIn,
5
+ scrollToElement,
6
+ } from '@splendidlabz/utils/dom'
3
7
  import { getTrigger, passEventToTrigger } from '../shared.js'
4
8
  let { ref = $bindable(null), ...p } = $props()
5
9
 
@@ -13,13 +17,17 @@
13
17
  placement = 'center',
14
18
 
15
19
  // Props
16
- // scrollToAnchor = false,
20
+ scrollToAnchor = false,
17
21
  lightDismiss = true,
18
22
 
19
23
  // Event listeners
20
24
  onclick = null,
21
25
  onbeforetoggle = null,
26
+ onbeforeopen = null,
27
+ onbeforeclose = null,
22
28
  ontoggle = null,
29
+ onopen = null,
30
+ onclose = null,
23
31
  onkeydown = null,
24
32
 
25
33
  // Slots
@@ -61,15 +69,23 @@
61
69
  if (!trigger) trigger = getTrigger(`[data-modal-trigger="${id}"]`)
62
70
  passEventToTrigger(event, trigger)
63
71
 
64
- // const { newState } = event
65
- // if (newState === 'open') ref.classList.add(animationInClass)
66
- // if (newState === 'closed') ref.classList.add(animationOutClass)
67
-
72
+ const { newState } = event
73
+ if (newState === 'open' && onbeforeopen) onbeforeopen(event)
74
+ if (newState === 'close' && onbeforeclose) onbeforeclose(event)
68
75
  if (onbeforetoggle) onbeforetoggle(event)
69
76
  }
70
77
 
71
78
  function handleToggle(event) {
72
79
  passEventToTrigger(event, trigger)
80
+
81
+ const { newState } = event
82
+ if (newState === 'open' && scrollToAnchor) {
83
+ const anchor = markActiveAnchorIn(ref)
84
+ scrollToElement(anchor)
85
+ }
86
+
87
+ if (newState === 'open' && onopen) onopen(event)
88
+ if (newState === 'close' && onclose) onclose(event)
73
89
  if (ontoggle) ontoggle(event)
74
90
  }
75
91
 
@@ -103,7 +119,7 @@
103
119
  {...rest}
104
120
  bind:this={ref}
105
121
  {id}
106
- class="modal {placementClass} {transitionClass} {klass}"
122
+ class="modal-content {placementClass} {transitionClass} {klass}"
107
123
  aria-describedby={ariaDescribedBy}
108
124
  aria-label={ariaLabel}
109
125
  aria-labelledby={ariaLabelledBy}
@@ -1,5 +1,5 @@
1
- import Modal from './Modal.svelte'
2
1
  import ModalClose from './ModalClose.svelte'
2
+ import ModalContent from './ModalContent.svelte'
3
3
  import ModalTrigger from './ModalTrigger.svelte'
4
4
 
5
- export { Modal, ModalClose, ModalTrigger }
5
+ export { ModalContent as Modal, ModalClose, ModalContent, ModalTrigger }
@@ -0,0 +1,119 @@
1
+ <script>
2
+ import { splitObject } from '@splendidlabz/utils'
3
+ import { checkForAccessibleName } from '@splendidlabz/utils/dom'
4
+ import { mergeOpts } from '../../../utils/merge-opts.js'
5
+ import { getTrigger, passEventToTrigger } from '../shared.js'
6
+ import { FLOATING_OPTS_KEYS, initFloating } from './floating.js'
7
+
8
+ let {
9
+ class: klass = '',
10
+ as = 'dialog',
11
+ ref = $bindable(null),
12
+ referenceNode = $bindable(null),
13
+ ...p
14
+ } = $props()
15
+
16
+ p = mergeOpts(p)
17
+
18
+ const {
19
+ componentName = 'Popover',
20
+ 'aria-label': ariaLabel,
21
+ 'aria-labelledBy': ariaLabelledBy,
22
+ 'aria-describedby': ariaDescribedBy,
23
+
24
+ // Props
25
+ id,
26
+ popover = 'auto', // manual, hint
27
+
28
+ // Event listeners
29
+ onbeforetoggle = null,
30
+ ontoggle = null,
31
+ onopen = null,
32
+ onclose = null,
33
+
34
+ // Slots
35
+ children,
36
+ ...rest
37
+ } = p
38
+
39
+ // ========================
40
+ // Checks
41
+ // ========================
42
+ if (!id) throw new Error(`${componentName} requires an id`)
43
+
44
+ // Accessible name warning
45
+ checkForAccessibleName({
46
+ name: `${componentName} (id: ${id})`,
47
+ ariaLabel,
48
+ ariaLabelledBy,
49
+ })
50
+
51
+ // ========================================
52
+ // Logic
53
+ // ========================================
54
+ let trigger = null
55
+ let floating = null
56
+
57
+ const { picked: floatingOpts } = splitObject(rest, FLOATING_OPTS_KEYS)
58
+
59
+ // ========================================
60
+ // Event Listeners
61
+ // ========================================
62
+ function beforetoggle(event) {
63
+ if (!trigger) trigger = getTrigger(`[popovertarget="${id}"]`)
64
+ passEventToTrigger(event, trigger)
65
+
66
+ const { newState } = event
67
+
68
+ if (newState === 'open') {
69
+ // Initialize floating.
70
+ if (!floating) {
71
+ floating = initFloating({
72
+ referenceNode: referenceNode || trigger,
73
+ floatingNode: ref,
74
+ ...floatingOpts,
75
+ })
76
+ }
77
+ floating.update()
78
+ }
79
+
80
+ // Calculate position before showing
81
+ if (onbeforetoggle) onbeforetoggle(event)
82
+ }
83
+
84
+ function handleToggle(event) {
85
+ passEventToTrigger(event, trigger)
86
+ const { newState } = event
87
+
88
+ // Send open event
89
+ if (newState === 'open') {
90
+ if (onopen) onopen(event)
91
+ }
92
+
93
+ if (newState === 'closed') {
94
+ floating.cleanup()
95
+ // Send close event
96
+ if (onclose) onclose(event)
97
+ }
98
+
99
+ // Send toggle event
100
+ if (ontoggle) ontoggle(event)
101
+ }
102
+ </script>
103
+
104
+ <!-- Snippets -->
105
+ <svelte:element
106
+ this={as}
107
+ bind:this={ref}
108
+ {...rest}
109
+ {id}
110
+ class="{klass} popover-content"
111
+ aria-describedby={ariaDescribedBy}
112
+ aria-label={ariaLabel}
113
+ aria-labelledby={ariaLabelledBy}
114
+ onbeforetoggle={beforetoggle}
115
+ ontoggle={handleToggle}
116
+ {popover}
117
+ >
118
+ {#if children}{@render children()}{/if}
119
+ </svelte:element>
@@ -2,7 +2,7 @@
2
2
  import { delay } from '@splendidlabz/utils'
3
3
  import { onMount } from 'svelte'
4
4
  import Icon from '../../Icon/Icon.svelte'
5
- let { show = $bindable(false), ref = $bindable(null), ...p } = $props()
5
+ let { show = $bindable(null), ref = $bindable(null), ...p } = $props()
6
6
 
7
7
  const {
8
8
  componentName = 'PopoverTrigger',
@@ -20,6 +20,8 @@
20
20
  // Event listeners
21
21
  onclick = null,
22
22
  ontoggle = null,
23
+ onopen = null,
24
+ onclose = null,
23
25
  ...rest
24
26
  } = p
25
27
 
@@ -44,9 +46,17 @@
44
46
 
45
47
  // Allows trigger to know whether the popover is open or closed
46
48
  function handleToggle(event) {
47
- const { newState, oldState } = event.detail
48
- if (newState === 'open') show = true
49
- if (oldState === 'closed') show = false
49
+ const { newState } = event.detail
50
+ if (newState === 'open') {
51
+ show = true
52
+ if (onopen) onopen(event)
53
+ }
54
+
55
+ if (newState === 'closed') {
56
+ show = false
57
+ if (onclose) onclose(event)
58
+ }
59
+
50
60
  if (ontoggle) ontoggle(event)
51
61
  }
52
62
  </script>
@@ -54,7 +64,7 @@
54
64
  <button
55
65
  {...rest}
56
66
  bind:this={ref}
57
- class="button {klass}"
67
+ class="button popover-trigger {klass}"
58
68
  data-show={show}
59
69
  ontoggle={handleToggle}
60
70
  popovertarget={target}
@@ -52,6 +52,7 @@ export function initFloating(options) {
52
52
 
53
53
  // Create arrow node — used for both styles
54
54
  const arrowNode = document.createElement('div')
55
+ const arrowClass = 'popover-content-arrow'
55
56
  const arrowHeight = resolveArrowHeight(options)
56
57
  const arrowWidth = getArrowWidth({ ...options, arrowHeight })
57
58
 
@@ -64,6 +65,7 @@ export function initFloating(options) {
64
65
  }
65
66
 
66
67
  applyArrowStyles({ boxStyle, ...arrowProps })
68
+ arrowNode.classList.add(arrowClass)
67
69
  if (arrow) floatingNode.appendChild(arrowNode)
68
70
 
69
71
  // Calculate offset
@@ -210,6 +212,7 @@ function applyArrowStyles({
210
212
  borderRadius: '0',
211
213
  borderTopRightRadius: arrowRadius,
212
214
  borderWidth: 'inherit',
215
+ borderColor: 'inherit',
213
216
  borderLeftWidth: '0',
214
217
  borderBottomWidth: '0',
215
218
  background: 'inherit',
@@ -1,5 +1,6 @@
1
1
  import Popover from './Popover.svelte'
2
2
  import PopoverClose from './PopoverClose.svelte'
3
+ import PopoverContent from './PopoverContent.svelte'
3
4
  import PopoverTrigger from './PopoverTrigger.svelte'
4
5
 
5
- export { Popover, PopoverClose, PopoverTrigger }
6
+ export { Popover, PopoverClose, PopoverContent, PopoverTrigger }
@@ -40,7 +40,6 @@
40
40
  disabled: timing.blocked,
41
41
  }))
42
42
 
43
- // console.log(timings)
44
43
  const showHours = opts.format.includes('HH')
45
44
  const showMinutes = opts.format.includes('mm')
46
45
  const showSeconds = opts.format.includes('ss')
@@ -48,23 +47,23 @@
48
47
 
49
48
  <PopoverContent
50
49
  {id}
51
- options={opts}
52
50
  class="TimepickerOptions ListboxPopover {klass}"
51
+ options={opts}
53
52
  >
54
53
  {#if mode === 'list' && selection === 'single'}
55
54
  <!-- This doesn't close the popover yet -->
56
55
  <!-- Need some action to determine when to close the popover -->
57
56
  <Radios
57
+ name="time"
58
58
  class="Timepicker {klass}"
59
59
  legend="Time"
60
- name="time"
61
60
  radios={timings}
62
61
  ></Radios>
63
62
  {/if}
64
63
 
65
64
  {#if mode === 'list' && selection === 'multiple'}
66
65
  <!-- This doesn't close the popover yet -->
67
- <Checkboxes class="Timepicker {klass}" legend="Time" checkboxes={timings}
66
+ <Checkboxes class="Timepicker {klass}" checkboxes={timings} legend="Time"
68
67
  ></Checkboxes>
69
68
  {/if}
70
69
 
@@ -30,9 +30,6 @@
30
30
 
31
31
  function submit(event) {
32
32
  const form = event.target
33
- // Do a standard form submit without JS if the user did not provide a custom onSubmit callback
34
- if (!onsubmit) return form.submit()
35
-
36
33
  event.preventDefault()
37
34
 
38
35
  // Format form data before submitting
@@ -49,7 +46,8 @@
49
46
  if (isTooFast || hasHoneypotValue || noInteraction) return
50
47
  }
51
48
 
52
- onsubmit(data)
49
+ if (!onsubmit) return form.submit()
50
+ else onsubmit(data)
53
51
  }
54
52
  </script>
55
53
 
@@ -9,26 +9,4 @@
9
9
  } = $props()
10
10
  </script>
11
11
 
12
- <TextInput
13
- {...rest}
14
- {name}
15
- class="form-field-helper {klass}"
16
- aria-hidden="true"
17
- autocomplete="off"
18
- tabindex="-1"
19
- bind:value
20
- />
21
-
22
- <style>
23
- .form-field-helper {
24
- display: none;
25
- visibility: hidden;
26
- position: absolute;
27
- left: -9999px;
28
- opacity: 0;
29
- pointer-events: none;
30
- height: 0;
31
- width: 0;
32
- overflow: hidden;
33
- }
34
- </style>
12
+ <TextInput {...rest} {name} class="form-field-helper {klass}" bind:value />
@@ -1,30 +1,21 @@
1
1
  <!-- @example
2
- <PushToLocalStorage
3
- values={{ firstName: 'Zell', email: '12345@gmail.com' }} client:idle
4
- />
5
-
6
- Stored value can be an object as well
7
2
  <PushToLocalStorage
8
- values={{
9
- user: {
10
- firstName: 'Zell',
11
- email: '12345@gmail.com',
12
- },
13
- }}
14
- client:idle
3
+ name="user"
4
+ value={ firstName: 'Zell', email: '12345@gmail.com' }
15
5
  />
16
6
  -->
17
7
 
18
8
  <script>
19
- import { isEmpty, objectForEach } from '@splendidlabz/utils'
20
9
  import { localStore } from '@splendidlabz/utils/dom'
21
- export let values = {}
22
10
 
23
- store(values)
11
+ const { name, value } = $props()
12
+ if (!name) throw new Error('name is required')
13
+
14
+ store()
24
15
 
25
- function store(values) {
16
+ function store() {
26
17
  if (typeof window === 'undefined') return
27
- if (isEmpty(values)) return
28
- objectForEach(values, ({ key, value }) => localStore.set(key, value))
18
+ if (!name) return
19
+ localStore.set(name, value)
29
20
  }
30
21
  </script>
@@ -0,0 +1,49 @@
1
+ <script>
2
+ import { toStyleString } from '@splendidlabz/utils'
3
+ import { onMount } from 'svelte'
4
+ import { domParser, naiveParser } from './parser.js'
5
+ const {
6
+ icon,
7
+ style,
8
+ parser = 'naive', // or DOM
9
+ children, // Just to remove children slots
10
+ ...p
11
+ } = $props()
12
+
13
+ const files = {
14
+ ...import.meta.glob(`/src/svg/**/*.svg`, { eager: true, query: 'raw' }),
15
+ ...import.meta.glob(`/src/svgs/**/*.svg`, { eager: true, query: 'raw' }),
16
+ }
17
+
18
+ // Find the SVG
19
+ if (!icon) throw new Error('icon property is required')
20
+
21
+ const file = Object.keys(files).find(file => {
22
+ const basename = file.split('/').pop()
23
+ return basename === `${icon}.svg`
24
+ })
25
+
26
+ if (!file) {
27
+ throw new Error(`${icon}.svg not found`)
28
+ }
29
+
30
+ const content = files[file].default
31
+ const svgProps = {
32
+ role: 'img',
33
+ xmlns: 'http://www.w3.org/2000/svg',
34
+ style: toStyleString(style),
35
+ ...p,
36
+ }
37
+
38
+ let svg = $state(null)
39
+
40
+ if (parser === 'naive') svg = naiveParser(content, svgProps)
41
+ if (parser === 'dom') {
42
+ onMount(_ => {
43
+ svg = domParser(content, svgProps)
44
+ })
45
+ }
46
+ </script>
47
+
48
+ <!-- eslint-disable-next-line svelte/no-at-html-tags -->
49
+ {@html svg}
@@ -0,0 +1,2 @@
1
+ import SVG from './SVG.svelte'
2
+ export { SVG }
@@ -0,0 +1,133 @@
1
+ // Simple regex parsing to add/adjust SVG attributes
2
+ // Written by AI.
3
+ export function naiveParser(content, options) {
4
+ const { class: klass, width, height, attributes = {} } = options
5
+
6
+ // Parse the opening <svg> tag
7
+ const svgMatch = content.match(/<svg[^>]*>/i)
8
+ if (!svgMatch) return content
9
+
10
+ let svgTag = svgMatch[0]
11
+
12
+ // Extract existing attributes
13
+ const existingWidth = svgTag.match(/width="([^"]*)"/)
14
+ const existingHeight = svgTag.match(/height="([^"]*)"/)
15
+ const existingViewBox = svgTag.match(/viewBox="([^"]*)"/)
16
+
17
+ // Parse values
18
+ const currentWidth = existingWidth ? existingWidth[1] : null
19
+ const currentHeight = existingHeight ? existingHeight[1] : null
20
+ const currentViewBox = existingViewBox ? existingViewBox[1] : null
21
+
22
+ // Add class if provided
23
+ if (klass) {
24
+ if (svgTag.includes('class=')) {
25
+ // Add to existing class
26
+ svgTag = svgTag.replace(/class="([^"]*)"/, `class="$1 ${klass}"`)
27
+ } else {
28
+ // Add new class attribute
29
+ svgTag = svgTag.replace('>', ` class="${klass}">`)
30
+ }
31
+ }
32
+
33
+ // Handle width/height and viewBox relationship
34
+ let finalWidth = width || currentWidth
35
+ let finalHeight = height || currentHeight
36
+ let finalViewBox = currentViewBox
37
+
38
+ // If viewBox exists but width/height don't, extract from viewBox
39
+ if (currentViewBox && (!currentWidth || !currentHeight)) {
40
+ const viewBoxValues = currentViewBox.split(/\s+/)
41
+ if (viewBoxValues.length === 4) {
42
+ const [, , vbWidth, vbHeight] = viewBoxValues
43
+ if (!currentWidth && !width) finalWidth = vbWidth
44
+ if (!currentHeight && !height) finalHeight = vbHeight
45
+ }
46
+ }
47
+
48
+ // If width/height exist but viewBox doesn't, create viewBox
49
+ if (!currentViewBox && (finalWidth || finalHeight)) {
50
+ const vbWidth = finalWidth || '0'
51
+ const vbHeight = finalHeight || '0'
52
+ finalViewBox = `0 0 ${vbWidth} ${vbHeight}`
53
+ }
54
+
55
+ // Apply width if we have a final value
56
+ if (finalWidth) {
57
+ if (svgTag.includes('width=')) {
58
+ svgTag = svgTag.replace(/width="[^"]*"/, `width="${finalWidth}"`)
59
+ } else {
60
+ svgTag = svgTag.replace('>', ` width="${finalWidth}">`)
61
+ }
62
+ }
63
+
64
+ // Apply height if we have a final value
65
+ if (finalHeight) {
66
+ if (svgTag.includes('height=')) {
67
+ svgTag = svgTag.replace(/height="[^"]*"/, `height="${finalHeight}"`)
68
+ } else {
69
+ svgTag = svgTag.replace('>', ` height="${finalHeight}">`)
70
+ }
71
+ }
72
+
73
+ // Apply viewBox if we have a final value
74
+ if (finalViewBox) {
75
+ if (svgTag.includes('viewBox=')) {
76
+ svgTag = svgTag.replace(/viewBox="[^"]*"/, `viewBox="${finalViewBox}"`)
77
+ } else {
78
+ svgTag = svgTag.replace('>', ` viewBox="${finalViewBox}">`)
79
+ }
80
+ }
81
+
82
+ // Add any additional attributes
83
+ Object.entries(attributes).forEach(([key, value]) => {
84
+ if (svgTag.includes(`${key}=`)) {
85
+ svgTag = svgTag.replace(new RegExp(`${key}="[^"]*"`), `${key}="${value}"`)
86
+ } else {
87
+ svgTag = svgTag.replace('>', ` ${key}="${value}">`)
88
+ }
89
+ })
90
+
91
+ // Replace the original svg tag with the modified one
92
+ return content.replace(/<svg[^>]*>/i, svgTag)
93
+ }
94
+
95
+ // Uses DOM Parser to modify the SVG.
96
+ // Likely not needed.
97
+ // Written by AI.
98
+ export function domParser(content, options) {
99
+ const { className, width, height, attributes = {}, transform } = options
100
+
101
+ // Parse SVG content
102
+ const parser = new DOMParser()
103
+ const doc = parser.parseFromString(content, 'image/svg+xml')
104
+ const svgElement = doc.querySelector('svg')
105
+
106
+ if (!svgElement) return content
107
+
108
+ // Add class
109
+ if (className) {
110
+ const currentClass = svgElement.getAttribute('class') || ''
111
+ svgElement.setAttribute(
112
+ 'class',
113
+ currentClass ? `${currentClass} ${className}` : className,
114
+ )
115
+ }
116
+
117
+ // Set dimensions
118
+ if (width) svgElement.setAttribute('width', width)
119
+ if (height) svgElement.setAttribute('height', height)
120
+
121
+ // Add additional attributes
122
+ Object.entries(attributes).forEach(([key, value]) => {
123
+ svgElement.setAttribute(key, value)
124
+ })
125
+
126
+ // Apply custom transform function
127
+ if (typeof transform === 'function') {
128
+ transform(svgElement)
129
+ }
130
+
131
+ // Return the modified SVG
132
+ return svgElement.outerHTML
133
+ }
@@ -18,9 +18,16 @@
18
18
  status = 'info'
19
19
  }
20
20
  }
21
+
22
+ const statusClasses = {
23
+ info: 'status-info',
24
+ success: 'status-success',
25
+ error: 'status-error',
26
+ }
27
+ const statusClass = statusClasses[status]
21
28
  </script>
22
29
 
23
- <div {...rest} class="status {status && `status-${status}`} prose {klass}">
30
+ <div {...rest} class="status {statusClass} {klass}">
24
31
  {#if children}
25
32
  {@render children()}
26
33
  {/if}
@@ -28,6 +28,8 @@
28
28
  $: tab = $tabs.find(t => t.id === target)
29
29
  $: tablistClasses = getTablistClasses(tab)
30
30
 
31
+ if (!target) throw new Error('Tablist must have a target')
32
+
31
33
  function getTablistClasses(tab) {
32
34
  if (!tab) return ''
33
35
  const { placement } = tab.state
@@ -2,6 +2,7 @@
2
2
  import { tabpanels } from './tabs.js'
3
3
 
4
4
  const { id = null, class: klass = '', children, ...rest } = $props()
5
+ if (!id) throw new Error('Tabpanels must have an id')
5
6
  </script>
6
7
 
7
8
  <div {...rest} {id} class="tabpanels {klass}" use:tabpanels>
@@ -9,10 +9,10 @@
9
9
 
10
10
  <div class={`Vimeo ${klass}`}>
11
11
  <iframe
12
- {src}
13
- {title}
12
+ allow="autoplay; fullscreen; picture-in-picture"
14
13
  allowfullscreen
15
14
  frameborder="0"
16
- allow="autoplay; fullscreen; picture-in-picture"
15
+ {src}
16
+ {title}
17
17
  ></iframe>
18
18
  </div>
@@ -1,15 +1,26 @@
1
1
  <script>
2
- export let id, title
3
- const link = `https://www.youtube.com/embed/${id}`
2
+ import { toStyleString } from '@splendidlabz/utils'
3
+ const { class: klass = '', id, link, title, short = false } = $props()
4
+
5
+ if (!id && !link)
6
+ throw new Error('id or link is required for Youtube component')
7
+
8
+ const _id = id || link.split('/').pop()
9
+ const src = `https://www.youtube.com/embed/${_id}?vq=highres`
10
+
11
+ const style = toStyleString({
12
+ width: '100%',
13
+ aspectRatio: short ? '9/16' : '16/9',
14
+ })
4
15
  </script>
5
16
 
6
- <!-- IMPROVE: Not sure if height and width is needed -->
7
- <div class="Youtube">
17
+ <div class="youtube {klass}">
8
18
  <iframe
9
- src={link}
10
- {title}
11
- frameborder="0"
19
+ {style}
12
20
  allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
13
21
  allowfullscreen
22
+ frameborder="0"
23
+ {src}
24
+ {title}
14
25
  ></iframe>
15
26
  </div>
package/index.js CHANGED
@@ -1,13 +1,16 @@
1
+ export * from './components/Breadcrumbs/index.js'
2
+ export * from './components/BrowserFrame/index.js'
3
+ export * from './components/Codepen/index.js'
4
+ export * from './components/ContentList/index.js'
1
5
  export * from './components/Disclosure/index.js'
2
6
  export * from './components/Icon/index.js'
7
+ export * from './components/Resizer/index.js'
8
+ export * from './components/Scrambler/index.js'
9
+ export * from './components/SVG/index.js'
3
10
 
4
11
  // Not tested yet
5
12
  export * from './components/Accordion/index.js'
6
- export * from './components/Breadcrumbs/index.js'
7
- export * from './components/BrowserFrame/index.js'
8
13
  export * from './components/Callout/index.js'
9
- export * from './components/Codepen/index.js'
10
- export * from './components/ContentList/index.js'
11
14
  export * from './components/effects/index.js'
12
15
  export * from './components/FancyList/index.js'
13
16
  export * from './components/Form/index.js'
@@ -17,15 +20,12 @@ export * from './components/Link/index.js'
17
20
  export * from './components/List/index.js'
18
21
  export * from './components/Masonry/index.js'
19
22
  export * from './components/Populate/index.js'
20
- export * from './components/Resizer/index.js'
21
- export * from './components/Scrambler/index.js'
22
23
  export * from './components/Switcheroo/index.js'
23
24
  export * from './components/Table/index.js'
24
25
  export * from './components/Tabs/index.js'
25
26
 
26
27
  // TO REMOVE AFTER SHIFTING TO ASTRO
27
28
  export * from './components/Textwall/index.js'
28
-
29
29
  export * from './components/Typewriter/index.js'
30
30
 
31
31
  export { default as Copyright } from './components/Copyright.svelte'
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@splendidlabz/svelte",
3
3
  "type": "module",
4
- "version": "4.1.0",
4
+ "version": "4.2.0",
5
5
  "sideEffects": false,
6
6
  "scripts": {
7
7
  "lint": "eslint . --fix",
@@ -21,8 +21,8 @@
21
21
  "dependencies": {
22
22
  "@floating-ui/dom": "^1.6.13",
23
23
  "@iconify/svelte": "^4.2.0",
24
- "@splendidlabz/styles": "4.1.0",
25
- "@splendidlabz/utils": "1.6.0",
24
+ "@splendidlabz/styles": "4.2.0",
25
+ "@splendidlabz/utils": "1.7.0",
26
26
  "autosuggest-highlight": "^3.3.4",
27
27
  "lodash-es": "^4.17.21",
28
28
  "node-html-parser": "^7.0.1"
@@ -1,29 +0,0 @@
1
- ---
2
- const {
3
- height = 300,
4
- defaultTab = 'result',
5
- user = 'zellwk',
6
- author = 'Zell Liew',
7
- themeID = 7929,
8
- hash,
9
- title,
10
- } = Astro.props
11
- ---
12
-
13
- <div
14
- class="Codepen"
15
- data-height={height}
16
- data-theme-id={themeID}
17
- data-default-tab={defaultTab}
18
- data-user={user}
19
- data-slug-hash={hash}
20
- style=`height: ${height}px;`
21
- data-pen-title={title}
22
- >
23
- <!-- prettier-ignore -->
24
- <span>
25
- See the Pen <a href=`https://codepen.io/${user}/pen/${hash}`> {title} </a>by {author} (<a href={`https://codepen.io/${user}`}>@{user}</a>) on<a href="https://codepen.io">CodePen</a>.
26
- </span>
27
-
28
- <script async src="https://static.codepen.io/assets/embed/ei.js"></script>
29
- </div>