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,238 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
function _assert() {
const data = _interopRequireDefault(require("assert"));
_assert = function () {
return data;
};
return data;
}
function _stream() {
const data = require("stream");
_stream = 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 _posthtml() {
const data = _interopRequireDefault(require("posthtml"));
_posthtml = function () {
return data;
};
return data;
}
function _nullthrows() {
const data = _interopRequireDefault(require("nullthrows"));
_nullthrows = function () {
return data;
};
return data;
}
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// https://www.w3.org/TR/html5/dom.html#metadata-content-2
const metadataContent = new Set(['base', 'link', 'meta', 'noscript',
// 'script', // retain script order (somewhat)
'style', 'template', 'title']);
var _default = exports.default = new (_plugin().Packager)({
async loadConfig({
config
}) {
var _posthtmlConfig$conte;
let posthtmlConfig = await config.getConfig(['.posthtmlrc', '.posthtmlrc.js', '.posthtmlrc.cjs', '.posthtmlrc.mjs', 'posthtml.config.js', 'posthtml.config.cjs', 'posthtml.config.mjs'], {
packageKey: 'posthtml'
});
return {
render: posthtmlConfig === null || posthtmlConfig === void 0 || (_posthtmlConfig$conte = posthtmlConfig.contents) === null || _posthtmlConfig$conte === void 0 ? void 0 : _posthtmlConfig$conte.render
};
},
async package({
bundle,
bundleGraph,
getInlineBundleContents,
config
}) {
let assets = [];
bundle.traverseAssets(asset => {
assets.push(asset);
});
_assert().default.equal(assets.length, 1, 'HTML bundles must only contain one asset');
let asset = assets[0];
let code = await asset.getCode();
// Add bundles in the same bundle group that are not inline. For example, if two inline
// bundles refer to the same library that is extracted into a shared bundle.
let referencedBundles = [...(0, _utils().setDifference)(new Set(bundleGraph.getReferencedBundles(bundle)), new Set(bundleGraph.getReferencedBundles(bundle, {
recursive: false
})))];
let renderConfig = config === null || config === void 0 ? void 0 : config.render;
let {
html
} = await (0, _posthtml().default)([tree => insertBundleReferences(referencedBundles, tree), tree => replaceInlineAssetContent(bundleGraph, getInlineBundleContents, tree)]).process(code, {
...renderConfig,
xmlMode: bundle.type === 'xhtml',
closingSingleTag: bundle.type === 'xhtml' ? 'slash' : undefined
});
let {
contents,
map
} = (0, _utils().replaceURLReferences)({
bundle,
bundleGraph,
contents: html,
relative: false,
getReplacement: contents => contents.replace(/"/g, '"')
});
return (0, _utils().replaceInlineReferences)({
bundle,
bundleGraph,
contents,
getInlineBundleContents,
getInlineReplacement: (dep, inlineType, contents) => ({
from: dep.id,
to: contents.replace(/"/g, '"').trim()
}),
map
});
}
});
async function getAssetContent(bundleGraph, getInlineBundleContents, assetId) {
let inlineBundle;
bundleGraph.traverseBundles((bundle, context, {
stop
}) => {
let entryAssets = bundle.getEntryAssets();
if (entryAssets.some(a => a.uniqueKey === assetId)) {
inlineBundle = bundle;
stop();
}
});
if (inlineBundle) {
const bundleResult = await getInlineBundleContents(inlineBundle, bundleGraph);
return {
bundle: inlineBundle,
contents: bundleResult.contents
};
}
return null;
}
async function replaceInlineAssetContent(bundleGraph, getInlineBundleContents, tree) {
const inlineNodes = [];
tree.walk(node => {
if (node.attrs && node.attrs['data-parcel-key']) {
inlineNodes.push(node);
}
return node;
});
for (let node of inlineNodes) {
let newContent = await getAssetContent(bundleGraph, getInlineBundleContents, node.attrs['data-parcel-key']);
if (newContent != null) {
let {
contents,
bundle
} = newContent;
node.content = (contents instanceof _stream().Readable ? await (0, _utils().bufferStream)(contents) : contents).toString();
if (node.tag === 'script' && (0, _nullthrows().default)(bundle).env.outputFormat === 'esmodule') {
node.attrs.type = 'module';
}
// Escape closing script tags and HTML comments in JS content.
// https://www.w3.org/TR/html52/semantics-scripting.html#restrictions-for-contents-of-script-elements
// Avoid replacing </script with <\/script as it would break the following valid JS: 0</script/ (i.e. regexp literal).
// Instead, escape the s character.
if (node.tag === 'script') {
node.content = node.content.replace(/<!--/g, '<\\!--').replace(/<\/(script)/gi, '</\\$1');
}
// Escape closing style tags in CSS content.
if (node.tag === 'style') {
node.content = node.content.replace(/<\/(style)/gi, '<\\/$1');
}
// remove attr from output
delete node.attrs['data-parcel-key'];
}
}
return tree;
}
function insertBundleReferences(siblingBundles, tree) {
const bundles = [];
for (let bundle of siblingBundles) {
if (bundle.type === 'css') {
bundles.push({
tag: 'link',
attrs: {
rel: 'stylesheet',
href: (0, _utils().urlJoin)(bundle.target.publicUrl, bundle.name)
}
});
} else if (bundle.type === 'js') {
let nomodule = bundle.env.outputFormat !== 'esmodule' && bundle.env.sourceType === 'module' && bundle.env.shouldScopeHoist;
bundles.push({
tag: 'script',
attrs: {
type: bundle.env.outputFormat === 'esmodule' ? 'module' : undefined,
nomodule: nomodule ? '' : undefined,
defer: nomodule ? '' : undefined,
src: (0, _utils().urlJoin)(bundle.target.publicUrl, bundle.name)
}
});
}
}
addBundlesToTree(bundles, tree);
}
function addBundlesToTree(bundles, tree) {
const main = find(tree, 'head') || find(tree, 'html');
const content = main ? main.content || (main.content = []) : tree;
const index = findBundleInsertIndex(content);
content.splice(index, 0, ...bundles);
}
function find(tree, tag) {
let res;
tree.match({
tag
}, node => {
res = node;
return node;
});
return res;
}
function findBundleInsertIndex(content) {
// HTML document order (https://html.spec.whatwg.org/multipage/syntax.html#writing)
// - Any number of comments and ASCII whitespace.
// - A DOCTYPE.
// - Any number of comments and ASCII whitespace.
// - The document element, in the form of an html element.
// - Any number of comments and ASCII whitespace.
//
// -> Insert before first non-metadata (or script) element; if none was found, after the doctype
let doctypeIndex;
for (let index = 0; index < content.length; index++) {
const node = content[index];
if (node && node.tag && !metadataContent.has(node.tag)) {
return index;
}
if (typeof node === 'string' && node.toLowerCase().startsWith('<!doctype')) {
doctypeIndex = index;
}
}
return doctypeIndex ? doctypeIndex + 1 : 0;
}

View File

@@ -0,0 +1,30 @@
{
"name": "@parcel/packager-html",
"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/HTMLPackager.js",
"source": "src/HTMLPackager.js",
"engines": {
"node": ">= 12.0.0",
"parcel": "^2.12.0"
},
"dependencies": {
"@parcel/plugin": "2.12.0",
"@parcel/types": "2.12.0",
"@parcel/utils": "2.12.0",
"nullthrows": "^1.1.1",
"posthtml": "^0.16.5"
},
"gitHead": "2059029ee91e5f03a273b0954d3e629d7375f986"
}

View File

@@ -0,0 +1,259 @@
// @flow strict-local
import type {Bundle, BundleGraph, NamedBundle} from '@parcel/types';
import assert from 'assert';
import {Readable} from 'stream';
import {Packager} from '@parcel/plugin';
import {setDifference} from '@parcel/utils';
import posthtml from 'posthtml';
import {
bufferStream,
replaceInlineReferences,
replaceURLReferences,
urlJoin,
} from '@parcel/utils';
import nullthrows from 'nullthrows';
// https://www.w3.org/TR/html5/dom.html#metadata-content-2
const metadataContent = new Set([
'base',
'link',
'meta',
'noscript',
// 'script', // retain script order (somewhat)
'style',
'template',
'title',
]);
export default (new Packager({
async loadConfig({config}) {
let posthtmlConfig = await config.getConfig(
[
'.posthtmlrc',
'.posthtmlrc.js',
'.posthtmlrc.cjs',
'.posthtmlrc.mjs',
'posthtml.config.js',
'posthtml.config.cjs',
'posthtml.config.mjs',
],
{
packageKey: 'posthtml',
},
);
return {
render: posthtmlConfig?.contents?.render,
};
},
async package({bundle, bundleGraph, getInlineBundleContents, config}) {
let assets = [];
bundle.traverseAssets(asset => {
assets.push(asset);
});
assert.equal(assets.length, 1, 'HTML bundles must only contain one asset');
let asset = assets[0];
let code = await asset.getCode();
// Add bundles in the same bundle group that are not inline. For example, if two inline
// bundles refer to the same library that is extracted into a shared bundle.
let referencedBundles = [
...setDifference(
new Set(bundleGraph.getReferencedBundles(bundle)),
new Set(bundleGraph.getReferencedBundles(bundle, {recursive: false})),
),
];
let renderConfig = config?.render;
let {html} = await posthtml([
tree => insertBundleReferences(referencedBundles, tree),
tree =>
replaceInlineAssetContent(bundleGraph, getInlineBundleContents, tree),
]).process(code, {
...renderConfig,
xmlMode: bundle.type === 'xhtml',
closingSingleTag: bundle.type === 'xhtml' ? 'slash' : undefined,
});
let {contents, map} = replaceURLReferences({
bundle,
bundleGraph,
contents: html,
relative: false,
getReplacement: contents => contents.replace(/"/g, '&quot;'),
});
return replaceInlineReferences({
bundle,
bundleGraph,
contents,
getInlineBundleContents,
getInlineReplacement: (dep, inlineType, contents) => ({
from: dep.id,
to: contents.replace(/"/g, '&quot;').trim(),
}),
map,
});
},
}): Packager);
async function getAssetContent(
bundleGraph: BundleGraph<NamedBundle>,
getInlineBundleContents,
assetId,
) {
let inlineBundle: ?Bundle;
bundleGraph.traverseBundles((bundle, context, {stop}) => {
let entryAssets = bundle.getEntryAssets();
if (entryAssets.some(a => a.uniqueKey === assetId)) {
inlineBundle = bundle;
stop();
}
});
if (inlineBundle) {
const bundleResult = await getInlineBundleContents(
inlineBundle,
bundleGraph,
);
return {bundle: inlineBundle, contents: bundleResult.contents};
}
return null;
}
async function replaceInlineAssetContent(
bundleGraph: BundleGraph<NamedBundle>,
getInlineBundleContents,
tree,
) {
const inlineNodes = [];
tree.walk(node => {
if (node.attrs && node.attrs['data-parcel-key']) {
inlineNodes.push(node);
}
return node;
});
for (let node of inlineNodes) {
let newContent = await getAssetContent(
bundleGraph,
getInlineBundleContents,
node.attrs['data-parcel-key'],
);
if (newContent != null) {
let {contents, bundle} = newContent;
node.content = (
contents instanceof Readable ? await bufferStream(contents) : contents
).toString();
if (
node.tag === 'script' &&
nullthrows(bundle).env.outputFormat === 'esmodule'
) {
node.attrs.type = 'module';
}
// Escape closing script tags and HTML comments in JS content.
// https://www.w3.org/TR/html52/semantics-scripting.html#restrictions-for-contents-of-script-elements
// Avoid replacing </script with <\/script as it would break the following valid JS: 0</script/ (i.e. regexp literal).
// Instead, escape the s character.
if (node.tag === 'script') {
node.content = node.content
.replace(/<!--/g, '<\\!--')
.replace(/<\/(script)/gi, '</\\$1');
}
// Escape closing style tags in CSS content.
if (node.tag === 'style') {
node.content = node.content.replace(/<\/(style)/gi, '<\\/$1');
}
// remove attr from output
delete node.attrs['data-parcel-key'];
}
}
return tree;
}
function insertBundleReferences(siblingBundles, tree) {
const bundles = [];
for (let bundle of siblingBundles) {
if (bundle.type === 'css') {
bundles.push({
tag: 'link',
attrs: {
rel: 'stylesheet',
href: urlJoin(bundle.target.publicUrl, bundle.name),
},
});
} else if (bundle.type === 'js') {
let nomodule =
bundle.env.outputFormat !== 'esmodule' &&
bundle.env.sourceType === 'module' &&
bundle.env.shouldScopeHoist;
bundles.push({
tag: 'script',
attrs: {
type: bundle.env.outputFormat === 'esmodule' ? 'module' : undefined,
nomodule: nomodule ? '' : undefined,
defer: nomodule ? '' : undefined,
src: urlJoin(bundle.target.publicUrl, bundle.name),
},
});
}
}
addBundlesToTree(bundles, tree);
}
function addBundlesToTree(bundles, tree) {
const main = find(tree, 'head') || find(tree, 'html');
const content = main ? main.content || (main.content = []) : tree;
const index = findBundleInsertIndex(content);
content.splice(index, 0, ...bundles);
}
function find(tree, tag) {
let res;
tree.match({tag}, node => {
res = node;
return node;
});
return res;
}
function findBundleInsertIndex(content) {
// HTML document order (https://html.spec.whatwg.org/multipage/syntax.html#writing)
// - Any number of comments and ASCII whitespace.
// - A DOCTYPE.
// - Any number of comments and ASCII whitespace.
// - The document element, in the form of an html element.
// - Any number of comments and ASCII whitespace.
//
// -> Insert before first non-metadata (or script) element; if none was found, after the doctype
let doctypeIndex;
for (let index = 0; index < content.length; index++) {
const node = content[index];
if (node && node.tag && !metadataContent.has(node.tag)) {
return index;
}
if (
typeof node === 'string' &&
node.toLowerCase().startsWith('<!doctype')
) {
doctypeIndex = index;
}
}
return doctypeIndex ? doctypeIndex + 1 : 0;
}