@christianirack/brainllm-runtime 0.8.6 → 0.8.8

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.
package/brain.js CHANGED
@@ -276,15 +276,23 @@ export function insert(p, f, end) {
276
276
  }
277
277
 
278
278
  // aria-* and data-* are enumerated, not boolean: true and false render as text (k[4] is their dash)
279
+ // A select only takes a value its options offer, and {#each}/{#if} options mount after attr() or change later.
280
+ const keepSelected = (el, f, M = globalThis.MutationObserver) =>
281
+ M && new M(() => {
282
+ const i = el.selectedIndex
283
+ el.value = typeof f == 'function' ? untrack(f) : f
284
+ if (el.selectedIndex < 0) el.selectedIndex = i // no option matches yet: the browser's choice stays
285
+ }).observe(el, { childList: true, subtree: true })
286
+
279
287
  export function attr(el, k, f) {
280
288
  bind(
281
289
  f,
282
290
  k.startsWith('style:')
283
291
  ? ((k = k.slice(6)), v => (v == null || v === false ? el.style.removeProperty(k) : el.style.setProperty(k, v)))
284
292
  : /^(value|checked|selected)$/.test(k) && !(k == 'value' && el.tagName == 'OPTION') // an option's value is its attribute (SSR, value="")
285
- ? v => {
293
+ ? ((el.tagName == 'SELECT' && k == 'value') ? keepSelected(el, f) : 0, v => {
286
294
  if (el[k] !== v) el[k] = v
287
- }
295
+ })
288
296
  : v => (v == null || (v === false && k[4] != '-') ? el.removeAttribute(k) : el.setAttribute(k, v === true && k[4] != '-' ? '' : /^(href|src|action|formaction|poster)$/.test(k) && typeof v == 'string' ? inBase(v) : v))
289
297
  )
290
298
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@christianirack/brainllm-runtime",
3
- "version": "0.8.6",
3
+ "version": "0.8.8",
4
4
  "description": "The BRAINLLM runtime for the Rust-built web compiler for LLMs: dependency-free ES modules (signals, DOM, router, data, forms, channels). The brain binary embeds this same version.",
5
5
  "type": "module",
6
6
  "exports": {
package/server/server.mjs CHANGED
@@ -1825,7 +1825,9 @@ export function createServer(o = {}) {
1825
1825
  const variant = urlVariant(req)
1826
1826
  if (variant) return send(res, 301, '', { location: variant, 'cache-control': 'public, max-age=3600' })
1827
1827
  if (req.url.startsWith('//')) return notFound(req, res)
1828
- const full = new URL(req.url, 'http://' + (req.headers.host || 'localhost'))
1828
+ const host = req.headers.host || 'localhost'
1829
+ let full
1830
+ try { full = new URL(req.url, 'http://' + host) } catch { return send(res, 400, 'Bad Request') }
1829
1831
  // /_health stays at the root: the supervisor calls it there whatever the base
1830
1832
  if (full.pathname === '/_health' || full.pathname === BASE + '_health') return send(res, 200, json({ ok: true, build: mf.build || null }), { 'content-type': MIME['.json'], 'cache-control': 'no-store' })
1831
1833
  let url = full
@@ -2247,7 +2249,11 @@ function parseCookies(h = '') {
2247
2249
  const i = part.indexOf('=')
2248
2250
  if (i > 0) {
2249
2251
  const k = part.slice(0, i).trim()
2250
- if (k && !(k in out)) out[k] = decodeURIComponent(part.slice(i + 1).trim())
2252
+ if (k && !(k in out)) {
2253
+ // Another site's cookie on this domain may hold anything: it must not cost the page.
2254
+ const value = part.slice(i + 1).trim()
2255
+ try { out[k] = decodeURIComponent(value) } catch { out[k] = value }
2256
+ }
2251
2257
  }
2252
2258
  }
2253
2259
  return out