{"version":3,"sources":["jsdelivr-header.js","/npm/rete-module-plugin@0.4.2/src/utils.js","/npm/rete-module-plugin@0.4.2/src/module.js","/npm/rete-module-plugin@0.4.2/src/module-manager.js","/npm/rete-module-plugin@0.4.2/src/index.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;k2BCNO,SAAS,aAAa,EAAO,G,IAC1B,EAAQ,MAAM,KAAK,EAAI,Q,OAEtB,OAAO,KAAK,GACd,QAAO,SAAA,G,OAAK,EAAM,SAAS,EAAM,GAAG,K,IACpC,KAAI,SAAA,G,OAAK,EAAM,E,IACf,MAAK,SAAC,EAAI,G,OAAO,EAAG,SAAS,GAAK,EAAG,SAAS,E,IAGvD,SAEgB,SAAS,EAAM,GAC3B,EAAK,iBAAiB,SAAQ,SAAA,G,OAAK,EAAO,iBAAiB,E,IAC3D,MAAM,KAAK,EAAK,OAAO,UAAU,SAAQ,SAAA,G,OAAS,EAAK,YAAY,E,IACnE,MAAM,KAAK,EAAK,QAAQ,UAAU,SAAQ,SAAA,G,OAAU,EAAK,aAAa,E,IAG1E,SAAgB,MAAM,EAAM,EAAQ,G,IAC1B,EAAoB,IAAI,IAAI,EAAO,KAAI,SAAA,G,OAAK,EAAE,I,KAAO,KACrD,EAAqB,IAAI,IAAI,EAAQ,KAAI,SAAA,G,OAAK,EAAE,I,KAAO,K,GAEzD,IAAsB,EAAO,OAC7B,eAAA,OAAgB,EAAK,KAAK,OAA1B,yB,GACA,IAAuB,EAAQ,OAC/B,eAAA,OAAgB,EAAK,KAAK,OAA1B,0BAEJ,EAAO,SAAQ,SAAA,G,OAAK,EAAK,SAAS,IAAI,WAAM,EAAE,KAAM,EAAE,KAAM,EAAE,Q,IAC9D,EAAQ,SAAQ,SAAA,G,OAAK,EAAK,UAAU,IAAI,YAAO,EAAE,KAAM,EAAE,KAAM,EAAE,Q,QC3BxD,OAAb,W,0CAGa,OAAS,G,KACT,QAAU,E,mDAGd,G,KACI,OAAS,C,+BAGZ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,EAAA,EAAA,EAAA,EAAA,IAAT,EAAS,GAAA,UAAA,GACxB,GAAe,EAAc,MAAM,EAAW,GAClD,EAAc,cAAc,MAAM,EAAe,E,EAzDlC,C,IAiE/B,IAAA,MAAe,CACX,iB","file":"/npm/rete-module-plugin@0.4.2/build/module-plugin.common.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/rete-module-plugin@0.4.2/build/module-plugin.common.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","export function extractNodes(nodes, map) {\n    const names = Array.from(map.keys());\n    \n    return Object.keys(nodes)\n        .filter(k => names.includes(nodes[k].name))\n        .map(k => nodes[k])\n        .sort((n1, n2) => n1.position[1] > n2.position[1]);\n}\n\nimport { Input, Output } from 'rete';\n\nexport function removeIO(node, editor) {\n    node.getConnections().forEach(c => editor.removeConnection(c));\n    Array.from(node.inputs.values()).forEach(input => node.removeInput(input));\n    Array.from(node.outputs.values()).forEach(output => node.removeOutput(output));\n}\n\nexport function addIO(node, inputs, outputs) {\n    const uniqueInputsCount = new Set(inputs.map(i => i.name)).size;\n    const uniqueOutputsCount = new Set(outputs.map(i => i.name)).size;\n\n    if (uniqueInputsCount !== inputs.length)\n        throw `Module ${node.data.module} has duplicate inputs`;\n    if (uniqueOutputsCount !== outputs.length)\n        throw `Module ${node.data.module} has duplicate outputs`;\n\n    inputs.forEach(i => node.addInput(new Input(i.name, i.name, i.socket)))\n    outputs.forEach(o => node.addOutput(new Output(o.name, o.name, o.socket)));\n}\n","export class Module {\n    \n    constructor() {\n        this.inputs = {};\n        this.outputs = {};\n    }\n    \n    read(inputs) {\n        this.inputs = inputs;\n    }\n    \n    write(outputs) {\n        Object.keys(this.outputs).map(key => {\n            outputs[key] = this.outputs[key];\n        });\n    }\n\n    getInput(key) {\n        return this.inputs[key];\n    }\n\n    setOutput(key, value) {\n        this.outputs[key] = value;\n    }\n}\n    ","import { Module } from './module';\nimport { extractNodes } from './utils';\n\nexport class ModuleManager {\n\n    constructor(modules) {\n        this.engine = null;\n        this.modules = modules;\n        this.inputs = new Map();\n        this.outputs = new Map();\n    }\n\n    getInputs(data) {\n        return extractNodes(data.nodes, this.inputs)\n            .map(node => ({ name: node.data.name, socket: this.socketFactory(node, this.inputs.get(node.name)) }));\n    }\n\n    getOutputs(data) {\n        return extractNodes(data.nodes, this.outputs)\n            .map(node => ({ name: node.data.name, socket: this.socketFactory(node, this.outputs.get(node.name)) }));\n    }\n\n    socketFactory(node, socket) {\n        socket = typeof socket === \"function\" ? socket(node) : socket;\n\n        if (!socket) throw new Error(`Socket not found for node with id = ${node.id} in the module`);\n\n        return socket;\n    }\n\n    registerInput(name, socket) {\n        this.inputs.set(name, socket)\n    }\n\n    registerOutput(name, socket) {\n        this.outputs.set(name, socket)\n    }\n\n    async workerModule(node, inputs, outputs, args) {\n        if (!node.data.module) return;\n        if (!this.modules[node.data.module]) return;\n\n        const data = this.modules[node.data.module].data;\n        const module = new Module();\n        const engine = this.engine.clone();\n\n        module.read(inputs);\n        await engine.process(data, null, Object.assign({}, args, { module, silent: true }));\n        module.write(outputs);\n    }\n    \n    workerInputs(node, inputs, outputs, { module } = {}) {\n        if (!module) return;\n            \n        outputs['output'] = (module.getInput(node.data.name) || [])[0];\n    }\n        \n    workerOutputs(node, inputs, outputs, { module } = {}) {\n        if (!module) return;\n\n        module.setOutput(node.data.name, inputs['input'][0]);\n    }\n        \n    setEngine(engine) {\n        this.engine = engine;\n    }\n}","import { addIO, removeIO } from './utils';\nimport { ModuleManager } from './module-manager';\n\nfunction install(context, { engine, modules }) {\n    const moduleManager = new ModuleManager(modules);\n\n    moduleManager.setEngine(engine);\n        \n    context.on('componentregister', component => {\n        if (!component.module) return;\n\n        // socket - Rete.Socket instance or function that returns a socket instance\n        const { nodeType, socket } = component.module;\n        const name = component.name;\n\n        switch (nodeType) {\n        case 'input':\n            let inputsWorker = component.worker;\n\n            moduleManager.registerInput(name, socket);\n\n            component.worker = (...args) => {\n                moduleManager.workerInputs.apply(moduleManager, args);\n                if (inputsWorker) inputsWorker.apply(component, args);\n            }\n            break;\n        case 'module':\n            const builder = component.builder;\n\n            if (builder) {\n                component.updateModuleSockets = (node) => {\n                    removeIO(node, context);\n\n                    if (!node.data.module || !modules[node.data.module]) return;\n\n                    const data = modules[node.data.module].data;\n                    const inputs = moduleManager.getInputs(data);\n                    const outputs = moduleManager.getOutputs(data);\n                    \n                    try {\n                        addIO(node, inputs, outputs)\n                    } catch (e) {\n                        return context.trigger('warn', e);\n                    }\n                }\n\n                component.builder = async (node) => {\n                    component.updateModuleSockets(node);\n                    await builder.call(component, node);\n                }\n            }\n\n            const moduleWorker = component.worker;\n\n            component.worker = async (...args) => {\n                await moduleManager.workerModule.apply(moduleManager, args);\n                if (moduleWorker) moduleWorker.apply(component, args);\n            };\n            break;\n        case 'output':\n            let outputsWorker = component.worker;\n\n            moduleManager.registerOutput(name, socket);\n\n            component.worker = (...args) => {\n                if (outputsWorker) outputsWorker.apply(component, args);\n                moduleManager.workerOutputs.apply(moduleManager, args);\n            }\n            break;\n        default: break;\n        }\n    });\n}\n\nexport default {\n    install\n}"]}