UNPKG

nuxt

Version:

Nuxt is a free and open-source framework with an intuitive and extendable way to create type-safe, performant and production-grade full-stack web applications and websites with Vue.js.

228 lines (227 loc) 5.22 kB
import { defineComponent } from "vue"; import { useHead } from "@unhead/vue"; const removeUndefinedProps = (props) => { const filteredProps = /* @__PURE__ */ Object.create(null); for (const key in props) { const value = props[key]; if (value !== void 0) { filteredProps[key] = value; } } return filteredProps; }; const setupForUseMeta = (metaFactory, renderChild) => (props, ctx) => { useHead(() => metaFactory({ ...removeUndefinedProps(props), ...ctx.attrs }, ctx)); return () => renderChild ? ctx.slots.default?.() : null; }; const globalProps = { accesskey: String, autocapitalize: String, autofocus: { type: Boolean, default: void 0 }, class: [String, Object, Array], contenteditable: { type: Boolean, default: void 0 }, contextmenu: String, dir: String, draggable: { type: Boolean, default: void 0 }, enterkeyhint: String, exportparts: String, hidden: { type: Boolean, default: void 0 }, id: String, inputmode: String, is: String, itemid: String, itemprop: String, itemref: String, itemscope: String, itemtype: String, lang: String, nonce: String, part: String, slot: String, spellcheck: { type: Boolean, default: void 0 }, style: String, tabindex: String, title: String, translate: String }; export const NoScript = defineComponent({ name: "NoScript", inheritAttrs: false, props: { ...globalProps, title: String, body: Boolean, renderPriority: [String, Number] }, setup: setupForUseMeta((props, { slots }) => { const noscript = { ...props }; const slotVnodes = slots.default?.(); const textContent = slotVnodes ? slotVnodes.filter(({ children }) => children).map(({ children }) => children).join("") : ""; if (textContent) { noscript.children = textContent; } return { noscript: [noscript] }; }) }); export const Link = defineComponent({ name: "Link", inheritAttrs: false, props: { ...globalProps, as: String, crossorigin: String, disabled: Boolean, fetchpriority: String, href: String, hreflang: String, imagesizes: String, imagesrcset: String, integrity: String, media: String, prefetch: { type: Boolean, default: void 0 }, referrerpolicy: String, rel: String, sizes: String, title: String, type: String, /** @deprecated **/ methods: String, /** @deprecated **/ target: String, body: Boolean, renderPriority: [String, Number] }, setup: setupForUseMeta((link) => ({ link: [link] })) }); export const Base = defineComponent({ name: "Base", inheritAttrs: false, props: { ...globalProps, href: String, target: String }, setup: setupForUseMeta((base) => ({ base })) }); export const Title = defineComponent({ name: "Title", inheritAttrs: false, setup: setupForUseMeta((_, { slots }) => { if (import.meta.dev) { const defaultSlot = slots.default?.(); if (defaultSlot && (defaultSlot.length > 1 || typeof defaultSlot[0].children !== "string")) { console.error("<Title> can take only one string in its default slot."); } return { title: defaultSlot?.[0]?.children || null }; } return { title: slots.default?.()?.[0]?.children || null }; }) }); export const Meta = defineComponent({ name: "Meta", inheritAttrs: false, props: { ...globalProps, charset: String, content: String, httpEquiv: String, name: String, body: Boolean, renderPriority: [String, Number] }, setup: setupForUseMeta((props) => { const meta = { ...props }; if (meta.httpEquiv) { meta["http-equiv"] = meta.httpEquiv; delete meta.httpEquiv; } return { meta: [meta] }; }) }); export const Style = defineComponent({ name: "Style", inheritAttrs: false, props: { ...globalProps, type: String, media: String, nonce: String, title: String, /** @deprecated **/ scoped: { type: Boolean, default: void 0 }, body: Boolean, renderPriority: [String, Number] }, setup: setupForUseMeta((props, { slots }) => { const style = { ...props }; const textContent = slots.default?.()?.[0]?.children; if (textContent) { if (import.meta.dev && typeof textContent !== "string") { console.error("<Style> can only take a string in its default slot."); } style.children = textContent; } return { style: [style] }; }) }); export const Head = defineComponent({ name: "Head", inheritAttrs: false, setup: (_props, ctx) => () => ctx.slots.default?.() }); export const Html = defineComponent({ name: "Html", inheritAttrs: false, props: { ...globalProps, manifest: String, version: String, xmlns: String, renderPriority: [String, Number] }, setup: setupForUseMeta((htmlAttrs) => ({ htmlAttrs }), true) }); export const Body = defineComponent({ name: "Body", inheritAttrs: false, props: { ...globalProps, renderPriority: [String, Number] }, setup: setupForUseMeta((bodyAttrs) => ({ bodyAttrs }), true) });