@seriousgaming/sdk-tools 1.7.0 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/dist/agent/guidance.md +1 -0
  2. package/dist/{cli-ZTZ5H55T.js → cli-27M4PX7O.js} +17 -17
  3. package/dist/{cli-2BH7FX27.js → cli-2FXZZLCL.js} +1 -1
  4. package/dist/{cli-HHPMAV4F.js → cli-2KDV2DYC.js} +3 -3
  5. package/dist/{cli-57V4ARER.js → cli-2QM63J3I.js} +1 -1
  6. package/dist/{cli-TFMNNVJ7.js → cli-32NRB2IT.js} +15 -15
  7. package/dist/{cli-JPAXKLVT.js → cli-3HBYH4VF.js} +11 -11
  8. package/dist/{cli-JR5AZLLK.js → cli-3HPAKEJJ.js} +2 -2
  9. package/dist/{cli-3PIJLSRQ.js → cli-3HZGJRQW.js} +11 -11
  10. package/dist/{cli-BOXXMDSX.js → cli-3OCKRPXI.js} +18 -18
  11. package/dist/{cli-4CHKF4DQ.js → cli-3OVXQJEW.js} +2 -2
  12. package/dist/{cli-4UWFQNGF.js → cli-3VV2JLHX.js} +1 -1
  13. package/dist/{cli-EJVAQCMQ.js → cli-42ZUP4X3.js} +114 -5
  14. package/dist/{cli-CV4JGVJR.js → cli-4B5OBHSY.js} +19 -19
  15. package/dist/{cli-2DQJACAH.js → cli-4EMNCU63.js} +17 -17
  16. package/dist/cli-5CG6BMCY.js +36 -0
  17. package/dist/{cli-VYR326C6.js → cli-5FRKWNVP.js} +19 -19
  18. package/dist/{cli-TDYKRXUA.js → cli-5P66N5G6.js} +17 -17
  19. package/dist/{cli-ZRPWZOCW.js → cli-5SYPXJCB.js} +20 -16
  20. package/dist/{cli-TJ3PLRHF.js → cli-66AHBZRZ.js} +15 -15
  21. package/dist/{cli-M7WEAIRF.js → cli-6AGWTGTO.js} +106 -28
  22. package/dist/{cli-WG36UJRK.js → cli-6BAZE75K.js} +18 -18
  23. package/dist/{cli-VPON5HGB.js → cli-6FVHRL3H.js} +19 -19
  24. package/dist/{cli-QVASWX2A.js → cli-6GDPO5VU.js} +2 -2
  25. package/dist/{cli-TPNQLYPC.js → cli-6NBER36P.js} +1 -1
  26. package/dist/{cli-LQ4VSM5R.js → cli-726NJARI.js} +0 -0
  27. package/dist/{cli-GHLILDH7.js → cli-72DRYVTT.js} +13 -13
  28. package/dist/{cli-MMN4BPO4.js → cli-7CW2BBJG.js} +1 -1
  29. package/dist/{cli-FP32D3T6.js → cli-7GJGFILU.js} +15 -15
  30. package/dist/{cli-HYEU3QS6.js → cli-7NCVUM5U.js} +3 -3
  31. package/dist/cli-7S4G4EKK.js +110 -0
  32. package/dist/{cli-J4DKUUTK.js → cli-7V6GUIIS.js} +2 -2
  33. package/dist/{cli-N6H6T2E2.js → cli-AEAFLZGY.js} +12 -0
  34. package/dist/{cli-C47GJATR.js → cli-AGYCXRPR.js} +3 -3
  35. package/dist/{cli-XSVGKI3R.js → cli-BC4KKNLA.js} +1 -1
  36. package/dist/cli-BQ3FHENQ.js +16 -0
  37. package/dist/{cli-CXCL7VRK.js → cli-BXCCODYD.js} +20 -20
  38. package/dist/cli-C2XDL4LD.js +30 -0
  39. package/dist/{cli-MJUYJIEP.js → cli-C45A5VX6.js} +3 -3
  40. package/dist/{cli-64AA7367.js → cli-C7YZNPWX.js} +11 -11
  41. package/dist/{cli-ZKG3OPZ6.js → cli-CAX4CQTC.js} +13 -13
  42. package/dist/{cli-YOTGR3NB.js → cli-CVOLMK3Z.js} +1 -1
  43. package/dist/{cli-PKQNOGBO.js → cli-D3CZRXVJ.js} +63 -17
  44. package/dist/{cli-4YB3ROVR.js → cli-DMKRP33X.js} +1 -1
  45. package/dist/{cli-FZ7QAZZP.js → cli-DPFN2LIZ.js} +15 -15
  46. package/dist/{cli-7TOLC62D.js → cli-DT756M3Z.js} +20 -20
  47. package/dist/{cli-TIDQ4WUE.js → cli-DXHPYN4N.js} +1 -1
  48. package/dist/{cli-OANH3BTQ.js → cli-E665NKUQ.js} +5 -5
  49. package/dist/{cli-DEBCP7UH.js → cli-EK7CGMGS.js} +17 -17
  50. package/dist/{cli-PIO7NWMH.js → cli-ESU3J563.js} +15 -15
  51. package/dist/{cli-6HB6HTC6.js → cli-F47ELAXM.js} +47 -47
  52. package/dist/{cli-JIZTQVL2.js → cli-FH4WBZHA.js} +14 -14
  53. package/dist/{cli-JRMHSMYT.js → cli-FHKRO6OU.js} +19 -19
  54. package/dist/{cli-ESA6YNPF.js → cli-FSEDPZR5.js} +19 -19
  55. package/dist/{cli-G5DQGZ2E.js → cli-FV45UZQP.js} +19 -19
  56. package/dist/{cli-XR2XSWQN.js → cli-G7FX7ZIU.js} +12 -12
  57. package/dist/{cli-X7E3637I.js → cli-GFONBOJT.js} +50 -26
  58. package/dist/{cli-C5QOJJWX.js → cli-GHIMH6JU.js} +1 -1
  59. package/dist/{cli-T4HWGMY4.js → cli-HC7L5DXV.js} +15 -15
  60. package/dist/{cli-WU43JT4T.js → cli-HJPNNORV.js} +2 -2
  61. package/dist/{cli-SOMIB4B4.js → cli-HMEZHQBC.js} +17 -17
  62. package/dist/{cli-TFZ53OA2.js → cli-HQUVSAHY.js} +18 -18
  63. package/dist/{cli-MYJGMA6U.js → cli-IC5FOT2J.js} +1 -1
  64. package/dist/{cli-VL2P354N.js → cli-IVZ7AHUJ.js} +3 -3
  65. package/dist/{cli-B6YHEKIJ.js → cli-J2OTL6JH.js} +5 -5
  66. package/dist/{cli-NEOLMC2P.js → cli-JA6UFTSX.js} +17 -17
  67. package/dist/{cli-Z5HWENER.js → cli-JOXCAGM7.js} +19 -19
  68. package/dist/{cli-NOQBWJQN.js → cli-JQ6I5GGE.js} +3 -3
  69. package/dist/{cli-TDSQSCX4.js → cli-K6M6YB67.js} +1 -1
  70. package/dist/{cli-MYJGGLC5.js → cli-KFVA7DT3.js} +3 -3
  71. package/dist/{cli-DHOWZCXT.js → cli-KH6FKM5A.js} +15 -15
  72. package/dist/{cli-4VZIJYKU.js → cli-KMT235FV.js} +2 -2
  73. package/dist/{cli-6ZSMW4HR.js → cli-KU4PG7ZA.js} +15 -15
  74. package/dist/{cli-ATI6OLJU.js → cli-L4DEEAMK.js} +17 -17
  75. package/dist/{cli-EDCAH2TC.js → cli-ME3JKMJL.js} +19 -19
  76. package/dist/{cli-R7RG2VMW.js → cli-MJ65PIYI.js} +15 -15
  77. package/dist/cli-MM2ROZWO.js +36 -0
  78. package/dist/{cli-RZITKPJX.js → cli-MN7X4UG2.js} +1 -1
  79. package/dist/{cli-LE5ICDAF.js → cli-MPU4FLA7.js} +4 -4
  80. package/dist/{cli-HCRTYQQS.js → cli-MPWTXNF6.js} +2 -2
  81. package/dist/{cli-NPPY557S.js → cli-N5K2KHPR.js} +15 -15
  82. package/dist/{cli-PVA52RC2.js → cli-NGOQWOQE.js} +15 -15
  83. package/dist/{cli-ZTWOE3ZT.js → cli-NU4SCD5D.js} +1 -1
  84. package/dist/{cli-UTM4QU67.js → cli-O3IMNLN2.js} +282 -96
  85. package/dist/{cli-MM3A4SPH.js → cli-OUFXSQOW.js} +7265 -4467
  86. package/dist/{cli-UBQCSUDH.js → cli-PEY6XZDE.js} +16 -16
  87. package/dist/{cli-HM7CD4VU.js → cli-PLW3TWJ7.js} +19 -19
  88. package/dist/{cli-LRQDF3ZO.js → cli-PO2ALWHP.js} +13 -13
  89. package/dist/{cli-IPP5FDCH.js → cli-PPEB3ENS.js} +18 -18
  90. package/dist/{cli-C3OERMIR.js → cli-PZ7G544B.js} +3 -3
  91. package/dist/{cli-GPAN6XK2.js → cli-Q5BKFFDL.js} +4 -4
  92. package/dist/{cli-MULKSLA4.js → cli-QAI6T5FL.js} +15 -15
  93. package/dist/{cli-JGFJWZFU.js → cli-QAVLRCQ5.js} +3 -3
  94. package/dist/{cli-OQG3Y4RU.js → cli-QDIH2G2P.js} +15 -15
  95. package/dist/cli-SN7D7HTX.js +36 -0
  96. package/dist/{cli-SWZY7L7K.js → cli-SOQJHK4Q.js} +6 -6
  97. package/dist/{cli-7RYIEKMB.js → cli-SPKPDXWD.js} +15 -15
  98. package/dist/{cli-WAZD75KE.js → cli-SWUAXVIJ.js} +15 -15
  99. package/dist/cli-TJNLXQJ5.js +36 -0
  100. package/dist/{cli-SX3ULO5P.js → cli-U2EWI6H5.js} +11 -11
  101. package/dist/{cli-FXY3DKPW.js → cli-UADUC4JD.js} +2 -2
  102. package/dist/{cli-FWFRKQNE.js → cli-UR63LFVK.js} +2 -2
  103. package/dist/{cli-YSPZZQCP.js → cli-UTHPCZYL.js} +2 -2
  104. package/dist/{cli-XTANOFQR.js → cli-UYV3BDPA.js} +3 -3
  105. package/dist/{cli-H3J3ICCQ.js → cli-UZCQL6YP.js} +3 -3
  106. package/dist/{cli-LQERHJFE.js → cli-V5K3CCYZ.js} +2 -2
  107. package/dist/cli-V7L3HEL4.js +36 -0
  108. package/dist/{cli-GEQUJF4L.js → cli-VBSF3R3L.js} +16 -16
  109. package/dist/{cli-FXWWYBYU.js → cli-VQ4OJ4KE.js} +18 -18
  110. package/dist/{cli-IUS2YCD3.js → cli-VTLFQHDO.js} +1 -1
  111. package/dist/{cli-SOFCTQAL.js → cli-W7XCTGQ7.js} +15 -15
  112. package/dist/{cli-GTWEGYSU.js → cli-W7Y7X3FX.js} +19 -19
  113. package/dist/cli-WWNTBK37.js +1973 -0
  114. package/dist/cli-XPJGW375.js +36 -0
  115. package/dist/{cli-SRHBXZCN.js → cli-Y33ULHYO.js} +1 -1
  116. package/dist/{cli-ZQ2Y3U7F.js → cli-YLYB4ITF.js} +13 -13
  117. package/dist/{cli-4XCQUM3E.js → cli-ZFY6TGU7.js} +4 -4
  118. package/dist/{cli-JRIIAZ33.js → cli-ZSKP2IRP.js} +53 -38
  119. package/dist/cli.js +52 -52
  120. package/dist/client.js +17518 -16558
  121. package/dist/core/save-scenario.d.ts +1 -0
  122. package/dist/core/session-start-gate.d.ts +25 -0
  123. package/dist/core/session.d.ts +4 -0
  124. package/dist/dev/console/assets/{index-CnXlPeLX.js → index-CVNjiRUh.js} +31 -27
  125. package/dist/dev/console/index.html +1 -1
  126. package/dist/docs/api/deck.md +1 -1
  127. package/dist/docs/api/index.md +1 -1
  128. package/dist/docs/api/sdk-e2e.md +7 -6
  129. package/dist/docs/api/sdk-projection.md +1 -0
  130. package/dist/docs/api/sdk-tools-client.md +3 -1
  131. package/dist/docs/api/sdk-tools-playwright.md +1 -8
  132. package/dist/docs/api/sdk-ui.md +40 -64
  133. package/dist/docs/api/sdk.md +10 -1
  134. package/dist/docs/changelog.md +15 -0
  135. package/dist/docs/cli-error-codes.md +7 -1
  136. package/dist/docs/cli-reference.md +3 -0
  137. package/dist/docs/concepts/index.md +1 -0
  138. package/dist/docs/guides/engine.md +5 -0
  139. package/dist/docs/guides/file-handling.md +4 -1
  140. package/dist/docs/guides/llm-integration.md +3 -2
  141. package/dist/docs/guides/multi-team-games.md +2 -0
  142. package/dist/docs/guides/patterns.md +5 -0
  143. package/dist/docs/guides/session.md +1 -1
  144. package/dist/docs/guides/settings.md +2 -0
  145. package/dist/docs/guides/setup.md +23 -2
  146. package/dist/docs/guides/speech-generation.md +1 -0
  147. package/dist/docs/guides/testing.md +2 -0
  148. package/dist/docs/guides/tick-controller.md +2 -0
  149. package/dist/docs/guides/type-safety.md +2 -1
  150. package/dist/docs/guides/ui-files-and-llms.md +3 -1
  151. package/dist/docs/guides/upgrading.md +4 -0
  152. package/dist/docs/guides/validators.md +27 -4
  153. package/dist/docs/guides/waiting-room.md +2 -0
  154. package/dist/docs/page-index.md +8 -6
  155. package/dist/docs/recipes/call-endpoint-from-ui.md +1 -0
  156. package/dist/docs/recipes/create-scenario-editor.md +2 -1
  157. package/dist/docs/recipes/create-setup.md +2 -1
  158. package/dist/docs/recipes/declare-api-uses.md +1 -0
  159. package/dist/docs/recipes/describe-setup-with-endpoint.md +69 -0
  160. package/dist/docs/recipes/index.md +3 -1
  161. package/dist/docs/recipes/share-logic-between-engine-and-ui.md +2 -2
  162. package/dist/docs/recipes/test-user-interface.md +1 -1
  163. package/dist/docs/recipes/validate-scenarios.md +9 -3
  164. package/dist/docs/recipes/write-setup-notes.md +58 -0
  165. package/dist/docs/troubleshooting.md +2 -1
  166. package/dist/execution/executor.d.ts +12 -0
  167. package/dist/execution/scenario-gates.d.ts +40 -0
  168. package/dist/host.js +1082 -467
  169. package/dist/playwright.js +17529 -16569
  170. package/dist/runtime/manifest-version.d.ts +1 -1
  171. package/dist/runtime.js +4 -2
  172. package/dist/setup/setup-notes.d.ts +42 -0
  173. package/dist/templates/package/package.json.liquid +15 -15
  174. package/dist/templates/starter-game/package.json +13 -13
  175. package/dist/utils/error-codes.d.ts +13 -1
  176. package/dist/validation/package-validation.d.ts +1 -1
  177. package/package.json +22 -23
  178. package/dist/cli-57C72YKJ.js +0 -36
  179. package/dist/cli-5G7TZHD3.js +0 -36
  180. package/dist/cli-7MBLH4M3.js +0 -36
  181. package/dist/cli-C6G65H6S.js +0 -256
  182. package/dist/cli-L5IG7MY2.js +0 -36
  183. package/dist/cli-SPGUVL6Z.js +0 -36
  184. package/dist/cli-UY4VDI7W.js +0 -30
  185. package/dist/cli-WM6SQJ6Q.js +0 -16
  186. package/dist/cli-ZBTFLZUL.js +0 -36
  187. package/dist/cli-ZF7IFB54.js +0 -4026
@@ -0,0 +1,1973 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ SKIP,
4
+ asciiAlpha,
5
+ ccount,
6
+ decodeNamedCharacterReference,
7
+ dereference,
8
+ factorySpace,
9
+ factoryWhitespace,
10
+ markdownLineEnding,
11
+ markdownLineEndingOrSpace,
12
+ markdownSpace,
13
+ ok,
14
+ parseSettingPath,
15
+ remarkGfm,
16
+ remarkParse,
17
+ settingPath,
18
+ unicodePunctuation,
19
+ unicodeWhitespace,
20
+ unified,
21
+ visit
22
+ } from "./cli-OUFXSQOW.js";
23
+
24
+ // cli/utils/schema-members.ts
25
+ function memberSchemas(schema, key) {
26
+ const found = [];
27
+ let declared = false;
28
+ const named = schema.properties?.[key];
29
+ if (named !== void 0) {
30
+ declared = true;
31
+ if (typeof named === "object") found.push(named);
32
+ }
33
+ for (const [pattern, child] of Object.entries(schema.patternProperties ?? {})) {
34
+ if (!matches(pattern, key)) continue;
35
+ declared = true;
36
+ if (typeof child === "object") found.push(child);
37
+ }
38
+ if (!declared && typeof schema.additionalProperties === "object") {
39
+ found.push(schema.additionalProperties);
40
+ }
41
+ return found;
42
+ }
43
+ function memberDeclarations(schema) {
44
+ const found = [];
45
+ for (const [key, child] of Object.entries(schema.properties ?? {})) {
46
+ if (typeof child === "object") found.push({ step: key, schema: child });
47
+ }
48
+ for (const [pattern, child] of Object.entries(schema.patternProperties ?? {})) {
49
+ if (typeof child === "object") found.push({ step: `/${pattern}/`, schema: child });
50
+ }
51
+ if (typeof schema.additionalProperties === "object") {
52
+ found.push({ step: "*", schema: schema.additionalProperties });
53
+ }
54
+ return found;
55
+ }
56
+ function matches(pattern, key) {
57
+ try {
58
+ return new RegExp(pattern, "u").test(key);
59
+ } catch {
60
+ return false;
61
+ }
62
+ }
63
+
64
+ // cli/execution/blob-inputs.ts
65
+ var MAX_INLINE_BYTES = 5 * 1024 * 1024;
66
+ function blobValues(declared, value, path = [], root = declared) {
67
+ if (!declared || typeof declared !== "object" || !root) return [];
68
+ const schema = dereference(root, declared);
69
+ const spec = schema.blob;
70
+ if (spec) return value === void 0 ? [] : [{ path, spec, value }];
71
+ if (Array.isArray(value) && schema.items && !Array.isArray(schema.items)) {
72
+ const items = schema.items;
73
+ return value.flatMap((item, at) => blobValues(items, item, [...path, at], root));
74
+ }
75
+ if (value && typeof value === "object" && !Array.isArray(value)) {
76
+ return Object.entries(value).flatMap(
77
+ ([key, member]) => memberSchemas(schema, key).flatMap(
78
+ (child) => blobValues(child, member, [...path, key], root)
79
+ )
80
+ );
81
+ }
82
+ return [];
83
+ }
84
+ function accepts(spec, mimeType) {
85
+ if (!spec.accept || spec.accept.length === 0) return true;
86
+ const type = mimeType.toLowerCase();
87
+ return spec.accept.some((pattern) => {
88
+ const wanted = pattern.toLowerCase();
89
+ return wanted.endsWith("/*") ? type.startsWith(wanted.slice(0, -1)) : type === wanted;
90
+ });
91
+ }
92
+ function sniffMimeType(data) {
93
+ const starts = (...bytes) => bytes.every((byte, at) => data[at] === byte);
94
+ if (starts(137, 80, 78, 71, 13, 10, 26, 10)) return "image/png";
95
+ if (starts(255, 216, 255)) return "image/jpeg";
96
+ if (starts(71, 73, 70, 56)) return "image/gif";
97
+ if (starts(82, 73, 70, 70) && data[8] === 87 && data[9] === 69) return "image/webp";
98
+ if (starts(37, 80, 68, 70)) return "application/pdf";
99
+ return void 0;
100
+ }
101
+ function parseDataUri(value) {
102
+ const match = /^data:([^;,]+)((?:;[^;,=]+=[^;,]*)*);base64,(.*)$/s.exec(value);
103
+ if (!match) return void 0;
104
+ const [, mimeType, params, body] = match;
105
+ const name = /;name=([^;,]*)/.exec(params ?? "")?.[1] ?? "upload";
106
+ const binary = atob((body ?? "").replace(/\s/g, ""));
107
+ const data = new Uint8Array(binary.length);
108
+ for (let at = 0; at < binary.length; at += 1) data[at] = binary.charCodeAt(at);
109
+ return { mimeType: (mimeType ?? "").trim(), name: decodeURIComponent(name), data };
110
+ }
111
+ function where(path) {
112
+ return path.length === 0 ? "(root)" : `/${path.join("/")}`;
113
+ }
114
+ function set(target, path, value) {
115
+ if (path.length === 0) return value;
116
+ const [head, ...rest] = path;
117
+ if (Array.isArray(target)) {
118
+ const copy = [...target];
119
+ copy[head] = set(copy[head], rest, value);
120
+ return copy;
121
+ }
122
+ const record = target;
123
+ return { ...record, [head]: set(record[head], rest, value) };
124
+ }
125
+ async function resolveBlobInputs(identifier, schema, request, store, options = {}) {
126
+ const fail = (path, why) => {
127
+ throw new Error(`Endpoint "${identifier}" rejected the request: ${where(path)} ${why}`);
128
+ };
129
+ let resolved = request;
130
+ for (const { path, spec, value } of blobValues(schema, request)) {
131
+ if (typeof value !== "string") fail(path, "must be a blob: reference or a data: URI");
132
+ const uri = value;
133
+ if (uri.startsWith("blob:")) {
134
+ const blob = await store.describe(uri.slice("blob:".length));
135
+ if (!blob) fail(path, `names a blob this session does not hold`);
136
+ if (options.draft && blob.retention !== "scenario") {
137
+ fail(
138
+ path,
139
+ `names a session's file, which a scenario draft cannot read. Upload the file to the draft, or send it inline`
140
+ );
141
+ }
142
+ if (!accepts(spec, blob.mimeType)) {
143
+ fail(path, `is ${blob.mimeType}, which is not one of ${spec.accept?.join(", ")}`);
144
+ }
145
+ if (spec.maxBytes !== void 0 && blob.size > spec.maxBytes) {
146
+ fail(path, `is ${blob.size} bytes, over the ${spec.maxBytes} allowed`);
147
+ }
148
+ continue;
149
+ }
150
+ if (!uri.startsWith("data:")) fail(path, "must be a blob: reference or a data: URI");
151
+ const encoded = uri.length - uri.indexOf(",") - 1;
152
+ if (Math.floor(encoded * 3 / 4) > MAX_INLINE_BYTES + 2) {
153
+ fail(
154
+ path,
155
+ `carries more than the ${MAX_INLINE_BYTES} bytes a data: URI may carry inline. Upload it and send the blob: reference`
156
+ );
157
+ }
158
+ const parsed = parseDataUri(uri);
159
+ if (!parsed) fail(path, "is not a base64 data: URI");
160
+ const { data, mimeType, name } = parsed;
161
+ const limit = Math.min(spec.maxBytes ?? MAX_INLINE_BYTES, MAX_INLINE_BYTES);
162
+ if (data.length > limit) {
163
+ fail(
164
+ path,
165
+ data.length > MAX_INLINE_BYTES ? `carries ${data.length} bytes inline, over the ${MAX_INLINE_BYTES} a data: URI may carry. Upload it and send the blob: reference` : `is ${data.length} bytes, over the ${limit} allowed`
166
+ );
167
+ }
168
+ const sniffed = sniffMimeType(data);
169
+ if (sniffed !== void 0 && sniffed !== mimeType.toLowerCase()) {
170
+ fail(path, `claims ${mimeType}, but its bytes are ${sniffed}`);
171
+ }
172
+ if (!accepts(spec, mimeType)) {
173
+ fail(path, `is ${mimeType}, which is not one of ${spec.accept?.join(", ")}`);
174
+ }
175
+ const id = await store.store(data, name, mimeType);
176
+ resolved = set(resolved, path, `blob:${id}`);
177
+ }
178
+ return resolved;
179
+ }
180
+
181
+ // cli/validation/file-settings.ts
182
+ function fileSettingValues(declared, value, path = [], root = declared) {
183
+ if (!declared || typeof declared !== "object" || !root) return [];
184
+ const schema = dereference(root, declared);
185
+ const spec = schema.blob;
186
+ if (spec) return value === void 0 ? [] : [{ path, spec, value }];
187
+ if (Array.isArray(value) && schema.items && !Array.isArray(schema.items)) {
188
+ const items = schema.items;
189
+ return value.flatMap(
190
+ (item, at) => fileSettingValues(items, item, [...path, String(at)], root)
191
+ );
192
+ }
193
+ if (value && typeof value === "object" && !Array.isArray(value)) {
194
+ return Object.entries(value).flatMap(
195
+ ([key, member]) => memberSchemas(schema, key).flatMap(
196
+ (child) => fileSettingValues(child, member, [...path, key], root)
197
+ )
198
+ );
199
+ }
200
+ return [];
201
+ }
202
+ function fileSettingDeclarations(root, declared = root, path = [], followed = /* @__PURE__ */ new Set()) {
203
+ if (typeof declared.$ref === "string") {
204
+ if (followed.has(declared.$ref)) return [];
205
+ followed.add(declared.$ref);
206
+ }
207
+ const schema = dereference(root, declared);
208
+ const found = [];
209
+ if ("blob" in schema) found.push({ path, schema });
210
+ for (const { step, schema: child } of memberDeclarations(schema)) {
211
+ found.push(...fileSettingDeclarations(root, child, [...path, step], followed));
212
+ }
213
+ if (schema.items && !Array.isArray(schema.items) && typeof schema.items === "object") {
214
+ found.push(...fileSettingDeclarations(root, schema.items, [...path, "[]"], followed));
215
+ }
216
+ return found;
217
+ }
218
+ var MEDIA_TYPE = /^[^/\s]+\/[^/\s]+$/;
219
+ function where2(identifier, path) {
220
+ return settingPath(identifier, ...path);
221
+ }
222
+ function fileSettingDeclarationErrors(identifier, settingsSchema) {
223
+ const errors = [];
224
+ for (const { path, schema } of fileSettingDeclarations(settingsSchema)) {
225
+ const setting = `Settings "${identifier}" property "${path.join(".")}"`;
226
+ if (schema.type !== "string") {
227
+ errors.push(`${setting} carries \`blob\`, which marks a file, but is not a string`);
228
+ }
229
+ const spec = schema.blob;
230
+ if (typeof spec !== "object" || spec === null || Array.isArray(spec)) {
231
+ errors.push(`${setting}: \`blob\` must be an object of \`accept\` and \`maxBytes\``);
232
+ continue;
233
+ }
234
+ const { accept, maxBytes, ...rest } = spec;
235
+ if (accept !== void 0 && !(Array.isArray(accept) && accept.every((type) => typeof type === "string" && MEDIA_TYPE.test(type)))) {
236
+ errors.push(
237
+ `${setting}: \`blob.accept\` must be an array of media types, such as ["image/png", "image/*"]`
238
+ );
239
+ }
240
+ if (maxBytes !== void 0 && !(typeof maxBytes === "number" && Number.isInteger(maxBytes) && maxBytes > 0)) {
241
+ errors.push(`${setting}: \`blob.maxBytes\` must be a positive whole number of bytes`);
242
+ }
243
+ for (const key of Object.keys(rest)) {
244
+ errors.push(
245
+ `${setting}: \`blob\` has no "${key}"; it takes \`accept\` and \`maxBytes\``
246
+ );
247
+ }
248
+ }
249
+ for (const [key, property] of Object.entries(settingsSchema.properties ?? {})) {
250
+ if (typeof property !== "object" || !("default" in property)) continue;
251
+ for (const { path, value } of fileSettingValues(
252
+ property,
253
+ property.default,
254
+ [],
255
+ settingsSchema
256
+ )) {
257
+ if (typeof value !== "string" || value === "" || value.startsWith("shared:")) {
258
+ continue;
259
+ }
260
+ errors.push(
261
+ `Settings "${identifier}" property "${settingPath(key, ...path)}" holds a file and defaults to ${JSON.stringify(value)}. A default resolves with no scenario active, so it must be empty for no file or a \`shared:\` reference`
262
+ );
263
+ }
264
+ }
265
+ return errors;
266
+ }
267
+ async function packageFileSettingErrors(owner, settings, schemas, resolve, skip = () => false) {
268
+ const errors = [];
269
+ for (const [identifier, value] of Object.entries(settings)) {
270
+ for (const file of fileSettingValues(schemas[identifier], value)) {
271
+ if (typeof file.value !== "string" || file.value === "" || skip(file.value)) continue;
272
+ const setting = `${owner} sets ${where2(identifier, file.path)} to ${JSON.stringify(file.value)}`;
273
+ if (file.value.startsWith("blob:")) {
274
+ errors.push(
275
+ `${setting}, an upload, which a package cannot carry. Ship the file under the scenario's assets/ or shared-assets/ and reference it as asset: or shared:`
276
+ );
277
+ continue;
278
+ }
279
+ const found = await resolve(file.value);
280
+ if (!found) {
281
+ errors.push(`${setting}, but the package ships no such file`);
282
+ continue;
283
+ }
284
+ errors.push(...specErrors(setting, file.spec, found));
285
+ }
286
+ }
287
+ return errors;
288
+ }
289
+ async function fileSettingWriteErrors(overrides, schemas, describeBlob, options = {}) {
290
+ const errors = [];
291
+ for (const [identifier, value] of Object.entries(overrides)) {
292
+ for (const file of fileSettingValues(schemas[identifier], value)) {
293
+ if (typeof file.value !== "string" || !file.value.startsWith("blob:")) continue;
294
+ const setting = `Setting ${where2(identifier, file.path)}`;
295
+ const found = await describeBlob(file.value);
296
+ if (!found) {
297
+ errors.push(
298
+ `${setting} names ${file.value}, which is not a stored blob. Upload the file first and use the reference it returns`
299
+ );
300
+ continue;
301
+ }
302
+ if (options.draft && found.retention !== "scenario") {
303
+ errors.push(
304
+ `${setting} names ${file.value}, a session's file, which a scenario draft cannot read. Upload the file to the draft and use the reference it returns`
305
+ );
306
+ continue;
307
+ }
308
+ errors.push(...specErrors(`${setting} names ${file.value}, which`, file.spec, found));
309
+ }
310
+ }
311
+ return errors;
312
+ }
313
+ function specErrors(subject, spec, file) {
314
+ const errors = [];
315
+ if (!accepts(spec, file.mimeType)) {
316
+ errors.push(`${subject} is ${file.mimeType}, not one of ${spec.accept?.join(", ")}`);
317
+ }
318
+ if (spec.maxBytes !== void 0 && file.size > spec.maxBytes) {
319
+ errors.push(`${subject} is ${file.size} bytes, over the ${spec.maxBytes} allowed`);
320
+ }
321
+ return errors;
322
+ }
323
+
324
+ // cli/guide/locale.ts
325
+ function referenceLocale(locales) {
326
+ const declared = Object.keys(locales);
327
+ return declared.includes("en") ? "en" : declared[0];
328
+ }
329
+
330
+ // ../node_modules/.pnpm/character-entities-legacy@3.0.0/node_modules/character-entities-legacy/index.js
331
+ var characterEntitiesLegacy = [
332
+ "AElig",
333
+ "AMP",
334
+ "Aacute",
335
+ "Acirc",
336
+ "Agrave",
337
+ "Aring",
338
+ "Atilde",
339
+ "Auml",
340
+ "COPY",
341
+ "Ccedil",
342
+ "ETH",
343
+ "Eacute",
344
+ "Ecirc",
345
+ "Egrave",
346
+ "Euml",
347
+ "GT",
348
+ "Iacute",
349
+ "Icirc",
350
+ "Igrave",
351
+ "Iuml",
352
+ "LT",
353
+ "Ntilde",
354
+ "Oacute",
355
+ "Ocirc",
356
+ "Ograve",
357
+ "Oslash",
358
+ "Otilde",
359
+ "Ouml",
360
+ "QUOT",
361
+ "REG",
362
+ "THORN",
363
+ "Uacute",
364
+ "Ucirc",
365
+ "Ugrave",
366
+ "Uuml",
367
+ "Yacute",
368
+ "aacute",
369
+ "acirc",
370
+ "acute",
371
+ "aelig",
372
+ "agrave",
373
+ "amp",
374
+ "aring",
375
+ "atilde",
376
+ "auml",
377
+ "brvbar",
378
+ "ccedil",
379
+ "cedil",
380
+ "cent",
381
+ "copy",
382
+ "curren",
383
+ "deg",
384
+ "divide",
385
+ "eacute",
386
+ "ecirc",
387
+ "egrave",
388
+ "eth",
389
+ "euml",
390
+ "frac12",
391
+ "frac14",
392
+ "frac34",
393
+ "gt",
394
+ "iacute",
395
+ "icirc",
396
+ "iexcl",
397
+ "igrave",
398
+ "iquest",
399
+ "iuml",
400
+ "laquo",
401
+ "lt",
402
+ "macr",
403
+ "micro",
404
+ "middot",
405
+ "nbsp",
406
+ "not",
407
+ "ntilde",
408
+ "oacute",
409
+ "ocirc",
410
+ "ograve",
411
+ "ordf",
412
+ "ordm",
413
+ "oslash",
414
+ "otilde",
415
+ "ouml",
416
+ "para",
417
+ "plusmn",
418
+ "pound",
419
+ "quot",
420
+ "raquo",
421
+ "reg",
422
+ "sect",
423
+ "shy",
424
+ "sup1",
425
+ "sup2",
426
+ "sup3",
427
+ "szlig",
428
+ "thorn",
429
+ "times",
430
+ "uacute",
431
+ "ucirc",
432
+ "ugrave",
433
+ "uml",
434
+ "uuml",
435
+ "yacute",
436
+ "yen",
437
+ "yuml"
438
+ ];
439
+
440
+ // ../node_modules/.pnpm/character-reference-invalid@2.0.1/node_modules/character-reference-invalid/index.js
441
+ var characterReferenceInvalid = {
442
+ 0: "\uFFFD",
443
+ 128: "\u20AC",
444
+ 130: "\u201A",
445
+ 131: "\u0192",
446
+ 132: "\u201E",
447
+ 133: "\u2026",
448
+ 134: "\u2020",
449
+ 135: "\u2021",
450
+ 136: "\u02C6",
451
+ 137: "\u2030",
452
+ 138: "\u0160",
453
+ 139: "\u2039",
454
+ 140: "\u0152",
455
+ 142: "\u017D",
456
+ 145: "\u2018",
457
+ 146: "\u2019",
458
+ 147: "\u201C",
459
+ 148: "\u201D",
460
+ 149: "\u2022",
461
+ 150: "\u2013",
462
+ 151: "\u2014",
463
+ 152: "\u02DC",
464
+ 153: "\u2122",
465
+ 154: "\u0161",
466
+ 155: "\u203A",
467
+ 156: "\u0153",
468
+ 158: "\u017E",
469
+ 159: "\u0178"
470
+ };
471
+
472
+ // ../node_modules/.pnpm/is-decimal@2.0.1/node_modules/is-decimal/index.js
473
+ function isDecimal(character) {
474
+ const code = typeof character === "string" ? character.charCodeAt(0) : character;
475
+ return code >= 48 && code <= 57;
476
+ }
477
+
478
+ // ../node_modules/.pnpm/is-hexadecimal@2.0.1/node_modules/is-hexadecimal/index.js
479
+ function isHexadecimal(character) {
480
+ const code = typeof character === "string" ? character.charCodeAt(0) : character;
481
+ return code >= 97 && code <= 102 || code >= 65 && code <= 70 || code >= 48 && code <= 57;
482
+ }
483
+
484
+ // ../node_modules/.pnpm/is-alphabetical@2.0.1/node_modules/is-alphabetical/index.js
485
+ function isAlphabetical(character) {
486
+ const code = typeof character === "string" ? character.charCodeAt(0) : character;
487
+ return code >= 97 && code <= 122 || code >= 65 && code <= 90;
488
+ }
489
+
490
+ // ../node_modules/.pnpm/is-alphanumerical@2.0.1/node_modules/is-alphanumerical/index.js
491
+ function isAlphanumerical(character) {
492
+ return isAlphabetical(character) || isDecimal(character);
493
+ }
494
+
495
+ // ../node_modules/.pnpm/parse-entities@4.0.2/node_modules/parse-entities/lib/index.js
496
+ var messages = [
497
+ "",
498
+ /* 1: Non terminated (named) */
499
+ "Named character references must be terminated by a semicolon",
500
+ /* 2: Non terminated (numeric) */
501
+ "Numeric character references must be terminated by a semicolon",
502
+ /* 3: Empty (named) */
503
+ "Named character references cannot be empty",
504
+ /* 4: Empty (numeric) */
505
+ "Numeric character references cannot be empty",
506
+ /* 5: Unknown (named) */
507
+ "Named character references must be known",
508
+ /* 6: Disallowed (numeric) */
509
+ "Numeric character references cannot be disallowed",
510
+ /* 7: Prohibited (numeric) */
511
+ "Numeric character references cannot be outside the permissible Unicode range"
512
+ ];
513
+ function parseEntities(value, options) {
514
+ const settings = options || {};
515
+ const additional = typeof settings.additional === "string" ? settings.additional.charCodeAt(0) : settings.additional;
516
+ const result = [];
517
+ let index = 0;
518
+ let lines = -1;
519
+ let queue = "";
520
+ let point2;
521
+ let indent;
522
+ if (settings.position) {
523
+ if ("start" in settings.position || "indent" in settings.position) {
524
+ indent = settings.position.indent;
525
+ point2 = settings.position.start;
526
+ } else {
527
+ point2 = settings.position;
528
+ }
529
+ }
530
+ let line = (point2 ? point2.line : 0) || 1;
531
+ let column = (point2 ? point2.column : 0) || 1;
532
+ let previous2 = now();
533
+ let character;
534
+ index--;
535
+ while (++index <= value.length) {
536
+ if (character === 10) {
537
+ column = (indent ? indent[lines] : 0) || 1;
538
+ }
539
+ character = value.charCodeAt(index);
540
+ if (character === 38) {
541
+ const following = value.charCodeAt(index + 1);
542
+ if (following === 9 || following === 10 || following === 12 || following === 32 || following === 38 || following === 60 || Number.isNaN(following) || additional && following === additional) {
543
+ queue += String.fromCharCode(character);
544
+ column++;
545
+ continue;
546
+ }
547
+ const start = index + 1;
548
+ let begin = start;
549
+ let end = start;
550
+ let type;
551
+ if (following === 35) {
552
+ end = ++begin;
553
+ const following2 = value.charCodeAt(end);
554
+ if (following2 === 88 || following2 === 120) {
555
+ type = "hexadecimal";
556
+ end = ++begin;
557
+ } else {
558
+ type = "decimal";
559
+ }
560
+ } else {
561
+ type = "named";
562
+ }
563
+ let characterReferenceCharacters = "";
564
+ let characterReference = "";
565
+ let characters = "";
566
+ const test = type === "named" ? isAlphanumerical : type === "decimal" ? isDecimal : isHexadecimal;
567
+ end--;
568
+ while (++end <= value.length) {
569
+ const following2 = value.charCodeAt(end);
570
+ if (!test(following2)) {
571
+ break;
572
+ }
573
+ characters += String.fromCharCode(following2);
574
+ if (type === "named" && characterEntitiesLegacy.includes(characters)) {
575
+ characterReferenceCharacters = characters;
576
+ characterReference = decodeNamedCharacterReference(characters);
577
+ }
578
+ }
579
+ let terminated = value.charCodeAt(end) === 59;
580
+ if (terminated) {
581
+ end++;
582
+ const namedReference = type === "named" ? decodeNamedCharacterReference(characters) : false;
583
+ if (namedReference) {
584
+ characterReferenceCharacters = characters;
585
+ characterReference = namedReference;
586
+ }
587
+ }
588
+ let diff = 1 + end - start;
589
+ let reference = "";
590
+ if (!terminated && settings.nonTerminated === false) {
591
+ } else if (!characters) {
592
+ if (type !== "named") {
593
+ warning(4, diff);
594
+ }
595
+ } else if (type === "named") {
596
+ if (terminated && !characterReference) {
597
+ warning(5, 1);
598
+ } else {
599
+ if (characterReferenceCharacters !== characters) {
600
+ end = begin + characterReferenceCharacters.length;
601
+ diff = 1 + end - begin;
602
+ terminated = false;
603
+ }
604
+ if (!terminated) {
605
+ const reason = characterReferenceCharacters ? 1 : 3;
606
+ if (settings.attribute) {
607
+ const following2 = value.charCodeAt(end);
608
+ if (following2 === 61) {
609
+ warning(reason, diff);
610
+ characterReference = "";
611
+ } else if (isAlphanumerical(following2)) {
612
+ characterReference = "";
613
+ } else {
614
+ warning(reason, diff);
615
+ }
616
+ } else {
617
+ warning(reason, diff);
618
+ }
619
+ }
620
+ }
621
+ reference = characterReference;
622
+ } else {
623
+ if (!terminated) {
624
+ warning(2, diff);
625
+ }
626
+ let referenceCode = Number.parseInt(
627
+ characters,
628
+ type === "hexadecimal" ? 16 : 10
629
+ );
630
+ if (prohibited(referenceCode)) {
631
+ warning(7, diff);
632
+ reference = String.fromCharCode(
633
+ 65533
634
+ /* `�` */
635
+ );
636
+ } else if (referenceCode in characterReferenceInvalid) {
637
+ warning(6, diff);
638
+ reference = characterReferenceInvalid[referenceCode];
639
+ } else {
640
+ let output = "";
641
+ if (disallowed(referenceCode)) {
642
+ warning(6, diff);
643
+ }
644
+ if (referenceCode > 65535) {
645
+ referenceCode -= 65536;
646
+ output += String.fromCharCode(
647
+ referenceCode >>> (10 & 1023) | 55296
648
+ );
649
+ referenceCode = 56320 | referenceCode & 1023;
650
+ }
651
+ reference = output + String.fromCharCode(referenceCode);
652
+ }
653
+ }
654
+ if (reference) {
655
+ flush();
656
+ previous2 = now();
657
+ index = end - 1;
658
+ column += end - start + 1;
659
+ result.push(reference);
660
+ const next = now();
661
+ next.offset++;
662
+ if (settings.reference) {
663
+ settings.reference.call(
664
+ settings.referenceContext || void 0,
665
+ reference,
666
+ { start: previous2, end: next },
667
+ value.slice(start - 1, end)
668
+ );
669
+ }
670
+ previous2 = next;
671
+ } else {
672
+ characters = value.slice(start - 1, end);
673
+ queue += characters;
674
+ column += characters.length;
675
+ index = end - 1;
676
+ }
677
+ } else {
678
+ if (character === 10) {
679
+ line++;
680
+ lines++;
681
+ column = 0;
682
+ }
683
+ if (Number.isNaN(character)) {
684
+ flush();
685
+ } else {
686
+ queue += String.fromCharCode(character);
687
+ column++;
688
+ }
689
+ }
690
+ }
691
+ return result.join("");
692
+ function now() {
693
+ return {
694
+ line,
695
+ column,
696
+ offset: index + ((point2 ? point2.offset : 0) || 0)
697
+ };
698
+ }
699
+ function warning(code, offset) {
700
+ let position;
701
+ if (settings.warning) {
702
+ position = now();
703
+ position.column += offset;
704
+ position.offset += offset;
705
+ settings.warning.call(
706
+ settings.warningContext || void 0,
707
+ messages[code],
708
+ position,
709
+ code
710
+ );
711
+ }
712
+ }
713
+ function flush() {
714
+ if (queue) {
715
+ result.push(queue);
716
+ if (settings.text) {
717
+ settings.text.call(settings.textContext || void 0, queue, {
718
+ start: previous2,
719
+ end: now()
720
+ });
721
+ }
722
+ queue = "";
723
+ }
724
+ }
725
+ }
726
+ function prohibited(code) {
727
+ return code >= 55296 && code <= 57343 || code > 1114111;
728
+ }
729
+ function disallowed(code) {
730
+ return code >= 1 && code <= 8 || code === 11 || code >= 13 && code <= 31 || code >= 127 && code <= 159 || code >= 64976 && code <= 65007 || (code & 65535) === 65535 || (code & 65535) === 65534;
731
+ }
732
+
733
+ // ../node_modules/.pnpm/stringify-entities@4.0.4/node_modules/stringify-entities/lib/core.js
734
+ var defaultSubsetRegex = /["&'<>`]/g;
735
+ var surrogatePairsRegex = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
736
+ var controlCharactersRegex = (
737
+ // eslint-disable-next-line no-control-regex, unicorn/no-hex-escape
738
+ /[\x01-\t\v\f\x0E-\x1F\x7F\x81\x8D\x8F\x90\x9D\xA0-\uFFFF]/g
739
+ );
740
+ var regexEscapeRegex = /[|\\{}()[\]^$+*?.]/g;
741
+ var subsetToRegexCache = /* @__PURE__ */ new WeakMap();
742
+ function core(value, options) {
743
+ value = value.replace(
744
+ options.subset ? charactersToExpressionCached(options.subset) : defaultSubsetRegex,
745
+ basic
746
+ );
747
+ if (options.subset || options.escapeOnly) {
748
+ return value;
749
+ }
750
+ return value.replace(surrogatePairsRegex, surrogate).replace(controlCharactersRegex, basic);
751
+ function surrogate(pair, index, all) {
752
+ return options.format(
753
+ (pair.charCodeAt(0) - 55296) * 1024 + pair.charCodeAt(1) - 56320 + 65536,
754
+ all.charCodeAt(index + 2),
755
+ options
756
+ );
757
+ }
758
+ function basic(character, index, all) {
759
+ return options.format(
760
+ character.charCodeAt(0),
761
+ all.charCodeAt(index + 1),
762
+ options
763
+ );
764
+ }
765
+ }
766
+ function charactersToExpressionCached(subset) {
767
+ let cached = subsetToRegexCache.get(subset);
768
+ if (!cached) {
769
+ cached = charactersToExpression(subset);
770
+ subsetToRegexCache.set(subset, cached);
771
+ }
772
+ return cached;
773
+ }
774
+ function charactersToExpression(subset) {
775
+ const groups = [];
776
+ let index = -1;
777
+ while (++index < subset.length) {
778
+ groups.push(subset[index].replace(regexEscapeRegex, "\\$&"));
779
+ }
780
+ return new RegExp("(?:" + groups.join("|") + ")", "g");
781
+ }
782
+
783
+ // ../node_modules/.pnpm/stringify-entities@4.0.4/node_modules/stringify-entities/lib/util/format-basic.js
784
+ function formatBasic(code) {
785
+ return "&#x" + code.toString(16).toUpperCase() + ";";
786
+ }
787
+
788
+ // ../node_modules/.pnpm/stringify-entities@4.0.4/node_modules/stringify-entities/lib/index.js
789
+ function stringifyEntitiesLight(value, options) {
790
+ return core(value, Object.assign({ format: formatBasic }, options));
791
+ }
792
+
793
+ // ../node_modules/.pnpm/mdast-util-directive@3.2.0/node_modules/mdast-util-directive/lib/index.js
794
+ var own = {}.hasOwnProperty;
795
+ var emptyFromMarkdownOptions = {};
796
+ var emptyOptions = {};
797
+ var shortcut = /^[^\t\n\r "#'.<=>`}]+$/;
798
+ var unquoted = /^[^\t\n\r "'<=>`}]+$/;
799
+ function directiveFromMarkdown(options) {
800
+ const settings = options || emptyFromMarkdownOptions;
801
+ return {
802
+ canContainEols: ["textDirective"],
803
+ enter: {
804
+ directiveContainer: enterContainer,
805
+ directiveContainerAttributes: enterAttributes,
806
+ directiveContainerLabel: enterContainerLabel,
807
+ directiveLeaf: enterLeaf,
808
+ directiveLeafAttributes: enterAttributes,
809
+ directiveText: enterText,
810
+ directiveTextAttributes: enterAttributes
811
+ },
812
+ exit: {
813
+ directiveContainer: exit,
814
+ directiveContainerAttributeClass: exitAttributeShortcut,
815
+ directiveContainerAttributeClassValue: exitAttributeClassValue,
816
+ directiveContainerAttributeId: exitAttributeShortcut,
817
+ directiveContainerAttributeIdValue: exitAttributeIdValue,
818
+ directiveContainerAttributeName: exitAttributeName,
819
+ directiveContainerAttributeValue: exitAttributeValue,
820
+ directiveContainerAttributeValueLiteral: exitAttributeValueLiteral,
821
+ directiveContainerAttributes: exitAttributes,
822
+ directiveContainerLabel: exitContainerLabel,
823
+ directiveContainerName: exitName,
824
+ directiveContainerSequence: exitSequence,
825
+ directiveLeaf: exit,
826
+ directiveLeafAttributeClass: exitAttributeShortcut,
827
+ directiveLeafAttributeClassValue: exitAttributeClassValue,
828
+ directiveLeafAttributeId: exitAttributeShortcut,
829
+ directiveLeafAttributeIdValue: exitAttributeIdValue,
830
+ directiveLeafAttributeName: exitAttributeName,
831
+ directiveLeafAttributeValue: exitAttributeValue,
832
+ directiveLeafAttributeValueLiteral: exitAttributeValueLiteral,
833
+ directiveLeafAttributes: exitAttributes,
834
+ directiveLeafLabel: exitLabel,
835
+ directiveLeafName: exitName,
836
+ directiveLeafSequence: exitSequence,
837
+ directiveText: exit,
838
+ directiveTextAttributeClass: exitAttributeShortcut,
839
+ directiveTextAttributeClassValue: exitAttributeClassValue,
840
+ directiveTextAttributeId: exitAttributeShortcut,
841
+ directiveTextAttributeIdValue: exitAttributeIdValue,
842
+ directiveTextAttributeName: exitAttributeName,
843
+ directiveTextAttributeValue: exitAttributeValue,
844
+ directiveTextAttributeValueLiteral: exitAttributeValueLiteral,
845
+ directiveTextAttributes: exitAttributes,
846
+ directiveTextLabel: exitLabel,
847
+ directiveTextMarker: exitSequence,
848
+ directiveTextName: exitName
849
+ }
850
+ };
851
+ function exitSequence(token) {
852
+ if (!settings.verbose) return;
853
+ const node = this.stack[this.stack.length - 1];
854
+ ok(node, "expected `node`");
855
+ ok(
856
+ node.type === "containerDirective" || node.type === "leafDirective" || node.type === "textDirective"
857
+ );
858
+ const place = { start: point(token.start), end: point(token.end) };
859
+ if (node.data && node.data.position) {
860
+ ok(node.type === "containerDirective");
861
+ node.data.position.closing = place;
862
+ } else {
863
+ node.data = { position: { opening: place } };
864
+ }
865
+ }
866
+ }
867
+ function directiveToMarkdown(options) {
868
+ const settings = options || emptyOptions;
869
+ if (settings.quote !== '"' && settings.quote !== "'" && settings.quote !== null && settings.quote !== void 0) {
870
+ throw new Error(
871
+ "Invalid quote `" + settings.quote + "`, expected `'` or `\"`"
872
+ );
873
+ }
874
+ handleDirective.peek = peekDirective;
875
+ return {
876
+ handlers: {
877
+ containerDirective: handleDirective,
878
+ leafDirective: handleDirective,
879
+ textDirective: handleDirective
880
+ },
881
+ unsafe: [
882
+ {
883
+ character: "\r",
884
+ inConstruct: ["leafDirectiveLabel", "containerDirectiveLabel"]
885
+ },
886
+ {
887
+ character: "\n",
888
+ inConstruct: ["leafDirectiveLabel", "containerDirectiveLabel"]
889
+ },
890
+ {
891
+ after: "[^\\s\\p{P}\\p{S}]",
892
+ before: "[^:]",
893
+ character: ":",
894
+ inConstruct: ["phrasing"],
895
+ unicode: true
896
+ },
897
+ { afterNode: "textDirective", character: ":", inConstruct: ["phrasing"] },
898
+ { atBreak: true, before: ":+", character: ":" }
899
+ ]
900
+ };
901
+ function handleDirective(node, _, state, info) {
902
+ const tracker = state.createTracker(info);
903
+ const exit2 = state.enter(node.type);
904
+ let content;
905
+ if (node.type === "containerDirective") {
906
+ const head = (node.children || [])[0];
907
+ const children = inlineDirectiveLabel(head) ? node.children.slice(1) : node.children;
908
+ if (children && children.length > 0) {
909
+ const current = tracker.current();
910
+ content = state.containerFlow(
911
+ { ...node, children },
912
+ {
913
+ now: { line: current.now.line + 1, column: 1 + current.lineShift },
914
+ lineShift: current.lineShift
915
+ }
916
+ );
917
+ }
918
+ }
919
+ const sequence = fence(node, content ? longestColonLine(content) : 0);
920
+ let value = tracker.move(sequence + (node.name || ""));
921
+ const attributesValue = attributes4(node, state);
922
+ const after = info.after.charCodeAt(0);
923
+ let label4;
924
+ if (node.type === "containerDirective") {
925
+ const head = (node.children || [])[0];
926
+ label4 = inlineDirectiveLabel(head) ? head : void 0;
927
+ } else {
928
+ label4 = node;
929
+ }
930
+ if (label4 && label4.children && label4.children.length > 0) {
931
+ const exit3 = state.enter("label");
932
+ const labelType = `${node.type}Label`;
933
+ const subexit = state.enter(labelType);
934
+ value += tracker.move("[");
935
+ value += tracker.move(
936
+ state.containerPhrasing(label4, {
937
+ ...tracker.current(),
938
+ before: value,
939
+ after: "]"
940
+ })
941
+ );
942
+ value += tracker.move("]");
943
+ subexit();
944
+ exit3();
945
+ } else if (!attributesValue && (after === 45 || after === 95 || !(unicodePunctuation(after) || unicodeWhitespace(after)))) {
946
+ value += tracker.move("[]");
947
+ }
948
+ value += tracker.move(
949
+ attributesValue || (after === 123 ? "{}" : "")
950
+ );
951
+ if (node.type === "containerDirective") {
952
+ if (content) {
953
+ value += tracker.move("\n" + content);
954
+ }
955
+ value += tracker.move("\n" + sequence);
956
+ }
957
+ exit2();
958
+ return value;
959
+ }
960
+ function attributes4(node, state) {
961
+ const attributes5 = node.attributes || {};
962
+ const values = [];
963
+ let classesFull;
964
+ let classes;
965
+ let id;
966
+ let key;
967
+ for (key in attributes5) {
968
+ if (own.call(attributes5, key) && attributes5[key] !== void 0 && attributes5[key] !== null) {
969
+ const value = encode(String(attributes5[key]));
970
+ if (key === "id") {
971
+ id = settings.preferShortcut !== false && shortcut.test(value) ? "#" + value : quoted("id", value, node, state);
972
+ } else if (key === "class") {
973
+ const list = value.split(/[\t\n\r ]+/);
974
+ const classesFullList = [];
975
+ const classesList = [];
976
+ for (const item of list) {
977
+ ;
978
+ (settings.preferShortcut !== false && shortcut.test(item) ? classesList : classesFullList).push(item);
979
+ }
980
+ classesFull = classesFullList.length > 0 ? quoted("class", classesFullList.join(" "), node, state) : "";
981
+ classes = classesList.length > 0 ? "." + classesList.join(".") : "";
982
+ } else {
983
+ values.push(quoted(key, value, node, state));
984
+ }
985
+ }
986
+ }
987
+ if (classesFull) {
988
+ values.unshift(classesFull);
989
+ }
990
+ if (classes) {
991
+ values.unshift(classes);
992
+ }
993
+ if (id) {
994
+ values.unshift(id);
995
+ }
996
+ return values.length > 0 ? "{" + values.join(" ") + "}" : "";
997
+ }
998
+ function quoted(key, value, node, state) {
999
+ if (settings.collapseEmptyAttributes !== false && !value) return key;
1000
+ if (settings.preferUnquoted && unquoted.test(value)) {
1001
+ return key + "=" + value;
1002
+ }
1003
+ const preferred = settings.quote || state.options.quote || '"';
1004
+ const alternative = preferred === '"' ? "'" : '"';
1005
+ const appliedQuote = settings.quoteSmart && ccount(value, preferred) > ccount(value, alternative) ? alternative : preferred;
1006
+ const subset = node.type === "textDirective" ? [appliedQuote] : [appliedQuote, "\n", "\r"];
1007
+ return key + "=" + appliedQuote + stringifyEntitiesLight(value, { subset }) + appliedQuote;
1008
+ }
1009
+ }
1010
+ function enterContainer(token) {
1011
+ enter.call(this, "containerDirective", token);
1012
+ }
1013
+ function enterLeaf(token) {
1014
+ enter.call(this, "leafDirective", token);
1015
+ }
1016
+ function enterText(token) {
1017
+ enter.call(this, "textDirective", token);
1018
+ }
1019
+ function enter(type, token) {
1020
+ this.enter({ type, name: "", attributes: {}, children: [] }, token);
1021
+ }
1022
+ function exitName(token) {
1023
+ const node = this.stack[this.stack.length - 1];
1024
+ ok(node, "expected `node`");
1025
+ ok(
1026
+ node.type === "containerDirective" || node.type === "leafDirective" || node.type === "textDirective"
1027
+ );
1028
+ node.name = this.sliceSerialize(token);
1029
+ openingEnd(node, token);
1030
+ }
1031
+ function enterContainerLabel(token) {
1032
+ this.enter(
1033
+ { type: "paragraph", data: { directiveLabel: true }, children: [] },
1034
+ token
1035
+ );
1036
+ }
1037
+ function exitContainerLabel(token) {
1038
+ this.exit(token);
1039
+ const node = this.stack[this.stack.length - 1];
1040
+ ok(node, "expected `node`");
1041
+ ok(node.type === "containerDirective");
1042
+ openingEnd(node, token);
1043
+ }
1044
+ function exitLabel(token) {
1045
+ const node = this.stack[this.stack.length - 1];
1046
+ ok(node, "expected `node`");
1047
+ ok(node.type === "leafDirective" || node.type === "textDirective");
1048
+ openingEnd(node, token);
1049
+ }
1050
+ function enterAttributes() {
1051
+ const node = this.stack[this.stack.length - 1];
1052
+ ok(node, "expected `node`");
1053
+ ok(
1054
+ node.type === "containerDirective" || node.type === "leafDirective" || node.type === "textDirective"
1055
+ );
1056
+ if (node.data && node.data.position) {
1057
+ this.data.directiveAttributePositions = {};
1058
+ }
1059
+ this.data.directiveAttributes = [];
1060
+ this.buffer();
1061
+ }
1062
+ function exitAttributeShortcut(token) {
1063
+ const positions = this.data.directiveAttributePositions;
1064
+ if (positions) {
1065
+ const list = this.data.directiveAttributes;
1066
+ ok(list, "expected `directiveAttributes`");
1067
+ const tail = list[list.length - 1];
1068
+ ok(tail, "expected attribute");
1069
+ positions[tail[0]] = { start: point(token.start), end: point(token.end) };
1070
+ }
1071
+ }
1072
+ function exitAttributeValueLiteral(token) {
1073
+ attributeEnd(this, token);
1074
+ }
1075
+ function exitAttributeIdValue(token) {
1076
+ const list = this.data.directiveAttributes;
1077
+ ok(list, "expected `directiveAttributes`");
1078
+ list.push([
1079
+ "id",
1080
+ parseEntities(this.sliceSerialize(token), { attribute: true })
1081
+ ]);
1082
+ }
1083
+ function exitAttributeClassValue(token) {
1084
+ const list = this.data.directiveAttributes;
1085
+ ok(list, "expected `directiveAttributes`");
1086
+ list.push([
1087
+ "class",
1088
+ parseEntities(this.sliceSerialize(token), { attribute: true })
1089
+ ]);
1090
+ }
1091
+ function exitAttributeValue(token) {
1092
+ const list = this.data.directiveAttributes;
1093
+ ok(list, "expected `directiveAttributes`");
1094
+ const tail = list[list.length - 1];
1095
+ ok(tail, "expected attribute");
1096
+ tail[1] = parseEntities(this.sliceSerialize(token), { attribute: true });
1097
+ attributeEnd(this, token);
1098
+ }
1099
+ function exitAttributeName(token) {
1100
+ const list = this.data.directiveAttributes;
1101
+ ok(list, "expected `directiveAttributes`");
1102
+ const name = this.sliceSerialize(token);
1103
+ list.push([name, ""]);
1104
+ const positions = this.data.directiveAttributePositions;
1105
+ if (positions) {
1106
+ positions[name] = { start: point(token.start), end: point(token.end) };
1107
+ }
1108
+ }
1109
+ function exitAttributes(token) {
1110
+ const list = this.data.directiveAttributes;
1111
+ ok(list, "expected `directiveAttributes`");
1112
+ const cleaned = {};
1113
+ for (const attribute of list) {
1114
+ if (attribute[0] === "class" && cleaned.class) {
1115
+ cleaned.class += " " + attribute[1];
1116
+ } else {
1117
+ cleaned[attribute[0]] = attribute[1];
1118
+ }
1119
+ }
1120
+ const positions = this.data.directiveAttributePositions;
1121
+ this.data.directiveAttributePositions = void 0;
1122
+ this.data.directiveAttributes = void 0;
1123
+ this.resume();
1124
+ const node = this.stack[this.stack.length - 1];
1125
+ ok(node, "expected `node`");
1126
+ ok(
1127
+ node.type === "containerDirective" || node.type === "leafDirective" || node.type === "textDirective"
1128
+ );
1129
+ node.attributes = cleaned;
1130
+ if (positions) {
1131
+ ok(node.data && node.data.position, "expected `position`");
1132
+ node.data.position.attributes = positions;
1133
+ }
1134
+ openingEnd(node, token);
1135
+ }
1136
+ function openingEnd(node, token) {
1137
+ if (node.data && node.data.position) {
1138
+ const { opening } = node.data.position;
1139
+ ok(opening, "expected `opening`");
1140
+ opening.end = point(token.end);
1141
+ }
1142
+ }
1143
+ function attributeEnd(context, token) {
1144
+ const positions = context.data.directiveAttributePositions;
1145
+ if (positions) {
1146
+ const list = context.data.directiveAttributes;
1147
+ ok(list, "expected `directiveAttributes`");
1148
+ const tail = list[list.length - 1];
1149
+ ok(tail, "expected attribute");
1150
+ const position = positions[tail[0]];
1151
+ ok(position, "expected position");
1152
+ position.end = point(token.end);
1153
+ }
1154
+ }
1155
+ function point(d) {
1156
+ return { line: d.line, column: d.column, offset: d.offset };
1157
+ }
1158
+ function exit(token) {
1159
+ this.exit(token);
1160
+ }
1161
+ function peekDirective() {
1162
+ return ":";
1163
+ }
1164
+ function encode(value) {
1165
+ const result = [];
1166
+ let start = 0;
1167
+ let index = value.indexOf("&");
1168
+ while (index !== -1) {
1169
+ const code = value.charCodeAt(index + 1);
1170
+ if (code === 35 || asciiAlpha(code)) {
1171
+ result.push(value.slice(start, index), "&#x26;");
1172
+ start = index + 1;
1173
+ }
1174
+ index = value.indexOf("&", index + 1);
1175
+ }
1176
+ result.push(value.slice(start));
1177
+ return result.join("");
1178
+ }
1179
+ function inlineDirectiveLabel(node) {
1180
+ return Boolean(
1181
+ node && node.type === "paragraph" && node.data && node.data.directiveLabel
1182
+ );
1183
+ }
1184
+ function fence(node, longest) {
1185
+ let size = 0;
1186
+ if (node.type === "containerDirective") {
1187
+ size = Math.max(3, longest + 1);
1188
+ } else if (node.type === "leafDirective") {
1189
+ size = 2;
1190
+ } else {
1191
+ size = 1;
1192
+ }
1193
+ return ":".repeat(size);
1194
+ }
1195
+ function longestColonLine(value) {
1196
+ let longest = 0;
1197
+ let index = 0;
1198
+ while (index < value.length) {
1199
+ let size = 0;
1200
+ let code = value.charCodeAt(index);
1201
+ while (code === 9 || code === 32) {
1202
+ code = value.charCodeAt(++index);
1203
+ }
1204
+ while (code === 58) {
1205
+ size++;
1206
+ code = value.charCodeAt(++index);
1207
+ }
1208
+ while (code === 9 || code === 32) {
1209
+ code = value.charCodeAt(++index);
1210
+ }
1211
+ while (!(code === 10 || code === 13 || Number.isNaN(code))) {
1212
+ size = 0;
1213
+ code = value.charCodeAt(++index);
1214
+ }
1215
+ if (size > longest) longest = size;
1216
+ index++;
1217
+ }
1218
+ return longest;
1219
+ }
1220
+
1221
+ // ../node_modules/.pnpm/micromark-extension-directive@4.0.0/node_modules/micromark-extension-directive/lib/factory-attributes.js
1222
+ function factoryAttributes(effects, ok2, nok, attributesType, attributesMarkerType, attributeType, attributeIdType, attributeClassType, attributeNameType, attributeInitializerType, attributeValueLiteralType, attributeValueType, attributeValueMarker, attributeValueData, disallowEol) {
1223
+ let type;
1224
+ let marker;
1225
+ return start;
1226
+ function start(code) {
1227
+ effects.enter(attributesType);
1228
+ effects.enter(attributesMarkerType);
1229
+ effects.consume(code);
1230
+ effects.exit(attributesMarkerType);
1231
+ return between;
1232
+ }
1233
+ function between(code) {
1234
+ if (code === 35) {
1235
+ type = attributeIdType;
1236
+ return shortcutStart(code);
1237
+ }
1238
+ if (code === 46) {
1239
+ type = attributeClassType;
1240
+ return shortcutStart(code);
1241
+ }
1242
+ if (disallowEol && markdownSpace(code)) {
1243
+ return factorySpace(effects, between, "whitespace")(code);
1244
+ }
1245
+ if (!disallowEol && markdownLineEndingOrSpace(code)) {
1246
+ return factoryWhitespace(effects, between)(code);
1247
+ }
1248
+ if (code === null || markdownLineEnding(code) || unicodeWhitespace(code) || unicodePunctuation(code) && code !== 45 && code !== 95) {
1249
+ return end(code);
1250
+ }
1251
+ effects.enter(attributeType);
1252
+ effects.enter(attributeNameType);
1253
+ effects.consume(code);
1254
+ return name;
1255
+ }
1256
+ function shortcutStart(code) {
1257
+ const markerType = (
1258
+ /** @type {TokenType} */
1259
+ type + "Marker"
1260
+ );
1261
+ effects.enter(attributeType);
1262
+ effects.enter(type);
1263
+ effects.enter(markerType);
1264
+ effects.consume(code);
1265
+ effects.exit(markerType);
1266
+ return shortcutStartAfter;
1267
+ }
1268
+ function shortcutStartAfter(code) {
1269
+ if (code === null || code === 34 || code === 35 || code === 39 || code === 46 || code === 60 || code === 61 || code === 62 || code === 96 || code === 125 || markdownLineEndingOrSpace(code)) {
1270
+ return nok(code);
1271
+ }
1272
+ const valueType = (
1273
+ /** @type {TokenType} */
1274
+ type + "Value"
1275
+ );
1276
+ effects.enter(valueType);
1277
+ effects.consume(code);
1278
+ return shortcut2;
1279
+ }
1280
+ function shortcut2(code) {
1281
+ if (code === null || code === 34 || code === 39 || code === 60 || code === 61 || code === 62 || code === 96) {
1282
+ return nok(code);
1283
+ }
1284
+ if (code === 35 || code === 46 || code === 125 || markdownLineEndingOrSpace(code)) {
1285
+ const valueType = (
1286
+ /** @type {TokenType} */
1287
+ type + "Value"
1288
+ );
1289
+ effects.exit(valueType);
1290
+ effects.exit(type);
1291
+ effects.exit(attributeType);
1292
+ return between(code);
1293
+ }
1294
+ effects.consume(code);
1295
+ return shortcut2;
1296
+ }
1297
+ function name(code) {
1298
+ if (code === null || markdownLineEnding(code) || unicodeWhitespace(code) || unicodePunctuation(code) && code !== 45 && code !== 46 && code !== 58 && code !== 95) {
1299
+ effects.exit(attributeNameType);
1300
+ if (disallowEol && markdownSpace(code)) {
1301
+ return factorySpace(effects, nameAfter, "whitespace")(code);
1302
+ }
1303
+ if (!disallowEol && markdownLineEndingOrSpace(code)) {
1304
+ return factoryWhitespace(effects, nameAfter)(code);
1305
+ }
1306
+ return nameAfter(code);
1307
+ }
1308
+ effects.consume(code);
1309
+ return name;
1310
+ }
1311
+ function nameAfter(code) {
1312
+ if (code === 61) {
1313
+ effects.enter(attributeInitializerType);
1314
+ effects.consume(code);
1315
+ effects.exit(attributeInitializerType);
1316
+ return valueBefore;
1317
+ }
1318
+ effects.exit(attributeType);
1319
+ return between(code);
1320
+ }
1321
+ function valueBefore(code) {
1322
+ if (code === null || code === 60 || code === 61 || code === 62 || code === 96 || code === 125 || disallowEol && markdownLineEnding(code)) {
1323
+ return nok(code);
1324
+ }
1325
+ if (code === 34 || code === 39) {
1326
+ effects.enter(attributeValueLiteralType);
1327
+ effects.enter(attributeValueMarker);
1328
+ effects.consume(code);
1329
+ effects.exit(attributeValueMarker);
1330
+ marker = code;
1331
+ return valueQuotedStart;
1332
+ }
1333
+ if (disallowEol && markdownSpace(code)) {
1334
+ return factorySpace(effects, valueBefore, "whitespace")(code);
1335
+ }
1336
+ if (!disallowEol && markdownLineEndingOrSpace(code)) {
1337
+ return factoryWhitespace(effects, valueBefore)(code);
1338
+ }
1339
+ effects.enter(attributeValueType);
1340
+ effects.enter(attributeValueData);
1341
+ effects.consume(code);
1342
+ marker = void 0;
1343
+ return valueUnquoted;
1344
+ }
1345
+ function valueUnquoted(code) {
1346
+ if (code === null || code === 34 || code === 39 || code === 60 || code === 61 || code === 62 || code === 96) {
1347
+ return nok(code);
1348
+ }
1349
+ if (code === 125 || markdownLineEndingOrSpace(code)) {
1350
+ effects.exit(attributeValueData);
1351
+ effects.exit(attributeValueType);
1352
+ effects.exit(attributeType);
1353
+ return between(code);
1354
+ }
1355
+ effects.consume(code);
1356
+ return valueUnquoted;
1357
+ }
1358
+ function valueQuotedStart(code) {
1359
+ if (code === marker) {
1360
+ effects.enter(attributeValueMarker);
1361
+ effects.consume(code);
1362
+ effects.exit(attributeValueMarker);
1363
+ effects.exit(attributeValueLiteralType);
1364
+ effects.exit(attributeType);
1365
+ return valueQuotedAfter;
1366
+ }
1367
+ effects.enter(attributeValueType);
1368
+ return valueQuotedBetween(code);
1369
+ }
1370
+ function valueQuotedBetween(code) {
1371
+ if (code === marker) {
1372
+ effects.exit(attributeValueType);
1373
+ return valueQuotedStart(code);
1374
+ }
1375
+ if (code === null) {
1376
+ return nok(code);
1377
+ }
1378
+ if (markdownLineEnding(code)) {
1379
+ return disallowEol ? nok(code) : factoryWhitespace(effects, valueQuotedBetween)(code);
1380
+ }
1381
+ effects.enter(attributeValueData);
1382
+ effects.consume(code);
1383
+ return valueQuoted;
1384
+ }
1385
+ function valueQuoted(code) {
1386
+ if (code === marker || code === null || markdownLineEnding(code)) {
1387
+ effects.exit(attributeValueData);
1388
+ return valueQuotedBetween(code);
1389
+ }
1390
+ effects.consume(code);
1391
+ return valueQuoted;
1392
+ }
1393
+ function valueQuotedAfter(code) {
1394
+ return code === 125 || markdownLineEndingOrSpace(code) ? between(code) : end(code);
1395
+ }
1396
+ function end(code) {
1397
+ if (code === 125) {
1398
+ effects.enter(attributesMarkerType);
1399
+ effects.consume(code);
1400
+ effects.exit(attributesMarkerType);
1401
+ effects.exit(attributesType);
1402
+ return ok2;
1403
+ }
1404
+ return nok(code);
1405
+ }
1406
+ }
1407
+
1408
+ // ../node_modules/.pnpm/micromark-extension-directive@4.0.0/node_modules/micromark-extension-directive/lib/factory-label.js
1409
+ function factoryLabel(effects, ok2, nok, type, markerType, stringType, disallowEol) {
1410
+ let size = 0;
1411
+ let balance = 0;
1412
+ let previous2;
1413
+ return start;
1414
+ function start(code) {
1415
+ effects.enter(type);
1416
+ effects.enter(markerType);
1417
+ effects.consume(code);
1418
+ effects.exit(markerType);
1419
+ return afterStart;
1420
+ }
1421
+ function afterStart(code) {
1422
+ if (code === 93) {
1423
+ effects.enter(markerType);
1424
+ effects.consume(code);
1425
+ effects.exit(markerType);
1426
+ effects.exit(type);
1427
+ return ok2;
1428
+ }
1429
+ effects.enter(stringType);
1430
+ return lineStart(code);
1431
+ }
1432
+ function lineStart(code) {
1433
+ if (code === 93 && !balance) {
1434
+ return atClosingBrace(code);
1435
+ }
1436
+ const token = effects.enter("chunkText", {
1437
+ _contentTypeTextTrailing: true,
1438
+ contentType: "text",
1439
+ previous: previous2
1440
+ });
1441
+ if (previous2) previous2.next = token;
1442
+ previous2 = token;
1443
+ return data(code);
1444
+ }
1445
+ function data(code) {
1446
+ if (code === null || size > 999) {
1447
+ return nok(code);
1448
+ }
1449
+ if (code === 91 && ++balance > 32) {
1450
+ return nok(code);
1451
+ }
1452
+ if (code === 93 && !balance--) {
1453
+ effects.exit("chunkText");
1454
+ return atClosingBrace(code);
1455
+ }
1456
+ if (markdownLineEnding(code)) {
1457
+ if (disallowEol) {
1458
+ return nok(code);
1459
+ }
1460
+ effects.consume(code);
1461
+ effects.exit("chunkText");
1462
+ return lineStart;
1463
+ }
1464
+ effects.consume(code);
1465
+ return code === 92 ? dataEscape : data;
1466
+ }
1467
+ function dataEscape(code) {
1468
+ if (code === 91 || code === 92 || code === 93) {
1469
+ effects.consume(code);
1470
+ size++;
1471
+ return data;
1472
+ }
1473
+ return data(code);
1474
+ }
1475
+ function atClosingBrace(code) {
1476
+ effects.exit(stringType);
1477
+ effects.enter(markerType);
1478
+ effects.consume(code);
1479
+ effects.exit(markerType);
1480
+ effects.exit(type);
1481
+ return ok2;
1482
+ }
1483
+ }
1484
+
1485
+ // ../node_modules/.pnpm/micromark-extension-directive@4.0.0/node_modules/micromark-extension-directive/lib/factory-name.js
1486
+ function factoryName(effects, ok2, nok, type) {
1487
+ const self = this;
1488
+ return start;
1489
+ function start(code) {
1490
+ if (code === null || markdownLineEnding(code) || unicodePunctuation(code) || unicodeWhitespace(code)) {
1491
+ return nok(code);
1492
+ }
1493
+ effects.enter(type);
1494
+ effects.consume(code);
1495
+ return name;
1496
+ }
1497
+ function name(code) {
1498
+ if (code === null || markdownLineEnding(code) || unicodeWhitespace(code) || unicodePunctuation(code) && code !== 45 && code !== 95) {
1499
+ effects.exit(type);
1500
+ return self.previous === 45 || self.previous === 95 ? nok(code) : ok2(code);
1501
+ }
1502
+ effects.consume(code);
1503
+ return name;
1504
+ }
1505
+ }
1506
+
1507
+ // ../node_modules/.pnpm/micromark-extension-directive@4.0.0/node_modules/micromark-extension-directive/lib/directive-container.js
1508
+ var directiveContainer = {
1509
+ tokenize: tokenizeDirectiveContainer,
1510
+ concrete: true
1511
+ };
1512
+ var label = {
1513
+ tokenize: tokenizeLabel,
1514
+ partial: true
1515
+ };
1516
+ var attributes = {
1517
+ tokenize: tokenizeAttributes,
1518
+ partial: true
1519
+ };
1520
+ var nonLazyLine = {
1521
+ tokenize: tokenizeNonLazyLine,
1522
+ partial: true
1523
+ };
1524
+ function tokenizeDirectiveContainer(effects, ok2, nok) {
1525
+ const self = this;
1526
+ const tail = self.events[self.events.length - 1];
1527
+ const initialSize = tail && tail[1].type === "linePrefix" ? tail[2].sliceSerialize(tail[1], true).length : 0;
1528
+ let sizeOpen = 0;
1529
+ let previous2;
1530
+ return start;
1531
+ function start(code) {
1532
+ effects.enter("directiveContainer");
1533
+ effects.enter("directiveContainerFence");
1534
+ effects.enter("directiveContainerSequence");
1535
+ return sequenceOpen(code);
1536
+ }
1537
+ function sequenceOpen(code) {
1538
+ if (code === 58) {
1539
+ effects.consume(code);
1540
+ sizeOpen++;
1541
+ return sequenceOpen;
1542
+ }
1543
+ if (sizeOpen < 3) {
1544
+ return nok(code);
1545
+ }
1546
+ effects.exit("directiveContainerSequence");
1547
+ return factoryName.call(self, effects, afterName, nok, "directiveContainerName")(code);
1548
+ }
1549
+ function afterName(code) {
1550
+ return code === 91 ? effects.attempt(label, afterLabel, afterLabel)(code) : afterLabel(code);
1551
+ }
1552
+ function afterLabel(code) {
1553
+ return code === 123 ? effects.attempt(attributes, afterAttributes, afterAttributes)(code) : afterAttributes(code);
1554
+ }
1555
+ function afterAttributes(code) {
1556
+ return factorySpace(effects, openAfter, "whitespace")(code);
1557
+ }
1558
+ function openAfter(code) {
1559
+ effects.exit("directiveContainerFence");
1560
+ if (code === null) {
1561
+ return after(code);
1562
+ }
1563
+ if (markdownLineEnding(code)) {
1564
+ if (self.interrupt) {
1565
+ return ok2(code);
1566
+ }
1567
+ return effects.attempt(nonLazyLine, contentStart, after)(code);
1568
+ }
1569
+ return nok(code);
1570
+ }
1571
+ function contentStart(code) {
1572
+ if (code === null) {
1573
+ return after(code);
1574
+ }
1575
+ if (markdownLineEnding(code)) {
1576
+ return effects.check(nonLazyLine, emptyContentNonLazyLineAfter, after)(code);
1577
+ }
1578
+ effects.enter("directiveContainerContent");
1579
+ return lineStart(code);
1580
+ }
1581
+ function lineStart(code) {
1582
+ return effects.attempt({
1583
+ tokenize: tokenizeClosingFence,
1584
+ partial: true
1585
+ }, afterContent, initialSize ? factorySpace(effects, chunkStart, "linePrefix", initialSize + 1) : chunkStart)(code);
1586
+ }
1587
+ function chunkStart(code) {
1588
+ if (code === null) {
1589
+ return afterContent(code);
1590
+ }
1591
+ if (markdownLineEnding(code)) {
1592
+ return effects.check(nonLazyLine, chunkNonLazyStart, afterContent)(code);
1593
+ }
1594
+ return chunkNonLazyStart(code);
1595
+ }
1596
+ function contentContinue(code) {
1597
+ if (code === null) {
1598
+ const t = effects.exit("chunkDocument");
1599
+ self.parser.lazy[t.start.line] = false;
1600
+ return afterContent(code);
1601
+ }
1602
+ if (markdownLineEnding(code)) {
1603
+ return effects.check(nonLazyLine, nonLazyLineAfter, lineAfter)(code);
1604
+ }
1605
+ effects.consume(code);
1606
+ return contentContinue;
1607
+ }
1608
+ function chunkNonLazyStart(code) {
1609
+ const token = effects.enter("chunkDocument", {
1610
+ contentType: "document",
1611
+ previous: previous2
1612
+ });
1613
+ if (previous2) previous2.next = token;
1614
+ previous2 = token;
1615
+ return contentContinue(code);
1616
+ }
1617
+ function emptyContentNonLazyLineAfter(code) {
1618
+ effects.enter("directiveContainerContent");
1619
+ return lineStart(code);
1620
+ }
1621
+ function nonLazyLineAfter(code) {
1622
+ effects.consume(code);
1623
+ const t = effects.exit("chunkDocument");
1624
+ self.parser.lazy[t.start.line] = false;
1625
+ return lineStart;
1626
+ }
1627
+ function lineAfter(code) {
1628
+ const t = effects.exit("chunkDocument");
1629
+ self.parser.lazy[t.start.line] = false;
1630
+ return afterContent(code);
1631
+ }
1632
+ function afterContent(code) {
1633
+ effects.exit("directiveContainerContent");
1634
+ return after(code);
1635
+ }
1636
+ function after(code) {
1637
+ effects.exit("directiveContainer");
1638
+ return ok2(code);
1639
+ }
1640
+ function tokenizeClosingFence(effects2, ok3, nok2) {
1641
+ let size = 0;
1642
+ return factorySpace(effects2, closingPrefixAfter, "linePrefix", self.parser.constructs.disable.null.includes("codeIndented") ? void 0 : 4);
1643
+ function closingPrefixAfter(code) {
1644
+ effects2.enter("directiveContainerFence");
1645
+ effects2.enter("directiveContainerSequence");
1646
+ return closingSequence(code);
1647
+ }
1648
+ function closingSequence(code) {
1649
+ if (code === 58) {
1650
+ effects2.consume(code);
1651
+ size++;
1652
+ return closingSequence;
1653
+ }
1654
+ if (size < sizeOpen) return nok2(code);
1655
+ effects2.exit("directiveContainerSequence");
1656
+ return factorySpace(effects2, closingSequenceEnd, "whitespace")(code);
1657
+ }
1658
+ function closingSequenceEnd(code) {
1659
+ if (code === null || markdownLineEnding(code)) {
1660
+ effects2.exit("directiveContainerFence");
1661
+ return ok3(code);
1662
+ }
1663
+ return nok2(code);
1664
+ }
1665
+ }
1666
+ }
1667
+ function tokenizeLabel(effects, ok2, nok) {
1668
+ return factoryLabel(effects, ok2, nok, "directiveContainerLabel", "directiveContainerLabelMarker", "directiveContainerLabelString", true);
1669
+ }
1670
+ function tokenizeAttributes(effects, ok2, nok) {
1671
+ return factoryAttributes(effects, ok2, nok, "directiveContainerAttributes", "directiveContainerAttributesMarker", "directiveContainerAttribute", "directiveContainerAttributeId", "directiveContainerAttributeClass", "directiveContainerAttributeName", "directiveContainerAttributeInitializerMarker", "directiveContainerAttributeValueLiteral", "directiveContainerAttributeValue", "directiveContainerAttributeValueMarker", "directiveContainerAttributeValueData", true);
1672
+ }
1673
+ function tokenizeNonLazyLine(effects, ok2, nok) {
1674
+ const self = this;
1675
+ return start;
1676
+ function start(code) {
1677
+ effects.enter("lineEnding");
1678
+ effects.consume(code);
1679
+ effects.exit("lineEnding");
1680
+ return lineStart;
1681
+ }
1682
+ function lineStart(code) {
1683
+ return self.parser.lazy[self.now().line] ? nok(code) : ok2(code);
1684
+ }
1685
+ }
1686
+
1687
+ // ../node_modules/.pnpm/micromark-extension-directive@4.0.0/node_modules/micromark-extension-directive/lib/directive-leaf.js
1688
+ var directiveLeaf = {
1689
+ tokenize: tokenizeDirectiveLeaf
1690
+ };
1691
+ var label2 = {
1692
+ tokenize: tokenizeLabel2,
1693
+ partial: true
1694
+ };
1695
+ var attributes2 = {
1696
+ tokenize: tokenizeAttributes2,
1697
+ partial: true
1698
+ };
1699
+ function tokenizeDirectiveLeaf(effects, ok2, nok) {
1700
+ const self = this;
1701
+ return start;
1702
+ function start(code) {
1703
+ effects.enter("directiveLeaf");
1704
+ effects.enter("directiveLeafSequence");
1705
+ effects.consume(code);
1706
+ return inStart;
1707
+ }
1708
+ function inStart(code) {
1709
+ if (code === 58) {
1710
+ effects.consume(code);
1711
+ effects.exit("directiveLeafSequence");
1712
+ return factoryName.call(self, effects, afterName, nok, "directiveLeafName");
1713
+ }
1714
+ return nok(code);
1715
+ }
1716
+ function afterName(code) {
1717
+ return code === 91 ? effects.attempt(label2, afterLabel, afterLabel)(code) : afterLabel(code);
1718
+ }
1719
+ function afterLabel(code) {
1720
+ return code === 123 ? effects.attempt(attributes2, afterAttributes, afterAttributes)(code) : afterAttributes(code);
1721
+ }
1722
+ function afterAttributes(code) {
1723
+ return factorySpace(effects, end, "whitespace")(code);
1724
+ }
1725
+ function end(code) {
1726
+ if (code === null || markdownLineEnding(code)) {
1727
+ effects.exit("directiveLeaf");
1728
+ return ok2(code);
1729
+ }
1730
+ return nok(code);
1731
+ }
1732
+ }
1733
+ function tokenizeLabel2(effects, ok2, nok) {
1734
+ return factoryLabel(effects, ok2, nok, "directiveLeafLabel", "directiveLeafLabelMarker", "directiveLeafLabelString", true);
1735
+ }
1736
+ function tokenizeAttributes2(effects, ok2, nok) {
1737
+ return factoryAttributes(effects, ok2, nok, "directiveLeafAttributes", "directiveLeafAttributesMarker", "directiveLeafAttribute", "directiveLeafAttributeId", "directiveLeafAttributeClass", "directiveLeafAttributeName", "directiveLeafAttributeInitializerMarker", "directiveLeafAttributeValueLiteral", "directiveLeafAttributeValue", "directiveLeafAttributeValueMarker", "directiveLeafAttributeValueData", true);
1738
+ }
1739
+
1740
+ // ../node_modules/.pnpm/micromark-extension-directive@4.0.0/node_modules/micromark-extension-directive/lib/directive-text.js
1741
+ var directiveText = {
1742
+ tokenize: tokenizeDirectiveText,
1743
+ previous
1744
+ };
1745
+ var label3 = {
1746
+ tokenize: tokenizeLabel3,
1747
+ partial: true
1748
+ };
1749
+ var attributes3 = {
1750
+ tokenize: tokenizeAttributes3,
1751
+ partial: true
1752
+ };
1753
+ function previous(code) {
1754
+ return code !== 58 || this.events[this.events.length - 1][1].type === "characterEscape";
1755
+ }
1756
+ function tokenizeDirectiveText(effects, ok2, nok) {
1757
+ const self = this;
1758
+ return start;
1759
+ function start(code) {
1760
+ effects.enter("directiveText");
1761
+ effects.enter("directiveTextMarker");
1762
+ effects.consume(code);
1763
+ effects.exit("directiveTextMarker");
1764
+ return factoryName.call(self, effects, afterName, nok, "directiveTextName");
1765
+ }
1766
+ function afterName(code) {
1767
+ return code === 58 ? nok(code) : code === 91 ? effects.attempt(label3, afterLabel, afterLabel)(code) : afterLabel(code);
1768
+ }
1769
+ function afterLabel(code) {
1770
+ return code === 123 ? effects.attempt(attributes3, afterAttributes, afterAttributes)(code) : afterAttributes(code);
1771
+ }
1772
+ function afterAttributes(code) {
1773
+ effects.exit("directiveText");
1774
+ return ok2(code);
1775
+ }
1776
+ }
1777
+ function tokenizeLabel3(effects, ok2, nok) {
1778
+ return factoryLabel(effects, ok2, nok, "directiveTextLabel", "directiveTextLabelMarker", "directiveTextLabelString");
1779
+ }
1780
+ function tokenizeAttributes3(effects, ok2, nok) {
1781
+ return factoryAttributes(effects, ok2, nok, "directiveTextAttributes", "directiveTextAttributesMarker", "directiveTextAttribute", "directiveTextAttributeId", "directiveTextAttributeClass", "directiveTextAttributeName", "directiveTextAttributeInitializerMarker", "directiveTextAttributeValueLiteral", "directiveTextAttributeValue", "directiveTextAttributeValueMarker", "directiveTextAttributeValueData");
1782
+ }
1783
+
1784
+ // ../node_modules/.pnpm/micromark-extension-directive@4.0.0/node_modules/micromark-extension-directive/lib/syntax.js
1785
+ function directive() {
1786
+ return {
1787
+ text: {
1788
+ [58]: directiveText
1789
+ },
1790
+ flow: {
1791
+ [58]: [directiveContainer, directiveLeaf]
1792
+ }
1793
+ };
1794
+ }
1795
+
1796
+ // ../node_modules/.pnpm/remark-directive@4.0.0/node_modules/remark-directive/lib/index.js
1797
+ function remarkDirective() {
1798
+ const self = (
1799
+ /** @type {Processor<Root>} */
1800
+ this
1801
+ );
1802
+ const data = self.data();
1803
+ const micromarkExtensions = data.micromarkExtensions || (data.micromarkExtensions = []);
1804
+ const fromMarkdownExtensions = data.fromMarkdownExtensions || (data.fromMarkdownExtensions = []);
1805
+ const toMarkdownExtensions = data.toMarkdownExtensions || (data.toMarkdownExtensions = []);
1806
+ micromarkExtensions.push(directive());
1807
+ fromMarkdownExtensions.push(directiveFromMarkdown());
1808
+ toMarkdownExtensions.push(directiveToMarkdown());
1809
+ }
1810
+
1811
+ // cli/guide/settings.ts
1812
+ var WHEN_ATTRIBUTES = ["setting", "is", "not"];
1813
+ function lookupSetting(settings, path) {
1814
+ const parsed = parseSettingPath(path);
1815
+ if (!parsed || parsed.keys.length === 0) return { found: false };
1816
+ const { identifier, keys } = parsed;
1817
+ if (!Object.prototype.hasOwnProperty.call(settings, identifier)) return { found: false };
1818
+ let value = settings[identifier];
1819
+ for (const key of keys) {
1820
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
1821
+ return { found: false };
1822
+ }
1823
+ if (!Object.prototype.hasOwnProperty.call(value, key)) return { found: false };
1824
+ value = value[key];
1825
+ }
1826
+ return { found: true, value };
1827
+ }
1828
+ function formatSettingValue(value, locale) {
1829
+ if (typeof value === "number") {
1830
+ try {
1831
+ return new Intl.NumberFormat(locale).format(value);
1832
+ } catch {
1833
+ return new Intl.NumberFormat("en").format(value);
1834
+ }
1835
+ }
1836
+ if (typeof value === "string") return value;
1837
+ return null;
1838
+ }
1839
+ function evaluateWhen(settings, attributes4) {
1840
+ const path = attributes4.setting;
1841
+ if (!path) return { error: ":::when names no setting" };
1842
+ const lookup = lookupSetting(settings, path);
1843
+ if (!lookup.found) return { error: `:::when names "${path}", which this guide is not given` };
1844
+ const { value } = lookup;
1845
+ const negate = attributes4.not !== void 0 && attributes4.not !== null;
1846
+ let matched;
1847
+ if (attributes4.is === void 0 || attributes4.is === null) {
1848
+ if (typeof value !== "boolean") {
1849
+ return { error: `:::when on "${path}" needs is="\u2026", since it is not true or false` };
1850
+ }
1851
+ matched = value;
1852
+ } else if (typeof value === "number") {
1853
+ matched = attributes4.is.trim() !== "" && Number(attributes4.is) === value;
1854
+ } else if (typeof value === "string" || typeof value === "boolean") {
1855
+ matched = String(value) === attributes4.is;
1856
+ } else {
1857
+ return { error: `:::when on "${path}" compares a value that is not a single value` };
1858
+ }
1859
+ return { show: negate ? !matched : matched };
1860
+ }
1861
+ function errorInline(message) {
1862
+ return {
1863
+ type: "emphasis",
1864
+ data: { hName: "span", hProperties: { dataGuideError: message } },
1865
+ children: [{ type: "text", value: message }]
1866
+ };
1867
+ }
1868
+ function errorBlock(message) {
1869
+ return {
1870
+ type: "paragraph",
1871
+ data: { hName: "div", hProperties: { dataGuideError: message } },
1872
+ children: [{ type: "text", value: message }]
1873
+ };
1874
+ }
1875
+ function remarkGuideSettings(options) {
1876
+ return (tree) => {
1877
+ visit(tree, (node, index, parent) => {
1878
+ if (!parent || typeof index !== "number") return;
1879
+ const directive2 = node;
1880
+ if (directive2.type === "containerDirective" && directive2.name === "when") {
1881
+ const outcome = evaluateWhen(options.settings, directive2.attributes ?? {});
1882
+ const replacement = "error" in outcome ? [errorBlock(outcome.error)] : outcome.show ? directive2.children : [];
1883
+ parent.children.splice(index, 1, ...replacement);
1884
+ return [SKIP, index];
1885
+ }
1886
+ if (directive2.type === "textDirective" && directive2.name === "setting") {
1887
+ const path = directiveLabel(directive2);
1888
+ const lookup = lookupSetting(options.settings, path);
1889
+ const text = lookup.found ? formatSettingValue(lookup.value, options.locale) : null;
1890
+ const replacement = text === null ? errorInline(
1891
+ lookup.found ? `:setting[${path}] is not a number or text` : `:setting[${path}] is not given to this guide`
1892
+ ) : { type: "text", value: text };
1893
+ parent.children.splice(index, 1, replacement);
1894
+ return [SKIP, index + 1];
1895
+ }
1896
+ });
1897
+ };
1898
+ }
1899
+ function directiveLabel(directive2) {
1900
+ return directive2.children.map((child) => "value" in child && typeof child.value === "string" ? child.value : "").join("").trim();
1901
+ }
1902
+ function parse(markdown) {
1903
+ return unified().use(remarkParse).use(remarkGfm).use(remarkDirective).parse(markdown);
1904
+ }
1905
+ function evaluateChapter(markdown, settings, locale) {
1906
+ const tree = parse(markdown);
1907
+ remarkGuideSettings({ settings, locale })(tree);
1908
+ return tree;
1909
+ }
1910
+ function isChapterEmpty(markdown, settings) {
1911
+ return evaluateChapter(markdown, settings, "en").children.length === 0;
1912
+ }
1913
+ function settingReferences(markdown) {
1914
+ const references = [];
1915
+ const walk = (nodes, insideWhen) => {
1916
+ for (const node of nodes) {
1917
+ const directive2 = node;
1918
+ const line = directive2.position?.start.line ?? 0;
1919
+ if (directive2.type === "containerDirective" && directive2.name === "when") {
1920
+ const attributes4 = directive2.attributes ?? {};
1921
+ references.push({
1922
+ kind: "when",
1923
+ path: attributes4.setting ?? "",
1924
+ line,
1925
+ ...attributes4.is !== void 0 && attributes4.is !== null ? { is: attributes4.is } : {},
1926
+ unknownAttributes: Object.keys(attributes4).filter(
1927
+ (name) => !WHEN_ATTRIBUTES.includes(name)
1928
+ ),
1929
+ nested: insideWhen
1930
+ });
1931
+ walk(directive2.children, true);
1932
+ continue;
1933
+ }
1934
+ if (directive2.type === "textDirective" && directive2.name === "setting") {
1935
+ references.push({
1936
+ kind: "value",
1937
+ path: directiveLabel(directive2),
1938
+ line,
1939
+ unknownAttributes: Object.keys(directive2.attributes ?? {}),
1940
+ nested: false
1941
+ });
1942
+ continue;
1943
+ }
1944
+ if ("children" in node && Array.isArray(node.children)) {
1945
+ walk(node.children, insideWhen);
1946
+ }
1947
+ }
1948
+ };
1949
+ walk(parse(markdown).children, false);
1950
+ return references;
1951
+ }
1952
+ function strayFences(markdown) {
1953
+ const lines = [];
1954
+ visit(parse(markdown), "text", (node) => {
1955
+ const start = node.position?.start.line ?? 0;
1956
+ node.value.split("\n").forEach((text, offset) => {
1957
+ if (/^:{3,}\s*$/.test(text)) lines.push(start + offset);
1958
+ });
1959
+ });
1960
+ return lines;
1961
+ }
1962
+
1963
+ export {
1964
+ referenceLocale,
1965
+ isChapterEmpty,
1966
+ settingReferences,
1967
+ strayFences,
1968
+ memberDeclarations,
1969
+ resolveBlobInputs,
1970
+ fileSettingDeclarationErrors,
1971
+ packageFileSettingErrors,
1972
+ fileSettingWriteErrors
1973
+ };