@hamur/adapter-html 0.0.0-stage → 0.0.2
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/LICENSE +22 -0
- package/README.md +31 -2
- package/dist/chunks/browser-index-2h1699xv.js +148 -0
- package/dist/chunks/browser-index-n6x04zrf.js +28 -0
- package/dist/chunks/browser-index-naq02zzj.js +4 -0
- package/dist/chunks/browser-index-qx74bd1y.js +302 -0
- package/dist/src/adapter.js +141 -0
- package/dist/src/error-page.js +335 -0
- package/dist/src/index.js +1241 -0
- package/dist/src/runtime/client.js +330 -0
- package/dist/src/runtime/island.js +40 -0
- package/dist/src/runtime/server.js +59 -0
- package/dist/types/src/adapter.d.ts +2 -0
- package/dist/types/src/async-data.d.ts +13 -0
- package/dist/types/src/context.d.ts +109 -0
- package/dist/types/src/error-page.d.ts +1 -0
- package/dist/types/src/index.d.ts +343 -0
- package/dist/types/src/island-html.d.ts +13 -0
- package/dist/types/src/island.d.ts +40 -0
- package/dist/types/src/lazy-hydration.d.ts +11 -0
- package/dist/types/src/markdown-page.d.ts +9 -0
- package/dist/types/src/markdown.d.ts +11 -0
- package/dist/types/src/plugin.d.ts +11 -0
- package/dist/types/src/runtime/client.d.ts +15 -0
- package/dist/types/src/runtime/hmr.d.ts +8 -0
- package/dist/types/src/runtime/hydration-dev.d.ts +1 -0
- package/dist/types/src/runtime/hydration.d.ts +10 -0
- package/dist/types/src/runtime/island.d.ts +8 -0
- package/dist/types/src/runtime/server.d.ts +8 -0
- package/dist/types/src/runtime/svg-id.d.ts +2 -0
- package/dist/types/src/server-component.d.ts +4 -0
- package/dist/types/src/svg.d.ts +10 -0
- package/package.json +62 -4
- package/src/adapter.ts +25 -0
- package/src/async-data.ts +65 -0
- package/src/context.ts +445 -0
- package/src/env.d.ts +3 -0
- package/src/error-page.ts +1 -0
- package/src/index.ts +1620 -0
- package/src/island-html.ts +58 -0
- package/src/island.ts +126 -0
- package/src/lazy-hydration.ts +56 -0
- package/src/markdown-page.ts +17 -0
- package/src/markdown.ts +29 -0
- package/src/plugin.ts +70 -0
- package/src/runtime/client.ts +363 -0
- package/src/runtime/hmr.ts +38 -0
- package/src/runtime/hydration-dev.ts +12 -0
- package/src/runtime/hydration.ts +11 -0
- package/src/runtime/island.ts +52 -0
- package/src/runtime/server.ts +56 -0
- package/src/runtime/svg-id.ts +12 -0
- package/src/server-component.ts +30 -0
- package/src/svg.ts +54 -0
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/adapter-html/src/index.ts
|
|
3
|
+
import {
|
|
4
|
+
addRouteMiddleware,
|
|
5
|
+
clearAsyncData,
|
|
6
|
+
$fetch,
|
|
7
|
+
clearError,
|
|
8
|
+
createForm,
|
|
9
|
+
disableScrollHandling,
|
|
10
|
+
forbidden,
|
|
11
|
+
navigateTo,
|
|
12
|
+
notFound,
|
|
13
|
+
permanentRedirect,
|
|
14
|
+
redirect,
|
|
15
|
+
refreshCookie,
|
|
16
|
+
setPageLayout,
|
|
17
|
+
showError,
|
|
18
|
+
unauthorized,
|
|
19
|
+
useCookie as useCookieRef,
|
|
20
|
+
withoutBase
|
|
21
|
+
} from "hamur/app";
|
|
22
|
+
import { reportWebVitals, syncedState } from "hamur/app";
|
|
23
|
+
import { deferPartId, whenAppReady } from "hamur/adapter";
|
|
24
|
+
import {
|
|
25
|
+
asyncDataArguments,
|
|
26
|
+
asyncDataKey,
|
|
27
|
+
stateArguments,
|
|
28
|
+
fetchKey,
|
|
29
|
+
timeAttributes,
|
|
30
|
+
timeView,
|
|
31
|
+
createLoadingIndicator as createLoadingIndicator2,
|
|
32
|
+
createRouteAnnouncer,
|
|
33
|
+
createAnnouncer,
|
|
34
|
+
announcerActions,
|
|
35
|
+
announcerRole,
|
|
36
|
+
ROUTE_ANNOUNCER_ID,
|
|
37
|
+
ANNOUNCER_POLITE_ID,
|
|
38
|
+
ANNOUNCER_ASSERTIVE_ID,
|
|
39
|
+
isHandlerReference,
|
|
40
|
+
isPending,
|
|
41
|
+
resolveCallOptions,
|
|
42
|
+
settledOf
|
|
43
|
+
} from "hamur/adapter";
|
|
44
|
+
import {
|
|
45
|
+
callOnce as callOnceOf,
|
|
46
|
+
clearState as clearStateOf,
|
|
47
|
+
setResponseStatus as setResponseStatusOf,
|
|
48
|
+
useResponseHeader as responseHeaderOf,
|
|
49
|
+
useRequestEvent as requestEventOf,
|
|
50
|
+
useRequestFetch as requestFetchOf,
|
|
51
|
+
useRequestHeader as requestHeaderOf,
|
|
52
|
+
useRequestHeaders as requestHeadersOf,
|
|
53
|
+
useRequestURL as requestURLOf,
|
|
54
|
+
usePreviewMode as previewModeOf
|
|
55
|
+
} from "hamur/app";
|
|
56
|
+
import {
|
|
57
|
+
assertFormMethod,
|
|
58
|
+
createActionRunner,
|
|
59
|
+
functionFormAction,
|
|
60
|
+
publicError,
|
|
61
|
+
restoredResult,
|
|
62
|
+
runtimeConfigOf,
|
|
63
|
+
siteConfigOf,
|
|
64
|
+
sanitizeHead,
|
|
65
|
+
seoMetaToHead,
|
|
66
|
+
LINK_DEFAULTS,
|
|
67
|
+
createLinkSlot,
|
|
68
|
+
linkAttributes,
|
|
69
|
+
linkDefaultsOf,
|
|
70
|
+
linkExtraAttributes,
|
|
71
|
+
linkPending,
|
|
72
|
+
linkPrefetchProps,
|
|
73
|
+
linkState,
|
|
74
|
+
warnRemovedLinkProps,
|
|
75
|
+
relativeTarget,
|
|
76
|
+
resolveLinkTarget,
|
|
77
|
+
resolveRelative,
|
|
78
|
+
prefetchAttribute,
|
|
79
|
+
viewTransitionAttribute,
|
|
80
|
+
checkTransitionName,
|
|
81
|
+
navigationHook,
|
|
82
|
+
navigationBlocker,
|
|
83
|
+
routeGuard,
|
|
84
|
+
createBlocker,
|
|
85
|
+
registerSnapshot
|
|
86
|
+
} from "hamur/adapter";
|
|
87
|
+
import { diagnosticURL, noteOutlet, prehydrate } from "hamur/adapter";
|
|
88
|
+
import { markWaiting as markWaiting3 } from "hamur/adapter";
|
|
89
|
+
|
|
90
|
+
// packages/adapter-html/src/async-data.ts
|
|
91
|
+
import { isPreviewMode } from "hamur/adapter";
|
|
92
|
+
var kept = new WeakMap;
|
|
93
|
+
|
|
94
|
+
// packages/adapter-html/src/context.ts
|
|
95
|
+
import { withBase } from "hamur/app";
|
|
96
|
+
import {
|
|
97
|
+
APP_ROOT_ID,
|
|
98
|
+
createLoadingIndicator,
|
|
99
|
+
createRouterApi,
|
|
100
|
+
routeBoundary
|
|
101
|
+
} from "hamur/adapter";
|
|
102
|
+
import { routeStateOf } from "hamur/adapter";
|
|
103
|
+
var LINK_STATE_ATTRIBUTE = "data-hamur-link";
|
|
104
|
+
var linkStateKey = (href, occurrence) => `${href} ${occurrence}`;
|
|
105
|
+
var current;
|
|
106
|
+
function routerOf(navigator, baseURL = "/", page) {
|
|
107
|
+
return createRouterApi({
|
|
108
|
+
...page,
|
|
109
|
+
navigator,
|
|
110
|
+
baseURL,
|
|
111
|
+
unavailable: () => new Error("useRouter() navigates only in the browser")
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
function detachedHref(to) {
|
|
115
|
+
if (typeof to !== "string")
|
|
116
|
+
throw new Error(`Link to the route "${to.name}" must be rendered inside a Hamur app`);
|
|
117
|
+
return withBase(to, "/");
|
|
118
|
+
}
|
|
119
|
+
var followed = new WeakSet;
|
|
120
|
+
function currentState() {
|
|
121
|
+
return current;
|
|
122
|
+
}
|
|
123
|
+
var rethrown = new WeakSet;
|
|
124
|
+
var lazyStrings = new WeakSet;
|
|
125
|
+
|
|
126
|
+
// packages/adapter-html/src/lazy-hydration.ts
|
|
127
|
+
import { hydrateOnAttribute, hydrateWrapper, markWaiting } from "hamur/adapter";
|
|
128
|
+
var pending = new Set;
|
|
129
|
+
// packages/adapter-html/src/island.ts
|
|
130
|
+
import {
|
|
131
|
+
ISLAND_ELEMENT,
|
|
132
|
+
SERVER_ISLAND_ELEMENT,
|
|
133
|
+
renderIsland,
|
|
134
|
+
renderServerIsland,
|
|
135
|
+
serverIslandProps
|
|
136
|
+
} from "hamur/adapter";
|
|
137
|
+
|
|
138
|
+
// packages/adapter-html/src/island-html.ts
|
|
139
|
+
import { markWaiting as markWaiting2 } from "hamur/adapter";
|
|
140
|
+
var outcomes = new WeakMap;
|
|
141
|
+
|
|
142
|
+
// packages/adapter-html/src/island.ts
|
|
143
|
+
var counters = new WeakMap;
|
|
144
|
+
// packages/adapter-html/src/markdown.ts
|
|
145
|
+
import { markdownProse, markdownView, writeMarkdownView } from "hamur/adapter";
|
|
146
|
+
|
|
147
|
+
// packages/adapter-html/src/index.ts
|
|
148
|
+
import { layoutOf, layoutSegments, matchesOf, routeDataOf } from "hamur/adapter";
|
|
149
|
+
import { isOnline, pollInterval, searchTarget, startPoll } from "hamur/adapter";
|
|
150
|
+
import { createAppUpdate } from "hamur/adapter";
|
|
151
|
+
var ESCAPES = { "&": "&", "<": "<", ">": ">", '"': """ };
|
|
152
|
+
function escapeAttribute(value) {
|
|
153
|
+
return String(value).replace(/[&<>"]/g, (char) => ESCAPES[char]);
|
|
154
|
+
}
|
|
155
|
+
function attributeString(attributes) {
|
|
156
|
+
let out = "";
|
|
157
|
+
for (const [name, value] of attributes) {
|
|
158
|
+
if (value === undefined || value === null || value === false)
|
|
159
|
+
continue;
|
|
160
|
+
out += value === true ? ` ${name}` : ` ${name}="${escapeAttribute(value)}"`;
|
|
161
|
+
}
|
|
162
|
+
return out;
|
|
163
|
+
}
|
|
164
|
+
function keepLinkState(states, href, entry) {
|
|
165
|
+
let occurrence = 0;
|
|
166
|
+
while (states.has(linkStateKey(href, occurrence)))
|
|
167
|
+
occurrence++;
|
|
168
|
+
states.set(linkStateKey(href, occurrence), entry);
|
|
169
|
+
return occurrence;
|
|
170
|
+
}
|
|
171
|
+
function resolveLink(props, attrs) {
|
|
172
|
+
warnRemovedLinkProps(props);
|
|
173
|
+
const { to: target, query, relative, mask, external } = props;
|
|
174
|
+
const current = currentState();
|
|
175
|
+
const searched = current ? searchTarget(relativeTarget(target, current.route, relative), current.route, query) : target;
|
|
176
|
+
const { to, props: rest } = resolveLinkTarget(current?.app, searched, attrs, current?.href, external);
|
|
177
|
+
const href = current ? current.href(to) : detachedHref(to);
|
|
178
|
+
const state = current ? linkState(typeof to === "string" ? to : withoutBase(href, current.baseURL), current.route) : undefined;
|
|
179
|
+
return {
|
|
180
|
+
current,
|
|
181
|
+
to,
|
|
182
|
+
href,
|
|
183
|
+
state,
|
|
184
|
+
rest,
|
|
185
|
+
maskHref: mask === undefined ? undefined : current ? current.href(mask) : detachedHref(mask)
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
function slotOf(props, d, { current, to, href, state, maskHref }) {
|
|
189
|
+
const {
|
|
190
|
+
state: entryState,
|
|
191
|
+
query,
|
|
192
|
+
mask,
|
|
193
|
+
unmaskOnReload,
|
|
194
|
+
viewTransition,
|
|
195
|
+
replace,
|
|
196
|
+
prefetch,
|
|
197
|
+
prefetchOn,
|
|
198
|
+
pendingClass = d.pendingClass,
|
|
199
|
+
ariaCurrentValue = "page",
|
|
200
|
+
external,
|
|
201
|
+
noRel,
|
|
202
|
+
prefetchedClass = d.prefetchedClass,
|
|
203
|
+
scroll,
|
|
204
|
+
prefetchDelay = d.prefetchDelay,
|
|
205
|
+
rel,
|
|
206
|
+
target
|
|
207
|
+
} = props;
|
|
208
|
+
return createLinkSlot({
|
|
209
|
+
href,
|
|
210
|
+
to,
|
|
211
|
+
attrs: linkAttributes({
|
|
212
|
+
href,
|
|
213
|
+
external,
|
|
214
|
+
...linkPrefetchProps({ prefetch, prefetchOn }, d),
|
|
215
|
+
replace,
|
|
216
|
+
viewTransition,
|
|
217
|
+
pendingClass,
|
|
218
|
+
trim: !!query,
|
|
219
|
+
mask: maskHref,
|
|
220
|
+
unmaskOnReload,
|
|
221
|
+
ariaCurrent: state?.exact ? ariaCurrentValue : undefined,
|
|
222
|
+
rel,
|
|
223
|
+
target,
|
|
224
|
+
noRel,
|
|
225
|
+
prefetchedClass,
|
|
226
|
+
scroll,
|
|
227
|
+
prefetchDelay,
|
|
228
|
+
externalRelAttribute: d.externalRelAttribute
|
|
229
|
+
}),
|
|
230
|
+
active: !!state?.active,
|
|
231
|
+
exact: !!state?.exact,
|
|
232
|
+
pending: !!current?.navigator?.get && linkPending(href, current.navigator.get(), current.baseURL),
|
|
233
|
+
external,
|
|
234
|
+
options: {
|
|
235
|
+
replace,
|
|
236
|
+
state: entryState,
|
|
237
|
+
mask,
|
|
238
|
+
unmaskOnReload,
|
|
239
|
+
viewTransition,
|
|
240
|
+
scroll: scroll === false ? false : undefined
|
|
241
|
+
},
|
|
242
|
+
router: current ? routerOf(current.navigator, current.baseURL, current) : null
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
var NO_DEFAULTS = {};
|
|
246
|
+
function linkOf(props, defaults) {
|
|
247
|
+
const {
|
|
248
|
+
to: _to,
|
|
249
|
+
href: _href,
|
|
250
|
+
noPrefetch: _noPrefetch,
|
|
251
|
+
query,
|
|
252
|
+
state: entryState,
|
|
253
|
+
relative: _relative,
|
|
254
|
+
mask,
|
|
255
|
+
unmaskOnReload,
|
|
256
|
+
viewTransition,
|
|
257
|
+
replace,
|
|
258
|
+
prefetch,
|
|
259
|
+
prefetchOn,
|
|
260
|
+
activeClass,
|
|
261
|
+
exactActiveClass,
|
|
262
|
+
pendingClass,
|
|
263
|
+
ariaCurrentValue = "page",
|
|
264
|
+
external,
|
|
265
|
+
noRel,
|
|
266
|
+
prefetchedClass,
|
|
267
|
+
scroll,
|
|
268
|
+
prefetchDelay,
|
|
269
|
+
onBeforeNavigate,
|
|
270
|
+
children,
|
|
271
|
+
...attrs
|
|
272
|
+
} = props;
|
|
273
|
+
const resolved = resolveLink(props, attrs);
|
|
274
|
+
const { current, href, state, maskHref, rest } = resolved;
|
|
275
|
+
const d = linkDefaultsOf(current?.app, defaults);
|
|
276
|
+
if (typeof children === "function")
|
|
277
|
+
return children(slotOf(props, d, resolved));
|
|
278
|
+
const mode = external ? "false" : prefetchAttribute(linkPrefetchProps({ prefetch, prefetchOn }, d));
|
|
279
|
+
const pending = pendingClass ?? d.pendingClass;
|
|
280
|
+
const { class: own, ...others } = rest;
|
|
281
|
+
const classes = [
|
|
282
|
+
own,
|
|
283
|
+
state?.active && (activeClass ?? d.activeClass),
|
|
284
|
+
state?.exact && (exactActiveClass ?? d.exactActiveClass)
|
|
285
|
+
].filter(Boolean).join(" ");
|
|
286
|
+
const entry = { state: entryState, onBeforeNavigate };
|
|
287
|
+
const extras = linkExtraAttributes({
|
|
288
|
+
href,
|
|
289
|
+
external,
|
|
290
|
+
noRel,
|
|
291
|
+
rel: rest.rel,
|
|
292
|
+
target: rest.target,
|
|
293
|
+
prefetchedClass: prefetchedClass ?? d.prefetchedClass,
|
|
294
|
+
scroll,
|
|
295
|
+
prefetchDelay: prefetchDelay ?? d.prefetchDelay,
|
|
296
|
+
externalRelAttribute: d.externalRelAttribute
|
|
297
|
+
});
|
|
298
|
+
const attributes = [
|
|
299
|
+
["class", classes || undefined],
|
|
300
|
+
...Object.entries(others).filter(([name]) => !(name === "rel" && extras.rel !== undefined)),
|
|
301
|
+
...state?.exact && others["aria-current"] === undefined ? [["aria-current", ariaCurrentValue]] : [],
|
|
302
|
+
["href", href],
|
|
303
|
+
["data-hamur-prefetch", mode],
|
|
304
|
+
["data-hamur-view-transition", viewTransitionAttribute(viewTransition)],
|
|
305
|
+
["data-hamur-mask", maskHref],
|
|
306
|
+
["data-hamur-unmask", mask !== undefined && unmaskOnReload === false ? "false" : undefined],
|
|
307
|
+
[
|
|
308
|
+
LINK_STATE_ATTRIBUTE,
|
|
309
|
+
(entryState !== undefined || onBeforeNavigate !== undefined) && current ? keepLinkState(current.linkStates ??= new Map, href, entry) : undefined
|
|
310
|
+
],
|
|
311
|
+
["data-hamur-pending-class", pending === LINK_DEFAULTS.pendingClass ? undefined : pending],
|
|
312
|
+
...Object.entries(extras)
|
|
313
|
+
];
|
|
314
|
+
return `<a${attributeString(attributes)}${replace ? " data-hamur-replace" : ""}${query ? " data-hamur-trim" : ""}>${children ?? ""}</a>`;
|
|
315
|
+
}
|
|
316
|
+
function Link(props) {
|
|
317
|
+
return linkOf(props, NO_DEFAULTS);
|
|
318
|
+
}
|
|
319
|
+
var navigatedTrees = new WeakSet;
|
|
320
|
+
var isDev = import.meta.dev === true;
|
|
321
|
+
var warnedSlots = new Set;
|
|
322
|
+
var learned = new WeakMap;
|
|
323
|
+
var watching = new WeakSet;
|
|
324
|
+
function DefaultErrorPage({ error }) {
|
|
325
|
+
const code = isDev && error.code ? `<p><a href="${escapeAttribute(diagnosticURL(error.code))}" target="_blank" rel="noopener">${escapeAttribute(error.code)}</a></p>` : "";
|
|
326
|
+
const stack = error.stack ? `<pre>${escapeAttribute(error.stack)}</pre>` : "";
|
|
327
|
+
return `<main style="font-family:system-ui,sans-serif;text-align:center;padding:4rem 1rem"><h1 style="font-size:4rem;margin:0">${error.status}</h1><p>${escapeAttribute(error.message)}</p>${code}${stack}${Link({ to: "/", children: "Back home" })}</main>`;
|
|
328
|
+
}
|
|
329
|
+
var readyOfApp = new WeakMap;
|
|
330
|
+
var pollsOfApp = new WeakMap;
|
|
331
|
+
var handlerForms = new WeakMap;
|
|
332
|
+
var actions = new WeakMap;
|
|
333
|
+
export {
|
|
334
|
+
DefaultErrorPage as default
|
|
335
|
+
};
|