@oscharko-dev/keiko 0.2.0-beta.0 → 0.2.0-beta.2
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/README.md +6 -5
- package/dist/ui/csp-hashes.json +20 -20
- package/dist/ui/static/404.html +1 -1
- package/dist/ui/static/_next/static/chunks/{422-70c16ea4b1f77f2e.js → 923-4141696576191bc0.js} +1 -1
- package/dist/ui/static/_next/static/chunks/app/_not-found/page-03d642dcd0f15b52.js +1 -0
- package/dist/ui/static/_next/static/chunks/app/launch/page-c725ff0c02b50663.js +1 -0
- package/dist/ui/static/_next/static/chunks/app/layout-aadefe615729db05.js +1 -0
- package/dist/ui/static/_next/static/chunks/app/local-knowledge/capsule/{page-0dc74e194a1f0092.js → page-4a7f242906e19a07.js} +1 -1
- package/dist/ui/static/_next/static/chunks/app/local-knowledge/page-3361769b8964e659.js +1 -0
- package/dist/ui/static/_next/static/chunks/app/memoriaviva/consolidation/{page-dc6c6bd180bc47a3.js → page-44b3f4fa3e10085f.js} +1 -1
- package/dist/ui/static/_next/static/chunks/app/memoriaviva/detail/{page-659e308e68ab2b1e.js → page-0cdfb3eeb659daeb.js} +1 -1
- package/dist/ui/static/_next/static/chunks/app/memoriaviva/{page-d6ba78f54207b69f.js → page-e78e0cd2876fec41.js} +1 -1
- package/dist/ui/static/_next/static/chunks/app/memoriaviva/review-queue/page-e32fe86466827484.js +1 -0
- package/dist/ui/static/_next/static/chunks/app/page-9ad91065d05ddfa0.js +1 -0
- package/dist/ui/static/_next/static/chunks/{main-app-5b043f6c611974ae.js → main-app-b52a8fa1d8127a5f.js} +1 -1
- package/dist/ui/static/apple-touch-icon.png +0 -0
- package/dist/ui/static/favicon.ico +0 -0
- package/dist/ui/static/icon-192-maskable.png +0 -0
- package/dist/ui/static/icon-192.png +0 -0
- package/dist/ui/static/icon-512-maskable.png +0 -0
- package/dist/ui/static/icon-512.png +0 -0
- package/dist/ui/static/index.html +1 -1
- package/dist/ui/static/index.txt +3 -3
- package/dist/ui/static/launch.html +1 -1
- package/dist/ui/static/launch.txt +3 -3
- package/dist/ui/static/local-knowledge/capsule.html +1 -1
- package/dist/ui/static/local-knowledge/capsule.txt +2 -2
- package/dist/ui/static/local-knowledge.html +1 -1
- package/dist/ui/static/local-knowledge.txt +2 -2
- package/dist/ui/static/memoriaviva/consolidation.html +1 -1
- package/dist/ui/static/memoriaviva/consolidation.txt +2 -2
- package/dist/ui/static/memoriaviva/detail.html +1 -1
- package/dist/ui/static/memoriaviva/detail.txt +2 -2
- package/dist/ui/static/memoriaviva/review-queue.html +1 -1
- package/dist/ui/static/memoriaviva/review-queue.txt +2 -2
- package/dist/ui/static/memoriaviva.html +1 -1
- package/dist/ui/static/memoriaviva.txt +2 -2
- package/node_modules/@oscharko-dev/keiko-cli/dist/.tsbuildinfo +1 -1
- package/node_modules/@oscharko-dev/keiko-cli/package.json +1 -1
- package/node_modules/@oscharko-dev/keiko-contracts/dist/.tsbuildinfo +1 -1
- package/node_modules/@oscharko-dev/keiko-contracts/dist/index.d.ts +1 -1
- package/node_modules/@oscharko-dev/keiko-contracts/dist/index.js +1 -1
- package/node_modules/@oscharko-dev/keiko-contracts/package.json +1 -1
- package/node_modules/@oscharko-dev/keiko-evaluations/dist/.tsbuildinfo +1 -1
- package/node_modules/@oscharko-dev/keiko-evaluations/package.json +1 -1
- package/node_modules/@oscharko-dev/keiko-evidence/dist/.tsbuildinfo +1 -1
- package/node_modules/@oscharko-dev/keiko-evidence/package.json +1 -1
- package/node_modules/@oscharko-dev/keiko-harness/dist/.tsbuildinfo +1 -1
- package/node_modules/@oscharko-dev/keiko-harness/package.json +1 -1
- package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/.tsbuildinfo +1 -1
- package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/parsers/pdf-parser.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/parsers/pdf-parser.js +2 -2
- package/node_modules/@oscharko-dev/keiko-local-knowledge/package.json +1 -1
- package/node_modules/@oscharko-dev/keiko-memory-capture/package.json +1 -1
- package/node_modules/@oscharko-dev/keiko-memory-consolidation/package.json +1 -1
- package/node_modules/@oscharko-dev/keiko-memory-governance/package.json +1 -1
- package/node_modules/@oscharko-dev/keiko-memory-retrieval/package.json +1 -1
- package/node_modules/@oscharko-dev/keiko-memory-vault/dist/.tsbuildinfo +1 -1
- package/node_modules/@oscharko-dev/keiko-memory-vault/package.json +1 -1
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/.tsbuildinfo +1 -1
- package/node_modules/@oscharko-dev/keiko-model-gateway/package.json +1 -1
- package/node_modules/@oscharko-dev/keiko-quality-intelligence/dist/.tsbuildinfo +1 -1
- package/node_modules/@oscharko-dev/keiko-quality-intelligence/package.json +1 -1
- package/node_modules/@oscharko-dev/keiko-sdk/dist/.tsbuildinfo +1 -1
- package/node_modules/@oscharko-dev/keiko-sdk/package.json +1 -1
- package/node_modules/@oscharko-dev/keiko-security/dist/.tsbuildinfo +1 -1
- package/node_modules/@oscharko-dev/keiko-security/package.json +1 -1
- package/node_modules/@oscharko-dev/keiko-server/dist/.tsbuildinfo +1 -1
- package/node_modules/@oscharko-dev/keiko-server/package.json +1 -1
- package/node_modules/@oscharko-dev/keiko-tools/dist/.tsbuildinfo +1 -1
- package/node_modules/@oscharko-dev/keiko-tools/package.json +1 -1
- package/node_modules/@oscharko-dev/keiko-verification/dist/.tsbuildinfo +1 -1
- package/node_modules/@oscharko-dev/keiko-verification/package.json +1 -1
- package/node_modules/@oscharko-dev/keiko-workflows/dist/.tsbuildinfo +1 -1
- package/node_modules/@oscharko-dev/keiko-workflows/package.json +1 -1
- package/node_modules/@oscharko-dev/keiko-workspace/dist/.tsbuildinfo +1 -1
- package/node_modules/@oscharko-dev/keiko-workspace/package.json +1 -1
- package/package.json +4 -3
- package/dist/ui/static/_next/static/chunks/app/_not-found/page-c4d800f366186be0.js +0 -1
- package/dist/ui/static/_next/static/chunks/app/launch/page-08afd1a052e7662c.js +0 -1
- package/dist/ui/static/_next/static/chunks/app/layout-0f75a39edc90325d.js +0 -1
- package/dist/ui/static/_next/static/chunks/app/local-knowledge/page-48bd57c5e542349e.js +0 -1
- package/dist/ui/static/_next/static/chunks/app/memoriaviva/review-queue/page-7186cd8b22efc78b.js +0 -1
- package/dist/ui/static/_next/static/chunks/app/page-f8386b8e05b3db03.js +0 -1
- package/node_modules/@napi-rs/canvas/LICENSE +0 -21
- package/node_modules/@napi-rs/canvas/README.md +0 -448
- package/node_modules/@napi-rs/canvas/geometry.js +0 -873
- package/node_modules/@napi-rs/canvas/index.d.ts +0 -1097
- package/node_modules/@napi-rs/canvas/index.js +0 -196
- package/node_modules/@napi-rs/canvas/js-binding.js +0 -464
- package/node_modules/@napi-rs/canvas/load-image.js +0 -156
- package/node_modules/@napi-rs/canvas/node-canvas.d.ts +0 -216
- package/node_modules/@napi-rs/canvas/node-canvas.js +0 -379
- package/node_modules/@napi-rs/canvas/package.json +0 -179
- package/node_modules/@napi-rs/canvas-linux-x64-gnu/README.md +0 -3
- package/node_modules/@napi-rs/canvas-linux-x64-gnu/package.json +0 -47
- package/node_modules/@napi-rs/canvas-linux-x64-gnu/skia.linux-x64-gnu.node +0 -0
- package/node_modules/@napi-rs/canvas-linux-x64-musl/README.md +0 -3
- package/node_modules/@napi-rs/canvas-linux-x64-musl/package.json +0 -47
- package/node_modules/@napi-rs/canvas-linux-x64-musl/skia.linux-x64-musl.node +0 -0
- /package/dist/ui/static/_next/static/{IZjQES_2JaG9qZ7_fkEPl → BNiyfCos3TiM2QdurajIZ}/_buildManifest.js +0 -0
- /package/dist/ui/static/_next/static/{IZjQES_2JaG9qZ7_fkEPl → BNiyfCos3TiM2QdurajIZ}/_ssgManifest.js +0 -0
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
const fs = require('fs')
|
|
2
|
-
const { Readable } = require('stream')
|
|
3
|
-
const { URL } = require('url')
|
|
4
|
-
|
|
5
|
-
const { Image } = require('./js-binding')
|
|
6
|
-
|
|
7
|
-
let http, https
|
|
8
|
-
|
|
9
|
-
const MAX_REDIRECTS = 20
|
|
10
|
-
const REDIRECT_STATUSES = new Set([301, 302])
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Loads the given source into canvas Image
|
|
14
|
-
* @param {string|URL|Image|Buffer} source The image source to be loaded
|
|
15
|
-
* @param {object} options Options passed to the loader
|
|
16
|
-
*/
|
|
17
|
-
module.exports = async function loadImage(source, options = {}) {
|
|
18
|
-
// use the same buffer without copying if the source is a buffer
|
|
19
|
-
if (Buffer.isBuffer(source) || source instanceof Uint8Array) return createImage(source, options.alt)
|
|
20
|
-
// load readable stream as image
|
|
21
|
-
if (source instanceof Readable) return createImage(await consumeStream(source), options.alt)
|
|
22
|
-
// construct a Uint8Array if the source is ArrayBuffer or SharedArrayBuffer
|
|
23
|
-
if (source instanceof ArrayBuffer || source instanceof SharedArrayBuffer)
|
|
24
|
-
return createImage(new Uint8Array(source), options.alt)
|
|
25
|
-
// construct a buffer if the source is buffer-like
|
|
26
|
-
if (isBufferLike(source)) return createImage(Buffer.from(source), options.alt)
|
|
27
|
-
// if the source is Image instance, copy the image src to new image
|
|
28
|
-
if (source instanceof Image) return createImage(source.src, options.alt)
|
|
29
|
-
// if source is string and in data uri format, construct image using data uri
|
|
30
|
-
if (typeof source === 'string' && source.trimStart().startsWith('data:')) {
|
|
31
|
-
const commaIdx = source.indexOf(',')
|
|
32
|
-
const encoding = source.lastIndexOf('base64', commaIdx) < 0 ? 'utf-8' : 'base64'
|
|
33
|
-
const data = Buffer.from(source.slice(commaIdx + 1), encoding)
|
|
34
|
-
// Empty payload would silently complete on Image (HTML spec) and the loadImage
|
|
35
|
-
// promise would never settle; reject upfront instead.
|
|
36
|
-
// See https://github.com/Brooooooklyn/canvas/issues/1255
|
|
37
|
-
if (data.length === 0) throw new Error(`Invalid data URI: empty payload in ${source.slice(0, 64)}`)
|
|
38
|
-
return createImage(data, options.alt)
|
|
39
|
-
}
|
|
40
|
-
// if source is a string or URL instance
|
|
41
|
-
if (typeof source === 'string') {
|
|
42
|
-
// if the source exists as a file, construct image from that file
|
|
43
|
-
if (!source.startsWith('http') && !source.startsWith('https') && (await exists(source))) {
|
|
44
|
-
return createImage(source, options.alt)
|
|
45
|
-
} else {
|
|
46
|
-
// the source is a remote url here
|
|
47
|
-
source = new URL(source)
|
|
48
|
-
// attempt to download the remote source and construct image
|
|
49
|
-
const data = await new Promise((resolve, reject) =>
|
|
50
|
-
makeRequest(
|
|
51
|
-
source,
|
|
52
|
-
resolve,
|
|
53
|
-
reject,
|
|
54
|
-
typeof options.maxRedirects === 'number' && options.maxRedirects >= 0 ? options.maxRedirects : MAX_REDIRECTS,
|
|
55
|
-
options.requestOptions,
|
|
56
|
-
),
|
|
57
|
-
)
|
|
58
|
-
return createImage(data, options.alt)
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (source instanceof URL) {
|
|
63
|
-
if (source.protocol === 'file:') {
|
|
64
|
-
// remove the leading slash on windows
|
|
65
|
-
return createImage(process.platform === 'win32' ? source.pathname.substring(1) : source.pathname, options.alt)
|
|
66
|
-
} else {
|
|
67
|
-
const data = await new Promise((resolve, reject) =>
|
|
68
|
-
makeRequest(
|
|
69
|
-
source,
|
|
70
|
-
resolve,
|
|
71
|
-
reject,
|
|
72
|
-
typeof options.maxRedirects === 'number' && options.maxRedirects >= 0 ? options.maxRedirects : MAX_REDIRECTS,
|
|
73
|
-
options.requestOptions,
|
|
74
|
-
),
|
|
75
|
-
)
|
|
76
|
-
return createImage(data, options.alt)
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// throw error as don't support that source
|
|
81
|
-
throw new TypeError('unsupported image source')
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function makeRequest(url, resolve, reject, redirectCount, requestOptions) {
|
|
85
|
-
const isHttps = url.protocol === 'https:'
|
|
86
|
-
// lazy load the lib
|
|
87
|
-
const lib = isHttps ? (!https ? (https = require('https')) : https) : !http ? (http = require('http')) : http
|
|
88
|
-
|
|
89
|
-
lib
|
|
90
|
-
.get(url.toString(), requestOptions || {}, (res) => {
|
|
91
|
-
try {
|
|
92
|
-
const shouldRedirect = REDIRECT_STATUSES.has(res.statusCode) && typeof res.headers.location === 'string'
|
|
93
|
-
if (shouldRedirect && redirectCount > 0)
|
|
94
|
-
return makeRequest(
|
|
95
|
-
new URL(res.headers.location, url.origin),
|
|
96
|
-
resolve,
|
|
97
|
-
reject,
|
|
98
|
-
redirectCount - 1,
|
|
99
|
-
requestOptions,
|
|
100
|
-
)
|
|
101
|
-
if (typeof res.statusCode === 'number' && (res.statusCode < 200 || res.statusCode >= 300)) {
|
|
102
|
-
return reject(new Error(`remote source rejected with status code ${res.statusCode}`))
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
consumeStream(res).then(resolve, reject)
|
|
106
|
-
} catch (err) {
|
|
107
|
-
reject(err)
|
|
108
|
-
}
|
|
109
|
-
})
|
|
110
|
-
.on('error', reject)
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// use stream/consumers in the future?
|
|
114
|
-
function consumeStream(res) {
|
|
115
|
-
return new Promise((resolve, reject) => {
|
|
116
|
-
const chunks = []
|
|
117
|
-
|
|
118
|
-
res.on('data', (chunk) => chunks.push(chunk))
|
|
119
|
-
res.on('end', () => resolve(Buffer.concat(chunks)))
|
|
120
|
-
res.on('error', reject)
|
|
121
|
-
})
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
async function createImage(src, alt) {
|
|
125
|
-
// Empty Buffer / Uint8Array: Image follows the HTML spec (silent completion,
|
|
126
|
-
// no events) so the promise below would hang. Reject upfront.
|
|
127
|
-
// See https://github.com/Brooooooklyn/canvas/issues/1255
|
|
128
|
-
if ((Buffer.isBuffer(src) || src instanceof Uint8Array) && src.length === 0) {
|
|
129
|
-
throw new Error('loadImage: empty image data')
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
const image = new Image()
|
|
133
|
-
if (typeof alt === 'string') image.alt = alt
|
|
134
|
-
|
|
135
|
-
return new Promise((resolve, reject) => {
|
|
136
|
-
image.onload = () => {
|
|
137
|
-
// Wait for bitmap decode before resolving
|
|
138
|
-
image.decode().then(() => resolve(image), reject)
|
|
139
|
-
}
|
|
140
|
-
image.onerror = (e) => reject(e)
|
|
141
|
-
image.src = src
|
|
142
|
-
})
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function isBufferLike(src) {
|
|
146
|
-
return (src && src.type === 'Buffer') || Array.isArray(src)
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
async function exists(path) {
|
|
150
|
-
try {
|
|
151
|
-
await fs.promises.access(path, fs.constants.F_OK)
|
|
152
|
-
return true
|
|
153
|
-
} catch {
|
|
154
|
-
return false
|
|
155
|
-
}
|
|
156
|
-
}
|
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* node-canvas compatibility layer for @napi-rs/canvas.
|
|
3
|
-
*
|
|
4
|
-
* Provides a drop-in replacement API matching the `canvas` (node-canvas) npm package.
|
|
5
|
-
* Quality values for JPEG/WebP use the node-canvas 0-1 scale and are automatically
|
|
6
|
-
* converted to @napi-rs/canvas's 0-100 scale internally.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```typescript
|
|
10
|
-
* // Drop-in replacement: change this import
|
|
11
|
-
* // import { createCanvas, registerFont, loadImage } from 'canvas'
|
|
12
|
-
* // to this:
|
|
13
|
-
* import { createCanvas, registerFont, loadImage } from '@napi-rs/canvas/node-canvas'
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import { Readable } from 'node:stream'
|
|
18
|
-
|
|
19
|
-
// Re-export types from @napi-rs/canvas that are API-compatible
|
|
20
|
-
import {
|
|
21
|
-
Image as NapiImage,
|
|
22
|
-
ImageData as NapiImageData,
|
|
23
|
-
Path2D as NapiPath2D,
|
|
24
|
-
DOMPoint as NapiDOMPoint,
|
|
25
|
-
DOMMatrix as NapiDOMMatrix,
|
|
26
|
-
DOMRect as NapiDOMRect,
|
|
27
|
-
SKRSContext2D,
|
|
28
|
-
Canvas as NapiCanvas,
|
|
29
|
-
SvgCanvas,
|
|
30
|
-
SvgExportFlag,
|
|
31
|
-
IGlobalFonts,
|
|
32
|
-
PDFDocument,
|
|
33
|
-
} from './index'
|
|
34
|
-
|
|
35
|
-
// ---------------------------------------------------------------------------
|
|
36
|
-
// Config interfaces (node-canvas conventions)
|
|
37
|
-
// ---------------------------------------------------------------------------
|
|
38
|
-
|
|
39
|
-
export interface PngConfig {
|
|
40
|
-
/** ZLIB compression level (0-9). Accepted for compatibility; Skia uses its own encoder. */
|
|
41
|
-
compressionLevel?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
|
|
42
|
-
/** PNG filter flags. Accepted for compatibility; Skia uses its own encoder. */
|
|
43
|
-
filters?: number
|
|
44
|
-
/** Palette for indexed PNGs. Not supported by Skia backend. */
|
|
45
|
-
palette?: Uint8ClampedArray
|
|
46
|
-
/** Background color index for indexed PNGs. Not supported by Skia backend. */
|
|
47
|
-
backgroundIndex?: number
|
|
48
|
-
/** Pixels per inch. Accepted for compatibility. */
|
|
49
|
-
resolution?: number
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export interface JpegConfig {
|
|
53
|
-
/** Quality between 0 and 1. Defaults to 0.75. Converted to 0-100 for Skia. */
|
|
54
|
-
quality?: number
|
|
55
|
-
/** Progressive encoding. Accepted for compatibility; not supported by Skia backend. */
|
|
56
|
-
progressive?: boolean
|
|
57
|
-
/** 2x2 chroma subsampling. Accepted for compatibility; not supported by Skia backend. */
|
|
58
|
-
chromaSubsampling?: boolean
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// ---------------------------------------------------------------------------
|
|
62
|
-
// Canvas class (with node-canvas compatible methods)
|
|
63
|
-
// ---------------------------------------------------------------------------
|
|
64
|
-
|
|
65
|
-
export interface Canvas extends Omit<NapiCanvas, 'toBuffer' | 'toDataURL'> {
|
|
66
|
-
/**
|
|
67
|
-
* Encode the canvas as a PNG and return a Node.js Readable stream.
|
|
68
|
-
* @param config PNG encoding options (accepted for compatibility)
|
|
69
|
-
*/
|
|
70
|
-
createPNGStream(config?: PngConfig): PNGStream
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Encode the canvas as a JPEG and return a Node.js Readable stream.
|
|
74
|
-
* @param config JPEG encoding options. Quality is 0-1 (default 0.75).
|
|
75
|
-
*/
|
|
76
|
-
createJPEGStream(config?: JpegConfig): JPEGStream
|
|
77
|
-
|
|
78
|
-
// --- toBuffer overloads (node-canvas conventions) ---
|
|
79
|
-
|
|
80
|
-
/** Encode as PNG (default). */
|
|
81
|
-
toBuffer(): Buffer
|
|
82
|
-
toBuffer(mimeType: 'image/png', config?: PngConfig): Buffer
|
|
83
|
-
/** Encode as JPEG. Quality in config is 0-1 (default 0.75). */
|
|
84
|
-
toBuffer(mimeType: 'image/jpeg', config?: JpegConfig): Buffer
|
|
85
|
-
/** Get raw unencoded pixel data. */
|
|
86
|
-
toBuffer(mimeType: 'raw'): Buffer
|
|
87
|
-
|
|
88
|
-
/** Async: encode as PNG (default) via callback. */
|
|
89
|
-
toBuffer(cb: (err: Error | null, result: Buffer) => void): void
|
|
90
|
-
toBuffer(cb: (err: Error | null, result: Buffer) => void, mimeType: 'image/png', config?: PngConfig): void
|
|
91
|
-
/** Async: encode as JPEG via callback. Quality in config is 0-1 (default 0.75). */
|
|
92
|
-
toBuffer(cb: (err: Error | null, result: Buffer) => void, mimeType: 'image/jpeg', config?: JpegConfig): void
|
|
93
|
-
|
|
94
|
-
// --- toDataURL overloads (node-canvas conventions) ---
|
|
95
|
-
|
|
96
|
-
/** Encode as PNG data URL (default). */
|
|
97
|
-
toDataURL(): string
|
|
98
|
-
toDataURL(mimeType: 'image/png'): string
|
|
99
|
-
/** Encode as JPEG data URL. Quality is 0-1. */
|
|
100
|
-
toDataURL(mimeType: 'image/jpeg', quality?: number): string
|
|
101
|
-
/** Async: encode as data URL via callback. */
|
|
102
|
-
toDataURL(cb: (err: Error | null, result: string) => void): void
|
|
103
|
-
toDataURL(mimeType: 'image/png', cb: (err: Error | null, result: string) => void): void
|
|
104
|
-
toDataURL(mimeType: 'image/jpeg', cb: (err: Error | null, result: string) => void): void
|
|
105
|
-
toDataURL(mimeType: 'image/jpeg', quality: number, cb: (err: Error | null, result: string) => void): void
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// ---------------------------------------------------------------------------
|
|
109
|
-
// Stream classes
|
|
110
|
-
// ---------------------------------------------------------------------------
|
|
111
|
-
|
|
112
|
-
/** Readable stream that emits PNG-encoded data. */
|
|
113
|
-
export class PNGStream extends Readable {}
|
|
114
|
-
|
|
115
|
-
/** Readable stream that emits JPEG-encoded data. */
|
|
116
|
-
export class JPEGStream extends Readable {}
|
|
117
|
-
|
|
118
|
-
// ---------------------------------------------------------------------------
|
|
119
|
-
// Factory functions
|
|
120
|
-
// ---------------------------------------------------------------------------
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Create a new canvas with node-canvas compatible API.
|
|
124
|
-
* Canvas instances created through this function have `createPNGStream()`,
|
|
125
|
-
* `createJPEGStream()`, and node-canvas compatible `toBuffer()` overloads.
|
|
126
|
-
*
|
|
127
|
-
* When `type` is `'svg'`, returns a `SvgCanvas` which produces vector output
|
|
128
|
-
* via `getContent()` instead of raster encoding methods.
|
|
129
|
-
*
|
|
130
|
-
* @param width Canvas width in pixels
|
|
131
|
-
* @param height Canvas height in pixels
|
|
132
|
-
* @param type Canvas type: 'image' (default) or 'svg'
|
|
133
|
-
*/
|
|
134
|
-
export function createCanvas(width: number, height: number, type: 'svg'): SvgCanvas
|
|
135
|
-
export function createCanvas(width: number, height: number, type?: 'image'): Canvas
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Create an ImageData instance.
|
|
139
|
-
* @param data Pixel data array
|
|
140
|
-
* @param width Width in pixels
|
|
141
|
-
* @param height Height in pixels (calculated from data length if omitted)
|
|
142
|
-
*/
|
|
143
|
-
export function createImageData(data: Uint8ClampedArray, width: number, height?: number): NapiImageData
|
|
144
|
-
export function createImageData(width: number, height: number): NapiImageData
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Load an image from a file path, URL, Buffer, or other source.
|
|
148
|
-
* Returns a Promise that resolves to an Image instance.
|
|
149
|
-
*/
|
|
150
|
-
export function loadImage(
|
|
151
|
-
source: string | URL | Buffer | ArrayBufferLike | Uint8Array | NapiImage | import('stream').Readable,
|
|
152
|
-
options?: { alt?: string; maxRedirects?: number; requestOptions?: import('http').RequestOptions },
|
|
153
|
-
): Promise<NapiImage>
|
|
154
|
-
|
|
155
|
-
// ---------------------------------------------------------------------------
|
|
156
|
-
// Font registration (node-canvas convention)
|
|
157
|
-
// ---------------------------------------------------------------------------
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Register a font file for use in canvas text rendering.
|
|
161
|
-
* Compatible with node-canvas's `registerFont()`.
|
|
162
|
-
*
|
|
163
|
-
* Note: @napi-rs/canvas auto-detects weight and style from font file metadata
|
|
164
|
-
* (matching browser behavior). The `weight` and `style` properties in fontFace
|
|
165
|
-
* are accepted for API compatibility.
|
|
166
|
-
*
|
|
167
|
-
* @param path Absolute path to the font file (.ttf, .otf, etc.)
|
|
168
|
-
* @param fontFace Font face properties matching CSS @font-face descriptors
|
|
169
|
-
*/
|
|
170
|
-
export function registerFont(path: string, fontFace: { family: string; weight?: string; style?: string }): void
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Deregister all previously registered fonts.
|
|
174
|
-
* Compatible with node-canvas's `deregisterAllFonts()`.
|
|
175
|
-
*/
|
|
176
|
-
export function deregisterAllFonts(): void
|
|
177
|
-
|
|
178
|
-
// ---------------------------------------------------------------------------
|
|
179
|
-
// Re-exported classes & values
|
|
180
|
-
// ---------------------------------------------------------------------------
|
|
181
|
-
|
|
182
|
-
// Canvas is exported both as a type (the compat interface above) and as a
|
|
183
|
-
// value (constructor that returns compat Canvas instances at runtime).
|
|
184
|
-
export declare const Canvas: {
|
|
185
|
-
new (width: number, height: number): Canvas
|
|
186
|
-
new (width: number, height: number, flag: SvgExportFlag): SvgCanvas
|
|
187
|
-
prototype: NapiCanvas
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
export { NapiImage as Image }
|
|
191
|
-
export { NapiImageData as ImageData }
|
|
192
|
-
export { NapiPath2D as Path2D }
|
|
193
|
-
export { NapiDOMPoint as DOMPoint }
|
|
194
|
-
export { NapiDOMMatrix as DOMMatrix }
|
|
195
|
-
export { NapiDOMRect as DOMRect }
|
|
196
|
-
|
|
197
|
-
// SKRSContext2D is an interface in index.d.ts but a class value at runtime.
|
|
198
|
-
// Declare as const to export the value for instanceof checks and re-export the type.
|
|
199
|
-
export type CanvasRenderingContext2D = SKRSContext2D
|
|
200
|
-
export declare const CanvasRenderingContext2D: { prototype: SKRSContext2D }
|
|
201
|
-
/** Legacy alias for CanvasRenderingContext2D. */
|
|
202
|
-
export type Context2d = SKRSContext2D
|
|
203
|
-
export declare const Context2d: { prototype: SKRSContext2D }
|
|
204
|
-
|
|
205
|
-
// ---------------------------------------------------------------------------
|
|
206
|
-
// @napi-rs/canvas extras (not part of node-canvas, but useful)
|
|
207
|
-
// ---------------------------------------------------------------------------
|
|
208
|
-
|
|
209
|
-
export { IGlobalFonts }
|
|
210
|
-
export declare const GlobalFonts: IGlobalFonts & {
|
|
211
|
-
/** Reload system fonts. Available at runtime but not declared in IGlobalFonts. */
|
|
212
|
-
loadSystemFonts(): number
|
|
213
|
-
}
|
|
214
|
-
export { PDFDocument }
|
|
215
|
-
export { NapiCanvas as CanvasElement }
|
|
216
|
-
export { SvgCanvas as SVGCanvas }
|