@gpichot/spectacle-deck 1.2.0 → 1.2.1

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.
Files changed (76) hide show
  1. package/.turbo/turbo-build.log +4 -0
  2. package/.turbo/turbo-dev.log +4 -0
  3. package/{index.cjs → dist/index.cjs} +5 -4
  4. package/{index.mjs → dist/index.mjs} +5 -4
  5. package/package.json +21 -16
  6. package/publish.sh +7 -0
  7. package/scripts/bundle.ts +84 -0
  8. package/src/SlideWrapper.tsx +25 -0
  9. package/src/colors.ts +42 -0
  10. package/src/components/CodeStepper/CodeStepper.tsx +228 -0
  11. package/src/components/CodeStepper/code-directives.test.ts +58 -0
  12. package/src/components/CodeStepper/code-directives.ts +129 -0
  13. package/src/components/DocumentationItem.tsx +85 -0
  14. package/src/components/FilePane.tsx +18 -0
  15. package/src/components/HorizontalList.tsx +141 -0
  16. package/src/components/IconBox.tsx +31 -0
  17. package/src/components/Image.tsx +39 -0
  18. package/src/components/ItemsColumn.tsx +60 -0
  19. package/src/components/QRCode.tsx +55 -0
  20. package/src/components/Timeline.styled.tsx +24 -0
  21. package/src/components/Timeline.tsx +159 -0
  22. package/src/components/map.tsx +128 -0
  23. package/src/components/styled.tsx +73 -0
  24. package/src/context.tsx +33 -0
  25. package/src/front.png +0 -0
  26. package/src/index.tsx +127 -0
  27. package/src/layouts/BaseLayout.tsx +52 -0
  28. package/src/layouts/CenteredLayout.tsx +40 -0
  29. package/src/layouts/Default3Layout.tsx +159 -0
  30. package/src/layouts/MainSectionLayout.tsx +31 -0
  31. package/src/layouts/QuoteLayout.tsx +107 -0
  32. package/src/layouts/SectionLayout.tsx +14 -0
  33. package/src/layouts/SideCodeLayout.tsx +44 -0
  34. package/src/layouts/SideImageLayout.tsx +82 -0
  35. package/src/layouts/SideLayout.tsx +31 -0
  36. package/src/layouts/columns.tsx +56 -0
  37. package/src/layouts/index.tsx +19 -0
  38. package/src/layouts/styled.ts +7 -0
  39. package/src/layouts/utils.ts +66 -0
  40. package/src/node.d.ts +5 -0
  41. package/src/style.d.ts +10 -0
  42. package/src/template.tsx +25 -0
  43. package/src/theme.ts +28 -0
  44. package/tsconfig.json +29 -0
  45. /package/{SlideWrapper.d.ts → dist/SlideWrapper.d.ts} +0 -0
  46. /package/{colors.d.ts → dist/colors.d.ts} +0 -0
  47. /package/{components → dist/components}/CodeStepper/CodeStepper.d.ts +0 -0
  48. /package/{components → dist/components}/CodeStepper/code-directives.d.ts +0 -0
  49. /package/{components → dist/components}/DocumentationItem.d.ts +0 -0
  50. /package/{components → dist/components}/FilePane.d.ts +0 -0
  51. /package/{components → dist/components}/HorizontalList.d.ts +0 -0
  52. /package/{components → dist/components}/IconBox.d.ts +0 -0
  53. /package/{components → dist/components}/Image.d.ts +0 -0
  54. /package/{components → dist/components}/ItemsColumn.d.ts +0 -0
  55. /package/{components → dist/components}/QRCode.d.ts +0 -0
  56. /package/{components → dist/components}/Timeline.d.ts +0 -0
  57. /package/{components → dist/components}/Timeline.styled.d.ts +0 -0
  58. /package/{components → dist/components}/map.d.ts +0 -0
  59. /package/{components → dist/components}/styled.d.ts +0 -0
  60. /package/{context.d.ts → dist/context.d.ts} +0 -0
  61. /package/{index.d.ts → dist/index.d.ts} +0 -0
  62. /package/{layouts → dist/layouts}/BaseLayout.d.ts +0 -0
  63. /package/{layouts → dist/layouts}/CenteredLayout.d.ts +0 -0
  64. /package/{layouts → dist/layouts}/Default3Layout.d.ts +0 -0
  65. /package/{layouts → dist/layouts}/MainSectionLayout.d.ts +0 -0
  66. /package/{layouts → dist/layouts}/QuoteLayout.d.ts +0 -0
  67. /package/{layouts → dist/layouts}/SectionLayout.d.ts +0 -0
  68. /package/{layouts → dist/layouts}/SideCodeLayout.d.ts +0 -0
  69. /package/{layouts → dist/layouts}/SideImageLayout.d.ts +0 -0
  70. /package/{layouts → dist/layouts}/SideLayout.d.ts +0 -0
  71. /package/{layouts → dist/layouts}/columns.d.ts +0 -0
  72. /package/{layouts → dist/layouts}/index.d.ts +0 -0
  73. /package/{layouts → dist/layouts}/styled.d.ts +0 -0
  74. /package/{layouts → dist/layouts}/utils.d.ts +0 -0
  75. /package/{template.d.ts → dist/template.d.ts} +0 -0
  76. /package/{theme.d.ts → dist/theme.d.ts} +0 -0
@@ -0,0 +1,129 @@
1
+ /**
2
+ * The Code Stepper component is a component that allows you to step through
3
+ * the code using familiar directives.
4
+ *
5
+ * @example "@step showLines(1-3)" will show lines 1-3
6
+ * @example "@step highlight(1-3)" will highlight lines 1-3
7
+ *
8
+ */
9
+
10
+ function range(start: number, end: number) {
11
+ return Array.from({ length: end - start + 1 }, (_, i) => i + start);
12
+ }
13
+
14
+ /**
15
+ * Function parse ranges list
16
+ */
17
+ function parseRangeList(str: string): number[] {
18
+ return str.split(',').reduce((acc, line) => {
19
+ if (!line.includes('-')) return [...acc, parseInt(line, 10)];
20
+
21
+ const [start, end] = line.split('-').map(Number);
22
+ return [...acc, ...range(start, end)];
23
+ }, [] as number[]);
24
+ }
25
+
26
+ /**
27
+ * Parse showLines fn
28
+ *
29
+ * "showLines(1-3)" => [1, 2, 3]
30
+ * "showLines(1,3)" => [1,3]
31
+ * "showLines(1-2,4-5)" => [1,2,4,5]
32
+ */
33
+ function parseShowLines(directive: string): { showLines: number[] } | null {
34
+ const match = directive.match(/showLines\((.*)\)/);
35
+ if (!match) return null;
36
+
37
+ const lines = parseRangeList(match[1]);
38
+
39
+ return { showLines: lines };
40
+ }
41
+
42
+ /**
43
+ * Parse highlight fn
44
+ *
45
+ * "highlight(1-3)" => [1,2,3]
46
+ * etc.
47
+ */
48
+ function parseHighlight(directive: string): { highlight: number[] } | null {
49
+ const match = directive.match(/highlight\((.*)\)/);
50
+ if (!match) return null;
51
+
52
+ const lines = parseRangeList(match[1]);
53
+
54
+ return { highlight: lines };
55
+ }
56
+
57
+ type StepDirective = {
58
+ showLines?: number[];
59
+ highlight?: number[];
60
+ name?: string;
61
+ };
62
+
63
+ /**
64
+ * Parse name fn
65
+ *
66
+ * "name("my name")" => "my name"
67
+ */
68
+ function parseName(directive: string): { name: string } | null {
69
+ const match = directive.match(/name\("(.*)"\)/);
70
+ if (!match) return null;
71
+
72
+ return { name: match[1] };
73
+ }
74
+
75
+ /**
76
+ * Parse step directive
77
+ *
78
+ * @example "@step showLines(1-3) highlight(1-3)"
79
+ * @example "@step showLines(1-3)"
80
+ * @example "@step highlight(1-3)"
81
+ */
82
+ function parseStepDirective(directive: string): StepDirective {
83
+ // Should match a showLines(1-3) or highlight(1-3) directive
84
+ // Should match name("(string)")
85
+ const regex = /showLines\([^)]+\)|highlight\([^)]+\)|name\("(.*)"\)/g;
86
+
87
+ const directives = directive.match(regex) || [];
88
+
89
+ const name = directives.map(parseName).find(Boolean);
90
+ const showLines = directives.map(parseShowLines).find(Boolean);
91
+ const highlight = directives.map(parseHighlight).find(Boolean);
92
+
93
+ return { ...showLines, ...highlight, ...name };
94
+ }
95
+
96
+ export type Step = {
97
+ hiddenLines: number[];
98
+ highlight: number[];
99
+ name?: string;
100
+ };
101
+
102
+ /**
103
+ * Reduce steps directives
104
+ */
105
+ export function combineStepDirectives(directives: StepDirective[]): Step[] {
106
+ let hiddenLines = directives.reduce((acc, { showLines }) => {
107
+ if (!showLines) return acc;
108
+
109
+ return [...acc, ...showLines];
110
+ }, [] as number[]);
111
+
112
+ return directives.map(({ highlight, showLines, name }) => {
113
+ hiddenLines = hiddenLines.filter((line) => !showLines?.includes(line));
114
+ return {
115
+ highlight: highlight || [],
116
+ hiddenLines,
117
+ name,
118
+ };
119
+ });
120
+ }
121
+
122
+ /**
123
+ * Parse step directives
124
+ */
125
+ export function parseStepDirectives(directives: string[]): Step[] {
126
+ const parsedDirectives = directives.map(parseStepDirective);
127
+
128
+ return combineStepDirectives(parsedDirectives);
129
+ }
@@ -0,0 +1,85 @@
1
+ import React from "react";
2
+
3
+ import styled from "styled-components";
4
+
5
+ const DocWrapper = styled.div`
6
+ position: absolute;
7
+ bottom: 0;
8
+ right: 0;
9
+ z-index: 10000;
10
+
11
+ .docContent {
12
+ display: none;
13
+ }
14
+
15
+ &:hover .docContent {
16
+ display: flex;
17
+ }
18
+ `;
19
+
20
+ const DocContainer = styled.div`
21
+ margin: 2rem 1rem;
22
+ background-color: #333;
23
+ border: 1px solid #333;
24
+ padding: 0.5rem 1rem;
25
+ border-radius: 1.5rem;
26
+ `;
27
+
28
+ const DocLink = styled.a`
29
+ text-decoration: none;
30
+ font-weight: normal;
31
+ font-family: var(--font-family);
32
+ color: var(--color-secondary);
33
+ `;
34
+
35
+ const DocLinkItem = styled(DocLink)`
36
+ width: fit-content;
37
+ display: inline-block;
38
+ background-color: #333;
39
+ border: 1px solid #333;
40
+ padding: 0.5rem 1rem;
41
+ border-radius: 1.5rem;
42
+ margin: 0.25rem 0;
43
+ `;
44
+
45
+ const DocContent = styled.div`
46
+ display: flex;
47
+ flex-flow: column-reverse nowrap;
48
+ position: absolute;
49
+ right: 1rem;
50
+ bottom: 4.5rem;
51
+ text-align: right;
52
+ border-radius: 0.5rem;
53
+ align-items: flex-end;
54
+ `;
55
+
56
+ export function Doc({
57
+ label,
58
+ link,
59
+ children,
60
+ }: {
61
+ label: string;
62
+ link: string;
63
+ children: React.ReactNode;
64
+ }) {
65
+ return (
66
+ <DocWrapper>
67
+ <DocContainer>
68
+ {children && <DocContent>{children}</DocContent>}
69
+ <div>
70
+ <DocLink target="_blank" rel="noopener noreferrer" href={link}>
71
+ {label}
72
+ </DocLink>
73
+ </div>
74
+ </DocContainer>
75
+ </DocWrapper>
76
+ );
77
+ }
78
+
79
+ export function DocItem({ label, link }: { label: string; link: string }) {
80
+ return (
81
+ <DocLinkItem target="_blank" rel="noopener noreferrer" href={link}>
82
+ {label}
83
+ </DocLinkItem>
84
+ );
85
+ }
@@ -0,0 +1,18 @@
1
+ import React from "react";
2
+
3
+ export default function FilePane({
4
+ name,
5
+ children,
6
+ priority,
7
+ ...divProps
8
+ }: React.ComponentProps<"div"> & { name: string; priority?: number }) {
9
+ return React.isValidElement(children)
10
+ ? React.cloneElement(children, {
11
+ // @ts-expect-error cloning
12
+ priority,
13
+ name,
14
+ })
15
+ : children;
16
+ }
17
+
18
+ FilePane.mdxType = "FilePane";
@@ -0,0 +1,141 @@
1
+ import { usePestacle } from "context";
2
+ import React from "react";
3
+ import { animated, useSpring } from "react-spring";
4
+ import { Stepper } from "spectacle";
5
+ import styled from "styled-components";
6
+
7
+ const Container = styled.div`
8
+ display: grid;
9
+ grid-gap: 2rem;
10
+ `;
11
+
12
+ export default function HorizontalList({
13
+ children,
14
+ columns = 3,
15
+ }: {
16
+ columns?: number;
17
+ children: React.ReactNode;
18
+ }) {
19
+ const items = React.Children.toArray(children);
20
+ return (
21
+ <Stepper values={items}>
22
+ {(_, step) => (
23
+ <Container
24
+ style={{
25
+ gridTemplateColumns: `repeat(${columns}, 1fr)`,
26
+ }}
27
+ >
28
+ {items.map((item, k) => {
29
+ if (!React.isValidElement(item)) {
30
+ return item;
31
+ }
32
+ return React.cloneElement(item, {
33
+ // @ts-expect-error cloning
34
+ position: k + 1,
35
+ isVisible: k <= step,
36
+ isLast: k === step,
37
+ });
38
+ })}
39
+ </Container>
40
+ )}
41
+ </Stepper>
42
+ );
43
+ }
44
+
45
+ function Pill({ position }: { position: number }) {
46
+ return (
47
+ <div
48
+ style={{ width: 48, transform: "translate(-25%, -25%)", opacity: 0.9 }}
49
+ >
50
+ <svg
51
+ width="48"
52
+ height="48"
53
+ viewBox="0 0 18 20"
54
+ fill="none"
55
+ xmlns="http://www.w3.org/2000/svg"
56
+ >
57
+ <path
58
+ d="M8.64717 20L0 15.0094V5.00134L8.64717 0L17.289 5.00134V15.0094L8.64717 20ZM1.48222 14.141L8.64717 18.2846L15.8068 14.141V5.85902L8.64717 1.71536L1.48222 5.85902V14.141Z"
59
+ fill="#ffffff"
60
+ ></path>
61
+ <text
62
+ x="9"
63
+ y="11"
64
+ text-anchor="middle"
65
+ dominant-baseline="middle"
66
+ fill="#f49676"
67
+ style={{ fontSize: "50%" }}
68
+ >
69
+ {position}
70
+ </text>
71
+ <path
72
+ d="M 8.758 16.01 L 3.549 13.004 L 3.549 6.975 L 8.758 3.963 L 13.964 6.975 L 13.964 13.004 L 8.758 16.01 Z"
73
+ fill="transparent"
74
+ ></path>
75
+ </svg>
76
+ </div>
77
+ );
78
+ }
79
+
80
+ const Item = styled(animated.div)`
81
+ display: flex;
82
+ flex-direction: column;
83
+ font-family: Bitter, "Helvetica Neue", Helvetica, Arial, sans-serif;
84
+ `;
85
+ const ItemHead = styled.div`
86
+ display: flex;
87
+ flex-direction: row;
88
+ font-size: 1.3rem;
89
+ margin-bottom: 0.4rem;
90
+
91
+ p {
92
+ margin: 0;
93
+ }
94
+ `;
95
+ const ItemContent = styled.div`
96
+ > * {
97
+ font-size: 1rem;
98
+ padding: 4px !important;
99
+ line-height: 1.5rem !important;
100
+ margin-top: 0;
101
+ }
102
+ `;
103
+
104
+ function getItemOpacity({
105
+ isLast,
106
+ isVisible,
107
+ }: {
108
+ isLast?: boolean;
109
+ isVisible?: boolean;
110
+ }) {
111
+ if (isLast) return 1;
112
+ if (isVisible) return 0.7;
113
+ return 0;
114
+ }
115
+ export function HorizontalListItem({
116
+ title,
117
+ children,
118
+ position,
119
+ isVisible,
120
+ isLast,
121
+ }: {
122
+ title: string;
123
+ position: number;
124
+ isVisible?: boolean;
125
+ isLast?: boolean;
126
+ children: React.ReactNode;
127
+ }) {
128
+ const opacityStyles = useSpring({
129
+ opacity: getItemOpacity({ isVisible, isLast }),
130
+ });
131
+ return (
132
+ <Item style={opacityStyles}>
133
+ <ItemHead>
134
+ <Pill position={position} />
135
+ <p>{title}</p>
136
+ </ItemHead>
137
+
138
+ <ItemContent>{children}</ItemContent>
139
+ </Item>
140
+ );
141
+ }
@@ -0,0 +1,31 @@
1
+ import React from "react";
2
+ import styled from "styled-components";
3
+
4
+ const IconBoxContent = styled.div`
5
+ * {
6
+ margin: 0.2rem !important;
7
+ padding: 0 !important;
8
+ }
9
+ `;
10
+
11
+ export function IconBox({
12
+ children,
13
+ icon,
14
+ }: {
15
+ children: React.ReactNode;
16
+ icon: React.ReactNode;
17
+ }) {
18
+ return (
19
+ <div
20
+ style={{
21
+ display: "flex",
22
+ flexDirection: "column",
23
+ alignItems: "center",
24
+ padding: "1rem 0",
25
+ }}
26
+ >
27
+ <div style={{ fontSize: 60 }}>{icon}</div>
28
+ <IconBoxContent>{children}</IconBoxContent>
29
+ </div>
30
+ );
31
+ }
@@ -0,0 +1,39 @@
1
+ import React from "react";
2
+ import { SVGObject } from "../layouts/styled";
3
+
4
+ export interface ImageProps extends React.ComponentProps<"img"> { }
5
+
6
+ export function Image(props: ImageProps) {
7
+ const { src, height, width,
8
+ style, ...otherProps
9
+ } = props;
10
+ if (!src?.endsWith(".svg")) {
11
+ return (
12
+ <img
13
+ src={src}
14
+ {...otherProps}
15
+ style={{
16
+ width,
17
+ height: height || "100%",
18
+ objectFit: "cover",
19
+ objectPosition: "center",
20
+ ...style
21
+ }}
22
+ />
23
+ );
24
+ }
25
+ return (
26
+ <SVGObject
27
+ type="image/svg+xml"
28
+ data={src}
29
+ style={{
30
+ height: height || "100%",
31
+ minWidth: "30vw",
32
+ width: width || "100%",
33
+ ...style
34
+ }}
35
+ />
36
+ );
37
+ }
38
+
39
+ Image.mdxType = "Image";
@@ -0,0 +1,60 @@
1
+ import React from "react";
2
+ import { Stepper } from "spectacle";
3
+ import styled from "styled-components";
4
+ import { useSpring, animated } from "react-spring";
5
+
6
+ export function ItemsColumn(divProps: React.ComponentProps<"div">) {
7
+ const { style, children, ...props } = divProps;
8
+ const childrenArray = React.Children.toArray(children);
9
+ return (
10
+ <Stepper values={childrenArray}>
11
+ {(value, step) => (
12
+ <div
13
+ style={{
14
+ display: "flex",
15
+ flexDirection: "column",
16
+ justifyItems: 'center',
17
+ alignItems: "stretch",
18
+ height: "100%",
19
+ rowGap: '2rem',
20
+ ...style,
21
+ }}
22
+ {...props}
23
+ >
24
+ {childrenArray.map((child, index) => {
25
+ const isVisible = index <= step;
26
+ if (!React.isValidElement(child)) {
27
+ return child;
28
+ }
29
+ return (
30
+ <ItemColumnWrapper key={index} isVisible={isVisible}>
31
+ {child}
32
+ </ItemColumnWrapper>
33
+ );
34
+ })}
35
+ </div>
36
+ )}
37
+ </Stepper>
38
+ );
39
+ }
40
+
41
+ const ItemColumnWrapperStyled = styled(animated.div)`
42
+ display: flex;
43
+ justify-content: center;
44
+ * {
45
+ text-align: center !important;
46
+ }
47
+ `;
48
+
49
+ function ItemColumnWrapper({
50
+ children,
51
+ isVisible,
52
+ ...props
53
+ }: React.ComponentPropsWithRef<"div"> & { isVisible: boolean }) {
54
+ const styles = useSpring({ opacity: isVisible ? 1 : 0 });
55
+ return (
56
+ <ItemColumnWrapperStyled style={styles} {...props}>
57
+ {children}
58
+ </ItemColumnWrapperStyled>
59
+ );
60
+ }
@@ -0,0 +1,55 @@
1
+ import QrCreator from "qr-creator";
2
+ import React, { useContext } from "react";
3
+ import { DeckContext } from "spectacle";
4
+
5
+ export interface QRCodeProps {
6
+ url: string;
7
+ size?: "xs" | "sm" | "md" | "lg";
8
+ }
9
+
10
+ const MapSize = {
11
+ xs: 64,
12
+ sm: 128,
13
+ md: 256,
14
+ lg: 512,
15
+ };
16
+
17
+ export function QRCode({ url, size = "md" }: QRCodeProps) {
18
+ const id = React.useId().replace(/:/g, "___");
19
+ const deck = useContext(DeckContext);
20
+ const width = MapSize[size];
21
+ const backgroundColor = deck.theme?.colors?.primary || "#ffffff";
22
+
23
+ React.useEffect(() => {
24
+ const element = document.querySelector(`#${id}`);
25
+
26
+ if (!element) return console.error("QRCode element not mounted");
27
+
28
+ QrCreator.render(
29
+ {
30
+ text: url,
31
+ radius: 0.5,
32
+ ecLevel: "H", // L, M, Q, H
33
+ fill: deck.theme?.colors?.secondary || "#000000",
34
+ background: backgroundColor,
35
+ size: width,
36
+ },
37
+ element as HTMLElement,
38
+ );
39
+
40
+ return () => {
41
+ element.replaceChildren();
42
+ };
43
+ }, [url]);
44
+
45
+ return (
46
+ <div
47
+ id={id}
48
+ style={{
49
+ padding: "1rem 1rem 0.6rem 1rem",
50
+ borderRadius: "1rem",
51
+ backgroundColor,
52
+ }}
53
+ />
54
+ );
55
+ }
@@ -0,0 +1,24 @@
1
+ import styled from "styled-components";
2
+
3
+ export const TimelineItemContent = styled.div`
4
+ display: flex;
5
+ padding: 0.7rem 0 1rem 12px;
6
+ `;
7
+ export const TimelineItemContentPhantom = styled(TimelineItemContent)`
8
+ opacity: 0;
9
+ `;
10
+
11
+ export const TimelineItemBody = styled.div`
12
+ &,
13
+ & > * {
14
+ font-size: 1.3rem !important;
15
+ color: #ffffff !important;
16
+ }
17
+ `;
18
+
19
+ export const TimelineItemTitle = styled.div`
20
+ font-family: Bitter, "Helvetica Neue", Helvetica, Arial, sans-serif;
21
+ font-size: 1rem;
22
+ font-weight: bold;
23
+ color: #ffffffbb;
24
+ `;