js-binding.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. // prettier-ignore
  2. /* eslint-disable */
  3. // @ts-nocheck
  4. /* auto-generated by NAPI-RS */
  5. const { readFileSync } = require('fs')
  6. let nativeBinding = null
  7. const loadErrors = []
  8. const isMusl = () => {
  9. let musl = false
  10. if (process.platform === 'linux') {
  11. musl = isMuslFromFilesystem()
  12. if (musl === null) {
  13. musl = isMuslFromReport()
  14. }
  15. if (musl === null) {
  16. musl = isMuslFromChildProcess()
  17. }
  18. }
  19. return musl
  20. }
  21. const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
  22. const isMuslFromFilesystem = () => {
  23. try {
  24. return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
  25. } catch {
  26. return null
  27. }
  28. }
  29. const isMuslFromReport = () => {
  30. let report = null
  31. if (typeof process.report?.getReport === 'function') {
  32. process.report.excludeNetwork = true
  33. report = process.report.getReport()
  34. }
  35. if (!report) {
  36. return null
  37. }
  38. if (report.header && report.header.glibcVersionRuntime) {
  39. return false
  40. }
  41. if (Array.isArray(report.sharedObjects)) {
  42. if (report.sharedObjects.some(isFileMusl)) {
  43. return true
  44. }
  45. }
  46. return false
  47. }
  48. const isMuslFromChildProcess = () => {
  49. try {
  50. return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
  51. } catch (e) {
  52. // If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
  53. return false
  54. }
  55. }
  56. function requireNative() {
  57. if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
  58. try {
  59. return require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH)
  60. } catch (err) {
  61. loadErrors.push(err)
  62. }
  63. } else if (process.platform === 'android') {
  64. if (process.arch === 'arm64') {
  65. try {
  66. return require('./skia.android-arm64.node')
  67. } catch (e) {
  68. loadErrors.push(e)
  69. }
  70. try {
  71. return require('@napi-rs/canvas-android-arm64')
  72. } catch (e) {
  73. loadErrors.push(e)
  74. }
  75. } else if (process.arch === 'arm') {
  76. try {
  77. return require('./skia.android-arm-eabi.node')
  78. } catch (e) {
  79. loadErrors.push(e)
  80. }
  81. try {
  82. return require('@napi-rs/canvas-android-arm-eabi')
  83. } catch (e) {
  84. loadErrors.push(e)
  85. }
  86. } else {
  87. loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
  88. }
  89. } else if (process.platform === 'win32') {
  90. if (process.arch === 'x64') {
  91. if (
  92. process.config?.variables?.shlib_suffix === 'dll.a' ||
  93. process.config?.variables?.node_target_type === 'shared_library'
  94. ) {
  95. try {
  96. return require('./skia.win32-x64-gnu.node')
  97. } catch (e) {
  98. loadErrors.push(e)
  99. }
  100. try {
  101. return require('@napi-rs/canvas-win32-x64-gnu')
  102. } catch (e) {
  103. loadErrors.push(e)
  104. }
  105. } else {
  106. try {
  107. return require('./skia.win32-x64-msvc.node')
  108. } catch (e) {
  109. loadErrors.push(e)
  110. }
  111. try {
  112. return require('@napi-rs/canvas-win32-x64-msvc')
  113. } catch (e) {
  114. loadErrors.push(e)
  115. }
  116. }
  117. } else if (process.arch === 'ia32') {
  118. try {
  119. return require('./skia.win32-ia32-msvc.node')
  120. } catch (e) {
  121. loadErrors.push(e)
  122. }
  123. try {
  124. return require('@napi-rs/canvas-win32-ia32-msvc')
  125. } catch (e) {
  126. loadErrors.push(e)
  127. }
  128. } else if (process.arch === 'arm64') {
  129. try {
  130. return require('./skia.win32-arm64-msvc.node')
  131. } catch (e) {
  132. loadErrors.push(e)
  133. }
  134. try {
  135. return require('@napi-rs/canvas-win32-arm64-msvc')
  136. } catch (e) {
  137. loadErrors.push(e)
  138. }
  139. } else {
  140. loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
  141. }
  142. } else if (process.platform === 'darwin') {
  143. try {
  144. return require('./skia.darwin-universal.node')
  145. } catch (e) {
  146. loadErrors.push(e)
  147. }
  148. try {
  149. return require('@napi-rs/canvas-darwin-universal')
  150. } catch (e) {
  151. loadErrors.push(e)
  152. }
  153. if (process.arch === 'x64') {
  154. try {
  155. return require('./skia.darwin-x64.node')
  156. } catch (e) {
  157. loadErrors.push(e)
  158. }
  159. try {
  160. return require('@napi-rs/canvas-darwin-x64')
  161. } catch (e) {
  162. loadErrors.push(e)
  163. }
  164. } else if (process.arch === 'arm64') {
  165. try {
  166. return require('./skia.darwin-arm64.node')
  167. } catch (e) {
  168. loadErrors.push(e)
  169. }
  170. try {
  171. return require('@napi-rs/canvas-darwin-arm64')
  172. } catch (e) {
  173. loadErrors.push(e)
  174. }
  175. } else {
  176. loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
  177. }
  178. } else if (process.platform === 'freebsd') {
  179. if (process.arch === 'x64') {
  180. try {
  181. return require('./skia.freebsd-x64.node')
  182. } catch (e) {
  183. loadErrors.push(e)
  184. }
  185. try {
  186. return require('@napi-rs/canvas-freebsd-x64')
  187. } catch (e) {
  188. loadErrors.push(e)
  189. }
  190. } else if (process.arch === 'arm64') {
  191. try {
  192. return require('./skia.freebsd-arm64.node')
  193. } catch (e) {
  194. loadErrors.push(e)
  195. }
  196. try {
  197. return require('@napi-rs/canvas-freebsd-arm64')
  198. } catch (e) {
  199. loadErrors.push(e)
  200. }
  201. } else {
  202. loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
  203. }
  204. } else if (process.platform === 'linux') {
  205. if (process.arch === 'x64') {
  206. if (isMusl()) {
  207. try {
  208. return require('./skia.linux-x64-musl.node')
  209. } catch (e) {
  210. loadErrors.push(e)
  211. }
  212. try {
  213. return require('@napi-rs/canvas-linux-x64-musl')
  214. } catch (e) {
  215. loadErrors.push(e)
  216. }
  217. } else {
  218. try {
  219. return require('./skia.linux-x64-gnu.node')
  220. } catch (e) {
  221. loadErrors.push(e)
  222. }
  223. try {
  224. return require('@napi-rs/canvas-linux-x64-gnu')
  225. } catch (e) {
  226. loadErrors.push(e)
  227. }
  228. }
  229. } else if (process.arch === 'arm64') {
  230. if (isMusl()) {
  231. try {
  232. return require('./skia.linux-arm64-musl.node')
  233. } catch (e) {
  234. loadErrors.push(e)
  235. }
  236. try {
  237. return require('@napi-rs/canvas-linux-arm64-musl')
  238. } catch (e) {
  239. loadErrors.push(e)
  240. }
  241. } else {
  242. try {
  243. return require('./skia.linux-arm64-gnu.node')
  244. } catch (e) {
  245. loadErrors.push(e)
  246. }
  247. try {
  248. return require('@napi-rs/canvas-linux-arm64-gnu')
  249. } catch (e) {
  250. loadErrors.push(e)
  251. }
  252. }
  253. } else if (process.arch === 'arm') {
  254. if (isMusl()) {
  255. try {
  256. return require('./skia.linux-arm-musleabihf.node')
  257. } catch (e) {
  258. loadErrors.push(e)
  259. }
  260. try {
  261. return require('@napi-rs/canvas-linux-arm-musleabihf')
  262. } catch (e) {
  263. loadErrors.push(e)
  264. }
  265. } else {
  266. try {
  267. return require('./skia.linux-arm-gnueabihf.node')
  268. } catch (e) {
  269. loadErrors.push(e)
  270. }
  271. try {
  272. return require('@napi-rs/canvas-linux-arm-gnueabihf')
  273. } catch (e) {
  274. loadErrors.push(e)
  275. }
  276. }
  277. } else if (process.arch === 'loong64') {
  278. if (isMusl()) {
  279. try {
  280. return require('./skia.linux-loong64-musl.node')
  281. } catch (e) {
  282. loadErrors.push(e)
  283. }
  284. try {
  285. return require('@napi-rs/canvas-linux-loong64-musl')
  286. } catch (e) {
  287. loadErrors.push(e)
  288. }
  289. } else {
  290. try {
  291. return require('./skia.linux-loong64-gnu.node')
  292. } catch (e) {
  293. loadErrors.push(e)
  294. }
  295. try {
  296. return require('@napi-rs/canvas-linux-loong64-gnu')
  297. } catch (e) {
  298. loadErrors.push(e)
  299. }
  300. }
  301. } else if (process.arch === 'riscv64') {
  302. if (isMusl()) {
  303. try {
  304. return require('./skia.linux-riscv64-musl.node')
  305. } catch (e) {
  306. loadErrors.push(e)
  307. }
  308. try {
  309. return require('@napi-rs/canvas-linux-riscv64-musl')
  310. } catch (e) {
  311. loadErrors.push(e)
  312. }
  313. } else {
  314. try {
  315. return require('./skia.linux-riscv64-gnu.node')
  316. } catch (e) {
  317. loadErrors.push(e)
  318. }
  319. try {
  320. return require('@napi-rs/canvas-linux-riscv64-gnu')
  321. } catch (e) {
  322. loadErrors.push(e)
  323. }
  324. }
  325. } else if (process.arch === 'ppc64') {
  326. try {
  327. return require('./skia.linux-ppc64-gnu.node')
  328. } catch (e) {
  329. loadErrors.push(e)
  330. }
  331. try {
  332. return require('@napi-rs/canvas-linux-ppc64-gnu')
  333. } catch (e) {
  334. loadErrors.push(e)
  335. }
  336. } else if (process.arch === 's390x') {
  337. try {
  338. return require('./skia.linux-s390x-gnu.node')
  339. } catch (e) {
  340. loadErrors.push(e)
  341. }
  342. try {
  343. return require('@napi-rs/canvas-linux-s390x-gnu')
  344. } catch (e) {
  345. loadErrors.push(e)
  346. }
  347. } else {
  348. loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
  349. }
  350. } else if (process.platform === 'openharmony') {
  351. if (process.arch === 'arm64') {
  352. try {
  353. return require('./skia.openharmony-arm64.node')
  354. } catch (e) {
  355. loadErrors.push(e)
  356. }
  357. try {
  358. return require('@napi-rs/canvas-openharmony-arm64')
  359. } catch (e) {
  360. loadErrors.push(e)
  361. }
  362. } else if (process.arch === 'x64') {
  363. try {
  364. return require('./skia.openharmony-x64.node')
  365. } catch (e) {
  366. loadErrors.push(e)
  367. }
  368. try {
  369. return require('@napi-rs/canvas-openharmony-x64')
  370. } catch (e) {
  371. loadErrors.push(e)
  372. }
  373. } else if (process.arch === 'arm') {
  374. try {
  375. return require('./skia.openharmony-arm.node')
  376. } catch (e) {
  377. loadErrors.push(e)
  378. }
  379. try {
  380. const binding = require('@napi-rs/canvas-openharmony-arm')
  381. return binding
  382. } catch (e) {
  383. loadErrors.push(e)
  384. }
  385. } else {
  386. loadErrors.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`))
  387. }
  388. } else {
  389. loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
  390. }
  391. }
  392. nativeBinding = requireNative()
  393. if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
  394. let wasiBinding = null
  395. let wasiBindingError = null
  396. try {
  397. wasiBinding = require('./skia.wasi.cjs')
  398. nativeBinding = wasiBinding
  399. } catch (err) {
  400. if (process.env.NAPI_RS_FORCE_WASI) {
  401. wasiBindingError = err
  402. }
  403. }
  404. if (!nativeBinding) {
  405. try {
  406. wasiBinding = require('@napi-rs/canvas-wasm32-wasi')
  407. nativeBinding = wasiBinding
  408. } catch (err) {
  409. if (process.env.NAPI_RS_FORCE_WASI) {
  410. wasiBindingError.cause = err
  411. loadErrors.push(err)
  412. }
  413. }
  414. }
  415. }
  416. if (!nativeBinding) {
  417. if (loadErrors.length > 0) {
  418. throw new Error(
  419. `Cannot find native binding. ` +
  420. `npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
  421. 'Please try `npm i` again after removing both package-lock.json and node_modules directory.',
  422. {
  423. cause: loadErrors.reduce((err, cur) => {
  424. cur.cause = err
  425. return cur
  426. }),
  427. },
  428. )
  429. }
  430. throw new Error(`Failed to load native binding`)
  431. }
  432. module.exports = nativeBinding
  433. module.exports.GlobalFonts = nativeBinding.GlobalFonts
  434. module.exports.CanvasElement = nativeBinding.CanvasElement
  435. module.exports.CanvasGradient = nativeBinding.CanvasGradient
  436. module.exports.CanvasPattern = nativeBinding.CanvasPattern
  437. module.exports.CanvasRenderingContext2D = nativeBinding.CanvasRenderingContext2D
  438. module.exports.FontKey = nativeBinding.FontKey
  439. module.exports.Image = nativeBinding.Image
  440. module.exports.ImageData = nativeBinding.ImageData
  441. module.exports.Path = nativeBinding.Path
  442. module.exports.PdfDocument = nativeBinding.PdfDocument
  443. module.exports.SVGCanvas = nativeBinding.SVGCanvas
  444. module.exports.ChromaSubsampling = nativeBinding.ChromaSubsampling
  445. module.exports.clearAllCache = nativeBinding.clearAllCache
  446. module.exports.convertSVGTextToPath = nativeBinding.convertSVGTextToPath
  447. module.exports.FillType = nativeBinding.FillType
  448. module.exports.PathOp = nativeBinding.PathOp
  449. module.exports.StrokeCap = nativeBinding.StrokeCap
  450. module.exports.StrokeJoin = nativeBinding.StrokeJoin
  451. module.exports.SvgExportFlag = nativeBinding.SvgExportFlag
  452. module.exports.GifEncoder = nativeBinding.GifEncoder
  453. module.exports.GifDisposal = nativeBinding.GifDisposal