figureone 1.0.4 → 1.0.6
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 +59 -16
- package/package.json +1 -1
- package/types/js/figure/webgl/Atlas.d.ts +0 -1
- package/types/js/tools/errors.d.ts +8 -0
package/index.js
CHANGED
|
@@ -63149,6 +63149,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
63149
63149
|
/* harmony import */ var _FontManager__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../FontManager */ "./src/js/figure/FontManager.ts");
|
|
63150
63150
|
/* harmony import */ var _DrawingObjects_TextObject_TextObject__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../DrawingObjects/TextObject/TextObject */ "./src/js/figure/DrawingObjects/TextObject/TextObject.ts");
|
|
63151
63151
|
/* harmony import */ var _tools_tools__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../tools/tools */ "./src/js/tools/tools.ts");
|
|
63152
|
+
/* harmony import */ var _tools_errors__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../tools/errors */ "./src/js/tools/errors.ts");
|
|
63152
63153
|
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); }
|
|
63153
63154
|
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
63154
63155
|
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."); }
|
|
@@ -63164,6 +63165,8 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
63164
63165
|
|
|
63165
63166
|
|
|
63166
63167
|
|
|
63168
|
+
|
|
63169
|
+
|
|
63167
63170
|
/* eslint-disable max-len */
|
|
63168
63171
|
/*
|
|
63169
63172
|
GLText asks for atlas from webgl
|
|
@@ -63274,15 +63277,14 @@ var Atlas = /*#__PURE__*/function () {
|
|
|
63274
63277
|
|
|
63275
63278
|
// Otherwise generate the atlas automatically
|
|
63276
63279
|
if (options.font == null) {
|
|
63277
|
-
throw
|
|
63280
|
+
throw (0,_tools_errors__WEBPACK_IMPORTED_MODULE_3__.figureOneError)(1000);
|
|
63278
63281
|
}
|
|
63279
63282
|
if (options.scene == null) {
|
|
63280
|
-
throw
|
|
63283
|
+
throw (0,_tools_errors__WEBPACK_IMPORTED_MODULE_3__.figureOneError)(1001);
|
|
63281
63284
|
}
|
|
63282
63285
|
this.scene = o.scene;
|
|
63283
63286
|
this.font = new _DrawingObjects_TextObject_TextObject__WEBPACK_IMPORTED_MODULE_1__.FigureFont(o.font);
|
|
63284
63287
|
this.fontManager = new _FontManager__WEBPACK_IMPORTED_MODULE_0__["default"]();
|
|
63285
|
-
this.canvas = document.createElement('canvas');
|
|
63286
63288
|
var _this$fontManager$wat = this.fontManager.watch(this.font, {
|
|
63287
63289
|
timeout: o.timeout,
|
|
63288
63290
|
maxCount: o.maxCount,
|
|
@@ -63353,10 +63355,21 @@ var Atlas = /*#__PURE__*/function () {
|
|
|
63353
63355
|
fontSizePX *= mDim / dimension * 0.95;
|
|
63354
63356
|
dimension = Math.floor(Math.ceil(Math.sqrt(glyphs.length) + 2) * fontSizePX * 1.5);
|
|
63355
63357
|
}
|
|
63356
|
-
var canvas
|
|
63357
|
-
|
|
63358
|
-
|
|
63359
|
-
|
|
63358
|
+
var canvas;
|
|
63359
|
+
var ctx = null;
|
|
63360
|
+
for (var attempt = 0; attempt < 4; attempt += 1) {
|
|
63361
|
+
canvas = document.createElement('canvas');
|
|
63362
|
+
canvas.width = dimension;
|
|
63363
|
+
canvas.height = dimension;
|
|
63364
|
+
ctx = canvas.getContext('2d');
|
|
63365
|
+
if (ctx != null) break;
|
|
63366
|
+
fontSizePX *= 0.5;
|
|
63367
|
+
this.fontSize = fontSizePX;
|
|
63368
|
+
dimension = Math.floor(Math.ceil(Math.sqrt(glyphs.length) + 2) * fontSizePX * 1.5);
|
|
63369
|
+
}
|
|
63370
|
+
if (ctx == null) {
|
|
63371
|
+
throw (0,_tools_errors__WEBPACK_IMPORTED_MODULE_3__.figureOneError)(1002, "dimension: ".concat(dimension));
|
|
63372
|
+
}
|
|
63360
63373
|
ctx.font = "".concat(font.style, " ").concat(font.weight, " ").concat(fontSizePX, "px ").concat(font.family);
|
|
63361
63374
|
var x = fontSizePX;
|
|
63362
63375
|
var y = fontSizePX;
|
|
@@ -63426,7 +63439,6 @@ var Atlas = /*#__PURE__*/function () {
|
|
|
63426
63439
|
// const image = canvas.toDataURL("image/png").replace("image/png", "image/octet-stream");
|
|
63427
63440
|
// window.location.href=image;
|
|
63428
63441
|
this.webgl.addTexture(this.font.getTextureID(), ctx.canvas, [0, 0, 0, 0], false, null, true);
|
|
63429
|
-
// canvas.remove();
|
|
63430
63442
|
}
|
|
63431
63443
|
}]);
|
|
63432
63444
|
}();
|
|
@@ -64269,8 +64281,7 @@ var WebGLInstance = /*#__PURE__*/function () {
|
|
|
64269
64281
|
id: id,
|
|
64270
64282
|
state: 'loading',
|
|
64271
64283
|
onLoad: [],
|
|
64272
|
-
index: index
|
|
64273
|
-
data: null
|
|
64284
|
+
index: index
|
|
64274
64285
|
};
|
|
64275
64286
|
var texture = this.textures[id];
|
|
64276
64287
|
if (onLoad != null) {
|
|
@@ -64284,14 +64295,12 @@ var WebGLInstance = /*#__PURE__*/function () {
|
|
|
64284
64295
|
image.src = data;
|
|
64285
64296
|
// When the image is loaded, set the texture to it
|
|
64286
64297
|
image.addEventListener('load', function () {
|
|
64287
|
-
texture.data = image;
|
|
64288
64298
|
_this.setTextureData(id, image, repeat);
|
|
64289
64299
|
_this.onLoad(id);
|
|
64290
64300
|
texture.state = 'loaded';
|
|
64291
64301
|
});
|
|
64292
64302
|
} else {
|
|
64293
|
-
|
|
64294
|
-
// Otherwise, the data is an image so set it directly
|
|
64303
|
+
// Otherwise, the data is an image/canvas so set it directly
|
|
64295
64304
|
this.setTextureData(id, data, repeat);
|
|
64296
64305
|
this.onLoad(id);
|
|
64297
64306
|
texture.state = 'loaded';
|
|
@@ -64320,9 +64329,17 @@ var WebGLInstance = /*#__PURE__*/function () {
|
|
|
64320
64329
|
key: "recreateAtlases",
|
|
64321
64330
|
value: function recreateAtlases() {
|
|
64322
64331
|
var _this2 = this;
|
|
64332
|
+
var errors = [];
|
|
64323
64333
|
Object.keys(this.atlases).forEach(function (textureID) {
|
|
64324
|
-
|
|
64334
|
+
try {
|
|
64335
|
+
_this2.atlases[textureID].recreate();
|
|
64336
|
+
} catch (e) {
|
|
64337
|
+
errors.push(e instanceof Error ? e : new Error(String(e)));
|
|
64338
|
+
}
|
|
64325
64339
|
});
|
|
64340
|
+
if (errors.length > 0) {
|
|
64341
|
+
throw errors[0];
|
|
64342
|
+
}
|
|
64326
64343
|
}
|
|
64327
64344
|
}, {
|
|
64328
64345
|
key: "deleteTexture",
|
|
@@ -66791,6 +66808,32 @@ function surface(options) {
|
|
|
66791
66808
|
}
|
|
66792
66809
|
|
|
66793
66810
|
|
|
66811
|
+
/***/ },
|
|
66812
|
+
|
|
66813
|
+
/***/ "./src/js/tools/errors.ts"
|
|
66814
|
+
/*!********************************!*\
|
|
66815
|
+
!*** ./src/js/tools/errors.ts ***!
|
|
66816
|
+
\********************************/
|
|
66817
|
+
(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
66818
|
+
|
|
66819
|
+
__webpack_require__.r(__webpack_exports__);
|
|
66820
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
66821
|
+
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__),
|
|
66822
|
+
/* harmony export */ figureOneError: () => (/* binding */ figureOneError)
|
|
66823
|
+
/* harmony export */ });
|
|
66824
|
+
var errors = {
|
|
66825
|
+
// Atlas errors (1xxx)
|
|
66826
|
+
1000: 'Either `src` or `font` must be defined to create an atlas',
|
|
66827
|
+
1001: 'Must define a scene to create an atlas from a font',
|
|
66828
|
+
1002: 'Failed to get 2D canvas context for atlas'
|
|
66829
|
+
};
|
|
66830
|
+
function figureOneError(code, detail) {
|
|
66831
|
+
var message = errors[code];
|
|
66832
|
+
var full = detail ? "".concat(message, " (").concat(detail, ")") : message;
|
|
66833
|
+
return new Error("F1-".concat(code, ": ").concat(full));
|
|
66834
|
+
}
|
|
66835
|
+
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (errors);
|
|
66836
|
+
|
|
66794
66837
|
/***/ },
|
|
66795
66838
|
|
|
66796
66839
|
/***/ "./src/js/tools/g2.ts"
|
|
@@ -79094,8 +79137,8 @@ var tools = {
|
|
|
79094
79137
|
*/
|
|
79095
79138
|
|
|
79096
79139
|
var Fig = {
|
|
79097
|
-
version: "1.0.
|
|
79098
|
-
gitHash: "
|
|
79140
|
+
version: "1.0.6",
|
|
79141
|
+
gitHash: "0610a714a",
|
|
79099
79142
|
tools: tools,
|
|
79100
79143
|
Figure: _js_figure_Figure__WEBPACK_IMPORTED_MODULE_5__["default"],
|
|
79101
79144
|
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.0.
|
|
3
|
+
"version": "1.0.6",
|
|
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",
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
declare const errors: {
|
|
2
|
+
readonly 1000: "Either `src` or `font` must be defined to create an atlas";
|
|
3
|
+
readonly 1001: "Must define a scene to create an atlas from a font";
|
|
4
|
+
readonly 1002: "Failed to get 2D canvas context for atlas";
|
|
5
|
+
};
|
|
6
|
+
export type FigureOneErrorCode = keyof typeof errors;
|
|
7
|
+
export declare function figureOneError(code: FigureOneErrorCode, detail?: string): Error;
|
|
8
|
+
export default errors;
|