Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 535f2eb

Browse files
committed
feat(mdx): add background syntax
1 parent 07e798d commit 535f2eb

File tree

10 files changed

+165
-14
lines changed

10 files changed

+165
-14
lines changed

packages/client/assets/style/customize.css

+14-1
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,26 @@
2929
color: var(--color-base);
3030
text-align: var(--base-align);
3131
background: var(--color-background);
32+
position: relative;
3233
}
3334

3435
.slide-internal-box {
35-
background: inherit;
3636
padding: 16px;
3737
text-align: inherit;
3838
max-width: var(--base-max-slide-size);
3939
margin: auto;
4040
min-width: 320px;
41+
z-index: 2;
42+
}
43+
44+
.slide-background-div {
45+
position: absolute;
46+
top: 0;
47+
left: 0;
48+
background-blend-mode: multiply;
49+
background-repeat: no-repeat;
50+
background-size: cover;
51+
width: 100%;
52+
height: 100%;
53+
pointer-events: none;
4154
}

packages/client/assets/style/tags.css

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
html {
22
font-size: 62.5%;
33
-webkit-print-color-adjust: exact;
4+
background: var(--color-background);
45
}
56

67
body {

packages/client/src/components/SlideCore.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,13 @@ export const SlideCore = ({ slides, onChangeSlideIndex }) => (
6363
onSlideChange={({ realIndex }) => onChangeSlideIndex(realIndex)}
6464
className="slide-background"
6565
>
66-
{slides.map(({ slide: Slide, fusumaProps }, i) => (
66+
{slides.map(({ slide: Slide, fusumaProps: { classes, sectionTitle, background } }, i) => (
6767
<SwiperSlide
6868
key={i /* mdx-loaderでhash作成 */}
69-
className={classnames(
70-
'slide-box',
71-
fusumaProps.classes,
72-
fusumaProps.sectionTitle ? 'section-title' : undefined
73-
)}
69+
className={classnames('slide-box', classes, sectionTitle ? 'section-title' : undefined)}
7470
data-hash={`slide-${i + 1}`}
7571
>
72+
{background && <div className="slide-background-div" style={{ background }} />}
7673
<div className="slide-internal-box">
7774
<Slide />
7875
</div>

packages/client/src/utils/createSlidesProps.js

+16-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ import { ToC } from '../components/ToC';
33
export function createSlidesProps(slides) {
44
const slidesArr = [];
55
const propsArr = [];
6+
const backgroundsArr = [];
67
const res = {};
78

8-
slides.forEach(({ slides, fusumaProps }) => {
9+
slides.forEach(({ slides, fusumaProps, backgrounds }) => {
910
slidesArr.push(...slides);
1011
propsArr.push(...fusumaProps);
12+
backgroundsArr.push(...backgrounds);
1113
});
1214

1315
propsArr.reduce((acc, { sectionTitle }, i) => {
@@ -22,10 +24,22 @@ export function createSlidesProps(slides) {
2224

2325
res.slides = slidesArr.map((slide, i) => {
2426
const props = propsArr[i];
27+
const background = (() => {
28+
if (backgroundsArr[i] === 0) {
29+
return null;
30+
}
31+
if (backgroundsArr[i].includes('/')) {
32+
return `url('${backgroundsArr[i]}')`;
33+
}
34+
return backgroundsArr[i];
35+
})();
2536

2637
return {
2738
slide: props.contents ? ToC({ list: res.contentsList }) : slide,
28-
fusumaProps: props,
39+
fusumaProps: {
40+
...props,
41+
background,
42+
},
2943
};
3044
});
3145

packages/mdx-loader/__tests__/__snapshots__/index.js.snap

+81
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,73 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`fusuma-loader should add background to props 1`] = `
4+
"/* @jsxRuntime classic */
5+
/* @jsx mdx */
6+
7+
import React from 'react';
8+
import { mdx } from '@mdx-js/react';
9+
export const slides = [props => <>
10+
11+
12+
13+
</>];
14+
export const backgrounds = ['red'];
15+
export const fusumaProps = [{}];
16+
17+
const layoutProps = {
18+
19+
};
20+
const MDXLayout = \\"wrapper\\"
21+
export default function MDXContent({
22+
components,
23+
...props
24+
}) {
25+
return <MDXLayout {...layoutProps} {...props} components={components} mdxType=\\"MDXLayout\\">
26+
{
27+
/* background: red */
28+
}
29+
30+
</MDXLayout>;
31+
}
32+
33+
;
34+
MDXContent.isMDXComponent = true;"
35+
`;
36+
37+
exports[`fusuma-loader should add background(url) to props 1`] = `
38+
"/* @jsxRuntime classic */
39+
/* @jsx mdx */
40+
41+
import React from 'react';
42+
import { mdx } from '@mdx-js/react';
43+
export const slides = [props => <>
44+
45+
46+
47+
</>];
48+
export const backgrounds = [require('../../img.jpeg')];
49+
export const fusumaProps = [{}];
50+
51+
const layoutProps = {
52+
53+
};
54+
const MDXLayout = \\"wrapper\\"
55+
export default function MDXContent({
56+
components,
57+
...props
58+
}) {
59+
return <MDXLayout {...layoutProps} {...props} components={components} mdxType=\\"MDXLayout\\">
60+
{
61+
/* background: '../../img.jpeg' */
62+
}
63+
64+
</MDXLayout>;
65+
}
66+
67+
;
68+
MDXContent.isMDXComponent = true;"
69+
`;
70+
371
exports[`fusuma-loader should add data-line to pre tag 1`] = `
472
"/* @jsxRuntime classic */
573
/* @jsx mdx */
@@ -22,6 +90,7 @@ export const slides = [props => <>
2290
\`}</code></pre>
2391

2492
</>];
93+
export const backgrounds = [0];
2594
export const fusumaProps = [{}];
2695

2796
const layoutProps = {
@@ -68,6 +137,7 @@ export const slides = [props => <>
68137
<div className=\\"fusuma-screen\\"><div>This view can capture the screen.<br />Click to get started.;)<br /><br />Note: This feature runs only in Presenter Mode.</div><video id=\\"fusuma-screen-1\\" /></div>
69138

70139
</>];
140+
export const backgrounds = [0];
71141
export const fusumaProps = [{
72142
note: 'This is Note!',
73143
classes: 'class!',
@@ -128,6 +198,7 @@ in\`}</p>
128198
</div>
129199

130200
</>];
201+
export const backgrounds = [0];
131202
export const fusumaProps = [{}];
132203

133204
const layoutProps = {
@@ -187,6 +258,7 @@ console.log(a + b);
187258
\`}</code></pre>
188259

189260
</>];
261+
export const backgrounds = [0];
190262
export const fusumaProps = [{
191263
hasExecutableCode: 'true'
192264
}];
@@ -380,6 +452,7 @@ export const slides = [props => <>
380452
}}>{\`2\`}</span></span></span></span></span></span></span></span></span></span></span></span></div>
381453

382454
</>];
455+
export const backgrounds = [0];
383456
export const fusumaProps = [{}];
384457

385458
const layoutProps = {
@@ -563,6 +636,7 @@ export const slides = [props => <>
563636
<svg className=\\"qr\\" version=\\"1.1\\" xmlns=\\"http://www.w3.org/2000/svg\\" width=\\"66px\\" height=\\"66px\\" viewBox=\\"0 0 66 66\\" preserveAspectRatio=\\"xMinYMin meet\\"><rect width=\\"100%\\" height=\\"100%\\" fill=\\"white\\" cx=\\"0\\" cy=\\"0\\" /><path d=\\"M8,8l2,0 0,2 -2,0 0,-2z M10,8l2,0 0,2 -2,0 0,-2z M12,8l2,0 0,2 -2,0 0,-2z M14,8l2,0 0,2 -2,0 0,-2z M16,8l2,0 0,2 -2,0 0,-2z M18,8l2,0 0,2 -2,0 0,-2z M20,8l2,0 0,2 -2,0 0,-2z M24,8l2,0 0,2 -2,0 0,-2z M26,8l2,0 0,2 -2,0 0,-2z M28,8l2,0 0,2 -2,0 0,-2z M30,8l2,0 0,2 -2,0 0,-2z M36,8l2,0 0,2 -2,0 0,-2z M44,8l2,0 0,2 -2,0 0,-2z M46,8l2,0 0,2 -2,0 0,-2z M48,8l2,0 0,2 -2,0 0,-2z M50,8l2,0 0,2 -2,0 0,-2z M52,8l2,0 0,2 -2,0 0,-2z M54,8l2,0 0,2 -2,0 0,-2z M56,8l2,0 0,2 -2,0 0,-2z M8,10l2,0 0,2 -2,0 0,-2z M20,10l2,0 0,2 -2,0 0,-2z M30,10l2,0 0,2 -2,0 0,-2z M32,10l2,0 0,2 -2,0 0,-2z M34,10l2,0 0,2 -2,0 0,-2z M40,10l2,0 0,2 -2,0 0,-2z M44,10l2,0 0,2 -2,0 0,-2z M56,10l2,0 0,2 -2,0 0,-2z M8,12l2,0 0,2 -2,0 0,-2z M12,12l2,0 0,2 -2,0 0,-2z M14,12l2,0 0,2 -2,0 0,-2z M16,12l2,0 0,2 -2,0 0,-2z M20,12l2,0 0,2 -2,0 0,-2z M26,12l2,0 0,2 -2,0 0,-2z M30,12l2,0 0,2 -2,0 0,-2z M34,12l2,0 0,2 -2,0 0,-2z M36,12l2,0 0,2 -2,0 0,-2z M44,12l2,0 0,2 -2,0 0,-2z M48,12l2,0 0,2 -2,0 0,-2z M50,12l2,0 0,2 -2,0 0,-2z M52,12l2,0 0,2 -2,0 0,-2z M56,12l2,0 0,2 -2,0 0,-2z M8,14l2,0 0,2 -2,0 0,-2z M12,14l2,0 0,2 -2,0 0,-2z M14,14l2,0 0,2 -2,0 0,-2z M16,14l2,0 0,2 -2,0 0,-2z M20,14l2,0 0,2 -2,0 0,-2z M28,14l2,0 0,2 -2,0 0,-2z M30,14l2,0 0,2 -2,0 0,-2z M36,14l2,0 0,2 -2,0 0,-2z M38,14l2,0 0,2 -2,0 0,-2z M40,14l2,0 0,2 -2,0 0,-2z M44,14l2,0 0,2 -2,0 0,-2z M48,14l2,0 0,2 -2,0 0,-2z M50,14l2,0 0,2 -2,0 0,-2z M52,14l2,0 0,2 -2,0 0,-2z M56,14l2,0 0,2 -2,0 0,-2z M8,16l2,0 0,2 -2,0 0,-2z M12,16l2,0 0,2 -2,0 0,-2z M14,16l2,0 0,2 -2,0 0,-2z M16,16l2,0 0,2 -2,0 0,-2z M20,16l2,0 0,2 -2,0 0,-2z M28,16l2,0 0,2 -2,0 0,-2z M30,16l2,0 0,2 -2,0 0,-2z M32,16l2,0 0,2 -2,0 0,-2z M34,16l2,0 0,2 -2,0 0,-2z M36,16l2,0 0,2 -2,0 0,-2z M40,16l2,0 0,2 -2,0 0,-2z M44,16l2,0 0,2 -2,0 0,-2z M48,16l2,0 0,2 -2,0 0,-2z M50,16l2,0 0,2 -2,0 0,-2z M52,16l2,0 0,2 -2,0 0,-2z M56,16l2,0 0,2 -2,0 0,-2z M8,18l2,0 0,2 -2,0 0,-2z M20,18l2,0 0,2 -2,0 0,-2z M26,18l2,0 0,2 -2,0 0,-2z M30,18l2,0 0,2 -2,0 0,-2z M34,18l2,0 0,2 -2,0 0,-2z M36,18l2,0 0,2 -2,0 0,-2z M44,18l2,0 0,2 -2,0 0,-2z M56,18l2,0 0,2 -2,0 0,-2z M8,20l2,0 0,2 -2,0 0,-2z M10,20l2,0 0,2 -2,0 0,-2z M12,20l2,0 0,2 -2,0 0,-2z M14,20l2,0 0,2 -2,0 0,-2z M16,20l2,0 0,2 -2,0 0,-2z M18,20l2,0 0,2 -2,0 0,-2z M20,20l2,0 0,2 -2,0 0,-2z M24,20l2,0 0,2 -2,0 0,-2z M28,20l2,0 0,2 -2,0 0,-2z M32,20l2,0 0,2 -2,0 0,-2z M36,20l2,0 0,2 -2,0 0,-2z M40,20l2,0 0,2 -2,0 0,-2z M44,20l2,0 0,2 -2,0 0,-2z M46,20l2,0 0,2 -2,0 0,-2z M48,20l2,0 0,2 -2,0 0,-2z M50,20l2,0 0,2 -2,0 0,-2z M52,20l2,0 0,2 -2,0 0,-2z M54,20l2,0 0,2 -2,0 0,-2z M56,20l2,0 0,2 -2,0 0,-2z M24,22l2,0 0,2 -2,0 0,-2z M26,22l2,0 0,2 -2,0 0,-2z M32,22l2,0 0,2 -2,0 0,-2z M36,22l2,0 0,2 -2,0 0,-2z M38,22l2,0 0,2 -2,0 0,-2z M8,24l2,0 0,2 -2,0 0,-2z M10,24l2,0 0,2 -2,0 0,-2z M14,24l2,0 0,2 -2,0 0,-2z M16,24l2,0 0,2 -2,0 0,-2z M20,24l2,0 0,2 -2,0 0,-2z M26,24l2,0 0,2 -2,0 0,-2z M32,24l2,0 0,2 -2,0 0,-2z M34,24l2,0 0,2 -2,0 0,-2z M36,24l2,0 0,2 -2,0 0,-2z M38,24l2,0 0,2 -2,0 0,-2z M40,24l2,0 0,2 -2,0 0,-2z M44,24l2,0 0,2 -2,0 0,-2z M56,24l2,0 0,2 -2,0 0,-2z M10,26l2,0 0,2 -2,0 0,-2z M22,26l2,0 0,2 -2,0 0,-2z M24,26l2,0 0,2 -2,0 0,-2z M28,26l2,0 0,2 -2,0 0,-2z M36,26l2,0 0,2 -2,0 0,-2z M38,26l2,0 0,2 -2,0 0,-2z M46,26l2,0 0,2 -2,0 0,-2z M48,26l2,0 0,2 -2,0 0,-2z M50,26l2,0 0,2 -2,0 0,-2z M52,26l2,0 0,2 -2,0 0,-2z M54,26l2,0 0,2 -2,0 0,-2z M14,28l2,0 0,2 -2,0 0,-2z M20,28l2,0 0,2 -2,0 0,-2z M26,28l2,0 0,2 -2,0 0,-2z M32,28l2,0 0,2 -2,0 0,-2z M36,28l2,0 0,2 -2,0 0,-2z M38,28l2,0 0,2 -2,0 0,-2z M46,28l2,0 0,2 -2,0 0,-2z M50,28l2,0 0,2 -2,0 0,-2z M56,28l2,0 0,2 -2,0 0,-2z M12,30l2,0 0,2 -2,0 0,-2z M14,30l2,0 0,2 -2,0 0,-2z M16,30l2,0 0,2 -2,0 0,-2z M18,30l2,0 0,2 -2,0 0,-2z M22,30l2,0 0,2 -2,0 0,-2z M24,30l2,0 0,2 -2,0 0,-2z M36,30l2,0 0,2 -2,0 0,-2z M38,30l2,0 0,2 -2,0 0,-2z M46,30l2,0 0,2 -2,0 0,-2z M50,30l2,0 0,2 -2,0 0,-2z M52,30l2,0 0,2 -2,0 0,-2z M54,30l2,0 0,2 -2,0 0,-2z M56,30l2,0 0,2 -2,0 0,-2z M8,32l2,0 0,2 -2,0 0,-2z M10,32l2,0 0,2 -2,0 0,-2z M12,32l2,0 0,2 -2,0 0,-2z M18,32l2,0 0,2 -2,0 0,-2z M20,32l2,0 0,2 -2,0 0,-2z M22,32l2,0 0,2 -2,0 0,-2z M24,32l2,0 0,2 -2,0 0,-2z M26,32l2,0 0,2 -2,0 0,-2z M28,32l2,0 0,2 -2,0 0,-2z M34,32l2,0 0,2 -2,0 0,-2z M36,32l2,0 0,2 -2,0 0,-2z M40,32l2,0 0,2 -2,0 0,-2z M44,32l2,0 0,2 -2,0 0,-2z M46,32l2,0 0,2 -2,0 0,-2z M56,32l2,0 0,2 -2,0 0,-2z M8,34l2,0 0,2 -2,0 0,-2z M14,34l2,0 0,2 -2,0 0,-2z M18,34l2,0 0,2 -2,0 0,-2z M22,34l2,0 0,2 -2,0 0,-2z M24,34l2,0 0,2 -2,0 0,-2z M26,34l2,0 0,2 -2,0 0,-2z M28,34l2,0 0,2 -2,0 0,-2z M32,34l2,0 0,2 -2,0 0,-2z M38,34l2,0 0,2 -2,0 0,-2z M48,34l2,0 0,2 -2,0 0,-2z M54,34l2,0 0,2 -2,0 0,-2z M8,36l2,0 0,2 -2,0 0,-2z M10,36l2,0 0,2 -2,0 0,-2z M16,36l2,0 0,2 -2,0 0,-2z M18,36l2,0 0,2 -2,0 0,-2z M20,36l2,0 0,2 -2,0 0,-2z M22,36l2,0 0,2 -2,0 0,-2z M24,36l2,0 0,2 -2,0 0,-2z M26,36l2,0 0,2 -2,0 0,-2z M28,36l2,0 0,2 -2,0 0,-2z M36,36l2,0 0,2 -2,0 0,-2z M38,36l2,0 0,2 -2,0 0,-2z M42,36l2,0 0,2 -2,0 0,-2z M48,36l2,0 0,2 -2,0 0,-2z M50,36l2,0 0,2 -2,0 0,-2z M52,36l2,0 0,2 -2,0 0,-2z M54,36l2,0 0,2 -2,0 0,-2z M56,36l2,0 0,2 -2,0 0,-2z M8,38l2,0 0,2 -2,0 0,-2z M22,38l2,0 0,2 -2,0 0,-2z M28,38l2,0 0,2 -2,0 0,-2z M32,38l2,0 0,2 -2,0 0,-2z M34,38l2,0 0,2 -2,0 0,-2z M36,38l2,0 0,2 -2,0 0,-2z M42,38l2,0 0,2 -2,0 0,-2z M46,38l2,0 0,2 -2,0 0,-2z M50,38l2,0 0,2 -2,0 0,-2z M52,38l2,0 0,2 -2,0 0,-2z M56,38l2,0 0,2 -2,0 0,-2z M8,40l2,0 0,2 -2,0 0,-2z M14,40l2,0 0,2 -2,0 0,-2z M16,40l2,0 0,2 -2,0 0,-2z M18,40l2,0 0,2 -2,0 0,-2z M20,40l2,0 0,2 -2,0 0,-2z M24,40l2,0 0,2 -2,0 0,-2z M28,40l2,0 0,2 -2,0 0,-2z M30,40l2,0 0,2 -2,0 0,-2z M32,40l2,0 0,2 -2,0 0,-2z M38,40l2,0 0,2 -2,0 0,-2z M40,40l2,0 0,2 -2,0 0,-2z M42,40l2,0 0,2 -2,0 0,-2z M44,40l2,0 0,2 -2,0 0,-2z M46,40l2,0 0,2 -2,0 0,-2z M48,40l2,0 0,2 -2,0 0,-2z M52,40l2,0 0,2 -2,0 0,-2z M54,40l2,0 0,2 -2,0 0,-2z M24,42l2,0 0,2 -2,0 0,-2z M26,42l2,0 0,2 -2,0 0,-2z M28,42l2,0 0,2 -2,0 0,-2z M30,42l2,0 0,2 -2,0 0,-2z M40,42l2,0 0,2 -2,0 0,-2z M48,42l2,0 0,2 -2,0 0,-2z M52,42l2,0 0,2 -2,0 0,-2z M54,42l2,0 0,2 -2,0 0,-2z M8,44l2,0 0,2 -2,0 0,-2z M10,44l2,0 0,2 -2,0 0,-2z M12,44l2,0 0,2 -2,0 0,-2z M14,44l2,0 0,2 -2,0 0,-2z M16,44l2,0 0,2 -2,0 0,-2z M18,44l2,0 0,2 -2,0 0,-2z M20,44l2,0 0,2 -2,0 0,-2z M32,44l2,0 0,2 -2,0 0,-2z M34,44l2,0 0,2 -2,0 0,-2z M36,44l2,0 0,2 -2,0 0,-2z M40,44l2,0 0,2 -2,0 0,-2z M44,44l2,0 0,2 -2,0 0,-2z M48,44l2,0 0,2 -2,0 0,-2z M56,44l2,0 0,2 -2,0 0,-2z M8,46l2,0 0,2 -2,0 0,-2z M20,46l2,0 0,2 -2,0 0,-2z M30,46l2,0 0,2 -2,0 0,-2z M34,46l2,0 0,2 -2,0 0,-2z M38,46l2,0 0,2 -2,0 0,-2z M40,46l2,0 0,2 -2,0 0,-2z M48,46l2,0 0,2 -2,0 0,-2z M8,48l2,0 0,2 -2,0 0,-2z M12,48l2,0 0,2 -2,0 0,-2z M14,48l2,0 0,2 -2,0 0,-2z M16,48l2,0 0,2 -2,0 0,-2z M20,48l2,0 0,2 -2,0 0,-2z M24,48l2,0 0,2 -2,0 0,-2z M26,48l2,0 0,2 -2,0 0,-2z M28,48l2,0 0,2 -2,0 0,-2z M30,48l2,0 0,2 -2,0 0,-2z M34,48l2,0 0,2 -2,0 0,-2z M38,48l2,0 0,2 -2,0 0,-2z M40,48l2,0 0,2 -2,0 0,-2z M42,48l2,0 0,2 -2,0 0,-2z M44,48l2,0 0,2 -2,0 0,-2z M46,48l2,0 0,2 -2,0 0,-2z M48,48l2,0 0,2 -2,0 0,-2z M56,48l2,0 0,2 -2,0 0,-2z M8,50l2,0 0,2 -2,0 0,-2z M12,50l2,0 0,2 -2,0 0,-2z M14,50l2,0 0,2 -2,0 0,-2z M16,50l2,0 0,2 -2,0 0,-2z M20,50l2,0 0,2 -2,0 0,-2z M24,50l2,0 0,2 -2,0 0,-2z M32,50l2,0 0,2 -2,0 0,-2z M34,50l2,0 0,2 -2,0 0,-2z M40,50l2,0 0,2 -2,0 0,-2z M42,50l2,0 0,2 -2,0 0,-2z M44,50l2,0 0,2 -2,0 0,-2z M54,50l2,0 0,2 -2,0 0,-2z M56,50l2,0 0,2 -2,0 0,-2z M8,52l2,0 0,2 -2,0 0,-2z M12,52l2,0 0,2 -2,0 0,-2z M14,52l2,0 0,2 -2,0 0,-2z M16,52l2,0 0,2 -2,0 0,-2z M20,52l2,0 0,2 -2,0 0,-2z M28,52l2,0 0,2 -2,0 0,-2z M30,52l2,0 0,2 -2,0 0,-2z M34,52l2,0 0,2 -2,0 0,-2z M40,52l2,0 0,2 -2,0 0,-2z M42,52l2,0 0,2 -2,0 0,-2z M48,52l2,0 0,2 -2,0 0,-2z M50,52l2,0 0,2 -2,0 0,-2z M52,52l2,0 0,2 -2,0 0,-2z M54,52l2,0 0,2 -2,0 0,-2z M56,52l2,0 0,2 -2,0 0,-2z M8,54l2,0 0,2 -2,0 0,-2z M20,54l2,0 0,2 -2,0 0,-2z M24,54l2,0 0,2 -2,0 0,-2z M30,54l2,0 0,2 -2,0 0,-2z M32,54l2,0 0,2 -2,0 0,-2z M34,54l2,0 0,2 -2,0 0,-2z M44,54l2,0 0,2 -2,0 0,-2z M46,54l2,0 0,2 -2,0 0,-2z M48,54l2,0 0,2 -2,0 0,-2z M52,54l2,0 0,2 -2,0 0,-2z M54,54l2,0 0,2 -2,0 0,-2z M56,54l2,0 0,2 -2,0 0,-2z M8,56l2,0 0,2 -2,0 0,-2z M10,56l2,0 0,2 -2,0 0,-2z M12,56l2,0 0,2 -2,0 0,-2z M14,56l2,0 0,2 -2,0 0,-2z M16,56l2,0 0,2 -2,0 0,-2z M18,56l2,0 0,2 -2,0 0,-2z M20,56l2,0 0,2 -2,0 0,-2z M24,56l2,0 0,2 -2,0 0,-2z M26,56l2,0 0,2 -2,0 0,-2z M30,56l2,0 0,2 -2,0 0,-2z M32,56l2,0 0,2 -2,0 0,-2z M34,56l2,0 0,2 -2,0 0,-2z M40,56l2,0 0,2 -2,0 0,-2z M50,56l2,0 0,2 -2,0 0,-2z M56,56l2,0 0,2 -2,0 0,-2z \\" stroke=\\"transparent\\" fill=\\"black\\" /></svg>
564637

565638
</>];
639+
export const backgrounds = [0];
566640
export const fusumaProps = [{}];
567641

568642
const layoutProps = {
@@ -601,6 +675,7 @@ export const slides = [props => <>
601675
</div>
602676

603677
</>];
678+
export const backgrounds = [0];
604679
export const fusumaProps = [{}];
605680

606681
const layoutProps = {
@@ -642,6 +717,7 @@ export const slides = [props => <>
642717
</div>
643718

644719
</>];
720+
export const backgrounds = [0];
645721
export const fusumaProps = [{}];
646722

647723
const layoutProps = {
@@ -682,6 +758,7 @@ export const slides = [props => <>
682758
<h1>{\`😄\`}</h1>
683759

684760
</>];
761+
export const backgrounds = [0, 0];
685762
export const fusumaProps = [{}, {}];
686763

687764
const layoutProps = {
@@ -718,6 +795,7 @@ export const slides = [props => <>
718795
\`}<img src={require('/tmp/withoutAlt.jpg')}></img></p>
719796

720797
</>];
798+
export const backgrounds = [0];
721799
export const fusumaProps = [{}];
722800

723801
const layoutProps = {
@@ -766,6 +844,7 @@ B-->D;
766844
C-->D;</div>
767845

768846
</>];
847+
export const backgrounds = [0, 0];
769848
export const fusumaProps = [{}, {}];
770849

771850
const layoutProps = {
@@ -810,6 +889,7 @@ export const slides = [props => <>
810889
<h1>{\`2\`}</h1>
811890

812891
</>];
892+
export const backgrounds = [0, 0];
813893
export const fusumaProps = [{}, {}];
814894

815895
const layoutProps = {
@@ -845,6 +925,7 @@ export const slides = [props => <>
845925
<Sample mdxType=\\"Sample\\" mdxType=\\"Sample\\" />
846926

847927
</>];
928+
export const backgrounds = [0];
848929
export const fusumaProps = [{}];
849930
const makeShortcode = name => function MDXDefaultShortcode(props) {
850931
console.warn(\\"Component \\" + name + \\" was not imported, exported, or provided by MDXProvider as global scope\\")

packages/mdx-loader/__tests__/index.js

+16
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,22 @@ const a = 1;
176176
const b = 2;
177177
console.log(a + b);
178178
\`\`\`
179+
`;
180+
181+
expect(await transformToJS(src)).toMatchSnapshot();
182+
});
183+
184+
test('should add background to props', async () => {
185+
const src = `
186+
<!-- background: red -->
187+
`;
188+
189+
expect(await transformToJS(src)).toMatchSnapshot();
190+
});
191+
192+
test('should add background(url) to props', async () => {
193+
const src = `
194+
<!-- background: '../../img.jpeg' -->
179195
`;
180196

181197
expect(await transformToJS(src)).toMatchSnapshot();

packages/mdx-loader/src/mdxPlugin.js

+16-5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ function mdxPlugin() {
1515
const slides = [];
1616
let slide = [];
1717
let props = {};
18+
let background = 0; // TODO: hmm... combine into fusumaProps but need to transform to `require`
1819
let videoId = 1;
1920
let mermaidId = 1;
2021

@@ -24,9 +25,10 @@ function mdxPlugin() {
2425

2526
// move to a new slide
2627
if (type === 'thematicBreak') {
27-
slides.push({ slide, props });
28+
slides.push({ slide, props, background });
2829
slide = [];
2930
props = {};
31+
background = 0; // why 0? null, undefined, '' are omitted at client side
3032
return;
3133
}
3234

@@ -35,6 +37,10 @@ function mdxPlugin() {
3537
const prefix = p.split('\n')[0];
3638
const attr = rest.map((r) => r.trim());
3739

40+
if (prefix === 'background') {
41+
background = attr[0].includes('/') ? `require(${attr[0]})` : `'${attr[0]}'`;
42+
return;
43+
}
3844
if (prefix === 'section-title') {
3945
props.sectionTitle = attr.join('');
4046
return;
@@ -138,15 +144,17 @@ function mdxPlugin() {
138144
.replace(/class=/g, 'className=');
139145
}
140146
});
147+
148+
// push last slide
149+
slides.push({ slide, props, background });
150+
141151
const res = {
142152
jsx: [],
143153
fusumaProps: [],
154+
background: [],
144155
};
145156

146-
// push last slide
147-
slides.push({ slide, props });
148-
149-
slides.forEach(({ slide, props }) => {
157+
slides.forEach(({ slide, props, background }) => {
150158
const hash = mdxAstToMdxHast()({
151159
type: 'root',
152160
children: slide,
@@ -160,6 +168,7 @@ function mdxPlugin() {
160168
for (const pos of matches) {
161169
const [, className] = pos;
162170
const div = className ? `<div className="${className.trim()}">` : '<div>';
171+
163172
mdxJSX = mdxJSX.replace(/{\s.+\/\* block-start:?(.*?) \*\/\s.+}/m, div);
164173
}
165174

@@ -179,6 +188,7 @@ function mdxPlugin() {
179188

180189
res.jsx.push(template);
181190
res.fusumaProps.push(fusumaProps);
191+
res.background.push(background);
182192
}
183193
});
184194

@@ -191,6 +201,7 @@ function mdxPlugin() {
191201
import React from 'react';
192202
import { mdx } from '@mdx-js/react';
193203
export const slides = [${res.jsx.join(',\n')}];
204+
export const backgrounds = [${res.background.join(',\n')}];
194205
export const fusumaProps = [${res.fusumaProps.join(',\n')}];`,
195206
});
196207
};

samples/debug/slides/09-background.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<!-- background: #444 -->
2+
3+
## background

samples/intro/assets/background.jpeg

90.9 KB
Loading

samples/intro/slides/04-slide.md

+15
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,21 @@ The class name of `<!-- block-start -->` isn't mandatory.
9898

9999
---
100100

101+
## Set Background
102+
103+
<!-- background: '../assets/background.jpeg' -->
104+
105+
```md
106+
<!-- background: '../assets/background.jpeg' -->
107+
108+
Also, you can specify `#` and names.
109+
110+
<!-- background: #f5f5f5 -->
111+
<!-- background: green -->
112+
```
113+
114+
---
115+
101116
## Declare Section Title
102117

103118
```md

0 commit comments

Comments
 (0)