@tunasand/sdk 0.8.0 → 0.11.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 (215) hide show
  1. package/CHANGELOG.md +121 -0
  2. package/README.md +162 -143
  3. package/dist/analytics.js +76 -65
  4. package/dist/app.js +184 -163
  5. package/dist/apps-DIxAWBSZ.js +318 -0
  6. package/dist/astro-image.d.ts +1 -0
  7. package/dist/astro-image.js +33 -0
  8. package/dist/astro-server-Bwau8F6d.js +99 -0
  9. package/dist/astro-server.d.ts +1 -0
  10. package/dist/astro-server.js +1 -0
  11. package/dist/astro.d.ts +1 -0
  12. package/dist/astro.js +306 -0
  13. package/dist/bridge-Dv4NxGZ7.js +81 -0
  14. package/dist/bridge.js +1 -13
  15. package/dist/build-file-DNi0PHC5.js +31 -0
  16. package/dist/cli.js +6212 -8
  17. package/dist/{client-Derrexwr.js → client-C8STAw9T.js} +43 -24
  18. package/dist/code-N8pBUDbq.js +30 -0
  19. package/dist/code.d.ts +1 -0
  20. package/dist/code.js +1 -0
  21. package/dist/collection-nUz1RetA.js +264 -0
  22. package/dist/{declared-DuNMsdXw.js → declared-CE4a61qb.js} +35 -35
  23. package/dist/delivery.js +121 -114
  24. package/dist/dev-operations-Tutwi1On.js +46 -0
  25. package/dist/dev.js +9 -16
  26. package/dist/embeds-B-Dbn64k.js +29 -0
  27. package/dist/end-users.d.ts +1 -0
  28. package/dist/end-users.js +185 -0
  29. package/dist/endUsers-DODfjnv1.js +77 -0
  30. package/dist/{errorLabels-BgtQ_zUn.js → errorLabels-aT2bnMsO.js} +355 -235
  31. package/dist/i18n.js +4 -4
  32. package/dist/ids-DmtIoqBX.js +109 -0
  33. package/dist/integrations.js +95 -24
  34. package/dist/{ja-Du6ooL6i.js → ja-CrY_72Tn.js} +88 -44
  35. package/dist/{ja-CeHU0EaY.js → ja-axQPxMJ-.js} +3 -3
  36. package/dist/operations-CIB99rIY.js +95 -0
  37. package/dist/operations.d.ts +1 -0
  38. package/dist/operations.js +1 -0
  39. package/dist/{page-Bzrj24sJ.js → page-yo1cw1kW.js} +1 -1
  40. package/dist/preview.js +8 -1
  41. package/dist/{profile-1em_lcxq.js → profile-DBsXLvvI.js} +48 -48
  42. package/dist/rich-text.js +16 -16
  43. package/dist/{schema-WnobuwLg.js → schema-Dcg1ajnW.js} +496 -263
  44. package/dist/schema.js +66 -88
  45. package/dist/types/access/src/handoff.d.ts +19 -14
  46. package/dist/types/access/src/index.d.ts +2 -2
  47. package/dist/types/access/src/jws.d.ts +41 -0
  48. package/dist/types/access/src/oidc.d.ts +10 -2
  49. package/dist/types/access/src/signed.d.ts +0 -2
  50. package/dist/types/adapter-cloudflare/src/eventLog/viewSchema.d.ts +11 -0
  51. package/dist/types/contract/src/accountProfile.d.ts +7 -0
  52. package/dist/types/contract/src/apiKeys.d.ts +6 -2
  53. package/dist/types/contract/src/app.d.ts +15 -5
  54. package/dist/types/contract/src/appChannels.d.ts +114 -0
  55. package/dist/types/contract/src/appDefinition.d.ts +11 -5
  56. package/dist/types/contract/src/appDependencies.d.ts +87 -24
  57. package/dist/types/contract/src/appIdentities.d.ts +21 -0
  58. package/dist/types/contract/src/appInbound.d.ts +28 -0
  59. package/dist/types/contract/src/appMail.d.ts +106 -0
  60. package/dist/types/contract/src/appSecrets.d.ts +45 -0
  61. package/dist/types/contract/src/appServer.d.ts +408 -43
  62. package/dist/types/contract/src/approvals.d.ts +1 -1
  63. package/dist/types/contract/src/apps.d.ts +112 -55
  64. package/dist/types/contract/src/auditActions.d.ts +2 -2
  65. package/dist/types/contract/src/auditLabels.d.ts +111 -15
  66. package/dist/types/contract/src/authorize.d.ts +42 -14
  67. package/dist/types/contract/src/bridge.d.ts +34 -35
  68. package/dist/types/contract/src/consents.d.ts +32 -25
  69. package/dist/types/contract/src/deletion.d.ts +18 -0
  70. package/dist/types/contract/src/embeds.d.ts +16 -82
  71. package/dist/types/contract/src/{customerLabels.d.ts → endUserLabels.d.ts} +6 -9
  72. package/dist/types/contract/src/endUsers.d.ts +241 -0
  73. package/dist/types/contract/src/errorLabels.d.ts +63 -36
  74. package/dist/types/contract/src/errorLabelsEn.d.ts +46 -32
  75. package/dist/types/contract/src/errors.d.ts +28 -16
  76. package/dist/types/contract/src/eventSchemas.d.ts +70 -0
  77. package/dist/types/contract/src/eventTraces.d.ts +43 -0
  78. package/dist/types/contract/src/failureStatus.d.ts +14 -22
  79. package/dist/types/contract/src/fieldAccess.d.ts +8 -8
  80. package/dist/types/contract/src/formLabels.d.ts +3 -0
  81. package/dist/types/contract/src/forms.d.ts +4 -0
  82. package/dist/types/contract/src/grants.d.ts +26 -0
  83. package/dist/types/contract/src/headers.d.ts +5 -0
  84. package/dist/types/contract/src/hostingRpc.d.ts +23 -17
  85. package/dist/types/contract/src/identifiers.d.ts +45 -17
  86. package/dist/types/contract/src/ids.d.ts +18 -10
  87. package/dist/types/contract/src/import.d.ts +17 -16
  88. package/dist/types/contract/src/index.d.ts +52 -27
  89. package/dist/types/contract/src/integrationGraph.d.ts +83 -0
  90. package/dist/types/contract/src/issueLabels.d.ts +113 -81
  91. package/dist/types/contract/src/issueLabelsEn.d.ts +57 -41
  92. package/dist/types/contract/src/manage.d.ts +11 -7
  93. package/dist/types/contract/src/manageLabels.d.ts +2 -0
  94. package/dist/types/contract/src/manifestText.d.ts +66 -0
  95. package/dist/types/contract/src/messagePort.d.ts +208 -0
  96. package/dist/types/contract/src/migration.d.ts +2 -2
  97. package/dist/types/contract/src/notices.d.ts +38 -0
  98. package/dist/types/contract/src/operatorOperations.d.ts +0 -63
  99. package/dist/types/contract/src/outbound.d.ts +29 -0
  100. package/dist/types/contract/src/paths.d.ts +13 -0
  101. package/dist/types/contract/src/pending.d.ts +2 -0
  102. package/dist/types/contract/src/permissions.d.ts +7 -11
  103. package/dist/types/contract/src/perspective.d.ts +26 -0
  104. package/dist/types/contract/src/powers.d.ts +5 -0
  105. package/dist/types/contract/src/principal.d.ts +127 -56
  106. package/dist/types/contract/src/recordLabels.d.ts +6 -0
  107. package/dist/types/contract/src/roles.d.ts +7 -4
  108. package/dist/types/contract/src/ruleLabels.d.ts +16 -0
  109. package/dist/types/contract/src/ruleProblems.d.ts +16 -0
  110. package/dist/types/contract/src/schemaLabels.d.ts +8 -0
  111. package/dist/types/contract/src/settingProblems.d.ts +1 -1
  112. package/dist/types/contract/src/settings.d.ts +5 -7
  113. package/dist/types/contract/src/siteDeclaration.d.ts +7 -7
  114. package/dist/types/contract/src/siteIndex.d.ts +76 -0
  115. package/dist/types/contract/src/transfer.d.ts +1 -1
  116. package/dist/types/contract/src/trial.d.ts +4 -1
  117. package/dist/types/contract/src/versions.d.ts +1 -3
  118. package/dist/types/contract/src/viewEvent.d.ts +0 -9
  119. package/dist/types/contract/src/webhooks.d.ts +24 -3
  120. package/dist/types/contract/src/workflow.d.ts +13 -19
  121. package/dist/types/contract/src/workspaceItems.d.ts +20 -6
  122. package/dist/types/rich-text/src/html.d.ts +1 -1
  123. package/dist/types/rich-text/src/index.d.ts +8 -7
  124. package/dist/types/rich-text/src/labels/en.d.ts +1 -1
  125. package/dist/types/rich-text/src/labels/ja.d.ts +2 -2
  126. package/dist/types/rich-text/src/library.d.ts +1 -1
  127. package/dist/types/rich-text/src/media.d.ts +2 -0
  128. package/dist/types/rich-text/src/normalize.d.ts +1 -1
  129. package/dist/types/rich-text/src/problems.d.ts +5 -5
  130. package/dist/types/rich-text/src/profile.d.ts +10 -10
  131. package/dist/types/rich-text/src/render.d.ts +1 -1
  132. package/dist/types/rich-text/src/schema.d.ts +2 -2
  133. package/dist/types/rich-text/src/standard.d.ts +4 -4
  134. package/dist/types/rich-text/src/types.d.ts +2 -2
  135. package/dist/types/schema/src/audience.d.ts +1 -3
  136. package/dist/types/schema/src/capabilities.d.ts +18 -27
  137. package/dist/types/schema/src/changes.d.ts +3 -1
  138. package/dist/types/schema/src/collection.d.ts +138 -111
  139. package/dist/types/schema/src/defaultSchema.d.ts +8 -2
  140. package/dist/types/schema/src/fieldIds.d.ts +18 -0
  141. package/dist/types/schema/src/file.d.ts +22 -11
  142. package/dist/types/schema/src/fileRefs.d.ts +14 -0
  143. package/dist/types/schema/src/fileSignature.d.ts +20 -0
  144. package/dist/types/schema/src/filesCollection.d.ts +7 -0
  145. package/dist/types/schema/src/forms.d.ts +43 -0
  146. package/dist/types/schema/src/imageMetadata.d.ts +9 -0
  147. package/dist/types/schema/src/index.d.ts +18 -10
  148. package/dist/types/schema/src/input.d.ts +1 -1
  149. package/dist/types/schema/src/integrity.d.ts +8 -7
  150. package/dist/types/schema/src/kinds.d.ts +26 -0
  151. package/dist/types/schema/src/labels/en.d.ts +87 -46
  152. package/dist/types/schema/src/labels/ja.d.ts +89 -45
  153. package/dist/types/schema/src/mediaUrl.d.ts +26 -33
  154. package/dist/types/schema/src/page.d.ts +4 -4
  155. package/dist/types/schema/src/problems.d.ts +82 -41
  156. package/dist/types/schema/src/refs.d.ts +0 -9
  157. package/dist/types/schema/src/schema.d.ts +17 -12
  158. package/dist/types/schema/src/selfOps.d.ts +20 -19
  159. package/dist/types/schema/src/traits.d.ts +28 -0
  160. package/dist/types/schema/src/typesSource.d.ts +1 -1
  161. package/dist/types/schema/src/values.d.ts +5 -2
  162. package/dist/types/schema/src/widening.d.ts +3 -0
  163. package/dist/types/sdk/src/analytics.d.ts +2 -1
  164. package/dist/types/sdk/src/app.d.ts +40 -14
  165. package/dist/types/sdk/src/astro-image.d.ts +19 -0
  166. package/dist/types/sdk/src/astro-response.d.ts +6 -0
  167. package/dist/types/sdk/src/astro-server.d.ts +16 -0
  168. package/dist/types/sdk/src/astro.d.ts +19 -0
  169. package/dist/types/sdk/src/bridge.d.ts +2 -4
  170. package/dist/types/sdk/src/code.d.ts +61 -0
  171. package/dist/types/sdk/src/delegation.d.ts +13 -3
  172. package/dist/types/sdk/src/delivery/changes.d.ts +4 -4
  173. package/dist/types/sdk/src/delivery/client.d.ts +33 -22
  174. package/dist/types/sdk/src/delivery/fields.d.ts +3 -3
  175. package/dist/types/sdk/src/delivery/index.d.ts +3 -3
  176. package/dist/types/sdk/src/delivery/media.d.ts +5 -8
  177. package/dist/types/sdk/src/delivery/query.d.ts +15 -11
  178. package/dist/types/sdk/src/delivery/schema.d.ts +1 -1
  179. package/dist/types/sdk/src/delivery/values.d.ts +10 -14
  180. package/dist/types/sdk/src/delivery.d.ts +2 -2
  181. package/dist/types/sdk/src/dev-operations.d.ts +20 -0
  182. package/dist/types/sdk/src/dev.d.ts +6 -5
  183. package/dist/types/sdk/src/end-users.d.ts +190 -0
  184. package/dist/types/sdk/src/i18n.d.ts +2 -2
  185. package/dist/types/sdk/src/integrations.d.ts +14 -21
  186. package/dist/types/sdk/src/operations.d.ts +17 -0
  187. package/dist/types/sdk/src/preview.d.ts +2 -1
  188. package/dist/types/sdk/src/rich-text.d.ts +2 -2
  189. package/dist/types/sdk/src/schema.d.ts +1 -1
  190. package/dist/types/sdk/src/site/artifact.d.ts +64 -0
  191. package/dist/types/sdk/src/site/build-file.d.ts +30 -0
  192. package/dist/types/sdk/src/site/check-code.d.ts +14 -0
  193. package/dist/types/sdk/src/site/check-text.d.ts +19 -0
  194. package/dist/types/sdk/src/site/cli.d.ts +52 -0
  195. package/dist/types/sdk/src/site/content-type.d.ts +2 -0
  196. package/dist/types/sdk/src/site/labels.d.ts +14 -0
  197. package/dist/types/sdk/src/types.d.ts +1 -1
  198. package/dist/{types-B77qvqPJ.js → types-DkO2N7u2.js} +5 -6
  199. package/dist/types.js +1 -1
  200. package/dist/{typesSource-CWybQYus.js → typesSource-VJIxtN9b.js} +17 -15
  201. package/dist/workflow-CUpl6hO_.js +148 -0
  202. package/package.json +32 -6
  203. package/dist/apps-BxnJ1RlU.js +0 -435
  204. package/dist/bridge-DtHw9hS6.js +0 -74
  205. package/dist/collection-BEOxeISR.js +0 -189
  206. package/dist/customers-DTbL0qn6.js +0 -86
  207. package/dist/customers.d.ts +0 -1
  208. package/dist/customers.js +0 -185
  209. package/dist/embeds-B5V54Zur.js +0 -34
  210. package/dist/ids--RF7hGyC.js +0 -36
  211. package/dist/src-sazhzYui.js +0 -71
  212. package/dist/types/contract/src/customers.d.ts +0 -266
  213. package/dist/types/schema/src/legacy.d.ts +0 -2
  214. package/dist/types/schema/src/media.d.ts +0 -5
  215. package/dist/types/sdk/src/customers.d.ts +0 -184
@@ -0,0 +1,95 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ // src/operations.ts
3
+ const KEY = Symbol.for("tunasand.operations");
4
+ const shared = globalThis;
5
+ const scopes = shared[KEY] ??= new AsyncLocalStorage();
6
+ const closed = () => Object.assign(/* @__PURE__ */ new Error("closed"), {
7
+ name: "OperationError",
8
+ code: "closed"
9
+ });
10
+ /** 終わった呼び出しの操作を拒む(先に取り出した値でも使えない) */
11
+ const openOf = (scope) => {
12
+ if (!scope.operations) throw closed();
13
+ return scope.operations;
14
+ };
15
+ const guarded = (scope) => Object.freeze({
16
+ call: async (name, input) => openOf(scope).call(name, input),
17
+ open: async (name, input) => openOf(scope).open(name, input),
18
+ fetch: async (input, init) => openOf(scope).fetch(input, init),
19
+ log: async (level, message) => openOf(scope).log(level, message)
20
+ });
21
+ /**
22
+ * 処理している呼び出しの操作
23
+ * @throws Error `operations_outside_call`(処理の外)、OperationError `closed`(呼び出しの終わりの後)
24
+ */
25
+ function operations() {
26
+ const scope = scopes.getStore();
27
+ if (!scope) throw new Error("operations_outside_call");
28
+ openOf(scope);
29
+ return guarded(scope);
30
+ }
31
+ /** 本文の終わり、打ち切り、失敗のどれかで1回だけ end を呼ぶ応答(本文のない応答はすぐに呼ぶ) */
32
+ function endingResponse(response, end) {
33
+ if (!response.body) {
34
+ end();
35
+ return response;
36
+ }
37
+ const reader = response.body.getReader();
38
+ const body = new ReadableStream({
39
+ async pull(controller) {
40
+ try {
41
+ const { done, value } = await reader.read();
42
+ if (!done) return controller.enqueue(value);
43
+ end();
44
+ controller.close();
45
+ } catch (e) {
46
+ end();
47
+ controller.error(e);
48
+ }
49
+ },
50
+ async cancel(reason) {
51
+ end();
52
+ await reader.cancel(reason);
53
+ }
54
+ }, { highWaterMark: 0 });
55
+ return new Response(body, {
56
+ status: response.status,
57
+ statusText: response.statusText,
58
+ headers: response.headers
59
+ });
60
+ }
61
+ /** given を、work とその中の非同期の処理の `operations()` にする(応答の本文の終わりに閉じる) */
62
+ async function provideOperations(given, work) {
63
+ const scope = { operations: given };
64
+ const end = () => {
65
+ scope.operations = null;
66
+ };
67
+ try {
68
+ const answer = await scopes.run(scope, async () => work());
69
+ if (answer instanceof Response) return endingResponse(answer, end);
70
+ end();
71
+ return answer;
72
+ } catch (e) {
73
+ end();
74
+ throw e;
75
+ }
76
+ }
77
+ /** 種類ごとの処理の中で `operations()` を使えるようにする(defineCode に渡す) */
78
+ function withOperations(handlers) {
79
+ const { request, event, check, schedule } = handlers;
80
+ return {
81
+ request: request && ((call, given) => provideOperations(given, () => request(call, operations()))),
82
+ event: event && ((call, given) => provideOperations(given, () => event(call, operations()))),
83
+ check: check && ((call, given) => provideOperations(given, () => check(call, operations()))),
84
+ schedule: schedule && ((call, given) => provideOperations(given, () => schedule(call, operations())))
85
+ };
86
+ }
87
+ /** 値の入れ物を作る(work とその中の非同期の処理だけが、その値を読む) */
88
+ function scopedValue() {
89
+ const storage = new AsyncLocalStorage();
90
+ return Object.freeze({
91
+ run: (value, work) => storage.run(value, work),
92
+ get: () => storage.getStore()
93
+ });
94
+ }
95
+ export { withOperations as i, provideOperations as n, scopedValue as r, operations as t };
@@ -0,0 +1 @@
1
+ export * from './types/sdk/src/operations.js';
@@ -0,0 +1 @@
1
+ export { t as operations, n as provideOperations, r as scopedValue, i as withOperations } from "./operations-CIB99rIY.js";
@@ -105,7 +105,7 @@ const matches = (when, record) => !when || when.in.includes(String(record[when.k
105
105
  const passes = (rule, record, now) => {
106
106
  const v = record[rule.key];
107
107
  if ("in" in rule) return rule.in.includes(String(v ?? ""));
108
- if ("notIn" in rule) return !rule.notIn.includes(String(v ?? ""));
108
+ if ("not_in" in rule) return !rule.not_in.includes(String(v ?? ""));
109
109
  if ("truthy" in rule) return Boolean(v);
110
110
  return v === void 0 || v === null || v === "" || String(v) <= now;
111
111
  };
package/dist/preview.js CHANGED
@@ -1 +1,8 @@
1
- export { n as SIGNED_HEADERS } from "./src-sazhzYui.js";
1
+ import { t as SECRET_TOKEN_PREFIXES } from "./ids-DmtIoqBX.js";
2
+ // src/preview.ts
3
+ /** CMS の転送のチケット(Authorization: Bearer がチケットの形でなければ null。照合は配信 API) */
4
+ function perspectiveTicketOf(request) {
5
+ const bearer = /^Bearer\s+(\S+)$/i.exec(request.headers.get("authorization") ?? "")?.[1];
6
+ return bearer?.startsWith(SECRET_TOKEN_PREFIXES.perspectiveTicket) ? bearer : null;
7
+ }
8
+ export { perspectiveTicketOf };
@@ -1,4 +1,4 @@
1
- import { l as bodyProblemText } from "./declared-DuNMsdXw.js";
1
+ import { l as richTextProblemText } from "./declared-CE4a61qb.js";
2
2
  // ../rich-text/src/types.ts
3
3
  /** 名前のついた値の見た目の種類(色・背景・大きさ) */
4
4
  const STYLE_KINDS = [
@@ -22,7 +22,7 @@ const SAFE_HREF = /^(?:https?:\/\/|mailto:|#|\/(?![/\\]))/i;
22
22
  /** 本文のリンク先として許可する形か(保存の検査とサイトの出力で共通) */
23
23
  const isSafeHref = (href) => SAFE_HREF.test(href);
24
24
  /** 許可しないリンク先の問題の文言 */
25
- const unsafeHrefMessage = (href) => bodyProblemText("link_unsafe", { href });
25
+ const unsafeHrefMessage = (href) => richTextProblemText("link_unsafe", { href });
26
26
  // ../rich-text/src/inline.ts
27
27
  /** 装飾の順序(外側から内側、Markdown と HTML の入れ子の順) */
28
28
  const MARK_ORDER = [
@@ -69,7 +69,7 @@ const CSS_SIZE = /^(\d{1,4}(\.\d{1,3})?(%|px|em|rem|pt)|xx-small|x-small|small|m
69
69
  /** 元の CSS の値として描画してよいか(kind は色か大きさ) */
70
70
  const isSafeCssValue = (kind, value) => (kind === "size" ? CSS_SIZE : CSS_COLOR).test(value.trim());
71
71
  /** 本文を設定で検査(合わない箇所をすべて返却) */
72
- function checkBody(body, profile) {
72
+ function checkRichText(body, profile) {
73
73
  const problems = [];
74
74
  const allowedMarks = new Set(profile.marks);
75
75
  body.forEach((block, index) => {
@@ -81,50 +81,50 @@ function checkBody(body, profile) {
81
81
  for (const inline of r) {
82
82
  if (typeof inline === "string") continue;
83
83
  if ("component" in inline) {
84
- if (plain) add(bodyProblemText("inline_component_here"));
85
- else if (!profile.components.includes(inline.component)) add(bodyProblemText("inline_component_unavailable", { name: inline.component }));
84
+ if (plain) add(richTextProblemText("inline_component_here"));
85
+ else if (!profile.components.includes(inline.component)) add(richTextProblemText("inline_component_unavailable", { name: inline.component }));
86
86
  continue;
87
87
  }
88
- if (plain && (inline.marks?.length || inline.link)) add(bodyProblemText("marks_here"));
89
- for (const m of inline.marks ?? []) if (!allowedMarks.has(m)) add(bodyProblemText("mark_unavailable", { mark: m }));
90
- if (profile.combineMarks === false && (inline.marks?.length ?? 0) + (inline.link ? 1 : 0) > 1) add(bodyProblemText("marks_combined"));
91
- if (inline.link?.rel && !profile.linkRels?.includes(inline.link.rel)) add(bodyProblemText("link_rel_unavailable", { rel: inline.link.rel }));
92
- if (inline.link?.target && !profile.linkTargets) add(bodyProblemText("link_target_unavailable"));
88
+ if (plain && (inline.marks?.length || inline.link)) add(richTextProblemText("marks_here"));
89
+ for (const m of inline.marks ?? []) if (!allowedMarks.has(m)) add(richTextProblemText("mark_unavailable", { mark: m }));
90
+ if (profile.combine_marks === false && (inline.marks?.length ?? 0) + (inline.link ? 1 : 0) > 1) add(richTextProblemText("marks_combined"));
91
+ if (inline.link?.rel && !profile.link_rels?.includes(inline.link.rel)) add(richTextProblemText("link_rel_unavailable", { rel: inline.link.rel }));
92
+ if (inline.link?.target && !profile.link_targets) add(richTextProblemText("link_target_unavailable"));
93
93
  if (inline.link && !isSafeHref(inline.link.href)) add(unsafeHrefMessage(inline.link.href));
94
94
  if (inline.style) textStyle(inline.style, plain);
95
95
  }
96
96
  };
97
97
  const textStyle = (style, plain) => {
98
- if (plain) add(bodyProblemText("text_style_here"));
98
+ if (plain) add(richTextProblemText("text_style_here"));
99
99
  for (const kind of STYLE_KINDS) {
100
100
  const v = style[kind];
101
101
  if (!v) continue;
102
- const declared = profile.textStyle?.[kind];
103
- if (!declared) add(bodyProblemText("style_unavailable", { kind }));
104
- else if (v.name && !declared.some((d) => d.name === v.name)) add(bodyProblemText("style_name_unknown", {
102
+ const declared = profile.text_style?.[kind];
103
+ if (!declared) add(richTextProblemText("style_unavailable", { kind }));
104
+ else if (v.name && !declared.some((d) => d.name === v.name)) add(richTextProblemText("style_name_unknown", {
105
105
  kind,
106
106
  name: v.name
107
107
  }));
108
- if (!v.name && !v.value) add(bodyProblemText("style_empty", { kind }));
109
- if (v.value && !isSafeCssValue(kind, v.value)) add(bodyProblemText("style_value_unsafe", {
108
+ if (!v.name && !v.value) add(richTextProblemText("style_empty", { kind }));
109
+ if (v.value && !isSafeCssValue(kind, v.value)) add(richTextProblemText("style_value_unsafe", {
110
110
  kind,
111
111
  value: v.value
112
112
  }));
113
113
  }
114
- for (const name of style.styles ?? []) if (!profile.textStyle?.styles?.some((d) => d.name === name)) add(bodyProblemText("named_style_unknown", { name }));
114
+ for (const name of style.styles ?? []) if (!profile.text_style?.styles?.some((d) => d.name === name)) add(richTextProblemText("named_style_unknown", { name }));
115
115
  };
116
116
  const align = (a) => {
117
- if (a && !profile.align) add(bodyProblemText("align_unavailable"));
117
+ if (a && !profile.align) add(richTextProblemText("align_unavailable"));
118
118
  };
119
119
  const cell = (c, head) => {
120
120
  if (isTableCell(c)) {
121
- if (!profile.table?.cells) add(bodyProblemText("table_cells_unavailable"));
122
- if ((c.colspan ?? 1) < 1 || (c.rowspan ?? 1) < 1) add(bodyProblemText("table_span_invalid"));
123
- c.content.forEach((r) => rich(r, (head || Boolean(c.header)) && profile.plain?.includes("tableHead")));
124
- } else rich(c, head && profile.plain?.includes("tableHead"));
121
+ if (!profile.table?.cells) add(richTextProblemText("table_cells_unavailable"));
122
+ if ((c.colspan ?? 1) < 1 || (c.rowspan ?? 1) < 1) add(richTextProblemText("table_span_invalid"));
123
+ c.content.forEach((r) => rich(r, (head || Boolean(c.header)) && profile.plain?.includes("table_head")));
124
+ } else rich(c, head && profile.plain?.includes("table_head"));
125
125
  };
126
126
  const variant = (v, allowed = []) => {
127
- if (v && !allowed.includes(v)) add(bodyProblemText("variant_unavailable", { variant: v }));
127
+ if (v && !allowed.includes(v)) add(richTextProblemText("variant_unavailable", { variant: v }));
128
128
  };
129
129
  const b = block;
130
130
  switch (b.type) {
@@ -134,7 +134,7 @@ function checkBody(body, profile) {
134
134
  rich(b.content);
135
135
  break;
136
136
  case "heading":
137
- if (!profile.headings.includes(b.level)) add(bodyProblemText("heading_unavailable", {
137
+ if (!profile.headings.includes(b.level)) add(richTextProblemText("heading_unavailable", {
138
138
  level: b.level,
139
139
  levels: profile.headings.join(", ")
140
140
  }));
@@ -145,12 +145,12 @@ function checkBody(body, profile) {
145
145
  case "list": {
146
146
  const p = profile.list;
147
147
  if (!p) {
148
- add(bodyProblemText("list_unavailable"));
148
+ add(richTextProblemText("list_unavailable"));
149
149
  break;
150
150
  }
151
- if (!p.nested && b.items.some((i) => i.children)) add(bodyProblemText("list_nested_unavailable"));
151
+ if (!p.nested && b.items.some((i) => i.children)) add(richTextProblemText("list_nested_unavailable"));
152
152
  const list = (l) => {
153
- if (l.ordered && !p.ordered) add(bodyProblemText("list_ordered_unavailable"));
153
+ if (l.ordered && !p.ordered) add(richTextProblemText("list_ordered_unavailable"));
154
154
  variant(l.variant, p.variants);
155
155
  l.items.forEach((i) => {
156
156
  rich(i.content);
@@ -163,61 +163,61 @@ function checkBody(body, profile) {
163
163
  case "quote": {
164
164
  const p = profile.quote;
165
165
  if (!p) {
166
- add(bodyProblemText("quote_unavailable"));
166
+ add(richTextProblemText("quote_unavailable"));
167
167
  break;
168
168
  }
169
- if (!p.multiple && b.content.length > 1) add(bodyProblemText("quote_single"));
170
- if (!p.cite && b.cite) add(bodyProblemText("quote_cite_unavailable"));
169
+ if (!p.multiple && b.content.length > 1) add(richTextProblemText("quote_single"));
170
+ if (!p.cite && b.cite) add(richTextProblemText("quote_cite_unavailable"));
171
171
  if (b.cite?.href && !isSafeHref(b.cite.href)) add(unsafeHrefMessage(b.cite.href));
172
172
  variant(b.variant);
173
173
  b.content.forEach((r) => rich(r));
174
174
  break;
175
175
  }
176
176
  case "code":
177
- if (!profile.code) add(bodyProblemText("code_unavailable"));
178
- else if (!profile.code.caption && b.caption) add(bodyProblemText("code_caption_unavailable"));
179
- else if (!profile.code.filename && b.filename) add(bodyProblemText("code_filename_unavailable"));
180
- else if (b.lang && profile.code.componentLangs?.[b.lang]) add(bodyProblemText("code_component_lang", {
177
+ if (!profile.code) add(richTextProblemText("code_unavailable"));
178
+ else if (!profile.code.caption && b.caption) add(richTextProblemText("code_caption_unavailable"));
179
+ else if (!profile.code.filename && b.filename) add(richTextProblemText("code_filename_unavailable"));
180
+ else if (b.lang && profile.code.component_langs?.[b.lang]) add(richTextProblemText("code_component_lang", {
181
181
  lang: b.lang,
182
- component: profile.code.componentLangs[b.lang]
182
+ component: profile.code.component_langs[b.lang]
183
183
  }));
184
184
  variant(b.variant);
185
185
  break;
186
186
  case "image":
187
- if (!profile.image) add(bodyProblemText("image_unavailable"));
187
+ if (!profile.image) add(richTextProblemText("image_unavailable"));
188
188
  else {
189
- if (b.link && !profile.image.link) add(bodyProblemText("image_link_unavailable"));
189
+ if (b.link && !profile.image.link) add(richTextProblemText("image_link_unavailable"));
190
190
  if (b.link && !isSafeHref(b.link.href)) add(unsafeHrefMessage(b.link.href));
191
- if (b.align && !profile.image.align) add(bodyProblemText("image_align_unavailable"));
191
+ if (b.align && !profile.image.align) add(richTextProblemText("image_align_unavailable"));
192
192
  }
193
193
  variant(b.variant, profile.image?.variants);
194
194
  break;
195
195
  case "file":
196
- if (!profile.file) add(bodyProblemText("file_unavailable"));
196
+ if (!profile.file) add(richTextProblemText("file_unavailable"));
197
197
  break;
198
198
  case "table": {
199
199
  const p = profile.table;
200
200
  if (!p) {
201
- add(bodyProblemText("table_unavailable"));
201
+ add(richTextProblemText("table_unavailable"));
202
202
  break;
203
203
  }
204
- if (p.head === "required" && !b.head) add(bodyProblemText("table_head_required"));
205
- if (p.caption === "required" && !b.caption) add(bodyProblemText("table_caption_required"));
206
- if (p.caption === "none" && b.caption) add(bodyProblemText("table_caption_unavailable"));
204
+ if (p.head === "required" && !b.head) add(richTextProblemText("table_head_required"));
205
+ if (p.caption === "required" && !b.caption) add(richTextProblemText("table_caption_required"));
206
+ if (p.caption === "none" && b.caption) add(richTextProblemText("table_caption_unavailable"));
207
207
  variant(b.variant);
208
- b.head?.forEach((r) => rich(r, profile.plain?.includes("tableHead")));
208
+ b.head?.forEach((r) => rich(r, profile.plain?.includes("table_head")));
209
209
  b.rows.forEach((row) => row.forEach((c) => cell(c, false)));
210
210
  break;
211
211
  }
212
212
  case "divider":
213
- if (!profile.divider) add(bodyProblemText("divider_unavailable"));
213
+ if (!profile.divider) add(richTextProblemText("divider_unavailable"));
214
214
  break;
215
215
  case "html":
216
- if (!profile.html) add(bodyProblemText("html_unavailable"));
216
+ if (!profile.html) add(richTextProblemText("html_unavailable"));
217
217
  break;
218
- case "component": if (!profile.components.includes(b.name)) add(bodyProblemText("component_unavailable", { name: b.name }));
218
+ case "component": if (!profile.components.includes(b.name)) add(richTextProblemText("component_unavailable", { name: b.name }));
219
219
  }
220
220
  });
221
221
  return problems;
222
222
  }
223
- export { mergeStyle as a, ALIGNS as c, MARK_HTML_TAGS as i, cellParagraphs as l, isSafeCssValue as n, sortMarks as o, HTML_TAG_MARKS as r, isSafeHref as s, checkBody as t, isTableCell as u };
223
+ export { mergeStyle as a, ALIGNS as c, MARK_HTML_TAGS as i, cellParagraphs as l, isSafeCssValue as n, sortMarks as o, HTML_TAG_MARKS as r, isSafeHref as s, checkRichText as t, isTableCell as u };
package/dist/rich-text.js CHANGED
@@ -1,5 +1,5 @@
1
- import { a as coreComponentOf, c as embedSrcOf, l as bodyProblemText, n as declaredPropsZod, o as EMBED_PROVIDERS, r as CITE, s as embedOfUrl } from "./declared-DuNMsdXw.js";
2
- import { c as ALIGNS, i as MARK_HTML_TAGS, l as cellParagraphs, n as isSafeCssValue, o as sortMarks, s as isSafeHref, t as checkBody, u as isTableCell } from "./profile-1em_lcxq.js";
1
+ import { a as coreComponentOf, c as embedSrcOf, l as richTextProblemText, n as declaredPropsZod, o as EMBED_PROVIDERS, r as CITE, s as embedOfUrl } from "./declared-CE4a61qb.js";
2
+ import { c as ALIGNS, i as MARK_HTML_TAGS, l as cellParagraphs, n as isSafeCssValue, o as sortMarks, s as isSafeHref, t as checkRichText, u as isTableCell } from "./profile-DBsXLvvI.js";
3
3
  import { z } from "zod";
4
4
  // ../rich-text/src/description.ts
5
5
  /** meta description の長さの上限(検索結果で省略されにくい字数の目安) */
@@ -81,7 +81,7 @@ const CSS_PROPERTY = {
81
81
  const EMBED_SANDBOX = "allow-scripts allow-same-origin allow-popups allow-presentation";
82
82
  const EMBED_ALLOW = "encrypted-media; picture-in-picture; fullscreen";
83
83
  /** 本文を HTML に */
84
- function bodyToHtml(body, options) {
84
+ function richTextToHtml(body, options) {
85
85
  const styleAttr = (style) => {
86
86
  const decls = Object.keys(CSS_PROPERTY).flatMap((kind) => {
87
87
  const v = style[kind];
@@ -180,7 +180,7 @@ function bodyToHtml(body, options) {
180
180
  href
181
181
  })}>${image ?? ""}${text("link-card-title", p.title)}${text("link-card-desc", p.desc)}${text("link-card-site", p.site)}</a>`;
182
182
  }
183
- case "gallery": return `<div class="gallery">${(Array.isArray(p.items) ? p.items : []).map((i) => `<figure>${imageHtml(i.media, void 0) ?? ""}${i.caption ? `<figcaption>${esc(i.caption)}</figcaption>` : ""}</figure>`).join("")}</div>`;
183
+ case "gallery": return `<div class="gallery">${(Array.isArray(p.items) ? p.items : []).map((i) => `<figure>${imageHtml(i.file, void 0) ?? ""}${i.caption ? `<figcaption>${esc(i.caption)}</figcaption>` : ""}</figure>`).join("")}</div>`;
184
184
  default: return "";
185
185
  }
186
186
  };
@@ -205,7 +205,7 @@ function bodyToHtml(body, options) {
205
205
  return b.caption ? `<figure${attrs({ class: b.variant })}>${pre}<figcaption>${esc(b.caption)}</figcaption></figure>` : pre;
206
206
  }
207
207
  case "image": {
208
- const img = imageHtml(b.media, b.alt);
208
+ const img = imageHtml(b.file, b.alt);
209
209
  if (!img) return "";
210
210
  const open = b.link ? linkOpen(b.link) : null;
211
211
  return `<figure${attrs({
@@ -219,7 +219,7 @@ function bodyToHtml(body, options) {
219
219
  return `<table${attrs({ class: b.variant })}>${b.caption ? `<caption>${esc(b.caption)}</caption>` : ""}${head}${rows}</table>`;
220
220
  }
221
221
  case "file": {
222
- const f = options.file?.(b.media);
222
+ const f = options.file?.(b.file);
223
223
  if (!f || !isSafeHref(f.url)) return "";
224
224
  return `<p class="file"><a${attrs({ href: f.url })}>${esc(b.label ?? f.url)}</a></p>`;
225
225
  }
@@ -248,7 +248,7 @@ const liftCites = (text) => text.split(CITE_TEXT).flatMap((piece, i) => i % 2 ?
248
248
  props: { id: piece }
249
249
  }] : piece ? [piece] : []);
250
250
  const link = z.object({
251
- href: z.string().min(1, bodyProblemText("link_href_missing")),
251
+ href: z.string().min(1, richTextProblemText("link_href_missing")),
252
252
  title: z.string().optional(),
253
253
  rel: z.string().optional(),
254
254
  target: z.literal("_blank").optional()
@@ -257,7 +257,7 @@ const named = z.object({
257
257
  name: z.string().min(1).optional(),
258
258
  value: z.string().min(1).optional()
259
259
  });
260
- const textStyle = z.object({
260
+ const text_style = z.object({
261
261
  color: named.optional(),
262
262
  background: named.optional(),
263
263
  size: named.optional(),
@@ -267,7 +267,7 @@ const text = z.object({
267
267
  text: z.string(),
268
268
  marks: z.array(z.enum(MARKS)).optional(),
269
269
  link: link.optional(),
270
- style: textStyle.optional()
270
+ style: text_style.optional()
271
271
  });
272
272
  const align = z.enum(ALIGNS).optional();
273
273
  /** 部品の props の検査(名前で核のコンポーネント、なければ宣言した部品、どちらもないか種類が違えば null) */
@@ -285,7 +285,7 @@ const inlineComponentOf = (declared) => z.object({
285
285
  const props = propsOf(c.component, true, z.never(), declared);
286
286
  if (!props) return void ctx.addIssue({
287
287
  code: "custom",
288
- message: bodyProblemText("inline_component_missing", { name: c.component })
288
+ message: richTextProblemText("inline_component_missing", { name: c.component })
289
289
  });
290
290
  const r = props.safeParse(c.props ?? {});
291
291
  if (!r.success) for (const issue of r.error.issues) ctx.addIssue({
@@ -365,7 +365,7 @@ function blockSchemaOf(profile, media, declared = []) {
365
365
  align,
366
366
  variant
367
367
  }),
368
- heading.refine((h) => h.content.some((i) => typeof i === "string" ? i.trim() : "text" in i && i.text?.trim()), bodyProblemText("heading_empty")),
368
+ heading.refine((h) => h.content.some((i) => typeof i === "string" ? i.trim() : "text" in i && i.text?.trim()), richTextProblemText("heading_empty")),
369
369
  list,
370
370
  z.object({
371
371
  type: z.literal("quote"),
@@ -386,7 +386,7 @@ function blockSchemaOf(profile, media, declared = []) {
386
386
  }),
387
387
  z.object({
388
388
  type: z.literal("image"),
389
- media,
389
+ file: media,
390
390
  alt: z.string().optional(),
391
391
  caption: z.string().optional(),
392
392
  link: link.optional(),
@@ -406,7 +406,7 @@ function blockSchemaOf(profile, media, declared = []) {
406
406
  }),
407
407
  z.object({
408
408
  type: z.literal("file"),
409
- media,
409
+ file: media,
410
410
  label: z.string().optional()
411
411
  }),
412
412
  z.object({ type: z.literal("divider") }),
@@ -426,7 +426,7 @@ function blockSchemaOf(profile, media, declared = []) {
426
426
  if (!props) {
427
427
  ctx.addIssue({
428
428
  code: "custom",
429
- message: bodyProblemText("component_missing", { name: out.name })
429
+ message: richTextProblemText("component_missing", { name: out.name })
430
430
  });
431
431
  return z.NEVER;
432
432
  }
@@ -444,11 +444,11 @@ function blockSchemaOf(profile, media, declared = []) {
444
444
  props: r.data
445
445
  };
446
446
  }
447
- for (const p of checkBody([out], profile)) ctx.addIssue({
447
+ for (const p of checkRichText([out], profile)) ctx.addIssue({
448
448
  code: "custom",
449
449
  message: p.message
450
450
  });
451
451
  return out;
452
452
  });
453
453
  }
454
- export { DESCRIPTION_MAX, EMBED_PROVIDERS, READING_SPEED, blockSchemaOf, bodyToHtml, cellParagraphs, citesOf, descriptionOf, embedOfUrl, embedSrcOf, excerptOf, isSafeCssValue, isSafeHref, isTableCell, linksOf, plainOf, readMinOf };
454
+ export { DESCRIPTION_MAX, EMBED_PROVIDERS, READING_SPEED, blockSchemaOf, cellParagraphs, citesOf, descriptionOf, embedOfUrl, embedSrcOf, excerptOf, isSafeCssValue, isSafeHref, isTableCell, linksOf, plainOf, readMinOf, richTextToHtml };