figureone 1.3.0 → 1.4.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.
package/index.js CHANGED
@@ -17225,6 +17225,10 @@ function offsetLocationForGlyphs(glyphs, offset) {
17225
17225
  });
17226
17226
  }
17227
17227
  var BaseAnnotationFunction = /*#__PURE__*/function () {
17228
+ // Optional caller-supplied identifier, assigned post-dispatch by
17229
+ // EquationFunctions.eqnMethod. Has no layout effect; used by
17230
+ // Equation.getFunctionElements to look up the contents of a sub-tree.
17231
+
17228
17232
  function BaseAnnotationFunction(content, annotations, glyphs, options) {
17229
17233
  var showContent = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
17230
17234
  _classCallCheck(this, BaseAnnotationFunction);
@@ -17236,6 +17240,7 @@ var BaseAnnotationFunction = /*#__PURE__*/function () {
17236
17240
  this.showContent = showContent;
17237
17241
  this.scale = 1;
17238
17242
  this.color = null;
17243
+ this.functionName = null;
17239
17244
  }
17240
17245
  return _createClass(BaseAnnotationFunction, [{
17241
17246
  key: "_dup",
@@ -17870,6 +17875,10 @@ function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf
17870
17875
 
17871
17876
 
17872
17877
  var BaseEquationFunction = /*#__PURE__*/function (_Elements) {
17878
+ // Optional caller-supplied identifier, assigned post-dispatch by
17879
+ // EquationFunctions.eqnMethod. Has no layout effect; used by
17880
+ // Equation.getFunctionElements to look up the contents of a sub-tree.
17881
+
17873
17882
  function BaseEquationFunction(content, glyph, options) {
17874
17883
  var _this;
17875
17884
  var showContent = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
@@ -17908,6 +17917,7 @@ var BaseEquationFunction = /*#__PURE__*/function (_Elements) {
17908
17917
  });
17909
17918
  _this.options = options;
17910
17919
  _this.showContent = showContent;
17920
+ _this.functionName = null;
17911
17921
  return _this;
17912
17922
  }
17913
17923
  _inherits(BaseEquationFunction, _Elements);
@@ -19441,11 +19451,12 @@ __webpack_require__.r(__webpack_exports__);
19441
19451
  /* harmony import */ var _DrawingObjects_TextObject_TextObject__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../DrawingObjects/TextObject/TextObject */ "./src/js/figure/DrawingObjects/TextObject/TextObject.ts");
19442
19452
  /* harmony import */ var _Elements_Element__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./Elements/Element */ "./src/js/figure/Equation/Elements/Element.ts");
19443
19453
  /* harmony import */ var _Elements_BaseAnnotationFunction__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./Elements/BaseAnnotationFunction */ "./src/js/figure/Equation/Elements/BaseAnnotationFunction.ts");
19444
- /* harmony import */ var _EquationForm__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./EquationForm */ "./src/js/figure/Equation/EquationForm.ts");
19445
- /* harmony import */ var _tools_htmlGenerator__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../../tools/htmlGenerator */ "./src/js/tools/htmlGenerator.ts");
19446
- /* harmony import */ var _EquationSymbols__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./EquationSymbols */ "./src/js/figure/Equation/EquationSymbols.ts");
19447
- /* harmony import */ var _EquationFunctions__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./EquationFunctions */ "./src/js/figure/Equation/EquationFunctions.ts");
19448
- /* harmony import */ var _Animation_Animation__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../Animation/Animation */ "./src/js/figure/Animation/Animation.ts");
19454
+ /* harmony import */ var _Elements_BaseEquationFunction__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./Elements/BaseEquationFunction */ "./src/js/figure/Equation/Elements/BaseEquationFunction.ts");
19455
+ /* harmony import */ var _EquationForm__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./EquationForm */ "./src/js/figure/Equation/EquationForm.ts");
19456
+ /* harmony import */ var _tools_htmlGenerator__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../../tools/htmlGenerator */ "./src/js/tools/htmlGenerator.ts");
19457
+ /* harmony import */ var _EquationSymbols__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./EquationSymbols */ "./src/js/figure/Equation/EquationSymbols.ts");
19458
+ /* harmony import */ var _EquationFunctions__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./EquationFunctions */ "./src/js/figure/Equation/EquationFunctions.ts");
19459
+ /* harmony import */ var _Animation_Animation__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ../Animation/Animation */ "./src/js/figure/Animation/Animation.ts");
19449
19460
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
19450
19461
  function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
19451
19462
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
@@ -19480,6 +19491,7 @@ function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf
19480
19491
 
19481
19492
 
19482
19493
 
19494
+
19483
19495
  // import HTMLObject from '../DrawingObjects/HTMLObject/HTMLObject';
19484
19496
 
19485
19497
 
@@ -20178,7 +20190,7 @@ var NextFormAnimationStep = /*#__PURE__*/function (_TriggerAnimationStep) {
20178
20190
  }
20179
20191
  _inherits(NextFormAnimationStep, _TriggerAnimationStep);
20180
20192
  return _createClass(NextFormAnimationStep);
20181
- }(_Animation_Animation__WEBPACK_IMPORTED_MODULE_10__.TriggerAnimationStep);
20193
+ }(_Animation_Animation__WEBPACK_IMPORTED_MODULE_11__.TriggerAnimationStep);
20182
20194
  /**
20183
20195
  * GoToForm form animation step
20184
20196
  *
@@ -20229,7 +20241,7 @@ var GoToFormAnimationStep = /*#__PURE__*/function (_TriggerAnimationStep2) {
20229
20241
  }
20230
20242
  _inherits(GoToFormAnimationStep, _TriggerAnimationStep2);
20231
20243
  return _createClass(GoToFormAnimationStep);
20232
- }(_Animation_Animation__WEBPACK_IMPORTED_MODULE_10__.TriggerAnimationStep); // export const foo = () => {};
20244
+ }(_Animation_Animation__WEBPACK_IMPORTED_MODULE_11__.TriggerAnimationStep); // export const foo = () => {};
20233
20245
  // An Equation is a collection of elements that can be arranged into different
20234
20246
  // forms.
20235
20247
  // Equation allows setting of forms, and navigating through form series
@@ -20430,8 +20442,8 @@ var Equation = /*#__PURE__*/function (_FigureElementCollect) {
20430
20442
  layout: optionsToUse.formDefaults.layout,
20431
20443
  ignoreColor: optionsToUse.formDefaults.ignoreColor
20432
20444
  },
20433
- functions: new _EquationFunctions__WEBPACK_IMPORTED_MODULE_9__.EquationFunctions(_this.elements, _this.addElementFromKey.bind(_this), _this.getExistingOrAddSymbol.bind(_this), _this.makeInlineElement.bind(_this)),
20434
- symbols: new _EquationSymbols__WEBPACK_IMPORTED_MODULE_8__["default"](_this.shapes, _this.color),
20445
+ functions: new _EquationFunctions__WEBPACK_IMPORTED_MODULE_10__.EquationFunctions(_this.elements, _this.addElementFromKey.bind(_this), _this.getExistingOrAddSymbol.bind(_this), _this.makeInlineElement.bind(_this)),
20446
+ symbols: new _EquationSymbols__WEBPACK_IMPORTED_MODULE_9__["default"](_this.shapes, _this.color),
20435
20447
  font: optionsToUse.font,
20436
20448
  textFont: optionsToUse.textFont,
20437
20449
  // fontText: optionsToUse.fontText,
@@ -20531,7 +20543,7 @@ var Equation = /*#__PURE__*/function (_FigureElementCollect) {
20531
20543
  o.delay = 0;
20532
20544
  o.setToEnd = '_showForm';
20533
20545
  o.timeKeeper = _this.timeKeeper;
20534
- return new _Animation_Animation__WEBPACK_IMPORTED_MODULE_10__.TriggerAnimationStep(o);
20546
+ return new _Animation_Animation__WEBPACK_IMPORTED_MODULE_11__.TriggerAnimationStep(o);
20535
20547
  };
20536
20548
  _this.animations.customSteps.push({
20537
20549
  step: _this.animations.goToForm.bind(_this),
@@ -20577,7 +20589,7 @@ var Equation = /*#__PURE__*/function (_FigureElementCollect) {
20577
20589
  o.delay = 0;
20578
20590
  o.setToEnd = '_showForm';
20579
20591
  o.timeKeeper = _this.timeKeeper;
20580
- return new _Animation_Animation__WEBPACK_IMPORTED_MODULE_10__.TriggerAnimationStep(o);
20592
+ return new _Animation_Animation__WEBPACK_IMPORTED_MODULE_11__.TriggerAnimationStep(o);
20581
20593
  };
20582
20594
  _this.animations.customSteps.push({
20583
20595
  step: _this.animations.nextForm.bind(_this),
@@ -21221,7 +21233,7 @@ var Equation = /*#__PURE__*/function (_FigureElementCollect) {
21221
21233
  key: "checkFixTo",
21222
21234
  value: function checkFixTo(fixTo, formElements) {
21223
21235
  if (typeof fixTo === 'string') {
21224
- var element = (0,_EquationFunctions__WEBPACK_IMPORTED_MODULE_9__.getFigureElement)(this, fixTo);
21236
+ var element = (0,_EquationFunctions__WEBPACK_IMPORTED_MODULE_10__.getFigureElement)(this, fixTo);
21225
21237
  if (element != null && formElements.indexOf(element) >= 0) {
21226
21238
  return element;
21227
21239
  }
@@ -21239,7 +21251,7 @@ var Equation = /*#__PURE__*/function (_FigureElementCollect) {
21239
21251
  key: "createForm",
21240
21252
  value: function createForm() {
21241
21253
  var elements = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.elements;
21242
- return new _EquationForm__WEBPACK_IMPORTED_MODULE_6__["default"](elements, {
21254
+ return new _EquationForm__WEBPACK_IMPORTED_MODULE_7__["default"](elements, {
21243
21255
  getAllElements: this.getChildren.bind(this),
21244
21256
  hideAll: this.hideAll.bind(this),
21245
21257
  show: this.show.bind(this),
@@ -21269,6 +21281,90 @@ var Equation = /*#__PURE__*/function (_FigureElementCollect) {
21269
21281
  return this.eqn.forms[form].content[0].getAllElements(includeHidden);
21270
21282
  }
21271
21283
 
21284
+ /**
21285
+ * Return all the elements inside the named equation function within a form.
21286
+ *
21287
+ * Any equation function (container, fraction, matrix, etc.) can be tagged
21288
+ * with a `name` property in its options — this has no layout effect, but
21289
+ * makes the function's sub-tree addressable here.
21290
+ *
21291
+ * With `mode: 'all'` (default), walks the entire tree, collects every
21292
+ * matching function (including those nested inside other matches), and
21293
+ * returns the de-duplicated union of their elements. With `mode: 'first'`,
21294
+ * returns only the elements inside the first matching function found by a
21295
+ * depth-first traversal.
21296
+ *
21297
+ * If `formName` is `null` (default), the current form is used.
21298
+ *
21299
+ * Returns an empty array if the form does not exist, or no matching
21300
+ * function is found.
21301
+ *
21302
+ * @param {string} name
21303
+ * @param {string | null} [formName] (`null` — uses current form)
21304
+ * @param {'first' | 'all'} [mode] (`'all'`)
21305
+ * @param {boolean} [includeHidden] (`false`)
21306
+ * @return {Array<FigureElement>}
21307
+ */
21308
+ }, {
21309
+ key: "getFunctionElements",
21310
+ value: function getFunctionElements(name) {
21311
+ var formName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
21312
+ var mode = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'all';
21313
+ var includeHidden = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
21314
+ var resolvedFormName = formName == null ? this.eqn.currentForm : formName;
21315
+ var form = this.eqn.forms[resolvedFormName];
21316
+ if (form == null) {
21317
+ return [];
21318
+ }
21319
+ // Single typed accessor that hides the structural differences between
21320
+ // Elements (.content: ElementInterface[]) and BaseAnnotationFunction
21321
+ // (.content: ElementInterface + .annotations[].content). All `as any`
21322
+ // casts for this walk live here.
21323
+ var childrenOf = function childrenOf(node) {
21324
+ var out = [];
21325
+ var c = node.content;
21326
+ if (Array.isArray(c)) {
21327
+ out.push.apply(out, _toConsumableArray(c));
21328
+ } else if (c != null) {
21329
+ out.push(c);
21330
+ }
21331
+ var annotations = node.annotations;
21332
+ if (Array.isArray(annotations)) {
21333
+ annotations.forEach(function (a) {
21334
+ if (a != null && a.content != null) out.push(a.content);
21335
+ });
21336
+ }
21337
+ return out;
21338
+ };
21339
+ var matches = [];
21340
+ var _walk = function walk(nodes) {
21341
+ for (var i = 0; i < nodes.length; i += 1) {
21342
+ var node = nodes[i];
21343
+ if ((node instanceof _Elements_BaseEquationFunction__WEBPACK_IMPORTED_MODULE_6__["default"] || node instanceof _Elements_BaseAnnotationFunction__WEBPACK_IMPORTED_MODULE_5__["default"]) && node.functionName === name) {
21344
+ matches.push(node);
21345
+ if (mode === 'first') return true;
21346
+ }
21347
+ if (_walk(childrenOf(node))) return true;
21348
+ }
21349
+ return false;
21350
+ };
21351
+ _walk(form.content);
21352
+ if (matches.length === 0) {
21353
+ return [];
21354
+ }
21355
+ var seen = new Set();
21356
+ var out = [];
21357
+ matches.forEach(function (m) {
21358
+ m.getAllElements(includeHidden).forEach(function (el) {
21359
+ if (!seen.has(el)) {
21360
+ seen.add(el);
21361
+ out.push(el);
21362
+ }
21363
+ });
21364
+ });
21365
+ return out;
21366
+ }
21367
+
21272
21368
  /**
21273
21369
  * Return all the elements that are used in an equation phrase.
21274
21370
  * @param {TypeEquationPhrase} phrase
@@ -21403,7 +21499,7 @@ var Equation = /*#__PURE__*/function (_FigureElementCollect) {
21403
21499
  var newMods = {};
21404
21500
  Object.keys(elementMods).forEach(function (elementName) {
21405
21501
  var mods = elementMods[elementName];
21406
- var figureElement = (0,_EquationFunctions__WEBPACK_IMPORTED_MODULE_9__.getFigureElement)(_this9, elementName);
21502
+ var figureElement = (0,_EquationFunctions__WEBPACK_IMPORTED_MODULE_10__.getFigureElement)(_this9, elementName);
21407
21503
  if (figureElement != null) {
21408
21504
  newMods[elementName] = {
21409
21505
  element: figureElement,
@@ -21416,7 +21512,7 @@ var Equation = /*#__PURE__*/function (_FigureElementCollect) {
21416
21512
  var transformTranslation = function transformTranslation(trans) {
21417
21513
  var newTranslation = {};
21418
21514
  Object.keys(trans).forEach(function (elementName) {
21419
- var figureElement = (0,_EquationFunctions__WEBPACK_IMPORTED_MODULE_9__.getFigureElement)(_this9, elementName);
21515
+ var figureElement = (0,_EquationFunctions__WEBPACK_IMPORTED_MODULE_10__.getFigureElement)(_this9, elementName);
21420
21516
  var mods = trans[elementName];
21421
21517
  var direction;
21422
21518
  var style;
@@ -21594,7 +21690,7 @@ var Equation = /*#__PURE__*/function (_FigureElementCollect) {
21594
21690
  value: function getForm(formOrName
21595
21691
  // subForm: ?string,
21596
21692
  ) {
21597
- if (formOrName instanceof _EquationForm__WEBPACK_IMPORTED_MODULE_6__["default"]) {
21693
+ if (formOrName instanceof _EquationForm__WEBPACK_IMPORTED_MODULE_7__["default"]) {
21598
21694
  return formOrName;
21599
21695
  }
21600
21696
  if (formOrName in this.eqn.forms) {
@@ -21938,7 +22034,7 @@ var Equation = /*#__PURE__*/function (_FigureElementCollect) {
21938
22034
  ) {
21939
22035
  var form = this.getForm(formOrName);
21940
22036
  if (form != null && form.description != null) {
21941
- return _tools_htmlGenerator__WEBPACK_IMPORTED_MODULE_7__.applyModifiers(form.description, form.modifiers);
22037
+ return _tools_htmlGenerator__WEBPACK_IMPORTED_MODULE_8__.applyModifiers(form.description, form.modifiers);
21942
22038
  }
21943
22039
  return '';
21944
22040
  }
@@ -22741,9 +22837,10 @@ __webpack_require__.r(__webpack_exports__);
22741
22837
  /* harmony import */ var _Elements_Scale__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./Elements/Scale */ "./src/js/figure/Equation/Elements/Scale.ts");
22742
22838
  /* harmony import */ var _Elements_Container__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./Elements/Container */ "./src/js/figure/Equation/Elements/Container.ts");
22743
22839
  /* harmony import */ var _Elements_BaseAnnotationFunction__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./Elements/BaseAnnotationFunction */ "./src/js/figure/Equation/Elements/BaseAnnotationFunction.ts");
22744
- /* harmony import */ var _Symbols_Line__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./Symbols/Line */ "./src/js/figure/Equation/Symbols/Line.ts");
22745
- /* harmony import */ var _Elements_Offset__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./Elements/Offset */ "./src/js/figure/Equation/Elements/Offset.ts");
22746
- /* harmony import */ var _Elements_Color__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./Elements/Color */ "./src/js/figure/Equation/Elements/Color.ts");
22840
+ /* harmony import */ var _Elements_BaseEquationFunction__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./Elements/BaseEquationFunction */ "./src/js/figure/Equation/Elements/BaseEquationFunction.ts");
22841
+ /* harmony import */ var _Symbols_Line__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./Symbols/Line */ "./src/js/figure/Equation/Symbols/Line.ts");
22842
+ /* harmony import */ var _Elements_Offset__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./Elements/Offset */ "./src/js/figure/Equation/Elements/Offset.ts");
22843
+ /* harmony import */ var _Elements_Color__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./Elements/Color */ "./src/js/figure/Equation/Elements/Color.ts");
22747
22844
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
22748
22845
  function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
22749
22846
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
@@ -22773,6 +22870,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
22773
22870
 
22774
22871
 
22775
22872
 
22873
+
22776
22874
  // import type {
22777
22875
  // EQN_Annotation, EQN_EncompassGlyph, EQN_LeftRightGlyph, EQN_TopBottomGlyph,
22778
22876
  // } from './Elements/BaseAnnotationFunction';
@@ -22893,6 +22991,9 @@ function getFigureElement(elementsObject, name) {
22893
22991
  * @property {boolean} [fullContentBounds] - (`false`)
22894
22992
  * @property {boolean} [showContent] - if `false`, a container will be created
22895
22993
  * around the content, but the content will not be shown (`true`)
22994
+ * @property {string} [name] - optional identifier (available on every equation
22995
+ * function). Has no effect on layout, but allows the function's contents to be
22996
+ * looked up later with {@link Equation.getFunctionElements} (`null`)
22896
22997
  *
22897
22998
  * @see To test examples, append them to the
22898
22999
  * <a href="#drawing-boilerplate">boilerplate</a>
@@ -25529,6 +25630,18 @@ var EquationFunctions = /*#__PURE__*/function () {
25529
25630
  }, {
25530
25631
  key: "eqnMethod",
25531
25632
  value: function eqnMethod(name, params) {
25633
+ var result = this.dispatchEqnMethod(name, params);
25634
+ // Allow any equation function to be tagged with a caller-supplied
25635
+ // `name` via its options object. The tag has no layout effect; it's
25636
+ // used by Equation.getFunctionElements to look up the function's sub-tree.
25637
+ if (result != null && params != null && !Array.isArray(params) && _typeof(params) === 'object' && params.name != null && (result instanceof _Elements_BaseEquationFunction__WEBPACK_IMPORTED_MODULE_10__["default"] || result instanceof _Elements_BaseAnnotationFunction__WEBPACK_IMPORTED_MODULE_9__["default"])) {
25638
+ result.functionName = params.name;
25639
+ }
25640
+ return result;
25641
+ }
25642
+ }, {
25643
+ key: "dispatchEqnMethod",
25644
+ value: function dispatchEqnMethod(name, params) {
25532
25645
  if (name === 'frac') {
25533
25646
  return this.frac(params);
25534
25647
  }
@@ -25723,7 +25836,7 @@ var EquationFunctions = /*#__PURE__*/function () {
25723
25836
  fullContentBounds: fullContentBounds
25724
25837
  };
25725
25838
  var o = (0,_tools_tools__WEBPACK_IMPORTED_MODULE_1__.joinObjects)(defaultOptions, optionsIn);
25726
- return new _Elements_Offset__WEBPACK_IMPORTED_MODULE_11__["default"]([this.contentToElement(content)], [], o);
25839
+ return new _Elements_Offset__WEBPACK_IMPORTED_MODULE_12__["default"]([this.contentToElement(content)], [], o);
25727
25840
  } catch (e) {
25728
25841
  throw new Error("FigureOne Equation Offset Error: ".concat(e.message));
25729
25842
  }
@@ -26229,7 +26342,7 @@ var EquationFunctions = /*#__PURE__*/function () {
26229
26342
  fullContentBounds: fullContentBounds
26230
26343
  };
26231
26344
  var o = (0,_tools_tools__WEBPACK_IMPORTED_MODULE_1__.joinObjects)(defaultOptions, optionsIn);
26232
- return new _Elements_Color__WEBPACK_IMPORTED_MODULE_12__["default"]([this.contentToElement(content)], [], o);
26345
+ return new _Elements_Color__WEBPACK_IMPORTED_MODULE_13__["default"]([this.contentToElement(content)], [], o);
26233
26346
  } catch (e) {
26234
26347
  throw new Error("FigureOne Equation Color Error: ".concat(e.message));
26235
26348
  }
@@ -27462,7 +27575,7 @@ var EquationFunctions = /*#__PURE__*/function () {
27462
27575
  });
27463
27576
  }
27464
27577
  var glyph = this.getExistingOrAddSymbol(symbol);
27465
- if (glyph instanceof _Symbols_Line__WEBPACK_IMPORTED_MODULE_10__["default"]) {
27578
+ if (glyph instanceof _Symbols_Line__WEBPACK_IMPORTED_MODULE_11__["default"]) {
27466
27579
  annotations[0].offset = [0, commentSpaceToUse + contentSpaceToUse];
27467
27580
  return this.annotate({
27468
27581
  content: content,
@@ -27545,7 +27658,7 @@ var EquationFunctions = /*#__PURE__*/function () {
27545
27658
  });
27546
27659
  }
27547
27660
  var glyph = this.getExistingOrAddSymbol(symbol);
27548
- if (glyph instanceof _Symbols_Line__WEBPACK_IMPORTED_MODULE_10__["default"]) {
27661
+ if (glyph instanceof _Symbols_Line__WEBPACK_IMPORTED_MODULE_11__["default"]) {
27549
27662
  annotations[0].offset = [0, -commentSpaceToUse - contentSpaceToUse];
27550
27663
  return this.annotate({
27551
27664
  content: content,
@@ -80682,8 +80795,8 @@ var tools = {
80682
80795
  */
80683
80796
 
80684
80797
  var Fig = {
80685
- version: "1.3.0",
80686
- gitHash: "3aa02f880",
80798
+ version: "1.4.1",
80799
+ gitHash: "2fa15b061",
80687
80800
  tools: tools,
80688
80801
  Figure: _js_figure_Figure__WEBPACK_IMPORTED_MODULE_5__["default"],
80689
80802
  Recorder: _js_figure_Recorder_Recorder__WEBPACK_IMPORTED_MODULE_7__.Recorder,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "figureone",
3
- "version": "1.3.0",
3
+ "version": "1.4.1",
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",
@@ -101,6 +101,7 @@ export default class BaseAnnotationFunction implements ElementInterface {
101
101
  annotations: Array<EQN_Annotation>;
102
102
  glyphs: EQN_Glyphs;
103
103
  options: Record<string, any>;
104
+ functionName: string | null;
104
105
  constructor(content: ElementInterface, annotations: Array<EQN_Annotation>, glyphs: EQN_Glyphs, options: Record<string, any>, showContent?: boolean);
105
106
  _dup(namedCollection?: Record<string, any>): any;
106
107
  cleanup(): void;
@@ -10,6 +10,7 @@ export default class BaseEquationFunction extends Elements {
10
10
  glyphHeights: Array<number>;
11
11
  showContent: boolean;
12
12
  options: Record<string, any>;
13
+ functionName: string | null;
13
14
  constructor(content: Elements | null | Array<Elements | null>, glyph: Symbol | null | undefined | Array<Symbol | null | undefined>, options: Record<string, any>, showContent?: boolean);
14
15
  _dup(namedCollection?: Record<string, any>): any;
15
16
  getAllElements(includeHidden?: boolean): any[];
@@ -906,6 +906,31 @@ export declare class Equation extends FigureElementCollection {
906
906
  * @return {Array<FigureElement>}
907
907
  */
908
908
  getFormElements(form: string, includeHidden?: boolean): (FigureElementCollection | FigureElementPrimitive | ElementInterface)[];
909
+ /**
910
+ * Return all the elements inside the named equation function within a form.
911
+ *
912
+ * Any equation function (container, fraction, matrix, etc.) can be tagged
913
+ * with a `name` property in its options — this has no layout effect, but
914
+ * makes the function's sub-tree addressable here.
915
+ *
916
+ * With `mode: 'all'` (default), walks the entire tree, collects every
917
+ * matching function (including those nested inside other matches), and
918
+ * returns the de-duplicated union of their elements. With `mode: 'first'`,
919
+ * returns only the elements inside the first matching function found by a
920
+ * depth-first traversal.
921
+ *
922
+ * If `formName` is `null` (default), the current form is used.
923
+ *
924
+ * Returns an empty array if the form does not exist, or no matching
925
+ * function is found.
926
+ *
927
+ * @param {string} name
928
+ * @param {string | null} [formName] (`null` — uses current form)
929
+ * @param {'first' | 'all'} [mode] (`'all'`)
930
+ * @param {boolean} [includeHidden] (`false`)
931
+ * @return {Array<FigureElement>}
932
+ */
933
+ getFunctionElements(name: string, formName?: string | null, mode?: 'first' | 'all', includeHidden?: boolean): any[];
909
934
  /**
910
935
  * Return all the elements that are used in an equation phrase.
911
936
  * @param {TypeEquationPhrase} phrase
@@ -170,6 +170,9 @@ export type TypeEquationPhrase = string | number | {
170
170
  * @property {boolean} [fullContentBounds] - (`false`)
171
171
  * @property {boolean} [showContent] - if `false`, a container will be created
172
172
  * around the content, but the content will not be shown (`true`)
173
+ * @property {string} [name] - optional identifier (available on every equation
174
+ * function). Has no effect on layout, but allows the function's contents to be
175
+ * looked up later with {@link Equation.getFunctionElements} (`null`)
173
176
  *
174
177
  * @see To test examples, append them to the
175
178
  * <a href="#drawing-boilerplate">boilerplate</a>
@@ -236,6 +239,7 @@ export type EQN_Container = {
236
239
  scale?: number;
237
240
  fullContentBounds?: boolean;
238
241
  showContent?: boolean;
242
+ name?: string;
239
243
  } | [
240
244
  TypeEquationPhrase,
241
245
  (number | null | undefined),
@@ -288,6 +292,7 @@ export type EQN_Offset = {
288
292
  offset?: TypeParsablePoint;
289
293
  inSize?: boolean;
290
294
  fullContentBounds?: boolean;
295
+ name?: string;
291
296
  } | [
292
297
  TypeEquationPhrase,
293
298
  (TypeParsablePoint | null | undefined),
@@ -411,6 +416,7 @@ export type EQN_Fraction = {
411
416
  offsetY?: number;
412
417
  baseline?: 'numerator' | 'denominator' | 'vinculum';
413
418
  fullContentBounds?: boolean;
419
+ name?: string;
414
420
  } | [
415
421
  TypeEquationPhrase,
416
422
  string,
@@ -486,6 +492,7 @@ export type EQN_Scale = {
486
492
  content: TypeEquationPhrase;
487
493
  scale?: number;
488
494
  fullContentBounds?: boolean;
495
+ name?: string;
489
496
  } | [
490
497
  TypeEquationPhrase,
491
498
  (number | null | undefined),
@@ -564,6 +571,7 @@ export type EQN_Color = {
564
571
  content: TypeEquationPhrase;
565
572
  color: TypeColor;
566
573
  fullContentBounds?: boolean;
574
+ name?: string;
567
575
  } | [
568
576
  TypeEquationPhrase,
569
577
  TypeColor,
@@ -677,6 +685,7 @@ export type EQN_Bracket = {
677
685
  descent?: number;
678
686
  fullContentBounds?: boolean;
679
687
  useFullBounds?: boolean;
688
+ name?: string;
680
689
  } | [
681
690
  string,
682
691
  TypeEquationPhrase,
@@ -812,6 +821,7 @@ export type EQN_Root = {
812
821
  rootScale?: number;
813
822
  fullContentBounds?: boolean;
814
823
  useFullBounds?: boolean;
824
+ name?: string;
815
825
  } | [
816
826
  string,
817
827
  TypeEquationPhrase,
@@ -928,6 +938,7 @@ export type EQN_Strike = {
928
938
  leftSpace?: number;
929
939
  fullContentBounds?: boolean;
930
940
  useFullBounds?: boolean;
941
+ name?: string;
931
942
  } | [
932
943
  TypeEquationPhrase,
933
944
  string,
@@ -1045,6 +1056,7 @@ export type EQN_Box = {
1045
1056
  leftSpace?: number;
1046
1057
  fullContentBounds?: boolean;
1047
1058
  useFullBounds?: boolean;
1059
+ name?: string;
1048
1060
  } | [
1049
1061
  TypeEquationPhrase,
1050
1062
  string,
@@ -1092,6 +1104,7 @@ export type EQN_TouchBox = {
1092
1104
  rightSpace?: number;
1093
1105
  bottomSpace?: number;
1094
1106
  leftSpace?: number;
1107
+ name?: string;
1095
1108
  } | [
1096
1109
  TypeEquationPhrase,
1097
1110
  string,
@@ -1232,6 +1245,7 @@ export type EQN_Bar = {
1232
1245
  descent?: number;
1233
1246
  fullContentBounds?: boolean;
1234
1247
  useFullBounds?: boolean;
1248
+ name?: string;
1235
1249
  } | [
1236
1250
  TypeEquationPhrase,
1237
1251
  (string | null | undefined),
@@ -1403,6 +1417,7 @@ export type EQN_Integral = {
1403
1417
  toYAlign?: 'bottom' | 'top' | 'middle' | 'baseline' | number;
1404
1418
  fullBoundsContent?: boolean;
1405
1419
  useFullBounds?: boolean;
1420
+ name?: string;
1406
1421
  } | [
1407
1422
  (string | null | undefined),
1408
1423
  (TypeEquationPhrase | null | undefined),
@@ -1543,6 +1558,7 @@ export type EQN_SumOf = {
1543
1558
  toOffset?: TypeParsablePoint;
1544
1559
  fullBoundsContent?: boolean;
1545
1560
  useFullBounds?: boolean;
1561
+ name?: string;
1546
1562
  } | [
1547
1563
  (string | null | undefined),
1548
1564
  TypeEquationPhrase,
@@ -1675,6 +1691,7 @@ export type EQN_ProdOf = {
1675
1691
  toOffset?: TypeParsablePoint;
1676
1692
  fullBoundsContent?: boolean;
1677
1693
  useFullBounds?: boolean;
1694
+ name?: string;
1678
1695
  } | [
1679
1696
  (string | null | undefined),
1680
1697
  TypeEquationPhrase,
@@ -1764,6 +1781,7 @@ export type EQN_Subscript = {
1764
1781
  scale?: number;
1765
1782
  offset?: TypeParsablePoint;
1766
1783
  inSize: boolean;
1784
+ name?: string;
1767
1785
  } | [
1768
1786
  TypeEquationPhrase,
1769
1787
  TypeEquationPhrase,
@@ -1831,6 +1849,7 @@ export type EQN_Superscript = {
1831
1849
  scale?: number;
1832
1850
  offset?: TypeParsablePoint;
1833
1851
  inSize: boolean;
1852
+ name?: string;
1834
1853
  } | [
1835
1854
  TypeEquationPhrase,
1836
1855
  TypeEquationPhrase,
@@ -1900,6 +1919,7 @@ export type EQN_SuperscriptSubscript = {
1900
1919
  superscriptOffset?: TypeParsablePoint;
1901
1920
  subscriptOffset?: TypeParsablePoint;
1902
1921
  inSize?: boolean;
1922
+ name?: string;
1903
1923
  } | [
1904
1924
  TypeEquationPhrase,
1905
1925
  TypeEquationPhrase,
@@ -2012,6 +2032,7 @@ export type EQN_Comment = {
2012
2032
  inSize?: boolean;
2013
2033
  fullContentBounds?: boolean;
2014
2034
  useFullBounds?: boolean;
2035
+ name?: string;
2015
2036
  } | [
2016
2037
  TypeEquationPhrase,
2017
2038
  TypeEquationPhrase,
@@ -2108,6 +2129,7 @@ export type EQN_StrikeComment = {
2108
2129
  space?: number;
2109
2130
  scale?: number;
2110
2131
  commentSpace?: number;
2132
+ name?: string;
2111
2133
  } | [
2112
2134
  (TypeEquationPhrase | null | undefined),
2113
2135
  (string | null | undefined),
@@ -2184,6 +2206,7 @@ export type EQN_Pad = {
2184
2206
  right?: number;
2185
2207
  bottom?: number;
2186
2208
  left?: number;
2209
+ name?: string;
2187
2210
  } | [
2188
2211
  TypeEquationPhrase,
2189
2212
  (number | null | undefined),
@@ -2306,6 +2329,7 @@ export type EQN_Matrix = {
2306
2329
  yAlign?: 'baseline' | 'middle';
2307
2330
  brac?: EQN_Bracket;
2308
2331
  fullContentBounds?: boolean;
2332
+ name?: string;
2309
2333
  } | [
2310
2334
  ([number, number] | null | undefined),
2311
2335
  (string | null | undefined),
@@ -2460,6 +2484,7 @@ export type EQN_Lines = {
2460
2484
  space?: number;
2461
2485
  yAlign?: 'bottom' | 'top' | 'middle' | number;
2462
2486
  fullContentBounds?: boolean;
2487
+ name?: string;
2463
2488
  };
2464
2489
  /**
2465
2490
  * Annotation options object.
@@ -3214,6 +3239,7 @@ export type EQN_Annotate = {
3214
3239
  leftSpace?: number;
3215
3240
  rightSpace?: number;
3216
3241
  contentScale?: number;
3242
+ name?: string;
3217
3243
  };
3218
3244
  /**
3219
3245
  * Equation Functions.
@@ -3247,6 +3273,7 @@ export declare class EquationFunctions {
3247
3273
  parseContent(content: TypeEquationPhrase | null | undefined): any;
3248
3274
  contentToElement(content: TypeEquationPhrase | Elements | FigureElementPrimitive | FigureElementCollection): Elements;
3249
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;
3250
3277
  /**
3251
3278
  * Equation container function
3252
3279
  * @see {@link EQN_Container} for description and examples