UNPKG

hydra-pitschpatsch

Version:

Creates a mini gui for hydra-synth

1,747 lines (1,722 loc) 556 kB
var __create = Object.create; var __getProtoOf = Object.getPrototypeOf; var __defProp = Object.defineProperty; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __toESM = (mod, isNodeMode, target) => { target = mod != null ? __create(__getProtoOf(mod)) : {}; const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target; for (let key of __getOwnPropNames(mod)) if (!__hasOwnProp.call(to, key)) __defProp(to, key, { get: () => mod[key], enumerable: true }); return to; }; var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports); // node_modules/astravel/dist/defaultTraveler.js var require_defaultTraveler = __commonJS((exports) => { (function(global2, factory) { if (typeof define === "function" && define.amd) { define(["exports"], factory); } else if (typeof exports !== "undefined") { factory(exports); } else { var mod = { exports: {} }; factory(mod.exports); global2.defaultTraveler = mod.exports; } })(exports, function(exports2) { exports2.__esModule = true; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var ForInStatement = undefined, FunctionDeclaration = undefined, RestElement = undefined, BinaryExpression = undefined, ArrayExpression = undefined; var ignore = Function.prototype; var Found = function Found(node, state) { _classCallCheck(this, Found); this.node = node; this.state = state; }; exports2.default = { go: function go(node, state) { this[node.type](node, state); }, find: function find(predicate, node, state) { var finder = Object.create(this); finder.go = function(node2, state2) { if (predicate(node2, state2)) { throw new Found(node2, state2); } this[node2.type](node2, state2); }; try { finder.go(node, state); } catch (error) { if (error instanceof Found) { return error; } else { throw error; } } }, makeChild: function makeChild() { var properties = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var traveler = Object.create(this); traveler.super = this; for (var key in properties) { traveler[key] = properties[key]; } return traveler; }, Program: function Program(node, state) { var statements = node.body, length = statements.length; for (var i2 = 0;i2 < length; i2++) { this.go(statements[i2], state); } }, BlockStatement: function BlockStatement(node, state) { var statements = node.body; if (statements != null) { for (var i2 = 0, length = statements.length;i2 < length; i2++) { this.go(statements[i2], state); } } }, EmptyStatement: ignore, ExpressionStatement: function ExpressionStatement(node, state) { this.go(node.expression, state); }, IfStatement: function IfStatement(node, state) { this.go(node.test, state); this.go(node.consequent, state); if (node.alternate != null) { this.go(node.alternate, state); } }, LabeledStatement: function LabeledStatement(node, state) { this.go(node.label, state); this.go(node.body, state); }, BreakStatement: function BreakStatement(node, state) { if (node.label) { this.go(node.label, state); } }, ContinueStatement: function ContinueStatement(node, state) { if (node.label) { this.go(node.label, state); } }, WithStatement: function WithStatement(node, state) { this.go(node.object, state); this.go(node.body, state); }, SwitchStatement: function SwitchStatement(node, state) { this.go(node.discriminant, state); var cases = node.cases, length = cases.length; for (var i2 = 0;i2 < length; i2++) { this.go(cases[i2], state); } }, SwitchCase: function SwitchCase(node, state) { if (node.test != null) { this.go(node.test, state); } var statements = node.consequent, length = statements.length; for (var i2 = 0;i2 < length; i2++) { this.go(statements[i2], state); } }, ReturnStatement: function ReturnStatement(node, state) { if (node.argument) { this.go(node.argument, state); } }, ThrowStatement: function ThrowStatement(node, state) { this.go(node.argument, state); }, TryStatement: function TryStatement(node, state) { this.go(node.block, state); if (node.handler != null) { this.go(node.handler, state); } if (node.finalizer != null) { this.go(node.finalizer, state); } }, CatchClause: function CatchClause(node, state) { if (node.param != null) { this.go(node.param, state); } this.go(node.body, state); }, WhileStatement: function WhileStatement(node, state) { this.go(node.test, state); this.go(node.body, state); }, DoWhileStatement: function DoWhileStatement(node, state) { this.go(node.body, state); this.go(node.test, state); }, ForStatement: function ForStatement(node, state) { if (node.init != null) { this.go(node.init, state); } if (node.test != null) { this.go(node.test, state); } if (node.update != null) { this.go(node.update, state); } this.go(node.body, state); }, ForInStatement: ForInStatement = function ForInStatement(node, state) { this.go(node.left, state); this.go(node.right, state); this.go(node.body, state); }, DebuggerStatement: ignore, FunctionDeclaration: FunctionDeclaration = function FunctionDeclaration(node, state) { if (node.id != null) { this.go(node.id, state); } var params = node.params; if (params != null) { for (var i2 = 0, length = params.length;i2 < length; i2++) { this.go(params[i2], state); } } this.go(node.body, state); }, VariableDeclaration: function VariableDeclaration(node, state) { var declarations = node.declarations, length = declarations.length; for (var i2 = 0;i2 < length; i2++) { this.go(declarations[i2], state); } }, VariableDeclarator: function VariableDeclarator(node, state) { this.go(node.id, state); if (node.init != null) { this.go(node.init, state); } }, ArrowFunctionExpression: function ArrowFunctionExpression(node, state) { var params = node.params; if (params != null) { for (var i2 = 0, length = params.length;i2 < length; i2++) { this.go(params[i2], state); } } this.go(node.body, state); }, ThisExpression: ignore, ArrayExpression: ArrayExpression = function ArrayExpression(node, state) { var elements = node.elements, length = elements.length; for (var i2 = 0;i2 < length; i2++) { var element = elements[i2]; if (element != null) { this.go(elements[i2], state); } } }, ObjectExpression: function ObjectExpression(node, state) { var properties = node.properties, length = properties.length; for (var i2 = 0;i2 < length; i2++) { this.go(properties[i2], state); } }, Property: function Property(node, state) { this.go(node.key, state); if (!node.shorthand) { this.go(node.value, state); } }, FunctionExpression: FunctionDeclaration, SequenceExpression: function SequenceExpression(node, state) { var expressions = node.expressions, length = expressions.length; for (var i2 = 0;i2 < length; i2++) { this.go(expressions[i2], state); } }, UnaryExpression: function UnaryExpression(node, state) { this.go(node.argument, state); }, UpdateExpression: function UpdateExpression(node, state) { this.go(node.argument, state); }, AssignmentExpression: function AssignmentExpression(node, state) { this.go(node.left, state); this.go(node.right, state); }, BinaryExpression: BinaryExpression = function BinaryExpression(node, state) { this.go(node.left, state); this.go(node.right, state); }, LogicalExpression: BinaryExpression, ConditionalExpression: function ConditionalExpression(node, state) { this.go(node.test, state); this.go(node.consequent, state); this.go(node.alternate, state); }, NewExpression: function NewExpression(node, state) { this.CallExpression(node, state); }, CallExpression: function CallExpression(node, state) { this.go(node.callee, state); var args = node["arguments"], length = args.length; for (var i2 = 0;i2 < length; i2++) { this.go(args[i2], state); } }, MemberExpression: function MemberExpression(node, state) { this.go(node.object, state); this.go(node.property, state); }, Identifier: ignore, Literal: ignore, ForOfStatement: ForInStatement, ClassDeclaration: function ClassDeclaration(node, state) { if (node.id) { this.go(node.id, state); } if (node.superClass) { this.go(node.superClass, state); } this.go(node.body, state); }, ClassBody: function ClassBody(node, state) { var body = node.body, length = body.length; for (var i2 = 0;i2 < length; i2++) { this.go(body[i2], state); } }, ImportDeclaration: function ImportDeclaration(node, state) { var specifiers = node.specifiers, length = specifiers.length; for (var i2 = 0;i2 < length; i2++) { this.go(specifiers[i2], state); } this.go(node.source, state); }, ImportNamespaceSpecifier: function ImportNamespaceSpecifier(node, state) { this.go(node.local, state); }, ImportDefaultSpecifier: function ImportDefaultSpecifier(node, state) { this.go(node.local, state); }, ImportSpecifier: function ImportSpecifier(node, state) { this.go(node.imported, state); this.go(node.local, state); }, ExportDefaultDeclaration: function ExportDefaultDeclaration(node, state) { this.go(node.declaration, state); }, ExportNamedDeclaration: function ExportNamedDeclaration(node, state) { if (node.declaration) { this.go(node.declaration, state); } var specifiers = node.specifiers, length = specifiers.length; for (var i2 = 0;i2 < length; i2++) { this.go(specifiers[i2], state); } if (node.source) { this.go(node.source, state); } }, ExportSpecifier: function ExportSpecifier(node, state) { this.go(node.local, state); this.go(node.exported, state); }, ExportAllDeclaration: function ExportAllDeclaration(node, state) { this.go(node.source, state); }, MethodDefinition: function MethodDefinition(node, state) { this.go(node.key, state); this.go(node.value, state); }, ClassExpression: function ClassExpression(node, state) { this.ClassDeclaration(node, state); }, Super: ignore, RestElement: RestElement = function RestElement(node, state) { this.go(node.argument, state); }, SpreadElement: RestElement, YieldExpression: function YieldExpression(node, state) { if (node.argument) { this.go(node.argument, state); } }, TaggedTemplateExpression: function TaggedTemplateExpression(node, state) { this.go(node.tag, state); this.go(node.quasi, state); }, TemplateLiteral: function TemplateLiteral(node, state) { var { quasis, expressions } = node; for (var i2 = 0, length = expressions.length;i2 < length; i2++) { this.go(expressions[i2], state); } for (var _i = 0, _length = quasis.length;_i < _length; _i++) { this.go(quasis[_i], state); } }, TemplateElement: ignore, ObjectPattern: function ObjectPattern(node, state) { var properties = node.properties, length = properties.length; for (var i2 = 0;i2 < length; i2++) { this.go(properties[i2], state); } }, ArrayPattern: ArrayExpression, AssignmentPattern: function AssignmentPattern(node, state) { this.go(node.left, state); this.go(node.right, state); }, MetaProperty: function MetaProperty(node, state) { this.go(node.meta, state); this.go(node.property, state); }, AwaitExpression: function AwaitExpression(node, state) { this.go(node.argument, state); } }; }); }); // node_modules/astravel/dist/attachComments.js var require_attachComments = __commonJS((exports) => { (function(global2, factory) { if (typeof define === "function" && define.amd) { define(["exports", "./defaultTraveler"], factory); } else if (typeof exports !== "undefined") { factory(exports, require_defaultTraveler()); } else { var mod = { exports: {} }; factory(mod.exports, global2.defaultTraveler); global2.attachComments = mod.exports; } })(exports, function(exports2, _defaultTraveler) { exports2.__esModule = true; exports2.default = function(node, comments) { customTraveler[node.type](node, { comments, index: 0 }); return node; }; var _defaultTraveler2 = _interopRequireDefault(_defaultTraveler); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function attachComments(parent, children, findHeadingComments, state, traveler) { var { index, comments } = state; var comment = comments[index]; var boundComments = undefined, trailingComments = undefined; if (comment != null) { if (children == null || children.length === 0) { boundComments = parent.comments != null ? parent.comments : []; while (comment != null && comment.end < parent.end) { boundComments.push(comment); comment = comments[++index]; } state.index = index; if (boundComments.length !== 0 && parent.comments == null) parent.comments = boundComments; } else { if (findHeadingComments) { boundComments = parent.comments != null ? parent.comments : []; var start = children[0].start; while (comment != null && comment.type[0] === "B" && comment.end < start) { boundComments.push(comment); comment = comments[++index]; } if (boundComments.length !== 0 && parent.comments == null) parent.comments = boundComments; } for (var i2 = 0, length = children.length;comment != null && i2 < length; i2++) { var child = children[i2]; boundComments = []; while (comment != null && comment.end < child.start) { boundComments.push(comment); comment = comments[++index]; } if (comment != null && comment.type[0] === "L") { if (comment.loc.start.line === child.loc.end.line) { boundComments.push(comment); comment = comments[++index]; } } if (boundComments.length !== 0) child.comments = boundComments; state.index = index; traveler[child.type](child, state); index = state.index; comment = comments[index]; } trailingComments = []; while (comment != null && comment.end < parent.end) { trailingComments.push(comment); comment = comments[++index]; } if (trailingComments.length !== 0) parent.trailingComments = trailingComments; state.index = index; } } } var Program = undefined; var customTraveler = _defaultTraveler2.default.makeChild({ Program: Program = function Program(node, state) { attachComments(node, node.body, true, state, this); }, BlockStatement: Program, ObjectExpression: function ObjectExpression(node, state) { attachComments(node, node.properties, true, state, this); }, ArrayExpression: function ArrayExpression(node, state) { attachComments(node, node.elements, true, state, this); }, SwitchStatement: function SwitchStatement(node, state) { attachComments(node, node.cases, false, state, this); }, SwitchCase: function SwitchCase(node, state) { attachComments(node, node.consequent, false, state, this); } }); }); }); // node_modules/astravel/dist/astravel.js var require_astravel = __commonJS((exports) => { (function(global2, factory) { if (typeof define === "function" && define.amd) { define(["exports", "./defaultTraveler", "./attachComments"], factory); } else if (typeof exports !== "undefined") { factory(exports, require_defaultTraveler(), require_attachComments()); } else { var mod = { exports: {} }; factory(mod.exports, global2.defaultTraveler, global2.attachComments); global2.astravel = mod.exports; } })(exports, function(exports2, _defaultTraveler, _attachComments) { exports2.__esModule = true; exports2.makeTraveler = exports2.attachComments = exports2.defaultTraveler = undefined; var _defaultTraveler2 = _interopRequireDefault(_defaultTraveler); var _attachComments2 = _interopRequireDefault(_attachComments); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function makeTraveler(properties) { return _defaultTraveler2.default.makeChild(properties); } exports2.defaultTraveler = _defaultTraveler2.default; exports2.attachComments = _attachComments2.default; exports2.makeTraveler = makeTraveler; }); }); // src/utils/logger.js class Logger2 { static isEnabled = true; static getCallerInfo() { const error = new Error; const stack = error.stack.split(` `)[3]; const match = stack.match(/at\s+(?:.*\s+\()?(.+):(\d+):(\d+)/); if (match) { const url = document?.currentScript?.src || "http://localhost:3000/hydra-pitschpatsch.js"; const [, file, line, column] = match; return url + ":" + line; } return "[unknown source]"; } static log(...args) { if (this.isEnabled) { const source = this.getCallerInfo(); console.log(source, ...args); } } static error(...args) { if (this.isEnabled) { const source = this.getCallerInfo(); console.error(source, ...args); } } static setEnabled(enabled) { this.isEnabled = enabled; } } // node_modules/@preact/signals-core/dist/signals-core.module.js var i = Symbol.for("preact-signals"); function t() { if (!(s > 1)) { var i2, t2 = false; while (h !== undefined) { var r = h; h = undefined; f++; while (r !== undefined) { var o = r.o; r.o = undefined; r.f &= -3; if (!(8 & r.f) && c(r)) try { r.c(); } catch (r2) { if (!t2) { i2 = r2; t2 = true; } } r = o; } } f = 0; s--; if (t2) throw i2; } else s--; } var o = undefined; var h = undefined; var s = 0; var f = 0; var v = 0; function e(i2) { if (o !== undefined) { var t2 = i2.n; if (t2 === undefined || t2.t !== o) { t2 = { i: 0, S: i2, p: o.s, n: undefined, t: o, e: undefined, x: undefined, r: t2 }; if (o.s !== undefined) o.s.n = t2; o.s = t2; i2.n = t2; if (32 & o.f) i2.S(t2); return t2; } else if (t2.i === -1) { t2.i = 0; if (t2.n !== undefined) { t2.n.p = t2.p; if (t2.p !== undefined) t2.p.n = t2.n; t2.p = o.s; t2.n = undefined; o.s.n = t2; o.s = t2; } return t2; } } } function u(i2) { this.v = i2; this.i = 0; this.n = undefined; this.t = undefined; } u.prototype.brand = i; u.prototype.h = function() { return true; }; u.prototype.S = function(i2) { if (this.t !== i2 && i2.e === undefined) { i2.x = this.t; if (this.t !== undefined) this.t.e = i2; this.t = i2; } }; u.prototype.U = function(i2) { if (this.t !== undefined) { var { e: t2, x: r } = i2; if (t2 !== undefined) { t2.x = r; i2.e = undefined; } if (r !== undefined) { r.e = t2; i2.x = undefined; } if (i2 === this.t) this.t = r; } }; u.prototype.subscribe = function(i2) { var t2 = this; return E(function() { var r = t2.value, n = o; o = undefined; try { i2(r); } finally { o = n; } }); }; u.prototype.valueOf = function() { return this.value; }; u.prototype.toString = function() { return this.value + ""; }; u.prototype.toJSON = function() { return this.value; }; u.prototype.peek = function() { var i2 = o; o = undefined; try { return this.value; } finally { o = i2; } }; Object.defineProperty(u.prototype, "value", { get: function() { var i2 = e(this); if (i2 !== undefined) i2.i = this.i; return this.v; }, set: function(i2) { if (i2 !== this.v) { if (f > 100) throw new Error("Cycle detected"); this.v = i2; this.i++; v++; s++; try { for (var r = this.t;r !== undefined; r = r.x) r.t.N(); } finally { t(); } } } }); function d(i2) { return new u(i2); } function c(i2) { for (var t2 = i2.s;t2 !== undefined; t2 = t2.n) if (t2.S.i !== t2.i || !t2.S.h() || t2.S.i !== t2.i) return true; return false; } function a(i2) { for (var t2 = i2.s;t2 !== undefined; t2 = t2.n) { var r = t2.S.n; if (r !== undefined) t2.r = r; t2.S.n = t2; t2.i = -1; if (t2.n === undefined) { i2.s = t2; break; } } } function l(i2) { var t2 = i2.s, r = undefined; while (t2 !== undefined) { var o2 = t2.p; if (t2.i === -1) { t2.S.U(t2); if (o2 !== undefined) o2.n = t2.n; if (t2.n !== undefined) t2.n.p = o2; } else r = t2; t2.S.n = t2.r; if (t2.r !== undefined) t2.r = undefined; t2 = o2; } i2.s = r; } function y(i2) { u.call(this, undefined); this.x = i2; this.s = undefined; this.g = v - 1; this.f = 4; } (y.prototype = new u).h = function() { this.f &= -3; if (1 & this.f) return false; if ((36 & this.f) == 32) return true; this.f &= -5; if (this.g === v) return true; this.g = v; this.f |= 1; if (this.i > 0 && !c(this)) { this.f &= -2; return true; } var i2 = o; try { a(this); o = this; var t2 = this.x(); if (16 & this.f || this.v !== t2 || this.i === 0) { this.v = t2; this.f &= -17; this.i++; } } catch (i3) { this.v = i3; this.f |= 16; this.i++; } o = i2; l(this); this.f &= -2; return true; }; y.prototype.S = function(i2) { if (this.t === undefined) { this.f |= 36; for (var t2 = this.s;t2 !== undefined; t2 = t2.n) t2.S.S(t2); } u.prototype.S.call(this, i2); }; y.prototype.U = function(i2) { if (this.t !== undefined) { u.prototype.U.call(this, i2); if (this.t === undefined) { this.f &= -33; for (var t2 = this.s;t2 !== undefined; t2 = t2.n) t2.S.U(t2); } } }; y.prototype.N = function() { if (!(2 & this.f)) { this.f |= 6; for (var i2 = this.t;i2 !== undefined; i2 = i2.x) i2.t.N(); } }; Object.defineProperty(y.prototype, "value", { get: function() { if (1 & this.f) throw new Error("Cycle detected"); var i2 = e(this); this.h(); if (i2 !== undefined) i2.i = this.i; if (16 & this.f) throw this.v; return this.v; } }); function w(i2) { return new y(i2); } function _(i2) { var r = i2.u; i2.u = undefined; if (typeof r == "function") { s++; var n = o; o = undefined; try { r(); } catch (t2) { i2.f &= -2; i2.f |= 8; g(i2); throw t2; } finally { o = n; t(); } } } function g(i2) { for (var t2 = i2.s;t2 !== undefined; t2 = t2.n) t2.S.U(t2); i2.x = undefined; i2.s = undefined; _(i2); } function p(i2) { if (o !== this) throw new Error("Out-of-order effect"); l(this); o = i2; this.f &= -2; if (8 & this.f) g(this); t(); } function b(i2) { this.x = i2; this.u = undefined; this.s = undefined; this.o = undefined; this.f = 32; } b.prototype.c = function() { var i2 = this.S(); try { if (8 & this.f) return; if (this.x === undefined) return; var t2 = this.x(); if (typeof t2 == "function") this.u = t2; } finally { i2(); } }; b.prototype.S = function() { if (1 & this.f) throw new Error("Cycle detected"); this.f |= 1; this.f &= -9; _(this); a(this); s++; var i2 = o; o = this; return p.bind(this, i2); }; b.prototype.N = function() { if (!(2 & this.f)) { this.f |= 2; this.o = h; h = this; } }; b.prototype.d = function() { this.f |= 8; if (!(1 & this.f)) g(this); }; function E(i2) { var t2 = new b(i2); try { t2.c(); } catch (i3) { t2.d(); throw i3; } return t2.d.bind(t2); } // src/state/signals.js var currentCode = d(""); var currentEvalCode = d(""); var currentEvalRange = d(null); var currentParameters = d([]); var valuePositions = d([]); var parameters = d(new Map); var settings = d({ isReset: false, showSettings: false }); var errors = d([]); var layout = d({ position: { top: "50px", right: "10px" }, zIndex: "9999" }); var guiReady = d(false); var hasErrors = w(() => errors.value.length > 0); var hasParameters = w(() => valuePositions.value.length > 0); E(() => { Logger2.log("currentEvalRange", currentEvalRange.value); Logger2.log("currentParameters", currentParameters.value); Logger2.log("currentCode", currentCode.value); Logger2.log("valuePositions", valuePositions.value); }); var actions = { evalResult: ({ result, code: code2, range, parameters: parameters2 }) => { currentEvalResult.value = result; currentEvalCode.value = code2; currentEvalRange.value = range; currentParameters.value = parameters2; }, currentParameters: () => currentParameters.value, updateCode: (code2) => currentCode.value = code2, updateParameter: (key, value) => { Logger2.log("actions.updateParameter", { key, value }); const newParams = new Map(parameters.value); newParams.set(key, value); parameters.value = newParams; }, updateEvalRange: (range) => currentEvalRange.value = range, updateSettings: (newSettings) => settings.value = { ...settings.value, ...newSettings }, setError: (error) => errors.value = [error], clearErrors: () => errors.value = [] }; // src/utils/hydra-utils.js var getHydra = () => { Logger2.log("getting hydra"); const whereami = window.location?.href?.includes("hydra.ojack.xyz") ? "editor" : window.atom?.packages ? "atom" : "idk"; if (whereami === "editor") { Logger2.log("got hydra from editor", window.hydraSynth); return window.hydraSynth; } if (whereami === "atom") { Logger2.log("got hydra from atom", global.atom.packages.loadedPackages["atom-hydra"]); return global.atom.packages.loadedPackages["atom-hydra"].mainModule.main.hydra; } let _h = [ window.hydraSynth, window._hydra, window.hydra, window.h, window.H, window.hy ].find((h2) => h2?.regl); Logger2.log("got hydra", _h); return _h; }; var waitForGUI = () => { return new Promise((resolve) => { const check = () => { if (window.lil?.GUI) { resolve(); guiReady.value = true; } else { setTimeout(check, 100); } }; check(); }); }; // src/editor/editor-integration.js var hookIntoEval = () => { Logger2.log("hooking into eval"); const originalEval = window.eval; window.eval = (code2) => { Logger2.log("window.eval:", code2); return originalEval.call(window, code2); }; }; var hookIntoHydraEditor = function() { Logger2.log("hooking into hydra editor"); const waitForEditor = setInterval(() => { if (window.cm) { clearInterval(waitForEditor); Logger2.log("got editor"); const cm = window.cm; cm.on("change", (cm2, change) => { if (this.codeManager?.isUpdating) return; if (currentEvalRange.value) { const changeInRange = change.from.line >= currentEvalRange.value.start.line && change.to.line <= currentEvalRange.value.end.line; if (changeInRange) { const code2 = cm2.getRange(currentEvalRange.value.start, currentEvalRange.value.end); actions.updateCode(code2); this.codeManager.findValues(code2); } } }); const getCurrentBlock = () => { const pos = cm.getCursor(); let startline = pos.line; let endline = pos.line; while (startline > 0) { const line = cm.getLine(startline - 1); if (line === undefined || line.trim() === "") { break; } startline--; } while (endline < cm.lineCount() - 1) { const line = cm.getLine(endline + 1); if (line === undefined || line.trim() === "") { break; } endline++; } endline++; const pos1 = { line: startline, ch: 0 }; const pos2 = { line: endline, ch: 0 }; const str = cm.getRange(pos1, pos2); Logger2.log("Found block:", { start: pos1, end: pos2, text: str }); return { start: pos1, end: pos2, text: str }; }; const evalKeys = { "Ctrl-Enter": "editor: eval line", "Alt-Enter": "editor: eval block", "Shift-Ctrl-Enter": "editor: eval all" }; const originalExtraKeys = cm.options.extraKeys || {}; Object.entries(evalKeys).forEach(([key, action]) => { if (originalExtraKeys[key]) { const originalHandler = originalExtraKeys[key]; originalExtraKeys[key] = () => { let range; if (action === "editor: eval block") { const block = getCurrentBlock(); range = { start: block.start, end: block.end }; } else if (action === "editor: eval line") { const line = cm.getCursor().line; range = { start: { line, ch: 0 }, end: { line: line + 1, ch: 0 } }; } else if (action === "editor: eval all") { range = { start: { line: 0, ch: 0 }, end: { line: cm.lineCount(), ch: 0 } }; } const rangeCode = cm.getRange(range.start, range.end); actions.updateCode(rangeCode, range); Logger2.log("lastEvalRange", range); originalHandler(); }; } }); cm.setOption("extraKeys", originalExtraKeys); Logger2.log("Successfully hooked into Hydra editor"); } }, 100); }; // src/gui/core/types/styles.js var DEFAULT_GUI_STYLES = { errorMessage: ` .error-message { color: #ff0000 !important; } .error-message .tp-lblv_l, .error-message .tp-lblv_v { color: #ff0000 !important; } `, scrollbar: ` #hydra-mini-gui::-webkit-scrollbar { width: 0px; } `, tabContent: ` .tp-tbpv_c { max-height: 80vh; overflow-y: auto; } .tp-tbpv_c::-webkit-scrollbar { width: 0px; } ` }; // src/gui/core/draggable-pane.js class DraggablePane { constructor(container) { this.container = container; this.dragBar = null; this.isDragging = false; this.startX = 0; this.startY = 0; this.initialX = 0; this.initialY = 0; this.onDragStart = this.onDragStart.bind(this); this.onDrag = this.onDrag.bind(this); this.onDragEnd = this.onDragEnd.bind(this); setTimeout(() => this.init(), 1000); } init() { const selectors = [ ".tp-rotv_t", ".hydra-mini-gui>div>button" ]; for (const selector of selectors) { this.dragBar = this.container.querySelector(selector); if (this.dragBar) { console.log("DraggablePane: Found drag handle using selector:", selector); break; } } if (!this.dragBar) { console.warn("DraggablePane: Could not find any suitable drag handle. DOM structure:", this.container.innerHTML); setTimeout(() => this.init(), 500); return; } this.dragBar.style.cursor = "grab"; this.dragBar.classList.add("draggable"); this.dragBar.addEventListener("mousedown", this.onDragStart); this.dragBar.addEventListener("touchstart", this.onDragStart, { passive: false }); } onDragStart(e2) { e2.preventDefault(); this.isDragging = true; this.dragBar.style.cursor = "grabbing"; if (e2.type === "mousedown") { this.startX = e2.clientX; this.startY = e2.clientY; } else if (e2.type === "touchstart") { this.startX = e2.touches[0].clientX; this.startY = e2.touches[0].clientY; } const rect = this.container.getBoundingClientRect(); this.container.style.removeProperty("right"); this.initialX = rect.left; this.initialY = rect.top; console.log("DraggablePane: Drag start", { startX: this.startX, startY: this.startY, initialX: this.initialX, initialY: this.initialY }); document.addEventListener("mousemove", this.onDrag); document.addEventListener("touchmove", this.onDrag, { passive: false }); document.addEventListener("mouseup", this.onDragEnd); document.addEventListener("touchend", this.onDragEnd); } onDrag(e2) { if (!this.isDragging) return; e2.preventDefault(); let currentX, currentY; if (e2.type === "mousemove") { currentX = e2.clientX; currentY = e2.clientY; } else if (e2.type === "touchmove") { currentX = e2.touches[0].clientX; currentY = e2.touches[0].clientY; } const deltaX = currentX - this.startX; const deltaY = currentY - this.startY; const newX = this.initialX + deltaX; const newY = this.initialY + deltaY; const maxX = window.innerWidth - this.container.offsetWidth; const maxY = window.innerHeight - this.container.offsetHeight; const finalX = Math.max(0, Math.min(maxX, newX)); const finalY = Math.max(0, Math.min(maxY, newY)); console.log("DraggablePane: Dragging", { deltaX, deltaY, newX: finalX, newY: finalY }); this.container.style.left = `${finalX}px`; this.container.style.top = `${finalY}px`; } onDragEnd() { if (!this.isDragging) return; this.isDragging = false; this.dragBar.style.cursor = "grab"; console.log("DraggablePane: Drag end", { finalX: this.container.style.left, finalY: this.container.style.top }); document.removeEventListener("mousemove", this.onDrag); document.removeEventListener("touchmove", this.onDrag); document.removeEventListener("mouseup", this.onDragEnd); document.removeEventListener("touchend", this.onDragEnd); } cleanup() { if (this.dragBar) { this.dragBar.removeEventListener("mousedown", this.onDragStart); this.dragBar.removeEventListener("touchstart", this.onDragStart); this.dragBar.classList.remove("draggable"); } document.removeEventListener("mousemove", this.onDrag); document.removeEventListener("touchmove", this.onDrag); document.removeEventListener("mouseup", this.onDragEnd); document.removeEventListener("touchend", this.onDragEnd); } } // src/gui/adapters/dom-adapter.js class DOMAdapter { constructor() { this.container = null; this.styleElement = null; this.draggablePane = null; } createElement(type, properties = {}) { if (typeof document === "undefined") return null; const element = document.createElement(type); if (properties.style) { Object.assign(element.style, properties.style); } if (properties.classes) { properties.classes.forEach((c2) => element.classList.add(c2)); } if (properties.attributes) { Object.entries(properties.attributes).forEach(([key, value]) => element.setAttribute(key, value)); } return element; } mountContainer(container) { if (typeof document === "undefined") return; const editorContainer = document.getElementById("editor-container"); if (editorContainer) { editorContainer.appendChild(container); return; } document.body.appendChild(container); } removeExistingGUI() { if (typeof document === "undefined") return; const existingGui = document.getElementById("hydra-mini-gui"); if (existingGui) { existingGui.remove(); } } setupContainer(layout2) { if (typeof document === "undefined") return null; this.removeExistingGUI(); this.container = this.createElement("div", { style: { zIndex: layout2.zIndex, position: "fixed", ...layout2.position }, classes: ["hydra-ui"], attributes: { id: "hydra-mini-gui" } }); this.mountContainer(this.container); this.applyStyles(); this.draggablePane = new DraggablePane(this.container); return this.container; } applyStyles(customStyles = {}) { if (typeof document === "undefined") return; this.removeStyles(); this.styleElement = this.createElement("style", { attributes: { id: "hydra-mini-gui-styles" } }); const styles = { ...DEFAULT_GUI_STYLES, ...customStyles }; this.styleElement.textContent = Object.values(styles).join(` `); document.head?.appendChild(this.styleElement); } removeStyles() { if (typeof document === "undefined") return; const existingStyle = document.getElementById("hydra-mini-gui-styles"); if (existingStyle) { existingStyle.remove(); } this.styleElement = null; } cleanup() { if (this.draggablePane) { this.draggablePane.cleanup(); this.draggablePane = null; } if (this.container) { this.container.remove(); this.container = null; } this.removeStyles(); } } // node_modules/tweakpane/dist/tweakpane.js /*! Tweakpane 4.0.5 (c) 2016 cocopon, licensed under the MIT license. */ function forceCast(v2) { return v2; } function isEmpty(value) { return value === null || value === undefined; } function isObject$1(value) { return value !== null && typeof value === "object"; } function isRecord(value) { return value !== null && typeof value === "object"; } function deepEqualsArray(a1, a2) { if (a1.length !== a2.length) { return false; } for (let i2 = 0;i2 < a1.length; i2++) { if (a1[i2] !== a2[i2]) { return false; } } return true; } function deepMerge(r1, r2) { const keys = Array.from(new Set([...Object.keys(r1), ...Object.keys(r2)])); return keys.reduce((result, key) => { const v1 = r1[key]; const v2 = r2[key]; return isRecord(v1) && isRecord(v2) ? Object.assign(Object.assign({}, result), { [key]: deepMerge(v1, v2) }) : Object.assign(Object.assign({}, result), { [key]: key in r2 ? v2 : v1 }); }, {}); } function isBinding(value) { if (!isObject$1(value)) { return false; } return "target" in value; } var CREATE_MESSAGE_MAP = { alreadydisposed: () => "View has been already disposed", invalidparams: (context) => `Invalid parameters for '${context.name}'`, nomatchingcontroller: (context) => `No matching controller for '${context.key}'`, nomatchingview: (context) => `No matching view for '${JSON.stringify(context.params)}'`, notbindable: () => `Value is not bindable`, notcompatible: (context) => `Not compatible with plugin '${context.id}'`, propertynotfound: (context) => `Property '${context.name}' not found`, shouldneverhappen: () => "This error should never happen" }; class TpError { static alreadyDisposed() { return new TpError({ type: "alreadydisposed" }); } static notBindable() { return new TpError({ type: "notbindable" }); } static notCompatible(bundleId, id) { return new TpError({ type: "notcompatible", context: { id: `${bundleId}.${id}` } }); } static propertyNotFound(name) { return new TpError({ type: "propertynotfound", context: { name } }); } static shouldNeverHappen() { return new TpError({ type: "shouldneverhappen" }); } constructor(config) { var _a; this.message = (_a = CREATE_MESSAGE_MAP[config.type](forceCast(config.context))) !== null && _a !== undefined ? _a : "Unexpected error"; this.name = this.constructor.name; this.stack = new Error(this.message).stack; this.type = config.type; } toString() { return this.message; } } class BindingTarget { constructor(obj, key) { this.obj_ = obj; this.key = key; } static isBindable(obj) { if (obj === null) { return false; } if (typeof obj !== "object" && typeof obj !== "function") { return false; } return true; } read() { return this.obj_[this.key]; } write(value) { this.obj_[this.key] = value; } writeProperty(name, value) { const valueObj = this.read(); if (!BindingTarget.isBindable(valueObj)) { throw TpError.notBindable(); } if (!(name in valueObj)) { throw TpError.propertyNotFound(name); } valueObj[name] = value; } } class Emitter { constructor() { this.observers_ = {}; } on(eventName, handler, opt_options) { var _a; let observers = this.observers_[eventName]; if (!observers) { observers = this.observers_[eventName] = []; } observers.push({ handler, key: (_a = opt_options === null || opt_options === undefined ? undefined : opt_options.key) !== null && _a !== undefined ? _a : handler }); return this; } off(eventName, key) { const observers = this.observers_[eventName]; if (observers) { this.observers_[eventName] = observers.filter((observer) => { return observer.key !== key; }); } return this; } emit(eventName, event) { const observers = this.observers_[eventName]; if (!observers) { return; } observers.forEach((observer) => { observer.handler(event); }); } } class ComplexValue { constructor(initialValue, config) { var _a; this.constraint_ = config === null || config === undefined ? undefined : config.constraint; this.equals_ = (_a = config === null || config === undefined ? undefined : config.equals) !== null && _a !== undefined ? _a : (v1, v2) => v1 === v2; this.emitter = new Emitter; this.rawValue_ = initialValue; } get constraint() { return this.constraint_; } get rawValue() { return this.rawValue_; } set rawValue(rawValue) { this.setRawValue(rawValue, { forceEmit: false, last: true }); } setRawValue(rawValue, options) { const opts = options !== null && options !== undefined ? options : { forceEmit: false, last: true }; const constrainedValue = this.constraint_ ? this.constraint_.constrain(rawValue) : rawValue; const prevValue = this.rawValue_; const changed = !this.equals_(prevValue, constrainedValue); if (!changed && !opts.forceEmit) { return; } this.emitter.emit("beforechange", { sender: this }); this.rawValue_ = constrainedValue; this.emitter.emit("change", { options: opts, previousRawValue: prevValue, rawValue: constrainedValue, sender: this }); } } class PrimitiveValue { constructor(initialValue) { this.emitter = new Emitter; this.value_ = initialValue; } get rawValue() { return this.value_; } set rawValue(value) { this.setRawValue(value, { forceEmit: false, last: true }); } setRawValue(value, options) { const opts = options !== null && options !== undefined ? options : { forceEmit: false, last: true }; const prevValue = this.value_; if (prevValue === value && !opts.forceEmit) { return; } this.emitter.emit("beforechange", { sender: this }); this.value_ = value; this.emitter.emit("change", { options: opts, previousRawValue: prevValue, rawValue: this.value_, sender: this }); } } class ReadonlyPrimitiveValue { constructor(value) { this.emitter = new Emitter; this.onValueBeforeChange_ = this.onValueBeforeChange_.bind(this); this.onValueChange_ = this.onValueChange_.bind(this); this.value_ = value; this.value_.emitter.on("beforechange", this.onValueBeforeChange_); this.value_.emitter.on("change", this.onValueChange_); } get rawValue() { return this.value_.rawValue; } onValueBeforeChange_(ev) { this.emitter.emit("beforechange", Object.assign(Object.assign({}, ev), { sender: this })); } onValueChange_(ev) { this.emitter.emit("change", Object.assign(Object.assign({}, ev), { sender: this })); } } function createValue(initialValue, config) { const constraint = config === null || config === undefined ? undefined : config.constraint; const equals = config === null || config === undefined ? undefined : config.equals; if (!constraint && !equals) { return new PrimitiveValue(initialValue); } return new ComplexValue(initialValue, config); } function createReadonlyValue(value) { return [ new ReadonlyPrimitiveValue(value), (rawValue, options) => { value.setRawValue(rawValue, options); } ]; } class ValueMap { constructor(valueMap) { this.emitter = new Emitter; this.valMap_ = valueMap; for (const key in this.valMap_) { const v2 = this.valMap_[key]; v2.emitter.on("change", () => { this.emitter.emit("change", { key, sender: this }); }); } } static createCore(initialValue) { const keys = Object.keys(initialValue); return keys.reduce((o2, key) => { return Object.assign(o2, { [key]: createValue(initialValue[key]) }); }, {}); } static fromObject(initialValue) { const core = this.createCore(initialValue); return new ValueMap(core); } get(key) { return this.valMap_[key].rawValue; } set(key, value) { this.valMap_[key].rawValue = value; } value(key) { return this.valMap_[key]; } } class DefiniteRangeConstraint { constructor(config) { this.values = ValueMap.fromObject({ max: config.max, min: config.min }); } constrain(value) { const max = this.values.get("max"); const min = this.values.get("min"); return Math.min(Math.max(value, min), max); } } class RangeConstraint { constructor(config) { this.values = ValueMap.fromObject({ max: config.max, min: config.min }); } constrain(value) { const max = this.values.get("max"); const min = this.values.get("min"); let result = value; if (!isEmpty(min)) { result = Math.max(result, min); } if (!isEmpty(max)) { result = Math.min(result, max); } return result; } } class StepConstraint { constructor(step, origin = 0) { this.step = step; this.origin = origin; } constrain(value) { const o2 = this.origin % this.step; const r = Math.round((value - o2) / this.step); return o2 + r * this.step; } } class NumberLiteralNode { constructor(text) { this.text = text; } evaluate() { return Number(this.text); } toString() { return this.text; } } var BINARY_OPERATION_MAP = { "**": (v1, v2) => Math.pow(v1, v2), "*": (v1, v2) => v1 * v2, "/": (v1, v2) => v1 / v2, "%": (v1, v2) => v1 % v2, "+": (v1, v2) => v1 + v2, "-": (v1, v2) => v1 - v2, "<<": (v1, v2) => v1 << v2, ">>": (v1, v2) => v1 >> v2, ">>>": (v1, v2) => v1 >>> v2, "&": (v1, v2) => v1 & v2, "^": (v1, v2) => v1 ^ v2, "|": (v1, v2) => v1 | v2 }; class BinaryOperationNode { constructor(operator, left, right) { this.left = left; this.operator = operator; this.right = right; } evaluate() { const op = BINARY_OPERATION_MAP[this.operator]; if (!op) { throw new Error(`unexpected binary operator: '${this.operator}`); }