@uniweb/runtime 0.4.4 → 0.5.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 (2) hide show
  1. package/package.json +2 -2
  2. package/src/index.jsx +93 -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.0",
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.0"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@vitejs/plugin-react": "^4.5.2",
package/src/index.jsx CHANGED
@@ -127,6 +127,96 @@ 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
+ vscode: 'vsc',
152
+ weather: 'wi',
153
+ game: 'gi',
154
+ // Also support direct codes for power users
155
+ lu: 'lu',
156
+ hi: 'hi',
157
+ hi2: 'hi2',
158
+ pi: 'pi',
159
+ tb: 'tb',
160
+ fi: 'fi',
161
+ bs: 'bs',
162
+ md: 'md',
163
+ ai: 'ai',
164
+ ri: 'ri',
165
+ si: 'si',
166
+ vsc: 'vsc',
167
+ wi: 'wi',
168
+ gi: 'gi'
169
+ }
170
+
171
+ /**
172
+ * Create CDN-based icon resolver
173
+ * @param {Object} iconConfig - From site.yml icons:
174
+ * @returns {Function} Resolver: (library, name) => Promise<string|null>
175
+ */
176
+ function createIconResolver(iconConfig = {}) {
177
+ // Default to GitHub Pages CDN, can be overridden in site.yml
178
+ const CDN_BASE = iconConfig.cdnUrl || 'https://uniweb.github.io/icons'
179
+ const useCdn = iconConfig.cdn !== false
180
+
181
+ // Cache resolved icons
182
+ const cache = new Map()
183
+
184
+ return async function resolve(library, name) {
185
+ // Map friendly name to react-icons code
186
+ const familyCode = ICON_FAMILY_MAP[library.toLowerCase()]
187
+ if (!familyCode) {
188
+ console.warn(`[icons] Unknown family "${library}"`)
189
+ return null
190
+ }
191
+
192
+ // Check cache
193
+ const key = `${familyCode}:${name}`
194
+ if (cache.has(key)) return cache.get(key)
195
+
196
+ // Fetch from CDN
197
+ if (!useCdn) {
198
+ cache.set(key, null)
199
+ return null
200
+ }
201
+
202
+ try {
203
+ // CDN structure: /{familyCode}/{familyCode}-{name}.svg
204
+ // e.g., lucide:home → /lu/lu-home.svg
205
+ const iconFileName = `${familyCode}-${name}`
206
+ const url = `${CDN_BASE}/${familyCode}/${iconFileName}.svg`
207
+ const response = await fetch(url)
208
+ if (!response.ok) throw new Error(`HTTP ${response.status}`)
209
+ const svg = await response.text()
210
+ cache.set(key, svg)
211
+ return svg
212
+ } catch (err) {
213
+ console.warn(`[icons] Failed to load ${library}:${name}`, err.message)
214
+ cache.set(key, null)
215
+ return null
216
+ }
217
+ }
218
+ }
219
+
130
220
  /**
131
221
  * Initialize the Uniweb instance
132
222
  * @param {Object} configData - Site configuration data
@@ -149,6 +239,9 @@ function initUniweb(configData) {
149
239
  useLocation
150
240
  }
151
241
 
242
+ // Set up icon resolver based on site config
243
+ uniwebInstance.iconResolver = createIconResolver(configData.icons)
244
+
152
245
  return uniwebInstance
153
246
  }
154
247