acrylblends 0.6.1 → 0.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -6
- package/docs/framework/README.md +3 -2
- package/docs/framework/UPSTREAM.md +1 -1
- package/docs/framework/api/presets.md +0 -3
- package/docs/framework/cordis/acryl-in-a-cordis-app.md +9 -0
- package/docs/framework/getting-started/basic.md +5 -4
- package/docs/framework/getting-started/desktop.md +41 -0
- package/docs/framework/guides/jsx-dom.md +0 -3
- package/docs/framework/guides/jsx.md +1 -4
- package/docs/framework/guides/middleware.md +1 -1
- package/docs/framework/helpers/cookie.md +1 -1
- package/docs/framework/helpers/css.md +0 -3
- package/docs/framework/helpers/dev.md +0 -3
- package/docs/framework/helpers/jwt.md +1 -1
- package/docs/framework/helpers/proxy.md +0 -3
- package/docs/framework/middleware/builtin/basic-auth.md +6 -6
- package/docs/framework/middleware/builtin/cache.md +0 -3
- package/docs/framework/middleware/builtin/combine.md +1 -1
- package/docs/framework/middleware/builtin/ip-restriction.md +1 -1
- package/docs/framework/middleware/builtin/logger.md +1 -1
- package/docs/framework/middleware/builtin/mount.md +0 -3
- package/docs/framework/upstream.json +3 -3
- package/lib/accepts.d.ts +1 -1
- package/lib/acryl-base.d.ts +1 -1
- package/lib/adapter.d.ts +1 -1
- package/lib/{app-CmAYW1Al.d.ts → app-wFwpg-bt.d.ts} +1 -1
- package/lib/base-BpQy2Rk7.d.ts +783 -0
- package/lib/base-ddiVmiE7.js +721 -0
- package/lib/basic-auth.d.ts +1 -1
- package/lib/bearer-auth.d.ts +1 -1
- package/lib/body-limit.d.ts +1 -1
- package/lib/cache.d.ts +43 -0
- package/lib/cache.js +169 -0
- package/lib/client.d.ts +2 -2
- package/lib/combine.d.ts +1 -1
- package/lib/common-D8Z4JRCw.d.ts +46 -0
- package/lib/components-Ce5FRyHU.js +268 -0
- package/lib/components-DYZdxJIJ.js +24 -0
- package/lib/compress.d.ts +1 -1
- package/lib/conninfo.d.ts +2 -2
- package/lib/constants-BR9jM9BC.js +9 -0
- package/lib/{context-Bm7rI-oK.d.ts → context-DVQBjuns.d.ts} +1 -1
- package/lib/context-DxFdY_un.d.ts +250 -0
- package/lib/context-storage.d.ts +1 -1
- package/lib/{cookie-ClMaKDQf.d.ts → cookie-CCelEqky.d.ts} +1 -1
- package/lib/cookie.d.ts +3 -3
- package/lib/cors.d.ts +1 -1
- package/lib/csrf.d.ts +1 -1
- package/lib/css-D2jb7X8b.js +320 -0
- package/lib/css.d.ts +82 -0
- package/lib/css.js +134 -0
- package/lib/dev.d.ts +19 -0
- package/lib/dev.js +50 -0
- package/lib/etag.d.ts +1 -1
- package/lib/factory.d.ts +2 -2
- package/lib/hooks-Bq5q9IMl.js +762 -0
- package/lib/html-SllAe0YT.d.ts +46 -0
- package/lib/html.d.ts +1 -1
- package/lib/index-C850MeBA.d.ts +94 -0
- package/lib/{index-oOClm_Xk.d.ts → index-CUTfU69R.d.ts} +3 -3
- package/lib/{index-B-3F4wt2.d.ts → index-Cqcdluyn.d.ts} +2 -2
- package/lib/{index-UTBmM3GX.d.ts → index-CsvB-F9j.d.ts} +2 -2
- package/lib/index.d.ts +4 -4
- package/lib/ip-restriction.d.ts +2 -2
- package/lib/jsx/dom/client.d.ts +30 -0
- package/lib/jsx/dom/client.js +49 -0
- package/lib/jsx/dom/css.d.ts +84 -0
- package/lib/jsx/dom/css.js +2 -0
- package/lib/jsx/dom/jsx-dev-runtime.d.ts +3 -0
- package/lib/jsx/dom/jsx-dev-runtime.js +2 -0
- package/lib/jsx/dom/jsx-runtime.d.ts +3 -0
- package/lib/jsx/dom/jsx-runtime.js +2 -0
- package/lib/jsx/dom/server.d.ts +105 -0
- package/lib/jsx/dom/server.js +37 -0
- package/lib/jsx/dom.d.ts +5 -0
- package/lib/jsx/dom.js +74 -0
- package/lib/jsx/jsx-dev-runtime.d.ts +6 -0
- package/lib/jsx/jsx-dev-runtime.js +14 -0
- package/lib/jsx/jsx-runtime.d.ts +10 -0
- package/lib/jsx/jsx-runtime.js +30 -0
- package/lib/jsx/streaming.d.ts +2 -0
- package/lib/jsx/streaming.js +2 -0
- package/lib/jsx-dev-runtime-B22O-Npk.d.ts +7 -0
- package/lib/jsx-dev-runtime-kAhR_4C7.js +354 -0
- package/lib/jsx-runtime-BVVgDSdq.d.ts +1 -0
- package/lib/jsx.d.ts +3 -0
- package/lib/jsx.js +47 -0
- package/lib/jwk.d.ts +4 -4
- package/lib/{jwt-Dg493Tai.d.ts → jwt-BARhotDz.d.ts} +1 -1
- package/lib/jwt.d.ts +4 -4
- package/lib/language.d.ts +1 -1
- package/lib/linear-router-C3FPib6h.js +96 -0
- package/lib/logger.d.ts +1 -1
- package/lib/loopback-only.d.ts +1 -1
- package/lib/method-not-allowed.d.ts +2 -2
- package/lib/method-override.d.ts +2 -2
- package/lib/mount.d.ts +44 -0
- package/lib/mount.js +67 -0
- package/lib/node-server/conninfo.d.ts +1 -1
- package/lib/node-server/serve-static.d.ts +1 -1
- package/lib/node-server/serve-static.js +1 -1
- package/lib/node-server.d.ts +1 -1
- package/lib/node-server.js +1 -1
- package/lib/pattern-router-HZxjDGEQ.js +41 -0
- package/lib/powered-by.d.ts +1 -1
- package/lib/pretty-json.d.ts +1 -1
- package/lib/proxy.d.ts +72 -0
- package/lib/proxy.js +121 -0
- package/lib/quick.d.ts +8 -0
- package/lib/quick.js +17 -0
- package/lib/request-id.d.ts +1 -1
- package/lib/request.d.ts +1 -1
- package/lib/route.d.ts +1 -1
- package/lib/router/linear-router.js +1 -95
- package/lib/router/pattern-router.js +1 -40
- package/lib/schema-validator.d.ts +1 -1
- package/lib/secure-headers.d.ts +1 -1
- package/lib/{serve-static-Dw_m6KxR.js → serve-static-Cw23shXv.js} +1 -0
- package/lib/serve-static.d.ts +1 -1
- package/lib/streaming.d.ts +1 -1
- package/lib/testing.d.ts +4 -4
- package/lib/timeout.d.ts +1 -1
- package/lib/timing.d.ts +1 -1
- package/lib/tiny.d.ts +8 -0
- package/lib/tiny.js +15 -0
- package/lib/trailing-slash.d.ts +1 -1
- package/lib/{types-CHesD1KG.d.ts → types-CQiGmsWW.d.ts} +3 -3
- package/lib/{types-CwrQjlaM.d.ts → types-Lqx5BxQF.d.ts} +10 -1
- package/lib/{types-CDO6I3B0.d.ts → types-nEL8VPDC.d.ts} +1 -1
- package/lib/types.d.ts +1 -1
- package/lib/utils/body.d.ts +1 -1
- package/lib/utils/cookie.d.ts +1 -1
- package/lib/utils/crypto.d.ts +1 -1
- package/lib/utils/html.d.ts +1 -45
- package/lib/utils/ipaddr.d.ts +1 -1
- package/lib/utils/jwt.d.ts +1 -1
- package/lib/utils/types.d.ts +2 -2
- package/lib/validator.d.ts +2 -2
- package/lib/ws.d.ts +1 -1
- package/package.json +69 -1
- package/plugins/acryl-inspect/upstream.json +1 -1
- package/plugins/acryl-node-server/upstream.json +1 -1
- package/plugins/acryl-router/src/core/helper/css/common.case.test.tsx +506 -0
- package/plugins/acryl-router/src/core/helper/css/common.ts +337 -0
- package/plugins/acryl-router/src/core/helper/css/index.test.tsx +678 -0
- package/plugins/acryl-router/src/core/helper/css/index.ts +262 -0
- package/plugins/acryl-router/src/core/helper/dev/index.test.ts +181 -0
- package/plugins/acryl-router/src/core/helper/dev/index.ts +79 -0
- package/plugins/acryl-router/src/core/helper/proxy/index.test.ts +356 -0
- package/plugins/acryl-router/src/core/helper/proxy/index.ts +203 -0
- package/plugins/acryl-router/src/core/helper/streaming/sse.test.tsx +557 -0
- package/plugins/acryl-router/src/core/jsx/base.test.tsx +97 -0
- package/plugins/acryl-router/src/core/jsx/base.ts +490 -0
- package/plugins/acryl-router/src/core/jsx/children.test.ts +52 -0
- package/plugins/acryl-router/src/core/jsx/children.ts +20 -0
- package/plugins/acryl-router/src/core/jsx/components.test.tsx +936 -0
- package/plugins/acryl-router/src/core/jsx/components.ts +257 -0
- package/plugins/acryl-router/src/core/jsx/constants.ts +6 -0
- package/plugins/acryl-router/src/core/jsx/context-isolation.test.ts +655 -0
- package/plugins/acryl-router/src/core/jsx/context.ts +266 -0
- package/plugins/acryl-router/src/core/jsx/dom/client.test.tsx +128 -0
- package/plugins/acryl-router/src/core/jsx/dom/client.ts +89 -0
- package/plugins/acryl-router/src/core/jsx/dom/components.test.tsx +330 -0
- package/plugins/acryl-router/src/core/jsx/dom/components.ts +39 -0
- package/plugins/acryl-router/src/core/jsx/dom/context.test.tsx +184 -0
- package/plugins/acryl-router/src/core/jsx/dom/context.ts +52 -0
- package/plugins/acryl-router/src/core/jsx/dom/css.test.tsx +149 -0
- package/plugins/acryl-router/src/core/jsx/dom/css.ts +263 -0
- package/plugins/acryl-router/src/core/jsx/dom/hooks/index.test.tsx +172 -0
- package/plugins/acryl-router/src/core/jsx/dom/hooks/index.ts +91 -0
- package/plugins/acryl-router/src/core/jsx/dom/index.test.tsx +3681 -0
- package/plugins/acryl-router/src/core/jsx/dom/index.ts +170 -0
- package/plugins/acryl-router/src/core/jsx/dom/intrinsic-element/components.test.tsx +1344 -0
- package/plugins/acryl-router/src/core/jsx/dom/intrinsic-element/components.ts +438 -0
- package/plugins/acryl-router/src/core/jsx/dom/jsx-dev-runtime.ts +23 -0
- package/plugins/acryl-router/src/core/jsx/dom/jsx-runtime.ts +8 -0
- package/plugins/acryl-router/src/core/jsx/dom/render.ts +879 -0
- package/plugins/acryl-router/src/core/jsx/dom/server.test.tsx +199 -0
- package/plugins/acryl-router/src/core/jsx/dom/server.ts +76 -0
- package/plugins/acryl-router/src/core/jsx/dom/utils.ts +7 -0
- package/plugins/acryl-router/src/core/jsx/hooks/dom.test.tsx +859 -0
- package/plugins/acryl-router/src/core/jsx/hooks/index.ts +437 -0
- package/plugins/acryl-router/src/core/jsx/hooks/string.test.tsx +40 -0
- package/plugins/acryl-router/src/core/jsx/index.test.tsx +1744 -0
- package/plugins/acryl-router/src/core/jsx/index.ts +115 -0
- package/plugins/acryl-router/src/core/jsx/intrinsic-element/common.ts +23 -0
- package/plugins/acryl-router/src/core/jsx/intrinsic-element/components.test.tsx +666 -0
- package/plugins/acryl-router/src/core/jsx/intrinsic-element/components.ts +210 -0
- package/plugins/acryl-router/src/core/jsx/intrinsic-elements.ts +938 -0
- package/plugins/acryl-router/src/core/jsx/jsx-dev-runtime.ts +26 -0
- package/plugins/acryl-router/src/core/jsx/jsx-runtime.test.tsx +85 -0
- package/plugins/acryl-router/src/core/jsx/jsx-runtime.ts +51 -0
- package/plugins/acryl-router/src/core/jsx/streaming.test.tsx +1281 -0
- package/plugins/acryl-router/src/core/jsx/streaming.ts +231 -0
- package/plugins/acryl-router/src/core/jsx/types.ts +41 -0
- package/plugins/acryl-router/src/core/jsx/utils.test.ts +366 -0
- package/plugins/acryl-router/src/core/jsx/utils.ts +202 -0
- package/plugins/acryl-router/src/core/middleware/cache/index.test.ts +1211 -0
- package/plugins/acryl-router/src/core/middleware/cache/index.ts +323 -0
- package/plugins/acryl-router/src/core/middleware/mount/index.test.ts +334 -0
- package/plugins/acryl-router/src/core/middleware/mount/index.ts +108 -0
- package/plugins/acryl-router/src/core/preset/quick.test.ts +42 -0
- package/plugins/acryl-router/src/core/preset/quick.ts +24 -0
- package/plugins/acryl-router/src/core/preset/tiny.test.ts +42 -0
- package/plugins/acryl-router/src/core/preset/tiny.ts +20 -0
- package/plugins/acryl-router/src/core/utils/types.ts +9 -0
- package/plugins/acryl-router/src/helpers/index.ts +3 -0
- package/plugins/acryl-router/src/middleware/index.ts +2 -0
- package/plugins/acryl-router/src/service.ts +22 -5
- package/plugins/acryl-router/tests/jsx.spec.tsx +63 -0
- package/plugins/acryl-router/upstream.json +3 -3
- package/plugins/acryl-router-http/upstream.json +1 -1
- package/plugins/acryl-state/upstream.json +1 -1
- package/plugins/desktop/upstream.json +1 -1
- package/plugins/desktop-web/upstream.json +1 -1
- package/plugins/save/plugin.json +1 -1
- package/templates/todo/upstream.json +1 -1
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import { raw } from '../helper/html/index.ts'
|
|
2
|
+
import type { HtmlEscapedCallback, HtmlEscapedString } from '../utils/html.ts'
|
|
3
|
+
import { HtmlEscapedCallbackPhase, resolveCallback } from '../utils/html.ts'
|
|
4
|
+
import type { Child, FC, PropsWithChildren } from './index.ts'
|
|
5
|
+
import { jsx, Fragment, isUntrustedObject, renderChildren, renderUntrustedObject } from './base.ts'
|
|
6
|
+
import { DOM_RENDERER } from './constants.ts'
|
|
7
|
+
import { captureRenderContext, useContext } from './context.ts'
|
|
8
|
+
import { ErrorBoundary as ErrorBoundaryDomRenderer } from './dom/components.ts'
|
|
9
|
+
import type { HasRenderToDom } from './dom/render.ts'
|
|
10
|
+
import { StreamingContext } from './streaming.ts'
|
|
11
|
+
|
|
12
|
+
let errorBoundaryCounter = 0
|
|
13
|
+
|
|
14
|
+
export const childrenToString = async (children: Child[]): Promise<HtmlEscapedString[]> => {
|
|
15
|
+
try {
|
|
16
|
+
return children.flat().map(resolveChildEarly) as HtmlEscapedString[]
|
|
17
|
+
} catch (e) {
|
|
18
|
+
if (e instanceof Promise) {
|
|
19
|
+
// Capture before `await`: on the fallback path the render context is
|
|
20
|
+
// only observable during this synchronous window.
|
|
21
|
+
const resume = captureRenderContext()
|
|
22
|
+
await e
|
|
23
|
+
return resume(() => childrenToString(children))
|
|
24
|
+
} else {
|
|
25
|
+
throw e
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const resolveChildEarly = (child: Child): HtmlEscapedString | Promise<HtmlEscapedString> => {
|
|
31
|
+
if (child == null || typeof child === 'boolean') {
|
|
32
|
+
return '' as HtmlEscapedString
|
|
33
|
+
} else if (typeof child === 'string' || Array.isArray(child)) {
|
|
34
|
+
return renderChildren([child])
|
|
35
|
+
} else if (isUntrustedObject(child)) {
|
|
36
|
+
return renderUntrustedObject(child)
|
|
37
|
+
} else {
|
|
38
|
+
const str = child.toString()
|
|
39
|
+
return str instanceof Promise ? (str as Promise<HtmlEscapedString>) : raw(str)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type ErrorHandler = (error: Error) => void
|
|
44
|
+
export type FallbackRender = (error: Error) => Child
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @experimental
|
|
48
|
+
* `ErrorBoundary` is an experimental feature.
|
|
49
|
+
* The API might be changed.
|
|
50
|
+
*/
|
|
51
|
+
export const ErrorBoundary: FC<
|
|
52
|
+
PropsWithChildren<{
|
|
53
|
+
fallback?: Child
|
|
54
|
+
fallbackRender?: FallbackRender
|
|
55
|
+
onError?: ErrorHandler
|
|
56
|
+
}>
|
|
57
|
+
> = async ({ children, fallback, fallbackRender, onError }) => {
|
|
58
|
+
if (!children) {
|
|
59
|
+
return raw('')
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (!Array.isArray(children)) {
|
|
63
|
+
children = [children]
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const nonce = useContext(StreamingContext)?.scriptNonce
|
|
67
|
+
|
|
68
|
+
let resume: ReturnType<typeof captureRenderContext> | undefined
|
|
69
|
+
const getResume = () => (resume ||= captureRenderContext())
|
|
70
|
+
|
|
71
|
+
let fallbackStrPromise: Promise<HtmlEscapedString | string | undefined> | undefined
|
|
72
|
+
const resolveFallbackStr = (): Promise<HtmlEscapedString | string | undefined> =>
|
|
73
|
+
(fallbackStrPromise ||= (async () => {
|
|
74
|
+
const awaitedFallback = await fallback
|
|
75
|
+
if (awaitedFallback === null || awaitedFallback === undefined) {
|
|
76
|
+
return
|
|
77
|
+
}
|
|
78
|
+
if (typeof awaitedFallback === 'string' || Array.isArray(awaitedFallback)) {
|
|
79
|
+
return getResume()(() => renderChildren([awaitedFallback]))
|
|
80
|
+
}
|
|
81
|
+
if (isUntrustedObject(awaitedFallback)) {
|
|
82
|
+
return getResume()(() => renderUntrustedObject(awaitedFallback))
|
|
83
|
+
}
|
|
84
|
+
const fallbackResult = await getResume()(() => awaitedFallback.toString())
|
|
85
|
+
return raw(
|
|
86
|
+
fallbackResult,
|
|
87
|
+
(fallbackResult as HtmlEscapedString).callbacks ||
|
|
88
|
+
(awaitedFallback as unknown as HtmlEscapedString).callbacks
|
|
89
|
+
)
|
|
90
|
+
})())
|
|
91
|
+
const renderFallback = async (error: Error): Promise<HtmlEscapedString> => {
|
|
92
|
+
const fallbackStr = await resolveFallbackStr()
|
|
93
|
+
return getResume()(async () => {
|
|
94
|
+
onError?.(error)
|
|
95
|
+
const fallbackRes = (
|
|
96
|
+
fallbackStr !== undefined
|
|
97
|
+
? fallbackStr
|
|
98
|
+
: (fallbackRender && jsx(Fragment, {}, fallbackRender(error) as HtmlEscapedString)) || ''
|
|
99
|
+
) as HtmlEscapedString
|
|
100
|
+
const fallbackResString = await Fragment({ children: fallbackRes }).toString()
|
|
101
|
+
return raw(
|
|
102
|
+
fallbackResString,
|
|
103
|
+
(fallbackResString as HtmlEscapedString).callbacks || fallbackRes.callbacks
|
|
104
|
+
)
|
|
105
|
+
})
|
|
106
|
+
}
|
|
107
|
+
let resArray: HtmlEscapedString[] | Promise<HtmlEscapedString[]>[] = []
|
|
108
|
+
try {
|
|
109
|
+
resArray = children.map(resolveChildEarly) as unknown as HtmlEscapedString[]
|
|
110
|
+
} catch (e) {
|
|
111
|
+
const resume = getResume()
|
|
112
|
+
if (e instanceof Promise) {
|
|
113
|
+
resArray = [
|
|
114
|
+
e
|
|
115
|
+
.then(() => resume(() => childrenToString(children as Child[])))
|
|
116
|
+
.catch((e) => renderFallback(e)),
|
|
117
|
+
] as Promise<HtmlEscapedString[]>[]
|
|
118
|
+
} else {
|
|
119
|
+
resArray = [await renderFallback(e as Error)]
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (resArray.some((res) => (res as {}) instanceof Promise)) {
|
|
124
|
+
// Prime the context capture while still synchronous: a child that returned
|
|
125
|
+
// a Promise from `resolveChildEarly` skipped the `catch`, so the deferred
|
|
126
|
+
// `catchCallback` would otherwise capture too late.
|
|
127
|
+
getResume()
|
|
128
|
+
const index = errorBoundaryCounter++
|
|
129
|
+
const replaceRe = RegExp(`(<template id="E:${index}"></template>)(.*?)(<!--E:${index}-->)`, 's')
|
|
130
|
+
let caught = false
|
|
131
|
+
const catchCallback = async ({ error, buffer }: { error: Error; buffer?: [string] }) => {
|
|
132
|
+
if (caught) {
|
|
133
|
+
return ''
|
|
134
|
+
}
|
|
135
|
+
caught = true
|
|
136
|
+
|
|
137
|
+
const fallbackResString = await renderFallback(error)
|
|
138
|
+
const fallbackCallbacks = fallbackResString.callbacks
|
|
139
|
+
if (buffer) {
|
|
140
|
+
buffer[0] = buffer[0].replace(replaceRe, () => fallbackResString)
|
|
141
|
+
return fallbackCallbacks?.length ? raw('', fallbackCallbacks) : ''
|
|
142
|
+
}
|
|
143
|
+
return raw(
|
|
144
|
+
`<template data-acryl-target="E:${index}">${fallbackResString}</template><script>
|
|
145
|
+
((d,c,n) => {
|
|
146
|
+
c=d.currentScript.previousSibling
|
|
147
|
+
d=d.getElementById('E:${index}')
|
|
148
|
+
if(!d)return
|
|
149
|
+
do{n=d.nextSibling;n.remove()}while(n.nodeType!=8||n.nodeValue!='E:${index}')
|
|
150
|
+
d.replaceWith(c.content)
|
|
151
|
+
})(document)
|
|
152
|
+
</script>`,
|
|
153
|
+
fallbackCallbacks
|
|
154
|
+
)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
let error: unknown
|
|
158
|
+
const promiseAll = Promise.all(resArray).catch((e) => (error = e))
|
|
159
|
+
return raw(`<template id="E:${index}"></template><!--E:${index}-->`, [
|
|
160
|
+
({ phase, buffer, context }) => {
|
|
161
|
+
if (phase === HtmlEscapedCallbackPhase.BeforeStream) {
|
|
162
|
+
return
|
|
163
|
+
}
|
|
164
|
+
return promiseAll
|
|
165
|
+
.then(async (htmlArray: HtmlEscapedString[]) => {
|
|
166
|
+
if (error) {
|
|
167
|
+
throw error
|
|
168
|
+
}
|
|
169
|
+
htmlArray = htmlArray.flat()
|
|
170
|
+
const content = htmlArray.join('')
|
|
171
|
+
let html = buffer
|
|
172
|
+
? ''
|
|
173
|
+
: `<template data-acryl-target="E:${index}">${content}</template><script${
|
|
174
|
+
nonce ? ` nonce="${nonce}"` : ''
|
|
175
|
+
}>
|
|
176
|
+
((d,c) => {
|
|
177
|
+
c=d.currentScript.previousSibling
|
|
178
|
+
d=d.getElementById('E:${index}')
|
|
179
|
+
if(!d)return
|
|
180
|
+
d.parentElement.insertBefore(c.content,d.nextSibling)
|
|
181
|
+
})(document)
|
|
182
|
+
</script>`
|
|
183
|
+
|
|
184
|
+
if (htmlArray.every((html) => !(html as HtmlEscapedString).callbacks?.length)) {
|
|
185
|
+
if (buffer) {
|
|
186
|
+
buffer[0] = buffer[0].replace(replaceRe, () => content)
|
|
187
|
+
}
|
|
188
|
+
return html
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (buffer) {
|
|
192
|
+
buffer[0] = buffer[0].replace(
|
|
193
|
+
replaceRe,
|
|
194
|
+
(_all, pre, _, post) => `${pre}${content}${post}`
|
|
195
|
+
)
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const callbacks = htmlArray
|
|
199
|
+
.map((html) => (html as HtmlEscapedString).callbacks || [])
|
|
200
|
+
.flat()
|
|
201
|
+
|
|
202
|
+
if (phase === HtmlEscapedCallbackPhase.Stream) {
|
|
203
|
+
html = await resolveCallback(
|
|
204
|
+
html,
|
|
205
|
+
HtmlEscapedCallbackPhase.BeforeStream,
|
|
206
|
+
true,
|
|
207
|
+
context
|
|
208
|
+
)
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
let resolvedCount = 0
|
|
212
|
+
const promises = callbacks.map<HtmlEscapedCallback>(
|
|
213
|
+
(c) =>
|
|
214
|
+
(...args) =>
|
|
215
|
+
c(...args)
|
|
216
|
+
?.then((content) => {
|
|
217
|
+
resolvedCount++
|
|
218
|
+
|
|
219
|
+
if (buffer) {
|
|
220
|
+
if (resolvedCount === callbacks.length) {
|
|
221
|
+
buffer[0] = buffer[0].replace(replaceRe, (_all, _pre, content) => content)
|
|
222
|
+
}
|
|
223
|
+
buffer[0] += content
|
|
224
|
+
return raw('', (content as HtmlEscapedString).callbacks)
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return raw(
|
|
228
|
+
content +
|
|
229
|
+
(resolvedCount !== callbacks.length
|
|
230
|
+
? ''
|
|
231
|
+
: `<script>
|
|
232
|
+
((d,c,n) => {
|
|
233
|
+
d=d.getElementById('E:${index}')
|
|
234
|
+
if(!d)return
|
|
235
|
+
n=d.nextSibling
|
|
236
|
+
while(n.nodeType!=8||n.nodeValue!='E:${index}'){n=n.nextSibling}
|
|
237
|
+
n.remove()
|
|
238
|
+
d.remove()
|
|
239
|
+
})(document)
|
|
240
|
+
</script>`),
|
|
241
|
+
(content as HtmlEscapedString).callbacks
|
|
242
|
+
)
|
|
243
|
+
})
|
|
244
|
+
.catch((error) => catchCallback({ error, buffer }))
|
|
245
|
+
)
|
|
246
|
+
|
|
247
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
248
|
+
return raw(html, promises as any)
|
|
249
|
+
})
|
|
250
|
+
.catch((error) => catchCallback({ error, buffer }))
|
|
251
|
+
},
|
|
252
|
+
])
|
|
253
|
+
} else {
|
|
254
|
+
return Fragment({ children: resArray as Child[] })
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
;(ErrorBoundary as HasRenderToDom)[DOM_RENDERER] = ErrorBoundaryDomRenderer
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export const DOM_RENDERER = Symbol('RENDERER')
|
|
2
|
+
export const DOM_ERROR_HANDLER = Symbol('ERROR_HANDLER')
|
|
3
|
+
export const DOM_STASH = Symbol('STASH')
|
|
4
|
+
export const DOM_INTERNAL_TAG = Symbol('INTERNAL')
|
|
5
|
+
export const DOM_MEMO = Symbol('MEMO')
|
|
6
|
+
export const PERMALINK = Symbol('PERMALINK')
|