@antglobal/copilot-cards-web 1.0.3 → 1.0.5

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.
package/README.md CHANGED
@@ -78,14 +78,19 @@ Common render options include:
78
78
  | Option | Purpose |
79
79
  | --- | --- |
80
80
  | `variables` | Overrides initial schema variables |
81
- | `botId` | Selects bot-scoped custom action handlers |
82
- | `isMobile` | Overrides automatic viewport detection |
81
+ | `botId` | Optionally selects bot-scoped custom action handlers |
82
+ | `isMobile` | Explicitly enables mobile component layout; defaults to `false` |
83
+ | `responsive` | Explicitly enables mobile px-to-rem conversion when configured |
83
84
  | `fetch` | Supplies a custom request implementation |
84
85
  | `showToast` | Connects toast actions to the host UI |
85
86
  | `navigate` | Connects URL actions to host navigation |
86
87
  | `emit` | Receives events emitted by a card |
87
88
  | `copyText` | Connects copy actions to the host clipboard |
88
89
 
90
+ The SDK does not infer mobile mode or CSS units from viewport width. Pass only
91
+ `isMobile: true` for mobile layout with px output. To opt into REM conversion,
92
+ also pass `responsive: { mobile: { unit: "rem", rootValue: 100 } }`.
93
+
89
94
  ### Streaming
90
95
 
91
96
  Use `renderStreamingCard` when the card arrives incrementally from an AI model or server:
@@ -121,6 +126,8 @@ const bot = new BotSDK({
121
126
  await bot.renderCard(container, schema);
122
127
  ```
123
128
 
129
+ `botId` is optional. Omit it when the application uses only one default action scope; provide it when isolating custom handlers or loading per-bot action configuration.
130
+
124
131
  ## Built-in components
125
132
 
126
133
  The renderer includes:
package/dist/index.d.ts CHANGED
@@ -29,6 +29,25 @@ interface WebActionContextOptions {
29
29
  */
30
30
  declare function createWebActionContext(options?: WebActionContextOptions): ActionRunnerContext;
31
31
 
32
+ interface ResponsiveMobileOptions {
33
+ readonly unit: 'rem';
34
+ readonly rootValue: number;
35
+ }
36
+ interface ResponsiveOptions {
37
+ readonly mobile?: ResponsiveMobileOptions;
38
+ }
39
+ interface ResponsiveContext {
40
+ readonly active: boolean;
41
+ readonly rootValue: number;
42
+ resolveLength(value: string | number): string;
43
+ convertCSS(value: string): string;
44
+ }
45
+ /** Reusable REM preset; applied only when passed explicitly as `responsive.mobile`. */
46
+ declare const DEFAULT_MOBILE_RESPONSIVE: ResponsiveMobileOptions;
47
+ /** Convert CSS px lengths while preserving strings, comments, and URLs. */
48
+ declare function convertPixelTokens(value: string, rootValue: number): string;
49
+ declare function createResponsiveContext(isMobile: boolean, responsive?: ResponsiveOptions): ResponsiveContext;
50
+
32
51
  /**
33
52
  * renderCard — the primary public API for @antglobal/copilot-cards-web.
34
53
  *
@@ -44,8 +63,10 @@ declare function createWebActionContext(options?: WebActionContextOptions): Acti
44
63
  */
45
64
 
46
65
  interface RenderCardOptions extends WebActionContextOptions {
47
- /** Force mobile mode; auto-detected from viewport if omitted */
66
+ /** Enable mobile component layout explicitly (default false). */
48
67
  isMobile?: boolean;
68
+ /** Optional mobile sizing conversion; omitted values preserve px output. */
69
+ responsive?: ResponsiveOptions;
49
70
  /** External variables to merge into schema.variables (overrides schema defaults) */
50
71
  variables?: Record<string, any>;
51
72
  /** Bot ID — used to look up bot-scoped action handlers */
@@ -262,8 +283,8 @@ declare function connectSSE(instance: StreamingCardInstance, options: SSEConnect
262
283
  */
263
284
 
264
285
  interface BotSDKOptions {
265
- /** Bot ID identifies which bot this instance is for */
266
- botId: string;
286
+ /** Optional bot ID used to scope custom actions and action configuration */
287
+ botId?: string;
267
288
  /** Base URL for business API requests (e.g. 'https://api.example.com') */
268
289
  baseUrl?: string;
269
290
  /**
@@ -413,7 +434,7 @@ declare function buildStyleString(styles: Record<string, string | number | undef
413
434
  * common style helpers. Designed to be used by `renderCard` which
414
435
  * passes resolved props via `setData()`.
415
436
  *
416
- * Note: lifecycle management, event binding, and viewport detection
437
+ * Note: lifecycle management, event binding, and mobile-mode selection
417
438
  * are handled externally by `renderCard` / the render pipeline.
418
439
  * BaseElement keeps itself lightweight and focused on DOM rendering.
419
440
  */
@@ -422,16 +443,18 @@ declare abstract class BaseElement extends HTMLElement {
422
443
  protected _node: RenderTreeNode | null;
423
444
  protected _props: Record<string, any>;
424
445
  protected _isMobile: boolean;
446
+ protected _responsiveOptions?: ResponsiveOptions;
447
+ protected _responsive: ResponsiveContext;
425
448
  constructor();
426
449
  /**
427
450
  * Set component data and trigger render.
428
451
  * Called by the component renderer (from `renderCard` pipeline).
429
452
  */
430
- setData(node: RenderTreeNode, props: Record<string, any>, isMobile: boolean): void;
453
+ setData(node: RenderTreeNode, props: Record<string, any>, isMobile: boolean, responsive?: ResponsiveOptions): void;
431
454
  /**
432
455
  * Update props only (e.g. on variable change + re-render).
433
456
  */
434
- updateProps(props: Record<string, any>, isMobile?: boolean): void;
457
+ updateProps(props: Record<string, any>, isMobile?: boolean, responsive?: ResponsiveOptions): void;
435
458
  /**
436
459
  * Subclasses must implement this to render their UI into `this.shadowRoot`.
437
460
  */
@@ -445,6 +468,8 @@ declare abstract class BaseElement extends HTMLElement {
445
468
  protected buildInlineStyle(style?: Record<string, any>, isExpressionResult?: boolean): string;
446
469
  /** Resolve a single size value (number → px). */
447
470
  protected toCSS(value: string | number): string;
471
+ /** Assign component markup and convert only its CSS declarations. */
472
+ protected setShadowHTML(html: string): void;
448
473
  /**
449
474
  * Escape a value before interpolating it into a double-quoted HTML
450
475
  * attribute. Browsers decode the entities before parsing inline CSS, so
@@ -472,7 +497,7 @@ declare class CardText extends BaseElement {
472
497
  private _mdPendingUpdate;
473
498
  private _tooltipEl;
474
499
  private _tooltipTimer;
475
- setData(node: RenderTreeNode, props: Record<string, any>, isMobile: boolean): void;
500
+ setData(node: RenderTreeNode, props: Record<string, any>, isMobile: boolean, responsive?: ResponsiveOptions): void;
476
501
  protected render(): void;
477
502
  /**
478
503
  * Handle incremental content update in streaming mode.
@@ -500,7 +525,7 @@ declare class CardText extends BaseElement {
500
525
  * Remove cursor when streaming ends.
501
526
  * Called externally when streaming prop changes to false.
502
527
  */
503
- updateProps(props: Record<string, any>, isMobile?: boolean): void;
528
+ updateProps(props: Record<string, any>, isMobile?: boolean, responsive?: ResponsiveOptions): void;
504
529
  /**
505
530
  * Parse markdown to HTML using marked.
506
531
  */
@@ -596,6 +621,8 @@ declare class CardButton extends BaseElement {
596
621
  declare class CardInput extends BaseElement {
597
622
  static readonly is = "ai-card-input";
598
623
  protected render(): void;
624
+ private getAutoFocusControl;
625
+ private isFirstAvailableAutoFocusInput;
599
626
  /** Escape HTML entities for safe insertion. */
600
627
  private escapeHtml;
601
628
  /** Escape attribute values for safe insertion. */
@@ -789,30 +816,6 @@ declare class CardTag extends BaseElement {
789
816
  protected render(): void;
790
817
  }
791
818
 
792
- /**
793
- * CardSelect — Custom Element for a dropdown selector.
794
- *
795
- * Schema example:
796
- * ```json
797
- * {
798
- * "type": "Select",
799
- * "props": {
800
- * "placeholder": "请选择",
801
- * "options": [
802
- * { "label": "选项一", "value": "1" },
803
- * { "label": "选项二", "value": "2" }
804
- * ],
805
- * "value": ""
806
- * }
807
- * }
808
- * ```
809
- *
810
- * The value is semi-controlled: a user-picked option shows on the trigger
811
- * immediately even when no `onChange` action is wired, while any external
812
- * `props.value` change (e.g. a variable update re-render) overrides the
813
- * local pick.
814
- */
815
-
816
819
  declare class CardSelect extends BaseElement {
817
820
  private _open;
818
821
  private _activeIndex;
@@ -824,7 +827,7 @@ declare class CardSelect extends BaseElement {
824
827
  static readonly is = "ai-card-select";
825
828
  protected render(): void;
826
829
  disconnectedCallback(): void;
827
- updateProps(props: Record<string, any>, isMobile?: boolean): void;
830
+ updateProps(props: Record<string, any>, isMobile?: boolean, responsive?: ResponsiveOptions): void;
828
831
  private _setOpen;
829
832
  private openWithCurrentOption;
830
833
  private handleKeydown;
@@ -1017,6 +1020,8 @@ type InputAffix = string | InputAffixConfig;
1017
1020
  interface InputProps {
1018
1021
  /** Placeholder text */
1019
1022
  placeholder?: string;
1023
+ /** Focus the native input after the component is mounted (default false) */
1024
+ autoFocus?: boolean;
1020
1025
  /** HTML input type: text / textarea / password / number etc. */
1021
1026
  inputType?: 'text' | 'textarea' | 'password' | (string & {});
1022
1027
  /** Label text displayed above the input */
@@ -1191,6 +1196,8 @@ interface SelectStyles {
1191
1196
  option?: Record<string, any>;
1192
1197
  /** Style merged into the selected option */
1193
1198
  selectedOption?: Record<string, any>;
1199
+ /** Arrow wrapper style; overrides arrowSize for declared dimensions */
1200
+ arrow?: Record<string, any>;
1194
1201
  }
1195
1202
  interface SelectProps {
1196
1203
  /** Dropdown options list */
@@ -1217,6 +1224,8 @@ interface SelectProps {
1217
1224
  variant?: SelectVariant;
1218
1225
  /** Accent used for focus and selection states */
1219
1226
  accentColor?: string;
1227
+ /** Dropdown arrow size in px or as a CSS length */
1228
+ arrowSize?: number | string;
1220
1229
  /** Advanced semantic styles for internal parts */
1221
1230
  styles?: SelectStyles;
1222
1231
  }
@@ -1758,7 +1767,7 @@ declare class CardChoiceItem extends BaseElement {
1758
1767
  * for the `renderCard` pipeline to attach events and children.
1759
1768
  */
1760
1769
 
1761
- type ComponentRenderer = (node: RenderTreeNode, props: Record<string, any>, isMobile: boolean) => HTMLElement;
1770
+ type ComponentRenderer = (node: RenderTreeNode, props: Record<string, any>, isMobile: boolean, responsive?: ResponsiveOptions) => HTMLElement;
1762
1771
  declare const componentRenderers: Record<string, ComponentRenderer>;
1763
1772
  /**
1764
1773
  * Register a custom component renderer.
@@ -1775,5 +1784,5 @@ declare const componentRenderers: Record<string, ComponentRenderer>;
1775
1784
  */
1776
1785
  declare function registerComponent(type: string, renderer: ComponentRenderer): void;
1777
1786
 
1778
- export { BaseElement, BotSDK, CardButton, CardChoiceItem, CardChoiceList, CardCollapse, CardCounter, CardDivider, CardForm, CardHtml, CardIcon, CardImage, CardInput, CardLoading, CardPasscodeInput, CardProgress, CardRate, CardSelect, CardSteps, CardSwitch, CardTag, CardText, LocalActionConfigProvider, RemoteActionConfigProvider, buildStyleString, componentRenderers, connectSSE, connectStreaming, createWebActionContext, isMobileViewport, onViewportChange, pxToRem, pxToVw, registerComponent, renderCard, renderStreamingCard, resolveSize, sanitizeHtml, trimIncompleteTag };
1779
- export type { A2UIActionPayload, BotSDKOptions, ButtonProps, CardInstance, ChoiceIndicatorIcon, ChoiceItemProps, ChoiceListProps, ChoiceListValue, CollapseProps, ComponentRenderer, ConnectorConfig, CounterIcon, CounterProps, DividerProps, FormField, FormProps, FormRule, HtmlProps, IconProps, ImageProps, InputAffix, InputAffixConfig, InputProps, LoadingProps, PartialFinalizeResult, PasscodeInputProps, ProgressProps, ProgressSegment, RateProps, RenderCardOptions, SSEConnectOptions, SelectOption, SelectProps, SelectSize, SelectStyles, SelectVariant, StepIcon, StepItem, StepsProps, StreamingCardInstance, StreamingCardOptions, StreamingConnectOptions, StreamingConnection, SwitchProps, TagProps, TextProps, WebActionContextOptions };
1787
+ export { BaseElement, BotSDK, CardButton, CardChoiceItem, CardChoiceList, CardCollapse, CardCounter, CardDivider, CardForm, CardHtml, CardIcon, CardImage, CardInput, CardLoading, CardPasscodeInput, CardProgress, CardRate, CardSelect, CardSteps, CardSwitch, CardTag, CardText, DEFAULT_MOBILE_RESPONSIVE, LocalActionConfigProvider, RemoteActionConfigProvider, buildStyleString, componentRenderers, connectSSE, connectStreaming, convertPixelTokens, createResponsiveContext, createWebActionContext, isMobileViewport, onViewportChange, pxToRem, pxToVw, registerComponent, renderCard, renderStreamingCard, resolveSize, sanitizeHtml, trimIncompleteTag };
1788
+ export type { A2UIActionPayload, BotSDKOptions, ButtonProps, CardInstance, ChoiceIndicatorIcon, ChoiceItemProps, ChoiceListProps, ChoiceListValue, CollapseProps, ComponentRenderer, ConnectorConfig, CounterIcon, CounterProps, DividerProps, FormField, FormProps, FormRule, HtmlProps, IconProps, ImageProps, InputAffix, InputAffixConfig, InputProps, LoadingProps, PartialFinalizeResult, PasscodeInputProps, ProgressProps, ProgressSegment, RateProps, RenderCardOptions, ResponsiveContext, ResponsiveMobileOptions, ResponsiveOptions, SSEConnectOptions, SelectOption, SelectProps, SelectSize, SelectStyles, SelectVariant, StepIcon, StepItem, StepsProps, StreamingCardInstance, StreamingCardOptions, StreamingConnectOptions, StreamingConnection, SwitchProps, TagProps, TextProps, WebActionContextOptions };