@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.
Files changed (50) hide show
  1. package/lib/__tests__/composites.test.js +255 -0
  2. package/lib/__tests__/drop-in-compat.test.js +133 -0
  3. package/lib/__tests__/embedded-fonts.test.js +121 -0
  4. package/lib/__tests__/index.test.js +118 -0
  5. package/lib/__tests__/input-imperative.test.js +155 -0
  6. package/lib/__tests__/keypad-label.test.js +231 -0
  7. package/lib/__tests__/keypad-render.test.js +206 -0
  8. package/lib/__tests__/latex-bridge.test.js +386 -0
  9. package/lib/__tests__/mathlive-instance.test.js +419 -0
  10. package/lib/__tests__/mount-race.test.js +218 -0
  11. package/lib/__tests__/static-prompts.test.js +405 -0
  12. package/lib/__tests__/tmp-markup.test.js +26 -0
  13. package/lib/keypad/index.js +36 -12
  14. package/lib/keypad/index.js.map +1 -1
  15. package/lib/latex-bridge.js +159 -4
  16. package/lib/latex-bridge.js.map +1 -1
  17. package/lib/mathlive-instance.js +21 -28
  18. package/lib/mathlive-instance.js.map +1 -1
  19. package/lib/mf/common-styles.js +17 -2
  20. package/lib/mf/common-styles.js.map +1 -1
  21. package/lib/mf/index.js +6 -0
  22. package/lib/mf/index.js.map +1 -1
  23. package/lib/mf/input.js +5 -0
  24. package/lib/mf/input.js.map +1 -1
  25. package/lib/mf/static.js +4 -2
  26. package/lib/mf/static.js.map +1 -1
  27. package/package.json +1 -1
  28. package/src/__tests__/composites.test.jsx +220 -0
  29. package/src/__tests__/drop-in-compat.test.jsx +112 -0
  30. package/src/__tests__/index.test.jsx +109 -0
  31. package/src/__tests__/input-imperative.test.jsx +144 -0
  32. package/src/__tests__/keypad-label.test.jsx +284 -0
  33. package/src/__tests__/keypad-render.test.jsx +123 -0
  34. package/src/__tests__/latex-bridge.test.js +389 -0
  35. package/src/__tests__/mathlive-instance.test.js +418 -0
  36. package/src/__tests__/mount-race.test.jsx +142 -0
  37. package/src/__tests__/static-prompts.test.jsx +364 -0
  38. package/src/keypad/index.jsx +18 -3
  39. package/src/latex-bridge.js +171 -4
  40. package/src/mathlive-instance.js +27 -29
  41. package/src/mf/common-styles.js +19 -0
  42. package/src/mf/index.js +2 -0
  43. package/src/mf/input.jsx +5 -0
  44. package/src/mf/static.jsx +4 -1
  45. package/lib/fonts/embedded.js +0 -120
  46. package/lib/fonts/index.js +0 -81
  47. package/lib/fonts/index.js.map +0 -1
  48. package/scripts/generate-embedded-fonts.js +0 -94
  49. package/src/fonts/embedded.js +0 -116
  50. package/src/fonts/index.js +0 -71
@@ -1,71 +0,0 @@
1
- import debug from 'debug';
2
-
3
- import { EMBEDDED_FONTS, MATHLIVE_VERSION } from './embedded';
4
-
5
- const log = debug('pie-lib:math-input-mathlive:fonts');
6
-
7
- let registered = false;
8
-
9
- /** The families MathLive needs; derived from the generated table. */
10
- export const EMBEDDED_FONT_FAMILIES = Array.from(new Set(EMBEDDED_FONTS.map((f) => f.family)));
11
-
12
- export { MATHLIVE_VERSION };
13
-
14
- /**
15
- * Put the embedded KaTeX faces into `document.fonts`.
16
- *
17
- * MathLive's `loadFonts()` short-circuits to "ready" as soon as every family it
18
- * needs is already in `document.fonts`, so registering here means it never
19
- * requests a woff2 over the network. That matters because MathLive composes some
20
- * glyphs from Private Use Area codepoints that exist only in these fonts - `\ne`
21
- * is U+E020 overlapped on `=` - so a blocked or missing font file does not
22
- * degrade to a plainer glyph, it renders tofu. Hosts that ship JS-only bundles
23
- * (pie-elements) have no stylesheet to carry `@font-face` and no asset path to
24
- * serve, and a CSP that omits the CDN left exactly that broken.
25
- *
26
- * Skipped when the document already has every family - a host that serves the
27
- * fonts itself, via `configureFonts` or by importing `mathlive/fonts.css`, wins.
28
- *
29
- * Idempotent, browser-only, and never throws: a font problem must not take the
30
- * editor down.
31
- *
32
- * @returns {boolean} whether the faces are available in the document
33
- */
34
- export const registerEmbeddedFonts = () => {
35
- if (registered) {
36
- return true;
37
- }
38
-
39
- if (typeof document === 'undefined' || !document.fonts || typeof FontFace === 'undefined') {
40
- return false;
41
- }
42
-
43
- try {
44
- const present = new Set(Array.from(document.fonts).map((f) => f.family));
45
-
46
- if (EMBEDDED_FONT_FAMILIES.every((family) => present.has(family))) {
47
- log('the document already provides every KaTeX family - leaving it alone');
48
- registered = true;
49
-
50
- return true;
51
- }
52
-
53
- EMBEDDED_FONTS.forEach(({ family, src, descriptors }) => {
54
- document.fonts.add(new FontFace(family, src, descriptors));
55
- });
56
-
57
- log('registered %d embedded KaTeX faces (mathlive@%s)', EMBEDDED_FONTS.length, MATHLIVE_VERSION);
58
- registered = true;
59
-
60
- return true;
61
- } catch (e) {
62
- log('could not register the embedded fonts: %s', e && e.message);
63
-
64
- return false;
65
- }
66
- };
67
-
68
- /** Test seam: forget that the faces were registered. */
69
- export const resetEmbeddedFontsForTests = () => {
70
- registered = false;
71
- };