{"version":3,"file":"nativeSourceWires.js","names":[],"sources":["esm/vite/plugins/nativeSourceWires.js"],"sourcesContent":["function toNativeSourceStructs(structs) {\n  const out = {};\n  for (const struct of structs ?? []) {\n    out[struct.name] = {\n      fields: struct.fields.map(\n        (field) => field.wire === void 0 ? { name: field.name, optional: field.optional } : { name: field.name, optional: field.optional, wire: field.wire }\n      )\n    };\n  }\n  return out;\n}\nfunction methodWired(method) {\n  return method.parameters.some((param) => param.wire) || method.resultWire !== void 0;\n}\nfunction methodSubscribed(method) {\n  return method.subscription !== void 0;\n}\nfunction renderMethodCall(target, method, hash) {\n  if (method.subscription) {\n    const payload = method.subscription;\n    const payloadWires = JSON.stringify(payload.payload.map((arg) => arg.wire ?? null));\n    return `${method.name}: (listener) => subscribeNativeSourceEvent(${JSON.stringify(target)}, ${JSON.stringify(method.name)}, listener, ${JSON.stringify(hash)}, ${payloadWires}, nativeSourceStructs)`;\n  }\n  if (!methodWired(method)) {\n    return `${method.name}: (...args) => callNativeSource(${JSON.stringify(target)}, ${JSON.stringify(method.name)}, args, ${JSON.stringify(hash)})`;\n  }\n  const paramWires = JSON.stringify(method.parameters.map((param) => param.wire ?? null));\n  const resultWire = JSON.stringify(method.resultWire ?? null);\n  return `${method.name}: (...args) => callNativeSource(${JSON.stringify(target)}, ${JSON.stringify(method.name)}, encodeNativeSourceArgs(args, ${paramWires}, nativeSourceStructs), ${JSON.stringify(hash)}).then((value) => decodeNativeSourceResult(value, ${resultWire}, nativeSourceStructs))`;\n}\nfunction renderViewWires(view, structs) {\n  const props = {};\n  const callbacks = {};\n  for (const prop of view.props) {\n    if (prop.wire) props[prop.name] = prop.wire;\n    if (prop.callback && prop.callback.some((arg) => arg.wire)) {\n      callbacks[prop.name] = prop.callback.map((arg) => arg.wire ?? null);\n    }\n  }\n  if (Object.keys(props).length === 0 && Object.keys(callbacks).length === 0) return \"\";\n  return `, wires: ${JSON.stringify({ props, callbacks, structs: toNativeSourceStructs(structs) })}`;\n}\nexport {\n  meth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