initial commit

This commit is contained in:
Zoe
2023-01-03 09:29:04 -06:00
commit 7851137d88
12889 changed files with 2557443 additions and 0 deletions

143
node_modules/@rollup/plugin-wasm/README.md generated vendored Executable file
View File

@@ -0,0 +1,143 @@
[npm]: https://img.shields.io/npm/v/@rollup/plugin-wasm
[npm-url]: https://www.npmjs.com/package/@rollup/plugin-wasm
[size]: https://packagephobia.now.sh/badge?p=@rollup/plugin-wasm
[size-url]: https://packagephobia.now.sh/result?p=@rollup/plugin-wasm
[![npm][npm]][npm-url]
[![size][size]][size-url]
[![libera manifesto](https://img.shields.io/badge/libera-manifesto-lightgrey.svg)](https://liberamanifesto.com)
# @rollup/plugin-wasm
🍣 A Rollup which allows importing and bundling [WebAssembly modules](http://webassembly.org).
WebAssembly Modules are imported asynchronous as base64 strings. Small modules [can be imported synchronously](#synchronous-modules).
## Requirements
This plugin requires an [LTS](https://github.com/nodejs/Release) Node version (v14.0.0+) and Rollup v1.20.0+.
## Install
Using npm:
```console
npm install @rollup/plugin-wasm --save-dev
```
## Usage
Create a `rollup.config.js` [configuration file](https://www.rollupjs.org/guide/en/#configuration-files) and import the plugin:
```js
import { wasm } from '@rollup/plugin-wasm';
export default {
input: 'src/index.js',
output: {
dir: 'output',
format: 'cjs'
},
plugins: [wasm()]
};
```
Then call `rollup` either via the [CLI](https://www.rollupjs.org/guide/en/#command-line-reference) or the [API](https://www.rollupjs.org/guide/en/#javascript-api).
## Options
### `sync`
Type: `Array[...String]`<br>
Default: `null`
Specifies an array of strings that each represent a WebAssembly file to load synchronously. See [Synchronous Modules](#synchronous-modules) for a functional example.
### `maxFileSize`
Type: `Number`<br>
Default: `14336` (14kb)
The maximum file size for inline files. If a file exceeds this limit, it will be copied to the destination folder and loaded from a separate file at runtime. If `maxFileSize` is set to `0` all files will be copied.
Files specified in `sync` to load synchronously are always inlined, regardless of size.
### `fileName`
Type: `String`<br>
Default: `'[hash][extname]'`
This option can be used to rename the emitted Wasm files. It accepts the following string replacements:
- `[hash]` - The hash value of the file's contents
- `[name]` - The name of the imported file (without its file extension)
- `[extname]` - The extension of the imported file (including the leading `.`)
### `publicPath`
Type: `String`<br>
Default: (empty string)
A string which will be added in front of filenames when they are not inlined but are copied.
### `targetEnv`
Type: `"auto" | "browser" | "node"`<br>
Default: `"auto"`
Configures what code is emitted to instantiate the Wasm (both inline and separate):
- `"auto"` will determine the environment at runtime and invoke the correct methods accordingly
- `"auto-inline"` always inlines the Wasm and will decode it according to the environment
- `"browser"` omits emitting code that requires node.js builtin modules that may play havoc on downstream bundlers
- `"node"` omits emitting code that requires `fetch`
## WebAssembly Example
Given the following simple C file:
```c
int main() {
return 42;
}
```
Compile the file using `emscripten`, or the online [WasmFiddle](https://wasdk.github.io/WasmFiddle//) tool. Then import and instantiate the resulting file:
```js
import sample from './sample.wasm';
sample({ ...imports }).then(({ instance }) => {
console.log(instance.exports.main());
});
```
The WebAssembly is inlined as a base64 encoded string. At runtime the string is decoded and a module is returned.
_Note: The base64 string that represents the WebAssembly within the bundle will be ~33% larger than the original file._
### Synchronous Modules
Small modules (< 4KB) can be compiled synchronously by specifying them in the configuration.
```js
wasm({
sync: ['web/sample.wasm', 'web/foobar.wasm']
});
```
This means that the exports can be accessed immediately.
```js
import sample from './sample.wasm';
const instance = sample({ ...imports });
console.log(instance.exports.main());
```
## Meta
[CONTRIBUTING](/.github/CONTRIBUTING.md)
[LICENSE (MIT)](/LICENSE)

224
node_modules/@rollup/plugin-wasm/dist/cjs/index.js generated vendored Normal file
View File

@@ -0,0 +1,224 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var fs = require('fs');
var path = require('path');
var crypto = require('crypto');
function _interopNamespaceDefault(e) {
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n.default = e;
return Object.freeze(n);
}
var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
const HELPERS_ID = '\0wasmHelpers.js';
const nodeFilePath = `
var fs = require("fs")
var path = require("path")
return new Promise((resolve, reject) => {
fs.readFile(path.resolve(__dirname, filepath), (error, buffer) => {
if (error != null) {
reject(error)
} else {
resolve(_instantiateOrCompile(buffer, imports, false))
}
});
});
`;
const nodeDecode = `
buf = Buffer.from(src, 'base64')
`;
const browserFilePath = `
return _instantiateOrCompile(fetch(filepath), imports, true);
`;
const browserDecode = `
var raw = globalThis.atob(src)
var rawLength = raw.length
buf = new Uint8Array(new ArrayBuffer(rawLength))
for(var i = 0; i < rawLength; i++) {
buf[i] = raw.charCodeAt(i)
}
`;
const autoModule = `
var buf = null
var isNode = typeof process !== 'undefined' && process.versions != null && process.versions.node != null
if (filepath && isNode) {
${nodeFilePath}
} else if (filepath) {
${browserFilePath}
}
if (isNode) {
${nodeDecode}
} else {
${browserDecode}
}
`;
const nodeModule = `
var buf = null
if (filepath) {
${nodeFilePath}
}
${nodeDecode}
`;
const browserModule = `
var buf = null
if (filepath) {
${browserFilePath}
}
${browserDecode}
`;
const autoInlineModule = `
var buf = null
var isNode = typeof process !== 'undefined' && process.versions != null && process.versions.node != null
if (isNode) {
${nodeDecode}
} else {
${browserDecode}
}
`;
const envModule = (env) => {
switch (env) {
case 'auto':
return autoModule;
case 'auto-inline':
return autoInlineModule;
case 'browser':
return browserModule;
case 'node':
return nodeModule;
default:
return null;
}
};
const getHelpersModule = (env) => `
function _loadWasmModule (sync, filepath, src, imports) {
function _instantiateOrCompile(source, imports, stream) {
var instantiateFunc = stream ? WebAssembly.instantiateStreaming : WebAssembly.instantiate;
var compileFunc = stream ? WebAssembly.compileStreaming : WebAssembly.compile;
if (imports) {
return instantiateFunc(source, imports)
} else {
return compileFunc(source)
}
}
${envModule(env)}
if(sync) {
var mod = new WebAssembly.Module(buf)
return imports ? new WebAssembly.Instance(mod, imports) : mod
} else {
return _instantiateOrCompile(buf, imports, false)
}
}
export { _loadWasmModule };
`;
function wasm(options = {}) {
const { sync = [], maxFileSize = 14 * 1024, publicPath = '', targetEnv = 'auto', fileName = '[hash][extname]' } = options;
const syncFiles = sync.map((x) => path__namespace.resolve(x));
const copies = Object.create(null);
return {
name: 'wasm',
resolveId(id) {
if (id === HELPERS_ID) {
return id;
}
return null;
},
load(id) {
if (id === HELPERS_ID) {
return getHelpersModule(targetEnv);
}
if (!/\.wasm$/.test(id)) {
return null;
}
return Promise.all([fs__namespace.promises.stat(id), fs__namespace.promises.readFile(id)]).then(([stats, buffer]) => {
if (targetEnv === 'auto-inline') {
return buffer.toString('binary');
}
if ((maxFileSize && stats.size > maxFileSize) || maxFileSize === 0) {
const hash = crypto.createHash('sha1').update(buffer).digest('hex').substr(0, 16);
const ext = path__namespace.extname(id);
const name = path__namespace.basename(id, ext);
const outputFileName = fileName
.replace(/\[hash\]/g, hash)
.replace(/\[extname\]/g, ext)
.replace(/\[name\]/g, name);
const publicFilepath = `${publicPath}${outputFileName}`;
// only copy if the file is not marked `sync`, `sync` files are always inlined
if (syncFiles.indexOf(id) === -1) {
copies[id] = {
filename: outputFileName,
publicFilepath,
buffer
};
}
}
return buffer.toString('binary');
});
},
transform(code, id) {
if (code && /\.wasm$/.test(id)) {
const isSync = syncFiles.indexOf(id) !== -1;
const publicFilepath = copies[id] ? `'${copies[id].publicFilepath}'` : null;
let src;
if (publicFilepath === null) {
src = Buffer.from(code, 'binary').toString('base64');
src = `'${src}'`;
}
else {
if (isSync) {
this.error('non-inlined files can not be `sync`.');
}
src = null;
}
return {
map: {
mappings: ''
},
code: `import { _loadWasmModule } from ${JSON.stringify(HELPERS_ID)};
export default function(imports){return _loadWasmModule(${+isSync}, ${publicFilepath}, ${src}, imports)}`
};
}
return null;
},
generateBundle: async function write() {
await Promise.all(Object.keys(copies).map(async (name) => {
const copy = copies[name];
this.emitFile({
type: 'asset',
source: copy.buffer,
name: 'Rollup WASM Asset',
fileName: copy.filename
});
}));
}
};
}
exports.default = wasm;
exports.wasm = wasm;
module.exports = Object.assign(exports.default, exports);
//# sourceMappingURL=index.js.map

198
node_modules/@rollup/plugin-wasm/dist/es/index.js generated vendored Normal file
View File

@@ -0,0 +1,198 @@
import * as fs from 'fs';
import * as path from 'path';
import { createHash } from 'crypto';
const HELPERS_ID = '\0wasmHelpers.js';
const nodeFilePath = `
var fs = require("fs")
var path = require("path")
return new Promise((resolve, reject) => {
fs.readFile(path.resolve(__dirname, filepath), (error, buffer) => {
if (error != null) {
reject(error)
} else {
resolve(_instantiateOrCompile(buffer, imports, false))
}
});
});
`;
const nodeDecode = `
buf = Buffer.from(src, 'base64')
`;
const browserFilePath = `
return _instantiateOrCompile(fetch(filepath), imports, true);
`;
const browserDecode = `
var raw = globalThis.atob(src)
var rawLength = raw.length
buf = new Uint8Array(new ArrayBuffer(rawLength))
for(var i = 0; i < rawLength; i++) {
buf[i] = raw.charCodeAt(i)
}
`;
const autoModule = `
var buf = null
var isNode = typeof process !== 'undefined' && process.versions != null && process.versions.node != null
if (filepath && isNode) {
${nodeFilePath}
} else if (filepath) {
${browserFilePath}
}
if (isNode) {
${nodeDecode}
} else {
${browserDecode}
}
`;
const nodeModule = `
var buf = null
if (filepath) {
${nodeFilePath}
}
${nodeDecode}
`;
const browserModule = `
var buf = null
if (filepath) {
${browserFilePath}
}
${browserDecode}
`;
const autoInlineModule = `
var buf = null
var isNode = typeof process !== 'undefined' && process.versions != null && process.versions.node != null
if (isNode) {
${nodeDecode}
} else {
${browserDecode}
}
`;
const envModule = (env) => {
switch (env) {
case 'auto':
return autoModule;
case 'auto-inline':
return autoInlineModule;
case 'browser':
return browserModule;
case 'node':
return nodeModule;
default:
return null;
}
};
const getHelpersModule = (env) => `
function _loadWasmModule (sync, filepath, src, imports) {
function _instantiateOrCompile(source, imports, stream) {
var instantiateFunc = stream ? WebAssembly.instantiateStreaming : WebAssembly.instantiate;
var compileFunc = stream ? WebAssembly.compileStreaming : WebAssembly.compile;
if (imports) {
return instantiateFunc(source, imports)
} else {
return compileFunc(source)
}
}
${envModule(env)}
if(sync) {
var mod = new WebAssembly.Module(buf)
return imports ? new WebAssembly.Instance(mod, imports) : mod
} else {
return _instantiateOrCompile(buf, imports, false)
}
}
export { _loadWasmModule };
`;
function wasm(options = {}) {
const { sync = [], maxFileSize = 14 * 1024, publicPath = '', targetEnv = 'auto', fileName = '[hash][extname]' } = options;
const syncFiles = sync.map((x) => path.resolve(x));
const copies = Object.create(null);
return {
name: 'wasm',
resolveId(id) {
if (id === HELPERS_ID) {
return id;
}
return null;
},
load(id) {
if (id === HELPERS_ID) {
return getHelpersModule(targetEnv);
}
if (!/\.wasm$/.test(id)) {
return null;
}
return Promise.all([fs.promises.stat(id), fs.promises.readFile(id)]).then(([stats, buffer]) => {
if (targetEnv === 'auto-inline') {
return buffer.toString('binary');
}
if ((maxFileSize && stats.size > maxFileSize) || maxFileSize === 0) {
const hash = createHash('sha1').update(buffer).digest('hex').substr(0, 16);
const ext = path.extname(id);
const name = path.basename(id, ext);
const outputFileName = fileName
.replace(/\[hash\]/g, hash)
.replace(/\[extname\]/g, ext)
.replace(/\[name\]/g, name);
const publicFilepath = `${publicPath}${outputFileName}`;
// only copy if the file is not marked `sync`, `sync` files are always inlined
if (syncFiles.indexOf(id) === -1) {
copies[id] = {
filename: outputFileName,
publicFilepath,
buffer
};
}
}
return buffer.toString('binary');
});
},
transform(code, id) {
if (code && /\.wasm$/.test(id)) {
const isSync = syncFiles.indexOf(id) !== -1;
const publicFilepath = copies[id] ? `'${copies[id].publicFilepath}'` : null;
let src;
if (publicFilepath === null) {
src = Buffer.from(code, 'binary').toString('base64');
src = `'${src}'`;
}
else {
if (isSync) {
this.error('non-inlined files can not be `sync`.');
}
src = null;
}
return {
map: {
mappings: ''
},
code: `import { _loadWasmModule } from ${JSON.stringify(HELPERS_ID)};
export default function(imports){return _loadWasmModule(${+isSync}, ${publicFilepath}, ${src}, imports)}`
};
}
return null;
},
generateBundle: async function write() {
await Promise.all(Object.keys(copies).map(async (name) => {
const copy = copies[name];
this.emitFile({
type: 'asset',
source: copy.buffer,
name: 'Rollup WASM Asset',
fileName: copy.filename
});
}));
}
};
}
export { wasm as default, wasm };
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"type":"module"}

86
node_modules/@rollup/plugin-wasm/package.json generated vendored Normal file
View File

@@ -0,0 +1,86 @@
{
"name": "@rollup/plugin-wasm",
"version": "6.1.1",
"publishConfig": {
"access": "public"
},
"description": "Import WebAssembly code with Rollup",
"license": "MIT",
"repository": {
"url": "rollup/plugins",
"directory": "packages/wasm"
},
"author": "Jamen Marz <jamenmarz+gh@gmail.com>",
"homepage": "https://github.com/rollup/plugins/tree/master/packages/wasm/#readme",
"bugs": "https://github.com/rollup/plugins/issues",
"main": "./dist/cjs/index.js",
"module": "./dist/es/index.js",
"exports": {
"types": "./types/index.d.ts",
"import": "./dist/es/index.js",
"default": "./dist/cjs/index.js"
},
"engines": {
"node": ">=14.0.0"
},
"scripts": {
"build": "rollup -c",
"ci:coverage": "nyc pnpm test && nyc report --reporter=text-lcov > coverage.lcov",
"ci:lint": "pnpm build && pnpm lint",
"ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}",
"ci:test": "pnpm test -- --verbose",
"prebuild": "del-cli dist",
"prepare": "if [ ! -d 'dist' ]; then pnpm build; fi",
"prerelease": "pnpm build",
"pretest": "pnpm build",
"release": "pnpm --workspace-root plugin:release --pkg $npm_package_name",
"test": "ava",
"test:ts": "tsc --noEmit"
},
"files": [
"dist",
"!dist/**/*.map",
"types",
"README.md",
"LICENSE"
],
"keywords": [
"rollup",
"plugin",
"webassembly",
"import",
"wasm",
"wast",
"wat",
"emscripten"
],
"peerDependencies": {
"rollup": "^1.20.0||^2.0.0||^3.0.0"
},
"peerDependenciesMeta": {
"rollup": {
"optional": true
}
},
"devDependencies": {
"@rollup/plugin-typescript": "^9.0.1",
"del-cli": "^5.0.0",
"rollup": "^3.2.3",
"source-map": "^0.7.4",
"typescript": "^4.8.3"
},
"types": "./types/index.d.ts",
"ava": {
"workerThreads": false,
"files": [
"!**/fixtures/**",
"!**/helpers/**",
"!**/recipes/**",
"!**/types.ts"
]
},
"contributors": [
"Jamen Marz <jamenmarz+gh@gmail.com>",
"Colin Eberhardt <colin.eberhardt@gmail.com>"
]
}

40
node_modules/@rollup/plugin-wasm/types/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,40 @@
import type { Plugin } from 'rollup';
/**
* - `"auto"` will determine the environment at runtime and invoke the correct methods accordingly
* - `"auto-inline"` always inlines the Wasm and will decode it according to the environment
* - `"browser"` omits emitting code that requires node.js builtin modules that may play havoc on downstream bundlers
* - `"node"` omits emitting code that requires `fetch`
*/
export type TargetEnv = 'auto' | 'auto-inline' | 'browser' | 'node';
export interface RollupWasmOptions {
/**
* Specifies an array of strings that each represent a WebAssembly file to load synchronously.
*/
sync?: readonly string[];
/**
* The maximum file size for inline files. If a file exceeds this limit, it will be copied to the destination folder and loaded from a separate file at runtime.
* If `maxFileSize` is set to `0` all files will be copied.
* Files specified in `sync` to load synchronously are always inlined, regardless of size.
*/
maxFileSize?: Number;
/**
* String used to rename the emitted Wasm files.
*/
fileName?: string;
/**
* A string which will be added in front of filenames when they are not inlined but are copied.
*/
publicPath?: string;
/**
* Configures what code is emitted to instantiate the Wasm (both inline and separate)
*/
targetEnv?: TargetEnv;
}
/**
* 🍣 A Rollup which allows importing and bundling [WebAssembly modules](http://webassembly.org).
*/
export function wasm(options?: RollupWasmOptions): Plugin;
export default wasm;