figureone 1.1.6 → 1.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.
- package/figureone.min.js +1 -1
- package/index.js +112 -46
- package/package.json +1 -1
- package/types/js/figure/Figure.d.ts +20 -0
- package/types/js/figure/webgl/webgl.d.ts +1 -0
package/index.js
CHANGED
|
@@ -34376,6 +34376,11 @@ var FIGURE1DEBUG = false;
|
|
|
34376
34376
|
* @property {boolean} [antialias] enable WebGL anti-aliasing (`true`)
|
|
34377
34377
|
* @property {number} [atlasScale] scale factor for GL text atlas texture
|
|
34378
34378
|
* resolution relative to 1:1 pixel mapping (`2`)
|
|
34379
|
+
* @property {() => void} [onWebGLUnavailable] callback fired once during
|
|
34380
|
+
* construction if the browser cannot provide a WebGL context (e.g. context
|
|
34381
|
+
* limit reached on resource-constrained hardware). The figure will still be
|
|
34382
|
+
* created but nothing will render. For runtime context loss, subscribe to
|
|
34383
|
+
* the `contextLost` / `contextRestored` notifications instead.
|
|
34379
34384
|
* @interface
|
|
34380
34385
|
* @group Figure
|
|
34381
34386
|
*/
|
|
@@ -34447,6 +34452,8 @@ var FIGURE1DEBUG = false;
|
|
|
34447
34452
|
* - `beforeDraw`: published before a frame is drawn
|
|
34448
34453
|
* - `afterDraw`: published after a frame is drawn
|
|
34449
34454
|
* - `resize`: published after a resize event, but before frame drawing
|
|
34455
|
+
* - `contextLost`: published when the browser removes the WebGL context
|
|
34456
|
+
* - `contextRestored`: published when the browser returns the WebGL context
|
|
34450
34457
|
*
|
|
34451
34458
|
* @class
|
|
34452
34459
|
* @param {OBJ_Figure} options
|
|
@@ -34457,6 +34464,10 @@ var FIGURE1DEBUG = false;
|
|
|
34457
34464
|
* @property {NotificationManager} notifications notification manager for
|
|
34458
34465
|
* element
|
|
34459
34466
|
* @property {FontManager} fonts watches and reports on font availability
|
|
34467
|
+
* @property {boolean} webglAvailable `true` when a live WebGL context is
|
|
34468
|
+
* attached to the figure. `false` if the browser could not provide a
|
|
34469
|
+
* context at construction time or if the context has since been lost (see
|
|
34470
|
+
* the `contextLost` / `contextRestored` notifications)
|
|
34460
34471
|
*
|
|
34461
34472
|
* @example
|
|
34462
34473
|
* // Simple html and javascript example to create a figure, and add a
|
|
@@ -34500,46 +34511,6 @@ var FIGURE1DEBUG = false;
|
|
|
34500
34511
|
* @group Figure
|
|
34501
34512
|
*/
|
|
34502
34513
|
var Figure = /*#__PURE__*/function () {
|
|
34503
|
-
// canvasHigh: HTMLCanvasElement;
|
|
34504
|
-
|
|
34505
|
-
// textCanvasHigh: HTMLCanvasElement;
|
|
34506
|
-
|
|
34507
|
-
// draw2DHigh: DrawContext2D;
|
|
34508
|
-
|
|
34509
|
-
// webglHigh: WebGLInstance;
|
|
34510
|
-
|
|
34511
|
-
// gestureElement: HTMLElement;
|
|
34512
|
-
|
|
34513
|
-
// shapesHigh: Object;
|
|
34514
|
-
// equation: Object;
|
|
34515
|
-
// equationLow: Object;
|
|
34516
|
-
// equationHigh: Object;
|
|
34517
|
-
|
|
34518
|
-
// objectsHigh: FigureCollections;
|
|
34519
|
-
|
|
34520
|
-
// used for drawing debug only
|
|
34521
|
-
|
|
34522
|
-
// zoom: {
|
|
34523
|
-
// last: {
|
|
34524
|
-
// mag: number,
|
|
34525
|
-
// position: Point,
|
|
34526
|
-
// angle: number,
|
|
34527
|
-
// distance: number,
|
|
34528
|
-
// },
|
|
34529
|
-
// current: {
|
|
34530
|
-
// position: Point,
|
|
34531
|
-
// angle: number,
|
|
34532
|
-
// distance: number,
|
|
34533
|
-
// },
|
|
34534
|
-
// max: null | number,
|
|
34535
|
-
// min: null | number,
|
|
34536
|
-
// scale: number,
|
|
34537
|
-
// mag: number,
|
|
34538
|
-
// cumOffset: Point,
|
|
34539
|
-
// cumAngle: number,
|
|
34540
|
-
// pinching: boolean,
|
|
34541
|
-
// }
|
|
34542
|
-
|
|
34543
34514
|
function Figure() {
|
|
34544
34515
|
var _this = this;
|
|
34545
34516
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
@@ -34661,6 +34632,9 @@ var Figure = /*#__PURE__*/function () {
|
|
|
34661
34632
|
this.backgroundColor = optionsToUse.backgroundColor;
|
|
34662
34633
|
var webglLow = new _webgl_webgl__WEBPACK_IMPORTED_MODULE_0__["default"](this.canvasLow, this.backgroundColor, optionsToUse.antialias, optionsToUse.atlasScale);
|
|
34663
34634
|
this.webglLow = webglLow;
|
|
34635
|
+
if (!webglLow.webglAvailable && optionsToUse.onWebGLUnavailable) {
|
|
34636
|
+
optionsToUse.onWebGLUnavailable();
|
|
34637
|
+
}
|
|
34664
34638
|
this._boundContextLost = this.contextLost.bind(this);
|
|
34665
34639
|
this._boundContextRestored = this.contextRestored.bind(this);
|
|
34666
34640
|
this.canvasLow.addEventListener('webglcontextlost', this._boundContextLost, false);
|
|
@@ -34893,6 +34867,59 @@ var Figure = /*#__PURE__*/function () {
|
|
|
34893
34867
|
this.originalScalePoint = null;
|
|
34894
34868
|
}
|
|
34895
34869
|
return _createClass(Figure, [{
|
|
34870
|
+
key: "webglAvailable",
|
|
34871
|
+
get:
|
|
34872
|
+
// canvasHigh: HTMLCanvasElement;
|
|
34873
|
+
|
|
34874
|
+
// textCanvasHigh: HTMLCanvasElement;
|
|
34875
|
+
|
|
34876
|
+
// draw2DHigh: DrawContext2D;
|
|
34877
|
+
|
|
34878
|
+
// webglHigh: WebGLInstance;
|
|
34879
|
+
|
|
34880
|
+
// gestureElement: HTMLElement;
|
|
34881
|
+
|
|
34882
|
+
// shapesHigh: Object;
|
|
34883
|
+
// equation: Object;
|
|
34884
|
+
// equationLow: Object;
|
|
34885
|
+
// equationHigh: Object;
|
|
34886
|
+
|
|
34887
|
+
// objectsHigh: FigureCollections;
|
|
34888
|
+
|
|
34889
|
+
// used for drawing debug only
|
|
34890
|
+
|
|
34891
|
+
// zoom: {
|
|
34892
|
+
// last: {
|
|
34893
|
+
// mag: number,
|
|
34894
|
+
// position: Point,
|
|
34895
|
+
// angle: number,
|
|
34896
|
+
// distance: number,
|
|
34897
|
+
// },
|
|
34898
|
+
// current: {
|
|
34899
|
+
// position: Point,
|
|
34900
|
+
// angle: number,
|
|
34901
|
+
// distance: number,
|
|
34902
|
+
// },
|
|
34903
|
+
// max: null | number,
|
|
34904
|
+
// min: null | number,
|
|
34905
|
+
// scale: number,
|
|
34906
|
+
// mag: number,
|
|
34907
|
+
// cumOffset: Point,
|
|
34908
|
+
// cumAngle: number,
|
|
34909
|
+
// pinching: boolean,
|
|
34910
|
+
// }
|
|
34911
|
+
|
|
34912
|
+
/**
|
|
34913
|
+
* `true` when a live WebGL context is attached to the figure. `false` if
|
|
34914
|
+
* the browser could not provide a context at construction time, or if the
|
|
34915
|
+
* context has since been lost. Transitions back to `true` when the
|
|
34916
|
+
* context is restored. Subscribe to the `contextLost` and
|
|
34917
|
+
* `contextRestored` notifications to react to runtime transitions.
|
|
34918
|
+
*/
|
|
34919
|
+
function get() {
|
|
34920
|
+
return this.webglLow.webglAvailable;
|
|
34921
|
+
}
|
|
34922
|
+
}, {
|
|
34896
34923
|
key: "fontsLoaded",
|
|
34897
34924
|
value: function fontsLoaded() {
|
|
34898
34925
|
this.elements.fontUpdated();
|
|
@@ -35546,6 +35573,7 @@ var Figure = /*#__PURE__*/function () {
|
|
|
35546
35573
|
event.preventDefault();
|
|
35547
35574
|
this.lostContextMessage.innerHTML = '<div class="figureone__lostcontext_message"><p>Browser removed WebGL context from FigureOne and has yet to return it.</p> <p>Reload page to restore.</p></div>';
|
|
35548
35575
|
this.lostContextMessage.style.display = 'table';
|
|
35576
|
+
this.webglLow.webglAvailable = false;
|
|
35549
35577
|
this.elements.contextLost();
|
|
35550
35578
|
this.webglLow.contextLost();
|
|
35551
35579
|
this.notifications.publish('contextLost');
|
|
@@ -35558,6 +35586,7 @@ var Figure = /*#__PURE__*/function () {
|
|
|
35558
35586
|
this.webglLow.init(this.webglLow.gl);
|
|
35559
35587
|
this.webglLow.recreateAtlases();
|
|
35560
35588
|
this.init(this.webglLow);
|
|
35589
|
+
this.webglLow.webglAvailable = true;
|
|
35561
35590
|
this.lostContextMessage.style.display = 'none';
|
|
35562
35591
|
this.notifications.publish('contextRestored');
|
|
35563
35592
|
(0,_tools_tools__WEBPACK_IMPORTED_MODULE_7__.Console)('FigureOne context restored!');
|
|
@@ -64738,6 +64767,7 @@ var Atlas = /*#__PURE__*/function () {
|
|
|
64738
64767
|
if (Math.pow(dimension, 2) > 16777216 && isIOS()) {
|
|
64739
64768
|
var mDim = Math.sqrt(16777216);
|
|
64740
64769
|
fontSizePX *= mDim / dimension * 0.95;
|
|
64770
|
+
this.fontSize = fontSizePX;
|
|
64741
64771
|
dimension = Math.floor(Math.ceil(Math.sqrt(glyphs.length) + 2) * fontSizePX * 1.5);
|
|
64742
64772
|
}
|
|
64743
64773
|
var canvas = document.createElement('canvas');
|
|
@@ -65450,6 +65480,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
65450
65480
|
|
|
65451
65481
|
|
|
65452
65482
|
var glMock = {
|
|
65483
|
+
// Constants
|
|
65453
65484
|
TRIANGLES: 1,
|
|
65454
65485
|
TRIANGLE_STRIP: 2,
|
|
65455
65486
|
TRIANGLE_FAN: 3,
|
|
@@ -65460,8 +65491,10 @@ var glMock = {
|
|
|
65460
65491
|
FRAGMENT_SHADER: 1,
|
|
65461
65492
|
SRC_ALPHA: 1,
|
|
65462
65493
|
ONE_MINUS_SRC_ALPHA: 1,
|
|
65494
|
+
ONE: 1,
|
|
65463
65495
|
BLEND: 1,
|
|
65464
65496
|
COLOR_BUFFER_BIT: 1,
|
|
65497
|
+
DEPTH_TEST: 1,
|
|
65465
65498
|
TEXTURE_2D: 1,
|
|
65466
65499
|
RGBA: 1,
|
|
65467
65500
|
UNSIGNED_BYTE: 1,
|
|
@@ -65474,6 +65507,15 @@ var glMock = {
|
|
|
65474
65507
|
STATIC_DRAW: 1,
|
|
65475
65508
|
FLOAT: 1,
|
|
65476
65509
|
UNPACK_PREMULTIPLY_ALPHA_WEBGL: 1,
|
|
65510
|
+
UNPACK_FLIP_Y_WEBGL: 1,
|
|
65511
|
+
REPEAT: 1,
|
|
65512
|
+
TEXTURE0: 1,
|
|
65513
|
+
RENDERBUFFER: 1,
|
|
65514
|
+
FRAMEBUFFER: 1,
|
|
65515
|
+
COLOR_ATTACHMENT0: 1,
|
|
65516
|
+
DEPTH_ATTACHMENT: 1,
|
|
65517
|
+
DEPTH_COMPONENT16: 1,
|
|
65518
|
+
// Methods
|
|
65477
65519
|
createBuffer: function createBuffer() {},
|
|
65478
65520
|
bindBuffer: function bindBuffer() {},
|
|
65479
65521
|
bufferData: function bufferData() {},
|
|
@@ -65488,7 +65530,9 @@ var glMock = {
|
|
|
65488
65530
|
drawArrays: function drawArrays() {},
|
|
65489
65531
|
clearColor: function clearColor() {},
|
|
65490
65532
|
clear: function clear() {},
|
|
65491
|
-
createTexture: function createTexture() {
|
|
65533
|
+
createTexture: function createTexture() {
|
|
65534
|
+
return null;
|
|
65535
|
+
},
|
|
65492
65536
|
activeTexture: function activeTexture() {},
|
|
65493
65537
|
bindTexture: function bindTexture() {},
|
|
65494
65538
|
pixelStorei: function pixelStorei() {},
|
|
@@ -65516,6 +65560,27 @@ var glMock = {
|
|
|
65516
65560
|
deleteShader: function deleteShader() {},
|
|
65517
65561
|
useProgram: function useProgram() {},
|
|
65518
65562
|
viewport: function viewport() {},
|
|
65563
|
+
generateMipmap: function generateMipmap() {},
|
|
65564
|
+
deleteTexture: function deleteTexture() {},
|
|
65565
|
+
getProgramInfoLog: function getProgramInfoLog() {
|
|
65566
|
+
return '';
|
|
65567
|
+
},
|
|
65568
|
+
// Framebuffer/renderbuffer methods (used by TargetTexture)
|
|
65569
|
+
createRenderbuffer: function createRenderbuffer() {
|
|
65570
|
+
return null;
|
|
65571
|
+
},
|
|
65572
|
+
bindRenderbuffer: function bindRenderbuffer() {},
|
|
65573
|
+
renderbufferStorage: function renderbufferStorage() {},
|
|
65574
|
+
createFramebuffer: function createFramebuffer() {
|
|
65575
|
+
return null;
|
|
65576
|
+
},
|
|
65577
|
+
bindFramebuffer: function bindFramebuffer() {},
|
|
65578
|
+
framebufferTexture2D: function framebufferTexture2D() {},
|
|
65579
|
+
framebufferRenderbuffer: function framebufferRenderbuffer() {},
|
|
65580
|
+
deleteRenderbuffer: function deleteRenderbuffer() {},
|
|
65581
|
+
deleteFramebuffer: function deleteFramebuffer() {},
|
|
65582
|
+
drawingBufferWidth: 100,
|
|
65583
|
+
drawingBufferHeight: 100,
|
|
65519
65584
|
canvas: {
|
|
65520
65585
|
toDataURL: function toDataURL() {
|
|
65521
65586
|
return '';
|
|
@@ -65640,10 +65705,11 @@ var WebGLInstance = /*#__PURE__*/function () {
|
|
|
65640
65705
|
this.atlases = {};
|
|
65641
65706
|
if (gl == null) {
|
|
65642
65707
|
gl = glMock;
|
|
65708
|
+
this.webglAvailable = false;
|
|
65709
|
+
} else {
|
|
65710
|
+
this.webglAvailable = true;
|
|
65643
65711
|
}
|
|
65644
|
-
|
|
65645
|
-
this.init(gl);
|
|
65646
|
-
}
|
|
65712
|
+
this.init(gl);
|
|
65647
65713
|
}
|
|
65648
65714
|
return _createClass(WebGLInstance, [{
|
|
65649
65715
|
key: "addTexture",
|
|
@@ -80583,8 +80649,8 @@ var tools = {
|
|
|
80583
80649
|
*/
|
|
80584
80650
|
|
|
80585
80651
|
var Fig = {
|
|
80586
|
-
version: "1.1
|
|
80587
|
-
gitHash: "
|
|
80652
|
+
version: "1.2.1",
|
|
80653
|
+
gitHash: "40843fa58",
|
|
80588
80654
|
tools: tools,
|
|
80589
80655
|
Figure: _js_figure_Figure__WEBPACK_IMPORTED_MODULE_5__["default"],
|
|
80590
80656
|
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
|
|
3
|
+
"version": "1.2.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",
|
|
@@ -86,6 +86,11 @@ export type OBJ_FigureForElement = {
|
|
|
86
86
|
* @property {boolean} [antialias] enable WebGL anti-aliasing (`true`)
|
|
87
87
|
* @property {number} [atlasScale] scale factor for GL text atlas texture
|
|
88
88
|
* resolution relative to 1:1 pixel mapping (`2`)
|
|
89
|
+
* @property {() => void} [onWebGLUnavailable] callback fired once during
|
|
90
|
+
* construction if the browser cannot provide a WebGL context (e.g. context
|
|
91
|
+
* limit reached on resource-constrained hardware). The figure will still be
|
|
92
|
+
* created but nothing will render. For runtime context loss, subscribe to
|
|
93
|
+
* the `contextLost` / `contextRestored` notifications instead.
|
|
89
94
|
* @interface
|
|
90
95
|
* @group Figure
|
|
91
96
|
*/
|
|
@@ -100,6 +105,7 @@ export type OBJ_Figure = {
|
|
|
100
105
|
backgroundColor?: number;
|
|
101
106
|
antialias?: boolean;
|
|
102
107
|
atlasScale?: number;
|
|
108
|
+
onWebGLUnavailable?: () => void;
|
|
103
109
|
};
|
|
104
110
|
/**
|
|
105
111
|
* Primary Figure class.
|
|
@@ -129,6 +135,8 @@ export type OBJ_Figure = {
|
|
|
129
135
|
* - `beforeDraw`: published before a frame is drawn
|
|
130
136
|
* - `afterDraw`: published after a frame is drawn
|
|
131
137
|
* - `resize`: published after a resize event, but before frame drawing
|
|
138
|
+
* - `contextLost`: published when the browser removes the WebGL context
|
|
139
|
+
* - `contextRestored`: published when the browser returns the WebGL context
|
|
132
140
|
*
|
|
133
141
|
* @class
|
|
134
142
|
* @param {OBJ_Figure} options
|
|
@@ -139,6 +147,10 @@ export type OBJ_Figure = {
|
|
|
139
147
|
* @property {NotificationManager} notifications notification manager for
|
|
140
148
|
* element
|
|
141
149
|
* @property {FontManager} fonts watches and reports on font availability
|
|
150
|
+
* @property {boolean} webglAvailable `true` when a live WebGL context is
|
|
151
|
+
* attached to the figure. `false` if the browser could not provide a
|
|
152
|
+
* context at construction time or if the context has since been lost (see
|
|
153
|
+
* the `contextLost` / `contextRestored` notifications)
|
|
142
154
|
*
|
|
143
155
|
* @example
|
|
144
156
|
* // Simple html and javascript example to create a figure, and add a
|
|
@@ -266,6 +278,14 @@ declare class Figure {
|
|
|
266
278
|
lostContextMessage: HTMLElement;
|
|
267
279
|
scene: Scene;
|
|
268
280
|
fonts: FontManager;
|
|
281
|
+
/**
|
|
282
|
+
* `true` when a live WebGL context is attached to the figure. `false` if
|
|
283
|
+
* the browser could not provide a context at construction time, or if the
|
|
284
|
+
* context has since been lost. Transitions back to `true` when the
|
|
285
|
+
* context is restored. Subscribe to the `contextLost` and
|
|
286
|
+
* `contextRestored` notifications to react to runtime transitions.
|
|
287
|
+
*/
|
|
288
|
+
get webglAvailable(): boolean;
|
|
269
289
|
animations: AnimationManager;
|
|
270
290
|
state: {
|
|
271
291
|
pause: 'paused' | 'preparingToPause' | 'preparingToUnpause' | 'unpaused';
|
|
@@ -49,6 +49,7 @@ declare class WebGLInstance {
|
|
|
49
49
|
getProgram(vertexShader: TypeVertexShader, fragmentShader: TypeFragmentShader): number;
|
|
50
50
|
useProgram(programIndex: number): Record<string, any> | null;
|
|
51
51
|
atlasScale: number;
|
|
52
|
+
webglAvailable: boolean;
|
|
52
53
|
constructor(canvas: HTMLCanvasElement, backgroundColor: Array<number>, antialias?: boolean, atlasScale?: number);
|
|
53
54
|
init(gl: WebGLRenderingContext): void;
|
|
54
55
|
resize(): void;
|