@virid/renderer 0.3.15 → 0.3.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,8 +1,8 @@
1
1
  /**
2
- * @virid/renderer v0.3.15
2
+ * @virid/renderer v0.3.16
3
3
  * Electron renderer process adapter for virid, responsible for forwarding and receiving messages from the main process
4
4
  */
5
- var m=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var x=(i,e,r)=>e in i?m(i,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):i[e]=r;var t=(i,e)=>m(i,"name",{value:e,configurable:!0});var y=(i,e)=>{for(var r in e)m(i,r,{get:e[r],enumerable:!0})},T=(i,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let _ of A(e))!V.call(i,_)&&_!==r&&m(i,_,{get:()=>e[_],enumerable:!(s=M(e,_))||s.enumerable});return i};var h=i=>T(m({},"__esModule",{value:!0}),i);var d=(i,e,r)=>x(i,typeof e!="symbol"?e+"":e,r);var $={};y($,{FromMain:()=>N,FromMainMessage:()=>R,RendererPlugin:()=>v,ToMainMessage:()=>o,middleWare:()=>f});module.exports=h($);var a=require("@virid/core");var I=require("@virid/core");var w=class w extends I.EventMessage{constructor(){super(...arguments);d(this,"__virid_source","unknown");d(this,"__virid_target","");d(this,"__virid_message_type","")}};t(w,"FromMainMessage");var R=w,p=class p extends I.EventMessage{};t(p,"ToMainMessage"),d(p,"__virid_source");var o=p;var E=require("@virid/core");var f=t((i,e)=>{if(i instanceof o){let{__virid_target:r,__virid_message_type:s,..._}=i;if(r==o.__virid_source){E.MessageWriter.warn(`[Virid Render] Prohibit Sending To Oneself: ${r} is not allowed in ToRenderMessage.`);return}window.__VIRID_BRIDGE__.post({__virid_source:o.__virid_source,__virid_target:r,__virid_message_type:s,payload:_})}else e()},"middleWare");var u=require("@virid/core"),c={...u.VIRID_METADATA,FROMMAIN:"virid:renderer:frommain"};function N(i){return function(e){Reflect.defineMetadata(c.FROMMAIN,i,e)}}t(N,"FromMain");var g=class g{constructor(){d(this,"name","@virid/renderer");d(this,"message_map",new Map)}install(e,r){if(!window.__VIRID_BRIDGE__){a.MessageWriter.error(new Error("[Virid Render] Preloading Failed: Please initialize in the preloaded script first."));return}if(!r.windowId){a.MessageWriter.error(new Error(`[Virid Render] Activate Failed: Please provide the windowId:${r?.windowId}.`));return}o.__virid_source=r.windowId,window.__VIRID_BRIDGE__.subscribe(this.convertFromMainMessage),window.__VIRID_BRIDGE__.post({__virid_source:r.windowId,__virid_target:"main",__virid_message_type:"VIRID_INTERNAL_REGISTER",payload:{windowId:r.windowId}}),e.useMiddleware(f)}bindRoute(e){let r=Reflect.getMetadata(c.FROMMAIN,e);this.message_map.has(r)&&a.MessageWriter.error(new Error(`[Virid Renderer] Duplicate IpcMessage: Registration for route: ${r}, message class: ${e}`)),this.message_map.set(r,e)}convertFromMainMessage(e){let{__virid_source:r,__virid_target:s,__virid_message_type:_,payload:l}=e;if(!_||!r||!s){a.MessageWriter.error(new Error(`[Virid Render] Incomplete Data:
5
+ var m=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var x=(i,e,r)=>e in i?m(i,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):i[e]=r;var t=(i,e)=>m(i,"name",{value:e,configurable:!0});var y=(i,e)=>{for(var r in e)m(i,r,{get:e[r],enumerable:!0})},h=(i,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let _ of A(e))!V.call(i,_)&&_!==r&&m(i,_,{get:()=>e[_],enumerable:!(s=M(e,_))||s.enumerable});return i};var T=i=>h(m({},"__esModule",{value:!0}),i);var d=(i,e,r)=>x(i,typeof e!="symbol"?e+"":e,r);var $={};y($,{FromMain:()=>N,FromMainMessage:()=>R,RendererPlugin:()=>v,ToMainMessage:()=>o,middleWare:()=>f});module.exports=T($);var a=require("@virid/core");var I=require("@virid/core");var w=class w extends I.EventMessage{constructor(){super(...arguments);d(this,"__virid_source","unknown");d(this,"__virid_target","");d(this,"__virid_message_type","")}};t(w,"FromMainMessage");var R=w,p=class p extends I.EventMessage{};t(p,"ToMainMessage"),d(p,"__virid_source");var o=p;var E=require("@virid/core");var f=t((i,e)=>{if(i instanceof o){let{__virid_target:r,__virid_message_type:s,..._}=i;if(r==o.__virid_source){E.MessageWriter.warn(`[Virid Render] Prohibit Sending To Oneself: ${r} is not allowed in ToRenderMessage.`);return}window.__VIRID_BRIDGE__.post({__virid_source:o.__virid_source,__virid_target:r,__virid_message_type:s,payload:_})}else e()},"middleWare");var u=require("@virid/core"),c={...u.VIRID_METADATA,FROMMAIN:"virid:renderer:frommain"};function N(i){return function(e){Reflect.defineMetadata(c.FROMMAIN,i,e)}}t(N,"FromMain");var g=class g{constructor(){d(this,"name","@virid/renderer");d(this,"message_map",new Map)}install(e,r){if(!window.__VIRID_BRIDGE__){a.MessageWriter.error(new Error("[Virid Render] Preloading Failed: Please initialize in the preloaded script first."));return}if(!r.windowId){a.MessageWriter.error(new Error(`[Virid Render] Activate Failed: Please provide the windowId:${r?.windowId}.`));return}o.__virid_source=r.windowId,window.__VIRID_BRIDGE__.subscribe(this.convertFromMainMessage.bind(this)),window.__VIRID_BRIDGE__.post({__virid_source:r.windowId,__virid_target:"main",__virid_message_type:"VIRID_INTERNAL_REGISTER",payload:{windowId:r.windowId}}),e.useMiddleware(f)}bindRoute(e){let r=Reflect.getMetadata(c.FROMMAIN,e);this.message_map.has(r)&&a.MessageWriter.error(new Error(`[Virid Renderer] Duplicate IpcMessage: Registration for route: ${r}, message class: ${e}`)),this.message_map.set(r,e)}convertFromMainMessage(e){let{__virid_source:r,__virid_target:s,__virid_message_type:_,payload:l}=e;if(!_||!r||!s){a.MessageWriter.error(new Error(`[Virid Render] Incomplete Data:
6
6
  __virid_source: ${r}
7
7
  __virid_target:${s}
8
8
  __virid_message_type: ${_}.`));return}if(!this.message_map.has(_)){a.MessageWriter.error(new Error(`[Virid Render] Unregistered type: ${_} `));return}let D=this.message_map.get(_),n=new D;n.__virid_source=r,n.__virid_target=s,n.__virid_message_type=_,l&&Object.assign(n,l),a.MessageWriter.write(n)}};t(g,"RendererPlugin");var v=g;0&&(module.exports={FromMain,FromMainMessage,RendererPlugin,ToMainMessage,middleWare});
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/renderer/message.ts","../src/renderer/middleware.ts","../src/renderer/constant.ts","../src/renderer/decorator.ts"],"sourcesContent":["/*\n * Copyright (c) 2026-present Ailrid\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * Description: Electron renderer process adapter for virid, responsible for forwarding and receiving messages from the main process.\n */\nimport {\n MessageWriter,\n Newable,\n ViridPlugin,\n type ViridApp,\n} from \"@virid/core\";\nimport { type PluginOption } from \"./interfaces\";\nimport { FromMainMessage } from \"./renderer\";\nimport { middleWare, ToMainMessage } from \"./renderer\";\nimport { VIRID_RENDERER_METADATA } from \"./renderer/constant\";\n\nexport * from \"./interfaces\";\nexport * from \"./renderer\";\n\nexport class RendererPlugin implements ViridPlugin<PluginOption> {\n name = \"@virid/renderer\";\n public message_map = new Map<string, Newable<FromMainMessage>>();\n\n install(app: ViridApp, options: PluginOption) {\n // first, check if the preload script has been loaded\n if (!window.__VIRID_BRIDGE__) {\n MessageWriter.error(\n new Error(\n `[Virid Render] Preloading Failed: Please initialize in the preloaded script first.`,\n ),\n );\n return;\n }\n // check whether parameters are passed\n if (!options.windowId) {\n MessageWriter.error(\n new Error(\n `[Virid Render] Activate Failed: Please provide the windowId:${options?.windowId}.`,\n ),\n );\n return;\n }\n // register your own id, so that all messages sent to the main process will carry your own id in the future\n ToMainMessage.__virid_source = options.windowId;\n // Subscribe to the ipc channel, and convert all returned messages into our own message types according to the registry\n window.__VIRID_BRIDGE__.subscribe(this.convertFromMainMessage);\n // actively send a registration message to the main process to register itself\n window.__VIRID_BRIDGE__.post({\n __virid_source: options.windowId,\n __virid_target: \"main\",\n __virid_message_type: \"VIRID_INTERNAL_REGISTER\",\n payload: {\n windowId: options.windowId,\n },\n });\n // register your own middleware function to intercept messages of type ToMainMessage and forward them to the main process of electron\n app.useMiddleware(middleWare);\n }\n bindRoute(target: Newable<FromMainMessage>) {\n const route = Reflect.getMetadata(VIRID_RENDERER_METADATA.FROMMAIN, target);\n if (this.message_map.has(route)) {\n MessageWriter.error(\n new Error(\n `[Virid Renderer] Duplicate IpcMessage: Registration for route: ${route}, message class: ${target}`,\n ),\n );\n }\n this.message_map.set(route, target);\n }\n\n convertFromMainMessage(ipcMessage: any): void {\n const { __virid_source, __virid_target, __virid_message_type, payload } =\n ipcMessage;\n if (!__virid_message_type || !__virid_source || !__virid_target) {\n MessageWriter.error(\n new Error(\n `[Virid Render] Incomplete Data:\\n__virid_source: ${__virid_source}\\n__virid_target:${__virid_target}\\n__virid_message_type: ${__virid_message_type}.`,\n ),\n );\n return;\n }\n if (!this.message_map.has(__virid_message_type)) {\n MessageWriter.error(\n new Error(`[Virid Render] Unregistered type: ${__virid_message_type} `),\n );\n return;\n }\n // Find the corresponding constructor\n const MessageClass = this.message_map.get(__virid_message_type)!;\n // Instantiate and inject parameters\n const instance = new MessageClass();\n\n // Explicitly assigning base class identifiers to ensure complete identity information of instances\n instance.__virid_source = __virid_source;\n instance.__virid_target = __virid_target;\n instance.__virid_message_type = __virid_message_type;\n\n // Restore data\n if (payload) {\n Object.assign(instance, payload);\n }\n\n // Redistribution\n MessageWriter.write(instance);\n }\n}\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Renderer\n */\nimport { EventMessage } from \"@virid/core\";\n/**\n * RenderMessage: Message sent by the main process\n */\nexport abstract class FromMainMessage extends EventMessage {\n /** Where am I from?\n */\n public __virid_source: string = \"unknown\";\n /**Where is my destination?\n *'main ': Sent to the main process for processing\n *'all': Broadcast to all windows (relayed through the main process)\n *String: Specify the ID of a window (windowId)\n */\n public __virid_target: string = \"\";\n /**\n *What message should I turn into at the destination?\n */\n public __virid_message_type: string = \"\";\n}\n\n/**\n *RenderMessage: Initiated by the rendering process, targeting the main process or other windows\n */\nexport abstract class ToMainMessage extends EventMessage {\n /**Where am I from?\n */\n public static __virid_source: string;\n\n /**Where is my destination?\n *'main ': Sent to the main process for processing\n *'all': Broadcast to all windows (relayed through the main process)\n *String: Specify the ID of a window (windowId)\n */\n public abstract __virid_target: string;\n\n /**\n *What message should I turn into at the destination?\n */\n public abstract __virid_message_type: string;\n}\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Renderer\n */\nimport { type Middleware, MessageWriter } from \"@virid/core\";\nimport { ToMainMessage } from \"./message\";\nexport const middleWare: Middleware = (message, next) => {\n // If the message inherits from ToMainMessage, intercept concurrency to the main process\n if (message instanceof ToMainMessage) {\n const { __virid_target, __virid_message_type, ...payload } = message;\n if (__virid_target == ToMainMessage.__virid_source) {\n MessageWriter.warn(\n `[Virid Render] Prohibit Sending To Oneself: ${__virid_target} is not allowed in ToRenderMessage.`,\n );\n return;\n }\n window.__VIRID_BRIDGE__.post({\n __virid_source: ToMainMessage.__virid_source,\n __virid_target: __virid_target,\n __virid_message_type: __virid_message_type,\n payload: payload, // Expand all attributes on the instance\n });\n } else {\n next();\n }\n};\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Renderer\n */\nimport { VIRID_METADATA } from \"@virid/core\";\n\nexport const VIRID_RENDERER_METADATA = {\n ...VIRID_METADATA,\n FROMMAIN: \"virid:renderer:frommain\",\n} as const;\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Renderer\n */\nimport { Newable } from \"@virid/core\";\nimport { type FromMainMessage } from \"./message\";\nimport { VIRID_RENDERER_METADATA } from \"./constant\";\nexport function FromMain(type: string) {\n return function (target: Newable<FromMainMessage>) {\n Reflect.defineMetadata(VIRID_RENDERER_METADATA.FROMMAIN, type, target);\n };\n}\n"],"mappings":";;;;ulBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,cAAAE,EAAA,oBAAAC,EAAA,mBAAAC,EAAA,kBAAAC,EAAA,eAAAC,IAAA,eAAAC,EAAAP,GAiBA,IAAAQ,EAKO,uBCjBP,IAAAC,EAA6B,uBAItB,IAAeC,EAAf,MAAeA,UAAwBC,cAAAA,CAAvC,kCAGEC,EAAAA,sBAAyB,WAMzBC,EAAAA,sBAAyB,IAIzBC,EAAAA,4BAA+B,IACxC,EAd8CH,EAAAA,EAAAA,mBAAvC,IAAeD,EAAfK,EAmBeC,EAAf,MAAeA,UAAsBL,cAAAA,CAgB5C,EAhB4CA,EAAAA,EAAAA,iBAG1CM,EAHoBD,EAGNJ,kBAHT,IAAeI,EAAfE,ECvBP,IAAAC,EAA+C,uBAExC,IAAMC,EAAyBC,EAAA,CAACC,EAASC,IAAAA,CAE9C,GAAID,aAAmBE,EAAe,CACpC,GAAM,CAAEC,eAAAA,EAAgBC,qBAAAA,EAAsB,GAAGC,CAAAA,EAAYL,EAC7D,GAAIG,GAAkBD,EAAcI,eAAgB,CAClDC,gBAAcC,KACZ,+CAA+CL,CAAAA,qCAAmD,EAEpG,MACF,CACAM,OAAOC,iBAAiBC,KAAK,CAC3BL,eAAgBJ,EAAcI,eAC9BH,eAAgBA,EAChBC,qBAAsBA,EACtBC,QAASA,CACX,CAAA,CACF,MACEJ,EAAAA,CAEJ,EAnBsC,cCFtC,IAAAW,EAA+B,uBAElBC,EAA0B,CACrC,GAAGC,iBACH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GAAuB,CAAA,EAG1J,MACF,CACA,GAAI,CAAC,KAAKjB,YAAY4B,IAAIX,CAAAA,EAAuB,CAC/CV,gBAAcC,MACZ,IAAIC,MAAM,qCAAqCQ,CAAAA,GAAuB,CAAA,EAExE,MACF,CAEA,IAAMc,EAAe,KAAK/B,YAAYgC,IAAIf,CAAAA,EAEpCgB,EAAW,IAAIF,EAGrBE,EAASrB,eAAiBA,EAC1BqB,EAASjB,eAAiBA,EAC1BiB,EAAShB,qBAAuBA,EAG5BC,GACFgB,OAAOC,OAAOF,EAAUf,CAAAA,EAI1BX,gBAAc6B,MAAMH,CAAAA,CACtB,CACF,EAtFanC,EAAAA,EAAAA,kBAAN,IAAMA,EAANuC","names":["index_exports","__export","FromMain","FromMainMessage","RendererPlugin","ToMainMessage","middleWare","__toCommonJS","import_core","import_core","FromMainMessage","EventMessage","__virid_source","__virid_target","__virid_message_type","_FromMainMessage","ToMainMessage","__publicField","_ToMainMessage","import_core","middleWare","__name","message","next","ToMainMessage","__virid_target","__virid_message_type","payload","__virid_source","MessageWriter","warn","window","__VIRID_BRIDGE__","post","import_core","VIRID_RENDERER_METADATA","VIRID_METADATA","FROMMAIN","FromMain","type","target","Reflect","defineMetadata","VIRID_RENDERER_METADATA","FROMMAIN","RendererPlugin","name","message_map","Map","install","app","options","window","__VIRID_BRIDGE__","MessageWriter","error","Error","windowId","ToMainMessage","__virid_source","subscribe","convertFromMainMessage","post","__virid_target","__virid_message_type","payload","useMiddleware","middleWare","bindRoute","target","route","Reflect","getMetadata","VIRID_RENDERER_METADATA","FROMMAIN","has","set","ipcMessage","MessageClass","get","instance","Object","assign","write","_RendererPlugin"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/renderer/message.ts","../src/renderer/middleware.ts","../src/renderer/constant.ts","../src/renderer/decorator.ts"],"sourcesContent":["/*\n * Copyright (c) 2026-present Ailrid\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * Description: Electron renderer process adapter for virid, responsible for forwarding and receiving messages from the main process.\n */\nimport {\n MessageWriter,\n Newable,\n ViridPlugin,\n type ViridApp,\n} from \"@virid/core\";\nimport { type PluginOption } from \"./interfaces\";\nimport { FromMainMessage } from \"./renderer\";\nimport { middleWare, ToMainMessage } from \"./renderer\";\nimport { VIRID_RENDERER_METADATA } from \"./renderer/constant\";\n\nexport * from \"./interfaces\";\nexport * from \"./renderer\";\n\nexport class RendererPlugin implements ViridPlugin<PluginOption> {\n name = \"@virid/renderer\";\n public message_map = new Map<string, Newable<FromMainMessage>>();\n\n install(app: ViridApp, options: PluginOption) {\n // first, check if the preload script has been loaded\n if (!window.__VIRID_BRIDGE__) {\n MessageWriter.error(\n new Error(\n `[Virid Render] Preloading Failed: Please initialize in the preloaded script first.`,\n ),\n );\n return;\n }\n // check whether parameters are passed\n if (!options.windowId) {\n MessageWriter.error(\n new Error(\n `[Virid Render] Activate Failed: Please provide the windowId:${options?.windowId}.`,\n ),\n );\n return;\n }\n // register your own id, so that all messages sent to the main process will carry your own id in the future\n ToMainMessage.__virid_source = options.windowId;\n // Subscribe to the ipc channel, and convert all returned messages into our own message types according to the registry\n window.__VIRID_BRIDGE__.subscribe(this.convertFromMainMessage.bind(this));\n // actively send a registration message to the main process to register itself\n window.__VIRID_BRIDGE__.post({\n __virid_source: options.windowId,\n __virid_target: \"main\",\n __virid_message_type: \"VIRID_INTERNAL_REGISTER\",\n payload: {\n windowId: options.windowId,\n },\n });\n // register your own middleware function to intercept messages of type ToMainMessage and forward them to the main process of electron\n app.useMiddleware(middleWare);\n }\n bindRoute(target: Newable<FromMainMessage>) {\n const route = Reflect.getMetadata(VIRID_RENDERER_METADATA.FROMMAIN, target);\n if (this.message_map.has(route)) {\n MessageWriter.error(\n new Error(\n `[Virid Renderer] Duplicate IpcMessage: Registration for route: ${route}, message class: ${target}`,\n ),\n );\n }\n this.message_map.set(route, target);\n }\n\n convertFromMainMessage(ipcMessage: any): void {\n const { __virid_source, __virid_target, __virid_message_type, payload } =\n ipcMessage;\n if (!__virid_message_type || !__virid_source || !__virid_target) {\n MessageWriter.error(\n new Error(\n `[Virid Render] Incomplete Data:\\n__virid_source: ${__virid_source}\\n__virid_target:${__virid_target}\\n__virid_message_type: ${__virid_message_type}.`,\n ),\n );\n return;\n }\n if (!this.message_map.has(__virid_message_type)) {\n MessageWriter.error(\n new Error(`[Virid Render] Unregistered type: ${__virid_message_type} `),\n );\n return;\n }\n // Find the corresponding constructor\n const MessageClass = this.message_map.get(__virid_message_type)!;\n // Instantiate and inject parameters\n const instance = new MessageClass();\n\n // Explicitly assigning base class identifiers to ensure complete identity information of instances\n instance.__virid_source = __virid_source;\n instance.__virid_target = __virid_target;\n instance.__virid_message_type = __virid_message_type;\n\n // Restore data\n if (payload) {\n Object.assign(instance, payload);\n }\n\n // Redistribution\n MessageWriter.write(instance);\n }\n}\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Renderer\n */\nimport { EventMessage } from \"@virid/core\";\n/**\n * RenderMessage: Message sent by the main process\n */\nexport abstract class FromMainMessage extends EventMessage {\n /** Where am I from?\n */\n public __virid_source: string = \"unknown\";\n /**Where is my destination?\n *'main ': Sent to the main process for processing\n *'all': Broadcast to all windows (relayed through the main process)\n *String: Specify the ID of a window (windowId)\n */\n public __virid_target: string = \"\";\n /**\n *What message should I turn into at the destination?\n */\n public __virid_message_type: string = \"\";\n}\n\n/**\n *RenderMessage: Initiated by the rendering process, targeting the main process or other windows\n */\nexport abstract class ToMainMessage extends EventMessage {\n /**Where am I from?\n */\n public static __virid_source: string;\n\n /**Where is my destination?\n *'main ': Sent to the main process for processing\n *'all': Broadcast to all windows (relayed through the main process)\n *String: Specify the ID of a window (windowId)\n */\n public abstract __virid_target: string;\n\n /**\n *What message should I turn into at the destination?\n */\n public abstract __virid_message_type: string;\n}\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Renderer\n */\nimport { type Middleware, MessageWriter } from \"@virid/core\";\nimport { ToMainMessage } from \"./message\";\nexport const middleWare: Middleware = (message, next) => {\n // If the message inherits from ToMainMessage, intercept concurrency to the main process\n if (message instanceof ToMainMessage) {\n const { __virid_target, __virid_message_type, ...payload } = message;\n if (__virid_target == ToMainMessage.__virid_source) {\n MessageWriter.warn(\n `[Virid Render] Prohibit Sending To Oneself: ${__virid_target} is not allowed in ToRenderMessage.`,\n );\n return;\n }\n window.__VIRID_BRIDGE__.post({\n __virid_source: ToMainMessage.__virid_source,\n __virid_target: __virid_target,\n __virid_message_type: __virid_message_type,\n payload: payload, // Expand all attributes on the instance\n });\n } else {\n next();\n }\n};\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Renderer\n */\nimport { VIRID_METADATA } from \"@virid/core\";\n\nexport const VIRID_RENDERER_METADATA = {\n ...VIRID_METADATA,\n FROMMAIN: \"virid:renderer:frommain\",\n} as const;\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Renderer\n */\nimport { Newable } from \"@virid/core\";\nimport { type FromMainMessage } from \"./message\";\nimport { VIRID_RENDERER_METADATA } from \"./constant\";\nexport function FromMain(type: string) {\n return function (target: Newable<FromMainMessage>) {\n Reflect.defineMetadata(VIRID_RENDERER_METADATA.FROMMAIN, type, target);\n };\n}\n"],"mappings":";;;;ulBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,cAAAE,EAAA,oBAAAC,EAAA,mBAAAC,EAAA,kBAAAC,EAAA,eAAAC,IAAA,eAAAC,EAAAP,GAiBA,IAAAQ,EAKO,uBCjB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EAANwC","names":["index_exports","__export","FromMain","FromMainMessage","RendererPlugin","ToMainMessage","middleWare","__toCommonJS","import_core","import_core","FromMainMessage","EventMessage","__virid_source","__virid_target","__virid_message_type","_FromMainMessage","ToMainMessage","__publicField","_ToMainMessage","import_core","middleWare","__name","message","next","ToMainMessage","__virid_target","__virid_message_type","payload","__virid_source","MessageWriter","warn","window","__VIRID_BRIDGE__","post","import_core","VIRID_RENDERER_METADATA","VIRID_METADATA","FROMMAIN","FromMain","type","target","Reflect","defineMetadata","VIRID_RENDERER_METADATA","FROMMAIN","RendererPlugin","name","message_map","Map","install","app","options","window","__VIRID_BRIDGE__","MessageWriter","error","Error","windowId","ToMainMessage","__virid_source","subscribe","convertFromMainMessage","bind","post","__virid_target","__virid_message_type","payload","useMiddleware","middleWare","bindRoute","target","route","Reflect","getMetadata","VIRID_RENDERER_METADATA","FROMMAIN","has","set","ipcMessage","MessageClass","get","instance","Object","assign","write","_RendererPlugin"]}
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  /**
2
- * @virid/renderer v0.3.15
2
+ * @virid/renderer v0.3.16
3
3
  * Electron renderer process adapter for virid, responsible for forwarding and receiving messages from the main process
4
4
  */
5
- var w=Object.defineProperty;var u=(i,e,r)=>e in i?w(i,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):i[e]=r;var _=(i,e)=>w(i,"name",{value:e,configurable:!0});var o=(i,e,r)=>u(i,typeof e!="symbol"?e+"":e,r);import{MessageWriter as d}from"@virid/core";import{EventMessage as v}from"@virid/core";var c=class c extends v{constructor(){super(...arguments);o(this,"__virid_source","unknown");o(this,"__virid_target","");o(this,"__virid_message_type","")}};_(c,"FromMainMessage");var f=c,m=class m extends v{};_(m,"ToMainMessage"),o(m,"__virid_source");var s=m;import{MessageWriter as D}from"@virid/core";var g=_((i,e)=>{if(i instanceof s){let{__virid_target:r,__virid_message_type:a,...t}=i;if(r==s.__virid_source){D.warn(`[Virid Render] Prohibit Sending To Oneself: ${r} is not allowed in ToRenderMessage.`);return}window.__VIRID_BRIDGE__.post({__virid_source:s.__virid_source,__virid_target:r,__virid_message_type:a,payload:t})}else e()},"middleWare");import{VIRID_METADATA as M}from"@virid/core";var p={...M,FROMMAIN:"virid:renderer:frommain"};function O(i){return function(e){Reflect.defineMetadata(p.FROMMAIN,i,e)}}_(O,"FromMain");var R=class R{constructor(){o(this,"name","@virid/renderer");o(this,"message_map",new Map)}install(e,r){if(!window.__VIRID_BRIDGE__){d.error(new Error("[Virid Render] Preloading Failed: Please initialize in the preloaded script first."));return}if(!r.windowId){d.error(new Error(`[Virid Render] Activate Failed: Please provide the windowId:${r?.windowId}.`));return}s.__virid_source=r.windowId,window.__VIRID_BRIDGE__.subscribe(this.convertFromMainMessage),window.__VIRID_BRIDGE__.post({__virid_source:r.windowId,__virid_target:"main",__virid_message_type:"VIRID_INTERNAL_REGISTER",payload:{windowId:r.windowId}}),e.useMiddleware(g)}bindRoute(e){let r=Reflect.getMetadata(p.FROMMAIN,e);this.message_map.has(r)&&d.error(new Error(`[Virid Renderer] Duplicate IpcMessage: Registration for route: ${r}, message class: ${e}`)),this.message_map.set(r,e)}convertFromMainMessage(e){let{__virid_source:r,__virid_target:a,__virid_message_type:t,payload:I}=e;if(!t||!r||!a){d.error(new Error(`[Virid Render] Incomplete Data:
5
+ var w=Object.defineProperty;var u=(i,e,r)=>e in i?w(i,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):i[e]=r;var _=(i,e)=>w(i,"name",{value:e,configurable:!0});var o=(i,e,r)=>u(i,typeof e!="symbol"?e+"":e,r);import{MessageWriter as d}from"@virid/core";import{EventMessage as v}from"@virid/core";var c=class c extends v{constructor(){super(...arguments);o(this,"__virid_source","unknown");o(this,"__virid_target","");o(this,"__virid_message_type","")}};_(c,"FromMainMessage");var f=c,m=class m extends v{};_(m,"ToMainMessage"),o(m,"__virid_source");var s=m;import{MessageWriter as D}from"@virid/core";var g=_((i,e)=>{if(i instanceof s){let{__virid_target:r,__virid_message_type:a,...t}=i;if(r==s.__virid_source){D.warn(`[Virid Render] Prohibit Sending To Oneself: ${r} is not allowed in ToRenderMessage.`);return}window.__VIRID_BRIDGE__.post({__virid_source:s.__virid_source,__virid_target:r,__virid_message_type:a,payload:t})}else e()},"middleWare");import{VIRID_METADATA as M}from"@virid/core";var p={...M,FROMMAIN:"virid:renderer:frommain"};function O(i){return function(e){Reflect.defineMetadata(p.FROMMAIN,i,e)}}_(O,"FromMain");var R=class R{constructor(){o(this,"name","@virid/renderer");o(this,"message_map",new Map)}install(e,r){if(!window.__VIRID_BRIDGE__){d.error(new Error("[Virid Render] Preloading Failed: Please initialize in the preloaded script first."));return}if(!r.windowId){d.error(new Error(`[Virid Render] Activate Failed: Please provide the windowId:${r?.windowId}.`));return}s.__virid_source=r.windowId,window.__VIRID_BRIDGE__.subscribe(this.convertFromMainMessage.bind(this)),window.__VIRID_BRIDGE__.post({__virid_source:r.windowId,__virid_target:"main",__virid_message_type:"VIRID_INTERNAL_REGISTER",payload:{windowId:r.windowId}}),e.useMiddleware(g)}bindRoute(e){let r=Reflect.getMetadata(p.FROMMAIN,e);this.message_map.has(r)&&d.error(new Error(`[Virid Renderer] Duplicate IpcMessage: Registration for route: ${r}, message class: ${e}`)),this.message_map.set(r,e)}convertFromMainMessage(e){let{__virid_source:r,__virid_target:a,__virid_message_type:t,payload:I}=e;if(!t||!r||!a){d.error(new Error(`[Virid Render] Incomplete Data:
6
6
  __virid_source: ${r}
7
7
  __virid_target:${a}
8
8
  __virid_message_type: ${t}.`));return}if(!this.message_map.has(t)){d.error(new Error(`[Virid Render] Unregistered type: ${t} `));return}let E=this.message_map.get(t),n=new E;n.__virid_source=r,n.__virid_target=a,n.__virid_message_type=t,I&&Object.assign(n,I),d.write(n)}};_(R,"RendererPlugin");var l=R;export{O as FromMain,f as FromMainMessage,l as RendererPlugin,s as ToMainMessage,g as middleWare};
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/renderer/message.ts","../src/renderer/middleware.ts","../src/renderer/constant.ts","../src/renderer/decorator.ts"],"sourcesContent":["/*\n * Copyright (c) 2026-present Ailrid\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * Description: Electron renderer process adapter for virid, responsible for forwarding and receiving messages from the main process.\n */\nimport {\n MessageWriter,\n Newable,\n ViridPlugin,\n type ViridApp,\n} from \"@virid/core\";\nimport { type PluginOption } from \"./interfaces\";\nimport { FromMainMessage } from \"./renderer\";\nimport { middleWare, ToMainMessage } from \"./renderer\";\nimport { VIRID_RENDERER_METADATA } from \"./renderer/constant\";\n\nexport * from \"./interfaces\";\nexport * from \"./renderer\";\n\nexport class RendererPlugin implements ViridPlugin<PluginOption> {\n name = \"@virid/renderer\";\n public message_map = new Map<string, Newable<FromMainMessage>>();\n\n install(app: ViridApp, options: PluginOption) {\n // first, check if the preload script has been loaded\n if (!window.__VIRID_BRIDGE__) {\n MessageWriter.error(\n new Error(\n `[Virid Render] Preloading Failed: Please initialize in the preloaded script first.`,\n ),\n );\n return;\n }\n // check whether parameters are passed\n if (!options.windowId) {\n MessageWriter.error(\n new Error(\n `[Virid Render] Activate Failed: Please provide the windowId:${options?.windowId}.`,\n ),\n );\n return;\n }\n // register your own id, so that all messages sent to the main process will carry your own id in the future\n ToMainMessage.__virid_source = options.windowId;\n // Subscribe to the ipc channel, and convert all returned messages into our own message types according to the registry\n window.__VIRID_BRIDGE__.subscribe(this.convertFromMainMessage);\n // actively send a registration message to the main process to register itself\n window.__VIRID_BRIDGE__.post({\n __virid_source: options.windowId,\n __virid_target: \"main\",\n __virid_message_type: \"VIRID_INTERNAL_REGISTER\",\n payload: {\n windowId: options.windowId,\n },\n });\n // register your own middleware function to intercept messages of type ToMainMessage and forward them to the main process of electron\n app.useMiddleware(middleWare);\n }\n bindRoute(target: Newable<FromMainMessage>) {\n const route = Reflect.getMetadata(VIRID_RENDERER_METADATA.FROMMAIN, target);\n if (this.message_map.has(route)) {\n MessageWriter.error(\n new Error(\n `[Virid Renderer] Duplicate IpcMessage: Registration for route: ${route}, message class: ${target}`,\n ),\n );\n }\n this.message_map.set(route, target);\n }\n\n convertFromMainMessage(ipcMessage: any): void {\n const { __virid_source, __virid_target, __virid_message_type, payload } =\n ipcMessage;\n if (!__virid_message_type || !__virid_source || !__virid_target) {\n MessageWriter.error(\n new Error(\n `[Virid Render] Incomplete Data:\\n__virid_source: ${__virid_source}\\n__virid_target:${__virid_target}\\n__virid_message_type: ${__virid_message_type}.`,\n ),\n );\n return;\n }\n if (!this.message_map.has(__virid_message_type)) {\n MessageWriter.error(\n new Error(`[Virid Render] Unregistered type: ${__virid_message_type} `),\n );\n return;\n }\n // Find the corresponding constructor\n const MessageClass = this.message_map.get(__virid_message_type)!;\n // Instantiate and inject parameters\n const instance = new MessageClass();\n\n // Explicitly assigning base class identifiers to ensure complete identity information of instances\n instance.__virid_source = __virid_source;\n instance.__virid_target = __virid_target;\n instance.__virid_message_type = __virid_message_type;\n\n // Restore data\n if (payload) {\n Object.assign(instance, payload);\n }\n\n // Redistribution\n MessageWriter.write(instance);\n }\n}\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Renderer\n */\nimport { EventMessage } from \"@virid/core\";\n/**\n * RenderMessage: Message sent by the main process\n */\nexport abstract class FromMainMessage extends EventMessage {\n /** Where am I from?\n */\n public __virid_source: string = \"unknown\";\n /**Where is my destination?\n *'main ': Sent to the main process for processing\n *'all': Broadcast to all windows (relayed through the main process)\n *String: Specify the ID of a window (windowId)\n */\n public __virid_target: string = \"\";\n /**\n *What message should I turn into at the destination?\n */\n public __virid_message_type: string = \"\";\n}\n\n/**\n *RenderMessage: Initiated by the rendering process, targeting the main process or other windows\n */\nexport abstract class ToMainMessage extends EventMessage {\n /**Where am I from?\n */\n public static __virid_source: string;\n\n /**Where is my destination?\n *'main ': Sent to the main process for processing\n *'all': Broadcast to all windows (relayed through the main process)\n *String: Specify the ID of a window (windowId)\n */\n public abstract __virid_target: string;\n\n /**\n *What message should I turn into at the destination?\n */\n public abstract __virid_message_type: string;\n}\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Renderer\n */\nimport { type Middleware, MessageWriter } from \"@virid/core\";\nimport { ToMainMessage } from \"./message\";\nexport const middleWare: Middleware = (message, next) => {\n // If the message inherits from ToMainMessage, intercept concurrency to the main process\n if (message instanceof ToMainMessage) {\n const { __virid_target, __virid_message_type, ...payload } = message;\n if (__virid_target == ToMainMessage.__virid_source) {\n MessageWriter.warn(\n `[Virid Render] Prohibit Sending To Oneself: ${__virid_target} is not allowed in ToRenderMessage.`,\n );\n return;\n }\n window.__VIRID_BRIDGE__.post({\n __virid_source: ToMainMessage.__virid_source,\n __virid_target: __virid_target,\n __virid_message_type: __virid_message_type,\n payload: payload, // Expand all attributes on the instance\n });\n } else {\n next();\n }\n};\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Renderer\n */\nimport { VIRID_METADATA } from \"@virid/core\";\n\nexport const VIRID_RENDERER_METADATA = {\n ...VIRID_METADATA,\n FROMMAIN: \"virid:renderer:frommain\",\n} as const;\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Renderer\n */\nimport { Newable } from \"@virid/core\";\nimport { type FromMainMessage } from \"./message\";\nimport { VIRID_RENDERER_METADATA } from \"./constant\";\nexport function FromMain(type: string) {\n return function (target: Newable<FromMainMessage>) {\n Reflect.defineMetadata(VIRID_RENDERER_METADATA.FROMMAIN, type, target);\n };\n}\n"],"m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EAtFanC,EAAAA,EAAAA,kBAAN,IAAMA,EAANuC","names":["MessageWriter","EventMessage","FromMainMessage","EventMessage","__virid_source","__virid_target","__virid_message_type","_FromMainMessage","ToMainMessage","__publicField","_ToMainMessage","MessageWriter","middleWare","__name","message","next","ToMainMessage","__virid_target","__virid_message_type","payload","__virid_source","MessageWriter","warn","window","__VIRID_BRIDGE__","post","VIRID_METADATA","VIRID_RENDERER_METADATA","FROMMAIN","FromMain","type","target","Reflect","defineMetadata","VIRID_RENDERER_METADATA","FROMMAIN","RendererPlugin","name","message_map","Map","install","app","options","window","__VIRID_BRIDGE__","MessageWriter","error","Error","windowId","ToMainMessage","__virid_source","subscribe","convertFromMainMessage","post","__virid_target","__virid_message_type","payload","useMiddleware","middleWare","bindRoute","target","route","Reflect","getMetadata","VIRID_RENDERER_METADATA","FROMMAIN","has","set","ipcMessage","MessageClass","get","instance","Object","assign","write","_RendererPlugin"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/renderer/message.ts","../src/renderer/middleware.ts","../src/renderer/constant.ts","../src/renderer/decorator.ts"],"sourcesContent":["/*\n * Copyright (c) 2026-present Ailrid\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * Description: Electron renderer process adapter for virid, responsible for forwarding and receiving messages from the main process.\n */\nimport {\n MessageWriter,\n Newable,\n ViridPlugin,\n type ViridApp,\n} from \"@virid/core\";\nimport { type PluginOption } from \"./interfaces\";\nimport { FromMainMessage } from \"./renderer\";\nimport { middleWare, ToMainMessage } from \"./renderer\";\nimport { VIRID_RENDERER_METADATA } from \"./renderer/constant\";\n\nexport * from \"./interfaces\";\nexport * from \"./renderer\";\n\nexport class RendererPlugin implements ViridPlugin<PluginOption> {\n name = \"@virid/renderer\";\n public message_map = new Map<string, Newable<FromMainMessage>>();\n\n install(app: ViridApp, options: PluginOption) {\n // first, check if the preload script has been loaded\n if (!window.__VIRID_BRIDGE__) {\n MessageWriter.error(\n new Error(\n `[Virid Render] Preloading Failed: Please initialize in the preloaded script first.`,\n ),\n );\n return;\n }\n // check whether parameters are passed\n if (!options.windowId) {\n MessageWriter.error(\n new Error(\n `[Virid Render] Activate Failed: Please provide the windowId:${options?.windowId}.`,\n ),\n );\n return;\n }\n // register your own id, so that all messages sent to the main process will carry your own id in the future\n ToMainMessage.__virid_source = options.windowId;\n // Subscribe to the ipc channel, and convert all returned messages into our own message types according to the registry\n window.__VIRID_BRIDGE__.subscribe(this.convertFromMainMessage.bind(this));\n // actively send a registration message to the main process to register itself\n window.__VIRID_BRIDGE__.post({\n __virid_source: options.windowId,\n __virid_target: \"main\",\n __virid_message_type: \"VIRID_INTERNAL_REGISTER\",\n payload: {\n windowId: options.windowId,\n },\n });\n // register your own middleware function to intercept messages of type ToMainMessage and forward them to the main process of electron\n app.useMiddleware(middleWare);\n }\n bindRoute(target: Newable<FromMainMessage>) {\n const route = Reflect.getMetadata(VIRID_RENDERER_METADATA.FROMMAIN, target);\n if (this.message_map.has(route)) {\n MessageWriter.error(\n new Error(\n `[Virid Renderer] Duplicate IpcMessage: Registration for route: ${route}, message class: ${target}`,\n ),\n );\n }\n this.message_map.set(route, target);\n }\n\n convertFromMainMessage(ipcMessage: any): void {\n const { __virid_source, __virid_target, __virid_message_type, payload } =\n ipcMessage;\n if (!__virid_message_type || !__virid_source || !__virid_target) {\n MessageWriter.error(\n new Error(\n `[Virid Render] Incomplete Data:\\n__virid_source: ${__virid_source}\\n__virid_target:${__virid_target}\\n__virid_message_type: ${__virid_message_type}.`,\n ),\n );\n return;\n }\n if (!this.message_map.has(__virid_message_type)) {\n MessageWriter.error(\n new Error(`[Virid Render] Unregistered type: ${__virid_message_type} `),\n );\n return;\n }\n // Find the corresponding constructor\n const MessageClass = this.message_map.get(__virid_message_type)!;\n // Instantiate and inject parameters\n const instance = new MessageClass();\n\n // Explicitly assigning base class identifiers to ensure complete identity information of instances\n instance.__virid_source = __virid_source;\n instance.__virid_target = __virid_target;\n instance.__virid_message_type = __virid_message_type;\n\n // Restore data\n if (payload) {\n Object.assign(instance, payload);\n }\n\n // Redistribution\n MessageWriter.write(instance);\n }\n}\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Renderer\n */\nimport { EventMessage } from \"@virid/core\";\n/**\n * RenderMessage: Message sent by the main process\n */\nexport abstract class FromMainMessage extends EventMessage {\n /** Where am I from?\n */\n public __virid_source: string = \"unknown\";\n /**Where is my destination?\n *'main ': Sent to the main process for processing\n *'all': Broadcast to all windows (relayed through the main process)\n *String: Specify the ID of a window (windowId)\n */\n public __virid_target: string = \"\";\n /**\n *What message should I turn into at the destination?\n */\n public __virid_message_type: string = \"\";\n}\n\n/**\n *RenderMessage: Initiated by the rendering process, targeting the main process or other windows\n */\nexport abstract class ToMainMessage extends EventMessage {\n /**Where am I from?\n */\n public static __virid_source: string;\n\n /**Where is my destination?\n *'main ': Sent to the main process for processing\n *'all': Broadcast to all windows (relayed through the main process)\n *String: Specify the ID of a window (windowId)\n */\n public abstract __virid_target: string;\n\n /**\n *What message should I turn into at the destination?\n */\n public abstract __virid_message_type: string;\n}\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Renderer\n */\nimport { type Middleware, MessageWriter } from \"@virid/core\";\nimport { ToMainMessage } from \"./message\";\nexport const middleWare: Middleware = (message, next) => {\n // If the message inherits from ToMainMessage, intercept concurrency to the main process\n if (message instanceof ToMainMessage) {\n const { __virid_target, __virid_message_type, ...payload } = message;\n if (__virid_target == ToMainMessage.__virid_source) {\n MessageWriter.warn(\n `[Virid Render] Prohibit Sending To Oneself: ${__virid_target} is not allowed in ToRenderMessage.`,\n );\n return;\n }\n window.__VIRID_BRIDGE__.post({\n __virid_source: ToMainMessage.__virid_source,\n __virid_target: __virid_target,\n __virid_message_type: __virid_message_type,\n payload: payload, // Expand all attributes on the instance\n });\n } else {\n next();\n }\n};\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Renderer\n */\nimport { VIRID_METADATA } from \"@virid/core\";\n\nexport const VIRID_RENDERER_METADATA = {\n ...VIRID_METADATA,\n FROMMAIN: \"virid:renderer:frommain\",\n} as const;\n","/*\n * Copyright (c) 2026-present Ailrid.\n * Licensed under the Apache License, Version 2.0.\n * Project: Virid Renderer\n */\nimport { Newable } from \"@virid/core\";\nimport { type FromMainMessage } from \"./message\";\nimport { VIRID_RENDERER_METADATA } from \"./constant\";\nexport function FromMain(type: string) {\n return function (target: Newable<FromMainMessage>) {\n Reflect.defineMetadata(VIRID_RENDERER_METADATA.FROMMAIN, type, target);\n };\n}\n"],"mappings":";;;;uNAiBA,OACEA,iBAAAA,MAIK,cCjBP,OAASC,gBAAAA,MAAoB,cAItB,IAAeC,EAAf,MAAeA,UAAwBC,CAAAA,CAAvC,kCAGEC,EAAAA,sBAAyB,WAMzBC,EAAAA,sBAAyB,IAIzBC,EAAAA,4BAA+B,IACxC,EAd8CH,EAAAA,EAAAA,mBAAvC,IAAeD,EAAfK,EAmBeC,EAAf,MAAeA,UAAsBL,CAAAA,CAgB5C,EAhB4CA,EAAAA,EAAAA,iBAG1CM,EAHoBD,EAGNJ,kBAHT,IAAeI,EAAfE,ECvBP,OAA0BC,iBAAAA,MAAqB,cAExC,IAAMC,EAAyBC,EAAA,CAACC,EAASC,IAAAA,CAE9C,GAAID,aAAmBE,EAAe,CACpC,GAAM,CAAEC,eAAAA,EAAgBC,qBAAAA,EAAsB,GAAGC,CAAAA,EAAYL,EAC7D,GAAIG,GAAkBD,EAAcI,eAAgB,CAClDC,EAAcC,KACZ,+CAA+CL,CAAAA,qCA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AT,uBAAuBiB,EAAuB,CAC5C,GAAM,CAAEnB,eAAAA,EAAgBK,eAAAA,EAAgBC,qBAAAA,EAAsBC,QAAAA,CAAO,EACnEY,EACF,GAAI,CAACb,GAAwB,CAACN,GAAkB,CAACK,EAAgB,CAC/DV,EAAcC,MACZ,IAAIC,MACF;kBAAoDG,CAAAA;iBAAkCK,CAAAA;wBAAyCC,CAAAA,GAAuB,CAAA,EAG1J,MACF,CACA,GAAI,CAAC,KAAKlB,YAAY6B,IAAIX,CAAAA,EAAuB,CAC/CX,EAAcC,MACZ,IAAIC,MAAM,qCAAqCS,CAAAA,GAAuB,CAAA,EAExE,MACF,CAEA,IAAMc,EAAe,KAAKhC,YAAYiC,IAAIf,CAAAA,EAEpCgB,EAAW,IAAIF,EAGrBE,EAAStB,eAAiBA,EAC1BsB,EAASjB,eAAiBA,EAC1BiB,EAAShB,qBAAuBA,EAG5BC,GACFgB,OAAOC,OAAOF,EAAUf,CAAAA,EAI1BZ,EAAc8B,MAAMH,CAAAA,CACtB,CACF,EAtFapC,EAAAA,EAAAA,kBAAN,IAAMA,EAANwC","names":["MessageWriter","EventMessage","FromMainMessage","EventMessage","__virid_source","__virid_target","__virid_message_type","_FromMainMessage","ToMainMessage","__publicField","_ToMainMessage","MessageWriter","middleWare","__name","message","next","ToMainMessage","__virid_target","__virid_message_type","payload","__virid_source","MessageWriter","warn","window","__VIRID_BRIDGE__","post","VIRID_METADATA","VIRID_RENDERER_METADATA","FROMMAIN","FromMain","type","target","Reflect","defineMetadata","VIRID_RENDERER_METADATA","FROMMAIN","RendererPlugin","name","message_map","Map","install","app","options","window","__VIRID_BRIDGE__","MessageWriter","error","Error","windowId","ToMainMessage","__virid_source","subscribe","convertFromMainMessage","bind","post","__virid_target","__virid_message_type","payload","useMiddleware","middleWare","bindRoute","target","route","Reflect","getMetadata","VIRID_RENDERER_METADATA","FROMMAIN","has","set","ipcMessage","MessageClass","get","instance","Object","assign","write","_RendererPlugin"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@virid/renderer",
3
3
  "type": "module",
4
- "version": "0.3.15",
4
+ "version": "0.3.16",
5
5
  "description": "Electron renderer process adapter for virid, responsible for forwarding and receiving messages from the main process",
6
6
  "author": "Ailrid",
7
7
  "license": "Apache 2.0",
@@ -34,7 +34,7 @@
34
34
  },
35
35
  "dependencies": {},
36
36
  "peerDependencies": {
37
- "@virid/core": "0.3.15"
37
+ "@virid/core": "0.3.16"
38
38
  },
39
39
  "scripts": {
40
40
  "build": "tsup --config tsup.config.ts",