@splendidlabz/svelte 0.4.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 (153) hide show
  1. package/.eslintrc.cjs +3 -0
  2. package/CHANGELOG.md +91 -0
  3. package/actions/breakpoint-observer.js +71 -0
  4. package/actions/index.js +6 -0
  5. package/actions/portal.js +20 -0
  6. package/actions/resize-observer.js +43 -0
  7. package/actions/scroll-observer.js +47 -0
  8. package/common.js +21 -0
  9. package/components/Accordion/Accordion.svelte +108 -0
  10. package/components/Accordion/index.js +3 -0
  11. package/components/Breadcrumbs/Breadcrumbs.svelte +69 -0
  12. package/components/Breadcrumbs/Crumb.svelte +37 -0
  13. package/components/Breadcrumbs/CrumbCustom.svelte +14 -0
  14. package/components/Breadcrumbs/index.js +5 -0
  15. package/components/BrowserFrame.svelte +37 -0
  16. package/components/BrowserWithTabs.svelte +28 -0
  17. package/components/CQChecker/CQChecker.astro +20 -0
  18. package/components/CQChecker/CQChecker.svelte +89 -0
  19. package/components/Callout/Callout.svelte +17 -0
  20. package/components/Callout/index.js +3 -0
  21. package/components/Codepen/Codepen.astro +29 -0
  22. package/components/Codepen/Codepen.svelte +24 -0
  23. package/components/Codepen/index.js +3 -0
  24. package/components/ContentList/ContentList-old.svelte +117 -0
  25. package/components/ContentList/ContentList.svelte +68 -0
  26. package/components/ContentList/index.js +3 -0
  27. package/components/Disclosure/Drawer/Drawer.svelte +35 -0
  28. package/components/Disclosure/Drawer/DrawerCloseButton.svelte +31 -0
  29. package/components/Disclosure/Drawer/DrawerContent-wrecked.svelte +198 -0
  30. package/components/Disclosure/Drawer/DrawerContent.svelte +164 -0
  31. package/components/Disclosure/Drawer/DrawerTrigger.svelte +32 -0
  32. package/components/Disclosure/Drawer/drawer.js +112 -0
  33. package/components/Disclosure/Drawer/index.js +6 -0
  34. package/components/Disclosure/Dropdown/DropdownContent.svelte +15 -0
  35. package/components/Disclosure/Dropdown/DropdownTrigger.svelte +14 -0
  36. package/components/Disclosure/Dropdown/dropdown.js +4 -0
  37. package/components/Disclosure/Dropdown/index.js +4 -0
  38. package/components/Disclosure/Modal/ModalContent.svelte +3 -0
  39. package/components/Disclosure/Modal/ModalTrigger.svelte +33 -0
  40. package/components/Disclosure/Modal/exit-intent.js +17 -0
  41. package/components/Disclosure/Modal/modal.js +13 -0
  42. package/components/Disclosure/Popover/PopoverCloseButton.svelte +29 -0
  43. package/components/Disclosure/Popover/PopoverContent.svelte +107 -0
  44. package/components/Disclosure/Popover/PopoverTrigger.svelte +33 -0
  45. package/components/Disclosure/Popover/floating.js +171 -0
  46. package/components/Disclosure/Popover/index.js +5 -0
  47. package/components/Disclosure/Popover/popover.js +18 -0
  48. package/components/Disclosure/Popover/references/FollowTheMouse.svelte +45 -0
  49. package/components/Disclosure/Tooltip/Tooltip.svelte +14 -0
  50. package/components/Disclosure/Tooltip/TooltipContent.svelte +7 -0
  51. package/components/Disclosure/Tooltip/TooltipTrigger.svelte +33 -0
  52. package/components/Disclosure/Tooltip/index.js +5 -0
  53. package/components/Disclosure/Tooltip/tooltip.js +22 -0
  54. package/components/Disclosure/disclosure-store.js +48 -0
  55. package/components/Disclosure/disclosure.js +439 -0
  56. package/components/Disclosure/index.js +3 -0
  57. package/components/Disclosure/state.svelte.js +138 -0
  58. package/components/FancyList/FancyList.svelte +49 -0
  59. package/components/FancyList/index.js +3 -0
  60. package/components/Form/Button.svelte +24 -0
  61. package/components/Form/Checkbox.svelte +80 -0
  62. package/components/Form/Checkboxes.svelte +48 -0
  63. package/components/Form/Combobox/AutocompleteInput.svelte +63 -0
  64. package/components/Form/Combobox/AutocompleteOptions.svelte +74 -0
  65. package/components/Form/Combobox/TimepickerInput.svelte +81 -0
  66. package/components/Form/Combobox/TimepickerOptions.svelte +100 -0
  67. package/components/Form/Combobox/autocomplete-matching.js +114 -0
  68. package/components/Form/Combobox/autocomplete.js +393 -0
  69. package/components/Form/Combobox/combobox-store.js +65 -0
  70. package/components/Form/Combobox/combobox.js +359 -0
  71. package/components/Form/Combobox/index.js +14 -0
  72. package/components/Form/Combobox/timepicker.js +119 -0
  73. package/components/Form/Form.svelte +62 -0
  74. package/components/Form/Hidden.svelte +16 -0
  75. package/components/Form/Radio.svelte +69 -0
  76. package/components/Form/Radios.svelte +50 -0
  77. package/components/Form/Select.svelte +127 -0
  78. package/components/Form/Switch.svelte +50 -0
  79. package/components/Form/TextInput.svelte +87 -0
  80. package/components/Form/Textarea.svelte +103 -0
  81. package/components/Form/check.svg +3 -0
  82. package/components/Form/index.js +12 -0
  83. package/components/Highlight/Highlight.svelte +27 -0
  84. package/components/Highlight/_Highlight.scss +19 -0
  85. package/components/Highlight/index.js +2 -0
  86. package/components/Image.svelte +24 -0
  87. package/components/InteractiveRegion/InteractiveRegion.svelte +47 -0
  88. package/components/InteractiveRegion/index.js +3 -0
  89. package/components/List/Lia.svelte +12 -0
  90. package/components/List/NestedListItem.svelte +50 -0
  91. package/components/List/index.js +3 -0
  92. package/components/Markdown/Markdown.svelte +35 -0
  93. package/components/Masonry/Masonry.svelte +79 -0
  94. package/components/Masonry/index.js +3 -0
  95. package/components/PerspectiveHover/PerspectiveHover.svelte +10 -0
  96. package/components/PerspectiveHover/perspective-hover.js +46 -0
  97. package/components/Populate/ConditionalPopulate.svelte +33 -0
  98. package/components/Populate/Populate.svelte +45 -0
  99. package/components/Populate/actions.js +29 -0
  100. package/components/Populate/get-value.js +17 -0
  101. package/components/Populate/index.js +4 -0
  102. package/components/Portal.svelte +27 -0
  103. package/components/PushToLocalStorage.svelte +30 -0
  104. package/components/Resizer/Resizer.svelte +32 -0
  105. package/components/Resizer/draggable.js +23 -0
  106. package/components/Resizer/index.js +3 -0
  107. package/components/Resizer/resizer.js +133 -0
  108. package/components/SVG/SVG.svelte +120 -0
  109. package/components/Scrambler/Scrambler.svelte +27 -0
  110. package/components/Scrambler/index.js +3 -0
  111. package/components/Spotlight/PointerPosition.js +32 -0
  112. package/components/Spotlight/Spotlight.svelte +9 -0
  113. package/components/Status.svelte +27 -0
  114. package/components/Switcheroo/Switcheroo.svelte +71 -0
  115. package/components/Switcheroo/index.js +3 -0
  116. package/components/Table/RowGroup.svelte +8 -0
  117. package/components/Table/Table.svelte +23 -0
  118. package/components/Table/Td.svelte +20 -0
  119. package/components/Table/Th.svelte +27 -0
  120. package/components/Table/Thead.svelte +8 -0
  121. package/components/Table/Tr.svelte +8 -0
  122. package/components/Table/index.js +17 -0
  123. package/components/Table/table.js +35 -0
  124. package/components/Tabs/Tab.svelte +12 -0
  125. package/components/Tabs/Tablist.svelte +62 -0
  126. package/components/Tabs/Tabpanel.svelte +10 -0
  127. package/components/Tabs/Tabpanels.svelte +12 -0
  128. package/components/Tabs/index.js +6 -0
  129. package/components/Tabs/tab-store.js +60 -0
  130. package/components/Tabs/tabs.js +364 -0
  131. package/components/Tabs-Old/Tab.svelte +9 -0
  132. package/components/Tabs-Old/Tablist.svelte +13 -0
  133. package/components/Tabs-Old/Tabpanel.svelte +10 -0
  134. package/components/Tabs-Old/Tabpanels.svelte +14 -0
  135. package/components/Tabs-Old/Tabs.svelte +83 -0
  136. package/components/Tabs-Old/index.js +7 -0
  137. package/components/Tabs-Old/tabs.js +306 -0
  138. package/components/Textwall/Repeat.svelte +10 -0
  139. package/components/Textwall/Textwall.svelte +30 -0
  140. package/components/Textwall/index.js +4 -0
  141. package/components/Typewriter/Typewriter.svelte +70 -0
  142. package/components/Typewriter/index.js +3 -0
  143. package/components/Video.svelte +46 -0
  144. package/components/Vimeo.svelte +18 -0
  145. package/components/Wrapper.svelte +22 -0
  146. package/components/Youtube.svelte +15 -0
  147. package/components/_shared/accessibility.js +9 -0
  148. package/components/_shared/key.js +1 -0
  149. package/components/_shared/transitions.js +48 -0
  150. package/components/_shared/use-actions.js +31 -0
  151. package/index.js +35 -0
  152. package/jsconfig.json +5 -0
  153. package/package.json +39 -0
@@ -0,0 +1,79 @@
1
+ <script>
2
+ import { onMount } from 'svelte'
3
+ import { resizeObserver } from '../../actions'
4
+
5
+ let klass = ''
6
+ export { klass as class }
7
+
8
+ let container
9
+ let colGap
10
+ let items
11
+
12
+ onMount(async () => {
13
+ if (isMasonrySupported(container)) return
14
+
15
+ items = getChildren(container)
16
+ colGap = parseFloat(getComputedStyle(container).columnGap)
17
+ container.style.setProperty('row-gap', '1px', 'important')
18
+ container.style.gridAutoRows = '0px'
19
+
20
+ await Promise.all([areImagesLoaded(), areVideosLoaded()])
21
+
22
+ layout()
23
+ })
24
+
25
+ function isMasonrySupported(container) {
26
+ if (typeof window === 'undefined') return
27
+ return getComputedStyle(container).gridTemplateRows === 'masonry'
28
+ }
29
+
30
+ function getChildren(container) {
31
+ let children = container.children
32
+
33
+ // Compensate for Astro Slots
34
+ if (children[0]?.nodeName === 'ASTRO-SLOT') children = children[0].children
35
+ return Array.from(children)
36
+ }
37
+
38
+ async function areImagesLoaded() {
39
+ const images = Array.from(container.querySelectorAll('img'))
40
+ const promises = images.map(img => {
41
+ return new Promise((resolve, reject) => {
42
+ if (img.complete) return resolve()
43
+ img.onload = resolve
44
+ img.onerror = reject
45
+ })
46
+ })
47
+ return Promise.all(promises)
48
+ }
49
+
50
+ function areVideosLoaded() {
51
+ const videos = Array.from(container.querySelectorAll('video'))
52
+ const promises = videos.map(video => {
53
+ return new Promise((resolve, reject) => {
54
+ if (video.readyState === 4) return resolve() // HAVE_ENOUGH_DATA
55
+ video.onloadedmetadata = resolve
56
+ video.onerror = reject
57
+ })
58
+ })
59
+ return Promise.all(promises)
60
+ }
61
+
62
+ async function layout() {
63
+ if (isMasonrySupported(container)) return
64
+ items.forEach(item => {
65
+ const ib = item.getBoundingClientRect()
66
+ item.style.gridRowEnd = `span ${Math.round(ib.height + colGap)}`
67
+ })
68
+ }
69
+ </script>
70
+
71
+ <div
72
+ class="Masonry {klass}"
73
+ {...$$restProps}
74
+ bind:this={container}
75
+ use:resizeObserver
76
+ on:resize={layout}
77
+ >
78
+ <slot />
79
+ </div>
@@ -0,0 +1,3 @@
1
+ import Masonry from './Masonry.svelte'
2
+
3
+ export { Masonry }
@@ -0,0 +1,10 @@
1
+ <script>
2
+ import perspectiveHover from './perspective-hover.js'
3
+ let klass
4
+ export { klass as class }
5
+ </script>
6
+
7
+ <div class="PerspectiveHover {klass}" use:perspectiveHover>
8
+ <h1>Perspective Hover</h1>
9
+ <slot />
10
+ </div>
@@ -0,0 +1,46 @@
1
+ /* eslint-env browser */
2
+ // Maybe the sensitivity and perspective values can be written directly in Svelte so we don't have to use Custom Properties
3
+ export default function perspectiveHover(node) {
4
+ const computedStyle = getComputedStyle(node)
5
+ const sensitivity = computedStyle.getPropertyValue('--sensitivity')
6
+ const perspective = computedStyle.getPropertyValue('--perspective')
7
+ const transition = computedStyle.getPropertyValue('transition')
8
+
9
+ node.addEventListener('pointerout', leave)
10
+ node.addEventListener('pointermove', move)
11
+
12
+ function calculateRotationValues(event) {
13
+ const boundingRect = node.getBoundingClientRect()
14
+ const xCenter = boundingRect.left + boundingRect.width / 2
15
+ const yCenter = boundingRect.top + boundingRect.height / 2
16
+ const x = (event.clientX - xCenter) / boundingRect.width
17
+ const y = (event.clientY - yCenter) / boundingRect.height
18
+
19
+ // Calculation rotation values
20
+ const rotateX = y * -sensitivity + 'deg'
21
+ const rotateY = x * sensitivity + 'deg'
22
+
23
+ return { rotateX, rotateY }
24
+ }
25
+
26
+ // This event begins abruptly.
27
+ function move(event) {
28
+ const { rotateX, rotateY } = calculateRotationValues(event)
29
+
30
+ // Apply rotation values
31
+ node.style.transition = `none`
32
+ node.style.transform = `perspective(${perspective}) rotateX(${rotateX}) rotateY(${rotateY})`
33
+ }
34
+
35
+ function leave(event) {
36
+ node.style.transition = transition
37
+ node.style.transform = `perspective(${perspective}) rotateX(0) rotateY(0)`
38
+ }
39
+
40
+ return {
41
+ destroy() {
42
+ node.addEventListener('pointerout', leave)
43
+ node.addEventListener('pointermove', move)
44
+ },
45
+ }
46
+ }
@@ -0,0 +1,33 @@
1
+ <!--
2
+ Similar to Populate Component
3
+ Except this takes in a conditions object and returns the value that matches the condition.
4
+ -->
5
+ <script>
6
+ import { isEmpty } from '@splendidlabz/utils'
7
+ import { onMount } from 'svelte'
8
+ import { getValueFromBrowserStorage, getValueFromSource } from './get-value'
9
+
10
+ export let prop = ''
11
+ export let conditions = {}
12
+ export let source = {}
13
+
14
+ let value
15
+ const list = prop.split('.')
16
+
17
+ // If source is provided, draw from source
18
+ if (!isEmpty(source)) value = getValueFromSource({ source, list })
19
+
20
+ // If source is not provided, draw from localStorage, sessionstorage or query parameters (in this order) — in this case client:load is required.
21
+ if (isEmpty(source)) {
22
+ onMount(async _ => {
23
+ value = getValueFromBrowserStorage(list)
24
+ value = conditions[value]
25
+ })
26
+ }
27
+ </script>
28
+
29
+ {#if value}
30
+ {value}
31
+ {:else}
32
+ {conditions.fallback}
33
+ {/if}
@@ -0,0 +1,45 @@
1
+ <!--
2
+ /**
3
+ * @component Populate
4
+ *
5
+ * This component is used to fetch and display the value of a nested property from a given source object or from local/session storage.
6
+ *
7
+ * @prop {string} prop - A string representing the path to the nested property. The path should be dot-separated. For example, 'user.profile.name'.
8
+ * @prop {string} fallback - A fallback value to display if the nested property is not found or its value is falsy.
9
+ * @prop {Object} source - An object from which to fetch the nested property. If not provided, the component will try to fetch the property from local/session storage.
10
+ *
11
+ * @example
12
+ * <Populate prop="user.profile.name" fallback="friend" source={user} />
13
+ *
14
+ * In this example, the component will display the user's name if it exists. If the user's name is not found or its value is falsy, it will display 'N/A'.
15
+ */
16
+ -->
17
+
18
+ <script>
19
+ import { isEmpty } from '@splendidlabz/utils'
20
+ import { onMount } from 'svelte'
21
+ import { getValueFromBrowserStorage, getValueFromSource } from './get-value'
22
+
23
+ export let prop = ''
24
+ export let fallback = ''
25
+ export let source = {}
26
+
27
+ let value
28
+ const list = prop.split('.')
29
+
30
+ // If source is provided, draw from source
31
+ if (!isEmpty(source)) value = getValueFromSource({ source, list })
32
+
33
+ // If source is not provided, draw from localStorage, sessionstorage or query parameters (in this order) — in this case client:load is required.
34
+ if (isEmpty(source)) {
35
+ onMount(async _ => {
36
+ value = getValueFromBrowserStorage(list)
37
+ })
38
+ }
39
+ </script>
40
+
41
+ {#if value}
42
+ {value}
43
+ {:else}
44
+ {fallback}
45
+ {/if}
@@ -0,0 +1,29 @@
1
+ // Bind into <input> elements as the value — that's probably the only use case so far.
2
+ import { getValueFromBrowserStorage, getValueFromSource } from './get-value'
3
+
4
+ import { isEmpty } from '@splendidlabz/utils'
5
+
6
+ export function populate(node, options) {
7
+ const { prop = '', fallback = '', source = {} } = options
8
+ const list = prop.split('.')
9
+ let value
10
+
11
+ if (!isEmpty(source)) value = getValueFromSource({ source, list }) || fallback
12
+ if (isEmpty(source)) value = getValueFromBrowserStorage(list) || fallback
13
+
14
+ node.value = value
15
+ }
16
+
17
+ export function conditionalPopulate(node, options) {
18
+ const { prop = '', conditions = { fallback: '' }, source = {} } = options
19
+ const list = prop.split('.')
20
+ let value
21
+
22
+ if (!isEmpty(source)) value = getValueFromSource({ source, list })
23
+ if (isEmpty(source)) {
24
+ const tmp = getValueFromBrowserStorage(list)
25
+ value = conditions[tmp] || conditions.fallback
26
+ }
27
+
28
+ node.value = value
29
+ }
@@ -0,0 +1,17 @@
1
+ import { localStore, queryParams, sessionStore } from '@splendidlabz/utils/dom'
2
+
3
+ import { getNestedProperty } from '@splendidlabz/utils'
4
+
5
+ export function getValueFromSource({ source, list }) {
6
+ return getNestedProperty(source, list)
7
+ }
8
+
9
+ export function getValueFromBrowserStorage(list) {
10
+ const [storageKey, ...rest] = list
11
+ const storageValue =
12
+ localStore.get(storageKey) ||
13
+ sessionStore.get(storageKey) ||
14
+ queryParams.get(storageKey)
15
+
16
+ return getNestedProperty(storageValue, rest)
17
+ }
@@ -0,0 +1,4 @@
1
+ import ConditionalPopulate from './ConditionalPopulate.svelte'
2
+ import Populate from './Populate.svelte'
3
+
4
+ export { Populate, ConditionalPopulate }
@@ -0,0 +1,27 @@
1
+ <script>
2
+ import { onMount, onDestroy } from 'svelte'
3
+
4
+ let klass = ''
5
+ export { klass as class } // Allows you to specify portal class
6
+ export let target = null // CSS Selector
7
+
8
+ let portal
9
+ let portalParent
10
+
11
+ // There's a strange effect: When elements are portalled away, they lose the ability to use onclick and other Svelte related stuff
12
+ // Known problem: When moving elements with portals, event listeners on Svelte components stop working. To combat this, add a ref and then add event listeners accordingly.
13
+
14
+ onMount(() => {
15
+ portalParent = target ? document.querySelector(target) : document.body
16
+ portalParent.append(portal)
17
+ })
18
+
19
+ onDestroy(() => {
20
+ if (!portalParent) return
21
+ portalParent.removeChild(portal)
22
+ })
23
+ </script>
24
+
25
+ <div class="Portal {klass}" bind:this={portal} {...$$restProps}>
26
+ <slot />
27
+ </div>
@@ -0,0 +1,30 @@
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
+ <PushToLocalStorage
8
+ values={{
9
+ user: {
10
+ firstName: 'Zell',
11
+ email: '12345@gmail.com',
12
+ },
13
+ }}
14
+ client:idle
15
+ />
16
+ -->
17
+
18
+ <script>
19
+ import { isEmpty, objectForEach } from '@splendidlabz/utils'
20
+ import { localStore } from '@splendidlabz/utils/dom'
21
+ export let values = {}
22
+
23
+ store(values)
24
+
25
+ function store(values) {
26
+ if (typeof window === 'undefined') return
27
+ if (isEmpty(values)) return
28
+ objectForEach(values, ({ key, value }) => localStore.set(key, value))
29
+ }
30
+ </script>
@@ -0,0 +1,32 @@
1
+ <script>
2
+ import { resizer } from './resizer.js'
3
+
4
+ export let options = {}
5
+ const DEFAULT_OPTIONS = {
6
+ direction: 'horizontal', // horizontal | vertical
7
+ placement: 'right', // Only works for right and bottom.
8
+ target: null,
9
+ minWidth: 0,
10
+ minHeight: 0,
11
+ canExceedOriginal: false,
12
+ }
13
+
14
+ // Notes:
15
+ // - Tricky to get 'left' to work because it requires logical CSS positioning properties which may not be used to create the element.
16
+ // - Tricky to get 'top' to work because it requires element to be bottom-fixed so top can be adjustable.
17
+
18
+ options = Object.assign({}, DEFAULT_OPTIONS, options)
19
+ const { direction, placement } = options
20
+ </script>
21
+
22
+ <div
23
+ class="Resizer"
24
+ class:Resizer-horizontal={direction === 'horizontal'}
25
+ class:Resizer-vertical={direction === 'vertical'}
26
+ class:Resizer-right={placement === 'right'}
27
+ class:Resizer-bottom={placement === 'bottom'}
28
+ use:resizer={options}
29
+ ></div>
30
+
31
+ <!-- class:Resizer-top={placement === 'top'}
32
+ class:Resizer-left={placement === 'left'} -->
@@ -0,0 +1,23 @@
1
+ export default function draggable(node, options) {
2
+ node.addEventListener('pointerdown', handlePointerDown)
3
+ node.addEventListener('pointermove', handlePointerMove)
4
+ node.addEventListener('pointerup', handlePointerUp)
5
+
6
+ function handlePointerDown(event) {}
7
+
8
+ function handlePointerMove(event) {}
9
+
10
+ function handlePointerUp(event) {}
11
+
12
+ return {
13
+ destroy() {
14
+ node.removeEventListener('pointerdown', handlePointerDown)
15
+ node.removeEventListener('pointermove', handlePointerMove)
16
+ node.removeEventListener('pointerup', handlePointerUp)
17
+ },
18
+ }
19
+ }
20
+
21
+ // function dispatchEvent(node, { name, detail }) {
22
+ // node.dispatchEvent(new CustomEvent(name, { detail }))
23
+ // }
@@ -0,0 +1,3 @@
1
+ import Resizer from './Resizer.svelte'
2
+
3
+ export { Resizer }
@@ -0,0 +1,133 @@
1
+ import { addListeners, removeListeners, toPx } from '@splendidlabz/utils/dom'
2
+
3
+ export function resizer(node, options) {
4
+ const elementToResize = options.target
5
+ ? node.closest(options.target)
6
+ : node.parentElement
7
+
8
+ const box = elementToResize.getBoundingClientRect()
9
+
10
+ const state = {
11
+ pointerId: null,
12
+ resizing: false,
13
+ prevX: 0,
14
+ prevY: 0,
15
+ widths: {
16
+ min: toPx(options.minWidth),
17
+ max: options.maxWidth && toPx(options.maxWidth),
18
+ current: box.width,
19
+ original: box.width,
20
+ },
21
+ heights: {
22
+ min: toPx(options.minHeight),
23
+ max: options.maxHeight && toPx(options.maxHeight),
24
+ current: box.height,
25
+ original: box.height,
26
+ },
27
+ }
28
+
29
+ const listeners = [
30
+ {
31
+ node,
32
+ event: 'pointerdown',
33
+ handler: handlePointerDown,
34
+ },
35
+ {
36
+ node,
37
+ event: 'pointermove',
38
+ handler: handlePointerMove,
39
+ },
40
+ {
41
+ node,
42
+ event: 'pointerup',
43
+ handler: handlePointerUp,
44
+ },
45
+ {
46
+ node,
47
+ event: 'pointerleave',
48
+ handler: handlePointerUp,
49
+ },
50
+ ]
51
+
52
+ addListeners(listeners)
53
+
54
+ function handlePointerDown(event) {
55
+ const { x, y, pointerId } = event
56
+ state.resizing = true
57
+ state.prevX = x
58
+ state.prevY = y
59
+ state.pointerId = pointerId
60
+ node.setPointerCapture(pointerId)
61
+ }
62
+
63
+ function handlePointerMove(event) {
64
+ if (!state.resizing) return
65
+ const { direction, canExceedOriginal } = options
66
+ const { x, y } = event
67
+ const deltaX = x - state.prevX
68
+ const deltaY = y - state.prevY
69
+
70
+ const {
71
+ current: currentWidth,
72
+ min: minWidth,
73
+ max: maxWidth,
74
+ original: originalWidth,
75
+ } = state.widths
76
+
77
+ const {
78
+ current: currentHeight,
79
+ min: minHeight,
80
+ max: maxHeight,
81
+ original: originalHeight,
82
+ } = state.heights
83
+
84
+ if (direction === 'horizontal') {
85
+ const newWidth = currentWidth + deltaX
86
+ switch (true) {
87
+ case newWidth < minWidth:
88
+ elementToResize.style.width = `${minWidth}px`
89
+ break
90
+ case maxWidth && newWidth > maxWidth:
91
+ elementToResize.style.width = `${maxWidth}px`
92
+ break
93
+ case !canExceedOriginal && newWidth > originalWidth:
94
+ elementToResize.style.width = `${originalWidth}px`
95
+ break
96
+ default:
97
+ elementToResize.style.width = `${newWidth}px`
98
+ break
99
+ }
100
+ }
101
+
102
+ if (direction === 'vertical') {
103
+ const newHeight = currentHeight + deltaY
104
+ switch (true) {
105
+ case newHeight < minHeight:
106
+ elementToResize.style.height = `${minHeight}px`
107
+ break
108
+ case maxHeight && newHeight > maxHeight:
109
+ elementToResize.style.height = `${maxHeight}px`
110
+ break
111
+ case !canExceedOriginal && newHeight > originalHeight:
112
+ elementToResize.style.width = `${originalHeight}px`
113
+ break
114
+ default:
115
+ elementToResize.style.height = `${newHeight}px`
116
+ }
117
+ }
118
+ }
119
+
120
+ function handlePointerUp(event) {
121
+ const { width, height } = elementToResize.getBoundingClientRect()
122
+ state.widths.current = width
123
+ state.heights.current = height
124
+ state.resizing = false
125
+ if (state.pointerId) node.releasePointerCapture(state.pointerId)
126
+ }
127
+
128
+ return {
129
+ destroy() {
130
+ removeListeners(listeners)
131
+ },
132
+ }
133
+ }
@@ -0,0 +1,120 @@
1
+ <script>
2
+ import { getIcon, loadIcon } from '@iconify/svelte'
3
+ import { toStyleString } from '@splendidlabz/utils'
4
+ import { parse } from 'node-html-parser'
5
+ import { onMount } from 'svelte'
6
+
7
+ export let icon
8
+ export let name = ''
9
+ export let style = ''
10
+
11
+ if (typeof style === 'object') style = toStyleString(style)
12
+
13
+ // TODO: Add aria-hidden by default
14
+ let iconify
15
+ let iconData
16
+ let innerHTML
17
+ let attributes = {
18
+ role: 'img',
19
+ xmlns: 'http://www.w3.org/2000/svg',
20
+ ...$$restProps,
21
+ }
22
+
23
+ icon = icon || name
24
+ icon = icon.trim() // Remove whitespace
25
+
26
+ if (name) console.log('name is deprecated. Please change to icon')
27
+
28
+ // If there is an icon set, we use Iconify.
29
+ // This stores the icon in localStorage after loading it for the first time. Subsequent loads will use the localStorage cached version.
30
+ if (icon.includes(':')) {
31
+ iconify = true
32
+
33
+ attributes = {
34
+ width: '1em',
35
+ height: '1em',
36
+ ...attributes,
37
+ class: `${icon.split(':')[1]} ${attributes.class || ''}`,
38
+ style,
39
+ }
40
+
41
+ // Populates icon data if the icon is in cache
42
+ iconData = getIcon(icon)
43
+
44
+ // If icon is not in cache, loads the icon from Iconify
45
+ if (!iconData) onMount(async _ => (iconData = await loadIcon(icon)))
46
+ }
47
+
48
+ $: if (iconData) {
49
+ attributes.viewBox = `0 0 ${iconData.width} ${iconData.height}`
50
+ innerHTML = iconData.body
51
+ }
52
+
53
+ // Otherwise we grab the SVG from the src folder
54
+ if (!iconify) {
55
+ const files = {
56
+ ...import.meta.glob('/src/**/*.svg', {
57
+ eager: true,
58
+ query: 'raw',
59
+ }),
60
+ ...import.meta.glob('/public/**/*.svg', {
61
+ eager: true,
62
+ query: 'raw',
63
+ }),
64
+ }
65
+
66
+ // Find the SVG
67
+ const file = Object.keys(files).find(file => {
68
+ const basename = file.split('/').pop()
69
+ return basename === `${icon}.svg`
70
+ })
71
+
72
+ if (!file) {
73
+ throw new Error(`${icon}.svg not found`)
74
+ }
75
+
76
+ const root = parse(files[file].default)
77
+ const svg = root.querySelector('svg')
78
+ innerHTML = svg.childNodes.join('')
79
+
80
+ // If SVG is missing width, height, or viewbox, add them
81
+ const svgAttributes = svg.attributes
82
+ const { width, height, viewBox } = svgAttributes
83
+
84
+ if ((!width || !height) && !viewBox) {
85
+ throw new Error(
86
+ `SVG ${icon} must contain a width, height, or viewBox attribute`,
87
+ )
88
+ }
89
+
90
+ if (!width || !height) {
91
+ const [viewBoxWidth, viewBoxHeight] = viewBox.split(' ').slice(2)
92
+ svgAttributes.width = viewBoxWidth
93
+ svgAttributes.height = viewBoxHeight
94
+ }
95
+
96
+ if (!viewBox) {
97
+ svgAttributes.viewBox = `0 0 ${width} ${height}`
98
+ }
99
+
100
+ // Arrange attributes
101
+ attributes = {
102
+ ...svgAttributes,
103
+ ...attributes,
104
+ class: `${svg.classNames} ${$$restProps.class || ''}`,
105
+ style,
106
+ }
107
+ }
108
+ </script>
109
+
110
+ {#if iconify}
111
+ {#if innerHTML}
112
+ <svg {...attributes}> {@html innerHTML} </svg>
113
+ {:else}
114
+ <svg {...attributes} />
115
+ {/if}
116
+ {/if}
117
+
118
+ {#if !iconify}
119
+ <svg {...attributes}> {@html innerHTML} </svg>
120
+ {/if}
@@ -0,0 +1,27 @@
1
+ <script>
2
+ import { traverseAndScramble } from '@splendidlabz/utils/dom'
3
+ import { onMount } from 'svelte'
4
+
5
+ let klass = null
6
+ export { klass as class }
7
+ export let style = null
8
+ export let options = {}
9
+
10
+ let ref
11
+ if (!klass && !style) style = 'display: contents;'
12
+
13
+ onMount(_ => {
14
+ if (typeof window === 'undefined') return
15
+ let elements = Array.from(ref.querySelectorAll('*'))
16
+
17
+ // Scramble text while retaining HTML structure
18
+ // Pass options.excludes as an argument to traverseAndScramble
19
+ elements.forEach(el =>
20
+ traverseAndScramble(el, { excludes: options.excludes }),
21
+ )
22
+ })
23
+ </script>
24
+
25
+ <div class={klass} {style} bind:this={ref}>
26
+ <slot />
27
+ </div>
@@ -0,0 +1,3 @@
1
+ import Scrambler from './Scrambler.svelte'
2
+
3
+ export { Scrambler }