@pyreon/head 0.11.5 → 0.11.6

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.
@@ -1,3 +1,3 @@
1
- import { GlobalRegistrator } from "@happy-dom/global-registrator"
1
+ import { GlobalRegistrator } from '@happy-dom/global-registrator'
2
2
 
3
3
  GlobalRegistrator.register()
package/src/use-head.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { onMount, onUnmount, useContext } from "@pyreon/core"
2
- import { effect } from "@pyreon/reactivity"
3
- import type { HeadEntry, HeadTag, UseHeadInput } from "./context"
4
- import { HeadContext } from "./context"
5
- import { syncDom } from "./dom"
1
+ import { onMount, onUnmount, useContext } from '@pyreon/core'
2
+ import { effect } from '@pyreon/reactivity'
3
+ import type { HeadEntry, HeadTag, UseHeadInput } from './context'
4
+ import { HeadContext } from './context'
5
+ import { syncDom } from './dom'
6
6
 
7
7
  /** Cast a strict tag interface to the internal props format, stripping undefined values */
8
8
  function toProps(obj: Record<string, string | undefined>): Record<string, string> {
@@ -15,25 +15,25 @@ function toProps(obj: Record<string, string | undefined>): Record<string, string
15
15
 
16
16
  function buildEntry(o: UseHeadInput): HeadEntry {
17
17
  const tags: HeadTag[] = []
18
- if (o.title != null) tags.push({ tag: "title", key: "title", children: o.title })
18
+ if (o.title != null) tags.push({ tag: 'title', key: 'title', children: o.title })
19
19
  o.meta?.forEach((m, i) => {
20
20
  tags.push({
21
- tag: "meta",
21
+ tag: 'meta',
22
22
  key: m.name ?? m.property ?? `meta-${i}`,
23
23
  props: toProps(m as Record<string, string | undefined>),
24
24
  })
25
25
  })
26
26
  o.link?.forEach((l, i) => {
27
27
  tags.push({
28
- tag: "link",
29
- key: l.href ? `link-${l.rel || ""}-${l.href}` : l.rel ? `link-${l.rel}` : `link-${i}`,
28
+ tag: 'link',
29
+ key: l.href ? `link-${l.rel || ''}-${l.href}` : l.rel ? `link-${l.rel}` : `link-${i}`,
30
30
  props: toProps(l as Record<string, string | undefined>),
31
31
  })
32
32
  })
33
33
  o.script?.forEach((s, i) => {
34
34
  const { children, ...rest } = s
35
35
  tags.push({
36
- tag: "script",
36
+ tag: 'script',
37
37
  key: s.src ?? `script-${i}`,
38
38
  props: toProps(rest as Record<string, string | undefined>),
39
39
  ...(children != null ? { children } : {}),
@@ -42,27 +42,27 @@ function buildEntry(o: UseHeadInput): HeadEntry {
42
42
  o.style?.forEach((s, i) => {
43
43
  const { children, ...rest } = s
44
44
  tags.push({
45
- tag: "style",
45
+ tag: 'style',
46
46
  key: `style-${i}`,
47
47
  props: toProps(rest as Record<string, string | undefined>),
48
48
  children,
49
49
  })
50
50
  })
51
51
  o.noscript?.forEach((ns, i) => {
52
- tags.push({ tag: "noscript", key: `noscript-${i}`, children: ns.children })
52
+ tags.push({ tag: 'noscript', key: `noscript-${i}`, children: ns.children })
53
53
  })
54
54
  if (o.jsonLd) {
55
55
  tags.push({
56
- tag: "script",
57
- key: "jsonld",
58
- props: { type: "application/ld+json" },
56
+ tag: 'script',
57
+ key: 'jsonld',
58
+ props: { type: 'application/ld+json' },
59
59
  children: JSON.stringify(o.jsonLd),
60
60
  })
61
61
  }
62
62
  if (o.base)
63
63
  tags.push({
64
- tag: "base",
65
- key: "base",
64
+ tag: 'base',
65
+ key: 'base',
66
66
  props: toProps(o.base as Record<string, string | undefined>),
67
67
  })
68
68
  return {
@@ -90,8 +90,8 @@ export function useHead(input: UseHeadInput | (() => UseHeadInput)): void {
90
90
 
91
91
  const id = Symbol()
92
92
 
93
- if (typeof input === "function") {
94
- if (typeof document !== "undefined") {
93
+ if (typeof input === 'function') {
94
+ if (typeof document !== 'undefined') {
95
95
  // CSR: reactive — re-register whenever signals change
96
96
  effect(() => {
97
97
  ctx.add(id, buildEntry(input()))