@uniweb/runtime 0.4.4 → 0.5.1

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 (2) hide show
  1. package/package.json +2 -2
  2. package/src/index.jsx +97 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniweb/runtime",
3
- "version": "0.4.4",
3
+ "version": "0.5.1",
4
4
  "description": "Minimal runtime for loading Uniweb foundations",
5
5
  "type": "module",
6
6
  "exports": {
@@ -31,7 +31,7 @@
31
31
  "node": ">=20.19"
32
32
  },
33
33
  "dependencies": {
34
- "@uniweb/core": "0.2.5"
34
+ "@uniweb/core": "0.3.1"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@vitejs/plugin-react": "^4.5.2",
package/src/index.jsx CHANGED
@@ -127,6 +127,100 @@ async function loadFoundation(source) {
127
127
  }
128
128
  }
129
129
 
130
+ /**
131
+ * Map friendly family names to react-icons codes
132
+ * The existing CDN uses react-icons structure: /{familyCode}/{familyCode}-{name}.svg
133
+ */
134
+ const ICON_FAMILY_MAP = {
135
+ // Friendly names
136
+ lucide: 'lu',
137
+ heroicons: 'hi',
138
+ heroicons2: 'hi2',
139
+ phosphor: 'pi',
140
+ tabler: 'tb',
141
+ feather: 'fi',
142
+ // Font Awesome (multiple versions)
143
+ fa: 'fa',
144
+ fa6: 'fa6',
145
+ // Additional families from react-icons
146
+ bootstrap: 'bs',
147
+ 'material-design': 'md',
148
+ 'ant-design': 'ai',
149
+ remix: 'ri',
150
+ 'simple-icons': 'si',
151
+ ionicons: 'io5',
152
+ boxicons: 'bi',
153
+ vscode: 'vsc',
154
+ weather: 'wi',
155
+ game: 'gi',
156
+ // Also support direct codes for power users
157
+ lu: 'lu',
158
+ hi: 'hi',
159
+ hi2: 'hi2',
160
+ pi: 'pi',
161
+ tb: 'tb',
162
+ fi: 'fi',
163
+ bs: 'bs',
164
+ md: 'md',
165
+ ai: 'ai',
166
+ ri: 'ri',
167
+ io5: 'io5',
168
+ bi: 'bi',
169
+ si: 'si',
170
+ vsc: 'vsc',
171
+ wi: 'wi',
172
+ gi: 'gi'
173
+ }
174
+
175
+ /**
176
+ * Create CDN-based icon resolver
177
+ * @param {Object} iconConfig - From site.yml icons:
178
+ * @returns {Function} Resolver: (library, name) => Promise<string|null>
179
+ */
180
+ function createIconResolver(iconConfig = {}) {
181
+ // Default to GitHub Pages CDN, can be overridden in site.yml
182
+ const CDN_BASE = iconConfig.cdnUrl || 'https://uniweb.github.io/icons'
183
+ const useCdn = iconConfig.cdn !== false
184
+
185
+ // Cache resolved icons
186
+ const cache = new Map()
187
+
188
+ return async function resolve(library, name) {
189
+ // Map friendly name to react-icons code
190
+ const familyCode = ICON_FAMILY_MAP[library.toLowerCase()]
191
+ if (!familyCode) {
192
+ console.warn(`[icons] Unknown family "${library}"`)
193
+ return null
194
+ }
195
+
196
+ // Check cache
197
+ const key = `${familyCode}:${name}`
198
+ if (cache.has(key)) return cache.get(key)
199
+
200
+ // Fetch from CDN
201
+ if (!useCdn) {
202
+ cache.set(key, null)
203
+ return null
204
+ }
205
+
206
+ try {
207
+ // CDN structure: /{familyCode}/{familyCode}-{name}.svg
208
+ // e.g., lucide:home → /lu/lu-home.svg
209
+ const iconFileName = `${familyCode}-${name}`
210
+ const url = `${CDN_BASE}/${familyCode}/${iconFileName}.svg`
211
+ const response = await fetch(url)
212
+ if (!response.ok) throw new Error(`HTTP ${response.status}`)
213
+ const svg = await response.text()
214
+ cache.set(key, svg)
215
+ return svg
216
+ } catch (err) {
217
+ console.warn(`[icons] Failed to load ${library}:${name}`, err.message)
218
+ cache.set(key, null)
219
+ return null
220
+ }
221
+ }
222
+ }
223
+
130
224
  /**
131
225
  * Initialize the Uniweb instance
132
226
  * @param {Object} configData - Site configuration data
@@ -149,6 +243,9 @@ function initUniweb(configData) {
149
243
  useLocation
150
244
  }
151
245
 
246
+ // Set up icon resolver based on site config
247
+ uniwebInstance.iconResolver = createIconResolver(configData.icons)
248
+
152
249
  return uniwebInstance
153
250
  }
154
251