@farm.js/core 0.1.63 → 0.1.65

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 (200) hide show
  1. package/dist/{agent-mcp-handler-OV4WRFBL.cjs → agent-mcp-handler-OXT73ZBY.cjs} +5 -5
  2. package/dist/{agent-mcp-handler-7QMX2LUY.mjs → agent-mcp-handler-QLFDDTYN.mjs} +4 -4
  3. package/dist/{agent-mcp.d-CCQ-wKwg.d.mts → agent-mcp.d-CO_ABmNK.d.mts} +1 -1
  4. package/dist/{agent-mcp.d-DOJCBSh9.d.ts → agent-mcp.d-QD2WZ9BS.d.ts} +1 -1
  5. package/dist/agent-runtime.d.mts +1 -1
  6. package/dist/agent-runtime.d.ts +1 -1
  7. package/dist/analyzer-GHWK46LX.cjs +16 -0
  8. package/dist/{analyzer-WNPQPWFR.mjs → analyzer-PE33SK5W.mjs} +3 -2
  9. package/dist/api/route-manager.d.mts +3 -3
  10. package/dist/api/route-manager.d.ts +3 -3
  11. package/dist/api/runtime.d.mts +2 -2
  12. package/dist/api/runtime.d.ts +2 -2
  13. package/dist/api.d.mts +3 -3
  14. package/dist/api.d.ts +3 -3
  15. package/dist/{app-manifest.d-BaA0omsv.d.mts → app-manifest.d-BpKxiU_E.d.mts} +1 -1
  16. package/dist/{app-manifest.d-poayV4lq.d.ts → app-manifest.d-DDmNkYQQ.d.ts} +1 -1
  17. package/dist/app-markdown.cjs +4 -4
  18. package/dist/app-markdown.d.mts +2 -2
  19. package/dist/app-markdown.d.ts +2 -2
  20. package/dist/app-markdown.mjs +3 -3
  21. package/dist/{app.d-DdWxeIGU.d.mts → app.d-kuoVWhWM.d.mts} +4 -4
  22. package/dist/{app.d-D4Dn03E3.d.ts → app.d-x68Cwr0_.d.ts} +4 -4
  23. package/dist/{chunk-LT4VAF5Z.cjs → chunk-2C5L5RPM.cjs} +7 -6
  24. package/dist/{chunk-BA2IA32Q.mjs → chunk-2L54YV25.mjs} +13 -11
  25. package/dist/{chunk-5IKQ7BIR.cjs → chunk-32RPJAAS.cjs} +16 -16
  26. package/dist/{chunk-QN5WRQSQ.cjs → chunk-3KJPIO5D.cjs} +610 -3102
  27. package/dist/{chunk-EENTT56C.mjs → chunk-6X5NKNBE.mjs} +43 -38
  28. package/dist/{chunk-RFYL5OLP.mjs → chunk-72JSHQQQ.mjs} +1 -1
  29. package/dist/{chunk-LA45FN37.mjs → chunk-7GYCZRTH.mjs} +386 -2878
  30. package/dist/chunk-7QVRWGBL.cjs +3704 -0
  31. package/dist/{chunk-PRFNLQSP.cjs → chunk-7XGWBPQQ.cjs} +4 -4
  32. package/dist/{chunk-FNHN3RBD.cjs → chunk-A3G5IY2W.cjs} +1 -1
  33. package/dist/{chunk-EYLC6GD6.cjs → chunk-C7DCMGC4.cjs} +12 -12
  34. package/dist/chunk-CJNAUEVC.mjs +34 -0
  35. package/dist/{chunk-LFFSDZ4Y.cjs → chunk-CZF4XIRZ.cjs} +3 -3
  36. package/dist/{chunk-7FFW7DC4.mjs → chunk-E2TSYUHV.mjs} +4 -4
  37. package/dist/{chunk-55U5QIXQ.mjs → chunk-FIR62CR3.mjs} +1 -1
  38. package/dist/{chunk-MEQN6DDA.cjs → chunk-FJWN7RV4.cjs} +5 -5
  39. package/dist/{chunk-VVTJTMGQ.cjs → chunk-GL7N5UHF.cjs} +4 -4
  40. package/dist/{chunk-4DIKLG56.mjs → chunk-GRBJ7VKH.mjs} +1 -1
  41. package/dist/{chunk-UR25Z5Z6.mjs → chunk-HCGWDRZO.mjs} +1 -1
  42. package/dist/{chunk-GPKBUME5.mjs → chunk-HKNYNSOK.mjs} +2 -2
  43. package/dist/{chunk-U6WCUVSV.cjs → chunk-IMK32ERL.cjs} +23 -21
  44. package/dist/chunk-IOEXXZK3.mjs +88 -0
  45. package/dist/{chunk-IOF4KXMP.mjs → chunk-IP2KHSGF.mjs} +205 -26
  46. package/dist/{chunk-YSXTNSXS.mjs → chunk-K7OZAVOI.mjs} +7 -6
  47. package/dist/{chunk-KVW2M6PI.mjs → chunk-KL7SHLQB.mjs} +1 -1
  48. package/dist/{chunk-UZZ6IEQP.mjs → chunk-MESQF2JC.mjs} +2 -2
  49. package/dist/{chunk-DZPR2W6U.cjs → chunk-O6L3YYPM.cjs} +5 -5
  50. package/dist/{chunk-6BJJYOFL.cjs → chunk-OLIGNTWU.cjs} +7 -7
  51. package/dist/{chunk-5L7I6AMY.cjs → chunk-OSFIUSYK.cjs} +5 -5
  52. package/dist/{chunk-LA6O5EL2.mjs → chunk-Q75QPLBA.mjs} +1 -1
  53. package/dist/{chunk-O5FCWI6O.mjs → chunk-QHRCR44V.mjs} +2 -2
  54. package/dist/{chunk-E72UD6ME.mjs → chunk-RVGSVQWT.mjs} +1 -1
  55. package/dist/{chunk-Z74NNER4.cjs → chunk-T4M52BA5.cjs} +164 -159
  56. package/dist/{chunk-PCXIJKPM.mjs → chunk-TNBJ4LZG.mjs} +2 -2
  57. package/dist/{chunk-PAKCHVUS.mjs → chunk-TPA2PV5J.mjs} +3 -35
  58. package/dist/{chunk-Y2YBNQ3D.cjs → chunk-TRIDJQ6A.cjs} +6 -6
  59. package/dist/{chunk-PVJX4UPA.cjs → chunk-TZOGZKI7.cjs} +411 -295
  60. package/dist/{chunk-O27PLNQZ.cjs → chunk-UJ3R2AH2.cjs} +4 -4
  61. package/dist/{chunk-BPNOYILC.cjs → chunk-UVV3I5QA.cjs} +3 -35
  62. package/dist/{chunk-CBDRR3J3.mjs → chunk-VHHLKIDZ.mjs} +166 -50
  63. package/dist/{chunk-T4TBK5NY.mjs → chunk-VQ4NWOWO.mjs} +2 -2
  64. package/dist/{chunk-ZZ2QKCKW.mjs → chunk-WAY6LOQH.mjs} +1 -1
  65. package/dist/chunk-WBTHHTBO.cjs +88 -0
  66. package/dist/{chunk-IWRLV46X.cjs → chunk-WMTBBQHY.cjs} +4 -4
  67. package/dist/{chunk-LWWDTBGL.cjs → chunk-WNXVWXG3.cjs} +2 -2
  68. package/dist/{chunk-CI4UNQHO.cjs → chunk-XBSKPLHF.cjs} +2 -2
  69. package/dist/{chunk-QAS7KE7J.cjs → chunk-Y5TOT5F6.cjs} +5 -5
  70. package/dist/{chunk-ANXU3D32.cjs → chunk-YD4J37RN.cjs} +403 -32
  71. package/dist/{chunk-XICXQXYE.mjs → chunk-YUW7F6SK.mjs} +2 -2
  72. package/dist/chunk-ZAUOOGER.mjs +3704 -0
  73. package/dist/{chunk-DPE53XWL.mjs → chunk-ZEXE4TGY.mjs} +1 -1
  74. package/dist/chunk-ZIHWAN55.cjs +34 -0
  75. package/dist/{chunk-GVOMPU3Y.cjs → chunk-ZQQK4U66.cjs} +213 -34
  76. package/dist/{chunk-S2NUYHRY.mjs → chunk-ZX2JHEWW.mjs} +384 -13
  77. package/dist/{client-component.d-CSEFlHfG.d.mts → client-component.d-D74pqdea.d.mts} +2 -2
  78. package/dist/{client-component.d-CQLvqLAJ.d.ts → client-component.d-D8VcypQA.d.ts} +2 -2
  79. package/dist/{client-plugins.d-BgPUYPc9.d.ts → client-plugins.d-CXElzotB.d.ts} +8 -1
  80. package/dist/{client-plugins.d-BTF0gZm4.d.mts → client-plugins.d-D4-6hNx7.d.mts} +8 -1
  81. package/dist/client-plugins.d.mts +1 -1
  82. package/dist/client-plugins.d.ts +1 -1
  83. package/dist/client.d.mts +6 -6
  84. package/dist/client.d.ts +6 -6
  85. package/dist/config.d.mts +1 -1
  86. package/dist/config.d.ts +1 -1
  87. package/dist/desktop.d.mts +2 -2
  88. package/dist/desktop.d.ts +2 -2
  89. package/dist/{devtools-HDKTYIZF.mjs → devtools-PUVZB3F2.mjs} +7 -6
  90. package/dist/{devtools-ZHN5JLVI.cjs → devtools-SGYOG36E.cjs} +8 -7
  91. package/dist/docs.cjs +10 -9
  92. package/dist/docs.d.mts +2 -2
  93. package/dist/docs.d.ts +2 -2
  94. package/dist/docs.mjs +9 -8
  95. package/dist/environment/vite.cjs +9 -2
  96. package/dist/environment/vite.d.mts +3 -0
  97. package/dist/environment/vite.d.ts +3 -0
  98. package/dist/environment/vite.mjs +8 -1
  99. package/dist/index.cjs +29 -27
  100. package/dist/{index.d-Coow7bD4.d.ts → index.d-A_x10zGS.d.ts} +1 -1
  101. package/dist/{index.d-Dbjx0ku7.d.mts → index.d-SSgYDv4D.d.mts} +1 -1
  102. package/dist/index.d.mts +16 -16
  103. package/dist/index.d.ts +16 -16
  104. package/dist/index.mjs +28 -26
  105. package/dist/integrations.d.mts +1 -1
  106. package/dist/integrations.d.ts +1 -1
  107. package/dist/internal/app-markdown-runtime.cjs +3 -3
  108. package/dist/internal/app-markdown-runtime.d.mts +2 -2
  109. package/dist/internal/app-markdown-runtime.d.ts +2 -2
  110. package/dist/internal/app-markdown-runtime.mjs +2 -2
  111. package/dist/internal/build-runtime.cjs +27 -25
  112. package/dist/internal/build-runtime.d.mts +3 -3
  113. package/dist/internal/build-runtime.d.ts +3 -3
  114. package/dist/internal/build-runtime.mjs +26 -24
  115. package/dist/internal/cli-runtime.cjs +10 -9
  116. package/dist/internal/cli-runtime.mjs +9 -8
  117. package/dist/internal/client-error-overlay.cjs +4 -4
  118. package/dist/internal/client-error-overlay.mjs +1 -1
  119. package/dist/internal/client-runtime.d.mts +4 -4
  120. package/dist/internal/client-runtime.d.ts +4 -4
  121. package/dist/internal/compression-runtime.d.mts +1 -1
  122. package/dist/internal/compression-runtime.d.ts +1 -1
  123. package/dist/internal/config-runtime.cjs +9 -8
  124. package/dist/internal/config-runtime.d.mts +4 -4
  125. package/dist/internal/config-runtime.d.ts +4 -4
  126. package/dist/internal/config-runtime.mjs +8 -7
  127. package/dist/internal/infra-analytics-runtime.cjs +9 -9
  128. package/dist/internal/infra-analytics-runtime.mjs +7 -7
  129. package/dist/internal/native-server-fns.cjs +5 -4
  130. package/dist/internal/native-server-fns.mjs +4 -3
  131. package/dist/internal/product-telemetry-runtime.cjs +3 -3
  132. package/dist/internal/product-telemetry-runtime.mjs +2 -2
  133. package/dist/internal/production-runtime.cjs +11 -11
  134. package/dist/internal/production-runtime.d.mts +20 -12
  135. package/dist/internal/production-runtime.d.ts +20 -12
  136. package/dist/internal/production-runtime.mjs +10 -10
  137. package/dist/markdown.cjs +2 -2
  138. package/dist/markdown.d.mts +1 -1
  139. package/dist/markdown.d.ts +1 -1
  140. package/dist/markdown.mjs +1 -1
  141. package/dist/middleware.d.mts +3 -3
  142. package/dist/middleware.d.ts +3 -3
  143. package/dist/mobile.d.mts +2 -2
  144. package/dist/mobile.d.ts +2 -2
  145. package/dist/{native-tree-Z2WYUJEV.cjs → native-tree-HE2FLS72.cjs} +3 -3
  146. package/dist/{native-tree-AS5L3ID3.mjs → native-tree-YF2DSPKM.mjs} +2 -2
  147. package/dist/{navigation-delegate.d-Ca_BV0Wu.d.mts → navigation-delegate.d-DQVYKoaZ.d.mts} +1 -1
  148. package/dist/{navigation-delegate.d-aHiPI6GL.d.ts → navigation-delegate.d-GghbHJuK.d.ts} +1 -1
  149. package/dist/navigation.d.mts +4 -4
  150. package/dist/navigation.d.ts +4 -4
  151. package/dist/plugin.cjs +18 -17
  152. package/dist/plugin.d.mts +3 -3
  153. package/dist/plugin.d.ts +3 -3
  154. package/dist/plugin.mjs +17 -16
  155. package/dist/{production-runtime.d-C0rF7a10.d.ts → production-runtime.d-Bzns3NW9.d.ts} +1 -1
  156. package/dist/{production-runtime.d-CnAsSWgF.d.mts → production-runtime.d-DiFa5vHW.d.mts} +1 -1
  157. package/dist/{render-plan.d-BxeITFT1.d.ts → render-plan.d-CL_Ikfg_.d.ts} +1 -1
  158. package/dist/{render-plan.d-Z-93m5GZ.d.mts → render-plan.d-CcF0MeCf.d.mts} +1 -1
  159. package/dist/renderer-client.d.mts +4 -4
  160. package/dist/renderer-client.d.ts +4 -4
  161. package/dist/{request.d-X7Q1vmGF.d.ts → request.d-B1RnTLri.d.ts} +1 -1
  162. package/dist/{request.d-8_fMFNEb.d.mts → request.d-DarDOCk9.d.mts} +1 -1
  163. package/dist/request.d.mts +2 -2
  164. package/dist/request.d.ts +2 -2
  165. package/dist/{route-rendering.d-BUr3Jp8S.d.ts → route-rendering.d-BTUYCIj4.d.ts} +1 -1
  166. package/dist/{route-rendering.d-BInmBmul.d.mts → route-rendering.d-D_2Ual0-.d.mts} +1 -1
  167. package/dist/{router.d-crorSRiW.d.ts → router.d-CMANF6da.d.ts} +1 -1
  168. package/dist/{router.d-CZQmbpHx.d.mts → router.d-Cuv1jntg.d.mts} +1 -1
  169. package/dist/{routes.d-BknKQcTu.d.ts → routes.d-B6yFe6jm.d.ts} +1 -1
  170. package/dist/{routes.d-D1IrO9KK.d.mts → routes.d-c2HKfrfL.d.mts} +1 -1
  171. package/dist/routes.d.mts +1 -1
  172. package/dist/routes.d.ts +1 -1
  173. package/dist/{rsc-pipeline-3MPRULGA.mjs → rsc-pipeline-T3PWURLJ.mjs} +9 -8
  174. package/dist/{rsc-pipeline-RHEZNBFQ.cjs → rsc-pipeline-V4ANLRAA.cjs} +10 -9
  175. package/dist/{runtime-OZKFZQCU.cjs → runtime-5AROV2C3.cjs} +29 -17
  176. package/dist/{runtime-X5UR7VHP.mjs → runtime-LRIQ3XH7.mjs} +26 -14
  177. package/dist/{runtime.d-CCsjTZJW.d.ts → runtime.d-C3RQUj6_.d.ts} +1 -1
  178. package/dist/{runtime.d-CETtpLb-.d.mts → runtime.d-wvh4ngU0.d.mts} +1 -1
  179. package/dist/server-plugins.d.mts +2 -2
  180. package/dist/server-plugins.d.ts +2 -2
  181. package/dist/server.cjs +42 -41
  182. package/dist/server.d.mts +9 -9
  183. package/dist/server.d.ts +9 -9
  184. package/dist/server.mjs +26 -25
  185. package/dist/{spa-router.d-CtSHzXlC.d.mts → spa-router.d-WU_qS5gJ.d.mts} +2 -2
  186. package/dist/{spa-router.d-CCADbSqJ.d.ts → spa-router.d-m8H_Kl_B.d.ts} +2 -2
  187. package/dist/testing.d.mts +1 -1
  188. package/dist/testing.d.ts +1 -1
  189. package/dist/{utils.d-CjyE-npA.d.ts → utils.d-C9dQD5Zg.d.ts} +1 -1
  190. package/dist/{utils.d-zFPHKFFJ.d.mts → utils.d-W9IiEqmW.d.mts} +1 -1
  191. package/dist/version.cjs +2 -2
  192. package/dist/version.mjs +1 -1
  193. package/dist/vite.cjs +21 -19
  194. package/dist/vite.d.mts +4 -4
  195. package/dist/vite.d.ts +4 -4
  196. package/dist/vite.mjs +20 -18
  197. package/package.json +1 -1
  198. package/dist/analyzer-KEA5JVDR.cjs +0 -15
  199. package/dist/chunk-NK2VWS7P.cjs +0 -954
  200. package/dist/chunk-ZQ5BDNKW.mjs +0 -954
@@ -18,7 +18,7 @@ import {
18
18
  } from "./chunk-22W4FNTG.mjs";
19
19
  import {
20
20
  farmAcceptQuality
21
- } from "./chunk-YSXTNSXS.mjs";
21
+ } from "./chunk-K7OZAVOI.mjs";
22
22
  import {
23
23
  matchesFarmIfNoneMatch
24
24
  } from "./chunk-QDWMCFTH.mjs";
@@ -0,0 +1,34 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }// src/server-components-mode.ts
2
+ function resolveFarmServerComponentsMode(value) {
3
+ if (value === void 0 || value === null || value === false) return void 0;
4
+ if (value === true) return "rsc";
5
+ const mode = typeof value === "object" ? value.mode : void 0;
6
+ if (mode === "rsc" || mode === "islands") return mode;
7
+ throw new TypeError(
8
+ 'experimental.serverComponents must be true, false, { mode: "rsc" } or { mode: "islands" }.'
9
+ );
10
+ }
11
+ function isExplicitFarmServerComponentsMode(value) {
12
+ return typeof value === "object" && value !== null;
13
+ }
14
+
15
+ // src/utils/source-dir.ts
16
+ var _path = require('path'); var _path2 = _interopRequireDefault(_path);
17
+ var FARM_PROJECT_SOURCE_DIRS = /* @__PURE__ */ Symbol.for("farm.projectSourceDirs");
18
+ function getProjectSourceDirs() {
19
+ const globalState = globalThis;
20
+ return _nullishCoalesce(globalState[FARM_PROJECT_SOURCE_DIRS], () => ( (globalState[FARM_PROJECT_SOURCE_DIRS] = /* @__PURE__ */ new Map())));
21
+ }
22
+ function setFarmProjectSourceDir(root, srcDir) {
23
+ getProjectSourceDirs().set(_path2.default.resolve(root), srcDir);
24
+ }
25
+ function getFarmProjectSourceDir(root) {
26
+ return _nullishCoalesce(getProjectSourceDirs().get(_path2.default.resolve(root)), () => ( "src"));
27
+ }
28
+
29
+
30
+
31
+
32
+
33
+
34
+ exports.resolveFarmServerComponentsMode = resolveFarmServerComponentsMode; exports.isExplicitFarmServerComponentsMode = isExplicitFarmServerComponentsMode; exports.setFarmProjectSourceDir = setFarmProjectSourceDir; exports.getFarmProjectSourceDir = getFarmProjectSourceDir;
@@ -10,9 +10,13 @@ var _chunkV727H3RIcjs = require('./chunk-V727H3RI.cjs');
10
10
  var _chunk3HLQTOVUcjs = require('./chunk-3HLQTOVU.cjs');
11
11
 
12
12
 
13
- var _chunkLT4VAF5Zcjs = require('./chunk-LT4VAF5Z.cjs');
13
+ var _chunk2C5L5RPMcjs = require('./chunk-2C5L5RPM.cjs');
14
14
 
15
15
  // src/mobile/native-tree.ts
16
+ var URLENCODED = "application/x-www-form-urlencoded";
17
+ var MULTIPART = "multipart/form-data";
18
+ var TEXT_INPUT_TYPES = /* @__PURE__ */ new Set(["text", "email", "password", "number", "search", "tel", "url"]);
19
+ var CONTROL_TAGS = /* @__PURE__ */ new Set(["input", "textarea", "select", "button"]);
16
20
  var VIEW_TAGS = new Set(
17
21
  "div section main article header footer nav aside figure ul ol li hr".split(" ")
18
22
  );
@@ -118,15 +122,29 @@ function settleLineHeight(style) {
118
122
  }
119
123
  return rest;
120
124
  }
125
+ function labelText(element) {
126
+ const text = (node) => typeof node === "string" ? node : CONTROL_TAGS.has(node.tag) || node.tag === "option" ? " " : node.children.map(text).join("");
127
+ return text(element).replace(/\s+/g, " ").trim();
128
+ }
129
+ function findNode(node, test) {
130
+ for (const child of _nullishCoalesce(node.children, () => ( []))) {
131
+ if (typeof child === "string") continue;
132
+ if (test(child)) return child;
133
+ const found = findNode(child, test);
134
+ if (found) return found;
135
+ }
136
+ return void 0;
137
+ }
121
138
  var Converter = class {
122
139
  /**
123
140
  * `sheets`: the page's stylesheets. Without them, a class the Tailwind table does not know is
124
141
  * reported; with them, only one a layered (Tailwind) rule styles is, since a class no rule
125
142
  * styles has no effect in a browser either.
126
143
  */
127
- constructor(pageUrl, sheets) {
144
+ constructor(pageUrl, sheets, labels = /* @__PURE__ */ new Map()) {
128
145
  this.pageUrl = pageUrl;
129
146
  this.sheets = sheets;
147
+ this.labels = labels;
130
148
  this.unsupported = [];
131
149
  /** Off while reading the ancestors above the page, which pass down text styles only. */
132
150
  this.reporting = true;
@@ -176,14 +194,75 @@ var Converter = class {
176
194
  return void 0;
177
195
  }
178
196
  }
179
- node(type, element, style, dark) {
180
- const changed = dark && Object.fromEntries(Object.entries(dark).filter(([key, value]) => _optionalChain([style, 'optionalAccess', _4 => _4[key]]) !== value));
197
+ /** A form's or button's action: absolute http(s), without a fragment; empty means this page. */
198
+ formUrl(value, what) {
199
+ let url;
200
+ try {
201
+ url = new URL(_nullishCoalesce(value, () => ( "")), this.pageUrl);
202
+ } catch (e2) {
203
+ this.problem(`${what} "${value}"`);
204
+ return void 0;
205
+ }
206
+ if (url.protocol !== "http:" && url.protocol !== "https:") {
207
+ this.problem(`${what} "${value}"`);
208
+ return void 0;
209
+ }
210
+ url.hash = "";
211
+ return url.href;
212
+ }
213
+ method(value, what) {
214
+ const method = _optionalChain([value, 'optionalAccess', _4 => _4.toLowerCase, 'call', _5 => _5()]);
215
+ if (method === void 0 || method === "") return void 0;
216
+ if (method === "get" || method === "post") return method;
217
+ this.problem(`${what} method "${value}"`);
218
+ return void 0;
219
+ }
220
+ enctype(value, what) {
221
+ const enctype = _optionalChain([value, 'optionalAccess', _6 => _6.toLowerCase, 'call', _7 => _7()]);
222
+ if (enctype === void 0 || enctype === "") return void 0;
223
+ if (enctype === URLENCODED || enctype === MULTIPART) return enctype;
224
+ this.problem(`${what} enctype "${value}"`);
225
+ return void 0;
226
+ }
227
+ /** What a submit button sends besides its form's fields, and where. */
228
+ submitter(element) {
229
+ const { name, value, formaction, formmethod, formenctype, formtarget } = element.attributes;
230
+ if (formtarget && formtarget !== "_self") this.problem(`<${element.tag}> formtarget`);
231
+ const action = formaction === void 0 ? void 0 : this.formUrl(formaction, `<${element.tag}> formaction`);
232
+ const method = this.method(formmethod, `<${element.tag}>`);
233
+ const enctype = this.enctype(formenctype, `<${element.tag}>`);
181
234
  return {
235
+ ...name ? { name, value: _nullishCoalesce(value, () => ( "")) } : {},
236
+ ...action ? { action } : {},
237
+ ...method ? { method } : {},
238
+ ...enctype ? { enctype } : {}
239
+ };
240
+ }
241
+ /** A `<label>` that wraps a field draws as a box: its text, then the field. */
242
+ holdsControl(element) {
243
+ return element.children.some(
244
+ (child) => typeof child !== "string" && (CONTROL_TAGS.has(child.tag) || this.holdsControl(child))
245
+ );
246
+ }
247
+ node(type, element, style, dark) {
248
+ const changed = dark && Object.fromEntries(Object.entries(dark).filter(([key, value]) => _optionalChain([style, 'optionalAccess', _8 => _8[key]]) !== value));
249
+ const node = {
182
250
  type,
183
251
  tag: element.tag,
184
252
  ...style && Object.keys(style).length > 0 ? { style } : {},
185
253
  ...changed && Object.keys(changed).length > 0 ? { dark: changed } : {}
186
254
  };
255
+ const { role } = element.attributes;
256
+ const level = _nullishCoalesce(_optionalChain([/^h([1-6])$/, 'access', _9 => _9.exec, 'call', _10 => _10(element.tag), 'optionalAccess', _11 => _11[1]]), () => ( (role === "heading" ? _nullishCoalesce(element.attributes["aria-level"], () => ( "2")) : void 0)));
257
+ if (type === "Text" && level && Number(level) >= 1 && Number(level) <= 6) {
258
+ node.heading = Number(level);
259
+ }
260
+ const label = _optionalChain([element, 'access', _12 => _12.attributes, 'access', _13 => _13["aria-label"], 'optionalAccess', _14 => _14.trim, 'call', _15 => _15()]);
261
+ if (label) node.label = label;
262
+ if (element.attributes["aria-hidden"] === "true" || role === "presentation" || role === "none" || element.tag === "img" && element.attributes.alt === "") {
263
+ node.hidden = true;
264
+ }
265
+ return node;
187
266
  }
188
267
  /** Inline content: runs of text, nested inline elements, and line breaks. */
189
268
  inline(content, inherited) {
@@ -223,11 +302,11 @@ var Converter = class {
223
302
  const runs = this.inline(content, inherited);
224
303
  const trimmed = collapse(runs);
225
304
  if (trimmed.length === 0) return void 0;
226
- const style = settleLineHeight({ ...inherited.style, ..._optionalChain([box, 'optionalAccess', _5 => _5.style]) });
305
+ const style = settleLineHeight({ ...inherited.style, ..._optionalChain([box, 'optionalAccess', _16 => _16.style]) });
227
306
  const dark = {
228
307
  ...inherited.dark,
229
308
  ...box ? textOnly(box.style) : {},
230
- ..._optionalChain([box, 'optionalAccess', _6 => _6.dark])
309
+ ..._optionalChain([box, 'optionalAccess', _17 => _17.dark])
231
310
  };
232
311
  const node = this.node("Text", element, style, dark);
233
312
  node.children = trimmed;
@@ -266,7 +345,7 @@ var Converter = class {
266
345
  pending = [];
267
346
  };
268
347
  for (const child of content) {
269
- if (typeof child === "string" || INLINE_TAGS.has(child.tag) && !this.isBlockLink(child)) {
348
+ if (typeof child === "string" || INLINE_TAGS.has(child.tag) && !this.isBlockLink(child) && !(child.tag === "label" && this.holdsControl(child))) {
270
349
  pending.push(child);
271
350
  continue;
272
351
  }
@@ -277,8 +356,31 @@ var Converter = class {
277
356
  flush();
278
357
  return nodes;
279
358
  }
359
+ /** `<input type="submit">`: a button whose label is its value. */
360
+ submitButton(element, passed, box, boxDark) {
361
+ const node = this.node("Pressable", element, box, boxDark);
362
+ const label = this.text(
363
+ { tag: "#text", attributes: {}, children: [] },
364
+ [_nullishCoalesce(element.attributes.value, () => ( "Submit"))],
365
+ passed
366
+ );
367
+ if (label) node.children = [label];
368
+ if (element.attributes.disabled !== void 0) node.disabled = true;
369
+ else node.submit = this.submitter(element);
370
+ return node;
371
+ }
280
372
  element(element, inherited, flexItem = false) {
281
373
  if (SKIPPED_TAGS.has(element.tag)) return void 0;
374
+ if (element.attributes.form !== void 0 && CONTROL_TAGS.has(element.tag)) {
375
+ this.problem(`<${element.tag}> form="${element.attributes.form}"`);
376
+ }
377
+ if (element.tag === "input" && _optionalChain([element, 'access', _18 => _18.attributes, 'access', _19 => _19.type, 'optionalAccess', _20 => _20.toLowerCase, 'call', _21 => _21()]) === "hidden") {
378
+ const { name, value, disabled } = element.attributes;
379
+ if (this.form && name && disabled === void 0) {
380
+ this.form.fields.push({ name, value: _nullishCoalesce(value, () => ( "")) });
381
+ }
382
+ return void 0;
383
+ }
282
384
  const own = this.stylesOf(element);
283
385
  if (own.style.display === "none") return void 0;
284
386
  const passed = {
@@ -296,6 +398,15 @@ var Converter = class {
296
398
  const box = current(withoutText(own.style), passed.style.color);
297
399
  const boxDark = current(withoutText(own.dark), _nullishCoalesce(passed.dark.color, () => ( passed.style.color)));
298
400
  const flex = own.style.display === "flex";
401
+ if (element.tag === "label" && this.holdsControl(element)) {
402
+ const node = this.node("View", element, box, boxDark);
403
+ const children = this.blocks(element.children, passed, flex);
404
+ if (children.length > 0) node.children = children;
405
+ const text = labelText(element);
406
+ const field = findNode(node, (child) => child.type === "TextInput");
407
+ if (text && field && !field.label) field.label = text;
408
+ return node;
409
+ }
299
410
  const textBox = flexItem && INLINE_TAGS.has(element.tag) && element.tag !== "a" && element.tag !== "br";
300
411
  if (BLOCK_TEXT_TAGS.has(element.tag) || textBox) {
301
412
  if (element.children.some((child) => typeof child !== "string" && !INLINE_TAGS.has(child.tag))) {
@@ -311,21 +422,76 @@ var Converter = class {
311
422
  if (!node.src) this.problem("<img> without src");
312
423
  return node;
313
424
  }
425
+ if (element.tag === "form") {
426
+ if (this.form) {
427
+ this.problem("<form> inside a form");
428
+ return void 0;
429
+ }
430
+ const { action, method, enctype, target } = element.attributes;
431
+ if (target && target !== "_self") this.problem(`<form> target="${target}"`);
432
+ const node = this.node("View", element, box, boxDark);
433
+ const form = {
434
+ action: _nullishCoalesce(this.formUrl(action, "<form> action"), () => ( "")),
435
+ method: _nullishCoalesce(this.method(method, "<form>"), () => ( "get"))
436
+ };
437
+ if (this.enctype(enctype, "<form>") === MULTIPART) form.enctype = MULTIPART;
438
+ this.form = { fields: [] };
439
+ try {
440
+ const children = this.blocks(element.children, passed, flex);
441
+ if (children.length > 0) node.children = children;
442
+ if (this.form.fields.length > 0) form.fields = this.form.fields;
443
+ } finally {
444
+ this.form = void 0;
445
+ }
446
+ node.form = form;
447
+ return node;
448
+ }
314
449
  if (element.tag === "input" || element.tag === "textarea") {
450
+ const { attributes } = element;
451
+ const type = element.tag === "input" ? (_nullishCoalesce(attributes.type, () => ( "text"))).toLowerCase() : "text";
452
+ if (!this.form) this.problem(`<${element.tag}> has no form to submit it`);
453
+ if (type === "submit") return this.submitButton(element, passed, box, boxDark);
454
+ if (!TEXT_INPUT_TYPES.has(type)) this.problem(`<input type="${type}">`);
315
455
  const node = this.node(
316
456
  "TextInput",
317
457
  element,
318
458
  settleLineHeight({ ...passed.style, ...box }),
319
459
  boxDark
320
460
  );
321
- if (element.attributes.placeholder) node.placeholder = element.attributes.placeholder;
322
- const value = element.tag === "textarea" ? textContent(element) : element.attributes.value;
461
+ if (attributes.name) node.name = attributes.name;
462
+ if (!node.label && attributes.id && this.labels.has(attributes.id)) {
463
+ node.label = this.labels.get(attributes.id);
464
+ }
465
+ if (type !== "text") node.inputType = type;
466
+ if (element.tag === "textarea") node.multiline = true;
467
+ if (attributes.placeholder) node.placeholder = attributes.placeholder;
468
+ const value = element.tag === "textarea" ? textContent(element) : attributes.value;
323
469
  if (value) node.value = value;
470
+ if (attributes.required !== void 0) node.required = true;
471
+ if (attributes.disabled !== void 0) node.disabled = true;
472
+ if (attributes.readonly !== void 0) node.readOnly = true;
473
+ const maxLength = Number(attributes.maxlength);
474
+ if (attributes.maxlength && Number.isInteger(maxLength) && maxLength >= 0) {
475
+ node.maxLength = maxLength;
476
+ }
324
477
  return node;
325
478
  }
326
- if (element.tag === "a" || element.tag === "button") {
479
+ if (element.tag === "button") {
480
+ const type = (_nullishCoalesce(element.attributes.type, () => ( "submit"))).toLowerCase();
481
+ if (!this.form) {
482
+ this.problem("<button> has no link or form to submit");
483
+ } else if (type !== "submit") {
484
+ this.problem(`<button type="${type}">`);
485
+ }
327
486
  const node = this.node("Pressable", element, box, boxDark);
328
- if (element.tag === "a") node.href = this.url(element.attributes.href);
487
+ node.children = this.blocks(element.children, passed, flex);
488
+ if (element.attributes.disabled !== void 0) node.disabled = true;
489
+ else node.submit = this.submitter(element);
490
+ return node;
491
+ }
492
+ if (element.tag === "a") {
493
+ const node = this.node("Pressable", element, box, boxDark);
494
+ node.href = this.url(element.attributes.href);
329
495
  node.children = this.blocks(element.children, passed, flex);
330
496
  return node;
331
497
  }
@@ -419,10 +585,19 @@ function parsedStylesheet(css) {
419
585
  return sheet;
420
586
  }
421
587
  function createFarmNativeTree(html, pageUrl, stylesheets) {
422
- const title = _optionalChain([/<title\b[^>]*>([\s\S]*?)<\/title>/i, 'access', _7 => _7.exec, 'call', _8 => _8(html), 'optionalAccess', _9 => _9[1]]);
423
- const document = parseHtml(_chunkLT4VAF5Zcjs._readFarmRenderedHtml.call(void 0, html));
588
+ const title = _optionalChain([/<title\b[^>]*>([\s\S]*?)<\/title>/i, 'access', _22 => _22.exec, 'call', _23 => _23(html), 'optionalAccess', _24 => _24[1]]);
589
+ const document = parseHtml(_chunk2C5L5RPMcjs._readFarmRenderedHtml.call(void 0, html, { keepAriaHidden: true }));
424
590
  const page = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(find(document, (element) => element.attributes.id === "__farm_page__"), () => ( find(document, (element) => element.attributes.id === "root"))), () => ( find(document, (element) => element.tag === "body"))), () => ( document));
425
- const converter = new Converter(pageUrl, _optionalChain([stylesheets, 'optionalAccess', _10 => _10.map, 'call', _11 => _11(parsedStylesheet)]));
591
+ const labels = /* @__PURE__ */ new Map();
592
+ const collectLabels = (element) => {
593
+ if (element.tag === "label" && element.attributes.for) {
594
+ const text = labelText(element);
595
+ if (text) labels.set(element.attributes.for, text);
596
+ }
597
+ for (const child of element.children) if (typeof child !== "string") collectLabels(child);
598
+ };
599
+ collectLabels(page);
600
+ const converter = new Converter(pageUrl, _optionalChain([stylesheets, 'optionalAccess', _25 => _25.map, 'call', _26 => _26(parsedStylesheet)]), labels);
426
601
  const ancestors = [];
427
602
  for (let element = page.parent; element; element = element.parent) ancestors.unshift(element);
428
603
  const inherited = { style: {}, dark: {} };
@@ -449,14 +624,14 @@ function createFarmNativeTree(html, pageUrl, stylesheets) {
449
624
  if (children.length > 0) root.children = children;
450
625
  return {
451
626
  version: 1,
452
- ..._optionalChain([title, 'optionalAccess', _12 => _12.trim, 'call', _13 => _13()]) ? { title: decode(title.trim()) } : firstHeading(root) ? { title: firstHeading(root) } : {},
627
+ ..._optionalChain([title, 'optionalAccess', _27 => _27.trim, 'call', _28 => _28()]) ? { title: decode(title.trim()) } : firstHeading(root) ? { title: firstHeading(root) } : {},
453
628
  root,
454
629
  unsupported: converter.unsupported
455
630
  };
456
631
  }
457
632
  function readFarmPageStylesheets(html, pageUrl) {
458
633
  const out = [];
459
- const head = _nullishCoalesce(_optionalChain([/<head\b[^>]*>([\s\S]*?)<\/head>/i, 'access', _14 => _14.exec, 'call', _15 => _15(html), 'optionalAccess', _16 => _16[1]]), () => ( html));
634
+ const head = _nullishCoalesce(_optionalChain([/<head\b[^>]*>([\s\S]*?)<\/head>/i, 'access', _29 => _29.exec, 'call', _30 => _30(html), 'optionalAccess', _31 => _31[1]]), () => ( html));
460
635
  for (const match of head.matchAll(/<link\b([^>]*)>|<style\b[^>]*>([\s\S]*?)<\/style>/gi)) {
461
636
  if (match[2] !== void 0) {
462
637
  out.push({ inline: match[2] });
@@ -464,7 +639,7 @@ function readFarmPageStylesheets(html, pageUrl) {
464
639
  }
465
640
  const attributes = match[1];
466
641
  if (!/\brel\s*=\s*["']?stylesheet\b/i.test(attributes)) continue;
467
- const href = _optionalChain([/\bhref\s*=\s*["']([^"']+)["']/i, 'access', _17 => _17.exec, 'call', _18 => _18(attributes), 'optionalAccess', _19 => _19[1]]);
642
+ const href = _optionalChain([/\bhref\s*=\s*["']([^"']+)["']/i, 'access', _32 => _32.exec, 'call', _33 => _33(attributes), 'optionalAccess', _34 => _34[1]]);
468
643
  if (!href) continue;
469
644
  const resolved = new URL(decode(href), pageUrl);
470
645
  if (resolved.origin === pageUrl.origin) out.push({ href: resolved.pathname + resolved.search });
@@ -478,25 +653,27 @@ async function createFarmNativeTreeResponse(options) {
478
653
  const headers = new Headers(options.request.headers);
479
654
  headers.set("accept", "text/html");
480
655
  headers.delete("accept-encoding");
656
+ headers.set("x-farm-native-tree", "1");
657
+ const submitted = options.request.method === "POST";
658
+ const init = submitted ? { method: "POST", headers, body: options.request.body, duplex: "half" } : { method: "GET", headers };
481
659
  const page = await options.renderPage(
482
- new Request(options.request.url, {
483
- method: "GET",
484
- headers,
485
- signal: options.request.signal
486
- })
660
+ new Request(options.request.url, { ...init, signal: options.request.signal })
487
661
  );
662
+ const cookies = _nullishCoalesce(_optionalChain([page, 'access', _35 => _35.headers, 'access', _36 => _36.getSetCookie, 'optionalCall', _37 => _37()]), () => ( []));
488
663
  const type = _nullishCoalesce(page.headers.get("content-type"), () => ( ""));
489
- if (page.status !== 200 || !type.includes("text/html")) return page;
664
+ const drawn = page.status === 200 || submitted && page.status >= 400 && page.status < 500;
665
+ if (!drawn || !type.includes("text/html")) return page;
490
666
  const html = await page.text();
491
- const pageUrl = new URL(options.request.url);
667
+ const requestUrl = new URL(options.request.url);
668
+ const pageUrl = options.origin ? new URL(requestUrl.pathname + requestUrl.search, options.origin) : requestUrl;
492
669
  const load = _nullishCoalesce(options.loadStylesheet, () => ( (async (href) => {
493
670
  const response = await options.renderPage(
494
- new Request(new URL(href, pageUrl), {
671
+ new Request(new URL(href, requestUrl), {
495
672
  headers: { accept: "text/css,*/*;q=0.1", cookie: _nullishCoalesce(headers.get("cookie"), () => ( "")) },
496
673
  signal: options.request.signal
497
674
  })
498
675
  );
499
- return response.status === 200 && _optionalChain([response, 'access', _20 => _20.headers, 'access', _21 => _21.get, 'call', _22 => _22("content-type"), 'optionalAccess', _23 => _23.includes, 'call', _24 => _24("text/css")]) ? response.text() : void 0;
676
+ return response.status === 200 && _optionalChain([response, 'access', _38 => _38.headers, 'access', _39 => _39.get, 'call', _40 => _40("content-type"), 'optionalAccess', _41 => _41.includes, 'call', _42 => _42("text/css")]) ? response.text() : void 0;
500
677
  })));
501
678
  const stylesheets = [];
502
679
  for (const source of readFarmPageStylesheets(html, pageUrl)) {
@@ -507,12 +684,13 @@ async function createFarmNativeTreeResponse(options) {
507
684
  root: { type: "View", tag: "#root" },
508
685
  unsupported: [`stylesheet "${source.href}" could not be read`]
509
686
  };
510
- return new Response(JSON.stringify(tree2), {
511
- headers: {
512
- "Content-Type": `${_chunk3HLQTOVUcjs.FARM_NATIVE_TREE_CONTENT_TYPE}; charset=utf-8`,
513
- Vary: "Accept"
514
- }
687
+ const out2 = new Headers({
688
+ "Content-Type": `${_chunk3HLQTOVUcjs.FARM_NATIVE_TREE_CONTENT_TYPE}; charset=utf-8`,
689
+ Vary: "Accept",
690
+ "Cache-Control": "no-store"
515
691
  });
692
+ for (const cookie of cookies) out2.append("Set-Cookie", cookie);
693
+ return new Response(JSON.stringify(tree2), { headers: out2 });
516
694
  }
517
695
  stylesheets.push(css);
518
696
  }
@@ -520,11 +698,12 @@ async function createFarmNativeTreeResponse(options) {
520
698
  const out = new Headers({
521
699
  "Content-Type": `${_chunk3HLQTOVUcjs.FARM_NATIVE_TREE_CONTENT_TYPE}; charset=utf-8`,
522
700
  Vary: "Accept",
523
- "Cache-Control": _nullishCoalesce(page.headers.get("cache-control"), () => ( "no-store"))
701
+ // The answer to a POST is that submission's result, never a cacheable page.
702
+ "Cache-Control": _nullishCoalesce((submitted ? void 0 : page.headers.get("cache-control")), () => ( "no-store"))
524
703
  });
525
- for (const cookie of _nullishCoalesce(_optionalChain([page, 'access', _25 => _25.headers, 'access', _26 => _26.getSetCookie, 'optionalCall', _27 => _27()]), () => ( []))) out.append("Set-Cookie", cookie);
704
+ for (const cookie of cookies) out.append("Set-Cookie", cookie);
526
705
  return new Response(options.request.method === "HEAD" ? null : JSON.stringify(tree), {
527
- status: 200,
706
+ status: page.status,
528
707
  headers: out
529
708
  });
530
709
  }