@matterandmotion/emdash-comics 0.0.0-stage → 0.1.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 +114 -2
- package/dist/batches.d.ts +84 -0
- package/dist/batches.d.ts.map +1 -0
- package/dist/batches.js +101 -0
- package/dist/batches.js.map +1 -0
- package/dist/blocks.d.ts +26 -0
- package/dist/blocks.d.ts.map +1 -0
- package/dist/blocks.js +45 -0
- package/dist/blocks.js.map +1 -0
- package/dist/id.d.ts +3 -0
- package/dist/id.d.ts.map +1 -0
- package/dist/id.js +3 -0
- package/dist/id.js.map +1 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +122 -0
- package/dist/index.js.map +1 -0
- package/dist/legacy-redirects.d.ts +15 -0
- package/dist/legacy-redirects.d.ts.map +1 -0
- package/dist/legacy-redirects.js +58 -0
- package/dist/legacy-redirects.js.map +1 -0
- package/dist/media.d.ts +26 -0
- package/dist/media.d.ts.map +1 -0
- package/dist/media.js +48 -0
- package/dist/media.js.map +1 -0
- package/dist/transcripts.d.ts +10 -0
- package/dist/transcripts.d.ts.map +1 -0
- package/dist/transcripts.js +22 -0
- package/dist/transcripts.js.map +1 -0
- package/package.json +67 -3
- package/profile/index.d.mts +46 -0
- package/profile/index.mjs +197 -0
- package/src/admin/BulkUploadPage.tsx +1004 -0
- package/src/admin/ComicPagesField.tsx +202 -0
- package/src/admin/bulk/api.ts +215 -0
- package/src/admin/bulk/config.ts +87 -0
- package/src/admin/bulk/files.ts +76 -0
- package/src/admin/bulk/history.ts +45 -0
- package/src/admin/bulk/plan.ts +446 -0
- package/src/admin/fingerprint.ts +26 -0
- package/src/admin/index.tsx +19 -0
- package/src/admin/media.ts +75 -0
- package/src/admin/pickers.tsx +132 -0
- package/src/admin/segments.ts +36 -0
- package/src/admin/slice.ts +46 -0
- package/src/admin/types.ts +47 -0
- package/src/astro/AgeGate.astro +85 -0
- package/src/astro/ArchiveGrid.astro +79 -0
- package/src/astro/CastGrid.astro +63 -0
- package/src/astro/ChapterList.astro +57 -0
- package/src/astro/CharacterCard.astro +54 -0
- package/src/astro/ComicEmbed.astro +55 -0
- package/src/astro/ComicNav.astro +131 -0
- package/src/astro/ComicReader.astro +193 -0
- package/src/astro/ContentWarnings.astro +61 -0
- package/src/astro/Transcript.astro +43 -0
- package/src/astro/astro-modules.d.ts +6 -0
- package/src/astro/blocks.ts +11 -0
- package/src/astro/index.ts +20 -0
- package/src/batches.ts +154 -0
- package/src/blocks.ts +46 -0
- package/src/id.ts +2 -0
- package/src/index.ts +152 -0
- package/src/legacy-redirects.ts +59 -0
- package/src/media.ts +60 -0
- package/src/transcripts.ts +20 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Planning the slices of a tall strip. EmDash doesn't transform images taller
|
|
3
|
+
* than 4000 px (V3), so long webtoon strips are stored as several pages of at
|
|
4
|
+
* most 4000 px each, split into equal heights so no sliver is left over.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export const MAX_SEGMENT_HEIGHT = 4000;
|
|
8
|
+
|
|
9
|
+
export interface Segment {
|
|
10
|
+
y: number;
|
|
11
|
+
height: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function planSegments(height: number, max = MAX_SEGMENT_HEIGHT): Segment[] {
|
|
15
|
+
if (!Number.isFinite(height) || height <= 0) return [];
|
|
16
|
+
if (height <= max) return [{ y: 0, height }];
|
|
17
|
+
const count = Math.ceil(height / max);
|
|
18
|
+
const base = Math.floor(height / count);
|
|
19
|
+
const segments: Segment[] = [];
|
|
20
|
+
let y = 0;
|
|
21
|
+
for (let index = 0; index < count; index++) {
|
|
22
|
+
// The last segment takes the remainder of the integer division.
|
|
23
|
+
const segmentHeight = index === count - 1 ? height - y : base;
|
|
24
|
+
segments.push({ y, height: segmentHeight });
|
|
25
|
+
y += segmentHeight;
|
|
26
|
+
}
|
|
27
|
+
return segments;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** "strip.png", 2, 3 → "strip-2-of-3.png" */
|
|
31
|
+
export function segmentFilename(filename: string, index: number, total: number): string {
|
|
32
|
+
const dot = filename.lastIndexOf(".");
|
|
33
|
+
const base = dot > 0 ? filename.slice(0, dot) : filename;
|
|
34
|
+
const extension = dot > 0 ? filename.slice(dot) : "";
|
|
35
|
+
return `${base}-${index + 1}-of-${total}${extension}`;
|
|
36
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { MAX_SEGMENT_HEIGHT, planSegments, segmentFilename } from "./segments.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Splits an image taller than `max` pixels into equal segments in the browser,
|
|
5
|
+
* before upload. GIFs (which may be animated) and SVGs are left whole.
|
|
6
|
+
*/
|
|
7
|
+
export async function splitTallImage(file: File, max = MAX_SEGMENT_HEIGHT): Promise<File[]> {
|
|
8
|
+
if (
|
|
9
|
+
!file.type.startsWith("image/") ||
|
|
10
|
+
file.type === "image/gif" ||
|
|
11
|
+
file.type === "image/svg+xml"
|
|
12
|
+
) {
|
|
13
|
+
return [file];
|
|
14
|
+
}
|
|
15
|
+
const bitmap = await createImageBitmap(file);
|
|
16
|
+
try {
|
|
17
|
+
const segments = planSegments(bitmap.height, max);
|
|
18
|
+
if (segments.length <= 1) return [file];
|
|
19
|
+
const type = file.type === "image/jpeg" || file.type === "image/webp" ? file.type : "image/png";
|
|
20
|
+
const parts: File[] = [];
|
|
21
|
+
for (const [index, segment] of segments.entries()) {
|
|
22
|
+
const canvas = document.createElement("canvas");
|
|
23
|
+
canvas.width = bitmap.width;
|
|
24
|
+
canvas.height = segment.height;
|
|
25
|
+
const context = canvas.getContext("2d");
|
|
26
|
+
if (!context) throw new Error("This browser can't slice images (no canvas).");
|
|
27
|
+
context.drawImage(
|
|
28
|
+
bitmap,
|
|
29
|
+
0,
|
|
30
|
+
segment.y,
|
|
31
|
+
bitmap.width,
|
|
32
|
+
segment.height,
|
|
33
|
+
0,
|
|
34
|
+
0,
|
|
35
|
+
bitmap.width,
|
|
36
|
+
segment.height,
|
|
37
|
+
);
|
|
38
|
+
const blob = await new Promise<Blob | null>((resolve) => canvas.toBlob(resolve, type, 0.92));
|
|
39
|
+
if (!blob) throw new Error(`Couldn't slice ${file.name}.`);
|
|
40
|
+
parts.push(new File([blob], segmentFilename(file.name, index, segments.length), { type }));
|
|
41
|
+
}
|
|
42
|
+
return parts;
|
|
43
|
+
} finally {
|
|
44
|
+
bitmap.close();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** Props EmDash passes to a plugin field widget (`fields` export of the admin entry). */
|
|
2
|
+
export interface FieldWidgetProps {
|
|
3
|
+
value: unknown;
|
|
4
|
+
onChange: (value: unknown) => void;
|
|
5
|
+
label: string;
|
|
6
|
+
id: string;
|
|
7
|
+
required?: boolean;
|
|
8
|
+
options?: Record<string, unknown> | Array<{ value: string; label: string }>;
|
|
9
|
+
validation?: Record<string, unknown>;
|
|
10
|
+
minimal?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** One comic page, as stored in the `pages` repeater. */
|
|
14
|
+
export interface PageItem {
|
|
15
|
+
image: ImageValue | null;
|
|
16
|
+
alt: string;
|
|
17
|
+
transcript: string;
|
|
18
|
+
hovertext: string;
|
|
19
|
+
/** Fingerprint of the file the page came from (see fingerprint.ts). */
|
|
20
|
+
sourceHash?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** The value EmDash's image fields store. */
|
|
24
|
+
export interface ImageValue {
|
|
25
|
+
id: string;
|
|
26
|
+
provider?: string;
|
|
27
|
+
src?: string;
|
|
28
|
+
previewUrl?: string;
|
|
29
|
+
alt?: string;
|
|
30
|
+
width?: number;
|
|
31
|
+
height?: number;
|
|
32
|
+
filename?: string;
|
|
33
|
+
mimeType?: string;
|
|
34
|
+
blurhash?: string;
|
|
35
|
+
dominantColor?: string;
|
|
36
|
+
meta?: Record<string, unknown>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Reads a string option from the widget's schema `options`. */
|
|
40
|
+
export function stringOption(
|
|
41
|
+
options: FieldWidgetProps["options"],
|
|
42
|
+
key: string,
|
|
43
|
+
): string | undefined {
|
|
44
|
+
if (!options || Array.isArray(options)) return undefined;
|
|
45
|
+
const value = options[key];
|
|
46
|
+
return typeof value === "string" && value ? value : undefined;
|
|
47
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* A soft, client-side age gate for mature series: an overlay asks readers to
|
|
4
|
+
* confirm their age and remembers the answer in the browser. It's a courtesy,
|
|
5
|
+
* not access control: search engines and readers without JavaScript see the
|
|
6
|
+
* page. Use members-only or early-access gating for real restrictions.
|
|
7
|
+
*/
|
|
8
|
+
interface Props {
|
|
9
|
+
minimumAge?: number;
|
|
10
|
+
/** Where "No" goes. */
|
|
11
|
+
exitHref?: string;
|
|
12
|
+
/** Separate answers per series by giving each its own key. */
|
|
13
|
+
storageKey?: string;
|
|
14
|
+
message?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const {
|
|
18
|
+
minimumAge = 18,
|
|
19
|
+
exitHref = "/",
|
|
20
|
+
storageKey = "mm-age-gate",
|
|
21
|
+
message = `This comic is intended for readers aged ${minimumAge} and over.`,
|
|
22
|
+
} = Astro.props;
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
<div class="mm-age-gate" data-mm-age-gate={storageKey} role="dialog" aria-modal="true" aria-labelledby="mm-age-gate-title" hidden>
|
|
26
|
+
<div class="mm-age-gate__panel">
|
|
27
|
+
<p id="mm-age-gate-title" class="mm-age-gate__title">{message}</p>
|
|
28
|
+
<p>Are you {minimumAge} or older?</p>
|
|
29
|
+
<div class="mm-age-gate__actions">
|
|
30
|
+
<button type="button" data-accept>Yes, continue</button>
|
|
31
|
+
<a href={exitHref}>No, take me back</a>
|
|
32
|
+
</div>
|
|
33
|
+
</div>
|
|
34
|
+
</div>
|
|
35
|
+
|
|
36
|
+
<style>
|
|
37
|
+
.mm-age-gate {
|
|
38
|
+
position: fixed;
|
|
39
|
+
inset: 0;
|
|
40
|
+
z-index: 1000;
|
|
41
|
+
display: grid;
|
|
42
|
+
place-items: center;
|
|
43
|
+
background: rgb(0 0 0 / 0.85);
|
|
44
|
+
backdrop-filter: blur(12px);
|
|
45
|
+
}
|
|
46
|
+
.mm-age-gate[hidden] {
|
|
47
|
+
display: none;
|
|
48
|
+
}
|
|
49
|
+
.mm-age-gate__panel {
|
|
50
|
+
max-width: 28rem;
|
|
51
|
+
padding: 1.5rem;
|
|
52
|
+
border-radius: 0.75rem;
|
|
53
|
+
background: var(--mm-age-gate-background, Canvas);
|
|
54
|
+
color: var(--mm-age-gate-color, CanvasText);
|
|
55
|
+
}
|
|
56
|
+
.mm-age-gate__actions {
|
|
57
|
+
display: flex;
|
|
58
|
+
gap: 1rem;
|
|
59
|
+
align-items: center;
|
|
60
|
+
}
|
|
61
|
+
</style>
|
|
62
|
+
|
|
63
|
+
<script>
|
|
64
|
+
for (const gate of document.querySelectorAll<HTMLElement>("[data-mm-age-gate]")) {
|
|
65
|
+
const key = gate.dataset.mmAgeGate ?? "mm-age-gate";
|
|
66
|
+
let accepted = false;
|
|
67
|
+
try {
|
|
68
|
+
accepted = window.localStorage.getItem(key) === "yes";
|
|
69
|
+
} catch {
|
|
70
|
+
// Storage blocked: ask every time.
|
|
71
|
+
}
|
|
72
|
+
if (accepted) continue;
|
|
73
|
+
gate.hidden = false;
|
|
74
|
+
const button = gate.querySelector<HTMLButtonElement>("[data-accept]");
|
|
75
|
+
button?.focus();
|
|
76
|
+
button?.addEventListener("click", () => {
|
|
77
|
+
try {
|
|
78
|
+
window.localStorage.setItem(key, "yes");
|
|
79
|
+
} catch {
|
|
80
|
+
// Remember for this page only.
|
|
81
|
+
}
|
|
82
|
+
gate.hidden = true;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
</script>
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* A grid of comics as thumbnails (or titles when there's no image), for
|
|
4
|
+
* archive, series and chapter pages. GIF thumbnails are served untransformed.
|
|
5
|
+
*/
|
|
6
|
+
import { Image } from "emdash/ui";
|
|
7
|
+
import { isAnimatedImage, originalMediaUrl } from "../media";
|
|
8
|
+
|
|
9
|
+
interface ArchiveItem {
|
|
10
|
+
href: string;
|
|
11
|
+
title: string;
|
|
12
|
+
number?: number | null;
|
|
13
|
+
image?: unknown;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface Props {
|
|
17
|
+
items: ArchiveItem[];
|
|
18
|
+
/** Minimum column width (CSS length). */
|
|
19
|
+
columnWidth?: string;
|
|
20
|
+
showNumbers?: boolean;
|
|
21
|
+
class?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const { items, columnWidth = "10rem", showNumbers = true, class: className } = Astro.props;
|
|
25
|
+
const resolveMediaUrl = (Astro.locals as { emdash?: { getPublicMediaUrl?: (key: string) => string } })
|
|
26
|
+
.emdash?.getPublicMediaUrl;
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
<ol class:list={["mm-archive", className]} style={`--mm-archive-column: ${columnWidth}`}>
|
|
30
|
+
{
|
|
31
|
+
items.map((item) => (
|
|
32
|
+
<li>
|
|
33
|
+
<a href={item.href} class="mm-archive__item">
|
|
34
|
+
{item.image ? (
|
|
35
|
+
isAnimatedImage(item.image) ? (
|
|
36
|
+
<img src={originalMediaUrl(item.image, resolveMediaUrl) ?? ""} alt="" loading="lazy" decoding="async" />
|
|
37
|
+
) : (
|
|
38
|
+
<Image image={item.image as never} alt="" sizes={`(min-width: 600px) ${columnWidth}, 50vw`} />
|
|
39
|
+
)
|
|
40
|
+
) : (
|
|
41
|
+
<span class="mm-archive__placeholder" aria-hidden="true" />
|
|
42
|
+
)}
|
|
43
|
+
<span class="mm-archive__title">
|
|
44
|
+
{showNumbers && typeof item.number === "number" && <span class="mm-archive__number">#{item.number}</span>}{" "}
|
|
45
|
+
{item.title}
|
|
46
|
+
</span>
|
|
47
|
+
</a>
|
|
48
|
+
</li>
|
|
49
|
+
))
|
|
50
|
+
}
|
|
51
|
+
</ol>
|
|
52
|
+
|
|
53
|
+
<style>
|
|
54
|
+
.mm-archive {
|
|
55
|
+
display: grid;
|
|
56
|
+
grid-template-columns: repeat(auto-fill, minmax(var(--mm-archive-column, 10rem), 1fr));
|
|
57
|
+
gap: 1rem;
|
|
58
|
+
list-style: none;
|
|
59
|
+
padding: 0;
|
|
60
|
+
margin: 0;
|
|
61
|
+
}
|
|
62
|
+
.mm-archive__item {
|
|
63
|
+
display: grid;
|
|
64
|
+
gap: 0.4rem;
|
|
65
|
+
text-decoration: none;
|
|
66
|
+
color: inherit;
|
|
67
|
+
}
|
|
68
|
+
.mm-archive__item :global(img),
|
|
69
|
+
.mm-archive__placeholder {
|
|
70
|
+
display: block;
|
|
71
|
+
width: 100%;
|
|
72
|
+
aspect-ratio: 3 / 4;
|
|
73
|
+
object-fit: cover;
|
|
74
|
+
background: var(--mm-archive-placeholder, color-mix(in srgb, currentColor 10%, transparent));
|
|
75
|
+
}
|
|
76
|
+
.mm-archive__number {
|
|
77
|
+
opacity: 0.7;
|
|
78
|
+
}
|
|
79
|
+
</style>
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* Cast members with portraits and a short introduction.
|
|
4
|
+
*/
|
|
5
|
+
import { Image, PortableText } from "emdash/ui";
|
|
6
|
+
|
|
7
|
+
interface CastMember {
|
|
8
|
+
title: string;
|
|
9
|
+
slug?: string;
|
|
10
|
+
href?: string;
|
|
11
|
+
portrait?: unknown;
|
|
12
|
+
/** Plain text or Portable Text. */
|
|
13
|
+
bio?: unknown;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface Props {
|
|
17
|
+
cast: CastMember[];
|
|
18
|
+
headingLevel?: 2 | 3 | 4;
|
|
19
|
+
class?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const { cast, headingLevel = 3, class: className } = Astro.props;
|
|
23
|
+
const Heading = `h${headingLevel}` as "h3";
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
<ul class:list={["mm-cast", className]}>
|
|
27
|
+
{
|
|
28
|
+
cast.map((member) => (
|
|
29
|
+
<li class="mm-cast__member" id={member.slug}>
|
|
30
|
+
{member.portrait && <Image image={member.portrait as never} alt="" sizes="12rem" />}
|
|
31
|
+
<Heading class="mm-cast__name">
|
|
32
|
+
{member.href ? <a href={member.href}>{member.title}</a> : member.title}
|
|
33
|
+
</Heading>
|
|
34
|
+
{typeof member.bio === "string" ? (
|
|
35
|
+
<p>{member.bio}</p>
|
|
36
|
+
) : Array.isArray(member.bio) ? (
|
|
37
|
+
<PortableText value={member.bio as never} />
|
|
38
|
+
) : null}
|
|
39
|
+
</li>
|
|
40
|
+
))
|
|
41
|
+
}
|
|
42
|
+
</ul>
|
|
43
|
+
|
|
44
|
+
<style>
|
|
45
|
+
.mm-cast {
|
|
46
|
+
display: grid;
|
|
47
|
+
grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr));
|
|
48
|
+
gap: 1.5rem;
|
|
49
|
+
list-style: none;
|
|
50
|
+
padding: 0;
|
|
51
|
+
}
|
|
52
|
+
.mm-cast__member :global(img) {
|
|
53
|
+
display: block;
|
|
54
|
+
width: 100%;
|
|
55
|
+
height: auto;
|
|
56
|
+
aspect-ratio: 1;
|
|
57
|
+
object-fit: cover;
|
|
58
|
+
border-radius: 0.5rem;
|
|
59
|
+
}
|
|
60
|
+
.mm-cast__name {
|
|
61
|
+
margin-block: 0.5rem 0.25rem;
|
|
62
|
+
}
|
|
63
|
+
</style>
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* Chapters with their comics, as nested lists. Comics are linked in order.
|
|
4
|
+
*/
|
|
5
|
+
interface ChapterItem {
|
|
6
|
+
title: string;
|
|
7
|
+
number?: number | null;
|
|
8
|
+
href?: string;
|
|
9
|
+
summary?: string;
|
|
10
|
+
comics: Array<{ href: string; title: string; number?: number | null }>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface Props {
|
|
14
|
+
chapters: ChapterItem[];
|
|
15
|
+
/** Heading level for chapter titles. */
|
|
16
|
+
headingLevel?: 2 | 3 | 4;
|
|
17
|
+
class?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const { chapters, headingLevel = 2, class: className } = Astro.props;
|
|
21
|
+
const Heading = `h${headingLevel}` as "h2";
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
<div class:list={["mm-chapters", className]}>
|
|
25
|
+
{
|
|
26
|
+
chapters.map((chapter) => (
|
|
27
|
+
<section class="mm-chapters__chapter">
|
|
28
|
+
<Heading class="mm-chapters__title">
|
|
29
|
+
{chapter.href ? <a href={chapter.href}>{chapter.title}</a> : chapter.title}
|
|
30
|
+
</Heading>
|
|
31
|
+
{chapter.summary && <p class="mm-chapters__summary">{chapter.summary}</p>}
|
|
32
|
+
{chapter.comics.length > 0 && (
|
|
33
|
+
<ol class="mm-chapters__comics">
|
|
34
|
+
{chapter.comics.map((comic) => (
|
|
35
|
+
<li>
|
|
36
|
+
<a href={comic.href}>
|
|
37
|
+
{typeof comic.number === "number" && <span class="mm-chapters__number">#{comic.number}</span>}{" "}
|
|
38
|
+
{comic.title}
|
|
39
|
+
</a>
|
|
40
|
+
</li>
|
|
41
|
+
))}
|
|
42
|
+
</ol>
|
|
43
|
+
)}
|
|
44
|
+
</section>
|
|
45
|
+
))
|
|
46
|
+
}
|
|
47
|
+
</div>
|
|
48
|
+
|
|
49
|
+
<style>
|
|
50
|
+
.mm-chapters__comics {
|
|
51
|
+
list-style: none;
|
|
52
|
+
padding: 0;
|
|
53
|
+
}
|
|
54
|
+
.mm-chapters__number {
|
|
55
|
+
opacity: 0.7;
|
|
56
|
+
}
|
|
57
|
+
</style>
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* Renderer for the "character-card" Portable Text block: a cast member's
|
|
4
|
+
* portrait, name and introduction, from the `cast` collection. Renders nothing
|
|
5
|
+
* if the cast member isn't published.
|
|
6
|
+
*/
|
|
7
|
+
import { getEmDashEntry } from "emdash";
|
|
8
|
+
import { Image, PortableText } from "emdash/ui";
|
|
9
|
+
|
|
10
|
+
interface Props {
|
|
11
|
+
node: { _type: string; _key?: string; character?: string };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const { node } = Astro.props;
|
|
15
|
+
const slug = node.character?.trim();
|
|
16
|
+
const { entry, cacheHint } = slug ? await getEmDashEntry("cast", slug) : { entry: null, cacheHint: null };
|
|
17
|
+
if (cacheHint && Astro.cache?.enabled) Astro.cache.set(cacheHint);
|
|
18
|
+
const member = entry?.data as { title?: string; portrait?: unknown; bio?: unknown } | undefined;
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
{
|
|
22
|
+
member && (
|
|
23
|
+
<aside class="mm-character-card">
|
|
24
|
+
{member.portrait && <Image image={member.portrait as never} alt="" sizes="8rem" />}
|
|
25
|
+
<div>
|
|
26
|
+
<p class="mm-character-card__name">{member.title}</p>
|
|
27
|
+
{Array.isArray(member.bio) && <PortableText value={member.bio as never} />}
|
|
28
|
+
</div>
|
|
29
|
+
</aside>
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
<style>
|
|
34
|
+
.mm-character-card {
|
|
35
|
+
display: grid;
|
|
36
|
+
grid-template-columns: 8rem 1fr;
|
|
37
|
+
gap: 1rem;
|
|
38
|
+
align-items: start;
|
|
39
|
+
padding: 1rem;
|
|
40
|
+
border: 1px solid color-mix(in srgb, currentColor 20%, transparent);
|
|
41
|
+
border-radius: 0.75rem;
|
|
42
|
+
}
|
|
43
|
+
.mm-character-card :global(img) {
|
|
44
|
+
width: 100%;
|
|
45
|
+
height: auto;
|
|
46
|
+
aspect-ratio: 1;
|
|
47
|
+
object-fit: cover;
|
|
48
|
+
border-radius: 50%;
|
|
49
|
+
}
|
|
50
|
+
.mm-character-card__name {
|
|
51
|
+
font-weight: 700;
|
|
52
|
+
margin: 0 0 0.25rem;
|
|
53
|
+
}
|
|
54
|
+
</style>
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* Renderer for the "comic-embed" Portable Text block: a comic's first page (or
|
|
4
|
+
* thumbnail) linked to the comic at /<series>/<slug>. Reads the `comics`
|
|
5
|
+
* collection; renders nothing if the comic isn't published.
|
|
6
|
+
*/
|
|
7
|
+
import { getEmDashEntry } from "emdash";
|
|
8
|
+
import { Image } from "emdash/ui";
|
|
9
|
+
import { isAnimatedImage, originalMediaUrl } from "../media";
|
|
10
|
+
|
|
11
|
+
interface Props {
|
|
12
|
+
node: { _type: string; _key?: string; comic?: string; caption?: string };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const { node } = Astro.props;
|
|
16
|
+
const slug = node.comic?.trim();
|
|
17
|
+
const { entry, cacheHint } = slug ? await getEmDashEntry("comics", slug) : { entry: null, cacheHint: null };
|
|
18
|
+
if (cacheHint && Astro.cache?.enabled) Astro.cache.set(cacheHint);
|
|
19
|
+
const comic = entry?.data as
|
|
20
|
+
| { slug?: string; title?: string; series?: string; thumbnail?: unknown; pages?: Array<{ image?: unknown; alt?: string }> }
|
|
21
|
+
| undefined;
|
|
22
|
+
const image = comic?.thumbnail ?? comic?.pages?.[0]?.image;
|
|
23
|
+
const href = comic?.series && comic.slug ? `/${comic.series}/${comic.slug}` : undefined;
|
|
24
|
+
const resolveMediaUrl = (Astro.locals as { emdash?: { getPublicMediaUrl?: (key: string) => string } })
|
|
25
|
+
.emdash?.getPublicMediaUrl;
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
{
|
|
29
|
+
comic && href && (
|
|
30
|
+
<figure class="mm-comic-embed">
|
|
31
|
+
<a href={href}>
|
|
32
|
+
{image &&
|
|
33
|
+
(isAnimatedImage(image) ? (
|
|
34
|
+
<img src={originalMediaUrl(image, resolveMediaUrl) ?? ""} alt={comic.title ?? ""} loading="lazy" />
|
|
35
|
+
) : (
|
|
36
|
+
<Image image={image as never} alt={comic.pages?.[0]?.alt || comic.title || ""} sizes="(min-width: 800px) 800px, 100vw" />
|
|
37
|
+
))}
|
|
38
|
+
</a>
|
|
39
|
+
<figcaption>
|
|
40
|
+
<a href={href}>{node.caption?.trim() || comic.title}</a>
|
|
41
|
+
</figcaption>
|
|
42
|
+
</figure>
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
<style>
|
|
47
|
+
.mm-comic-embed :global(img) {
|
|
48
|
+
display: block;
|
|
49
|
+
width: 100%;
|
|
50
|
+
height: auto;
|
|
51
|
+
}
|
|
52
|
+
.mm-comic-embed figcaption {
|
|
53
|
+
margin-top: 0.5rem;
|
|
54
|
+
}
|
|
55
|
+
</style>
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* First, previous, random, next and latest links, with keyboard (arrow keys)
|
|
4
|
+
* and swipe navigation. For right-to-left comics the arrows and swipes flip,
|
|
5
|
+
* so "forward" always matches the reading direction. In a paged reader, the
|
|
6
|
+
* keys turn pages first and move to the next comic at the end.
|
|
7
|
+
*
|
|
8
|
+
* Pass hrefs (from the series helpers); missing ones are left out.
|
|
9
|
+
*/
|
|
10
|
+
interface Props {
|
|
11
|
+
first?: string | undefined;
|
|
12
|
+
previous?: string | undefined;
|
|
13
|
+
random?: string | undefined;
|
|
14
|
+
next?: string | undefined;
|
|
15
|
+
latest?: string | undefined;
|
|
16
|
+
direction?: "ltr" | "rtl" | "vertical";
|
|
17
|
+
labels?: Partial<Record<"first" | "previous" | "random" | "next" | "latest", string>>;
|
|
18
|
+
/** Listen for arrow keys and swipes. Turn off when a page has two navs. */
|
|
19
|
+
keyboard?: boolean;
|
|
20
|
+
class?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const {
|
|
24
|
+
first,
|
|
25
|
+
previous,
|
|
26
|
+
random,
|
|
27
|
+
next,
|
|
28
|
+
latest,
|
|
29
|
+
direction = "ltr",
|
|
30
|
+
labels = {},
|
|
31
|
+
keyboard = true,
|
|
32
|
+
class: className,
|
|
33
|
+
} = Astro.props;
|
|
34
|
+
|
|
35
|
+
const text = {
|
|
36
|
+
first: labels.first ?? "First",
|
|
37
|
+
previous: labels.previous ?? "Previous",
|
|
38
|
+
random: labels.random ?? "Random",
|
|
39
|
+
next: labels.next ?? "Next",
|
|
40
|
+
latest: labels.latest ?? "Latest",
|
|
41
|
+
};
|
|
42
|
+
const rtl = direction === "rtl";
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
<nav
|
|
46
|
+
class:list={["mm-comic-nav", className]}
|
|
47
|
+
aria-label="Comic navigation"
|
|
48
|
+
dir={rtl ? "rtl" : undefined}
|
|
49
|
+
data-mm-comic-nav={keyboard ? "keys" : ""}
|
|
50
|
+
data-direction={direction}
|
|
51
|
+
>
|
|
52
|
+
{first ? <a href={first} rel="first" data-nav="first">{text.first}</a> : <span aria-hidden="true" class="mm-comic-nav__off">{text.first}</span>}
|
|
53
|
+
{previous ? <a href={previous} rel="prev" data-nav="previous">{text.previous}</a> : <span aria-hidden="true" class="mm-comic-nav__off">{text.previous}</span>}
|
|
54
|
+
{random && <a href={random} data-nav="random">{text.random}</a>}
|
|
55
|
+
{next ? <a href={next} rel="next" data-nav="next">{text.next}</a> : <span aria-hidden="true" class="mm-comic-nav__off">{text.next}</span>}
|
|
56
|
+
{latest ? <a href={latest} data-nav="latest">{text.latest}</a> : <span aria-hidden="true" class="mm-comic-nav__off">{text.latest}</span>}
|
|
57
|
+
</nav>
|
|
58
|
+
|
|
59
|
+
<style>
|
|
60
|
+
.mm-comic-nav {
|
|
61
|
+
display: flex;
|
|
62
|
+
flex-wrap: wrap;
|
|
63
|
+
gap: 0.5rem 1.25rem;
|
|
64
|
+
justify-content: center;
|
|
65
|
+
padding-block: 1rem;
|
|
66
|
+
}
|
|
67
|
+
.mm-comic-nav__off {
|
|
68
|
+
opacity: 0.4;
|
|
69
|
+
}
|
|
70
|
+
</style>
|
|
71
|
+
|
|
72
|
+
<script>
|
|
73
|
+
const nav = document.querySelector<HTMLElement>("[data-mm-comic-nav='keys']");
|
|
74
|
+
if (nav) {
|
|
75
|
+
const rtl = nav.dataset.direction === "rtl";
|
|
76
|
+
const link = (name: string) => nav.querySelector<HTMLAnchorElement>(`[data-nav='${name}']`);
|
|
77
|
+
|
|
78
|
+
// step: +1 is forward in reading order, -1 is back.
|
|
79
|
+
const go = (step: 1 | -1) => {
|
|
80
|
+
const reader = document.querySelector<HTMLElement>("[data-mm-comic]");
|
|
81
|
+
if (reader) {
|
|
82
|
+
const event = new CustomEvent("mm-comic:page", { detail: step, cancelable: true });
|
|
83
|
+
// The paged reader cancels the event when it turned a page itself.
|
|
84
|
+
if (!reader.dispatchEvent(event)) return;
|
|
85
|
+
}
|
|
86
|
+
const target = link(step === 1 ? "next" : "previous");
|
|
87
|
+
if (target) window.location.assign(target.href);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const typing = (target: EventTarget | null) =>
|
|
91
|
+
target instanceof HTMLElement &&
|
|
92
|
+
(target.isContentEditable || ["INPUT", "TEXTAREA", "SELECT"].includes(target.tagName));
|
|
93
|
+
|
|
94
|
+
document.addEventListener("keydown", (event) => {
|
|
95
|
+
if (event.defaultPrevented || event.altKey || event.ctrlKey || event.metaKey || typing(event.target)) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (event.key === "ArrowRight") go(rtl ? -1 : 1);
|
|
99
|
+
else if (event.key === "ArrowLeft") go(rtl ? 1 : -1);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// Horizontal swipes on the reader: swipe left moves forward in a
|
|
103
|
+
// left-to-right comic, backward in a right-to-left one.
|
|
104
|
+
const area = document.querySelector<HTMLElement>("[data-mm-comic]");
|
|
105
|
+
let startX = 0;
|
|
106
|
+
let startY = 0;
|
|
107
|
+
area?.addEventListener(
|
|
108
|
+
"touchstart",
|
|
109
|
+
(event) => {
|
|
110
|
+
const touch = event.changedTouches[0];
|
|
111
|
+
if (!touch) return;
|
|
112
|
+
startX = touch.clientX;
|
|
113
|
+
startY = touch.clientY;
|
|
114
|
+
},
|
|
115
|
+
{ passive: true },
|
|
116
|
+
);
|
|
117
|
+
area?.addEventListener(
|
|
118
|
+
"touchend",
|
|
119
|
+
(event) => {
|
|
120
|
+
const touch = event.changedTouches[0];
|
|
121
|
+
if (!touch) return;
|
|
122
|
+
const dx = touch.clientX - startX;
|
|
123
|
+
const dy = touch.clientY - startY;
|
|
124
|
+
if (Math.abs(dx) < 60 || Math.abs(dx) < Math.abs(dy) * 1.5) return;
|
|
125
|
+
const swipedLeft = dx < 0;
|
|
126
|
+
go(swipedLeft !== rtl ? 1 : -1);
|
|
127
|
+
},
|
|
128
|
+
{ passive: true },
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
</script>
|