@atom63/mdx 0.4.0-beta.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/API.md +47 -0
- package/CONTRIBUTING.md +58 -0
- package/LICENSE +21 -0
- package/README.md +190 -0
- package/dist/article/index.d.ts +32 -0
- package/dist/article/index.js +38 -0
- package/dist/article/index.js.map +1 -0
- package/dist/blocks/credits-block-entry.d.ts +14 -0
- package/dist/blocks/credits-block-entry.js +4 -0
- package/dist/blocks/credits-block-entry.js.map +1 -0
- package/dist/blocks/index.d.ts +175 -0
- package/dist/blocks/index.js +9 -0
- package/dist/blocks/index.js.map +1 -0
- package/dist/blocks/media-caption-entry.d.ts +11 -0
- package/dist/blocks/media-caption-entry.js +4 -0
- package/dist/blocks/media-caption-entry.js.map +1 -0
- package/dist/chunk-2RCEDZBB.js +11 -0
- package/dist/chunk-2RCEDZBB.js.map +1 -0
- package/dist/chunk-34B2U2Y2.js +59 -0
- package/dist/chunk-34B2U2Y2.js.map +1 -0
- package/dist/chunk-A3NG5VKX.js +169 -0
- package/dist/chunk-A3NG5VKX.js.map +1 -0
- package/dist/chunk-CSXZ2XEN.js +479 -0
- package/dist/chunk-CSXZ2XEN.js.map +1 -0
- package/dist/chunk-DJSENA7Q.js +63 -0
- package/dist/chunk-DJSENA7Q.js.map +1 -0
- package/dist/chunk-EIY6ZR6T.js +2471 -0
- package/dist/chunk-EIY6ZR6T.js.map +1 -0
- package/dist/chunk-EPSRYU5X.js +61 -0
- package/dist/chunk-EPSRYU5X.js.map +1 -0
- package/dist/chunk-FVCE4FER.js +132 -0
- package/dist/chunk-FVCE4FER.js.map +1 -0
- package/dist/chunk-IART7J2U.js +101 -0
- package/dist/chunk-IART7J2U.js.map +1 -0
- package/dist/chunk-OUEW54AC.js +144 -0
- package/dist/chunk-OUEW54AC.js.map +1 -0
- package/dist/chunk-WZ6US342.js +231 -0
- package/dist/chunk-WZ6US342.js.map +1 -0
- package/dist/constants-CuaBcwMe.d.ts +4 -0
- package/dist/editor/index.d.ts +47 -0
- package/dist/editor/index.js +118 -0
- package/dist/editor/index.js.map +1 -0
- package/dist/framed-block-DM5LLxO7.d.ts +87 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/lightbox/index.d.ts +44 -0
- package/dist/lightbox/index.js +5 -0
- package/dist/lightbox/index.js.map +1 -0
- package/dist/mdx-provider-6gOypsy5.d.ts +185 -0
- package/dist/photo-swipe-CwzAHpP-.d.ts +66 -0
- package/dist/primitives/index.d.ts +130 -0
- package/dist/primitives/index.js +132 -0
- package/dist/primitives/index.js.map +1 -0
- package/dist/runtime/index.d.ts +39 -0
- package/dist/runtime/index.js +4 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/slots-BvPdUMdY.d.ts +23 -0
- package/dist/video-block-C0a5Yx9x.d.ts +468 -0
- package/package.json +139 -0
- package/src/blocks/callout/callout.css +37 -0
- package/src/blocks/code-block/code-block.css +40 -0
- package/src/blocks/color-swatch-item/color-swatch-item.css +36 -0
- package/src/blocks/compare/compare.css +14 -0
- package/src/blocks/comparison-pair/comparison-pair.css +27 -0
- package/src/blocks/credits-block/credits-block.css +16 -0
- package/src/blocks/demo-stage/demo-stage.css +50 -0
- package/src/blocks/doc-example/doc-example.css +44 -0
- package/src/blocks/image-compare/image-compare.css +45 -0
- package/src/blocks/layer-stack/layer-stack.css +28 -0
- package/src/blocks/media-placeholder/media-placeholder.css +11 -0
- package/src/blocks/mermaid-diagram/mermaid-diagram.css +52 -0
- package/src/blocks/page-meta/page-meta.css +7 -0
- package/src/blocks/page-table-of-contents/page-table-of-contents.css +73 -0
- package/src/blocks/resource-list/resource-list.css +138 -0
- package/src/blocks/scroll-stage/scroll-stage.css +12 -0
- package/src/blocks/stat-card/stat-card.css +18 -0
- package/src/blocks/steps/steps.css +20 -0
- package/src/blocks/timeline/timeline.css +12 -0
- package/src/blocks/video-block/video-block.css +11 -0
- package/src/primitives/motion-tokens.css +16 -0
- package/src/styles/a63.css +13 -0
- package/src/styles/base.css +362 -0
- package/src/styles/block-recipes.css +21 -0
- package/src/styles/consumer.css +7 -0
- package/src/styles/index.css +12 -0
- package/src/styles/mdx-blocks.css +9 -0
- package/src/styles/shadcn.css +12 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// src/mdx-styles.ts
|
|
2
|
+
var inlineLinkTreatment = "[&_a]:underline [&_a]:underline-offset-4";
|
|
3
|
+
var mdxTypography = {
|
|
4
|
+
articleBody: "text-base leading-relaxed text-secondary-foreground",
|
|
5
|
+
articleBodySpacing: "mt-4 first:mt-0 last:mb-0",
|
|
6
|
+
calloutBody: "text-base leading-relaxed"
|
|
7
|
+
};
|
|
8
|
+
var mdxStyles = {
|
|
9
|
+
// wrapper you put around MDX content container (highly recommended)
|
|
10
|
+
// Note: .not-mdx, .example-container, and .component-preview will opt-out of all typography styles
|
|
11
|
+
root: [
|
|
12
|
+
// `.mdx` is the class hook; foundation color lives in mdx-blocks.css
|
|
13
|
+
// (`.mdx { color: var(--a63-text-primary) }`). Color/surface/border/radius
|
|
14
|
+
// for raw-JSX figures + media are likewise in mdx-blocks.css so this layer
|
|
15
|
+
// needs no Tailwind utility generation. Only geometry stays as utilities.
|
|
16
|
+
"mdx",
|
|
17
|
+
// Raw JSX figures bypass component mapping — spacing via root selectors.
|
|
18
|
+
// (figure>video|img|iframe|figcaption color/border/radius → mdx-blocks.css)
|
|
19
|
+
"[&_figure]:my-8 [&_figure:first-child]:mt-0 [&_figure:last-child]:mb-0 sm:[&_figure]:my-10",
|
|
20
|
+
"[&_figure>figcaption]:mx-auto [&_figure>figcaption]:mt-2 [&_figure>figcaption]:max-w-[var(--mdx-measure,42rem)] [&_figure>figcaption]:text-center [&_figure>figcaption]:text-xs [&_figure>figcaption]:leading-snug [&_figure>figcaption]:text-balance",
|
|
21
|
+
// Reset only the live demo wrapper; rendered components keep their own internal rhythm.
|
|
22
|
+
"[&_.example-container_.not-mdx]:!m-0",
|
|
23
|
+
"[&_.not-mdx:not(.example-container):not(.callout):not(.mdx-block):not(.mdx-page-meta):not(.mdx-page-nav):not([data-media])]:!m-0",
|
|
24
|
+
"[&_.not-mdx>a]:!no-underline",
|
|
25
|
+
"[&>.callout+.callout]:mt-4",
|
|
26
|
+
"[&_.foundation-preview_p]:!m-0 [&_.foundation-preview_p]:![font-size:unset] [&_.foundation-preview_p]:![line-height:unset]"
|
|
27
|
+
// .example-container — MDX typography is suppressed via React Context (useMdxStyle hook),
|
|
28
|
+
// so no CSS overrides are needed here. Components inside control their own styles.
|
|
29
|
+
].join(" "),
|
|
30
|
+
spacing: {
|
|
31
|
+
block: "my-6 first:mt-0 last:mb-0 sm:my-8",
|
|
32
|
+
component: "my-5 first:mt-0 last:mb-0",
|
|
33
|
+
media: "my-8 first:mt-0 last:mb-0 sm:my-10",
|
|
34
|
+
mediaLg: "my-12 first:mt-0 last:mb-0 sm:my-16",
|
|
35
|
+
mediaSm: "my-6 first:mt-0 last:mb-0"
|
|
36
|
+
},
|
|
37
|
+
headings: {
|
|
38
|
+
h1: "text-4xl font-semibold tracking-tight scroll-mt-24 mt-10 first:mt-0 sm:text-5xl",
|
|
39
|
+
h2: "text-2xl font-semibold tracking-tight scroll-mt-24 mt-10 first:mt-0 sm:text-3xl",
|
|
40
|
+
h3: "text-xl font-semibold tracking-tight scroll-mt-24 mt-8 first:mt-0 sm:text-2xl",
|
|
41
|
+
h4: "text-lg font-semibold tracking-tight scroll-mt-24 mt-6 first:mt-0",
|
|
42
|
+
h5: "text-base font-semibold scroll-mt-24 mt-6 first:mt-0",
|
|
43
|
+
h6: "mdx-h6 text-sm font-semibold scroll-mt-24 mt-6 first:mt-0"
|
|
44
|
+
},
|
|
45
|
+
text: {
|
|
46
|
+
paragraph: `${mdxTypography.articleBody} ${mdxTypography.articleBodySpacing} ${inlineLinkTreatment}`,
|
|
47
|
+
lead: "mdx-text-secondary text-lg leading-relaxed mt-4 first:mt-0",
|
|
48
|
+
small: "mdx-text-secondary text-sm leading-relaxed"
|
|
49
|
+
},
|
|
50
|
+
// NOTE (tailwind-independence): FOUNDATION styling (color / surface / border /
|
|
51
|
+
// shadow / radius) for these elements lives in styles/mdx-blocks.css keyed on
|
|
52
|
+
// --a63-* and applied via the `.mdx-*` recipe classes referenced below.
|
|
53
|
+
// Only LAYOUT/TYPOGRAPHY geometry stays as Tailwind utilities here; those are
|
|
54
|
+
// pure geometry and override cleanly via @layer components.
|
|
55
|
+
content: {
|
|
56
|
+
// links — decoration color still Tailwind (decorative underline tint, no
|
|
57
|
+
// --a63-* equivalent; renders via shadcn compat when Tailwind is present)
|
|
58
|
+
link: "font-normal underline underline-offset-4 decoration-2 decoration-foreground/30 hover:decoration-foreground/70 transition-colors",
|
|
59
|
+
// emphasis (color via `.mdx strong`/`.mdx del` recipes in mdx-blocks.css)
|
|
60
|
+
strong: "font-semibold",
|
|
61
|
+
em: "italic",
|
|
62
|
+
del: "line-through",
|
|
63
|
+
ins: "mdx-ins underline",
|
|
64
|
+
// inline code
|
|
65
|
+
inlineCode: "mdx-inline-code px-1 py-0.5 font-mono text-xs leading-snug font-medium",
|
|
66
|
+
// code blocks (pre)
|
|
67
|
+
pre: "mdx-pre overflow-x-auto p-4 text-sm leading-relaxed [&_code]:bg-transparent [&_code]:border-0 [&_code]:p-0 [&_code]:font-normal [&_code]:leading-relaxed [&_code]:ring-0 [&_code]:text-sm",
|
|
68
|
+
code: "font-mono text-sm leading-relaxed font-normal",
|
|
69
|
+
// used inside <pre><code>
|
|
70
|
+
// blockquote
|
|
71
|
+
blockquote: "mdx-blockquote mt-6 px-4 py-3 text-base italic rounded-e [&_p]:mt-2 [&_p:first-child]:mt-0",
|
|
72
|
+
// lists
|
|
73
|
+
ul: `mt-4 list-disc space-y-2 ps-4 [&_ul]:mt-2 [&_ul]:space-y-2 [&_ul]:ps-4 ${inlineLinkTreatment}`,
|
|
74
|
+
ol: `mt-4 list-decimal space-y-2 ps-4 [&_ol]:mt-2 [&_ol]:space-y-2 [&_ol]:ps-4 ${inlineLinkTreatment}`,
|
|
75
|
+
li: mdxTypography.articleBody,
|
|
76
|
+
// hr
|
|
77
|
+
hr: "mdx-hr my-8 sm:my-10",
|
|
78
|
+
// kbd
|
|
79
|
+
kbd: "mdx-kbd inline-flex h-6 select-none items-center gap-1 px-2 font-mono text-xs font-medium",
|
|
80
|
+
// tables (wrap recommended)
|
|
81
|
+
/* Clips to the wrapper's own radius/border only. The horizontal scroller is
|
|
82
|
+
* the DS Table's `.a63-Table-container` inside it, so an `overflow-x-auto`
|
|
83
|
+
* here never scrolled — its scrollWidth always equalled its clientWidth. */
|
|
84
|
+
tableWrapper: "mdx-table-wrapper mt-6 w-full overflow-hidden sm:mt-8",
|
|
85
|
+
table: "w-full border-collapse text-sm [&_code]:text-xs",
|
|
86
|
+
thead: "mdx-thead",
|
|
87
|
+
tbody: "[&_tr:last-child]:border-0",
|
|
88
|
+
tr: "mdx-tr transition-colors",
|
|
89
|
+
th: "mdx-th h-9 px-3 text-start align-middle font-semibold",
|
|
90
|
+
td: "mdx-td px-3 py-2 align-middle",
|
|
91
|
+
caption: "mdx-caption mt-3 text-balance text-xs",
|
|
92
|
+
// media — vertical rhythm aligned with spacing.media / mediaLg tokens
|
|
93
|
+
// (rounded/border color for iframe/video via `.mdx-media-framed` recipe)
|
|
94
|
+
img: "my-8 rounded-xl first:mt-0 last:mb-0 sm:my-10",
|
|
95
|
+
figure: "my-8 first:mt-0 last:mb-0 sm:my-10",
|
|
96
|
+
/* A caption labels the media above it, so it sits close and reads quiet.
|
|
97
|
+
* `leading-relaxed` (1.625) is prose leading: on a one-line caption its
|
|
98
|
+
* half-leading added ~4px of dead space on top of the margin, so a 12px gap
|
|
99
|
+
* measured ~16px optically and the caption drifted free of its own image.
|
|
100
|
+
* `snug` + `mt-2` lands it at ~10px. Ratio leading, never a fixed step. */
|
|
101
|
+
figcaption: "mdx-figcaption mx-auto mt-2 max-w-[var(--mdx-measure,42rem)] text-center text-xs leading-snug text-balance",
|
|
102
|
+
iframe: "mdx-media-framed my-8 first:mt-0 last:mb-0 w-full rounded-xl sm:my-10",
|
|
103
|
+
video: "mdx-media-framed my-8 first:mt-0 last:mb-0 w-full rounded-xl sm:my-10",
|
|
104
|
+
audio: "my-8 first:mt-0 last:mb-0 w-full sm:my-10",
|
|
105
|
+
// details/summary
|
|
106
|
+
details: "mdx-details mt-6 p-4 [&>*:first-child:not(summary)]:mt-0 [&>summary+*]:mt-3",
|
|
107
|
+
summary: "mdx-summary cursor-pointer select-none font-semibold [&::-webkit-details-marker]:hidden",
|
|
108
|
+
// misc semantics
|
|
109
|
+
mark: "mdx-mark rounded-sm px-1",
|
|
110
|
+
sub: "text-xs align-sub",
|
|
111
|
+
sup: "text-xs align-super",
|
|
112
|
+
abbr: "mdx-abbr cursor-help",
|
|
113
|
+
cite: "mdx-cite italic",
|
|
114
|
+
dfn: "font-semibold",
|
|
115
|
+
time: "mdx-time",
|
|
116
|
+
var: "font-mono italic",
|
|
117
|
+
samp: "mdx-samp px-1 font-mono text-xs",
|
|
118
|
+
output: "mdx-output px-2 py-1 font-mono text-xs"
|
|
119
|
+
},
|
|
120
|
+
layout: {
|
|
121
|
+
callout: {
|
|
122
|
+
// Scoped classes are written out literally, never composed by a helper:
|
|
123
|
+
// Tailwind's scanner is static, so a class assembled at runtime is never
|
|
124
|
+
// seen and no rule is generated for it.
|
|
125
|
+
base: `my-4 rounded-lg border p-4 ${mdxTypography.calloutBody} first:mt-0 last:mb-0 sm:my-5 [&_p]:mt-1.5 [&_p]:text-base [&_p]:leading-relaxed [&_p:first-child]:mt-0 [&_ul]:mt-1.5 [&_ul]:space-y-1 [&_ol]:mt-1.5 [&_ol]:space-y-1 [&_li]:text-base [&_li]:leading-relaxed [&_li]:text-inherit`
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
export { mdxStyles };
|
|
131
|
+
//# sourceMappingURL=chunk-FVCE4FER.js.map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AM,iBAAA;AAAA,IACN,GAAA,EAAK,eAAA;AAAA,IACL,IAAA,EAAM,UAAA;AAAA,IACN,GAAA,EAAK,kBAAA;AAAA,IACL,IAAA,EAAM,iCAAA;AAAA,IACN,MAAA,EAAQ;AAAA,GACV;AAAA,EAEA,MAAA,EAAQ;AAAA,IACN,OAAA,EAAS;AAAA;AAAA;AAAA;AAAA,MAIP,IAAA,EAAM,CAAA,2BAAA,EAA8B,aAAA,CAAc,WAAW,CAAA,iOAAA;AAAA;AAC/D;AAEJ","file":"chunk-FVCE4FER.js","sourcesContent":["/**\n * MDX STYLES - Consolidated style definitions\n * Extracted to separate file to avoid circular dependencies\n *\n * IMPORTANT: Two styling paths exist for MDX elements:\n *\n * 1. Component mapping (mdxComponents) — applies to markdown syntax (e.g. )\n * and lowercase HTML tags that MDX routes through the provider. Styles live in\n * `mdxStyles.content.*` and are applied via `cn()` in each component.\n *\n * 2. Root selectors (below) — apply to raw JSX written directly in MDX files\n * (e.g. <figure><video ... /></figure>). These bypass the component mapping,\n * so styles must be applied via descendant selectors on the root wrapper.\n *\n * When changing spacing/styles for media or figures, update BOTH paths or the\n * styling will be inconsistent between markdown syntax and raw JSX usage.\n */\n\nconst inlineLinkTreatment = '[&_a]:underline [&_a]:underline-offset-4'\n\n/* Prose leading is expressed as a RATIO, never a fixed step. `text-base` is\n * `15px * --typography-scale` (a user-adjustable personalization axis), so a\n * fixed `leading-7` freezes at 28px while the text grows — 1.87 at scale 1,\n * but 1.24 at scale 1.5, where lines nearly collide.\n *\n * Scoped classes (`[&>p]:text-base`, …) are always written out literally at the\n * point of use. They cannot be composed from these tokens by a helper: Tailwind's\n * scanner is a static lexer over source text, so a class assembled at runtime is\n * never seen and no rule is generated for it. */\nexport const mdxTypography = {\n articleBody: 'text-base leading-relaxed text-secondary-foreground',\n articleBodySpacing: 'mt-4 first:mt-0 last:mb-0',\n calloutBody: 'text-base leading-relaxed',\n} as const\n\nexport const mdxStyles = {\n // wrapper you put around MDX content container (highly recommended)\n // Note: .not-mdx, .example-container, and .component-preview will opt-out of all typography styles\n root: [\n // `.mdx` is the class hook; foundation color lives in mdx-blocks.css\n // (`.mdx { color: var(--a63-text-primary) }`). Color/surface/border/radius\n // for raw-JSX figures + media are likewise in mdx-blocks.css so this layer\n // needs no Tailwind utility generation. Only geometry stays as utilities.\n 'mdx',\n // Raw JSX figures bypass component mapping — spacing via root selectors.\n // (figure>video|img|iframe|figcaption color/border/radius → mdx-blocks.css)\n '[&_figure]:my-8 [&_figure:first-child]:mt-0 [&_figure:last-child]:mb-0 sm:[&_figure]:my-10',\n '[&_figure>figcaption]:mx-auto [&_figure>figcaption]:mt-2 [&_figure>figcaption]:max-w-[var(--mdx-measure,42rem)] [&_figure>figcaption]:text-center [&_figure>figcaption]:text-xs [&_figure>figcaption]:leading-snug [&_figure>figcaption]:text-balance',\n // Reset only the live demo wrapper; rendered components keep their own internal rhythm.\n '[&_.example-container_.not-mdx]:!m-0',\n '[&_.not-mdx:not(.example-container):not(.callout):not(.mdx-block):not(.mdx-page-meta):not(.mdx-page-nav):not([data-media])]:!m-0',\n '[&_.not-mdx>a]:!no-underline',\n '[&>.callout+.callout]:mt-4',\n '[&_.foundation-preview_p]:!m-0 [&_.foundation-preview_p]:![font-size:unset] [&_.foundation-preview_p]:![line-height:unset]',\n // .example-container — MDX typography is suppressed via React Context (useMdxStyle hook),\n // so no CSS overrides are needed here. Components inside control their own styles.\n ].join(' '),\n\n spacing: {\n block: 'my-6 first:mt-0 last:mb-0 sm:my-8',\n component: 'my-5 first:mt-0 last:mb-0',\n media: 'my-8 first:mt-0 last:mb-0 sm:my-10',\n mediaLg: 'my-12 first:mt-0 last:mb-0 sm:my-16',\n mediaSm: 'my-6 first:mt-0 last:mb-0',\n },\n\n headings: {\n h1: 'text-4xl font-semibold tracking-tight scroll-mt-24 mt-10 first:mt-0 sm:text-5xl',\n h2: 'text-2xl font-semibold tracking-tight scroll-mt-24 mt-10 first:mt-0 sm:text-3xl',\n h3: 'text-xl font-semibold tracking-tight scroll-mt-24 mt-8 first:mt-0 sm:text-2xl',\n h4: 'text-lg font-semibold tracking-tight scroll-mt-24 mt-6 first:mt-0',\n h5: 'text-base font-semibold scroll-mt-24 mt-6 first:mt-0',\n h6: 'mdx-h6 text-sm font-semibold scroll-mt-24 mt-6 first:mt-0',\n },\n\n text: {\n paragraph: `${mdxTypography.articleBody} ${mdxTypography.articleBodySpacing} ${inlineLinkTreatment}`,\n lead: 'mdx-text-secondary text-lg leading-relaxed mt-4 first:mt-0',\n small: 'mdx-text-secondary text-sm leading-relaxed',\n },\n\n // NOTE (tailwind-independence): FOUNDATION styling (color / surface / border /\n // shadow / radius) for these elements lives in styles/mdx-blocks.css keyed on\n // --a63-* and applied via the `.mdx-*` recipe classes referenced below.\n // Only LAYOUT/TYPOGRAPHY geometry stays as Tailwind utilities here; those are\n // pure geometry and override cleanly via @layer components.\n content: {\n // links — decoration color still Tailwind (decorative underline tint, no\n // --a63-* equivalent; renders via shadcn compat when Tailwind is present)\n link: 'font-normal underline underline-offset-4 decoration-2 decoration-foreground/30 hover:decoration-foreground/70 transition-colors',\n\n // emphasis (color via `.mdx strong`/`.mdx del` recipes in mdx-blocks.css)\n strong: 'font-semibold',\n em: 'italic',\n del: 'line-through',\n ins: 'mdx-ins underline',\n\n // inline code\n inlineCode: 'mdx-inline-code px-1 py-0.5 font-mono text-xs leading-snug font-medium',\n\n // code blocks (pre)\n pre: 'mdx-pre overflow-x-auto p-4 text-sm leading-relaxed [&_code]:bg-transparent [&_code]:border-0 [&_code]:p-0 [&_code]:font-normal [&_code]:leading-relaxed [&_code]:ring-0 [&_code]:text-sm',\n code: 'font-mono text-sm leading-relaxed font-normal', // used inside <pre><code>\n\n // blockquote\n blockquote:\n 'mdx-blockquote mt-6 px-4 py-3 text-base italic rounded-e [&_p]:mt-2 [&_p:first-child]:mt-0',\n\n // lists\n ul: `mt-4 list-disc space-y-2 ps-4 [&_ul]:mt-2 [&_ul]:space-y-2 [&_ul]:ps-4 ${inlineLinkTreatment}`,\n ol: `mt-4 list-decimal space-y-2 ps-4 [&_ol]:mt-2 [&_ol]:space-y-2 [&_ol]:ps-4 ${inlineLinkTreatment}`,\n li: mdxTypography.articleBody,\n\n // hr\n hr: 'mdx-hr my-8 sm:my-10',\n\n // kbd\n kbd: 'mdx-kbd inline-flex h-6 select-none items-center gap-1 px-2 font-mono text-xs font-medium',\n\n // tables (wrap recommended)\n /* Clips to the wrapper's own radius/border only. The horizontal scroller is\n * the DS Table's `.a63-Table-container` inside it, so an `overflow-x-auto`\n * here never scrolled — its scrollWidth always equalled its clientWidth. */\n tableWrapper: 'mdx-table-wrapper mt-6 w-full overflow-hidden sm:mt-8',\n table: 'w-full border-collapse text-sm [&_code]:text-xs',\n thead: 'mdx-thead',\n tbody: '[&_tr:last-child]:border-0',\n tr: 'mdx-tr transition-colors',\n th: 'mdx-th h-9 px-3 text-start align-middle font-semibold',\n td: 'mdx-td px-3 py-2 align-middle',\n caption: 'mdx-caption mt-3 text-balance text-xs',\n\n // media — vertical rhythm aligned with spacing.media / mediaLg tokens\n // (rounded/border color for iframe/video via `.mdx-media-framed` recipe)\n img: 'my-8 rounded-xl first:mt-0 last:mb-0 sm:my-10',\n figure: 'my-8 first:mt-0 last:mb-0 sm:my-10',\n /* A caption labels the media above it, so it sits close and reads quiet.\n * `leading-relaxed` (1.625) is prose leading: on a one-line caption its\n * half-leading added ~4px of dead space on top of the margin, so a 12px gap\n * measured ~16px optically and the caption drifted free of its own image.\n * `snug` + `mt-2` lands it at ~10px. Ratio leading, never a fixed step. */\n figcaption:\n 'mdx-figcaption mx-auto mt-2 max-w-[var(--mdx-measure,42rem)] text-center text-xs leading-snug text-balance',\n iframe: 'mdx-media-framed my-8 first:mt-0 last:mb-0 w-full rounded-xl sm:my-10',\n video: 'mdx-media-framed my-8 first:mt-0 last:mb-0 w-full rounded-xl sm:my-10',\n audio: 'my-8 first:mt-0 last:mb-0 w-full sm:my-10',\n\n // details/summary\n details: 'mdx-details mt-6 p-4 [&>*:first-child:not(summary)]:mt-0 [&>summary+*]:mt-3',\n summary:\n 'mdx-summary cursor-pointer select-none font-semibold [&::-webkit-details-marker]:hidden',\n\n // misc semantics\n mark: 'mdx-mark rounded-sm px-1',\n sub: 'text-xs align-sub',\n sup: 'text-xs align-super',\n abbr: 'mdx-abbr cursor-help',\n cite: 'mdx-cite italic',\n dfn: 'font-semibold',\n time: 'mdx-time',\n var: 'font-mono italic',\n samp: 'mdx-samp px-1 font-mono text-xs',\n output: 'mdx-output px-2 py-1 font-mono text-xs',\n },\n\n layout: {\n callout: {\n // Scoped classes are written out literally, never composed by a helper:\n // Tailwind's scanner is static, so a class assembled at runtime is never\n // seen and no rule is generated for it.\n base: `my-4 rounded-lg border p-4 ${mdxTypography.calloutBody} first:mt-0 last:mb-0 sm:my-5 [&_p]:mt-1.5 [&_p]:text-base [&_p]:leading-relaxed [&_p:first-child]:mt-0 [&_ul]:mt-1.5 [&_ul]:space-y-1 [&_ol]:mt-1.5 [&_ol]:space-y-1 [&_li]:text-base [&_li]:leading-relaxed [&_li]:text-inherit`,\n },\n },\n} as const\n\nexport type CalloutType = 'info' | 'warning' | 'error' | 'success'\n"]}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { clsx } from 'clsx';
|
|
2
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
+
|
|
4
|
+
// src/lightbox/constants.ts
|
|
5
|
+
var MDX_FIGURE_LIGHTBOX_GALLERY_ID = "atom63-mdx-figures";
|
|
6
|
+
|
|
7
|
+
// src/lightbox/dimensions.ts
|
|
8
|
+
function getImageDimensions(aspectRatio, defaultWidth = 1200) {
|
|
9
|
+
const ratioMap = {
|
|
10
|
+
"1/1": { width: defaultWidth, height: defaultWidth },
|
|
11
|
+
"4/3": { width: defaultWidth, height: Math.round(defaultWidth * 0.75) },
|
|
12
|
+
"3/4": { width: defaultWidth, height: Math.round(defaultWidth * 1.33) },
|
|
13
|
+
"16/9": { width: defaultWidth, height: Math.round(defaultWidth * 0.5625) },
|
|
14
|
+
"9/16": { width: defaultWidth, height: Math.round(defaultWidth * 1.78) }
|
|
15
|
+
};
|
|
16
|
+
return ratioMap[aspectRatio] ?? ratioMap["16/9"];
|
|
17
|
+
}
|
|
18
|
+
function loadImageDimensions(src) {
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
const img = new Image();
|
|
21
|
+
img.onload = () => {
|
|
22
|
+
const width = img.naturalWidth;
|
|
23
|
+
const height = img.naturalHeight;
|
|
24
|
+
if (width > 0 && height > 0) {
|
|
25
|
+
resolve({ width, height });
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
reject(new Error("Image has no intrinsic dimensions"));
|
|
29
|
+
};
|
|
30
|
+
img.onerror = () => {
|
|
31
|
+
reject(new Error(`Failed to load image dimensions for ${src}`));
|
|
32
|
+
};
|
|
33
|
+
img.src = src;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
async function getRealImageDimensions(src, aspectRatio) {
|
|
37
|
+
try {
|
|
38
|
+
return await loadImageDimensions(src);
|
|
39
|
+
} catch {
|
|
40
|
+
return getImageDimensions(aspectRatio);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function FigureLightboxTrigger({
|
|
44
|
+
src,
|
|
45
|
+
alt,
|
|
46
|
+
caption,
|
|
47
|
+
width,
|
|
48
|
+
height,
|
|
49
|
+
galleryId = MDX_FIGURE_LIGHTBOX_GALLERY_ID,
|
|
50
|
+
className,
|
|
51
|
+
children
|
|
52
|
+
}) {
|
|
53
|
+
const label = alt.trim() ? `View ${alt} in gallery` : "View image in gallery";
|
|
54
|
+
return /* @__PURE__ */ jsxs(
|
|
55
|
+
"button",
|
|
56
|
+
{
|
|
57
|
+
"aria-label": label,
|
|
58
|
+
className: clsx(
|
|
59
|
+
"group relative block w-full cursor-zoom-in overflow-hidden border-none bg-transparent p-0",
|
|
60
|
+
className
|
|
61
|
+
),
|
|
62
|
+
"data-gallery-id": galleryId,
|
|
63
|
+
"data-pswp-alt": alt,
|
|
64
|
+
"data-pswp-caption": caption,
|
|
65
|
+
"data-pswp-height": height,
|
|
66
|
+
"data-pswp-src": src,
|
|
67
|
+
"data-pswp-width": width,
|
|
68
|
+
type: "button",
|
|
69
|
+
children: [
|
|
70
|
+
children,
|
|
71
|
+
/* @__PURE__ */ jsx(
|
|
72
|
+
"span",
|
|
73
|
+
{
|
|
74
|
+
"aria-hidden": "true",
|
|
75
|
+
className: "bg-background/90 ring-border pointer-events-none absolute top-3 right-3 flex size-8 items-center justify-center rounded-full opacity-0 ring-1 transition-opacity group-hover:opacity-100 group-focus-visible:opacity-100",
|
|
76
|
+
children: /* @__PURE__ */ jsxs(
|
|
77
|
+
"svg",
|
|
78
|
+
{
|
|
79
|
+
className: "text-foreground size-4",
|
|
80
|
+
fill: "none",
|
|
81
|
+
stroke: "currentColor",
|
|
82
|
+
strokeLinecap: "round",
|
|
83
|
+
strokeLinejoin: "round",
|
|
84
|
+
strokeWidth: "2",
|
|
85
|
+
viewBox: "0 0 24 24",
|
|
86
|
+
children: [
|
|
87
|
+
/* @__PURE__ */ jsx("title", { children: "Zoom" }),
|
|
88
|
+
/* @__PURE__ */ jsx("path", { d: "M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7" })
|
|
89
|
+
]
|
|
90
|
+
}
|
|
91
|
+
)
|
|
92
|
+
}
|
|
93
|
+
)
|
|
94
|
+
]
|
|
95
|
+
}
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export { FigureLightboxTrigger, MDX_FIGURE_LIGHTBOX_GALLERY_ID, getImageDimensions, getRealImageDimensions, loadImageDimensions };
|
|
100
|
+
//# sourceMappingURL=chunk-IART7J2U.js.map
|
|
101
|
+
//# sourceMappingURL=chunk-IART7J2U.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lightbox/constants.ts","../src/lightbox/dimensions.ts","../src/lightbox/figure-l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A,EAAY,MAAA;AAAA,YACZ,SAAA,EAAU,0NAAA;AAAA,YAEV,QAAA,kBAAA,IAAA;AAAA,cAAC,KAAA;AAAA,cAAA;AAAA,gBACC,SAAA,EAAU,wBAAA;AAAA,gBACV,IAAA,EAAK,MAAA;AAAA,gBACL,MAAA,EAAO,cAAA;AAAA,gBACP,aAAA,EAAc,OAAA;AAAA,gBACd,cAAA,EAAe,OAAA;AAAA,gBACf,WAAA,EAAY,GAAA;AAAA,gBACZ,OAAA,EAAQ,WAAA;AAAA,gBAER,QAAA,EAAA;AAAA,kCAAA,GAAA,CAAC,WAAM,QAAA,EAAA,MAAA,EAAI,CAAA;AAAA,kCACX,GAAA,CAAC,MAAA,EAAA,EAAK,CAAA,EAAE,wCAAA,EAAyC;AAAA;AAAA;AAAA;AACnD;AAAA;AACF;AAAA;AAAA,GACF;AAEJ","file":"chunk-IART7J2U.js","sourcesContent":["/** Default gallery id — all FigureBlocks with lightbox share this connected set. */\nexport const MDX_FIGURE_LIGHTBOX_GALLERY_ID = 'atom63-mdx-figures'\n","export function getImageDimensions(\n aspectRatio?: string,\n defaultWidth = 1200\n): { width: number; height: number } {\n const ratioMap = {\n '1/1': { width: defaultWidth, height: defaultWidth },\n '4/3': { width: defaultWidth, height: Math.round(defaultWidth * 0.75) },\n '3/4': { width: defaultWidth, height: Math.round(defaultWidth * 1.33) },\n '16/9': { width: defaultWidth, height: Math.round(defaultWidth * 0.5625) },\n '9/16': { width: defaultWidth, height: Math.round(defaultWidth * 1.78) },\n }\n\n return ratioMap[aspectRatio as keyof typeof ratioMap] ?? ratioMap['16/9']\n}\n\nexport function loadImageDimensions(src: string): Promise<{ width: number; height: number }> {\n return new Promise((resolve, reject) => {\n const img = new Image()\n\n img.onload = () => {\n const width = img.naturalWidth\n const height = img.naturalHeight\n if (width > 0 && height > 0) {\n resolve({ width, height })\n return\n }\n reject(new Error('Image has no intrinsic dimensions'))\n }\n\n img.onerror = () => {\n reject(new Error(`Failed to load image dimensions for ${src}`))\n }\n\n img.src = src\n })\n}\n\nexport async function getRealImageDimensions(\n src: string,\n aspectRatio?: string\n): Promise<{ width: number; height: number }> {\n try {\n return await loadImageDimensions(src)\n } catch {\n return getImageDimensions(aspectRatio)\n }\n}\n","import { clsx } from 'clsx'\nimport { MDX_FIGURE_LIGHTBOX_GALLERY_ID } from './constants'\n\nexport type FigureLightboxTriggerProps = {\n alt: string\n caption?: string\n children: React.ReactNode\n className?: string\n galleryId?: string\n height: number\n src: string\n width: number\n}\n\nexport function FigureLightboxTrigger({\n src,\n alt,\n caption,\n width,\n height,\n galleryId = MDX_FIGURE_LIGHTBOX_GALLERY_ID,\n className,\n children,\n}: FigureLightboxTriggerProps) {\n const label = alt.trim() ? `View ${alt} in gallery` : 'View image in gallery'\n\n return (\n <button\n aria-label={label}\n className={clsx(\n 'group relative block w-full cursor-zoom-in overflow-hidden border-none bg-transparent p-0',\n className\n )}\n data-gallery-id={galleryId}\n data-pswp-alt={alt}\n data-pswp-caption={caption}\n data-pswp-height={height}\n data-pswp-src={src}\n data-pswp-width={width}\n type=\"button\"\n >\n {children}\n <span\n aria-hidden=\"true\"\n className=\"bg-background/90 ring-border pointer-events-none absolute top-3 right-3 flex size-8 items-center justify-center rounded-full opacity-0 ring-1 transition-opacity group-hover:opacity-100 group-focus-visible:opacity-100\"\n >\n <svg\n className=\"text-foreground size-4\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n strokeWidth=\"2\"\n viewBox=\"0 0 24 24\"\n >\n <title>Zoom</title>\n <path d=\"M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7\" />\n </svg>\n </span>\n </button>\n )\n}\n"]}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { MDX_FIGURE_LIGHTBOX_GALLERY_ID } from './chunk-IART7J2U.js';
|
|
2
|
+
import { MediaLightbox } from '@atom63/ui-react/media';
|
|
3
|
+
import { useRef, useState, useEffect } from 'react';
|
|
4
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
5
|
+
|
|
6
|
+
// src/lightbox/open-lightbox.ts
|
|
7
|
+
function normalizeDimension(value, fallback) {
|
|
8
|
+
const parsed = Number.parseInt(value ?? "", 10);
|
|
9
|
+
return parsed > 0 ? parsed : fallback;
|
|
10
|
+
}
|
|
11
|
+
function readTriggerImage(trigger) {
|
|
12
|
+
return {
|
|
13
|
+
src: trigger.getAttribute("data-pswp-src") ?? "",
|
|
14
|
+
width: normalizeDimension(trigger.getAttribute("data-pswp-width") ?? void 0, 1200),
|
|
15
|
+
height: normalizeDimension(trigger.getAttribute("data-pswp-height") ?? void 0, 800),
|
|
16
|
+
alt: trigger.getAttribute("data-pswp-alt") ?? "",
|
|
17
|
+
caption: trigger.getAttribute("data-pswp-caption") ?? void 0
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function collectFigureLightboxImages(galleryId, clickedTrigger) {
|
|
21
|
+
const selector = [
|
|
22
|
+
`button[data-pswp-src][data-gallery-id="${galleryId}"]`,
|
|
23
|
+
`[data-gallery-id="${galleryId}"] button[data-pswp-src]`
|
|
24
|
+
].join(", ");
|
|
25
|
+
const triggers = document.querySelectorAll(selector);
|
|
26
|
+
const images = [];
|
|
27
|
+
const imageTriggers = [];
|
|
28
|
+
let clickedIndex = 0;
|
|
29
|
+
for (const trigger of triggers) {
|
|
30
|
+
if (trigger === clickedTrigger) {
|
|
31
|
+
clickedIndex = images.length;
|
|
32
|
+
}
|
|
33
|
+
const image = readTriggerImage(trigger);
|
|
34
|
+
if (image.src) {
|
|
35
|
+
images.push(image);
|
|
36
|
+
imageTriggers.push(trigger);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return { images, index: clickedIndex, triggers: imageTriggers };
|
|
40
|
+
}
|
|
41
|
+
var openLightboxCount = 0;
|
|
42
|
+
var lightboxClosedAt = 0;
|
|
43
|
+
function markFigureLightboxOpen(open) {
|
|
44
|
+
if (open) {
|
|
45
|
+
openLightboxCount += 1;
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
openLightboxCount = Math.max(0, openLightboxCount - 1);
|
|
49
|
+
lightboxClosedAt = Date.now();
|
|
50
|
+
}
|
|
51
|
+
function isFigureLightboxOpen() {
|
|
52
|
+
if (openLightboxCount > 0) return true;
|
|
53
|
+
return Date.now() - lightboxClosedAt < 50;
|
|
54
|
+
}
|
|
55
|
+
function resolveLightboxTrigger(target) {
|
|
56
|
+
return target.closest("button[data-pswp-src]");
|
|
57
|
+
}
|
|
58
|
+
function originFor(trigger) {
|
|
59
|
+
return trigger?.querySelector("img, video") ?? trigger ?? null;
|
|
60
|
+
}
|
|
61
|
+
function FigureLightboxHost({ children, galleryId }) {
|
|
62
|
+
const rootRef = useRef(null);
|
|
63
|
+
const [gallery, setGallery] = useState({ items: [], triggers: [] });
|
|
64
|
+
const [open, setOpen] = useState(false);
|
|
65
|
+
const [index, setIndex] = useState(0);
|
|
66
|
+
const [origin, setOrigin] = useState(null);
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
const root = rootRef.current;
|
|
69
|
+
if (!root) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const handleClick = (event) => {
|
|
73
|
+
const target = event.target;
|
|
74
|
+
if (!(target instanceof Element)) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const trigger = resolveLightboxTrigger(target);
|
|
78
|
+
if (!trigger || !root.contains(trigger)) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const triggerGalleryId = trigger.getAttribute("data-gallery-id") || MDX_FIGURE_LIGHTBOX_GALLERY_ID;
|
|
82
|
+
if (galleryId && triggerGalleryId !== galleryId) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
event.preventDefault();
|
|
86
|
+
const {
|
|
87
|
+
images,
|
|
88
|
+
index: clickedIndex,
|
|
89
|
+
triggers
|
|
90
|
+
} = collectFigureLightboxImages(triggerGalleryId, trigger);
|
|
91
|
+
if (images.length === 0) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
setGallery({
|
|
95
|
+
items: images.map((image, imageIndex) => ({
|
|
96
|
+
id: `${triggerGalleryId}-${imageIndex}-${image.src}`,
|
|
97
|
+
src: image.src,
|
|
98
|
+
alt: image.alt ?? "",
|
|
99
|
+
title: image.alt || image.caption || "Image",
|
|
100
|
+
caption: image.caption
|
|
101
|
+
})),
|
|
102
|
+
triggers
|
|
103
|
+
});
|
|
104
|
+
setIndex(clickedIndex);
|
|
105
|
+
setOrigin(originFor(triggers[clickedIndex]));
|
|
106
|
+
setOpen(true);
|
|
107
|
+
};
|
|
108
|
+
root.addEventListener("click", handleClick);
|
|
109
|
+
return () => {
|
|
110
|
+
root.removeEventListener("click", handleClick);
|
|
111
|
+
};
|
|
112
|
+
}, [galleryId]);
|
|
113
|
+
useEffect(() => {
|
|
114
|
+
if (!open) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
markFigureLightboxOpen(true);
|
|
118
|
+
return () => markFigureLightboxOpen(false);
|
|
119
|
+
}, [open]);
|
|
120
|
+
const handleOpenChange = (next) => {
|
|
121
|
+
if (!next) {
|
|
122
|
+
setOrigin(originFor(gallery.triggers[index]));
|
|
123
|
+
}
|
|
124
|
+
setOpen(next);
|
|
125
|
+
};
|
|
126
|
+
return /* @__PURE__ */ jsxs("div", { className: "contents", "data-figure-lightbox-host": "", ref: rootRef, children: [
|
|
127
|
+
children,
|
|
128
|
+
gallery.items.length > 0 ? /* @__PURE__ */ jsx(
|
|
129
|
+
MediaLightbox,
|
|
130
|
+
{
|
|
131
|
+
index,
|
|
132
|
+
items: gallery.items,
|
|
133
|
+
onIndexChange: setIndex,
|
|
134
|
+
onOpenChange: handleOpenChange,
|
|
135
|
+
open,
|
|
136
|
+
origin
|
|
137
|
+
}
|
|
138
|
+
) : null
|
|
139
|
+
] });
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export { FigureLightboxHost, collectFigureLightboxImages, isFigureLightboxOpen, resolveLightboxTrigger };
|
|
143
|
+
//# sourceMappingURL=chunk-OUEW54AC.js.map
|
|
144
|
+
//# sourceMappingURL=chunk-OUEW54AC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lightbox/open-lightbox.ts","../src/lightbox/figure-lightbox-host.tsx"],"names":[],"mappings":";;;;;;AAEA,SAAS,kBAAA,CAAmB,OAA2B,QAAA,EAAkB;AACvE,EAAA,MAAM,MAAA,GAAS,MAAA,CAAO,QAAA,CAAS,KAAA,IAAS,IAAI,EAAE,CAAA;AAC9C,EAAA,OAAO,MAAA,GAAS,IAAI,MAAA,GAAS,QAAA;AAC/B;AAEA,SAAS,iBAAiB,OAAA,EAA2C;AACnE,EAAA,OAAO;AAAA,IACL,GAAA,EAAK,OAAA,CAAQ,YAAA,CAAa,eAAe,CAAA,IAAK,EAAA;AAAA,IAC9C,OAAO,kBAAA,CAAmB,OAAA,CAAQ,aAAa,iBAAiB,CAAA,IAAK,QAAW,IAAI,CAAA;AAAA,IACpF,QAAQ,kBAAA,CAAmB,OAAA,CAAQ,aAAa,kBAAkB,CAAA,IAAK,QAAW,GAAG,CAAA;AAAA,IACrF,GAAA,EAAK,OAAA,CAAQ,YAAA,CAAa,eAAe,CAAA,IAAK,EAAA;AAAA,IAC9C,OAAA,EAAS,OAAA,CAAQ,YAAA,CAAa,mBAAmB,CAAA,IAAK;AAAA,GACxD;AACF;AAGO,SAAS,2BAAA,CAA4B,WAAmB,cAAA,EAA6B;AAC1F,EAAA,MAAM,QAAA,GAAW;AAAA,IACf,0CAA0C,SAAS,CAAA,EAAA,CAAA;AAAA,IACnD,qBAAqB,SAAS,CAAA,wBAAA;AAAA,GAChC,CAAE,KAAK,IAAI,CAAA;AAEX,EAAA,MAAM,QAAA,GAAW,QAAA,CAAS,gBAAA,CAA8B,QAAQ,CAAA;AAChE,EAAA,MAAM,SAAgC,EAAC;AACvC,EAAA,MAAM,gBAA+B,EA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A;AAAA,EACd,CAAA;AAEA,EAAA,4BACG,KAAA,EAAA,EAAI,SAAA,EAAU,YAAW,2BAAA,EAA0B,EAAA,EAAG,KAAK,OAAA,EACzD,QAAA,EAAA;AAAA,IAAA,QAAA;AAAA,IACA,OAAA,CAAQ,KAAA,CAAM,MAAA,GAAS,CAAA,mBACtB,GAAA;AAAA,MAAC,aAAA;AAAA,MAAA;AAAA,QACC,KAAA;AAAA,QACA,OAAO,OAAA,CAAQ,KAAA;AAAA,QACf,aAAA,EAAe,QAAA;AAAA,QACf,YAAA,EAAc,gBAAA;AAAA,QACd,IAAA;AAAA,QACA;AAAA;AAAA,KACF,GACE;AAAA,GAAA,EACN,CAAA;AAEJ","file":"chunk-OUEW54AC.js","sourcesContent":["import type { PhotoSwipeImageData } from './types'\n\nfunction normalizeDimension(value: string | undefined, fallback: number) {\n const parsed = Number.parseInt(value ?? '', 10)\n return parsed > 0 ? parsed : fallback\n}\n\nfunction readTriggerImage(trigger: HTMLElement): PhotoSwipeImageData {\n return {\n src: trigger.getAttribute('data-pswp-src') ?? '',\n width: normalizeDimension(trigger.getAttribute('data-pswp-width') ?? undefined, 1200),\n height: normalizeDimension(trigger.getAttribute('data-pswp-height') ?? undefined, 800),\n alt: trigger.getAttribute('data-pswp-alt') ?? '',\n caption: trigger.getAttribute('data-pswp-caption') ?? undefined,\n }\n}\n\n/** Collect all lightbox triggers for a gallery id in DOM order. */\nexport function collectFigureLightboxImages(galleryId: string, clickedTrigger: HTMLElement) {\n const selector = [\n `button[data-pswp-src][data-gallery-id=\"${galleryId}\"]`,\n `[data-gallery-id=\"${galleryId}\"] button[data-pswp-src]`,\n ].join(', ')\n\n const triggers = document.querySelectorAll<HTMLElement>(selector)\n const images: PhotoSwipeImageData[] = []\n const imageTriggers: HTMLElement[] = []\n let clickedIndex = 0\n\n for (const trigger of triggers) {\n if (trigger === clickedTrigger) {\n clickedIndex = images.length\n }\n const image = readTriggerImage(trigger)\n if (image.src) {\n images.push(image)\n imageTriggers.push(trigger)\n }\n }\n\n return { images, index: clickedIndex, triggers: imageTriggers }\n}\n\nlet openLightboxCount = 0\n/** Grace window so Escape that closes the lightbox does not also dismiss a parent modal. */\nlet lightboxClosedAt = 0\n\n/** Called by FigureLightboxHost when its lightbox opens or closes. */\nexport function markFigureLightboxOpen(open: boolean) {\n if (open) {\n openLightboxCount += 1\n return\n }\n openLightboxCount = Math.max(0, openLightboxCount - 1)\n lightboxClosedAt = Date.now()\n}\n\n/** True while a figure lightbox is open (or just closed on this Escape tick). */\nexport function isFigureLightboxOpen() {\n if (openLightboxCount > 0) return true\n return Date.now() - lightboxClosedAt < 50\n}\n","import { MediaLightbox, type MediaLightboxItem } from '@atom63/ui-react/media'\nimport { useEffect, useRef, useState } from 'react'\nimport { MDX_FIGURE_LIGHTBOX_GALLERY_ID } from './constants'\nimport { collectFigureLightboxImages, markFigureLightboxOpen } from './open-lightbox'\n\nexport type FigureLightboxHostProps = {\n children: React.ReactNode\n /**\n * Optional gallery filter. When omitted (default), every `button[data-pswp-src]`\n * in the subtree is handled — including ImageBlock / ImageGrid custom gallery ids.\n */\n galleryId?: string\n}\n\ntype Gallery = {\n items: MediaLightboxItem[]\n triggers: HTMLElement[]\n}\n\n/** Resolve a lightbox trigger from a click target (any gallery). */\nexport function resolveLightboxTrigger(target: Element): HTMLElement | null {\n return target.closest<HTMLElement>('button[data-pswp-src]')\n}\n\n/** The morph grows out of the picture inside the trigger, not the button around it. */\nfunction originFor(trigger: HTMLElement | undefined) {\n return trigger?.querySelector<HTMLElement>('img, video') ?? trigger ?? null\n}\n\n/**\n * Single delegated click handler for all figure lightbox triggers in MDX content.\n * Mount once per MDX root (via MDXContentProvider). The gallery opens in the\n * design system's `MediaLightbox`.\n */\nexport function FigureLightboxHost({ children, galleryId }: FigureLightboxHostProps) {\n const rootRef = useRef<HTMLDivElement>(null)\n const [gallery, setGallery] = useState<Gallery>({ items: [], triggers: [] })\n const [open, setOpen] = useState(false)\n const [index, setIndex] = useState(0)\n const [origin, setOrigin] = useState<HTMLElement | null>(null)\n\n useEffect(() => {\n const root = rootRef.current\n if (!root) {\n return\n }\n\n const handleClick = (event: MouseEvent) => {\n const target = event.target\n if (!(target instanceof Element)) {\n return\n }\n\n const trigger = resolveLightboxTrigger(target)\n if (!trigger || !root.contains(trigger)) {\n return\n }\n\n const triggerGalleryId =\n trigger.getAttribute('data-gallery-id') || MDX_FIGURE_LIGHTBOX_GALLERY_ID\n\n if (galleryId && triggerGalleryId !== galleryId) {\n return\n }\n\n event.preventDefault()\n const {\n images,\n index: clickedIndex,\n triggers,\n } = collectFigureLightboxImages(triggerGalleryId, trigger)\n if (images.length === 0) {\n return\n }\n\n setGallery({\n items: images.map((image, imageIndex) => ({\n id: `${triggerGalleryId}-${imageIndex}-${image.src}`,\n src: image.src,\n alt: image.alt ?? '',\n title: image.alt || image.caption || 'Image',\n caption: image.caption,\n })),\n triggers,\n })\n setIndex(clickedIndex)\n setOrigin(originFor(triggers[clickedIndex]))\n setOpen(true)\n }\n\n // Bubble from subtree (works with `display: contents` host).\n root.addEventListener('click', handleClick)\n return () => {\n root.removeEventListener('click', handleClick)\n }\n }, [galleryId])\n\n useEffect(() => {\n if (!open) {\n return\n }\n markFigureLightboxOpen(true)\n return () => markFigureLightboxOpen(false)\n }, [open])\n\n const handleOpenChange = (next: boolean) => {\n if (!next) {\n // Morph back to the picture now on screen, which a swipe may have changed.\n setOrigin(originFor(gallery.triggers[index]))\n }\n setOpen(next)\n }\n\n return (\n <div className=\"contents\" data-figure-lightbox-host=\"\" ref={rootRef}>\n {children}\n {gallery.items.length > 0 ? (\n <MediaLightbox\n index={index}\n items={gallery.items}\n onIndexChange={setIndex}\n onOpenChange={handleOpenChange}\n open={open}\n origin={origin}\n />\n ) : null}\n </div>\n )\n}\n"]}
|