@pie-lib/math-input-mathlive 1.1.5-beta.1 → 1.1.5-beta.10
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/lib/__tests__/composites.test.js +255 -0
- package/lib/__tests__/drop-in-compat.test.js +133 -0
- package/lib/__tests__/embedded-fonts.test.js +121 -0
- package/lib/__tests__/index.test.js +118 -0
- package/lib/__tests__/input-imperative.test.js +155 -0
- package/lib/__tests__/keypad-label.test.js +231 -0
- package/lib/__tests__/keypad-render.test.js +206 -0
- package/lib/__tests__/latex-bridge.test.js +386 -0
- package/lib/__tests__/mathlive-instance.test.js +419 -0
- package/lib/__tests__/mount-race.test.js +218 -0
- package/lib/__tests__/static-prompts.test.js +405 -0
- package/lib/__tests__/tmp-markup.test.js +26 -0
- package/lib/keypad/index.js +36 -12
- package/lib/keypad/index.js.map +1 -1
- package/lib/latex-bridge.js +159 -4
- package/lib/latex-bridge.js.map +1 -1
- package/lib/mathlive-instance.js +21 -28
- package/lib/mathlive-instance.js.map +1 -1
- package/lib/mf/common-styles.js +17 -2
- package/lib/mf/common-styles.js.map +1 -1
- package/lib/mf/index.js +6 -0
- package/lib/mf/index.js.map +1 -1
- package/lib/mf/input.js +5 -0
- package/lib/mf/input.js.map +1 -1
- package/lib/mf/static.js +4 -2
- package/lib/mf/static.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/composites.test.jsx +220 -0
- package/src/__tests__/drop-in-compat.test.jsx +112 -0
- package/src/__tests__/index.test.jsx +109 -0
- package/src/__tests__/input-imperative.test.jsx +144 -0
- package/src/__tests__/keypad-label.test.jsx +284 -0
- package/src/__tests__/keypad-render.test.jsx +123 -0
- package/src/__tests__/latex-bridge.test.js +389 -0
- package/src/__tests__/mathlive-instance.test.js +418 -0
- package/src/__tests__/mount-race.test.jsx +142 -0
- package/src/__tests__/static-prompts.test.jsx +364 -0
- package/src/keypad/index.jsx +18 -3
- package/src/latex-bridge.js +171 -4
- package/src/mathlive-instance.js +27 -29
- package/src/mf/common-styles.js +19 -0
- package/src/mf/index.js +2 -0
- package/src/mf/input.jsx +5 -0
- package/src/mf/static.jsx +4 -1
- package/lib/fonts/embedded.js +0 -120
- package/lib/fonts/index.js +0 -81
- package/lib/fonts/index.js.map +0 -1
- package/scripts/generate-embedded-fonts.js +0 -94
- package/src/fonts/embedded.js +0 -116
- package/src/fonts/index.js +0 -71
package/lib/fonts/index.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.EMBEDDED_FONT_FAMILIES = void 0;
|
|
8
|
-
Object.defineProperty(exports, "MATHLIVE_VERSION", {
|
|
9
|
-
enumerable: true,
|
|
10
|
-
get: function get() {
|
|
11
|
-
return _embedded.MATHLIVE_VERSION;
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
exports.resetEmbeddedFontsForTests = exports.registerEmbeddedFonts = void 0;
|
|
15
|
-
var _debug = _interopRequireDefault(require("debug"));
|
|
16
|
-
var _embedded = require("./embedded");
|
|
17
|
-
var log = (0, _debug["default"])('pie-lib:math-input-mathlive:fonts');
|
|
18
|
-
var registered = false;
|
|
19
|
-
|
|
20
|
-
/** The families MathLive needs; derived from the generated table. */
|
|
21
|
-
var EMBEDDED_FONT_FAMILIES = exports.EMBEDDED_FONT_FAMILIES = Array.from(new Set(_embedded.EMBEDDED_FONTS.map(function (f) {
|
|
22
|
-
return f.family;
|
|
23
|
-
})));
|
|
24
|
-
/**
|
|
25
|
-
* Put the embedded KaTeX faces into `document.fonts`.
|
|
26
|
-
*
|
|
27
|
-
* MathLive's `loadFonts()` short-circuits to "ready" as soon as every family it
|
|
28
|
-
* needs is already in `document.fonts`, so registering here means it never
|
|
29
|
-
* requests a woff2 over the network. That matters because MathLive composes some
|
|
30
|
-
* glyphs from Private Use Area codepoints that exist only in these fonts - `\ne`
|
|
31
|
-
* is U+E020 overlapped on `=` - so a blocked or missing font file does not
|
|
32
|
-
* degrade to a plainer glyph, it renders tofu. Hosts that ship JS-only bundles
|
|
33
|
-
* (pie-elements) have no stylesheet to carry `@font-face` and no asset path to
|
|
34
|
-
* serve, and a CSP that omits the CDN left exactly that broken.
|
|
35
|
-
*
|
|
36
|
-
* Skipped when the document already has every family - a host that serves the
|
|
37
|
-
* fonts itself, via `configureFonts` or by importing `mathlive/fonts.css`, wins.
|
|
38
|
-
*
|
|
39
|
-
* Idempotent, browser-only, and never throws: a font problem must not take the
|
|
40
|
-
* editor down.
|
|
41
|
-
*
|
|
42
|
-
* @returns {boolean} whether the faces are available in the document
|
|
43
|
-
*/
|
|
44
|
-
var registerEmbeddedFonts = exports.registerEmbeddedFonts = function registerEmbeddedFonts() {
|
|
45
|
-
if (registered) {
|
|
46
|
-
return true;
|
|
47
|
-
}
|
|
48
|
-
if (typeof document === 'undefined' || !document.fonts || typeof FontFace === 'undefined') {
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
try {
|
|
52
|
-
var present = new Set(Array.from(document.fonts).map(function (f) {
|
|
53
|
-
return f.family;
|
|
54
|
-
}));
|
|
55
|
-
if (EMBEDDED_FONT_FAMILIES.every(function (family) {
|
|
56
|
-
return present.has(family);
|
|
57
|
-
})) {
|
|
58
|
-
log('the document already provides every KaTeX family - leaving it alone');
|
|
59
|
-
registered = true;
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
|
-
_embedded.EMBEDDED_FONTS.forEach(function (_ref) {
|
|
63
|
-
var family = _ref.family,
|
|
64
|
-
src = _ref.src,
|
|
65
|
-
descriptors = _ref.descriptors;
|
|
66
|
-
document.fonts.add(new FontFace(family, src, descriptors));
|
|
67
|
-
});
|
|
68
|
-
log('registered %d embedded KaTeX faces (mathlive@%s)', _embedded.EMBEDDED_FONTS.length, _embedded.MATHLIVE_VERSION);
|
|
69
|
-
registered = true;
|
|
70
|
-
return true;
|
|
71
|
-
} catch (e) {
|
|
72
|
-
log('could not register the embedded fonts: %s', e && e.message);
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
/** Test seam: forget that the faces were registered. */
|
|
78
|
-
var resetEmbeddedFontsForTests = exports.resetEmbeddedFontsForTests = function resetEmbeddedFontsForTests() {
|
|
79
|
-
registered = false;
|
|
80
|
-
};
|
|
81
|
-
//# sourceMappingURL=index.js.map
|
package/lib/fonts/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_debug","_interopRequireDefault","require","_embedded","log","debug","registered","EMBEDDED_FONT_FAMILIES","exports","Array","from","Set","EMBEDDED_FONTS","map","f","family","registerEmbeddedFonts","document","fonts","FontFace","present","every","has","forEach","_ref","src","descriptors","add","length","MATHLIVE_VERSION","e","message","resetEmbeddedFontsForTests"],"sources":["../../src/fonts/index.js"],"sourcesContent":["import debug from 'debug';\n\nimport { EMBEDDED_FONTS, MATHLIVE_VERSION } from './embedded';\n\nconst log = debug('pie-lib:math-input-mathlive:fonts');\n\nlet registered = false;\n\n/** The families MathLive needs; derived from the generated table. */\nexport const EMBEDDED_FONT_FAMILIES = Array.from(new Set(EMBEDDED_FONTS.map((f) => f.family)));\n\nexport { MATHLIVE_VERSION };\n\n/**\n * Put the embedded KaTeX faces into `document.fonts`.\n *\n * MathLive's `loadFonts()` short-circuits to \"ready\" as soon as every family it\n * needs is already in `document.fonts`, so registering here means it never\n * requests a woff2 over the network. That matters because MathLive composes some\n * glyphs from Private Use Area codepoints that exist only in these fonts - `\\ne`\n * is U+E020 overlapped on `=` - so a blocked or missing font file does not\n * degrade to a plainer glyph, it renders tofu. Hosts that ship JS-only bundles\n * (pie-elements) have no stylesheet to carry `@font-face` and no asset path to\n * serve, and a CSP that omits the CDN left exactly that broken.\n *\n * Skipped when the document already has every family - a host that serves the\n * fonts itself, via `configureFonts` or by importing `mathlive/fonts.css`, wins.\n *\n * Idempotent, browser-only, and never throws: a font problem must not take the\n * editor down.\n *\n * @returns {boolean} whether the faces are available in the document\n */\nexport const registerEmbeddedFonts = () => {\n if (registered) {\n return true;\n }\n\n if (typeof document === 'undefined' || !document.fonts || typeof FontFace === 'undefined') {\n return false;\n }\n\n try {\n const present = new Set(Array.from(document.fonts).map((f) => f.family));\n\n if (EMBEDDED_FONT_FAMILIES.every((family) => present.has(family))) {\n log('the document already provides every KaTeX family - leaving it alone');\n registered = true;\n\n return true;\n }\n\n EMBEDDED_FONTS.forEach(({ family, src, descriptors }) => {\n document.fonts.add(new FontFace(family, src, descriptors));\n });\n\n log('registered %d embedded KaTeX faces (mathlive@%s)', EMBEDDED_FONTS.length, MATHLIVE_VERSION);\n registered = true;\n\n return true;\n } catch (e) {\n log('could not register the embedded fonts: %s', e && e.message);\n\n return false;\n }\n};\n\n/** Test seam: forget that the faces were registered. */\nexport const resetEmbeddedFontsForTests = () => {\n registered = false;\n};\n"],"mappings":";;;;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,SAAA,GAAAD,OAAA;AAEA,IAAME,GAAG,GAAG,IAAAC,iBAAK,EAAC,mCAAmC,CAAC;AAEtD,IAAIC,UAAU,GAAG,KAAK;;AAEtB;AACO,IAAMC,sBAAsB,GAAAC,OAAA,CAAAD,sBAAA,GAAGE,KAAK,CAACC,IAAI,CAAC,IAAIC,GAAG,CAACC,wBAAc,CAACC,GAAG,CAAC,UAACC,CAAC;EAAA,OAAKA,CAAC,CAACC,MAAM;AAAA,EAAC,CAAC,CAAC;AAI9F;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,IAAMC,qBAAqB,GAAAR,OAAA,CAAAQ,qBAAA,GAAG,SAAxBA,qBAAqBA,CAAA,EAAS;EAC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S;EAC9C1B,UAAU,GAAG,KAAK;AACpB,CAAC","ignoreList":[]}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Generate `src/fonts/embedded.js` - MathLive's KaTeX faces as base64 data URIs.
|
|
4
|
-
*
|
|
5
|
-
* pie-elements ships JS-only web components, so there is no host stylesheet to
|
|
6
|
-
* carry `@font-face` and no static asset path to serve woff2 files from. Without
|
|
7
|
-
* the fonts, glyphs MathLive composes from Private Use Area codepoints render as
|
|
8
|
-
* tofu (`\ne` is U+E020 overlapped on `=`), so the fonts travel in the bundle.
|
|
9
|
-
*
|
|
10
|
-
* Re-run after bumping the `mathlive` dependency:
|
|
11
|
-
* node scripts/generate-embedded-fonts.js
|
|
12
|
-
*/
|
|
13
|
-
const fs = require('fs');
|
|
14
|
-
const path = require('path');
|
|
15
|
-
|
|
16
|
-
// Mirrors MathLive's own table (`loadFonts` in mathlive.mjs): file name plus the
|
|
17
|
-
// FontFace descriptors. The family is the file name minus its style suffix.
|
|
18
|
-
const FACES = [
|
|
19
|
-
['KaTeX_Main-Regular'],
|
|
20
|
-
['KaTeX_Main-BoldItalic', { style: 'italic', weight: 'bold' }],
|
|
21
|
-
['KaTeX_Main-Bold', { weight: 'bold' }],
|
|
22
|
-
['KaTeX_Main-Italic', { style: 'italic' }],
|
|
23
|
-
['KaTeX_Math-Italic', { style: 'italic' }],
|
|
24
|
-
['KaTeX_Math-BoldItalic', { style: 'italic', weight: 'bold' }],
|
|
25
|
-
['KaTeX_AMS-Regular'],
|
|
26
|
-
['KaTeX_Caligraphic-Regular'],
|
|
27
|
-
['KaTeX_Caligraphic-Bold', { weight: 'bold' }],
|
|
28
|
-
['KaTeX_Fraktur-Regular'],
|
|
29
|
-
['KaTeX_Fraktur-Bold', { weight: 'bold' }],
|
|
30
|
-
['KaTeX_SansSerif-Regular'],
|
|
31
|
-
['KaTeX_SansSerif-Bold', { weight: 'bold' }],
|
|
32
|
-
['KaTeX_SansSerif-Italic', { style: 'italic' }],
|
|
33
|
-
['KaTeX_Script-Regular'],
|
|
34
|
-
['KaTeX_Typewriter-Regular'],
|
|
35
|
-
['KaTeX_Size1-Regular'],
|
|
36
|
-
['KaTeX_Size2-Regular'],
|
|
37
|
-
['KaTeX_Size3-Regular'],
|
|
38
|
-
['KaTeX_Size4-Regular'],
|
|
39
|
-
];
|
|
40
|
-
|
|
41
|
-
const pkgRoot = path.resolve(__dirname, '..');
|
|
42
|
-
const mathliveRoot = path.dirname(require.resolve('mathlive/package.json', { paths: [pkgRoot] }));
|
|
43
|
-
const version = require(path.join(mathliveRoot, 'package.json')).version;
|
|
44
|
-
const fontsDir = path.join(mathliveRoot, 'fonts');
|
|
45
|
-
const out = path.join(pkgRoot, 'src', 'fonts', 'embedded.js');
|
|
46
|
-
|
|
47
|
-
const entries = FACES.map(([file, descriptors]) => {
|
|
48
|
-
const p = path.join(fontsDir, `${file}.woff2`);
|
|
49
|
-
|
|
50
|
-
if (!fs.existsSync(p)) {
|
|
51
|
-
console.error(`[embedded-fonts] missing ${p} - mathlive ${version} may have changed its font set`);
|
|
52
|
-
process.exit(1);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return {
|
|
56
|
-
family: file.replace(/-[a-zA-Z]+$/, ''),
|
|
57
|
-
descriptors: descriptors || {},
|
|
58
|
-
base64: fs.readFileSync(p).toString('base64'),
|
|
59
|
-
};
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
const lines = entries.map(
|
|
63
|
-
(e) =>
|
|
64
|
-
` {\n family: '${e.family}',\n descriptors: ${JSON.stringify(e.descriptors)},\n` +
|
|
65
|
-
` src: "url(data:font/woff2;base64,${e.base64}) format('woff2')",\n },`,
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
const header = `/* eslint-disable */
|
|
69
|
-
/**
|
|
70
|
-
* GENERATED FILE - do not edit.
|
|
71
|
-
*
|
|
72
|
-
* MathLive's KaTeX faces (mathlive@${version}) as base64 data URIs, so math
|
|
73
|
-
* renders with no network request and under any CSP. Regenerate with
|
|
74
|
-
* \`node scripts/generate-embedded-fonts.js\` after bumping mathlive.
|
|
75
|
-
*
|
|
76
|
-
* See scripts/generate-embedded-fonts.js for why these travel in the bundle.
|
|
77
|
-
*/
|
|
78
|
-
export const MATHLIVE_VERSION = '${version}';
|
|
79
|
-
|
|
80
|
-
export const EMBEDDED_FONTS = [
|
|
81
|
-
${lines.join('\n')}
|
|
82
|
-
];
|
|
83
|
-
|
|
84
|
-
export default EMBEDDED_FONTS;
|
|
85
|
-
`;
|
|
86
|
-
|
|
87
|
-
fs.mkdirSync(path.dirname(out), { recursive: true });
|
|
88
|
-
fs.writeFileSync(out, header);
|
|
89
|
-
|
|
90
|
-
const kb = Math.round(fs.statSync(out).size / 1024);
|
|
91
|
-
|
|
92
|
-
console.log(
|
|
93
|
-
`[embedded-fonts] wrote ${entries.length} faces for mathlive@${version} -> ${path.relative(pkgRoot, out)} (${kb}KB)`,
|
|
94
|
-
);
|