tikzify 0.0.14 → 0.0.16
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/package.json +1 -1
- package/src/book.ts +35 -7
- package/src/common.ts +25 -2
- package/src/index.ts +1 -1
package/package.json
CHANGED
package/src/book.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import assert from 'assert'
|
|
2
2
|
import z from 'zod'
|
|
3
|
-
import { colorMap, defineColors, Emoji, fromSvg, getColors, gradient, svgTex, type Transform } from './common'
|
|
3
|
+
import { color, colorMap, defineColors, Emoji, fromSvg, getColors, gradient, Lang, svgTex, type Transform } from './common'
|
|
4
4
|
import { emojiMap } from './emojis'
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
type Page = z.infer<typeof Page>
|
|
8
|
-
const Page = z.object({
|
|
7
|
+
export type Page = z.infer<typeof Page>
|
|
8
|
+
export const Page = z.object({
|
|
9
9
|
gradient: gradient,
|
|
10
10
|
textBg: z.string(),
|
|
11
11
|
text: z.string().max(1024),
|
|
@@ -18,7 +18,16 @@ const Page = z.object({
|
|
|
18
18
|
|
|
19
19
|
export type Book = z.infer<typeof Book>
|
|
20
20
|
export const Book = z.object({
|
|
21
|
-
|
|
21
|
+
lang: Lang,
|
|
22
|
+
|
|
23
|
+
// FIRST PAGE
|
|
24
|
+
color: color,
|
|
25
|
+
title: z.string().max(256),
|
|
26
|
+
author: z.string().max(256),
|
|
27
|
+
date: z.coerce.date(),
|
|
28
|
+
heroJpgBase64: z.string().max(256_000),
|
|
29
|
+
|
|
30
|
+
// OTHER PAGES
|
|
22
31
|
pages: z.array(Page),
|
|
23
32
|
})
|
|
24
33
|
|
|
@@ -47,6 +56,7 @@ export function bookTex(book: Book) {
|
|
|
47
56
|
const textBgColors = pages.map(p => p.textBg)
|
|
48
57
|
const emojiColors = Object.values(emojiElements).flatMap(es => es.flatMap(getColors))
|
|
49
58
|
const colors = colorMap(new Set([
|
|
59
|
+
book.color,
|
|
50
60
|
...gradColors,
|
|
51
61
|
...textBgColors,
|
|
52
62
|
...emojiColors
|
|
@@ -81,8 +91,25 @@ ${defineColors(colors)}
|
|
|
81
91
|
|
|
82
92
|
\pagestyle{bigpagenumbers}
|
|
83
93
|
|
|
84
|
-
\
|
|
94
|
+
\pagecolor{c${colors[book.color]}!60}
|
|
95
|
+
|
|
96
|
+
\vspace*{\fill}
|
|
97
|
+
|
|
98
|
+
\begin{center}
|
|
99
|
+
\begin{tikzpicture}
|
|
100
|
+
\clip[] (0,0) circle (3.5cm);
|
|
101
|
+
\node[opacity=0.8] at (0,0) {\includegraphics[width=7cm]{hero.jpg}};
|
|
102
|
+
\end{tikzpicture}
|
|
103
|
+
|
|
104
|
+
\vspace{1cm}
|
|
105
|
+
\Huge \textbf{${book.title}}\\[1cm]
|
|
106
|
+
\LARGE ${book.author} \\[1cm]
|
|
107
|
+
\normalsize \today \\[2cm]
|
|
108
|
+
\end{center}
|
|
109
|
+
\vspace*{\fill}
|
|
110
|
+
|
|
85
111
|
\newpage
|
|
112
|
+
\nopagecolor
|
|
86
113
|
|
|
87
114
|
${book.pages.map((page, i) => {
|
|
88
115
|
const [c1, c2] = page.gradient
|
|
@@ -99,7 +126,7 @@ ${book.pages.map((page, i) => {
|
|
|
99
126
|
|
|
100
127
|
const esText = emojisTex(page.emojis.text, TRANSFORMS_TEXT)
|
|
101
128
|
const esImage = emojisTex(page.emojis.image, TRANSFORMS_IMAGE)
|
|
102
|
-
const rtl = book.
|
|
129
|
+
const rtl = book.lang === 'he'
|
|
103
130
|
|
|
104
131
|
const image = String.raw`
|
|
105
132
|
\begin{tikzpicture}[remember picture, overlay]
|
|
@@ -149,11 +176,12 @@ ${page.text}
|
|
|
149
176
|
\vspace*{\fill}
|
|
150
177
|
\newpage
|
|
151
178
|
`
|
|
179
|
+
|
|
152
180
|
return [
|
|
153
181
|
rtl ? image : text,
|
|
154
182
|
rtl ? text : image,
|
|
155
183
|
].join('\n\n')
|
|
156
|
-
})}
|
|
184
|
+
}).join('\n\n')}
|
|
157
185
|
|
|
158
186
|
\end{document}`
|
|
159
187
|
}
|
package/src/common.ts
CHANGED
|
@@ -2,10 +2,14 @@ import assert from 'assert'
|
|
|
2
2
|
import sax from 'sax'
|
|
3
3
|
import { z } from 'zod'
|
|
4
4
|
|
|
5
|
-
export const
|
|
5
|
+
export const color = z.string().length(7)
|
|
6
|
+
export const gradient = z.array(color).length(2)
|
|
6
7
|
|
|
7
8
|
export const Emoji = z.string().max(8)
|
|
8
9
|
|
|
10
|
+
const langs = ['he', 'en'] as const
|
|
11
|
+
export const Lang = z.enum(langs)
|
|
12
|
+
|
|
9
13
|
type Path = z.infer<typeof Path>
|
|
10
14
|
const Path = z.object({
|
|
11
15
|
type: z.literal("path"),
|
|
@@ -22,6 +26,17 @@ const Circle = z.object({
|
|
|
22
26
|
fill: z.string().optional(),
|
|
23
27
|
})
|
|
24
28
|
|
|
29
|
+
const Ellipse = z.object({
|
|
30
|
+
type: z.literal("ellipse"),
|
|
31
|
+
cx: z.number(),
|
|
32
|
+
cy: z.number(),
|
|
33
|
+
rx: z.number(),
|
|
34
|
+
ry: z.number(),
|
|
35
|
+
fill: z.string().optional(),
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
25
40
|
type Group = z.infer<typeof Group>
|
|
26
41
|
const Group = z.object({
|
|
27
42
|
type: z.literal("g"),
|
|
@@ -33,7 +48,7 @@ const Group = z.object({
|
|
|
33
48
|
|
|
34
49
|
type types = Element["type"]
|
|
35
50
|
type Element = z.infer<typeof Element>
|
|
36
|
-
const Element = z.union([Group, Path, Circle])
|
|
51
|
+
const Element = z.union([Group, Path, Circle, Ellipse])
|
|
37
52
|
|
|
38
53
|
type Open = {
|
|
39
54
|
[t in types]: (args: Omit<Extract<Element, { type: t }>, "type">) => void
|
|
@@ -65,6 +80,9 @@ export function fromSvg(svg: string): Group[] {
|
|
|
65
80
|
circle(attrs) {
|
|
66
81
|
push({ type: "circle", ...attrs })
|
|
67
82
|
},
|
|
83
|
+
ellipse(attrs) {
|
|
84
|
+
push({ type: "ellipse", ...attrs })
|
|
85
|
+
},
|
|
68
86
|
path(attrs) {
|
|
69
87
|
push({ type: "path", ...attrs })
|
|
70
88
|
},
|
|
@@ -79,6 +97,7 @@ export function fromSvg(svg: string): Group[] {
|
|
|
79
97
|
|
|
80
98
|
const close: Close = {
|
|
81
99
|
circle() { },
|
|
100
|
+
ellipse() { },
|
|
82
101
|
path() { },
|
|
83
102
|
g() {
|
|
84
103
|
res.push({
|
|
@@ -136,6 +155,10 @@ export const toTikz: To = {
|
|
|
136
155
|
return `\\fill[${fillStr(fill, colors)}] (${cx}, ${cy}) circle (${r});`
|
|
137
156
|
},
|
|
138
157
|
|
|
158
|
+
ellipse({ cx, cy, rx, ry, fill }, colors) {
|
|
159
|
+
return `\\fill[${fillStr(fill, colors)}] (${cx}, ${cy}) ellipse (${rx} and ${ry});`
|
|
160
|
+
},
|
|
161
|
+
|
|
139
162
|
path({ d, fill }, colors) {
|
|
140
163
|
return `\\fill[${fillStr(fill, colors)}] svg {${d}};`
|
|
141
164
|
},
|
package/src/index.ts
CHANGED