figureone 1.1.5 → 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/index.js CHANGED
@@ -20406,7 +20406,7 @@ var Equation = /*#__PURE__*/function (_FigureElementCollect) {
20406
20406
  layout: optionsToUse.formDefaults.layout,
20407
20407
  ignoreColor: optionsToUse.formDefaults.ignoreColor
20408
20408
  },
20409
- functions: new _EquationFunctions__WEBPACK_IMPORTED_MODULE_9__.EquationFunctions(_this.elements, _this.addElementFromKey.bind(_this), _this.getExistingOrAddSymbol.bind(_this)),
20409
+ functions: new _EquationFunctions__WEBPACK_IMPORTED_MODULE_9__.EquationFunctions(_this.elements, _this.addElementFromKey.bind(_this), _this.getExistingOrAddSymbol.bind(_this), _this.makeInlineElement.bind(_this)),
20410
20410
  symbols: new _EquationSymbols__WEBPACK_IMPORTED_MODULE_8__["default"](_this.shapes, _this.color),
20411
20411
  font: optionsToUse.font,
20412
20412
  textFont: optionsToUse.textFont,
@@ -20944,6 +20944,29 @@ var Equation = /*#__PURE__*/function (_FigureElementCollect) {
20944
20944
  // this.add(key, element);
20945
20945
  // return element;
20946
20946
  // }
20947
+ }, {
20948
+ key: "makeInlineElement",
20949
+ value: function makeInlineElement(options) {
20950
+ var name = options.name || (0,_tools_tools__WEBPACK_IMPORTED_MODULE_1__.generateUniqueId)('eqn_');
20951
+ var existing = this.getElement(name);
20952
+ if (existing != null) {
20953
+ return existing;
20954
+ }
20955
+ var make = options.make;
20956
+ var method = this.shapes[make];
20957
+ if (typeof method !== 'function') {
20958
+ return null;
20959
+ }
20960
+ var element = method.call(this.shapes, options);
20961
+ if (element == null) {
20962
+ return null;
20963
+ }
20964
+ if (options.mods != null) {
20965
+ element.setProperties(options.mods);
20966
+ }
20967
+ this.add(name, element);
20968
+ return element;
20969
+ }
20947
20970
  }, {
20948
20971
  key: "makeSymbolElem",
20949
20972
  value: function makeSymbolElem(options) {
@@ -22769,6 +22792,9 @@ function getFigureElement(elementsObject, name) {
22769
22792
  * - `{ prodOf: `{@link EQN_ProdOf} `}`
22770
22793
  * - `{ topStrike: `{@link EQN_StrikeComment} `}`
22771
22794
  * - `{ bottomStrike: `{@link EQN_StrikeComment} `}`
22795
+ * - `{ make: string, name?: string, ... }` (inline element — creates any
22796
+ * element type directly in a form using the same `make` values as
22797
+ * {@link Figure.add}. If `name` is omitted, one is auto-generated.)
22772
22798
  * - `Array<TypeEquationPhrase>`
22773
22799
  *
22774
22800
  *
@@ -22796,6 +22822,18 @@ function getFigureElement(elementsObject, name) {
22796
22822
  * .goToForm({ target: 'form3', animate: 'move', delay: 1 })
22797
22823
  * .goToForm({ target: 'form4', animate: 'move', delay: 1 })
22798
22824
  * .start();
22825
+ *
22826
+ * @example
22827
+ * // Inline element creation in forms
22828
+ * figure.add({
22829
+ * make: 'equation',
22830
+ * forms: {
22831
+ * // Create a text element inline with a name
22832
+ * form1: ['a', { make: 'text', name: 'B', text: { text: 'B' } }, 'c'],
22833
+ * // Create any element type inline (e.g., polygon)
22834
+ * form2: ['a', { make: 'polygon', name: 'p', radius: 0.05, sides: 4 }],
22835
+ * },
22836
+ * });
22799
22837
  * @group Equations
22800
22838
  */
22801
22839
 
@@ -25328,7 +25366,7 @@ var EquationFunctions = /*#__PURE__*/function () {
25328
25366
  * @hideconstructor
25329
25367
  */
25330
25368
  // eslint-disable-next-line no-use-before-define
25331
- function EquationFunctions(elements, addElementFromKey, getExistingOrAddSymbol) {
25369
+ function EquationFunctions(elements, addElementFromKey, getExistingOrAddSymbol, makeElement) {
25332
25370
  _classCallCheck(this, EquationFunctions);
25333
25371
  this.elements = elements;
25334
25372
  this.phrases = {};
@@ -25336,6 +25374,7 @@ var EquationFunctions = /*#__PURE__*/function () {
25336
25374
  this.fullLineHeightPrimitive = null;
25337
25375
  this.addElementFromKey = addElementFromKey;
25338
25376
  this.getExistingOrAddSymbol = getExistingOrAddSymbol;
25377
+ this.makeElement = makeElement;
25339
25378
  this.phraseElements = {};
25340
25379
  }
25341
25380
 
@@ -25416,6 +25455,13 @@ var EquationFunctions = /*#__PURE__*/function () {
25416
25455
  return elementArray;
25417
25456
  }
25418
25457
  // Otherwise its an object
25458
+ // If it has a 'make' property, create the element inline
25459
+ if (content.make != null) {
25460
+ var _elem = this.makeElement(content);
25461
+ if (_elem != null) {
25462
+ return new _Elements_Element__WEBPACK_IMPORTED_MODULE_3__.Element(_elem);
25463
+ }
25464
+ }
25419
25465
  var _Object$entries$ = _slicedToArray(Object.entries(content)[0], 2),
25420
25466
  method = _Object$entries$[0],
25421
25467
  params = _Object$entries$[1];
@@ -34330,6 +34376,11 @@ var FIGURE1DEBUG = false;
34330
34376
  * @property {boolean} [antialias] enable WebGL anti-aliasing (`true`)
34331
34377
  * @property {number} [atlasScale] scale factor for GL text atlas texture
34332
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.
34333
34384
  * @interface
34334
34385
  * @group Figure
34335
34386
  */
@@ -34401,6 +34452,8 @@ var FIGURE1DEBUG = false;
34401
34452
  * - `beforeDraw`: published before a frame is drawn
34402
34453
  * - `afterDraw`: published after a frame is drawn
34403
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
34404
34457
  *
34405
34458
  * @class
34406
34459
  * @param {OBJ_Figure} options
@@ -34411,6 +34464,10 @@ var FIGURE1DEBUG = false;
34411
34464
  * @property {NotificationManager} notifications notification manager for
34412
34465
  * element
34413
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)
34414
34471
  *
34415
34472
  * @example
34416
34473
  * // Simple html and javascript example to create a figure, and add a
@@ -34454,46 +34511,6 @@ var FIGURE1DEBUG = false;
34454
34511
  * @group Figure
34455
34512
  */
34456
34513
  var Figure = /*#__PURE__*/function () {
34457
- // canvasHigh: HTMLCanvasElement;
34458
-
34459
- // textCanvasHigh: HTMLCanvasElement;
34460
-
34461
- // draw2DHigh: DrawContext2D;
34462
-
34463
- // webglHigh: WebGLInstance;
34464
-
34465
- // gestureElement: HTMLElement;
34466
-
34467
- // shapesHigh: Object;
34468
- // equation: Object;
34469
- // equationLow: Object;
34470
- // equationHigh: Object;
34471
-
34472
- // objectsHigh: FigureCollections;
34473
-
34474
- // used for drawing debug only
34475
-
34476
- // zoom: {
34477
- // last: {
34478
- // mag: number,
34479
- // position: Point,
34480
- // angle: number,
34481
- // distance: number,
34482
- // },
34483
- // current: {
34484
- // position: Point,
34485
- // angle: number,
34486
- // distance: number,
34487
- // },
34488
- // max: null | number,
34489
- // min: null | number,
34490
- // scale: number,
34491
- // mag: number,
34492
- // cumOffset: Point,
34493
- // cumAngle: number,
34494
- // pinching: boolean,
34495
- // }
34496
-
34497
34514
  function Figure() {
34498
34515
  var _this = this;
34499
34516
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
@@ -34615,6 +34632,9 @@ var Figure = /*#__PURE__*/function () {
34615
34632
  this.backgroundColor = optionsToUse.backgroundColor;
34616
34633
  var webglLow = new _webgl_webgl__WEBPACK_IMPORTED_MODULE_0__["default"](this.canvasLow, this.backgroundColor, optionsToUse.antialias, optionsToUse.atlasScale);
34617
34634
  this.webglLow = webglLow;
34635
+ if (!webglLow.webglAvailable && optionsToUse.onWebGLUnavailable) {
34636
+ optionsToUse.onWebGLUnavailable();
34637
+ }
34618
34638
  this._boundContextLost = this.contextLost.bind(this);
34619
34639
  this._boundContextRestored = this.contextRestored.bind(this);
34620
34640
  this.canvasLow.addEventListener('webglcontextlost', this._boundContextLost, false);
@@ -34847,6 +34867,59 @@ var Figure = /*#__PURE__*/function () {
34847
34867
  this.originalScalePoint = null;
34848
34868
  }
34849
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
+ }, {
34850
34923
  key: "fontsLoaded",
34851
34924
  value: function fontsLoaded() {
34852
34925
  this.elements.fontUpdated();
@@ -35500,6 +35573,7 @@ var Figure = /*#__PURE__*/function () {
35500
35573
  event.preventDefault();
35501
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>';
35502
35575
  this.lostContextMessage.style.display = 'table';
35576
+ this.webglLow.webglAvailable = false;
35503
35577
  this.elements.contextLost();
35504
35578
  this.webglLow.contextLost();
35505
35579
  this.notifications.publish('contextLost');
@@ -35512,6 +35586,7 @@ var Figure = /*#__PURE__*/function () {
35512
35586
  this.webglLow.init(this.webglLow.gl);
35513
35587
  this.webglLow.recreateAtlases();
35514
35588
  this.init(this.webglLow);
35589
+ this.webglLow.webglAvailable = true;
35515
35590
  this.lostContextMessage.style.display = 'none';
35516
35591
  this.notifications.publish('contextRestored');
35517
35592
  (0,_tools_tools__WEBPACK_IMPORTED_MODULE_7__.Console)('FigureOne context restored!');
@@ -65404,6 +65479,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
65404
65479
 
65405
65480
 
65406
65481
  var glMock = {
65482
+ // Constants
65407
65483
  TRIANGLES: 1,
65408
65484
  TRIANGLE_STRIP: 2,
65409
65485
  TRIANGLE_FAN: 3,
@@ -65414,8 +65490,10 @@ var glMock = {
65414
65490
  FRAGMENT_SHADER: 1,
65415
65491
  SRC_ALPHA: 1,
65416
65492
  ONE_MINUS_SRC_ALPHA: 1,
65493
+ ONE: 1,
65417
65494
  BLEND: 1,
65418
65495
  COLOR_BUFFER_BIT: 1,
65496
+ DEPTH_TEST: 1,
65419
65497
  TEXTURE_2D: 1,
65420
65498
  RGBA: 1,
65421
65499
  UNSIGNED_BYTE: 1,
@@ -65428,6 +65506,15 @@ var glMock = {
65428
65506
  STATIC_DRAW: 1,
65429
65507
  FLOAT: 1,
65430
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
65431
65518
  createBuffer: function createBuffer() {},
65432
65519
  bindBuffer: function bindBuffer() {},
65433
65520
  bufferData: function bufferData() {},
@@ -65442,7 +65529,9 @@ var glMock = {
65442
65529
  drawArrays: function drawArrays() {},
65443
65530
  clearColor: function clearColor() {},
65444
65531
  clear: function clear() {},
65445
- createTexture: function createTexture() {},
65532
+ createTexture: function createTexture() {
65533
+ return null;
65534
+ },
65446
65535
  activeTexture: function activeTexture() {},
65447
65536
  bindTexture: function bindTexture() {},
65448
65537
  pixelStorei: function pixelStorei() {},
@@ -65470,6 +65559,27 @@ var glMock = {
65470
65559
  deleteShader: function deleteShader() {},
65471
65560
  useProgram: function useProgram() {},
65472
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,
65473
65583
  canvas: {
65474
65584
  toDataURL: function toDataURL() {
65475
65585
  return '';
@@ -65594,10 +65704,11 @@ var WebGLInstance = /*#__PURE__*/function () {
65594
65704
  this.atlases = {};
65595
65705
  if (gl == null) {
65596
65706
  gl = glMock;
65707
+ this.webglAvailable = false;
65708
+ } else {
65709
+ this.webglAvailable = true;
65597
65710
  }
65598
- if (gl != null) {
65599
- this.init(gl);
65600
- }
65711
+ this.init(gl);
65601
65712
  }
65602
65713
  return _createClass(WebGLInstance, [{
65603
65714
  key: "addTexture",
@@ -80537,8 +80648,8 @@ var tools = {
80537
80648
  */
80538
80649
 
80539
80650
  var Fig = {
80540
- version: "1.1.5",
80541
- gitHash: "8c6ecd2ed",
80651
+ version: "1.2.0",
80652
+ gitHash: "b3f17c9ba",
80542
80653
  tools: tools,
80543
80654
  Figure: _js_figure_Figure__WEBPACK_IMPORTED_MODULE_5__["default"],
80544
80655
  Recorder: _js_figure_Recorder_Recorder__WEBPACK_IMPORTED_MODULE_7__.Recorder,
package/llms-full.txt CHANGED
@@ -2315,6 +2315,20 @@ Symbols can be created inline in forms without pre-declaring in elements:
2315
2315
  { frac: ['a', 'v1_vinculum', { frac: ['c', 'v2_vinculum', 'd'] }] }
2316
2316
  ```
2317
2317
 
2318
+ ### Inline Element Creation with `make`
2319
+ Any element type can be created inline in forms using `make` (same values as `figure.add`):
2320
+ ```js
2321
+ forms: {
2322
+ // Text element with custom styling
2323
+ 1: ['a', { make: 'text', name: 'B', text: { text: 'B' }, style: 'normal' }],
2324
+ // Any primitive (polygon, line, rectangle, etc.)
2325
+ 2: ['a', { make: 'polygon', name: 'p', radius: 0.05, sides: 4 }],
2326
+ // name is optional — auto-generated if omitted
2327
+ 3: ['a', { make: 'text', text: { text: 'X' } }],
2328
+ }
2329
+ ```
2330
+ Named elements are reused across forms if the same name appears again.
2331
+
2318
2332
  ### Coordinate Spaces
2319
2333
  - `'draw'` — Drawing canvas coordinates (element's own draw space)
2320
2334
  - `'local'` — Element's local space (after element's transform)
package/llms.txt CHANGED
@@ -223,6 +223,13 @@ Elements not defined in `elements` are auto-created from form strings. Use `_` p
223
223
 
224
224
  Duplicate elements: append `_N` to create copies — `'b_1'`, `'b_2'` display as `b`.
225
225
 
226
+ Any element type can be created inline in forms using `make`:
227
+ ```js
228
+ { make: 'text', name: 'B', text: { text: 'B' }, style: 'normal' }
229
+ { make: 'polygon', name: 'p', radius: 0.05, sides: 4 }
230
+ ```
231
+ `name` is optional (auto-generated if omitted). Named elements are reused if already created.
232
+
226
233
  ### Layout Functions
227
234
 
228
235
  | Function | Syntax | Description |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "figureone",
3
- "version": "1.1.5",
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",
@@ -883,6 +883,7 @@ export declare class Equation extends FigureElementCollection {
883
883
  getExistingOrAddSymbol(symbol: string | Record<string, any>): any;
884
884
  getExistingOrAddSymbolFromKey(key: string, options?: Record<string, any>): any;
885
885
  addElementFromKey(key: string, options?: Record<string, any>): any;
886
+ makeInlineElement(options: Record<string, any>): any;
886
887
  makeSymbolElem(options: any): import("./Symbols/Bracket").default | import("./Symbols/Box").default | import("./Symbols/Sum").default | import("./Symbols/Product").default | import("./Symbols/Integral").default | import("./Symbols/Vinculum").default | import("./Symbols/Strike").default | import("./Symbols/Radical").default | import("./Symbols/Division").default | import("./Symbols/Line").default | null;
887
888
  /**
888
889
  * Add elements to equation.
@@ -46,6 +46,9 @@ export declare function getFigureElement(elementsObject: {
46
46
  * - `{ prodOf: `{@link EQN_ProdOf} `}`
47
47
  * - `{ topStrike: `{@link EQN_StrikeComment} `}`
48
48
  * - `{ bottomStrike: `{@link EQN_StrikeComment} `}`
49
+ * - `{ make: string, name?: string, ... }` (inline element — creates any
50
+ * element type directly in a form using the same `make` values as
51
+ * {@link Figure.add}. If `name` is omitted, one is auto-generated.)
49
52
  * - `Array<TypeEquationPhrase>`
50
53
  *
51
54
  *
@@ -73,6 +76,18 @@ export declare function getFigureElement(elementsObject: {
73
76
  * .goToForm({ target: 'form3', animate: 'move', delay: 1 })
74
77
  * .goToForm({ target: 'form4', animate: 'move', delay: 1 })
75
78
  * .start();
79
+ *
80
+ * @example
81
+ * // Inline element creation in forms
82
+ * figure.add({
83
+ * make: 'equation',
84
+ * forms: {
85
+ * // Create a text element inline with a name
86
+ * form1: ['a', { make: 'text', name: 'B', text: { text: 'B' } }, 'c'],
87
+ * // Create any element type inline (e.g., polygon)
88
+ * form2: ['a', { make: 'polygon', name: 'p', radius: 0.05, sides: 4 }],
89
+ * },
90
+ * });
76
91
  * @group Equations
77
92
  */
78
93
  export type TypeEquationPhrase = string | number | {
@@ -127,6 +142,10 @@ export type TypeEquationPhrase = string | number | {
127
142
  topStrike: EQN_StrikeComment;
128
143
  } | {
129
144
  bottomStrike: EQN_StrikeComment;
145
+ } | {
146
+ make: string;
147
+ name?: string;
148
+ [key: string]: any;
130
149
  } | Array<TypeEquationPhrase> | FigureElementPrimitive | FigureElementCollection | Elements | Element | BaseAnnotationFunction;
131
150
  /**
132
151
  * Equation container options
@@ -3217,12 +3236,13 @@ export declare class EquationFunctions {
3217
3236
  fullLineHeightPrimitive: FigureElementPrimitive | null;
3218
3237
  addElementFromKey: (key: string, params: Record<string, any>) => FigureElementPrimitive | null | undefined;
3219
3238
  getExistingOrAddSymbol: (keyOrObj: string | Record<string, any>) => FigureElementPrimitive | null | undefined;
3239
+ makeElement: (options: Record<string, any>) => FigureElementPrimitive | FigureElementCollection | null;
3220
3240
  /**
3221
3241
  * @hideconstructor
3222
3242
  */
3223
3243
  constructor(elements: {
3224
3244
  [name: string]: FigureElementCollection | FigureElementPrimitive;
3225
- }, addElementFromKey: (key: string) => FigureElementPrimitive | null | undefined, getExistingOrAddSymbol: (keyOrObj: string | Record<string, any>) => FigureElementPrimitive | null | undefined);
3245
+ }, addElementFromKey: (key: string) => FigureElementPrimitive | null | undefined, getExistingOrAddSymbol: (keyOrObj: string | Record<string, any>) => FigureElementPrimitive | null | undefined, makeElement: (options: Record<string, any>) => FigureElementPrimitive | FigureElementCollection | null);
3226
3246
  stringToElement(content: string): any;
3227
3247
  parseContent(content: TypeEquationPhrase | null | undefined): any;
3228
3248
  contentToElement(content: TypeEquationPhrase | Elements | FigureElementPrimitive | FigureElementCollection): Elements;
@@ -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;