Skip to content

Commit

Permalink
merging some strange upstream commits
Browse files Browse the repository at this point in the history
  • Loading branch information
monofon committed Nov 5, 2024
2 parents 84a0f3d + 82612bf commit b8e24ef
Show file tree
Hide file tree
Showing 32 changed files with 604 additions and 339 deletions.
33 changes: 17 additions & 16 deletions app/Decker.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,16 @@ import Text.Decker.Internal.Common
import Text.Decker.Internal.External
import Text.Decker.Internal.Helper
import Text.Decker.Internal.Meta
import Text.Decker.Project.ActionContext (Flags (LectureFlag), actionContext, extra)
import Text.Decker.Project.Glob (fastGlobFiles')
import Text.Decker.Project.Project
import Text.Decker.Project.Shake
import Text.Decker.Resource.Resource
import Text.Decker.Server.Video (copyVttForVideos)
import Text.Decker.Writer.Html
import Text.Decker.Writer.Layout
import Text.Decker.Writer.Pdf
import Text.Groom
import Text.Pandoc hiding (lookupMeta)
import Text.Decker.Project.ActionContext (actionContext, extra, Flags (LectureFlag))

main :: IO ()
main = do
Expand Down Expand Up @@ -181,6 +180,8 @@ deckerRules = do
need [src]
meta <- getGlobalMeta
markdownToHtml htmlDeck meta getTemplate src out
needPublicIfExists $ replaceSuffix "-deck.md" "-recording-de.vtt" src
needPublicIfExists $ replaceSuffix "-deck.md" "-recording-en.vtt" src
needPublicIfExists $ replaceSuffix "-deck.md" "-recording.mp4" src
needPublicIfExists $ replaceSuffix "-deck.md" "-annot.json" src
needPublicIfExists $ replaceSuffix "-deck.md" "-manip.json" src
Expand Down Expand Up @@ -321,7 +322,6 @@ deckerRules = do
let src = makeRelative publicDir out
putVerbose $ "# copy (for " <> out <> ")"
copyFile' src out
copyVttForVideos src out
--
withTargetDocs "Copy static file to public dir." $
phony "static-files" $ do
Expand Down Expand Up @@ -358,9 +358,10 @@ deckerRules = do
meta <- getGlobalMeta
context <- actionContext
let flags = context ^. extra
-- TODO handle pages as well
if LectureFlag `elem` flags
then do
case lookupMeta "publish.rsync.destination" meta of
case lookupMeta "publish.rsync.destination" meta of
Just (destination :: String) -> do
-- clean out the public dir
liftIO $ runClean False
Expand All @@ -380,18 +381,18 @@ deckerRules = do
publishWithRsync src destination meta
_ -> putError "publish.rsync.destination not configured"
else do
need ["support"]
getDeps >>= needTargets' [decks, pages]
createPublicManifest
let src = publicDir ++ "/"
case lookupMeta "publish.rsync.destination" meta of
Just destination -> publishWithRsync src destination meta
_ -> do
let host = lookupMetaOrFail "rsync-destination.host" meta
let path = lookupMetaOrFail "rsync-destination.path" meta
let dst = intercalate ":" [host, path]
ssh [host, "mkdir -p", path] Nothing
rsync [src, dst] Nothing
need ["support"]
getDeps >>= needTargets' [decks, pages]
createPublicManifest
let src = publicDir ++ "/"
case lookupMeta "publish.rsync.destination" meta of
Just destination -> publishWithRsync src destination meta
_ -> do
let host = lookupMetaOrFail "rsync-destination.host" meta
let path = lookupMetaOrFail "rsync-destination.path" meta
let dst = intercalate ":" [host, path]
ssh [host, "mkdir -p", path] Nothing
rsync [src, dst] Nothing

createPublicManifest :: Action ()
createPublicManifest = do
Expand Down
14 changes: 14 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

## decker 0.14.0

- Palette for charts can now be defined in YAML in `chart.colors`.
For this to work, disable the color plugin of Chart.js.
``` yaml
chart:
colors:
- #ff0000
- #00ff00
- #00ff00
defaults:
plugins:
colors:
enabled: false
```
- The colorscheme ("light" or "dark") can now be enforced in YAML. Simply add
``` yaml
colorscheme: "light"
Expand Down
9 changes: 9 additions & 0 deletions resource/decker/support/flyingFocus/flying-focus.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ export function showFlyingFocus(event) {
}
target = event.target;

// Navigate to the slide the focus target is located in if not in handout mode
if (!document.documentElement.classList.contains("handout")) {
const section = target.closest("section");
if (section && !section.classList.contains("present")) {
const index = window.Reveal.getIndices(section);
window.Reveal.slide(index.h, index.v);
}
}

// set new position of flying focus
Object.assign(flyingFocus.style, rectOf(target));

Expand Down
31 changes: 24 additions & 7 deletions resource/decker/support/plugins/a11y/a11y.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function addScreenReaderSlideNumbers() {

function addScreenReaderSlideNumber(slide, h, v) {
const header = slide.querySelector("h1");
if (header) {
if (header && header.textContent.trim() !== "") {
const innerHTML = header.innerHTML;
const replacementHTML = `<span class="sr-only">${localization.slide} ${
h + 1
Expand Down Expand Up @@ -95,7 +95,7 @@ function addCustomSpacebarHandler() {
}
}

function toggleA11YMode() {
function toggleAccessibility() {
a11yMode = !a11yMode;

if (a11yMode) {
Expand All @@ -111,6 +111,15 @@ function toggleA11YMode() {
modifyMedia(audio);
}
Decker.flash.message(localization.accessible_colors_on);
if (window.MathJax) {
window.MathJax.startup.document.options.enableMenu = true;
window.MathJax.startup.document.menu.menu
.findID("Accessibility", "Activate")
.variable.setter(true);
window.MathJax.startup.document.menu.loadingPromise.then(() => {
window.MathJax.startup.document.rerender();
});
}
} else {
pluginButton.ariaPressed = false;
pluginButton.setLabel(localization.activate_accessibility);
Expand All @@ -124,6 +133,16 @@ function toggleA11YMode() {
restoreMedia(audio);
}
Decker.flash.message(localization.accessible_colors_off);
if (window.MathJax) {
// Does it make sense to remove this again if once activated?
window.MathJax.startup.document.options.enableMenu = false;
window.MathJax.startup.document.menu.menu
.findID("Accessibility", "Activate")
.variable.setter(false);
window.MathJax.startup.document.menu.loadingPromise.then(() => {
window.MathJax.startup.document.rerender();
});
}
}
}

Expand Down Expand Up @@ -162,9 +181,7 @@ const Plugin = {
description: "Toggle Decker Accessibility Adjustments (Triple Click)",
},

Decker.tripleClick(() => {
toggleA11YMode();
})
Decker.tripleClick(toggleAccessibility)
);
reveal.addEventListener("ready", () => {
const menuPlugin = reveal.getPlugin("decker-menu");
Expand All @@ -173,13 +190,13 @@ const Plugin = {
"decker-menu-a11y-button",
"fa-universal-access",
localization.activate_accessibility,
toggleA11YMode
toggleAccessibility
);
}
});
if (a11y) {
Reveal.addEventListener("ready", () => {
toggleA11YMode();
toggleAccessibility();
});
}
},
Expand Down
74 changes: 59 additions & 15 deletions resource/decker/support/plugins/charts/charts.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ const printMode = /print-pdf/gi.test(window.location.search);
let chartConfig;
let pixelRatio = 1;

// color palette: when not defined in chart config, use deck palette
// NOTE: colors have to be specified in hex form as #RRGGBB
// NOTE: color plugin of Chart.js has to be turned off explicitly for
// this to work: chart.defaults.plugins.colors.enabled=false
const palette = Decker.meta?.chart?.colors;
function getColorRGB(i) {
return palette[i % palette.length];
}
function getColorRGBA(i) {
return palette[i % palette.length] + "99";
}

function parseJSON(str) {
let json;
try {
Expand Down Expand Up @@ -90,8 +102,6 @@ function createChart(canvas, CSV, comments) {
};
}

console.log(chartOptions);

// MARIO: set pixel ratio
chartOptions.devicePixelRatio = pixelRatio;

Expand Down Expand Up @@ -141,6 +151,49 @@ function createChart(canvas, CSV, comments) {
}
}

// MARIO: assign colors (unless they are specified already
// and only if color-plugin of Chart.js is disabled
if (palette) {
const type = canvas.getAttribute("data-chart");
for (let i = 0; i < chartData.datasets.length; i++) {
let dataset = chartData.datasets[i];
if (!dataset.backgroundColor && !dataset.borderColor) {
switch (type) {
// one color per dataset (solid border, solid fill)
case "bar":
case "horizontalBar": {
dataset.borderColor = getColorRGB(i);
dataset.backgroundColor = getColorRGB(i);
break;
}

// one color per dataset (solid border, semi-transparent fill)
case "line":
case "radar": {
dataset.borderColor = getColorRGB(i);
dataset.backgroundColor = getColorRGBA(i);
break;
}

// many colors per dataset (no border, solid fill)
case "doughnut":
case "pie": {
let j = i;
dataset.backgroundColor = dataset.data.map(() => getColorRGB(j++));
break;
}

// many colors per dataset (no border, semi-transparent fill)
case "polarArea": {
let j = i;
dataset.backgroundColor = dataset.data.map(() => getColorRGBA(j++));
break;
}
}
}
}
}

// non-filled chart?
if (canvas.hasAttribute("data-nofill")) {
for (let j = 0; j < chartData.datasets.length; j++) {
Expand All @@ -167,6 +220,10 @@ function createChart(canvas, CSV, comments) {
};
}

// DEBUG: output final data and options
// console.log(chartData);
// console.log(chartOptions);

canvas.chart = new Chart(ctx, {
type: canvas.getAttribute("data-chart"),
data: chartData,
Expand Down Expand Up @@ -304,9 +361,6 @@ function recreateChart(canvas) {
config.options.devicePixelRatio = pixelRatio;

canvas.chart.destroy();
// setTimeout(function () {
// canvas.chart = new Chart(canvas, config);
// }, 500); // wait for slide transition
canvas.chart = new Chart(canvas, config);
}

Expand Down Expand Up @@ -337,16 +391,6 @@ const Plugin = {
mergeRecursive(Chart.defaults, config);
}

// MARIO: disabled this, since it's more robust to
// add a light background to charts in CSS
// const colors =
// window.matchMedia &&
// window.matchMedia("(prefers-color-scheme: dark)").matches
// ? window.Decker.meta.palette.colors.dark
// : window.Decker.meta.palette.colors.light;
// Chart.defaults.color = colors[7];
// Chart.defaults.borderColor = colors[2];

Reveal.addEventListener("ready", function () {
// MARIO: when in print mode, set animation duration to zero
// otherwise we might get half-ready charts in exported PDF
Expand Down
3 changes: 1 addition & 2 deletions resource/decker/support/plugins/feedback/feedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ class Feedback {
}
${
isAdmin
? `<button class="far fa-plus-square feedback-answer-question-button" title="${text.add}" aria-label="${text.add}"></button>`
? `<button class="fa fa-reply feedback-answer-question-button" title="${text.add}" aria-label="${text.add}"></button>`
: ""
}
${
Expand Down Expand Up @@ -572,7 +572,6 @@ class Feedback {
let deleteButton = item.querySelector(".feedback-delete-answer-button");
deleteButton.addEventListener("click", () => this.deleteAnswer(answer));
}
MathJax.typeset([item]);
return item;
}

Expand Down
Loading

0 comments on commit b8e24ef

Please sign in to comment.