2023-07-24 03:13:08 +00:00
'use strict' ;
Object . defineProperty ( exports , '__esModule' , { value : true } ) ;
2023-09-06 01:51:55 +00:00
var Vue = require ( 'vue' ) ;
2023-07-24 03:13:08 +00:00
var shared = require ( '@vue/shared' ) ;
var compilerSsr = require ( '@vue/compiler-ssr' ) ;
2023-09-06 01:51:55 +00:00
function _interopNamespaceDefault ( e ) {
var n = Object . create ( null ) ;
if ( e ) {
for ( var k in e ) {
n [ k ] = e [ k ] ;
2023-07-24 03:13:08 +00:00
}
2023-09-06 01:51:55 +00:00
}
n . default = e ;
return Object . freeze ( n ) ;
}
var Vue _ _namespace = /*#__PURE__*/ _interopNamespaceDefault ( Vue ) ;
const shouldIgnoreProp = shared . makeMap (
` ,key,ref,innerHTML,textContent,ref_key,ref_for `
) ;
function ssrRenderAttrs ( props , tag ) {
let ret = "" ;
for ( const key in props ) {
if ( shouldIgnoreProp ( key ) || shared . isOn ( key ) || tag === "textarea" && key === "value" ) {
continue ;
}
const value = props [ key ] ;
if ( key === "class" ) {
ret += ` class=" ${ ssrRenderClass ( value ) } " ` ;
} else if ( key === "style" ) {
ret += ` style=" ${ ssrRenderStyle ( value ) } " ` ;
} else {
ret += ssrRenderDynamicAttr ( key , value , tag ) ;
}
}
return ret ;
2023-07-24 03:13:08 +00:00
}
function ssrRenderDynamicAttr ( key , value , tag ) {
2023-09-06 01:51:55 +00:00
if ( ! isRenderableValue ( value ) ) {
return ` ` ;
}
const attrKey = tag && ( tag . indexOf ( "-" ) > 0 || shared . isSVGTag ( tag ) ) ? key : shared . propsToAttrMap [ key ] || key . toLowerCase ( ) ;
if ( shared . isBooleanAttr ( attrKey ) ) {
return shared . includeBooleanAttr ( value ) ? ` ${ attrKey } ` : ` ` ;
} else if ( shared . isSSRSafeAttrName ( attrKey ) ) {
return value === "" ? ` ${ attrKey } ` : ` ${ attrKey } =" ${ shared . escapeHtml ( value ) } " ` ;
} else {
console . warn (
` [@vue/server-renderer] Skipped rendering unsafe attribute name: ${ attrKey } `
) ;
return ` ` ;
}
2023-07-24 03:13:08 +00:00
}
function ssrRenderAttr ( key , value ) {
2023-09-06 01:51:55 +00:00
if ( ! isRenderableValue ( value ) ) {
return ` ` ;
}
return ` ${ key } =" ${ shared . escapeHtml ( value ) } " ` ;
2023-07-24 03:13:08 +00:00
}
function isRenderableValue ( value ) {
2023-09-06 01:51:55 +00:00
if ( value == null ) {
return false ;
}
const type = typeof value ;
return type === "string" || type === "number" || type === "boolean" ;
2023-07-24 03:13:08 +00:00
}
function ssrRenderClass ( raw ) {
2023-09-06 01:51:55 +00:00
return shared . escapeHtml ( shared . normalizeClass ( raw ) ) ;
2023-07-24 03:13:08 +00:00
}
function ssrRenderStyle ( raw ) {
2023-09-06 01:51:55 +00:00
if ( ! raw ) {
return "" ;
}
if ( shared . isString ( raw ) ) {
return shared . escapeHtml ( raw ) ;
}
const styles = shared . normalizeStyle ( raw ) ;
return shared . escapeHtml ( shared . stringifyStyle ( styles ) ) ;
2023-07-24 03:13:08 +00:00
}
2023-09-06 01:51:55 +00:00
function ssrRenderComponent ( comp , props = null , children = null , parentComponent = null , slotScopeId ) {
return renderComponentVNode (
Vue . createVNode ( comp , props , children ) ,
parentComponent ,
slotScopeId
) ;
}
function ssrRenderSlot ( slots , slotName , slotProps , fallbackRenderFn , push , parentComponent , slotScopeId ) {
push ( ` <!--[--> ` ) ;
ssrRenderSlotInner (
slots ,
slotName ,
slotProps ,
fallbackRenderFn ,
push ,
parentComponent ,
slotScopeId
) ;
push ( ` <!--]--> ` ) ;
}
function ssrRenderSlotInner ( slots , slotName , slotProps , fallbackRenderFn , push , parentComponent , slotScopeId , transition ) {
const slotFn = slots [ slotName ] ;
if ( slotFn ) {
const slotBuffer = [ ] ;
const bufferedPush = ( item ) => {
slotBuffer . push ( item ) ;
2023-07-24 03:13:08 +00:00
} ;
2023-09-06 01:51:55 +00:00
const ret = slotFn (
slotProps ,
bufferedPush ,
parentComponent ,
slotScopeId ? " " + slotScopeId : ""
) ;
if ( shared . isArray ( ret ) ) {
renderVNodeChildren ( push , ret , parentComponent , slotScopeId ) ;
} else {
let isEmptySlot = true ;
if ( transition ) {
isEmptySlot = false ;
} else {
for ( let i = 0 ; i < slotBuffer . length ; i ++ ) {
if ( ! isComment ( slotBuffer [ i ] ) ) {
isEmptySlot = false ;
break ;
}
}
}
if ( isEmptySlot ) {
if ( fallbackRenderFn ) {
fallbackRenderFn ( ) ;
}
} else {
for ( let i = 0 ; i < slotBuffer . length ; i ++ ) {
push ( slotBuffer [ i ] ) ;
}
}
}
} else if ( fallbackRenderFn ) {
fallbackRenderFn ( ) ;
}
}
const commentTestRE = / ^ < ! - - . * - - > $ / s ;
const commentRE = /<!--[^]*?-->/gm ;
function isComment ( item ) {
if ( typeof item !== "string" || ! commentTestRE . test ( item ) )
return false ;
if ( item . length <= 8 )
return true ;
return ! item . replace ( commentRE , "" ) . trim ( ) ;
2023-07-24 03:13:08 +00:00
}
function ssrRenderTeleport ( parentPush , contentRenderFn , target , disabled , parentComponent ) {
2023-09-06 01:51:55 +00:00
parentPush ( "<!--teleport start-->" ) ;
const context = parentComponent . appContext . provides [ Vue . ssrContextKey ] ;
const teleportBuffers = context . _ _teleportBuffers || ( context . _ _teleportBuffers = { } ) ;
const targetBuffer = teleportBuffers [ target ] || ( teleportBuffers [ target ] = [ ] ) ;
const bufferIndex = targetBuffer . length ;
let teleportContent ;
if ( disabled ) {
contentRenderFn ( parentPush ) ;
teleportContent = ` <!--teleport anchor--> ` ;
} else {
const { getBuffer , push } = createBuffer ( ) ;
contentRenderFn ( push ) ;
push ( ` <!--teleport anchor--> ` ) ;
teleportContent = getBuffer ( ) ;
}
targetBuffer . splice ( bufferIndex , 0 , teleportContent ) ;
parentPush ( "<!--teleport end-->" ) ;
2023-07-24 03:13:08 +00:00
}
2023-09-06 01:51:55 +00:00
function ssrInterpolate ( value ) {
return shared . escapeHtml ( shared . toDisplayString ( value ) ) ;
}
function ssrRenderList ( source , renderItem ) {
if ( shared . isArray ( source ) || shared . isString ( source ) ) {
for ( let i = 0 , l = source . length ; i < l ; i ++ ) {
renderItem ( source [ i ] , i ) ;
}
} else if ( typeof source === "number" ) {
for ( let i = 0 ; i < source ; i ++ ) {
renderItem ( i + 1 , i ) ;
}
} else if ( shared . isObject ( source ) ) {
if ( source [ Symbol . iterator ] ) {
const arr = Array . from ( source ) ;
for ( let i = 0 , l = arr . length ; i < l ; i ++ ) {
renderItem ( arr [ i ] , i ) ;
}
} else {
const keys = Object . keys ( source ) ;
for ( let i = 0 , l = keys . length ; i < l ; i ++ ) {
const key = keys [ i ] ;
renderItem ( source [ key ] , key , i ) ;
}
}
}
}
async function ssrRenderSuspense ( push , { default : renderContent } ) {
if ( renderContent ) {
renderContent ( ) ;
} else {
push ( ` <!----> ` ) ;
}
}
function ssrGetDirectiveProps ( instance , dir , value , arg , modifiers = { } ) {
if ( typeof dir !== "function" && dir . getSSRProps ) {
return dir . getSSRProps (
{
dir ,
instance ,
value ,
oldValue : void 0 ,
arg ,
modifiers
} ,
null
) || { } ;
}
return { } ;
}
const ssrLooseEqual = shared . looseEqual ;
function ssrLooseContain ( arr , value ) {
return shared . looseIndexOf ( arr , value ) > - 1 ;
}
function ssrRenderDynamicModel ( type , model , value ) {
switch ( type ) {
case "radio" :
return shared . looseEqual ( model , value ) ? " checked" : "" ;
case "checkbox" :
return ( shared . isArray ( model ) ? ssrLooseContain ( model , value ) : model ) ? " checked" : "" ;
default :
return ssrRenderAttr ( "value" , model ) ;
}
}
function ssrGetDynamicModelProps ( existingProps = { } , model ) {
const { type , value } = existingProps ;
switch ( type ) {
case "radio" :
return shared . looseEqual ( model , value ) ? { checked : true } : null ;
case "checkbox" :
return ( shared . isArray ( model ) ? ssrLooseContain ( model , value ) : model ) ? { checked : true } : null ;
default :
return { value : model } ;
}
}
var helpers = /*#__PURE__*/ Object . freeze ( {
_ _proto _ _ : null ,
ssrGetDirectiveProps : ssrGetDirectiveProps ,
ssrGetDynamicModelProps : ssrGetDynamicModelProps ,
ssrIncludeBooleanAttr : shared . includeBooleanAttr ,
ssrInterpolate : ssrInterpolate ,
ssrLooseContain : ssrLooseContain ,
ssrLooseEqual : ssrLooseEqual ,
ssrRenderAttr : ssrRenderAttr ,
ssrRenderAttrs : ssrRenderAttrs ,
ssrRenderClass : ssrRenderClass ,
ssrRenderComponent : ssrRenderComponent ,
ssrRenderDynamicAttr : ssrRenderDynamicAttr ,
ssrRenderDynamicModel : ssrRenderDynamicModel ,
ssrRenderList : ssrRenderList ,
ssrRenderSlot : ssrRenderSlot ,
ssrRenderSlotInner : ssrRenderSlotInner ,
ssrRenderStyle : ssrRenderStyle ,
ssrRenderSuspense : ssrRenderSuspense ,
ssrRenderTeleport : ssrRenderTeleport ,
ssrRenderVNode : renderVNode
} ) ;
const compileCache = /* @__PURE__ */ Object . create ( null ) ;
function ssrCompile ( template , instance ) {
const Component = instance . type ;
const { isCustomElement , compilerOptions } = instance . appContext . config ;
const { delimiters , compilerOptions : componentCompilerOptions } = Component ;
const finalCompilerOptions = shared . extend (
shared . extend (
{
isCustomElement ,
delimiters
} ,
compilerOptions
) ,
componentCompilerOptions
) ;
finalCompilerOptions . isCustomElement = finalCompilerOptions . isCustomElement || shared . NO ;
finalCompilerOptions . isNativeTag = finalCompilerOptions . isNativeTag || shared . NO ;
const cacheKey = JSON . stringify (
{
template ,
compilerOptions : finalCompilerOptions
} ,
( key , value ) => {
return shared . isFunction ( value ) ? value . toString ( ) : value ;
}
) ;
const cached = compileCache [ cacheKey ] ;
if ( cached ) {
return cached ;
}
finalCompilerOptions . onError = ( err ) => {
{
throw err ;
}
} ;
const { code } = compilerSsr . compile ( template , finalCompilerOptions ) ;
const requireMap = {
vue : Vue _ _namespace ,
"vue/server-renderer" : helpers
} ;
const fakeRequire = ( id ) => requireMap [ id ] ;
return compileCache [ cacheKey ] = Function ( "require" , code ) ( fakeRequire ) ;
}
const {
createComponentInstance ,
setCurrentRenderingInstance ,
setupComponent ,
renderComponentRoot ,
normalizeVNode
} = Vue . ssrUtils ;
2023-07-24 03:13:08 +00:00
function createBuffer ( ) {
2023-09-06 01:51:55 +00:00
let appendable = false ;
const buffer = [ ] ;
return {
getBuffer ( ) {
return buffer ;
} ,
push ( item ) {
const isStringItem = shared . isString ( item ) ;
if ( appendable && isStringItem ) {
buffer [ buffer . length - 1 ] += item ;
} else {
buffer . push ( item ) ;
}
appendable = isStringItem ;
if ( shared . isPromise ( item ) || shared . isArray ( item ) && item . hasAsync ) {
buffer . hasAsync = true ;
}
}
} ;
2023-07-24 03:13:08 +00:00
}
function renderComponentVNode ( vnode , parentComponent = null , slotScopeId ) {
2023-09-06 01:51:55 +00:00
const instance = createComponentInstance ( vnode , parentComponent , null ) ;
const res = setupComponent (
instance ,
true
/* isSSR */
) ;
const hasAsyncSetup = shared . isPromise ( res ) ;
const prefetches = instance . sp ;
if ( hasAsyncSetup || prefetches ) {
let p = hasAsyncSetup ? res : Promise . resolve ( ) ;
if ( prefetches ) {
p = p . then (
( ) => Promise . all ( prefetches . map ( ( prefetch ) => prefetch . call ( instance . proxy ) ) )
) . catch ( ( ) => {
} ) ;
}
return p . then ( ( ) => renderComponentSubTree ( instance , slotScopeId ) ) ;
} else {
return renderComponentSubTree ( instance , slotScopeId ) ;
}
2023-07-24 03:13:08 +00:00
}
function renderComponentSubTree ( instance , slotScopeId ) {
2023-09-06 01:51:55 +00:00
const comp = instance . type ;
const { getBuffer , push } = createBuffer ( ) ;
if ( shared . isFunction ( comp ) ) {
let root = renderComponentRoot ( instance ) ;
if ( ! comp . props ) {
for ( const key in instance . attrs ) {
if ( key . startsWith ( ` data-v- ` ) ) {
( root . props || ( root . props = { } ) ) [ key ] = ` ` ;
}
}
}
renderVNode ( push , instance . subTree = root , instance , slotScopeId ) ;
} else {
if ( ( ! instance . render || instance . render === shared . NOOP ) && ! instance . ssrRender && ! comp . ssrRender && shared . isString ( comp . template ) ) {
comp . ssrRender = ssrCompile ( comp . template , instance ) ;
}
for ( const e of instance . scope . effects ) {
if ( e . computed )
e . computed . _cacheable = true ;
}
const ssrRender = instance . ssrRender || comp . ssrRender ;
if ( ssrRender ) {
let attrs = instance . inheritAttrs !== false ? instance . attrs : void 0 ;
let hasCloned = false ;
let cur = instance ;
while ( true ) {
const scopeId = cur . vnode . scopeId ;
if ( scopeId ) {
if ( ! hasCloned ) {
attrs = { ... attrs } ;
hasCloned = true ;
}
attrs [ scopeId ] = "" ;
}
const parent = cur . parent ;
if ( parent && parent . subTree && parent . subTree === cur . vnode ) {
cur = parent ;
} else {
break ;
}
}
if ( slotScopeId ) {
if ( ! hasCloned )
attrs = { ... attrs } ;
attrs [ slotScopeId . trim ( ) ] = "" ;
}
const prev = setCurrentRenderingInstance ( instance ) ;
try {
ssrRender (
instance . proxy ,
push ,
instance ,
attrs ,
// compiler-optimized bindings
instance . props ,
instance . setupState ,
instance . data ,
instance . ctx
) ;
} finally {
setCurrentRenderingInstance ( prev ) ;
}
} else if ( instance . render && instance . render !== shared . NOOP ) {
renderVNode (
push ,
instance . subTree = renderComponentRoot ( instance ) ,
instance ,
slotScopeId
) ;
} else {
const componentName = comp . name || comp . _ _file || ` <Anonymous> ` ;
Vue . warn ( ` Component ${ componentName } is missing template or render function. ` ) ;
push ( ` <!----> ` ) ;
}
}
return getBuffer ( ) ;
2023-07-24 03:13:08 +00:00
}
function renderVNode ( push , vnode , parentComponent , slotScopeId ) {
2023-09-06 01:51:55 +00:00
const { type , shapeFlag , children } = vnode ;
switch ( type ) {
case Vue . Text :
push ( shared . escapeHtml ( children ) ) ;
break ;
case Vue . Comment :
push (
children ? ` <!-- ${ shared . escapeHtmlComment ( children ) } --> ` : ` <!----> `
) ;
break ;
case Vue . Static :
push ( children ) ;
break ;
case Vue . Fragment :
if ( vnode . slotScopeIds ) {
slotScopeId = ( slotScopeId ? slotScopeId + " " : "" ) + vnode . slotScopeIds . join ( " " ) ;
}
push ( ` <!--[--> ` ) ;
renderVNodeChildren (
push ,
children ,
parentComponent ,
slotScopeId
) ;
push ( ` <!--]--> ` ) ;
break ;
default :
if ( shapeFlag & 1 ) {
renderElementVNode ( push , vnode , parentComponent , slotScopeId ) ;
} else if ( shapeFlag & 6 ) {
push ( renderComponentVNode ( vnode , parentComponent , slotScopeId ) ) ;
} else if ( shapeFlag & 64 ) {
renderTeleportVNode ( push , vnode , parentComponent , slotScopeId ) ;
} else if ( shapeFlag & 128 ) {
renderVNode ( push , vnode . ssContent , parentComponent , slotScopeId ) ;
} else {
Vue . warn (
"[@vue/server-renderer] Invalid VNode type:" ,
type ,
` ( ${ typeof type } ) `
) ;
}
}
2023-07-24 03:13:08 +00:00
}
function renderVNodeChildren ( push , children , parentComponent , slotScopeId ) {
2023-09-06 01:51:55 +00:00
for ( let i = 0 ; i < children . length ; i ++ ) {
renderVNode ( push , normalizeVNode ( children [ i ] ) , parentComponent , slotScopeId ) ;
}
2023-07-24 03:13:08 +00:00
}
function renderElementVNode ( push , vnode , parentComponent , slotScopeId ) {
2023-09-06 01:51:55 +00:00
const tag = vnode . type ;
let { props , children , shapeFlag , scopeId , dirs } = vnode ;
let openTag = ` < ${ tag } ` ;
if ( dirs ) {
props = applySSRDirectives ( vnode , props , dirs ) ;
}
if ( props ) {
openTag += ssrRenderAttrs ( props , tag ) ;
}
if ( scopeId ) {
openTag += ` ${ scopeId } ` ;
}
let curParent = parentComponent ;
let curVnode = vnode ;
while ( curParent && curVnode === curParent . subTree ) {
curVnode = curParent . vnode ;
if ( curVnode . scopeId ) {
openTag += ` ${ curVnode . scopeId } ` ;
}
curParent = curParent . parent ;
}
if ( slotScopeId ) {
openTag += ` ${ slotScopeId } ` ;
}
push ( openTag + ` > ` ) ;
if ( ! shared . isVoidTag ( tag ) ) {
let hasChildrenOverride = false ;
2023-07-24 03:13:08 +00:00
if ( props ) {
2023-09-06 01:51:55 +00:00
if ( props . innerHTML ) {
hasChildrenOverride = true ;
push ( props . innerHTML ) ;
} else if ( props . textContent ) {
hasChildrenOverride = true ;
push ( shared . escapeHtml ( props . textContent ) ) ;
} else if ( tag === "textarea" && props . value ) {
hasChildrenOverride = true ;
push ( shared . escapeHtml ( props . value ) ) ;
}
}
if ( ! hasChildrenOverride ) {
if ( shapeFlag & 8 ) {
push ( shared . escapeHtml ( children ) ) ;
} else if ( shapeFlag & 16 ) {
renderVNodeChildren (
push ,
children ,
parentComponent ,
slotScopeId
) ;
}
}
push ( ` </ ${ tag } > ` ) ;
}
2023-07-24 03:13:08 +00:00
}
function applySSRDirectives ( vnode , rawProps , dirs ) {
2023-09-06 01:51:55 +00:00
const toMerge = [ ] ;
for ( let i = 0 ; i < dirs . length ; i ++ ) {
const binding = dirs [ i ] ;
const {
dir : { getSSRProps }
} = binding ;
if ( getSSRProps ) {
const props = getSSRProps ( binding , vnode ) ;
if ( props )
toMerge . push ( props ) ;
}
}
return Vue . mergeProps ( rawProps || { } , ... toMerge ) ;
2023-07-24 03:13:08 +00:00
}
function renderTeleportVNode ( push , vnode , parentComponent , slotScopeId ) {
2023-09-06 01:51:55 +00:00
const target = vnode . props && vnode . props . to ;
const disabled = vnode . props && vnode . props . disabled ;
if ( ! target ) {
if ( ! disabled ) {
Vue . warn ( ` [@vue/server-renderer] Teleport is missing target prop. ` ) ;
}
return [ ] ;
}
if ( ! shared . isString ( target ) ) {
Vue . warn (
` [@vue/server-renderer] Teleport target must be a query selector string. `
) ;
return [ ] ;
}
ssrRenderTeleport (
push ,
( push2 ) => {
renderVNodeChildren (
push2 ,
vnode . children ,
parentComponent ,
slotScopeId
) ;
} ,
target ,
disabled || disabled === "" ,
parentComponent
) ;
2023-07-24 03:13:08 +00:00
}
2023-09-06 01:51:55 +00:00
const { isVNode : isVNode$1 } = Vue . ssrUtils ;
async function unrollBuffer$1 ( buffer ) {
if ( buffer . hasAsync ) {
let ret = "" ;
2023-07-24 03:13:08 +00:00
for ( let i = 0 ; i < buffer . length ; i ++ ) {
2023-09-06 01:51:55 +00:00
let item = buffer [ i ] ;
if ( shared . isPromise ( item ) ) {
item = await item ;
}
if ( shared . isString ( item ) ) {
ret += item ;
} else {
ret += await unrollBuffer$1 ( item ) ;
}
2023-07-24 03:13:08 +00:00
}
return ret ;
2023-09-06 01:51:55 +00:00
} else {
return unrollBufferSync$1 ( buffer ) ;
}
}
function unrollBufferSync$1 ( buffer ) {
let ret = "" ;
for ( let i = 0 ; i < buffer . length ; i ++ ) {
let item = buffer [ i ] ;
if ( shared . isString ( item ) ) {
ret += item ;
} else {
ret += unrollBufferSync$1 ( item ) ;
}
}
return ret ;
2023-07-24 03:13:08 +00:00
}
async function renderToString ( input , context = { } ) {
2023-09-06 01:51:55 +00:00
if ( isVNode$1 ( input ) ) {
return renderToString ( Vue . createApp ( { render : ( ) => input } ) , context ) ;
}
const vnode = Vue . createVNode ( input . _component , input . _props ) ;
vnode . appContext = input . _context ;
input . provide ( Vue . ssrContextKey , context ) ;
const buffer = await renderComponentVNode ( vnode ) ;
const result = await unrollBuffer$1 ( buffer ) ;
await resolveTeleports ( context ) ;
if ( context . _ _watcherHandles ) {
for ( const unwatch of context . _ _watcherHandles ) {
unwatch ( ) ;
}
}
return result ;
2023-07-24 03:13:08 +00:00
}
async function resolveTeleports ( context ) {
2023-09-06 01:51:55 +00:00
if ( context . _ _teleportBuffers ) {
context . teleports = context . teleports || { } ;
for ( const key in context . _ _teleportBuffers ) {
context . teleports [ key ] = await unrollBuffer$1 (
await Promise . all ( [ context . _ _teleportBuffers [ key ] ] )
) ;
2023-07-24 03:13:08 +00:00
}
2023-09-06 01:51:55 +00:00
}
2023-07-24 03:13:08 +00:00
}
2023-09-06 01:51:55 +00:00
const { isVNode } = Vue . ssrUtils ;
async function unrollBuffer ( buffer , stream ) {
if ( buffer . hasAsync ) {
2023-07-24 03:13:08 +00:00
for ( let i = 0 ; i < buffer . length ; i ++ ) {
2023-09-06 01:51:55 +00:00
let item = buffer [ i ] ;
if ( shared . isPromise ( item ) ) {
item = await item ;
}
if ( shared . isString ( item ) ) {
stream . push ( item ) ;
} else {
await unrollBuffer ( item , stream ) ;
}
}
} else {
unrollBufferSync ( buffer , stream ) ;
}
}
function unrollBufferSync ( buffer , stream ) {
for ( let i = 0 ; i < buffer . length ; i ++ ) {
let item = buffer [ i ] ;
if ( shared . isString ( item ) ) {
stream . push ( item ) ;
} else {
unrollBufferSync ( item , stream ) ;
}
}
2023-07-24 03:13:08 +00:00
}
function renderToSimpleStream ( input , context , stream ) {
2023-09-06 01:51:55 +00:00
if ( isVNode ( input ) ) {
return renderToSimpleStream (
Vue . createApp ( { render : ( ) => input } ) ,
context ,
stream
) ;
}
const vnode = Vue . createVNode ( input . _component , input . _props ) ;
vnode . appContext = input . _context ;
input . provide ( Vue . ssrContextKey , context ) ;
Promise . resolve ( renderComponentVNode ( vnode ) ) . then ( ( buffer ) => unrollBuffer ( buffer , stream ) ) . then ( ( ) => resolveTeleports ( context ) ) . then ( ( ) => {
if ( context . _ _watcherHandles ) {
for ( const unwatch of context . _ _watcherHandles ) {
unwatch ( ) ;
}
2023-07-24 03:13:08 +00:00
}
2023-09-06 01:51:55 +00:00
} ) . then ( ( ) => stream . push ( null ) ) . catch ( ( error ) => {
stream . destroy ( error ) ;
} ) ;
return stream ;
}
2023-07-24 03:13:08 +00:00
function renderToStream ( input , context = { } ) {
2023-09-06 01:51:55 +00:00
console . warn (
` [@vue/server-renderer] renderToStream is deprecated - use renderToNodeStream instead. `
) ;
return renderToNodeStream ( input , context ) ;
2023-07-24 03:13:08 +00:00
}
function renderToNodeStream ( input , context = { } ) {
2023-09-06 01:51:55 +00:00
const stream = new ( require ( "stream" ) ) . Readable ( { read ( ) {
} } ) ;
if ( ! stream ) {
throw new Error (
` ESM build of renderToStream() does not support renderToNodeStream(). Use pipeToNodeWritable() with an existing Node.js Writable stream instance instead. `
) ;
}
return renderToSimpleStream ( input , context , stream ) ;
2023-07-24 03:13:08 +00:00
}
function pipeToNodeWritable ( input , context = { } , writable ) {
2023-09-06 01:51:55 +00:00
renderToSimpleStream ( input , context , {
push ( content ) {
if ( content != null ) {
writable . write ( content ) ;
} else {
writable . end ( ) ;
}
} ,
destroy ( err ) {
writable . destroy ( err ) ;
}
} ) ;
2023-07-24 03:13:08 +00:00
}
function renderToWebStream ( input , context = { } ) {
2023-09-06 01:51:55 +00:00
if ( typeof ReadableStream !== "function" ) {
throw new Error (
` ReadableStream constructor is not available in the global scope. If the target environment does support web streams, consider using pipeToWebWritable() with an existing WritableStream instance instead. `
) ;
}
const encoder = new TextEncoder ( ) ;
let cancelled = false ;
return new ReadableStream ( {
start ( controller ) {
renderToSimpleStream ( input , context , {
push ( content ) {
if ( cancelled )
return ;
if ( content != null ) {
controller . enqueue ( encoder . encode ( content ) ) ;
} else {
controller . close ( ) ;
}
2023-07-24 03:13:08 +00:00
} ,
destroy ( err ) {
2023-09-06 01:51:55 +00:00
controller . error ( err ) ;
2023-07-24 03:13:08 +00:00
}
2023-09-06 01:51:55 +00:00
} ) ;
} ,
cancel ( ) {
cancelled = true ;
2023-07-24 03:13:08 +00:00
}
2023-09-06 01:51:55 +00:00
} ) ;
2023-07-24 03:13:08 +00:00
}
2023-09-06 01:51:55 +00:00
function pipeToWebWritable ( input , context = { } , writable ) {
const writer = writable . getWriter ( ) ;
const encoder = new TextEncoder ( ) ;
let hasReady = false ;
try {
hasReady = shared . isPromise ( writer . ready ) ;
} catch ( e ) {
}
renderToSimpleStream ( input , context , {
async push ( content ) {
if ( hasReady ) {
await writer . ready ;
}
if ( content != null ) {
return writer . write ( encoder . encode ( content ) ) ;
} else {
return writer . close ( ) ;
}
} ,
destroy ( err ) {
console . log ( err ) ;
writer . close ( ) ;
}
} ) ;
2023-07-24 03:13:08 +00:00
}
2023-09-06 01:51:55 +00:00
Vue . initDirectivesForSSR ( ) ;
2023-07-24 03:13:08 +00:00
exports . ssrIncludeBooleanAttr = shared . includeBooleanAttr ;
exports . pipeToNodeWritable = pipeToNodeWritable ;
exports . pipeToWebWritable = pipeToWebWritable ;
exports . renderToNodeStream = renderToNodeStream ;
exports . renderToSimpleStream = renderToSimpleStream ;
exports . renderToStream = renderToStream ;
exports . renderToString = renderToString ;
exports . renderToWebStream = renderToWebStream ;
exports . ssrGetDirectiveProps = ssrGetDirectiveProps ;
exports . ssrGetDynamicModelProps = ssrGetDynamicModelProps ;
exports . ssrInterpolate = ssrInterpolate ;
exports . ssrLooseContain = ssrLooseContain ;
exports . ssrLooseEqual = ssrLooseEqual ;
exports . ssrRenderAttr = ssrRenderAttr ;
exports . ssrRenderAttrs = ssrRenderAttrs ;
exports . ssrRenderClass = ssrRenderClass ;
exports . ssrRenderComponent = ssrRenderComponent ;
exports . ssrRenderDynamicAttr = ssrRenderDynamicAttr ;
exports . ssrRenderDynamicModel = ssrRenderDynamicModel ;
exports . ssrRenderList = ssrRenderList ;
exports . ssrRenderSlot = ssrRenderSlot ;
exports . ssrRenderSlotInner = ssrRenderSlotInner ;
exports . ssrRenderStyle = ssrRenderStyle ;
exports . ssrRenderSuspense = ssrRenderSuspense ;
exports . ssrRenderTeleport = ssrRenderTeleport ;
exports . ssrRenderVNode = renderVNode ;