@kensio/colophon 0.2.0
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 +201 -0
- package/README.md +198 -0
- package/dist/background.d.ts +8 -0
- package/dist/background.d.ts.map +1 -0
- package/dist/background.js +22 -0
- package/dist/background.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +74 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +17 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +64 -0
- package/dist/config.js.map +1 -0
- package/dist/content/index.d.ts +39 -0
- package/dist/content/index.d.ts.map +1 -0
- package/dist/content/index.js +99 -0
- package/dist/content/index.js.map +1 -0
- package/dist/generate.d.ts +42 -0
- package/dist/generate.d.ts.map +1 -0
- package/dist/generate.js +56 -0
- package/dist/generate.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/render.d.ts +17 -0
- package/dist/render.d.ts.map +1 -0
- package/dist/render.js +52 -0
- package/dist/render.js.map +1 -0
- package/dist/templates/banner.d.ts +9 -0
- package/dist/templates/banner.d.ts.map +1 -0
- package/dist/templates/banner.js +125 -0
- package/dist/templates/banner.js.map +1 -0
- package/dist/templates/card.d.ts +7 -0
- package/dist/templates/card.d.ts.map +1 -0
- package/dist/templates/card.js +82 -0
- package/dist/templates/card.js.map +1 -0
- package/dist/templates/index.d.ts +9 -0
- package/dist/templates/index.d.ts.map +1 -0
- package/dist/templates/index.js +13 -0
- package/dist/templates/index.js.map +1 -0
- package/dist/text.d.ts +56 -0
- package/dist/text.d.ts.map +1 -0
- package/dist/text.js +78 -0
- package/dist/text.js.map +1 -0
- package/dist/types.d.ts +129 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +87 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
# @kensio/colophon
|
|
2
|
+
|
|
3
|
+
Generate social meta images (Open Graph / share-card images) for the posts of a
|
|
4
|
+
static website, driven by each post's frontmatter.
|
|
5
|
+
|
|
6
|
+
You describe an image in frontmatter — `title`, `subtitle`, `version`, a
|
|
7
|
+
template name — and Colophon renders branded PNGs at the sizes you need. The
|
|
8
|
+
name comes from the printer's _colophon_: the emblem a publisher stamps on a
|
|
9
|
+
finished work.
|
|
10
|
+
|
|
11
|
+
- **Frontmatter-driven** — general props read from a post, not a fixed schema.
|
|
12
|
+
- **Templates** — a small registry of layouts; frontmatter picks one.
|
|
13
|
+
- **Configurable branding** — colours, gradient, fonts, footer and badge come
|
|
14
|
+
from config, not from any one site's stylesheet.
|
|
15
|
+
- **Multiple sizes from one input** — a 1:1 square plus a 1.91:1 landscape by
|
|
16
|
+
default, or whatever set you configure.
|
|
17
|
+
- **Small, reusable API** — a render core with no filesystem concerns, plus an
|
|
18
|
+
optional content walker and CLI.
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pnpm add @kensio/colophon
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
`sharp` is a dependency and does the SVG → PNG rasterisation.
|
|
27
|
+
|
|
28
|
+
## Quick start (CLI)
|
|
29
|
+
|
|
30
|
+
Add image props to a post's frontmatter:
|
|
31
|
+
|
|
32
|
+
```yaml
|
|
33
|
+
---
|
|
34
|
+
title: My post
|
|
35
|
+
meta_img_props:
|
|
36
|
+
template: banner
|
|
37
|
+
title: "@kensio/colophon"
|
|
38
|
+
subtitle: Generate social meta images from frontmatter
|
|
39
|
+
version: 1.2.0
|
|
40
|
+
---
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Create a config module (optional — omit to use the neutral defaults):
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
// colophon.config.ts
|
|
47
|
+
import { defineConfig } from "@kensio/colophon";
|
|
48
|
+
|
|
49
|
+
export default defineConfig({
|
|
50
|
+
colors: { brand: "#2563eb", brandDark: "#1e3a8a", brandWarm: "#f59e0b" },
|
|
51
|
+
footer: "example.com",
|
|
52
|
+
badge: { text: "npm" },
|
|
53
|
+
});
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Run it over a content tree:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
colophon content --config colophon.config.ts
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
For every file that declares `meta_img_props`, Colophon writes a PNG next to it
|
|
63
|
+
(`post/index.md` → `post/post.png`, plus `post/post-1200x630.png` for the extra
|
|
64
|
+
size). Existing files are skipped unless you pass `--overwrite`.
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
colophon [contentDir] [options]
|
|
68
|
+
|
|
69
|
+
-c, --config <path> Config module whose default export is a ColophonConfig
|
|
70
|
+
-o, --overwrite Re-render even if the output file already exists
|
|
71
|
+
-h, --help Show help
|
|
72
|
+
|
|
73
|
+
contentDir defaults to "content"
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Programmatic use
|
|
77
|
+
|
|
78
|
+
### Render from props (core)
|
|
79
|
+
|
|
80
|
+
The core takes props and config and returns rendered bytes — no filesystem, no
|
|
81
|
+
content discovery:
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
import { renderMetaImages } from "@kensio/colophon";
|
|
85
|
+
import { writeFile } from "node:fs/promises";
|
|
86
|
+
|
|
87
|
+
const images = await renderMetaImages(
|
|
88
|
+
{
|
|
89
|
+
template: "banner",
|
|
90
|
+
title: "@kensio/colophon",
|
|
91
|
+
subtitle: "Generate social meta images from frontmatter",
|
|
92
|
+
version: "1.2.0",
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
colors: { brand: "#2563eb" },
|
|
96
|
+
footer: "example.com",
|
|
97
|
+
badge: { text: "npm" },
|
|
98
|
+
},
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
for (const image of images) {
|
|
102
|
+
const { width, height } = image.dimensions;
|
|
103
|
+
await writeFile(`card-${width}x${height}.png`, image.png);
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Walk content + generate (host helpers)
|
|
108
|
+
|
|
109
|
+
`walkContent` finds `.md` files and reads their frontmatter; `generate` ties
|
|
110
|
+
walking, rendering and writing together (this is what the CLI uses):
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
import { generate } from "@kensio/colophon";
|
|
114
|
+
|
|
115
|
+
await generate({
|
|
116
|
+
contentDir: "content",
|
|
117
|
+
config: { colors: { brand: "#2563eb" } },
|
|
118
|
+
overwrite: false,
|
|
119
|
+
onResult: (result) =>
|
|
120
|
+
console.log(`${result.skipped ? "skip" : "wrote"} ${result.outputPath}`),
|
|
121
|
+
});
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Import the walker on its own from the `@kensio/colophon/content` subpath if you
|
|
125
|
+
only want frontmatter discovery.
|
|
126
|
+
|
|
127
|
+
## Templates
|
|
128
|
+
|
|
129
|
+
| Name | Layout |
|
|
130
|
+
| -------- | ---------------------------------------------------------------------------- |
|
|
131
|
+
| `banner` | Left-aligned title with optional version, subtitle, corner badge and footer. |
|
|
132
|
+
| `card` | Minimal centred title with an optional subtitle. |
|
|
133
|
+
|
|
134
|
+
Register your own by passing `templates` in config — a template is `{ name,
|
|
135
|
+
render(context) }` returning SVG foreground content. Anything you add merges
|
|
136
|
+
over (and can override) the built-ins.
|
|
137
|
+
|
|
138
|
+
## Configuration
|
|
139
|
+
|
|
140
|
+
All fields are optional; sensible defaults apply.
|
|
141
|
+
|
|
142
|
+
| Option | Default | Notes |
|
|
143
|
+
| ------------ | ------------------------------ | --------------------------------------------------- |
|
|
144
|
+
| `colors` | neutral indigo/pink | `brand`, `brandDark`, `brandWarm`, `foreground`. |
|
|
145
|
+
| `background` | gradient derived from `colors` | Or a `{ type: "solid" }` / custom gradient. |
|
|
146
|
+
| `fontFamily` | `Arial, Helvetica, sans-serif` | Uses fonts available to `sharp`/librsvg. |
|
|
147
|
+
| `footer` | none | Footer text; omit the field for none. |
|
|
148
|
+
| `badge` | none | Corner badge for `banner`; omit the field for none. |
|
|
149
|
+
| `dimensions` | `1200×1200` and `1200×630` | Any list of `{ width, height }`. |
|
|
150
|
+
| `templates` | `banner`, `card` | Merged over the built-ins. |
|
|
151
|
+
|
|
152
|
+
### Frontmatter shape
|
|
153
|
+
|
|
154
|
+
By default Colophon reads a `meta_img_props` object and a `template` field
|
|
155
|
+
within it. Both are configurable via walk options (`propsKey`, `templateField`,
|
|
156
|
+
`defaultTemplate`, `extensions`) so you can match an existing convention.
|
|
157
|
+
|
|
158
|
+
## Sample output
|
|
159
|
+
|
|
160
|
+
These are generated by [`scripts/gen-samples.ts`](scripts/gen-samples.ts) — run
|
|
161
|
+
`pnpm samples` to regenerate them after changing a template, then commit the
|
|
162
|
+
updated PNGs so this gallery stays in sync.
|
|
163
|
+
|
|
164
|
+
<table>
|
|
165
|
+
<tr>
|
|
166
|
+
<td width="50%">
|
|
167
|
+
<img src="docs/samples/banner-square.png" alt="banner template, square" width="100%" /><br />
|
|
168
|
+
<sub><code>banner</code> · 1200×1200 · gradient, badge, version, subtitle, footer</sub>
|
|
169
|
+
</td>
|
|
170
|
+
<td width="50%">
|
|
171
|
+
<img src="docs/samples/card-square.png" alt="card template, square" width="100%" /><br />
|
|
172
|
+
<sub><code>card</code> · 1200×1200 · centred title and subtitle</sub>
|
|
173
|
+
</td>
|
|
174
|
+
</tr>
|
|
175
|
+
<tr>
|
|
176
|
+
<td>
|
|
177
|
+
<img src="docs/samples/banner-wide.png" alt="banner template, landscape" width="100%" /><br />
|
|
178
|
+
<sub><code>banner</code> · 1200×630 · the same input at Open Graph size</sub>
|
|
179
|
+
</td>
|
|
180
|
+
<td>
|
|
181
|
+
<img src="docs/samples/card-wide-solid.png" alt="card template, solid background" width="100%" /><br />
|
|
182
|
+
<sub><code>card</code> · 1200×630 · solid background, title only</sub>
|
|
183
|
+
</td>
|
|
184
|
+
</tr>
|
|
185
|
+
</table>
|
|
186
|
+
|
|
187
|
+
## Development
|
|
188
|
+
|
|
189
|
+
- `pnpm build` — compile to `dist/`.
|
|
190
|
+
- `pnpm test` / `pnpm test:coverage` — run Vitest.
|
|
191
|
+
- `pnpm lint` — ESLint + Prettier check.
|
|
192
|
+
- `pnpm fmt` — auto-fix.
|
|
193
|
+
- `pnpm samples` — regenerate the README sample images into `docs/samples/`.
|
|
194
|
+
- `pnpm check` — format, typecheck and test with coverage (run before committing).
|
|
195
|
+
|
|
196
|
+
## License
|
|
197
|
+
|
|
198
|
+
Apache-2.0
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Background, Dimensions } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Render a full-bleed background as SVG. For a gradient, this emits a `<defs>`
|
|
4
|
+
* block with a `<linearGradient>` (using the given `id`) followed by a filled
|
|
5
|
+
* rect; for a solid colour it emits just the rect.
|
|
6
|
+
*/
|
|
7
|
+
export declare function backgroundSvg(background: Background, dimensions: Dimensions, id: string): string;
|
|
8
|
+
//# sourceMappingURL=background.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"background.d.ts","sourceRoot":"","sources":["../src/background.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAEzD;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,UAAU,EACtB,EAAE,EAAE,MAAM,GACT,MAAM,CAqBR"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Render a full-bleed background as SVG. For a gradient, this emits a `<defs>`
|
|
3
|
+
* block with a `<linearGradient>` (using the given `id`) followed by a filled
|
|
4
|
+
* rect; for a solid colour it emits just the rect.
|
|
5
|
+
*/
|
|
6
|
+
export function backgroundSvg(background, dimensions, id) {
|
|
7
|
+
const { width, height } = dimensions;
|
|
8
|
+
if (background.type === "solid") {
|
|
9
|
+
return `<rect width="${String(width)}" height="${String(height)}" fill="${background.color}"/>`;
|
|
10
|
+
}
|
|
11
|
+
const from = background.from ?? { x: 0, y: 0 };
|
|
12
|
+
const to = background.to ?? { x: 1, y: 1 };
|
|
13
|
+
const stops = background.stops
|
|
14
|
+
.map((stop) => `<stop offset="${stop.offset}" stop-color="${stop.color}"/>`)
|
|
15
|
+
.join("");
|
|
16
|
+
return (`<defs>` +
|
|
17
|
+
`<linearGradient id="${id}" x1="${String(from.x)}" y1="${String(from.y)}"` +
|
|
18
|
+
` x2="${String(to.x)}" y2="${String(to.y)}">${stops}</linearGradient>` +
|
|
19
|
+
`</defs>` +
|
|
20
|
+
`<rect width="${String(width)}" height="${String(height)}" fill="url(#${id})"/>`);
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=background.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"background.js","sourceRoot":"","sources":["../src/background.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAC3B,UAAsB,EACtB,UAAsB,EACtB,EAAU;IAEV,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC;IAErC,IAAI,UAAU,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;QAChC,OAAO,gBAAgB,MAAM,CAAC,KAAK,CAAC,aAAa,MAAM,CAAC,MAAM,CAAC,WAAW,UAAU,CAAC,KAAK,KAAK,CAAC;IAClG,CAAC;IAED,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;IAC/C,MAAM,EAAE,GAAG,UAAU,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;IAE3C,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK;SAC3B,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,iBAAiB,IAAI,CAAC,MAAM,iBAAiB,IAAI,CAAC,KAAK,KAAK,CAAC;SAC3E,IAAI,CAAC,EAAE,CAAC,CAAC;IAEZ,OAAO,CACL,QAAQ;QACR,uBAAuB,EAAE,SAAS,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG;QAC1E,QAAQ,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,mBAAmB;QACtE,SAAS;QACT,gBAAgB,MAAM,CAAC,KAAK,CAAC,aAAa,MAAM,CAAC,MAAM,CAAC,gBAAgB,EAAE,MAAM,CACjF,CAAC;AACJ,CAAC"}
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { pathToFileURL } from "node:url";
|
|
4
|
+
import { generate } from "./generate.js";
|
|
5
|
+
const usage = `colophon — generate social meta images from frontmatter
|
|
6
|
+
|
|
7
|
+
Usage:
|
|
8
|
+
colophon [contentDir] [options]
|
|
9
|
+
|
|
10
|
+
Options:
|
|
11
|
+
-c, --config <path> Load a config module (default export = ColophonConfig)
|
|
12
|
+
-o, --overwrite Re-render images even if the output file exists
|
|
13
|
+
-h, --help Show this help
|
|
14
|
+
|
|
15
|
+
Defaults:
|
|
16
|
+
contentDir content`;
|
|
17
|
+
function parseCliArgs(argv) {
|
|
18
|
+
let contentDir = "content";
|
|
19
|
+
let configPath;
|
|
20
|
+
let shouldOverwrite = false;
|
|
21
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
22
|
+
const arg = argv[index];
|
|
23
|
+
if (arg === "-c" || arg === "--config") {
|
|
24
|
+
index += 1;
|
|
25
|
+
const value = argv[index];
|
|
26
|
+
if (value === undefined) {
|
|
27
|
+
throw new Error(`Missing value for ${arg}`);
|
|
28
|
+
}
|
|
29
|
+
configPath = value;
|
|
30
|
+
}
|
|
31
|
+
else if (arg === "-o" || arg === "--overwrite") {
|
|
32
|
+
shouldOverwrite = true;
|
|
33
|
+
}
|
|
34
|
+
else if (arg !== undefined && !arg.startsWith("-")) {
|
|
35
|
+
contentDir = arg;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return { contentDir, configPath, overwrite: shouldOverwrite };
|
|
39
|
+
}
|
|
40
|
+
async function loadConfig(configPath) {
|
|
41
|
+
if (configPath === undefined) {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
const url = pathToFileURL(path.resolve(configPath)).href;
|
|
45
|
+
const module = (await import(url));
|
|
46
|
+
return module.default;
|
|
47
|
+
}
|
|
48
|
+
async function main() {
|
|
49
|
+
const argv = process.argv.slice(2);
|
|
50
|
+
if (argv.includes("-h") || argv.includes("--help")) {
|
|
51
|
+
console.log(usage);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const args = parseCliArgs(argv);
|
|
55
|
+
const config = await loadConfig(args.configPath);
|
|
56
|
+
const results = await generate({
|
|
57
|
+
contentDir: args.contentDir,
|
|
58
|
+
overwrite: args.overwrite,
|
|
59
|
+
...(config !== undefined && { config }),
|
|
60
|
+
onResult: (result) => {
|
|
61
|
+
console.log(`${result.skipped ? "skip " : "wrote"} ${result.outputPath}`);
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
const written = results.filter((result) => !result.skipped).length;
|
|
65
|
+
console.log(`Done: ${String(written)} written, ${String(results.length - written)} skipped.`);
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
await main();
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
72
|
+
process.exitCode = 1;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"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"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { BrandColors, ColophonConfig, Dimensions, ResolvedConfig } from "./types.js";
|
|
2
|
+
/** Default output sizes: a 1:1 square plus a 1.91:1 landscape (Open Graph). */
|
|
3
|
+
export declare const DEFAULT_DIMENSIONS: readonly Dimensions[];
|
|
4
|
+
/** Default font stack. Override via `config.fontFamily` for branded fonts. */
|
|
5
|
+
export declare const DEFAULT_FONT_FAMILY = "Arial, Helvetica, sans-serif";
|
|
6
|
+
/** Neutral default palette, used when no `colors.brand` is supplied. */
|
|
7
|
+
export declare const DEFAULT_COLORS: Required<BrandColors>;
|
|
8
|
+
/**
|
|
9
|
+
* Identity helper that returns its argument typed as {@link ColophonConfig}.
|
|
10
|
+
* Use it in a config module to get editor completion and type-checking.
|
|
11
|
+
*/
|
|
12
|
+
export declare function defineConfig(config: ColophonConfig): ColophonConfig;
|
|
13
|
+
/**
|
|
14
|
+
* Apply defaults to a user config. Safe to call with no argument.
|
|
15
|
+
*/
|
|
16
|
+
export declare function resolveConfig(config?: ColophonConfig): ResolvedConfig;
|
|
17
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAEV,WAAW,EACX,cAAc,EACd,UAAU,EACV,cAAc,EACf,MAAM,YAAY,CAAC;AAEpB,+EAA+E;AAC/E,eAAO,MAAM,kBAAkB,EAAE,SAAS,UAAU,EAGnD,CAAC;AAEF,8EAA8E;AAC9E,eAAO,MAAM,mBAAmB,iCAAiC,CAAC;AAElE,wEAAwE;AACxE,eAAO,MAAM,cAAc,EAAE,QAAQ,CAAC,WAAW,CAKhD,CAAC;AAEF;;;GAGG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,cAAc,GAAG,cAAc,CAEnE;AA4BD;;GAEG;AACH,wBAAgB,aAAa,CAAC,MAAM,GAAE,cAAmB,GAAG,cAAc,CAgBzE"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { builtinTemplates } from "./templates/index.js";
|
|
2
|
+
/** Default output sizes: a 1:1 square plus a 1.91:1 landscape (Open Graph). */
|
|
3
|
+
export const DEFAULT_DIMENSIONS = [
|
|
4
|
+
{ width: 1200, height: 1200 },
|
|
5
|
+
{ width: 1200, height: 630 },
|
|
6
|
+
];
|
|
7
|
+
/** Default font stack. Override via `config.fontFamily` for branded fonts. */
|
|
8
|
+
export const DEFAULT_FONT_FAMILY = "Arial, Helvetica, sans-serif";
|
|
9
|
+
/** Neutral default palette, used when no `colors.brand` is supplied. */
|
|
10
|
+
export const DEFAULT_COLORS = {
|
|
11
|
+
brand: "#4f46e5",
|
|
12
|
+
brandDark: "#3730a3",
|
|
13
|
+
brandWarm: "#db2777",
|
|
14
|
+
foreground: "#ffffff",
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Identity helper that returns its argument typed as {@link ColophonConfig}.
|
|
18
|
+
* Use it in a config module to get editor completion and type-checking.
|
|
19
|
+
*/
|
|
20
|
+
export function defineConfig(config) {
|
|
21
|
+
return config;
|
|
22
|
+
}
|
|
23
|
+
function resolveColors(colors) {
|
|
24
|
+
if (colors === undefined) {
|
|
25
|
+
return DEFAULT_COLORS;
|
|
26
|
+
}
|
|
27
|
+
// When a project supplies only `brand`, use it for the whole gradient rather
|
|
28
|
+
// than mixing in the neutral defaults, which would clash.
|
|
29
|
+
return {
|
|
30
|
+
brand: colors.brand,
|
|
31
|
+
brandDark: colors.brandDark ?? colors.brand,
|
|
32
|
+
brandWarm: colors.brandWarm ?? colors.brand,
|
|
33
|
+
foreground: colors.foreground ?? DEFAULT_COLORS.foreground,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function defaultBackground(colors) {
|
|
37
|
+
return {
|
|
38
|
+
type: "gradient",
|
|
39
|
+
stops: [
|
|
40
|
+
{ offset: "0%", color: colors.brandDark },
|
|
41
|
+
{ offset: "55%", color: colors.brand },
|
|
42
|
+
{ offset: "100%", color: colors.brandWarm },
|
|
43
|
+
],
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Apply defaults to a user config. Safe to call with no argument.
|
|
48
|
+
*/
|
|
49
|
+
export function resolveConfig(config = {}) {
|
|
50
|
+
const colors = resolveColors(config.colors);
|
|
51
|
+
const dimensions = config.dimensions && config.dimensions.length > 0
|
|
52
|
+
? config.dimensions
|
|
53
|
+
: DEFAULT_DIMENSIONS;
|
|
54
|
+
return {
|
|
55
|
+
colors,
|
|
56
|
+
background: config.background ?? defaultBackground(colors),
|
|
57
|
+
fontFamily: config.fontFamily ?? DEFAULT_FONT_FAMILY,
|
|
58
|
+
footer: config.footer,
|
|
59
|
+
badge: config.badge,
|
|
60
|
+
dimensions,
|
|
61
|
+
templates: { ...builtinTemplates, ...config.templates },
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AASxD,+EAA+E;AAC/E,MAAM,CAAC,MAAM,kBAAkB,GAA0B;IACvD,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE;IAC7B,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE;CAC7B,CAAC;AAEF,8EAA8E;AAC9E,MAAM,CAAC,MAAM,mBAAmB,GAAG,8BAA8B,CAAC;AAElE,wEAAwE;AACxE,MAAM,CAAC,MAAM,cAAc,GAA0B;IACnD,KAAK,EAAE,SAAS;IAChB,SAAS,EAAE,SAAS;IACpB,SAAS,EAAE,SAAS;IACpB,UAAU,EAAE,SAAS;CACtB,CAAC;AAEF;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,MAAsB;IACjD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,aAAa,CAAC,MAA+B;IACpD,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,cAAc,CAAC;IACxB,CAAC;IAED,6EAA6E;IAC7E,0DAA0D;IAC1D,OAAO;QACL,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,SAAS,EAAE,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,KAAK;QAC3C,SAAS,EAAE,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,KAAK;QAC3C,UAAU,EAAE,MAAM,CAAC,UAAU,IAAI,cAAc,CAAC,UAAU;KAC3D,CAAC;AACJ,CAAC;AAED,SAAS,iBAAiB,CAAC,MAA6B;IACtD,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,KAAK,EAAE;YACL,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,SAAS,EAAE;YACzC,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE;YACtC,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,SAAS,EAAE;SAC5C;KACF,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,MAAM,GAAmB,EAAE;IACvD,MAAM,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC5C,MAAM,UAAU,GACd,MAAM,CAAC,UAAU,IAAI,MAAM,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC;QAC/C,CAAC,CAAC,MAAM,CAAC,UAAU;QACnB,CAAC,CAAC,kBAAkB,CAAC;IAEzB,OAAO;QACL,MAAM;QACN,UAAU,EAAE,MAAM,CAAC,UAAU,IAAI,iBAAiB,CAAC,MAAM,CAAC;QAC1D,UAAU,EAAE,MAAM,CAAC,UAAU,IAAI,mBAAmB;QACpD,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,UAAU;QACV,SAAS,EAAE,EAAE,GAAG,gBAAgB,EAAE,GAAG,MAAM,CAAC,SAAS,EAAE;KACxD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { MetaImageProps } from "../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Options for {@link walkContent}. Only `dir` is required.
|
|
4
|
+
*/
|
|
5
|
+
export interface WalkOptions {
|
|
6
|
+
/** Root directory to search recursively for content files. */
|
|
7
|
+
readonly dir: string;
|
|
8
|
+
/** Frontmatter key holding the image props object. Default `meta_img_props`. */
|
|
9
|
+
readonly propsKey?: string;
|
|
10
|
+
/** Field within the props object naming the template. Default `template`. */
|
|
11
|
+
readonly templateField?: string;
|
|
12
|
+
/** Template to use when the template field is absent. */
|
|
13
|
+
readonly defaultTemplate?: string;
|
|
14
|
+
/** File extensions to include. Default `.md` and `.markdown`. */
|
|
15
|
+
readonly extensions?: readonly string[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A discovered content file with the image props read from its frontmatter.
|
|
19
|
+
*/
|
|
20
|
+
export interface ContentFile {
|
|
21
|
+
/** Path relative to the walk `dir`. */
|
|
22
|
+
readonly contentPath: string;
|
|
23
|
+
/** Absolute path on disk. */
|
|
24
|
+
readonly absolutePath: string;
|
|
25
|
+
readonly props: MetaImageProps;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Extract {@link MetaImageProps} from a parsed frontmatter object, or return
|
|
29
|
+
* `undefined` if this file should be skipped (no props object, or no usable
|
|
30
|
+
* template/title). Pure — no filesystem access.
|
|
31
|
+
*/
|
|
32
|
+
export declare function extractProps(frontmatter: Record<string, unknown>, options?: Pick<WalkOptions, "propsKey" | "templateField" | "defaultTemplate">): MetaImageProps | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Walk a content tree, read each file's frontmatter with `gray-matter`, and
|
|
35
|
+
* return the files that declare image props. This is the host-project concern
|
|
36
|
+
* — finding content and reading frontmatter — kept separate from rendering.
|
|
37
|
+
*/
|
|
38
|
+
export declare function walkContent(options: WalkOptions): Promise<ContentFile[]>;
|
|
39
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/content/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAsBlD;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,8DAA8D;IAC9D,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,gFAAgF;IAChF,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,6EAA6E;IAC7E,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,yDAAyD;IACzD,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAClC,iEAAiE;IACjE,QAAQ,CAAC,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACzC;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,uCAAuC;IACvC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,6BAA6B;IAC7B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC;CAChC;AAMD;;;;GAIG;AACH,wBAAgB,YAAY,CAC1B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACpC,OAAO,GAAE,IAAI,CACX,WAAW,EACX,UAAU,GAAG,eAAe,GAAG,iBAAiB,CAC5C,GACL,cAAc,GAAG,SAAS,CA+C5B;AA8BD;;;;GAIG;AACH,wBAAsB,WAAW,CAC/B,OAAO,EAAE,WAAW,GACnB,OAAO,CAAC,WAAW,EAAE,CAAC,CAsBxB"}
|