Skip to content

Commit

Permalink
Small changes to support integration with OSMD.
Browse files Browse the repository at this point in the history
Include offscreencanvas type information directly, to remove a dependency.
  • Loading branch information
ronyeh committed Dec 10, 2021
1 parent 166dfd4 commit 4ae9441
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 35 deletions.
12 changes: 2 additions & 10 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
}
},
{
"files": ["demos/**/*.js", "demos/**/*.mjs"],
// disable some eslint rules in the demos and tools folders.
"files": ["{demos,tools}/**/*.{js,cjs,mjs}"],
"extends": ["eslint:recommended", "prettier"],
"rules": {
"no-console": "off",
Expand All @@ -57,15 +58,6 @@
{
"files": ["src/**/*.js"],
"extends": ["eslint:recommended", "prettier"]
},
{
"files": ["tests/**/*.js"],
"extends": ["eslint:recommended", "prettier"],
"rules": {
"no-restricted-globals": "off",
"no-undef": "off",
"no-undef-init": "off"
}
}
]
}
13 changes: 0 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@
"bugs": {
"url": "https://github.com/0xfe/vexflow/issues"
},
"dependencies": {
"@types/offscreencanvas": "^2019.6.4"
},
"dependencies": {},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.4.0",
"@typescript-eslint/parser": "^5.4.0",
Expand Down
29 changes: 29 additions & 0 deletions src/canvascontext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,35 @@ import { GroupAttributes, RenderContext, TextMeasure } from './rendercontext';
import { globalObject, warn } from './util';
import { isHTMLCanvas } from './web';

// https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/offscreencanvas
// https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/master/types/offscreencanvas/index.d.ts

interface OffscreenCanvas extends EventTarget {
width: number;
height: number;
// ...more stuff that we removed.
}

// https://html.spec.whatwg.org/multipage/canvas.html#offscreencanvasrenderingcontext2d
interface OffscreenCanvasRenderingContext2D
extends CanvasState,
CanvasTransform,
CanvasCompositing,
CanvasImageSmoothing,
CanvasFillStrokeStyles,
CanvasShadowStyles,
CanvasFilters,
CanvasRect,
CanvasDrawPath,
CanvasText,
CanvasDrawImage,
CanvasImageData,
CanvasPathDrawingStyles,
CanvasTextDrawingStyles,
CanvasPath {
readonly canvas: OffscreenCanvas;
}

/**
* A rendering context for the Canvas backend. This class serves as a proxy for the
* underlying CanvasRenderingContext2D object, part of the browser's API.
Expand Down
2 changes: 2 additions & 0 deletions src/textformatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export class TextFormatter {
* This method will return a fallback formatter if there are no matches.
*/
static create(requestedFont: FontInfo = {}): TextFormatter {
L('create: ', requestedFont);
if (!requestedFont.family) {
requestedFont.family = Font.SANS_SERIF;
}
Expand Down Expand Up @@ -138,6 +139,7 @@ export class TextFormatter {
* @param overwrite
*/
static registerInfo(info: TextFormatterInfo, overwrite: boolean = false): void {
L('registerInfo: ', info, overwrite);
const fontFamily = info.family;
const currFontInfo = registry[fontFamily];
if (currFontInfo === undefined || overwrite) {
Expand Down
3 changes: 2 additions & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const VERSION: string = '4.0.0';
export const BUILD: string = '9b46e51d13c77870fe742e3eae9a1777df489d95';
export const BUILD: string = '8526732110cb6f2fb843ec54a99809bb161b91f0';
export const DATE: string = '2021-12-10T22:57:36.968Z';
2 changes: 2 additions & 0 deletions tests/offscreencanvas_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const OffscreenCanvasTests = {

function simpleTest(): void {
// Create a CanvasContext from an OffscreenCanvas.
// eslint-disable-next-line
// @ts-ignore
const offscreenCanvas = new OffscreenCanvas(550, 200);
const offscreenCtx = offscreenCanvas.getContext('2d');
if (offscreenCtx == null) {
Expand Down
2 changes: 0 additions & 2 deletions tools/esm/fix-imports-and-exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
// - Assume single quoted strings.
// - Assume import(...) function uses only string literals.

/* eslint-disable no-console */

import * as fs from 'fs';
import * as path from 'path';

Expand Down
2 changes: 0 additions & 2 deletions tools/generate_png_images.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
// This meant to be used with the visual regression test system in
// `tools/visual_regression.sh`.

/* eslint-disable no-console */

const { JSDOM } = require('jsdom');
const fs = require('fs');
const path = require('path');
Expand Down
9 changes: 5 additions & 4 deletions tools/generate_version_file.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ const path = require('path');
const fs = require('fs');
const child_process = require('child_process');

/* eslint-disable no-console */

const outputFile = process.argv[2] ?? path.join(__dirname, '../src/version.ts');

const PACKAGE_JSON = JSON.parse(fs.readFileSync('package.json'));
const VEXFLOW_VERSION = PACKAGE_JSON.version;
const GIT_COMMIT_HASH = child_process.execSync('git rev-parse HEAD').toString().trim();

const contents = `export const VERSION: string = '${VEXFLOW_VERSION}';\nexport const BUILD: string = '${GIT_COMMIT_HASH}';`;
fs.writeFileSync(outputFile, contents);
const VERSION = `export const VERSION: string = '${VEXFLOW_VERSION}';`;
const BUILD = `export const BUILD: string = '${GIT_COMMIT_HASH}';`;
const DATE = `export const DATE: string = '${new Date().toISOString()}';`;

fs.writeFileSync(outputFile, `${VERSION}\n${BUILD}\n${DATE}`);

0 comments on commit 4ae9441

Please sign in to comment.