@altpsyche/maths 0.13.0 → 1.0.0

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.
package/dist/index.d.ts CHANGED
@@ -80,7 +80,7 @@ export { frameTimesOf, framesOf } from './figure/frames.js';
80
80
  export type { Frame, FrameStep, FramesOptions } from './figure/frames.js';
81
81
  export type { Figure, TrackValues } from './figure/figure.js';
82
82
  export { paintSvg, pathToData, svgElements, svgMarkup } from './paint/svg.js';
83
- export type { ElementMaker, PaintNode, PaintTarget, SvgElement, SvgMarkupOptions, SvgTheme } from './paint/svg.js';
83
+ export type { ElementMaker, PaintNode, PaintTarget, SvgColour, SvgElement, SvgMarkupOptions, SvgTheme } from './paint/svg.js';
84
84
  export { paintCanvas } from './paint/canvas.js';
85
85
  export type { CanvasLike } from './paint/canvas.js';
86
86
  export { arrow, brace, bracePath, callout, dot } from './figure/annotate.js';
@@ -23,19 +23,30 @@ export interface SvgElement {
23
23
  attributes: Record<string, string>;
24
24
  text?: string;
25
25
  }
26
+ /** One colour for each of the two grounds a sheet is read on. */
27
+ export interface SvgColour {
28
+ light: string;
29
+ dark: string;
30
+ }
26
31
  /** A colour per ground for one CSS custom property. A mark painted with
27
32
  * `var(--name, colour)` takes the value of the ground it is read on, and the
28
33
  * colour written inside the `var()` is what it falls back to. */
29
34
  export interface SvgTheme {
30
- [property: string]: {
31
- light: string;
32
- dark: string;
33
- };
35
+ [property: string]: SvgColour;
34
36
  }
35
37
  export interface SvgMarkupOptions {
36
38
  /** Written into the markup as a `<style>` element, so one file is read on a
37
39
  * light page and a dark one with no script and no page CSS. */
38
40
  theme?: SvgTheme;
41
+ /**
42
+ * What the sheet paints behind its own marks, one colour per ground.
43
+ *
44
+ * Inside an `<img>` the colour scheme query answers for the browser and not
45
+ * for the page around it, so a dark half chosen on a light page lands on a
46
+ * ground it was never measured against. A sheet that paints the ground it was
47
+ * measured on holds its readings wherever it is shown.
48
+ */
49
+ ground?: SvgColour;
39
50
  /**
40
51
  * The smallest font size written, in the units painted into rather than in
41
52
  * figure units. A view that fits a wide extent scales every figure unit down,
package/dist/paint/svg.js CHANGED
@@ -107,18 +107,26 @@ function plainValue(value) {
107
107
  return !/[<>&{};"]/.test(value);
108
108
  }
109
109
  /**
110
- * The theme as a `<style>` element, the light ground on `:root` and the dark one
111
- * behind `prefers-color-scheme`.
110
+ * The theme and the ground as a `<style>` element, the light half on `:root` and
111
+ * the dark one behind `prefers-color-scheme`.
112
112
  *
113
113
  * An entry whose name or either colour would need escaping is left out, which
114
114
  * leaves the mark on the colour written inside its own `var()` rather than on a
115
- * value that could close the element.
115
+ * value that could close the element. A ground either colour of which would need
116
+ * escaping is dropped whole, since half a ground is a sheet painted on white by
117
+ * accident.
116
118
  */
117
- function themeStyle(theme) {
118
- const names = Object.keys(theme).filter((name) => PROPERTY.test(name) && plainValue(theme[name].light) && plainValue(theme[name].dark));
119
- if (names.length === 0)
119
+ function themeStyle(theme, ground) {
120
+ const names = theme
121
+ ? Object.keys(theme).filter((name) => PROPERTY.test(name) && plainValue(theme[name].light) && plainValue(theme[name].dark))
122
+ : [];
123
+ const painted = ground && plainValue(ground.light) && plainValue(ground.dark) ? ground : undefined;
124
+ if (names.length === 0 && painted === undefined)
120
125
  return '';
121
- const block = (ground) => names.map((name) => `--${name}:${theme[name][ground]}`).join(';');
126
+ const block = (side) => {
127
+ const properties = theme ? names.map((name) => `--${name}:${theme[name][side]}`) : [];
128
+ return [...properties, ...(painted ? [`background:${painted[side]}`] : [])].join(';');
129
+ };
122
130
  return `<style>:root{${block('light')}}@media(prefers-color-scheme:dark){:root{${block('dark')}}}</style>`;
123
131
  }
124
132
  /**
@@ -128,7 +136,7 @@ function themeStyle(theme) {
128
136
  * around it decides how big it is and the picture stays where it was put.
129
137
  */
130
138
  export function svgMarkup(marks, view, width, height, options = {}) {
131
- const style = options.theme ? themeStyle(options.theme) : '';
139
+ const style = themeStyle(options.theme, options.ground);
132
140
  const body = svgElements(marks, view, options)
133
141
  .map((element) => {
134
142
  const attributes = Object.entries(element.attributes)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@altpsyche/maths",
3
- "version": "0.13.0",
3
+ "version": "1.0.0",
4
4
  "description": "The mathematics AltPsyche's figures are drawn from: vectors, matrices, curves, and a value walked over time.",
5
5
  "license": "MIT",
6
6
  "author": "Siva",