/
Alex_Ural
/
opencode
Обзор
Документация
Войти
/
Alex_Ural
/
opencode
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
packages/app/happydom.ts
75 строк
2 KB
Adam
chore: rename packages/desktop -> packages/app
23 дек 2025, 04:39
Не верифицирован
23 дек 2025, 04:39
794fe8f
Код
Авторство
О чём код?
import { GlobalRegistrator } from "@happy-dom/global-registrator" GlobalRegistrator.register() const originalGetContext = HTMLCanvasElement.prototype.getContext // @ts-expect-error - we're overriding with a simplified mock HTMLCanvasElement.prototype.getContext = function (contextType: string, _options?: unknown) { if (contextType === "2d") { return { canvas: this, fillStyle: "#000000", strokeStyle: "#000000", font: "12px monospace", textAlign: "start", textBaseline: "alphabetic", globalAlpha: 1, globalCompositeOperation: "source-over", imageSmoothingEnabled: true, lineWidth: 1, lineCap: "butt", lineJoin: "miter", miterLimit: 10, shadowBlur: 0, shadowColor: "rgba(0, 0, 0, 0)", shadowOffsetX: 0, shadowOffsetY: 0, fillRect: () => {}, strokeRect: () => {}, clearRect: () => {}, fillText: () => {}, strokeText: () => {}, measureText: (text: string) => ({ width: text.length * 8 }), drawImage: () => {}, save: () => {}, restore: () => {}, scale: () => {}, rotate: () => {}, translate: () => {}, transform: () => {}, setTransform: () => {}, resetTransform: () => {}, createLinearGradient: () => ({ addColorStop: () => {} }), createRadialGradient: () => ({ addColorStop: () => {} }), createPattern: () => null, beginPath: () => {}, closePath: () => {}, moveTo: () => {}, lineTo: () => {}, bezierCurveTo: () => {}, quadraticCurveTo: () => {}, arc: () => {}, arcTo: () => {}, ellipse: () => {}, rect: () => {}, fill: () => {}, stroke: () => {}, clip: () => {}, isPointInPath: () => false, isPointInStroke: () => false, getTransform: () => ({}), getImageData: () => ({ data: new Uint8ClampedArray(0), width: 0, height: 0, }), putImageData: () => {}, createImageData: () => ({ data: new Uint8ClampedArray(0), width: 0, height: 0, }), } as unknown as CanvasRenderingContext2D } return originalGetContext.call(this, contextType as "2d", _options) }