figureone 1.0.6 → 1.0.7
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
|
@@ -8421,6 +8421,7 @@ var FigureFont = /*#__PURE__*/function () {
|
|
|
8421
8421
|
this.loadColor = optionsIn.loadColor;
|
|
8422
8422
|
this.atlasColor = optionsIn.atlasColor;
|
|
8423
8423
|
this.atlasSize = optionsIn.atlasSize;
|
|
8424
|
+
this.atlasId = optionsIn.atlasId;
|
|
8424
8425
|
this.letterSpacing = optionsIn.letterSpacing;
|
|
8425
8426
|
this.render = optionsIn.render;
|
|
8426
8427
|
this.mods = (0,_glyphMeasures__WEBPACK_IMPORTED_MODULE_4__["default"])(this.family, this.style, this.maxAscent, this.midAscent, this.maxDescent, this.midDescent, this.descent, this.modifiers);
|
|
@@ -8451,6 +8452,7 @@ var FigureFont = /*#__PURE__*/function () {
|
|
|
8451
8452
|
loadColor: [0, 0, 0, 0],
|
|
8452
8453
|
atlasColor: false,
|
|
8453
8454
|
atlasSize: null,
|
|
8455
|
+
atlasId: '',
|
|
8454
8456
|
render: '2d'
|
|
8455
8457
|
};
|
|
8456
8458
|
var options = (0,_tools_tools__WEBPACK_IMPORTED_MODULE_0__.joinObjects)({}, defaultOptions, optionsIn);
|
|
@@ -8504,6 +8506,7 @@ var FigureFont = /*#__PURE__*/function () {
|
|
|
8504
8506
|
this.atlasSize = optionsIn.atlasSize || null;
|
|
8505
8507
|
this.loadColor = options.loadColor;
|
|
8506
8508
|
this.atlasColor = options.atlasColor;
|
|
8509
|
+
this.atlasId = options.atlasId;
|
|
8507
8510
|
this.glyphs = options.glyphs;
|
|
8508
8511
|
this.id = options.id;
|
|
8509
8512
|
this.timeout = options.timeout;
|
|
@@ -8553,6 +8556,9 @@ var FigureFont = /*#__PURE__*/function () {
|
|
|
8553
8556
|
}, {
|
|
8554
8557
|
key: "getTextureID",
|
|
8555
8558
|
value: function getTextureID() {
|
|
8559
|
+
if (this.atlasId && this.atlasId !== '') {
|
|
8560
|
+
return this.atlasId;
|
|
8561
|
+
}
|
|
8556
8562
|
if (this.id && this.id !== '') {
|
|
8557
8563
|
return this.id;
|
|
8558
8564
|
}
|
|
@@ -33117,6 +33123,9 @@ var FIGURE1DEBUG = false;
|
|
|
33117
33123
|
* @property {number} [length] default shape primary dimension
|
|
33118
33124
|
* @property {TypeColor} [backgroundColor] background color for the figure.
|
|
33119
33125
|
* Use [r, g, b, 1] for opaque and [0, 0, 0, 0] for transparent.
|
|
33126
|
+
* @property {boolean} [antialias] enable WebGL anti-aliasing (`true`)
|
|
33127
|
+
* @property {number} [atlasScale] scale factor for GL text atlas texture
|
|
33128
|
+
* resolution relative to 1:1 pixel mapping (`2`)
|
|
33120
33129
|
* @interface
|
|
33121
33130
|
* @group Figure
|
|
33122
33131
|
*/
|
|
@@ -33299,7 +33308,9 @@ var Figure = /*#__PURE__*/function () {
|
|
|
33299
33308
|
glyphs: 'mathlatin',
|
|
33300
33309
|
render: '2d'
|
|
33301
33310
|
},
|
|
33302
|
-
backgroundColor: [1, 1, 1, 1]
|
|
33311
|
+
backgroundColor: [1, 1, 1, 1],
|
|
33312
|
+
antialias: true,
|
|
33313
|
+
atlasScale: 2
|
|
33303
33314
|
// scene: {
|
|
33304
33315
|
// style: '2D',
|
|
33305
33316
|
// left: -1,
|
|
@@ -33397,14 +33408,14 @@ var Figure = /*#__PURE__*/function () {
|
|
|
33397
33408
|
canvasStyle.innerHTML = "\n .figureone__container {\n position: relative;\n pointer-events: none;\n }\n .figureone__canvas {\n width: 100%;\n height: 100%;\n position: absolute;\n }\n .figureone__html {\n pointer-events: auto;\n }\n .figureone__lostcontext {\n display: table;\n background-color: white;\n }\n .figureone__lostcontext_message {\n text-align: center;\n vertical-align: middle;\n display: table-cell;\n border: 1px solid #444;\n color: #444;\n padding: 2em;\n }\n ";
|
|
33398
33409
|
document.getElementsByTagName('head')[0].appendChild(canvasStyle);
|
|
33399
33410
|
this.backgroundColor = optionsToUse.backgroundColor;
|
|
33400
|
-
var webglLow = new _webgl_webgl__WEBPACK_IMPORTED_MODULE_0__["default"](this.canvasLow, this.backgroundColor);
|
|
33411
|
+
var webglLow = new _webgl_webgl__WEBPACK_IMPORTED_MODULE_0__["default"](this.canvasLow, this.backgroundColor, optionsToUse.antialias, optionsToUse.atlasScale);
|
|
33401
33412
|
this.webglLow = webglLow;
|
|
33402
33413
|
this.canvasLow.addEventListener('webglcontextlost', this.contextLost.bind(this), false);
|
|
33403
33414
|
this.canvasLow.addEventListener('webglcontextrestored', this.contextRestored.bind(this), false);
|
|
33404
33415
|
// TODO in future, if still using canvasOffScreen then need to have it
|
|
33405
33416
|
// handle context lost and restored events
|
|
33406
33417
|
if (this.canvasOffscreen) {
|
|
33407
|
-
var webglOffscreen = new _webgl_webgl__WEBPACK_IMPORTED_MODULE_0__["default"](this.canvasOffscreen, this.backgroundColor);
|
|
33418
|
+
var webglOffscreen = new _webgl_webgl__WEBPACK_IMPORTED_MODULE_0__["default"](this.canvasOffscreen, this.backgroundColor, optionsToUse.antialias, optionsToUse.atlasScale);
|
|
33408
33419
|
this.webglOffscreen = webglOffscreen;
|
|
33409
33420
|
}
|
|
33410
33421
|
this.draw2DLow = new _DrawContext2D__WEBPACK_IMPORTED_MODULE_12__["default"](this.textCanvasLow);
|
|
@@ -63338,7 +63349,7 @@ var Atlas = /*#__PURE__*/function () {
|
|
|
63338
63349
|
if (font.atlasSize != null) {
|
|
63339
63350
|
fontSizePX = this.webgl.gl.canvas.height * font.atlasSize;
|
|
63340
63351
|
} else {
|
|
63341
|
-
fontSizePX = font.size / scene.heightNear * this.webgl.gl.canvas.height *
|
|
63352
|
+
fontSizePX = font.size / scene.heightNear * this.webgl.gl.canvas.height * this.webgl.atlasScale;
|
|
63342
63353
|
}
|
|
63343
63354
|
this.fontSize = fontSizePX;
|
|
63344
63355
|
var glyphs = this.font.getGlyphs();
|
|
@@ -63355,14 +63366,17 @@ var Atlas = /*#__PURE__*/function () {
|
|
|
63355
63366
|
fontSizePX *= mDim / dimension * 0.95;
|
|
63356
63367
|
dimension = Math.floor(Math.ceil(Math.sqrt(glyphs.length) + 2) * fontSizePX * 1.5);
|
|
63357
63368
|
}
|
|
63358
|
-
var canvas;
|
|
63369
|
+
var canvas = document.createElement('canvas');
|
|
63359
63370
|
var ctx = null;
|
|
63360
63371
|
for (var attempt = 0; attempt < 4; attempt += 1) {
|
|
63361
|
-
canvas = document.createElement('canvas');
|
|
63362
63372
|
canvas.width = dimension;
|
|
63363
63373
|
canvas.height = dimension;
|
|
63364
63374
|
ctx = canvas.getContext('2d');
|
|
63365
63375
|
if (ctx != null) break;
|
|
63376
|
+
// Free the failed canvas backing store before creating a new one
|
|
63377
|
+
canvas.width = 0;
|
|
63378
|
+
canvas.height = 0;
|
|
63379
|
+
canvas = document.createElement('canvas');
|
|
63366
63380
|
fontSizePX *= 0.5;
|
|
63367
63381
|
this.fontSize = fontSizePX;
|
|
63368
63382
|
dimension = Math.floor(Math.ceil(Math.sqrt(glyphs.length) + 2) * fontSizePX * 1.5);
|
|
@@ -63426,12 +63440,12 @@ var Atlas = /*#__PURE__*/function () {
|
|
|
63426
63440
|
font.setColorInContext(ctx, underlineColor);
|
|
63427
63441
|
ctx.fillRect(0, dimension - 5, 5, 5);
|
|
63428
63442
|
|
|
63429
|
-
//
|
|
63430
|
-
ctx.
|
|
63431
|
-
ctx.
|
|
63432
|
-
ctx.stroke();
|
|
63443
|
+
// // Uncomment this to draw a debug border around the atlas
|
|
63444
|
+
// ctx.beginPath();
|
|
63445
|
+
// ctx.rect(0, 0, dimension, dimension);
|
|
63446
|
+
// ctx.stroke();
|
|
63433
63447
|
|
|
63434
|
-
// //
|
|
63448
|
+
// // Uncomment this to debug atlas
|
|
63435
63449
|
// document.body.appendChild(canvas);
|
|
63436
63450
|
|
|
63437
63451
|
// // Uncomment this to save atlas as image file
|
|
@@ -63439,6 +63453,10 @@ var Atlas = /*#__PURE__*/function () {
|
|
|
63439
63453
|
// const image = canvas.toDataURL("image/png").replace("image/png", "image/octet-stream");
|
|
63440
63454
|
// window.location.href=image;
|
|
63441
63455
|
this.webgl.addTexture(this.font.getTextureID(), ctx.canvas, [0, 0, 0, 0], false, null, true);
|
|
63456
|
+
// Free the canvas backing store immediately since pixel data has already
|
|
63457
|
+
// been uploaded to the GPU via texImage2D
|
|
63458
|
+
ctx.canvas.width = 0;
|
|
63459
|
+
ctx.canvas.height = 0;
|
|
63442
63460
|
}
|
|
63443
63461
|
}]);
|
|
63444
63462
|
}();
|
|
@@ -64212,9 +64230,12 @@ var WebGLInstance = /*#__PURE__*/function () {
|
|
|
64212
64230
|
// fragmentSource: string,
|
|
64213
64231
|
// shaderLocations: Array<string>,
|
|
64214
64232
|
backgroundColor) {
|
|
64233
|
+
var antialias = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
64234
|
+
var atlasScale = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 2;
|
|
64215
64235
|
_classCallCheck(this, WebGLInstance);
|
|
64236
|
+
this.atlasScale = atlasScale;
|
|
64216
64237
|
var gl = canvas.getContext('webgl', {
|
|
64217
|
-
antialias:
|
|
64238
|
+
antialias: antialias
|
|
64218
64239
|
// premultipliedAlpha: false,
|
|
64219
64240
|
// alpha: false
|
|
64220
64241
|
});
|
|
@@ -79137,8 +79158,8 @@ var tools = {
|
|
|
79137
79158
|
*/
|
|
79138
79159
|
|
|
79139
79160
|
var Fig = {
|
|
79140
|
-
version: "1.0.
|
|
79141
|
-
gitHash: "
|
|
79161
|
+
version: "1.0.7",
|
|
79162
|
+
gitHash: "9c0a1c7fa",
|
|
79142
79163
|
tools: tools,
|
|
79143
79164
|
Figure: _js_figure_Figure__WEBPACK_IMPORTED_MODULE_5__["default"],
|
|
79144
79165
|
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.7",
|
|
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",
|
|
@@ -9,6 +9,7 @@ declare class FigureFont {
|
|
|
9
9
|
map: OBJ_AtlasMap;
|
|
10
10
|
glyphs: string | 'greek' | 'math' | 'mathExt' | 'common' | 'latin' | 'all' | 'numbers' | 'mathlatin' | Array<string>;
|
|
11
11
|
atlasSize: null | number;
|
|
12
|
+
atlasId: string;
|
|
12
13
|
loadColor: TypeColor;
|
|
13
14
|
size: number;
|
|
14
15
|
underline: false | {
|
|
@@ -83,6 +83,9 @@ export type OBJ_FigureForElement = {
|
|
|
83
83
|
* @property {number} [length] default shape primary dimension
|
|
84
84
|
* @property {TypeColor} [backgroundColor] background color for the figure.
|
|
85
85
|
* Use [r, g, b, 1] for opaque and [0, 0, 0, 0] for transparent.
|
|
86
|
+
* @property {boolean} [antialias] enable WebGL anti-aliasing (`true`)
|
|
87
|
+
* @property {number} [atlasScale] scale factor for GL text atlas texture
|
|
88
|
+
* resolution relative to 1:1 pixel mapping (`2`)
|
|
86
89
|
* @interface
|
|
87
90
|
* @group Figure
|
|
88
91
|
*/
|
|
@@ -94,6 +97,8 @@ export type OBJ_Figure = {
|
|
|
94
97
|
lineWidth?: number;
|
|
95
98
|
length?: number;
|
|
96
99
|
backgroundColor?: number;
|
|
100
|
+
antialias?: boolean;
|
|
101
|
+
atlasScale?: number;
|
|
97
102
|
};
|
|
98
103
|
/**
|
|
99
104
|
* Primary Figure class.
|
|
@@ -47,7 +47,8 @@ declare class WebGLInstance {
|
|
|
47
47
|
cancel(id: string): void;
|
|
48
48
|
getProgram(vertexShader: TypeVertexShader, fragmentShader: TypeFragmentShader): number;
|
|
49
49
|
useProgram(programIndex: number): Record<string, any> | null;
|
|
50
|
-
|
|
50
|
+
atlasScale: number;
|
|
51
|
+
constructor(canvas: HTMLCanvasElement, backgroundColor: Array<number>, antialias?: boolean, atlasScale?: number);
|
|
51
52
|
init(gl: WebGLRenderingContext): void;
|
|
52
53
|
resize(): void;
|
|
53
54
|
}
|