@atom.io/spa 0.0.0-stage → 0.0.1

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 (106) hide show
  1. package/LICENSE +373 -0
  2. package/README.md +401 -2
  3. package/README.mdx +150 -0
  4. package/dist/astro-application.d.ts +15 -0
  5. package/dist/astro-application.d.ts.map +1 -0
  6. package/dist/astro-application.js +62 -0
  7. package/dist/astro-application.js.map +1 -0
  8. package/dist/astro-client.d.ts +9 -0
  9. package/dist/astro-client.d.ts.map +1 -0
  10. package/dist/astro-client.js +98 -0
  11. package/dist/astro-client.js.map +1 -0
  12. package/dist/astro-context-OdlexHR4.js +79 -0
  13. package/dist/astro-context-OdlexHR4.js.map +1 -0
  14. package/dist/astro-middleware.d.ts +4 -0
  15. package/dist/astro-middleware.d.ts.map +1 -0
  16. package/dist/astro-middleware.js +49 -0
  17. package/dist/astro-middleware.js.map +1 -0
  18. package/dist/astro-request-DRKvDjsO.js +70 -0
  19. package/dist/astro-request-DRKvDjsO.js.map +1 -0
  20. package/dist/astro-server.d.ts +4 -0
  21. package/dist/astro-server.d.ts.map +1 -0
  22. package/dist/astro-server.js +30 -0
  23. package/dist/astro-server.js.map +1 -0
  24. package/dist/astro-shared-BT45auwR.js +29 -0
  25. package/dist/astro-shared-BT45auwR.js.map +1 -0
  26. package/dist/astro-shared-DkZaqX7L.d.ts +31 -0
  27. package/dist/astro-shared-DkZaqX7L.d.ts.map +1 -0
  28. package/dist/astro.d.ts +6 -0
  29. package/dist/astro.d.ts.map +1 -0
  30. package/dist/astro.js +26 -0
  31. package/dist/astro.js.map +1 -0
  32. package/dist/client.min.d.ts +1 -0
  33. package/dist/client.min.js +1 -0
  34. package/dist/core-BhiA9fFi.d.ts +44 -0
  35. package/dist/core-BhiA9fFi.d.ts.map +1 -0
  36. package/dist/core-Dvqm7w2y.js +231 -0
  37. package/dist/core-Dvqm7w2y.js.map +1 -0
  38. package/dist/development/astro-application.js +62 -0
  39. package/dist/development/astro-application.js.map +1 -0
  40. package/dist/development/astro-client.js +98 -0
  41. package/dist/development/astro-client.js.map +1 -0
  42. package/dist/development/astro-context-OdlexHR4.js +79 -0
  43. package/dist/development/astro-context-OdlexHR4.js.map +1 -0
  44. package/dist/development/astro-middleware.js +49 -0
  45. package/dist/development/astro-middleware.js.map +1 -0
  46. package/dist/development/astro-request-DRKvDjsO.js +70 -0
  47. package/dist/development/astro-request-DRKvDjsO.js.map +1 -0
  48. package/dist/development/astro-server.js +30 -0
  49. package/dist/development/astro-server.js.map +1 -0
  50. package/dist/development/astro-shared-BT45auwR.js +29 -0
  51. package/dist/development/astro-shared-BT45auwR.js.map +1 -0
  52. package/dist/development/astro.js +26 -0
  53. package/dist/development/astro.js.map +1 -0
  54. package/dist/development/core-DB3sQz4h.js +234 -0
  55. package/dist/development/core-DB3sQz4h.js.map +1 -0
  56. package/dist/development/dom-D9cY6l1R.js +194 -0
  57. package/dist/development/dom-D9cY6l1R.js.map +1 -0
  58. package/dist/development/index.js +40 -0
  59. package/dist/development/index.js.map +1 -0
  60. package/dist/development/jsx-runtime.js +25 -0
  61. package/dist/development/jsx-runtime.js.map +1 -0
  62. package/dist/development/server.js +87 -0
  63. package/dist/development/server.js.map +1 -0
  64. package/dist/development/vite-CQchIQ_-.js +126 -0
  65. package/dist/development/vite-CQchIQ_-.js.map +1 -0
  66. package/dist/development/vite.js +1 -0
  67. package/dist/dom-BR9o9wZW.js +188 -0
  68. package/dist/dom-BR9o9wZW.js.map +1 -0
  69. package/dist/index.d.ts +24 -0
  70. package/dist/index.d.ts.map +1 -0
  71. package/dist/index.js +40 -0
  72. package/dist/index.js.map +1 -0
  73. package/dist/jsx-runtime-BzGV18VO.d.ts +965 -0
  74. package/dist/jsx-runtime-BzGV18VO.d.ts.map +1 -0
  75. package/dist/jsx-runtime.d.ts +2 -0
  76. package/dist/jsx-runtime.js +25 -0
  77. package/dist/jsx-runtime.js.map +1 -0
  78. package/dist/server.d.ts +3 -0
  79. package/dist/server.d.ts.map +1 -0
  80. package/dist/server.js +87 -0
  81. package/dist/server.js.map +1 -0
  82. package/dist/size.json +30 -0
  83. package/dist/vite-CQchIQ_-.js +126 -0
  84. package/dist/vite-CQchIQ_-.js.map +1 -0
  85. package/dist/vite.d.ts +6 -0
  86. package/dist/vite.d.ts.map +1 -0
  87. package/dist/vite.js +1 -0
  88. package/package.json +129 -3
  89. package/src/astro-application.ts +71 -0
  90. package/src/astro-client.ts +136 -0
  91. package/src/astro-context.ts +102 -0
  92. package/src/astro-middleware.ts +48 -0
  93. package/src/astro-request.ts +79 -0
  94. package/src/astro-server.ts +43 -0
  95. package/src/astro-shared.ts +78 -0
  96. package/src/astro.ts +47 -0
  97. package/src/compiler.ts +190 -0
  98. package/src/core.ts +385 -0
  99. package/src/dom.ts +385 -0
  100. package/src/env.d.ts +1 -0
  101. package/src/index.ts +24 -0
  102. package/src/jsx-runtime.ts +63 -0
  103. package/src/jsx-types.d.ts +909 -0
  104. package/src/server.ts +155 -0
  105. package/src/use-loadable.ts +67 -0
  106. package/src/vite.ts +48 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsx-runtime-BzGV18VO.d.ts","names":[],"sources":["../src/jsx-types.d.ts","../src/jsx-runtime.ts"],"mappings":";;KAGY,cAAc,UAAU,SAAS,UAAU,QAAQ,SAAS,KACvE;WAEc,eAAe;;KAClB,aAAa,UAAU,SAAS,UAAU,QAAQ,UAC7D,OAAO,cAAc,GAAG;KAEb,IAAI,UAAU,YAAY,SAAS;KAE1C,WAAW,QAAQ,WAAW,KAAK,EAAE;;UAGhC;EACT;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;KAEI,UAAU,oBACZ,IACA,WAAW,MACV,gBAAgB,aAAa,WAAW;KACvC,cAAc,UAAU,WAAW,UAAU,mBAC/C,2BACA,UAAU,mBACT,2BACA,UAAU,kBACT,0BACA,UAAU,sBACT,8BACA,UAAU,gBACT,wBACA,UAAU,aACT,qBACA;KACI,gBAAgB,UAAU,cAEpC,WAAW,cAAc,oBAAoB,UAAU,yBACpD,aAAa,GAAG,QAAQ,cAAc,GAAG,IAAI;KAG7C;KACO,iBAAiB;GAC3B;GACA,gBAAgB;GAChB;GACA;GACA;GACA,cAAc;GACd,iBAAiB;GACjB;GACA;GACA;GACA;GACA;GACA,iBAAiB;GACjB;GACA;GACA;GACA,kBAAkB;GAClB;GACA;GACA,kBAAkB;GAClB;GACA,iBAAiB;GACjB,kBAAkB;GAClB,gBAAgB;GAChB,iBAAiB;GACjB;GACA;GACA;GACA;GACA;GACA,eAAe;GACf,mBAAmB;GACnB,yBAAyB;GACzB;GACA;GACA;GACA;GACA,iBAAiB;GACjB,kBAAkB;GAClB;GAWA,kBAAkB;GAClB;GACA;GACA;GACA;GACA;GACA,kBAAkB;GAClB;GACA;GACA;GACA;GACA;GACA;;KAGU,cAAc,UAAU,WAAW,gBAAgB,KAC9D,iBACA;EACC,UAAU;EACV;EACA,KAAK,IAAI;EACT;EACA;EACA;EACA;EACA;EACA;EACA;EACA;QACO;;;KAIJ,YAAY,KAAK,WAAW,QAC/B,WAAW,KAAK,mBAAmB,UAAU,cAC3C,EAAE;KAIM,eAAe,UAAU,cAAc,eAClD,cAAc,KACb;EACC;EACA;EAOA;EACA;EACA;EACA;EACA;EACA;EAQA;EACA;EACA;EACA;EASA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;EAEA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;KAGE;KACA;KAUA;KACA;EACJ;EACA;EACA;EACA;EACA;EACA;;KAEI;EACJ;EACA;EACA;EACA,aAAa;EACb;EACA;EACA;EACA;EACA;;KAEI;EACJ;EACA;EACA;EACA;EACA,gBAAgB;EAChB;EACA;EACA;;KAEI;EACJ;EACA;EACA;EACA;EACA;;;UAIS;EACT,GAAG;EACH,MAAM;IACL;IACA;IACA;;EAED,OAAO;EACP;IAAQ;IAAc;;EACtB;IAAc;;EACd,QAAQ;IACP;IACA;IACA;IACA,OAAO;IACP;IACA;IACA;IACA;;EAED;IAAU,QAAQ;IAAgB,OAAO;;EACzC;IAAO;;EACP;IAAY;;EACZ;IAAQ,OAAO;;EACf;IAAO;IAAc;;EACrB;IAAW;IAAc;;EACzB;IAAU;IAAe;;EACzB;IACC,QAAQ;IACR;IACA;IACA,OAAO;;EAER;IAAY;IAAmB;IAAc;;EAC7C;IACC;KACC;IACD;IACA;IACA;IACA;IACA;IACA;IACA;IACA;;EAED;IAAQ;;EACR;IACC;IACA;IACA;IACA,QAAQ;IACR;IACA;IACA,gBAAgB;IAChB;IACA;IACA;IACA,OAAO;;EAER;IACC;IACA,aAAa;IACb;IACA;IACA,QAAQ;IACR;IACA;IACA,gBAAgB;IAChB;IACA;IACA;IACA;IACA,OAAO;;EAER,OAAO;IACN;IACA;IACA;IACA;IACA;IACA;IACA,cAAc;IACd;IACA;IACA,QAAQ;IACR;IACA,KAAK;IACL;IACA,KAAK;IACL;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,MAAM;IACN;IACA,OAAO;IACP,OAAO;;EAER;IAAO;IAAc;;EACrB;IAAS;IAAa;IAAiB;;EACvC;IAAM;;EACN;IACC;IACA;IACA,aAAa;IACb;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,gBAAgB;IAChB;IACA;IACA;;EAED;IAAO;;EACP;IACC;IACA;IACA;KACC;IACD;IACA;;EAED;IACC;IACA;IACA;IACA;IACA;IACA;;EAED;IACC;IACA;IACA,QAAQ;IACR;IACA;IACA;IACA,OAAO;;EAER;IAAM;IAAmB;IAAe;;EACxC;IAAY;IAAmB;;EAC/B;IACC;IACA;IACA;IACA,OAAO;;EAER;IAAU;IAAa;IAAiB;IAAc;;EACtD;IAAY;IAAa;;EACzB;IAAK;;EACL;IACC;IACA;IACA;IACA,aAAa;IACb;IACA;IACA;IACA;IACA,gBAAgB;IAChB;IACA;;EAED;IACC;IACA;IACA;IACA;IACA;IACA;IACA;IACA,OAAO;;EAER;IAAQ;;EACR;IACC,QAAQ;IACR;IACA;IACA;IACA;IACA;IACA,OAAO;;EAER;IAAS;IAAkB;IAAe;IAAe;;EACzD;IAAS,aAAa;IAAgB,aAAa;;EACnD,IAAI;EACJ;IACC;IACA;IACA;IACA;;EAED;IACC;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;;EAED,IAAI;EACJ;IAAQ;;EACR;IACC;IACA;IACA;IACA;IACA;;EAED,OAAO;IACN;IACA,QAAQ;IACR;IACA;IACA,OAAO;;;KAIG,2BACV,aAAa,wBAAwB,eACrC,sBAAsB,SAErB,kBAAkB,oBAChB,YAAY,kBAAkB;;KAKvB,cAAc,UAAU,aAAa,cAAc,cAAc,KAC5E;EACC;GACC;GACA;EACD;GACC;GACA;GACA,mBAAmB;EACpB;GACC;GACA;EACD;GACC;GACA;GACA;EACD;EACA;EACA;GACC;EACD;GACC,iBAAiB;GACjB;EACD;GACC;GACA,kBAAkB;GAClB;GACA,cAAc;GACd,qBAAqB;GACrB;GACA;GACA;GACA,gBAAgB;GAChB;GACA,mBAAmB;GACnB;GACA;GACA;GACA;EACD;EACA,SAAS;EACT;GACC;GACA;GACA;GACA;GACA,iBAAiB;EAClB;GACC,qBAAqB;GACrB,sBAAsB;GACtB;GACA;GACA,sBAAsB;GACtB,mBAAmB;GACnB,iBAAiB;GACjB;GACA;GACA;EACD;GACC;GACA;GACA;EACD;GACC,iBAAiB;GACjB;;KAGE;EACJ,GAAG;EACH,GAAG;EACH,OAAO;EACP,QAAQ;;KAEJ;EAAe;EAAiB;;KAChC;EAAY;GAAe;;KAC3B,qBAAqB;EAAW;;KAChC,eAAe;EACnB;EACA;EACA,OAAO;EACP,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL;EACA,aAAa;EACb,WAAW;EACX;EACA;EACA;EACA;EACA,MAAM;EACN,IAAI;EACJ,IAAI;EACJ;EACA;;KAEI;EACJ,GAAG;EACH,GAAG;EACH,IAAI;EACJ,IAAI;EACJ,QAAQ;EACR,YAAY;EACZ;;UAES;EACT,GAAG;IACF;IACA;IACA;IACA;IACA;;EAED,SAAS;EACT,eAAe;IACd;IACA;IACA,QAAQ;IACR;;EAED,kBAAkB;IACjB;;EAED;IACC,IAAI;IACJ,IAAI;IACJ,GAAG;IACH;;EAED;IAAY;;EACZ;IACC,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ;;EAED,SAAS;IAAuB;IAAY;IAAa;;EACzD,eAAe;IACd;IACA;IACA;;EAED,qBAAqB;IAAuB;;EAC5C,aAAa;IACZ;IACA;IACA;IACA;IACA;IACA;IACA;;EAED,kBAAkB;IACjB;IACA,OAAO;IACP;IACA;IACA;IACA;IACA;IACA;IACA,eAAe;;EAEhB,mBAAmB;IAClB;IACA;IACA;IACA,kBAAkB;;EAEnB,mBAAmB;IAClB;IACA;IACA;IACA;IACA;;EAED;IAAkB;IAAiB;;EACnC,cAAc;IACb,IAAI;IACJ,IAAI;IACJ,cAAc;;EAEf,SAAS;EACT;IACC;IACA;IACA;IACA;IACA;IACA;IACA;;EAED,SAAS;EACT,SAAS;EACT,SAAS;EACT,gBAAgB;IACf;IACA,cAAc;IACd;;EAED,SAAS,qBACR;IAAY;IAA6B,aAAa;;EACvD,SAAS;EACT;IAAe;;EACf,cA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AAW;MAAU;iBACvC,IACf,MAAM,eACN,OAAO,uBACP,gBACE;cAMU,aAAI;cACJ,eAAM;;iBAGH,SACZ,UAAU,6BAA6B,0BACxC;kBAkBc;OACJ,UAAU;OACV,oBAAoB,oBAAoB;YACnC;IAChB;;YAEgB;IAChB;;;YAGgB,0BAA0B;KACzC,6BAA6B,eAAe"}
@@ -0,0 +1,2 @@
1
+ import { a as jsxs, c as DOMAttributes, d as HTMLAttributes, f as Ref, i as jsxDEV, l as EventAttributes, m as TargetedEvent, n as JSX, o as merge, p as SVGAttributes, r as jsx, s as AriaAttributes, t as Fragment, u as EventHandler } from "./jsx-runtime-BzGV18VO.js";
2
+ export { type AriaAttributes, type DOMAttributes, type EventAttributes, type EventHandler, Fragment, type HTMLAttributes, JSX, type Ref, type SVGAttributes, type TargetedEvent, jsx, jsxDEV, jsxs, merge };
@@ -0,0 +1,25 @@
1
+ // src/jsx-runtime.ts
2
+ const Fragment = (props) => props.children;
3
+ function jsx(type, props, key) {
4
+ return {
5
+ type,
6
+ props: key === void 0 ? props ?? {} : merge(props ?? {}, { key })
7
+ };
8
+ }
9
+ const jsxs = jsx;
10
+ const jsxDEV = jsx;
11
+ /** Preserve lazy props and spread precedence, including keys added by later updates. */
12
+ function merge(...sources) {
13
+ const values = () => sources.map((source) => (typeof source === `function` ? source() : source) ?? {});
14
+ return new Proxy({}, {
15
+ get: (_, key) => values().reverse().find((source) => Object.hasOwn(source, key))?.[key],
16
+ ownKeys: () => [...new Set(values().flatMap(Object.keys))],
17
+ getOwnPropertyDescriptor: () => ({
18
+ enumerable: true,
19
+ configurable: true
20
+ })
21
+ });
22
+ }
23
+ export { Fragment, jsx, jsxDEV, jsxs, merge };
24
+
25
+ //# sourceMappingURL=jsx-runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsx-runtime.js","names":[],"sources":["../src/jsx-runtime.ts"],"sourcesContent":["import type { Child, Component, VNode } from \"./core.ts\"\nimport type { HTMLAttributes, NativeElements } from \"./jsx-types.d.ts\"\n\nexport type {\n\tAriaAttributes,\n\tDOMAttributes,\n\tEventAttributes,\n\tEventHandler,\n\tHTMLAttributes,\n\tRef,\n\tSVGAttributes,\n\tTargetedEvent,\n} from \"./jsx-types.d.ts\"\n\nexport const Fragment = (props: { children?: Child }): Child => props.children\nexport function jsx(\n\ttype: VNode[`type`],\n\tprops: VNode[`props`] | null,\n\tkey?: unknown,\n): VNode {\n\treturn {\n\t\ttype,\n\t\tprops: key === undefined ? (props ?? {}) : merge(props ?? {}, { key }),\n\t}\n}\nexport const jsxs = jsx\nexport const jsxDEV = jsx\n\n/** Preserve lazy props and spread precedence, including keys added by later updates. */\nexport function merge(\n\t...sources: (Record<string, any> | (() => Record<string, any>))[]\n): Record<string, any> {\n\tconst values = () =>\n\t\tsources.map(\n\t\t\t(source) => (typeof source === `function` ? source() : source) ?? {},\n\t\t)\n\treturn new Proxy(\n\t\t{},\n\t\t{\n\t\t\tget: (_, key) =>\n\t\t\t\tvalues()\n\t\t\t\t\t.reverse()\n\t\t\t\t\t.find((source) => Object.hasOwn(source, key))?.[key],\n\t\t\townKeys: () => [...new Set(values().flatMap(Object.keys))],\n\t\t\tgetOwnPropertyDescriptor: () => ({ enumerable: true, configurable: true }),\n\t\t},\n\t)\n}\n\nexport namespace JSX {\n\texport type Element = VNode\n\texport type ElementType = keyof IntrinsicElements | Component\n\texport interface ElementChildrenAttribute {\n\t\tchildren: {}\n\t}\n\texport interface IntrinsicAttributes {\n\t\tkey?: string | number\n\t}\n\t/** Augment this interface to declare attributes for registered custom elements. */\n\texport interface IntrinsicElements extends NativeElements {\n\t\t[tag: `${string}-${string}`]: HTMLAttributes<HTMLElement>\n\t}\n}\n"],"mappings":";AAcA,MAAa,YAAY,UAAuC,MAAM;AACtE,SAAgB,IACf,MACA,OACA,KACQ;CACR,OAAO;EACN;EACA,OAAO,QAAQ,KAAA,IAAa,SAAS,CAAC,IAAK,MAAM,SAAS,CAAC,GAAG,EAAE,IAAI,CAAC;CACtE;AACD;AACA,MAAa,OAAO;AACpB,MAAa,SAAS;;AAGtB,SAAgB,MACf,GAAG,SACmB;CACtB,MAAM,eACL,QAAQ,KACN,YAAY,OAAO,WAAW,aAAa,OAAO,IAAI,WAAW,CAAC,CACpE;CACD,OAAO,IAAI,MACV,CAAC,GACD;EACC,MAAM,GAAG,QACR,OAAO,CAAC,CACN,QAAQ,CAAC,CACT,MAAM,WAAW,OAAO,OAAO,QAAQ,GAAG,CAAC,CAAC,GAAG;EAClD,eAAe,CAAC,GAAG,IAAI,IAAI,OAAO,CAAC,CAAC,QAAQ,OAAO,IAAI,CAAC,CAAC;EACzD,iCAAiC;GAAE,YAAY;GAAM,cAAc;EAAK;CACzE,CACD;AACD"}
@@ -0,0 +1,3 @@
1
+ import { i as RootOptions, n as Child } from "./core-BhiA9fFi.js";
2
+ export declare function renderToString(setup: () => Child, options?: RootOptions): string;
3
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","names":[],"sources":["../src/server.ts"],"mappings":";wBA+IgB,eACf,aAAa,OACb,UAAS"}
package/dist/server.js ADDED
@@ -0,0 +1,87 @@
1
+ import { b as within, f as untrack, n as createScope, r as dispose, t as createRoot, u as plain } from "./core-Dvqm7w2y.js";
2
+ import { Fragment } from "./jsx-runtime.js";
3
+ // src/server.ts
4
+ const escape = (value) => String(value).replace(/[&<>"']/g, (char) => ({
5
+ "&": `&amp;`,
6
+ "<": `&lt;`,
7
+ ">": `&gt;`,
8
+ "\"": `&quot;`,
9
+ "'": `&#39;`
10
+ })[char]);
11
+ const voidTags = /^(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/;
12
+ const booleans = new Set(`allowfullscreen async autofocus autoplay checked controls credentialless default defer disabled disablepictureinpicture disableremoteplayback formnovalidate inert ismap itemscope loop multiple muted nomodule novalidate open playsinline readonly required reversed selected shadowrootclonable shadowrootdelegatesfocus shadowrootserializable`.split(` `));
13
+ function stringify(value, owner, namespace = `html`, selectValue) {
14
+ if (typeof value === `function`) {
15
+ const values = [untrack(value)].flat(Infinity);
16
+ const keys = /* @__PURE__ */ new Set();
17
+ return `<!--{-->` + values.map((child, index) => {
18
+ const explicit = child?.props?.[`key`];
19
+ const key = explicit == null ? index : String(explicit);
20
+ if (keys.has(key)) throw new Error(`spa: duplicate key`);
21
+ keys.add(key);
22
+ return `<!--[-->${within(owner, () => stringify(child, createScope(owner), namespace, selectValue))}<!--]-->`;
23
+ }).join(``) + `<!--}-->`;
24
+ }
25
+ if (Array.isArray(value)) return value.map((child) => stringify(child, owner, namespace, selectValue)).join(``);
26
+ if (value == null || typeof value === `boolean`) return ``;
27
+ if (typeof value !== `object`) return `<!--t-->${escape(value)}`;
28
+ if (!(`type` in value) || !(`props` in value)) throw new TypeError(`spa: invalid child`);
29
+ const { type, props } = value;
30
+ if (!type || type === Fragment) return stringify(() => props[`children`], owner, namespace, selectValue);
31
+ if (typeof type === `function`) {
32
+ const childOwner = createScope(owner);
33
+ return within(childOwner, () => stringify(untrack(() => type(props)), childOwner, namespace, selectValue));
34
+ }
35
+ if (!/^[A-Za-z][\w.:-]*$/.test(type)) throw new Error(`spa: invalid tag`);
36
+ if (type === `astro-slot`) return `<astro-slot${props[`name`] ? ` name="${escape(props[`name`])}"` : ``}>${props[`innerHTML`] ?? ``}</astro-slot>`;
37
+ const ns = type === `svg` ? `svg` : namespace;
38
+ let attrs = ``;
39
+ let textValue;
40
+ for (let key of Object.keys(props)) {
41
+ if (key === `children` || key === `ref` || key === `key` || key.startsWith(`on`)) continue;
42
+ if (/^(innerHTML|outerHTML|textContent|innerText|dangerouslySetInnerHTML)$/.test(key)) throw new Error(`spa: owned content`);
43
+ let attribute = props[key];
44
+ if (ns === `html`) {
45
+ if (key === `defaultValue` && (type === `input` || type === `textarea`)) {
46
+ if (props[`value`] != null) continue;
47
+ key = `value`;
48
+ } else if (key === `defaultChecked` && type === `input`) {
49
+ if (props[`checked`] != null) continue;
50
+ key = `checked`;
51
+ }
52
+ }
53
+ if (key === `className`) key = `class`;
54
+ if (key === `htmlFor`) key = `for`;
55
+ if (!/^[^\s"'<>/=]+$/.test(key)) throw new Error(`spa: invalid attribute`);
56
+ if (key === `value` && (type === `select` || type === `textarea`)) {
57
+ textValue = attribute ?? textValue;
58
+ continue;
59
+ }
60
+ if (key === `style` && attribute != null && typeof attribute !== `string`) throw new TypeError(`spa: CSS string required`);
61
+ const boolean = ns === `html` && (booleans.has(key.toLowerCase()) || /^(capture|download|hidden)$/.test(key) && typeof attribute === `boolean`);
62
+ if (attribute == null || boolean && !attribute) continue;
63
+ attrs += boolean ? ` ${key}=""` : ` ${key}="${escape(attribute)}"`;
64
+ }
65
+ if (type === `option` && selectValue !== void 0 && String(props[`value`]) === String(selectValue)) attrs += ` selected=""`;
66
+ if (ns === `html` && voidTags.test(type)) return `<${type}${attrs}>`;
67
+ if (ns === `html` && /^(textarea|title|style|script)$/.test(type)) {
68
+ let text = plain(type === `textarea` ? textValue ?? props[`children`] : props[`children`]);
69
+ if (type === `textarea` && text.startsWith(`\n`)) text = `\n${text}`;
70
+ if (/^(script|style)$/.test(type) && new RegExp(`</${type}`, `i`).test(text)) throw new Error(`spa: unsafe raw text`);
71
+ return `<${type}${attrs}>${/^(script|style)$/.test(type) ? text : escape(text)}</${type}>`;
72
+ }
73
+ const children = stringify(() => props[`children`], owner, type === `foreignObject` ? `html` : ns, type === `select` ? textValue : selectValue);
74
+ return `<${type}${attrs}>${children}</${type}>`;
75
+ }
76
+ function renderToString(setup, options = {}) {
77
+ const root = createRoot(options, true);
78
+ if (/--|[<>]/.test(root._prefix)) throw new Error(`spa: invalid idPrefix`);
79
+ try {
80
+ return `<!--w:${root._prefix}-->${within(root, () => stringify(untrack(setup), root))}<!--/w-->`;
81
+ } finally {
82
+ dispose(root);
83
+ }
84
+ }
85
+ export { renderToString };
86
+
87
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","names":[],"sources":["../src/server.ts"],"sourcesContent":["import type { Child, RootOptions, Scope, VNode } from \"./core.ts\"\nimport {\n\tcreateRoot,\n\tcreateScope,\n\tdispose,\n\tplain,\n\tuntrack,\n\twithin,\n} from \"./core.ts\"\nimport { Fragment } from \"./jsx-runtime.ts\"\n\nconst escape = (value: unknown): string =>\n\tString(value).replace(\n\t\t/[&<>\"']/g,\n\t\t(char) =>\n\t\t\t({ \"&\": `&amp;`, \"<\": `&lt;`, \">\": `&gt;`, '\"': `&quot;`, \"'\": `&#39;` })[\n\t\t\t\tchar\n\t\t\t]!,\n\t)\nconst voidTags =\n\t/^(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/\nconst booleans = new Set(\n\t`allowfullscreen async autofocus autoplay checked controls credentialless default defer disabled disablepictureinpicture disableremoteplayback formnovalidate inert ismap itemscope loop multiple muted nomodule novalidate open playsinline readonly required reversed selected shadowrootclonable shadowrootdelegatesfocus shadowrootserializable`.split(\n\t\t` `,\n\t),\n)\nfunction stringify(\n\tvalue: Child,\n\towner: Scope,\n\tnamespace = `html`,\n\tselectValue?: string | number,\n): string {\n\tif (typeof value === `function`) {\n\t\tconst values = ([untrack(value)] as unknown[]).flat(Infinity) as Child[]\n\t\tconst keys = new Set<unknown>()\n\t\treturn (\n\t\t\t`<!--{-->` +\n\t\t\tvalues\n\t\t\t\t.map((child, index) => {\n\t\t\t\t\tconst explicit = (child as VNode | null)?.props?.[`key`]\n\t\t\t\t\tconst key = explicit == null ? index : String(explicit)\n\t\t\t\t\tif (keys.has(key)) throw new Error(`spa: duplicate key`)\n\t\t\t\t\tkeys.add(key)\n\t\t\t\t\treturn `<!--[-->${within(owner, () => stringify(child, createScope(owner), namespace, selectValue))}<!--]-->`\n\t\t\t\t})\n\t\t\t\t.join(``) +\n\t\t\t`<!--}-->`\n\t\t)\n\t}\n\tif (Array.isArray(value))\n\t\treturn value\n\t\t\t.map((child) => stringify(child, owner, namespace, selectValue))\n\t\t\t.join(``)\n\tif (value == null || typeof value === `boolean`) return ``\n\tif (typeof value !== `object`) return `<!--t-->${escape(value)}`\n\tif (!(`type` in value) || !(`props` in value))\n\t\tthrow new TypeError(`spa: invalid child`)\n\tconst { type, props } = value\n\tif (!type || type === Fragment)\n\t\treturn stringify(() => props[`children`], owner, namespace, selectValue)\n\tif (typeof type === `function`) {\n\t\tconst childOwner = createScope(owner)\n\t\treturn within(childOwner, () =>\n\t\t\tstringify(\n\t\t\t\tuntrack(() => type(props)),\n\t\t\t\tchildOwner,\n\t\t\t\tnamespace,\n\t\t\t\tselectValue,\n\t\t\t),\n\t\t)\n\t}\n\tif (!/^[A-Za-z][\\w.:-]*$/.test(type)) throw new Error(`spa: invalid tag`)\n\tif (type === `astro-slot`)\n\t\treturn `<astro-slot${props[`name`] ? ` name=\"${escape(props[`name`])}\"` : ``}>${props[`innerHTML`] ?? ``}</astro-slot>`\n\tconst ns = type === `svg` ? `svg` : namespace\n\tlet attrs = ``\n\tlet textValue: string | number | undefined\n\tfor (let key of Object.keys(props)) {\n\t\tif (\n\t\t\tkey === `children` ||\n\t\t\tkey === `ref` ||\n\t\t\tkey === `key` ||\n\t\t\tkey.startsWith(`on`)\n\t\t)\n\t\t\tcontinue\n\t\tif (\n\t\t\t/^(innerHTML|outerHTML|textContent|innerText|dangerouslySetInnerHTML)$/.test(\n\t\t\t\tkey,\n\t\t\t)\n\t\t)\n\t\t\tthrow new Error(`spa: owned content`)\n\t\tlet attribute = props[key]\n\t\tif (ns === `html`) {\n\t\t\tif (key === `defaultValue` && (type === `input` || type === `textarea`)) {\n\t\t\t\tif (props[`value`] != null) continue\n\t\t\t\tkey = `value`\n\t\t\t} else if (key === `defaultChecked` && type === `input`) {\n\t\t\t\tif (props[`checked`] != null) continue\n\t\t\t\tkey = `checked`\n\t\t\t}\n\t\t}\n\t\tif (key === `className`) key = `class`\n\t\tif (key === `htmlFor`) key = `for`\n\t\tif (!/^[^\\s\"'<>/=]+$/.test(key)) throw new Error(`spa: invalid attribute`)\n\t\tif (key === `value` && (type === `select` || type === `textarea`)) {\n\t\t\ttextValue = attribute ?? textValue\n\t\t\tcontinue\n\t\t}\n\t\tif (key === `style` && attribute != null && typeof attribute !== `string`)\n\t\t\tthrow new TypeError(`spa: CSS string required`)\n\t\tconst boolean =\n\t\t\tns === `html` &&\n\t\t\t(booleans.has(key.toLowerCase()) ||\n\t\t\t\t(/^(capture|download|hidden)$/.test(key) &&\n\t\t\t\t\ttypeof attribute === `boolean`))\n\t\tif (attribute == null || (boolean && !attribute)) continue\n\t\tattrs += boolean ? ` ${key}=\"\"` : ` ${key}=\"${escape(attribute)}\"`\n\t}\n\tif (\n\t\ttype === `option` &&\n\t\tselectValue !== undefined &&\n\t\tString(props[`value`]) === String(selectValue)\n\t)\n\t\tattrs += ` selected=\"\"`\n\tif (ns === `html` && voidTags.test(type)) return `<${type}${attrs}>`\n\tif (ns === `html` && /^(textarea|title|style|script)$/.test(type)) {\n\t\tlet text = plain(\n\t\t\ttype === `textarea` ? (textValue ?? props[`children`]) : props[`children`],\n\t\t)\n\t\tif (type === `textarea` && text.startsWith(`\\n`)) text = `\\n${text}`\n\t\tif (/^(script|style)$/.test(type) && new RegExp(`</${type}`, `i`).test(text))\n\t\t\tthrow new Error(`spa: unsafe raw text`)\n\t\treturn `<${type}${attrs}>${/^(script|style)$/.test(type) ? text : escape(text)}</${type}>`\n\t}\n\tconst children = stringify(\n\t\t() => props[`children`],\n\t\towner,\n\t\ttype === `foreignObject` ? `html` : ns,\n\t\ttype === `select` ? textValue : selectValue,\n\t)\n\treturn `<${type}${attrs}>${children}</${type}>`\n}\n\nexport function renderToString(\n\tsetup: () => Child,\n\toptions: RootOptions = {},\n): string {\n\tconst root = createRoot(options, true)\n\tif (/--|[<>]/.test(root._prefix)) throw new Error(`spa: invalid idPrefix`)\n\ttry {\n\t\treturn `<!--w:${root._prefix}-->${within(root, () => stringify(untrack(setup), root))}<!--/w-->`\n\t} finally {\n\t\tdispose(root)\n\t}\n}\n"],"mappings":";;;AAWA,MA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EAAE;CACjE;CACA,IACC,SAAS,YACT,gBAAgB,KAAA,KAChB,OAAO,MAAM,QAAQ,MAAM,OAAO,WAAW,GAE7C,SAAS;CACV,IAAI,OAAO,UAAU,SAAS,KAAK,IAAI,GAAG,OAAO,IAAI,OAAO,MAAM;CAClE,IAAI,OAAO,UAAU,kCAAkC,KAAK,IAAI,GAAG;EAClE,IAAI,OAAO,MACV,SAAS,aAAc,aAAa,MAAM,cAAe,MAAM,WAChE;EACA,IAAI,SAAS,cAAc,KAAK,WAAW,IAAI,GAAG,OAAO,KAAK;EAC9D,IAAI,mBAAmB,KAAK,IAAI,KAAK,IAAI,OAAO,KAAK,QAAQ,GAAG,CAAC,CAAC,KAAK,IAAI,GAC1E,MAAM,IAAI,MAAM,sBAAsB;EACvC,OAAO,IAAI,OAAO,MAAM,GAAG,mBAAmB,KAAK,IAAI,IAAI,OAAO,OAAO,IAAI,EAAE,IAAI,KAAK;CACzF;CACA,MAAM,WAAW,gBACV,MAAM,aACZ,OACA,SAAS,kBAAkB,SAAS,IACpC,SAAS,WAAW,YAAY,WACjC;CACA,OAAO,IAAI,OAAO,MAAM,GAAG,SAAS,IAAI,KAAK;AAC9C;AAEA,SAAgB,eACf,OACA,UAAuB,CAAC,GACf;CACT,MAAM,OAAO,WAAW,SAAS,IAAI;CACrC,IAAI,UAAU,KAAK,KAAK,OAAO,GAAG,MAAM,IAAI,MAAM,uBAAuB;CACzE,IAAI;EACH,OAAO,SAAS,KAAK,QAAQ,KAAK,OAAO,YAAY,UAAU,QAAQ,KAAK,GAAG,IAAI,CAAC,EAAE;CACvF,UAAU;EACT,QAAQ,IAAI;CACb;AACD"}
package/dist/size.json ADDED
@@ -0,0 +1,30 @@
1
+ [
2
+ {
3
+ "name": "spa client",
4
+ "raw": 16033,
5
+ "minified": 7799,
6
+ "gzip": 3358,
7
+ "brotli": 3086
8
+ },
9
+ {
10
+ "name": "spa + atom.io",
11
+ "raw": 104659,
12
+ "minified": 51020,
13
+ "gzip": 15229,
14
+ "brotli": 13780
15
+ },
16
+ {
17
+ "name": "spa Astro client",
18
+ "raw": 20784,
19
+ "minified": 9858,
20
+ "gzip": 4107,
21
+ "brotli": 3721
22
+ },
23
+ {
24
+ "name": "Preact",
25
+ "raw": 17964,
26
+ "minified": 12002,
27
+ "gzip": 4957,
28
+ "brotli": 4538
29
+ }
30
+ ]
@@ -0,0 +1,126 @@
1
+ import { transformSync, types } from "@babel/core";
2
+ // src/compiler.ts
3
+ function compile(code, filename) {
4
+ const plugin = () => {
5
+ let create;
6
+ let merge;
7
+ const generated = /* @__PURE__ */ new WeakSet();
8
+ const components = /* @__PURE__ */ new Set();
9
+ function name(node) {
10
+ if (types.isJSXMemberExpression(node)) return types.memberExpression(types.isJSXIdentifier(node.object) ? node.object.name === `this` ? types.thisExpression() : types.identifier(node.object.name) : name(node.object), types.identifier(node.property.name));
11
+ if (types.isJSXNamespacedName(node)) return types.stringLiteral(`${node.namespace.name}:${node.name.name}`);
12
+ return /^[a-z]/.test(node.name) || node.name.includes(`-`) ? types.stringLiteral(node.name) : types.identifier(node.name);
13
+ }
14
+ function literal(node) {
15
+ return types.isLiteral(node) && (!types.isTemplateLiteral(node) || node.expressions.length === 0);
16
+ }
17
+ function child(node) {
18
+ return generated.has(node) || literal(node) || types.isFunction(node) ? node : types.arrowFunctionExpression([], node);
19
+ }
20
+ return { visitor: {
21
+ ExportDefaultDeclaration(path) {
22
+ if (types.isArrowFunctionExpression(path.node.declaration) || types.isFunctionExpression(path.node.declaration)) {
23
+ const id = path.scope.generateUidIdentifier(`Component`);
24
+ path.replaceWithMultiple([types.variableDeclaration(`const`, [types.variableDeclarator(id, path.node.declaration)]), types.exportDefaultDeclaration(id)]);
25
+ }
26
+ },
27
+ Program: {
28
+ enter(path) {
29
+ create = path.scope.generateUidIdentifier(`spa`);
30
+ merge = path.scope.generateUidIdentifier(`props`);
31
+ },
32
+ exit(path) {
33
+ path.unshiftContainer(`body`, types.importDeclaration([types.importSpecifier(create, types.identifier(`jsx`)), types.importSpecifier(merge, types.identifier(`merge`))], types.stringLiteral(`@atom.io/spa/jsx-runtime`)));
34
+ for (const component of components) path.pushContainer(`body`, types.expressionStatement(types.assignmentExpression(`=`, types.memberExpression(types.identifier(component), types.identifier(`spa`)), types.booleanLiteral(true))));
35
+ }
36
+ },
37
+ "JSXElement|JSXFragment": { exit(path) {
38
+ const node = path.node;
39
+ const chunks = [];
40
+ let properties = [];
41
+ const flush = () => {
42
+ if (properties.length) {
43
+ chunks.push(types.objectExpression(properties));
44
+ properties = [];
45
+ }
46
+ };
47
+ if (types.isJSXElement(node)) for (const attribute of node.openingElement.attributes) {
48
+ if (types.isJSXSpreadAttribute(attribute)) {
49
+ flush();
50
+ chunks.push(types.arrowFunctionExpression([], attribute.argument));
51
+ continue;
52
+ }
53
+ const key = types.isJSXNamespacedName(attribute.name) ? `${attribute.name.namespace.name}:${attribute.name.name.name}` : attribute.name.name;
54
+ const expression = attribute.value == null ? types.booleanLiteral(true) : types.isJSXExpressionContainer(attribute.value) ? attribute.value.expression : attribute.value;
55
+ properties.push(key === `key` || literal(expression) || types.isFunction(expression) ? types.objectProperty(types.stringLiteral(key), expression) : types.objectMethod(`get`, types.stringLiteral(key), [], types.blockStatement([types.returnStatement(expression)])));
56
+ }
57
+ const children = types.react.buildChildren(node).map((value) => child(value));
58
+ if (children.length) properties.push(types.objectProperty(types.identifier(`children`), children.length === 1 ? children[0] : types.arrayExpression(children)));
59
+ flush();
60
+ const props = chunks.length > 1 || types.isArrowFunctionExpression(chunks[0]) ? types.callExpression(merge, chunks) : chunks[0] ?? types.objectExpression([]);
61
+ const result = types.callExpression(create, [types.isJSXElement(node) ? name(node.openingElement.name) : types.nullLiteral(), props]);
62
+ generated.add(result);
63
+ let fn = path.findParent((parent) => parent.isFunction());
64
+ while (fn?.findParent((parent) => parent.isFunction())) fn = fn.findParent((parent) => parent.isFunction());
65
+ if (fn) {
66
+ if (fn.isFunctionDeclaration() && fn.node.id) components.add(fn.node.id.name);
67
+ else if (fn.parentPath.isVariableDeclarator() && types.isIdentifier(fn.parentPath.node.id)) components.add(fn.parentPath.node.id.name);
68
+ else if (fn.parentPath.isExportDefaultDeclaration() && types.isFunctionDeclaration(fn.node)) {
69
+ fn.node.id = path.scope.generateUidIdentifier(`Component`);
70
+ components.add(fn.node.id.name);
71
+ }
72
+ }
73
+ path.replaceWith(result);
74
+ } }
75
+ } };
76
+ };
77
+ const result = transformSync(code, {
78
+ filename,
79
+ babelrc: false,
80
+ configFile: false,
81
+ sourceMaps: true,
82
+ parserOpts: { plugins: [`jsx`, `typescript`] },
83
+ plugins: [plugin]
84
+ });
85
+ return {
86
+ code: result.code,
87
+ map: result.map
88
+ };
89
+ }
90
+ // src/vite.ts
91
+ function spa(options = {}) {
92
+ const include = options.include ?? /\.[jt]sx$/;
93
+ const matches = (id) => {
94
+ include.lastIndex = 0;
95
+ return !id.includes(`/node_modules/`) && include.test(id.split(`?`)[0]);
96
+ };
97
+ return {
98
+ name: `spa`,
99
+ enforce: `pre`,
100
+ config() {
101
+ return {
102
+ resolve: { dedupe: [`@atom.io/spa`, `atom.io`] },
103
+ optimizeDeps: { exclude: [`@atom.io/spa`, `atom.io`] }
104
+ };
105
+ },
106
+ configEnvironment: {
107
+ order: `post`,
108
+ handler(_name, config) {
109
+ if (config.optimizeDeps?.include) config.optimizeDeps.include = config.optimizeDeps.include.filter((id) => !/^(@atom\.io\/spa|atom\.io)(\/|$)/.test(id));
110
+ }
111
+ },
112
+ transform(code, id) {
113
+ if (!matches(id)) return;
114
+ return compile(code, id);
115
+ },
116
+ handleHotUpdate({ server, file }) {
117
+ if (matches(file)) {
118
+ server.ws.send({ type: `full-reload` });
119
+ return [];
120
+ }
121
+ }
122
+ };
123
+ }
124
+ export { spa as t };
125
+
126
+ //# sourceMappingURL=vite-CQchIQ_-.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite-CQchIQ_-.js","names":["t"],"sources":["../src/compiler.ts","../src/vite.ts"],"sourcesContent":["import type { PluginObject } from \"@babel/core\"\nimport { transformSync, types as t } from \"@babel/core\"\n\nexport function compile(\n\tcode: string,\n\tfilename: string,\n): { code: string; map: any } {\n\tconst plugin = (): PluginObject => {\n\t\tlet create: t.Identifier\n\t\tlet merge: t.Identifier\n\t\tconst generated = new WeakSet<object>()\n\t\tconst components = new Set<string>()\n\t\tfunction name(\n\t\t\tnode: t.JSXIdentifier | t.JSXMemberExpression | t.JSXNamespacedName,\n\t\t): t.Expression {\n\t\t\tif (t.isJSXMemberExpression(node))\n\t\t\t\treturn t.memberExpression(\n\t\t\t\t\tt.isJSXIdentifier(node.object)\n\t\t\t\t\t\t? node.object.name === `this`\n\t\t\t\t\t\t\t? t.thisExpression()\n\t\t\t\t\t\t\t: t.identifier(node.object.name)\n\t\t\t\t\t\t: name(node.object),\n\t\t\t\t\tt.identifier(node.property.name),\n\t\t\t\t)\n\t\t\tif (t.isJSXNamespacedName(node))\n\t\t\t\treturn t.stringLiteral(`${node.namespace.name}:${node.name.name}`)\n\t\t\treturn /^[a-z]/.test(node.name) || node.name.includes(`-`)\n\t\t\t\t? t.stringLiteral(node.name)\n\t\t\t\t: t.identifier(node.name)\n\t\t}\n\t\tfunction literal(node: t.Node): boolean {\n\t\t\treturn (\n\t\t\t\tt.isLiteral(node) &&\n\t\t\t\t(!t.isTemplateLiteral(node) || node.expressions.length === 0)\n\t\t\t)\n\t\t}\n\t\tfunction child(node: t.Expression): t.Expression {\n\t\t\treturn generated.has(node) || literal(node) || t.isFunction(node)\n\t\t\t\t? node\n\t\t\t\t: t.arrowFunctionExpression([], node)\n\t\t}\n\t\treturn {\n\t\t\tvisitor: {\n\t\t\t\tExportDefaultDeclaration(path) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tt.isArrowFunctionExpression(path.node.declaration) ||\n\t\t\t\t\t\tt.isFunctionExpression(path.node.declaration)\n\t\t\t\t\t) {\n\t\t\t\t\t\tconst id = path.scope.generateUidIdentifier(`Component`)\n\t\t\t\t\t\tpath.replaceWithMultiple([\n\t\t\t\t\t\t\tt.variableDeclaration(`const`, [\n\t\t\t\t\t\t\t\tt.variableDeclarator(id, path.node.declaration),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\tt.exportDefaultDeclaration(id),\n\t\t\t\t\t\t])\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tProgram: {\n\t\t\t\t\tenter(path) {\n\t\t\t\t\t\tcreate = path.scope.generateUidIdentifier(`spa`)\n\t\t\t\t\t\tmerge = path.scope.generateUidIdentifier(`props`)\n\t\t\t\t\t},\n\t\t\t\t\texit(path) {\n\t\t\t\t\t\tpath.unshiftContainer(\n\t\t\t\t\t\t\t`body`,\n\t\t\t\t\t\t\tt.importDeclaration(\n\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\tt.importSpecifier(create, t.identifier(`jsx`)),\n\t\t\t\t\t\t\t\t\tt.importSpecifier(merge, t.identifier(`merge`)),\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\tt.stringLiteral(`@atom.io/spa/jsx-runtime`),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t)\n\t\t\t\t\t\tfor (const component of components)\n\t\t\t\t\t\t\tpath.pushContainer(\n\t\t\t\t\t\t\t\t`body`,\n\t\t\t\t\t\t\t\tt.expressionStatement(\n\t\t\t\t\t\t\t\t\tt.assignmentExpression(\n\t\t\t\t\t\t\t\t\t\t`=`,\n\t\t\t\t\t\t\t\t\t\tt.memberExpression(\n\t\t\t\t\t\t\t\t\t\t\tt.identifier(component),\n\t\t\t\t\t\t\t\t\t\t\tt.identifier(`spa`),\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\tt.booleanLiteral(true),\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t\"JSXElement|JSXFragment\": {\n\t\t\t\t\texit(path: any) {\n\t\t\t\t\t\tconst node = path.node as t.JSXElement | t.JSXFragment\n\t\t\t\t\t\tconst chunks: t.Expression[] = []\n\t\t\t\t\t\tlet properties: (t.ObjectProperty | t.ObjectMethod)[] = []\n\t\t\t\t\t\tconst flush = () => {\n\t\t\t\t\t\t\tif (properties.length) {\n\t\t\t\t\t\t\t\tchunks.push(t.objectExpression(properties))\n\t\t\t\t\t\t\t\tproperties = []\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (t.isJSXElement(node))\n\t\t\t\t\t\t\tfor (const attribute of node.openingElement.attributes) {\n\t\t\t\t\t\t\t\tif (t.isJSXSpreadAttribute(attribute)) {\n\t\t\t\t\t\t\t\t\tflush()\n\t\t\t\t\t\t\t\t\tchunks.push(t.arrowFunctionExpression([], attribute.argument))\n\t\t\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst key = t.isJSXNamespacedName(attribute.name)\n\t\t\t\t\t\t\t\t\t? `${attribute.name.namespace.name}:${attribute.name.name.name}`\n\t\t\t\t\t\t\t\t\t: attribute.name.name\n\t\t\t\t\t\t\t\tconst value =\n\t\t\t\t\t\t\t\t\tattribute.value == null\n\t\t\t\t\t\t\t\t\t\t? t.booleanLiteral(true)\n\t\t\t\t\t\t\t\t\t\t: t.isJSXExpressionContainer(attribute.value)\n\t\t\t\t\t\t\t\t\t\t\t? attribute.value.expression\n\t\t\t\t\t\t\t\t\t\t\t: attribute.value\n\t\t\t\t\t\t\t\t// The parser rejects empty attribute expressions.\n\t\t\t\t\t\t\t\tconst expression = value as t.Expression\n\t\t\t\t\t\t\t\tproperties.push(\n\t\t\t\t\t\t\t\t\tkey === `key` ||\n\t\t\t\t\t\t\t\t\t\tliteral(expression) ||\n\t\t\t\t\t\t\t\t\t\tt.isFunction(expression)\n\t\t\t\t\t\t\t\t\t\t? t.objectProperty(t.stringLiteral(key), expression)\n\t\t\t\t\t\t\t\t\t\t: t.objectMethod(\n\t\t\t\t\t\t\t\t\t\t\t\t`get`,\n\t\t\t\t\t\t\t\t\t\t\t\tt.stringLiteral(key),\n\t\t\t\t\t\t\t\t\t\t\t\t[],\n\t\t\t\t\t\t\t\t\t\t\t\tt.blockStatement([t.returnStatement(expression)]),\n\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\tconst children = t.react\n\t\t\t\t\t\t\t.buildChildren(node)\n\t\t\t\t\t\t\t.map((value) => child(value as t.Expression))\n\t\t\t\t\t\tif (children.length)\n\t\t\t\t\t\t\tproperties.push(\n\t\t\t\t\t\t\t\tt.objectProperty(\n\t\t\t\t\t\t\t\t\tt.identifier(`children`),\n\t\t\t\t\t\t\t\t\tchildren.length === 1\n\t\t\t\t\t\t\t\t\t\t? children[0]\n\t\t\t\t\t\t\t\t\t\t: t.arrayExpression(children),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\tflush()\n\t\t\t\t\t\tconst props =\n\t\t\t\t\t\t\tchunks.length > 1 || t.isArrowFunctionExpression(chunks[0])\n\t\t\t\t\t\t\t\t? t.callExpression(merge, chunks)\n\t\t\t\t\t\t\t\t: (chunks[0] ?? t.objectExpression([]))\n\t\t\t\t\t\tconst result = t.callExpression(create, [\n\t\t\t\t\t\t\tt.isJSXElement(node)\n\t\t\t\t\t\t\t\t? name(node.openingElement.name)\n\t\t\t\t\t\t\t\t: t.nullLiteral(),\n\t\t\t\t\t\t\tprops,\n\t\t\t\t\t\t])\n\t\t\t\t\t\tgenerated.add(result)\n\t\t\t\t\t\tlet fn = path.findParent((parent: any) => parent.isFunction())\n\t\t\t\t\t\twhile (fn?.findParent((parent: any) => parent.isFunction()))\n\t\t\t\t\t\t\tfn = fn.findParent((parent: any) => parent.isFunction())\n\t\t\t\t\t\tif (fn) {\n\t\t\t\t\t\t\tif (fn.isFunctionDeclaration() && fn.node.id)\n\t\t\t\t\t\t\t\tcomponents.add(fn.node.id.name)\n\t\t\t\t\t\t\telse if (\n\t\t\t\t\t\t\t\tfn.parentPath.isVariableDeclarator() &&\n\t\t\t\t\t\t\t\tt.isIdentifier(fn.parentPath.node.id)\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tcomponents.add(fn.parentPath.node.id.name)\n\t\t\t\t\t\t\telse if (\n\t\t\t\t\t\t\t\tfn.parentPath.isExportDefaultDeclaration() &&\n\t\t\t\t\t\t\t\tt.isFunctionDeclaration(fn.node)\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tfn.node.id = path.scope.generateUidIdentifier(`Component`)\n\t\t\t\t\t\t\t\tcomponents.add(fn.node.id.name)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tpath.replaceWith(result)\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t}\n\t}\n\tconst result = transformSync(code, {\n\t\tfilename,\n\t\tbabelrc: false,\n\t\tconfigFile: false,\n\t\tsourceMaps: true,\n\t\tparserOpts: { plugins: [`jsx`, `typescript`] },\n\t\tplugins: [plugin],\n\t})!\n\treturn { code: result.code!, map: result.map }\n}\n","import type { Plugin } from \"vite\"\n\nimport { compile } from \"./compiler.ts\"\n\nexport interface SpaPluginOptions {\n\tinclude?: RegExp\n}\nexport default function spa(options: SpaPluginOptions = {}): Plugin {\n\tconst include = options.include ?? /\\.[jt]sx$/\n\tconst matches = (id: string): boolean => {\n\t\tinclude.lastIndex = 0\n\t\treturn !id.includes(`/node_modules/`) && include.test(id.split(`?`)[0])\n\t}\n\treturn {\n\t\tname: `spa`,\n\t\tenforce: `pre`,\n\t\tconfig() {\n\t\t\treturn {\n\t\t\t\tresolve: { dedupe: [`@atom.io/spa`, `atom.io`] },\n\t\t\t\toptimizeDeps: { exclude: [`@atom.io/spa`, `atom.io`] },\n\t\t\t}\n\t\t},\n\t\tconfigEnvironment: {\n\t\t\torder: `post`,\n\t\t\thandler(_name, config) {\n\t\t\t\t// Astro and its adapters force renderer entries into the optimizer.\n\t\t\t\t// Vite processes explicit includes even when their package is excluded.\n\t\t\t\t// Keep the renderer, hooks, and store in one unbundled module graph.\n\t\t\t\tif (config.optimizeDeps?.include) {\n\t\t\t\t\tconfig.optimizeDeps.include = config.optimizeDeps.include.filter(\n\t\t\t\t\t\t(id) => !/^(@atom\\.io\\/spa|atom\\.io)(\\/|$)/.test(id),\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t\ttransform(code, id) {\n\t\t\tif (!matches(id)) return\n\t\t\treturn compile(code, id)\n\t\t},\n\t\t// A reload disposes the whole document. No state-preserving HMR is promised.\n\t\thandleHotUpdate({ server, file }) {\n\t\t\tif (matches(file)) {\n\t\t\t\tserver.ws.send({ type: `full-reload` })\n\t\t\t\treturn []\n\t\t\t}\n\t\t},\n\t}\n}\n"],"mappings":";;AAGA,SAAgB,QACf,MACA,UAC6B;CAC7B,MAAM,eAA6B;EAClC,IAAI;EACJ,IAAI;EACJ,MAAM,4BAAY,IAAI,QAAgB;EACtC,MAAM,6BAAa,IAAI,IAAY;EACnC,SAAS,KACR,MACe;GACf,IAAIA,MAAE,sBAAsB,IAAI,GAC/B,OAAOA,MAAE,iBACRA,MAAE,gBAAgB,KAAK,MAAM,IAC1B,KAAK,OAAO,SAAS,SACpBA,MAAE,eAAe,IACjBA,MAAE,WAAW,KAAK,OAAO,IAAI,IAC9B,KAAK,KAAK,MAAM,GACnBA,MAAE,WAAW,KAAK,SAAS,IAAI,CAChC;GACD,IAAIA,MAAE,oBAAoB,IAAI,GAC7B,OAAOA,MAAE,cAAc,GAAG,KAAK,UAAU,KAAK,GAAG,KAAK,KAAK,MAAM;GAClE,OAAO,SAAS,KAAK,KAAK,IAAI,KAAK,KAAK,KAAK,SAAS,GAAG,IACtDA,MAAE,cAAc,KAAK,IAAI,IACzBA,MAAE,WAAW,KAAK,IAAI;EAC1B;EACA,SAAS,QAAQ,MAAuB;GACvC,OACCA,MAAE,UAAU,I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;EACD;EACA,mBAAmB;GAClB,OAAO;GACP,QAAQ,OAAO,QAAQ;IAItB,IAAI,OAAO,cAAc,SACxB,OAAO,aAAa,UAAU,OAAO,aAAa,QAAQ,QACxD,OAAO,CAAC,mCAAmC,KAAK,EAAE,CACpD;GAEF;EACD;EACA,UAAU,MAAM,IAAI;GACnB,IAAI,CAAC,QAAQ,EAAE,GAAG;GAClB,OAAO,QAAQ,MAAM,EAAE;EACxB;EAEA,gBAAgB,EAAE,QAAQ,QAAQ;GACjC,IAAI,QAAQ,IAAI,GAAG;IAClB,OAAO,GAAG,KAAK,EAAE,MAAM,cAAc,CAAC;IACtC,OAAO,CAAC;GACT;EACD;CACD;AACD"}
package/dist/vite.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { Plugin } from "vite";
2
+ export interface SpaPluginOptions {
3
+ include?: RegExp;
4
+ }
5
+ export default function spa(options?: SpaPluginOptions): Plugin;
6
+ //# sourceMappingURL=vite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite.d.ts","names":[],"sources":["../src/vite.ts"],"mappings":";iBAIiB;EAChB,UAAU;;wBAEa,IAAI,UAAS,mBAAwB"}
package/dist/vite.js ADDED
@@ -0,0 +1 @@
1
+ export { t as default } from "./vite-CQchIQ_-.js";
package/package.json CHANGED
@@ -1,6 +1,132 @@
1
1
  {
2
2
  "name": "@atom.io/spa",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.0.1",
4
+ "description": "An atom.io-driven JSX renderer.",
5
+ "homepage": "https://atom.io.fyi/docs/spa",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/jeremybanka/atom.io.git",
9
+ "directory": "packages/spa"
10
+ },
11
+ "license": "MPL-2.0",
12
+ "author": "Jeremy Banka",
13
+ "sideEffects": false,
14
+ "type": "module",
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/index.d.ts",
18
+ "development": "./dist/development/index.js",
19
+ "import": "./dist/index.js"
20
+ },
21
+ "./jsx-runtime": {
22
+ "types": "./dist/jsx-runtime.d.ts",
23
+ "development": "./dist/development/jsx-runtime.js",
24
+ "import": "./dist/jsx-runtime.js"
25
+ },
26
+ "./jsx-dev-runtime": {
27
+ "types": "./dist/jsx-runtime.d.ts",
28
+ "development": "./dist/development/jsx-runtime.js",
29
+ "import": "./dist/jsx-runtime.js"
30
+ },
31
+ "./server": {
32
+ "types": "./dist/server.d.ts",
33
+ "development": "./dist/development/server.js",
34
+ "import": "./dist/server.js"
35
+ },
36
+ "./vite": {
37
+ "types": "./dist/vite.d.ts",
38
+ "development": "./dist/development/vite.js",
39
+ "import": "./dist/vite.js"
40
+ },
41
+ "./astro": {
42
+ "types": "./dist/astro.d.ts",
43
+ "development": "./dist/development/astro.js",
44
+ "import": "./dist/astro.js"
45
+ },
46
+ "./astro-client": {
47
+ "types": "./dist/astro-client.d.ts",
48
+ "development": "./dist/development/astro-client.js",
49
+ "import": "./dist/astro-client.js"
50
+ },
51
+ "./astro-server": {
52
+ "types": "./dist/astro-server.d.ts",
53
+ "development": "./dist/development/astro-server.js",
54
+ "import": "./dist/astro-server.js"
55
+ },
56
+ "./package.json": "./package.json",
57
+ "./astro-middleware": {
58
+ "types": "./dist/astro-middleware.d.ts",
59
+ "development": "./dist/development/astro-middleware.js",
60
+ "import": "./dist/astro-middleware.js"
61
+ },
62
+ "./astro-application": {
63
+ "types": "./dist/astro-application.d.ts",
64
+ "development": "./dist/development/astro-application.js",
65
+ "import": "./dist/astro-application.js"
66
+ }
67
+ },
68
+ "main": "./dist/index.js",
69
+ "types": "./dist/index.d.ts",
70
+ "files": [
71
+ "dist",
72
+ "src"
73
+ ],
74
+ "dependencies": {
75
+ "@babel/core": "8.0.10"
76
+ },
77
+ "devDependencies": {
78
+ "@breakage/changesets": "0.1.0",
79
+ "@types/babel__core": "7.20.5",
80
+ "@types/node": "26.6.6",
81
+ "@vitest/coverage-v8": "5.0.5",
82
+ "astro": "7.4.4",
83
+ "atom.io": "0.54.3",
84
+ "breakage": "0.10.1",
85
+ "esbuild": "0.28.2",
86
+ "eslint": "10.13.0",
87
+ "happy-dom": "21.0.4",
88
+ "playwright": "1.64.1",
89
+ "preact": "11.1.0",
90
+ "rolldown": "1.2.16",
91
+ "tsdown": "0.23.4",
92
+ "typescript": "7.0.2",
93
+ "vite": "8.3.5",
94
+ "vitest": "5.0.5"
95
+ },
96
+ "peerDependencies": {
97
+ "astro": "^7.4.2",
98
+ "atom.io": "^0.54.1",
99
+ "vite": "^8.3.5"
100
+ },
101
+ "peerDependenciesMeta": {
102
+ "astro": {
103
+ "optional": true
104
+ },
105
+ "vite": {
106
+ "optional": true
107
+ }
108
+ },
109
+ "publishConfig": {
110
+ "access": "public"
111
+ },
112
+ "scripts": {
113
+ "build": "tsdown && node scripts/size.ts",
114
+ "lint:eslint": "eslint",
115
+ "lint:oxlint": "oxlint",
116
+ "lint:types": "tsc -p tsconfig.json && tsc -p __tests__/fixtures/consumer/tsconfig.json",
117
+ "size": "node scripts/size.ts",
118
+ "pack:breakage": "pnpm --reporter=silent pack --out .breakage/package.tgz",
119
+ "test:breakage:peers": "breakage npm check",
120
+ "test": "vitest",
121
+ "test:once": "vitest run --config vitest.config.ts && pnpm test:consumer",
122
+ "test:consumer": "node __tests__/fixtures/consumer/check.ts",
123
+ "test:production": "node scripts/production-test.ts",
124
+ "test:browser": "astro build --root __tests__/astro && node scripts/browser-test.mjs && node scripts/dev-browser-test.mjs",
125
+ "test:browser:dev": "node scripts/dev-browser-test.mjs",
126
+ "cov": "vitest run --config vitest.config.ts --coverage",
127
+ "readme:write": "galley write README.mdx",
128
+ "readme:check": "galley check README.mdx",
129
+ "tonnage": "pnpm readme:write",
130
+ "tonnage:check": "pnpm readme:check"
131
+ }
6
132
  }
@@ -0,0 +1,71 @@
1
+ import type { ReadableToken } from "atom.io"
2
+ import { IMPLICIT, withdraw } from "atom.io/internal"
3
+
4
+ import { applicationContext } from "./astro-context.ts"
5
+
6
+ const applications = new WeakMap<
7
+ Document,
8
+ ReturnType<typeof applicationContext>
9
+ >()
10
+
11
+ /** Called by the integration's early page script, before island preparation. */
12
+ export function browserApplication(
13
+ document: Document,
14
+ ): ReturnType<typeof applicationContext> {
15
+ let application = applications.get(document)
16
+ if (application) return application
17
+ application = applicationContext()
18
+ const app = application
19
+ const store = IMPLICIT.STORE
20
+ const originalDefault = store.runDefault
21
+ applications.set(document, app)
22
+ const changed = () => {
23
+ app.canResume = false
24
+ }
25
+ const internal = (key: string) => key.startsWith(`🔍 spa islands`)
26
+ const subscriptions = new Map<string, () => void>()
27
+ const watch = (token: ReadableToken<unknown, any, any>) => {
28
+ if (internal(token.key)) return
29
+ if (store.valueMap.has(token.key)) changed()
30
+ subscriptions.get(token.key)?.()
31
+ const state = withdraw(store, token)
32
+ subscriptions.set(
33
+ token.key,
34
+ state.subject.subscribe(`spa:bootstrap`, changed),
35
+ )
36
+ }
37
+ for (const state of [
38
+ ...store.atoms.values(),
39
+ ...store.readonlySelectors.values(),
40
+ ...store.writableSelectors.values(),
41
+ ])
42
+ watch(state)
43
+ const removed = (token: ReadableToken<unknown, any, any>) => {
44
+ if (!internal(token.key)) {
45
+ changed()
46
+ subscriptions.get(token.key)?.()
47
+ subscriptions.delete(token.key)
48
+ }
49
+ }
50
+ const events = [
51
+ store.on.atomCreation.subscribe(`spa:bootstrap`, watch),
52
+ store.on.selectorCreation.subscribe(`spa:bootstrap`, watch),
53
+ store.on.atomDisposal.subscribe(`spa:bootstrap`, removed),
54
+ store.on.selectorDisposal.subscribe(`spa:bootstrap`, removed),
55
+ store.on.transactionCommit.subscribe(`spa:bootstrap`, changed),
56
+ ]
57
+ document.addEventListener(`astro:before-swap`, changed)
58
+ const pagehide = (event: PageTransitionEvent) => {
59
+ if (!event.persisted) app.dispose()
60
+ }
61
+ document.defaultView?.addEventListener(`pagehide`, pagehide)
62
+ app.onCleanup(() => {
63
+ for (const unsubscribe of subscriptions.values()) unsubscribe()
64
+ for (const unsubscribe of events) unsubscribe()
65
+ document.removeEventListener(`astro:before-swap`, changed)
66
+ document.defaultView?.removeEventListener(`pagehide`, pagehide)
67
+ store.runDefault = originalDefault
68
+ applications.delete(document)
69
+ })
70
+ return app
71
+ }