asyncapi-viewer 2.0.0 → 2.1.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 (39) hide show
  1. package/README.md +13 -3
  2. package/dist/asyncapi-viewer.iife.js +22 -22
  3. package/dist/asyncapi-viewer.iife.js.map +1 -1
  4. package/dist/asyncapi-viewer.js +179 -132
  5. package/dist/asyncapi-viewer.js.map +1 -1
  6. package/dist/types/element.d.ts +33 -0
  7. package/dist/types/events.d.ts +99 -0
  8. package/dist/types/index.d.ts +12 -0
  9. package/dist/types/load/loader.d.ts +46 -0
  10. package/dist/types/load/refs.d.ts +62 -0
  11. package/dist/types/model/avro.d.ts +14 -0
  12. package/dist/types/model/context.d.ts +75 -0
  13. package/dist/types/model/invariants.d.ts +7 -0
  14. package/dist/types/model/normalize.d.ts +16 -0
  15. package/dist/types/model/schema.d.ts +16 -0
  16. package/dist/types/model/types.d.ts +324 -0
  17. package/dist/types/model/v2.d.ts +8 -0
  18. package/dist/types/model/v3.d.ts +8 -0
  19. package/dist/types/options.d.ts +56 -0
  20. package/dist/types/render/details.d.ts +23 -0
  21. package/dist/types/render/example.d.ts +36 -0
  22. package/dist/types/render/format.d.ts +2 -0
  23. package/dist/types/render/header.d.ts +19 -0
  24. package/dist/types/render/info.d.ts +4 -0
  25. package/dist/types/render/markdown.d.ts +4 -0
  26. package/dist/types/render/nav.d.ts +69 -0
  27. package/dist/types/render/operation.d.ts +18 -0
  28. package/dist/types/render/sections.d.ts +17 -0
  29. package/dist/types/render/sidebar.d.ts +30 -0
  30. package/dist/types/render/tag.d.ts +7 -0
  31. package/dist/types/render/tree.d.ts +36 -0
  32. package/dist/types/styles/base.d.ts +2 -0
  33. package/dist/types/styles/tokens.d.ts +7 -0
  34. package/dist/types/theme/theme.d.ts +26 -0
  35. package/dist/types/util/color.d.ts +22 -0
  36. package/dist/types/util/example.d.ts +8 -0
  37. package/package.json +12 -3
  38. package/types/react.d.ts +28 -0
  39. package/types/react.js +2 -0
@@ -0,0 +1,36 @@
1
+ /**
2
+ * The payload tree (spec 4.8): stacked rows, guide lines per level, expand/collapse with real
3
+ * buttons, a toolbar with counts, oneOf/anyOf as a segmented control, constraints under the
4
+ * description, and leaves for circular references. RawSchema renders as a labelled code block.
5
+ *
6
+ * Display rules that differ from the model: the "[]" item node of an array is not a row. A
7
+ * primitive item folds into the parent's type ("array of string"); an object item's children
8
+ * are shown as the array's children, and their path already reads "items[]".
9
+ */
10
+ import { nothing, type TemplateResult } from 'lit';
11
+ import type { Schema, SchemaNode } from '../model/types.js';
12
+ export declare const treeStyles: import("lit").CSSResult;
13
+ /** Expansion and variant selection for one tree, keyed by node path. */
14
+ export declare class TreeState {
15
+ #private;
16
+ readonly onChange: () => void;
17
+ constructor(onChange: () => void);
18
+ isExpanded(key: string, depth: number): boolean;
19
+ /** True once "Expand all" was used and nothing has been collapsed since. */
20
+ get allExpanded(): boolean;
21
+ toggle(key: string, depth: number): void;
22
+ setAll(expanded: boolean): void;
23
+ variant(key: string): number;
24
+ selectVariant(key: string, index: number): void;
25
+ }
26
+ export interface TreeOptions {
27
+ /** Toolbar text at the left; the field count when absent. */
28
+ label?: string;
29
+ /** Anchor prefix of the viewer, for links to the Schemas section. */
30
+ prefix: string;
31
+ /** Unique within the viewer, e.g. the message anchor plus "payload". */
32
+ key: string;
33
+ state: TreeState;
34
+ }
35
+ export declare function typeLabel(node: SchemaNode): string;
36
+ export declare function renderSchema(schema: Schema | undefined, options: TreeOptions): TemplateResult | typeof nothing;
@@ -0,0 +1,2 @@
1
+ /** Layout shell, typography and the shared small components (pills, chips, buttons). */
2
+ export declare const base: import("lit").CSSResult;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Design tokens (spec 4.3). Public variables are `--asyncapi-*`, set on the element by the
3
+ * theme file or page CSS. Each maps to a private `--_*` with the design default, so page CSS
4
+ * wins whenever it sets a public one. Dark values apply through the reflected
5
+ * `resolved-theme` attribute, so page CSS can scope overrides per mode.
6
+ */
7
+ export declare const tokens: import("lit").CSSResult;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Theme mode resolution (spec 4.4).
3
+ *
4
+ * `auto` follows the host page: Material for MkDocs (`body[data-md-color-scheme="slate"]`),
5
+ * then `html[data-theme="dark"]`, then `prefers-color-scheme`. All three are watched so the
6
+ * viewer follows the site's own toggle live. The in-viewer toggle overrides the host for this
7
+ * element only. The resolved mode is reflected as `resolved-theme="light|dark"` on the host so
8
+ * page CSS can scope overrides to one mode.
9
+ */
10
+ export type ThemeMode = 'auto' | 'light' | 'dark';
11
+ export type Resolved = 'light' | 'dark';
12
+ export declare class ThemeController {
13
+ #private;
14
+ private readonly host;
15
+ private readonly onChange;
16
+ constructor(host: HTMLElement, onChange: (resolved: Resolved) => void);
17
+ get resolved(): Resolved;
18
+ /** The option value; a change clears any toggle override. */
19
+ set mode(mode: ThemeMode);
20
+ /** The toggle button: flips the resolved mode for this element only. */
21
+ toggle(): void;
22
+ connect(): void;
23
+ disconnect(): void;
24
+ /** What the host page says, before any override. Exported for tests. */
25
+ hostPreference(): Resolved;
26
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Colour maths for the runtime rules in spec 4.2: badge text colour from the accent's
3
+ * lightness, and a text-safe variant of the accent when it does not reach 4.5:1 on the
4
+ * page background. Pure functions over `[r, g, b]` in 0-255 so they are easy to test.
5
+ */
6
+ export type RGB = [number, number, number];
7
+ /** Parse `rgb(…)`, `rgba(…)`, `#rgb`, `#rrggbb` or `#rrggbbaa`. Undefined for anything else. */
8
+ export declare function parseColor(text: string): RGB | undefined;
9
+ export declare function toHex([r, g, b]: RGB): string;
10
+ /** WCAG relative luminance, 0 (black) to 1 (white). */
11
+ export declare function luminance([r, g, b]: RGB): number;
12
+ /** WCAG contrast ratio, 1 to 21. */
13
+ export declare function contrast(a: RGB, b: RGB): number;
14
+ /** Spec 4.2: `#14161B` on light accents (lightness above 0.6), white otherwise. */
15
+ export declare function badgeInk(accent: RGB): string;
16
+ /**
17
+ * The accent itself when it reaches `ratio` against `background`, otherwise the nearest
18
+ * darker (light theme) or lighter (dark theme) shade that does. Mixes towards black or white
19
+ * in small steps so the hue is kept.
20
+ */
21
+ export declare function textSafe(accent: RGB, background: RGB, dark: boolean, ratio?: number): RGB;
22
+ export declare function mix(a: RGB, b: RGB, t: number): RGB;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Generated examples (ROADMAP amendment 9). When a message has no authored example, one is
3
+ * built from the schema so readers get a taste of real traffic. Values come from, in order:
4
+ * the field's own examples or default, const, the first enum value, the format, numeric bounds,
5
+ * then field-name heuristics. Never a bare "string" or 0 when a hint exists.
6
+ */
7
+ import type { Schema } from '../model/types.js';
8
+ export declare function generateExample(schema: Schema | undefined): unknown;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "asyncapi-viewer",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "Renders AsyncAPI 2 and 3 documents as a web component: <asyncapi-viewer src=\"...\">",
5
5
  "keywords": [
6
6
  "asyncapi",
@@ -23,13 +23,22 @@
23
23
  "files": [
24
24
  "dist",
25
25
  "theme",
26
+ "types",
26
27
  "README.md"
27
28
  ],
28
29
  "main": "./dist/asyncapi-viewer.js",
29
30
  "module": "./dist/asyncapi-viewer.js",
31
+ "types": "./dist/types/index.d.ts",
30
32
  "exports": {
31
- ".": "./dist/asyncapi-viewer.js",
33
+ ".": {
34
+ "types": "./dist/types/index.d.ts",
35
+ "default": "./dist/asyncapi-viewer.js"
36
+ },
32
37
  "./iife": "./dist/asyncapi-viewer.iife.js",
38
+ "./react": {
39
+ "types": "./types/react.d.ts",
40
+ "default": "./types/react.js"
41
+ },
33
42
  "./theme/asyncapi-theme.css": "./theme/asyncapi-theme.css"
34
43
  },
35
44
  "publishConfig": {
@@ -37,7 +46,7 @@
37
46
  },
38
47
  "scripts": {
39
48
  "dev": "vite",
40
- "build": "vite build",
49
+ "build": "vite build && tsc -p tsconfig.build.json",
41
50
  "typecheck": "tsc --noEmit",
42
51
  "lint": "eslint .",
43
52
  "check": "npm run typecheck && npm run lint",
@@ -0,0 +1,28 @@
1
+ /**
2
+ * JSX typing for <asyncapi-viewer> in React 19. Opt in once, anywhere in the app:
3
+ *
4
+ * import type {} from 'asyncapi-viewer/react';
5
+ *
6
+ * Attributes are the element's kebab-case names; booleans may be passed as true/false (React 19
7
+ * writes true as a bare attribute and removes false). Events use React 19's custom element
8
+ * convention: `onasyncapi-load` and `onasyncapi-error`.
9
+ */
10
+ import type { DetailedHTMLProps, HTMLAttributes } from 'react';
11
+ import type { AsyncAPIErrorEvent, AsyncAPILoadEvent, AsyncAPIViewerAttributes, AsyncAPIViewerElement } from 'asyncapi-viewer';
12
+
13
+ export interface AsyncAPIViewerJSXProps
14
+ extends Omit<DetailedHTMLProps<HTMLAttributes<AsyncAPIViewerElement>, AsyncAPIViewerElement>, keyof AsyncAPIViewerAttributes>,
15
+ AsyncAPIViewerAttributes {
16
+ /** The document loaded and rendered. */
17
+ 'onasyncapi-load'?: (event: AsyncAPILoadEvent) => void;
18
+ /** The document could not be loaded; the viewer shows the error in place. */
19
+ 'onasyncapi-error'?: (event: AsyncAPIErrorEvent) => void;
20
+ }
21
+
22
+ declare module 'react' {
23
+ namespace JSX {
24
+ interface IntrinsicElements {
25
+ 'asyncapi-viewer': AsyncAPIViewerJSXProps;
26
+ }
27
+ }
28
+ }
package/types/react.js ADDED
@@ -0,0 +1,2 @@
1
+ // Types only: see react.d.ts. Present so that `import 'asyncapi-viewer/react'` also resolves.
2
+ export {};