figureone 1.1.0 → 1.1.2

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
@@ -7065,7 +7065,9 @@ var DrawingObject = /*#__PURE__*/function () {
7065
7065
  /* eslint-disable class-methods-use-this */
7066
7066
  }, {
7067
7067
  key: "cleanup",
7068
- value: function cleanup() {}
7068
+ value: function cleanup() {
7069
+ var _deleteTexture = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
7070
+ }
7069
7071
 
7070
7072
  /* eslint-disable no-unused-vars, class-methods-use-this */
7071
7073
  }, {
@@ -7657,17 +7659,13 @@ var GLObject = /*#__PURE__*/function (_DrawingObject) {
7657
7659
  webgl = this.webgl,
7658
7660
  gl = this.gl;
7659
7661
  if (texture) {
7660
- if (deleteTexture && webgl.textures[texture.id].glTexture != null) {
7661
- gl.activeTexture(gl.TEXTURE0 + webgl.textures[texture.id].index);
7662
- gl.bindTexture(gl.TEXTURE_2D, null);
7663
- // gl.deleteTexture(webgl.textures[texture.id].glTexture);
7664
- webgl.textures[texture.id].glTexture = null;
7662
+ if (deleteTexture && webgl.textures[texture.id] != null) {
7663
+ webgl.deleteTexture(texture.id);
7665
7664
  }
7666
7665
  if (texture.buffer != null) {
7667
7666
  gl.deleteBuffer(texture.buffer);
7668
7667
  texture.buffer = null;
7669
7668
  }
7670
- // texture.glTexture = null;
7671
7669
  }
7672
7670
  }
7673
7671
  }, {
@@ -8296,6 +8294,13 @@ var HTMLObject = /*#__PURE__*/function (_DrawingObject) {
8296
8294
  this.element.setAttribute('style', "position: absolute; left: -10000px; top: -10000px; visibility: hidden; opacity: ".concat(opacity, ";"));
8297
8295
  }
8298
8296
  }
8297
+ }, {
8298
+ key: "cleanup",
8299
+ value: function cleanup() {
8300
+ if (this.element && this.element.parentNode) {
8301
+ this.element.parentNode.removeChild(this.element);
8302
+ }
8303
+ }
8299
8304
  }, {
8300
8305
  key: "drawWithTransformMatrix",
8301
8306
  value: function drawWithTransformMatrix(scene, worldMatrix, color) {
@@ -10517,6 +10522,9 @@ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstruct
10517
10522
  function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
10518
10523
  function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
10519
10524
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
10525
+ function _superPropGet(t, o, e, r) { var p = _get(_getPrototypeOf(1 & r ? t.prototype : t), o, e); return 2 & r && "function" == typeof p ? function (t) { return p.apply(e, t); } : p; }
10526
+ function _get() { return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get.bind() : function (e, t, r) { var p = _superPropBase(e, t); if (p) { var n = Object.getOwnPropertyDescriptor(p, t); return n.get ? n.get.call(arguments.length < 3 ? e : r) : n.value; } }, _get.apply(null, arguments); }
10527
+ function _superPropBase(t, o) { for (; !{}.hasOwnProperty.call(t, o) && null !== (t = _getPrototypeOf(t));); return t; }
10520
10528
  function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
10521
10529
  function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
10522
10530
  function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
@@ -10583,12 +10591,24 @@ var VertexText = /*#__PURE__*/function (_VertexGeneric) {
10583
10591
  _this.drawTextIntoBuffer();
10584
10592
  return _this;
10585
10593
  }
10586
-
10587
- // Text is positioned such that the text baseline will be at
10588
- // vertex space y = 0.
10589
- // The border will then cover the ascent and descent of the text.
10590
10594
  _inherits(VertexText, _VertexGeneric);
10591
10595
  return _createClass(VertexText, [{
10596
+ key: "cleanup",
10597
+ value: function cleanup() {
10598
+ var deleteTexture = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
10599
+ // Free the 2D canvas backing store before parent deletes GL buffers
10600
+ if (this.canvas) {
10601
+ this.canvas.width = 0;
10602
+ this.canvas.height = 0;
10603
+ }
10604
+ this.ctx = null;
10605
+ _superPropGet(VertexText, "cleanup", this, 3)([deleteTexture]);
10606
+ }
10607
+
10608
+ // Text is positioned such that the text baseline will be at
10609
+ // vertex space y = 0.
10610
+ // The border will then cover the ascent and descent of the text.
10611
+ }, {
10592
10612
  key: "resizeText",
10593
10613
  value: function resizeText() {
10594
10614
  var _this2 = this;
@@ -12280,6 +12300,7 @@ var FigureElement = /*#__PURE__*/function () {
12280
12300
  }, {
12281
12301
  key: "cleanup",
12282
12302
  value: function cleanup() {
12303
+ var deleteTexture = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
12283
12304
  this.stop();
12284
12305
  this.notifications.cleanup();
12285
12306
  this.animations.notifications.cleanup();
@@ -14426,8 +14447,9 @@ var FigureElementPrimitive = /*#__PURE__*/function (_FigureElement) {
14426
14447
  }, {
14427
14448
  key: "cleanup",
14428
14449
  value: function cleanup() {
14429
- _superPropGet(FigureElementPrimitive, "cleanup", this, 3)([]);
14430
- this.drawingObject.cleanup();
14450
+ var deleteTexture = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
14451
+ _superPropGet(FigureElementPrimitive, "cleanup", this, 3)([deleteTexture]);
14452
+ this.drawingObject.cleanup(deleteTexture);
14431
14453
  }
14432
14454
  }, {
14433
14455
  key: "_getStateProperties",
@@ -20982,6 +21004,7 @@ var Equation = /*#__PURE__*/function (_FigureElementCollect) {
20982
21004
  form.content = [this.eqn.functions.contentToElement(fullLineHeightPrimitive)];
20983
21005
  form.arrange(this.eqn.scale, 'left', 'baseline', new _tools_g2__WEBPACK_IMPORTED_MODULE_0__.Point(0, 0));
20984
21006
  this.eqn.functions.fullLineHeight = form;
21007
+ this.eqn.functions.fullLineHeightPrimitive = fullLineHeightPrimitive;
20985
21008
  this.setFirstTransform(this.transform);
20986
21009
  }
20987
21010
  }, {
@@ -21466,6 +21489,14 @@ var Equation = /*#__PURE__*/function (_FigureElementCollect) {
21466
21489
  _this0.eqn.forms[form].cleanup();
21467
21490
  delete _this0.eqn.forms[form];
21468
21491
  });
21492
+ if (this.eqn.functions.fullLineHeightPrimitive != null) {
21493
+ this.eqn.functions.fullLineHeightPrimitive.cleanup(false);
21494
+ this.eqn.functions.fullLineHeightPrimitive = null;
21495
+ }
21496
+ if (this.eqn.functions.fullLineHeight != null) {
21497
+ this.eqn.functions.fullLineHeight.cleanup();
21498
+ this.eqn.functions.fullLineHeight = null;
21499
+ }
21469
21500
  }
21470
21501
 
21471
21502
  /**
@@ -25262,6 +25293,7 @@ var EquationFunctions = /*#__PURE__*/function () {
25262
25293
  this.elements = elements;
25263
25294
  this.phrases = {};
25264
25295
  this.fullLineHeight = null;
25296
+ this.fullLineHeightPrimitive = null;
25265
25297
  this.addElementFromKey = addElementFromKey;
25266
25298
  this.getExistingOrAddSymbol = getExistingOrAddSymbol;
25267
25299
  this.phraseElements = {};
@@ -34751,6 +34783,7 @@ var Figure = /*#__PURE__*/function () {
34751
34783
  this._boundResize = this.resize.bind(this);
34752
34784
  this._boundFocusGained = this.focusGained.bind(this);
34753
34785
  this._boundFocusLost = this.focusLost.bind(this);
34786
+ this._boundScrollEvent = this.scrollEvent.bind(this);
34754
34787
  window.addEventListener('resize', this._boundResize);
34755
34788
  window.addEventListener('focus', this._boundFocusGained);
34756
34789
  window.addEventListener('blur', this._boundFocusLost);
@@ -34982,12 +35015,12 @@ var Figure = /*#__PURE__*/function () {
34982
35015
  }, {
34983
35016
  key: "enableScrolling",
34984
35017
  value: function enableScrolling() {
34985
- document.addEventListener('scroll', this.scrollEvent.bind(this), false);
35018
+ document.addEventListener('scroll', this._boundScrollEvent, false);
34986
35019
  }
34987
35020
  }, {
34988
35021
  key: "disableScrolling",
34989
35022
  value: function disableScrolling() {
34990
- document.removeEventListener('scroll', this.scrollEvent.bind(this), false);
35023
+ document.removeEventListener('scroll', this._boundScrollEvent, false);
34991
35024
  }
34992
35025
  }, {
34993
35026
  key: "init",
@@ -35457,10 +35490,11 @@ var Figure = /*#__PURE__*/function () {
35457
35490
  // Remove gesture listeners (canvas + window)
35458
35491
  this.gesture.destroy();
35459
35492
 
35460
- // Remove window listeners
35493
+ // Remove window/document listeners
35461
35494
  window.removeEventListener('resize', this._boundResize);
35462
35495
  window.removeEventListener('focus', this._boundFocusGained);
35463
35496
  window.removeEventListener('blur', this._boundFocusLost);
35497
+ this.disableScrolling();
35464
35498
 
35465
35499
  // Remove canvas listeners (only set when webgl !== 'manual')
35466
35500
  if (this.canvasLow && this._boundContextLost) {
@@ -35468,6 +35502,16 @@ var Figure = /*#__PURE__*/function () {
35468
35502
  this.canvasLow.removeEventListener('webglcontextrestored', this._boundContextRestored, false);
35469
35503
  }
35470
35504
 
35505
+ // Clear pending timers
35506
+ if (this.scrollTimeoutId) {
35507
+ clearTimeout(this.scrollTimeoutId);
35508
+ this.scrollTimeoutId = null;
35509
+ }
35510
+ this.clearDrawTimeout();
35511
+
35512
+ // Clean up recorder (audio listeners, worker, timeouts)
35513
+ this.recorder.cleanup();
35514
+
35471
35515
  // Clean up all elements recursively (notifications, drawing objects, children)
35472
35516
  this.elements.cleanup();
35473
35517
  this.elements = null;
@@ -51812,10 +51856,11 @@ var FigureElementPrimitiveGLText = /*#__PURE__*/function (_FigureElementPrimiti)
51812
51856
  }, {
51813
51857
  key: "cleanup",
51814
51858
  value: function cleanup() {
51815
- _superPropGet(FigureElementPrimitiveGLText, "cleanup", this, 3)([]);
51859
+ var deleteTexture = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
51816
51860
  if (this.atlas != null && this.atlasNotificationsID != null) {
51817
51861
  this.atlas.notifications.remove('updated', this.atlasNotificationsID);
51818
51862
  }
51863
+ _superPropGet(FigureElementPrimitiveGLText, "cleanup", this, 3)([deleteTexture]);
51819
51864
  }
51820
51865
  }, {
51821
51866
  key: "calcTouchBorder",
@@ -56749,6 +56794,46 @@ var Recorder = /*#__PURE__*/function () {
56749
56794
  this.queueSeekId = null;
56750
56795
  // this.useAutoEvents = false;
56751
56796
  this.timeUpdates = 100; // ms
56797
+ this._boundParseMessage = null;
56798
+ this._audioHandlers = null;
56799
+ }
56800
+ }, {
56801
+ key: "cleanupAudio",
56802
+ value: function cleanupAudio() {
56803
+ if (this.audio && this._audioHandlers) {
56804
+ this.audio.removeEventListener('pause', this._audioHandlers.pause);
56805
+ this.audio.removeEventListener('play', this._audioHandlers.play);
56806
+ this.audio.removeEventListener('playing', this._audioHandlers.playing, false);
56807
+ this.audio.removeEventListener('ended', this._audioHandlers.ended, false);
56808
+ this.audio.onloadedmetadata = null;
56809
+ this.audio.oncanplaythrough = null;
56810
+ }
56811
+ this._audioHandlers = null;
56812
+ }
56813
+ }, {
56814
+ key: "cleanup",
56815
+ value: function cleanup() {
56816
+ this.cleanupAudio();
56817
+ this.audio = null;
56818
+ if (this.worker && this._boundParseMessage) {
56819
+ this.worker.removeEventListener('message', this._boundParseMessage);
56820
+ this.worker.terminate();
56821
+ }
56822
+ this.worker = null;
56823
+ this._boundParseMessage = null;
56824
+ if (this.timeoutID != null) {
56825
+ this.timeKeeper.clearTimeout(this.timeoutID);
56826
+ this.timeoutID = null;
56827
+ }
56828
+ if (this.timeUpdatesTimeoutID != null) {
56829
+ this.timeKeeper.clearTimeout(this.timeUpdatesTimeoutID);
56830
+ this.timeUpdatesTimeoutID = null;
56831
+ }
56832
+ if (this.queueSeekId != null) {
56833
+ this.timeKeeper.clearTimeout(this.queueSeekId);
56834
+ this.queueSeekId = null;
56835
+ }
56836
+ this.notifications.cleanup();
56752
56837
  }
56753
56838
 
56754
56839
  // ////////////////////////////////////
@@ -56881,6 +56966,7 @@ var Recorder = /*#__PURE__*/function () {
56881
56966
  key: "loadAudioTrack",
56882
56967
  value: function loadAudioTrack(audio) {
56883
56968
  var _this3 = this;
56969
+ this.cleanupAudio();
56884
56970
  this.audio = audio;
56885
56971
  this.audio.onloadedmetadata = function () {
56886
56972
  _this3.duration = _this3.calcDuration();
@@ -56889,24 +56975,30 @@ var Recorder = /*#__PURE__*/function () {
56889
56975
  this.audio.oncanplaythrough = function () {
56890
56976
  _this3.notifications.publish('audioLoaded');
56891
56977
  };
56892
- this.audio.addEventListener('pause', function () {
56893
- if (_this3.state === 'playing') {
56894
- _this3.pausePlayback();
56895
- }
56896
- });
56897
- this.audio.addEventListener('play', function () {
56898
- // This is here to handle audio triggered start/stop (like headphones
56899
- // being removed or inserted)
56900
- if (_this3.state === 'idle' && _this3.audioStartedCallback == null) {
56901
- _this3.resumePlayback();
56978
+ this._audioHandlers = {
56979
+ pause: function pause() {
56980
+ if (_this3.state === 'playing') {
56981
+ _this3.pausePlayback();
56982
+ }
56983
+ },
56984
+ play: function play() {
56985
+ // This is here to handle audio triggered start/stop (like headphones
56986
+ // being removed or inserted)
56987
+ if (_this3.state === 'idle' && _this3.audioStartedCallback == null) {
56988
+ _this3.resumePlayback();
56989
+ }
56990
+ },
56991
+ playing: function playing() {
56992
+ return _this3.audioStarted();
56993
+ },
56994
+ ended: function ended() {
56995
+ return _this3.audioEnded();
56902
56996
  }
56903
- });
56904
- audio.addEventListener('playing', function () {
56905
- return _this3.audioStarted();
56906
- }, false);
56907
- audio.addEventListener('ended', function () {
56908
- return _this3.audioEnded();
56909
- }, false);
56997
+ };
56998
+ this.audio.addEventListener('pause', this._audioHandlers.pause);
56999
+ this.audio.addEventListener('play', this._audioHandlers.play);
57000
+ this.audio.addEventListener('playing', this._audioHandlers.playing, false);
57001
+ this.audio.addEventListener('ended', this._audioHandlers.ended, false);
56910
57002
  }
56911
57003
  }, {
56912
57004
  key: "loadEvents",
@@ -57148,7 +57240,8 @@ var Recorder = /*#__PURE__*/function () {
57148
57240
  value: function startWorker() {
57149
57241
  if (this.worker == null) {
57150
57242
  this.worker = new _recorder_worker__WEBPACK_IMPORTED_MODULE_3__["default"]();
57151
- this.worker.addEventListener('message', this.parseMessage.bind(this));
57243
+ this._boundParseMessage = this.parseMessage.bind(this);
57244
+ this.worker.addEventListener('message', this._boundParseMessage);
57152
57245
  }
57153
57246
  }
57154
57247
  }, {
@@ -80402,8 +80495,8 @@ var tools = {
80402
80495
  */
80403
80496
 
80404
80497
  var Fig = {
80405
- version: "1.1.0",
80406
- gitHash: "5b0735b51",
80498
+ version: "1.1.2",
80499
+ gitHash: "1444c13bc",
80407
80500
  tools: tools,
80408
80501
  Figure: _js_figure_Figure__WEBPACK_IMPORTED_MODULE_5__["default"],
80409
80502
  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.1.0",
3
+ "version": "1.1.2",
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",
@@ -36,7 +36,7 @@ declare class DrawingObject {
36
36
  updateBuffer(name: string, data: Array<number>): void;
37
37
  updateUniform(uniformName: string, value: number | Array<number>): void;
38
38
  getUniform(uniformName: string): void;
39
- cleanup(): void;
39
+ cleanup(_deleteTexture?: boolean): void;
40
40
  change(drawingPrimitive: any, copy?: Array<CPY_Step>): void;
41
41
  _getStateProperties(): never[];
42
42
  _state(options: Record<string, any>): Record<string, any>;
@@ -24,6 +24,7 @@ declare class HTMLObject extends DrawingObject {
24
24
  glToPixelSpace(p: Point): Point;
25
25
  change(newHtml: any, lastDrawTransformMatrix?: any): void;
26
26
  transformHtml(transformMatrix: Type3DMatrix, opacity?: number): void;
27
+ cleanup(): void;
27
28
  drawWithTransformMatrix(scene: Scene, worldMatrix: Type3DMatrix, color: TypeColor): void;
28
29
  }
29
30
  export default HTMLObject;
@@ -27,6 +27,7 @@ declare class VertexText extends VertexGeneric {
27
27
  height: number;
28
28
  width: number;
29
29
  constructor(webgl: WebGLInstance, textOptions: TypeVertexInputTextOptions);
30
+ cleanup(deleteTexture?: boolean): void;
30
31
  resizeText(pixelToVertexSpaceScale?: Point): void;
31
32
  calcAscentDescent(): void;
32
33
  drawTextIntoBuffer(pixelToVertexSpaceScale?: Point): void;
@@ -585,7 +585,7 @@ declare class FigureElement {
585
585
  transformSet(publish?: boolean, fromMovement?: boolean): void;
586
586
  nextMovingFreelyFrame(now: number): void;
587
587
  clear(_canvasIndex?: number): void;
588
- cleanup(): void;
588
+ cleanup(deleteTexture?: boolean): void;
589
589
  willStartAnimating(): boolean;
590
590
  /**
591
591
  Set element color.
@@ -859,7 +859,7 @@ declare class FigureElementPrimitive extends FigureElement {
859
859
  */
860
860
  constructor(drawingObject: DrawingObject, transform?: Transform, color?: TypeColor, parent?: FigureElement | null, name?: string, timeKeeper?: TimeKeeper);
861
861
  init(webgl: WebGLInstance): void;
862
- cleanup(): void;
862
+ cleanup(deleteTexture?: boolean): void;
863
863
  _getStateProperties(options: {
864
864
  ignoreShown?: boolean;
865
865
  }): string[];
@@ -3214,6 +3214,7 @@ export declare class EquationFunctions {
3214
3214
  [phraseName: string]: Array<FigureElementPrimitive>;
3215
3215
  };
3216
3216
  fullLineHeight: EquationForm | null;
3217
+ fullLineHeightPrimitive: FigureElementPrimitive | null;
3217
3218
  addElementFromKey: (key: string, params: Record<string, any>) => FigureElementPrimitive | null | undefined;
3218
3219
  getExistingOrAddSymbol: (keyOrObj: string | Record<string, any>) => FigureElementPrimitive | null | undefined;
3219
3220
  /**
@@ -276,6 +276,7 @@ declare class Figure {
276
276
  _boundFocusLost: EventListener;
277
277
  _boundContextLost: EventListener;
278
278
  _boundContextRestored: EventListener;
279
+ _boundScrollEvent: EventListener;
279
280
  constructor(options?: OBJ_Figure);
280
281
  fontsLoaded(): void;
281
282
  /**
@@ -85,7 +85,7 @@ export default class FigureElementPrimitiveGLText extends FigureElementPrimitive
85
85
  calcBorderAndBounds(): void;
86
86
  calcBorder(): void;
87
87
  stateSet(): void;
88
- cleanup(): void;
88
+ cleanup(deleteTexture?: boolean): void;
89
89
  calcTouchBorder(): void;
90
90
  _getStateProperties(options: {
91
91
  ignoreShown?: boolean;
@@ -135,10 +135,19 @@ declare class Recorder {
135
135
  play: TypePlaySettings;
136
136
  };
137
137
  worker: any;
138
+ _boundParseMessage: ((event: MessageEvent) => void) | null;
139
+ _audioHandlers: {
140
+ pause: () => void;
141
+ play: () => void;
142
+ playing: () => void;
143
+ ended: () => void;
144
+ } | null;
138
145
  timeKeeper: TimeKeeper;
139
146
  audioStartedCallback: (() => void) | null;
140
147
  constructor(timeKeeper: TimeKeeper);
141
148
  initialize(): void;
149
+ cleanupAudio(): void;
150
+ cleanup(): void;
142
151
  timeStamp(): number;
143
152
  now(): number;
144
153
  /**