From fb4906f400c1873ef46750b61df1765232d923f8 Mon Sep 17 00:00:00 2001 From: Caleb Hearon Date: Tue, 31 Dec 2024 12:57:27 -0500 Subject: [PATCH] typescript 5.7.2 I need this PR: https://github.com/microsoft/TypeScript/pull/57681 because currently tsconfig has to use DOM types to keep ts from emitting references to the dom in the .d.ts files, but that does something equally bad: it defines all the DOM types inside of dropflow (e.g. `navigator` is considered available) --- bun.lock | 10 +++++----- package.json | 4 ++-- src/layout-flow.ts | 4 ++-- src/paint-canvas.ts | 7 +++---- src/paint-html.ts | 7 +++---- src/paint-svg.ts | 7 +++---- src/paint.ts | 2 +- src/text-font.ts | 8 ++------ 8 files changed, 21 insertions(+), 28 deletions(-) diff --git a/bun.lock b/bun.lock index af09219..9d7328e 100755 --- a/bun.lock +++ b/bun.lock @@ -8,7 +8,7 @@ "@ddietr/codemirror-themes": "^1.4.2", "@rollup/plugin-node-resolve": "^15.2.3", "@types/mocha": "^8.0.3", - "@types/node": "^20.8.10", + "@types/node": "^20.17.10", "canvas": "^3.0.0", "chai": "^4.2.0", "codemirror": "^6.0.1", @@ -18,7 +18,7 @@ "mocha": "^10.0.0", "peggy": "^2.0.1", "punycode": "^2.1.1", - "typescript": "^5.2.2", + "typescript": "^5.7.2", "vite": "^6.0.3", }, }, @@ -154,7 +154,7 @@ "@types/mocha": ["@types/mocha@8.2.3", "", {}, "sha512-ekGvFhFgrc2zYQoX4JeZPmVzZxw6Dtllga7iGHzfbYIYkAMUx/sAFP2GdFpLff+vdHXu5fl7WX9AT+TtqYcsyw=="], - "@types/node": ["@types/node@20.8.10", "", { "dependencies": { "undici-types": "~5.26.4" } }, "sha512-TlgT8JntpcbmKUFzjhsyhGfP2fsiz1Mv56im6enJ905xG1DAYesxJaeSbGqQmAw8OWPdhyJGhGSQGKRNJ45u9w=="], + "@types/node": ["@types/node@20.17.10", "", { "dependencies": { "undici-types": "~6.19.2" } }, "sha512-/jrvh5h6NXhEauFFexRin69nA0uHJ5gwk4iDivp/DeoEua3uwCUto6PC86IpRITBOs4+6i2I56K5x5b6WYGXHA=="], "@types/resolve": ["@types/resolve@1.20.2", "", {}, "sha512-60BCwRFOZCQhDncwQdxxeOEEkbc5dIMccYLwbxsS4TUNeVECQ/pBJ0j09mrHOl/JJvpRPGwO9SvE4nR2Nb/a4Q=="], @@ -450,9 +450,9 @@ "type-detect": ["type-detect@4.0.8", "", {}, "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g=="], - "typescript": ["typescript@5.2.2", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w=="], + "typescript": ["typescript@5.7.2", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-i5t66RHxDvVN40HfDd1PsEThGNnlMCMT3jMUuoh9/0TaqWevNontacunWyN02LA9/fIbEWlcHZcgTKb9QoaLfg=="], - "undici-types": ["undici-types@5.26.5", "", {}, "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA=="], + "undici-types": ["undici-types@6.19.8", "", {}, "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw=="], "untildify": ["untildify@4.0.0", "", {}, "sha512-KK8xQ1mkzZeg9inewmFVDNkg3l5LUhoq9kN6iWYB/CC9YMG8HA+c1Q8HwDe6dEX7kErrEVNVBO3fWsVq5iDgtw=="], diff --git a/package.json b/package.json index f19e8a0..0f2df3d 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "@ddietr/codemirror-themes": "^1.4.2", "@rollup/plugin-node-resolve": "^15.2.3", "@types/mocha": "^8.0.3", - "@types/node": "^20.8.10", + "@types/node": "^20.17.10", "canvas": "^3.0.0", "chai": "^4.2.0", "codemirror": "^6.0.1", @@ -15,7 +15,7 @@ "mocha": "^10.0.0", "peggy": "^2.0.1", "punycode": "^2.1.1", - "typescript": "^5.2.2", + "typescript": "^5.7.2", "vite": "^6.0.3" }, "name": "dropflow", diff --git a/src/layout-flow.ts b/src/layout-flow.ts index 2bf9b3b..2b1301e 100644 --- a/src/layout-flow.ts +++ b/src/layout-flow.ts @@ -901,7 +901,7 @@ export class BlockContainer extends Box { }; } - getLastBaseline() { + getLastBaseline(): number | undefined { const stack: {block: BlockContainer, offset: number}[] = [{block: this, offset: 0}]; while (stack.length) { @@ -974,7 +974,7 @@ export class BlockContainer extends Box { return Boolean(this.children.length && this.children[0].isIfcInline()); } - canCollapseThrough() { + canCollapseThrough(): boolean { const blockSize = this.style.getBlockSize(this); if (blockSize !== 'auto' && blockSize !== 0) return false; diff --git a/src/paint-canvas.ts b/src/paint-canvas.ts index 4a0c1ef..05631d5 100644 --- a/src/paint-canvas.ts +++ b/src/paint-canvas.ts @@ -1,4 +1,3 @@ -import {firstCascadeItem} from './text-font.js'; import { prevCluster, nextCluster, @@ -125,7 +124,7 @@ export default class CanvasPaintBackend implements PaintBackend { strokeColor: Color; lineWidth: number; direction: 'ltr' | 'rtl'; - font: FaceMatch; + font: FaceMatch | undefined; fontSize: number; ctx: CanvasRenderingContext2D; @@ -134,7 +133,7 @@ export default class CanvasPaintBackend implements PaintBackend { this.strokeColor = {r: 0, g: 0, b: 0, a: 0}; this.lineWidth = 0; this.direction = 'ltr'; - this.font = firstCascadeItem(); + this.font = undefined; this.fontSize = 8; this.ctx = ctx; } @@ -168,7 +167,7 @@ export default class CanvasPaintBackend implements PaintBackend { if ('textDrawingMode' in this.ctx) { this.ctx.textDrawingMode = 'glyph'; } - this.ctx.font = this.font.toFontString(this.fontSize); + this.ctx.font = this.font?.toFontString(this.fontSize) || ''; this.ctx.fillStyle = `rgba(${r}, ${g}, ${b}, ${a})`; this.ctx.fillText(text, x, y); this.ctx.restore(); diff --git a/src/paint-html.ts b/src/paint-html.ts index e4f72c9..08c9d80 100644 --- a/src/paint-html.ts +++ b/src/paint-html.ts @@ -1,5 +1,4 @@ import {getMetrics, ShapedItem} from './layout-text.js'; -import {firstCascadeItem} from './text-font.js'; import type {Color} from './style.js'; import type {PaintBackend} from './paint.js'; @@ -21,7 +20,7 @@ export default class HtmlPaintBackend implements PaintBackend { strokeColor: Color; lineWidth: number; direction: 'ltr' | 'rtl'; - font: FaceMatch; + font: FaceMatch | undefined; fontSize: number; constructor() { @@ -30,7 +29,7 @@ export default class HtmlPaintBackend implements PaintBackend { this.strokeColor = {r: 0, g: 0, b: 0, a: 0}; this.lineWidth = 0; this.direction = 'ltr'; - this.font = firstCascadeItem(); + this.font = undefined; this.fontSize = 0; } @@ -71,7 +70,7 @@ export default class HtmlPaintBackend implements PaintBackend { left: '0', top: '0', transform: `translate(${x}px, ${y - (ascenderBox - (ascenderBox + descenderBox)/2)}px)`, - font: this.font.toFontString(this.fontSize), + font: this.font?.toFontString(this.fontSize) || "", lineHeight: '0', whiteSpace: 'pre', direction: this.direction, diff --git a/src/paint-svg.ts b/src/paint-svg.ts index 7f4723b..693358e 100644 --- a/src/paint-svg.ts +++ b/src/paint-svg.ts @@ -1,5 +1,4 @@ import {ShapedItem} from './layout-text.js'; -import {firstCascadeItem} from './text-font.js'; import type {Color} from './style.js'; import type {PaintBackend} from './paint.js'; @@ -52,7 +51,7 @@ export default class HtmlPaintBackend implements PaintBackend { strokeColor: Color; lineWidth: number; direction: 'ltr' | 'rtl'; - font: FaceMatch; + font: FaceMatch | undefined; fontSize: number; usedFonts: Map; @@ -64,7 +63,7 @@ export default class HtmlPaintBackend implements PaintBackend { this.strokeColor = {r: 0, g: 0, b: 0, a: 0}; this.lineWidth = 0; this.direction = 'ltr'; - this.font = firstCascadeItem(); + this.font = undefined; this.fontSize = 0; this.usedFonts = new Map(); } @@ -92,7 +91,7 @@ export default class HtmlPaintBackend implements PaintBackend { const {r, g, b, a} = this.fillColor; const color = `rgba(${r}, ${g}, ${b}, ${a})`; const style = this.style({ - font: this.font.toFontString(this.fontSize), + font: this.font?.toFontString(this.fontSize) ?? '', whiteSpace: 'pre', direction: this.direction, unicodeBidi: 'bidi-override' diff --git a/src/paint.ts b/src/paint.ts index 303952b..b2470a6 100644 --- a/src/paint.ts +++ b/src/paint.ts @@ -11,7 +11,7 @@ export interface PaintBackend { strokeColor: Color; lineWidth: number; direction: 'ltr' | 'rtl'; - font: FaceMatch; + font: FaceMatch | undefined; fontSize: number; edge(x: number, y: number, length: number, side: 'top' | 'right' | 'bottom' | 'left'): void; text(x: number, y: number, item: ShapedItem, textStart: number, textEnd: number, isColorBoundary?: boolean): void; diff --git a/src/text-font.ts b/src/text-font.ts index 9353423..272fbf9 100644 --- a/src/text-font.ts +++ b/src/text-font.ts @@ -473,9 +473,9 @@ export interface RegisterFontOptions { } export async function registerFont(url: URL, options?: RegisterFontOptions): Promise; -export async function registerFont(buffer: ArrayBuffer, url: URL, options?: RegisterFontOptions): Promise; +export async function registerFont(buffer: ArrayBufferLike, url: URL, options?: RegisterFontOptions): Promise; export async function registerFont( - arg1: URL | ArrayBuffer, + arg1: URL | ArrayBufferLike, arg2?: RegisterFontOptions | URL, arg3?: RegisterFontOptions ) { @@ -759,10 +759,6 @@ export function eachRegisteredFont(cb: (family: FaceMatch) => void) { } } -export function firstCascadeItem(): FaceMatch { - return registeredFonts.values().next().value; // TODO Why is this any? -} - const systemFontTrie = new UnicodeTrie(wasm.instance.exports.system_font_trie.value); export function getFontUrls(root: HTMLElement) {