larry babby and threejs for glsl

This commit is contained in:
Sam
2024-06-24 21:24:00 +12:00
parent 87d5dc634d
commit 907ebae4c0
6474 changed files with 1279596 additions and 8 deletions

View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2017-present Devon Govett
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,170 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
function _nullthrows() {
const data = _interopRequireDefault(require("nullthrows"));
_nullthrows = function () {
return data;
};
return data;
}
function _core() {
const data = require("@swc/core");
_core = function () {
return data;
};
return data;
}
function _plugin() {
const data = require("@parcel/plugin");
_plugin = function () {
return data;
};
return data;
}
function _utils() {
const data = require("@parcel/utils");
_utils = function () {
return data;
};
return data;
}
function _sourceMap() {
const data = _interopRequireDefault(require("@parcel/source-map"));
_sourceMap = function () {
return data;
};
return data;
}
function _diagnostic() {
const data = _interopRequireWildcard(require("@parcel/diagnostic"));
_diagnostic = function () {
return data;
};
return data;
}
function _path() {
const data = _interopRequireDefault(require("path"));
_path = function () {
return data;
};
return data;
}
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _default = exports.default = new (_plugin().Optimizer)({
async loadConfig({
config,
options
}) {
let userConfig = await config.getConfigFrom(_path().default.join(options.projectRoot, 'index'), ['.terserrc', '.terserrc.js', '.terserrc.cjs', '.terserrc.mjs']);
return userConfig === null || userConfig === void 0 ? void 0 : userConfig.contents;
},
async optimize({
contents,
map: originalMap,
bundle,
config: userConfig,
options,
getSourceMapReference
}) {
if (!bundle.env.shouldOptimize) {
return {
contents,
map: originalMap
};
}
let code = await (0, _utils().blobToString)(contents);
let result;
try {
result = await (0, _core().transform)(code, {
jsc: {
target: 'es2022',
minify: {
mangle: true,
compress: true,
...userConfig,
toplevel: bundle.env.outputFormat === 'esmodule' || bundle.env.outputFormat === 'commonjs',
module: bundle.env.outputFormat === 'esmodule'
}
},
minify: true,
sourceMaps: !!bundle.env.sourceMap,
configFile: false,
swcrc: false
});
} catch (err) {
// SWC doesn't give us nice error objects, so we need to parse the message.
let message = (0, _diagnostic().escapeMarkdown)(((0, _utils().stripAnsi)(err.message).split('\n').find(line => line.trim().length > 0) || '').trim().replace(/^(×|x)\s+/, ''));
let location = err.message.match(/(?:╭─|,-)\[(\d+):(\d+)\]/);
if (location) {
let line = Number(location[1]);
let col = Number(location[1]);
let mapping = originalMap === null || originalMap === void 0 ? void 0 : originalMap.findClosestMapping(line, col);
if (mapping && mapping.original && mapping.source) {
let {
source,
original
} = mapping;
let filePath = _path().default.resolve(options.projectRoot, source);
throw new (_diagnostic().default)({
diagnostic: {
message,
origin: '@parcel/optimizer-swc',
codeFrames: [{
language: 'js',
filePath,
codeHighlights: [{
start: original,
end: original
}]
}]
}
});
}
let loc = {
line: line,
column: col
};
throw new (_diagnostic().default)({
diagnostic: {
message,
origin: '@parcel/optimizer-swc',
codeFrames: [{
language: 'js',
filePath: undefined,
code,
codeHighlights: [{
start: loc,
end: loc
}]
}]
}
});
}
throw err;
}
let sourceMap = null;
let minifiedContents = (0, _nullthrows().default)(result.code);
let resultMap = result.map;
if (resultMap) {
sourceMap = new (_sourceMap().default)(options.projectRoot);
sourceMap.addVLQMap(JSON.parse(resultMap));
if (originalMap) {
sourceMap.extends(originalMap);
}
let sourcemapReference = await getSourceMapReference(sourceMap);
if (sourcemapReference) {
minifiedContents += `\n//# sourceMappingURL=${sourcemapReference}\n`;
}
}
return {
contents: minifiedContents,
map: sourceMap
};
}
});

View File

@@ -0,0 +1,31 @@
{
"name": "@parcel/optimizer-swc",
"version": "2.12.0",
"license": "MIT",
"publishConfig": {
"access": "public"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/parcel"
},
"repository": {
"type": "git",
"url": "https://github.com/parcel-bundler/parcel.git"
},
"main": "lib/SwcOptimizer.js",
"source": "src/SwcOptimizer.js",
"engines": {
"node": ">= 12.0.0",
"parcel": "^2.12.0"
},
"dependencies": {
"@parcel/diagnostic": "2.12.0",
"@parcel/plugin": "2.12.0",
"@parcel/source-map": "^2.1.1",
"@parcel/utils": "2.12.0",
"@swc/core": "^1.3.36",
"nullthrows": "^1.1.1"
},
"gitHead": "2059029ee91e5f03a273b0954d3e629d7375f986"
}

View File

@@ -0,0 +1,128 @@
// @flow
import nullthrows from 'nullthrows';
import {transform} from '@swc/core';
import {Optimizer} from '@parcel/plugin';
import {blobToString, stripAnsi} from '@parcel/utils';
import SourceMap from '@parcel/source-map';
import ThrowableDiagnostic, {escapeMarkdown} from '@parcel/diagnostic';
import path from 'path';
export default (new Optimizer({
async loadConfig({config, options}) {
let userConfig = await config.getConfigFrom(
path.join(options.projectRoot, 'index'),
['.terserrc', '.terserrc.js', '.terserrc.cjs', '.terserrc.mjs'],
);
return userConfig?.contents;
},
async optimize({
contents,
map: originalMap,
bundle,
config: userConfig,
options,
getSourceMapReference,
}) {
if (!bundle.env.shouldOptimize) {
return {contents, map: originalMap};
}
let code = await blobToString(contents);
let result;
try {
result = await transform(code, {
jsc: {
target: 'es2022',
minify: {
mangle: true,
compress: true,
...userConfig,
toplevel:
bundle.env.outputFormat === 'esmodule' ||
bundle.env.outputFormat === 'commonjs',
module: bundle.env.outputFormat === 'esmodule',
},
},
minify: true,
sourceMaps: !!bundle.env.sourceMap,
configFile: false,
swcrc: false,
});
} catch (err) {
// SWC doesn't give us nice error objects, so we need to parse the message.
let message = escapeMarkdown(
(
stripAnsi(err.message)
.split('\n')
.find(line => line.trim().length > 0) || ''
)
.trim()
.replace(/^(×|x)\s+/, ''),
);
let location = err.message.match(/(?:╭─|,-)\[(\d+):(\d+)\]/);
if (location) {
let line = Number(location[1]);
let col = Number(location[1]);
let mapping = originalMap?.findClosestMapping(line, col);
if (mapping && mapping.original && mapping.source) {
let {source, original} = mapping;
let filePath = path.resolve(options.projectRoot, source);
throw new ThrowableDiagnostic({
diagnostic: {
message,
origin: '@parcel/optimizer-swc',
codeFrames: [
{
language: 'js',
filePath,
codeHighlights: [{start: original, end: original}],
},
],
},
});
}
let loc = {
line: line,
column: col,
};
throw new ThrowableDiagnostic({
diagnostic: {
message,
origin: '@parcel/optimizer-swc',
codeFrames: [
{
language: 'js',
filePath: undefined,
code,
codeHighlights: [{start: loc, end: loc}],
},
],
},
});
}
throw err;
}
let sourceMap = null;
let minifiedContents: string = nullthrows(result.code);
let resultMap = result.map;
if (resultMap) {
sourceMap = new SourceMap(options.projectRoot);
sourceMap.addVLQMap(JSON.parse(resultMap));
if (originalMap) {
sourceMap.extends(originalMap);
}
let sourcemapReference = await getSourceMapReference(sourceMap);
if (sourcemapReference) {
minifiedContents += `\n//# sourceMappingURL=${sourcemapReference}\n`;
}
}
return {contents: minifiedContents, map: sourceMap};
},
}): Optimizer);