@r2digisolutions/components 0.9.1 → 0.9.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.
@@ -28,28 +28,24 @@
28
28
  class: className = ''
29
29
  }: ImageProps = $props();
30
30
 
31
- let isLoaded = $state(false);
32
31
  let hasError = $state(false);
33
- let activeSrc = $state(src);
32
+ let useFallback = $state(false);
33
+
34
+ const displaySrc = $derived(useFallback && fallbackSrc ? fallbackSrc : src);
34
35
 
35
36
  $effect(() => {
36
- activeSrc = src;
37
- isLoaded = false;
37
+ void src;
38
+ useFallback = false;
38
39
  hasError = false;
39
40
  });
40
41
 
41
- function handleLoad() {
42
- isLoaded = true;
43
- hasError = false;
44
- }
45
-
46
- function handleError() {
47
- if (fallbackSrc && activeSrc !== fallbackSrc) {
48
- activeSrc = fallbackSrc;
49
- } else {
50
- hasError = true;
51
- isLoaded = true;
42
+ function onError() {
43
+ if (fallbackSrc && !useFallback) {
44
+ useFallback = true;
45
+ hasError = false;
46
+ return;
52
47
  }
48
+ hasError = true;
53
49
  }
54
50
 
55
51
  const roundedClass = $derived(
@@ -78,51 +74,51 @@
78
74
  : 'object-none'
79
75
  );
80
76
 
81
- const styleStr = $derived([
82
- aspectRatio ? `aspect-ratio:${aspectRatio}` : '',
83
- width ? `width:${typeof width === 'number' ? `${width}px` : width}` : '',
84
- height ? `height:${typeof height === 'number' ? `${height}px` : height}` : ''
85
- ].filter(Boolean).join(';'));
77
+ const styleStr = $derived(
78
+ [
79
+ aspectRatio ? `aspect-ratio:${aspectRatio}` : '',
80
+ width ? `width:${typeof width === 'number' ? `${width}px` : width}` : '',
81
+ height ? `height:${typeof height === 'number' ? `${height}px` : height}` : ''
82
+ ]
83
+ .filter(Boolean)
84
+ .join(';')
85
+ );
86
86
  </script>
87
87
 
88
88
  <div
89
89
  class={['relative overflow-hidden bg-surface-overlay', roundedClass, className]}
90
90
  style={styleStr || undefined}
91
91
  >
92
- {#if !isLoaded && !hasError}
93
- <!-- Skeleton shimmer -->
94
- <div class="absolute inset-0 animate-pulse bg-surface-overlay">
95
- <div class="h-full w-full bg-gradient-to-r from-surface-overlay via-border to-surface-overlay bg-[length:200%_100%] animate-[shimmer_1.5s_ease-in-out_infinite]"></div>
96
- </div>
97
- {/if}
98
-
99
92
  {#if hasError}
100
- <!-- Error placeholder -->
101
- <div class="absolute inset-0 flex flex-col items-center justify-center gap-2 bg-surface-overlay text-muted">
102
- <svg class="h-8 w-8" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" aria-hidden="true">
103
- <path stroke-linecap="round" stroke-linejoin="round" d="M2.25 15.75l5.159-5.159a2.25 2.25 0 013.182 0l5.159 5.159m-1.5-1.5l1.409-1.409a2.25 2.25 0 013.182 0l2.909 2.909M13.5 10.5h.008v.008H13.5V10.5zm-7.5 9h15a2.25 2.25 0 002.25-2.25V6.75A2.25 2.25 0 0019.5 4.5h-15a2.25 2.25 0 00-2.25 2.25v10.5A2.25 2.25 0 006 21.75z" />
93
+ <div
94
+ class="absolute inset-0 flex flex-col items-center justify-center gap-2 bg-surface-overlay text-muted"
95
+ >
96
+ <svg
97
+ class="h-8 w-8"
98
+ viewBox="0 0 24 24"
99
+ fill="none"
100
+ stroke="currentColor"
101
+ stroke-width="1.5"
102
+ aria-hidden="true"
103
+ >
104
+ <path
105
+ stroke-linecap="round"
106
+ stroke-linejoin="round"
107
+ d="M2.25 15.75l5.159-5.159a2.25 2.25 0 013.182 0l5.159 5.159m-1.5-1.5l1.409-1.409a2.25 2.25 0 013.182 0l2.909 2.909M13.5 10.5h.008v.008H13.5V10.5zm-7.5 9h15a2.25 2.25 0 002.25-2.25V6.75A2.25 2.25 0 0019.5 4.5h-15a2.25 2.25 0 00-2.25 2.25v10.5A2.25 2.25 0 006 21.75z"
108
+ />
104
109
  </svg>
105
110
  <span class="text-xs">{alt || 'Image not found'}</span>
106
111
  </div>
107
112
  {:else}
108
- <img
109
- src={activeSrc}
110
- {alt}
111
- {loading}
112
- onload={handleLoad}
113
- onerror={handleError}
114
- class={[
115
- 'block h-full w-full transition-opacity duration-300',
116
- objectFitClass,
117
- isLoaded ? 'opacity-100' : 'opacity-0'
118
- ]}
119
- />
113
+ {#key displaySrc}
114
+ <img
115
+ src={displaySrc}
116
+ {alt}
117
+ {loading}
118
+ decoding="async"
119
+ onerror={onError}
120
+ class={['block h-full w-full', objectFitClass]}
121
+ />
122
+ {/key}
120
123
  {/if}
121
124
  </div>
122
-
123
- <style>
124
- @keyframes shimmer {
125
- 0% { background-position: 200% 0; }
126
- 100% { background-position: -200% 0; }
127
- }
128
- </style>
@@ -24,8 +24,13 @@
24
24
  }: SectionTitleProps = $props();
25
25
  </script>
26
26
 
27
- <div class={['flex flex-col gap-3 sm:flex-row sm:items-end sm:justify-between', className]}>
28
- <div class="min-w-0 space-y-1">
27
+ <div
28
+ class={[
29
+ 'flex w-full flex-col gap-3 sm:flex-row sm:items-start sm:justify-between',
30
+ className
31
+ ]}
32
+ >
33
+ <div class="min-w-0 flex-1 space-y-1">
29
34
  {#if eyebrow}
30
35
  <p class="text-xs font-semibold uppercase tracking-wider text-brand-600 dark:text-brand-400">
31
36
  {eyebrow}
@@ -37,7 +42,7 @@
37
42
  {/if}
38
43
  </div>
39
44
  {#if actions}
40
- <div class="flex shrink-0 items-center gap-2">
45
+ <div class="flex shrink-0 items-center justify-end gap-2 self-end sm:ml-auto sm:self-start">
41
46
  {@render actions()}
42
47
  </div>
43
48
  {/if}
@@ -20,7 +20,7 @@
20
20
 
21
21
  <nav class={['w-full', className]} aria-label="Breadcrumb">
22
22
  <ol class="flex flex-wrap items-center gap-1.5 text-sm">
23
- {#each items as item, index (item.id)}
23
+ {#each items as item, index (item.id ?? `breadcrumb-${index}`)}
24
24
  <li class="inline-flex items-center gap-1.5">
25
25
  {#if index > 0}
26
26
  <svg class="h-3.5 w-3.5 text-secondary" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
@@ -67,7 +67,7 @@
67
67
  {#if header}
68
68
  <div
69
69
  class={[
70
- 'border-b border-border',
70
+ 'w-full border-b border-border',
71
71
  chrome && 'bg-surface/40',
72
72
  paddingClasses[padding]
73
73
  ]}
@@ -77,7 +77,12 @@
77
77
  {/if}
78
78
 
79
79
  {#if children}
80
- <div class={['min-w-0 flex-1', padding !== 'none' ? paddingClasses[padding] : '']}>
80
+ <div
81
+ class={[
82
+ 'flex min-w-0 flex-1 flex-col',
83
+ padding !== 'none' ? paddingClasses[padding] : ''
84
+ ]}
85
+ >
81
86
  {@render children()}
82
87
  </div>
83
88
  {/if}
@@ -14,8 +14,19 @@
14
14
  */
15
15
  import { UI_DICTIONARIES, formatMessage, getDictionary, resolveLocaleTag } from './i18n.js';
16
16
  const STORAGE_KEY = 'r2-locale';
17
+ function canUseLocalStorage() {
18
+ try {
19
+ return (typeof localStorage !== 'undefined' &&
20
+ typeof localStorage.getItem === 'function' &&
21
+ typeof localStorage.setItem === 'function');
22
+ }
23
+ catch {
24
+ // Node / locked-down environments may throw on access
25
+ return false;
26
+ }
27
+ }
17
28
  function getStoredLocale() {
18
- if (typeof localStorage === 'undefined')
29
+ if (!canUseLocalStorage())
19
30
  return 'en';
20
31
  return localStorage.getItem(STORAGE_KEY) ?? 'en';
21
32
  }
@@ -52,7 +63,7 @@ class I18nStore {
52
63
  /** Change active locale (`es`, `en-US`, …). */
53
64
  set(locale) {
54
65
  this.#locale = locale;
55
- if (typeof localStorage !== 'undefined') {
66
+ if (canUseLocalStorage()) {
56
67
  localStorage.setItem(STORAGE_KEY, locale);
57
68
  }
58
69
  applyDocumentLang(locale);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@r2digisolutions/components",
3
- "version": "0.9.1",
3
+ "version": "0.9.2",
4
4
  "private": false,
5
5
  "description": "R2DigiSolutions Svelte 5 component library — Atomic Design, Tailwind 4, Light/Dark mode",
6
6
  "license": "MIT",
@@ -111,6 +111,6 @@
111
111
  "atomic-design"
112
112
  ],
113
113
  "dependencies": {
114
- "@xyflow/svelte": "^1.6.3"
114
+ "@xyflow/svelte": "^1.6.5"
115
115
  }
116
116
  }