figureone 1.4.1 → 1.7.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "figureone",
3
- "version": "1.4.1",
3
+ "version": "1.7.0",
4
4
  "description": "Draw, animate and interact with shapes, text, plots and equations in Javascript. Create interactive slide shows, and interactive videos.",
5
5
  "main": "index.js",
6
6
  "types": "types/index.d.ts",
@@ -503,6 +503,7 @@ declare class FigureElement {
503
503
  drawNumber: number;
504
504
  moveSetTransform: boolean;
505
505
  allowSetColor: string;
506
+ ignoreSetColor: string | Array<string>;
506
507
  /**
507
508
  * @hideconstructor
508
509
  */
@@ -588,12 +589,20 @@ declare class FigureElement {
588
589
  clear(_canvasIndex?: number): void;
589
590
  cleanup(deleteTexture?: boolean): void;
590
591
  willStartAnimating(): boolean;
592
+ /**
593
+ * Returns `true` if a `setColor` command tagged with source `from` should be
594
+ * ignored by this element (per `ignoreSetColor`). Untagged commands
595
+ * (`from == null`) are never ignored.
596
+ */
597
+ isSetColorIgnored(from?: string | null): boolean;
591
598
  /**
592
599
  Set element color.
593
600
  @param {[number, number, number, number]} color RGBA color from 0 to 1
594
601
  @param {boolean} [setDefault] also set the default color to this color
602
+ @param {string | null} [from] source label of this color command; if it
603
+ matches `ignoreSetColor` the command is ignored
595
604
  */
596
- setColor(color: TypeColor, setDefault?: boolean): void;
605
+ setColor(color: TypeColor, setDefault?: boolean, from?: string | null): void;
597
606
  /**
598
607
  * Set element color to `dimColor`
599
608
  */
@@ -879,7 +888,7 @@ declare class FigureElementPrimitive extends FigureElement {
879
888
  _dup(transform?: Transform | null): FigureElementPrimitive;
880
889
  clear(canvasIndex?: number): void;
881
890
  resize(figureHTMLElement?: HTMLElement | null | undefined): void;
882
- setColor(color: TypeColor, setDefault?: boolean): void;
891
+ setColor(color: TypeColor, setDefault?: boolean, from?: string | null): void;
883
892
  setOpacity(opacity: number): void;
884
893
  show(): void;
885
894
  hide(): void;
@@ -1138,7 +1147,7 @@ declare class FigureElementCollection extends FigureElement {
1138
1147
  getSelectionFromBorders(glLocation: Point): FigureElement | null;
1139
1148
  stop(how?: 'freeze' | 'cancel' | 'complete' | 'animateToComplete' | 'dissolveToComplete', elementOnly?: boolean): void;
1140
1149
  setFont(fontSize: number): void;
1141
- setColor(color?: TypeColor, setDefault?: boolean): void;
1150
+ setColor(color?: TypeColor, setDefault?: boolean, from?: string | null): void;
1142
1151
  setDimColor(color?: TypeColor): void;
1143
1152
  undim(children?: TypeElementPath | null | undefined): void;
1144
1153
  dim(children?: TypeElementPath | null | undefined): void;
@@ -89,6 +89,7 @@ export default class BaseAnnotationFunction implements ElementInterface {
89
89
  scale: number;
90
90
  showContent: boolean;
91
91
  color: TypeColor | null;
92
+ opacity: number | null;
92
93
  fullSize: {
93
94
  leftOffset: number;
94
95
  width: number;
@@ -107,7 +108,9 @@ export default class BaseAnnotationFunction implements ElementInterface {
107
108
  cleanup(): void;
108
109
  getAllElements(includeHidden?: boolean): any[];
109
110
  setPositions(): void;
110
- setColor(colorIn?: TypeColor | null): void;
111
+ setColor(colorIn?: TypeColor | null, from?: string | null): void;
112
+ setOpacity(opacityIn?: number | null): void;
113
+ collectDrawOrder(ops: Array<any>): void;
111
114
  offsetLocation(offset?: Point): void;
112
115
  calcSize(location: Point, scale: number): void;
113
116
  setEncompassGlyph(scale: number, contentBoundsIn: Bounds): [Bounds, Bounds];
@@ -15,7 +15,8 @@ export default class BaseEquationFunction extends Elements {
15
15
  _dup(namedCollection?: Record<string, any>): any;
16
16
  getAllElements(includeHidden?: boolean): any[];
17
17
  setPositions(): void;
18
- setColor(colorIn?: TypeColor | null): void;
18
+ setColor(colorIn?: TypeColor | null, from?: string | null): void;
19
+ setOpacity(opacityIn?: number | null): void;
19
20
  offsetLocation(offset?: Point): void;
20
21
  calcSize(location: Point, scale: number): void;
21
22
  }
@@ -0,0 +1,6 @@
1
+ import { Point } from '../../../tools/g2';
2
+ import BaseEquationFunction from './BaseEquationFunction';
3
+ export default class DrawOrder extends BaseEquationFunction {
4
+ calcSize(location: Point, scale: number): void;
5
+ collectDrawOrder(ops: Array<any>): void;
6
+ }
@@ -25,7 +25,9 @@ export interface ElementInterface {
25
25
  offsetLocation(offset: Point): void;
26
26
  getBounds(useFullSize?: boolean): Bounds;
27
27
  cleanup(): void;
28
- setColor(colorIn: TypeColor | null): void;
28
+ setColor(colorIn: TypeColor | null, from?: string | null): void;
29
+ setOpacity(opacityIn: number | null): void;
30
+ collectDrawOrder(ops: Array<any>): void;
29
31
  }
30
32
  declare class BlankElement {
31
33
  ascent: number;
@@ -48,6 +50,7 @@ declare class Element implements ElementInterface {
48
50
  showContent: boolean;
49
51
  color: TypeColor | null;
50
52
  defaultColor: TypeColor;
53
+ opacity: number | null;
51
54
  fullSize: {
52
55
  leftOffset: number;
53
56
  width: number;
@@ -61,7 +64,9 @@ declare class Element implements ElementInterface {
61
64
  _dup(namedCollection?: Record<string, any>): Element;
62
65
  getAllElements(includeHidden?: boolean): (FigureElementCollection | FigureElementPrimitive)[];
63
66
  setPositions(): void;
64
- setColor(colorIn?: TypeColor | null): void;
67
+ setColor(colorIn?: TypeColor | null, from?: string | null): void;
68
+ setOpacity(opacityIn?: number | null): void;
69
+ collectDrawOrder(ops: Array<any>): void;
65
70
  offsetLocation(offset?: Point): void;
66
71
  getBounds(useFullSize?: boolean): Bounds;
67
72
  }
@@ -75,6 +80,7 @@ declare class Elements implements ElementInterface {
75
80
  fnMap: FunctionMap;
76
81
  showContent: boolean;
77
82
  color: TypeColor | null;
83
+ opacity: number | null;
78
84
  fullSize: {
79
85
  leftOffset: number;
80
86
  width: number;
@@ -88,7 +94,9 @@ declare class Elements implements ElementInterface {
88
94
  calcSize(location: Point, scale: number): void;
89
95
  getAllElements(includeHidden?: boolean): (FigureElementCollection | FigureElementPrimitive | ElementInterface)[];
90
96
  setPositions(): void;
91
- setColor(colorIn?: TypeColor | null): void;
97
+ setColor(colorIn?: TypeColor | null, from?: string | null): void;
98
+ setOpacity(opacityIn?: number | null): void;
99
+ collectDrawOrder(ops: Array<any>): void;
92
100
  offsetLocation(offset?: Point): void;
93
101
  getBounds(useFullSize?: boolean): Bounds;
94
102
  }
@@ -0,0 +1,6 @@
1
+ import { Point } from '../../../tools/g2';
2
+ import BaseEquationFunction from './BaseEquationFunction';
3
+ export default class Opacity extends BaseEquationFunction {
4
+ opacity: number | null;
5
+ calcSize(location: Point, scale: number): void;
6
+ }
@@ -31,6 +31,16 @@ export type EQN_UpdateElementText = {
31
31
  * Object where keys are property names of a {@link FigureElement} and values
32
32
  * are the values to set the properties to.
33
33
  *
34
+ * Two keys are treated specially as draw-order operations rather than element
35
+ * properties: `back` and `front`. Each takes an options object (`{}` for the
36
+ * full extreme, `{ num }` to move a set number of places, or `{ before }` /
37
+ * `{ after }` to position relative to an anchor element) and reorders the
38
+ * element in the equation's draw stack - paralleling the {@link EQN_Back} and
39
+ * {@link EQN_Front} equation functions. When several elements declare `back` or
40
+ * `front` mods, they are applied in definition order, so
41
+ * `{ a: { back: {} }, b: { back: {} } }` sends `a` to the back and then `b` to
42
+ * the back.
43
+ *
34
44
  * @property {any} [_propertyName]
35
45
  * @interface
36
46
  * @group Misc Figure Element
@@ -392,6 +402,11 @@ export type EQN_FromForms = {
392
402
  * automatically in the equation based on EQN_Color equation functions. In such
393
403
  * cases, colors that are set external to the equation will be overridden. Use
394
404
  * `true` to allow setting of colors externally only. (`false`)
405
+ * @property {boolean} [ignoreOpacity] when `false`, opacity will be set
406
+ * automatically in the equation based on EQN_Opacity equation functions
407
+ * (multiplicative cascade). Element opacities set externally will be
408
+ * overridden. Use `true` to allow setting of opacities externally only.
409
+ * (`false`)
395
410
  *
396
411
  * @example
397
412
  * // Simple form definition of two different forms of the same equation and one
@@ -483,6 +498,7 @@ type EQN_FormObjectDefinition = {
483
498
  elementMods?: OBJ_ElementMods;
484
499
  fromForm: EQN_FromForms;
485
500
  ignoreColor?: boolean;
501
+ ignoreOpacity?: boolean;
486
502
  };
487
503
  /**
488
504
  * A form definition can either be:
@@ -588,6 +604,7 @@ export type EQN_FormDefaults = {
588
604
  onTransition?: null | string | (() => void);
589
605
  layout?: 'lazy' | 'init' | 'always';
590
606
  ignoreColor?: boolean;
607
+ ignoreOpacity?: boolean;
591
608
  };
592
609
  /**
593
610
  * Options objects to construct an {@link Equation} class.
@@ -726,6 +743,32 @@ type EQN_EquationGoToForm = {
726
743
  * * {@link GoToFormAnimationStep}
727
744
  * * {@link NextFormAnimationStep}
728
745
  *
746
+ * In addition to the notifications published by {@link FigureElement}, an
747
+ * Equation publishes a `formChanged` notification whenever the displayed form
748
+ * may have changed. The payload is an object
749
+ * `{ phase, form, fromForm?, progress? }` where `phase` is one of:
750
+ * - `'showForm'`: a form was set via `showForm`. Callers can suppress this
751
+ * event by passing `notify: false` to `showForm`; internal `showForm`
752
+ * calls made by `goToForm` do this so the `goToForm*` event stream is
753
+ * not interleaved with stray `showForm` events.
754
+ * - `'goToFormStart'`: a `goToForm` call has just begun
755
+ * - `'goToFormStep'`: published on every animation frame during a `goToForm`
756
+ * animation; `progress` is the percentage (0-1) through the animation. A
757
+ * final `goToFormStep` with `progress: 1` is always published immediately
758
+ * before `goToFormEnd`
759
+ * - `'goToFormEnd'`: a `goToForm` call has finished
760
+ *
761
+ * * `fromForm` is only included on the `goToForm*` phases (it carries the
762
+ * `fromWhere` option from `goToForm`); it is absent on `showForm`. `progress`
763
+ * is only included on `goToFormStep`. The event order for a `goToForm` call
764
+ * is always: `goToFormStart` → zero-or-more `goToFormStep` → `goToFormStep`
765
+ * with `progress: 1` → `goToFormEnd`.
766
+ *
767
+ * A user-initiated `showForm` made while a `goToForm` animation is running
768
+ * will publish its `showForm` event interleaved with the ongoing
769
+ * `goToFormStep` stream — listeners that drive UI from "the current
770
+ * transition" should account for this. Pass `notify: false` to suppress.
771
+ *
729
772
  * @extends FigureElementCollection
730
773
  *
731
774
  * @see To test examples, append them to the
@@ -799,6 +842,7 @@ export declare class Equation extends FigureElementCollection {
799
842
  onTransition?: null | string | (() => void);
800
843
  layout?: 'always' | 'lazy' | 'init';
801
844
  ignoreColor?: boolean;
845
+ ignoreOpacity?: boolean;
802
846
  };
803
847
  isAnimating: boolean;
804
848
  descriptionElement: FigureElementPrimitive | null;
@@ -979,7 +1023,20 @@ export declare class Equation extends FigureElementCollection {
979
1023
  /**
980
1024
  * Show equation form
981
1025
  */
982
- showForm(formOrName?: EquationForm | string, animationStop?: boolean): void;
1026
+ /**
1027
+ * Show equation form.
1028
+ *
1029
+ * @param formOrName the form, or its name, to show
1030
+ * @param animationStop if `true`, stops any in-progress element animations
1031
+ * before rendering the form (default `true`)
1032
+ * @param notify if `true`, publish a `formChanged` notification with
1033
+ * `phase: 'showForm'` (default `true`). Pass `false` to suppress the
1034
+ * event — useful for bulk updates or when this `showForm` is part of a
1035
+ * larger transition the caller is broadcasting separately. The internal
1036
+ * `showForm` calls made by `goToForm` use `false` so the `goToForm*`
1037
+ * event stream is not interleaved with stray `showForm` events.
1038
+ */
1039
+ showForm(formOrName?: EquationForm | string, animationStop?: boolean, notify?: boolean): void;
983
1040
  showAll(): void;
984
1041
  cleanup(): void;
985
1042
  cleanupForms(): void;
@@ -103,6 +103,7 @@ export default class EquationForm extends Elements {
103
103
  positionsSet: boolean;
104
104
  layout: 'always' | 'lazy' | 'init';
105
105
  ignoreColor: boolean;
106
+ ignoreOpacity: boolean;
106
107
  fromForm: {
107
108
  [key: string]: {
108
109
  onTransition?: string | (() => void);
@@ -122,6 +123,9 @@ export default class EquationForm extends Elements {
122
123
  getNamedElements(): Record<string, any>;
123
124
  rearrange(): void;
124
125
  setPositions(noArrange?: boolean): void;
126
+ collectElementModDrawOrder(ops: Array<any>): void;
127
+ setDrawOrder(): void;
128
+ applyDrawOrderOp(collection: any, op: any): void;
125
129
  _dup(elements?: TypeElements, collectionMethods?: TypeCollectionMethods): EquationForm;
126
130
  arrange(scale?: number, xAlign?: TypeHAlign | null, yAlign?: TypeVAlign | null, fixTo?: FigureElementPrimitive | FigureElementCollection | Point): void;
127
131
  lazyArrange(scale?: number, xAlign?: TypeHAlign | null, yAlign?: TypeVAlign | null, fixTo?: FigureElementPrimitive | FigureElementCollection | Point): void;
@@ -133,7 +137,7 @@ export default class EquationForm extends Elements {
133
137
  render(): void;
134
138
  showHide(showTime?: number, hideTime?: number, callback?: ((arg?: any) => void) | null, animationStop?: boolean): void;
135
139
  hideShow(showTime?: number, hideTime?: number, callback?: ((arg?: any) => void) | null, animationStop?: boolean): void;
136
- allHideShow(delay?: number, hideTime?: number, blankTime?: number, showTime?: number, callback?: ((cancelled: boolean) => void) | null): void;
140
+ allHideShow(delay?: number, hideTime?: number, blankTime?: number, showTime?: number, callback?: ((cancelled: boolean) => void) | null): number;
137
141
  applyElementMods(fromWhere?: null | string): void;
138
142
  animatePositionsTo(delay: number, dissolveOutTime: number, moveTime: number | null, dissolveInTime: number, callback?: (string | ((arg?: any) => void)) | null, fromWhere?: string | null | undefined, dissolveInBeforeMove?: boolean): number;
139
143
  }
@@ -11,6 +11,8 @@ import Container from './Elements/Container';
11
11
  import BaseAnnotationFunction from './Elements/BaseAnnotationFunction';
12
12
  import Offset from './Elements/Offset';
13
13
  import Color from './Elements/Color';
14
+ import Opacity from './Elements/Opacity';
15
+ import DrawOrder from './Elements/DrawOrder';
14
16
  import type { TypeColor } from '../../tools/types';
15
17
  export declare function getFigureElement(elementsObject: {
16
18
  [key: string]: FigureElementPrimitive | FigureElementCollection;
@@ -46,6 +48,10 @@ export declare function getFigureElement(elementsObject: {
46
48
  * - `{ prodOf: `{@link EQN_ProdOf} `}`
47
49
  * - `{ topStrike: `{@link EQN_StrikeComment} `}`
48
50
  * - `{ bottomStrike: `{@link EQN_StrikeComment} `}`
51
+ * - `{ color: `{@link EQN_Color} `}`
52
+ * - `{ opacity: `{@link EQN_Opacity} `}`
53
+ * - `{ back: `{@link EQN_Back} `}`
54
+ * - `{ front: `{@link EQN_Front} `}`
49
55
  * - `{ make: string, name?: string, ... }` (inline element — creates any
50
56
  * element type directly in a form using the same `make` values as
51
57
  * {@link Figure.add}. If `name` is omitted, one is auto-generated.)
@@ -142,6 +148,14 @@ export type TypeEquationPhrase = string | number | {
142
148
  topStrike: EQN_StrikeComment;
143
149
  } | {
144
150
  bottomStrike: EQN_StrikeComment;
151
+ } | {
152
+ color: EQN_Color;
153
+ } | {
154
+ opacity: EQN_Opacity;
155
+ } | {
156
+ back: EQN_Back;
157
+ } | {
158
+ front: EQN_Front;
145
159
  } | {
146
160
  make: string;
147
161
  name?: string;
@@ -564,6 +578,25 @@ export type EQN_Scale = {
564
578
  * },
565
579
  * touch: { onClick: e => e.nextForm() },
566
580
  * });
581
+ * @example
582
+ * // The `color` function recolours a phrase explicitly. Separately, an element
583
+ * // can opt out of the equation's default ('form') colour cascade with
584
+ * // `ignoreSetColor`, while still accepting explicit colour commands. Here both
585
+ * // squares start blue; recolouring the whole equation to grey greys the left
586
+ * // (free) square, but the right (locked) square keeps its colour.
587
+ * const blue = [0, 0, 1, 1];
588
+ * const locked = figure.primitives.rectangle({ width: 0.5, height: 0.5, color: blue });
589
+ * locked.ignoreSetColor = 'form'; // ignore the default cascade, keep blue
590
+ * const eqn = figure.add({
591
+ * make: 'equation',
592
+ * color: [1, 0, 0, 1],
593
+ * elements: {
594
+ * free: figure.primitives.rectangle({ width: 0.5, height: 0.5, color: blue }),
595
+ * locked,
596
+ * },
597
+ * forms: { 0: ['free', ' ', 'locked'] },
598
+ * });
599
+ * eqn.setColor([0.5, 0.5, 0.5, 1], true, 'form'); // free -> grey, locked stays blue
567
600
  * @interface
568
601
  * @group Equation Layout
569
602
  */
@@ -577,6 +610,255 @@ export type EQN_Color = {
577
610
  TypeColor,
578
611
  (boolean | null | undefined)
579
612
  ];
613
+ /**
614
+ * Equation opacity function
615
+ *
616
+ * Set an opacity multiplier on an equation phrase. The opacity cascades
617
+ * multiplicatively, so nested `opacity` functions multiply together (e.g. an
618
+ * outer `0.5` around an inner `0.5` yields `0.25` on the inner content).
619
+ *
620
+ * Opacity values are expected to be in the range `[0, 1]`. Whenever the form
621
+ * is shown, the cascaded opacity is assigned to each wrapped element, overriding
622
+ * any externally-set element `opacity`. Set `ignoreOpacity: true` on the form
623
+ * to suppress this and preserve externally-set opacities.
624
+ *
625
+ * Options can be an object, or an array in the property order below
626
+ *
627
+ * @property {TypeEquationPhrase} content
628
+ * @property {number} opacity opacity multiplier in the range `[0, 1]`
629
+ * @property {boolean} [fullContentBounds] Use full bounds with content (`false`)
630
+ *
631
+ * @see To test examples, append them to the
632
+ * <a href="#drawing-boilerplate">boilerplate</a>
633
+ *
634
+ * @example
635
+ * // Simple Array Definition
636
+ * figure.add({
637
+ * make: 'equation',
638
+ * forms: {
639
+ * 0: ['a', { opacity: ['b', 0.3] }, 'c'],
640
+ * },
641
+ * });
642
+ *
643
+ * @example
644
+ * // Simple Object Definition
645
+ * figure.add({
646
+ * make: 'equation',
647
+ * forms: {
648
+ * 0: [
649
+ * 'a',
650
+ * {
651
+ * opacity: {
652
+ * content: 'b',
653
+ * opacity: 0.3,
654
+ * },
655
+ * },
656
+ * 'c',
657
+ * ],
658
+ * },
659
+ * });
660
+ *
661
+ * @interface
662
+ * @group Equation Layout
663
+ */
664
+ export type EQN_Opacity = {
665
+ content: TypeEquationPhrase;
666
+ opacity: number;
667
+ fullContentBounds?: boolean;
668
+ name?: string;
669
+ } | [
670
+ TypeEquationPhrase,
671
+ number,
672
+ (boolean | null | undefined)
673
+ ];
674
+ /**
675
+ * Equation back function
676
+ *
677
+ * Send an equation phrase's elements back in the equation's draw stack. All
678
+ * elements within `content` are moved together as a group, keeping their
679
+ * current relative draw order. Nested `front`/`back` functions are applied
680
+ * inner-most first, so an inner `front`/`back` reorders the elements and this
681
+ * (outer) function then moves the reordered group as a unit.
682
+ *
683
+ * The group's position is determined by, in order of precedence:
684
+ * - `before` - position the group just before (behind) the most-back of the
685
+ * named anchor element(s). `num` shifts it further back (default `0`).
686
+ * - `after` - position the group just after (in front of) the most-front of
687
+ * the named anchor element(s). `num` shifts it further forward (default `0`).
688
+ * - `num` - a positive value moves the group that many places back; a negative
689
+ * value positions it `|num|` places ahead of the very back.
690
+ * - otherwise the group is sent completely to the back.
691
+ *
692
+ * The reorder is applied whenever the form is shown, relative to the equation's
693
+ * natural (definition) draw order, so each form deterministically defines its
694
+ * own stacking.
695
+ *
696
+ * Options can be an object, or an array in the property order below
697
+ *
698
+ * @property {TypeEquationPhrase} content
699
+ * @property {number} [num] places to send the group back (positive), or an
700
+ * absolute position `|num|` places ahead of the full back (negative). When
701
+ * `before`/`after` is set, `num` is the offset from the anchor (default `0`).
702
+ * If undefined (and no anchor), the group is sent completely to the back
703
+ * @property {string | Array<string>} [before] anchor element name(s) - position
704
+ * the group just before the most-back anchor
705
+ * @property {string | Array<string>} [after] anchor element name(s) - position
706
+ * the group just after the most-front anchor
707
+ * @property {boolean} [fullContentBounds] Use full bounds with content (`false`)
708
+ *
709
+ * @see To test examples, append them to the
710
+ * <a href="#drawing-boilerplate">boilerplate</a>
711
+ *
712
+ * @example
713
+ * // Three overlapping squares, offset so the stacking order is visible. Blue
714
+ * // is defined last so it sits on top by default; `back` sends it behind the
715
+ * // red and green squares (so green ends up on top).
716
+ * const sq = color => figure.primitives.rectangle({ width: 0.6, height: 0.6, color });
717
+ * figure.add({
718
+ * make: 'equation',
719
+ * elements: {
720
+ * r: sq([1, 0, 0, 1]),
721
+ * g: sq([0, 0.8, 0, 1]),
722
+ * b: sq([0, 0, 1, 1]),
723
+ * },
724
+ * forms: {
725
+ * 0: [
726
+ * { offset: ['r', [0, 0]] },
727
+ * { offset: ['g', [0.3, -0.25]] },
728
+ * { offset: [{ back: ['b'] }, [0.6, -0.5]] },
729
+ * ],
730
+ * },
731
+ * });
732
+ *
733
+ * @example
734
+ * // Object Definition with an anchor - position the blue square just before
735
+ * // (behind) the red square, so red and green sit on top of it.
736
+ * const sq = color => figure.primitives.rectangle({ width: 0.6, height: 0.6, color });
737
+ * figure.add({
738
+ * make: 'equation',
739
+ * elements: {
740
+ * r: sq([1, 0, 0, 1]),
741
+ * g: sq([0, 0.8, 0, 1]),
742
+ * b: sq([0, 0, 1, 1]),
743
+ * },
744
+ * forms: {
745
+ * 0: [
746
+ * { offset: ['r', [0, 0]] },
747
+ * { offset: ['g', [0.3, -0.25]] },
748
+ * { offset: [{ back: { content: 'b', before: 'r' } }, [0.6, -0.5]] },
749
+ * ],
750
+ * },
751
+ * });
752
+ *
753
+ * @interface
754
+ * @group Equation Layout
755
+ */
756
+ export type EQN_Back = {
757
+ content: TypeEquationPhrase;
758
+ num?: number;
759
+ before?: string | Array<string>;
760
+ after?: string | Array<string>;
761
+ fullContentBounds?: boolean;
762
+ name?: string;
763
+ } | [
764
+ TypeEquationPhrase,
765
+ (number | null | undefined),
766
+ (boolean | null | undefined)
767
+ ];
768
+ /**
769
+ * Equation front function
770
+ *
771
+ * Bring an equation phrase's elements forward in the equation's draw stack. All
772
+ * elements within `content` are moved together as a group, keeping their
773
+ * current relative draw order. Nested `front`/`back` functions are applied
774
+ * inner-most first, so an inner `front`/`back` reorders the elements and this
775
+ * (outer) function then moves the reordered group as a unit.
776
+ *
777
+ * The group's position is determined by, in order of precedence:
778
+ * - `before` - position the group just before (behind) the most-back of the
779
+ * named anchor element(s). `num` shifts it further back (default `0`).
780
+ * - `after` - position the group just after (in front of) the most-front of
781
+ * the named anchor element(s). `num` shifts it further forward (default `0`).
782
+ * - `num` - a positive value moves the group that many places forward; a
783
+ * negative value positions it `|num|` places behind the very front.
784
+ * - otherwise the group is brought completely to the front.
785
+ *
786
+ * The reorder is applied whenever the form is shown, relative to the equation's
787
+ * natural (definition) draw order, so each form deterministically defines its
788
+ * own stacking.
789
+ *
790
+ * Options can be an object, or an array in the property order below
791
+ *
792
+ * @property {TypeEquationPhrase} content
793
+ * @property {number} [num] places to bring the group forward (positive), or an
794
+ * absolute position `|num|` places behind the full front (negative). When
795
+ * `before`/`after` is set, `num` is the offset from the anchor (default `0`).
796
+ * If undefined (and no anchor), the group is brought completely to the front
797
+ * @property {string | Array<string>} [before] anchor element name(s) - position
798
+ * the group just before the most-back anchor
799
+ * @property {string | Array<string>} [after] anchor element name(s) - position
800
+ * the group just after the most-front anchor
801
+ * @property {boolean} [fullContentBounds] Use full bounds with content (`false`)
802
+ *
803
+ * @see To test examples, append them to the
804
+ * <a href="#drawing-boilerplate">boilerplate</a>
805
+ *
806
+ * @example
807
+ * // Three overlapping squares, offset so the stacking order is visible. Red is
808
+ * // defined first so it sits at the back by default; `front` brings it on top
809
+ * // of the green and blue squares.
810
+ * const sq = color => figure.primitives.rectangle({ width: 0.6, height: 0.6, color });
811
+ * figure.add({
812
+ * make: 'equation',
813
+ * elements: {
814
+ * r: sq([1, 0, 0, 1]),
815
+ * g: sq([0, 0.8, 0, 1]),
816
+ * b: sq([0, 0, 1, 1]),
817
+ * },
818
+ * forms: {
819
+ * 0: [
820
+ * { offset: [{ front: ['r'] }, [0, 0]] },
821
+ * { offset: ['g', [0.3, -0.25]] },
822
+ * { offset: ['b', [0.6, -0.5]] },
823
+ * ],
824
+ * },
825
+ * });
826
+ *
827
+ * @example
828
+ * // Object Definition with an anchor - position the red square just after (in
829
+ * // front of) the green square, so it covers green but stays behind blue.
830
+ * const sq = color => figure.primitives.rectangle({ width: 0.6, height: 0.6, color });
831
+ * figure.add({
832
+ * make: 'equation',
833
+ * elements: {
834
+ * r: sq([1, 0, 0, 1]),
835
+ * g: sq([0, 0.8, 0, 1]),
836
+ * b: sq([0, 0, 1, 1]),
837
+ * },
838
+ * forms: {
839
+ * 0: [
840
+ * { offset: [{ front: { content: 'r', after: 'g' } }, [0, 0]] },
841
+ * { offset: ['g', [0.3, -0.25]] },
842
+ * { offset: ['b', [0.6, -0.5]] },
843
+ * ],
844
+ * },
845
+ * });
846
+ *
847
+ * @interface
848
+ * @group Equation Layout
849
+ */
850
+ export type EQN_Front = {
851
+ content: TypeEquationPhrase;
852
+ num?: number;
853
+ before?: string | Array<string>;
854
+ after?: string | Array<string>;
855
+ fullContentBounds?: boolean;
856
+ name?: string;
857
+ } | [
858
+ TypeEquationPhrase,
859
+ (number | null | undefined),
860
+ (boolean | null | undefined)
861
+ ];
580
862
  /**
581
863
  * Equation bracket
582
864
  *
@@ -3272,8 +3554,8 @@ export declare class EquationFunctions {
3272
3554
  stringToElement(content: string): any;
3273
3555
  parseContent(content: TypeEquationPhrase | null | undefined): any;
3274
3556
  contentToElement(content: TypeEquationPhrase | Elements | FigureElementPrimitive | FigureElementCollection): Elements;
3275
- eqnMethod(name: string, params: any): BaseAnnotationFunction | Fraction | Matrix | Lines | Scale | Container | Offset | Color | null;
3276
- dispatchEqnMethod(name: string, params: any): BaseAnnotationFunction | Fraction | Matrix | Lines | Scale | Container | Offset | Color | null;
3557
+ eqnMethod(name: string, params: any): BaseAnnotationFunction | Fraction | Matrix | Lines | Scale | Container | Offset | Color | Opacity | DrawOrder | null;
3558
+ dispatchEqnMethod(name: string, params: any): BaseAnnotationFunction | Fraction | Matrix | Lines | Scale | Container | Offset | Color | Opacity | DrawOrder | null;
3277
3559
  /**
3278
3560
  * Equation container function
3279
3561
  * @see {@link EQN_Container} for description and examples
@@ -3309,6 +3591,22 @@ export declare class EquationFunctions {
3309
3591
  * @see {@link EQN_Color} for description and examples
3310
3592
  */
3311
3593
  color(options: EQN_Color): Color;
3594
+ /**
3595
+ * Equation opacity function
3596
+ * @see {@link EQN_Opacity} for description and examples
3597
+ */
3598
+ opacity(options: EQN_Opacity): Opacity;
3599
+ /**
3600
+ * Equation back function
3601
+ * @see {@link EQN_Back} for description and examples
3602
+ */
3603
+ back(options: EQN_Back): DrawOrder;
3604
+ /**
3605
+ * Equation front function
3606
+ * @see {@link EQN_Front} for description and examples
3607
+ */
3608
+ front(options: EQN_Front): DrawOrder;
3609
+ drawOrder(options: EQN_Front | EQN_Back, front: boolean): DrawOrder;
3312
3610
  /**
3313
3611
  * Equation fraction function
3314
3612
  * @see {@link EQN_Fraction} for description and examples
@@ -108,7 +108,7 @@ export default class FigureElementPrimitive2DText extends FigureElementPrimitive
108
108
  * @return {FigureFont}
109
109
  */
110
110
  getFont(): FigureFont;
111
- setColor(color: TypeColor, setDefault?: boolean): void;
111
+ setColor(color: TypeColor, setDefault?: boolean, from?: string | null): void;
112
112
  stateSet(): void;
113
113
  measureAndAlignText(): void;
114
114
  _getStateProperties(options: {
@@ -81,7 +81,7 @@ export default class FigureElementPrimitiveGLText extends FigureElementPrimitive
81
81
  * @param {OBJ_Font} font
82
82
  */
83
83
  setFont(font: OBJ_Font): void;
84
- setColor(color: TypeColor, setDefault?: boolean): void;
84
+ setColor(color: TypeColor, setDefault?: boolean, from?: string | null): void;
85
85
  calcBorderAndBounds(): void;
86
86
  calcBorder(): void;
87
87
  stateSet(): void;