figureone 1.1.6 → 1.2.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/figureone.min.js +1 -1
- package/index.js +111 -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!');
|
|
@@ -65450,6 +65479,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
65450
65479
|
|
|
65451
65480
|
|
|
65452
65481
|
var glMock = {
|
|
65482
|
+
// Constants
|
|
65453
65483
|
TRIANGLES: 1,
|
|
65454
65484
|
TRIANGLE_STRIP: 2,
|
|
65455
65485
|
TRIANGLE_FAN: 3,
|
|
@@ -65460,8 +65490,10 @@ var glMock = {
|
|
|
65460
65490
|
FRAGMENT_SHADER: 1,
|
|
65461
65491
|
SRC_ALPHA: 1,
|
|
65462
65492
|
ONE_MINUS_SRC_ALPHA: 1,
|
|
65493
|
+
ONE: 1,
|
|
65463
65494
|
BLEND: 1,
|
|
65464
65495
|
COLOR_BUFFER_BIT: 1,
|
|
65496
|
+
DEPTH_TEST: 1,
|
|
65465
65497
|
TEXTURE_2D: 1,
|
|
65466
65498
|
RGBA: 1,
|
|
65467
65499
|
UNSIGNED_BYTE: 1,
|
|
@@ -65474,6 +65506,15 @@ var glMock = {
|
|
|
65474
65506
|
STATIC_DRAW: 1,
|
|
65475
65507
|
FLOAT: 1,
|
|
65476
65508
|
UNPACK_PREMULTIPLY_ALPHA_WEBGL: 1,
|
|
65509
|
+
UNPACK_FLIP_Y_WEBGL: 1,
|
|
65510
|
+
REPEAT: 1,
|
|
65511
|
+
TEXTURE0: 1,
|
|
65512
|
+
RENDERBUFFER: 1,
|
|
65513
|
+
FRAMEBUFFER: 1,
|
|
65514
|
+
COLOR_ATTACHMENT0: 1,
|
|
65515
|
+
DEPTH_ATTACHMENT: 1,
|
|
65516
|
+
DEPTH_COMPONENT16: 1,
|
|
65517
|
+
// Methods
|
|
65477
65518
|
createBuffer: function createBuffer() {},
|
|
65478
65519
|
bindBuffer: function bindBuffer() {},
|
|
65479
65520
|
bufferData: function bufferData() {},
|
|
@@ -65488,7 +65529,9 @@ var glMock = {
|
|
|
65488
65529
|
drawArrays: function drawArrays() {},
|
|
65489
65530
|
clearColor: function clearColor() {},
|
|
65490
65531
|
clear: function clear() {},
|
|
65491
|
-
createTexture: function createTexture() {
|
|
65532
|
+
createTexture: function createTexture() {
|
|
65533
|
+
return null;
|
|
65534
|
+
},
|
|
65492
65535
|
activeTexture: function activeTexture() {},
|
|
65493
65536
|
bindTexture: function bindTexture() {},
|
|
65494
65537
|
pixelStorei: function pixelStorei() {},
|
|
@@ -65516,6 +65559,27 @@ var glMock = {
|
|
|
65516
65559
|
deleteShader: function deleteShader() {},
|
|
65517
65560
|
useProgram: function useProgram() {},
|
|
65518
65561
|
viewport: function viewport() {},
|
|
65562
|
+
generateMipmap: function generateMipmap() {},
|
|
65563
|
+
deleteTexture: function deleteTexture() {},
|
|
65564
|
+
getProgramInfoLog: function getProgramInfoLog() {
|
|
65565
|
+
return '';
|
|
65566
|
+
},
|
|
65567
|
+
// Framebuffer/renderbuffer methods (used by TargetTexture)
|
|
65568
|
+
createRenderbuffer: function createRenderbuffer() {
|
|
65569
|
+
return null;
|
|
65570
|
+
},
|
|
65571
|
+
bindRenderbuffer: function bindRenderbuffer() {},
|
|
65572
|
+
renderbufferStorage: function renderbufferStorage() {},
|
|
65573
|
+
createFramebuffer: function createFramebuffer() {
|
|
65574
|
+
return null;
|
|
65575
|
+
},
|
|
65576
|
+
bindFramebuffer: function bindFramebuffer() {},
|
|
65577
|
+
framebufferTexture2D: function framebufferTexture2D() {},
|
|
65578
|
+
framebufferRenderbuffer: function framebufferRenderbuffer() {},
|
|
65579
|
+
deleteRenderbuffer: function deleteRenderbuffer() {},
|
|
65580
|
+
deleteFramebuffer: function deleteFramebuffer() {},
|
|
65581
|
+
drawingBufferWidth: 100,
|
|
65582
|
+
drawingBufferHeight: 100,
|
|
65519
65583
|
canvas: {
|
|
65520
65584
|
toDataURL: function toDataURL() {
|
|
65521
65585
|
return '';
|
|
@@ -65640,10 +65704,11 @@ var WebGLInstance = /*#__PURE__*/function () {
|
|
|
65640
65704
|
this.atlases = {};
|
|
65641
65705
|
if (gl == null) {
|
|
65642
65706
|
gl = glMock;
|
|
65707
|
+
this.webglAvailable = false;
|
|
65708
|
+
} else {
|
|
65709
|
+
this.webglAvailable = true;
|
|
65643
65710
|
}
|
|
65644
|
-
|
|
65645
|
-
this.init(gl);
|
|
65646
|
-
}
|
|
65711
|
+
this.init(gl);
|
|
65647
65712
|
}
|
|
65648
65713
|
return _createClass(WebGLInstance, [{
|
|
65649
65714
|
key: "addTexture",
|
|
@@ -80583,8 +80648,8 @@ var tools = {
|
|
|
80583
80648
|
*/
|
|
80584
80649
|
|
|
80585
80650
|
var Fig = {
|
|
80586
|
-
version: "1.
|
|
80587
|
-
gitHash: "
|
|
80651
|
+
version: "1.2.0",
|
|
80652
|
+
gitHash: "b3f17c9ba",
|
|
80588
80653
|
tools: tools,
|
|
80589
80654
|
Figure: _js_figure_Figure__WEBPACK_IMPORTED_MODULE_5__["default"],
|
|
80590
80655
|
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
|
+
"version": "1.2.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",
|
|
@@ -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;
|