vitral 0.2.0 → 0.3.0

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.
Files changed (53) hide show
  1. package/README.md +1 -1
  2. package/dist/angular.d.ts +3 -2
  3. package/dist/angular.js +7 -6
  4. package/dist/auto.js +7 -6
  5. package/dist/capture-JYFERAPL.js +42 -0
  6. package/dist/{chunk-6Y3VMWHH.js → chunk-3YXI3G34.js} +3 -3
  7. package/dist/{chunk-S5MZT5IT.js → chunk-AH7KNMBW.js} +1 -1
  8. package/dist/chunk-AKNNHQ2H.js +45 -0
  9. package/dist/{chunk-PX7PBCCT.js → chunk-GNHCZRQP.js} +7 -17
  10. package/dist/{chunk-NCONW6WS.js → chunk-I3VSKSAZ.js} +58 -30
  11. package/dist/{chunk-UTYAX6MU.js → chunk-IHTUM6LT.js} +2 -2
  12. package/dist/{chunk-HP6QWU6K.js → chunk-SDB5AZEI.js} +2 -2
  13. package/dist/{chunk-2XF5BKV3.js → chunk-TD4S3IHA.js} +23 -12
  14. package/dist/chunk-ZAC6QQI6.js +64 -0
  15. package/dist/cli.js +59 -9
  16. package/dist/contract-46EZFQPQ.js +17 -0
  17. package/dist/{dedupe-IWFIXRWG.js → dedupe-S7BHQMOZ.js} +4 -3
  18. package/dist/element.d.ts +3 -3
  19. package/dist/element.js +7 -6
  20. package/dist/{errors-KKB8FGCz.d.ts → errors-kjBv6IH_.d.ts} +7 -1
  21. package/dist/{events-DUdjhfps.d.ts → events-D5gs7rff.d.ts} +1 -1
  22. package/dist/expose-JUOUN5N5.js +15 -0
  23. package/dist/iframe.d.ts +1 -1
  24. package/dist/iframe.js +13 -10
  25. package/dist/index.d.ts +23 -21
  26. package/dist/index.js +5 -4
  27. package/dist/otel.d.ts +44 -0
  28. package/dist/otel.js +27 -0
  29. package/dist/preact.d.ts +5 -5
  30. package/dist/preact.js +6 -5
  31. package/dist/react.d.ts +12 -4
  32. package/dist/react.js +11 -6
  33. package/dist/routes.d.ts +3 -3
  34. package/dist/routes.js +5 -4
  35. package/dist/sentry.d.ts +25 -0
  36. package/dist/sentry.js +11 -0
  37. package/dist/{shadow-MYRJQLLY.js → shadow-6HELCHCJ.js} +37 -11
  38. package/dist/{slot-pB276oPt.d.ts → slot-DqXTwGbs.d.ts} +2 -2
  39. package/dist/solid.d.ts +4 -4
  40. package/dist/solid.js +6 -5
  41. package/dist/{sri-BVKZNX5Q.js → sri-JMX6JLQP.js} +6 -4
  42. package/dist/svelte.d.ts +5 -5
  43. package/dist/svelte.js +6 -5
  44. package/dist/testing.d.ts +2 -1
  45. package/dist/testing.js +5 -4
  46. package/dist/{types-BV-hUrms.d.ts → types-Czvm-siZ.d.ts} +63 -1
  47. package/dist/vite.d.ts +8 -0
  48. package/dist/vite.js +364 -35
  49. package/dist/vue.d.ts +10 -3
  50. package/dist/vue.js +10 -5
  51. package/package.json +54 -20
  52. package/dist/chunk-SFL6LTP3.js +0 -56
  53. package/dist/expose-53BEJB34.js +0 -14
package/dist/vite.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // src/vite.ts
2
2
  import { createHash as createHash2 } from "crypto";
3
- import { readFileSync as readFileSync3, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "fs";
4
- import { join as join4, resolve as resolve4 } from "path";
3
+ import { readFileSync as readFileSync4, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "fs";
4
+ import { join as join5, resolve as resolve5 } from "path";
5
5
 
6
6
  // src/vite-exposes.ts
7
7
  import { resolve } from "path";
@@ -16,6 +16,7 @@ function exposeKeys(exposes) {
16
16
  }
17
17
  return out;
18
18
  }
19
+ var EXPOSES_IDS = /(^|[\\/])__vitral_exposes__\.js$/;
19
20
  function resolveExposesId(id) {
20
21
  return id === EXPOSES_ENTRY || id.endsWith("/" + EXPOSES_ENTRY) || id.endsWith("\\" + EXPOSES_ENTRY) ? ID : null;
21
22
  }
@@ -99,7 +100,7 @@ ${helper()}${code.slice(at)}`;
99
100
  }
100
101
  function withSplit(m, outDir, s, groups2 = []) {
101
102
  const files = {};
102
- for (const f of [m.entry, ...m.css ?? [], ...s?.files ?? []]) files[f] = sri(join(outDir, f));
103
+ for (const f of [m.entry, ...m.css ?? [], ...m.shadow?.css ?? [], ...m.shadow?.global ?? [], ...s?.files ?? []]) files[f] = sri(join(outDir, f));
103
104
  const dedupe = groups2.filter((g) => s?.own[g.name]).map(({ name, range, version }) => ({ name, range, version, ...s.own[name] }));
104
105
  return { ...m, files, ...s && { split: { entry: s.entry, chunks: s.chunks } }, ...dedupe.length && { dedupe } };
105
106
  }
@@ -152,6 +153,11 @@ async function groups(list, root, entry, resolveId) {
152
153
  }
153
154
  return out;
154
155
  }
156
+ var escape = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&").replace(/\0/g, "\\x00");
157
+ function dedupeIds(list) {
158
+ const specs = new Set(list.flatMap((s) => groupOf(s) === "react" ? REACT : [s]));
159
+ return new RegExp(`${escape(BOOT)}$|^(${[DEPS, ...specs].map(escape).join("|")})$|^(${escape(OWN)}|${escape(SHIM)})`);
160
+ }
155
161
  function dedupeHooks(entry, getGroups) {
156
162
  const keyOf = (id) => getGroups().find((g) => g.keys.includes(id));
157
163
  return {
@@ -389,6 +395,26 @@ function transformCss(css, options, scope) {
389
395
  if (options.scopeCss !== false) scopeRoot(root, scope);
390
396
  return root.toString();
391
397
  }
398
+ var RELATIVE_URL = /url\(\s*(['"]?)(?![a-z]+:|\/\/|#)([^'")]+)\1\s*\)/i;
399
+ var IMPORT_URL = /^\s*(?:url\(\s*(['"]?)([^'")]+)\1\s*\)|(['"])(.*?)\3)/i;
400
+ function splitShadowCss(text) {
401
+ const root = postcss2.parse(text);
402
+ const global = [];
403
+ const imports = [];
404
+ root.walkAtRules((rule) => {
405
+ const name = rule.name.toLowerCase();
406
+ if (name === "import" && rule.parent === root) {
407
+ const m = IMPORT_URL.exec(rule.params);
408
+ if (m) imports.push(m[2] ?? m[4]);
409
+ rule.remove();
410
+ } else if (name === "property" || name === "font-face") {
411
+ global.push(rule.toString());
412
+ rule.remove();
413
+ }
414
+ });
415
+ const css = global.length || imports.length ? root.toString() : text;
416
+ return { css, global: global.join("\n"), imports, rebase: RELATIVE_URL.test(css) };
417
+ }
392
418
 
393
419
  // src/vite/adapter.ts
394
420
  import { existsSync as existsSync2 } from "fs";
@@ -450,28 +476,301 @@ function findEntry(root) {
450
476
  }
451
477
 
452
478
  // src/vite/types.ts
479
+ import { createRequire as createRequire2 } from "module";
480
+ import { join as join4 } from "path";
481
+
482
+ // src/vite/oxc.ts
483
+ import { existsSync as existsSync3, readFileSync as readFileSync3 } from "fs";
453
484
  import { createRequire } from "module";
454
- import { join as join3 } from "path";
485
+ import { dirname as dirname2, join as join3, resolve as resolve4 } from "path";
486
+ import { pathToFileURL as pathToFileURL2 } from "url";
487
+ async function loadOxc(root) {
488
+ const req = createRequire(join3(root, "package.json"));
489
+ const ids = [() => req.resolve("oxc-transform"), () => createRequire(req.resolve("vite/package.json")).resolve("rolldown/experimental")];
490
+ for (const id of ids) {
491
+ try {
492
+ const mod = await import(pathToFileURL2(id()).href);
493
+ if (typeof mod.isolatedDeclarationSync === "function") return mod;
494
+ } catch {
495
+ }
496
+ }
497
+ return null;
498
+ }
499
+ var GLOBAL3 = /^(Date|RegExp|Error|Map|Set|WeakMap|WeakSet|Promise|PromiseLike|Record|Partial|Required|Readonly|Pick|Omit|URL|URLSearchParams|Blob|File|FormData|Headers|AbortSignal|EventTarget|Node|Element|Document|DocumentFragment|ShadowRoot|Window|(HTML|SVG)\w*Element|\w*Event)$/;
500
+ var IDENT = /^[A-Za-z_$][\w$]*$/;
501
+ var Unsupported = class extends Error {
502
+ };
503
+ var unsupported = () => {
504
+ throw new Unsupported();
505
+ };
506
+ function propsFromOxc(ts, oxc, file) {
507
+ try {
508
+ const reader = new Reader(ts, oxc);
509
+ const scope = reader.scope(file);
510
+ const props = reader.defaultProps(scope);
511
+ return props ? reader.print(props.node, props.scope, 0, { top: true }) : "Record<string, unknown>";
512
+ } catch {
513
+ return null;
514
+ }
515
+ }
516
+ var Reader = class {
517
+ constructor(ts, oxc) {
518
+ this.ts = ts;
519
+ this.oxc = oxc;
520
+ this.scopes = /* @__PURE__ */ new Map();
521
+ this.seen = /* @__PURE__ */ new Set();
522
+ }
523
+ /** Declarações de um arquivo: `.d.ts` como está, o resto pelo Oxc. */
524
+ scope(file) {
525
+ const cached = this.scopes.get(file);
526
+ if (cached) return cached;
527
+ const { ts } = this;
528
+ let code = readFileSync3(file, "utf8");
529
+ if (!/\.d\.[cm]?ts$/.test(file)) {
530
+ const out = this.oxc.isolatedDeclarationSync(file, code, {});
531
+ if (out.errors.length) unsupported();
532
+ code = out.code;
533
+ }
534
+ const source = ts.createSourceFile(file + ".d.ts", code, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
535
+ const scope = { file, types: /* @__PURE__ */ new Map(), values: /* @__PURE__ */ new Map(), imports: /* @__PURE__ */ new Map() };
536
+ const isDefault = (n) => ts.canHaveModifiers(n) && !!ts.getModifiers(n)?.some((m) => m.kind === ts.SyntaxKind.DefaultKeyword);
537
+ let defaultName;
538
+ for (const st of source.statements) {
539
+ if (ts.isInterfaceDeclaration(st) || ts.isTypeAliasDeclaration(st)) {
540
+ if (scope.types.has(st.name.text)) unsupported();
541
+ scope.types.set(st.name.text, st);
542
+ } else if (ts.isImportDeclaration(st) && ts.isStringLiteral(st.moduleSpecifier)) {
543
+ const from = st.moduleSpecifier.text;
544
+ const clause = st.importClause;
545
+ if (clause?.name) scope.imports.set(clause.name.text, { from, name: "default" });
546
+ const bindings = clause?.namedBindings;
547
+ if (bindings && ts.isNamespaceImport(bindings)) scope.imports.set(bindings.name.text, { from, name: "*" });
548
+ if (bindings && ts.isNamedImports(bindings)) for (const el of bindings.elements) scope.imports.set(el.name.text, { from, name: (el.propertyName ?? el.name).text });
549
+ } else if (ts.isFunctionDeclaration(st) || ts.isClassDeclaration(st)) {
550
+ if (isDefault(st)) scope.default ??= st;
551
+ else if (st.name && !scope.values.has(st.name.text)) scope.values.set(st.name.text, st);
552
+ } else if (ts.isVariableStatement(st)) {
553
+ for (const d of st.declarationList.declarations) if (ts.isIdentifier(d.name)) scope.values.set(d.name.text, d);
554
+ } else if (ts.isExportAssignment(st) && !st.isExportEquals) {
555
+ defaultName = ts.isIdentifier(st.expression) ? st.expression.text : unsupported();
556
+ } else if (ts.isExportDeclaration(st) && !st.moduleSpecifier && st.exportClause && ts.isNamedExports(st.exportClause)) {
557
+ const el = st.exportClause.elements.find((e) => e.name.text === "default");
558
+ if (el) defaultName = (el.propertyName ?? el.name).text;
559
+ }
560
+ }
561
+ if (defaultName) scope.default = scope.values.get(defaultName);
562
+ this.scopes.set(file, scope);
563
+ return scope;
564
+ }
565
+ /** `mount(el, props)`, componente-função `(props)` ou classe com `props`. `undefined`: sem props. */
566
+ defaultProps(scope) {
567
+ const { ts } = this;
568
+ const node = scope.default ?? unsupported();
569
+ const param = (params, i) => {
570
+ const p = params[i];
571
+ return p && { node: p.type ?? unsupported(), scope };
572
+ };
573
+ if (ts.isFunctionDeclaration(node)) return param(node.parameters, 0);
574
+ if (ts.isClassDeclaration(node)) {
575
+ if (node.heritageClauses?.length) unsupported();
576
+ const props = node.members.find((m) => ts.isPropertyDeclaration(m) && m.name.getText() === "props");
577
+ return props && { node: props.type ?? unsupported(), scope };
578
+ }
579
+ if (ts.isVariableDeclaration(node)) return this.propsOfType(node.type ?? unsupported(), scope);
580
+ return unsupported();
581
+ }
582
+ propsOfType(node, scope) {
583
+ const { ts } = this;
584
+ const param = (params, i, at2) => {
585
+ const p = params[i];
586
+ return p && { node: p.type ?? unsupported(), scope: at2 };
587
+ };
588
+ if (ts.isParenthesizedTypeNode(node)) return this.propsOfType(node.type, scope);
589
+ if (ts.isFunctionTypeNode(node)) return param(node.parameters, 0, scope);
590
+ let members;
591
+ let at = scope;
592
+ if (ts.isTypeLiteralNode(node)) members = node.members;
593
+ else if (ts.isTypeReferenceNode(node) && ts.isIdentifier(node.typeName) && !node.typeArguments) {
594
+ const found = this.lookup(node.typeName.text, scope);
595
+ if (!found || found === "package" || found.decl.typeParameters) return unsupported();
596
+ if (ts.isTypeAliasDeclaration(found.decl)) return this.propsOfType(found.decl.type, found.scope);
597
+ if (found.decl.heritageClauses?.length) unsupported();
598
+ members = found.decl.members;
599
+ at = found.scope;
600
+ } else return unsupported();
601
+ const mount = members.find((m) => m.name?.getText() === "mount");
602
+ if (mount) {
603
+ if (ts.isMethodSignature(mount)) return param(mount.parameters, 1, at);
604
+ if (ts.isPropertySignature(mount) && mount.type) return this.mountProps(mount.type, at);
605
+ return unsupported();
606
+ }
607
+ const call = members.find(ts.isCallSignatureDeclaration);
608
+ if (call) return param(call.parameters, 0, at);
609
+ if (members.some(ts.isConstructSignatureDeclaration)) unsupported();
610
+ return void 0;
611
+ }
612
+ mountProps(node, scope) {
613
+ const { ts } = this;
614
+ if (ts.isParenthesizedTypeNode(node)) return this.mountProps(node.type, scope);
615
+ if (!ts.isFunctionTypeNode(node)) return unsupported();
616
+ const p = node.parameters[1];
617
+ return p && { node: p.type ?? unsupported(), scope };
618
+ }
619
+ /** Acha um tipo pelo nome: no arquivo, num import relativo ou num pacote. */
620
+ lookup(name, scope) {
621
+ const decl = scope.types.get(name);
622
+ if (decl) return { decl, scope };
623
+ const imp = scope.imports.get(name);
624
+ if (!imp) return void 0;
625
+ if (!imp.from.startsWith(".")) return "package";
626
+ if (imp.name === "default" || imp.name === "*") return unsupported();
627
+ const found = this.lookup(imp.name, this.scope(resolveFile(scope.file, imp.from)));
628
+ return found ?? unsupported();
629
+ }
630
+ print(node, scope, depth, opts = {}) {
631
+ const { ts } = this;
632
+ const K = ts.SyntaxKind;
633
+ switch (node.kind) {
634
+ case K.AnyKeyword:
635
+ case K.UnknownKeyword:
636
+ return "unknown";
637
+ case K.StringKeyword:
638
+ case K.NumberKeyword:
639
+ case K.BooleanKeyword:
640
+ case K.BigIntKeyword:
641
+ case K.SymbolKeyword:
642
+ case K.UndefinedKeyword:
643
+ case K.VoidKeyword:
644
+ case K.NeverKeyword:
645
+ return node.getText();
646
+ }
647
+ if (ts.isLiteralTypeNode(node)) {
648
+ const lit = node.literal;
649
+ if (ts.isStringLiteral(lit)) return JSON.stringify(lit.text);
650
+ if (lit.kind === K.NullKeyword || lit.kind === K.TrueKeyword || lit.kind === K.FalseKeyword || ts.isNumericLiteral(lit) || ts.isPrefixUnaryExpression(lit)) return lit.getText();
651
+ return unsupported();
652
+ }
653
+ if (ts.isParenthesizedTypeNode(node)) return this.print(node.type, scope, depth, opts);
654
+ if (ts.isUnionTypeNode(node)) {
655
+ const types = opts.nonNull ? node.types.filter((t) => t.kind !== K.UndefinedKeyword && !(ts.isLiteralTypeNode(t) && t.literal.kind === K.NullKeyword)) : node.types;
656
+ const parts = [...new Set(types.map((t) => this.print(t, scope, depth)))];
657
+ if (parts.includes("true") && parts.includes("false")) parts.splice(parts.indexOf("true"), 1, "boolean"), parts.splice(parts.indexOf("false"), 1);
658
+ return parts.join(" | ");
659
+ }
660
+ if (ts.isIntersectionTypeNode(node)) {
661
+ return node.types.map((t) => {
662
+ const s = this.print(t, scope, depth);
663
+ return ts.isUnionTypeNode(t) ? `(${s})` : s;
664
+ }).join(" & ");
665
+ }
666
+ if (depth > 6) return "unknown";
667
+ if (ts.isArrayTypeNode(node)) return `Array<${this.print(node.elementType, scope, depth + 1)}>`;
668
+ if (ts.isTypeOperatorNode(node) && node.operator === K.ReadonlyKeyword && (ts.isArrayTypeNode(node.type) || ts.isTupleTypeNode(node.type))) return this.print(node.type, scope, depth);
669
+ if (ts.isTupleTypeNode(node)) {
670
+ if (node.elements.some((e) => ts.isNamedTupleMember(e) || ts.isOptionalTypeNode(e) || ts.isRestTypeNode(e))) unsupported();
671
+ return `[${node.elements.map((e) => this.print(e, scope, depth + 1)).join(", ")}]`;
672
+ }
673
+ if (ts.isTypeLiteralNode(node)) return this.object(node.members, scope, depth, !!opts.top);
674
+ if (ts.isFunctionTypeNode(node)) return this.signature(node, scope, depth);
675
+ if (ts.isTypeReferenceNode(node)) return this.reference(node, scope, depth, opts);
676
+ return unsupported();
677
+ }
678
+ reference(node, scope, depth, opts) {
679
+ const { ts } = this;
680
+ if (!ts.isIdentifier(node.typeName)) return unsupported();
681
+ const name = node.typeName.text;
682
+ const args = node.typeArguments ?? [];
683
+ const found = this.lookup(name, scope);
684
+ if (found === "package") return "unknown";
685
+ if (found) {
686
+ if (args.length || found.decl.typeParameters) unsupported();
687
+ if (this.seen.has(found.decl)) return "unknown";
688
+ this.seen.add(found.decl);
689
+ try {
690
+ const decl = found.decl;
691
+ if (ts.isTypeAliasDeclaration(decl)) return this.print(decl.type, found.scope, depth, opts);
692
+ if (decl.heritageClauses?.length) unsupported();
693
+ return this.object(decl.members, found.scope, depth, !!opts.top);
694
+ } finally {
695
+ this.seen.delete(found.decl);
696
+ }
697
+ }
698
+ if ((name === "Array" || name === "ReadonlyArray") && args.length === 1) return `Array<${this.print(args[0], scope, depth + 1)}>`;
699
+ if (!GLOBAL3.test(name)) return unsupported();
700
+ return args.length ? `${name}<${args.map((t) => this.print(t, scope, depth + 1)).join(", ")}>` : name;
701
+ }
702
+ object(members, scope, depth, top) {
703
+ const { ts } = this;
704
+ const fields = [];
705
+ const calls = [];
706
+ let index;
707
+ for (const m of members) {
708
+ if (ts.isPropertySignature(m) || ts.isMethodSignature(m)) {
709
+ const name = ts.isIdentifier(m.name) || ts.isStringLiteral(m.name) || ts.isNumericLiteral(m.name) ? m.name.text : unsupported();
710
+ if (top && name === "vitral") continue;
711
+ const optional = m.questionToken ? "?" : "";
712
+ const key = IDENT.test(name) ? name : JSON.stringify(name);
713
+ const type = ts.isMethodSignature(m) ? this.signature(m, scope, depth + 1) : m.type ? this.print(m.type, scope, depth + 1, { nonNull: !!optional }) : "unknown";
714
+ fields.push(`${key}${optional}: ${type}`);
715
+ } else if (ts.isIndexSignatureDeclaration(m)) {
716
+ const key = m.parameters[0]?.type;
717
+ if (!key || key.kind !== ts.SyntaxKind.StringKeyword) unsupported();
718
+ index = `[key: string]: ${this.print(m.type, scope, depth + 1)}`;
719
+ } else if (ts.isCallSignatureDeclaration(m)) {
720
+ calls.push(this.signature(m, scope, depth));
721
+ } else unsupported();
722
+ }
723
+ if (calls.length && !fields.length) return calls[0];
724
+ if (index) fields.push(index);
725
+ for (const c of calls) fields.push(c.replace(" =>", ":"));
726
+ return fields.length ? `{ ${fields.join("; ")} }` : "{}";
727
+ }
728
+ signature(sig, scope, depth) {
729
+ const { ts } = this;
730
+ if (sig.typeParameters?.length || !sig.type) unsupported();
731
+ const params = sig.parameters.map((p, i) => {
732
+ if (p.dotDotDotToken || ts.isIdentifier(p.name) && p.name.text === "this") unsupported();
733
+ const name = ts.isIdentifier(p.name) && IDENT.test(p.name.text) ? p.name.text : `a${i}`;
734
+ const type = p.type ? this.print(p.type, scope, depth + 1) : "unknown";
735
+ return `${name}: ${p.questionToken || p.initializer ? `${type} | undefined` : type}`;
736
+ });
737
+ return `(${params.join(", ")}) => ${this.print(sig.type, scope, depth + 1)}`;
738
+ }
739
+ };
740
+ function resolveFile(from, spec) {
741
+ const base = resolve4(dirname2(from), spec);
742
+ const stem = base.replace(/\.[cm]?jsx?$/, "");
743
+ const candidates = [base, ...[".ts", ".tsx", ".mts", ".cts", ".d.ts"].map((ext) => stem + ext), ...["index.ts", "index.tsx", "index.d.ts"].map((f) => join3(base, f))];
744
+ const file = candidates.find((f) => /\.[cm]?tsx?$/.test(f) && existsSync3(f));
745
+ return file ?? unsupported();
746
+ }
747
+
748
+ // src/vite/types.ts
455
749
  function typesFile(name, props) {
456
750
  return `// Props do remote ${JSON.stringify(name)}, geradas pelo vitral. N\xE3o edite.
457
751
  export type Props = ${props}
458
752
  `;
459
753
  }
460
754
  async function loadTs(root) {
755
+ const api = (ts) => typeof ts?.createProgram === "function" ? ts : null;
461
756
  try {
462
- return createRequire(join3(root, "package.json"))("typescript");
757
+ const ts = api(createRequire2(join4(root, "package.json"))("typescript"));
758
+ if (ts) return ts;
463
759
  } catch {
464
- try {
465
- return (await import("typescript")).default;
466
- } catch {
467
- return null;
468
- }
760
+ }
761
+ try {
762
+ return api((await import("typescript")).default);
763
+ } catch {
764
+ return null;
469
765
  }
470
766
  }
471
767
  async function extractProps(root, file) {
472
768
  if (!/\.[cm]?[jt]sx?$/.test(file)) return null;
473
769
  const ts = await loadTs(root);
474
770
  if (!ts) return null;
771
+ const oxc = /\.[cm]?tsx?$/.test(file) ? await loadOxc(root) : null;
772
+ const fast = oxc && propsFromOxc(ts, oxc, file);
773
+ if (fast) return fast;
475
774
  const configPath = ts.findConfigFile(root, ts.sys.fileExists);
476
775
  const base = configPath ? ts.parseJsonConfigFileContent(ts.readConfigFile(configPath, ts.sys.readFile).config, ts.sys, root).options : {};
477
776
  const options = {
@@ -623,6 +922,7 @@ if (import.meta.hot) {
623
922
  }
624
923
  `;
625
924
  }
925
+ var DEV_IDS = /^virtual:vitral-react-preamble$|\/@vitral\/entry\.js$/;
626
926
  function resolveDevId(id) {
627
927
  if (id === PREAMBLE_ID) return "\0" + PREAMBLE_ID;
628
928
  if (id.endsWith("/" + DEV_ENTRY)) return VIRTUAL_DEV_ENTRY;
@@ -633,8 +933,9 @@ function loadPreamble(id) {
633
933
  function devManifest(name, scope) {
634
934
  return { name, entry: DEV_ENTRY, css: [], ...scope ? { scope } : {} };
635
935
  }
936
+ var DEV_CSS = { include: /\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(\?|$)/, exclude: /[?&](raw|url|inline)\b/ };
636
937
  function scopeDevCss(code, id, scope) {
637
- if (!/\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(\?|$)/.test(id) || /[?&](raw|url|inline)\b/.test(id)) return;
938
+ if (!DEV_CSS.include.test(id) || DEV_CSS.exclude.test(id)) return;
638
939
  return scopeCss(code, scope);
639
940
  }
640
941
  function serveDevManifest(server, manifest) {
@@ -673,7 +974,7 @@ function vitral(options = {}) {
673
974
  let entry = options.entry;
674
975
  let adapter = "element";
675
976
  let framework = "element";
676
- const entryFile = () => resolve4(root, entry);
977
+ const entryFile = () => resolve5(root, entry);
677
978
  let serve = false;
678
979
  let shared = [];
679
980
  const dedupe = !!options.dedupe?.length;
@@ -682,7 +983,7 @@ function vitral(options = {}) {
682
983
  return {
683
984
  name: "vitral",
684
985
  config(user, { mode, command }) {
685
- entry ??= findEntry(resolve4(user.root ?? process.cwd()));
986
+ entry ??= findEntry(resolve5(user.root ?? process.cwd()));
686
987
  if (!entry) throw new Error("[vitral] n\xE3o achei a entrada do remote (src/remote.* ou src/App.*). Use vitral({ entry }).");
687
988
  const rolldown = "rolldownVersion" in this.meta;
688
989
  return {
@@ -708,9 +1009,9 @@ function vitral(options = {}) {
708
1009
  framework = detectAdapter(c.plugins);
709
1010
  adapter = options.adapter || framework;
710
1011
  serve = c.command === "serve";
711
- outDir = resolve4(c.root, c.build.outDir);
1012
+ outDir = resolve5(c.root, c.build.outDir);
712
1013
  try {
713
- pkg = JSON.parse(readFileSync3(join4(root, "package.json"), "utf8"));
1014
+ pkg = JSON.parse(readFileSync4(join5(root, "package.json"), "utf8"));
714
1015
  } catch {
715
1016
  }
716
1017
  },
@@ -722,8 +1023,11 @@ function vitral(options = {}) {
722
1023
  const scope = options.scopeCss === false ? void 0 : scopeName();
723
1024
  serveDevManifest(server, () => devManifest(options.name ?? pkg.name ?? "remote", scope));
724
1025
  },
1026
+ // Filtros de hook (Rolldown, Vite 6.3+): os módulos que não são do vitral
1027
+ // nem chegam ao JS. As checagens nos handlers continuam para Vite 5 e 6.0-6.2.
725
1028
  resolveId: {
726
1029
  order: "pre",
1030
+ filter: { id: [...dedupe ? [dedupeIds(options.dedupe)] : [], ...options.exposes ? [EXPOSES_IDS] : [], /__vitral_entry__\.js$/, DEV_IDS] },
727
1031
  handler(id, importer) {
728
1032
  const own = dedupe && !serve ? hooks.resolveId.handler(id, importer) : null;
729
1033
  if (own) return own;
@@ -732,54 +1036,79 @@ function vitral(options = {}) {
732
1036
  return resolveDevId(id);
733
1037
  }
734
1038
  },
735
- load(id) {
736
- const own = dedupe && !serve ? hooks.load(id) : null;
737
- if (own != null) return own;
738
- const exposed = options.exposes ? loadExposes(id, root, entry, options.exposes, options.adapter === false ? void 0 : ENTRY_ID) : null;
739
- if (exposed != null) return exposed;
740
- if (id === VIRTUAL_ENTRY) return entryCode(resolve4(root, entry), adapter, scopeName());
741
- if (id === VIRTUAL_DEV_ENTRY) return devEntryCode(framework, options.adapter === false ? resolve4(root, entry) : void 0);
742
- return loadPreamble(id);
1039
+ load: {
1040
+ // Todos os módulos virtuais do vitral: \0vitral... e \0virtual:vitral...
1041
+ filter: { id: /^\x00(virtual:)?vitral/ },
1042
+ handler(id) {
1043
+ const own = dedupe && !serve ? hooks.load(id) : null;
1044
+ if (own != null) return own;
1045
+ const exposed = options.exposes ? loadExposes(id, root, entry, options.exposes, options.adapter === false ? void 0 : ENTRY_ID) : null;
1046
+ if (exposed != null) return exposed;
1047
+ if (id === VIRTUAL_ENTRY) return entryCode(resolve5(root, entry), adapter, scopeName());
1048
+ if (id === VIRTUAL_DEV_ENTRY) return devEntryCode(framework, options.adapter === false ? resolve5(root, entry) : void 0);
1049
+ return loadPreamble(id);
1050
+ }
743
1051
  },
744
- transform(code, id) {
745
- if (serve && options.scopeCss !== false) return scopeDevCss(code, id, scopeName());
1052
+ transform: {
1053
+ filter: { id: DEV_CSS },
1054
+ handler(code, id) {
1055
+ if (serve && options.scopeCss !== false) return scopeDevCss(code, id, scopeName());
1056
+ }
746
1057
  },
747
1058
  writeBundle(_, bundle) {
748
1059
  if (isSplit(bundle)) return void (split = collect(outDir, bundle));
749
1060
  const files = Object.values(bundle);
750
1061
  const entry2 = files.find((f) => f.type === "chunk" && f.isEntry);
751
1062
  if (!entry2) return;
752
- const css = files.filter((f) => f.type === "asset" && f.fileName.endsWith(".css")).map((f) => {
753
- const from = join4(outDir, f.fileName);
754
- let text = readFileSync3(from, "utf8");
755
- text = transformCss(text, options, scopeName());
1063
+ const emit = (file, text, kind = "") => {
756
1064
  const hash = createHash2("sha256").update(text).digest("base64url").slice(0, 8);
757
- const name = f.fileName.replace(/\.css$/, `-${hash}.css`);
758
- writeFileSync2(join4(outDir, name), text);
1065
+ const name = file.replace(/\.css$/, `${kind}-${hash}.css`);
1066
+ writeFileSync2(join5(outDir, name), text);
1067
+ return name;
1068
+ };
1069
+ const shadow = { css: [] };
1070
+ const css = files.filter((f) => f.type === "asset" && f.fileName.endsWith(".css")).map((f) => {
1071
+ const from = join5(outDir, f.fileName);
1072
+ const text = transformCss(readFileSync4(from, "utf8"), options, scopeName());
1073
+ const name = emit(f.fileName, text);
759
1074
  if (name !== f.fileName) rmSync2(from);
1075
+ const split2 = splitShadowCss(text);
1076
+ shadow.css.push(split2.css === text ? name : emit(f.fileName, split2.css, "-shadow"));
1077
+ if (split2.global) (shadow.global ??= []).push(emit(f.fileName, split2.global, "-global"));
1078
+ if (split2.imports.length) (shadow.imports ??= []).push(...split2.imports);
1079
+ if (split2.rebase) shadow.rebase = true;
760
1080
  return name;
761
1081
  });
762
- const code = readFileSync3(join4(outDir, entry2.fileName));
1082
+ const code = readFileSync4(join5(outDir, entry2.fileName));
763
1083
  manifest = {
764
1084
  name: options.name ?? pkg.name ?? "remote",
765
1085
  version: options.version ?? pkg.version,
766
1086
  entry: entry2.fileName,
767
1087
  css,
1088
+ ...css.length ? { shadow } : {},
768
1089
  integrity: "sha384-" + createHash2("sha384").update(code).digest("base64"),
769
1090
  ...options.scopeCss === false ? {} : { scope: scopeName() },
770
- ...options.exposes ? { exposes: Object.keys(exposeKeys(options.exposes)) } : {}
1091
+ ...options.exposes ? { exposes: Object.keys(exposeKeys(options.exposes)) } : {},
1092
+ ...contractOf(options.contract?.version, shared)
771
1093
  };
772
1094
  },
773
1095
  async closeBundle() {
774
1096
  if (!manifest) return;
775
1097
  const done = withSplit(manifest, outDir, split, shared);
776
1098
  manifest = split = void 0;
777
- writeFileSync2(join4(outDir, "vitral.json"), JSON.stringify(done, null, 2) + "\n");
1099
+ writeFileSync2(join5(outDir, "vitral.json"), JSON.stringify(done, null, 2) + "\n");
778
1100
  const props = options.types === false ? null : await extractProps(root, entryFile());
779
- if (props) writeFileSync2(join4(outDir, "vitral.d.ts"), typesFile(done.name, props));
1101
+ if (props) writeFileSync2(join5(outDir, "vitral.d.ts"), typesFile(done.name, props));
780
1102
  }
781
1103
  };
782
1104
  }
1105
+ function contractOf(version, groups2) {
1106
+ const contract = {
1107
+ ...version && { version },
1108
+ ...groups2.length && { peers: Object.fromEntries(groups2.map((g) => [g.name, g.range])) }
1109
+ };
1110
+ return Object.keys(contract).length ? { contract } : {};
1111
+ }
783
1112
  export {
784
1113
  vitral as default,
785
1114
  vitral
package/dist/vue.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import * as vue from 'vue';
2
2
  import { PropType, App, ShallowRef, WritableComputedRef, ComputedRef, Component } from 'vue';
3
- import { P as Props, I as Isolation, R as RemoteContext, S as Shared, a as RemoteModule } from './types-BV-hUrms.js';
4
- export { e as events } from './events-DUdjhfps.js';
3
+ import { P as Props, I as Isolation, R as RemoteContext, S as Shared, a as RemoteModule } from './types-Czvm-siZ.js';
4
+ export { e as events } from './events-D5gs7rff.js';
5
5
  import { L as Loading, P as Prefetch } from './host-slot-Cz6EiGsB.js';
6
+ import './errors-kjBv6IH_.js';
6
7
 
7
8
  interface VueRemoteOptions {
8
9
  /** Instale plugins (router, pinia, i18n…) no app do remote. */
@@ -12,6 +13,12 @@ interface VueRemoteOptions {
12
13
  declare function vueRemote<P extends Props>(component: Component, options?: VueRemoteOptions): RemoteModule<P>;
13
14
  /** Dentro de um remote: dá acesso ao contexto (nome, eventos, baseUrl). */
14
15
  declare function useVitral(): RemoteContext | null;
16
+ /**
17
+ * Dentro de um remote: onde renderizar portais. No Shadow DOM é um elemento
18
+ * dentro do shadow root (com os estilos do remote); senão, `'body'`. Use em
19
+ * `<Teleport :to="portal">`.
20
+ */
21
+ declare function usePortalContainer(): HTMLElement | 'body';
15
22
  /** Assina um evento do barramento global enquanto o componente existir. */
16
23
  declare function useEvent<T = unknown>(type: string, handler: (payload: T) => void): void;
17
24
  /** Ref com o último valor emitido em `type`. */
@@ -130,4 +137,4 @@ declare const VitralRemote: vue.DefineComponent<vue.ExtractPropTypes<{
130
137
  keepAlive: number | boolean;
131
138
  }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
132
139
 
133
- export { VitralRemote, type VueRemoteOptions, useEvent, useEventValue, useShared, useVitral, vueRemote };
140
+ export { VitralRemote, type VueRemoteOptions, useEvent, useEventValue, usePortalContainer, useShared, useVitral, vueRemote };
package/dist/vue.js CHANGED
@@ -1,19 +1,20 @@
1
1
  import {
2
2
  hostSlot,
3
3
  timings
4
- } from "./chunk-UTYAX6MU.js";
4
+ } from "./chunk-IHTUM6LT.js";
5
5
  import {
6
6
  defineRemote,
7
7
  events,
8
8
  memoSelect,
9
9
  same,
10
10
  shared
11
- } from "./chunk-NCONW6WS.js";
12
- import "./chunk-2XF5BKV3.js";
13
- import "./chunk-SFL6LTP3.js";
11
+ } from "./chunk-I3VSKSAZ.js";
12
+ import "./chunk-TD4S3IHA.js";
13
+ import "./chunk-ZAC6QQI6.js";
14
14
  import {
15
15
  absolute
16
- } from "./chunk-PX7PBCCT.js";
16
+ } from "./chunk-GNHCZRQP.js";
17
+ import "./chunk-AKNNHQ2H.js";
17
18
  import "./chunk-GNPFWISJ.js";
18
19
 
19
20
  // src/vue.ts
@@ -55,6 +56,9 @@ function vueRemote(component, options = {}) {
55
56
  function useVitral() {
56
57
  return inject(VitralKey, null);
57
58
  }
59
+ function usePortalContainer() {
60
+ return useVitral()?.portalContainer ?? "body";
61
+ }
58
62
  function useEvent(type, handler) {
59
63
  let off;
60
64
  onMounted(() => off = events.on(type, handler));
@@ -142,6 +146,7 @@ export {
142
146
  events,
143
147
  useEvent,
144
148
  useEventValue,
149
+ usePortalContainer,
145
150
  useShared,
146
151
  useVitral,
147
152
  vueRemote