@motionscript/latex 0.0.0-stage → 0.1.0-alpha.3

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.
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "@motionscript/latex",
3
+ "version": "0.1.0-alpha.3",
4
+ "exports": {
5
+ ".": "dist/browser/index.js"
6
+ },
7
+ "peers": [
8
+ "@motionscript/sdk"
9
+ ],
10
+ "assets": {}
11
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * A bounded, least-recently-used memo.
3
+ *
4
+ * Sits under `geometry.ts`, and imports nothing, so it is testable in bare Node:
5
+ * everything else in this package reaches MathJax's browser adaptor at module
6
+ * scope, which means a test that touches it needs a DOM. The one piece of logic
7
+ * here worth being sure about — what gets thrown away when the memo is full —
8
+ * is exactly the piece that does not need one.
9
+ *
10
+ * Least-recently-used rather than oldest-first, and that matters for the shape
11
+ * of work this sees. A `Latex` node re-resolves its formula whenever `fontSize`
12
+ * changes, so animating the size of one formula inserts a fresh key every frame
13
+ * and would, under a first-in-first-out rule, walk the whole memo out of it in a
14
+ * couple of seconds — including the entries for every *other* formula in the
15
+ * scene, none of which had done anything wrong. Touching an entry on read keeps
16
+ * the formulas that are actually being asked for ahead of the ones streaming
17
+ * past.
18
+ */
19
+ export interface BoundedCache<T> {
20
+ get(key: string): T | undefined;
21
+ set(key: string, value: T): void;
22
+ /** Entries held. For tests and for anyone measuring. */
23
+ readonly size: number;
24
+ }
25
+ /**
26
+ * @param limit Most entries to hold. One more arriving evicts the least
27
+ * recently read or written.
28
+ */
29
+ export declare function createBoundedCache<T>(limit: number): BoundedCache<T>;
30
+ //# sourceMappingURL=cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,MAAM,WAAW,YAAY,CAAC,CAAC;IAC3B,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAAC;IAChC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;IACjC,wDAAwD;IACxD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACzB;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,YAAY,CAAC,CAAC,CAAC,CA8BpE"}
package/dist/cache.js ADDED
@@ -0,0 +1,53 @@
1
+ /**
2
+ * A bounded, least-recently-used memo.
3
+ *
4
+ * Sits under `geometry.ts`, and imports nothing, so it is testable in bare Node:
5
+ * everything else in this package reaches MathJax's browser adaptor at module
6
+ * scope, which means a test that touches it needs a DOM. The one piece of logic
7
+ * here worth being sure about — what gets thrown away when the memo is full —
8
+ * is exactly the piece that does not need one.
9
+ *
10
+ * Least-recently-used rather than oldest-first, and that matters for the shape
11
+ * of work this sees. A `Latex` node re-resolves its formula whenever `fontSize`
12
+ * changes, so animating the size of one formula inserts a fresh key every frame
13
+ * and would, under a first-in-first-out rule, walk the whole memo out of it in a
14
+ * couple of seconds — including the entries for every *other* formula in the
15
+ * scene, none of which had done anything wrong. Touching an entry on read keeps
16
+ * the formulas that are actually being asked for ahead of the ones streaming
17
+ * past.
18
+ */
19
+ /**
20
+ * @param limit Most entries to hold. One more arriving evicts the least
21
+ * recently read or written.
22
+ */
23
+ export function createBoundedCache(limit) {
24
+ // Insertion order is the eviction order, which is what makes a plain `Map`
25
+ // an LRU as long as every read re-inserts.
26
+ const entries = new Map();
27
+ return {
28
+ get(key) {
29
+ if (!entries.has(key))
30
+ return undefined;
31
+ const value = entries.get(key);
32
+ // Delete-then-set moves the key to the end, so the next eviction
33
+ // takes the genuinely coldest entry rather than the oldest one.
34
+ entries.delete(key);
35
+ entries.set(key, value);
36
+ return value;
37
+ },
38
+ set(key, value) {
39
+ entries.delete(key);
40
+ entries.set(key, value);
41
+ while (entries.size > limit) {
42
+ const coldest = entries.keys().next().value;
43
+ if (coldest === undefined)
44
+ break;
45
+ entries.delete(coldest);
46
+ }
47
+ },
48
+ get size() {
49
+ return entries.size;
50
+ },
51
+ };
52
+ }
53
+ //# sourceMappingURL=cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AASH;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAI,KAAa;IAC/C,2EAA2E;IAC3E,2CAA2C;IAC3C,MAAM,OAAO,GAAG,IAAI,GAAG,EAAa,CAAC;IAErC,OAAO;QACH,GAAG,CAAC,GAAG;YACH,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;gBAAE,OAAO,SAAS,CAAC;YACxC,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAM,CAAC;YACpC,iEAAiE;YACjE,gEAAgE;YAChE,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACpB,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YACxB,OAAO,KAAK,CAAC;QACjB,CAAC;QAED,GAAG,CAAC,GAAG,EAAE,KAAK;YACV,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACpB,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YACxB,OAAO,OAAO,CAAC,IAAI,GAAG,KAAK,EAAE,CAAC;gBAC1B,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC;gBAC5C,IAAI,OAAO,KAAK,SAAS;oBAAE,MAAM;gBACjC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAC5B,CAAC;QACL,CAAC;QAED,IAAI,IAAI;YACJ,OAAO,OAAO,CAAC,IAAI,CAAC;QACxB,CAAC;KACJ,CAAC;AACN,CAAC","sourcesContent":["/**\n * A bounded, least-recently-used memo.\n *\n * Sits under `geometry.ts`, and imports nothing, so it is testable in bare Node:\n * everything else in this package reaches MathJax's browser adaptor at module\n * scope, which means a test that touches it needs a DOM. The one piece of logic\n * here worth being sure about — what gets thrown away when the memo is full —\n * is exactly the piece that does not need one.\n *\n * Least-recently-used rather than oldest-first, and that matters for the shape\n * of work this sees. A `Latex` node re-resolves its formula whenever `fontSize`\n * changes, so animating the size of one formula inserts a fresh key every frame\n * and would, under a first-in-first-out rule, walk the whole memo out of it in a\n * couple of seconds — including the entries for every *other* formula in the\n * scene, none of which had done anything wrong. Touching an entry on read keeps\n * the formulas that are actually being asked for ahead of the ones streaming\n * past.\n */\n\nexport interface BoundedCache<T> {\n get(key: string): T | undefined;\n set(key: string, value: T): void;\n /** Entries held. For tests and for anyone measuring. */\n readonly size: number;\n}\n\n/**\n * @param limit Most entries to hold. One more arriving evicts the least\n * recently read or written.\n */\nexport function createBoundedCache<T>(limit: number): BoundedCache<T> {\n // Insertion order is the eviction order, which is what makes a plain `Map`\n // an LRU as long as every read re-inserts.\n const entries = new Map<string, T>();\n\n return {\n get(key) {\n if (!entries.has(key)) return undefined;\n const value = entries.get(key) as T;\n // Delete-then-set moves the key to the end, so the next eviction\n // takes the genuinely coldest entry rather than the oldest one.\n entries.delete(key);\n entries.set(key, value);\n return value;\n },\n\n set(key, value) {\n entries.delete(key);\n entries.set(key, value);\n while (entries.size > limit) {\n const coldest = entries.keys().next().value;\n if (coldest === undefined) break;\n entries.delete(coldest);\n }\n },\n\n get size() {\n return entries.size;\n },\n };\n}\n"]}
@@ -0,0 +1,5 @@
1
+ export { buildLatexPath } from './geometry.js';
2
+ export type { LatexToken, LatexPathResult } from './geometry.js';
3
+ export { prepareLatexTween as defaultLatexMorph } from './tween.js';
4
+ export type { AnimatedToken, LatexMorphStrategy } from './tween.js';
5
+ //# sourceMappingURL=engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,YAAY,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC9D,OAAO,EAAE,iBAAiB,IAAI,iBAAiB,EAAE,MAAM,SAAS,CAAC;AACjE,YAAY,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC"}
package/dist/engine.js ADDED
@@ -0,0 +1,10 @@
1
+ // The Latex "engine": MathJax-backed glyph-path building and morph
2
+ // interpolation, kept separate from node.ts so `ms add latex` can copy just
3
+ // the node declaration and import this behind `@motionscript/latex` instead
4
+ // What gets copied is whatever this package's registry.json declares, which
5
+ // for this component is node.ts; packages/site/scripts/build-registry.mjs
6
+ // enforces that anything it reaches for is either copied alongside it or
7
+ // re-exported from here.
8
+ export { buildLatexPath } from './geometry.js';
9
+ export { prepareLatexTween as defaultLatexMorph } from './tween.js';
10
+ //# sourceMappingURL=engine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.js","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,4EAA4E;AAC5E,4EAA4E;AAC5E,4EAA4E;AAC5E,0EAA0E;AAC1E,yEAAyE;AACzE,yBAAyB;AACzB,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,OAAO,EAAE,iBAAiB,IAAI,iBAAiB,EAAE,MAAM,SAAS,CAAC","sourcesContent":["// The Latex \"engine\": MathJax-backed glyph-path building and morph\n// interpolation, kept separate from node.ts so `ms add latex` can copy just\n// the node declaration and import this behind `@motionscript/latex` instead\n// What gets copied is whatever this package's registry.json declares, which\n// for this component is node.ts; packages/site/scripts/build-registry.mjs\n// enforces that anything it reaches for is either copied alongside it or\n// re-exported from here.\nexport { buildLatexPath } from './geometry';\nexport type { LatexToken, LatexPathResult } from './geometry';\nexport { prepareLatexTween as defaultLatexMorph } from './tween';\nexport type { AnimatedToken, LatexMorphStrategy } from './tween';\n"]}
@@ -0,0 +1,40 @@
1
+ import '@mathjax/src/js/input/tex/base/BaseConfiguration.js';
2
+ import '@mathjax/src/js/input/tex/ams/AmsConfiguration.js';
3
+ import '@mathjax/src/js/input/tex/boldsymbol/BoldsymbolConfiguration.js';
4
+ import '@mathjax/src/js/input/tex/newcommand/NewcommandConfiguration.js';
5
+ import '@mathjax/src/js/input/tex/cancel/CancelConfiguration.js';
6
+ import '@mathjax/src/js/input/tex/color/ColorConfiguration.js';
7
+ import '@mathjax/src/js/input/tex/mhchem/MhchemConfiguration.js';
8
+ import '@mathjax/src/js/input/tex/physics/PhysicsConfiguration.js';
9
+ import '@mathjax/src/js/input/tex/bbox/BboxConfiguration.js';
10
+ import '@mathjax/src/js/input/tex/mathtools/MathtoolsConfiguration.js';
11
+ import '@mathjax/mathjax-newcm-font/js/svg/dynamic/calligraphic.js';
12
+ import '@mathjax/mathjax-newcm-font/js/svg/dynamic/double-struck.js';
13
+ import '@mathjax/mathjax-newcm-font/js/svg/dynamic/fraktur.js';
14
+ import '@mathjax/mathjax-newcm-font/js/svg/dynamic/monospace.js';
15
+ import '@mathjax/mathjax-newcm-font/js/svg/dynamic/sans-serif.js';
16
+ import '@mathjax/mathjax-newcm-font/js/svg/dynamic/script.js';
17
+ import { PathCommand } from '@motionscript/sdk';
18
+ /** A single rendered glyph or shape with its character key and path commands. */
19
+ export interface LatexToken {
20
+ /** Character this token represents, or a synthetic key for non-glyph shapes. */
21
+ token: string;
22
+ path: PathCommand[];
23
+ }
24
+ export interface LatexPathResult {
25
+ /** All tokens in render order. */
26
+ tokens: LatexToken[];
27
+ /** Flat array of all path commands (for legacy single-path rendering). */
28
+ commands: PathCommand[];
29
+ width: number;
30
+ height: number;
31
+ /**
32
+ * Bounding box over every token, in token coordinate space:
33
+ * [minX, minY, maxX, maxY]. All tokens share this frame, so passing it as
34
+ * each path's center frame keeps their relative layout (instead of each
35
+ * glyph centering on its own bbox).
36
+ */
37
+ bounds: [number, number, number, number];
38
+ }
39
+ export declare function buildLatexPath(text: string, fontSize: number): LatexPathResult;
40
+ //# sourceMappingURL=geometry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geometry.d.ts","sourceRoot":"","sources":["../src/geometry.ts"],"names":[],"mappings":"AAQA,OAAO,qDAAqD,CAAC;AAC7D,OAAO,mDAAmD,CAAC;AAC3D,OAAO,iEAAiE,CAAC;AACzE,OAAO,iEAAiE,CAAC;AACzE,OAAO,yDAAyD,CAAC;AACjE,OAAO,uDAAuD,CAAC;AAC/D,OAAO,yDAAyD,CAAC;AACjE,OAAO,2DAA2D,CAAC;AACnE,OAAO,qDAAqD,CAAC;AAC7D,OAAO,+DAA+D,CAAC;AAGvE,OAAO,4DAA4D,CAAC;AACpE,OAAO,6DAA6D,CAAC;AACrE,OAAO,uDAAuD,CAAC;AAC/D,OAAO,yDAAyD,CAAC;AACjE,OAAO,0DAA0D,CAAC;AAClE,OAAO,sDAAsD,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAkDhD,iFAAiF;AACjF,MAAM,WAAW,UAAU;IACvB,gFAAgF;IAChF,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,WAAW,EAAE,CAAC;CACvB;AAED,MAAM,WAAW,eAAe;IAC5B,kCAAkC;IAClC,MAAM,EAAE,UAAU,EAAE,CAAC;IACrB,0EAA0E;IAC1E,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;CAC5C;AAoDD,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,eAAe,CAiB9E"}