maverick-wave-astro 1.17.0 → 1.19.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/bin/check.mjs +37 -3
- package/components/StoryCards.astro +147 -45
- package/dist/content.d.ts +3 -1
- package/dist/content.js +11 -3
- package/dist/integration.js +1 -2
- package/dist/story/base.d.ts +4 -8
- package/dist/story/base.js +17 -30
- package/dist/story/cards.d.ts +27 -13
- package/dist/story/cards.js +21 -16
- package/dist/story/event.d.ts +1 -1
- package/dist/story/event.js +54 -27
- package/dist/story/motion.d.ts +8 -4
- package/dist/story/motion.js +25 -67
- package/dist/story/promo.d.ts +2 -2
- package/dist/story/promo.js +151 -99
- package/dist/werkbank.d.ts +10 -5
- package/dist/werkbank.js +13 -4
- package/package.json +1 -1
- package/schemas/story-blocks.schema.json +50 -7
- package/schemas/story-look.schema.json +355 -247
- package/schemas/story-promo.schema.json +16 -0
package/bin/check.mjs
CHANGED
|
@@ -32,6 +32,12 @@ ajv.addVocabulary([
|
|
|
32
32
|
// values, and how wide it stands next to other short fields.
|
|
33
33
|
'x-show-if',
|
|
34
34
|
'x-width',
|
|
35
|
+
'x-empty-by',
|
|
36
|
+
// The werkbank fills it with the designs of the section Stories, lowers the
|
|
37
|
+
// maximum of the list without the larger booking, and keeps its ids.
|
|
38
|
+
'x-story-design',
|
|
39
|
+
'x-package',
|
|
40
|
+
'x-keep-ids',
|
|
35
41
|
]);
|
|
36
42
|
// Same rule as in the werkbank: YYYY-MM-DD compares as text.
|
|
37
43
|
ajv.addKeyword({
|
|
@@ -79,14 +85,42 @@ const documents = existsSync(WERKBANK)
|
|
|
79
85
|
|
|
80
86
|
const compiled = new Map();
|
|
81
87
|
const validator = schema => {
|
|
82
|
-
if (!compiled.has(schema))
|
|
88
|
+
if (!compiled.has(schema)) {
|
|
89
|
+
const json = read(schema);
|
|
90
|
+
compiled.set(schema, { json, validate: ajv.compile(json) });
|
|
91
|
+
}
|
|
83
92
|
return compiled.get(schema);
|
|
84
93
|
};
|
|
85
94
|
|
|
95
|
+
// The ids of a list with x-keep-ids stay in the file for other sections to
|
|
96
|
+
// point at - they are no field of the schema.
|
|
97
|
+
const withoutKeptIds = (schema, value) => {
|
|
98
|
+
if (Array.isArray(value)) {
|
|
99
|
+
return value.map(entry => {
|
|
100
|
+
const inner = withoutKeptIds(schema?.items, entry);
|
|
101
|
+
if (!schema?.['x-keep-ids'] || !inner || typeof inner !== 'object') {
|
|
102
|
+
return inner;
|
|
103
|
+
}
|
|
104
|
+
const rest = { ...inner };
|
|
105
|
+
delete rest._id;
|
|
106
|
+
return rest;
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
if (value && typeof value === 'object') {
|
|
110
|
+
return Object.fromEntries(
|
|
111
|
+
Object.entries(value).map(([key, inner]) => [
|
|
112
|
+
key,
|
|
113
|
+
withoutKeptIds(schema?.properties?.[key], inner),
|
|
114
|
+
])
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
return value;
|
|
118
|
+
};
|
|
119
|
+
|
|
86
120
|
let count = 0;
|
|
87
121
|
for (const { name, schema, document } of documents) {
|
|
88
|
-
const validate = validator(schema);
|
|
89
|
-
if (validate(document)) continue;
|
|
122
|
+
const { json, validate } = validator(schema);
|
|
123
|
+
if (validate(withoutKeptIds(json, document))) continue;
|
|
90
124
|
for (const error of validate.errors) {
|
|
91
125
|
console.error(`${name}${error.instancePath}: ${message(error)}`);
|
|
92
126
|
count++;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
---
|
|
2
2
|
// Story images in 9:16 for Instagram Story and WhatsApp Status, drawn in the
|
|
3
3
|
// browser from what the site keeps anyway: the upcoming events and the running
|
|
4
|
-
// promotion, and the story tabs of the werkbank in the
|
|
5
|
-
// Stories. Meant for a page of its own with noIndex and no link to it - the
|
|
4
|
+
// promotion, and the story tabs of the werkbank, each in the design it picks
|
|
5
|
+
// from the section Stories. Meant for a page of its own with noIndex and no link to it - the
|
|
6
6
|
// owner's tool, not a page of the homepage. With #mw-story=... the werkbank
|
|
7
7
|
// shows the state it just saved here.
|
|
8
8
|
import '../styles/story-cards.css';
|
|
@@ -26,11 +26,12 @@ import {
|
|
|
26
26
|
eventCard,
|
|
27
27
|
promoOffers,
|
|
28
28
|
seriesCards,
|
|
29
|
+
type StoriesConfig,
|
|
29
30
|
type StoryCard,
|
|
30
31
|
type StoryEvent,
|
|
31
32
|
storyFileName,
|
|
32
|
-
type StoryLookConfig,
|
|
33
33
|
type StoryOffer,
|
|
34
|
+
type StoryPromoConfig,
|
|
34
35
|
type StorySeries,
|
|
35
36
|
} from '../dist/story/cards.js';
|
|
36
37
|
import type { StoryLook } from '../dist/types.js';
|
|
@@ -41,9 +42,11 @@ interface Props extends StoryLook {
|
|
|
41
42
|
// The prices the promotion applies to - as in Price, only those with an
|
|
42
43
|
// amount.
|
|
43
44
|
offers?: readonly StoryOffer[];
|
|
44
|
-
// From stories() in maverick-wave-astro/werkbank: the
|
|
45
|
-
// Stories and every story tab with the entries
|
|
46
|
-
|
|
45
|
+
// From stories() in maverick-wave-astro/werkbank: the designs of the section
|
|
46
|
+
// Stories, the design of the promotion and every story tab with the entries
|
|
47
|
+
// of its section.
|
|
48
|
+
look?: { name: string; config: StoriesConfig };
|
|
49
|
+
promoStory?: { name: string; config: StoryPromoConfig };
|
|
47
50
|
series?: readonly StorySeries[];
|
|
48
51
|
// Path data from the site's own icon set, so the story matches the page.
|
|
49
52
|
icons?: Partial<Record<StoryIcon, string>>;
|
|
@@ -84,6 +87,7 @@ const {
|
|
|
84
87
|
offers = [],
|
|
85
88
|
series = [],
|
|
86
89
|
look: storyLook,
|
|
90
|
+
promoStory,
|
|
87
91
|
icons = {},
|
|
88
92
|
texts = {},
|
|
89
93
|
} = Astro.props;
|
|
@@ -205,6 +209,7 @@ const look: LookOptions = {
|
|
|
205
209
|
class="mwa-story-cards"
|
|
206
210
|
data-story-cards={JSON.stringify(look)}
|
|
207
211
|
data-look={JSON.stringify(storyLook ?? null)}
|
|
212
|
+
data-promo-story={JSON.stringify(promoStory ?? null)}
|
|
208
213
|
data-stories={JSON.stringify(seriesData)}
|
|
209
214
|
data-site={site}
|
|
210
215
|
data-locale={siteLocale}
|
|
@@ -245,6 +250,7 @@ const look: LookOptions = {
|
|
|
245
250
|
<script>
|
|
246
251
|
import { outOfSchedule } from '../dist/schedule.js';
|
|
247
252
|
import {
|
|
253
|
+
cardFrameFor,
|
|
248
254
|
CLASSIC,
|
|
249
255
|
type Frame,
|
|
250
256
|
frameFor,
|
|
@@ -258,12 +264,16 @@ const look: LookOptions = {
|
|
|
258
264
|
} from '../dist/story/base.js';
|
|
259
265
|
import {
|
|
260
266
|
type BlocksCard,
|
|
267
|
+
designFor,
|
|
268
|
+
designsOf,
|
|
261
269
|
seriesCards,
|
|
262
270
|
type SeriesStory,
|
|
263
271
|
seriesTexts,
|
|
272
|
+
type StoriesConfig,
|
|
264
273
|
type StoryCard,
|
|
265
274
|
storyDate,
|
|
266
275
|
type StoryLookConfig,
|
|
276
|
+
type StoryPromoConfig,
|
|
267
277
|
type StorySeries,
|
|
268
278
|
type StorySeriesConfig,
|
|
269
279
|
} from '../dist/story/cards.js';
|
|
@@ -276,6 +286,7 @@ const look: LookOptions = {
|
|
|
276
286
|
drawScene,
|
|
277
287
|
layersOf,
|
|
278
288
|
markProgress,
|
|
289
|
+
type Motion,
|
|
279
290
|
motionFor,
|
|
280
291
|
type Scene,
|
|
281
292
|
sceneOf,
|
|
@@ -289,9 +300,16 @@ const look: LookOptions = {
|
|
|
289
300
|
const seriesData = JSON.parse(root?.dataset.stories ?? '{}') as SeriesData;
|
|
290
301
|
const lookSection = JSON.parse(root?.dataset.look ?? 'null') as {
|
|
291
302
|
name: string;
|
|
292
|
-
config:
|
|
303
|
+
config: StoriesConfig;
|
|
293
304
|
} | null;
|
|
294
|
-
|
|
305
|
+
const promoSection = JSON.parse(root?.dataset.promoStory ?? 'null') as {
|
|
306
|
+
name: string;
|
|
307
|
+
config: StoryPromoConfig;
|
|
308
|
+
} | null;
|
|
309
|
+
let designs = designsOf(lookSection?.config);
|
|
310
|
+
let promoDesign = promoSection?.config.design;
|
|
311
|
+
// The samples of the preview, one per design.
|
|
312
|
+
const sampleDesigns = new Map<string, StoryLookConfig>();
|
|
295
313
|
|
|
296
314
|
// The werkbank sends the saved state of one section in the hash - never to
|
|
297
315
|
// the server, so no request line gets too long and no log keeps it.
|
|
@@ -303,11 +321,19 @@ const look: LookOptions = {
|
|
|
303
321
|
atob(value.replace(/-/g, '+').replace(/_/g, '/')),
|
|
304
322
|
char => char.charCodeAt(0)
|
|
305
323
|
);
|
|
306
|
-
const { section, content } = JSON.parse(
|
|
324
|
+
const { section, content, look } = JSON.parse(
|
|
325
|
+
new TextDecoder().decode(bytes)
|
|
326
|
+
);
|
|
307
327
|
return typeof section === 'string' &&
|
|
308
328
|
content &&
|
|
309
329
|
typeof content === 'object'
|
|
310
|
-
? {
|
|
330
|
+
? {
|
|
331
|
+
section,
|
|
332
|
+
content: content as Record<string, unknown>,
|
|
333
|
+
// With a story tab the designs as saved, published or not.
|
|
334
|
+
look:
|
|
335
|
+
look && typeof look === 'object' ? (look as StoriesConfig) : null,
|
|
336
|
+
}
|
|
311
337
|
: null;
|
|
312
338
|
} catch {
|
|
313
339
|
return null;
|
|
@@ -396,32 +422,58 @@ const look: LookOptions = {
|
|
|
396
422
|
).slice(0, count);
|
|
397
423
|
};
|
|
398
424
|
|
|
399
|
-
// The
|
|
400
|
-
//
|
|
401
|
-
// the
|
|
425
|
+
// The designs show on a sample each, with the name of the design on top, and
|
|
426
|
+
// on the first story of every series and the first running event and
|
|
427
|
+
// promotion. A story tab shows on all the stories of its section, the tab of
|
|
428
|
+
// the offers on the promotion. The rest of the page stays out of the preview.
|
|
402
429
|
const showPreview = (
|
|
403
430
|
container: HTMLElement,
|
|
404
|
-
{ section, content }: NonNullable<ReturnType<typeof readPreview>>
|
|
431
|
+
{ section, content, look }: NonNullable<ReturnType<typeof readPreview>>
|
|
405
432
|
) => {
|
|
406
433
|
container.classList.add('mwa-story-cards-preview');
|
|
434
|
+
if (look) designs = designsOf(look);
|
|
407
435
|
const isLook = section === lookSection?.name;
|
|
408
|
-
|
|
436
|
+
const isPromo = section === promoSection?.name;
|
|
437
|
+
if (isLook) designs = designsOf(content as StoriesConfig);
|
|
438
|
+
else if (isPromo) promoDesign = (content as StoryPromoConfig).design;
|
|
409
439
|
else if (seriesData[section]) {
|
|
410
440
|
seriesData[section].config = content as StorySeriesConfig;
|
|
411
441
|
}
|
|
412
|
-
container.querySelectorAll('[data-story]')
|
|
413
|
-
const
|
|
442
|
+
const all = [...container.querySelectorAll<HTMLElement>('[data-story]')];
|
|
443
|
+
const firstOf = (kind: StoryCard['kind']) =>
|
|
444
|
+
all.find(
|
|
445
|
+
el =>
|
|
446
|
+
(JSON.parse(el.dataset.story ?? '{}') as StoryCard).kind === kind &&
|
|
447
|
+
!outOfSchedule(el.dataset, new Date())
|
|
448
|
+
);
|
|
449
|
+
const kept = isLook
|
|
450
|
+
? [firstOf('event'), firstOf('promo')]
|
|
451
|
+
: isPromo
|
|
452
|
+
? [firstOf('promo')]
|
|
453
|
+
: [];
|
|
454
|
+
all.forEach(el => el.remove());
|
|
455
|
+
const names = isLook ? Object.keys(seriesData) : isPromo ? [] : [section];
|
|
414
456
|
const empty = container.querySelector('[data-story-empty]');
|
|
415
457
|
if (isLook) {
|
|
416
458
|
const sample = sampleStory(container.dataset.locale ?? 'de-DE');
|
|
417
|
-
|
|
418
|
-
|
|
459
|
+
(designs.length > 0 ? designs : [{}]).forEach((design, index) => {
|
|
460
|
+
const name = `${SAMPLE}-${index}`;
|
|
461
|
+
const kicker = design.name?.trim() || sample.config.kicker;
|
|
462
|
+
seriesData[name] = {
|
|
463
|
+
config: { ...sample.config, kicker },
|
|
464
|
+
items: [],
|
|
465
|
+
fields: {},
|
|
466
|
+
};
|
|
467
|
+
sampleDesigns.set(name, design);
|
|
468
|
+
empty?.before(cardElement(sample.story, name));
|
|
469
|
+
});
|
|
419
470
|
}
|
|
420
471
|
for (const name of names.filter(name => seriesData[name])) {
|
|
421
472
|
for (const story of previewCards(name, container, isLook ? 1 : 30)) {
|
|
422
473
|
empty?.before(cardElement(story, name));
|
|
423
474
|
}
|
|
424
475
|
}
|
|
476
|
+
for (const el of kept) if (el) empty?.before(el);
|
|
425
477
|
// Saving again changes only the hash - the frame stays, the story redraws.
|
|
426
478
|
addEventListener('hashchange', () => location.reload());
|
|
427
479
|
};
|
|
@@ -511,19 +563,44 @@ const look: LookOptions = {
|
|
|
511
563
|
const look = await loadLook(
|
|
512
564
|
JSON.parse(root.dataset.storyCards ?? '{}') as LookOptions
|
|
513
565
|
);
|
|
514
|
-
// A
|
|
515
|
-
|
|
566
|
+
// A design that does not parse takes the defaults instead of the page.
|
|
567
|
+
function safely<T>(make: () => T, fallback: T): T {
|
|
516
568
|
try {
|
|
517
|
-
return
|
|
569
|
+
return make();
|
|
518
570
|
} catch (error) {
|
|
519
571
|
console.warn('Story look:', error);
|
|
520
|
-
return
|
|
572
|
+
return fallback;
|
|
521
573
|
}
|
|
522
|
-
}
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
// A series takes the design its tab picked, the promotion the one of the
|
|
577
|
+
// offers' tab, an event card the first.
|
|
578
|
+
const designOf = (card: StoryCard, series = '') =>
|
|
579
|
+
card.kind === 'blocks'
|
|
580
|
+
? (sampleDesigns.get(series) ??
|
|
581
|
+
designFor(designs, seriesData[series]?.config.design))
|
|
582
|
+
: designFor(designs, card.kind === 'promo' ? promoDesign : undefined);
|
|
583
|
+
|
|
584
|
+
const plans = stories.map(el => {
|
|
585
|
+
const card = JSON.parse(el.dataset.story ?? '{}') as StoryCard;
|
|
586
|
+
const design = designOf(card, el.dataset.series);
|
|
587
|
+
const blocks = card.kind === 'blocks';
|
|
588
|
+
return {
|
|
589
|
+
el,
|
|
590
|
+
card,
|
|
591
|
+
design,
|
|
592
|
+
frame: safely(
|
|
593
|
+
() => (blocks ? frameFor(design) : cardFrameFor(design)),
|
|
594
|
+
blocks ? frameFor() : CLASSIC
|
|
595
|
+
),
|
|
596
|
+
motion: safely(() => motionFor(design), null),
|
|
597
|
+
};
|
|
598
|
+
});
|
|
523
599
|
// The preview only plays the video. The page hands out the file, so it
|
|
524
600
|
// needs an H.264 encoder - without one the stories stay images.
|
|
525
|
-
const encoders =
|
|
526
|
-
|
|
601
|
+
const encoders =
|
|
602
|
+
!preview && plans.some(plan => plan.motion) ? await videoConfigs() : [];
|
|
603
|
+
const playable = preview || encoders.length > 0;
|
|
527
604
|
const label = (canShare ? root.dataset.share : root.dataset.save) ?? '';
|
|
528
605
|
const videoLabel =
|
|
529
606
|
(canShareVideo ? root.dataset.shareVideo : root.dataset.saveVideo) ?? '';
|
|
@@ -534,7 +611,9 @@ const look: LookOptions = {
|
|
|
534
611
|
canvas: HTMLCanvasElement;
|
|
535
612
|
ctx: CanvasRenderingContext2D | null;
|
|
536
613
|
card: StoryCard;
|
|
614
|
+
design: StoryLookConfig;
|
|
537
615
|
frame: Frame;
|
|
616
|
+
motion: Motion | null;
|
|
538
617
|
texts: SeriesTexts;
|
|
539
618
|
moves: boolean;
|
|
540
619
|
state: 'waiting' | 'preparing' | 'ready' | 'failed';
|
|
@@ -547,12 +626,11 @@ const look: LookOptions = {
|
|
|
547
626
|
stillButton?: HTMLButtonElement;
|
|
548
627
|
}
|
|
549
628
|
|
|
550
|
-
// Event and promotion keep the frame from before there were designs.
|
|
551
629
|
const piecesOf = (ctx: CanvasRenderingContext2D, story: Story) =>
|
|
552
630
|
story.card.kind === 'promo'
|
|
553
|
-
? promoPieces(ctx, story.card, look)
|
|
631
|
+
? promoPieces(ctx, story.card, look, story.frame)
|
|
554
632
|
: story.card.kind === 'event'
|
|
555
|
-
? eventPieces(ctx, story.card, look)
|
|
633
|
+
? eventPieces(ctx, story.card, look, story.frame)
|
|
556
634
|
: blockPieces(ctx, story.card, look, story.frame, story.texts);
|
|
557
635
|
|
|
558
636
|
const paintStill = (story: Story) => {
|
|
@@ -612,9 +690,9 @@ const look: LookOptions = {
|
|
|
612
690
|
const layout = scratch.getContext('2d', { willReadFrequently: true });
|
|
613
691
|
|
|
614
692
|
const build = (story: Story) => {
|
|
615
|
-
if (!layout || !
|
|
693
|
+
if (!layout || !story.motion) throw new Error('Story video: no canvas');
|
|
616
694
|
const pieces = piecesOf(layout, story);
|
|
617
|
-
return sceneOf(look, story.frame,
|
|
695
|
+
return sceneOf(look, story.frame, story.motion, layersOf(layout, pieces));
|
|
618
696
|
};
|
|
619
697
|
|
|
620
698
|
// The last frame stands this long before the story starts over.
|
|
@@ -775,11 +853,10 @@ const look: LookOptions = {
|
|
|
775
853
|
{ threshold: 0.4 }
|
|
776
854
|
);
|
|
777
855
|
|
|
778
|
-
for (const el of
|
|
856
|
+
for (const { el, card, design, frame, motion } of plans) {
|
|
779
857
|
const canvas = el.querySelector('canvas');
|
|
780
858
|
const stage = canvas?.parentElement;
|
|
781
859
|
if (!canvas || !stage) continue;
|
|
782
|
-
const card = JSON.parse(el.dataset.story ?? '{}') as StoryCard;
|
|
783
860
|
const button = el.querySelector<HTMLButtonElement>('[data-story-save]');
|
|
784
861
|
if (preview) button?.remove();
|
|
785
862
|
const story: Story = {
|
|
@@ -788,9 +865,11 @@ const look: LookOptions = {
|
|
|
788
865
|
canvas,
|
|
789
866
|
ctx: null,
|
|
790
867
|
card,
|
|
791
|
-
|
|
868
|
+
design,
|
|
869
|
+
frame,
|
|
870
|
+
motion: playable ? motion : null,
|
|
792
871
|
texts: seriesTexts(seriesData[el.dataset.series ?? '']?.config ?? {}),
|
|
793
|
-
moves: Boolean(
|
|
872
|
+
moves: playable && Boolean(motion),
|
|
794
873
|
state: 'waiting',
|
|
795
874
|
scene: null,
|
|
796
875
|
visible: false,
|
|
@@ -852,11 +931,12 @@ const look: LookOptions = {
|
|
|
852
931
|
background: 'Background',
|
|
853
932
|
};
|
|
854
933
|
const CONTENT = new Set(['tile', 'row', 'heading', 'text', 'price']);
|
|
855
|
-
// Fields of
|
|
856
|
-
//
|
|
934
|
+
// Fields of a design and of a story tab, by their name - JSON pointers as
|
|
935
|
+
// the werkbank has them, like /blocks/2/source or /designs/1/logo.
|
|
857
936
|
const PARTS: Record<string, readonly string[]> = {
|
|
937
|
+
name: ['kicker'],
|
|
938
|
+
design: ['area'],
|
|
858
939
|
blocks: ['blocks'],
|
|
859
|
-
contentIn: ['blocks'],
|
|
860
940
|
showKicker: ['kicker'],
|
|
861
941
|
kicker: ['kicker'],
|
|
862
942
|
showFooter: ['call'],
|
|
@@ -866,12 +946,10 @@ const look: LookOptions = {
|
|
|
866
946
|
footerOffset: ['call', 'reply'],
|
|
867
947
|
logo: ['logo'],
|
|
868
948
|
logoOffset: ['logo'],
|
|
869
|
-
logoIn: ['logo'],
|
|
870
949
|
align: ['area'],
|
|
871
950
|
areaWidth: ['area'],
|
|
872
951
|
areaHeight: ['area'],
|
|
873
952
|
areaPosition: ['area'],
|
|
874
|
-
areaIn: ['area'],
|
|
875
953
|
background: ['background'],
|
|
876
954
|
color: ['background'],
|
|
877
955
|
colorBottom: ['background'],
|
|
@@ -882,12 +960,20 @@ const look: LookOptions = {
|
|
|
882
960
|
all: false,
|
|
883
961
|
};
|
|
884
962
|
|
|
963
|
+
// A field of a design marks only the stories in that design.
|
|
885
964
|
const targetOf = (path: string | null) => {
|
|
886
|
-
const [, first = '', index = ''] = (path ?? '').split('/');
|
|
887
|
-
|
|
888
|
-
|
|
965
|
+
const [, first = '', index = '', field = ''] = (path ?? '').split('/');
|
|
966
|
+
const numbered = /^\d+$/.test(index);
|
|
967
|
+
if (first === 'designs' && numbered) {
|
|
968
|
+
return {
|
|
969
|
+
refs: new Set(PARTS[field] ?? []),
|
|
970
|
+
design: designs[Number(index)],
|
|
971
|
+
};
|
|
972
|
+
}
|
|
973
|
+
if (first === 'blocks' && numbered) {
|
|
974
|
+
return { refs: new Set([`block:${index}`]) };
|
|
889
975
|
}
|
|
890
|
-
return new Set(PARTS[first] ?? []);
|
|
976
|
+
return { refs: new Set(PARTS[first] ?? []) };
|
|
891
977
|
};
|
|
892
978
|
const refsOf = (piece: Piece) => [
|
|
893
979
|
piece.kind,
|
|
@@ -900,16 +986,18 @@ const look: LookOptions = {
|
|
|
900
986
|
: (NAMES[piece.kind] ?? null);
|
|
901
987
|
|
|
902
988
|
const percent = (value: number, of: number) => `${(value / of) * 100}%`;
|
|
989
|
+
let inView: StoryLookConfig | undefined;
|
|
903
990
|
const mark = () => {
|
|
904
991
|
const target = targetOf(wanted.path);
|
|
905
992
|
for (const story of all.values()) {
|
|
993
|
+
const mine = !target.design || story.design === target.design;
|
|
906
994
|
story.stage.querySelector('.mwa-story-marks')?.remove();
|
|
907
995
|
const layer = document.createElement('div');
|
|
908
996
|
layer.className = 'mwa-story-marks';
|
|
909
997
|
layer.setAttribute('aria-hidden', 'true');
|
|
910
998
|
for (const piece of piecesOf(layout, story)) {
|
|
911
999
|
const label = labelOf(piece);
|
|
912
|
-
const hit = refsOf(piece).some(ref => target.has(ref));
|
|
1000
|
+
const hit = mine && refsOf(piece).some(ref => target.refs.has(ref));
|
|
913
1001
|
if (
|
|
914
1002
|
!label ||
|
|
915
1003
|
!(hit || (wanted.all && piece.kind !== 'background'))
|
|
@@ -932,6 +1020,20 @@ const look: LookOptions = {
|
|
|
932
1020
|
}
|
|
933
1021
|
story.stage.append(layer);
|
|
934
1022
|
}
|
|
1023
|
+
// A field of a later design brings its sample into view - the first
|
|
1024
|
+
// story on top would show the change nowhere.
|
|
1025
|
+
if (target.design && target.design !== inView) {
|
|
1026
|
+
const own = [...all.values()].find(
|
|
1027
|
+
story => story.design === target.design
|
|
1028
|
+
);
|
|
1029
|
+
const box = own?.stage.getBoundingClientRect();
|
|
1030
|
+
if (box) {
|
|
1031
|
+
scrollTo({
|
|
1032
|
+
top: scrollY + box.top - (innerHeight - box.height) / 2,
|
|
1033
|
+
});
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
inView = target.design;
|
|
935
1037
|
};
|
|
936
1038
|
|
|
937
1039
|
addEventListener('message', event => {
|
package/dist/content.d.ts
CHANGED
|
@@ -6,8 +6,10 @@ export type StorySource = {
|
|
|
6
6
|
fields: Readonly<Record<string, FieldKind>>;
|
|
7
7
|
};
|
|
8
8
|
export type StorySections = {
|
|
9
|
-
/** The section with the
|
|
9
|
+
/** The section with the designs every story picks from. */
|
|
10
10
|
look?: string;
|
|
11
|
+
/** The story tab that picks the design of the promotion. */
|
|
12
|
+
promo?: string;
|
|
11
13
|
series: readonly StorySource[];
|
|
12
14
|
};
|
|
13
15
|
export type Sections = Readonly<Record<string, Readonly<Record<string, unknown>>>>;
|
package/dist/content.js
CHANGED
|
@@ -5,6 +5,7 @@ const MANIFEST = 'werkbank/struktur.json';
|
|
|
5
5
|
const BUILT = 'src/content/werkbank';
|
|
6
6
|
const STORY_LOOK = 'maverick-wave-astro/schemas/story-look.schema.json';
|
|
7
7
|
const STORY_BLOCKS = 'maverick-wave-astro/schemas/story-blocks.schema.json';
|
|
8
|
+
const STORY_PROMO = 'maverick-wave-astro/schemas/story-promo.schema.json';
|
|
8
9
|
// The same rule as in the werkbank, which offers these fields as the source of
|
|
9
10
|
// a block: text and numbers, but no choice, picture or colour.
|
|
10
11
|
const fieldKind = (field) => {
|
|
@@ -52,9 +53,10 @@ export const loadWerkbank = (root) => {
|
|
|
52
53
|
for (const { schluessel, schema, start } of manifest.bereiche) {
|
|
53
54
|
schemas[schluessel] = schema;
|
|
54
55
|
const built = path.join(root, BUILT, `${schluessel}.json`);
|
|
56
|
+
// Watched before it exists: the first publish creates it under a running dev server
|
|
57
|
+
files.push(built);
|
|
55
58
|
if (existsSync(built)) {
|
|
56
59
|
sections[schluessel] = readJson(built);
|
|
57
|
-
files.push(built);
|
|
58
60
|
continue;
|
|
59
61
|
}
|
|
60
62
|
fromStart.push(schluessel);
|
|
@@ -81,14 +83,20 @@ export const loadWerkbank = (root) => {
|
|
|
81
83
|
fields: entryFields(readJson(schemaFile), liste),
|
|
82
84
|
};
|
|
83
85
|
});
|
|
84
|
-
const
|
|
86
|
+
const sectionOf = (ending) => manifest.bereiche.find(({ schema }) => schema.endsWith(ending))?.schluessel;
|
|
87
|
+
const look = sectionOf(STORY_LOOK);
|
|
88
|
+
const promo = sectionOf(STORY_PROMO);
|
|
85
89
|
return {
|
|
86
90
|
languages,
|
|
87
91
|
sections,
|
|
88
92
|
schemas,
|
|
89
93
|
fromStart,
|
|
90
94
|
files,
|
|
91
|
-
stories: {
|
|
95
|
+
stories: {
|
|
96
|
+
...(look ? { look } : {}),
|
|
97
|
+
...(promo ? { promo } : {}),
|
|
98
|
+
series,
|
|
99
|
+
},
|
|
92
100
|
};
|
|
93
101
|
};
|
|
94
102
|
export const pick = (werkbank, section, lang) => {
|
package/dist/integration.js
CHANGED
package/dist/story/base.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { StoryLook } from '../types.ts';
|
|
2
|
-
import { type StoryLookConfig } from './cards.ts';
|
|
2
|
+
import { STEP, type StoryLookConfig } from './cards.ts';
|
|
3
3
|
export declare const WIDTH = 1080;
|
|
4
4
|
export declare const HEIGHT = 1920;
|
|
5
5
|
export declare const PADDING = 76;
|
|
@@ -12,7 +12,7 @@ declare const MARGINS: {
|
|
|
12
12
|
readonly normal: 80;
|
|
13
13
|
readonly wide: 30;
|
|
14
14
|
};
|
|
15
|
-
export
|
|
15
|
+
export { STEP };
|
|
16
16
|
export declare const LOGO_STEPS: readonly [-15, 30];
|
|
17
17
|
export declare const FOOTER_STEPS: readonly [-20, 10];
|
|
18
18
|
type Surface = 'card' | 'square' | 'round' | 'outline' | 'band' | 'glass' | 'none';
|
|
@@ -45,6 +45,7 @@ export interface Frame extends Pick<Design, 'background' | 'logo' | 'align' | 's
|
|
|
45
45
|
}
|
|
46
46
|
export declare const choice: <T extends string>(value: unknown, allowed: readonly T[], fallback: T) => T;
|
|
47
47
|
export declare const frameFor: (look?: StoryLookConfig) => Frame;
|
|
48
|
+
export declare const cardFrameFor: (look?: StoryLookConfig) => Frame;
|
|
48
49
|
export declare const CLASSIC: Frame;
|
|
49
50
|
type Rgb = readonly [number, number, number];
|
|
50
51
|
export type StoryIcon = 'calendar' | 'clock' | 'location' | 'sparkle';
|
|
@@ -212,12 +213,7 @@ export interface Ink {
|
|
|
212
213
|
fade: string;
|
|
213
214
|
icons: Look['icons'];
|
|
214
215
|
}
|
|
216
|
+
export declare const onDarkGround: (frame: Frame) => boolean;
|
|
215
217
|
export declare const inkFor: (look: Look, frame: Frame) => Ink;
|
|
216
218
|
export declare const footerPieces: (ctx: CanvasRenderingContext2D, look: Look, frame: Frame, call?: string, reply?: string) => Piece[];
|
|
217
219
|
export declare const markPreview: (ctx: CanvasRenderingContext2D, look: Look) => void;
|
|
218
|
-
export declare const storyPieces: (ctx: CanvasRenderingContext2D, look: Look, { kicker, footer, content, }: {
|
|
219
|
-
kicker?: string;
|
|
220
|
-
footer?: string;
|
|
221
|
-
content: (card: Stage) => Piece[];
|
|
222
|
-
}) => Piece[];
|
|
223
|
-
export {};
|
package/dist/story/base.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { STORY_DESIGNS, } from "./cards.js";
|
|
1
|
+
import { STEP, STORY_DESIGNS, } from "./cards.js";
|
|
2
2
|
export const WIDTH = 1080;
|
|
3
3
|
export const HEIGHT = 1920;
|
|
4
4
|
// Instagram and WhatsApp put their own controls over the top and bottom of the
|
|
@@ -31,7 +31,7 @@ const MIN_CARD_HEIGHT = 760;
|
|
|
31
31
|
// a badge in the dark of the gradient.
|
|
32
32
|
const BADGE_PADDING = 26;
|
|
33
33
|
const MARGINS = { narrow: 140, normal: 80, wide: 30 };
|
|
34
|
-
export
|
|
34
|
+
export { STEP };
|
|
35
35
|
// From the top the logo may go up to 40px below the edge, the footer up to
|
|
36
36
|
// 160px below where Instagram starts covering it.
|
|
37
37
|
export const LOGO_STEPS = [-15, 30];
|
|
@@ -165,8 +165,15 @@ export const frameFor = (look = {}) => {
|
|
|
165
165
|
...sized(MARGINS[width]),
|
|
166
166
|
};
|
|
167
167
|
};
|
|
168
|
-
//
|
|
169
|
-
|
|
168
|
+
// Event and promo cards take the look as well, only at the normal width they
|
|
169
|
+
// keep their own margin - so with the look left alone they stay as they were.
|
|
170
|
+
export const cardFrameFor = (look = {}) => {
|
|
171
|
+
const frame = frameFor(look);
|
|
172
|
+
return frame.margin === MARGINS.normal
|
|
173
|
+
? { ...frame, ...sized(MARGIN) }
|
|
174
|
+
: frame;
|
|
175
|
+
};
|
|
176
|
+
export const CLASSIC = cardFrameFor();
|
|
170
177
|
const ACCENT_STROKE = mw(2);
|
|
171
178
|
const ACCENT_STRETCH = 1.5;
|
|
172
179
|
const ACCENT_OPAQUE = 0.55;
|
|
@@ -484,9 +491,11 @@ export const textBlock = (ctx, text, style, gap, { x = LEFT, maxWidth = CONTENT_
|
|
|
484
491
|
tries[tries.length - 1];
|
|
485
492
|
ctx.font = style.font(size);
|
|
486
493
|
const lines = clampLines(ctx, wrapped, style.maxLines, maxWidth);
|
|
494
|
+
const width = Math.max(0, ...lines.map(line => ctx.measureText(line).width));
|
|
487
495
|
spaced(ctx, 0);
|
|
488
496
|
const lineHeight = Math.round(size * style.lineHeight);
|
|
489
497
|
return {
|
|
498
|
+
width,
|
|
490
499
|
height: lines.length * lineHeight,
|
|
491
500
|
gap,
|
|
492
501
|
paint: y => {
|
|
@@ -901,11 +910,13 @@ const accentOnBackground = (look, frame) => {
|
|
|
901
910
|
? look.colors.secondary
|
|
902
911
|
: '#ffffff';
|
|
903
912
|
};
|
|
913
|
+
// Without a white area, on a background that is not white either.
|
|
914
|
+
export const onDarkGround = (frame) => (frame.surface === 'none' || frame.surface === 'glass') &&
|
|
915
|
+
frame.background !== 'light';
|
|
904
916
|
// Text on the white area takes the colours of the page. Straight on a dark
|
|
905
917
|
// background it turns white, the secondary colour stays where it still reads.
|
|
906
918
|
export const inkFor = (look, frame) => {
|
|
907
|
-
|
|
908
|
-
if (!onGround || frame.background === 'light') {
|
|
919
|
+
if (!onDarkGround(frame)) {
|
|
909
920
|
return {
|
|
910
921
|
text: look.colors.text,
|
|
911
922
|
primary: look.colors.accentText,
|
|
@@ -1005,27 +1016,3 @@ export const markPreview = (ctx, look) => {
|
|
|
1005
1016
|
}, CARD_WIDTH);
|
|
1006
1017
|
label.paint((WIDTH - label.width) / 2, 70);
|
|
1007
1018
|
};
|
|
1008
|
-
// Everything around the content: background, logo and kicker, the card with
|
|
1009
|
-
// its silhouette, the call to action. The content brings its own pieces.
|
|
1010
|
-
export const storyPieces = (ctx, look, { kicker, footer, content, }) => {
|
|
1011
|
-
const placement = place(look, CLASSIC, kicker);
|
|
1012
|
-
const card = placement.stage;
|
|
1013
|
-
return [
|
|
1014
|
-
{
|
|
1015
|
-
kind: 'background',
|
|
1016
|
-
box: { x: 0, y: 0, width: WIDTH, height: HEIGHT },
|
|
1017
|
-
paint: () => drawBackground(ctx, look, CLASSIC),
|
|
1018
|
-
},
|
|
1019
|
-
...topBarPieces(ctx, look, CLASSIC, placement, kicker),
|
|
1020
|
-
{
|
|
1021
|
-
kind: 'area',
|
|
1022
|
-
box: { x: MARGIN, y: card.top, width: CARD_WIDTH, height: card.height },
|
|
1023
|
-
paint: () => {
|
|
1024
|
-
drawSurface(ctx, look, MARGIN, card.top, CARD_WIDTH, card.height);
|
|
1025
|
-
drawAccent(ctx, look, MARGIN, card.top, CARD_WIDTH, card.height);
|
|
1026
|
-
},
|
|
1027
|
-
},
|
|
1028
|
-
...content(card),
|
|
1029
|
-
...footerPieces(ctx, look, CLASSIC, footer, look.texts.reply),
|
|
1030
|
-
];
|
|
1031
|
-
};
|