@dirwell/share-image 0.0.0-stage → 0.0.1-alpha

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Dirwell contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,23 @@
1
- # Temporary Holding Version
1
+ # @dirwell/share-image
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Optional build-time metadata and 1200 × 630 PNG images. Install this package only when share metadata or image rendering is needed. Core, Plain and the rich themes do not depend on it.
4
+
5
+ ```js
6
+ import { generateExplorer } from "@dirwell/core";
7
+ import { createPlainTheme } from "@dirwell/theme-plain";
8
+ import { createMetadataProvider } from "@dirwell/share-image";
9
+
10
+ await generateExplorer({
11
+ sourceDir: "files",
12
+ outputDir: "public/downloads",
13
+ theme: createPlainTheme(),
14
+ metadata: createMetadataProvider(
15
+ { siteName: "Sample downloads", siteUrl: "https://example.com/downloads/" },
16
+ { siteName: "Sample downloads", repositoryName: "example/files", imageTheme: "plain" },
17
+ ),
18
+ });
19
+ ```
20
+
21
+ Omit `imageTheme` for text-only metadata. `image: false` disables any preset; a local File/path/file URL or async callback supplies a custom image. `createShareImage({ theme, title, description })` returns a PNG File. Rendering is lazy, uses bundled Adobe fonts without network/system-font lookup, and retains at most 32 rendered PNGs per process. The existing renderer requires bundled glyph coverage; unsupported text fails instead of silently emitting missing glyphs. Use a custom renderer for other scripts. Per-build image loading is deduplicated; image output paths are validated and conflicting bytes are rejected.
22
+
23
+ This is a static-build provider. No server image route or runtime image service is implied. All packages remain private until publication setup is completed.
@@ -0,0 +1,3 @@
1
+ # Third-party notices
2
+
3
+ The bundled Adobe Source Sans 3 and Source Serif 4 fonts use the SIL Open Font License 1.1. Their complete copyright and license files are included under `dist/fonts/`. The renderer uses installed fontkit (MIT) and resvg-js (MPL-2.0); their packages include license notices.
@@ -0,0 +1,46 @@
1
+ [
2
+ {
3
+ "repo": "https://github.com/adobe-fonts/source-sans",
4
+ "sha": "87b37a2daaed80fcb8e8ccb0085c4d72ddade12e",
5
+ "path": "OTF/SourceSans3-Regular.otf",
6
+ "file": "SourceSans3-Regular.otf",
7
+ "bytes": 334924,
8
+ "sha256": "08df266400933d3178d081a45f94a08814c3e55b4b7dd2e0ff69cb1329f13ab6"
9
+ },
10
+ {
11
+ "repo": "https://github.com/adobe-fonts/source-sans",
12
+ "sha": "87b37a2daaed80fcb8e8ccb0085c4d72ddade12e",
13
+ "path": "OTF/SourceSans3-Light.otf",
14
+ "file": "SourceSans3-Light.otf",
15
+ "bytes": 327396,
16
+ "sha256": "bbfab2c58d46defe8a194634744660ee15d560dcf3d7a8c7bb509936acc618c7"
17
+ },
18
+ {
19
+ "repo": "https://github.com/adobe-fonts/source-sans",
20
+ "sha": "87b37a2daaed80fcb8e8ccb0085c4d72ddade12e",
21
+ "path": "LICENSE.md",
22
+ "file": "source-sans-LICENSE.md",
23
+ "bytes": 4480,
24
+ "sha256": "3d78cfa3c4c179a49cbfe4b7603f9683b58d41c3e29f85b5ee9a480e2a057165",
25
+ "upstreamSha256": "56af9b9c6715597e458284a474dc118a50a4150e9d547c70f7b4a33c3e6a9328",
26
+ "transformation": "License line endings normalized to LF; license text unchanged"
27
+ },
28
+ {
29
+ "repo": "https://github.com/adobe-fonts/source-serif",
30
+ "sha": "80d3f8894c09c937bebfa9011247d2e1c79fd6f4",
31
+ "path": "OTF/SourceSerif4-Regular.otf",
32
+ "file": "SourceSerif4-Regular.otf",
33
+ "bytes": 241392,
34
+ "sha256": "edf160d0d584deee8a3bb2c3371b2a7624ca63580fbe02c57c1f4c91e84d8787"
35
+ },
36
+ {
37
+ "repo": "https://github.com/adobe-fonts/source-serif",
38
+ "sha": "80d3f8894c09c937bebfa9011247d2e1c79fd6f4",
39
+ "path": "LICENSE.md",
40
+ "file": "source-serif-LICENSE.md",
41
+ "bytes": 4486,
42
+ "sha256": "58d616db06d9f0540735051efb49b5b3b77c9c0f2f2a37a6b1bf72bd241fec80",
43
+ "upstreamSha256": "c21d7293d87b6d7ab1d0229a2f55b77f33a7613a6a4e66f6693d68d7d8d09464",
44
+ "transformation": "License line endings normalized to LF; license text unchanged"
45
+ }
46
+ ]
Binary file
@@ -0,0 +1,93 @@
1
+ Copyright 2010-2024 Adobe (http://www.adobe.com/), with Reserved Font Name 'Source'. All Rights Reserved. Source is a trademark of Adobe in the United States and/or other countries.
2
+
3
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
4
+
5
+ This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL
6
+
7
+ ---
8
+
9
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
10
+ -----------------------------------------------------------
11
+
12
+ PREAMBLE
13
+ The goals of the Open Font License (OFL) are to stimulate worldwide
14
+ development of collaborative font projects, to support the font creation
15
+ efforts of academic and linguistic communities, and to provide a free and
16
+ open framework in which fonts may be shared and improved in partnership
17
+ with others.
18
+
19
+ The OFL allows the licensed fonts to be used, studied, modified and
20
+ redistributed freely as long as they are not sold by themselves. The
21
+ fonts, including any derivative works, can be bundled, embedded,
22
+ redistributed and/or sold with any software provided that any reserved
23
+ names are not used by derivative works. The fonts and derivatives,
24
+ however, cannot be released under any other type of license. The
25
+ requirement for fonts to remain under this license does not apply
26
+ to any document created using the fonts or their derivatives.
27
+
28
+ DEFINITIONS
29
+ "Font Software" refers to the set of files released by the Copyright
30
+ Holder(s) under this license and clearly marked as such. This may
31
+ include source files, build scripts and documentation.
32
+
33
+ "Reserved Font Name" refers to any names specified as such after the
34
+ copyright statement(s).
35
+
36
+ "Original Version" refers to the collection of Font Software components as
37
+ distributed by the Copyright Holder(s).
38
+
39
+ "Modified Version" refers to any derivative made by adding to, deleting,
40
+ or substituting -- in part or in whole -- any of the components of the
41
+ Original Version, by changing formats or by porting the Font Software to a
42
+ new environment.
43
+
44
+ "Author" refers to any designer, engineer, programmer, technical
45
+ writer or other person who contributed to the Font Software.
46
+
47
+ PERMISSION & CONDITIONS
48
+ Permission is hereby granted, free of charge, to any person obtaining
49
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
50
+ redistribute, and sell modified and unmodified copies of the Font
51
+ Software, subject to the following conditions:
52
+
53
+ 1. Neither the Font Software nor any of its individual components,
54
+ in Original or Modified Versions, may be sold by itself.
55
+
56
+ 2. Original or Modified Versions of the Font Software may be bundled,
57
+ redistributed and/or sold with any software, provided that each copy
58
+ contains the above copyright notice and this license. These can be
59
+ included either as stand-alone text files, human-readable headers or
60
+ in the appropriate machine-readable metadata fields within text or
61
+ binary files as long as those fields can be easily viewed by the user.
62
+
63
+ 3. No Modified Version of the Font Software may use the Reserved Font
64
+ Name(s) unless explicit written permission is granted by the corresponding
65
+ Copyright Holder. This restriction only applies to the primary font name as
66
+ presented to the users.
67
+
68
+ 4. The name(s) of the Copyright Holder(s) or the Author(s) of the Font
69
+ Software shall not be used to promote, endorse or advertise any
70
+ Modified Version, except to acknowledge the contribution(s) of the
71
+ Copyright Holder(s) and the Author(s) or with their explicit written
72
+ permission.
73
+
74
+ 5. The Font Software, modified or unmodified, in part or in whole,
75
+ must be distributed entirely under this license, and must not be
76
+ distributed under any other license. The requirement for fonts to
77
+ remain under this license does not apply to any document created
78
+ using the Font Software.
79
+
80
+ TERMINATION
81
+ This license becomes null and void if any of the above conditions are
82
+ not met.
83
+
84
+ DISCLAIMER
85
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
86
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
87
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
88
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
89
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
90
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
91
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
92
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
93
+ OTHER DEALINGS IN THE FONT SOFTWARE.
@@ -0,0 +1,93 @@
1
+ Copyright 2014 - 2023 Adobe (http://www.adobe.com/), with Reserved Font Name ‘Source’. All Rights Reserved. Source is a trademark of Adobe in the United States and/or other countries.
2
+
3
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
4
+
5
+ This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL
6
+
7
+ ---
8
+
9
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
10
+ -----------------------------------------------------------
11
+
12
+ PREAMBLE
13
+ The goals of the Open Font License (OFL) are to stimulate worldwide
14
+ development of collaborative font projects, to support the font creation
15
+ efforts of academic and linguistic communities, and to provide a free and
16
+ open framework in which fonts may be shared and improved in partnership
17
+ with others.
18
+
19
+ The OFL allows the licensed fonts to be used, studied, modified and
20
+ redistributed freely as long as they are not sold by themselves. The
21
+ fonts, including any derivative works, can be bundled, embedded,
22
+ redistributed and/or sold with any software provided that any reserved
23
+ names are not used by derivative works. The fonts and derivatives,
24
+ however, cannot be released under any other type of license. The
25
+ requirement for fonts to remain under this license does not apply
26
+ to any document created using the fonts or their derivatives.
27
+
28
+ DEFINITIONS
29
+ "Font Software" refers to the set of files released by the Copyright
30
+ Holder(s) under this license and clearly marked as such. This may
31
+ include source files, build scripts and documentation.
32
+
33
+ "Reserved Font Name" refers to any names specified as such after the
34
+ copyright statement(s).
35
+
36
+ "Original Version" refers to the collection of Font Software components as
37
+ distributed by the Copyright Holder(s).
38
+
39
+ "Modified Version" refers to any derivative made by adding to, deleting,
40
+ or substituting -- in part or in whole -- any of the components of the
41
+ Original Version, by changing formats or by porting the Font Software to a
42
+ new environment.
43
+
44
+ "Author" refers to any designer, engineer, programmer, technical
45
+ writer or other person who contributed to the Font Software.
46
+
47
+ PERMISSION & CONDITIONS
48
+ Permission is hereby granted, free of charge, to any person obtaining
49
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
50
+ redistribute, and sell modified and unmodified copies of the Font
51
+ Software, subject to the following conditions:
52
+
53
+ 1. Neither the Font Software nor any of its individual components,
54
+ in Original or Modified Versions, may be sold by itself.
55
+
56
+ 2. Original or Modified Versions of the Font Software may be bundled,
57
+ redistributed and/or sold with any software, provided that each copy
58
+ contains the above copyright notice and this license. These can be
59
+ included either as stand-alone text files, human-readable headers or
60
+ in the appropriate machine-readable metadata fields within text or
61
+ binary files as long as those fields can be easily viewed by the user.
62
+
63
+ 3. No Modified Version of the Font Software may use the Reserved Font
64
+ Name(s) unless explicit written permission is granted by the corresponding
65
+ Copyright Holder. This restriction only applies to the primary font name as
66
+ presented to the users.
67
+
68
+ 4. The name(s) of the Copyright Holder(s) or the Author(s) of the Font
69
+ Software shall not be used to promote, endorse or advertise any
70
+ Modified Version, except to acknowledge the contribution(s) of the
71
+ Copyright Holder(s) and the Author(s) or with their explicit written
72
+ permission.
73
+
74
+ 5. The Font Software, modified or unmodified, in part or in whole,
75
+ must be distributed entirely under this license, and must not be
76
+ distributed under any other license. The requirement for fonts to
77
+ remain under this license does not apply to any document created
78
+ using the Font Software.
79
+
80
+ TERMINATION
81
+ This license becomes null and void if any of the above conditions are
82
+ not met.
83
+
84
+ DISCLAIMER
85
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
86
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
87
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
88
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
89
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
90
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
91
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
92
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
93
+ OTHER DEALINGS IN THE FONT SOFTWARE.
@@ -0,0 +1,30 @@
1
+ import { ContentCounts, DirectoryData, MetadataOptions, MetadataProviderFactory, PageMetadata, ThemeMetadataDefaults } from "@dirwell/core";
2
+ //#region src/share-image.d.ts
3
+ interface ShareImageOptions {
4
+ readonly theme?: "ledger" | "plain" | "crosswave";
5
+ readonly title: string;
6
+ readonly description: string;
7
+ readonly repositoryName?: string;
8
+ readonly directoryPath?: string;
9
+ }
10
+ //#endregion
11
+ //#region src/share-image-api.d.ts
12
+ /** Render a PNG at build time using the selected built-in theme and bundled fonts. */
13
+ export declare function createShareImage(options: ShareImageOptions): Promise<File>;
14
+ //#endregion
15
+ //#region src/metadata.d.ts
16
+ export declare function countEntries(directory: DirectoryData): ContentCounts;
17
+ export declare function countKinds(kinds: Iterable<string>): ContentCounts;
18
+ export declare function describeContent(counts: ContentCounts): string;
19
+ export declare function repositoryName(repositoryUrl: string): string;
20
+ export declare function createMetadataResolver(options: MetadataOptions, defaults: ThemeMetadataDefaults, counts: ContentCounts, sourceDirectory: string): {
21
+ assets: Map<string, Uint8Array<ArrayBufferLike>>;
22
+ resolve(directory: DirectoryData, hrefForOutput: (outputPath: string) => string, pagePath: string): Promise<PageMetadata>;
23
+ };
24
+ //#endregion
25
+ //#region src/index.d.ts
26
+ /** Opt-in build metadata. PNG presets are generated only when defaults.imageTheme is supplied. */
27
+ export declare function createMetadataProvider(options: MetadataOptions, defaults: ThemeMetadataDefaults, sourceDirectory?: string): MetadataProviderFactory;
28
+ //#endregion
29
+ export type { ShareImageOptions };
30
+ //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs ADDED
@@ -0,0 +1,176 @@
1
+ import { t as createShareImage } from "./share-image-api-DcmMcWT0.mjs";
2
+ import { escapeHtml } from "@dirwell/core";
3
+ import { createHash } from "node:crypto";
4
+ import { readFile } from "node:fs/promises";
5
+ import path from "node:path";
6
+ import { fileURLToPath } from "node:url";
7
+ //#region src/metadata.ts
8
+ function countEntries(directory) {
9
+ return countKinds(directory.entries.map((entry) => entry.kind));
10
+ }
11
+ function countKinds(kinds) {
12
+ let folderCount = 0, fileCount = 0, linkCount = 0;
13
+ for (const kind of kinds) if (kind === "directory") folderCount++;
14
+ else if (kind === "file") fileCount++;
15
+ else if (kind === "symlink") linkCount++;
16
+ return {
17
+ folderCount,
18
+ fileCount,
19
+ linkCount
20
+ };
21
+ }
22
+ function describeContent(counts) {
23
+ const parts = [];
24
+ for (const [count, noun] of [
25
+ [counts.folderCount, "folder"],
26
+ [counts.fileCount, "file"],
27
+ [counts.linkCount, "link"]
28
+ ]) if (count > 0) parts.push(`${count} ${noun}${count === 1 ? "" : "s"}`);
29
+ return parts.join(" · ") || "Empty folder";
30
+ }
31
+ function repositoryName(repositoryUrl) {
32
+ try {
33
+ return new URL(repositoryUrl).pathname.replace(/^\/+|\/+$/g, "").replace(/\.git$/, "");
34
+ } catch {
35
+ return repositoryUrl;
36
+ }
37
+ }
38
+ function stringValue(value, label) {
39
+ if (typeof value !== "string") throw new TypeError(`${label} must resolve to a string`);
40
+ return value;
41
+ }
42
+ function safeOutputPath(value) {
43
+ if (!value || value.includes("\\") || value.includes("\0") || value.startsWith("/") || /^[a-z]:/i.test(value) || value.split("/").some((part) => !part || part === "." || part === "..")) throw new Error(`Unsafe metadata image outputPath: ${value}`);
44
+ if (value.startsWith("__dirwell/") && !value.startsWith("__dirwell/metadata/")) throw new Error("Metadata image cannot overwrite reserved Dirwell assets");
45
+ return value;
46
+ }
47
+ function deployedRoot(value) {
48
+ if (value === void 0) return void 0;
49
+ const url = new URL(value);
50
+ if (!["http:", "https:"].includes(url.protocol) || url.search || url.hash || url.username || url.password) throw new Error("metadata.siteUrl must be an HTTP(S) explorer root without credentials, query, or fragment");
51
+ if (!url.pathname.endsWith("/")) url.pathname += "/";
52
+ return url;
53
+ }
54
+ function createMetadataResolver(options, defaults, counts, sourceDirectory) {
55
+ const site = Object.freeze({
56
+ ...counts,
57
+ name: stringValue(options.siteName ?? defaults.siteName, "metadata.siteName"),
58
+ repositoryName: stringValue(options.repositoryName ?? defaults.repositoryName, "metadata.repositoryName")
59
+ });
60
+ const siteUrl = deployedRoot(options.siteUrl);
61
+ const presetTitle = typeof options.title === "string" ? options.title : site.name;
62
+ const presetDescription = typeof options.description === "string" ? options.description : `Archive totals: ${describeContent(site)}`;
63
+ const assets = /* @__PURE__ */ new Map();
64
+ let defaultImage;
65
+ const fileSources = /* @__PURE__ */ new WeakMap();
66
+ const pathSources = /* @__PURE__ */ new Map();
67
+ const loaded = async (bytes, filename) => {
68
+ const extension = path.extname(filename).toLowerCase();
69
+ if (![
70
+ ".png",
71
+ ".jpg",
72
+ ".jpeg",
73
+ ".webp",
74
+ ".gif"
75
+ ].includes(extension)) throw new Error("Metadata images must be PNG, JPEG, WebP, or GIF files");
76
+ return {
77
+ bytes,
78
+ extension,
79
+ digest: createHash("sha256").update(bytes).digest("hex")
80
+ };
81
+ };
82
+ function loadImage(source) {
83
+ if (source instanceof File) {
84
+ let image = fileSources.get(source);
85
+ if (image === void 0) {
86
+ image = source.arrayBuffer().then((buffer) => loaded(new Uint8Array(buffer), source.name));
87
+ fileSources.set(source, image);
88
+ }
89
+ return image;
90
+ }
91
+ if (typeof source !== "string" && !(source instanceof URL)) throw new TypeError("metadata.image.source must be a File, local path, or file URL");
92
+ if (source instanceof URL && source.protocol !== "file:") throw new Error("metadata.image source URLs must use file:");
93
+ const input = source instanceof URL ? fileURLToPath(source) : path.resolve(sourceDirectory, source);
94
+ let image = pathSources.get(input);
95
+ if (image === void 0) {
96
+ image = readFile(input).then((bytes) => loaded(bytes, path.basename(input)));
97
+ pathSources.set(input, image);
98
+ }
99
+ return image;
100
+ }
101
+ async function imageFor(context) {
102
+ const configured = options.image === void 0 ? defaults.image : options.image;
103
+ const isPreset = configured === void 0 && defaults.imageTheme !== void 0;
104
+ let image = typeof configured === "function" ? await configured(context) : configured;
105
+ if (image === false) return null;
106
+ if (configured === void 0) {
107
+ const preset = defaults.imageTheme;
108
+ if (preset === void 0) return null;
109
+ defaultImage ??= import("./share-image-api-BZH7001a.mjs").then(({ createShareImage }) => createShareImage({
110
+ theme: preset,
111
+ repositoryName: site.repositoryName,
112
+ title: presetTitle,
113
+ description: presetDescription
114
+ }));
115
+ image = await defaultImage;
116
+ }
117
+ if (image === void 0) throw new TypeError("metadata.image callback must return an image or false");
118
+ const config = image instanceof File || typeof image === "string" || image instanceof URL ? { source: image } : image;
119
+ if (!config || typeof config !== "object") throw new TypeError("metadata.image must resolve to a File, local path, file URL, or source object");
120
+ const { bytes, extension, digest } = await loadImage(config.source);
121
+ const outputPath = safeOutputPath(config.outputPath ?? `__dirwell/metadata/${digest}${extension}`);
122
+ const existing = assets.get(outputPath);
123
+ if (existing !== void 0 && existing !== bytes && !Buffer.from(existing).equals(bytes)) throw new Error(`Conflicting metadata image outputPath: ${outputPath}`);
124
+ assets.set(outputPath, bytes);
125
+ return {
126
+ outputPath,
127
+ alt: stringValue(config.alt ?? (isPreset ? `${presetTitle}. ${presetDescription}` : context.title), "metadata.image.alt")
128
+ };
129
+ }
130
+ return {
131
+ assets,
132
+ async resolve(directory, hrefForOutput, pagePath) {
133
+ const relativePath = directory.current.relativePath;
134
+ const context = Object.freeze({
135
+ site,
136
+ directory: Object.freeze({
137
+ ...countEntries(directory),
138
+ relativePath,
139
+ name: directory.current.name
140
+ })
141
+ });
142
+ const title = stringValue(typeof options.title === "function" ? await options.title(context) : options.title ?? (relativePath ? `${relativePath} · ${site.name}` : site.name), "metadata.title");
143
+ const description = stringValue(typeof options.description === "function" ? await options.description(context) : options.description ?? (relativePath ? `Browse ${relativePath} in ${site.name}. This folder: ${describeContent(context.directory)}.` : `Browse files in ${site.name}. Archive totals: ${describeContent(site)}.`), "metadata.description");
144
+ const image = await imageFor(Object.freeze({
145
+ ...context,
146
+ title,
147
+ description
148
+ }));
149
+ const meta = (key, value, property = false) => `<meta data-dirwell-metadata ${property ? "property" : "name"}="${key}" content="${escapeHtml(value)}">`;
150
+ let head = `<title>${escapeHtml(title)}</title>${meta("description", description)}${meta("og:title", title, true)}${meta("og:description", description, true)}${meta("og:type", "website", true)}`;
151
+ if (siteUrl) {
152
+ const canonical = new URL(pagePath.split("/").map(encodeURIComponent).join("/"), siteUrl).href;
153
+ head += `${meta("og:url", canonical, true)}<link data-dirwell-metadata rel="canonical" href="${escapeHtml(canonical)}">`;
154
+ }
155
+ if (image) {
156
+ const href = siteUrl ? new URL(image.outputPath.split("/").map(encodeURIComponent).join("/"), siteUrl).href : hrefForOutput(image.outputPath);
157
+ head += meta("og:image", href, true) + meta("og:image:alt", image.alt, true) + meta("twitter:card", "summary_large_image") + meta("twitter:title", title) + meta("twitter:description", description) + meta("twitter:image", href) + meta("twitter:image:alt", image.alt);
158
+ }
159
+ return {
160
+ title,
161
+ description,
162
+ head
163
+ };
164
+ }
165
+ };
166
+ }
167
+ //#endregion
168
+ //#region src/index.ts
169
+ /** Opt-in build metadata. PNG presets are generated only when defaults.imageTheme is supplied. */
170
+ function createMetadataProvider(options, defaults, sourceDirectory = process.cwd()) {
171
+ return ({ sourceKinds }) => createMetadataResolver(options, defaults, countKinds(sourceKinds.values()), sourceDirectory);
172
+ }
173
+ //#endregion
174
+ export { countEntries, countKinds, createMetadataProvider, createMetadataResolver, createShareImage, describeContent, repositoryName };
175
+
176
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/metadata.ts","../src/index.ts"],"sourcesContent":["import { escapeHtml } from \"@dirwell/core\";\nimport { createHash } from \"node:crypto\";\nimport { readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport type { DirectoryData } from \"@dirwell/core\";\n\nimport type {\n ContentCounts,\n MetadataContext,\n ImageSource,\n MetadataImage,\n ResolvedMetadataContext,\n MetadataOptions,\n ThemeMetadataDefaults,\n PageMetadata,\n} from \"@dirwell/core\";\nexport type {\n ContentCounts,\n MetadataContext,\n MetadataValue,\n ImageSource,\n MetadataImage,\n ResolvedMetadataContext,\n MetadataImageValue,\n MetadataOptions,\n ThemeMetadataDefaults,\n PageMetadata,\n} from \"@dirwell/core\";\nexport function countEntries(directory: DirectoryData): ContentCounts {\n return countKinds(directory.entries.map((entry) => entry.kind));\n}\nexport function countKinds(kinds: Iterable<string>): ContentCounts {\n let folderCount = 0,\n fileCount = 0,\n linkCount = 0;\n for (const kind of kinds) {\n if (kind === \"directory\") folderCount++;\n else if (kind === \"file\") fileCount++;\n else if (kind === \"symlink\") linkCount++;\n }\n return { folderCount, fileCount, linkCount };\n}\nexport function describeContent(counts: ContentCounts): string {\n const parts: string[] = [];\n for (const [count, noun] of [\n [counts.folderCount, \"folder\"],\n [counts.fileCount, \"file\"],\n [counts.linkCount, \"link\"],\n ] as const) {\n if (count > 0) parts.push(`${count} ${noun}${count === 1 ? \"\" : \"s\"}`);\n }\n return parts.join(\" · \") || \"Empty folder\";\n}\nexport function repositoryName(repositoryUrl: string): string {\n try {\n return new URL(repositoryUrl).pathname.replace(/^\\/+|\\/+$/g, \"\").replace(/\\.git$/, \"\");\n } catch {\n return repositoryUrl;\n }\n}\n\nfunction stringValue(value: unknown, label: string): string {\n if (typeof value !== \"string\") throw new TypeError(`${label} must resolve to a string`);\n return value;\n}\nfunction safeOutputPath(value: string): string {\n if (\n !value ||\n value.includes(\"\\\\\") ||\n value.includes(\"\\0\") ||\n value.startsWith(\"/\") ||\n /^[a-z]:/i.test(value) ||\n value.split(\"/\").some((part) => !part || part === \".\" || part === \"..\")\n )\n throw new Error(`Unsafe metadata image outputPath: ${value}`);\n if (value.startsWith(\"__dirwell/\") && !value.startsWith(\"__dirwell/metadata/\"))\n throw new Error(\"Metadata image cannot overwrite reserved Dirwell assets\");\n return value;\n}\nfunction deployedRoot(value: string | undefined): URL | undefined {\n if (value === undefined) return undefined;\n const url = new URL(value);\n if (\n ![\"http:\", \"https:\"].includes(url.protocol) ||\n url.search ||\n url.hash ||\n url.username ||\n url.password\n )\n throw new Error(\n \"metadata.siteUrl must be an HTTP(S) explorer root without credentials, query, or fragment\",\n );\n if (!url.pathname.endsWith(\"/\")) url.pathname += \"/\";\n return url;\n}\nexport function createMetadataResolver(\n options: MetadataOptions,\n defaults: ThemeMetadataDefaults,\n counts: ContentCounts,\n sourceDirectory: string,\n) {\n const site = Object.freeze({\n ...counts,\n name: stringValue(options.siteName ?? defaults.siteName, \"metadata.siteName\"),\n repositoryName: stringValue(\n options.repositoryName ?? defaults.repositoryName,\n \"metadata.repositoryName\",\n ),\n });\n const siteUrl = deployedRoot(options.siteUrl);\n const presetTitle = typeof options.title === \"string\" ? options.title : site.name;\n const presetDescription =\n typeof options.description === \"string\"\n ? options.description\n : `Archive totals: ${describeContent(site)}`;\n const assets = new Map<string, Uint8Array>();\n let defaultImage: Promise<File> | undefined;\n // One source snapshot per build: fixed images should not reread or rehash per page.\n const fileSources = new WeakMap<\n File,\n Promise<{ bytes: Uint8Array; extension: string; digest: string }>\n >();\n const pathSources = new Map<\n string,\n Promise<{ bytes: Uint8Array; extension: string; digest: string }>\n >();\n const loaded = async (bytes: Uint8Array, filename: string) => {\n const extension = path.extname(filename).toLowerCase();\n if (![\".png\", \".jpg\", \".jpeg\", \".webp\", \".gif\"].includes(extension))\n throw new Error(\"Metadata images must be PNG, JPEG, WebP, or GIF files\");\n return { bytes, extension, digest: createHash(\"sha256\").update(bytes).digest(\"hex\") };\n };\n function loadImage(source: ImageSource) {\n if (source instanceof File) {\n let image = fileSources.get(source);\n if (image === undefined) {\n image = source.arrayBuffer().then((buffer) => loaded(new Uint8Array(buffer), source.name));\n fileSources.set(source, image);\n }\n return image;\n }\n if (typeof source !== \"string\" && !(source instanceof URL))\n throw new TypeError(\"metadata.image.source must be a File, local path, or file URL\");\n if (source instanceof URL && source.protocol !== \"file:\")\n throw new Error(\"metadata.image source URLs must use file:\");\n const input =\n source instanceof URL ? fileURLToPath(source) : path.resolve(sourceDirectory, source);\n let image = pathSources.get(input);\n if (image === undefined) {\n image = readFile(input).then((bytes) => loaded(bytes, path.basename(input)));\n pathSources.set(input, image);\n }\n return image;\n }\n\n async function imageFor(\n context: ResolvedMetadataContext,\n ): Promise<{ outputPath: string; alt: string } | null> {\n const configured = options.image === undefined ? defaults.image : options.image;\n const isPreset = configured === undefined && defaults.imageTheme !== undefined;\n let image = typeof configured === \"function\" ? await configured(context) : configured;\n if (image === false) return null;\n if (configured === undefined) {\n const preset = defaults.imageTheme;\n if (preset === undefined) return null;\n defaultImage ??= import(\"./share-image-api.ts\").then(({ createShareImage }) =>\n createShareImage({\n theme: preset,\n repositoryName: site.repositoryName,\n title: presetTitle,\n description: presetDescription,\n }),\n );\n image = await defaultImage;\n }\n if (image === undefined)\n throw new TypeError(\"metadata.image callback must return an image or false\");\n const config: MetadataImage =\n image instanceof File || typeof image === \"string\" || image instanceof URL\n ? { source: image }\n : image;\n if (!config || typeof config !== \"object\")\n throw new TypeError(\n \"metadata.image must resolve to a File, local path, file URL, or source object\",\n );\n const { bytes, extension, digest } = await loadImage(config.source);\n const outputPath = safeOutputPath(\n config.outputPath ?? `__dirwell/metadata/${digest}${extension}`,\n );\n const existing = assets.get(outputPath);\n if (existing !== undefined && existing !== bytes && !Buffer.from(existing).equals(bytes))\n throw new Error(`Conflicting metadata image outputPath: ${outputPath}`);\n assets.set(outputPath, bytes);\n return {\n outputPath,\n alt: stringValue(\n config.alt ?? (isPreset ? `${presetTitle}. ${presetDescription}` : context.title),\n \"metadata.image.alt\",\n ),\n };\n }\n return {\n assets,\n async resolve(\n directory: DirectoryData,\n hrefForOutput: (outputPath: string) => string,\n pagePath: string,\n ): Promise<PageMetadata> {\n const relativePath = directory.current.relativePath;\n const context: MetadataContext = Object.freeze({\n site,\n directory: Object.freeze({\n ...countEntries(directory),\n relativePath,\n name: directory.current.name,\n }),\n });\n const title = stringValue(\n typeof options.title === \"function\"\n ? await options.title(context)\n : (options.title ?? (relativePath ? `${relativePath} · ${site.name}` : site.name)),\n \"metadata.title\",\n );\n const description = stringValue(\n typeof options.description === \"function\"\n ? await options.description(context)\n : (options.description ??\n (relativePath\n ? `Browse ${relativePath} in ${site.name}. This folder: ${describeContent(context.directory)}.`\n : `Browse files in ${site.name}. Archive totals: ${describeContent(site)}.`)),\n \"metadata.description\",\n );\n const image = await imageFor(Object.freeze({ ...context, title, description }));\n const meta = (key: string, value: string, property = false) =>\n `<meta data-dirwell-metadata ${property ? \"property\" : \"name\"}=\"${key}\" content=\"${escapeHtml(value)}\">`;\n let head = `<title>${escapeHtml(title)}</title>${meta(\"description\", description)}${meta(\"og:title\", title, true)}${meta(\"og:description\", description, true)}${meta(\"og:type\", \"website\", true)}`;\n if (siteUrl) {\n const canonical = new URL(pagePath.split(\"/\").map(encodeURIComponent).join(\"/\"), siteUrl)\n .href;\n head += `${meta(\"og:url\", canonical, true)}<link data-dirwell-metadata rel=\"canonical\" href=\"${escapeHtml(canonical)}\">`;\n }\n if (image) {\n const href = siteUrl\n ? new URL(image.outputPath.split(\"/\").map(encodeURIComponent).join(\"/\"), siteUrl).href\n : hrefForOutput(image.outputPath);\n head +=\n meta(\"og:image\", href, true) +\n meta(\"og:image:alt\", image.alt, true) +\n meta(\"twitter:card\", \"summary_large_image\") +\n meta(\"twitter:title\", title) +\n meta(\"twitter:description\", description) +\n meta(\"twitter:image\", href) +\n meta(\"twitter:image:alt\", image.alt);\n }\n return { title, description, head };\n },\n };\n}\n","import type {\n MetadataOptions,\n ThemeMetadataDefaults,\n MetadataProviderFactory,\n} from \"@dirwell/core\";\nimport { countKinds, createMetadataResolver } from \"./metadata.ts\";\nexport { createShareImage } from \"./share-image-api.ts\";\nexport type { ShareImageOptions } from \"./share-image-api.ts\";\nexport {\n countEntries,\n countKinds,\n describeContent,\n repositoryName,\n createMetadataResolver,\n} from \"./metadata.ts\";\n/** Opt-in build metadata. PNG presets are generated only when defaults.imageTheme is supplied. */\nexport function createMetadataProvider(\n options: MetadataOptions,\n defaults: ThemeMetadataDefaults,\n sourceDirectory = process.cwd(),\n): MetadataProviderFactory {\n return ({ sourceKinds }) =>\n createMetadataResolver(options, defaults, countKinds(sourceKinds.values()), sourceDirectory);\n}\n"],"mappings":";;;;;;;AA6BA,SAAgB,aAAa,WAAyC;CACpE,OAAO,WAAW,UAAU,QAAQ,KAAK,UAAU,MAAM,IAAI,CAAC;AAChE;AACA,SAAgB,WAAW,OAAwC;CACjE,IAAI,cAAc,GAChB,YAAY,GACZ,YAAY;CACd,KAAK,MAAM,QAAQ,OACjB,IAAI,SAAS,aAAa;MACrB,IAAI,SAAS,QAAQ;MACrB,IAAI,SAAS,WAAW;CAE/B,OAAO;EAAE;EAAa;EAAW;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AI,SAAS;IACX,MAAM,YAAY,IAAI,IAAI,SAAS,MAAM,GAAG,CAAC,CAAC,IAAI,kBAAkB,CAAC,CAAC,KAAK,GAAG,GAAG,OAAO,CAAC,CACtF;IACH,QAAQ,GAAG,KAAK,UAAU,WAAW,IAAI,EAAE,oDAAoD,WAAW,SAAS,EAAE;GACvH;GACA,IAAI,OAAO;IACT,MAAM,OAAO,UACT,IAAI,IAAI,MAAM,WAAW,MAAM,GAAG,CAAC,CAAC,IAAI,kBAAkB,CAAC,CAAC,KAAK,GAAG,GAAG,OAAO,CAAC,CAAC,OAChF,cAAc,MAAM,UAAU;IAClC,QACE,KAAK,YAAY,MAAM,IAAI,IAC3B,KAAK,gBAAgB,MAAM,KAAK,IAAI,IACpC,KAAK,gBAAgB,qBAAqB,IAC1C,KAAK,iBAAiB,KAAK,IAC3B,KAAK,uBAAuB,WAAW,IACvC,KAAK,iBAAiB,IAAI,IAC1B,KAAK,qBAAqB,MAAM,GAAG;GACvC;GACA,OAAO;IAAE;IAAO;IAAa;GAAK;EACpC;CACF;AACF;;;;AClPA,SAAgB,uBACd,SACA,UACA,kBAAkB,QAAQ,IAAI,GACL;CACzB,QAAQ,EAAE,kBACR,uBAAuB,SAAS,UAAU,WAAW,YAAY,OAAO,CAAC,GAAG,eAAe;AAC/F"}
@@ -0,0 +1,140 @@
1
+ import { escapeHtml } from "@dirwell/core";
2
+ import { createHash } from "node:crypto";
3
+ import { readFile } from "node:fs/promises";
4
+ import { fileURLToPath } from "node:url";
5
+ import { create } from "fontkit";
6
+ import { Resvg } from "@resvg/resvg-js";
7
+ //#region src/share-image.ts
8
+ const fontNames = [
9
+ "SourceSans3-Regular.otf",
10
+ "SourceSans3-Light.otf",
11
+ "SourceSerif4-Regular.otf"
12
+ ];
13
+ const buffers = await Promise.all(fontNames.map((name) => readFile(new URL(`./fonts/${name}`, import.meta.url))));
14
+ const fonts = buffers.map((bytes) => create(bytes));
15
+ const fontDigest = createHash("sha256").update(Buffer.concat(buffers)).digest("hex");
16
+ const themes = {
17
+ ledger: {
18
+ name: "Ledger",
19
+ face: 0,
20
+ family: "Source Sans 3",
21
+ bg: "#f3f0e8",
22
+ fg: "#171815",
23
+ muted: "#64655f",
24
+ rule: "#c9c5ba",
25
+ weight: 400
26
+ },
27
+ plain: {
28
+ name: "Plain",
29
+ face: 2,
30
+ family: "Source Serif 4",
31
+ bg: "#ffffff",
32
+ fg: "#171815",
33
+ muted: "#454545",
34
+ rule: "#171815",
35
+ weight: 400
36
+ },
37
+ crosswave: {
38
+ name: "Crosswave",
39
+ face: 1,
40
+ family: "Source Sans 3",
41
+ bg: "#091a3a",
42
+ fg: "#f7fbff",
43
+ muted: "#edf4fc",
44
+ rule: "#edf4fc",
45
+ weight: 300
46
+ }
47
+ };
48
+ const segmenter = new Intl.Segmenter("en", { granularity: "grapheme" });
49
+ function width(text, face, size) {
50
+ const font = fonts[face];
51
+ return font.layout(text).positions.reduce((sum, position) => sum + position.xAdvance, 0) * size / font.unitsPerEm;
52
+ }
53
+ function fit(value, face, sizes, limit, maxLines = 2) {
54
+ if (typeof value !== "string") throw new TypeError("Share image text must be a string");
55
+ const text = Array.from(segmenter.segment(value.slice(0, 16384).normalize("NFC").replace(/\s+/g, " ").trim()), (part) => part.segment);
56
+ const bounded = text.slice(0, 2048);
57
+ for (const character of bounded.join("")) {
58
+ const codePoint = character.codePointAt(0);
59
+ if (!fonts[face].hasGlyphForCodePoint(codePoint)) throw new Error(`Bundled share-image font lacks U+${codePoint.toString(16).toUpperCase()}; use a custom image renderer or metadata.image: false`);
60
+ }
61
+ for (const size of sizes) {
62
+ let position = 0;
63
+ const lines = [];
64
+ while (position < bounded.length && lines.length < maxLines) {
65
+ let low = 0, high = bounded.length - position;
66
+ while (low < high) {
67
+ const count = Math.ceil((low + high) / 2);
68
+ if (width(bounded.slice(position, position + count).join(""), face, size) <= limit) low = count;
69
+ else high = count - 1;
70
+ }
71
+ const end = position + Math.max(1, low);
72
+ let line = bounded.slice(position, end).join("").trim();
73
+ if (lines.length === maxLines - 1 && (end < text.length || value.length > 16384)) {
74
+ let graphemes = Array.from(segmenter.segment(line), (part) => part.segment);
75
+ while (graphemes.length && width(graphemes.join("") + "…", face, size) > limit) graphemes.pop();
76
+ line = graphemes.join("") + "…";
77
+ }
78
+ lines.push(line);
79
+ position = end;
80
+ }
81
+ if (position >= text.length || size === sizes.at(-1)) return {
82
+ size,
83
+ lines
84
+ };
85
+ }
86
+ return {
87
+ size: 56,
88
+ lines: []
89
+ };
90
+ }
91
+ function text(value, x, y, gap, fill, family, weight = 400, anchor = "start") {
92
+ return value.lines.map((line, index) => `<text x="${x}" y="${y + index * gap}" font-family="${family}" font-weight="${weight}" font-size="${value.size}" fill="${fill}" text-anchor="${anchor}">${escapeHtml(line)}</text>`).join("");
93
+ }
94
+ const wave = `<defs><linearGradient id="bg" x2=".2" y2="1"><stop stop-color="#2b4f85"/><stop offset="1" stop-color="#091a3a"/></linearGradient><linearGradient id="ribbon"><stop stop-color="#80afff" stop-opacity=".02"/><stop offset=".5" stop-color="#b7d6ff" stop-opacity=".24"/><stop offset="1" stop-color="#e6f2ff" stop-opacity=".03"/></linearGradient></defs><rect width="1200" height="630" fill="url(#bg)"/><path d="M-80 470C170 270 330 560 630 435S980 290 1280 470" stroke="url(#ribbon)" stroke-width="32" fill="none"/><path d="M-80 495C170 590 370 315 690 465S1020 580 1280 390" stroke="url(#ribbon)" stroke-width="14" fill="none"/>`;
95
+ const cache = /* @__PURE__ */ new Map();
96
+ /** Build-time PNG generation with bundled fonts; no network or system-font search. */
97
+ function renderShareImage(options) {
98
+ const theme = options.theme ?? "ledger";
99
+ const t = themes[theme];
100
+ if (!t) throw new TypeError("Unknown share image theme");
101
+ const regular = theme === "plain" ? 2 : 0;
102
+ const headline = fit(options.title, t.face, [
103
+ 96,
104
+ 88,
105
+ 80,
106
+ 72,
107
+ 64,
108
+ 56
109
+ ], 1064);
110
+ const header = fit(options.repositoryName ?? "", regular, [
111
+ 30,
112
+ 28,
113
+ 26
114
+ ], 800, 1);
115
+ const description = fit(options.description, regular, [
116
+ 34,
117
+ 30,
118
+ 26
119
+ ], 1064, 1);
120
+ const directory = fit(options.directoryPath ? `/${options.directoryPath}/` : "", regular, [24], 1064, 1);
121
+ const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="1200" height="630" viewBox="0 0 1200 630"><rect width="1200" height="630" fill="${t.bg}"/>${theme === "crosswave" ? wave : ""}${text(header, 68, 86, 0, t.fg, t.family)}${text({
122
+ size: 30,
123
+ lines: [t.name]
124
+ }, 1130, 86, 0, t.fg, t.family, 400, "end")}${theme === "crosswave" ? "" : `<path d="M64 126H1136" stroke="${t.rule}"/>`}${text(headline, 68, 276, 112, t.fg, t.family, t.weight)}${text(description, 68, 480, 0, t.muted, t.family)}${text(directory, 68, 572, 0, t.muted, t.family)}</svg>`;
125
+ const key = createHash("sha256").update(fontDigest).update(svg).digest("hex");
126
+ const previous = cache.get(key);
127
+ if (previous) return previous;
128
+ const png = new Resvg(svg, { font: {
129
+ fontFiles: fontNames.map((name) => fileURLToPath(new URL(`./fonts/${name}`, import.meta.url))),
130
+ loadSystemFonts: false
131
+ } }).render().asPng();
132
+ const file = new File([new Uint8Array(png)], `${theme}.png`, { type: "image/png" });
133
+ if (cache.size >= 32) cache.delete(cache.keys().next().value);
134
+ cache.set(key, file);
135
+ return file;
136
+ }
137
+ //#endregion
138
+ export { renderShareImage };
139
+
140
+ //# sourceMappingURL=share-image-D2N_4dRw.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"share-image-D2N_4dRw.mjs","names":[],"sources":["../src/share-image.ts"],"sourcesContent":["import { escapeHtml } from \"@dirwell/core\";\nimport { readFile } from \"node:fs/promises\";\nimport { fileURLToPath } from \"node:url\";\nimport { createHash } from \"node:crypto\";\nimport { create, type Font } from \"fontkit\";\nimport { Resvg } from \"@resvg/resvg-js\";\n\nexport interface ShareImageOptions {\n readonly theme?: \"ledger\" | \"plain\" | \"crosswave\";\n readonly title: string;\n readonly description: string;\n readonly repositoryName?: string;\n readonly directoryPath?: string;\n}\nconst fontNames = [\n \"SourceSans3-Regular.otf\",\n \"SourceSans3-Light.otf\",\n \"SourceSerif4-Regular.otf\",\n] as const;\nconst buffers = await Promise.all(\n fontNames.map((name) => readFile(new URL(`./fonts/${name}`, import.meta.url))),\n);\nconst fonts = buffers.map((bytes) => create(bytes) as Font);\nconst fontDigest = createHash(\"sha256\").update(Buffer.concat(buffers)).digest(\"hex\");\nconst themes = {\n ledger: {\n name: \"Ledger\",\n face: 0,\n family: \"Source Sans 3\",\n bg: \"#f3f0e8\",\n fg: \"#171815\",\n muted: \"#64655f\",\n rule: \"#c9c5ba\",\n weight: 400,\n },\n plain: {\n name: \"Plain\",\n face: 2,\n family: \"Source Serif 4\",\n bg: \"#ffffff\",\n fg: \"#171815\",\n muted: \"#454545\",\n rule: \"#171815\",\n weight: 400,\n },\n crosswave: {\n name: \"Crosswave\",\n face: 1,\n family: \"Source Sans 3\",\n bg: \"#091a3a\",\n fg: \"#f7fbff\",\n muted: \"#edf4fc\",\n rule: \"#edf4fc\",\n weight: 300,\n },\n} as const;\nconst segmenter = new Intl.Segmenter(\"en\", { granularity: \"grapheme\" });\n\nfunction width(text: string, face: number, size: number): number {\n const font = fonts[face]!;\n return (\n (font.layout(text).positions.reduce((sum, position) => sum + position.xAdvance, 0) * size) /\n font.unitsPerEm\n );\n}\nfunction fit(\n value: string,\n face: number,\n sizes: readonly number[],\n limit: number,\n maxLines = 2,\n): { size: number; lines: string[] } {\n if (typeof value !== \"string\") throw new TypeError(\"Share image text must be a string\");\n const text = Array.from(\n segmenter.segment(value.slice(0, 16384).normalize(\"NFC\").replace(/\\s+/g, \" \").trim()),\n (part) => part.segment,\n );\n const bounded = text.slice(0, 2048);\n for (const character of bounded.join(\"\")) {\n const codePoint = character.codePointAt(0)!;\n if (!fonts[face]!.hasGlyphForCodePoint(codePoint))\n throw new Error(\n `Bundled share-image font lacks U+${codePoint.toString(16).toUpperCase()}; use a custom image renderer or metadata.image: false`,\n );\n }\n for (const size of sizes) {\n let position = 0;\n const lines: string[] = [];\n while (position < bounded.length && lines.length < maxLines) {\n let low = 0,\n high = bounded.length - position;\n while (low < high) {\n const count = Math.ceil((low + high) / 2);\n if (width(bounded.slice(position, position + count).join(\"\"), face, size) <= limit)\n low = count;\n else high = count - 1;\n }\n const end = position + Math.max(1, low);\n let line = bounded.slice(position, end).join(\"\").trim();\n if (lines.length === maxLines - 1 && (end < text.length || value.length > 16384)) {\n let graphemes = Array.from(segmenter.segment(line), (part) => part.segment);\n while (graphemes.length && width(graphemes.join(\"\") + \"…\", face, size) > limit)\n graphemes.pop();\n line = graphemes.join(\"\") + \"…\";\n }\n lines.push(line);\n position = end;\n }\n if (position >= text.length || size === sizes.at(-1)) return { size, lines };\n }\n return { size: 56, lines: [] };\n}\nfunction text(\n value: { size: number; lines: string[] },\n x: number,\n y: number,\n gap: number,\n fill: string,\n family: string,\n weight = 400,\n anchor = \"start\",\n): string {\n return value.lines\n .map(\n (line, index) =>\n `<text x=\"${x}\" y=\"${y + index * gap}\" font-family=\"${family}\" font-weight=\"${weight}\" font-size=\"${value.size}\" fill=\"${fill}\" text-anchor=\"${anchor}\">${escapeHtml(line)}</text>`,\n )\n .join(\"\");\n}\nconst wave = `<defs><linearGradient id=\"bg\" x2=\".2\" y2=\"1\"><stop stop-color=\"#2b4f85\"/><stop offset=\"1\" stop-color=\"#091a3a\"/></linearGradient><linearGradient id=\"ribbon\"><stop stop-color=\"#80afff\" stop-opacity=\".02\"/><stop offset=\".5\" stop-color=\"#b7d6ff\" stop-opacity=\".24\"/><stop offset=\"1\" stop-color=\"#e6f2ff\" stop-opacity=\".03\"/></linearGradient></defs><rect width=\"1200\" height=\"630\" fill=\"url(#bg)\"/><path d=\"M-80 470C170 270 330 560 630 435S980 290 1280 470\" stroke=\"url(#ribbon)\" stroke-width=\"32\" fill=\"none\"/><path d=\"M-80 495C170 590 370 315 690 465S1020 580 1280 390\" stroke=\"url(#ribbon)\" stroke-width=\"14\" fill=\"none\"/>`;\nconst cache = new Map<string, File>();\n/** Build-time PNG generation with bundled fonts; no network or system-font search. */\nexport function renderShareImage(options: ShareImageOptions): File {\n const theme = options.theme ?? \"ledger\";\n const t = themes[theme];\n if (!t) throw new TypeError(\"Unknown share image theme\");\n const regular = theme === \"plain\" ? 2 : 0;\n const headline = fit(options.title, t.face, [96, 88, 80, 72, 64, 56], 1064);\n const header = fit(options.repositoryName ?? \"\", regular, [30, 28, 26], 800, 1);\n const description = fit(options.description, regular, [34, 30, 26], 1064, 1);\n const directory = fit(\n options.directoryPath ? `/${options.directoryPath}/` : \"\",\n regular,\n [24],\n 1064,\n 1,\n );\n const svg = `<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"1200\" height=\"630\" viewBox=\"0 0 1200 630\"><rect width=\"1200\" height=\"630\" fill=\"${t.bg}\"/>${theme === \"crosswave\" ? wave : \"\"}${text(header, 68, 86, 0, t.fg, t.family)}${text({ size: 30, lines: [t.name] }, 1130, 86, 0, t.fg, t.family, 400, \"end\")}${theme === \"crosswave\" ? \"\" : `<path d=\"M64 126H1136\" stroke=\"${t.rule}\"/>`}${text(headline, 68, 276, 112, t.fg, t.family, t.weight)}${text(description, 68, 480, 0, t.muted, t.family)}${text(directory, 68, 572, 0, t.muted, t.family)}</svg>`;\n const key = createHash(\"sha256\").update(fontDigest).update(svg).digest(\"hex\");\n const previous = cache.get(key);\n if (previous) return previous;\n const png = new Resvg(svg, {\n font: {\n fontFiles: fontNames.map((name) =>\n fileURLToPath(new URL(`./fonts/${name}`, import.meta.url)),\n ),\n loadSystemFonts: false,\n },\n })\n .render()\n .asPng();\n const file = new File([new Uint8Array(png)], `${theme}.png`, { type: \"image/png\" });\n if (cache.size >= 32) cache.delete(cache.keys().next().value!);\n cache.set(key, file);\n return file;\n}\n"],"mappings":";;;;;;;AAcA,MAAM,YAAY;CAChB;CACA;CACA;AACF;AACA,MAAM,UAAU,MAAM,QAAQ,IAC5B,UA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,EAAE,MAAM,EAAE;CAC7hB,MAAM,MAAM,WAAW,QAAQ,CAAC,CAAC,OAAO,UAAU,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO,KAAK;CAC5E,MAAM,WAAW,MAAM,IAAI,GAAG;CAC9B,IAAI,UAAU,OAAO;CACrB,MAAM,MAAM,IAAI,MAAM,KAAK,EACzB,MAAM;EACJ,WAAW,UAAU,KAAK,SACxB,cAAc,IAAI,IAAI,WAAW,QAAQ,YAAY,GAAG,CAAC,CAC3D;EACA,iBAAiB;CACnB,EACF,CAAC,CAAC,CACC,OAAO,CAAC,CACR,MAAM;CACT,MAAM,OAAO,IAAI,KAAK,CAAC,IAAI,WAAW,GAAG,CAAC,GAAG,GAAG,MAAM,OAAO,EAAE,MAAM,YAAY,CAAC;CAClF,IAAI,MAAM,QAAQ,IAAI,MAAM,OAAO,MAAM,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,KAAM;CAC7D,MAAM,IAAI,KAAK,IAAI;CACnB,OAAO;AACT"}
@@ -0,0 +1,2 @@
1
+ import { t as createShareImage } from "./share-image-api-DcmMcWT0.mjs";
2
+ export { createShareImage };
@@ -0,0 +1,10 @@
1
+ //#region src/share-image-api.ts
2
+ /** Render a PNG at build time using the selected built-in theme and bundled fonts. */
3
+ async function createShareImage(options) {
4
+ const { renderShareImage } = await import("./share-image-D2N_4dRw.mjs");
5
+ return renderShareImage(options);
6
+ }
7
+ //#endregion
8
+ export { createShareImage as t };
9
+
10
+ //# sourceMappingURL=share-image-api-DcmMcWT0.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"share-image-api-DcmMcWT0.mjs","names":[],"sources":["../src/share-image-api.ts"],"sourcesContent":["import type { ShareImageOptions } from \"./share-image.ts\";\nexport type { ShareImageOptions } from \"./share-image.ts\";\n/** Render a PNG at build time using the selected built-in theme and bundled fonts. */\nexport async function createShareImage(options: ShareImageOptions): Promise<File> {\n const { renderShareImage } = await import(\"./share-image.ts\");\n return renderShareImage(options);\n}\n"],"mappings":";;AAGA,eAAsB,iBAAiB,SAA2C;CAChF,MAAM,EAAE,qBAAqB,MAAM,OAAO;CAC1C,OAAO,iBAAiB,OAAO;AACjC"}
package/package.json CHANGED
@@ -1,6 +1,40 @@
1
1
  {
2
2
  "name": "@dirwell/share-image",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.0.1-alpha",
4
+ "description": "Optional build-time metadata and PNG share-image rendering.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/vp-tw/dirwell.git",
9
+ "directory": "packages/share-image"
10
+ },
11
+ "files": [
12
+ "dist",
13
+ "README.md",
14
+ "LICENSE",
15
+ "THIRD_PARTY_NOTICES.md"
16
+ ],
17
+ "type": "module",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.mts",
21
+ "import": "./dist/index.mjs"
22
+ }
23
+ },
24
+ "publishConfig": {
25
+ "access": "public",
26
+ "provenance": true,
27
+ "tag": "alpha"
28
+ },
29
+ "dependencies": {
30
+ "@dirwell/core": "0.0.1-alpha",
31
+ "@resvg/resvg-js": "2.6.2",
32
+ "fontkit": "2.0.4"
33
+ },
34
+ "engines": {
35
+ "node": ">=22.12.0"
36
+ },
37
+ "scripts": {
38
+ "build": "vp pack && node ../../scripts/copy-share-image-assets.mjs"
39
+ }
6
40
  }