Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

xterm-addon-ligatures

Package Overview
Dependencies
Maintainers
1
Versions
109
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xterm-addon-ligatures - npm Package Compare versions

Comparing version 0.5.0-beta.1 to 0.5.0-beta.2

74

out/font.js

@@ -6,5 +6,11 @@ "use strict";

*/
var __asyncValues = (this && this.__asyncValues) || function (o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
};
Object.defineProperty(exports, "__esModule", { value: true });
const fontFinder = require("font-finder");
const fontLigatures = require("font-ligatures");
const font_ligatures_1 = require("font-ligatures");
const parse_1 = require("./parse");

@@ -19,4 +25,60 @@ let fontsPromise = undefined;

async function load(fontFamily, cacheSize) {
var e_1, _a;
var _b, _c;
if (!fontsPromise) {
fontsPromise = fontFinder.list();
// Web environment that supports font access API
if (typeof navigator !== 'undefined' && 'fonts' in navigator) {
try {
const status = await ((_c = (_b = navigator.permissions).request) === null || _c === void 0 ? void 0 : _c.call(_b, {
name: 'local-fonts'
}));
if (status && status.state !== 'granted') {
throw new Error('Permission to access local fonts not granted.');
}
}
catch (err) {
// A `TypeError` indicates the 'local-fonts'
// permission is not yet implemented, so
// only `throw` if this is _not_ the problem.
if (err.name !== 'TypeError') {
throw err;
}
}
const fonts = {};
try {
const fontsIterator = navigator.fonts.query();
try {
for (var fontsIterator_1 = __asyncValues(fontsIterator), fontsIterator_1_1; fontsIterator_1_1 = await fontsIterator_1.next(), !fontsIterator_1_1.done;) {
const metadata = fontsIterator_1_1.value;
if (!fonts.hasOwnProperty(metadata.family)) {
fonts[metadata.family] = [];
}
fonts[metadata.family].push(metadata);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (fontsIterator_1_1 && !fontsIterator_1_1.done && (_a = fontsIterator_1.return)) await _a.call(fontsIterator_1);
}
finally { if (e_1) throw e_1.error; }
}
fontsPromise = Promise.resolve(fonts);
}
catch (err) {
console.error(err.name, err.message);
}
}
// Node environment or no font access API
else {
try {
fontsPromise = (await Promise.resolve().then(() => require('font-finder'))).list();
}
catch (err) {
// No-op
}
}
if (!fontsPromise) {
fontsPromise = Promise.resolve({});
}
}

@@ -32,3 +94,7 @@ const fonts = await fontsPromise;

if (fonts.hasOwnProperty(family) && fonts[family].length > 0) {
return await fontLigatures.loadFile(fonts[family][0].path, { cacheSize });
const font = fonts[family][0];
if ('blob' in font) {
return font_ligatures_1.loadBuffer(await (await font.blob()).arrayBuffer(), { cacheSize });
}
return await font_ligatures_1.loadFile(font.path, { cacheSize });
}

@@ -35,0 +101,0 @@ }

4

package.json
{
"name": "xterm-addon-ligatures",
"version": "0.5.0-beta.1",
"version": "0.5.0-beta.2",
"description": "Add support for programming ligatures to xterm.js",

@@ -35,3 +35,3 @@ "author": {

"font-finder": "^1.1.0",
"font-ligatures": "^1.3.3"
"font-ligatures": "^1.4.0"
},

@@ -38,0 +38,0 @@ "devDependencies": {

@@ -54,1 +54,2 @@ ## xterm-addon-ligatures

[Iosevka License]: https://github.com/be5invis/Iosevka/blob/master/LICENSE.md

@@ -6,9 +6,16 @@ /**

import * as fontFinder from 'font-finder';
import * as fontLigatures from 'font-ligatures';
import { FontList } from 'font-finder';
import { Font, loadBuffer, loadFile } from 'font-ligatures';
import parse from './parse';
let fontsPromise: Promise<fontFinder.FontList> | undefined = undefined;
interface IFontMetadata {
family: string;
fullName: string;
postscriptName: string;
blob: () => Promise<Blob>;
}
let fontsPromise: Promise<FontList | Record<string, IFontMetadata[]>> | undefined = undefined;
/**

@@ -20,5 +27,46 @@ * Loads the font ligature wrapper for the specified font family if it could be

*/
export default async function load(fontFamily: string, cacheSize: number): Promise<fontLigatures.Font | undefined> {
export default async function load(fontFamily: string, cacheSize: number): Promise<Font | undefined> {
if (!fontsPromise) {
fontsPromise = fontFinder.list();
// Web environment that supports font access API
if (typeof navigator !== 'undefined' && 'fonts' in navigator) {
try {
const status = await (navigator as any).permissions.request?.({
name: 'local-fonts'
});
if (status && status.state !== 'granted') {
throw new Error('Permission to access local fonts not granted.');
}
} catch (err) {
// A `TypeError` indicates the 'local-fonts'
// permission is not yet implemented, so
// only `throw` if this is _not_ the problem.
if (err.name !== 'TypeError') {
throw err;
}
}
const fonts: Record<string, IFontMetadata[]> = {};
try {
const fontsIterator: AsyncIterableIterator<IFontMetadata> = (navigator as any).fonts.query();
for await (const metadata of fontsIterator) {
if (!fonts.hasOwnProperty(metadata.family)) {
fonts[metadata.family] = [];
}
fonts[metadata.family].push(metadata);
}
fontsPromise = Promise.resolve(fonts);
} catch (err) {
console.error(err.name, err.message);
}
}
// Node environment or no font access API
else {
try {
fontsPromise = (await import('font-finder')).list();
} catch (err) {
// No-op
}
}
if (!fontsPromise) {
fontsPromise = Promise.resolve({});
}
}

@@ -36,3 +84,7 @@

if (fonts.hasOwnProperty(family) && fonts[family].length > 0) {
return await fontLigatures.loadFile(fonts[family][0].path, { cacheSize });
const font = fonts[family][0];
if ('blob' in font) {
return loadBuffer(await (await font.blob()).arrayBuffer(), { cacheSize });
}
return await loadFile(font.path, { cacheSize });
}

@@ -39,0 +91,0 @@ }

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc