1// This build file creates a static version of the Typr.ts library used for
2// processing fonts. It's isolated within a "factory" function wrapper so it can
3// easily be marshalled into a web worker.
6import nodeResolve from 'rollup-plugin-node-resolve'
7import commonjs from '@rollup/plugin-commonjs'
8import { terser } from 'rollup-plugin-terser'
11const {LERNA_ROOT_PATH} = process.env
12if (!LERNA_ROOT_PATH) {
13 throw new Error("Please execute `npm run build-typr` from the repository root.")
17const OUTPUT_TEMPLATE = `
19Custom build of Typr.ts (https://github.com/fredli74/Typr.ts) for use in Troika text rendering.
20Original MIT license applies: https://github.com/fredli74/Typr.ts/blob/master/LICENSE
23export default function() {
24 // Trick it into being able to run in a web worker
25 if (typeof window === 'undefined') {
31 return TyprExports.Typr
35const [banner, footer] = OUTPUT_TEMPLATE.split('$$CONTENT$$')
39 input: LERNA_ROOT_PATH + '/node_modules/@lojjic/typr/dist/Typr.js',
45 transform(source, id) {
46 // Quiet the console.warn statements added in the Typr.ts fork
47 source = source.replace(/console\.warn/g, 'console.debug')
49 // Replace some unneeded property assignments with unused stub vars so they get pruned out
50 // SVG fonts are unsupported by browsers anyway
51 removeMethodAssignment('Typr.SVG')
52 removeMethodAssignment('Typr.SVG.parse')
53 removeMethodAssignment('Typr.SVG.toPath')
54 removeMethodAssignment('Typr.SVG._toPath')
55 removeMethodAssignment('Typr.SVG._tokens')
56 removeMethodAssignment('Typr.SVG._toksToPath')
57 removeMethodAssignment('Typr.SVG._reps')
58 removeMethodAssignment('Typr.U.pathToSVG')
59 removeMethodAssignment('Typr.U.pathToContext')
61 // We provide our own implementation for stringToGlyphs that fixes joining-type shaping
62 // and improves performance, so don't need the original
63 removeMethodAssignment('Typr.U.stringToGlyphs')
64 removeMethodAssignment('Typr.U._getWPfeature')
65 // Same for position adjustments to support mark anchoring
66 removeMethodAssignment('Typr.U.getPairAdjustment')
70 function removeMethodAssignment(name) {
71 const re = new RegExp(`(${name}\\s*=)`)
72 source = source.replace(re, `var prunable${Math.round(Math.random()*1e12)}=`)
84 file: 'libs/typr.factory.js',
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list