Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/src/format/reveal/metadata.ts
6451 views
1
/*
2
* metadata.ts
3
*
4
* Copyright (C) 2022 Posit Software, PBC
5
*/
6
7
import { Metadata } from "../../config/types.ts";
8
import { camelToKebab, kebabToCamel } from "../../core/config.ts";
9
import {
10
kAutoAnimateDuration,
11
kAutoAnimateEasing,
12
kAutoAnimateUnmatched,
13
kJumpToSlide,
14
kPdfMaxPagesPerSlide,
15
kPdfSeparateFragments,
16
kScrollActivationWidth,
17
kScrollLayout,
18
kScrollProgress,
19
kScrollSnap,
20
kView,
21
} from "./constants.ts";
22
23
export function optionsToKebab(options: string[]) {
24
return options.reduce(
25
(options: string[], option: string) => {
26
const kebab = camelToKebab(option);
27
if (kebab !== option) {
28
options.push(kebab);
29
}
30
return options;
31
},
32
[],
33
);
34
}
35
36
export function revealMetadataFilter(
37
metadata: Metadata,
38
kebabOptions = kRevealKebabOptions,
39
) {
40
// this is, more-or-less, an admission of defeat.
41
// By inspection of src/resources/schema/document-reveal-*.yml we can see
42
// that this is the only case where camel case is
43
// used inconsistently by revealJS (we should have fragmentInUrl instead of fragmentInURL).
44
//
45
// https://github.com/quarto-dev/quarto-cli/issues/7358
46
const mappingExceptions: Record<string, string> = {
47
"fragment-in-url": "fragmentInURL",
48
};
49
// convert kebab case to camel case for reveal options
50
const filtered: Metadata = {};
51
Object.keys(metadata).forEach((key) => {
52
const value = metadata[key];
53
if (
54
kebabOptions.includes(key)
55
) {
56
const camel = mappingExceptions[key] || kebabToCamel(key);
57
filtered[camel] = value;
58
} else {
59
filtered[key] = value;
60
}
61
});
62
return filtered;
63
}
64
65
const kRevealOptions = [
66
"controls",
67
"controlsTutorial",
68
"controlsLayout",
69
"controlsBackArrows",
70
"progress",
71
"slideNumber",
72
"showSlideNumber",
73
"hash",
74
"hashOneBasedIndex",
75
"respondToHashChanges",
76
"history",
77
"keyboard",
78
"overview",
79
"disableLayout",
80
"center",
81
"touch",
82
"loop",
83
"rtl",
84
"navigationMode",
85
"shuffle",
86
"fragments",
87
"fragmentInURL",
88
"embedded",
89
"help",
90
"pause",
91
"showNotes",
92
"autoPlayMedia",
93
"preloadIframes",
94
"autoAnimate",
95
"autoAnimateMatcher",
96
kAutoAnimateEasing,
97
kAutoAnimateDuration,
98
kAutoAnimateUnmatched,
99
"autoAnimateStyles",
100
"autoSlide",
101
"autoSlideStoppable",
102
"autoSlideMethod",
103
"defaultTiming",
104
"mouseWheel",
105
"display",
106
"hideInactiveCursor",
107
"hideCursorTime",
108
"previewLinks",
109
"transition",
110
"transitionSpeed",
111
"backgroundTransition",
112
"viewDistance",
113
"mobileViewDistance",
114
"parallaxBackgroundImage",
115
"parallaxBackgroundSize",
116
"parallaxBackgroundHorizontal",
117
"parallaxBackgroundVertical",
118
"width",
119
"height",
120
"margin",
121
"minScale",
122
"maxScale",
123
"mathjax",
124
kPdfMaxPagesPerSlide,
125
kPdfSeparateFragments,
126
"pdfPageHeightOffset",
127
kJumpToSlide,
128
kView,
129
kScrollProgress,
130
kScrollSnap,
131
kScrollLayout,
132
kScrollActivationWidth,
133
];
134
135
const kRevealKebabOptions = optionsToKebab(kRevealOptions);
136
137