@farm.js/core 0.1.51-beta.2 → 0.1.51-beta.3

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 (183) hide show
  1. package/dist/{agent-mcp-handler-WWCC4GLG.mjs → agent-mcp-handler-7JSKGSOW.mjs} +4 -4
  2. package/dist/{agent-mcp-handler-RT3COCEL.cjs → agent-mcp-handler-YE4AGWHN.cjs} +5 -5
  3. package/dist/{agent-mcp.d-CR5Ov83o.d.ts → agent-mcp.d-BAR9njbJ.d.ts} +1 -1
  4. package/dist/{agent-mcp.d-Z5DuwrqW.d.mts → agent-mcp.d-BJKChOrO.d.mts} +1 -1
  5. package/dist/agent-runtime.d.mts +2 -2
  6. package/dist/agent-runtime.d.ts +2 -2
  7. package/dist/{analyzer-Z6TNEAET.mjs → analyzer-OTPEWH5W.mjs} +14 -3
  8. package/dist/{analyzer-T76CN3S7.cjs → analyzer-TSQXZCZN.cjs} +14 -3
  9. package/dist/api/route-manager.d.mts +4 -4
  10. package/dist/api/route-manager.d.ts +4 -4
  11. package/dist/api/runtime.d.mts +3 -3
  12. package/dist/api/runtime.d.ts +3 -3
  13. package/dist/api.d.mts +4 -4
  14. package/dist/api.d.ts +4 -4
  15. package/dist/{app-manifest.d-DiWr_Jfx.d.ts → app-manifest.d-BLFbaqx8.d.ts} +1 -1
  16. package/dist/{app-manifest.d-CAHkOBFa.d.mts → app-manifest.d-DEQNnNhV.d.mts} +1 -1
  17. package/dist/app-markdown.cjs +4 -4
  18. package/dist/app-markdown.d.mts +3 -3
  19. package/dist/app-markdown.d.ts +3 -3
  20. package/dist/app-markdown.mjs +3 -3
  21. package/dist/{app.d-DmapqkbV.d.ts → app.d-CNPaUYaa.d.ts} +4 -4
  22. package/dist/{app.d-BfgJCsTQ.d.mts → app.d-CT7xDkj2.d.mts} +4 -4
  23. package/dist/{chunk-YVJV7Q2X.mjs → chunk-3BLEXUGE.mjs} +1 -1
  24. package/dist/chunk-3HLQTOVU.cjs +6 -0
  25. package/dist/{chunk-E6LTONL4.mjs → chunk-3SMXQNFD.mjs} +2 -2
  26. package/dist/{chunk-PMKUU273.mjs → chunk-3TLKUBXG.mjs} +411 -166
  27. package/dist/{chunk-74Z5KX4A.mjs → chunk-3WSIYBMG.mjs} +41 -19
  28. package/dist/{chunk-GNJIYJMS.cjs → chunk-3XQ57EFI.cjs} +16 -16
  29. package/dist/{chunk-GW4YUIHW.mjs → chunk-3Z63X45F.mjs} +1 -1
  30. package/dist/{chunk-IBSAYAWB.mjs → chunk-4353ZRE5.mjs} +1 -1
  31. package/dist/{chunk-SBABQKPT.cjs → chunk-46KXZBOG.cjs} +5 -5
  32. package/dist/{chunk-YU42A5MA.cjs → chunk-4CGOMZP3.cjs} +221 -199
  33. package/dist/{chunk-J3LBO2O4.cjs → chunk-4SEHMBL4.cjs} +10 -10
  34. package/dist/{chunk-E73PGHSR.mjs → chunk-4TKAIO2F.mjs} +3 -3
  35. package/dist/{chunk-NJLTQR5P.cjs → chunk-53SACYBY.cjs} +7 -7
  36. package/dist/{chunk-FM2UEKS2.mjs → chunk-5FXPJIOT.mjs} +2 -2
  37. package/dist/{chunk-QXPSWMUD.cjs → chunk-7MD37P5V.cjs} +5 -5
  38. package/dist/{chunk-JATTVAHA.cjs → chunk-B3GM5I6N.cjs} +4 -4
  39. package/dist/{chunk-WJFFPXCV.cjs → chunk-D7UQC4O6.cjs} +10 -8
  40. package/dist/{chunk-KRRZJ77U.mjs → chunk-E5DXF5GE.mjs} +2 -2
  41. package/dist/chunk-EFZGB7JC.cjs +114 -0
  42. package/dist/{chunk-NYQSC4DX.cjs → chunk-FFE2EMF7.cjs} +5 -5
  43. package/dist/{chunk-CTM4SPB3.mjs → chunk-GAO7MS5O.mjs} +4 -3
  44. package/dist/{chunk-HIFIG6HL.cjs → chunk-H33PJEXN.cjs} +5 -5
  45. package/dist/{chunk-NXBHYO7S.cjs → chunk-HLWOWZFX.cjs} +2 -2
  46. package/dist/chunk-JXEPLIXD.cjs +389 -0
  47. package/dist/{chunk-NPQLMP7M.cjs → chunk-KLNFJDFM.cjs} +10 -9
  48. package/dist/{chunk-KBRZAYI7.mjs → chunk-LDNSSHEG.mjs} +2 -2
  49. package/dist/chunk-LLZSYFOM.mjs +6 -0
  50. package/dist/{chunk-N77JBPLC.mjs → chunk-LPDKG6RA.mjs} +9 -7
  51. package/dist/chunk-MIGFX2FN.mjs +758 -0
  52. package/dist/{chunk-72D2NX77.mjs → chunk-MRNDAJEV.mjs} +1 -1
  53. package/dist/{chunk-4SSRBCBR.mjs → chunk-NOTSHVRN.mjs} +355 -218
  54. package/dist/{chunk-GUJTVM36.cjs → chunk-OAMUSC7H.cjs} +1 -1
  55. package/dist/chunk-P6MHI5O2.cjs +758 -0
  56. package/dist/{chunk-6CYQQQGR.mjs → chunk-R4PHCZ3G.mjs} +1 -1
  57. package/dist/{chunk-WZW6LEHM.cjs → chunk-TQMI6BYO.cjs} +675 -430
  58. package/dist/{chunk-76GHW3WI.cjs → chunk-TSFMFPRU.cjs} +4 -4
  59. package/dist/{chunk-5N7QAGEA.cjs → chunk-TWHXBMLJ.cjs} +37 -7
  60. package/dist/{chunk-BOVGCUDZ.cjs → chunk-UJL4JOXV.cjs} +2 -2
  61. package/dist/chunk-UQF3OJVE.mjs +389 -0
  62. package/dist/{chunk-DTU4PX7V.cjs → chunk-WGUHDWT5.cjs} +557 -420
  63. package/dist/{chunk-LAZK6UV7.mjs → chunk-YAJTD3ZG.mjs} +1 -1
  64. package/dist/{chunk-7UPCJDB5.mjs → chunk-YUEYBL35.mjs} +2 -2
  65. package/dist/{chunk-EIMK7D2D.mjs → chunk-ZD2VKAUI.mjs} +34 -4
  66. package/dist/chunk-ZNXTU4YH.mjs +114 -0
  67. package/dist/{client-plugins.d-Bx3FXpqm.d.mts → client-plugins.d-DllmH8eM.d.mts} +17 -4
  68. package/dist/{client-plugins.d-TiLbS5j4.d.ts → client-plugins.d-n3iWY1EJ.d.ts} +17 -4
  69. package/dist/client-plugins.d.mts +2 -2
  70. package/dist/client-plugins.d.ts +2 -2
  71. package/dist/client.d.mts +7 -7
  72. package/dist/client.d.ts +7 -7
  73. package/dist/{config.d-iRPI16ku.d.ts → config.d-DqKaCr1r.d.mts} +8 -1
  74. package/dist/{config.d-iRPI16ku.d.mts → config.d-DqKaCr1r.d.ts} +8 -1
  75. package/dist/config.d.mts +2 -2
  76. package/dist/config.d.ts +2 -2
  77. package/dist/desktop.d.mts +3 -3
  78. package/dist/desktop.d.ts +3 -3
  79. package/dist/{devtools-6XWCZIGO.cjs → devtools-TO6TAO32.cjs} +5 -5
  80. package/dist/{devtools-UQLDAOEI.mjs → devtools-UESYARTF.mjs} +4 -4
  81. package/dist/docs.cjs +7 -7
  82. package/dist/docs.d.mts +3 -3
  83. package/dist/docs.d.ts +3 -3
  84. package/dist/docs.mjs +6 -6
  85. package/dist/index.cjs +22 -18
  86. package/dist/{index.d-YxJ2AiDF.d.mts → index.d-BL7KKiwa.d.mts} +1 -1
  87. package/dist/{index.d-yueUNipJ.d.ts → index.d-BXsAXm1U.d.ts} +1 -1
  88. package/dist/index.d.mts +17 -17
  89. package/dist/index.d.ts +17 -17
  90. package/dist/index.mjs +22 -18
  91. package/dist/integrations.d.mts +2 -2
  92. package/dist/integrations.d.ts +2 -2
  93. package/dist/internal/app-markdown-runtime.cjs +3 -3
  94. package/dist/internal/app-markdown-runtime.d.mts +3 -3
  95. package/dist/internal/app-markdown-runtime.d.ts +3 -3
  96. package/dist/internal/app-markdown-runtime.mjs +2 -2
  97. package/dist/internal/build-runtime.cjs +20 -18
  98. package/dist/internal/build-runtime.d.mts +4 -4
  99. package/dist/internal/build-runtime.d.ts +4 -4
  100. package/dist/internal/build-runtime.mjs +19 -17
  101. package/dist/internal/cli-runtime.cjs +7 -7
  102. package/dist/internal/cli-runtime.mjs +6 -6
  103. package/dist/internal/client-error-overlay.cjs +4 -4
  104. package/dist/internal/client-error-overlay.mjs +1 -1
  105. package/dist/internal/client-runtime.d.mts +5 -5
  106. package/dist/internal/client-runtime.d.ts +5 -5
  107. package/dist/internal/compression-runtime.d.mts +2 -2
  108. package/dist/internal/compression-runtime.d.ts +2 -2
  109. package/dist/internal/config-runtime.cjs +6 -6
  110. package/dist/internal/config-runtime.d.mts +31 -7
  111. package/dist/internal/config-runtime.d.ts +31 -7
  112. package/dist/internal/config-runtime.mjs +5 -5
  113. package/dist/internal/infra-analytics-runtime.cjs +8 -8
  114. package/dist/internal/infra-analytics-runtime.mjs +6 -6
  115. package/dist/internal/product-telemetry-runtime.cjs +2 -2
  116. package/dist/internal/product-telemetry-runtime.mjs +1 -1
  117. package/dist/internal/production-runtime.cjs +87 -9
  118. package/dist/internal/production-runtime.d.mts +44 -12
  119. package/dist/internal/production-runtime.d.ts +44 -12
  120. package/dist/internal/production-runtime.mjs +86 -8
  121. package/dist/markdown.cjs +4 -2
  122. package/dist/markdown.d.mts +2 -2
  123. package/dist/markdown.d.ts +2 -2
  124. package/dist/markdown.mjs +3 -1
  125. package/dist/middleware.d.mts +4 -4
  126. package/dist/middleware.d.ts +4 -4
  127. package/dist/mobile.d.mts +21 -5
  128. package/dist/mobile.d.ts +21 -5
  129. package/dist/native-tree-EBPDFTRW.mjs +25 -0
  130. package/dist/native-tree-MMZS7S6W.cjs +25 -0
  131. package/dist/{navigation-delegate.d-HnDXhlyP.d.mts → navigation-delegate.d-C76gXTmO.d.mts} +1 -1
  132. package/dist/{navigation-delegate.d-BY1e_Xrh.d.ts → navigation-delegate.d-DIyDslxt.d.ts} +1 -1
  133. package/dist/navigation.d.mts +5 -5
  134. package/dist/navigation.d.ts +5 -5
  135. package/dist/plugin.cjs +14 -13
  136. package/dist/plugin.d.mts +5 -4
  137. package/dist/plugin.d.ts +5 -4
  138. package/dist/plugin.mjs +13 -12
  139. package/dist/{production-runtime.d-BpJUDzP8.d.mts → production-runtime.d-CDHztggO.d.mts} +1 -1
  140. package/dist/{production-runtime.d-lMjvE9cf.d.ts → production-runtime.d-tyaGdbk6.d.ts} +1 -1
  141. package/dist/{programmatic-routes-client.d-BlFp5hv4.d.ts → programmatic-routes-client.d-XfmIrCK1.d.ts} +2 -2
  142. package/dist/{programmatic-routes-client.d-6CGQ3TCk.d.mts → programmatic-routes-client.d-aAWiDd64.d.mts} +2 -2
  143. package/dist/{render-plan.d-BH9edqKs.d.mts → render-plan.d-Diwybxo8.d.mts} +1 -1
  144. package/dist/{render-plan.d-DhP0mTHF.d.ts → render-plan.d-Dr5WRjoV.d.ts} +1 -1
  145. package/dist/renderer-client.d.mts +5 -5
  146. package/dist/renderer-client.d.ts +5 -5
  147. package/dist/{request.d-BVZrsR1v.d.ts → request.d-D01fRn--.d.ts} +1 -1
  148. package/dist/{request.d-DJFRdKi8.d.mts → request.d-Dd3AFR79.d.mts} +1 -1
  149. package/dist/request.d.mts +3 -3
  150. package/dist/request.d.ts +3 -3
  151. package/dist/{route-rendering.d-Bpmw7PED.d.mts → route-rendering.d-BQ53lJ_D.d.mts} +1 -1
  152. package/dist/{route-rendering.d-B00JtK_-.d.ts → route-rendering.d-Bhx4QoJt.d.ts} +1 -1
  153. package/dist/{router.d-e0jQ3jQ-.d.mts → router.d-Bi23a6Xc.d.mts} +1 -1
  154. package/dist/{router.d-Bd1x9XxQ.d.ts → router.d-DQ3k7EYn.d.ts} +1 -1
  155. package/dist/{routes.d-Cmv8TgVq.d.mts → routes.d-BgTd7vI4.d.mts} +3 -3
  156. package/dist/{routes.d-D96Dq9lz.d.ts → routes.d-C7jMJFvP.d.ts} +3 -3
  157. package/dist/routes.d.mts +2 -2
  158. package/dist/routes.d.ts +2 -2
  159. package/dist/{rsc-pipeline-ZQ4CTVEG.mjs → rsc-pipeline-K3ER3Q4N.mjs} +5 -5
  160. package/dist/{rsc-pipeline-DX4OC5FN.cjs → rsc-pipeline-OCZIT5OF.cjs} +6 -6
  161. package/dist/{runtime-NQ3EDSA7.cjs → runtime-DKNSIH7V.cjs} +30 -23
  162. package/dist/{runtime-NPDRDV6R.mjs → runtime-MKYDEUZT.mjs} +20 -13
  163. package/dist/{runtime.d-CgB3IJDq.d.mts → runtime.d-B2Js6qZ2.d.mts} +1 -1
  164. package/dist/{runtime.d-D-td-RR3.d.ts → runtime.d-BL-CGwoi.d.ts} +1 -1
  165. package/dist/server-plugins.d.mts +3 -3
  166. package/dist/server-plugins.d.ts +3 -3
  167. package/dist/server.cjs +31 -30
  168. package/dist/server.d.mts +11 -10
  169. package/dist/server.d.ts +11 -10
  170. package/dist/server.mjs +16 -15
  171. package/dist/{spa-router.d-BWDhS0FK.d.mts → spa-router.d-B2rIFGs0.d.mts} +2 -2
  172. package/dist/{spa-router.d-CO01mVOM.d.ts → spa-router.d-DqZ6Lfs0.d.ts} +2 -2
  173. package/dist/testing.d.mts +2 -2
  174. package/dist/testing.d.ts +2 -2
  175. package/dist/{utils.d-B77__yh8.d.ts → utils.d-Bv2MPeLR.d.ts} +1 -1
  176. package/dist/{utils.d-DRDazhCA.d.mts → utils.d-fqXe8lNc.d.mts} +1 -1
  177. package/dist/version.cjs +2 -2
  178. package/dist/version.mjs +1 -1
  179. package/dist/vite.cjs +14 -13
  180. package/dist/vite.d.mts +12 -6
  181. package/dist/vite.d.ts +12 -6
  182. package/dist/vite.mjs +13 -12
  183. package/package.json +1 -1
@@ -3,7 +3,7 @@
3
3
  var _chunkOWOUTKIJcjs = require('./chunk-OWOUTKIJ.cjs');
4
4
 
5
5
 
6
- var _chunkHIFIG6HLcjs = require('./chunk-HIFIG6HL.cjs');
6
+ var _chunkH33PJEXNcjs = require('./chunk-H33PJEXN.cjs');
7
7
 
8
8
 
9
9
  var _chunk6JHZPB52cjs = require('./chunk-6JHZPB52.cjs');
@@ -12,7 +12,7 @@ var _chunk6JHZPB52cjs = require('./chunk-6JHZPB52.cjs');
12
12
  var _chunkWT6RAN2Icjs = require('./chunk-WT6RAN2I.cjs');
13
13
 
14
14
 
15
- var _chunkWJFFPXCVcjs = require('./chunk-WJFFPXCV.cjs');
15
+ var _chunkD7UQC4O6cjs = require('./chunk-D7UQC4O6.cjs');
16
16
 
17
17
 
18
18
  var _chunkPFV2KPDZcjs = require('./chunk-PFV2KPDZ.cjs');
@@ -603,12 +603,12 @@ function createFarmMetadataRouteResponse(kind, value, routeModule = {}, options
603
603
  return new Response(null, { status: 405, headers: { Allow: "GET, HEAD" } });
604
604
  }
605
605
  if ((kind === "llms" || kind === "llms-full") && options.request) {
606
- _chunkWJFFPXCVcjs.emitFarmAgentRead.call(void 0, options.request, kind, isResponse(value) ? value.status : 200);
606
+ _chunkD7UQC4O6cjs.emitFarmAgentRead.call(void 0, options.request, kind, isResponse(value) ? value.status : 200);
607
607
  }
608
608
  if (isResponse(value)) {
609
609
  return method === "HEAD" ? _chunk4DCWVSL2cjs.omitFarmResponseBody.call(void 0, value) : value;
610
610
  }
611
- const body = kind === "sitemap" ? serializeSitemap(value) : kind === "robots" ? serializeRobots(value) : kind === "llms" || kind === "llms-full" ? _chunkHIFIG6HLcjs.serializeFarmLlmsTxt.call(void 0, value) : serializeManifest(value);
611
+ const body = kind === "sitemap" ? serializeSitemap(value) : kind === "robots" ? serializeRobots(value) : kind === "llms" || kind === "llms-full" ? _chunkH33PJEXNcjs.serializeFarmLlmsTxt.call(void 0, value) : serializeManifest(value);
612
612
  const contentType = kind === "sitemap" ? "application/xml; charset=utf-8" : kind === "robots" || kind === "llms" || kind === "llms-full" ? "text/plain; charset=utf-8" : "application/manifest+json; charset=utf-8";
613
613
  return new Response(method === "HEAD" ? null : body, {
614
614
  headers: {
@@ -18,7 +18,7 @@ var _chunkERMUL73Lcjs = require('./chunk-ERMUL73L.cjs');
18
18
  var _chunk6JHZPB52cjs = require('./chunk-6JHZPB52.cjs');
19
19
 
20
20
 
21
- var _chunkWJFFPXCVcjs = require('./chunk-WJFFPXCV.cjs');
21
+ var _chunkD7UQC4O6cjs = require('./chunk-D7UQC4O6.cjs');
22
22
 
23
23
 
24
24
  var _chunkLIFUPCXWcjs = require('./chunk-LIFUPCXW.cjs');
@@ -758,6 +758,23 @@ function titleFromMarkdown(body, fallback) {
758
758
  const heading = _optionalChain([body, 'access', _46 => _46.match, 'call', _47 => _47(/^#\s+(.+)$/m), 'optionalAccess', _48 => _48[1], 'optionalAccess', _49 => _49.trim, 'call', _50 => _50()]);
759
759
  return heading || fallback;
760
760
  }
761
+ function createLastModifiedResolver(contentDir, sourcePath, frontmatter) {
762
+ let resolved = false;
763
+ let value;
764
+ return {
765
+ get() {
766
+ if (!resolved) {
767
+ value = resolveFarmDocsPageLastModified(contentDir, sourcePath, frontmatter);
768
+ resolved = true;
769
+ }
770
+ return value;
771
+ },
772
+ set(next) {
773
+ value = next;
774
+ resolved = true;
775
+ }
776
+ };
777
+ }
761
778
  function loadFarmDocsPage(contentDir, docs, slug) {
762
779
  const sourcePath = findDocsPageFile(contentDir, slug);
763
780
  if (!sourcePath) return null;
@@ -765,6 +782,7 @@ function loadFarmDocsPage(contentDir, docs, slug) {
765
782
  const { frontmatter, body } = parseFrontmatter(source);
766
783
  const title = frontmatter.title || titleFromMarkdown(body, titleFromSlug(slug));
767
784
  const href = createDocsHref(docs.entry, slug);
785
+ const lastModified = createLastModifiedResolver(contentDir, sourcePath, frontmatter);
768
786
  return {
769
787
  slug,
770
788
  title,
@@ -772,7 +790,12 @@ function loadFarmDocsPage(contentDir, docs, slug) {
772
790
  section: frontmatter.section,
773
791
  href,
774
792
  sourcePath,
775
- lastModified: resolveFarmDocsPageLastModified(contentDir, sourcePath, frontmatter),
793
+ get lastModified() {
794
+ return lastModified.get();
795
+ },
796
+ set lastModified(value) {
797
+ lastModified.set(value);
798
+ },
776
799
  frontmatter,
777
800
  body
778
801
  };
@@ -817,6 +840,7 @@ function discoverFarmDocsPages(contentDir, docs) {
817
840
  if (slug === null) continue;
818
841
  const source = _fs.readFileSync.call(void 0, absolutePath, "utf8");
819
842
  const { frontmatter, body } = parseFrontmatter(source);
843
+ const lastModified = createLastModifiedResolver(contentDir, absolutePath, frontmatter);
820
844
  pages.push({
821
845
  slug,
822
846
  title: frontmatter.title || titleFromMarkdown(body, titleFromSlug(slug)),
@@ -824,7 +848,12 @@ function discoverFarmDocsPages(contentDir, docs) {
824
848
  section: frontmatter.section,
825
849
  href: createDocsHref(docs.entry, slug),
826
850
  sourcePath: absolutePath,
827
- lastModified: resolveFarmDocsPageLastModified(contentDir, absolutePath, frontmatter)
851
+ get lastModified() {
852
+ return lastModified.get();
853
+ },
854
+ set lastModified(value) {
855
+ lastModified.set(value);
856
+ }
828
857
  });
829
858
  }
830
859
  };
@@ -901,8 +930,9 @@ function formatLastModifiedDate(value) {
901
930
  }
902
931
  function renderLastUpdatedText(page, docs, position) {
903
932
  const config = resolveLastUpdatedDisplayConfig(docs);
933
+ if (!config.enabled || config.position !== position) return "";
904
934
  const formatted = formatLastModifiedDate(page.lastModified);
905
- if (!config.enabled || config.position !== position || !formatted) return "";
935
+ if (!formatted) return "";
906
936
  const time = `<time datetime="${escapeAttribute(page.lastModified || "")}">${escapeHtml(formatted)}</time>`;
907
937
  const label = config.label.trim();
908
938
  return label ? `${escapeHtml(label)} ${time}` : time;
@@ -1149,11 +1179,11 @@ function shouldReturnMarkdown(request) {
1149
1179
  if (url.pathname.endsWith(".md")) return true;
1150
1180
  const accept = request.headers.get("accept");
1151
1181
  const markdown = Math.max(
1152
- _chunkWJFFPXCVcjs.farmAcceptQuality.call(void 0, accept, "text/markdown"),
1153
- _chunkWJFFPXCVcjs.farmAcceptQuality.call(void 0, accept, "text/plain")
1182
+ _chunkD7UQC4O6cjs.farmAcceptQuality.call(void 0, accept, "text/markdown"),
1183
+ _chunkD7UQC4O6cjs.farmAcceptQuality.call(void 0, accept, "text/plain")
1154
1184
  );
1155
1185
  if (markdown <= 0) return false;
1156
- return markdown >= _chunkWJFFPXCVcjs.farmAcceptQuality.call(void 0, accept, "text/html", { wildcards: true });
1186
+ return markdown >= _chunkD7UQC4O6cjs.farmAcceptQuality.call(void 0, accept, "text/html", { wildcards: true });
1157
1187
  }
1158
1188
  function escapeAttribute(value) {
1159
1189
  return escapeHtml(value).replace(/'/g, "&#39;");
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
- var _chunkJATTVAHAcjs = require('./chunk-JATTVAHA.cjs');
3
+ var _chunkB3GM5I6Ncjs = require('./chunk-B3GM5I6N.cjs');
4
4
 
5
5
  // src/app-markdown.ts
6
6
  var _promises = require('fs/promises');
@@ -8,7 +8,7 @@ var _path = require('path'); var _path2 = _interopRequireDefault(_path);
8
8
  var _url = require('url');
9
9
  async function createFarmMarkdownRouteModuleFromFile(filePath, options = {}) {
10
10
  const source = await _promises.readFile.call(void 0, filePath, "utf8");
11
- return _chunkJATTVAHAcjs.createFarmMarkdownRouteModule.call(void 0, {
11
+ return _chunkB3GM5I6Ncjs.createFarmMarkdownRouteModule.call(void 0, {
12
12
  source,
13
13
  filePath,
14
14
  components: options.components,
@@ -0,0 +1,389 @@
1
+ import {
2
+ FARM_NATIVE_TEXT_KEYS,
3
+ resolveFarmNativeClasses,
4
+ resolveFarmNativeInlineStyle
5
+ } from "./chunk-MIGFX2FN.mjs";
6
+ import {
7
+ FARM_NATIVE_TREE_CONTENT_TYPE
8
+ } from "./chunk-LLZSYFOM.mjs";
9
+ import {
10
+ _readFarmRenderedHtml
11
+ } from "./chunk-LPDKG6RA.mjs";
12
+
13
+ // src/mobile/native-tree.ts
14
+ var VIEW_TAGS = new Set(
15
+ "div section main article header footer nav aside figure ul ol li hr".split(" ")
16
+ );
17
+ var BLOCK_TEXT_TAGS = new Set("p h1 h2 h3 h4 h5 h6".split(" "));
18
+ var INLINE_TAGS = new Set("span strong em b i small label code br a".split(" "));
19
+ var VOID_TAGS = new Set(
20
+ "area base br col embed hr img input link meta source track wbr".split(" ")
21
+ );
22
+ var SKIPPED_TAGS = new Set("link meta template title".split(" "));
23
+ var INLINE_DEFAULTS = {
24
+ strong: { fontWeight: 700 },
25
+ b: { fontWeight: 700 },
26
+ em: { fontStyle: "italic" },
27
+ i: { fontStyle: "italic" },
28
+ code: { fontFamily: "mono" }
29
+ };
30
+ var ENTITIES = {
31
+ amp: "&",
32
+ lt: "<",
33
+ gt: ">",
34
+ quot: '"',
35
+ apos: "'",
36
+ nbsp: "\xA0"
37
+ };
38
+ function decode(text) {
39
+ return text.replace(/&(#x[0-9a-f]+|#\d+|[a-z]+);/gi, (entity, name) => {
40
+ if (name[0] === "#") {
41
+ const code = name[1] === "x" || name[1] === "X" ? parseInt(name.slice(2), 16) : Number(name.slice(1));
42
+ return Number.isFinite(code) ? String.fromCodePoint(code) : entity;
43
+ }
44
+ return ENTITIES[name.toLowerCase()] ?? entity;
45
+ });
46
+ }
47
+ function parseHtml(html) {
48
+ const root = { tag: "#root", attributes: {}, children: [] };
49
+ const stack = [root];
50
+ const tag = /<(\/?)([a-zA-Z][\w:-]*)((?:[^>"']|"[^"]*"|'[^']*')*?)(\/?)>/g;
51
+ let cursor = 0;
52
+ let match;
53
+ while (match = tag.exec(html)) {
54
+ if (match.index > cursor) stack.at(-1).children.push(decode(html.slice(cursor, match.index)));
55
+ cursor = tag.lastIndex;
56
+ const name = match[2].toLowerCase();
57
+ if (match[1]) {
58
+ let open = stack.length - 1;
59
+ while (open > 0 && stack[open].tag !== name) open -= 1;
60
+ if (open > 0) stack.length = open;
61
+ continue;
62
+ }
63
+ const attributes = {};
64
+ for (const attribute of match[3].matchAll(
65
+ /([^\s=/]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'>]+)))?/g
66
+ )) {
67
+ attributes[attribute[1].toLowerCase()] = decode(
68
+ attribute[2] ?? attribute[3] ?? attribute[4] ?? ""
69
+ );
70
+ }
71
+ const element = { tag: name, attributes, children: [] };
72
+ stack.at(-1).children.push(element);
73
+ if (!match[4] && !VOID_TAGS.has(name)) stack.push(element);
74
+ }
75
+ if (cursor < html.length) stack.at(-1).children.push(decode(html.slice(cursor)));
76
+ return root;
77
+ }
78
+ function find(element, test) {
79
+ if (test(element)) return element;
80
+ for (const child of element.children) {
81
+ if (typeof child === "string") continue;
82
+ const found = find(child, test);
83
+ if (found) return found;
84
+ }
85
+ return void 0;
86
+ }
87
+ function textOnly(style) {
88
+ return Object.fromEntries(
89
+ Object.entries(style).filter(([key]) => FARM_NATIVE_TEXT_KEYS.has(key))
90
+ );
91
+ }
92
+ function withoutText(style) {
93
+ const rest = Object.entries(style).filter(([key]) => !FARM_NATIVE_TEXT_KEYS.has(key));
94
+ return rest.length > 0 ? Object.fromEntries(rest) : void 0;
95
+ }
96
+ function settleLineHeight(style) {
97
+ const { lineHeightScale, lineHeightPx, ...rest } = style;
98
+ if (lineHeightPx !== void 0) rest.lineHeight = lineHeightPx;
99
+ else if (typeof lineHeightScale === "number") {
100
+ rest.lineHeight = Math.round(lineHeightScale * Number(rest.fontSize ?? 16) * 100) / 100;
101
+ }
102
+ return rest;
103
+ }
104
+ var Converter = class {
105
+ constructor(pageUrl) {
106
+ this.pageUrl = pageUrl;
107
+ this.unsupported = [];
108
+ }
109
+ problem(message) {
110
+ if (!this.unsupported.includes(message)) this.unsupported.push(message);
111
+ }
112
+ stylesOf(element) {
113
+ const classes = resolveFarmNativeClasses(element.attributes.class ?? "");
114
+ for (const token of classes.unsupported) this.problem(`<${element.tag}> class "${token}"`);
115
+ const inline = resolveFarmNativeInlineStyle(element.attributes.style ?? "");
116
+ for (const declaration of inline.unsupported) {
117
+ this.problem(`<${element.tag}> style "${declaration}"`);
118
+ }
119
+ return {
120
+ style: { ...INLINE_DEFAULTS[element.tag], ...classes.style, ...inline.style },
121
+ dark: classes.dark ?? {}
122
+ };
123
+ }
124
+ url(value) {
125
+ if (!value) return void 0;
126
+ try {
127
+ return new URL(value, this.pageUrl).href;
128
+ } catch {
129
+ this.problem(`URL "${value}"`);
130
+ return void 0;
131
+ }
132
+ }
133
+ node(type, element, style, dark) {
134
+ return {
135
+ type,
136
+ tag: element.tag,
137
+ ...style && Object.keys(style).length > 0 ? { style } : {},
138
+ ...dark && Object.keys(dark).length > 0 ? { dark } : {}
139
+ };
140
+ }
141
+ /** Inline content: runs of text, nested inline elements, and line breaks. */
142
+ inline(content, inherited) {
143
+ const runs = [];
144
+ for (const child of content) {
145
+ if (typeof child === "string") {
146
+ runs.push(child);
147
+ continue;
148
+ }
149
+ if (SKIPPED_TAGS.has(child.tag)) continue;
150
+ if (child.tag === "br") {
151
+ runs.push("\n");
152
+ continue;
153
+ }
154
+ if (!INLINE_TAGS.has(child.tag)) {
155
+ this.problem(`<${child.tag}> inside text`);
156
+ continue;
157
+ }
158
+ const own = this.stylesOf(child);
159
+ if (own.style.display === "none") continue;
160
+ const run = this.node(
161
+ "Text",
162
+ child,
163
+ settleLineHeight(textOnly(own.style)),
164
+ textOnly(own.dark)
165
+ );
166
+ if (withoutText(own.style)) this.problem(`<${child.tag}> inside text has box styles`);
167
+ if (child.tag === "a") run.href = this.url(child.attributes.href);
168
+ const children = this.inline(child.children, inherited);
169
+ if (children.length > 0) run.children = children;
170
+ runs.push(run);
171
+ }
172
+ return runs;
173
+ }
174
+ /** A text block: its runs, with the text style its ancestors pass down. */
175
+ text(element, content, inherited, box) {
176
+ const runs = this.inline(content, inherited);
177
+ const trimmed = collapse(runs);
178
+ if (trimmed.length === 0) return void 0;
179
+ const style = settleLineHeight({ ...inherited.style, ...box?.style });
180
+ const dark = { ...inherited.dark, ...box?.dark };
181
+ const node = this.node("Text", element, style, dark);
182
+ node.children = trimmed;
183
+ return node;
184
+ }
185
+ /**
186
+ * Block content: each element a view, and each run of inline content a text block. In a flex
187
+ * container every child is its own item, as CSS blockifies them: a `<span>` pill there is a box.
188
+ */
189
+ blocks(content, inherited, flex = false) {
190
+ if (flex) {
191
+ const items = [];
192
+ for (const child of content) {
193
+ const item = typeof child === "string" ? this.text({ tag: "#text", attributes: {}, children: [] }, [child], inherited) : this.element(child, inherited, true);
194
+ if (item) items.push(item);
195
+ }
196
+ return items;
197
+ }
198
+ const nodes = [];
199
+ let pending = [];
200
+ const flush = () => {
201
+ const block = this.text({ tag: "#text", attributes: {}, children: [] }, pending, inherited);
202
+ if (block) nodes.push(block);
203
+ pending = [];
204
+ };
205
+ for (const child of content) {
206
+ if (typeof child === "string" || INLINE_TAGS.has(child.tag) && !isBlockLink(child)) {
207
+ pending.push(child);
208
+ continue;
209
+ }
210
+ flush();
211
+ const node = this.element(child, inherited);
212
+ if (node) nodes.push(node);
213
+ }
214
+ flush();
215
+ return nodes;
216
+ }
217
+ element(element, inherited, flexItem = false) {
218
+ if (SKIPPED_TAGS.has(element.tag)) return void 0;
219
+ const own = this.stylesOf(element);
220
+ if (own.style.display === "none") return void 0;
221
+ const passed = {
222
+ style: { ...inherited.style, ...textOnly(own.style) },
223
+ dark: { ...inherited.dark, ...textOnly(own.dark) }
224
+ };
225
+ const current = (style, color) => style && Object.fromEntries(
226
+ Object.entries(style).map(([key, value]) => [
227
+ key,
228
+ value === "currentColor" && typeof color === "string" ? color : value
229
+ ])
230
+ );
231
+ const box = current(withoutText(own.style), passed.style.color);
232
+ const boxDark = current(withoutText(own.dark), passed.dark.color ?? passed.style.color);
233
+ const flex = own.style.display === "flex";
234
+ const textBox = flexItem && INLINE_TAGS.has(element.tag) && element.tag !== "a" && element.tag !== "br";
235
+ if (BLOCK_TEXT_TAGS.has(element.tag) || textBox) {
236
+ if (element.children.some((child) => typeof child !== "string" && !INLINE_TAGS.has(child.tag))) {
237
+ this.problem(`<${element.tag}> holds block elements`);
238
+ }
239
+ const node = this.text(element, element.children, inherited, own);
240
+ return node ?? this.node("View", element, box, boxDark);
241
+ }
242
+ if (element.tag === "img") {
243
+ const node = this.node("Image", element, box, boxDark);
244
+ node.src = this.url(element.attributes.src);
245
+ if (element.attributes.alt) node.alt = element.attributes.alt;
246
+ if (!node.src) this.problem("<img> without src");
247
+ return node;
248
+ }
249
+ if (element.tag === "input" || element.tag === "textarea") {
250
+ const node = this.node(
251
+ "TextInput",
252
+ element,
253
+ settleLineHeight({ ...passed.style, ...box }),
254
+ boxDark
255
+ );
256
+ if (element.attributes.placeholder) node.placeholder = element.attributes.placeholder;
257
+ const value = element.tag === "textarea" ? textContent(element) : element.attributes.value;
258
+ if (value) node.value = value;
259
+ return node;
260
+ }
261
+ if (element.tag === "a" || element.tag === "button") {
262
+ const node = this.node("Pressable", element, box, boxDark);
263
+ if (element.tag === "a") node.href = this.url(element.attributes.href);
264
+ node.children = this.blocks(element.children, passed, flex);
265
+ return node;
266
+ }
267
+ if (element.tag === "hr") {
268
+ return this.node(
269
+ "View",
270
+ element,
271
+ {
272
+ borderTopWidth: 1,
273
+ borderTopColor: String(passed.style.color ?? "currentColor"),
274
+ ...box
275
+ },
276
+ boxDark
277
+ );
278
+ }
279
+ if (VIEW_TAGS.has(element.tag)) {
280
+ const node = this.node("View", element, box, boxDark);
281
+ const children = this.blocks(element.children, passed, flex);
282
+ if (children.length > 0) node.children = children;
283
+ return node;
284
+ }
285
+ if (INLINE_TAGS.has(element.tag)) {
286
+ return this.text(element, [element], inherited);
287
+ }
288
+ this.problem(`<${element.tag}>`);
289
+ return void 0;
290
+ }
291
+ };
292
+ function isBlockLink(element) {
293
+ if (element.tag !== "a") return false;
294
+ if (element.children.some((child) => typeof child !== "string" && !INLINE_TAGS.has(child.tag))) {
295
+ return true;
296
+ }
297
+ const classes = resolveFarmNativeClasses(element.attributes.class ?? "").style;
298
+ const inline = resolveFarmNativeInlineStyle(element.attributes.style ?? "").style;
299
+ return withoutText({ ...classes, ...inline }) !== void 0;
300
+ }
301
+ function textContent(element) {
302
+ return element.children.map((child) => typeof child === "string" ? child : textContent(child)).join("");
303
+ }
304
+ function collapse(runs) {
305
+ let previousSpace = true;
306
+ const walk = (items) => {
307
+ const out2 = [];
308
+ for (const item of items) {
309
+ if (typeof item === "string") {
310
+ if (item === "\n") {
311
+ out2.push(item);
312
+ previousSpace = true;
313
+ continue;
314
+ }
315
+ let text = item.replace(/[ \t\r\n\f]+/g, " ");
316
+ if (previousSpace) text = text.replace(/^ /, "");
317
+ if (text) {
318
+ previousSpace = text.endsWith(" ");
319
+ out2.push(text);
320
+ }
321
+ continue;
322
+ }
323
+ const children = item.children ? walk(item.children) : [];
324
+ if (children.length > 0 || item.href) out2.push({ ...item, children });
325
+ }
326
+ return out2;
327
+ };
328
+ const out = walk(runs);
329
+ for (let index = out.length - 1; index >= 0; index -= 1) {
330
+ const item = out[index];
331
+ if (typeof item !== "string") break;
332
+ const trimmed = item.replace(/ $/, "");
333
+ if (trimmed) {
334
+ out[index] = trimmed;
335
+ break;
336
+ }
337
+ out.splice(index, 1);
338
+ }
339
+ return out;
340
+ }
341
+ function createFarmNativeTree(html, pageUrl) {
342
+ const title = /<title\b[^>]*>([\s\S]*?)<\/title>/i.exec(html)?.[1];
343
+ const document = parseHtml(_readFarmRenderedHtml(html));
344
+ const page = find(document, (element) => element.attributes.id === "__farm_page__") ?? find(document, (element) => element.attributes.id === "root") ?? find(document, (element) => element.tag === "body") ?? document;
345
+ const converter = new Converter(pageUrl);
346
+ const root = { type: "View", tag: page.tag };
347
+ const children = converter.blocks(page.children, { style: {}, dark: {} });
348
+ if (children.length > 0) root.children = children;
349
+ return {
350
+ version: 1,
351
+ ...title ? { title: decode(title.trim()) } : {},
352
+ root,
353
+ unsupported: converter.unsupported
354
+ };
355
+ }
356
+ function farmRequestWantsNativeTree(request) {
357
+ return (request.headers.get("accept") ?? "").includes(FARM_NATIVE_TREE_CONTENT_TYPE);
358
+ }
359
+ async function createFarmNativeTreeResponse(options) {
360
+ const headers = new Headers(options.request.headers);
361
+ headers.set("accept", "text/html");
362
+ headers.delete("accept-encoding");
363
+ const page = await options.renderPage(
364
+ new Request(options.request.url, {
365
+ method: "GET",
366
+ headers,
367
+ signal: options.request.signal
368
+ })
369
+ );
370
+ const type = page.headers.get("content-type") ?? "";
371
+ if (page.status !== 200 || !type.includes("text/html")) return page;
372
+ const tree = createFarmNativeTree(await page.text(), new URL(options.request.url));
373
+ const out = new Headers({
374
+ "Content-Type": `${FARM_NATIVE_TREE_CONTENT_TYPE}; charset=utf-8`,
375
+ Vary: "Accept",
376
+ "Cache-Control": page.headers.get("cache-control") ?? "no-store"
377
+ });
378
+ for (const cookie of page.headers.getSetCookie?.() ?? []) out.append("Set-Cookie", cookie);
379
+ return new Response(options.request.method === "HEAD" ? null : JSON.stringify(tree), {
380
+ status: 200,
381
+ headers: out
382
+ });
383
+ }
384
+
385
+ export {
386
+ createFarmNativeTree,
387
+ farmRequestWantsNativeTree,
388
+ createFarmNativeTreeResponse
389
+ };