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,224 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.PluginLogger = exports.INTERNAL_ORIGINAL_CONSOLE = void 0;
exports.patchConsole = patchConsole;
exports.unpatchConsole = unpatchConsole;
function _events() {
const data = require("@parcel/events");
_events = function () {
return data;
};
return data;
}
function _util() {
const data = require("util");
_util = function () {
return data;
};
return data;
}
function _diagnostic() {
const data = require("@parcel/diagnostic");
_diagnostic = function () {
return data;
};
return data;
}
class Logger {
#logEmitter /*: ValueEmitter<LogEvent> */ = new (_events().ValueEmitter)();
onLog(cb) {
return this.#logEmitter.addListener(cb);
}
verbose(diagnostic) {
this.#logEmitter.emit({
type: 'log',
level: 'verbose',
diagnostics: Array.isArray(diagnostic) ? diagnostic : [diagnostic]
});
}
info(diagnostic) {
this.log(diagnostic);
}
log(diagnostic) {
this.#logEmitter.emit({
type: 'log',
level: 'info',
diagnostics: Array.isArray(diagnostic) ? diagnostic : [diagnostic]
});
}
warn(diagnostic) {
this.#logEmitter.emit({
type: 'log',
level: 'warn',
diagnostics: Array.isArray(diagnostic) ? diagnostic : [diagnostic]
});
}
error(input, realOrigin) {
let diagnostic = (0, _diagnostic().anyToDiagnostic)(input);
if (typeof realOrigin === 'string') {
diagnostic = Array.isArray(diagnostic) ? diagnostic.map(d => {
return {
...d,
origin: realOrigin
};
}) : {
...diagnostic,
origin: realOrigin
};
}
this.#logEmitter.emit({
type: 'log',
level: 'error',
diagnostics: Array.isArray(diagnostic) ? diagnostic : [diagnostic]
});
}
progress(message) {
this.#logEmitter.emit({
type: 'log',
level: 'progress',
message
});
}
}
const logger = new Logger();
var _default = exports.default = logger;
/** @private */
class PluginLogger {
/** @private */
/** @private */
constructor(opts) {
this.origin = opts.origin;
}
/** @private */
updateOrigin(diagnostic) {
return Array.isArray(diagnostic) ? diagnostic.map(d => {
return {
...d,
origin: this.origin
};
}) : {
...diagnostic,
origin: this.origin
};
}
verbose(diagnostic) {
logger.verbose(this.updateOrigin(diagnostic));
}
info(diagnostic) {
logger.info(this.updateOrigin(diagnostic));
}
log(diagnostic) {
logger.log(this.updateOrigin(diagnostic));
}
warn(diagnostic) {
logger.warn(this.updateOrigin(diagnostic));
}
error(input) {
logger.error(input, this.origin);
}
/** @private */
progress(message) {
logger.progress(message);
}
}
/** @private */
exports.PluginLogger = PluginLogger;
const INTERNAL_ORIGINAL_CONSOLE = exports.INTERNAL_ORIGINAL_CONSOLE = {
...console
};
let consolePatched = false;
/**
* Patch `console` APIs within workers to forward their messages to the Logger
* at the appropriate levels.
* @private
*/
function patchConsole() {
// Skip if console is already patched...
if (consolePatched) return;
/* eslint-disable no-console */
// $FlowFixMe
console.log = console.info = (...messages) => {
logger.info(messagesToDiagnostic(messages));
};
// $FlowFixMe
console.debug = (...messages) => {
// TODO: dedicated debug level?
logger.verbose(messagesToDiagnostic(messages));
};
// $FlowFixMe
console.warn = (...messages) => {
logger.warn(messagesToDiagnostic(messages));
};
// $FlowFixMe
console.error = (...messages) => {
logger.error(messagesToDiagnostic(messages));
};
/* eslint-enable no-console */
consolePatched = true;
}
/** @private */
function unpatchConsole() {
// Skip if console isn't patched...
if (!consolePatched) return;
/* eslint-disable no-console */
// $FlowFixMe
console.log = INTERNAL_ORIGINAL_CONSOLE.log;
// $FlowFixMe
console.info = INTERNAL_ORIGINAL_CONSOLE.info;
// $FlowFixMe
console.debug = INTERNAL_ORIGINAL_CONSOLE.debug;
// $FlowFixMe
console.warn = INTERNAL_ORIGINAL_CONSOLE.warn;
// $FlowFixMe
console.error = INTERNAL_ORIGINAL_CONSOLE.error;
/* eslint-enable no-console */
consolePatched = false;
}
function messagesToDiagnostic(messages) {
if (messages.length === 1 && messages[0] instanceof Error) {
let error = messages[0];
let diagnostic = (0, _diagnostic().errorToDiagnostic)(error);
if (Array.isArray(diagnostic)) {
return diagnostic.map(d => {
return {
...d,
skipFormatting: true
};
});
} else {
return {
...diagnostic,
skipFormatting: true
};
}
} else {
return {
message: joinLogMessages(messages),
origin: 'console',
skipFormatting: true
};
}
}
function joinLogMessages(messages) {
return messages.map(m => typeof m === 'string' ? m : (0, _util().inspect)(m)).join(' ');
}

View File

@@ -0,0 +1,27 @@
{
"name": "@parcel/logger",
"version": "2.12.0",
"description": "Blazing fast, zero configuration web application bundler",
"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/Logger.js",
"source": "src/Logger.js",
"engines": {
"node": ">= 12.0.0"
},
"dependencies": {
"@parcel/diagnostic": "2.12.0",
"@parcel/events": "2.12.0"
},
"gitHead": "2059029ee91e5f03a273b0954d3e629d7375f986"
}

View File

@@ -0,0 +1,244 @@
// @flow strict-local
import type {
IDisposable,
LogEvent,
PluginLogger as IPluginLogger,
} from '@parcel/types';
import type {
Diagnostic,
Diagnostifiable,
DiagnosticWithoutOrigin,
} from '@parcel/diagnostic';
import {ValueEmitter} from '@parcel/events';
import {inspect} from 'util';
import {errorToDiagnostic, anyToDiagnostic} from '@parcel/diagnostic';
class Logger {
#logEmitter /*: ValueEmitter<LogEvent> */ = new ValueEmitter();
onLog(cb: (event: LogEvent) => mixed): IDisposable {
return this.#logEmitter.addListener(cb);
}
verbose(diagnostic: Diagnostic | Array<Diagnostic>): void {
this.#logEmitter.emit({
type: 'log',
level: 'verbose',
diagnostics: Array.isArray(diagnostic) ? diagnostic : [diagnostic],
});
}
info(diagnostic: Diagnostic | Array<Diagnostic>): void {
this.log(diagnostic);
}
log(diagnostic: Diagnostic | Array<Diagnostic>): void {
this.#logEmitter.emit({
type: 'log',
level: 'info',
diagnostics: Array.isArray(diagnostic) ? diagnostic : [diagnostic],
});
}
warn(diagnostic: Diagnostic | Array<Diagnostic>): void {
this.#logEmitter.emit({
type: 'log',
level: 'warn',
diagnostics: Array.isArray(diagnostic) ? diagnostic : [diagnostic],
});
}
error(input: Diagnostifiable, realOrigin?: string): void {
let diagnostic = anyToDiagnostic(input);
if (typeof realOrigin === 'string') {
diagnostic = Array.isArray(diagnostic)
? diagnostic.map(d => {
return {...d, origin: realOrigin};
})
: {
...diagnostic,
origin: realOrigin,
};
}
this.#logEmitter.emit({
type: 'log',
level: 'error',
diagnostics: Array.isArray(diagnostic) ? diagnostic : [diagnostic],
});
}
progress(message: string): void {
this.#logEmitter.emit({
type: 'log',
level: 'progress',
message,
});
}
}
const logger: Logger = new Logger();
export default logger;
/** @private */
export type PluginLoggerOpts = {|
origin: string,
|};
export class PluginLogger implements IPluginLogger {
/** @private */
origin: string;
/** @private */
constructor(opts: PluginLoggerOpts) {
this.origin = opts.origin;
}
/** @private */
updateOrigin(
diagnostic: DiagnosticWithoutOrigin | Array<DiagnosticWithoutOrigin>,
): Diagnostic | Array<Diagnostic> {
return Array.isArray(diagnostic)
? diagnostic.map(d => {
return {...d, origin: this.origin};
})
: {...diagnostic, origin: this.origin};
}
verbose(
diagnostic: DiagnosticWithoutOrigin | Array<DiagnosticWithoutOrigin>,
): void {
logger.verbose(this.updateOrigin(diagnostic));
}
info(
diagnostic: DiagnosticWithoutOrigin | Array<DiagnosticWithoutOrigin>,
): void {
logger.info(this.updateOrigin(diagnostic));
}
log(
diagnostic: DiagnosticWithoutOrigin | Array<DiagnosticWithoutOrigin>,
): void {
logger.log(this.updateOrigin(diagnostic));
}
warn(
diagnostic: DiagnosticWithoutOrigin | Array<DiagnosticWithoutOrigin>,
): void {
logger.warn(this.updateOrigin(diagnostic));
}
error(
input:
| Diagnostifiable
| DiagnosticWithoutOrigin
| Array<DiagnosticWithoutOrigin>,
): void {
logger.error(input, this.origin);
}
/** @private */
progress(message: string): void {
logger.progress(message);
}
}
/** @private */
export const INTERNAL_ORIGINAL_CONSOLE = {...console};
let consolePatched = false;
/**
* Patch `console` APIs within workers to forward their messages to the Logger
* at the appropriate levels.
* @private
*/
export function patchConsole() {
// Skip if console is already patched...
if (consolePatched) return;
/* eslint-disable no-console */
// $FlowFixMe
console.log = console.info = (...messages: Array<mixed>) => {
logger.info(messagesToDiagnostic(messages));
};
// $FlowFixMe
console.debug = (...messages: Array<mixed>) => {
// TODO: dedicated debug level?
logger.verbose(messagesToDiagnostic(messages));
};
// $FlowFixMe
console.warn = (...messages: Array<mixed>) => {
logger.warn(messagesToDiagnostic(messages));
};
// $FlowFixMe
console.error = (...messages: Array<mixed>) => {
logger.error(messagesToDiagnostic(messages));
};
/* eslint-enable no-console */
consolePatched = true;
}
/** @private */
export function unpatchConsole() {
// Skip if console isn't patched...
if (!consolePatched) return;
/* eslint-disable no-console */
// $FlowFixMe
console.log = INTERNAL_ORIGINAL_CONSOLE.log;
// $FlowFixMe
console.info = INTERNAL_ORIGINAL_CONSOLE.info;
// $FlowFixMe
console.debug = INTERNAL_ORIGINAL_CONSOLE.debug;
// $FlowFixMe
console.warn = INTERNAL_ORIGINAL_CONSOLE.warn;
// $FlowFixMe
console.error = INTERNAL_ORIGINAL_CONSOLE.error;
/* eslint-enable no-console */
consolePatched = false;
}
function messagesToDiagnostic(
messages: Array<mixed>,
): Diagnostic | Array<Diagnostic> {
if (messages.length === 1 && messages[0] instanceof Error) {
let error: Error = messages[0];
let diagnostic = errorToDiagnostic(error);
if (Array.isArray(diagnostic)) {
return diagnostic.map(d => {
return {
...d,
skipFormatting: true,
};
});
} else {
return {
...diagnostic,
skipFormatting: true,
};
}
} else {
return {
message: joinLogMessages(messages),
origin: 'console',
skipFormatting: true,
};
}
}
function joinLogMessages(messages: Array<mixed>): string {
return messages.map(m => (typeof m === 'string' ? m : inspect(m))).join(' ');
}

View File

@@ -0,0 +1,72 @@
// @flow strict-local
import assert from 'assert';
import sinon from 'sinon';
import Logger from '../src/Logger';
describe('Logger', () => {
let onLog;
let logDisposable;
beforeEach(() => {
onLog = sinon.spy();
logDisposable = Logger.onLog(onLog);
});
afterEach(() => {
logDisposable.dispose();
});
it('emits log diagnostics with info level', () => {
let diagnostic = {
message: 'hello',
origin: 'logger',
};
Logger.log(diagnostic);
assert(
onLog.calledWith({
level: 'info',
diagnostics: [diagnostic],
type: 'log',
}),
);
});
it('emits warn diagnostic with warn level', () => {
let diagnostic = {
message: 'zomg',
origin: 'logger',
};
Logger.warn(diagnostic);
assert(
onLog.calledWith({level: 'warn', diagnostics: [diagnostic], type: 'log'}),
);
});
it('emits error messages with error level', () => {
let diagnostic = {
message: 'oh noes',
origin: 'logger',
};
Logger.error(diagnostic);
assert(
onLog.calledWith({
level: 'error',
diagnostics: [diagnostic],
type: 'log',
}),
);
});
it('emits progress messages with progress level', () => {
Logger.progress('update');
assert(
onLog.calledWith({level: 'progress', message: 'update', type: 'log'}),
);
});
});