-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.html
356 lines (340 loc) · 17.3 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
<!doctype html>
<html class="no-js" lang="">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Card Creator</title>
<meta name="description" content="">
<meta property="og:title" content="">
<meta property="og:type" content="">
<meta property="og:url" content="">
<meta property="og:image" content="">
<meta property="og:image:alt" content="">
<link rel="icon" href="/favicon.ico" sizes="any">
<link rel="icon" href="/icon.svg" type="image/svg+xml">
<link rel="apple-touch-icon" href="icon.png">
<meta name="theme-color" content="#fafafa">
<script src="vendor/alpine.persist.3.13.7.min.js" defer></script>
<script src="vendor/alpine.3.13.7.min.js" defer></script>
<script src="js/app.js"></script>
<script>
</script>
</head>
<body :class="[`print-${page_name}`]"
x-data="{
// Change these default settings if you like!
// That way, you can have them the same every time you
// refresh the page (which you'll be doing a lot)
units: $persist('mm'),
card_width: $persist(63),
card_height: $persist(88),
card_bleed: $persist(3),
page_width: $persist(210),
page_height: $persist(297),
card_cols_per_page: $persist(3),
card_rows_per_page: $persist(3),
center: $persist('1/1'),
page_name: $persist('individual'),
// If you're running via a local web server, you can use this to load examples.
// modern: poker size (63 x 88mm)
// classic: responsive - can work pretty much any size
// fantasy: best in poker size (63 x 88mm), but any portait aspect card works fine
// tarot: only tarot size (70 x 120mm)
example: null, // 'modern', 'tarot', 'fantasy' or 'classic'
// Here you can have project directory, containing:
// card.html
// cards.csv
// optional card.js (for including JS)
// optional card.css (for including css)
//
// This will overwrite 'file' and 'template' options below.
project: null,
// If you are able to run a local webserver, then put the relative filename
// to the csv file here
file: null,
// Template file (e.g. 'card.html')
template: 'card.html',
// Set to true to enable inline card html
inline_card_html: false,
// The HTML for each card
card_html: $persist(null),
// Change this function to pre-process any of the card data.
processCard: (card, row_index, card_index, subcard_index) => {
// you can process the card data any way you like.
if (typeof processCard === 'function') {
processCard(card, row_index, card_index, subcard_index);
}
return card;
},
get filteredCards() {
const cards = [];
let rownum = 0;
let cardnum = 0;
for (let card of this.cards) {
const quantity = card.quantity ?? 1;
for (let i = 0; i < quantity; i++) {
let subcard = Object.assign({}, card);
if (typeof subcard.id ==='undefined') {
subcard.id = rownum;
}
subcard = this.processCard(subcard, rownum, cardnum, i);
subcard._index = i+1;
cards.push(subcard);
cardnum++;
}
rownum++;
}
console.info('filteredCards', cards);
return cards;
},
refreshAll: function() {
// load the template if present
this.refreshTemplate();
// load the file if present
this.refreshFile();
// refresh CSS
this.refreshCss();
},
refreshTemplate: function() {
if (this.template && location.href.startsWith('http')) {
fetch(this.template + '?t=' + (new Date().getTime()))
.then(response => {
if (response.ok) {
return response.text();
} else {
if (response.status === 404) {
alert(`Could not find ${this.template} - did you forget to create it?`);
}
throw new Error('Request error getting template');
}
})
.then(html => {
this.card_html = html;
}).catch(e => {
console.error(e);
});
}
},
refreshFile: function() {
if (this.file && location.href.startsWith('http')) {
fetch(this.file + '?t=' + (new Date().getTime()))
.then(response => {
if (response.ok) {
return response.text();
} else {
if (response.status === 404) {
alert(`Could not find ${this.file} - did you forget to create it?`);
}
throw new Error('Request error getting file');
}
})
.then(a => parseCsv(a))
.then(c => this.cards = c)
.catch(e => {
console.error(e);
});
;
}
},
refreshHtml: function() {
if (this.card_html) {
document.querySelector('#cards').innerHTML = `<template x-for='card in filteredCards'>${this.card_html}</template>`;
}
},
refreshCss: function() {
document.querySelectorAll(`link[rel='stylesheet']`).forEach(el => {
let u = new URL(el.href);
u.searchParams.set('t', new Date()/1);
el.href=`${u}`;
});
},
card_preset: null,
page_preset: null,
cards: $persist([])
}"
x-init="
let folder = example ?? project ?? null;
let type = 'example';
if (example) {
type = 'example';
} else if (project) {
type = 'project';
}
if (folder) {
file = `${type}s/${folder}/cards.csv`;
template = `${type}s/${folder}/card.html`;
}
// We can only load external files via http unfortunately due to CORS policy
if (location.href.startsWith('http')) {
refreshAll();
$watch('card_preset', (value) => {
const p = presets.cards[value];
if (p) {
if (p.width) {
card_width = p.width;
}
if (p.height) {
card_height = p.height;
}
}
});
$watch('page_preset', (value) => {
const p = presets.pages[value];
if (p) {
if (p.width) {
page_width = p.width;
}
if (p.height) {
page_height = p.height;
}
}
});
$watch('card_html', (value) => {
refreshHtml();
});
}
setTimeout(() => refreshHtml(), 1);"
x-effect="
const r = document.querySelector(':root');
const c = center.split('/').map(a => a/1);
r.style.setProperty('--card-width', numberWithOptionalUnits(card_width, units));
r.style.setProperty('--card-height', numberWithOptionalUnits(card_height, units));
r.style.setProperty('--card-bleed', numberWithOptionalUnits(card_bleed, units));
r.style.setProperty('--page-width', numberWithOptionalUnits(page_width, units));
r.style.setProperty('--page-height', numberWithOptionalUnits(page_height, units));
r.style.setProperty('--card-cols-per-page', card_cols_per_page);
r.style.setProperty('--card-rows-per-page', card_rows_per_page);
r.style.setProperty('--center-horizontally', c[0]);
r.style.setProperty('--center-vertically', c[1]);
"
>
<div class="app">
<nav class="noprint">
<div class="controls" x-data="{settings_open: true}" :class='[settings_open ? "open" : "closed"]'>
<h1 @click="settings_open = !settings_open"><img src="/docs/im/icon_and_logotype-180.png" class="logo"> Settings</h1>
<div class="group" x-data="{open: true}" :class='[open ? "open" : "closed"]'>
<h2 class="group-title" @click="open = !open">Card Settings</h2>
<div class="inputs">
<div class="field">
<label for="card_width">Width</label>
<input x-model="card_width" id="card_width" name="card_width" type="text">
</div>
<div class="field">
<label for="card_height">Height</label>
<input x-model="card_height" id="card_height" name="card_height" type="text">
</div>
<div class="field">
<label for="card_bleed">Bleed</label>
<input x-model="card_bleed" id="card_bleed" name="card_bleed" type="text">
</div>
<div class="field">
<label for="card_preset">Defaults</label>
<select x-model="card_preset" id="card_preset" name="card_preset">
<option>Select</option>
<template x-for="(preset, key) in presets.cards">
<option :value="key" x-text="`${preset.name} [${preset.width} x ${preset.height}]`"></option>
</template>
</select>
</div>
</div>
</div>
<div class="group" x-data="{open: true}" :class='[open ? "open" : "closed"]'>
<h2 class="group-title" @click="open = !open">Page Settings</h2>
<div class="inputs">
<div class="field">
<label for="page_name">Print Page Size</label>
<select x-model="page_name" id="page_name" name="page_name">
<option value="auto">Auto</option>
<option value="individual">Individual</option>
<option value="a4">A4</option>
<option value="a3">A3</option>
<option value="a2">A2</option>
<option value="custom">Custom</option>
</select>
</div>
<div class="field" x-show="page_name==`custom`">
<label for="page_width">Width</label>
<input x-model="page_width" id="page_width" name="page_width" type="text">
</div>
<div class="field" x-show="page_name==`custom`">
<label for="page_height">Height</label>
<input x-model="page_height" id="page_height" name="page_height" type="text">
</div>
<div class="field" x-show="page_name==`custom`">
<label for="card_cols_per_page">Cols per Page</label>
<input x-model="card_cols_per_page" id="card_cols_per_page" name="card_cols_per_page" type="number" min="1" max="999" step="1">
</div>
<div class="field" x-show="page_name==`custom`">
<label for="card_rows_per_page">Rows per Page</label>
<input x-model="card_rows_per_page" id="card_rows_per_page" name="card_rows_per_page" type="number" min="1" max="999" step="1">
</div>
<div class="field" x-show="page_name==`custom`">
<label for="center">Centering</label>
<select x-model="center" id="center" name="center">
<option value="0/0">No centering</option>
<option value="0/1">Center Vertically</option>
<option value="1/0">Center Horizontally</option>
<option value="1/1">Center Both</option>
</select>
</div>
<div class="field" x-show="page_name==`custom`">
<label for="card_preset">Defaults</label>
<select x-model="page_preset" id="page_preset" name="page_preset">
<option>Select</option>
<template x-for="(preset, key) in presets.pages">
<option :value="key" x-text="`${preset.name} [${preset.width} x ${preset.height}]`"></option>
</template>
</select>
</div>
</div>
</div>
<template x-if="inline_card_html">
<div class="group" x-data="{open: true}" :class='[open ? "open" : "closed"]'>
<h2 class="group-title" @click="open = !open">Card Design</h2>
<div class="inputs">
<div class="field">
<label for="card_html">Card HTML</label>
<textarea cols="100" rows="10" x-model="card_html" id="card_html" name="card_html"></textarea>
</div>
</div>
</div>
</template>
<div class="group" x-data="{open: true}" :class='[open ? "open" : "closed"]'>
<h2 class="group-title" @click="open = !open">Other Settings</h2>
<div class="inputs">
<div class="field">
<label for="units">Default Units</label>
<select x-model="units" id="units" name="units">
<option value="mm">mm</option>
<option value="in">inches</option>
<option value="pt">points</option>
<option value="px">pixels</option>
</select>
</div>
<div class="field">
<label for="file">CSV File</label>
<input type="file" accept=".csv" @change="loadCsv($event).then(c => cards = c)">
</div>
</div>
</div>
<div class="help">
<a href="/docs/help.html">Help & Documentation</a> •
<button @click="if (confirm('Are you sure?')) { localStorage.clear(); location.href = location.href; }">Clear local storage</button> •
<button @click="refreshAll();" x-text="`Refresh ${(file)?'file and ':''}template`"></button>
</div>
</div>
</nav>
<main>
<div id="cards" :class="[`project-${project}`, `example-${example}`]">
<template x-for="card in filteredCards">
<!-- the contents here are replaced with card.html -->
<!-- If you are running serverless, replace the entire contents of this template with your card html -->
<div class="card">
<div x-text="card.name"></div>
</div>
</template>
</div>
</main>
</div>
</body>
</html>