@altpsyche/maths 0.2.0 → 0.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.
@@ -37,21 +37,26 @@ export declare function svgElements(marks: readonly Mark[], view: Mat3): SvgElem
37
37
  export declare function svgMarkup(marks: readonly Mark[], view: Mat3, width: number, height: number): string;
38
38
  /**
39
39
  * Only what a painter needs from a document, named here rather than taken from
40
- * the DOM types.
40
+ * the DOM types, so this package declares no browser library at all: it can be
41
+ * checked and tested without one, and a caller can hand in a stand-in.
41
42
  *
42
- * A real `SVGElement` and a real `Document` both satisfy these already, and
43
- * writing them out means this package declares no browser library at all: it can
44
- * be checked and tested without one, and a caller can hand in a stand-in.
43
+ * The element a maker makes is the element the target is handed, and that type
44
+ * travels through rather than being flattened to the two members named below. An
45
+ * element in a real document takes whole nodes and text where the painter's own
46
+ * type takes neither, so a target written in terms of the painter's type is a
47
+ * target no real element can be: what a document offers and what the painter
48
+ * would ask for are each missing something the other has, and neither signature
49
+ * is assignable to the other in either direction.
45
50
  */
46
51
  export interface PaintNode {
47
52
  setAttribute(name: string, value: string): void;
48
53
  textContent: string | null;
49
54
  }
50
- export interface PaintTarget {
51
- replaceChildren(...nodes: PaintNode[]): void;
55
+ export interface PaintTarget<Made extends PaintNode = PaintNode> {
56
+ replaceChildren(...nodes: Made[]): void;
52
57
  }
53
- export interface ElementMaker {
54
- createElementNS(namespace: string, tag: string): PaintNode;
58
+ export interface ElementMaker<Made extends PaintNode = PaintNode> {
59
+ createElementNS(namespace: string, tag: string): Made;
55
60
  }
56
61
  /**
57
62
  * The marks put into an element that is already on the page.
@@ -61,4 +66,4 @@ export interface ElementMaker {
61
66
  * and matching them up first would cost more than it saved while adding a way for
62
67
  * two frames to disagree.
63
68
  */
64
- export declare function paintSvg(into: PaintTarget, marks: readonly Mark[], view: Mat3, maker: ElementMaker): void;
69
+ export declare function paintSvg<Made extends PaintNode>(into: PaintTarget<NoInfer<Made>>, marks: readonly Mark[], view: Mat3, maker: ElementMaker<Made>): void;
package/dist/paint/svg.js CHANGED
@@ -114,7 +114,11 @@ const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
114
114
  * and matching them up first would cost more than it saved while adding a way for
115
115
  * two frames to disagree.
116
116
  */
117
- export function paintSvg(into, marks, view, maker) {
117
+ export function paintSvg(
118
+ // The maker alone says what kind of element this is. Read from the target as
119
+ // well, a real element would offer the whole union its own call accepts, text
120
+ // included, and that union is not a thing this painter can set an attribute on.
121
+ into, marks, view, maker) {
118
122
  const elements = svgElements(marks, view);
119
123
  into.replaceChildren(...elements.map((element) => {
120
124
  const node = maker.createElementNS(SVG_NAMESPACE, element.tag);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@altpsyche/maths",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
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",