@noxlovette/material 0.8.0 → 0.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,8 +15,24 @@ const CONTAINER_TOKENS = [
15
15
  ];
16
16
  /** Used server-side, or if a token hasn't been painted yet (styles not loaded). */
17
17
  const FALLBACK_PALETTE = ['e9ddff', 'e8def8', 'ffd9e3', 'ffdad6', 'e6e0e9'];
18
- /** Converts the `rgb(r g b)` (or `rgb(r, g, b)`) format these tokens are always defined in to hex. */
19
- function rgbStringToHex(value) {
18
+ /**
19
+ * Converts a token's resolved value to a 6-digit hex. Dev serves the tokens as written in the
20
+ * theme CSS, `rgb(r g b)` (or `rgb(r, g, b)`), but a production build's CSS minifier rewrites
21
+ * them to hex (`#d1e5f3`, or the short `#fff`): pulling the numbers out of a hex string reads
22
+ * its digit runs as channels and yields a near-black colour, so hex is handled on its own.
23
+ */
24
+ function colorToHex(value) {
25
+ const hex = value.match(/^#([0-9a-f]{3,8})$/i)?.[1];
26
+ if (hex) {
27
+ if (hex.length === 3 || hex.length === 4) {
28
+ return [...hex.slice(0, 3)]
29
+ .map((c) => c + c)
30
+ .join('')
31
+ .toLowerCase();
32
+ }
33
+ // 6 digits, or 8 with alpha (dropped: DiceBear takes opaque backgrounds).
34
+ return hex.length === 6 || hex.length === 8 ? hex.slice(0, 6).toLowerCase() : undefined;
35
+ }
20
36
  const channels = value.match(/\d+(?:\.\d+)?/g);
21
37
  if (!channels || channels.length < 3)
22
38
  return undefined;
@@ -38,7 +54,7 @@ export function getMaterialAvatarPalette() {
38
54
  const styles = getComputedStyle(document.documentElement);
39
55
  const palette = CONTAINER_TOKENS.map((token) => {
40
56
  const raw = styles.getPropertyValue(token).trim();
41
- return raw ? rgbStringToHex(raw) : undefined;
57
+ return raw ? colorToHex(raw) : undefined;
42
58
  }).filter((hex) => Boolean(hex));
43
59
  return palette.length > 0 ? palette : FALLBACK_PALETTE;
44
60
  }
@@ -98,10 +98,7 @@ It combines a Material 3 Textfield with a TimepickerInput for intuitive time sel
98
98
  <div {...wrapperProps}>
99
99
  <div
100
100
  {...props}
101
- class={[
102
- props.class,
103
- 'max-h-(--bits-floating-available-height) min-w-(--bits-floating-anchor-width) overflow-auto'
104
- ]}
101
+ class={[props.class, 'min-w-(--bits-floating-anchor-width)']}
105
102
  {@attach presence(() => open, enterExit.scale)}
106
103
  >
107
104
  <TimepickerInput
@@ -0,0 +1,17 @@
1
+ /*
2
+ Optional, for `<App iconProviderProps={{ selfHosted: true }}>`. Google's stylesheet normally
3
+ binds each `.material-symbols-*` class to its font family; a self-hoster imports this instead and
4
+ writes only the `@font-face` rules (variable, with the opsz, wght, FILL and GRAD axes).
5
+ The rest of the class metrics (line-height, ligatures, smoothing…) ship in `./styles`.
6
+ */
7
+ .material-symbols-rounded {
8
+ font-family: 'Material Symbols Rounded';
9
+ }
10
+
11
+ .material-symbols-outlined {
12
+ font-family: 'Material Symbols Outlined';
13
+ }
14
+
15
+ .material-symbols-sharp {
16
+ font-family: 'Material Symbols Sharp';
17
+ }
@@ -2,12 +2,16 @@
2
2
  @component
3
3
  A helper that handles google icons. Should not be used directly.
4
4
  Use the App.svelte component instead
5
+
6
+ With `selfHosted` it renders nothing, so no request goes to fonts.googleapis.com. The consumer then
7
+ supplies the `@font-face` rules; see `@noxlovette/material/styles/icon-font.css`.
5
8
  -->
6
9
  <script lang="ts">
7
10
  import { baseIcons } from './base-icons.js';
8
11
  import type { MaterialSymbolsProviderProps } from './types.js';
9
12
 
10
13
  const {
14
+ selfHosted = false,
11
15
  extraIcons = [],
12
16
  display = 'swap',
13
17
  subset = true,
@@ -41,5 +45,7 @@ Use the App.svelte component instead
41
45
  </script>
42
46
 
43
47
  <svelte:head>
44
- <link rel="stylesheet" {href} />
48
+ {#if !selfHosted}
49
+ <link rel="stylesheet" {href} />
50
+ {/if}
45
51
  </svelte:head>
@@ -2,6 +2,9 @@ import type { MaterialSymbolsProviderProps } from './types.js';
2
2
  /**
3
3
  * A helper that handles google icons. Should not be used directly.
4
4
  * Use the App.svelte component instead
5
+ *
6
+ * With `selfHosted` it renders nothing, so no request goes to fonts.googleapis.com. The consumer then
7
+ * supplies the `@font-face` rules; see `@noxlovette/material/styles/icon-font.css`.
5
8
  */
6
9
  declare const MaterialSymbolsProvider: import("svelte").Component<MaterialSymbolsProviderProps, {}, "">;
7
10
  type MaterialSymbolsProvider = ReturnType<typeof MaterialSymbolsProvider>;
@@ -59,6 +59,17 @@ export type LoadingIndicatorProps = HTMLAttributes<SVGAElement> & LoadingIndicat
59
59
  center?: boolean;
60
60
  };
61
61
  export type MaterialSymbolsProviderProps = {
62
+ /**
63
+ * Skip the Google Fonts `<link>` so the page makes no request to `fonts.googleapis.com`, and
64
+ * supply the font yourself. Define an `@font-face` for each family in use (`"Material Symbols
65
+ * Rounded"`, `"Material Symbols Outlined"`, `"Material Symbols Sharp"`), variable, with the
66
+ * `opsz`, `wght`, `FILL` and `GRAD` axes that `Icon` sets through `font-variation-settings`, and
67
+ * import `@noxlovette/material/styles/icon-font.css` for the `font-family` of each
68
+ * `.material-symbols-*` class. The remaining class metrics ship with `@noxlovette/material/styles`.
69
+ * With this set, `icons`, `extraIcons`, `subset`, `families` and `display` have no effect.
70
+ * @default false
71
+ */
72
+ selfHosted?: boolean;
62
73
  icons?: MaterialSymbolName[];
63
74
  /** Icon names to load on top of `baseIcons`. Ignored when `subset` is false. */
64
75
  extraIcons?: MaterialSymbolName[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noxlovette/material",
3
- "version": "0.8.0",
3
+ "version": "0.8.2",
4
4
  "type": "module",
5
5
  "description": "A Material Design 3 component library for Svelte, built on Bits UI.",
6
6
  "keywords": [
@@ -57,6 +57,7 @@
57
57
  "svelte": "./dist/index.js"
58
58
  },
59
59
  "./styles": "./dist/index.css",
60
+ "./styles/icon-font.css": "./dist/styles/icon-font.css",
60
61
  "./theme/*": "./dist/styles/theme/*.css"
61
62
  },
62
63
  "peerDependencies": {