@tin.so/core 0.0.0-stage → 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 +21 -0
- package/README.md +120 -2
- package/THIRD_PARTY_NOTICES.md +61 -0
- package/dist/index-blYEvwPp.d.mts +1123 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +1 -0
- package/dist/node.d.mts +21 -0
- package/dist/node.mjs +31 -0
- package/dist/src-VhDXsdB0.mjs +8662 -0
- package/fonts/commit-mono/LICENSE.txt +90 -0
- package/fonts/commit-mono/commit-mono-400-italic.ttf +0 -0
- package/fonts/commit-mono/commit-mono-400.ttf +0 -0
- package/fonts/commit-mono/commit-mono-700.ttf +0 -0
- package/fonts/fira-code/LICENSE.txt +93 -0
- package/fonts/fira-code/fira-code-400.ttf +0 -0
- package/fonts/fira-code/fira-code-700.ttf +0 -0
- package/fonts/geist-mono/LICENSE.txt +93 -0
- package/fonts/geist-mono/geist-mono-400.ttf +0 -0
- package/fonts/geist-mono/geist-mono-700.ttf +0 -0
- package/fonts/google-sans-code/LICENSE.txt +93 -0
- package/fonts/google-sans-code/google-sans-code-400-italic.ttf +0 -0
- package/fonts/google-sans-code/google-sans-code-400.ttf +0 -0
- package/fonts/google-sans-code/google-sans-code-700.ttf +0 -0
- package/fonts/ibm-plex-mono/LICENSE.txt +93 -0
- package/fonts/ibm-plex-mono/ibm-plex-mono-500-italic.ttf +0 -0
- package/fonts/ibm-plex-mono/ibm-plex-mono-500.ttf +0 -0
- package/fonts/ibm-plex-mono/ibm-plex-mono-700.ttf +0 -0
- package/fonts/inter/LICENSE.txt +93 -0
- package/fonts/inter/inter-400.ttf +0 -0
- package/fonts/inter/inter-500.ttf +0 -0
- package/fonts/jetbrains-mono/LICENSE.txt +93 -0
- package/fonts/jetbrains-mono/jetbrains-mono-500-italic.ttf +0 -0
- package/fonts/jetbrains-mono/jetbrains-mono-500.ttf +0 -0
- package/fonts/jetbrains-mono/jetbrains-mono-700.ttf +0 -0
- package/fonts/roboto-mono/LICENSE.txt +93 -0
- package/fonts/roboto-mono/roboto-mono-400-italic.ttf +0 -0
- package/fonts/roboto-mono/roboto-mono-400.ttf +0 -0
- package/fonts/roboto-mono/roboto-mono-700.ttf +0 -0
- package/fonts/source-code-pro/LICENSE.txt +93 -0
- package/fonts/source-code-pro/source-code-pro-400-italic.ttf +0 -0
- package/fonts/source-code-pro/source-code-pro-400.ttf +0 -0
- package/fonts/source-code-pro/source-code-pro-700.ttf +0 -0
- package/fonts/space-mono/LICENSE.txt +93 -0
- package/fonts/space-mono/space-mono-400-italic.ttf +0 -0
- package/fonts/space-mono/space-mono-400.ttf +0 -0
- package/fonts/space-mono/space-mono-700.ttf +0 -0
- package/package.json +58 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Chris Cook
|
|
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,121 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @tin.so/core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Renders code images from a JSON spec, to SVG and PNG. One image can show several snippets: windows next to each other or below each other, panes in a window, and popovers that point to a word. It has all [ray.so](https://ray.so) themes, line highlights, text styles and colors, tabs with file icons, and fixed aspect ratios for social media.
|
|
4
|
+
|
|
5
|
+
The pipeline is `spec → Shiki tokens → layout → SVG → PNG` and needs no browser. The layout puts every character on a monospace grid with the metrics of the bundled fonts, and [resvg](https://github.com/linebender/resvg) (WebAssembly) rasterizes the SVG. The same code runs in Node and in the browser.
|
|
6
|
+
|
|
7
|
+
This package is the renderer of the [tin.so](https://tin.so) web editor and of the [`tin` CLI](https://www.npmjs.com/package/tin.so). To make images from the command line, use the CLI.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @tin.so/core
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Node 22.18 or later.
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { writeFile } from "node:fs/promises";
|
|
21
|
+
import { render } from "@tin.so/core/node";
|
|
22
|
+
|
|
23
|
+
const png = await render({
|
|
24
|
+
theme: "vercel",
|
|
25
|
+
windows: [
|
|
26
|
+
{
|
|
27
|
+
tabs: true,
|
|
28
|
+
titleBar: false,
|
|
29
|
+
panes: [
|
|
30
|
+
{
|
|
31
|
+
title: "main.ts",
|
|
32
|
+
code: 'import plans from "./plans.toml";\n\nplans.free.price;',
|
|
33
|
+
highlight: [3],
|
|
34
|
+
annotations: [
|
|
35
|
+
{ line: 1, match: "plans", code: "const plans: {\n free: { price: 0 };\n}" },
|
|
36
|
+
],
|
|
37
|
+
},
|
|
38
|
+
{ title: "plans.toml", code: "[free]\nprice = 0" },
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
await writeFile("plans.png", png);
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
`render(spec, { format: "svg" })` gives an SVG with the fonts inside it. `scale` sets the pixel ratio of a PNG (default 2). By default, the image contains the spec and a link that opens it in the web editor. `metadata: false` turns this off.
|
|
48
|
+
|
|
49
|
+
`createLink(spec)` gives that link without an image:
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
import { createLink } from "@tin.so/core";
|
|
53
|
+
|
|
54
|
+
const link = await createLink(spec); // https://tin.so/#spec=…
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## The spec
|
|
58
|
+
|
|
59
|
+
A spec is JSON with the image settings, its windows, the panes of each window, and the code of each pane. A spec needs only `windows`, `panes` and `code`.
|
|
60
|
+
|
|
61
|
+
```json
|
|
62
|
+
{
|
|
63
|
+
"$schema": "https://tin.so/schema/v1.json",
|
|
64
|
+
"theme": "candy",
|
|
65
|
+
"windows": [{ "panes": [{ "title": "main.ts", "code": "const a = 1;" }] }]
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
| Level | Fields |
|
|
70
|
+
| ------ | -------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
71
|
+
| Image | `theme`, `mode`, `background`, `padding`, `font`, `lineNumbers`, `direction`, `gap`, `aspectRatio`, `width`, `height`, `windows` |
|
|
72
|
+
| Window | `panes`, `split`, `titleBar`, `tabs`, `frame`, `controls`, `title`, `width`, `height`, `x`, `y` |
|
|
73
|
+
| Pane | `code`, `title`, `language`, `highlight`, `marks` (bold, italic, colors, highlighter fills), `annotations` (popovers), `icon`, `lineNumbers` |
|
|
74
|
+
|
|
75
|
+
The full spec, with a description, a default and the limits of each field, is the JSON Schema at [`https://tin.so/schema/v1.json`](https://tin.so/schema/v1.json). `specJsonSchema()` gives the same schema.
|
|
76
|
+
|
|
77
|
+
The `$schema` URL (`/schema/v1.json`) or the field `v` gives the version of the spec. A spec without both is version 1. A new version comes only with a change that can break a spec. New optional fields and new themes, fonts or languages come without one.
|
|
78
|
+
|
|
79
|
+
The renderer ignores keys that start with `x-` in every object, so a spec can carry data of other tools.
|
|
80
|
+
|
|
81
|
+
An invalid spec throws a `SpecError` that names each problem with its path, for example `windows.0.panes.0.annotations.0.match: "plnas" (occurrence 1) is not in line 1`.
|
|
82
|
+
|
|
83
|
+
## API
|
|
84
|
+
|
|
85
|
+
| Function | What it does |
|
|
86
|
+
| -------------------------------------------------------- | ------------------------------------------------------------------------------------------ |
|
|
87
|
+
| `render(spec, options?)` | Renders a spec to PNG or SVG bytes, in Node (`@tin.so/core/node`) |
|
|
88
|
+
| `parseSpec(input)` | Checks a spec and fills in the defaults. Throws a `SpecError` |
|
|
89
|
+
| `layout(spec, options?)` | Highlights the code and places the windows, panes and popovers. Gives a `Scene` |
|
|
90
|
+
| `toSvg(scene, options?)` | Writes the SVG of a scene, with or without embedded fonts and metadata |
|
|
91
|
+
| `initPng(load)`, `svgToPng(svg, fonts, options?)` | Loads the resvg WebAssembly once, then rasterizes an SVG |
|
|
92
|
+
| `loadSceneFonts(scene, loadFont)` | Loads the font files that a scene uses |
|
|
93
|
+
| `createLink(spec, appUrl?)`, `readLink(link)` | Writes a spec into an editor link, and reads it back |
|
|
94
|
+
| `encodeSpec(spec)`, `decodeSpec(encoded)` | The compressed spec of a link, without the URL |
|
|
95
|
+
| `readImageSpec(image)` | Reads the spec from a PNG or SVG that has the metadata. Gives `undefined` for other images |
|
|
96
|
+
| `specJsonSchema()`, `SPEC_SCHEMA_URL` | The JSON Schema of the spec, and its URL |
|
|
97
|
+
| `THEME_IDS`, `CODE_FONT_IDS`, `LANGUAGE_IDS`, `ICON_IDS` | The ids that the spec accepts |
|
|
98
|
+
|
|
99
|
+
### In the browser
|
|
100
|
+
|
|
101
|
+
Import from `@tin.so/core`, and give the steps that read files a loader, because the browser has no file system:
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
import { initPng, layout, loadSceneFonts, svgToPng, toSvg } from "@tin.so/core";
|
|
105
|
+
|
|
106
|
+
const scene = await layout(spec);
|
|
107
|
+
// loadFont gets a path in the fonts/ directory of this package, for example "fira-code/fira-code-400.ttf"
|
|
108
|
+
const fonts = await loadSceneFonts(scene, loadFont);
|
|
109
|
+
await initPng(() => fetch(wasmUrl)); // the index_bg.wasm file of @resvg/resvg-wasm
|
|
110
|
+
const png = await svgToPng(toSvg(scene), fonts.values());
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Scripts
|
|
114
|
+
|
|
115
|
+
- `pnpm port-themes` fetches the ray.so themes at a pinned commit and writes `src/themes/*.json`.
|
|
116
|
+
- `pnpm download-fonts` downloads the fonts to `fonts/` and writes their metrics to `src/fonts/fonts.generated.json`.
|
|
117
|
+
- `pnpm generate-icons` writes the language icons from Simple Icons.
|
|
118
|
+
|
|
119
|
+
## License
|
|
120
|
+
|
|
121
|
+
MIT. The themes come from ray.so (MIT), the file icon from Lucide (ISC), the language icons from Simple Icons (CC0), and the fonts are under the SIL Open Font License, except Commit Mono (MIT). See [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md).
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# Third-party notices
|
|
2
|
+
|
|
3
|
+
`@tin.so/core` contains work of other projects. Their licenses follow.
|
|
4
|
+
|
|
5
|
+
## ray.so
|
|
6
|
+
|
|
7
|
+
The themes, the token colors and the frame styles come from [ray.so](https://github.com/raycast/ray-so).
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
MIT License
|
|
11
|
+
|
|
12
|
+
Copyright (c) 2024 Raycast Technologies Ltd
|
|
13
|
+
|
|
14
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
15
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
16
|
+
in the Software without restriction, including without limitation the rights
|
|
17
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
18
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
19
|
+
furnished to do so, subject to the following conditions:
|
|
20
|
+
|
|
21
|
+
The above copyright notice and this permission notice shall be included in all
|
|
22
|
+
copies or substantial portions of the Software.
|
|
23
|
+
|
|
24
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
25
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
26
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
27
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
28
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
29
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
30
|
+
SOFTWARE.
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Lucide
|
|
34
|
+
|
|
35
|
+
The file icon comes from [Lucide](https://lucide.dev).
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
ISC License
|
|
39
|
+
|
|
40
|
+
Copyright (c) 2026 Lucide Icons and Contributors
|
|
41
|
+
|
|
42
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
43
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
44
|
+
copyright notice and this permission notice appear in all copies.
|
|
45
|
+
|
|
46
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
47
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
48
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
49
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
50
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
51
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
52
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Simple Icons
|
|
56
|
+
|
|
57
|
+
The language icons come from [Simple Icons](https://simpleicons.org), under [CC0 1.0](https://github.com/simple-icons/simple-icons/blob/develop/LICENSE.md).
|
|
58
|
+
|
|
59
|
+
## Fonts
|
|
60
|
+
|
|
61
|
+
The fonts in `fonts/` are under the SIL Open Font License 1.1, except Commit Mono, which is under the MIT License. Each font directory contains its license.
|