@quaffui/quaff 0.1.0-prealpha16 → 0.1.0-prealpha19

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 (269) hide show
  1. package/README.md +6 -6
  2. package/dist/classes/QContext.svelte.d.ts +42 -0
  3. package/dist/classes/QContext.svelte.js +63 -0
  4. package/dist/classes/QScrollObserver.svelte.d.ts +44 -0
  5. package/dist/classes/QScrollObserver.svelte.js +95 -0
  6. package/dist/classes/QTheme.svelte.d.ts +11 -0
  7. package/dist/classes/QTheme.svelte.js +49 -0
  8. package/dist/classes/Quaff.svelte.d.ts +14 -0
  9. package/dist/classes/Quaff.svelte.js +35 -0
  10. package/dist/components/avatar/QAvatar.scss +97 -0
  11. package/dist/components/avatar/QAvatar.svelte +35 -60
  12. package/dist/components/avatar/QAvatar.svelte.d.ts +2 -25
  13. package/dist/components/avatar/docs.props.js +21 -5
  14. package/dist/components/avatar/index.scss +5 -3
  15. package/dist/components/avatar/props.d.ts +24 -7
  16. package/dist/components/breadcrumbs/QBreadcrumbs.scss +10 -0
  17. package/dist/components/breadcrumbs/QBreadcrumbs.svelte +24 -9
  18. package/dist/components/breadcrumbs/QBreadcrumbs.svelte.d.ts +2 -22
  19. package/dist/components/breadcrumbs/QBreadcrumbsEl.scss +10 -0
  20. package/dist/components/breadcrumbs/QBreadcrumbsEl.svelte +64 -38
  21. package/dist/components/breadcrumbs/QBreadcrumbsEl.svelte.d.ts +2 -25
  22. package/dist/components/breadcrumbs/docs.props.js +27 -27
  23. package/dist/components/breadcrumbs/props.d.ts +25 -24
  24. package/dist/components/button/QBtn.scss +133 -0
  25. package/dist/components/button/QBtn.svelte +88 -48
  26. package/dist/components/button/QBtn.svelte.d.ts +2 -33
  27. package/dist/components/button/docs.props.js +26 -18
  28. package/dist/components/button/props.d.ts +21 -15
  29. package/dist/components/card/QCard.scss +25 -0
  30. package/dist/components/card/QCard.svelte +25 -16
  31. package/dist/components/card/QCard.svelte.d.ts +2 -25
  32. package/dist/components/card/QCardActions.scss +10 -0
  33. package/dist/components/card/QCardActions.svelte +11 -8
  34. package/dist/components/card/QCardActions.svelte.d.ts +2 -21
  35. package/dist/components/card/QCardSection.scss +10 -0
  36. package/dist/components/card/QCardSection.svelte +8 -6
  37. package/dist/components/card/QCardSection.svelte.d.ts +2 -22
  38. package/dist/components/card/docs.props.js +6 -14
  39. package/dist/components/card/props.d.ts +9 -15
  40. package/dist/components/checkbox/QCheckbox.svelte +8 -3
  41. package/dist/components/checkbox/QCheckbox.svelte.d.ts +2 -20
  42. package/dist/components/checkbox/docs.props.js +1 -1
  43. package/dist/components/checkbox/index.scss +3 -1
  44. package/dist/components/checkbox/props.d.ts +1 -2
  45. package/dist/components/chip/QChip.scss +179 -0
  46. package/dist/components/chip/QChip.svelte +95 -70
  47. package/dist/components/chip/QChip.svelte.d.ts +2 -35
  48. package/dist/components/chip/docs.props.js +23 -47
  49. package/dist/components/chip/props.d.ts +21 -34
  50. package/dist/components/codeBlock/QCodeBlock.svelte +64 -42
  51. package/dist/components/codeBlock/QCodeBlock.svelte.d.ts +2 -20
  52. package/dist/components/codeBlock/docs.props.js +10 -2
  53. package/dist/components/codeBlock/props.d.ts +6 -1
  54. package/dist/components/dialog/{index.scss → QDialog.scss} +9 -7
  55. package/dist/components/dialog/QDialog.svelte +72 -70
  56. package/dist/components/dialog/QDialog.svelte.d.ts +6 -36
  57. package/dist/components/dialog/docs.props.d.ts +0 -8
  58. package/dist/components/dialog/docs.props.js +1 -131
  59. package/dist/components/dialog/props.d.ts +0 -16
  60. package/dist/components/drawer/QDrawer.scss +45 -0
  61. package/dist/components/drawer/QDrawer.svelte +87 -91
  62. package/dist/components/drawer/QDrawer.svelte.d.ts +6 -32
  63. package/dist/components/drawer/docs.props.js +3 -3
  64. package/dist/components/drawer/props.d.ts +2 -2
  65. package/dist/components/footer/QFooter.scss +42 -0
  66. package/dist/components/footer/QFooter.svelte +62 -23
  67. package/dist/components/footer/QFooter.svelte.d.ts +2 -23
  68. package/dist/components/footer/docs.props.js +14 -6
  69. package/dist/components/footer/props.d.ts +8 -5
  70. package/dist/components/header/QHeader.scss +54 -0
  71. package/dist/components/header/QHeader.svelte +52 -24
  72. package/dist/components/header/QHeader.svelte.d.ts +2 -23
  73. package/dist/components/header/docs.props.js +23 -7
  74. package/dist/components/header/props.d.ts +11 -3
  75. package/dist/components/icon/{index.scss → QIcon.scss} +2 -4
  76. package/dist/components/icon/QIcon.svelte +29 -16
  77. package/dist/components/icon/QIcon.svelte.d.ts +2 -27
  78. package/dist/components/icon/docs.props.js +3 -3
  79. package/dist/components/icon/props.d.ts +4 -4
  80. package/dist/components/index.d.ts +2 -2
  81. package/dist/components/index.js +2 -2
  82. package/dist/components/input/QInput.svelte +52 -25
  83. package/dist/components/input/QInput.svelte.d.ts +2 -32
  84. package/dist/components/input/docs.props.js +33 -1
  85. package/dist/components/input/props.d.ts +5 -12
  86. package/dist/components/input/props.js +1 -12
  87. package/dist/components/layout/QLayout.scss +178 -0
  88. package/dist/components/layout/QLayout.svelte +100 -80
  89. package/dist/components/layout/QLayout.svelte.d.ts +16 -43
  90. package/dist/components/layout/docs.props.js +57 -1
  91. package/dist/components/layout/props.d.ts +8 -0
  92. package/dist/components/list/QItem.scss +61 -0
  93. package/dist/components/list/QItem.svelte +65 -46
  94. package/dist/components/list/QItem.svelte.d.ts +2 -30
  95. package/dist/components/list/QItemSection.scss +45 -0
  96. package/dist/components/list/QItemSection.svelte +48 -33
  97. package/dist/components/list/QItemSection.svelte.d.ts +2 -24
  98. package/dist/components/list/QList.scss +30 -0
  99. package/dist/components/list/QList.svelte +25 -14
  100. package/dist/components/list/QList.svelte.d.ts +2 -28
  101. package/dist/components/list/docs.props.js +36 -4
  102. package/dist/components/list/props.d.ts +9 -8
  103. package/dist/components/list/props.js +1 -25
  104. package/dist/components/private/ContextReseter.svelte +6 -11
  105. package/dist/components/private/ContextReseter.svelte.d.ts +6 -18
  106. package/dist/components/private/QApi.svelte +117 -103
  107. package/dist/components/private/QApi.svelte.d.ts +4 -16
  108. package/dist/components/private/QDocs.svelte +67 -48
  109. package/dist/components/private/QDocs.svelte.d.ts +9 -20
  110. package/dist/components/private/QDocsSection.svelte +15 -14
  111. package/dist/components/private/QDocsSection.svelte.d.ts +7 -19
  112. package/dist/components/private/QIconSnippet.svelte +12 -0
  113. package/dist/components/private/QIconSnippet.svelte.d.ts +8 -0
  114. package/dist/components/progress/QCircularProgress.scss +63 -0
  115. package/dist/components/progress/QCircularProgress.svelte +104 -28
  116. package/dist/components/progress/QCircularProgress.svelte.d.ts +2 -22
  117. package/dist/components/progress/QLinearProgress.scss +75 -0
  118. package/dist/components/progress/QLinearProgress.svelte +55 -13
  119. package/dist/components/progress/QLinearProgress.svelte.d.ts +2 -20
  120. package/dist/components/progress/docs.props.js +138 -10
  121. package/dist/components/progress/props.d.ts +75 -12
  122. package/dist/components/radio/QRadio.svelte +14 -3
  123. package/dist/components/radio/QRadio.svelte.d.ts +2 -21
  124. package/dist/components/radio/docs.props.js +1 -1
  125. package/dist/components/radio/index.scss +3 -1
  126. package/dist/components/radio/props.d.ts +1 -3
  127. package/dist/components/radio/props.js +1 -8
  128. package/dist/components/railbar/QRailbar.scss +54 -0
  129. package/dist/components/railbar/QRailbar.svelte +43 -66
  130. package/dist/components/railbar/QRailbar.svelte.d.ts +2 -22
  131. package/dist/components/railbar/docs.props.js +4 -4
  132. package/dist/components/railbar/props.d.ts +3 -3
  133. package/dist/components/select/QSelect.svelte +121 -88
  134. package/dist/components/select/QSelect.svelte.d.ts +2 -34
  135. package/dist/components/select/docs.js +7 -0
  136. package/dist/components/select/docs.props.js +41 -1
  137. package/dist/components/select/index.scss +8 -6
  138. package/dist/components/select/props.d.ts +6 -12
  139. package/dist/components/select/props.js +1 -12
  140. package/dist/components/separator/QSeparator.scss +54 -0
  141. package/dist/components/separator/QSeparator.svelte +38 -45
  142. package/dist/components/separator/QSeparator.svelte.d.ts +2 -24
  143. package/dist/components/separator/docs.props.js +4 -4
  144. package/dist/components/separator/props.d.ts +5 -7
  145. package/dist/components/separator/props.js +1 -9
  146. package/dist/components/switch/QSwitch.scss +305 -0
  147. package/dist/components/switch/QSwitch.svelte +96 -0
  148. package/dist/components/switch/QSwitch.svelte.d.ts +3 -0
  149. package/dist/components/{toggle → switch}/docs.d.ts +1 -1
  150. package/dist/components/{toggle → switch}/docs.js +3 -3
  151. package/dist/components/{toggle → switch}/docs.props.d.ts +1 -1
  152. package/dist/components/{toggle → switch}/docs.props.js +30 -6
  153. package/dist/components/switch/props.d.ts +13 -0
  154. package/dist/components/switch/props.js +1 -0
  155. package/dist/components/table/QTable.svelte +99 -85
  156. package/dist/components/table/QTable.svelte.d.ts +3 -29
  157. package/dist/components/table/docs.props.js +9 -1
  158. package/dist/components/table/index.scss +3 -1
  159. package/dist/components/table/props.d.ts +10 -0
  160. package/dist/components/tabs/QTab.scss +71 -0
  161. package/dist/components/tabs/QTab.svelte +74 -90
  162. package/dist/components/tabs/QTab.svelte.d.ts +2 -25
  163. package/dist/components/tabs/QTabs.scss +40 -0
  164. package/dist/components/tabs/QTabs.svelte +110 -58
  165. package/dist/components/tabs/QTabs.svelte.d.ts +6 -31
  166. package/dist/components/tabs/docs.props.js +3 -3
  167. package/dist/components/tabs/index.scss +4 -2
  168. package/dist/components/tabs/props.d.ts +5 -4
  169. package/dist/components/toolbar/QToolbar.svelte +15 -12
  170. package/dist/components/toolbar/QToolbar.svelte.d.ts +2 -23
  171. package/dist/components/toolbar/QToolbarTitle.svelte +8 -7
  172. package/dist/components/toolbar/QToolbarTitle.svelte.d.ts +2 -21
  173. package/dist/components/toolbar/docs.props.js +4 -4
  174. package/dist/components/toolbar/index.scss +12 -14
  175. package/dist/components/toolbar/props.d.ts +4 -5
  176. package/dist/components/tooltip/QTooltip.svelte +5 -9
  177. package/dist/components/tooltip/QTooltip.svelte.d.ts +2 -21
  178. package/dist/components/tooltip/docs.props.js +1 -1
  179. package/dist/components/tooltip/index.scss +3 -1
  180. package/dist/components/tooltip/props.d.ts +1 -1
  181. package/dist/composables/index.d.ts +1 -1
  182. package/dist/composables/index.js +1 -1
  183. package/dist/composables/useSize.d.ts +10 -9
  184. package/dist/composables/useSize.js +32 -20
  185. package/dist/composables/useSizeLegacy.d.ts +9 -0
  186. package/dist/composables/useSizeLegacy.js +25 -0
  187. package/dist/css/_components.scss +31 -0
  188. package/dist/css/_disabled.scss +18 -0
  189. package/dist/css/{ripple.scss → _ripple.scss} +1 -1
  190. package/dist/css/_variables.scss +73 -0
  191. package/dist/css/classes/_design.scss +57 -0
  192. package/dist/css/classes/_flex.scss +62 -0
  193. package/dist/css/classes/_grid.scss +35 -0
  194. package/dist/css/classes/_index.scss +7 -0
  195. package/dist/css/classes/_overflow.scss +7 -0
  196. package/dist/css/classes/_position.scss +7 -0
  197. package/dist/css/classes/_select.scss +6 -0
  198. package/dist/css/classes/_spaces.scss +23 -0
  199. package/dist/css/index.css +1 -1
  200. package/dist/css/index.scss +15 -94
  201. package/dist/css/mixins/_design.scss +63 -0
  202. package/dist/css/mixins/{field-mixins.scss → _field.scss} +16 -5
  203. package/dist/css/mixins/_image.scss +63 -0
  204. package/dist/css/mixins/_index.scss +9 -0
  205. package/dist/css/mixins/_layout.scss +20 -0
  206. package/dist/css/mixins/{menu.scss → _menu.scss} +4 -2
  207. package/dist/css/mixins/{selection.scss → _selection.scss} +7 -67
  208. package/dist/css/mixins/_spaces.scss +36 -0
  209. package/dist/css/mixins/_typography.scss +7 -0
  210. package/dist/css/shared/q-field.scss +62 -32
  211. package/dist/css/theme/_colors.scss +173 -0
  212. package/dist/css/theme/css-variables.scss +5 -0
  213. package/dist/css/theme/page.scss +3 -3
  214. package/dist/css/theme/reset.scss +17 -1
  215. package/dist/css/theme/theme.scss +2 -3
  216. package/dist/css/theme/tokens.scss +0 -159
  217. package/dist/helpers/clickOutside.js +2 -1
  218. package/dist/helpers/ripple.d.ts +1 -1
  219. package/dist/helpers/ripple.js +13 -4
  220. package/dist/helpers/version.d.ts +1 -1
  221. package/dist/helpers/version.js +1 -1
  222. package/dist/index.d.ts +2 -1
  223. package/dist/index.js +2 -1
  224. package/dist/stores/index.d.ts +0 -2
  225. package/dist/stores/index.js +1 -2
  226. package/dist/utils/colors.d.ts +71 -0
  227. package/dist/utils/colors.js +101 -14
  228. package/dist/utils/dom.d.ts +2 -0
  229. package/dist/utils/dom.js +6 -0
  230. package/dist/utils/number.d.ts +2 -0
  231. package/dist/utils/number.js +9 -0
  232. package/dist/utils/props.js +3 -1
  233. package/dist/utils/router.d.ts +17 -0
  234. package/dist/utils/router.js +23 -0
  235. package/dist/utils/string.d.ts +1 -0
  236. package/dist/utils/string.js +3 -0
  237. package/dist/utils/types.d.ts +6 -1
  238. package/dist/utils/types.js +0 -3
  239. package/dist/utils/types.json +8 -5
  240. package/dist/utils/watchable.d.ts +0 -1
  241. package/package.json +40 -37
  242. package/dist/components/breadcrumbs/index.scss +0 -20
  243. package/dist/components/button/index.scss +0 -103
  244. package/dist/components/card/index.scss +0 -56
  245. package/dist/components/chip/index.scss +0 -103
  246. package/dist/components/drawer/index.scss +0 -59
  247. package/dist/components/footer/index.scss +0 -28
  248. package/dist/components/layout/index.scss +0 -387
  249. package/dist/components/list/index.scss +0 -144
  250. package/dist/components/progress/index.scss +0 -82
  251. package/dist/components/railbar/index.scss +0 -39
  252. package/dist/components/separator/index.scss +0 -52
  253. package/dist/components/toggle/QToggle.svelte +0 -34
  254. package/dist/components/toggle/QToggle.svelte.d.ts +0 -23
  255. package/dist/components/toggle/index.scss +0 -31
  256. package/dist/components/toggle/props.d.ts +0 -9
  257. package/dist/components/toggle/props.js +0 -9
  258. package/dist/css/grid.scss +0 -50
  259. package/dist/css/mixins.scss +0 -137
  260. package/dist/css/states.scss +0 -75
  261. package/dist/css/theme/bridge.scss +0 -15
  262. package/dist/css/theme/theme.dark.scss +0 -39
  263. package/dist/css/theme/theme.light.scss +0 -39
  264. package/dist/css/variables-sass.scss +0 -16
  265. package/dist/stores/QTheme.d.ts +0 -42
  266. package/dist/stores/QTheme.js +0 -59
  267. package/dist/stores/Quaff.d.ts +0 -32
  268. package/dist/stores/Quaff.js +0 -58
  269. /package/dist/css/mixins/{table.scss → _table.scss} +0 -0
package/README.md CHANGED
@@ -6,13 +6,13 @@ Quaff is an experimental project utilizing [Beer CSS](https://www.beercss.com/)
6
6
 
7
7
  ## Developing
8
8
 
9
- Once you've installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
9
+ Once you've installed dependencies with `bun install`, start a development server:
10
10
 
11
11
  ```bash
12
- npm run dev
12
+ bun run dev
13
13
 
14
14
  # or start the server and open the app in a new browser tab
15
- npm run dev -- --open
15
+ bun run dev -- --open
16
16
  ```
17
17
 
18
18
  Everything inside `src/lib` is part of the library, everything inside `src/routes` can be used as a showcase or preview app.
@@ -22,16 +22,16 @@ Everything inside `src/lib` is part of the library, everything inside `src/route
22
22
  To build the library:
23
23
 
24
24
  ```bash
25
- npm run package
25
+ bun run package
26
26
  ```
27
27
 
28
28
  To create a production version of your showcase app:
29
29
 
30
30
  ```bash
31
- npm run build
31
+ bun run build
32
32
  ```
33
33
 
34
- You can preview the production build with `npm run preview`.
34
+ You can preview the production build with `bun run preview`.
35
35
 
36
36
  > To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.
37
37
 
@@ -0,0 +1,42 @@
1
+ /**
2
+ * This class allows to manipulate reactive contexts more easily.
3
+ * It avoids having to pass a Svelte store down the components but rather use runes to keep the context reactive.
4
+ *
5
+ * This class should be used when the context has to be modified from a child component. Otherwise, using svelte's context API should be enough.
6
+ */
7
+ export default class QContext<T> {
8
+ #private;
9
+ constructor(contextName: string, init: T);
10
+ /**
11
+ * Gets the value of context with id `contextName`
12
+ * @param contextName - Name of the context to get
13
+ * @returns The context's value
14
+ */
15
+ static get<T>(contextName: string): QContext<T> | undefined;
16
+ /**
17
+ * Prevents the propagation of the context further down
18
+ * @param contextName - Name of the context to get
19
+ * @returns The context result
20
+ */
21
+ static reset(contextName: string): void;
22
+ /**
23
+ * Updates the context's inner value with `newVal`
24
+ * @param newVal - New value to update the context with
25
+ */
26
+ update(newVal: T): void;
27
+ /**
28
+ * Updates the property of id `key` with `newVal` in the context's inner value
29
+ * @param key - Key to update
30
+ * @param newVal - New value to update the context's property with
31
+ */
32
+ updateEntry(key: keyof T, newVal: NonNullable<T>[keyof T]): void;
33
+ /**
34
+ * Updates the given properties their corresponding values in the context's inner value
35
+ * @param from - Object containing keys to update with their respective value
36
+ */
37
+ updateEntries(from: Record<keyof T, NonNullable<T>[keyof T]>): void;
38
+ /**
39
+ * Inner value of the context
40
+ */
41
+ get value(): T;
42
+ }
@@ -0,0 +1,63 @@
1
+ import { getContext, setContext } from "svelte";
2
+ /**
3
+ * This class allows to manipulate reactive contexts more easily.
4
+ * It avoids having to pass a Svelte store down the components but rather use runes to keep the context reactive.
5
+ *
6
+ * This class should be used when the context has to be modified from a child component. Otherwise, using svelte's context API should be enough.
7
+ */
8
+ export default class QContext {
9
+ #state = $state();
10
+ constructor(contextName, init) {
11
+ this.#state = init;
12
+ setContext(contextName, this);
13
+ }
14
+ /**
15
+ * Gets the value of context with id `contextName`
16
+ * @param contextName - Name of the context to get
17
+ * @returns The context's value
18
+ */
19
+ static get(contextName) {
20
+ return getContext(contextName);
21
+ }
22
+ /**
23
+ * Prevents the propagation of the context further down
24
+ * @param contextName - Name of the context to get
25
+ * @returns The context result
26
+ */
27
+ static reset(contextName) {
28
+ setContext(contextName, undefined);
29
+ }
30
+ /**
31
+ * Updates the context's inner value with `newVal`
32
+ * @param newVal - New value to update the context with
33
+ */
34
+ update(newVal) {
35
+ this.#state = newVal;
36
+ }
37
+ /**
38
+ * Updates the property of id `key` with `newVal` in the context's inner value
39
+ * @param key - Key to update
40
+ * @param newVal - New value to update the context's property with
41
+ */
42
+ updateEntry(key, newVal) {
43
+ if (!this.#state || typeof this.#state !== "object" || !Object.hasOwn(this.#state, key)) {
44
+ throw new Error(`${key.toString()} doesn't exist on ${this.#state}`);
45
+ }
46
+ this.#state[key] = newVal;
47
+ }
48
+ /**
49
+ * Updates the given properties their corresponding values in the context's inner value
50
+ * @param from - Object containing keys to update with their respective value
51
+ */
52
+ updateEntries(from) {
53
+ for (const key in from) {
54
+ this.updateEntry(key, from[key]);
55
+ }
56
+ }
57
+ /**
58
+ * Inner value of the context
59
+ */
60
+ get value() {
61
+ return this.#state;
62
+ }
63
+ }
@@ -0,0 +1,44 @@
1
+ type Direction = "up" | "right" | "down" | "left";
2
+ type WindowScrollType = "scrollX" | "scrollY";
3
+ type DocumentScrollType = "scrollLeft" | "scrollTop";
4
+ type ScrollType = {
5
+ window: WindowScrollType;
6
+ document: DocumentScrollType;
7
+ };
8
+ type Target = HTMLDivElement | typeof window | Document | string;
9
+ type ScrollObserverOptions = {
10
+ debounce?: number;
11
+ horizontal?: boolean;
12
+ };
13
+ /**
14
+ * A scroll observer utility.
15
+ * @example
16
+ * ```js
17
+ * // Inside the <script> tag
18
+ * const scroll = new QScrollObserver();
19
+ *
20
+ * $inspect(scroll.direction)
21
+ * ```
22
+ *
23
+ * @param target - Element or selector of the element to add the scroll listener on
24
+ * @param options - Options of the observer
25
+ * @param options.horizontal - If set to `true`, observe horizontal scrolling rather than vertical
26
+ * @param options.debounce - Time in milliseconds between each observation update
27
+ */
28
+ export default class QScrollObserver {
29
+ protected scrollType: ScrollType;
30
+ protected lastScroll: number;
31
+ protected horizontal: boolean;
32
+ protected clearTimer: (() => void) | null;
33
+ protected target: Exclude<Target, string> | null;
34
+ direction: Direction;
35
+ changedDirection: boolean;
36
+ delta: number;
37
+ inflectionPoint: number;
38
+ position: number;
39
+ constructor(target?: Target | null, { horizontal, debounce }?: ScrollObserverOptions);
40
+ protected getScrollPosition(target?: HTMLElement | typeof window | undefined): number;
41
+ protected updateDirection(target: HTMLElement): void;
42
+ protected handleDebounce(target: HTMLElement, debounce: number): void;
43
+ }
44
+ export {};
@@ -0,0 +1,95 @@
1
+ import { onMount } from "svelte";
2
+ import { elFromSelector } from "../utils";
3
+ /**
4
+ * A scroll observer utility.
5
+ * @example
6
+ * ```js
7
+ * // Inside the <script> tag
8
+ * const scroll = new QScrollObserver();
9
+ *
10
+ * $inspect(scroll.direction)
11
+ * ```
12
+ *
13
+ * @param target - Element or selector of the element to add the scroll listener on
14
+ * @param options - Options of the observer
15
+ * @param options.horizontal - If set to `true`, observe horizontal scrolling rather than vertical
16
+ * @param options.debounce - Time in milliseconds between each observation update
17
+ */
18
+ export default class QScrollObserver {
19
+ scrollType = {
20
+ window: "scrollY",
21
+ document: "scrollTop",
22
+ };
23
+ lastScroll;
24
+ horizontal = false;
25
+ clearTimer = null;
26
+ target = null;
27
+ direction = $state("down");
28
+ changedDirection = $state(false);
29
+ delta = $state(0);
30
+ inflectionPoint = $state(0);
31
+ position = $state(0);
32
+ constructor(target, { horizontal, debounce } = { horizontal: false, debounce: 250 }) {
33
+ this.horizontal = horizontal ?? false;
34
+ this.scrollType = horizontal
35
+ ? { window: "scrollX", document: "scrollLeft" }
36
+ : { window: "scrollY", document: "scrollTop" };
37
+ this.lastScroll = 0;
38
+ this.position = 0;
39
+ this.inflectionPoint = 0;
40
+ this.direction = horizontal ? "right" : "down";
41
+ const handler = (e) => {
42
+ const eventTarget = e.target;
43
+ if (!eventTarget || !this.target || eventTarget !== this.target) {
44
+ return;
45
+ }
46
+ if (debounce) {
47
+ this.handleDebounce(this.target, debounce);
48
+ }
49
+ else {
50
+ this.updateDirection(this.target);
51
+ }
52
+ };
53
+ onMount(() => {
54
+ let parsedTarget = elFromSelector(target ?? null);
55
+ if (parsedTarget === null) {
56
+ console.warn(`The given target (${target}) is null, observing window instead`);
57
+ parsedTarget = window;
58
+ }
59
+ this.target = parsedTarget;
60
+ parsedTarget.addEventListener("scroll", handler, { capture: true });
61
+ return () => {
62
+ this.clearTimer?.();
63
+ parsedTarget.removeEventListener("scroll", handler, true);
64
+ };
65
+ });
66
+ }
67
+ getScrollPosition(target = window) {
68
+ return Math.max(0, target === window
69
+ ? target[this.scrollType.window]
70
+ : target[this.scrollType.document]);
71
+ }
72
+ updateDirection(target) {
73
+ this.clearTimer?.();
74
+ const newScrollPosition = this.getScrollPosition(target);
75
+ this.position = newScrollPosition;
76
+ this.delta = newScrollPosition - this.lastScroll;
77
+ const newDirection = this.delta > 0 ? (this.horizontal ? "right" : "down") : this.horizontal ? "left" : "up";
78
+ this.changedDirection = newDirection !== this.direction;
79
+ if (this.changedDirection) {
80
+ this.direction = newDirection;
81
+ this.inflectionPoint = newScrollPosition;
82
+ }
83
+ this.lastScroll = newScrollPosition <= 0 ? 0 : newScrollPosition;
84
+ }
85
+ handleDebounce(target, debounce) {
86
+ if (this.clearTimer) {
87
+ return;
88
+ }
89
+ const timer = setTimeout(this.updateDirection.bind(this, target), debounce);
90
+ this.clearTimer = () => {
91
+ clearTimeout(timer);
92
+ this.clearTimer = null;
93
+ };
94
+ }
95
+ }
@@ -0,0 +1,11 @@
1
+ import type { HexValue, QuaffColors, Mode } from "../utils/colors";
2
+ type ThemeColors = Record<`${keyof QuaffColors}-${Mode}`, HexValue>;
3
+ declare class QTheme {
4
+ themeColors: ThemeColors;
5
+ constructor();
6
+ private apply;
7
+ updateThemeColor(color: keyof ThemeColors, newVal: HexValue): void;
8
+ setTheme(from: string): void;
9
+ }
10
+ declare const _default: QTheme;
11
+ export default _default;
@@ -0,0 +1,49 @@
1
+ import { generateColors } from "../utils/colors";
2
+ function extractColorFromCssVar(cssVar) {
3
+ const rootStyles = getComputedStyle(document.documentElement);
4
+ // remove var(...) to get only the color
5
+ const varName = cssVar.replace(/var\(([a-z0-9-]+)\)/, "$1");
6
+ return rootStyles.getPropertyValue(varName).trim();
7
+ }
8
+ function prepareThemeColors(from) {
9
+ if (from.startsWith("var(")) {
10
+ from = extractColorFromCssVar(from);
11
+ }
12
+ const theme = generateColors(from);
13
+ //@ts-expect-error The properties are added in the next for loop
14
+ const themeColors = {};
15
+ let mode;
16
+ for (mode in theme) {
17
+ let color;
18
+ for (color in theme[mode]) {
19
+ const cssColor = `${color}-${mode}`;
20
+ themeColors[cssColor] = theme[mode][color];
21
+ }
22
+ }
23
+ return themeColors;
24
+ }
25
+ class QTheme {
26
+ themeColors = $state({});
27
+ constructor() {
28
+ this.themeColors = prepareThemeColors("#0039b4");
29
+ }
30
+ apply() {
31
+ const root = document.documentElement;
32
+ if (root === null) {
33
+ return;
34
+ }
35
+ let colorName;
36
+ for (colorName in this.themeColors) {
37
+ root.style.setProperty(`--${colorName}`, this.themeColors[colorName]);
38
+ }
39
+ }
40
+ updateThemeColor(color, newVal) {
41
+ this.themeColors[color] = newVal;
42
+ }
43
+ setTheme(from) {
44
+ const newTheme = prepareThemeColors(from);
45
+ this.themeColors = newTheme;
46
+ this.apply();
47
+ }
48
+ }
49
+ export default new QTheme();
@@ -0,0 +1,14 @@
1
+ declare class Quaff {
2
+ version: string;
3
+ protected dark: boolean;
4
+ private toggleDarkMode;
5
+ private setDarkMode;
6
+ get darkMode(): {
7
+ readonly isActive: boolean;
8
+ toggle: () => void;
9
+ set: (newVal: boolean) => void;
10
+ };
11
+ get router(): import("@sveltejs/kit").Page<Record<string, string>, string | null>;
12
+ }
13
+ declare const _default: Quaff;
14
+ export default _default;
@@ -0,0 +1,35 @@
1
+ import { get } from "svelte/store";
2
+ import version from "../helpers/version";
3
+ import { page } from "$app/stores";
4
+ class Quaff {
5
+ version = version;
6
+ dark = $state(false);
7
+ toggleDarkMode() {
8
+ this.dark = !this.dark;
9
+ const mode = {
10
+ from: this.dark ? "light" : "dark",
11
+ to: this.dark ? "dark" : "light",
12
+ };
13
+ const body = document.querySelector("body");
14
+ body?.classList.replace(`body--${mode.from}`, `body--${mode.to}`);
15
+ document.cookie = `current_mode=${mode.to}; max-age=31536000; path="/"; SameSite=strict`;
16
+ }
17
+ setDarkMode(newVal) {
18
+ this.dark = newVal;
19
+ }
20
+ get darkMode() {
21
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
22
+ const self = this;
23
+ return {
24
+ get isActive() {
25
+ return self.dark;
26
+ },
27
+ toggle: () => this.toggleDarkMode(),
28
+ set: (newVal) => this.setDarkMode(newVal),
29
+ };
30
+ }
31
+ get router() {
32
+ return get(page);
33
+ }
34
+ }
35
+ export default new Quaff();
@@ -0,0 +1,97 @@
1
+ @use "$css/variables";
2
+
3
+ @layer q-avatar {
4
+ // Basic styles
5
+ .q-avatar {
6
+ height: var(--size);
7
+ width: var(--size);
8
+
9
+ & > img,
10
+ & > video {
11
+ object-fit: cover;
12
+ object-position: center;
13
+ aspect-ratio: 1;
14
+ width: 100%;
15
+ height: 100%;
16
+ }
17
+ transition:
18
+ variables.$speed3 transform,
19
+ variables.$speed3 border-radius,
20
+ variables.$speed3 padding;
21
+ border-radius: 0;
22
+
23
+ display: flex;
24
+ align-items: center;
25
+ justify-content: center;
26
+
27
+ font-size: 1rem;
28
+ text-transform: uppercase;
29
+
30
+ overflow: hidden;
31
+
32
+ -webkit-user-select: none;
33
+ -moz-user-select: none;
34
+ -ms-user-select: none;
35
+ user-select: none;
36
+
37
+ &.circle {
38
+ margin: 0;
39
+ }
40
+ }
41
+
42
+ // Sizes
43
+ $sizes: (
44
+ "xs": 0,
45
+ "sm": 1,
46
+ "md": 2,
47
+ "lg": 3,
48
+ "xl": 4,
49
+ );
50
+
51
+ .q-avatar {
52
+ @each $size, $val in $sizes {
53
+ &--#{$size} {
54
+ --size: calc(2rem + #{$val} * 0.5rem);
55
+ }
56
+ }
57
+ }
58
+
59
+ // Border radius
60
+ $positions-y: "top", "bottom";
61
+ $positions-x: "right", "left";
62
+
63
+ .q-avatar {
64
+ border-radius: 50%;
65
+
66
+ &--top-right-round {
67
+ border-bottom-left-radius: 0;
68
+ }
69
+ &--top-left-round {
70
+ border-bottom-right-radius: 0;
71
+ }
72
+ &--bottom-right-round {
73
+ border-top-left-radius: 0;
74
+ }
75
+ &--bottom-left-round {
76
+ border-top-right-radius: 0;
77
+ }
78
+
79
+ @each $pos-y in $positions-y {
80
+ &--#{$pos-y}-round {
81
+ @extend .q-avatar--#{$pos-y}-left-round;
82
+ @extend .q-avatar--#{$pos-y}-right-round;
83
+ }
84
+ }
85
+
86
+ @each $pos-x in $positions-x {
87
+ &--#{$pos-x}-round {
88
+ @extend .q-avatar--top-#{$pos-x}-round;
89
+ @extend .q-avatar--bottom-#{$pos-x}-round;
90
+ }
91
+ }
92
+
93
+ &--round {
94
+ border-radius: 0.5rem;
95
+ }
96
+ }
97
+ }
@@ -1,62 +1,37 @@
1
- <script>import { useSize } from "../../composables";
2
- export let shape = "circle", size = "md", src = void 0, video = false, userClasses = "";
3
- export { userClasses as class };
4
- $:
5
- sizeObj = useSize(size);
1
+ <svelte:options runes={true} />
2
+
3
+ <script lang="ts">
4
+ import { useSize } from "../../composables/useSize";
5
+ let {
6
+ alt,
7
+ shape = "circle",
8
+ size = "md",
9
+ src,
10
+ video = false,
11
+ children,
12
+ videoAccessibility,
13
+ ...props
14
+ } = $props();
15
+ const qSize = $derived(useSize(size, "q-avatar"));
16
+ const qShape = $derived(`q-avatar--${shape}`);
6
17
  </script>
7
18
 
8
- {#if video === true}
9
- <!-- svelte-ignore a11y-media-has-caption -->
10
- <video
11
- class="q-avatar {sizeObj.class ? `q-avatar--${sizeObj.class}` : ''} {userClasses}"
12
- class:q-avatar--circle={shape === "circle"}
13
- class:q-avatar--round={shape === "rounded"}
14
- class:q-avatar--top-round={shape?.includes("top")}
15
- class:q-avatar--bottom-round={shape?.includes("bottom")}
16
- class:q-avatar--left-round={shape?.includes("left")}
17
- class:q-avatar--right-round={shape?.includes("right")}
18
- style:width={sizeObj.style}
19
- style:height={sizeObj.style}
20
- autoplay
21
- loop
22
- playsinline
23
- {...$$restProps}
24
- on:click
25
- >
26
- <source {src} type="video/mp4" />
27
- </video>
28
- {:else if src !== undefined}
29
- <!-- svelte-ignore a11y-missing-attribute -->
30
- <!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
31
- <img
32
- class="q-avatar {sizeObj.class ? `q-avatar--${sizeObj.class}` : ''} {userClasses}"
33
- class:q-avatar--circle={shape === "circle"}
34
- class:q-avatar--round={shape === "rounded"}
35
- class:q-avatar--top-round={shape?.includes("top")}
36
- class:q-avatar--bottom-round={shape?.includes("bottom")}
37
- class:q-avatar--left-round={shape?.includes("left")}
38
- class:q-avatar--right-round={shape?.includes("right")}
39
- style:width={sizeObj.style}
40
- style:height={sizeObj.style}
41
- {src}
42
- {...$$restProps}
43
- on:click
44
- />
45
- {:else}
46
- <!-- svelte-ignore a11y-no-static-element-interactions -->
47
- <div
48
- class="q-avatar {sizeObj.class ? `q-avatar--${sizeObj.class}` : ''} {userClasses}"
49
- class:q-avatar--circle={shape === "circle"}
50
- class:q-avatar--round={shape === "rounded"}
51
- class:q-avatar--top-round={shape?.includes("top")}
52
- class:q-avatar--bottom-round={shape?.includes("bottom")}
53
- class:q-avatar--left-round={shape?.includes("left")}
54
- class:q-avatar--right-round={shape?.includes("right")}
55
- style:width={sizeObj.style}
56
- style:height={sizeObj.style}
57
- {...$$restProps}
58
- on:click
59
- >
60
- <slot />
61
- </div>
62
- {/if}
19
+ <div
20
+ {...props}
21
+ class="q-avatar{qShape ? ` ${qShape}` : ''}{qSize.class
22
+ ? ` ${qSize.class}`
23
+ : ''}{props.class ? ` ${props.class}` : ''}"
24
+ style:--size={qSize.style}
25
+ >
26
+ {#if video}
27
+ <video>
28
+ <source {src} type="video/mp4" />
29
+ <track kind="captions" />
30
+ {@render videoAccessibility?.()}
31
+ </video>
32
+ {:else if src !== undefined}
33
+ <img {src} {alt} />
34
+ {:else}
35
+ {@render children?.()}
36
+ {/if}
37
+ </div>
@@ -1,26 +1,3 @@
1
- import { SvelteComponent } from "svelte";
2
1
  import type { QAvatarProps } from "./props";
3
- declare const __propDef: {
4
- props: {
5
- [x: string]: any;
6
- shape?: QAvatarProps["shape"];
7
- size?: QAvatarProps["size"];
8
- src?: QAvatarProps["src"];
9
- video?: QAvatarProps["video"];
10
- class?: string | null | undefined;
11
- };
12
- events: {
13
- click: MouseEvent;
14
- } & {
15
- [evt: string]: CustomEvent<any>;
16
- };
17
- slots: {
18
- default: {};
19
- };
20
- };
21
- type QAvatarProps_ = typeof __propDef.props;
22
- export { QAvatarProps_ as QAvatarProps };
23
- export type QAvatarEvents = typeof __propDef.events;
24
- export type QAvatarSlots = typeof __propDef.slots;
25
- export default class QAvatar extends SvelteComponent<QAvatarProps, QAvatarEvents, QAvatarSlots> {
26
- }
2
+ declare const QAvatar: import("svelte").Component<QAvatarProps, {}, "">;
3
+ export default QAvatar;
@@ -1,5 +1,5 @@
1
1
  // AUTO GENERATED FILE - DO NOT MODIFY OR DELETE
2
- // @quaffHash 24254a62ac601e8b6e85a3b74a7b3297
2
+ // @quaffHash 1e0adf78358181054a99b1cbccf54f26
3
3
  export const QAvatarDocsProps = [
4
4
  {
5
5
  name: "shape",
@@ -7,7 +7,7 @@ export const QAvatarDocsProps = [
7
7
  optional: true,
8
8
  clickableType: true,
9
9
  description: "Shape of the avatar.",
10
- default: "circle",
10
+ default: '"circle"',
11
11
  },
12
12
  {
13
13
  name: "size",
@@ -15,14 +15,14 @@ export const QAvatarDocsProps = [
15
15
  optional: true,
16
16
  clickableType: true,
17
17
  description: 'Size of the avatar, can be a custom size using CSS units. If no unit is specified, "px" will be used.',
18
- default: "md",
18
+ default: '"md"',
19
19
  },
20
20
  {
21
21
  name: "src",
22
22
  type: "string",
23
23
  optional: true,
24
24
  clickableType: false,
25
- description: "Source of the image to use as the avatar. Can be a url or a path to a local file.",
25
+ description: "Source of the image to be used as the avatar. Can be a url or a path to a local file.",
26
26
  default: "undefined",
27
27
  },
28
28
  {
@@ -30,7 +30,23 @@ export const QAvatarDocsProps = [
30
30
  type: "boolean",
31
31
  optional: true,
32
32
  clickableType: false,
33
- description: 'If set to true, will use the "src" prop as a video source.',
33
+ description: 'If set to true, the "src" prop will be used as a video source.',
34
34
  default: "false",
35
35
  },
36
+ {
37
+ name: "alt",
38
+ type: "string",
39
+ optional: true,
40
+ clickableType: false,
41
+ description: "alt property for the image.",
42
+ default: "undefined",
43
+ },
44
+ {
45
+ name: "videoAccessibility",
46
+ type: "Snippet",
47
+ optional: true,
48
+ clickableType: true,
49
+ description: "Accessibility controls you might want to add inside the <video> element.\nFor example, you might want to add a <p> tag in case the video player doesn't work.",
50
+ default: "undefined",
51
+ },
36
52
  ];