@xterm/addon-web-fonts 0.2.0-beta.70 → 0.2.0-beta.72
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/addon-web-fonts.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.WebFontsAddon=e():t.WebFontsAddon=e()}(globalThis,()=>(()=>{"use strict";var t={};return(()=>{var e=t;function n(t){return'"'===t[0]&&'"'===t[t.length-1]||"'"===t[0]&&"'"===t[t.length-1]?t.slice(1,-1):t}function o(t){const e=t.match(/([-_a-zA-Z0-9\xA0-\u{10FFFF}]+)/u);return!t.match(/^(-?\d|--)/m)&&e&&e[1]===t?t:`"${t.replace(/"/g,'\\"')}"`}function
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.WebFontsAddon=e():t.WebFontsAddon=e()}(globalThis,()=>(()=>{"use strict";var t={};return(()=>{var e=t;function n(t){return'"'===t[0]&&'"'===t[t.length-1]||"'"===t[0]&&"'"===t[t.length-1]?t.slice(1,-1):t}function o(t){const e=t.match(/([-_a-zA-Z0-9\xA0-\u{10FFFF}]+)/u);return!t.match(/^(-?\d|--)/m)&&e&&e[1]===t?t:`"${t.replace(/"/g,'\\"')}"`}function i(t){return JSON.stringify([n(t.family),t.stretch,t.style,t.unicodeRange,t.weight])}function r(t){const e=Array.from(document.fonts);if(!t||!t.length)return Promise.all(e.map(t=>t.load()));let o=[];const r=e.map(t=>i(t));for(const s of t)if(s instanceof FontFace){const t=i(s),n=r.indexOf(t);-1===n?(document.fonts.add(s),e.push(s),r.push(t),o.push(s)):o.push(e[n])}else{const t=e.filter(t=>s===n(t.family));if(o=o.concat(t),!t.length)return Promise.reject(`font family "${s}" not registered in document.fonts`)}return Promise.all(o.map(t=>t.load()))}function s(t){return document.fonts.ready.then(()=>r(t))}Object.defineProperty(e,"__esModule",{value:!0}),e.WebFontsAddon=void 0,e.loadFonts=s,e.WebFontsAddon=class{initialRelayout;_term;constructor(t=!0){this.initialRelayout=t}dispose(){this._term=void 0}activate(t){this._term=t,this.initialRelayout&&document.fonts.ready.then(()=>this.relayout())}loadFonts(t){return s(t)}async relayout(){if(!this._term)return;await document.fonts.ready;const t=this._term.options.fontFamily,e=function(t){return t?t.split(",").map(t=>n(t.trim())):[]}(t),i=Array.from(new Set(Array.from(document.fonts).map(t=>n(t.family)))),s=[],a=[];for(const t of e)(-1!==i.indexOf(t)?s:a).push(t);s.length&&(await r(s),this._term&&(this._term.options.fontFamily=a.length?function(t){return t.map(o).join(", ")}(a):"monospace",this._term.options.fontFamily=t))}}})(),t})());
|
|
2
2
|
//# sourceMappingURL=addon-web-fonts.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addon-web-fonts.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACdA,QAAuB,cAAID,IAE3BD,EAAoB,cAAIC,GACzB,CATD,CASGK,WAAY,I,gDCGf,SAASC,EAAQC,GACf,MAAa,MAATA,EAAE,IAAkC,MAApBA,EAAEA,EAAEC,OAAS,IACpB,MAATD,EAAE,IAAmC,MAApBA,EAAEA,EAAEC,OAAS,GADkBD,EAAEE,MAAM,GAAI,GAEzDF,
|
|
1
|
+
{"version":3,"file":"addon-web-fonts.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACdA,QAAuB,cAAID,IAE3BD,EAAoB,cAAIC,GACzB,CATD,CASGK,WAA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AAMC,KAAK,IAAMxB,EAAWC,GAAQ,C,sGAI5D,MAGqBwB,gBAFXC,MAER,WAAAC,CAAmBF,GAA2B,G,qBAA3BA,CAAkC,CAE9C,OAAAG,GACLC,KAAKH,WAAQI,CAAU,CAGlB,QAAAC,CAASC,GACdH,KAAKH,MAAQM,EACTH,KAAKJ,iBACPpB,SAASJ,MAAMsB,MAAMC,KAAK,IAAMK,KAAKI,WACtC,CAGI,SAAAC,CAAUjC,GACf,OAAOiC,EAAUjC,EAAO,CAGnB,cAAMgC,GACX,IAAKJ,KAAKH,MACR,aAEIrB,SAASJ,MAAMsB,MACrB,MAAM5B,EAASkC,KAAKH,MAAMS,QAAQC,WAC5BC,EAxGV,SAAqB1C,GACnB,OAAKA,EACEA,EAAO2C,MAAM,KAAK9B,IAAI+B,GAAKxD,EAAQwD,EAAEC,SADxB,EACiC,CAsGlCC,CAAY9C,GACvB+C,EAAcvC,MAAMC,KAAK,IAAIuC,IAAIxC,MAAMC,KAAKC,SAASJ,OAAOO,IAAI+B,GAAKxD,EAAQwD,EAAE5C,WAC/EiD,EAAkB,GAClBC,EAAkB,GACxB,IAAK,MAAMC,KAAOT,IACe,IAA9BK,EAAY1B,QAAQ8B,GAAcF,EAAQC,GAAO3B,KAAK4B,GAEpDF,EAAM3D,eAGLe,EAAW4C,GACbf,KAAKH,QACPG,KAAKH,MAAMS,QAAQC,WAAaS,EAAM5D,OA9G5C,SAAsBoD,GACpB,OAAOA,EAAS7B,IAAIrB,GAAO4D,KAAK,KAAM,CA6GaC,CAAaH,GAAS,YACrEhB,KAAKH,MAAMS,QAAQC,WAAazC,GACjC,E","sources":["webpack://WebFontsAddon/webpack/universalModuleDefinition","webpack://WebFontsAddon/./src/WebFontsAddon.ts"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"WebFontsAddon\"] = factory();\n\telse\n\t\troot[\"WebFontsAddon\"] = factory();\n})(globalThis, () => {\nreturn ","/**\n * Copyright (c) 2024 The xterm.js authors. All rights reserved.\n * @license MIT\n */\n\nimport type { Terminal, ITerminalAddon } from '@xterm/xterm';\nimport type { WebFontsAddon as IWebFontsApi } from '@xterm/addon-web-fonts';\n\n\n/**\n * Unquote a font family name.\n */\nfunction unquote(s: string): string {\n if (s[0] === '\"' && s[s.length - 1] === '\"') return s.slice(1, -1);\n if (s[0] === '\\'' && s[s.length - 1] === '\\'') return s.slice(1, -1);\n return s;\n}\n\n\n/**\n * Quote a font family name conditionally.\n * @see https://mathiasbynens.be/notes/unquoted-font-family\n */\nfunction quote(s: string): string {\n const pos = s.match(/([-_a-zA-Z0-9\\xA0-\\u{10FFFF}]+)/u);\n const neg = s.match(/^(-?\\d|--)/m);\n if (!neg && pos && pos[1] === s) return s;\n return `\"${s.replace(/\"/g, '\\\\\"')}\"`;\n}\n\n\nfunction splitFamily(family: string | undefined): string[] {\n if (!family) return [];\n return family.split(',').map(e => unquote(e.trim()));\n}\n\n\nfunction createFamily(families: string[]): string {\n return families.map(quote).join(', ');\n}\n\n\n/**\n * Hash a font face from it properties.\n * Used in `loadFonts` to avoid bloating\n * `document.fonts` from multiple calls.\n */\nfunction hashFontFace(ff: FontFace): string {\n return JSON.stringify([\n unquote(ff.family),\n ff.stretch,\n ff.style,\n ff.unicodeRange,\n ff.weight\n ]);\n}\n\n\n/**\n * Wait for webfont resources to be loaded.\n *\n * Without any argument, all fonts currently listed in\n * `document.fonts` will be loaded.\n * For a more fine-grained loading strategy you can populate\n * the `fonts` argument with:\n * - font families : loads all fontfaces in `document.fonts`\n * matching the family names\n * - fontface objects : loads given fontfaces and adds them to\n * `document.fonts`\n *\n * The returned promise will resolve, when all loading is done.\n */\nfunction _loadFonts(fonts?: (string | FontFace)[]): Promise<FontFace[]> {\n const ffs = Array.from(document.fonts);\n if (!fonts || !fonts.length) {\n return Promise.all(ffs.map(ff => ff.load()));\n }\n let toLoad: FontFace[] = [];\n const ffsHashed = ffs.map(ff => hashFontFace(ff));\n for (const font of fonts) {\n if (font instanceof FontFace) {\n const fontHashed = hashFontFace(font);\n const idx = ffsHashed.indexOf(fontHashed);\n if (idx === -1) {\n document.fonts.add(font);\n ffs.push(font);\n ffsHashed.push(fontHashed);\n toLoad.push(font);\n } else {\n toLoad.push(ffs[idx]);\n }\n } else {\n // string as font\n const familyFiltered = ffs.filter(ff => font === unquote(ff.family));\n toLoad = toLoad.concat(familyFiltered);\n if (!familyFiltered.length) {\n return Promise.reject(`font family \"${font}\" not registered in document.fonts`);\n }\n }\n }\n return Promise.all(toLoad.map(ff => ff.load()));\n}\n\n\nexport function loadFonts(fonts?: (string | FontFace)[]): Promise<FontFace[]> {\n return document.fonts.ready.then(() => _loadFonts(fonts));\n}\n\n\nexport class WebFontsAddon implements ITerminalAddon, IWebFontsApi {\n private _term: Terminal | undefined;\n\n constructor(public initialRelayout: boolean = true) { }\n\n public dispose(): void {\n this._term = undefined;\n }\n\n public activate(term: Terminal): void {\n this._term = term;\n if (this.initialRelayout) {\n document.fonts.ready.then(() => this.relayout());\n }\n }\n\n public loadFonts(fonts?: (string | FontFace)[]): Promise<FontFace[]> {\n return loadFonts(fonts);\n }\n\n public async relayout(): Promise<void> {\n if (!this._term) {\n return;\n }\n await document.fonts.ready;\n const family = this._term.options.fontFamily;\n const families = splitFamily(family);\n const webFamilies = Array.from(new Set(Array.from(document.fonts).map(e => unquote(e.family))));\n const dirty: string[] = [];\n const clean: string[] = [];\n for (const fam of families) {\n (webFamilies.indexOf(fam) !== -1 ? dirty : clean).push(fam);\n }\n if (!dirty.length) {\n return;\n }\n await _loadFonts(dirty);\n if (this._term) {\n this._term.options.fontFamily = clean.length ? createFamily(clean) : 'monospace';\n this._term.options.fontFamily = family;\n }\n }\n}\n"],"names":["root","factory","exports","module","define","amd","globalThis","unquote","s","length","slice","quote","pos","match","replace","hashFontFace","ff","JSON","stringify","family","stretch","style","unicodeRange","weight","_loadFonts","fonts","ffs","Array","from","document","Promise","all","map","load","toLoad","ffsHashed","font","FontFace","fontHashed","idx","indexOf","add","push","familyFiltered","filter","concat","reject","ready","then","initialRelayout","_term","constructor","dispose","this","undefined","activate","term","relayout","loadFonts","options","fontFamily","families","split","e","trim","splitFamily","webFamilies","Set","dirty","clean","fam","join","createFamily"],"ignoreList":[],"sourceRoot":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xterm/addon-web-fonts",
|
|
3
|
-
"version": "0.2.0-beta.
|
|
3
|
+
"version": "0.2.0-beta.72",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "The xterm.js authors",
|
|
6
6
|
"url": "https://xtermjs.org/"
|
|
@@ -16,15 +16,15 @@
|
|
|
16
16
|
"xterm.js"
|
|
17
17
|
],
|
|
18
18
|
"scripts": {
|
|
19
|
-
"build": "../../node_modules/.bin/
|
|
19
|
+
"build": "../../node_modules/.bin/tsgo -p .",
|
|
20
20
|
"prepackage": "npm run build",
|
|
21
21
|
"package": "../../node_modules/.bin/webpack",
|
|
22
22
|
"prepublishOnly": "npm run package",
|
|
23
23
|
"start": "node ../../demo/start"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {},
|
|
26
|
-
"commit": "
|
|
26
|
+
"commit": "c8704930e370aa29a1cb24e3ff5b5f613f9cf2fb",
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@xterm/xterm": "^6.1.0-beta.
|
|
28
|
+
"@xterm/xterm": "^6.1.0-beta.158"
|
|
29
29
|
}
|
|
30
30
|
}
|