skia-canvas 3.0.0 → 3.0.1

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 CHANGED
@@ -16,6 +16,12 @@
16
16
  <a href="https://github.com/samizdatco/skia-canvas/discussions">Discussion Forum</a>
17
17
  </div>
18
18
 
19
+ <div align="center">
20
+
21
+ ### [Version 3.0 now available](https://github.com/samizdatco/skia-canvas/discussions/255)
22
+
23
+ </div>
24
+
19
25
  ---
20
26
 
21
27
  Skia Canvas is a Node.js implementation of the HTML Canvas drawing [API](https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API) for both on- and off-screen rendering. Since it uses Google’s [Skia](https://skia.org) graphics engine, its output is very similar to Chrome’s [`<canvas>`](https://html.spec.whatwg.org/multipage/canvas.html) element — though it's also capable of things the browser’s Canvas still can't achieve.
package/lib/browser.js CHANGED
@@ -24,8 +24,6 @@ class Canvas{
24
24
  let elt = document.createElement('canvas'),
25
25
  pages = []
26
26
 
27
- Object.defineProperty(elt, "async", {value:true, writable:false, enumerable:true})
28
-
29
27
  for (var [prop, get] of Object.entries({
30
28
  png: () => asBuffer(elt, 'image/png'),
31
29
  jpg: () => asBuffer(elt, 'image/jpeg'),
@@ -5,9 +5,9 @@
5
5
  "use strict"
6
6
 
7
7
  const {RustClass, core, readOnly, inspect, neon, argc, REPR} = require('./neon'),
8
+ {fetch} = require('../fetch'),
8
9
  {EventEmitter} = require('events'),
9
10
  {readFile} = require('fs/promises'),
10
- {fetch} = require('cross-fetch'),
11
11
  url = require('url')
12
12
 
13
13
  //
package/lib/fetch.js ADDED
@@ -0,0 +1,9 @@
1
+ // wrapper that calls either native fetch (on node v18+) or node-fetch (for older systems)
2
+ const fetch = (src, options) => {
3
+ const fn = global.fetch
4
+ ? Promise.resolve(global.fetch)
5
+ : import('node-fetch').then(({default:fetch}) => fetch)
6
+ return fn.then(fetch => fetch(src, options))
7
+ }
8
+
9
+ module.exports = {fetch}
package/lib/prebuild.mjs CHANGED
@@ -6,9 +6,9 @@ import {createReadStream, createWriteStream, existsSync} from 'fs'
6
6
  import {readFile, writeFile, rm} from 'fs/promises'
7
7
  import {resolve} from 'path'
8
8
  import {promisify} from 'util'
9
- import fetch from 'cross-fetch'
10
9
  import {family} from 'detect-libc'
11
- import { HttpsProxyAgent } from 'https-proxy-agent'
10
+ import {fetch} from "./fetch.js"
11
+ import {HttpsProxyAgent} from 'https-proxy-agent'
12
12
 
13
13
  const pipeline = promisify(stream.pipeline)
14
14
  const exec = promisify(child_process.exec);
@@ -26,6 +26,23 @@ const CARGO_FEATURES = {
26
26
  win32: "vulkan,window",
27
27
  }[process.platform]
28
28
 
29
+ class Hasher extends stream.Transform {
30
+ #digest
31
+ constructor(options) {
32
+ super(options)
33
+ this.hash = crypto.createHash('sha256')
34
+ }
35
+ _transform(chunk, encoding, callback) {
36
+ this.hash.update(chunk)
37
+ this.push(chunk)
38
+ callback()
39
+ }
40
+ get digest(){
41
+ this.#digest = this.#digest || `sha256:${this.hash.digest('hex')}`
42
+ return this.#digest
43
+ }
44
+ }
45
+
29
46
  async function config(){
30
47
  let package_json = JSON.parse(await readFile(PACKAGE_JSON)),
31
48
  {platform, arch} = process,
@@ -71,18 +88,17 @@ async function download(...args){
71
88
  if (status==404) throw Error(`Prebuilt library not found at "${url}" (HTTP error ${status})`)
72
89
  else throw Error(`Failed to load prebuilt binary from "${url}" (HTTP error ${status})`)
73
90
  }else{
74
- console.log(`Prebuilt libary found at "${url}"`)
91
+ console.log(`Fetching prebuilt libary from "${url}"`)
75
92
  }
76
93
 
77
94
  // write to /lib/skia.node while also hashing the .gz file
78
- let [digest, _] = await Promise.all([
79
- pipeline( body, crypto.createHash('sha256').setEncoding('hex'), digest => digest.toArray() ),
80
- pipeline( body, zlib.createGunzip(), createWriteStream(BINARY_PATH) )
81
- ])
95
+ let sha = new Hasher()
96
+ let gunzip = zlib.createGunzip()
97
+ await pipeline(body, sha, gunzip, createWriteStream(BINARY_PATH))
82
98
 
83
99
  // verify hash if `prebuild` obj exists in package.json (i.e., this is a published module, not a repo copy)
84
100
  let official = (prebuild || {})[`${triplet}.gz`],
85
- actual = `sha256:${digest}`
101
+ actual = sha.digest
86
102
  if (official && actual != official){
87
103
  await rm(BINARY_PATH, {force:true})
88
104
  throw Error(`Prebuilt library file '${triplet}.gz' failed integrity check\nDownloaded: ${url}\nExpected: ${official}\nReceived: ${actual}`)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "skia-canvas",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "A multi-threaded, GPU-accelerated, Canvas API for Node",
5
5
  "author": "Christian Swinehart <drafting@samizdat.co>",
6
6
  "license": "MIT",
@@ -28,10 +28,10 @@
28
28
  "test": "jest"
29
29
  },
30
30
  "dependencies": {
31
- "cross-fetch": "^4.1.0",
32
31
  "detect-libc": "^2.0.4",
33
32
  "fast-glob": "^3.3.3",
34
33
  "https-proxy-agent": "^7.0.6",
34
+ "node-fetch": "^3.3.2",
35
35
  "string-split-by": "^1.0.0"
36
36
  },
37
37
  "devDependencies": {
@@ -70,15 +70,15 @@
70
70
  "rust"
71
71
  ],
72
72
  "prebuild": {
73
- "aws-lambda-arm64.zip": "sha256:13e4987d905adb6708168c747c533ecb412f2e1b62d6d49dde11d62868cf02b7",
74
- "aws-lambda-x64.zip": "sha256:555d0cfd43b76481bfd309a1258ecbd22e58cf50c4d9832c5f437a3271a3f656",
75
- "darwin-arm64.gz": "sha256:e50f32c760ffd237a9f55b7277f69fe61df73cb8ebde500b36e41d49bcc6b69c",
76
- "darwin-x64.gz": "sha256:606b5368af960c150687101f2d8794293b73cf5766438f03ee2ab0949bb140fd",
77
- "linux-arm64-glibc.gz": "sha256:988c653a0c98991bb9822c78d616dd8f5ef346899cde495830888b5a9d182135",
78
- "linux-arm64-musl.gz": "sha256:b3884a8be601789a01c3615b7b7a0d1a09356ac811b1c22430cfbcf7a1e17e4b",
79
- "linux-x64-glibc.gz": "sha256:9f57032652094baba1cd5b897dc51d7c287daeb7e2f1db9e11c7e7f5dda55c99",
80
- "linux-x64-musl.gz": "sha256:3ac0b095b3b2f9e7353fd14b9f6305f4bdffb68aa594b1f836887bcbe892a1a6",
81
- "win32-arm64.gz": "sha256:47bb7f9f6e526c282348fcfa5ec60528ecce8ffc5b5fb6ea09dd3ca28f1ff4a4",
82
- "win32-x64.gz": "sha256:01d2d9c1ba54f59761c6d65ef6f4ebd8d7f0e0a955484dd827c342b39832acd9"
73
+ "aws-lambda-arm64.zip": "sha256:6277df5424e71150ff186f28a5f083c6a04365dfe02c5750ec667171b4e3b59c",
74
+ "aws-lambda-x64.zip": "sha256:8f57d142d9c739307bf4a52308151310c1b520d1540c02d2cf24941c09958615",
75
+ "darwin-arm64.gz": "sha256:554b6dd523ec71337f77a650d9df413aaec156b274633611398c512a03f9ed9e",
76
+ "darwin-x64.gz": "sha256:e5d701b95c74c42146e03c8a2794f96daafb32ed4afaa0ea267509847f4222f1",
77
+ "linux-arm64-glibc.gz": "sha256:90f91f355e807dd336b779a7ff432999a1361b6307f60ac0c4f706d422ebc86c",
78
+ "linux-arm64-musl.gz": "sha256:5952bf795abc0933a1ea0ef7be69eacf062680e72076a9370ddb0598e037e848",
79
+ "linux-x64-glibc.gz": "sha256:568618bb562d79ab8c9124e9179b0139d6715689fb12c796788d5c4c6eb5897b",
80
+ "linux-x64-musl.gz": "sha256:1ad2a48e5810970110dfd81216ff94c893794c58578e02af6461f9f0378b3bf6",
81
+ "win32-arm64.gz": "sha256:eb65c083ade85cb1f72eb45350175cf99b642c38651ecb14c3af163bed4ef528",
82
+ "win32-x64.gz": "sha256:9a60f2d71321f922fe9a54cf6af9f05e3e1e66defed2822777ce99bb2e79bab6"
83
83
  }
84
84
  }