@farm.js/core 0.1.62 → 0.1.64

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 (194) 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-BKZ3UNbt.d.mts → agent-mcp.d-CO_ABmNK.d.mts} +1 -1
  4. package/dist/{agent-mcp.d-C1zr_nGS.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-ODLF2Z6O.cjs +16 -0
  8. package/dist/{analyzer-YESYU3GK.mjs → analyzer-Q3QXC6PD.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-ntch_bvA.d.ts → app-manifest.d-BpKxiU_E.d.mts} +9 -1
  16. package/dist/{app-manifest.d-BpvhfKRH.d.mts → app-manifest.d-DDmNkYQQ.d.ts} +9 -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-CysWA_8v.d.mts → app.d-kuoVWhWM.d.mts} +4 -4
  22. package/dist/{app.d-AE8_v3Db.d.ts → app.d-x68Cwr0_.d.ts} +4 -4
  23. package/dist/{chunk-LT4VAF5Z.cjs → chunk-2C5L5RPM.cjs} +7 -6
  24. package/dist/{chunk-RMUD75WT.cjs → chunk-3EBHJET2.cjs} +355 -270
  25. package/dist/{chunk-RZNCMRD3.mjs → chunk-6NHSGVVA.mjs} +1 -1
  26. package/dist/{chunk-LVWGURLD.mjs → chunk-6NNYPY5W.mjs} +327 -13
  27. package/dist/{chunk-PRFNLQSP.cjs → chunk-7XGWBPQQ.cjs} +4 -4
  28. package/dist/{chunk-SG57PX7K.cjs → chunk-BTVDYS4B.cjs} +7 -2
  29. package/dist/{chunk-545WJ5UG.cjs → chunk-DUSHDZQL.cjs} +11 -11
  30. package/dist/{chunk-GVOMPU3Y.cjs → chunk-EL4364S2.cjs} +209 -32
  31. package/dist/{chunk-GGNJAGGE.cjs → chunk-FAP7CX7C.cjs} +1056 -529
  32. package/dist/{chunk-T46NNU4D.mjs → chunk-FH45OB37.mjs} +2 -2
  33. package/dist/{chunk-55U5QIXQ.mjs → chunk-FIR62CR3.mjs} +1 -1
  34. package/dist/{chunk-MEQN6DDA.cjs → chunk-FJWN7RV4.cjs} +5 -5
  35. package/dist/chunk-IOEXXZK3.mjs +88 -0
  36. package/dist/{chunk-EXXFSZOC.cjs → chunk-JCPSA4X5.cjs} +135 -134
  37. package/dist/{chunk-YSXTNSXS.mjs → chunk-K7OZAVOI.mjs} +7 -6
  38. package/dist/{chunk-KVW2M6PI.mjs → chunk-KL7SHLQB.mjs} +1 -1
  39. package/dist/{chunk-NT3QDN2E.mjs → chunk-LQDLEWPO.mjs} +1 -1
  40. package/dist/{chunk-UZZ6IEQP.mjs → chunk-MESQF2JC.mjs} +2 -2
  41. package/dist/{chunk-WKJQ2FJA.cjs → chunk-MG356ROI.cjs} +5 -5
  42. package/dist/{chunk-AJB3DHN6.cjs → chunk-N3Z3PLHC.cjs} +2 -2
  43. package/dist/{chunk-2CNKQC3G.mjs → chunk-NNLFW3P4.mjs} +2 -2
  44. package/dist/{chunk-XX32BOMM.cjs → chunk-NXFA7G3Y.cjs} +52 -26
  45. package/dist/{chunk-SM25ZC4S.cjs → chunk-O2XFIPNL.cjs} +1 -1
  46. package/dist/{chunk-VWW4Q3BJ.mjs → chunk-O4FWNLQK.mjs} +4 -4
  47. package/dist/{chunk-DZPR2W6U.cjs → chunk-O6L3YYPM.cjs} +5 -5
  48. package/dist/{chunk-UWI3SJAK.cjs → chunk-O7IEMY55.cjs} +3 -3
  49. package/dist/{chunk-6BJJYOFL.cjs → chunk-OLIGNTWU.cjs} +7 -7
  50. package/dist/{chunk-OUWRNHTV.mjs → chunk-OYF23QLG.mjs} +17 -16
  51. package/dist/{chunk-IQIKPKFP.mjs → chunk-RAH5MT53.mjs} +110 -25
  52. package/dist/{chunk-E72UD6ME.mjs → chunk-RVGSVQWT.mjs} +1 -1
  53. package/dist/{chunk-ZVIEFTUA.cjs → chunk-S25BQIFW.cjs} +16 -16
  54. package/dist/chunk-S7ZW72JH.cjs +254 -0
  55. package/dist/{chunk-VM7X5CKC.mjs → chunk-SLYDIHLW.mjs} +31 -5
  56. package/dist/chunk-SNFTMSHX.mjs +254 -0
  57. package/dist/{chunk-2WZTGPK6.mjs → chunk-SQ5O7I3L.mjs} +7 -2
  58. package/dist/{chunk-PCXIJKPM.mjs → chunk-TNBJ4LZG.mjs} +2 -2
  59. package/dist/{chunk-O27PLNQZ.cjs → chunk-UJ3R2AH2.cjs} +4 -4
  60. package/dist/{chunk-T4TBK5NY.mjs → chunk-VQ4NWOWO.mjs} +2 -2
  61. package/dist/{chunk-ZZ2QKCKW.mjs → chunk-WAY6LOQH.mjs} +1 -1
  62. package/dist/chunk-WBTHHTBO.cjs +88 -0
  63. package/dist/{chunk-ZBUAOGMY.mjs → chunk-WFNAOWH4.mjs} +1 -1
  64. package/dist/{chunk-IWRLV46X.cjs → chunk-WMTBBQHY.cjs} +4 -4
  65. package/dist/{chunk-2JYBLE63.mjs → chunk-WNYRYI4D.mjs} +770 -243
  66. package/dist/{chunk-CI4UNQHO.cjs → chunk-XBSKPLHF.cjs} +2 -2
  67. package/dist/{chunk-IOF4KXMP.mjs → chunk-XVWSDSUM.mjs} +201 -24
  68. package/dist/{chunk-JEJQGZI7.cjs → chunk-XZLZ6YPP.cjs} +346 -32
  69. package/dist/{chunk-QAS7KE7J.cjs → chunk-Y5TOT5F6.cjs} +5 -5
  70. package/dist/{chunk-DPE53XWL.mjs → chunk-ZEXE4TGY.mjs} +1 -1
  71. package/dist/{client-component.d-BoqC2MLC.d.mts → client-component.d-D74pqdea.d.mts} +14 -3
  72. package/dist/{client-component.d-Bgt3x5Fu.d.ts → client-component.d-D8VcypQA.d.ts} +14 -3
  73. package/dist/{client-plugins.d-BcqIy4au.d.ts → client-plugins.d-CXElzotB.d.ts} +18 -2
  74. package/dist/{client-plugins.d-CWyYBxXf.d.mts → client-plugins.d-D4-6hNx7.d.mts} +18 -2
  75. package/dist/client-plugins.d.mts +1 -1
  76. package/dist/client-plugins.d.ts +1 -1
  77. package/dist/client.d.mts +6 -6
  78. package/dist/client.d.ts +6 -6
  79. package/dist/config.d.mts +1 -1
  80. package/dist/config.d.ts +1 -1
  81. package/dist/desktop.d.mts +2 -2
  82. package/dist/desktop.d.ts +2 -2
  83. package/dist/{devtools-NUVXYG7I.mjs → devtools-MX3FE733.mjs} +5 -5
  84. package/dist/{devtools-SVRSGPNC.cjs → devtools-WET5NAKO.cjs} +6 -6
  85. package/dist/docs.cjs +8 -8
  86. package/dist/docs.d.mts +2 -2
  87. package/dist/docs.d.ts +2 -2
  88. package/dist/docs.mjs +7 -7
  89. package/dist/index.cjs +21 -20
  90. package/dist/{index.d-nAncqTXz.d.ts → index.d-A_x10zGS.d.ts} +1 -1
  91. package/dist/{index.d-BDaiu2i5.d.mts → index.d-SSgYDv4D.d.mts} +1 -1
  92. package/dist/index.d.mts +16 -16
  93. package/dist/index.d.ts +16 -16
  94. package/dist/index.mjs +20 -19
  95. package/dist/integrations.d.mts +1 -1
  96. package/dist/integrations.d.ts +1 -1
  97. package/dist/internal/app-markdown-runtime.cjs +3 -3
  98. package/dist/internal/app-markdown-runtime.d.mts +2 -2
  99. package/dist/internal/app-markdown-runtime.d.ts +2 -2
  100. package/dist/internal/app-markdown-runtime.mjs +2 -2
  101. package/dist/internal/build-runtime.cjs +22 -21
  102. package/dist/internal/build-runtime.d.mts +3 -3
  103. package/dist/internal/build-runtime.d.ts +3 -3
  104. package/dist/internal/build-runtime.mjs +21 -20
  105. package/dist/internal/cli-runtime.cjs +7 -7
  106. package/dist/internal/cli-runtime.mjs +6 -6
  107. package/dist/internal/client-error-overlay.cjs +4 -4
  108. package/dist/internal/client-error-overlay.mjs +1 -1
  109. package/dist/internal/client-runtime.d.mts +4 -4
  110. package/dist/internal/client-runtime.d.ts +4 -4
  111. package/dist/internal/compression-runtime.d.mts +1 -1
  112. package/dist/internal/compression-runtime.d.ts +1 -1
  113. package/dist/internal/config-runtime.cjs +7 -7
  114. package/dist/internal/config-runtime.d.mts +4 -4
  115. package/dist/internal/config-runtime.d.ts +4 -4
  116. package/dist/internal/config-runtime.mjs +6 -6
  117. package/dist/internal/infra-analytics-runtime.cjs +11 -9
  118. package/dist/internal/infra-analytics-runtime.mjs +9 -7
  119. package/dist/internal/native-server-fns.cjs +5 -4
  120. package/dist/internal/native-server-fns.mjs +4 -3
  121. package/dist/internal/product-telemetry-runtime.cjs +17 -211
  122. package/dist/internal/product-telemetry-runtime.mjs +10 -204
  123. package/dist/internal/production-runtime.cjs +13 -12
  124. package/dist/internal/production-runtime.d.mts +13 -12
  125. package/dist/internal/production-runtime.d.ts +13 -12
  126. package/dist/internal/production-runtime.mjs +14 -13
  127. package/dist/internal/react-cache.cjs +21 -1
  128. package/dist/internal/react-cache.d.mts +8 -1
  129. package/dist/internal/react-cache.d.ts +8 -1
  130. package/dist/internal/react-cache.mjs +21 -1
  131. package/dist/markdown.cjs +2 -2
  132. package/dist/markdown.d.mts +1 -1
  133. package/dist/markdown.d.ts +1 -1
  134. package/dist/markdown.mjs +1 -1
  135. package/dist/middleware.d.mts +3 -3
  136. package/dist/middleware.d.ts +3 -3
  137. package/dist/mobile.d.mts +2 -2
  138. package/dist/mobile.d.ts +2 -2
  139. package/dist/{native-tree-AS5L3ID3.mjs → native-tree-BPEE2LAL.mjs} +2 -2
  140. package/dist/{native-tree-Z2WYUJEV.cjs → native-tree-WOX3JMBG.cjs} +3 -3
  141. package/dist/{navigation-delegate.d-CSCm8ZxL.d.mts → navigation-delegate.d-DQVYKoaZ.d.mts} +1 -1
  142. package/dist/{navigation-delegate.d-BbUHRXxG.d.ts → navigation-delegate.d-GghbHJuK.d.ts} +1 -1
  143. package/dist/navigation.d.mts +4 -4
  144. package/dist/navigation.d.ts +4 -4
  145. package/dist/plugin.cjs +14 -14
  146. package/dist/plugin.d.mts +3 -3
  147. package/dist/plugin.d.ts +3 -3
  148. package/dist/plugin.mjs +13 -13
  149. package/dist/{production-runtime.d-DgT24A0f.d.ts → production-runtime.d-Bzns3NW9.d.ts} +1 -1
  150. package/dist/{production-runtime.d-CcQiDko5.d.mts → production-runtime.d-DiFa5vHW.d.mts} +1 -1
  151. package/dist/{render-plan.d-CyrX6MDs.d.ts → render-plan.d-CL_Ikfg_.d.ts} +1 -1
  152. package/dist/{render-plan.d-BH9WF-JZ.d.mts → render-plan.d-CcF0MeCf.d.mts} +1 -1
  153. package/dist/renderer-client.d.mts +4 -4
  154. package/dist/renderer-client.d.ts +4 -4
  155. package/dist/{request.d-BB8M8bcD.d.ts → request.d-B1RnTLri.d.ts} +1 -1
  156. package/dist/{request.d-CUrPnCW7.d.mts → request.d-DarDOCk9.d.mts} +1 -1
  157. package/dist/request.d.mts +2 -2
  158. package/dist/request.d.ts +2 -2
  159. package/dist/{route-rendering.d-DYqZMIf4.d.ts → route-rendering.d-BTUYCIj4.d.ts} +1 -1
  160. package/dist/{route-rendering.d-CYxlzaFm.d.mts → route-rendering.d-D_2Ual0-.d.mts} +1 -1
  161. package/dist/{router.d-DaKo507j.d.ts → router.d-CMANF6da.d.ts} +1 -1
  162. package/dist/{router.d-7o24CD8u.d.mts → router.d-Cuv1jntg.d.mts} +1 -1
  163. package/dist/{routes.d-BknKQcTu.d.ts → routes.d-B6yFe6jm.d.ts} +1 -1
  164. package/dist/{routes.d-D1IrO9KK.d.mts → routes.d-c2HKfrfL.d.mts} +1 -1
  165. package/dist/routes.d.mts +1 -1
  166. package/dist/routes.d.ts +1 -1
  167. package/dist/{rsc-pipeline-RFLHDAKD.mjs → rsc-pipeline-3LNVP2OO.mjs} +6 -6
  168. package/dist/{rsc-pipeline-OF2I7PCX.cjs → rsc-pipeline-G5WELVW3.cjs} +7 -7
  169. package/dist/{runtime-LBTK62AD.cjs → runtime-DMEULPE7.cjs} +22 -11
  170. package/dist/{runtime-M6UJCSLA.mjs → runtime-HQJ2LLQL.mjs} +20 -9
  171. package/dist/{runtime.d-CN73a-IL.d.ts → runtime.d-C3RQUj6_.d.ts} +1 -1
  172. package/dist/{runtime.d-CcNuzhX6.d.mts → runtime.d-wvh4ngU0.d.mts} +1 -1
  173. package/dist/server-plugins.d.mts +2 -2
  174. package/dist/server-plugins.d.ts +2 -2
  175. package/dist/server.cjs +31 -31
  176. package/dist/server.d.mts +9 -9
  177. package/dist/server.d.ts +9 -9
  178. package/dist/server.mjs +16 -16
  179. package/dist/{spa-router.d-CNi77LZm.d.mts → spa-router.d-WU_qS5gJ.d.mts} +2 -2
  180. package/dist/{spa-router.d-Cvgf5QP4.d.ts → spa-router.d-m8H_Kl_B.d.ts} +2 -2
  181. package/dist/testing.d.mts +1 -1
  182. package/dist/testing.d.ts +1 -1
  183. package/dist/{utils.d-C3H-14_Y.d.ts → utils.d-C9dQD5Zg.d.ts} +1 -1
  184. package/dist/{utils.d-D8VfzZYn.d.mts → utils.d-W9IiEqmW.d.mts} +1 -1
  185. package/dist/version.cjs +2 -2
  186. package/dist/version.mjs +1 -1
  187. package/dist/vite.cjs +18 -14
  188. package/dist/vite.d.mts +23 -5
  189. package/dist/vite.d.ts +23 -5
  190. package/dist/vite.mjs +17 -13
  191. package/package.json +1 -1
  192. package/dist/analyzer-2AHWJJR7.cjs +0 -15
  193. package/dist/chunk-CSLUBKGG.mjs +0 -44
  194. package/dist/chunk-SGBNF56S.cjs +0 -44
@@ -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,15 +653,15 @@ 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
+ const submitted = options.request.method === "POST";
657
+ const init = submitted ? { method: "POST", headers, body: options.request.body, duplex: "half" } : { method: "GET", headers };
481
658
  const page = await options.renderPage(
482
- new Request(options.request.url, {
483
- method: "GET",
484
- headers,
485
- signal: options.request.signal
486
- })
659
+ new Request(options.request.url, { ...init, signal: options.request.signal })
487
660
  );
661
+ const cookies = _nullishCoalesce(_optionalChain([page, 'access', _35 => _35.headers, 'access', _36 => _36.getSetCookie, 'optionalCall', _37 => _37()]), () => ( []));
488
662
  const type = _nullishCoalesce(page.headers.get("content-type"), () => ( ""));
489
- if (page.status !== 200 || !type.includes("text/html")) return page;
663
+ const drawn = page.status === 200 || submitted && page.status >= 400 && page.status < 500;
664
+ if (!drawn || !type.includes("text/html")) return page;
490
665
  const html = await page.text();
491
666
  const pageUrl = new URL(options.request.url);
492
667
  const load = _nullishCoalesce(options.loadStylesheet, () => ( (async (href) => {
@@ -496,7 +671,7 @@ async function createFarmNativeTreeResponse(options) {
496
671
  signal: options.request.signal
497
672
  })
498
673
  );
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;
674
+ 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
675
  })));
501
676
  const stylesheets = [];
502
677
  for (const source of readFarmPageStylesheets(html, pageUrl)) {
@@ -507,12 +682,13 @@ async function createFarmNativeTreeResponse(options) {
507
682
  root: { type: "View", tag: "#root" },
508
683
  unsupported: [`stylesheet "${source.href}" could not be read`]
509
684
  };
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
- }
685
+ const out2 = new Headers({
686
+ "Content-Type": `${_chunk3HLQTOVUcjs.FARM_NATIVE_TREE_CONTENT_TYPE}; charset=utf-8`,
687
+ Vary: "Accept",
688
+ "Cache-Control": "no-store"
515
689
  });
690
+ for (const cookie of cookies) out2.append("Set-Cookie", cookie);
691
+ return new Response(JSON.stringify(tree2), { headers: out2 });
516
692
  }
517
693
  stylesheets.push(css);
518
694
  }
@@ -520,11 +696,12 @@ async function createFarmNativeTreeResponse(options) {
520
696
  const out = new Headers({
521
697
  "Content-Type": `${_chunk3HLQTOVUcjs.FARM_NATIVE_TREE_CONTENT_TYPE}; charset=utf-8`,
522
698
  Vary: "Accept",
523
- "Cache-Control": _nullishCoalesce(page.headers.get("cache-control"), () => ( "no-store"))
699
+ // The answer to a POST is that submission's result, never a cacheable page.
700
+ "Cache-Control": _nullishCoalesce((submitted ? void 0 : page.headers.get("cache-control")), () => ( "no-store"))
524
701
  });
525
- for (const cookie of _nullishCoalesce(_optionalChain([page, 'access', _25 => _25.headers, 'access', _26 => _26.getSetCookie, 'optionalCall', _27 => _27()]), () => ( []))) out.append("Set-Cookie", cookie);
702
+ for (const cookie of cookies) out.append("Set-Cookie", cookie);
526
703
  return new Response(options.request.method === "HEAD" ? null : JSON.stringify(tree), {
527
- status: 200,
704
+ status: page.status,
528
705
  headers: out
529
706
  });
530
707
  }