workers-start 0.1.1 → 0.2.1
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/CHANGELOG.md +21 -1
- package/README.md +28 -15
- package/biome.preset.json +31 -13
- package/dist/accept.d.ts +18 -0
- package/dist/accept.d.ts.map +1 -0
- package/dist/accept.js +54 -0
- package/dist/accept.js.map +1 -0
- package/dist/check-bundle-cli.d.ts +1 -1
- package/dist/check-bundle-cli.js +50 -25
- package/dist/check-bundle-cli.js.map +1 -1
- package/dist/check-bundle.d.ts +36 -8
- package/dist/check-bundle.d.ts.map +1 -1
- package/dist/check-bundle.js +122 -31
- package/dist/check-bundle.js.map +1 -1
- package/dist/entry.d.ts +40 -18
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +99 -35
- package/dist/entry.js.map +1 -1
- package/dist/head.d.ts +34 -10
- package/dist/head.d.ts.map +1 -1
- package/dist/head.js +46 -26
- package/dist/head.js.map +1 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/scripts.d.ts +34 -6
- package/dist/scripts.d.ts.map +1 -1
- package/dist/scripts.js +36 -11
- package/dist/scripts.js.map +1 -1
- package/dist/workers.d.ts +6 -4
- package/dist/workers.d.ts.map +1 -1
- package/dist/workers.js +17 -13
- package/dist/workers.js.map +1 -1
- package/package.json +21 -9
- package/src/accept.ts +63 -0
- package/src/check-bundle-cli.ts +57 -23
- package/src/check-bundle.ts +133 -34
- package/src/entry.ts +117 -44
- package/src/head.ts +75 -40
- package/src/index.ts +14 -3
- package/src/scripts.ts +62 -14
- package/src/workers.ts +19 -15
package/dist/head.js
CHANGED
|
@@ -2,55 +2,75 @@
|
|
|
2
2
|
* Per-page head tags in the shape a TanStack Router `head()` returns.
|
|
3
3
|
*
|
|
4
4
|
* The router keeps one meta per `name` or `property`, deepest route winning,
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* and concatenates links. So call `pageHead` from leaf routes only: a tag a
|
|
6
|
+
* leaf leaves out falls back to a parent's, and a canonical from both a
|
|
7
|
+
* layout and a leaf is emitted twice. Put site-wide tags (charset, viewport,
|
|
8
|
+
* icons) in the root route without this helper.
|
|
8
9
|
*/
|
|
9
10
|
export function createPageHead(site) {
|
|
10
|
-
const origin = site.url.
|
|
11
|
+
const origin = new URL(site.url).origin;
|
|
11
12
|
const template = site.titleTemplate ?? ((title) => `${title} | ${site.name}`);
|
|
13
|
+
/** `/` maps to the bare origin; anything else resolves against it, so absolute URLs pass through. */
|
|
12
14
|
const absoluteUrl = (path) => {
|
|
13
|
-
if (
|
|
14
|
-
return
|
|
15
|
+
if (path === "/" || path === "") {
|
|
16
|
+
return origin;
|
|
15
17
|
}
|
|
16
|
-
|
|
18
|
+
const resolved = new URL(path.startsWith("/") || /^[a-z][a-z0-9+.-]*:|^\/\//i.test(path) ? path : `/${path}`, `${origin}/`);
|
|
19
|
+
return resolved.href;
|
|
17
20
|
};
|
|
18
21
|
const pageHead = (seo) => {
|
|
19
22
|
const url = absoluteUrl(seo.path);
|
|
20
23
|
const socialTitle = seo.socialTitle ?? seo.title;
|
|
21
24
|
const socialDescription = seo.socialDescription ?? seo.description;
|
|
22
|
-
const
|
|
23
|
-
const image =
|
|
25
|
+
const imageInput = seo.image ?? site.defaultImage;
|
|
26
|
+
const image = typeof imageInput === "string" ? { url: imageInput, ...seo.imageSize } : imageInput;
|
|
27
|
+
const imageUrl = image ? absoluteUrl(image.url) : undefined;
|
|
24
28
|
const meta = [
|
|
25
29
|
{ title: seo.rawTitle ? seo.title : template(seo.title) },
|
|
26
30
|
{ name: "description", content: seo.description },
|
|
27
31
|
];
|
|
28
|
-
|
|
29
|
-
|
|
32
|
+
const robots = seo.robots ?? (seo.noindex ? "noindex" : undefined);
|
|
33
|
+
if (robots) {
|
|
34
|
+
meta.push({ name: "robots", content: robots });
|
|
30
35
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
meta.push({ property: "og:image", content: image });
|
|
36
|
+
if (seo.keywords?.length) {
|
|
37
|
+
meta.push({ name: "keywords", content: seo.keywords.join(", ") });
|
|
34
38
|
}
|
|
35
|
-
|
|
36
|
-
|
|
39
|
+
meta.push({ property: "og:title", content: socialTitle }, { property: "og:description", content: socialDescription }, { property: "og:url", content: url }, { property: "og:site_name", content: site.name }, { property: "og:locale", content: site.locale ?? "en_US" });
|
|
40
|
+
if (image && imageUrl) {
|
|
41
|
+
meta.push({ property: "og:image", content: imageUrl });
|
|
42
|
+
if (image.type)
|
|
43
|
+
meta.push({ property: "og:image:type", content: image.type });
|
|
44
|
+
if (image.width)
|
|
45
|
+
meta.push({ property: "og:image:width", content: String(image.width) });
|
|
46
|
+
if (image.height)
|
|
47
|
+
meta.push({ property: "og:image:height", content: String(image.height) });
|
|
48
|
+
if (image.alt)
|
|
49
|
+
meta.push({ property: "og:image:alt", content: image.alt });
|
|
37
50
|
}
|
|
38
51
|
meta.push({ property: "og:type", content: seo.type ?? "website" });
|
|
39
|
-
if (seo.published)
|
|
52
|
+
if (seo.published)
|
|
40
53
|
meta.push({ property: "article:published_time", content: seo.published });
|
|
41
|
-
|
|
42
|
-
if (seo.modified) {
|
|
54
|
+
if (seo.modified)
|
|
43
55
|
meta.push({ property: "article:modified_time", content: seo.modified });
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
56
|
+
for (const author of seo.authors ?? [])
|
|
57
|
+
meta.push({ property: "article:author", content: author });
|
|
58
|
+
for (const tag of seo.tags ?? [])
|
|
59
|
+
meta.push({ property: "article:tag", content: tag });
|
|
60
|
+
meta.push({ name: "twitter:card", content: imageUrl ? "summary_large_image" : "summary" });
|
|
61
|
+
if (site.twitterSite)
|
|
62
|
+
meta.push({ name: "twitter:site", content: site.twitterSite });
|
|
63
|
+
if (site.twitterCreator)
|
|
47
64
|
meta.push({ name: "twitter:creator", content: site.twitterCreator });
|
|
48
|
-
}
|
|
49
65
|
meta.push({ name: "twitter:title", content: socialTitle }, { name: "twitter:description", content: seo.twitterDescription ?? socialDescription });
|
|
50
|
-
if (
|
|
51
|
-
meta.push({ name: "twitter:image", content:
|
|
66
|
+
if (imageUrl) {
|
|
67
|
+
meta.push({ name: "twitter:image", content: imageUrl });
|
|
68
|
+
if (image?.alt)
|
|
69
|
+
meta.push({ name: "twitter:image:alt", content: image.alt });
|
|
52
70
|
}
|
|
53
|
-
|
|
71
|
+
meta.push(...(seo.meta ?? []));
|
|
72
|
+
const links = seo.canonical === false ? [] : [{ rel: "canonical", href: seo.canonical ? absoluteUrl(seo.canonical) : url }];
|
|
73
|
+
return { meta, links };
|
|
54
74
|
};
|
|
55
75
|
return { pageHead, absoluteUrl };
|
|
56
76
|
}
|
package/dist/head.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"head.js","sourceRoot":"","sources":["../src/head.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"head.js","sourceRoot":"","sources":["../src/head.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAyEH,MAAM,UAAU,cAAc,CAAC,IAAc;IAI3C,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,MAAM,QAAQ,GAAG,IAAI,CAAC,aAAa,IAAI,CAAC,CAAC,KAAa,EAAE,EAAE,CAAC,GAAG,KAAK,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IAEtF,qGAAqG;IACrG,MAAM,WAAW,GAAG,CAAC,IAAY,EAAU,EAAE;QAC3C,IAAI,IAAI,KAAK,GAAG,IAAI,IAAI,KAAK,EAAE,EAAE,CAAC;YAChC,OAAO,MAAM,CAAC;QAChB,CAAC;QACD,MAAM,QAAQ,GAAG,IAAI,GAAG,CACtB,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,4BAA4B,CAAC,IAAI,CAAC,IAAI,CAA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,IAAI,CAAC,EAAE,IAAI,EAAE,iBAAiB,EAAE,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC;QAC9F,IAAI,CAAC,IAAI,CACP,EAAE,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,WAAW,EAAE,EAC/C,EAAE,IAAI,EAAE,qBAAqB,EAAE,OAAO,EAAE,GAAG,CAAC,kBAAkB,IAAI,iBAAiB,EAAE,CACtF,CAAC;QACF,IAAI,QAAQ,EAAE,CAAC;YACb,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAC;YACxD,IAAI,KAAK,EAAE,GAAG;gBAAE,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,mBAAmB,EAAE,OAAO,EAAE,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC;QAC/E,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC;QAE/B,MAAM,KAAK,GACT,GAAG,CAAC,SAAS,KAAK,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;QAChH,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;IACzB,CAAC,CAAC;IAEF,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;AACnC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
export type { MediaRange } from "./accept.js";
|
|
2
|
+
export { parseAccept, quality } from "./accept.js";
|
|
1
3
|
export type { EntryOptions, FetchHandler, MarkdownResult } from "./entry.js";
|
|
2
|
-
export { createEntry, defaultIsPage, MARKDOWN_HEADERS, normalizePath, wantsMarkdown } from "./entry.js";
|
|
3
|
-
export type { HeadTags, MetaTag, PageSeo, SiteHead } from "./head.js";
|
|
4
|
+
export { acceptsHtml, createEntry, defaultIsPage, MARKDOWN_HEADERS, mergeVary, normalizePath, underPrefix, wantsMarkdown, } from "./entry.js";
|
|
5
|
+
export type { HeadTags, MetaTag, PageImage, PageSeo, SiteHead } from "./head.js";
|
|
4
6
|
export { createPageHead } from "./head.js";
|
|
5
7
|
export type { AnalyticsScriptOptions, ThemeScriptOptions } from "./scripts.js";
|
|
6
|
-
export { analyticsScript, themeScript } from "./scripts.js";
|
|
8
|
+
export { analyticsScript, inlineJson, themeScript } from "./scripts.js";
|
|
7
9
|
export type { WorkersModule } from "./workers.js";
|
|
8
10
|
export { afterResponse, getBinding, getEnvString, isKvNamespace, loadWorkers, setWorkersModule } from "./workers.js";
|
|
9
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC7E,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACnD,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC7E,OAAO,EACL,WAAW,EACX,WAAW,EACX,aAAa,EACb,gBAAgB,EAChB,SAAS,EACT,aAAa,EACb,WAAW,EACX,aAAa,GACd,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACjF,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,YAAY,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAC/E,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACxE,YAAY,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { parseAccept, quality } from "./accept.js";
|
|
2
|
+
export { acceptsHtml, createEntry, defaultIsPage, MARKDOWN_HEADERS, mergeVary, normalizePath, underPrefix, wantsMarkdown, } from "./entry.js";
|
|
2
3
|
export { createPageHead } from "./head.js";
|
|
3
|
-
export { analyticsScript, themeScript } from "./scripts.js";
|
|
4
|
+
export { analyticsScript, inlineJson, themeScript } from "./scripts.js";
|
|
4
5
|
export { afterResponse, getBinding, getEnvString, isKvNamespace, loadWorkers, setWorkersModule } from "./workers.js";
|
|
5
6
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,EACL,WAAW,EACX,WAAW,EACX,aAAa,EACb,gBAAgB,EAChB,SAAS,EACT,aAAa,EACb,WAAW,EACX,aAAa,GACd,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAE3C,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAExE,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/scripts.d.ts
CHANGED
|
@@ -3,29 +3,57 @@
|
|
|
3
3
|
* `dangerouslySetInnerHTML`. Both run before hydration and touch nothing
|
|
4
4
|
* React renders, so they cause no hydration mismatch.
|
|
5
5
|
*/
|
|
6
|
+
/**
|
|
7
|
+
* JSON for embedding in an inline script: `<`, U+2028 and U+2029 are escaped,
|
|
8
|
+
* so no value can close the script tag or break the line.
|
|
9
|
+
*/
|
|
10
|
+
export declare function inlineJson(value: unknown): string;
|
|
6
11
|
export interface ThemeScriptOptions {
|
|
7
12
|
/** localStorage key. Default `theme`. */
|
|
8
13
|
storageKey?: string;
|
|
9
|
-
/** Attribute set on `<html>`. Default `data-theme`. */
|
|
10
|
-
attribute?: string;
|
|
11
14
|
/** Accepted stored values. Default `["light", "dark"]`. */
|
|
12
15
|
values?: string[];
|
|
16
|
+
/**
|
|
17
|
+
* How the choice is applied to `<html>`: set as an attribute (default
|
|
18
|
+
* `data-theme`), or added as a class (`{ class: true }`, as Tailwind's
|
|
19
|
+
* class-based dark mode expects).
|
|
20
|
+
*/
|
|
21
|
+
target?: {
|
|
22
|
+
attribute: string;
|
|
23
|
+
} | {
|
|
24
|
+
class: true;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* With no stored choice, apply the OS preference anyway (needed when CSS
|
|
28
|
+
* keys dark mode off the class or attribute rather than the media query).
|
|
29
|
+
*/
|
|
30
|
+
followSystem?: boolean;
|
|
13
31
|
}
|
|
14
32
|
/**
|
|
15
|
-
* Applies
|
|
16
|
-
*
|
|
33
|
+
* Applies the stored theme before first paint, so it never flashes the other
|
|
34
|
+
* one. With nothing stored and `followSystem` off it does nothing, and CSS
|
|
17
35
|
* `color-scheme: light dark` follows the operating system.
|
|
18
36
|
*/
|
|
19
37
|
export declare function themeScript(options?: ThemeScriptOptions): string;
|
|
20
38
|
export interface AnalyticsScriptOptions {
|
|
21
39
|
/** GA4 measurement id, `G-…`. Public; safe in the bundle. */
|
|
22
40
|
measurementId: string;
|
|
23
|
-
/** Hostnames that report. Every other host (localhost, previews) loads nothing. */
|
|
41
|
+
/** Hostnames that report, compared without case. Every other host (localhost, previews) loads nothing. */
|
|
24
42
|
hosts: string[];
|
|
43
|
+
/** Path prefixes that never load analytics, such as `/admin`. */
|
|
44
|
+
skipPaths?: string[];
|
|
45
|
+
/**
|
|
46
|
+
* Load only after consent: the name of a cookie that must be present (and
|
|
47
|
+
* equal `value`, when given). Without it, analytics loads on every page view.
|
|
48
|
+
*/
|
|
49
|
+
consentCookie?: {
|
|
50
|
+
name: string;
|
|
51
|
+
value?: string;
|
|
52
|
+
};
|
|
25
53
|
}
|
|
26
54
|
/**
|
|
27
55
|
* Google Analytics 4 bootstrap gated on `location.hostname`, so local dev and
|
|
28
56
|
* preview deploys never fetch gtag.js or land in the production property.
|
|
29
57
|
*/
|
|
30
|
-
export declare function analyticsScript(
|
|
58
|
+
export declare function analyticsScript(options: AnalyticsScriptOptions): string;
|
|
31
59
|
//# sourceMappingURL=scripts.d.ts.map
|
package/dist/scripts.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scripts.d.ts","sourceRoot":"","sources":["../src/scripts.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,WAAW,kBAAkB;IACjC,yCAAyC;IACzC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,
|
|
1
|
+
{"version":3,"file":"scripts.d.ts","sourceRoot":"","sources":["../src/scripts.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAKjD;AAED,MAAM,WAAW,kBAAkB;IACjC,yCAAyC;IACzC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,2DAA2D;IAC3D,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB;;;;OAIG;IACH,MAAM,CAAC,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,KAAK,EAAE,IAAI,CAAA;KAAE,CAAC;IACjD;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,OAAO,GAAE,kBAAuB,GAAG,MAAM,CAYpE;AAED,MAAM,WAAW,sBAAsB;IACrC,6DAA6D;IAC7D,aAAa,EAAE,MAAM,CAAC;IACtB,0GAA0G;IAC1G,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,iEAAiE;IACjE,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB;;;OAGG;IACH,aAAa,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAClD;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG,MAAM,CAoBvE"}
|
package/dist/scripts.js
CHANGED
|
@@ -4,25 +4,50 @@
|
|
|
4
4
|
* React renders, so they cause no hydration mismatch.
|
|
5
5
|
*/
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
7
|
+
* JSON for embedding in an inline script: `<`, U+2028 and U+2029 are escaped,
|
|
8
|
+
* so no value can close the script tag or break the line.
|
|
9
|
+
*/
|
|
10
|
+
export function inlineJson(value) {
|
|
11
|
+
return JSON.stringify(value)
|
|
12
|
+
.replace(/</g, "\\u003c")
|
|
13
|
+
.replace(/\u2028/g, "\\u2028")
|
|
14
|
+
.replace(/\u2029/g, "\\u2029");
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Applies the stored theme before first paint, so it never flashes the other
|
|
18
|
+
* one. With nothing stored and `followSystem` off it does nothing, and CSS
|
|
9
19
|
* `color-scheme: light dark` follows the operating system.
|
|
10
20
|
*/
|
|
11
21
|
export function themeScript(options = {}) {
|
|
12
|
-
const key =
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
|
|
22
|
+
const key = inlineJson(options.storageKey ?? "theme");
|
|
23
|
+
const values = inlineJson(options.values ?? ["light", "dark"]);
|
|
24
|
+
const target = options.target ?? { attribute: "data-theme" };
|
|
25
|
+
const apply = "class" in target
|
|
26
|
+
? `var c=document.documentElement.classList;${values}.forEach(function(v){c.remove(v)});c.add(t)`
|
|
27
|
+
: `document.documentElement.setAttribute(${inlineJson(target.attribute)},t)`;
|
|
28
|
+
const fallback = options.followSystem
|
|
29
|
+
? `if(${values}.indexOf(t)===-1){t=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}`
|
|
30
|
+
: "";
|
|
31
|
+
return `try{var t=localStorage.getItem(${key});${fallback}if(${values}.indexOf(t)!==-1){${apply}}}catch(e){}`;
|
|
16
32
|
}
|
|
17
33
|
/**
|
|
18
34
|
* Google Analytics 4 bootstrap gated on `location.hostname`, so local dev and
|
|
19
35
|
* preview deploys never fetch gtag.js or land in the production property.
|
|
20
36
|
*/
|
|
21
|
-
export function analyticsScript(
|
|
22
|
-
if (!/^G-[A-Z0-9]+$/.test(measurementId)) {
|
|
23
|
-
throw new Error(`Not a GA4 measurement id: ${measurementId}`);
|
|
37
|
+
export function analyticsScript(options) {
|
|
38
|
+
if (!/^G-[A-Z0-9]+$/.test(options.measurementId)) {
|
|
39
|
+
throw new Error(`Not a GA4 measurement id: ${options.measurementId}`);
|
|
40
|
+
}
|
|
41
|
+
const id = inlineJson(options.measurementId);
|
|
42
|
+
const hosts = inlineJson(options.hosts.map((h) => h.toLowerCase()));
|
|
43
|
+
const checks = [`if(${hosts}.indexOf(location.hostname.toLowerCase())===-1)return;`];
|
|
44
|
+
if (options.skipPaths?.length) {
|
|
45
|
+
checks.push(`var p=location.pathname;if(${inlineJson(options.skipPaths)}.some(function(s){return p===s||p.indexOf(s.replace(/\\/$/,"")+"/")===0}))return;`);
|
|
46
|
+
}
|
|
47
|
+
if (options.consentCookie) {
|
|
48
|
+
const pair = options.consentCookie.value === undefined ? null : `${options.consentCookie.name}=${options.consentCookie.value}`;
|
|
49
|
+
checks.push(`var k=document.cookie.split(/;\\s*/);if(!k.some(function(c){return ${pair === null ? `c.split("=")[0]===${inlineJson(options.consentCookie.name)}` : `c===${inlineJson(pair)}`}}))return;`);
|
|
24
50
|
}
|
|
25
|
-
|
|
26
|
-
return `(function(){if(${JSON.stringify(hosts)}.indexOf(location.hostname)===-1)return;var s=document.createElement("script");s.async=true;s.src="https://www.googletagmanager.com/gtag/js?id="+${id};document.head.appendChild(s);window.dataLayer=window.dataLayer||[];function gtag(){window.dataLayer.push(arguments);}window.gtag=gtag;gtag("js",new Date());gtag("config",${id});})();`;
|
|
51
|
+
return `(function(){${checks.join("")}var s=document.createElement("script");s.async=true;s.src="https://www.googletagmanager.com/gtag/js?id="+${id};document.head.appendChild(s);window.dataLayer=window.dataLayer||[];function gtag(){window.dataLayer.push(arguments);}window.gtag=gtag;gtag("js",new Date());gtag("config",${id});})();`;
|
|
27
52
|
}
|
|
28
53
|
//# sourceMappingURL=scripts.js.map
|
package/dist/scripts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scripts.js","sourceRoot":"","sources":["../src/scripts.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"scripts.js","sourceRoot":"","sources":["../src/scripts.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;SACzB,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC;SACxB,OAAO,CAAC,SAAS,EAAE,SAAS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AAwD,CAAC,CAAC;IACrF,IAAI,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,CAAC;QAC9B,MAAM,CAAC,IAAI,CACT,8BAA8B,UAAU,CAAC,OAAO,CAAC,SAAS,CAAC,mFAAmF,CAC/I,CAAC;IACJ,CAAC;IACD,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;QAC1B,MAAM,IAAI,GACR,OAAO,CAAC,aAAa,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,aAAa,CAAC,IAAI,IAAI,OAAO,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;QACpH,MAAM,CAAC,IAAI,CACT,sEAAsE,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,qBAAqB,UAAU,CAAC,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,UAAU,CAAC,IAAI,CAAC,EAAE,YAAY,CAC5L,CAAC;IACJ,CAAC;IACD,OAAO,eAAe,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,4GAA4G,EAAE,8KAA8K,EAAE,SAAS,CAAC;AAC/U,CAAC"}
|
package/dist/workers.d.ts
CHANGED
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
* that also runs in vitest, Node scripts and the client bundle.
|
|
4
4
|
*
|
|
5
5
|
* The module is imported through a variable specifier, so neither Vite nor
|
|
6
|
-
* vitest tries to resolve it, and only on first use. Outside workerd
|
|
7
|
-
* import fails and every helper here
|
|
8
|
-
* fall back to `process.env`, and
|
|
6
|
+
* vitest tries to resolve it, and only on first use. Outside workerd (Node,
|
|
7
|
+
* vitest in Node, the browser) the import fails and every helper here
|
|
8
|
+
* degrades: bindings are null, env reads fall back to `process.env`, and
|
|
9
|
+
* `afterResponse` awaits the work in place. Inside workerd, including
|
|
10
|
+
* `@cloudflare/vitest-pool-workers`, the real bindings are used.
|
|
9
11
|
*/
|
|
10
12
|
export interface WorkersModule {
|
|
11
13
|
env: Record<string, unknown>;
|
|
@@ -27,7 +29,7 @@ export declare function getEnvString(name: string): Promise<string | undefined>;
|
|
|
27
29
|
* workerd there is nobody to hand it to, so this awaits it instead.
|
|
28
30
|
*/
|
|
29
31
|
export declare function afterResponse(work: Promise<unknown>): Promise<void>;
|
|
30
|
-
/** True for
|
|
32
|
+
/** True for a KV namespace (it has `getWithMetadata`, which R2 buckets do not). Use as a `getBinding` guard. */
|
|
31
33
|
export declare function isKvNamespace(value: unknown): value is {
|
|
32
34
|
get(key: string): Promise<string | null>;
|
|
33
35
|
put(key: string, value: string, options?: {
|
package/dist/workers.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workers.d.ts","sourceRoot":"","sources":["../src/workers.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"workers.d.ts","sourceRoot":"","sources":["../src/workers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7B,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC;CACjD;AAWD,gEAAgE;AAChE,wBAAgB,WAAW,IAAI,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CAU3D;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,aAAa,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI,CAG5E;AAED,wEAAwE;AACxE,wBAAsB,UAAU,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,KAAK,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAU3G;AAED,wGAAwG;AACxG,wBAAsB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAO5E;AAED;;;GAGG;AACH,wBAAsB,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAazE;AAED,gHAAgH;AAChH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI;IACtD,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACzC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACtF,CAUA"}
|
package/dist/workers.js
CHANGED
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
* that also runs in vitest, Node scripts and the client bundle.
|
|
4
4
|
*
|
|
5
5
|
* The module is imported through a variable specifier, so neither Vite nor
|
|
6
|
-
* vitest tries to resolve it, and only on first use. Outside workerd
|
|
7
|
-
* import fails and every helper here
|
|
8
|
-
* fall back to `process.env`, and
|
|
6
|
+
* vitest tries to resolve it, and only on first use. Outside workerd (Node,
|
|
7
|
+
* vitest in Node, the browser) the import fails and every helper here
|
|
8
|
+
* degrades: bindings are null, env reads fall back to `process.env`, and
|
|
9
|
+
* `afterResponse` awaits the work in place. Inside workerd, including
|
|
10
|
+
* `@cloudflare/vitest-pool-workers`, the real bindings are used.
|
|
9
11
|
*/
|
|
10
12
|
const WORKERS_MODULE = "cloudflare:workers";
|
|
11
13
|
let modulePromise = null;
|
|
@@ -13,18 +15,11 @@ let override;
|
|
|
13
15
|
function processEnv() {
|
|
14
16
|
return globalThis.process?.env ?? {};
|
|
15
17
|
}
|
|
16
|
-
function isTestRuntime() {
|
|
17
|
-
const env = processEnv();
|
|
18
|
-
return Boolean(env.VITEST) || env.NODE_ENV === "test";
|
|
19
|
-
}
|
|
20
18
|
/** The `cloudflare:workers` module, or null outside workerd. */
|
|
21
19
|
export function loadWorkers() {
|
|
22
20
|
if (override !== undefined) {
|
|
23
21
|
return Promise.resolve(override);
|
|
24
22
|
}
|
|
25
|
-
if (isTestRuntime()) {
|
|
26
|
-
return Promise.resolve(null);
|
|
27
|
-
}
|
|
28
23
|
if (!modulePromise) {
|
|
29
24
|
modulePromise = import(/* @vite-ignore */ WORKERS_MODULE)
|
|
30
25
|
.then((mod) => mod)
|
|
@@ -71,14 +66,23 @@ export async function afterResponse(work) {
|
|
|
71
66
|
mod.waitUntil(work);
|
|
72
67
|
return;
|
|
73
68
|
}
|
|
74
|
-
|
|
69
|
+
// Same contract as waitUntil: a background failure is logged, never thrown
|
|
70
|
+
// into the request that started it.
|
|
71
|
+
try {
|
|
72
|
+
await work;
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
console.error("workers-start: background work failed", error);
|
|
76
|
+
}
|
|
75
77
|
}
|
|
76
|
-
/** True for
|
|
78
|
+
/** True for a KV namespace (it has `getWithMetadata`, which R2 buckets do not). Use as a `getBinding` guard. */
|
|
77
79
|
export function isKvNamespace(value) {
|
|
78
80
|
if (typeof value !== "object" || value === null) {
|
|
79
81
|
return false;
|
|
80
82
|
}
|
|
81
83
|
const candidate = value;
|
|
82
|
-
return typeof candidate.get === "function" &&
|
|
84
|
+
return (typeof candidate.get === "function" &&
|
|
85
|
+
typeof candidate.put === "function" &&
|
|
86
|
+
typeof candidate.getWithMetadata === "function");
|
|
83
87
|
}
|
|
84
88
|
//# sourceMappingURL=workers.js.map
|
package/dist/workers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workers.js","sourceRoot":"","sources":["../src/workers.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"workers.js","sourceRoot":"","sources":["../src/workers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAOH,MAAM,cAAc,GAAG,oBAAoB,CAAC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,MAAM,WAAW,GAAG,GAAG,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;IACnC,IAAI,OAAO,WAAW,KAAK,QAAQ,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC9D,OAAO,WAAW,CAAC;IACrB,CAAC;IACD,OAAO,UAAU,EAAE,CAAC,IAAI,CAAC,IAAI,SAAS,CAAC;AACzC,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,IAAsB;IACxD,MAAM,GAAG,GAAG,MAAM,WAAW,EAAE,CAAC;IAChC,IAAI,GAAG,EAAE,SAAS,EAAE,CAAC;QACnB,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QACpB,OAAO;IACT,CAAC;IACD,2EAA2E;IAC3E,oCAAoC;IACpC,IAAI,CAAC;QACH,MAAM,IAAI,CAAC;IACb,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,uCAAuC,EAAE,KAAK,CAAC,CAAC;IAChE,CAAC;AACH,CAAC;AAED,gHAAgH;AAChH,MAAM,UAAU,aAAa,CAAC,KAAc;IAI1C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAChD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,SAAS,GAAG,KAAoE,CAAC;IACvF,OAAO,CACL,OAAO,SAAS,CAAC,GAAG,KAAK,UAAU;QACnC,OAAO,SAAS,CAAC,GAAG,KAAK,UAAU;QACnC,OAAO,SAAS,CAAC,eAAe,KAAK,UAAU,CAChD,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "workers-start",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "The parts every TanStack Start app on Cloudflare Workers ends up writing: Markdown for agents on the same URL, a head helper that stops share cards leaking between pages, lazy Workers bindings, and a check that no local secret ships in the build.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Ryan Ghods",
|
|
@@ -23,29 +23,41 @@
|
|
|
23
23
|
"exports": {
|
|
24
24
|
".": {
|
|
25
25
|
"types": "./dist/index.d.ts",
|
|
26
|
-
"import": "./dist/index.js"
|
|
26
|
+
"import": "./dist/index.js",
|
|
27
|
+
"default": "./dist/index.js"
|
|
27
28
|
},
|
|
28
29
|
"./entry": {
|
|
29
30
|
"types": "./dist/entry.d.ts",
|
|
30
|
-
"import": "./dist/entry.js"
|
|
31
|
+
"import": "./dist/entry.js",
|
|
32
|
+
"default": "./dist/entry.js"
|
|
31
33
|
},
|
|
32
34
|
"./head": {
|
|
33
35
|
"types": "./dist/head.d.ts",
|
|
34
|
-
"import": "./dist/head.js"
|
|
36
|
+
"import": "./dist/head.js",
|
|
37
|
+
"default": "./dist/head.js"
|
|
35
38
|
},
|
|
36
39
|
"./workers": {
|
|
37
40
|
"types": "./dist/workers.d.ts",
|
|
38
|
-
"import": "./dist/workers.js"
|
|
41
|
+
"import": "./dist/workers.js",
|
|
42
|
+
"default": "./dist/workers.js"
|
|
39
43
|
},
|
|
40
44
|
"./scripts": {
|
|
41
45
|
"types": "./dist/scripts.d.ts",
|
|
42
|
-
"import": "./dist/scripts.js"
|
|
46
|
+
"import": "./dist/scripts.js",
|
|
47
|
+
"default": "./dist/scripts.js"
|
|
43
48
|
},
|
|
44
49
|
"./check-bundle": {
|
|
45
50
|
"types": "./dist/check-bundle.d.ts",
|
|
46
|
-
"import": "./dist/check-bundle.js"
|
|
51
|
+
"import": "./dist/check-bundle.js",
|
|
52
|
+
"default": "./dist/check-bundle.js"
|
|
47
53
|
},
|
|
48
|
-
"./biome": "./biome.preset.json"
|
|
54
|
+
"./biome": "./biome.preset.json",
|
|
55
|
+
"./accept": {
|
|
56
|
+
"types": "./dist/accept.d.ts",
|
|
57
|
+
"import": "./dist/accept.js",
|
|
58
|
+
"default": "./dist/accept.js"
|
|
59
|
+
},
|
|
60
|
+
"./package.json": "./package.json"
|
|
49
61
|
},
|
|
50
62
|
"bin": {
|
|
51
63
|
"workers-start-check-bundle": "dist/check-bundle-cli.js"
|
|
@@ -59,7 +71,7 @@
|
|
|
59
71
|
"LICENSE"
|
|
60
72
|
],
|
|
61
73
|
"engines": {
|
|
62
|
-
"node": ">=
|
|
74
|
+
"node": ">=22"
|
|
63
75
|
},
|
|
64
76
|
"scripts": {
|
|
65
77
|
"build": "rm -rf dist && tsc -p tsconfig.build.json && chmod +x dist/check-bundle-cli.js",
|
package/src/accept.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Accept header parsing with q-values, per RFC 9110 section 12.5.1.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export interface MediaRange {
|
|
6
|
+
type: string;
|
|
7
|
+
subtype: string;
|
|
8
|
+
q: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Media ranges from an Accept header, lowercased. An empty or missing header means `*\/*`. */
|
|
12
|
+
export function parseAccept(header: string | null | undefined): MediaRange[] {
|
|
13
|
+
if (!header?.trim()) {
|
|
14
|
+
return [{ type: "*", subtype: "*", q: 1 }];
|
|
15
|
+
}
|
|
16
|
+
const ranges: MediaRange[] = [];
|
|
17
|
+
for (const part of header.split(",")) {
|
|
18
|
+
const [range = "", ...params] = part.split(";").map((s) => s.trim());
|
|
19
|
+
const [type, subtype] = range.toLowerCase().split("/");
|
|
20
|
+
if (!(type && subtype)) {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
let q = 1;
|
|
24
|
+
for (const param of params) {
|
|
25
|
+
const [key, value] = param.split("=").map((s) => s.trim());
|
|
26
|
+
if (key?.toLowerCase() === "q" && value !== undefined) {
|
|
27
|
+
const parsed = Number(value);
|
|
28
|
+
q = Number.isFinite(parsed) ? Math.min(Math.max(parsed, 0), 1) : 0;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
ranges.push({ type, subtype, q });
|
|
32
|
+
}
|
|
33
|
+
return ranges;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The quality a client gives `mediaType`, from the most specific range that
|
|
38
|
+
* matches it. 0 when nothing matches or the match says q=0.
|
|
39
|
+
*/
|
|
40
|
+
export function quality(
|
|
41
|
+
ranges: readonly MediaRange[],
|
|
42
|
+
mediaType: string,
|
|
43
|
+
options: { exactOnly?: boolean } = {},
|
|
44
|
+
): number {
|
|
45
|
+
const [type, subtype] = mediaType.toLowerCase().split("/");
|
|
46
|
+
let best = -1;
|
|
47
|
+
let q = 0;
|
|
48
|
+
for (const range of ranges) {
|
|
49
|
+
let specificity = -1;
|
|
50
|
+
if (range.type === type && range.subtype === subtype) {
|
|
51
|
+
specificity = 2;
|
|
52
|
+
} else if (!options.exactOnly && range.type === type && range.subtype === "*") {
|
|
53
|
+
specificity = 1;
|
|
54
|
+
} else if (!options.exactOnly && range.type === "*" && range.subtype === "*") {
|
|
55
|
+
specificity = 0;
|
|
56
|
+
}
|
|
57
|
+
if (specificity > best) {
|
|
58
|
+
best = specificity;
|
|
59
|
+
q = range.q;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return q;
|
|
63
|
+
}
|