resource-engine-devtools 0.1.0__py3-none-any.whl

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 (88) hide show
  1. resource_engine_devtools/__init__.py +6 -0
  2. resource_engine_devtools/ai/__init__.py +1 -0
  3. resource_engine_devtools/ai/example.py +66 -0
  4. resource_engine_devtools/ai/installer.py +424 -0
  5. resource_engine_devtools/ai/skill/SKILL.md +130 -0
  6. resource_engine_devtools/ai/skill/examples/README.md +7 -0
  7. resource_engine_devtools/ai/skill/examples/invoices/__init__.py +0 -0
  8. resource_engine_devtools/ai/skill/examples/invoices/app.py +245 -0
  9. resource_engine_devtools/ai/skill/examples/invoices/application/__init__.py +0 -0
  10. resource_engine_devtools/ai/skill/examples/invoices/application/actions.py +61 -0
  11. resource_engine_devtools/ai/skill/examples/invoices/application/balances.py +51 -0
  12. resource_engine_devtools/ai/skill/examples/invoices/application/customers.py +35 -0
  13. resource_engine_devtools/ai/skill/examples/invoices/application/hooks.py +61 -0
  14. resource_engine_devtools/ai/skill/examples/invoices/application/processes.py +80 -0
  15. resource_engine_devtools/ai/skill/examples/invoices/application/resource.py +112 -0
  16. resource_engine_devtools/ai/skill/examples/invoices/application/schemas.py +164 -0
  17. resource_engine_devtools/ai/skill/examples/invoices/application/tags.py +77 -0
  18. resource_engine_devtools/ai/skill/examples/invoices/authz.py +126 -0
  19. resource_engine_devtools/ai/skill/examples/invoices/bootstrap.py +80 -0
  20. resource_engine_devtools/ai/skill/examples/invoices/domain/__init__.py +0 -0
  21. resource_engine_devtools/ai/skill/examples/invoices/domain/entities.py +112 -0
  22. resource_engine_devtools/ai/skill/examples/invoices/domain/events.py +22 -0
  23. resource_engine_devtools/ai/skill/examples/invoices/domain/state_machine.py +88 -0
  24. resource_engine_devtools/ai/skill/examples/invoices/infrastructure/__init__.py +0 -0
  25. resource_engine_devtools/ai/skill/examples/invoices/infrastructure/persistence.py +121 -0
  26. resource_engine_devtools/ai/skill/examples/invoices/locale/en/LC_MESSAGES/messages.po +682 -0
  27. resource_engine_devtools/ai/skill/examples/invoices/locale/es/LC_MESSAGES/messages.po +685 -0
  28. resource_engine_devtools/ai/skill/examples/invoices/notifications.py +47 -0
  29. resource_engine_devtools/ai/skill/examples/invoices/templates/email/base.html +7 -0
  30. resource_engine_devtools/ai/skill/examples/invoices/templates/email/invoice_approved.html +5 -0
  31. resource_engine_devtools/ai/skill/examples/invoices/templates/email/invoice_approved.subject.txt +1 -0
  32. resource_engine_devtools/ai/skill/examples/invoices/templates/email/invoice_approved.txt +5 -0
  33. resource_engine_devtools/ai/skill/examples/invoices/tests/conftest.py +40 -0
  34. resource_engine_devtools/ai/skill/examples/invoices/tests/test_invoices_engine.py +241 -0
  35. resource_engine_devtools/ai/skill/examples/invoices/worker.py +53 -0
  36. resource_engine_devtools/ai/skill/llms.txt +25 -0
  37. resource_engine_devtools/ai/skill/references/anti-patterns.md +209 -0
  38. resource_engine_devtools/ai/skill/references/docstrings.md +97 -0
  39. resource_engine_devtools/ai/skill/references/errors.md +81 -0
  40. resource_engine_devtools/ai/skill/references/lifecycle.md +118 -0
  41. resource_engine_devtools/ai/skill/references/permissions.md +111 -0
  42. resource_engine_devtools/ai/skill/references/resource.md +301 -0
  43. resource_engine_devtools/ai/skill/references/state-machines.md +126 -0
  44. resource_engine_devtools/ai/skill/references/testing.md +80 -0
  45. resource_engine_devtools/ai/templates/agents_block.md +26 -0
  46. resource_engine_devtools/ai/templates/cursor_rule.mdc +7 -0
  47. resource_engine_devtools/check.py +67 -0
  48. resource_engine_devtools/cli.py +1112 -0
  49. resource_engine_devtools/consumer_scaffold.py +715 -0
  50. resource_engine_devtools/contracts.py +471 -0
  51. resource_engine_devtools/db.py +132 -0
  52. resource_engine_devtools/declarations_check.py +116 -0
  53. resource_engine_devtools/documentation/__init__.py +10 -0
  54. resource_engine_devtools/documentation/docstrings.py +72 -0
  55. resource_engine_devtools/documentation/generators/__init__.py +9 -0
  56. resource_engine_devtools/documentation/generators/ai_context.py +121 -0
  57. resource_engine_devtools/documentation/generators/api.py +63 -0
  58. resource_engine_devtools/documentation/generators/json.py +12 -0
  59. resource_engine_devtools/documentation/generators/markdown.py +687 -0
  60. resource_engine_devtools/documentation/generators/mermaid.py +22 -0
  61. resource_engine_devtools/documentation/generators/site.py +379 -0
  62. resource_engine_devtools/documentation/generators/site_assets/site.css +62 -0
  63. resource_engine_devtools/documentation/generators/site_assets/site.js +54 -0
  64. resource_engine_devtools/documentation/i18n.py +185 -0
  65. resource_engine_devtools/documentation/introspector.py +563 -0
  66. resource_engine_devtools/documentation/locale/ca/LC_MESSAGES/docs.po +628 -0
  67. resource_engine_devtools/documentation/locale/es/LC_MESSAGES/docs.po +627 -0
  68. resource_engine_devtools/documentation/model.py +311 -0
  69. resource_engine_devtools/documentation/validator.py +128 -0
  70. resource_engine_devtools/emails.py +172 -0
  71. resource_engine_devtools/events_check.py +124 -0
  72. resource_engine_devtools/gates_check.py +133 -0
  73. resource_engine_devtools/hooks_check.py +287 -0
  74. resource_engine_devtools/i18n.py +312 -0
  75. resource_engine_devtools/loader.py +93 -0
  76. resource_engine_devtools/logic_check.py +136 -0
  77. resource_engine_devtools/mcp_server.py +685 -0
  78. resource_engine_devtools/py.typed +0 -0
  79. resource_engine_devtools/scaffold.py +805 -0
  80. resource_engine_devtools/scaffold_parts.py +637 -0
  81. resource_engine_devtools/source_edit.py +424 -0
  82. resource_engine_devtools/templates_check.py +59 -0
  83. resource_engine_devtools/worker.py +68 -0
  84. resource_engine_devtools-0.1.0.dist-info/METADATA +38 -0
  85. resource_engine_devtools-0.1.0.dist-info/RECORD +88 -0
  86. resource_engine_devtools-0.1.0.dist-info/WHEEL +4 -0
  87. resource_engine_devtools-0.1.0.dist-info/entry_points.txt +2 -0
  88. resource_engine_devtools-0.1.0.dist-info/licenses/LICENSE +202 -0
@@ -0,0 +1,22 @@
1
+ """State machines as Mermaid diagrams."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from resource_engine_devtools.documentation.model import StateMachineDoc
6
+
7
+
8
+ def render_state_machine(sm: StateMachineDoc) -> str:
9
+ """Mermaid ``stateDiagram-v2`` built from the executable machine definition."""
10
+ lines = ["stateDiagram-v2"]
11
+ for s in sm.states:
12
+ label = s.name if s.name and s.name != s.id else s.id
13
+ lines.append(f" {s.id}: {label}")
14
+ for s in sm.states:
15
+ if s.initial:
16
+ lines.append(f" [*] --> {s.id}")
17
+ for t in sm.transitions:
18
+ lines.append(f" {t.source} --> {t.target}: {t.event}")
19
+ for s in sm.states:
20
+ if s.final:
21
+ lines.append(f" {s.id} --> [*]")
22
+ return "\n".join(lines)
@@ -0,0 +1,379 @@
1
+ """A browsable static site of the functional documentation: the same pages as
2
+ ``docs generate`` (resources, state diagrams, permission matrix) plus the
3
+ published events, as plain HTML with navigation and search. The API's
4
+ machine-readable documents (``openapi.json``, ``asyncapi.json``,
5
+ ``schema.graphql``) are written next to it and linked from the home page; to
6
+ try the API, use the explorer (``mount_explorer``, docs/explorer.md).
7
+
8
+ ``resource-engine docs site --out site/`` writes it; any static host serves it
9
+ (GitHub Pages, S3, an intranet server). Diagrams are drawn in the browser by
10
+ Mermaid, from a CDN unless ``--mermaid-url`` points elsewhere (or is empty:
11
+ then they stay as text).
12
+ """
13
+
14
+ from __future__ import annotations
15
+
16
+ import html
17
+ import json
18
+ import re
19
+ from collections.abc import Callable, Mapping, Sequence
20
+ from dataclasses import dataclass
21
+ from typing import Any
22
+
23
+ from markdown_it import MarkdownIt
24
+
25
+ from resource_engine_devtools.documentation.generators.markdown import render_markdown
26
+ from resource_engine_devtools.documentation.i18n import docs_locale, t, translate_model
27
+ from resource_engine_devtools.documentation.model import DocumentationModel
28
+
29
+ MERMAID_URL = "https://cdn.jsdelivr.net/npm/mermaid@11.4.1/dist/mermaid.esm.min.mjs"
30
+
31
+
32
+ def labels() -> dict[str, str]:
33
+ """The site's own texts, in the current docs locale."""
34
+ return {
35
+ "home": t("Home"),
36
+ "permissions": t("Permissions"),
37
+ "events": t("Events"),
38
+ "machines": t("State machines"),
39
+ "emails": t("Emails"),
40
+ "documents": t("Documents"),
41
+ "resources": t("Resources"),
42
+ "search": t("Search…"),
43
+ "no_results": t("No results"),
44
+ "generated": t("Generated from the code with Resource Engine"),
45
+ "language": t("Language"),
46
+ }
47
+
48
+
49
+ @dataclass(frozen=True)
50
+ class SiteOptions:
51
+ """What the HTML site includes beyond the model: API documents, the title and the Mermaid
52
+ script."""
53
+
54
+ asyncapi: Mapping[str, Any] | None = None
55
+ title: str | None = None
56
+ mermaid_url: str = MERMAID_URL
57
+ openapi: Mapping[str, Any] | None = None
58
+ graphql: str | None = None
59
+
60
+
61
+ def render_site(
62
+ model: DocumentationModel,
63
+ *,
64
+ asyncapi: Mapping[str, Any] | None = None,
65
+ title: str | None = None,
66
+ mermaid_url: str = MERMAID_URL,
67
+ locales: Sequence[str] | None = None,
68
+ translate: Callable[[str], Callable[[str], str]] | None = None,
69
+ openapi: Mapping[str, Any] | None = None,
70
+ graphql: str | None = None,
71
+ ) -> dict[str, str]:
72
+ """Return ``{relative_path: content}`` of the site.
73
+
74
+ With several ``locales`` each gets a copy of the site under its own folder
75
+ (``ca/``, ``en/``), a language switcher on every page, and a root
76
+ ``index.html`` that sends visitors to the first one. ``translate(locale)``
77
+ gives the application's gettext for a locale (its docstrings and
78
+ descriptions); the generator's own texts come with devtools.
79
+
80
+ ``openapi`` and ``graphql`` (SDL), with ``asyncapi``, are written as
81
+ files next to the pages and linked from the home page.
82
+ """
83
+ options = SiteOptions(asyncapi, title, mermaid_url, openapi, graphql)
84
+ if locales and len(locales) > 1:
85
+ files: dict[str, str] = {}
86
+ for locale in locales:
87
+ localised = translate_model(model, translate(locale)) if translate else model
88
+ with docs_locale(locale):
89
+ part = _render_site(localised, options, locale=locale, others=locales)
90
+ files.update({f"{locale}/{path}": text for path, text in part.items()})
91
+ files["index.html"] = _redirect(list(locales))
92
+ return files
93
+ only = locales[0] if locales else None
94
+ if only and translate:
95
+ model = translate_model(model, translate(only))
96
+ with docs_locale(only):
97
+ return _render_site(model, options, locale=only, others=())
98
+
99
+
100
+ def _render_site(
101
+ model: DocumentationModel, options: SiteOptions, *, locale: str | None, others: Sequence[str]
102
+ ) -> dict[str, str]:
103
+ from resource_engine_devtools.documentation.generators.api import (
104
+ api_pages,
105
+ documents_section,
106
+ )
107
+
108
+ LABELS = labels()
109
+ asyncapi = options.asyncapi
110
+ pages = render_markdown(model)
111
+ extra, documents = api_pages(asyncapi, options.openapi, options.graphql)
112
+ pages.update(extra)
113
+ pages["index.md"] = pages.get("index.md", "") + documents_section(documents)
114
+ title = (
115
+ options.title
116
+ or (asyncapi or {}).get("info", {}).get("title")
117
+ or t("Functional documentation")
118
+ )
119
+ md = _markdown()
120
+ nav = _navigation(model, set(pages))
121
+ files: dict[str, str] = dict(documents)
122
+ search: list[dict[str, str]] = []
123
+ for path, text in sorted(pages.items()):
124
+ target = path.removesuffix(".md") + ".html"
125
+ heading = _first_heading(text) or path
126
+ body = md.render(text)
127
+ files[target] = _page(
128
+ title=title,
129
+ heading=heading,
130
+ body=_links(body),
131
+ nav=nav,
132
+ current=target,
133
+ root="../" * target.count("/"),
134
+ mermaid_url=options.mermaid_url,
135
+ locale=locale,
136
+ others=others,
137
+ labels=LABELS,
138
+ )
139
+ search.append({"path": target, "title": heading, "text": _plain(text)[:4000]})
140
+ files["assets/site.css"] = _asset("site.css")
141
+ index = json.dumps(search, ensure_ascii=False)
142
+ script = _asset("site.js").replace("__NO_RESULTS__", json.dumps(LABELS["no_results"]))
143
+ files["assets/site.js"] = f"window.SITE_SEARCH = {index};\n{script}"
144
+ return files
145
+
146
+
147
+ def render_events(asyncapi: Mapping[str, Any]) -> str:
148
+ """The published events (AsyncAPI) as a page: one section per channel."""
149
+ components = asyncapi.get("components", {})
150
+ messages = components.get("messages", {})
151
+ schemas = components.get("schemas", {})
152
+ out = [
153
+ f"# {t('Published events')}",
154
+ "",
155
+ t("Messages the application publishes after each committed change."),
156
+ ]
157
+ for name, channel in asyncapi.get("channels", {}).items():
158
+ out += ["", f"## {name}", ""]
159
+ if channel.get("description"):
160
+ out += [channel["description"].strip().splitlines()[0], ""]
161
+ out += [f"| {t('Event')} | {t('Description')} | {t('Data')} |", "|---|---|---|"]
162
+ for event, ref in channel.get("messages", {}).items():
163
+ message = messages.get(_ref_name(ref), {})
164
+ schema = schemas.get(_ref_name(message.get("payload", {})), {})
165
+ payload = schema.get("properties", {}).get("payload", {}).get("properties", {})
166
+ fields = ", ".join(f"`{f}`{_describe(s)}" for f, s in payload.items()) or "—"
167
+ summary = _cell(message.get("summary") or "")
168
+ out.append(f"| `{event}` | {summary or '—'} | {fields} |")
169
+ return "\n".join(out) + "\n"
170
+
171
+
172
+ # ----------------------------------------------------------------- helpers
173
+
174
+
175
+ def _markdown() -> MarkdownIt:
176
+ md = MarkdownIt("commonmark", {"html": False}).enable("table")
177
+ # plain functions replace the default rules (markdown-it types them as methods)
178
+ rules: dict[str, Any] = getattr(md.renderer, "rules") # noqa: B009
179
+ default_fence = rules["fence"]
180
+
181
+ def fence(tokens: Any, idx: int, options: Any, env: Any) -> str:
182
+ token = tokens[idx]
183
+ if token.info.strip() == "mermaid":
184
+ return f'<pre class="mermaid">{html.escape(token.content)}</pre>\n'
185
+ if token.info.strip() == "email-html":
186
+ # the email's own HTML, isolated: no scripts, no access to the site
187
+ return (
188
+ f'<iframe class="email-preview" sandbox="" referrerpolicy="no-referrer" '
189
+ f'loading="lazy" title="HTML" srcdoc="{html.escape(token.content, quote=True)}">'
190
+ "</iframe>\n"
191
+ )
192
+ rendered: str = default_fence(tokens, idx, options, env)
193
+ return rendered
194
+
195
+ def heading_open(tokens: Any, idx: int, options: Any, env: Any) -> str:
196
+ token = tokens[idx]
197
+ slug = _slug(tokens[idx + 1].content)
198
+ seen = env.setdefault("slugs", {})
199
+ seen[slug] = seen.get(slug, 0) + 1
200
+ if seen[slug] > 1:
201
+ slug = f"{slug}-{seen[slug]}"
202
+ return f'<{token.tag} id="{slug}">'
203
+
204
+ rules["fence"] = fence
205
+ rules["heading_open"] = heading_open
206
+ return md
207
+
208
+
209
+ def _slug(text: str) -> str:
210
+ text = re.sub(r"[`*\[\]()]", "", text.lower())
211
+ return re.sub(r"[^\w]+", "-", text).strip("-") or "section"
212
+
213
+
214
+ def _links(body: str) -> str:
215
+ """Links between the Markdown pages point at their HTML pages."""
216
+ return re.sub(r'href="([^":#]+)\.md(#[^"]*)?"', r'href="\1.html\2"', body)
217
+
218
+
219
+ def _first_heading(text: str) -> str | None:
220
+ match = re.search(r"^# (.+)$", text, re.MULTILINE)
221
+ return match.group(1).strip().strip("`") if match else None
222
+
223
+
224
+ def _plain(text: str) -> str:
225
+ text = re.sub(r"```.*?```", " ", text, flags=re.DOTALL)
226
+ text = re.sub(r"[`#*|\[\]()>_-]+", " ", text)
227
+ return re.sub(r"\s+", " ", text).strip()
228
+
229
+
230
+ def _cell(text: str) -> str:
231
+ return " ".join(text.split()).replace("|", "\\|")
232
+
233
+
234
+ def _ref_name(ref: Any) -> str:
235
+ value = ref.get("$ref", "") if isinstance(ref, Mapping) else ""
236
+ return value.rsplit("/", 1)[-1]
237
+
238
+
239
+ def _describe(schema: Mapping[str, Any]) -> str:
240
+ if "const" in schema:
241
+ return f" = `{schema['const']}`"
242
+ if "enum" in schema:
243
+ values = ", ".join(str(v) for v in schema["enum"][:8])
244
+ return f" ({values}{'…' if len(schema['enum']) > 8 else ''})"
245
+ return ""
246
+
247
+
248
+ # a page (href, label, None) or a group ("", label, [(href, label, summary)])
249
+ type NavItem = tuple[str, str, list[tuple[str, str, str]] | None]
250
+
251
+
252
+ def _navigation(model: DocumentationModel, pages: set[str]) -> list[NavItem]:
253
+ LABELS = labels()
254
+ items: list[NavItem] = [("index.html", LABELS["home"], None)]
255
+ for page, label in (
256
+ ("state-machines.md", "machines"),
257
+ ("emails.md", "emails"),
258
+ ("documents.md", "documents"),
259
+ ("permissions.md", "permissions"),
260
+ ("events.md", "events"),
261
+ ):
262
+ if page in pages:
263
+ items.append((page.removesuffix(".md") + ".html", LABELS[label], None))
264
+ resources = [(f"resources/{r.name}.html", r.name, r.doc.summary or "") for r in model.resources]
265
+ return [*items, ("", LABELS["resources"], resources)]
266
+
267
+
268
+ def _page(
269
+ *,
270
+ title: str,
271
+ heading: str,
272
+ body: str,
273
+ nav: list[NavItem],
274
+ current: str,
275
+ root: str,
276
+ mermaid_url: str,
277
+ locale: str | None = None,
278
+ others: Sequence[str] = (),
279
+ labels: Mapping[str, str],
280
+ ) -> str:
281
+ LABELS = labels
282
+ links = []
283
+ for href, label, children in nav:
284
+ if children is None:
285
+ active = ' aria-current="page"' if href == current else ""
286
+ links.append(f'<li><a href="{root}{href}"{active}>{html.escape(label)}</a></li>')
287
+ continue
288
+ links.append(f'<li class="group">{html.escape(label)}<ul>')
289
+ for child, name, summary in children:
290
+ active = ' aria-current="page"' if child == current else ""
291
+ tip = f' title="{html.escape(summary)}"' if summary else ""
292
+ links.append(f'<li><a href="{root}{child}"{active}{tip}>{html.escape(name)}</a></li>')
293
+ links.append("</ul></li>")
294
+ mermaid = (
295
+ f'<script type="module">import mermaid from {json.dumps(mermaid_url)};'
296
+ "mermaid.initialize({startOnLoad: true, flowchart: {useMaxWidth: false}, theme: matchMedia("
297
+ "'(prefers-color-scheme: dark)').matches ? 'dark' : 'default'});</script>"
298
+ if mermaid_url and '<pre class="mermaid">' in body
299
+ else ""
300
+ )
301
+ return f"""<!doctype html>
302
+ <html lang="{html.escape(locale or "en")}">
303
+ <head>
304
+ <meta charset="utf-8">
305
+ <meta name="viewport" content="width=device-width, initial-scale=1">
306
+ <title>{html.escape(heading)} · {html.escape(title)}</title>
307
+ <link rel="stylesheet" href="{root}assets/site.css">
308
+ </head>
309
+ <body data-root="{root}">
310
+ <header><button id="menu-toggle" aria-controls="nav" aria-expanded="false">☰</button>
311
+ <a class="brand" href="{root}index.html">{html.escape(title)}</a>
312
+ <input id="search" type="search" placeholder="{LABELS["search"]}" aria-label="{LABELS["search"]}">
313
+ {_switcher(locale, others, current, root, LABELS["language"])}
314
+ </header>
315
+ <div class="layout">
316
+ <nav id="nav" aria-label="{LABELS["resources"]}">
317
+ <ul id="results" hidden></ul>
318
+ <ul id="menu">{"".join(links)}</ul>
319
+ </nav>
320
+ <main>{body}</main>
321
+ </div>
322
+ <footer>{LABELS["generated"]}</footer>
323
+ <script src="{root}assets/site.js"></script>
324
+ {mermaid}
325
+ </body>
326
+ </html>
327
+ """
328
+
329
+
330
+ def _switcher(
331
+ locale: str | None, others: Sequence[str], current: str, root: str, label: str
332
+ ) -> str:
333
+ """Links to the same page in the other languages (``../en/resources/x.html``)."""
334
+ if len(others) < 2:
335
+ return ""
336
+ links = []
337
+ for other in others:
338
+ if other == locale:
339
+ links.append(f'<span aria-current="true" lang="{other}">{html.escape(other)}</span>')
340
+ else:
341
+ links.append(
342
+ f'<a href="{root}../{other}/{current}" hreflang="{other}" lang="{other}">'
343
+ f"{html.escape(other)}</a>"
344
+ )
345
+ return f'<nav class="languages" aria-label="{html.escape(label)}">{" ".join(links)}</nav>'
346
+
347
+
348
+ def _redirect(locales: list[str]) -> str:
349
+ """The root page: the visitor's language when offered, else the first one."""
350
+ target = f"{locales[0]}/index.html"
351
+ script = (
352
+ f"var offered = {json.dumps(locales)};"
353
+ "var wanted = (navigator.languages || [navigator.language || '']).map("
354
+ "function (l) { return l.toLowerCase(); });"
355
+ "var pick = offered[0];"
356
+ "outer: for (var i = 0; i < wanted.length; i++) {"
357
+ " for (var j = 0; j < offered.length; j++) {"
358
+ " var o = offered[j].toLowerCase();"
359
+ " if (wanted[i] === o || wanted[i].split('-')[0] === o.split('-')[0]) {"
360
+ " pick = offered[j]; break outer; } } }"
361
+ "location.replace(pick + '/index.html');"
362
+ )
363
+ links = " · ".join(f'<a href="{loc}/index.html" hreflang="{loc}">{loc}</a>' for loc in locales)
364
+ return f"""<!doctype html>
365
+ <html><head><meta charset="utf-8">
366
+ <meta name="viewport" content="width=device-width, initial-scale=1">
367
+ <noscript><meta http-equiv="refresh" content="0; url={target}"></noscript>
368
+ <script>{script}</script>
369
+ </head><body><p>{links}</p></body></html>
370
+ """
371
+
372
+
373
+ def _asset(name: str) -> str:
374
+ from importlib.resources import files
375
+
376
+ return (files(__package__) / "site_assets" / name).read_text(encoding="utf-8")
377
+
378
+
379
+ __all__ = ["MERMAID_URL", "SiteOptions", "labels", "render_events", "render_site"]
@@ -0,0 +1,62 @@
1
+ :root {
2
+ --bg: #ffffff; --fg: #1f2328; --muted: #59636e; --line: #d1d9e0; --soft: #f6f8fa;
3
+ --accent: #0b5cad; --code: #eff2f5;
4
+ color-scheme: light dark;
5
+ }
6
+ @media (prefers-color-scheme: dark) {
7
+ :root { --bg: #0f1115; --fg: #e6e8eb; --muted: #9aa4af; --line: #2d333b;
8
+ --soft: #161a20; --accent: #6cb6ff; --code: #1d232b; }
9
+ }
10
+ * { box-sizing: border-box; }
11
+ body { margin: 0; background: var(--bg); color: var(--fg);
12
+ font: 16px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif; }
13
+ header { display: flex; gap: 1rem; align-items: center; padding: .75rem 1.25rem;
14
+ border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--bg); z-index: 1; }
15
+ .brand { font-weight: 600; color: var(--fg); text-decoration: none; }
16
+ #search { margin-left: auto; width: min(22rem, 50vw); padding: .4rem .6rem; font: inherit;
17
+ border: 1px solid var(--line); border-radius: 6px; background: var(--soft); color: var(--fg); }
18
+ .layout { display: grid; grid-template-columns: 16rem minmax(0, 1fr); }
19
+ nav { border-right: 1px solid var(--line); padding: 1rem; position: sticky; top: 3.4rem;
20
+ align-self: start; max-height: calc(100vh - 3.4rem); overflow: auto; }
21
+ nav ul { list-style: none; margin: 0; padding: 0; }
22
+ nav li { margin: .15rem 0; }
23
+ nav .group { margin-top: 1rem; color: var(--muted); font-size: .8rem; text-transform: uppercase;
24
+ letter-spacing: .04em; }
25
+ nav .group ul { text-transform: none; letter-spacing: 0; font-size: 1rem; margin-top: .3rem; }
26
+ nav a { color: var(--fg); text-decoration: none; display: block; padding: .1rem .4rem; border-radius: 4px; }
27
+ nav a:hover, nav a[aria-current] { background: var(--soft); color: var(--accent); }
28
+ #results small { display: block; color: var(--muted); }
29
+ main { padding: 1.5rem 2.5rem 3rem; max-width: 72rem; }
30
+ h1 { margin-top: 0; }
31
+ h1, h2, h3 { scroll-margin-top: 4.5rem; } /* anchors clear the sticky header */
32
+ h2 { border-bottom: 1px solid var(--line); padding-bottom: .3rem; margin-top: 2rem; }
33
+ a { color: var(--accent); }
34
+ code { background: var(--code); padding: .1em .3em; border-radius: 4px; font-size: .9em; }
35
+ p code, li code, h1 code { overflow-wrap: anywhere; }
36
+ pre { background: var(--code); padding: .8rem 1rem; border-radius: 6px; overflow: auto; }
37
+ pre code { background: none; padding: 0; }
38
+ pre.mermaid { background: var(--soft); text-align: center; }
39
+ /* an email body, rendered in isolation; always on a white page like a mail client */
40
+ .languages { display: flex; gap: .5rem; align-items: center; font-size: .9rem; white-space: nowrap; }
41
+ .languages [aria-current] { font-weight: 600; }
42
+ iframe.email-preview { width: 100%; height: 22rem; border: 1px solid var(--line, #d0d7de); border-radius: 6px; background: #fff; }
43
+ table { border-collapse: collapse; display: block; overflow-x: auto; margin: 1rem 0; }
44
+ th, td { border: 1px solid var(--line); padding: .35rem .6rem; text-align: left; vertical-align: top; }
45
+ th { background: var(--soft); }
46
+ footer { color: var(--muted); font-size: .85rem; padding: 1rem 1.25rem; border-top: 1px solid var(--line); }
47
+ #menu-toggle { display: none; font: inherit; background: none; color: var(--fg);
48
+ border: 1px solid var(--line); border-radius: 6px; padding: .2rem .55rem; }
49
+ @media (max-width: 760px) {
50
+ .layout { grid-template-columns: 1fr; }
51
+ #menu-toggle { display: inline-block; }
52
+ nav { display: none; position: static; max-height: none; border-right: 0;
53
+ border-bottom: 1px solid var(--line); }
54
+ nav.open, nav.searching { display: block; }
55
+ main { padding: 1rem; }
56
+ #search { width: 45vw; }
57
+ }
58
+ @media print {
59
+ header, nav, footer { display: none; }
60
+ .layout { display: block; }
61
+ main { padding: 0; max-width: none; }
62
+ }
@@ -0,0 +1,54 @@
1
+ (function () {
2
+ var input = document.getElementById("search");
3
+ var results = document.getElementById("results");
4
+ var menu = document.getElementById("menu");
5
+ var root = document.body.dataset.root || "";
6
+ var nav = document.getElementById("nav");
7
+ var toggle = document.getElementById("menu-toggle");
8
+ toggle.addEventListener("click", function () {
9
+ var open = nav.classList.toggle("open");
10
+ toggle.setAttribute("aria-expanded", String(open));
11
+ });
12
+ function render(query) {
13
+ var terms = query.toLowerCase().split(/\s+/).filter(Boolean);
14
+ if (!terms.length) {
15
+ results.hidden = true; menu.hidden = false; nav.classList.remove("searching"); return;
16
+ }
17
+ var hits = window.SITE_SEARCH.map(function (page) {
18
+ var hay = (page.title + " " + page.text).toLowerCase();
19
+ var score = 0;
20
+ for (var i = 0; i < terms.length; i++) {
21
+ if (hay.indexOf(terms[i]) < 0) return null;
22
+ score += page.title.toLowerCase().indexOf(terms[i]) >= 0 ? 10 : 1;
23
+ }
24
+ return { page: page, score: score };
25
+ }).filter(Boolean).sort(function (a, b) { return b.score - a.score; }).slice(0, 20);
26
+ results.innerHTML = "";
27
+ if (!hits.length) {
28
+ var none = document.createElement("li");
29
+ none.textContent = __NO_RESULTS__;
30
+ results.appendChild(none);
31
+ }
32
+ hits.forEach(function (hit) {
33
+ var li = document.createElement("li");
34
+ var a = document.createElement("a");
35
+ a.href = root + hit.page.path;
36
+ a.textContent = hit.page.title;
37
+ var at = hit.page.text.toLowerCase().indexOf(terms[0]);
38
+ var small = document.createElement("small");
39
+ small.textContent = hit.page.text.slice(Math.max(0, at - 40), at + 80);
40
+ a.appendChild(small);
41
+ li.appendChild(a);
42
+ results.appendChild(li);
43
+ });
44
+ results.hidden = false; menu.hidden = true; nav.classList.add("searching");
45
+ }
46
+ input.addEventListener("input", function () { render(input.value); });
47
+ input.addEventListener("keydown", function (e) {
48
+ if (e.key === "Enter") { var first = results.querySelector("a"); if (first) location.href = first.href; }
49
+ if (e.key === "Escape") { input.value = ""; render(""); }
50
+ });
51
+ document.addEventListener("keydown", function (e) {
52
+ if (e.key === "/" && document.activeElement !== input) { e.preventDefault(); input.focus(); }
53
+ });
54
+ })();