mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
highlight io shapes in answer side (#3098)
This commit is contained in:
parent
31e2dc1409
commit
038a0189d0
3 changed files with 49 additions and 2 deletions
|
@ -313,6 +313,12 @@ fn render_image_occlusion(text: &str, question_side: bool, active: bool, ordinal
|
||||||
ordinal,
|
ordinal,
|
||||||
&get_image_cloze_data(text)
|
&get_image_cloze_data(text)
|
||||||
)
|
)
|
||||||
|
} else if !question_side && active {
|
||||||
|
format!(
|
||||||
|
r#"<div class="cloze-highlight" data-ordinal="{}" {}></div>"#,
|
||||||
|
ordinal,
|
||||||
|
&get_image_cloze_data(text)
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
"".into()
|
"".into()
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
--active-shape-color: #ff8e8e;
|
--active-shape-color: #ff8e8e;
|
||||||
--inactive-shape-border: 1px #212121;
|
--inactive-shape-border: 1px #212121;
|
||||||
--active-shape-border: 1px #212121;
|
--active-shape-border: 1px #212121;
|
||||||
|
--highlight-shape-color: #ff8e8e00;
|
||||||
|
--highlight-shape-border: 1px #ff8e8e;
|
||||||
}
|
}
|
||||||
|
|
||||||
.card {
|
.card {
|
||||||
|
|
|
@ -12,6 +12,7 @@ import type { Size } from "./types";
|
||||||
export type DrawShapesData = {
|
export type DrawShapesData = {
|
||||||
activeShapes: Shape[];
|
activeShapes: Shape[];
|
||||||
inactiveShapes: Shape[];
|
inactiveShapes: Shape[];
|
||||||
|
highlightShapes: Shape[];
|
||||||
properties: ShapeProperties;
|
properties: ShapeProperties;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -181,12 +182,14 @@ function drawShapes(
|
||||||
|
|
||||||
let activeShapes = extractShapesFromRenderedClozes(".cloze");
|
let activeShapes = extractShapesFromRenderedClozes(".cloze");
|
||||||
let inactiveShapes = extractShapesFromRenderedClozes(".cloze-inactive");
|
let inactiveShapes = extractShapesFromRenderedClozes(".cloze-inactive");
|
||||||
|
let highlightShapes = extractShapesFromRenderedClozes(".cloze-highlight");
|
||||||
let properties = getShapeProperties();
|
let properties = getShapeProperties();
|
||||||
|
|
||||||
const processed = onWillDrawShapes?.({ activeShapes, inactiveShapes, properties }, context);
|
const processed = onWillDrawShapes?.({ activeShapes, inactiveShapes, highlightShapes, properties }, context);
|
||||||
if (processed) {
|
if (processed) {
|
||||||
activeShapes = processed.activeShapes;
|
activeShapes = processed.activeShapes;
|
||||||
inactiveShapes = processed.inactiveShapes;
|
inactiveShapes = processed.inactiveShapes;
|
||||||
|
highlightShapes = processed.highlightShapes;
|
||||||
properties = processed.properties;
|
properties = processed.properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,8 +213,18 @@ function drawShapes(
|
||||||
strokeWidth: properties.inActiveBorder.width,
|
strokeWidth: properties.inActiveBorder.width,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
for (const shape of highlightShapes) {
|
||||||
|
drawShape({
|
||||||
|
context,
|
||||||
|
size,
|
||||||
|
shape,
|
||||||
|
fill: properties.highlightShapeColor,
|
||||||
|
stroke: properties.highlightShapeBorder.color,
|
||||||
|
strokeWidth: properties.highlightShapeBorder.width,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
onDidDrawShapes?.({ activeShapes, inactiveShapes, properties }, context);
|
onDidDrawShapes?.({ activeShapes, inactiveShapes, highlightShapes, properties }, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface DrawShapeParameters {
|
interface DrawShapeParameters {
|
||||||
|
@ -324,8 +337,10 @@ function topLeftOfPoints(points: { x: number; y: number }[]): {
|
||||||
export type ShapeProperties = {
|
export type ShapeProperties = {
|
||||||
activeShapeColor: string;
|
activeShapeColor: string;
|
||||||
inActiveShapeColor: string;
|
inActiveShapeColor: string;
|
||||||
|
highlightShapeColor: string;
|
||||||
activeBorder: { width: number; color: string };
|
activeBorder: { width: number; color: string };
|
||||||
inActiveBorder: { width: number; color: string };
|
inActiveBorder: { width: number; color: string };
|
||||||
|
highlightShapeBorder: { width: number; color: string };
|
||||||
};
|
};
|
||||||
function getShapeProperties(): ShapeProperties {
|
function getShapeProperties(): ShapeProperties {
|
||||||
const canvas = document.getElementById("image-occlusion-canvas");
|
const canvas = document.getElementById("image-occlusion-canvas");
|
||||||
|
@ -339,6 +354,9 @@ function getShapeProperties(): ShapeProperties {
|
||||||
const inActiveShapeColor = computedStyle.getPropertyValue(
|
const inActiveShapeColor = computedStyle.getPropertyValue(
|
||||||
"--inactive-shape-color",
|
"--inactive-shape-color",
|
||||||
);
|
);
|
||||||
|
const highlightShapeColor = computedStyle.getPropertyValue(
|
||||||
|
"--highlight-shape-color",
|
||||||
|
);
|
||||||
// inactive shape border
|
// inactive shape border
|
||||||
const inActiveShapeBorder = computedStyle.getPropertyValue(
|
const inActiveShapeBorder = computedStyle.getPropertyValue(
|
||||||
"--inactive-shape-border",
|
"--inactive-shape-border",
|
||||||
|
@ -353,12 +371,22 @@ function getShapeProperties(): ShapeProperties {
|
||||||
const activeBorder = activeShapeBorder.split(" ").filter((x) => x);
|
const activeBorder = activeShapeBorder.split(" ").filter((x) => x);
|
||||||
const activeShapeBorderWidth = parseFloat(activeBorder[0]);
|
const activeShapeBorderWidth = parseFloat(activeBorder[0]);
|
||||||
const activeShapeBorderColor = activeBorder[1];
|
const activeShapeBorderColor = activeBorder[1];
|
||||||
|
// highlight shape border
|
||||||
|
const highlightShapeBorder = computedStyle.getPropertyValue(
|
||||||
|
"--highlight-shape-border",
|
||||||
|
);
|
||||||
|
const highlightBorder = highlightShapeBorder.split(" ").filter((x) => x);
|
||||||
|
const highlightShapeBorderWidth = parseFloat(highlightBorder[0]);
|
||||||
|
const highlightShapeBorderColor = highlightBorder[1];
|
||||||
|
|
||||||
return {
|
return {
|
||||||
activeShapeColor: activeShapeColor ? activeShapeColor : "#ff8e8e",
|
activeShapeColor: activeShapeColor ? activeShapeColor : "#ff8e8e",
|
||||||
inActiveShapeColor: inActiveShapeColor
|
inActiveShapeColor: inActiveShapeColor
|
||||||
? inActiveShapeColor
|
? inActiveShapeColor
|
||||||
: "#ffeba2",
|
: "#ffeba2",
|
||||||
|
highlightShapeColor: highlightShapeColor
|
||||||
|
? highlightShapeColor
|
||||||
|
: "#ff8e8e00",
|
||||||
activeBorder: {
|
activeBorder: {
|
||||||
width: !isNaN(activeShapeBorderWidth) ? activeShapeBorderWidth : 1,
|
width: !isNaN(activeShapeBorderWidth) ? activeShapeBorderWidth : 1,
|
||||||
color: activeShapeBorderColor
|
color: activeShapeBorderColor
|
||||||
|
@ -371,12 +399,19 @@ function getShapeProperties(): ShapeProperties {
|
||||||
? inActiveShapeBorderColor
|
? inActiveShapeBorderColor
|
||||||
: "#212121",
|
: "#212121",
|
||||||
},
|
},
|
||||||
|
highlightShapeBorder: {
|
||||||
|
width: !isNaN(highlightShapeBorderWidth) ? highlightShapeBorderWidth : 1,
|
||||||
|
color: highlightShapeBorderColor
|
||||||
|
? highlightShapeBorderColor
|
||||||
|
: "#ff8e8e",
|
||||||
|
},
|
||||||
};
|
};
|
||||||
} catch {
|
} catch {
|
||||||
// return default values
|
// return default values
|
||||||
return {
|
return {
|
||||||
activeShapeColor: "#ff8e8e",
|
activeShapeColor: "#ff8e8e",
|
||||||
inActiveShapeColor: "#ffeba2",
|
inActiveShapeColor: "#ffeba2",
|
||||||
|
highlightShapeColor: "#ff8e8e00",
|
||||||
activeBorder: {
|
activeBorder: {
|
||||||
width: 1,
|
width: 1,
|
||||||
color: "#212121",
|
color: "#212121",
|
||||||
|
@ -385,6 +420,10 @@ function getShapeProperties(): ShapeProperties {
|
||||||
width: 1,
|
width: 1,
|
||||||
color: "#212121",
|
color: "#212121",
|
||||||
},
|
},
|
||||||
|
highlightShapeBorder: {
|
||||||
|
width: 1,
|
||||||
|
color: "#ff8e8e",
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue