2024-05-29 18:43:41 +00:00
import { i as is _primitive , g as get _type , s as stringify _string , D as DevalueError , a as is _plain _object , e as enumerable _symbols , b as escaped , c as DEV , d as stringify } from './chunks/stringify-D5iWhcfN.js' ;
import { s as setContext } from './chunks/lifecycle-CPZ0ouVO.js' ;
import { c as create _ssr _component , v as validate _component , m as missing _component } from './chunks/ssr-DX6yy04n.js' ;
import { a as afterUpdate } from './chunks/ssr2-BVSPLo1E.js' ;
import { H as HttpError , j as json , t as text , R as Redirect , S as SvelteKitError , A as ActionFailure } from './chunks/index-Ddp2AB5f.js' ;
import { d as decode _pathname , h as has _data _suffix , s as strip _data _suffix , a as decode _params , n as normalize _path , b as disable _search , c as add _data _suffix , m as make _trackable , r as resolve } from './chunks/exports-DuWZopOC.js' ;
import { r as readable , w as writable } from './chunks/index2-CkEewRlU.js' ;
2024-05-29 19:31:10 +00:00
import { p as public _env , s as safe _public _env , a as set _public _env , b as set _safe _public _env } from './chunks/shared-server-i79vVjEm.js' ;
2024-05-29 18:43:41 +00:00
let base = "" ;
let assets = base ;
const initial = { base , assets } ;
function override ( paths ) {
base = paths . base ;
assets = paths . assets ;
}
function reset ( ) {
base = initial . base ;
assets = initial . assets ;
}
const Root = create _ssr _component ( ( $$result , $$props , $$bindings , slots ) => {
let { stores } = $$props ;
let { page } = $$props ;
let { constructors } = $$props ;
let { components = [ ] } = $$props ;
let { form } = $$props ;
let { data _0 = null } = $$props ;
let { data _1 = null } = $$props ;
let { data _2 = null } = $$props ;
{
setContext ( "__svelte__" , stores ) ;
}
afterUpdate ( stores . page . notify ) ;
if ( $$props . stores === void 0 && $$bindings . stores && stores !== void 0 )
$$bindings . stores ( stores ) ;
if ( $$props . page === void 0 && $$bindings . page && page !== void 0 )
$$bindings . page ( page ) ;
if ( $$props . constructors === void 0 && $$bindings . constructors && constructors !== void 0 )
$$bindings . constructors ( constructors ) ;
if ( $$props . components === void 0 && $$bindings . components && components !== void 0 )
$$bindings . components ( components ) ;
if ( $$props . form === void 0 && $$bindings . form && form !== void 0 )
$$bindings . form ( form ) ;
if ( $$props . data _0 === void 0 && $$bindings . data _0 && data _0 !== void 0 )
$$bindings . data _0 ( data _0 ) ;
if ( $$props . data _1 === void 0 && $$bindings . data _1 && data _1 !== void 0 )
$$bindings . data _1 ( data _1 ) ;
if ( $$props . data _2 === void 0 && $$bindings . data _2 && data _2 !== void 0 )
$$bindings . data _2 ( data _2 ) ;
let $$settled ;
let $$rendered ;
let previous _head = $$result . head ;
do {
$$settled = true ;
$$result . head = previous _head ;
{
stores . page . set ( page ) ;
}
$$rendered = ` ${ constructors [ 1 ] ? ` ${ validate _component ( constructors [ 0 ] || missing _component , "svelte:component" ) . $$render (
$$result ,
{ data : data _0 , this : components [ 0 ] } ,
{
this : ( $$value ) => {
components [ 0 ] = $$value ;
$$settled = false ;
}
} ,
{
default : ( ) => {
return ` ${ constructors [ 2 ] ? ` ${ validate _component ( constructors [ 1 ] || missing _component , "svelte:component" ) . $$render (
$$result ,
{ data : data _1 , this : components [ 1 ] } ,
{
this : ( $$value ) => {
components [ 1 ] = $$value ;
$$settled = false ;
}
} ,
{
default : ( ) => {
return ` ${ validate _component ( constructors [ 2 ] || missing _component , "svelte:component" ) . $$render (
$$result ,
{ data : data _2 , form , this : components [ 2 ] } ,
{
this : ( $$value ) => {
components [ 2 ] = $$value ;
$$settled = false ;
}
} ,
{ }
) } ` ;
}
}
) } ` : ` $ { validate _component ( constructors [ 1 ] || missing _component , "svelte:component" ) . $$render (
$$result ,
{ data : data _1 , form , this : components [ 1 ] } ,
{
this : ( $$value ) => {
components [ 1 ] = $$value ;
$$settled = false ;
}
} ,
{ }
) } ` } ` ;
}
}
) } ` : ` $ { validate _component ( constructors [ 0 ] || missing _component , "svelte:component" ) . $$render (
$$result ,
{ data : data _0 , form , this : components [ 0 ] } ,
{
this : ( $$value ) => {
components [ 0 ] = $$value ;
$$settled = false ;
}
} ,
{ }
) } ` } ${ ` ` } ` ;
} while ( ! $$settled ) ;
return $$rendered ;
} ) ;
const options = {
app _dir : "_app" ,
app _template _contains _nonce : false ,
csp : { "mode" : "auto" , "directives" : { "upgrade-insecure-requests" : false , "block-all-mixed-content" : false } , "reportOnly" : { "upgrade-insecure-requests" : false , "block-all-mixed-content" : false } } ,
csrf _check _origin : true ,
embedded : false ,
env _public _prefix : "PUBLIC_" ,
env _private _prefix : "" ,
hooks : null ,
// added lazily, via `get_hooks`
preload _strategy : "modulepreload" ,
root : Root ,
service _worker : false ,
templates : {
app : ( { head , body , assets : assets2 , nonce , env } ) => '<!doctype html>\r\n<html lang="en">\r\n <head>\r\n <meta charset="utf-8" />\r\n <link rel="icon" href="' + assets2 + '/favicon.png" />\r\n <meta name="viewport" content="width=device-width, initial-scale=1" />\r\n ' + head + '\r\n </head>\r\n <body data-sveltekit-preload-data="hover" style="min-height: 100vh">\r\n <div style="display: contents">' + body + "</div>\r\n </body>\r\n</html>\r\n" ,
error : ( { status , message } ) => '<!doctype html>\n<html lang="en">\n <head>\n <meta charset="utf-8" />\n <title>' + message + ` </title>
< style >
body {
-- bg : white ;
-- fg : # 222 ;
-- divider : # ccc ;
background : var ( -- bg ) ;
color : var ( -- fg ) ;
font - family :
system - ui ,
- apple - system ,
BlinkMacSystemFont ,
'Segoe UI' ,
Roboto ,
Oxygen ,
Ubuntu ,
Cantarell ,
'Open Sans' ,
'Helvetica Neue' ,
sans - serif ;
display : flex ;
align - items : center ;
justify - content : center ;
height : 100 vh ;
margin : 0 ;
}
. error {
display : flex ;
align - items : center ;
max - width : 32 rem ;
margin : 0 1 rem ;
}
. status {
font - weight : 200 ;
font - size : 3 rem ;
line - height : 1 ;
position : relative ;
top : - 0.05 rem ;
}
. message {
border - left : 1 px solid var ( -- divider ) ;
padding : 0 0 0 1 rem ;
margin : 0 0 0 1 rem ;
min - height : 2.5 rem ;
display : flex ;
align - items : center ;
}
. message h1 {
font - weight : 400 ;
font - size : 1 em ;
margin : 0 ;
}
@ media ( prefers - color - scheme : dark ) {
body {
-- bg : # 222 ;
-- fg : # ddd ;
-- divider : # 666 ;
}
}
< / s t y l e >
< / h e a d >
< body >
< div class = "error" >
< span class = "status" > ` + status + '</span> \n <div class="message"> \n <h1>' + message + "</h1> \n </div> \n </div> \n </body> \n </html> \n "
} ,
2024-06-13 19:47:09 +00:00
version _hash : "qw4spd"
2024-05-29 18:43:41 +00:00
} ;
async function get _hooks ( ) {
return {
2024-05-29 19:31:10 +00:00
... await import ( './chunks/hooks.server-DfOW8mFe.js' )
2024-05-29 18:43:41 +00:00
} ;
}
const chars$1 = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$' ;
const unsafe _chars = /[<\b\f\n\r\t\0\u2028\u2029]/g ;
const reserved =
/^(?:do|if|in|for|int|let|new|try|var|byte|case|char|else|enum|goto|long|this|void|with|await|break|catch|class|const|final|float|short|super|throw|while|yield|delete|double|export|import|native|return|switch|throws|typeof|boolean|default|extends|finally|package|private|abstract|continue|debugger|function|volatile|interface|protected|transient|implements|instanceof|synchronized)$/ ;
/ * *
* Turn a value into the JavaScript that creates an equivalent value
* @ param { any } value
* @ param { ( value : any ) => string | void } [ replacer ]
* /
function uneval ( value , replacer ) {
const counts = new Map ( ) ;
/** @type {string[]} */
const keys = [ ] ;
const custom = new Map ( ) ;
/** @param {any} thing */
function walk ( thing ) {
if ( typeof thing === 'function' ) {
throw new DevalueError ( ` Cannot stringify a function ` , keys ) ;
}
if ( ! is _primitive ( thing ) ) {
if ( counts . has ( thing ) ) {
counts . set ( thing , counts . get ( thing ) + 1 ) ;
return ;
}
counts . set ( thing , 1 ) ;
if ( replacer ) {
const str = replacer ( thing ) ;
if ( typeof str === 'string' ) {
custom . set ( thing , str ) ;
return ;
}
}
const type = get _type ( thing ) ;
switch ( type ) {
case 'Number' :
case 'BigInt' :
case 'String' :
case 'Boolean' :
case 'Date' :
case 'RegExp' :
return ;
case 'Array' :
/** @type {any[]} */ ( thing ) . forEach ( ( value , i ) => {
keys . push ( ` [ ${ i } ] ` ) ;
walk ( value ) ;
keys . pop ( ) ;
} ) ;
break ;
case 'Set' :
Array . from ( thing ) . forEach ( walk ) ;
break ;
case 'Map' :
for ( const [ key , value ] of thing ) {
keys . push (
` .get( ${ is _primitive ( key ) ? stringify _primitive ( key ) : '...' } ) `
) ;
walk ( value ) ;
keys . pop ( ) ;
}
break ;
default :
if ( ! is _plain _object ( thing ) ) {
throw new DevalueError (
` Cannot stringify arbitrary non-POJOs ` ,
keys
) ;
}
if ( enumerable _symbols ( thing ) . length > 0 ) {
throw new DevalueError (
` Cannot stringify POJOs with symbolic keys ` ,
keys
) ;
}
for ( const key in thing ) {
keys . push ( ` . ${ key } ` ) ;
walk ( thing [ key ] ) ;
keys . pop ( ) ;
}
}
}
}
walk ( value ) ;
const names = new Map ( ) ;
Array . from ( counts )
. filter ( ( entry ) => entry [ 1 ] > 1 )
. sort ( ( a , b ) => b [ 1 ] - a [ 1 ] )
. forEach ( ( entry , i ) => {
names . set ( entry [ 0 ] , get _name ( i ) ) ;
} ) ;
/ * *
* @ param { any } thing
* @ returns { string }
* /
function stringify ( thing ) {
if ( names . has ( thing ) ) {
return names . get ( thing ) ;
}
if ( is _primitive ( thing ) ) {
return stringify _primitive ( thing ) ;
}
if ( custom . has ( thing ) ) {
return custom . get ( thing ) ;
}
const type = get _type ( thing ) ;
switch ( type ) {
case 'Number' :
case 'String' :
case 'Boolean' :
return ` Object( ${ stringify ( thing . valueOf ( ) ) } ) ` ;
case 'RegExp' :
return ` new RegExp( ${ stringify _string ( thing . source ) } , " ${
thing . flags
} " ) ` ;
case 'Date' :
return ` new Date( ${ thing . getTime ( ) } ) ` ;
case 'Array' :
const members = /** @type {any[]} */ ( thing ) . map ( ( v , i ) =>
i in thing ? stringify ( v ) : ''
) ;
const tail = thing . length === 0 || thing . length - 1 in thing ? '' : ',' ;
return ` [ ${ members . join ( ',' ) } ${ tail } ] ` ;
case 'Set' :
case 'Map' :
return ` new ${ type } ([ ${ Array . from ( thing ) . map ( stringify ) . join ( ',' ) } ]) ` ;
default :
const obj = ` { ${ Object . keys ( thing )
. map ( ( key ) => ` ${ safe _key ( key ) } : ${ stringify ( thing [ key ] ) } ` )
. join ( ',' ) } } ` ;
const proto = Object . getPrototypeOf ( thing ) ;
if ( proto === null ) {
return Object . keys ( thing ) . length > 0
? ` Object.assign(Object.create(null), ${ obj } ) `
: ` Object.create(null) ` ;
}
return obj ;
}
}
const str = stringify ( value ) ;
if ( names . size ) {
/** @type {string[]} */
const params = [ ] ;
/** @type {string[]} */
const statements = [ ] ;
/** @type {string[]} */
const values = [ ] ;
names . forEach ( ( name , thing ) => {
params . push ( name ) ;
if ( custom . has ( thing ) ) {
values . push ( /** @type {string} */ ( custom . get ( thing ) ) ) ;
return ;
}
if ( is _primitive ( thing ) ) {
values . push ( stringify _primitive ( thing ) ) ;
return ;
}
const type = get _type ( thing ) ;
switch ( type ) {
case 'Number' :
case 'String' :
case 'Boolean' :
values . push ( ` Object( ${ stringify ( thing . valueOf ( ) ) } ) ` ) ;
break ;
case 'RegExp' :
values . push ( thing . toString ( ) ) ;
break ;
case 'Date' :
values . push ( ` new Date( ${ thing . getTime ( ) } ) ` ) ;
break ;
case 'Array' :
values . push ( ` Array( ${ thing . length } ) ` ) ;
/** @type {any[]} */ ( thing ) . forEach ( ( v , i ) => {
statements . push ( ` ${ name } [ ${ i } ]= ${ stringify ( v ) } ` ) ;
} ) ;
break ;
case 'Set' :
values . push ( ` new Set ` ) ;
statements . push (
` ${ name } . ${ Array . from ( thing )
. map ( ( v ) => ` add( ${ stringify ( v ) } ) ` )
. join ( '.' ) } `
) ;
break ;
case 'Map' :
values . push ( ` new Map ` ) ;
statements . push (
` ${ name } . ${ Array . from ( thing )
. map ( ( [ k , v ] ) => ` set( ${ stringify ( k ) } , ${ stringify ( v ) } ) ` )
. join ( '.' ) } `
) ;
break ;
default :
values . push (
Object . getPrototypeOf ( thing ) === null ? 'Object.create(null)' : '{}'
) ;
Object . keys ( thing ) . forEach ( ( key ) => {
statements . push (
` ${ name } ${ safe _prop ( key ) } = ${ stringify ( thing [ key ] ) } `
) ;
} ) ;
}
} ) ;
statements . push ( ` return ${ str } ` ) ;
return ` (function( ${ params . join ( ',' ) } ){ ${ statements . join (
';'
) } } ( $ { values . join ( ',' ) } ) ) ` ;
} else {
return str ;
}
}
/** @param {number} num */
function get _name ( num ) {
let name = '' ;
do {
name = chars$1 [ num % chars$1 . length ] + name ;
num = ~ ~ ( num / chars$1 . length ) - 1 ;
} while ( num >= 0 ) ;
return reserved . test ( name ) ? ` ${ name } 0 ` : name ;
}
/** @param {string} c */
function escape _unsafe _char ( c ) {
return escaped [ c ] || c ;
}
/** @param {string} str */
function escape _unsafe _chars ( str ) {
return str . replace ( unsafe _chars , escape _unsafe _char ) ;
}
/** @param {string} key */
function safe _key ( key ) {
return /^[_$a-zA-Z][_$a-zA-Z0-9]*$/ . test ( key )
? key
: escape _unsafe _chars ( JSON . stringify ( key ) ) ;
}
/** @param {string} key */
function safe _prop ( key ) {
return /^[_$a-zA-Z][_$a-zA-Z0-9]*$/ . test ( key )
? ` . ${ key } `
: ` [ ${ escape _unsafe _chars ( JSON . stringify ( key ) ) } ] ` ;
}
/** @param {any} thing */
function stringify _primitive ( thing ) {
if ( typeof thing === 'string' ) return stringify _string ( thing ) ;
if ( thing === void 0 ) return 'void 0' ;
if ( thing === 0 && 1 / thing < 0 ) return '-0' ;
const str = String ( thing ) ;
if ( typeof thing === 'number' ) return str . replace ( /^(-)?0\./ , '$1.' ) ;
if ( typeof thing === 'bigint' ) return thing + 'n' ;
return str ;
}
var cookie = { } ;
/ * !
* cookie
* Copyright ( c ) 2012 - 2014 Roman Shtylman
* Copyright ( c ) 2015 Douglas Christopher Wilson
* MIT Licensed
* /
var hasRequiredCookie ;
function requireCookie ( ) {
if ( hasRequiredCookie ) return cookie ;
hasRequiredCookie = 1 ;
/ * *
* Module exports .
* @ public
* /
cookie . parse = parse ;
cookie . serialize = serialize ;
/ * *
* Module variables .
* @ private
* /
var _ _toString = Object . prototype . toString ;
/ * *
* RegExp to match field - content in RFC 7230 sec 3.2
*
* field - content = field - vchar [ 1 * ( SP / HTAB ) field - vchar ]
* field - vchar = VCHAR / obs - text
* obs - text = % x80 - FF
* /
var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/ ;
/ * *
* Parse a cookie header .
*
* Parse the given cookie header string into an object
* The object has the various cookies as keys ( names ) => values
*
* @ param { string } str
* @ param { object } [ options ]
* @ return { object }
* @ public
* /
function parse ( str , options ) {
if ( typeof str !== 'string' ) {
throw new TypeError ( 'argument str must be a string' ) ;
}
var obj = { } ;
var opt = options || { } ;
var dec = opt . decode || decode ;
var index = 0 ;
while ( index < str . length ) {
var eqIdx = str . indexOf ( '=' , index ) ;
// no more cookie pairs
if ( eqIdx === - 1 ) {
break
}
var endIdx = str . indexOf ( ';' , index ) ;
if ( endIdx === - 1 ) {
endIdx = str . length ;
} else if ( endIdx < eqIdx ) {
// backtrack on prior semicolon
index = str . lastIndexOf ( ';' , eqIdx - 1 ) + 1 ;
continue
}
var key = str . slice ( index , eqIdx ) . trim ( ) ;
// only assign once
if ( undefined === obj [ key ] ) {
var val = str . slice ( eqIdx + 1 , endIdx ) . trim ( ) ;
// quoted values
if ( val . charCodeAt ( 0 ) === 0x22 ) {
val = val . slice ( 1 , - 1 ) ;
}
obj [ key ] = tryDecode ( val , dec ) ;
}
index = endIdx + 1 ;
}
return obj ;
}
/ * *
* Serialize data into a cookie header .
*
* Serialize the a name value pair into a cookie string suitable for
* http headers . An optional options object specified cookie parameters .
*
* serialize ( 'foo' , 'bar' , { httpOnly : true } )
* => "foo=bar; httpOnly"
*
* @ param { string } name
* @ param { string } val
* @ param { object } [ options ]
* @ return { string }
* @ public
* /
function serialize ( name , val , options ) {
var opt = options || { } ;
var enc = opt . encode || encode ;
if ( typeof enc !== 'function' ) {
throw new TypeError ( 'option encode is invalid' ) ;
}
if ( ! fieldContentRegExp . test ( name ) ) {
throw new TypeError ( 'argument name is invalid' ) ;
}
var value = enc ( val ) ;
if ( value && ! fieldContentRegExp . test ( value ) ) {
throw new TypeError ( 'argument val is invalid' ) ;
}
var str = name + '=' + value ;
if ( null != opt . maxAge ) {
var maxAge = opt . maxAge - 0 ;
if ( isNaN ( maxAge ) || ! isFinite ( maxAge ) ) {
throw new TypeError ( 'option maxAge is invalid' )
}
str += '; Max-Age=' + Math . floor ( maxAge ) ;
}
if ( opt . domain ) {
if ( ! fieldContentRegExp . test ( opt . domain ) ) {
throw new TypeError ( 'option domain is invalid' ) ;
}
str += '; Domain=' + opt . domain ;
}
if ( opt . path ) {
if ( ! fieldContentRegExp . test ( opt . path ) ) {
throw new TypeError ( 'option path is invalid' ) ;
}
str += '; Path=' + opt . path ;
}
if ( opt . expires ) {
var expires = opt . expires ;
if ( ! isDate ( expires ) || isNaN ( expires . valueOf ( ) ) ) {
throw new TypeError ( 'option expires is invalid' ) ;
}
str += '; Expires=' + expires . toUTCString ( ) ;
}
if ( opt . httpOnly ) {
str += '; HttpOnly' ;
}
if ( opt . secure ) {
str += '; Secure' ;
}
if ( opt . partitioned ) {
str += '; Partitioned' ;
}
if ( opt . priority ) {
var priority = typeof opt . priority === 'string'
? opt . priority . toLowerCase ( )
: opt . priority ;
switch ( priority ) {
case 'low' :
str += '; Priority=Low' ;
break
case 'medium' :
str += '; Priority=Medium' ;
break
case 'high' :
str += '; Priority=High' ;
break
default :
throw new TypeError ( 'option priority is invalid' )
}
}
if ( opt . sameSite ) {
var sameSite = typeof opt . sameSite === 'string'
? opt . sameSite . toLowerCase ( ) : opt . sameSite ;
switch ( sameSite ) {
case true :
str += '; SameSite=Strict' ;
break ;
case 'lax' :
str += '; SameSite=Lax' ;
break ;
case 'strict' :
str += '; SameSite=Strict' ;
break ;
case 'none' :
str += '; SameSite=None' ;
break ;
default :
throw new TypeError ( 'option sameSite is invalid' ) ;
}
}
return str ;
}
/ * *
* URL - decode string value . Optimized to skip native call when no % .
*
* @ param { string } str
* @ returns { string }
* /
function decode ( str ) {
return str . indexOf ( '%' ) !== - 1
? decodeURIComponent ( str )
: str
}
/ * *
* URL - encode value .
*
* @ param { string } val
* @ returns { string }
* /
function encode ( val ) {
return encodeURIComponent ( val )
}
/ * *
* Determine if value is a Date .
*
* @ param { * } val
* @ private
* /
function isDate ( val ) {
return _ _toString . call ( val ) === '[object Date]' ||
val instanceof Date
}
/ * *
* Try decoding a string using a decoding function .
*
* @ param { string } str
* @ param { function } decode
* @ private
* /
function tryDecode ( str , decode ) {
try {
return decode ( str ) ;
} catch ( e ) {
return str ;
}
}
return cookie ;
}
var cookieExports = requireCookie ( ) ;
var setCookie = { exports : { } } ;
var hasRequiredSetCookie ;
function requireSetCookie ( ) {
if ( hasRequiredSetCookie ) return setCookie . exports ;
hasRequiredSetCookie = 1 ;
var defaultParseOptions = {
decodeValues : true ,
map : false ,
silent : false ,
} ;
function isNonEmptyString ( str ) {
return typeof str === "string" && ! ! str . trim ( ) ;
}
function parseString ( setCookieValue , options ) {
var parts = setCookieValue . split ( ";" ) . filter ( isNonEmptyString ) ;
var nameValuePairStr = parts . shift ( ) ;
var parsed = parseNameValuePair ( nameValuePairStr ) ;
var name = parsed . name ;
var value = parsed . value ;
options = options
? Object . assign ( { } , defaultParseOptions , options )
: defaultParseOptions ;
try {
value = options . decodeValues ? decodeURIComponent ( value ) : value ; // decode cookie value
} catch ( e ) {
console . error (
"set-cookie-parser encountered an error while decoding a cookie with value '" +
value +
"'. Set options.decodeValues to false to disable this feature." ,
e
) ;
}
var cookie = {
name : name ,
value : value ,
} ;
parts . forEach ( function ( part ) {
var sides = part . split ( "=" ) ;
var key = sides . shift ( ) . trimLeft ( ) . toLowerCase ( ) ;
var value = sides . join ( "=" ) ;
if ( key === "expires" ) {
cookie . expires = new Date ( value ) ;
} else if ( key === "max-age" ) {
cookie . maxAge = parseInt ( value , 10 ) ;
} else if ( key === "secure" ) {
cookie . secure = true ;
} else if ( key === "httponly" ) {
cookie . httpOnly = true ;
} else if ( key === "samesite" ) {
cookie . sameSite = value ;
} else {
cookie [ key ] = value ;
}
} ) ;
return cookie ;
}
function parseNameValuePair ( nameValuePairStr ) {
// Parses name-value-pair according to rfc6265bis draft
var name = "" ;
var value = "" ;
var nameValueArr = nameValuePairStr . split ( "=" ) ;
if ( nameValueArr . length > 1 ) {
name = nameValueArr . shift ( ) ;
value = nameValueArr . join ( "=" ) ; // everything after the first =, joined by a "=" if there was more than one part
} else {
value = nameValuePairStr ;
}
return { name : name , value : value } ;
}
function parse ( input , options ) {
options = options
? Object . assign ( { } , defaultParseOptions , options )
: defaultParseOptions ;
if ( ! input ) {
if ( ! options . map ) {
return [ ] ;
} else {
return { } ;
}
}
if ( input . headers ) {
if ( typeof input . headers . getSetCookie === "function" ) {
// for fetch responses - they combine headers of the same type in the headers array,
// but getSetCookie returns an uncombined array
input = input . headers . getSetCookie ( ) ;
} else if ( input . headers [ "set-cookie" ] ) {
// fast-path for node.js (which automatically normalizes header names to lower-case
input = input . headers [ "set-cookie" ] ;
} else {
// slow-path for other environments - see #25
var sch =
input . headers [
Object . keys ( input . headers ) . find ( function ( key ) {
return key . toLowerCase ( ) === "set-cookie" ;
} )
] ;
// warn if called on a request-like object with a cookie header rather than a set-cookie header - see #34, 36
if ( ! sch && input . headers . cookie && ! options . silent ) {
console . warn (
"Warning: set-cookie-parser appears to have been called on a request object. It is designed to parse Set-Cookie headers from responses, not Cookie headers from requests. Set the option {silent: true} to suppress this warning."
) ;
}
input = sch ;
}
}
if ( ! Array . isArray ( input ) ) {
input = [ input ] ;
}
options = options
? Object . assign ( { } , defaultParseOptions , options )
: defaultParseOptions ;
if ( ! options . map ) {
return input . filter ( isNonEmptyString ) . map ( function ( str ) {
return parseString ( str , options ) ;
} ) ;
} else {
var cookies = { } ;
return input . filter ( isNonEmptyString ) . reduce ( function ( cookies , str ) {
var cookie = parseString ( str , options ) ;
cookies [ cookie . name ] = cookie ;
return cookies ;
} , cookies ) ;
}
}
/ *
Set - Cookie header field - values are sometimes comma joined in one string . This splits them without choking on commas
that are within a single set - cookie field - value , such as in the Expires portion .
This is uncommon , but explicitly allowed - see https : //tools.ietf.org/html/rfc2616#section-4.2
Node . js does this for every header * except * set - cookie - see https : //github.com/nodejs/node/blob/d5e363b77ebaf1caf67cd7528224b651c86815c1/lib/_http_incoming.js#L128
React Native ' s fetch does this for * every * header , including set - cookie .
Based on : https : //github.com/google/j2objc/commit/16820fdbc8f76ca0c33472810ce0cb03d20efe25
Credits to : https : //github.com/tomball for original and https://github.com/chrusart for JavaScript implementation
* /
function splitCookiesString ( cookiesString ) {
if ( Array . isArray ( cookiesString ) ) {
return cookiesString ;
}
if ( typeof cookiesString !== "string" ) {
return [ ] ;
}
var cookiesStrings = [ ] ;
var pos = 0 ;
var start ;
var ch ;
var lastComma ;
var nextStart ;
var cookiesSeparatorFound ;
function skipWhitespace ( ) {
while ( pos < cookiesString . length && /\s/ . test ( cookiesString . charAt ( pos ) ) ) {
pos += 1 ;
}
return pos < cookiesString . length ;
}
function notSpecialChar ( ) {
ch = cookiesString . charAt ( pos ) ;
return ch !== "=" && ch !== ";" && ch !== "," ;
}
while ( pos < cookiesString . length ) {
start = pos ;
cookiesSeparatorFound = false ;
while ( skipWhitespace ( ) ) {
ch = cookiesString . charAt ( pos ) ;
if ( ch === "," ) {
// ',' is a cookie separator if we have later first '=', not ';' or ','
lastComma = pos ;
pos += 1 ;
skipWhitespace ( ) ;
nextStart = pos ;
while ( pos < cookiesString . length && notSpecialChar ( ) ) {
pos += 1 ;
}
// currently special character
if ( pos < cookiesString . length && cookiesString . charAt ( pos ) === "=" ) {
// we found cookies separator
cookiesSeparatorFound = true ;
// pos is inside the next cookie, so back up and return it.
pos = nextStart ;
cookiesStrings . push ( cookiesString . substring ( start , lastComma ) ) ;
start = pos ;
} else {
// in param ',' or param separator ';',
// we continue from that comma
pos = lastComma + 1 ;
}
} else {
pos += 1 ;
}
}
if ( ! cookiesSeparatorFound || pos >= cookiesString . length ) {
cookiesStrings . push ( cookiesString . substring ( start , cookiesString . length ) ) ;
}
}
return cookiesStrings ;
}
setCookie . exports = parse ;
setCookie . exports . parse = parse ;
setCookie . exports . parseString = parseString ;
setCookie . exports . splitCookiesString = splitCookiesString ;
return setCookie . exports ;
}
var setCookieExports = requireSetCookie ( ) ;
const SVELTE _KIT _ASSETS = "/_svelte_kit_assets" ;
const ENDPOINT _METHODS = [ "GET" , "POST" , "PUT" , "PATCH" , "DELETE" , "OPTIONS" , "HEAD" ] ;
const PAGE _METHODS = [ "GET" , "POST" , "HEAD" ] ;
function negotiate ( accept , types ) {
const parts = [ ] ;
accept . split ( "," ) . forEach ( ( str , i ) => {
const match = /([^/]+)\/([^;]+)(?:;q=([0-9.]+))?/ . exec ( str ) ;
if ( match ) {
const [ , type , subtype , q = "1" ] = match ;
parts . push ( { type , subtype , q : + q , i } ) ;
}
} ) ;
parts . sort ( ( a , b ) => {
if ( a . q !== b . q ) {
return b . q - a . q ;
}
if ( a . subtype === "*" !== ( b . subtype === "*" ) ) {
return a . subtype === "*" ? 1 : - 1 ;
}
if ( a . type === "*" !== ( b . type === "*" ) ) {
return a . type === "*" ? 1 : - 1 ;
}
return a . i - b . i ;
} ) ;
let accepted ;
let min _priority = Infinity ;
for ( const mimetype of types ) {
const [ type , subtype ] = mimetype . split ( "/" ) ;
const priority = parts . findIndex (
( part ) => ( part . type === type || part . type === "*" ) && ( part . subtype === subtype || part . subtype === "*" )
) ;
if ( priority !== - 1 && priority < min _priority ) {
accepted = mimetype ;
min _priority = priority ;
}
}
return accepted ;
}
function is _content _type ( request , ... types ) {
const type = request . headers . get ( "content-type" ) ? . split ( ";" , 1 ) [ 0 ] . trim ( ) ? ? "" ;
return types . includes ( type . toLowerCase ( ) ) ;
}
function is _form _content _type ( request ) {
return is _content _type (
request ,
"application/x-www-form-urlencoded" ,
"multipart/form-data" ,
"text/plain"
) ;
}
function coalesce _to _error ( err ) {
return err instanceof Error || err && /** @type {any} */
err . name && /** @type {any} */
err . message ? (
/** @type {Error} */
err
) : new Error ( JSON . stringify ( err ) ) ;
}
function normalize _error ( error ) {
return (
/** @type {import('../runtime/control.js').Redirect | HttpError | SvelteKitError | Error} */
error
) ;
}
function get _status ( error ) {
return error instanceof HttpError || error instanceof SvelteKitError ? error . status : 500 ;
}
function get _message ( error ) {
return error instanceof SvelteKitError ? error . text : "Internal Error" ;
}
function method _not _allowed ( mod , method ) {
return text ( ` ${ method } method not allowed ` , {
status : 405 ,
headers : {
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/405
// "The server must generate an Allow header field in a 405 status code response"
allow : allowed _methods ( mod ) . join ( ", " )
}
} ) ;
}
function allowed _methods ( mod ) {
const allowed = ENDPOINT _METHODS . filter ( ( method ) => method in mod ) ;
if ( "GET" in mod || "HEAD" in mod )
allowed . push ( "HEAD" ) ;
return allowed ;
}
function static _error _page ( options2 , status , message ) {
let page = options2 . templates . error ( { status , message } ) ;
return text ( page , {
headers : { "content-type" : "text/html; charset=utf-8" } ,
status
} ) ;
}
async function handle _fatal _error ( event , options2 , error ) {
error = error instanceof HttpError ? error : coalesce _to _error ( error ) ;
const status = get _status ( error ) ;
const body2 = await handle _error _and _jsonify ( event , options2 , error ) ;
const type = negotiate ( event . request . headers . get ( "accept" ) || "text/html" , [
"application/json" ,
"text/html"
] ) ;
if ( event . isDataRequest || type === "application/json" ) {
return json ( body2 , {
status
} ) ;
}
return static _error _page ( options2 , status , body2 . message ) ;
}
async function handle _error _and _jsonify ( event , options2 , error ) {
if ( error instanceof HttpError ) {
return error . body ;
}
const status = get _status ( error ) ;
const message = get _message ( error ) ;
return await options2 . hooks . handleError ( { error , event , status , message } ) ? ? { message } ;
}
function redirect _response ( status , location ) {
const response = new Response ( void 0 , {
status ,
headers : { location }
} ) ;
return response ;
}
function clarify _devalue _error ( event , error ) {
if ( error . path ) {
return ` Data returned from \` load \` while rendering ${ event . route . id } is not serializable: ${ error . message } (data ${ error . path } ) ` ;
}
if ( error . path === "" ) {
return ` Data returned from \` load \` while rendering ${ event . route . id } is not a plain object ` ;
}
return error . message ;
}
function stringify _uses ( node ) {
const uses = [ ] ;
if ( node . uses && node . uses . dependencies . size > 0 ) {
uses . push ( ` "dependencies": ${ JSON . stringify ( Array . from ( node . uses . dependencies ) ) } ` ) ;
}
if ( node . uses && node . uses . search _params . size > 0 ) {
uses . push ( ` "search_params": ${ JSON . stringify ( Array . from ( node . uses . search _params ) ) } ` ) ;
}
if ( node . uses && node . uses . params . size > 0 ) {
uses . push ( ` "params": ${ JSON . stringify ( Array . from ( node . uses . params ) ) } ` ) ;
}
if ( node . uses ? . parent )
uses . push ( '"parent":1' ) ;
if ( node . uses ? . route )
uses . push ( '"route":1' ) ;
if ( node . uses ? . url )
uses . push ( '"url":1' ) ;
return ` "uses":{ ${ uses . join ( "," ) } } ` ;
}
async function render _endpoint ( event , mod , state ) {
const method = (
/** @type {import('types').HttpMethod} */
event . request . method
) ;
let handler = mod [ method ] || mod . fallback ;
if ( method === "HEAD" && mod . GET && ! mod . HEAD ) {
handler = mod . GET ;
}
if ( ! handler ) {
return method _not _allowed ( mod , method ) ;
}
const prerender = mod . prerender ? ? state . prerender _default ;
if ( prerender && ( mod . POST || mod . PATCH || mod . PUT || mod . DELETE ) ) {
throw new Error ( "Cannot prerender endpoints that have mutative methods" ) ;
}
if ( state . prerendering && ! prerender ) {
if ( state . depth > 0 ) {
throw new Error ( ` ${ event . route . id } is not prerenderable ` ) ;
} else {
return new Response ( void 0 , { status : 204 } ) ;
}
}
try {
let response = await handler (
/** @type {import('@sveltejs/kit').RequestEvent<Record<string, any>>} */
event
) ;
if ( ! ( response instanceof Response ) ) {
throw new Error (
` Invalid response from route ${ event . url . pathname } : handler should return a Response object `
) ;
}
if ( state . prerendering ) {
response = new Response ( response . body , {
status : response . status ,
statusText : response . statusText ,
headers : new Headers ( response . headers )
} ) ;
response . headers . set ( "x-sveltekit-prerender" , String ( prerender ) ) ;
}
return response ;
} catch ( e ) {
if ( e instanceof Redirect ) {
return new Response ( void 0 , {
status : e . status ,
headers : { location : e . location }
} ) ;
}
throw e ;
}
}
function is _endpoint _request ( event ) {
const { method , headers : headers2 } = event . request ;
if ( ENDPOINT _METHODS . includes ( method ) && ! PAGE _METHODS . includes ( method ) ) {
return true ;
}
if ( method === "POST" && headers2 . get ( "x-sveltekit-action" ) === "true" )
return false ;
const accept = event . request . headers . get ( "accept" ) ? ? "*/*" ;
return negotiate ( accept , [ "*" , "text/html" ] ) !== "text/html" ;
}
function compact ( arr ) {
return arr . filter (
/** @returns {val is NonNullable<T>} */
( val ) => val != null
) ;
}
function is _action _json _request ( event ) {
const accept = negotiate ( event . request . headers . get ( "accept" ) ? ? "*/*" , [
"application/json" ,
"text/html"
] ) ;
return accept === "application/json" && event . request . method === "POST" ;
}
async function handle _action _json _request ( event , options2 , server ) {
const actions = server ? . actions ;
if ( ! actions ) {
const no _actions _error = new SvelteKitError (
405 ,
"Method Not Allowed" ,
"POST method not allowed. No actions exist for this page"
) ;
return action _json (
{
type : "error" ,
error : await handle _error _and _jsonify ( event , options2 , no _actions _error )
} ,
{
status : no _actions _error . status ,
headers : {
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/405
// "The server must generate an Allow header field in a 405 status code response"
allow : "GET"
}
}
) ;
}
check _named _default _separate ( actions ) ;
try {
const data = await call _action ( event , actions ) ;
if ( false )
;
if ( data instanceof ActionFailure ) {
return action _json ( {
type : "failure" ,
status : data . status ,
// @ts-expect-error we assign a string to what is supposed to be an object. That's ok
// because we don't use the object outside, and this way we have better code navigation
// through knowing where the related interface is used.
data : stringify _action _response (
data . data ,
/** @type {string} */
event . route . id
)
} ) ;
} else {
return action _json ( {
type : "success" ,
status : data ? 200 : 204 ,
// @ts-expect-error see comment above
data : stringify _action _response (
data ,
/** @type {string} */
event . route . id
)
} ) ;
}
} catch ( e ) {
const err = normalize _error ( e ) ;
if ( err instanceof Redirect ) {
return action _json _redirect ( err ) ;
}
return action _json (
{
type : "error" ,
error : await handle _error _and _jsonify ( event , options2 , check _incorrect _fail _use ( err ) )
} ,
{
status : get _status ( err )
}
) ;
}
}
function check _incorrect _fail _use ( error ) {
return error instanceof ActionFailure ? new Error ( 'Cannot "throw fail()". Use "return fail()"' ) : error ;
}
function action _json _redirect ( redirect ) {
return action _json ( {
type : "redirect" ,
status : redirect . status ,
location : redirect . location
} ) ;
}
function action _json ( data , init2 ) {
return json ( data , init2 ) ;
}
function is _action _request ( event ) {
return event . request . method === "POST" ;
}
async function handle _action _request ( event , server ) {
const actions = server ? . actions ;
if ( ! actions ) {
event . setHeaders ( {
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/405
// "The server must generate an Allow header field in a 405 status code response"
allow : "GET"
} ) ;
return {
type : "error" ,
error : new SvelteKitError (
405 ,
"Method Not Allowed" ,
"POST method not allowed. No actions exist for this page"
)
} ;
}
check _named _default _separate ( actions ) ;
try {
const data = await call _action ( event , actions ) ;
if ( false )
;
if ( data instanceof ActionFailure ) {
return {
type : "failure" ,
status : data . status ,
data : data . data
} ;
} else {
return {
type : "success" ,
status : 200 ,
// @ts-expect-error this will be removed upon serialization, so `undefined` is the same as omission
data
} ;
}
} catch ( e ) {
const err = normalize _error ( e ) ;
if ( err instanceof Redirect ) {
return {
type : "redirect" ,
status : err . status ,
location : err . location
} ;
}
return {
type : "error" ,
error : check _incorrect _fail _use ( err )
} ;
}
}
function check _named _default _separate ( actions ) {
if ( actions . default && Object . keys ( actions ) . length > 1 ) {
throw new Error (
"When using named actions, the default action cannot be used. See the docs for more info: https://kit.svelte.dev/docs/form-actions#named-actions"
) ;
}
}
async function call _action ( event , actions ) {
const url = new URL ( event . request . url ) ;
let name = "default" ;
for ( const param of url . searchParams ) {
if ( param [ 0 ] . startsWith ( "/" ) ) {
name = param [ 0 ] . slice ( 1 ) ;
if ( name === "default" ) {
throw new Error ( 'Cannot use reserved action name "default"' ) ;
}
break ;
}
}
const action = actions [ name ] ;
if ( ! action ) {
throw new SvelteKitError ( 404 , "Not Found" , ` No action with name ' ${ name } ' found ` ) ;
}
if ( ! is _form _content _type ( event . request ) ) {
throw new SvelteKitError (
415 ,
"Unsupported Media Type" ,
` Form actions expect form-encoded data — received ${ event . request . headers . get (
"content-type"
) } `
) ;
}
return action ( event ) ;
}
function uneval _action _response ( data , route _id ) {
return try _deserialize ( data , uneval , route _id ) ;
}
function stringify _action _response ( data , route _id ) {
return try _deserialize ( data , stringify , route _id ) ;
}
function try _deserialize ( data , fn , route _id ) {
try {
return fn ( data ) ;
} catch ( e ) {
const error = (
/** @type {any} */
e
) ;
if ( "path" in error ) {
let message = ` Data returned from action inside ${ route _id } is not serializable: ${ error . message } ` ;
if ( error . path !== "" )
message += ` (data. ${ error . path } ) ` ;
throw new Error ( message ) ;
}
throw error ;
}
}
const INVALIDATED _PARAM = "x-sveltekit-invalidated" ;
const TRAILING _SLASH _PARAM = "x-sveltekit-trailing-slash" ;
function b64 _encode ( buffer ) {
if ( globalThis . Buffer ) {
return Buffer . from ( buffer ) . toString ( "base64" ) ;
}
const little _endian = new Uint8Array ( new Uint16Array ( [ 1 ] ) . buffer ) [ 0 ] > 0 ;
return btoa (
new TextDecoder ( little _endian ? "utf-16le" : "utf-16be" ) . decode (
new Uint16Array ( new Uint8Array ( buffer ) )
)
) ;
}
async function load _server _data ( { event , state , node , parent } ) {
if ( ! node ? . server )
return null ;
let is _tracking = true ;
const uses = {
dependencies : /* @__PURE__ */ new Set ( ) ,
params : /* @__PURE__ */ new Set ( ) ,
parent : false ,
route : false ,
url : false ,
search _params : /* @__PURE__ */ new Set ( )
} ;
const url = make _trackable (
event . url ,
( ) => {
if ( is _tracking ) {
uses . url = true ;
}
} ,
( param ) => {
if ( is _tracking ) {
uses . search _params . add ( param ) ;
}
}
) ;
if ( state . prerendering ) {
disable _search ( url ) ;
}
const result = await node . server . load ? . call ( null , {
... event ,
fetch : ( info , init2 ) => {
new URL ( info instanceof Request ? info . url : info , event . url ) ;
return event . fetch ( info , init2 ) ;
} ,
/** @param {string[]} deps */
depends : ( ... deps ) => {
for ( const dep of deps ) {
const { href } = new URL ( dep , event . url ) ;
uses . dependencies . add ( href ) ;
}
} ,
params : new Proxy ( event . params , {
get : ( target , key2 ) => {
if ( is _tracking ) {
uses . params . add ( key2 ) ;
}
return target [
/** @type {string} */
key2
] ;
}
} ) ,
parent : async ( ) => {
if ( is _tracking ) {
uses . parent = true ;
}
return parent ( ) ;
} ,
route : new Proxy ( event . route , {
get : ( target , key2 ) => {
if ( is _tracking ) {
uses . route = true ;
}
return target [
/** @type {'id'} */
key2
] ;
}
} ) ,
url ,
untrack ( fn ) {
is _tracking = false ;
try {
return fn ( ) ;
} finally {
is _tracking = true ;
}
}
} ) ;
return {
type : "data" ,
data : result ? ? null ,
uses ,
slash : node . server . trailingSlash
} ;
}
async function load _data ( {
event ,
fetched ,
node ,
parent ,
server _data _promise ,
state ,
resolve _opts ,
csr
} ) {
const server _data _node = await server _data _promise ;
if ( ! node ? . universal ? . load ) {
return server _data _node ? . data ? ? null ;
}
const result = await node . universal . load . call ( null , {
url : event . url ,
params : event . params ,
data : server _data _node ? . data ? ? null ,
route : event . route ,
fetch : create _universal _fetch ( event , state , fetched , csr , resolve _opts ) ,
setHeaders : event . setHeaders ,
depends : ( ) => {
} ,
parent ,
untrack : ( fn ) => fn ( )
} ) ;
return result ? ? null ;
}
function create _universal _fetch ( event , state , fetched , csr , resolve _opts ) {
const universal _fetch = async ( input , init2 ) => {
const cloned _body = input instanceof Request && input . body ? input . clone ( ) . body : null ;
const cloned _headers = input instanceof Request && [ ... input . headers ] . length ? new Headers ( input . headers ) : init2 ? . headers ;
let response = await event . fetch ( input , init2 ) ;
const url = new URL ( input instanceof Request ? input . url : input , event . url ) ;
const same _origin = url . origin === event . url . origin ;
let dependency ;
if ( same _origin ) {
if ( state . prerendering ) {
dependency = { response , body : null } ;
state . prerendering . dependencies . set ( url . pathname , dependency ) ;
}
} else {
const mode = input instanceof Request ? input . mode : init2 ? . mode ? ? "cors" ;
if ( mode === "no-cors" ) {
response = new Response ( "" , {
status : response . status ,
statusText : response . statusText ,
headers : response . headers
} ) ;
} else {
const acao = response . headers . get ( "access-control-allow-origin" ) ;
if ( ! acao || acao !== event . url . origin && acao !== "*" ) {
throw new Error (
` CORS error: ${ acao ? "Incorrect" : "No" } 'Access-Control-Allow-Origin' header is present on the requested resource `
) ;
}
}
}
const proxy = new Proxy ( response , {
get ( response2 , key2 , _receiver ) {
async function push _fetched ( body2 , is _b64 ) {
const status _number = Number ( response2 . status ) ;
if ( isNaN ( status _number ) ) {
throw new Error (
` response.status is not a number. value: " ${ response2 . status } " type: ${ typeof response2 . status } `
) ;
}
fetched . push ( {
url : same _origin ? url . href . slice ( event . url . origin . length ) : url . href ,
method : event . request . method ,
request _body : (
/** @type {string | ArrayBufferView | undefined} */
input instanceof Request && cloned _body ? await stream _to _string ( cloned _body ) : init2 ? . body
) ,
request _headers : cloned _headers ,
response _body : body2 ,
response : response2 ,
is _b64
} ) ;
}
if ( key2 === "arrayBuffer" ) {
return async ( ) => {
const buffer = await response2 . arrayBuffer ( ) ;
if ( dependency ) {
dependency . body = new Uint8Array ( buffer ) ;
}
if ( buffer instanceof ArrayBuffer ) {
await push _fetched ( b64 _encode ( buffer ) , true ) ;
}
return buffer ;
} ;
}
async function text2 ( ) {
const body2 = await response2 . text ( ) ;
if ( ! body2 || typeof body2 === "string" ) {
await push _fetched ( body2 , false ) ;
}
if ( dependency ) {
dependency . body = body2 ;
}
return body2 ;
}
if ( key2 === "text" ) {
return text2 ;
}
if ( key2 === "json" ) {
return async ( ) => {
return JSON . parse ( await text2 ( ) ) ;
} ;
}
return Reflect . get ( response2 , key2 , response2 ) ;
}
} ) ;
if ( csr ) {
const get = response . headers . get ;
response . headers . get = ( key2 ) => {
const lower = key2 . toLowerCase ( ) ;
const value = get . call ( response . headers , lower ) ;
if ( value && ! lower . startsWith ( "x-sveltekit-" ) ) {
const included = resolve _opts . filterSerializedResponseHeaders ( lower , value ) ;
if ( ! included ) {
throw new Error (
` Failed to get response header " ${ lower } " — it must be included by the \` filterSerializedResponseHeaders \` option: https://kit.svelte.dev/docs/hooks#server-hooks-handle (at ${ event . route . id } ) `
) ;
}
}
return value ;
} ;
}
return proxy ;
} ;
return ( input , init2 ) => {
const response = universal _fetch ( input , init2 ) ;
response . catch ( ( ) => {
} ) ;
return response ;
} ;
}
async function stream _to _string ( stream ) {
let result = "" ;
const reader = stream . getReader ( ) ;
const decoder = new TextDecoder ( ) ;
while ( true ) {
const { done , value } = await reader . read ( ) ;
if ( done ) {
break ;
}
result += decoder . decode ( value ) ;
}
return result ;
}
function hash ( ... values ) {
let hash2 = 5381 ;
for ( const value of values ) {
if ( typeof value === "string" ) {
let i = value . length ;
while ( i )
hash2 = hash2 * 33 ^ value . charCodeAt ( -- i ) ;
} else if ( ArrayBuffer . isView ( value ) ) {
const buffer = new Uint8Array ( value . buffer , value . byteOffset , value . byteLength ) ;
let i = buffer . length ;
while ( i )
hash2 = hash2 * 33 ^ buffer [ -- i ] ;
} else {
throw new TypeError ( "value must be a string or TypedArray" ) ;
}
}
return ( hash2 >>> 0 ) . toString ( 36 ) ;
}
const escape _html _attr _dict = {
"&" : "&" ,
'"' : """
} ;
const escape _html _attr _regex = new RegExp (
// special characters
` [ ${ Object . keys ( escape _html _attr _dict ) . join ( "" ) } ]|[ \\ ud800- \\ udbff](?![ \\ udc00- \\ udfff])|[ \\ ud800- \\ udbff][ \\ udc00- \\ udfff]|[ \\ udc00- \\ udfff] ` ,
"g"
) ;
function escape _html _attr ( str ) {
const escaped _str = str . replace ( escape _html _attr _regex , ( match ) => {
if ( match . length === 2 ) {
return match ;
}
return escape _html _attr _dict [ match ] ? ? ` &# ${ match . charCodeAt ( 0 ) } ; ` ;
} ) ;
return ` " ${ escaped _str } " ` ;
}
const replacements = {
"<" : "\\u003C" ,
"\u2028" : "\\u2028" ,
"\u2029" : "\\u2029"
} ;
const pattern = new RegExp ( ` [ ${ Object . keys ( replacements ) . join ( "" ) } ] ` , "g" ) ;
function serialize _data ( fetched , filter , prerendering2 = false ) {
const headers2 = { } ;
let cache _control = null ;
let age = null ;
let varyAny = false ;
for ( const [ key2 , value ] of fetched . response . headers ) {
if ( filter ( key2 , value ) ) {
headers2 [ key2 ] = value ;
}
if ( key2 === "cache-control" )
cache _control = value ;
else if ( key2 === "age" )
age = value ;
else if ( key2 === "vary" && value . trim ( ) === "*" )
varyAny = true ;
}
const payload = {
status : fetched . response . status ,
statusText : fetched . response . statusText ,
headers : headers2 ,
body : fetched . response _body
} ;
const safe _payload = JSON . stringify ( payload ) . replace ( pattern , ( match ) => replacements [ match ] ) ;
const attrs = [
'type="application/json"' ,
"data-sveltekit-fetched" ,
` data-url= ${ escape _html _attr ( fetched . url ) } `
] ;
if ( fetched . is _b64 ) {
attrs . push ( "data-b64" ) ;
}
if ( fetched . request _headers || fetched . request _body ) {
const values = [ ] ;
if ( fetched . request _headers ) {
values . push ( [ ... new Headers ( fetched . request _headers ) ] . join ( "," ) ) ;
}
if ( fetched . request _body ) {
values . push ( fetched . request _body ) ;
}
attrs . push ( ` data-hash=" ${ hash ( ... values ) } " ` ) ;
}
if ( ! prerendering2 && fetched . method === "GET" && cache _control && ! varyAny ) {
const match = /s-maxage=(\d+)/g . exec ( cache _control ) ? ? /max-age=(\d+)/g . exec ( cache _control ) ;
if ( match ) {
const ttl = + match [ 1 ] - + ( age ? ? "0" ) ;
attrs . push ( ` data-ttl=" ${ ttl } " ` ) ;
}
}
return ` <script ${ attrs . join ( " " ) } > ${ safe _payload } < \/ script> ` ;
}
const s = JSON . stringify ;
const encoder$2 = new TextEncoder ( ) ;
function sha256 ( data ) {
if ( ! key [ 0 ] )
precompute ( ) ;
const out = init . slice ( 0 ) ;
const array2 = encode ( data ) ;
for ( let i = 0 ; i < array2 . length ; i += 16 ) {
const w = array2 . subarray ( i , i + 16 ) ;
let tmp ;
let a ;
let b ;
let out0 = out [ 0 ] ;
let out1 = out [ 1 ] ;
let out2 = out [ 2 ] ;
let out3 = out [ 3 ] ;
let out4 = out [ 4 ] ;
let out5 = out [ 5 ] ;
let out6 = out [ 6 ] ;
let out7 = out [ 7 ] ;
for ( let i2 = 0 ; i2 < 64 ; i2 ++ ) {
if ( i2 < 16 ) {
tmp = w [ i2 ] ;
} else {
a = w [ i2 + 1 & 15 ] ;
b = w [ i2 + 14 & 15 ] ;
tmp = w [ i2 & 15 ] = ( a >>> 7 ^ a >>> 18 ^ a >>> 3 ^ a << 25 ^ a << 14 ) + ( b >>> 17 ^ b >>> 19 ^ b >>> 10 ^ b << 15 ^ b << 13 ) + w [ i2 & 15 ] + w [ i2 + 9 & 15 ] | 0 ;
}
tmp = tmp + out7 + ( out4 >>> 6 ^ out4 >>> 11 ^ out4 >>> 25 ^ out4 << 26 ^ out4 << 21 ^ out4 << 7 ) + ( out6 ^ out4 & ( out5 ^ out6 ) ) + key [ i2 ] ;
out7 = out6 ;
out6 = out5 ;
out5 = out4 ;
out4 = out3 + tmp | 0 ;
out3 = out2 ;
out2 = out1 ;
out1 = out0 ;
out0 = tmp + ( out1 & out2 ^ out3 & ( out1 ^ out2 ) ) + ( out1 >>> 2 ^ out1 >>> 13 ^ out1 >>> 22 ^ out1 << 30 ^ out1 << 19 ^ out1 << 10 ) | 0 ;
}
out [ 0 ] = out [ 0 ] + out0 | 0 ;
out [ 1 ] = out [ 1 ] + out1 | 0 ;
out [ 2 ] = out [ 2 ] + out2 | 0 ;
out [ 3 ] = out [ 3 ] + out3 | 0 ;
out [ 4 ] = out [ 4 ] + out4 | 0 ;
out [ 5 ] = out [ 5 ] + out5 | 0 ;
out [ 6 ] = out [ 6 ] + out6 | 0 ;
out [ 7 ] = out [ 7 ] + out7 | 0 ;
}
const bytes = new Uint8Array ( out . buffer ) ;
reverse _endianness ( bytes ) ;
return base64 ( bytes ) ;
}
const init = new Uint32Array ( 8 ) ;
const key = new Uint32Array ( 64 ) ;
function precompute ( ) {
function frac ( x ) {
return ( x - Math . floor ( x ) ) * 4294967296 ;
}
let prime = 2 ;
for ( let i = 0 ; i < 64 ; prime ++ ) {
let is _prime = true ;
for ( let factor = 2 ; factor * factor <= prime ; factor ++ ) {
if ( prime % factor === 0 ) {
is _prime = false ;
break ;
}
}
if ( is _prime ) {
if ( i < 8 ) {
init [ i ] = frac ( prime * * ( 1 / 2 ) ) ;
}
key [ i ] = frac ( prime * * ( 1 / 3 ) ) ;
i ++ ;
}
}
}
function reverse _endianness ( bytes ) {
for ( let i = 0 ; i < bytes . length ; i += 4 ) {
const a = bytes [ i + 0 ] ;
const b = bytes [ i + 1 ] ;
const c = bytes [ i + 2 ] ;
const d = bytes [ i + 3 ] ;
bytes [ i + 0 ] = d ;
bytes [ i + 1 ] = c ;
bytes [ i + 2 ] = b ;
bytes [ i + 3 ] = a ;
}
}
function encode ( str ) {
const encoded = encoder$2 . encode ( str ) ;
const length = encoded . length * 8 ;
const size = 512 * Math . ceil ( ( length + 65 ) / 512 ) ;
const bytes = new Uint8Array ( size / 8 ) ;
bytes . set ( encoded ) ;
bytes [ encoded . length ] = 128 ;
reverse _endianness ( bytes ) ;
const words = new Uint32Array ( bytes . buffer ) ;
words [ words . length - 2 ] = Math . floor ( length / 4294967296 ) ;
words [ words . length - 1 ] = length ;
return words ;
}
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" . split ( "" ) ;
function base64 ( bytes ) {
const l = bytes . length ;
let result = "" ;
let i ;
for ( i = 2 ; i < l ; i += 3 ) {
result += chars [ bytes [ i - 2 ] >> 2 ] ;
result += chars [ ( bytes [ i - 2 ] & 3 ) << 4 | bytes [ i - 1 ] >> 4 ] ;
result += chars [ ( bytes [ i - 1 ] & 15 ) << 2 | bytes [ i ] >> 6 ] ;
result += chars [ bytes [ i ] & 63 ] ;
}
if ( i === l + 1 ) {
result += chars [ bytes [ i - 2 ] >> 2 ] ;
result += chars [ ( bytes [ i - 2 ] & 3 ) << 4 ] ;
result += "==" ;
}
if ( i === l ) {
result += chars [ bytes [ i - 2 ] >> 2 ] ;
result += chars [ ( bytes [ i - 2 ] & 3 ) << 4 | bytes [ i - 1 ] >> 4 ] ;
result += chars [ ( bytes [ i - 1 ] & 15 ) << 2 ] ;
result += "=" ;
}
return result ;
}
const array = new Uint8Array ( 16 ) ;
function generate _nonce ( ) {
crypto . getRandomValues ( array ) ;
return base64 ( array ) ;
}
const quoted = /* @__PURE__ */ new Set ( [
"self" ,
"unsafe-eval" ,
"unsafe-hashes" ,
"unsafe-inline" ,
"none" ,
"strict-dynamic" ,
"report-sample" ,
"wasm-unsafe-eval" ,
"script"
] ) ;
const crypto _pattern = /^(nonce|sha\d\d\d)-/ ;
class BaseProvider {
/** @type {boolean} */
# use _hashes ;
/** @type {boolean} */
# script _needs _csp ;
/** @type {boolean} */
# style _needs _csp ;
/** @type {import('types').CspDirectives} */
# directives ;
/** @type {import('types').Csp.Source[]} */
# script _src ;
/** @type {import('types').Csp.Source[]} */
# script _src _elem ;
/** @type {import('types').Csp.Source[]} */
# style _src ;
/** @type {import('types').Csp.Source[]} */
# style _src _attr ;
/** @type {import('types').Csp.Source[]} */
# style _src _elem ;
/** @type {string} */
# nonce ;
/ * *
* @ param { boolean } use _hashes
* @ param { import ( 'types' ) . CspDirectives } directives
* @ param { string } nonce
* /
constructor ( use _hashes , directives , nonce ) {
this . # use _hashes = use _hashes ;
this . # directives = directives ;
const d = this . # directives ;
this . # script _src = [ ] ;
this . # script _src _elem = [ ] ;
this . # style _src = [ ] ;
this . # style _src _attr = [ ] ;
this . # style _src _elem = [ ] ;
const effective _script _src = d [ "script-src" ] || d [ "default-src" ] ;
const script _src _elem = d [ "script-src-elem" ] ;
const effective _style _src = d [ "style-src" ] || d [ "default-src" ] ;
const style _src _attr = d [ "style-src-attr" ] ;
const style _src _elem = d [ "style-src-elem" ] ;
this . # script _needs _csp = ! ! effective _script _src && effective _script _src . filter ( ( value ) => value !== "unsafe-inline" ) . length > 0 || ! ! script _src _elem && script _src _elem . filter ( ( value ) => value !== "unsafe-inline" ) . length > 0 ;
this . # style _needs _csp = ! ! effective _style _src && effective _style _src . filter ( ( value ) => value !== "unsafe-inline" ) . length > 0 || ! ! style _src _attr && style _src _attr . filter ( ( value ) => value !== "unsafe-inline" ) . length > 0 || ! ! style _src _elem && style _src _elem . filter ( ( value ) => value !== "unsafe-inline" ) . length > 0 ;
this . script _needs _nonce = this . # script _needs _csp && ! this . # use _hashes ;
this . style _needs _nonce = this . # style _needs _csp && ! this . # use _hashes ;
this . # nonce = nonce ;
}
/** @param {string} content */
add _script ( content ) {
if ( this . # script _needs _csp ) {
const d = this . # directives ;
if ( this . # use _hashes ) {
const hash2 = sha256 ( content ) ;
this . # script _src . push ( ` sha256- ${ hash2 } ` ) ;
if ( d [ "script-src-elem" ] ? . length ) {
this . # script _src _elem . push ( ` sha256- ${ hash2 } ` ) ;
}
} else {
if ( this . # script _src . length === 0 ) {
this . # script _src . push ( ` nonce- ${ this . # nonce } ` ) ;
}
if ( d [ "script-src-elem" ] ? . length ) {
this . # script _src _elem . push ( ` nonce- ${ this . # nonce } ` ) ;
}
}
}
}
/** @param {string} content */
add _style ( content ) {
if ( this . # style _needs _csp ) {
const empty _comment _hash = "9OlNO0DNEeaVzHL4RZwCLsBHA8WBQ8toBp/4F5XV2nc=" ;
const d = this . # directives ;
if ( this . # use _hashes ) {
const hash2 = sha256 ( content ) ;
this . # style _src . push ( ` sha256- ${ hash2 } ` ) ;
if ( d [ "style-src-attr" ] ? . length ) {
this . # style _src _attr . push ( ` sha256- ${ hash2 } ` ) ;
}
if ( d [ "style-src-elem" ] ? . length ) {
if ( hash2 !== empty _comment _hash && ! d [ "style-src-elem" ] . includes ( ` sha256- ${ empty _comment _hash } ` ) ) {
this . # style _src _elem . push ( ` sha256- ${ empty _comment _hash } ` ) ;
}
this . # style _src _elem . push ( ` sha256- ${ hash2 } ` ) ;
}
} else {
if ( this . # style _src . length === 0 && ! d [ "style-src" ] ? . includes ( "unsafe-inline" ) ) {
this . # style _src . push ( ` nonce- ${ this . # nonce } ` ) ;
}
if ( d [ "style-src-attr" ] ? . length ) {
this . # style _src _attr . push ( ` nonce- ${ this . # nonce } ` ) ;
}
if ( d [ "style-src-elem" ] ? . length ) {
if ( ! d [ "style-src-elem" ] . includes ( ` sha256- ${ empty _comment _hash } ` ) ) {
this . # style _src _elem . push ( ` sha256- ${ empty _comment _hash } ` ) ;
}
this . # style _src _elem . push ( ` nonce- ${ this . # nonce } ` ) ;
}
}
}
}
/ * *
* @ param { boolean } [ is _meta ]
* /
get _header ( is _meta = false ) {
const header = [ ] ;
const directives = { ... this . # directives } ;
if ( this . # style _src . length > 0 ) {
directives [ "style-src" ] = [
... directives [ "style-src" ] || directives [ "default-src" ] || [ ] ,
... this . # style _src
] ;
}
if ( this . # style _src _attr . length > 0 ) {
directives [ "style-src-attr" ] = [
... directives [ "style-src-attr" ] || [ ] ,
... this . # style _src _attr
] ;
}
if ( this . # style _src _elem . length > 0 ) {
directives [ "style-src-elem" ] = [
... directives [ "style-src-elem" ] || [ ] ,
... this . # style _src _elem
] ;
}
if ( this . # script _src . length > 0 ) {
directives [ "script-src" ] = [
... directives [ "script-src" ] || directives [ "default-src" ] || [ ] ,
... this . # script _src
] ;
}
if ( this . # script _src _elem . length > 0 ) {
directives [ "script-src-elem" ] = [
... directives [ "script-src-elem" ] || [ ] ,
... this . # script _src _elem
] ;
}
for ( const key2 in directives ) {
if ( is _meta && ( key2 === "frame-ancestors" || key2 === "report-uri" || key2 === "sandbox" ) ) {
continue ;
}
const value = (
/** @type {string[] | true} */
directives [ key2 ]
) ;
if ( ! value )
continue ;
const directive = [ key2 ] ;
if ( Array . isArray ( value ) ) {
value . forEach ( ( value2 ) => {
if ( quoted . has ( value2 ) || crypto _pattern . test ( value2 ) ) {
directive . push ( ` ' ${ value2 } ' ` ) ;
} else {
directive . push ( value2 ) ;
}
} ) ;
}
header . push ( directive . join ( " " ) ) ;
}
return header . join ( "; " ) ;
}
}
class CspProvider extends BaseProvider {
get _meta ( ) {
const content = this . get _header ( true ) ;
if ( ! content ) {
return ;
}
return ` <meta http-equiv="content-security-policy" content= ${ escape _html _attr ( content ) } > ` ;
}
}
class CspReportOnlyProvider extends BaseProvider {
/ * *
* @ param { boolean } use _hashes
* @ param { import ( 'types' ) . CspDirectives } directives
* @ param { string } nonce
* /
constructor ( use _hashes , directives , nonce ) {
super ( use _hashes , directives , nonce ) ;
if ( Object . values ( directives ) . filter ( ( v ) => ! ! v ) . length > 0 ) {
const has _report _to = directives [ "report-to" ] ? . length ? ? 0 > 0 ;
const has _report _uri = directives [ "report-uri" ] ? . length ? ? 0 > 0 ;
if ( ! has _report _to && ! has _report _uri ) {
throw Error (
"`content-security-policy-report-only` must be specified with either the `report-to` or `report-uri` directives, or both"
) ;
}
}
}
}
class Csp {
/** @readonly */
nonce = generate _nonce ( ) ;
/** @type {CspProvider} */
csp _provider ;
/** @type {CspReportOnlyProvider} */
report _only _provider ;
/ * *
* @ param { import ( './types.js' ) . CspConfig } config
* @ param { import ( './types.js' ) . CspOpts } opts
* /
constructor ( { mode , directives , reportOnly } , { prerender } ) {
const use _hashes = mode === "hash" || mode === "auto" && prerender ;
this . csp _provider = new CspProvider ( use _hashes , directives , this . nonce ) ;
this . report _only _provider = new CspReportOnlyProvider ( use _hashes , reportOnly , this . nonce ) ;
}
get script _needs _nonce ( ) {
return this . csp _provider . script _needs _nonce || this . report _only _provider . script _needs _nonce ;
}
get style _needs _nonce ( ) {
return this . csp _provider . style _needs _nonce || this . report _only _provider . style _needs _nonce ;
}
/** @param {string} content */
add _script ( content ) {
this . csp _provider . add _script ( content ) ;
this . report _only _provider . add _script ( content ) ;
}
/** @param {string} content */
add _style ( content ) {
this . csp _provider . add _style ( content ) ;
this . report _only _provider . add _style ( content ) ;
}
}
function defer ( ) {
let fulfil ;
let reject ;
const promise = new Promise ( ( f , r ) => {
fulfil = f ;
reject = r ;
} ) ;
return { promise , fulfil , reject } ;
}
function create _async _iterator ( ) {
const deferred = [ defer ( ) ] ;
return {
iterator : {
[ Symbol . asyncIterator ] ( ) {
return {
next : async ( ) => {
const next = await deferred [ 0 ] . promise ;
if ( ! next . done )
deferred . shift ( ) ;
return next ;
}
} ;
}
} ,
push : ( value ) => {
deferred [ deferred . length - 1 ] . fulfil ( {
value ,
done : false
} ) ;
deferred . push ( defer ( ) ) ;
} ,
done : ( ) => {
deferred [ deferred . length - 1 ] . fulfil ( { done : true } ) ;
}
} ;
}
const updated = {
... readable ( false ) ,
check : ( ) => false
} ;
const encoder$1 = new TextEncoder ( ) ;
async function render _response ( {
branch ,
fetched ,
options : options2 ,
manifest ,
state ,
page _config ,
status ,
error = null ,
event ,
resolve _opts ,
action _result
} ) {
if ( state . prerendering ) {
if ( options2 . csp . mode === "nonce" ) {
throw new Error ( 'Cannot use prerendering if config.kit.csp.mode === "nonce"' ) ;
}
if ( options2 . app _template _contains _nonce ) {
throw new Error ( "Cannot use prerendering if page template contains %sveltekit.nonce%" ) ;
}
}
const { client } = manifest . _ ;
const modulepreloads = new Set ( client . imports ) ;
const stylesheets = new Set ( client . stylesheets ) ;
const fonts = new Set ( client . fonts ) ;
const link _header _preloads = /* @__PURE__ */ new Set ( ) ;
const inline _styles = /* @__PURE__ */ new Map ( ) ;
let rendered ;
const form _value = action _result ? . type === "success" || action _result ? . type === "failure" ? action _result . data ? ? null : null ;
let base$1 = base ;
let assets$1 = assets ;
let base _expression = s ( base ) ;
if ( ! state . prerendering ? . fallback ) {
const segments = event . url . pathname . slice ( base . length ) . split ( "/" ) . slice ( 2 ) ;
base$1 = segments . map ( ( ) => ".." ) . join ( "/" ) || "." ;
base _expression = ` new URL( ${ s ( base$1 ) } , location).pathname.slice(0, -1) ` ;
if ( ! assets || assets [ 0 ] === "/" && assets !== SVELTE _KIT _ASSETS ) {
assets$1 = base$1 ;
}
}
if ( page _config . ssr ) {
const props = {
stores : {
page : writable ( null ) ,
navigating : writable ( null ) ,
updated
} ,
constructors : await Promise . all ( branch . map ( ( { node } ) => node . component ( ) ) ) ,
form : form _value
} ;
let data2 = { } ;
for ( let i = 0 ; i < branch . length ; i += 1 ) {
data2 = { ... data2 , ... branch [ i ] . data } ;
props [ ` data_ ${ i } ` ] = data2 ;
}
props . page = {
error ,
params : (
/** @type {Record<string, any>} */
event . params
) ,
route : event . route ,
status ,
url : event . url ,
data : data2 ,
form : form _value ,
state : { }
} ;
override ( { base : base$1 , assets : assets$1 } ) ;
{
try {
rendered = options2 . root . render ( props ) ;
} finally {
reset ( ) ;
}
}
for ( const { node } of branch ) {
for ( const url of node . imports )
modulepreloads . add ( url ) ;
for ( const url of node . stylesheets )
stylesheets . add ( url ) ;
for ( const url of node . fonts )
fonts . add ( url ) ;
if ( node . inline _styles ) {
Object . entries ( await node . inline _styles ( ) ) . forEach ( ( [ k , v ] ) => inline _styles . set ( k , v ) ) ;
}
}
} else {
rendered = { head : "" , html : "" , css : { code : "" , map : null } } ;
}
let head = "" ;
let body2 = rendered . html ;
const csp = new Csp ( options2 . csp , {
prerender : ! ! state . prerendering
} ) ;
const prefixed = ( path ) => {
if ( path . startsWith ( "/" ) ) {
return base + path ;
}
return ` ${ assets$1 } / ${ path } ` ;
} ;
if ( inline _styles . size > 0 ) {
const content = Array . from ( inline _styles . values ( ) ) . join ( "\n" ) ;
const attributes = [ ] ;
if ( csp . style _needs _nonce )
attributes . push ( ` nonce=" ${ csp . nonce } " ` ) ;
csp . add _style ( content ) ;
head += `
< style$ { attributes . join ( "" ) } > $ { content } < / s t y l e > ` ;
}
for ( const dep of stylesheets ) {
const path = prefixed ( dep ) ;
const attributes = [ 'rel="stylesheet"' ] ;
if ( inline _styles . has ( dep ) ) {
attributes . push ( "disabled" , 'media="(max-width: 0)"' ) ;
} else {
if ( resolve _opts . preload ( { type : "css" , path } ) ) {
const preload _atts = [ 'rel="preload"' , 'as="style"' ] ;
link _header _preloads . add ( ` < ${ encodeURI ( path ) } >; ${ preload _atts . join ( ";" ) } ; nopush ` ) ;
}
}
head += `
< link href = "${path}" $ { attributes . join ( " " ) } > ` ;
}
for ( const dep of fonts ) {
const path = prefixed ( dep ) ;
if ( resolve _opts . preload ( { type : "font" , path } ) ) {
const ext = dep . slice ( dep . lastIndexOf ( "." ) + 1 ) ;
const attributes = [
'rel="preload"' ,
'as="font"' ,
` type="font/ ${ ext } " ` ,
` href=" ${ path } " ` ,
"crossorigin"
] ;
head += `
< link $ { attributes . join ( " " ) } > ` ;
}
}
const global = ` __sveltekit_ ${ options2 . version _hash } ` ;
const { data , chunks } = get _data (
event ,
options2 ,
branch . map ( ( b ) => b . server _data ) ,
global
) ;
if ( page _config . ssr && page _config . csr ) {
body2 += `
$ { fetched . map (
( item ) => serialize _data ( item , resolve _opts . filterSerializedResponseHeaders , ! ! state . prerendering )
) . join ( "\n " ) } ` ;
}
if ( page _config . csr ) {
if ( client . uses _env _dynamic _public && state . prerendering ) {
modulepreloads . add ( ` ${ options2 . app _dir } /env.js ` ) ;
}
const included _modulepreloads = Array . from ( modulepreloads , ( dep ) => prefixed ( dep ) ) . filter (
( path ) => resolve _opts . preload ( { type : "js" , path } )
) ;
for ( const path of included _modulepreloads ) {
link _header _preloads . add ( ` < ${ encodeURI ( path ) } >; rel="modulepreload"; nopush ` ) ;
if ( options2 . preload _strategy !== "modulepreload" ) {
head += `
< link rel = "preload" as = "script" crossorigin = "anonymous" href = "${path}" > ` ;
} else if ( state . prerendering ) {
head += `
< link rel = "modulepreload" href = "${path}" > ` ;
}
}
const blocks = [ ] ;
const load _env _eagerly = client . uses _env _dynamic _public && state . prerendering ;
const properties = [ ` base: ${ base _expression } ` ] ;
if ( assets ) {
properties . push ( ` assets: ${ s ( assets ) } ` ) ;
}
if ( client . uses _env _dynamic _public ) {
properties . push ( ` env: ${ load _env _eagerly ? "null" : s ( public _env ) } ` ) ;
}
if ( chunks ) {
blocks . push ( "const deferred = new Map();" ) ;
properties . push ( ` defer: (id) => new Promise((fulfil, reject) => {
deferred . set ( id , { fulfil , reject } ) ;
} ) ` );
properties . push ( ` resolve: ({ id, data, error }) => {
const { fulfil , reject } = deferred . get ( id ) ;
deferred . delete ( id ) ;
if ( error ) reject ( error ) ;
else fulfil ( data ) ;
} ` );
}
blocks . push ( ` ${ global } = {
$ { properties . join ( ",\n " ) }
} ; ` );
const args = [ "app" , "element" ] ;
blocks . push ( "const element = document.currentScript.parentElement;" ) ;
if ( page _config . ssr ) {
const serialized = { form : "null" , error : "null" } ;
blocks . push ( ` const data = ${ data } ; ` ) ;
if ( form _value ) {
serialized . form = uneval _action _response (
form _value ,
/** @type {string} */
event . route . id
) ;
}
if ( error ) {
serialized . error = uneval ( error ) ;
}
const hydrate = [
` node_ids: [ ${ branch . map ( ( { node } ) => node.index).join(", ")}] ` ,
"data" ,
` form: ${ serialized . form } ` ,
` error: ${ serialized . error } `
] ;
if ( status !== 200 ) {
hydrate . push ( ` status: ${ status } ` ) ;
}
if ( options2 . embedded ) {
hydrate . push ( ` params: ${ uneval ( event . params ) } ` , ` route: ${ s ( event . route ) } ` ) ;
}
const indent = " " . repeat ( load _env _eagerly ? 7 : 6 ) ;
args . push ( ` {
$ { indent } $ { hydrate . join ( ` ,
$ { indent } ` )}
$ { indent } } ` );
}
if ( load _env _eagerly ) {
blocks . push ( ` import( ${ s ( ` ${ base$1 } / ${ options2 . app _dir } /env.js ` ) } ).then(({ env }) => {
$ { global } . env = env ;
Promise . all ( [
import ( $ { s ( prefixed ( client . start ) ) } ) ,
import ( $ { s ( prefixed ( client . app ) ) } )
] ) . then ( ( [ kit , app ] ) => {
kit . start ( $ { args . join ( ", " ) } ) ;
} ) ;
} ) ; ` );
} else {
blocks . push ( ` Promise.all([
import ( $ { s ( prefixed ( client . start ) ) } ) ,
import ( $ { s ( prefixed ( client . app ) ) } )
] ) . then ( ( [ kit , app ] ) => {
kit . start ( $ { args . join ( ", " ) } ) ;
} ) ; ` );
}
if ( options2 . service _worker ) {
const opts = "" ;
blocks . push ( ` if ('serviceWorker' in navigator) {
addEventListener ( 'load' , function ( ) {
navigator . serviceWorker . register ( '${prefixed("service-worker.js")}' $ { opts } ) ;
} ) ;
} ` );
}
const init _app = `
{
$ { blocks . join ( "\n\n " ) }
}
` ;
csp . add _script ( init _app ) ;
body2 += `
< script$ { csp . script _needs _nonce ? ` nonce=" ${ csp . nonce } " ` : "" } > $ { init _app } < \ / script >
` ;
}
const headers2 = new Headers ( {
"x-sveltekit-page" : "true" ,
"content-type" : "text/html"
} ) ;
if ( state . prerendering ) {
const http _equiv = [ ] ;
const csp _headers = csp . csp _provider . get _meta ( ) ;
if ( csp _headers ) {
http _equiv . push ( csp _headers ) ;
}
if ( state . prerendering . cache ) {
http _equiv . push ( ` <meta http-equiv="cache-control" content=" ${ state . prerendering . cache } "> ` ) ;
}
if ( http _equiv . length > 0 ) {
head = http _equiv . join ( "\n" ) + head ;
}
} else {
const csp _header = csp . csp _provider . get _header ( ) ;
if ( csp _header ) {
headers2 . set ( "content-security-policy" , csp _header ) ;
}
const report _only _header = csp . report _only _provider . get _header ( ) ;
if ( report _only _header ) {
headers2 . set ( "content-security-policy-report-only" , report _only _header ) ;
}
if ( link _header _preloads . size ) {
headers2 . set ( "link" , Array . from ( link _header _preloads ) . join ( ", " ) ) ;
}
}
head += rendered . head ;
const html = options2 . templates . app ( {
head ,
body : body2 ,
assets : assets$1 ,
nonce : (
/** @type {string} */
csp . nonce
) ,
env : safe _public _env
} ) ;
const transformed = await resolve _opts . transformPageChunk ( {
html ,
done : true
} ) || "" ;
if ( ! chunks ) {
headers2 . set ( "etag" , ` " ${ hash ( transformed ) } " ` ) ;
}
return ! chunks ? text ( transformed , {
status ,
headers : headers2
} ) : new Response (
new ReadableStream ( {
async start ( controller ) {
controller . enqueue ( encoder$1 . encode ( transformed + "\n" ) ) ;
for await ( const chunk of chunks ) {
controller . enqueue ( encoder$1 . encode ( chunk ) ) ;
}
controller . close ( ) ;
} ,
type : "bytes"
} ) ,
{
headers : {
"content-type" : "text/html"
}
}
) ;
}
function get _data ( event , options2 , nodes , global ) {
let promise _id = 1 ;
let count = 0 ;
const { iterator , push , done } = create _async _iterator ( ) ;
function replacer ( thing ) {
if ( typeof thing ? . then === "function" ) {
const id = promise _id ++ ;
count += 1 ;
thing . then (
/** @param {any} data */
( data ) => ( { data } )
) . catch (
/** @param {any} error */
async ( error ) => ( {
error : await handle _error _and _jsonify ( event , options2 , error )
} )
) . then (
/ * *
* @ param { { data : any ; error : any } } result
* /
async ( { data , error } ) => {
count -= 1 ;
let str ;
try {
str = uneval ( { id , data , error } , replacer ) ;
} catch ( e ) {
error = await handle _error _and _jsonify (
event ,
options2 ,
new Error ( ` Failed to serialize promise while rendering ${ event . route . id } ` )
) ;
data = void 0 ;
str = uneval ( { id , data , error } , replacer ) ;
}
push ( ` <script> ${ global } .resolve( ${ str } )< \/ script>
` );
if ( count === 0 )
done ( ) ;
}
) ;
return ` ${ global } .defer( ${ id } ) ` ;
}
}
try {
const strings = nodes . map ( ( node ) => {
if ( ! node )
return "null" ;
return ` {"type":"data","data": ${ uneval ( node . data , replacer ) } , ${ stringify _uses ( node ) } ${ node . slash ? ` ,"slash": ${ JSON . stringify ( node . slash ) } ` : "" } } ` ;
} ) ;
return {
data : ` [ ${ strings . join ( "," ) } ] ` ,
chunks : count > 0 ? iterator : null
} ;
} catch ( e ) {
throw new Error ( clarify _devalue _error (
event ,
/** @type {any} */
e
) ) ;
}
}
function get _option ( nodes , option ) {
return nodes . reduce (
( value , node ) => {
return (
/** @type {Value} TypeScript's too dumb to understand this */
node ? . universal ? . [ option ] ? ? node ? . server ? . [ option ] ? ? value
) ;
} ,
/** @type {Value | undefined} */
void 0
) ;
}
async function respond _with _error ( {
event ,
options : options2 ,
manifest ,
state ,
status ,
error ,
resolve _opts
} ) {
if ( event . request . headers . get ( "x-sveltekit-error" ) ) {
return static _error _page (
options2 ,
status ,
/** @type {Error} */
error . message
) ;
}
const fetched = [ ] ;
try {
const branch = [ ] ;
const default _layout = await manifest . _ . nodes [ 0 ] ( ) ;
const ssr = get _option ( [ default _layout ] , "ssr" ) ? ? true ;
const csr = get _option ( [ default _layout ] , "csr" ) ? ? true ;
if ( ssr ) {
state . error = true ;
const server _data _promise = load _server _data ( {
event ,
state ,
node : default _layout ,
parent : async ( ) => ( { } )
} ) ;
const server _data = await server _data _promise ;
const data = await load _data ( {
event ,
fetched ,
node : default _layout ,
parent : async ( ) => ( { } ) ,
resolve _opts ,
server _data _promise ,
state ,
csr
} ) ;
branch . push (
{
node : default _layout ,
server _data ,
data
} ,
{
node : await manifest . _ . nodes [ 1 ] ( ) ,
// 1 is always the root error
data : null ,
server _data : null
}
) ;
}
return await render _response ( {
options : options2 ,
manifest ,
state ,
page _config : {
ssr ,
csr
} ,
status ,
error : await handle _error _and _jsonify ( event , options2 , error ) ,
branch ,
fetched ,
event ,
resolve _opts
} ) ;
} catch ( e ) {
if ( e instanceof Redirect ) {
return redirect _response ( e . status , e . location ) ;
}
return static _error _page (
options2 ,
get _status ( e ) ,
( await handle _error _and _jsonify ( event , options2 , e ) ) . message
) ;
}
}
function once ( fn ) {
let done = false ;
let result ;
return ( ) => {
if ( done )
return result ;
done = true ;
return result = fn ( ) ;
} ;
}
const encoder = new TextEncoder ( ) ;
async function render _data ( event , route , options2 , manifest , state , invalidated _data _nodes , trailing _slash ) {
if ( ! route . page ) {
return new Response ( void 0 , {
status : 404
} ) ;
}
try {
const node _ids = [ ... route . page . layouts , route . page . leaf ] ;
const invalidated = invalidated _data _nodes ? ? node _ids . map ( ( ) => true ) ;
let aborted = false ;
const url = new URL ( event . url ) ;
url . pathname = normalize _path ( url . pathname , trailing _slash ) ;
const new _event = { ... event , url } ;
const functions = node _ids . map ( ( n , i ) => {
return once ( async ( ) => {
try {
if ( aborted ) {
return (
/** @type {import('types').ServerDataSkippedNode} */
{
type : "skip"
}
) ;
}
const node = n == void 0 ? n : await manifest . _ . nodes [ n ] ( ) ;
return load _server _data ( {
event : new _event ,
state ,
node ,
parent : async ( ) => {
const data2 = { } ;
for ( let j = 0 ; j < i ; j += 1 ) {
const parent = (
/** @type {import('types').ServerDataNode | null} */
await functions [ j ] ( )
) ;
if ( parent ) {
Object . assign ( data2 , parent . data ) ;
}
}
return data2 ;
}
} ) ;
} catch ( e ) {
aborted = true ;
throw e ;
}
} ) ;
} ) ;
const promises = functions . map ( async ( fn , i ) => {
if ( ! invalidated [ i ] ) {
return (
/** @type {import('types').ServerDataSkippedNode} */
{
type : "skip"
}
) ;
}
return fn ( ) ;
} ) ;
let length = promises . length ;
const nodes = await Promise . all (
promises . map (
( p , i ) => p . catch ( async ( error ) => {
if ( error instanceof Redirect ) {
throw error ;
}
length = Math . min ( length , i + 1 ) ;
return (
/** @type {import('types').ServerErrorNode} */
{
type : "error" ,
error : await handle _error _and _jsonify ( event , options2 , error ) ,
status : error instanceof HttpError || error instanceof SvelteKitError ? error . status : void 0
}
) ;
} )
)
) ;
const { data , chunks } = get _data _json ( event , options2 , nodes ) ;
if ( ! chunks ) {
return json _response ( data ) ;
}
return new Response (
new ReadableStream ( {
async start ( controller ) {
controller . enqueue ( encoder . encode ( data ) ) ;
for await ( const chunk of chunks ) {
controller . enqueue ( encoder . encode ( chunk ) ) ;
}
controller . close ( ) ;
} ,
type : "bytes"
} ) ,
{
headers : {
// we use a proprietary content type to prevent buffering.
// the `text` prefix makes it inspectable
"content-type" : "text/sveltekit-data" ,
"cache-control" : "private, no-store"
}
}
) ;
} catch ( e ) {
const error = normalize _error ( e ) ;
if ( error instanceof Redirect ) {
return redirect _json _response ( error ) ;
} else {
return json _response ( await handle _error _and _jsonify ( event , options2 , error ) , 500 ) ;
}
}
}
function json _response ( json2 , status = 200 ) {
return text ( typeof json2 === "string" ? json2 : JSON . stringify ( json2 ) , {
status ,
headers : {
"content-type" : "application/json" ,
"cache-control" : "private, no-store"
}
} ) ;
}
function redirect _json _response ( redirect ) {
return json _response ( {
type : "redirect" ,
location : redirect . location
} ) ;
}
function get _data _json ( event , options2 , nodes ) {
let promise _id = 1 ;
let count = 0 ;
const { iterator , push , done } = create _async _iterator ( ) ;
const reducers = {
/** @param {any} thing */
Promise : ( thing ) => {
if ( typeof thing ? . then === "function" ) {
const id = promise _id ++ ;
count += 1 ;
let key2 = "data" ;
thing . catch (
/** @param {any} e */
async ( e ) => {
key2 = "error" ;
return handle _error _and _jsonify (
event ,
options2 ,
/** @type {any} */
e
) ;
}
) . then (
/** @param {any} value */
async ( value ) => {
let str ;
try {
str = stringify ( value , reducers ) ;
} catch ( e ) {
const error = await handle _error _and _jsonify (
event ,
options2 ,
new Error ( ` Failed to serialize promise while rendering ${ event . route . id } ` )
) ;
key2 = "error" ;
str = stringify ( error , reducers ) ;
}
count -= 1 ;
push ( ` {"type":"chunk","id": ${ id } ," ${ key2 } ": ${ str } }
` );
if ( count === 0 )
done ( ) ;
}
) ;
return id ;
}
}
} ;
try {
const strings = nodes . map ( ( node ) => {
if ( ! node )
return "null" ;
if ( node . type === "error" || node . type === "skip" ) {
return JSON . stringify ( node ) ;
}
return ` {"type":"data","data": ${ stringify ( node . data , reducers ) } , ${ stringify _uses (
node
) } $ { node . slash ? ` ,"slash": ${ JSON . stringify ( node . slash ) } ` : "" } } ` ;
} ) ;
return {
data : ` {"type":"data","nodes":[ ${ strings . join ( "," ) } ]}
` ,
chunks : count > 0 ? iterator : null
} ;
} catch ( e ) {
throw new Error ( clarify _devalue _error (
event ,
/** @type {any} */
e
) ) ;
}
}
function load _page _nodes ( page , manifest ) {
return Promise . all ( [
// we use == here rather than === because [undefined] serializes as "[null]"
... page . layouts . map ( ( n ) => n == void 0 ? n : manifest . _ . nodes [ n ] ( ) ) ,
manifest . _ . nodes [ page . leaf ] ( )
] ) ;
}
const MAX _DEPTH = 10 ;
async function render _page ( event , page , options2 , manifest , state , resolve _opts ) {
if ( state . depth > MAX _DEPTH ) {
return text ( ` Not found: ${ event . url . pathname } ` , {
status : 404
// TODO in some cases this should be 500. not sure how to differentiate
} ) ;
}
if ( is _action _json _request ( event ) ) {
const node = await manifest . _ . nodes [ page . leaf ] ( ) ;
return handle _action _json _request ( event , options2 , node ? . server ) ;
}
try {
const nodes = await load _page _nodes ( page , manifest ) ;
const leaf _node = (
/** @type {import('types').SSRNode} */
nodes . at ( - 1 )
) ;
let status = 200 ;
let action _result = void 0 ;
if ( is _action _request ( event ) ) {
action _result = await handle _action _request ( event , leaf _node . server ) ;
if ( action _result ? . type === "redirect" ) {
return redirect _response ( action _result . status , action _result . location ) ;
}
if ( action _result ? . type === "error" ) {
status = get _status ( action _result . error ) ;
}
if ( action _result ? . type === "failure" ) {
status = action _result . status ;
}
}
const should _prerender _data = nodes . some ( ( node ) => node ? . server ? . load ) ;
const data _pathname = add _data _suffix ( event . url . pathname ) ;
const should _prerender = get _option ( nodes , "prerender" ) ? ? false ;
if ( should _prerender ) {
const mod = leaf _node . server ;
if ( mod ? . actions ) {
throw new Error ( "Cannot prerender pages with actions" ) ;
}
} else if ( state . prerendering ) {
return new Response ( void 0 , {
status : 204
} ) ;
}
state . prerender _default = should _prerender ;
const fetched = [ ] ;
if ( get _option ( nodes , "ssr" ) === false && ! ( state . prerendering && should _prerender _data ) ) {
return await render _response ( {
branch : [ ] ,
fetched ,
page _config : {
ssr : false ,
csr : get _option ( nodes , "csr" ) ? ? true
} ,
status ,
error : null ,
event ,
options : options2 ,
manifest ,
state ,
resolve _opts
} ) ;
}
const branch = [ ] ;
let load _error = null ;
const server _promises = nodes . map ( ( node , i ) => {
if ( load _error ) {
throw load _error ;
}
return Promise . resolve ( ) . then ( async ( ) => {
try {
if ( node === leaf _node && action _result ? . type === "error" ) {
throw action _result . error ;
}
return await load _server _data ( {
event ,
state ,
node ,
parent : async ( ) => {
const data = { } ;
for ( let j = 0 ; j < i ; j += 1 ) {
const parent = await server _promises [ j ] ;
if ( parent )
Object . assign ( data , await parent . data ) ;
}
return data ;
}
} ) ;
} catch ( e ) {
load _error = /** @type {Error} */
e ;
throw load _error ;
}
} ) ;
} ) ;
const csr = get _option ( nodes , "csr" ) ? ? true ;
const load _promises = nodes . map ( ( node , i ) => {
if ( load _error )
throw load _error ;
return Promise . resolve ( ) . then ( async ( ) => {
try {
return await load _data ( {
event ,
fetched ,
node ,
parent : async ( ) => {
const data = { } ;
for ( let j = 0 ; j < i ; j += 1 ) {
Object . assign ( data , await load _promises [ j ] ) ;
}
return data ;
} ,
resolve _opts ,
server _data _promise : server _promises [ i ] ,
state ,
csr
} ) ;
} catch ( e ) {
load _error = /** @type {Error} */
e ;
throw load _error ;
}
} ) ;
} ) ;
for ( const p of server _promises )
p . catch ( ( ) => {
} ) ;
for ( const p of load _promises )
p . catch ( ( ) => {
} ) ;
for ( let i = 0 ; i < nodes . length ; i += 1 ) {
const node = nodes [ i ] ;
if ( node ) {
try {
const server _data = await server _promises [ i ] ;
const data = await load _promises [ i ] ;
branch . push ( { node , server _data , data } ) ;
} catch ( e ) {
const err = normalize _error ( e ) ;
if ( err instanceof Redirect ) {
if ( state . prerendering && should _prerender _data ) {
const body2 = JSON . stringify ( {
type : "redirect" ,
location : err . location
} ) ;
state . prerendering . dependencies . set ( data _pathname , {
response : text ( body2 ) ,
body : body2
} ) ;
}
return redirect _response ( err . status , err . location ) ;
}
const status2 = get _status ( err ) ;
const error = await handle _error _and _jsonify ( event , options2 , err ) ;
while ( i -- ) {
if ( page . errors [ i ] ) {
const index = (
/** @type {number} */
page . errors [ i ]
) ;
const node2 = await manifest . _ . nodes [ index ] ( ) ;
let j = i ;
while ( ! branch [ j ] )
j -= 1 ;
return await render _response ( {
event ,
options : options2 ,
manifest ,
state ,
resolve _opts ,
page _config : { ssr : true , csr : true } ,
status : status2 ,
error ,
branch : compact ( branch . slice ( 0 , j + 1 ) ) . concat ( {
node : node2 ,
data : null ,
server _data : null
} ) ,
fetched
} ) ;
}
}
return static _error _page ( options2 , status2 , error . message ) ;
}
} else {
branch . push ( null ) ;
}
}
if ( state . prerendering && should _prerender _data ) {
let { data , chunks } = get _data _json (
event ,
options2 ,
branch . map ( ( node ) => node ? . server _data )
) ;
if ( chunks ) {
for await ( const chunk of chunks ) {
data += chunk ;
}
}
state . prerendering . dependencies . set ( data _pathname , {
response : text ( data ) ,
body : data
} ) ;
}
const ssr = get _option ( nodes , "ssr" ) ? ? true ;
return await render _response ( {
event ,
options : options2 ,
manifest ,
state ,
resolve _opts ,
page _config : {
csr : get _option ( nodes , "csr" ) ? ? true ,
ssr
} ,
status ,
error : null ,
branch : ssr === false ? [ ] : compact ( branch ) ,
action _result ,
fetched
} ) ;
} catch ( e ) {
return await respond _with _error ( {
event ,
options : options2 ,
manifest ,
state ,
status : 500 ,
error : e ,
resolve _opts
} ) ;
}
}
function exec ( match , params , matchers ) {
const result = { } ;
const values = match . slice ( 1 ) ;
const values _needing _match = values . filter ( ( value ) => value !== void 0 ) ;
let buffered = 0 ;
for ( let i = 0 ; i < params . length ; i += 1 ) {
const param = params [ i ] ;
let value = values [ i - buffered ] ;
if ( param . chained && param . rest && buffered ) {
value = values . slice ( i - buffered , i + 1 ) . filter ( ( s2 ) => s2 ) . join ( "/" ) ;
buffered = 0 ;
}
if ( value === void 0 ) {
if ( param . rest )
result [ param . name ] = "" ;
continue ;
}
if ( ! param . matcher || matchers [ param . matcher ] ( value ) ) {
result [ param . name ] = value ;
const next _param = params [ i + 1 ] ;
const next _value = values [ i + 1 ] ;
if ( next _param && ! next _param . rest && next _param . optional && next _value && param . chained ) {
buffered = 0 ;
}
if ( ! next _param && ! next _value && Object . keys ( result ) . length === values _needing _match . length ) {
buffered = 0 ;
}
continue ;
}
if ( param . optional && param . chained ) {
buffered ++ ;
continue ;
}
return ;
}
if ( buffered )
return ;
return result ;
}
function validate _options ( options2 ) {
if ( options2 ? . path === void 0 ) {
throw new Error ( "You must specify a `path` when setting, deleting or serializing cookies" ) ;
}
}
function get _cookies ( request , url , trailing _slash ) {
const header = request . headers . get ( "cookie" ) ? ? "" ;
const initial _cookies = cookieExports . parse ( header , { decode : ( value ) => value } ) ;
const normalized _url = normalize _path ( url . pathname , trailing _slash ) ;
const new _cookies = { } ;
const defaults = {
httpOnly : true ,
sameSite : "lax" ,
secure : url . hostname === "localhost" && url . protocol === "http:" ? false : true
} ;
const cookies = {
// The JSDoc param annotations appearing below for get, set and delete
// are necessary to expose the `cookie` library types to
// typescript users. `@type {import('@sveltejs/kit').Cookies}` above is not
// sufficient to do so.
/ * *
* @ param { string } name
* @ param { import ( 'cookie' ) . CookieParseOptions } opts
* /
get ( name , opts ) {
const c = new _cookies [ name ] ;
if ( c && domain _matches ( url . hostname , c . options . domain ) && path _matches ( url . pathname , c . options . path ) ) {
return c . value ;
}
const decoder = opts ? . decode || decodeURIComponent ;
const req _cookies = cookieExports . parse ( header , { decode : decoder } ) ;
const cookie = req _cookies [ name ] ;
return cookie ;
} ,
/ * *
* @ param { import ( 'cookie' ) . CookieParseOptions } opts
* /
getAll ( opts ) {
const decoder = opts ? . decode || decodeURIComponent ;
const cookies2 = cookieExports . parse ( header , { decode : decoder } ) ;
for ( const c of Object . values ( new _cookies ) ) {
if ( domain _matches ( url . hostname , c . options . domain ) && path _matches ( url . pathname , c . options . path ) ) {
cookies2 [ c . name ] = c . value ;
}
}
return Object . entries ( cookies2 ) . map ( ( [ name , value ] ) => ( { name , value } ) ) ;
} ,
/ * *
* @ param { string } name
* @ param { string } value
* @ param { import ( './page/types.js' ) . Cookie [ 'options' ] } options
* /
set ( name , value , options2 ) {
validate _options ( options2 ) ;
set _internal ( name , value , { ... defaults , ... options2 } ) ;
} ,
/ * *
* @ param { string } name
* @ param { import ( './page/types.js' ) . Cookie [ 'options' ] } options
* /
delete ( name , options2 ) {
validate _options ( options2 ) ;
cookies . set ( name , "" , { ... options2 , maxAge : 0 } ) ;
} ,
/ * *
* @ param { string } name
* @ param { string } value
* @ param { import ( './page/types.js' ) . Cookie [ 'options' ] } options
* /
serialize ( name , value , options2 ) {
validate _options ( options2 ) ;
let path = options2 . path ;
if ( ! options2 . domain || options2 . domain === url . hostname ) {
path = resolve ( normalized _url , path ) ;
}
return cookieExports . serialize ( name , value , { ... defaults , ... options2 , path } ) ;
}
} ;
function get _cookie _header ( destination , header2 ) {
const combined _cookies = {
// cookies sent by the user agent have lowest precedence
... initial _cookies
} ;
for ( const key2 in new _cookies ) {
const cookie = new _cookies [ key2 ] ;
if ( ! domain _matches ( destination . hostname , cookie . options . domain ) )
continue ;
if ( ! path _matches ( destination . pathname , cookie . options . path ) )
continue ;
const encoder2 = cookie . options . encode || encodeURIComponent ;
combined _cookies [ cookie . name ] = encoder2 ( cookie . value ) ;
}
if ( header2 ) {
const parsed = cookieExports . parse ( header2 , { decode : ( value ) => value } ) ;
for ( const name in parsed ) {
combined _cookies [ name ] = parsed [ name ] ;
}
}
return Object . entries ( combined _cookies ) . map ( ( [ name , value ] ) => ` ${ name } = ${ value } ` ) . join ( "; " ) ;
}
function set _internal ( name , value , options2 ) {
let path = options2 . path ;
if ( ! options2 . domain || options2 . domain === url . hostname ) {
path = resolve ( normalized _url , path ) ;
}
new _cookies [ name ] = { name , value , options : { ... options2 , path } } ;
}
return { cookies , new _cookies , get _cookie _header , set _internal } ;
}
function domain _matches ( hostname , constraint ) {
if ( ! constraint )
return true ;
const normalized = constraint [ 0 ] === "." ? constraint . slice ( 1 ) : constraint ;
if ( hostname === normalized )
return true ;
return hostname . endsWith ( "." + normalized ) ;
}
function path _matches ( path , constraint ) {
if ( ! constraint )
return true ;
const normalized = constraint . endsWith ( "/" ) ? constraint . slice ( 0 , - 1 ) : constraint ;
if ( path === normalized )
return true ;
return path . startsWith ( normalized + "/" ) ;
}
function add _cookies _to _headers ( headers2 , cookies ) {
for ( const new _cookie of cookies ) {
const { name , value , options : options2 } = new _cookie ;
headers2 . append ( "set-cookie" , cookieExports . serialize ( name , value , options2 ) ) ;
if ( options2 . path . endsWith ( ".html" ) ) {
const path = add _data _suffix ( options2 . path ) ;
headers2 . append ( "set-cookie" , cookieExports . serialize ( name , value , { ... options2 , path } ) ) ;
}
}
}
function create _fetch ( { event , options : options2 , manifest , state , get _cookie _header , set _internal } ) {
const server _fetch = async ( info , init2 ) => {
const original _request = normalize _fetch _input ( info , init2 , event . url ) ;
let mode = ( info instanceof Request ? info . mode : init2 ? . mode ) ? ? "cors" ;
let credentials = ( info instanceof Request ? info . credentials : init2 ? . credentials ) ? ? "same-origin" ;
return options2 . hooks . handleFetch ( {
event ,
request : original _request ,
fetch : async ( info2 , init3 ) => {
const request = normalize _fetch _input ( info2 , init3 , event . url ) ;
const url = new URL ( request . url ) ;
if ( ! request . headers . has ( "origin" ) ) {
request . headers . set ( "origin" , event . url . origin ) ;
}
if ( info2 !== original _request ) {
mode = ( info2 instanceof Request ? info2 . mode : init3 ? . mode ) ? ? "cors" ;
credentials = ( info2 instanceof Request ? info2 . credentials : init3 ? . credentials ) ? ? "same-origin" ;
}
if ( ( request . method === "GET" || request . method === "HEAD" ) && ( mode === "no-cors" && url . origin !== event . url . origin || url . origin === event . url . origin ) ) {
request . headers . delete ( "origin" ) ;
}
if ( url . origin !== event . url . origin ) {
if ( ` . ${ url . hostname } ` . endsWith ( ` . ${ event . url . hostname } ` ) && credentials !== "omit" ) {
const cookie = get _cookie _header ( url , request . headers . get ( "cookie" ) ) ;
if ( cookie )
request . headers . set ( "cookie" , cookie ) ;
}
return fetch ( request ) ;
}
const prefix = assets || base ;
const decoded = decodeURIComponent ( url . pathname ) ;
const filename = ( decoded . startsWith ( prefix ) ? decoded . slice ( prefix . length ) : decoded ) . slice ( 1 ) ;
const filename _html = ` ${ filename } /index.html ` ;
const is _asset = manifest . assets . has ( filename ) ;
const is _asset _html = manifest . assets . has ( filename _html ) ;
if ( is _asset || is _asset _html ) {
const file = is _asset ? filename : filename _html ;
if ( state . read ) {
const type = is _asset ? manifest . mimeTypes [ filename . slice ( filename . lastIndexOf ( "." ) ) ] : "text/html" ;
return new Response ( state . read ( file ) , {
headers : type ? { "content-type" : type } : { }
} ) ;
}
return await fetch ( request ) ;
}
if ( credentials !== "omit" ) {
const cookie = get _cookie _header ( url , request . headers . get ( "cookie" ) ) ;
if ( cookie ) {
request . headers . set ( "cookie" , cookie ) ;
}
const authorization = event . request . headers . get ( "authorization" ) ;
if ( authorization && ! request . headers . has ( "authorization" ) ) {
request . headers . set ( "authorization" , authorization ) ;
}
}
if ( ! request . headers . has ( "accept" ) ) {
request . headers . set ( "accept" , "*/*" ) ;
}
if ( ! request . headers . has ( "accept-language" ) ) {
request . headers . set (
"accept-language" ,
/** @type {string} */
event . request . headers . get ( "accept-language" )
) ;
}
const response = await respond ( request , options2 , manifest , {
... state ,
depth : state . depth + 1
} ) ;
const set _cookie = response . headers . get ( "set-cookie" ) ;
if ( set _cookie ) {
for ( const str of setCookieExports . splitCookiesString ( set _cookie ) ) {
const { name , value , ... options3 } = setCookieExports . parseString ( str , {
decodeValues : false
} ) ;
const path = options3 . path ? ? ( url . pathname . split ( "/" ) . slice ( 0 , - 1 ) . join ( "/" ) || "/" ) ;
set _internal ( name , value , {
path ,
encode : ( value2 ) => value2 ,
... /** @type {import('cookie').CookieSerializeOptions} */
options3
} ) ;
}
}
return response ;
}
} ) ;
} ;
return ( input , init2 ) => {
const response = server _fetch ( input , init2 ) ;
response . catch ( ( ) => {
} ) ;
return response ;
} ;
}
function normalize _fetch _input ( info , init2 , url ) {
if ( info instanceof Request ) {
return info ;
}
return new Request ( typeof info === "string" ? new URL ( info , url ) : info , init2 ) ;
}
let body ;
let etag ;
let headers ;
function get _public _env ( request ) {
body ? ? = ` export const env= ${ JSON . stringify ( public _env ) } ` ;
etag ? ? = ` W/ ${ Date . now ( ) } ` ;
headers ? ? = new Headers ( {
"content-type" : "application/javascript; charset=utf-8" ,
etag
} ) ;
if ( request . headers . get ( "if-none-match" ) === etag ) {
return new Response ( void 0 , { status : 304 , headers } ) ;
}
return new Response ( body , { headers } ) ;
}
function get _page _config ( nodes ) {
let current = { } ;
for ( const node of nodes ) {
if ( ! node ? . universal ? . config && ! node ? . server ? . config )
continue ;
current = {
... current ,
... node ? . universal ? . config ,
... node ? . server ? . config
} ;
}
return Object . keys ( current ) . length ? current : void 0 ;
}
const default _transform = ( { html } ) => html ;
const default _filter = ( ) => false ;
const default _preload = ( { type } ) => type === "js" || type === "css" ;
const page _methods = /* @__PURE__ */ new Set ( [ "GET" , "HEAD" , "POST" ] ) ;
const allowed _page _methods = /* @__PURE__ */ new Set ( [ "GET" , "HEAD" , "OPTIONS" ] ) ;
async function respond ( request , options2 , manifest , state ) {
const url = new URL ( request . url ) ;
if ( options2 . csrf _check _origin ) {
const forbidden = is _form _content _type ( request ) && ( request . method === "POST" || request . method === "PUT" || request . method === "PATCH" || request . method === "DELETE" ) && request . headers . get ( "origin" ) !== url . origin ;
if ( forbidden ) {
const csrf _error = new HttpError (
403 ,
` Cross-site ${ request . method } form submissions are forbidden `
) ;
if ( request . headers . get ( "accept" ) === "application/json" ) {
return json ( csrf _error . body , { status : csrf _error . status } ) ;
}
return text ( csrf _error . body . message , { status : csrf _error . status } ) ;
}
}
let rerouted _path ;
try {
rerouted _path = options2 . hooks . reroute ( { url : new URL ( url ) } ) ? ? url . pathname ;
} catch ( e ) {
return text ( "Internal Server Error" , {
status : 500
} ) ;
}
let decoded ;
try {
decoded = decode _pathname ( rerouted _path ) ;
} catch {
return text ( "Malformed URI" , { status : 400 } ) ;
}
let route = null ;
let params = { } ;
if ( base && ! state . prerendering ? . fallback ) {
if ( ! decoded . startsWith ( base ) ) {
return text ( "Not found" , { status : 404 } ) ;
}
decoded = decoded . slice ( base . length ) || "/" ;
}
if ( decoded === ` / ${ options2 . app _dir } /env.js ` ) {
return get _public _env ( request ) ;
}
if ( decoded . startsWith ( ` / ${ options2 . app _dir } ` ) ) {
return text ( "Not found" , { status : 404 } ) ;
}
const is _data _request = has _data _suffix ( decoded ) ;
let invalidated _data _nodes ;
if ( is _data _request ) {
decoded = strip _data _suffix ( decoded ) || "/" ;
url . pathname = strip _data _suffix ( url . pathname ) + ( url . searchParams . get ( TRAILING _SLASH _PARAM ) === "1" ? "/" : "" ) || "/" ;
url . searchParams . delete ( TRAILING _SLASH _PARAM ) ;
invalidated _data _nodes = url . searchParams . get ( INVALIDATED _PARAM ) ? . split ( "" ) . map ( ( node ) => node === "1" ) ;
url . searchParams . delete ( INVALIDATED _PARAM ) ;
}
if ( ! state . prerendering ? . fallback ) {
const matchers = await manifest . _ . matchers ( ) ;
for ( const candidate of manifest . _ . routes ) {
const match = candidate . pattern . exec ( decoded ) ;
if ( ! match )
continue ;
const matched = exec ( match , candidate . params , matchers ) ;
if ( matched ) {
route = candidate ;
params = decode _params ( matched ) ;
break ;
}
}
}
let trailing _slash = void 0 ;
const headers2 = { } ;
let cookies _to _add = { } ;
const event = {
// @ts-expect-error `cookies` and `fetch` need to be created after the `event` itself
cookies : null ,
// @ts-expect-error
fetch : null ,
getClientAddress : state . getClientAddress || ( ( ) => {
throw new Error (
` ${ "@sveltejs/adapter-node" } does not specify getClientAddress. Please raise an issue `
) ;
} ) ,
locals : { } ,
params ,
platform : state . platform ,
request ,
route : { id : route ? . id ? ? null } ,
setHeaders : ( new _headers ) => {
for ( const key2 in new _headers ) {
const lower = key2 . toLowerCase ( ) ;
const value = new _headers [ key2 ] ;
if ( lower === "set-cookie" ) {
throw new Error (
"Use `event.cookies.set(name, value, options)` instead of `event.setHeaders` to set cookies"
) ;
} else if ( lower in headers2 ) {
throw new Error ( ` " ${ key2 } " header is already set ` ) ;
} else {
headers2 [ lower ] = value ;
if ( state . prerendering && lower === "cache-control" ) {
state . prerendering . cache = /** @type {string} */
value ;
}
}
}
} ,
url ,
isDataRequest : is _data _request ,
isSubRequest : state . depth > 0
} ;
let resolve _opts = {
transformPageChunk : default _transform ,
filterSerializedResponseHeaders : default _filter ,
preload : default _preload
} ;
try {
if ( route ) {
if ( url . pathname === base || url . pathname === base + "/" ) {
trailing _slash = "always" ;
} else if ( route . page ) {
const nodes = await load _page _nodes ( route . page , manifest ) ;
if ( DEV )
;
trailing _slash = get _option ( nodes , "trailingSlash" ) ;
} else if ( route . endpoint ) {
const node = await route . endpoint ( ) ;
trailing _slash = node . trailingSlash ;
if ( DEV )
;
}
if ( ! is _data _request ) {
const normalized = normalize _path ( url . pathname , trailing _slash ? ? "never" ) ;
if ( normalized !== url . pathname && ! state . prerendering ? . fallback ) {
return new Response ( void 0 , {
status : 308 ,
headers : {
"x-sveltekit-normalize" : "1" ,
location : (
// ensure paths starting with '//' are not treated as protocol-relative
( normalized . startsWith ( "//" ) ? url . origin + normalized : normalized ) + ( url . search === "?" ? "" : url . search )
)
}
} ) ;
}
}
if ( state . before _handle || state . emulator ? . platform ) {
let config = { } ;
let prerender = false ;
if ( route . endpoint ) {
const node = await route . endpoint ( ) ;
config = node . config ? ? config ;
prerender = node . prerender ? ? prerender ;
} else if ( route . page ) {
const nodes = await load _page _nodes ( route . page , manifest ) ;
config = get _page _config ( nodes ) ? ? config ;
prerender = get _option ( nodes , "prerender" ) ? ? false ;
}
if ( state . before _handle ) {
state . before _handle ( event , config , prerender ) ;
}
if ( state . emulator ? . platform ) {
event . platform = await state . emulator . platform ( { config , prerender } ) ;
}
}
}
const { cookies , new _cookies , get _cookie _header , set _internal } = get _cookies (
request ,
url ,
trailing _slash ? ? "never"
) ;
cookies _to _add = new _cookies ;
event . cookies = cookies ;
event . fetch = create _fetch ( {
event ,
options : options2 ,
manifest ,
state ,
get _cookie _header ,
set _internal
} ) ;
if ( state . prerendering && ! state . prerendering . fallback )
disable _search ( url ) ;
const response = await options2 . hooks . handle ( {
event ,
resolve : ( event2 , opts ) => resolve2 ( event2 , opts ) . then ( ( response2 ) => {
for ( const key2 in headers2 ) {
const value = headers2 [ key2 ] ;
response2 . headers . set (
key2 ,
/** @type {string} */
value
) ;
}
add _cookies _to _headers ( response2 . headers , Object . values ( cookies _to _add ) ) ;
if ( state . prerendering && event2 . route . id !== null ) {
response2 . headers . set ( "x-sveltekit-routeid" , encodeURI ( event2 . route . id ) ) ;
}
return response2 ;
} )
} ) ;
if ( response . status === 200 && response . headers . has ( "etag" ) ) {
let if _none _match _value = request . headers . get ( "if-none-match" ) ;
if ( if _none _match _value ? . startsWith ( 'W/"' ) ) {
if _none _match _value = if _none _match _value . substring ( 2 ) ;
}
const etag2 = (
/** @type {string} */
response . headers . get ( "etag" )
) ;
if ( if _none _match _value === etag2 ) {
const headers22 = new Headers ( { etag : etag2 } ) ;
for ( const key2 of [
"cache-control" ,
"content-location" ,
"date" ,
"expires" ,
"vary" ,
"set-cookie"
] ) {
const value = response . headers . get ( key2 ) ;
if ( value )
headers22 . set ( key2 , value ) ;
}
return new Response ( void 0 , {
status : 304 ,
headers : headers22
} ) ;
}
}
if ( is _data _request && response . status >= 300 && response . status <= 308 ) {
const location = response . headers . get ( "location" ) ;
if ( location ) {
return redirect _json _response ( new Redirect (
/** @type {any} */
response . status ,
location
) ) ;
}
}
return response ;
} catch ( e ) {
if ( e instanceof Redirect ) {
const response = is _data _request ? redirect _json _response ( e ) : route ? . page && is _action _json _request ( event ) ? action _json _redirect ( e ) : redirect _response ( e . status , e . location ) ;
add _cookies _to _headers ( response . headers , Object . values ( cookies _to _add ) ) ;
return response ;
}
return await handle _fatal _error ( event , options2 , e ) ;
}
async function resolve2 ( event2 , opts ) {
try {
if ( opts ) {
resolve _opts = {
transformPageChunk : opts . transformPageChunk || default _transform ,
filterSerializedResponseHeaders : opts . filterSerializedResponseHeaders || default _filter ,
preload : opts . preload || default _preload
} ;
}
if ( state . prerendering ? . fallback ) {
return await render _response ( {
event : event2 ,
options : options2 ,
manifest ,
state ,
page _config : { ssr : false , csr : true } ,
status : 200 ,
error : null ,
branch : [ ] ,
fetched : [ ] ,
resolve _opts
} ) ;
}
if ( route ) {
const method = (
/** @type {import('types').HttpMethod} */
event2 . request . method
) ;
let response ;
if ( is _data _request ) {
response = await render _data (
event2 ,
route ,
options2 ,
manifest ,
state ,
invalidated _data _nodes ,
trailing _slash ? ? "never"
) ;
} else if ( route . endpoint && ( ! route . page || is _endpoint _request ( event2 ) ) ) {
response = await render _endpoint ( event2 , await route . endpoint ( ) , state ) ;
} else if ( route . page ) {
if ( page _methods . has ( method ) ) {
response = await render _page ( event2 , route . page , options2 , manifest , state , resolve _opts ) ;
} else {
const allowed _methods2 = new Set ( allowed _page _methods ) ;
const node = await manifest . _ . nodes [ route . page . leaf ] ( ) ;
if ( node ? . server ? . actions ) {
allowed _methods2 . add ( "POST" ) ;
}
if ( method === "OPTIONS" ) {
response = new Response ( null , {
status : 204 ,
headers : {
allow : Array . from ( allowed _methods2 . values ( ) ) . join ( ", " )
}
} ) ;
} else {
const mod = [ ... allowed _methods2 ] . reduce (
( acc , curr ) => {
acc [ curr ] = true ;
return acc ;
} ,
/** @type {Record<string, any>} */
{ }
) ;
response = method _not _allowed ( mod , method ) ;
}
}
} else {
throw new Error ( "This should never happen" ) ;
}
if ( request . method === "GET" && route . page && route . endpoint ) {
const vary = response . headers . get ( "vary" ) ? . split ( "," ) ? . map ( ( v ) => v . trim ( ) . toLowerCase ( ) ) ;
if ( ! ( vary ? . includes ( "accept" ) || vary ? . includes ( "*" ) ) ) {
response = new Response ( response . body , {
status : response . status ,
statusText : response . statusText ,
headers : new Headers ( response . headers )
} ) ;
response . headers . append ( "Vary" , "Accept" ) ;
}
}
return response ;
}
if ( state . error && event2 . isSubRequest ) {
return await fetch ( request , {
headers : {
"x-sveltekit-error" : "true"
}
} ) ;
}
if ( state . error ) {
return text ( "Internal Server Error" , {
status : 500
} ) ;
}
if ( state . depth === 0 ) {
return await respond _with _error ( {
event : event2 ,
options : options2 ,
manifest ,
state ,
status : 404 ,
error : new SvelteKitError ( 404 , "Not Found" , ` Not found: ${ event2 . url . pathname } ` ) ,
resolve _opts
} ) ;
}
if ( state . prerendering ) {
return text ( "not found" , { status : 404 } ) ;
}
return await fetch ( request ) ;
} catch ( e ) {
return await handle _fatal _error ( event2 , options2 , e ) ;
} finally {
event2 . cookies . set = ( ) => {
throw new Error ( "Cannot use `cookies.set(...)` after the response has been generated" ) ;
} ;
event2 . setHeaders = ( ) => {
throw new Error ( "Cannot use `setHeaders(...)` after the response has been generated" ) ;
} ;
}
}
}
function filter _private _env ( env , { public _prefix , private _prefix } ) {
return Object . fromEntries (
Object . entries ( env ) . filter (
( [ k ] ) => k . startsWith ( private _prefix ) && ( public _prefix === "" || ! k . startsWith ( public _prefix ) )
)
) ;
}
function filter _public _env ( env , { public _prefix , private _prefix } ) {
return Object . fromEntries (
Object . entries ( env ) . filter (
( [ k ] ) => k . startsWith ( public _prefix ) && ( private _prefix === "" || ! k . startsWith ( private _prefix ) )
)
) ;
}
class Server {
/** @type {import('types').SSROptions} */
# options ;
/** @type {import('@sveltejs/kit').SSRManifest} */
# manifest ;
/** @param {import('@sveltejs/kit').SSRManifest} manifest */
constructor ( manifest ) {
this . # options = options ;
this . # manifest = manifest ;
}
/ * *
* @ param { {
* env : Record < string , string > ;
* read ? : ( file : string ) => ReadableStream ;
* } } opts
* /
async init ( { env , read } ) {
const prefixes = {
public _prefix : this . # options . env _public _prefix ,
private _prefix : this . # options . env _private _prefix
} ;
filter _private _env ( env , prefixes ) ;
const public _env2 = filter _public _env ( env , prefixes ) ;
set _public _env (
public _env2
) ;
set _safe _public _env ( public _env2 ) ;
if ( ! this . # options . hooks ) {
try {
const module = await get _hooks ( ) ;
this . # options . hooks = {
handle : module . handle || ( ( { event , resolve : resolve2 } ) => resolve2 ( event ) ) ,
handleError : module . handleError || ( ( { error } ) => console . error ( error ) ) ,
handleFetch : module . handleFetch || ( ( { request , fetch : fetch2 } ) => fetch2 ( request ) ) ,
reroute : module . reroute || ( ( ) => {
} )
} ;
} catch ( error ) {
{
throw error ;
}
}
}
}
/ * *
* @ param { Request } request
* @ param { import ( 'types' ) . RequestOptions } options
* /
async respond ( request , options2 ) {
return respond ( request , this . # options , this . # manifest , {
... options2 ,
error : false ,
depth : 0
} ) ;
}
}
export { Server } ;
//# sourceMappingURL=index.js.map