@qw-ui/core 0.3.0-next.11 → 0.3.0-next.13

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/dist/index.d.ts CHANGED
@@ -28,3 +28,7 @@ export { TAG_PARTS, TAG_SIZES, TAG_VARIANTS } from "./tag/index.js";
28
28
  export type { TagPart, TagSize, TagVariant, QwTagProps } from "./tag/index.js";
29
29
  export { createInputProps } from "./input/index.js";
30
30
  export type { QwInputProps, InputApi, InputMode, InputReadOnlyOverflow } from "./input/index.js";
31
+ export { SWITCH_PARTS, getSwitchRootProps, getSwitchThumbProps, resolveSwitchState } from "./switch/index.js";
32
+ export type { SwitchPart, QwSwitchProps, ResolvedSwitchState, SwitchRootProps, SwitchThumbProps } from "./switch/index.js";
33
+ export { STEPPER_SIZES, STEPPER_PARTS, clampStepperValue, getStepperRootProps, getStepperDecrementProps, getStepperDecrementValue, getStepperIncrementProps, getStepperIncrementValue, getStepperValueProps, resolveStepperState, } from "./stepper/index.js";
34
+ export type { StepperPart, StepperSize, QwStepperProps, ResolvedStepperState, StepperRootProps, StepperDecrementProps, StepperIncrementProps, StepperValueProps, } from "./stepper/index.js";
package/dist/index.js CHANGED
@@ -13,4 +13,6 @@ import { AVATAR_BADGE_TYPES, AVATAR_LOAD_STATUS, AVATAR_PARTS, AVATAR_SHAPES, AV
13
13
  import { connect as connect$1, createTextAreaProps, machine } from "./textarea/index.js";
14
14
  import { TAG_PARTS, TAG_SIZES, TAG_VARIANTS } from "./tag/index.js";
15
15
  import { createInputProps } from "./input/index.js";
16
- export { AVATAR_BADGE_TYPES, AVATAR_LOAD_STATUS, AVATAR_PARTS, AVATAR_SHAPES, AVATAR_SIZES, BADGE_COUNT_MAX, BUTTON_ICON_POSITIONS, BUTTON_PARTS, BUTTON_SHAPES, BUTTON_SIZES, BUTTON_TONES, BUTTON_VARIANTS, DEFAULT_OVERLAY_PANEL_HEADER_HEIGHT, DEFAULT_TOAST_DURATION, DEFAULT_TOAST_POSITION, DIVIDER_ORIENTATIONS, DIVIDER_PARTS, DIVIDER_WEIGHTS, EMPTY_PARTS, ICON_FALLBACK_NAME, ICON_PARTS, LOADING_SIZES, OVERLAY_PANEL_PARTS, SKELETON_ANIMATIONS, SKELETON_PARTS, SKELETON_RADII, SKELETON_VARIANTS, TAG_PARTS, TAG_SIZES, TAG_VARIANTS, TOAST_ICON_TYPES, TOAST_PARTS, TOAST_POSITIONS, TOPBAR_VARIANTS, connect, createDialogProps, createInputProps, createTabsProps, createTextAreaProps, createTopBarProps, dialogMachine, extractInitials, getAvatarBadgeProps, getAvatarFallbackProps, getAvatarImageElementProps, getAvatarImageProps, getAvatarRootProps, getButtonRootProps, isToastIconType, resolveAvatarState, resolveButtonState, resolveIconName, resolveOverlayPanelHeight, resolveToastDuration, tabsMachine, connect$1 as textAreaConnect, machine as textAreaMachine };
16
+ import { SWITCH_PARTS, getSwitchRootProps, getSwitchThumbProps, resolveSwitchState } from "./switch/index.js";
17
+ import { STEPPER_PARTS, STEPPER_SIZES, clampStepperValue, getStepperDecrementProps, getStepperDecrementValue, getStepperIncrementProps, getStepperIncrementValue, getStepperRootProps, getStepperValueProps, resolveStepperState } from "./stepper/index.js";
18
+ export { AVATAR_BADGE_TYPES, AVATAR_LOAD_STATUS, AVATAR_PARTS, AVATAR_SHAPES, AVATAR_SIZES, BADGE_COUNT_MAX, BUTTON_ICON_POSITIONS, BUTTON_PARTS, BUTTON_SHAPES, BUTTON_SIZES, BUTTON_TONES, BUTTON_VARIANTS, DEFAULT_OVERLAY_PANEL_HEADER_HEIGHT, DEFAULT_TOAST_DURATION, DEFAULT_TOAST_POSITION, DIVIDER_ORIENTATIONS, DIVIDER_PARTS, DIVIDER_WEIGHTS, EMPTY_PARTS, ICON_FALLBACK_NAME, ICON_PARTS, LOADING_SIZES, OVERLAY_PANEL_PARTS, SKELETON_ANIMATIONS, SKELETON_PARTS, SKELETON_RADII, SKELETON_VARIANTS, STEPPER_PARTS, STEPPER_SIZES, SWITCH_PARTS, TAG_PARTS, TAG_SIZES, TAG_VARIANTS, TOAST_ICON_TYPES, TOAST_PARTS, TOAST_POSITIONS, TOPBAR_VARIANTS, clampStepperValue, connect, createDialogProps, createInputProps, createTabsProps, createTextAreaProps, createTopBarProps, dialogMachine, extractInitials, getAvatarBadgeProps, getAvatarFallbackProps, getAvatarImageElementProps, getAvatarImageProps, getAvatarRootProps, getButtonRootProps, getStepperDecrementProps, getStepperDecrementValue, getStepperIncrementProps, getStepperIncrementValue, getStepperRootProps, getStepperValueProps, getSwitchRootProps, getSwitchThumbProps, isToastIconType, resolveAvatarState, resolveButtonState, resolveIconName, resolveOverlayPanelHeight, resolveStepperState, resolveSwitchState, resolveToastDuration, tabsMachine, connect$1 as textAreaConnect, machine as textAreaMachine };
@@ -0,0 +1 @@
1
+ export * from "./stepper.js";
@@ -0,0 +1,111 @@
1
+ //#region src/stepper/stepper.ts
2
+ /**
3
+ * Stepper 加减(数量步进器)的跨框架行为契约。
4
+ *
5
+ * Stepper 是原型 A(无状态 Core 状态机):交互由原生 `<button>` 承担,
6
+ * core 只负责数值归一化、边界 clamp、按钮可用性计算与 prop-getter 生成。
7
+ */
8
+ /** 尺寸全集:s = 15×15px,m = 18×18px。 */
9
+ const STEPPER_SIZES = ["s", "m"];
10
+ /** 形态变体全集:default = 裸按钮组合,bordered = 带边框卡片形态。 */
11
+ const STEPPER_VARIANTS = ["default", "bordered"];
12
+ /** 渲染部位全集(data-part 取值)。 */
13
+ const STEPPER_PARTS = [
14
+ "root",
15
+ "decrement",
16
+ "value",
17
+ "increment"
18
+ ];
19
+ /** 将数值约束在 [min, max] 范围内;边界未定义时跳过对应侧。 */
20
+ function clampStepperValue(value, min, max) {
21
+ let result = value;
22
+ if (typeof min === "number" && !Number.isNaN(min)) result = Math.max(result, min);
23
+ if (typeof max === "number" && !Number.isNaN(max)) result = Math.min(result, max);
24
+ return result;
25
+ }
26
+ /** 规范化 step:仅接受正数,否则回退到 1。 */
27
+ function normalizeStepperStep(step) {
28
+ return typeof step === "number" && step > 0 && !Number.isNaN(step) ? step : 1;
29
+ }
30
+ /** 规范化 min:未指定时按规格默认 0(不做负数默认值)。 */
31
+ function normalizeStepperMin(min) {
32
+ return typeof min === "number" && !Number.isNaN(min) ? min : 0;
33
+ }
34
+ /** 将公开输入归一化为唯一的跨框架状态。 */
35
+ function resolveStepperState(props = {}) {
36
+ const min = normalizeStepperMin(props.min);
37
+ const max = props.max;
38
+ const step = normalizeStepperStep(props.step);
39
+ const disabled = props.disabled ?? false;
40
+ const variant = props.variant ?? "default";
41
+ const value = clampStepperValue(props.value !== void 0 ? props.value : props.defaultValue ?? min, min, max);
42
+ return {
43
+ value,
44
+ min,
45
+ max,
46
+ step,
47
+ disabled,
48
+ size: props.size ?? "m",
49
+ variant,
50
+ selected: value > min,
51
+ canDecrement: !disabled && value > min,
52
+ canIncrement: !disabled && (typeof max !== "number" || value < max)
53
+ };
54
+ }
55
+ /** 计算减量后的目标值(已 clamp)。 */
56
+ function getStepperDecrementValue(state) {
57
+ return clampStepperValue(state.value - state.step, state.min, state.max);
58
+ }
59
+ /** 计算增量后的目标值(已 clamp)。 */
60
+ function getStepperIncrementValue(state) {
61
+ return clampStepperValue(state.value + state.step, state.min, state.max);
62
+ }
63
+ /** 生成根容器属性。 */
64
+ function getStepperRootProps(state) {
65
+ return {
66
+ role: "group",
67
+ "data-scope": "stepper",
68
+ "data-part": "root",
69
+ "data-size": state.size,
70
+ "data-variant": state.variant,
71
+ ...state.selected ? { "data-selected": "true" } : {},
72
+ ...state.disabled ? { "data-disabled": "true" } : {}
73
+ };
74
+ }
75
+ /** 生成减量按钮属性。 */
76
+ function getStepperDecrementProps(state) {
77
+ const disabled = !state.canDecrement;
78
+ return {
79
+ type: "button",
80
+ disabled,
81
+ "data-scope": "stepper",
82
+ "data-part": "decrement",
83
+ "aria-label": "减少",
84
+ ...disabled ? { "data-disabled": "true" } : {}
85
+ };
86
+ }
87
+ /** 生成增量按钮属性。 */
88
+ function getStepperIncrementProps(state) {
89
+ const disabled = !state.canIncrement;
90
+ return {
91
+ type: "button",
92
+ disabled,
93
+ "data-scope": "stepper",
94
+ "data-part": "increment",
95
+ "aria-label": "增加",
96
+ ...disabled ? { "data-disabled": "true" } : {}
97
+ };
98
+ }
99
+ /** 生成数值展示属性。 */
100
+ function getStepperValueProps() {
101
+ return {
102
+ "data-scope": "stepper",
103
+ "data-part": "value",
104
+ "aria-live": "polite",
105
+ "aria-atomic": "true"
106
+ };
107
+ }
108
+ //#endregion
109
+ export { STEPPER_PARTS, STEPPER_SIZES, STEPPER_VARIANTS, clampStepperValue, getStepperDecrementProps, getStepperDecrementValue, getStepperIncrementProps, getStepperIncrementValue, getStepperRootProps, getStepperValueProps, resolveStepperState };
110
+
111
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/stepper/stepper.ts"],"sourcesContent":["/**\n * Stepper 加减(数量步进器)的跨框架行为契约。\n *\n * Stepper 是原型 A(无状态 Core 状态机):交互由原生 `<button>` 承担,\n * core 只负责数值归一化、边界 clamp、按钮可用性计算与 prop-getter 生成。\n */\n\n/** 尺寸全集:s = 15×15px,m = 18×18px。 */\nexport const STEPPER_SIZES = [\"s\", \"m\"] as const;\n\n/** 形态变体全集:default = 裸按钮组合,bordered = 带边框卡片形态。 */\nexport const STEPPER_VARIANTS = [\"default\", \"bordered\"] as const;\n\n/** 渲染部位全集(data-part 取值)。 */\nexport const STEPPER_PARTS = [\"root\", \"decrement\", \"value\", \"increment\"] as const;\n\nexport type StepperSize = (typeof STEPPER_SIZES)[number];\nexport type StepperVariant = (typeof STEPPER_VARIANTS)[number];\nexport type StepperPart = (typeof STEPPER_PARTS)[number];\n\n/**\n * QwStepperProps — 双栈共享的行为契约(全字段可选)。\n * `value` 未传时走非受控模式,由适配层管理内部数值。\n */\nexport interface QwStepperProps {\n /** 受控值。未传时走非受控模式。 */\n value?: number;\n /** 非受控初始值,默认 `0`(若 `min > 0` 则取 `min`)。仅在 `value` 未传时生效。 */\n defaultValue?: number;\n /** 数值变化回调,参数为新的 value。 */\n onChange?: (value: number) => void;\n /** 最小值。 */\n min?: number;\n /** 最大值。 */\n max?: number;\n /** 步长,默认 1;非法值(非正数)回退到 1。 */\n step?: number;\n /** 禁用状态。 */\n disabled?: boolean;\n /** 按钮尺寸,默认 m。 */\n size?: StepperSize;\n /** 形态变体,默认 default;bordered 为带边框卡片形态。 */\n variant?: StepperVariant;\n}\n\n/** 适配器唯一可消费的归一化结果。 */\nexport interface ResolvedStepperState {\n /** 当前数值(已按 min/max clamp)。 */\n value: number;\n /** 最小值。 */\n min: number | undefined;\n /** 最大值。 */\n max: number | undefined;\n /** 实际生效的步长。 */\n step: number;\n /** 是否整体禁用。 */\n disabled: boolean;\n /** 按钮尺寸。 */\n size: StepperSize;\n /** 形态变体。 */\n variant: StepperVariant;\n /** 选中态:value > min 派生,仅影响 bordered 视觉。 */\n selected: boolean;\n /** 减量按钮是否可用。 */\n canDecrement: boolean;\n /** 增量按钮是否可用。 */\n canIncrement: boolean;\n}\n\n/** 将数值约束在 [min, max] 范围内;边界未定义时跳过对应侧。 */\nexport function clampStepperValue(\n value: number,\n min: number | undefined,\n max: number | undefined,\n): number {\n let result = value;\n if (typeof min === \"number\" && !Number.isNaN(min)) {\n result = Math.max(result, min);\n }\n if (typeof max === \"number\" && !Number.isNaN(max)) {\n result = Math.min(result, max);\n }\n return result;\n}\n\n/** 规范化 step:仅接受正数,否则回退到 1。 */\nfunction normalizeStepperStep(step: number | undefined): number {\n return typeof step === \"number\" && step > 0 && !Number.isNaN(step) ? step : 1;\n}\n\n/** 规范化 min:未指定时按规格默认 0(不做负数默认值)。 */\nfunction normalizeStepperMin(min: number | undefined): number {\n return typeof min === \"number\" && !Number.isNaN(min) ? min : 0;\n}\n\n/** 将公开输入归一化为唯一的跨框架状态。 */\nexport function resolveStepperState(props: QwStepperProps = {}): ResolvedStepperState {\n const min = normalizeStepperMin(props.min);\n const max = props.max;\n const step = normalizeStepperStep(props.step);\n const disabled = props.disabled ?? false;\n const variant = props.variant ?? \"default\";\n\n const isControlled = props.value !== undefined;\n const rawValue = isControlled\n ? props.value!\n : (props.defaultValue ?? min);\n\n const value = clampStepperValue(rawValue, min, max);\n\n const size = props.size ?? \"m\";\n\n const selected = value > min;\n\n const canDecrement = !disabled && value > min;\n const canIncrement = !disabled && (typeof max !== \"number\" || value < max);\n\n return {\n value,\n min,\n max,\n step,\n disabled,\n size,\n variant,\n selected,\n canDecrement,\n canIncrement,\n };\n}\n\n/** 计算减量后的目标值(已 clamp)。 */\nexport function getStepperDecrementValue(state: ResolvedStepperState): number {\n return clampStepperValue(state.value - state.step, state.min, state.max);\n}\n\n/** 计算增量后的目标值(已 clamp)。 */\nexport function getStepperIncrementValue(state: ResolvedStepperState): number {\n return clampStepperValue(state.value + state.step, state.min, state.max);\n}\n\n/** Core 生成、由适配器最后覆盖到根元素的属性。 */\nexport interface StepperRootProps {\n role: \"group\";\n \"data-scope\": \"stepper\";\n \"data-part\": \"root\";\n \"data-size\": StepperSize;\n \"data-variant\": StepperVariant;\n \"data-selected\"?: \"true\";\n \"data-disabled\"?: \"true\";\n}\n\n/** 生成根容器属性。 */\nexport function getStepperRootProps(state: ResolvedStepperState): StepperRootProps {\n return {\n role: \"group\",\n \"data-scope\": \"stepper\",\n \"data-part\": \"root\",\n \"data-size\": state.size,\n \"data-variant\": state.variant,\n ...(state.selected ? { \"data-selected\": \"true\" as const } : {}),\n ...(state.disabled ? { \"data-disabled\": \"true\" as const } : {}),\n };\n}\n\n/** 减量按钮属性。 */\nexport interface StepperDecrementProps {\n type: \"button\";\n disabled: boolean;\n \"data-scope\": \"stepper\";\n \"data-part\": \"decrement\";\n \"aria-label\": string;\n \"data-disabled\"?: \"true\";\n}\n\n/** 生成减量按钮属性。 */\nexport function getStepperDecrementProps(state: ResolvedStepperState): StepperDecrementProps {\n const disabled = !state.canDecrement;\n return {\n type: \"button\",\n disabled,\n \"data-scope\": \"stepper\",\n \"data-part\": \"decrement\",\n \"aria-label\": \"减少\",\n ...(disabled ? { \"data-disabled\": \"true\" as const } : {}),\n };\n}\n\n/** 增量按钮属性。 */\nexport interface StepperIncrementProps {\n type: \"button\";\n disabled: boolean;\n \"data-scope\": \"stepper\";\n \"data-part\": \"increment\";\n \"aria-label\": string;\n \"data-disabled\"?: \"true\";\n}\n\n/** 生成增量按钮属性。 */\nexport function getStepperIncrementProps(state: ResolvedStepperState): StepperIncrementProps {\n const disabled = !state.canIncrement;\n return {\n type: \"button\",\n disabled,\n \"data-scope\": \"stepper\",\n \"data-part\": \"increment\",\n \"aria-label\": \"增加\",\n ...(disabled ? { \"data-disabled\": \"true\" as const } : {}),\n };\n}\n\n/** 数值展示属性。 */\nexport interface StepperValueProps {\n \"data-scope\": \"stepper\";\n \"data-part\": \"value\";\n \"aria-live\": \"polite\";\n \"aria-atomic\": \"true\";\n}\n\n/** 生成数值展示属性。 */\nexport function getStepperValueProps(): StepperValueProps {\n return {\n \"data-scope\": \"stepper\",\n \"data-part\": \"value\",\n \"aria-live\": \"polite\",\n \"aria-atomic\": \"true\",\n };\n}\n"],"mappings":";;;;;;;;AAQA,MAAa,gBAAgB,CAAC,KAAK,GAAG;;AAGtC,MAAa,mBAAmB,CAAC,WAAW,UAAU;;AAGtD,MAAa,gBAAgB;CAAC;CAAQ;CAAa;CAAS;AAAW;;AAwDvE,SAAgB,kBACd,OACA,KACA,KACQ;CACR,IAAI,SAAS;CACb,IAAI,OAAO,QAAQ,YAAY,CAAC,OAAO,MAAM,GAAG,GAC9C,SAAS,KAAK,IAAI,QAAQ,GAAG;CAE/B,IAAI,OAAO,QAAQ,YAAY,CAAC,OAAO,MAAM,GAAG,GAC9C,SAAS,KAAK,IAAI,QAAQ,GAAG;CAE/B,OAAO;AACT;;AAGA,SAAS,qBAAqB,MAAkC;CAC9D,OAAO,OAAO,SAAS,YAAY,OAAO,KAAK,CAAC,OAAO,MAAM,IAAI,IAAI,OAAO;AAC9E;;AAGA,SAAS,oBAAoB,KAAiC;CAC5D,OAAO,OAAO,QAAQ,YAAY,CAAC,OAAO,MAAM,GAAG,IAAI,MAAM;AAC/D;;AAGA,SAAgB,oBAAoB,QAAwB,CAAC,GAAyB;CACpF,MAAM,MAAM,oBAAoB,MAAM,GAAG;CACzC,MAAM,MAAM,MAAM;CAClB,MAAM,OAAO,qBAAqB,MAAM,IAAI;CAC5C,MAAM,WAAW,MAAM,YAAY;CACnC,MAAM,UAAU,MAAM,WAAW;CAOjC,MAAM,QAAQ,kBALO,MAAM,UAAU,KAAA,IAEjC,MAAM,QACL,MAAM,gBAAgB,KAEe,KAAK,GAAG;CASlD,OAAO;EACL;EACA;EACA;EACA;EACA;EACA,MAbW,MAAM,QAAQ;EAczB;EACA,UAbe,QAAQ;EAcvB,cAZmB,CAAC,YAAY,QAAQ;EAaxC,cAZmB,CAAC,aAAa,OAAO,QAAQ,YAAY,QAAQ;CAatE;AACF;;AAGA,SAAgB,yBAAyB,OAAqC;CAC5E,OAAO,kBAAkB,MAAM,QAAQ,MAAM,MAAM,MAAM,KAAK,MAAM,GAAG;AACzE;;AAGA,SAAgB,yBAAyB,OAAqC;CAC5E,OAAO,kBAAkB,MAAM,QAAQ,MAAM,MAAM,MAAM,KAAK,MAAM,GAAG;AACzE;;AAcA,SAAgB,oBAAoB,OAA+C;CACjF,OAAO;EACL,MAAM;EACN,cAAc;EACd,aAAa;EACb,aAAa,MAAM;EACnB,gBAAgB,MAAM;EACtB,GAAI,MAAM,WAAW,EAAE,iBAAiB,OAAgB,IAAI,CAAC;EAC7D,GAAI,MAAM,WAAW,EAAE,iBAAiB,OAAgB,IAAI,CAAC;CAC/D;AACF;;AAaA,SAAgB,yBAAyB,OAAoD;CAC3F,MAAM,WAAW,CAAC,MAAM;CACxB,OAAO;EACL,MAAM;EACN;EACA,cAAc;EACd,aAAa;EACb,cAAc;EACd,GAAI,WAAW,EAAE,iBAAiB,OAAgB,IAAI,CAAC;CACzD;AACF;;AAaA,SAAgB,yBAAyB,OAAoD;CAC3F,MAAM,WAAW,CAAC,MAAM;CACxB,OAAO;EACL,MAAM;EACN;EACA,cAAc;EACd,aAAa;EACb,cAAc;EACd,GAAI,WAAW,EAAE,iBAAiB,OAAgB,IAAI,CAAC;CACzD;AACF;;AAWA,SAAgB,uBAA0C;CACxD,OAAO;EACL,cAAc;EACd,aAAa;EACb,aAAa;EACb,eAAe;CACjB;AACF"}
@@ -0,0 +1,113 @@
1
+ /**
2
+ * Stepper 加减(数量步进器)的跨框架行为契约。
3
+ *
4
+ * Stepper 是原型 A(无状态 Core 状态机):交互由原生 `<button>` 承担,
5
+ * core 只负责数值归一化、边界 clamp、按钮可用性计算与 prop-getter 生成。
6
+ */
7
+ /** 尺寸全集:s = 15×15px,m = 18×18px。 */
8
+ export declare const STEPPER_SIZES: readonly ["s", "m"];
9
+ /** 形态变体全集:default = 裸按钮组合,bordered = 带边框卡片形态。 */
10
+ export declare const STEPPER_VARIANTS: readonly ["default", "bordered"];
11
+ /** 渲染部位全集(data-part 取值)。 */
12
+ export declare const STEPPER_PARTS: readonly ["root", "decrement", "value", "increment"];
13
+ export type StepperSize = (typeof STEPPER_SIZES)[number];
14
+ export type StepperVariant = (typeof STEPPER_VARIANTS)[number];
15
+ export type StepperPart = (typeof STEPPER_PARTS)[number];
16
+ /**
17
+ * QwStepperProps — 双栈共享的行为契约(全字段可选)。
18
+ * `value` 未传时走非受控模式,由适配层管理内部数值。
19
+ */
20
+ export interface QwStepperProps {
21
+ /** 受控值。未传时走非受控模式。 */
22
+ value?: number;
23
+ /** 非受控初始值,默认 `0`(若 `min > 0` 则取 `min`)。仅在 `value` 未传时生效。 */
24
+ defaultValue?: number;
25
+ /** 数值变化回调,参数为新的 value。 */
26
+ onChange?: (value: number) => void;
27
+ /** 最小值。 */
28
+ min?: number;
29
+ /** 最大值。 */
30
+ max?: number;
31
+ /** 步长,默认 1;非法值(非正数)回退到 1。 */
32
+ step?: number;
33
+ /** 禁用状态。 */
34
+ disabled?: boolean;
35
+ /** 按钮尺寸,默认 m。 */
36
+ size?: StepperSize;
37
+ /** 形态变体,默认 default;bordered 为带边框卡片形态。 */
38
+ variant?: StepperVariant;
39
+ }
40
+ /** 适配器唯一可消费的归一化结果。 */
41
+ export interface ResolvedStepperState {
42
+ /** 当前数值(已按 min/max clamp)。 */
43
+ value: number;
44
+ /** 最小值。 */
45
+ min: number | undefined;
46
+ /** 最大值。 */
47
+ max: number | undefined;
48
+ /** 实际生效的步长。 */
49
+ step: number;
50
+ /** 是否整体禁用。 */
51
+ disabled: boolean;
52
+ /** 按钮尺寸。 */
53
+ size: StepperSize;
54
+ /** 形态变体。 */
55
+ variant: StepperVariant;
56
+ /** 选中态:value > min 派生,仅影响 bordered 视觉。 */
57
+ selected: boolean;
58
+ /** 减量按钮是否可用。 */
59
+ canDecrement: boolean;
60
+ /** 增量按钮是否可用。 */
61
+ canIncrement: boolean;
62
+ }
63
+ /** 将数值约束在 [min, max] 范围内;边界未定义时跳过对应侧。 */
64
+ export declare function clampStepperValue(value: number, min: number | undefined, max: number | undefined): number;
65
+ /** 将公开输入归一化为唯一的跨框架状态。 */
66
+ export declare function resolveStepperState(props?: QwStepperProps): ResolvedStepperState;
67
+ /** 计算减量后的目标值(已 clamp)。 */
68
+ export declare function getStepperDecrementValue(state: ResolvedStepperState): number;
69
+ /** 计算增量后的目标值(已 clamp)。 */
70
+ export declare function getStepperIncrementValue(state: ResolvedStepperState): number;
71
+ /** Core 生成、由适配器最后覆盖到根元素的属性。 */
72
+ export interface StepperRootProps {
73
+ role: "group";
74
+ "data-scope": "stepper";
75
+ "data-part": "root";
76
+ "data-size": StepperSize;
77
+ "data-variant": StepperVariant;
78
+ "data-selected"?: "true";
79
+ "data-disabled"?: "true";
80
+ }
81
+ /** 生成根容器属性。 */
82
+ export declare function getStepperRootProps(state: ResolvedStepperState): StepperRootProps;
83
+ /** 减量按钮属性。 */
84
+ export interface StepperDecrementProps {
85
+ type: "button";
86
+ disabled: boolean;
87
+ "data-scope": "stepper";
88
+ "data-part": "decrement";
89
+ "aria-label": string;
90
+ "data-disabled"?: "true";
91
+ }
92
+ /** 生成减量按钮属性。 */
93
+ export declare function getStepperDecrementProps(state: ResolvedStepperState): StepperDecrementProps;
94
+ /** 增量按钮属性。 */
95
+ export interface StepperIncrementProps {
96
+ type: "button";
97
+ disabled: boolean;
98
+ "data-scope": "stepper";
99
+ "data-part": "increment";
100
+ "aria-label": string;
101
+ "data-disabled"?: "true";
102
+ }
103
+ /** 生成增量按钮属性。 */
104
+ export declare function getStepperIncrementProps(state: ResolvedStepperState): StepperIncrementProps;
105
+ /** 数值展示属性。 */
106
+ export interface StepperValueProps {
107
+ "data-scope": "stepper";
108
+ "data-part": "value";
109
+ "aria-live": "polite";
110
+ "aria-atomic": "true";
111
+ }
112
+ /** 生成数值展示属性。 */
113
+ export declare function getStepperValueProps(): StepperValueProps;
@@ -0,0 +1 @@
1
+ export * from "./switch.js";
@@ -0,0 +1,43 @@
1
+ //#region src/switch/switch.ts
2
+ /**
3
+ * Switch 的跨框架行为契约。
4
+ *
5
+ * Switch 是无状态的 Prototype A:交互由原生 button 承担,
6
+ * 这里仅归一化公开 props(checked / defaultChecked / disabled)。
7
+ * React/Vue 适配器不得复制 disabled 或 checked 的组合规则。
8
+ */
9
+ /** Switch 各渲染部位全集(data-part 取值)。 */
10
+ const SWITCH_PARTS = ["root", "thumb"];
11
+ /** 将公开输入归一化为唯一的跨框架状态。 */
12
+ function resolveSwitchState(props = {}) {
13
+ return {
14
+ checked: props.checked ?? props.defaultChecked ?? false,
15
+ disabled: props.disabled ?? false,
16
+ type: props.type ?? "button"
17
+ };
18
+ }
19
+ /** 将归一化结果转成 root 属性。 */
20
+ function getSwitchRootProps(state) {
21
+ return {
22
+ type: state.type,
23
+ role: "switch",
24
+ disabled: state.disabled,
25
+ "aria-checked": state.checked ? "true" : "false",
26
+ "data-scope": "switch",
27
+ "data-part": "root",
28
+ "data-checked": state.checked ? "true" : "false",
29
+ ...state.disabled ? { "data-disabled": "true" } : {}
30
+ };
31
+ }
32
+ /** 生成旋钮属性。 */
33
+ function getSwitchThumbProps() {
34
+ return {
35
+ "data-scope": "switch",
36
+ "data-part": "thumb",
37
+ "aria-hidden": "true"
38
+ };
39
+ }
40
+ //#endregion
41
+ export { SWITCH_PARTS, getSwitchRootProps, getSwitchThumbProps, resolveSwitchState };
42
+
43
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/switch/switch.ts"],"sourcesContent":["/**\n * Switch 的跨框架行为契约。\n *\n * Switch 是无状态的 Prototype A:交互由原生 button 承担,\n * 这里仅归一化公开 props(checked / defaultChecked / disabled)。\n * React/Vue 适配器不得复制 disabled 或 checked 的组合规则。\n */\n\n/** Switch 各渲染部位全集(data-part 取值)。 */\nexport const SWITCH_PARTS = [\"root\", \"thumb\"] as const;\n\nexport type SwitchPart = (typeof SWITCH_PARTS)[number];\n\n/**\n * QwSwitchProps — 双栈共享的行为契约(全字段可选)。\n * checked 未传时走非受控模式,由适配层管理内部状态。\n */\nexport interface QwSwitchProps {\n /** 受控值。未传时走非受控模式。 */\n checked?: boolean;\n /** 非受控初始值,默认 false。仅在 checked 未传时生效。 */\n defaultChecked?: boolean;\n /** 状态变化回调,参数为新的 checked 值。 */\n onToggle?: (checked: boolean) => void;\n /** 禁用状态。 */\n disabled?: boolean;\n /** 原生 button 类型,默认 `button`。 */\n type?: \"button\" | \"submit\" | \"reset\";\n}\n\n/** 适配器唯一可消费的归一化结果。 */\nexport interface ResolvedSwitchState {\n checked: boolean;\n disabled: boolean;\n type: \"button\" | \"submit\" | \"reset\";\n}\n\n/** Core 生成、由适配器最后覆盖到根元素的属性。 */\nexport interface SwitchRootProps {\n type: \"button\" | \"submit\" | \"reset\";\n role: \"switch\";\n disabled: boolean;\n \"aria-checked\": \"true\" | \"false\";\n \"data-scope\": \"switch\";\n \"data-part\": \"root\";\n \"data-checked\": \"true\" | \"false\";\n \"data-disabled\"?: \"true\";\n}\n\n/** 旋钮属性(纯视觉元素)。 */\nexport interface SwitchThumbProps {\n \"data-scope\": \"switch\";\n \"data-part\": \"thumb\";\n \"aria-hidden\": \"true\";\n}\n\n/** 将公开输入归一化为唯一的跨框架状态。 */\nexport function resolveSwitchState(props: QwSwitchProps = {}): ResolvedSwitchState {\n return {\n checked: props.checked ?? props.defaultChecked ?? false,\n disabled: props.disabled ?? false,\n type: props.type ?? \"button\",\n };\n}\n\n/** 将归一化结果转成 root 属性。 */\nexport function getSwitchRootProps(state: ResolvedSwitchState): SwitchRootProps {\n return {\n type: state.type,\n role: \"switch\",\n disabled: state.disabled,\n \"aria-checked\": state.checked ? \"true\" : \"false\",\n \"data-scope\": \"switch\",\n \"data-part\": \"root\",\n \"data-checked\": state.checked ? \"true\" : \"false\",\n ...(state.disabled ? { \"data-disabled\": \"true\" as const } : {}),\n };\n}\n\n/** 生成旋钮属性。 */\nexport function getSwitchThumbProps(): SwitchThumbProps {\n return {\n \"data-scope\": \"switch\",\n \"data-part\": \"thumb\",\n \"aria-hidden\": \"true\",\n };\n}\n"],"mappings":";;;;;;;;;AASA,MAAa,eAAe,CAAC,QAAQ,OAAO;;AAgD5C,SAAgB,mBAAmB,QAAuB,CAAC,GAAwB;CACjF,OAAO;EACL,SAAS,MAAM,WAAW,MAAM,kBAAkB;EAClD,UAAU,MAAM,YAAY;EAC5B,MAAM,MAAM,QAAQ;CACtB;AACF;;AAGA,SAAgB,mBAAmB,OAA6C;CAC9E,OAAO;EACL,MAAM,MAAM;EACZ,MAAM;EACN,UAAU,MAAM;EAChB,gBAAgB,MAAM,UAAU,SAAS;EACzC,cAAc;EACd,aAAa;EACb,gBAAgB,MAAM,UAAU,SAAS;EACzC,GAAI,MAAM,WAAW,EAAE,iBAAiB,OAAgB,IAAI,CAAC;CAC/D;AACF;;AAGA,SAAgB,sBAAwC;CACtD,OAAO;EACL,cAAc;EACd,aAAa;EACb,eAAe;CACjB;AACF"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Switch 的跨框架行为契约。
3
+ *
4
+ * Switch 是无状态的 Prototype A:交互由原生 button 承担,
5
+ * 这里仅归一化公开 props(checked / defaultChecked / disabled)。
6
+ * React/Vue 适配器不得复制 disabled 或 checked 的组合规则。
7
+ */
8
+ /** Switch 各渲染部位全集(data-part 取值)。 */
9
+ export declare const SWITCH_PARTS: readonly ["root", "thumb"];
10
+ export type SwitchPart = (typeof SWITCH_PARTS)[number];
11
+ /**
12
+ * QwSwitchProps — 双栈共享的行为契约(全字段可选)。
13
+ * checked 未传时走非受控模式,由适配层管理内部状态。
14
+ */
15
+ export interface QwSwitchProps {
16
+ /** 受控值。未传时走非受控模式。 */
17
+ checked?: boolean;
18
+ /** 非受控初始值,默认 false。仅在 checked 未传时生效。 */
19
+ defaultChecked?: boolean;
20
+ /** 状态变化回调,参数为新的 checked 值。 */
21
+ onToggle?: (checked: boolean) => void;
22
+ /** 禁用状态。 */
23
+ disabled?: boolean;
24
+ /** 原生 button 类型,默认 `button`。 */
25
+ type?: "button" | "submit" | "reset";
26
+ }
27
+ /** 适配器唯一可消费的归一化结果。 */
28
+ export interface ResolvedSwitchState {
29
+ checked: boolean;
30
+ disabled: boolean;
31
+ type: "button" | "submit" | "reset";
32
+ }
33
+ /** Core 生成、由适配器最后覆盖到根元素的属性。 */
34
+ export interface SwitchRootProps {
35
+ type: "button" | "submit" | "reset";
36
+ role: "switch";
37
+ disabled: boolean;
38
+ "aria-checked": "true" | "false";
39
+ "data-scope": "switch";
40
+ "data-part": "root";
41
+ "data-checked": "true" | "false";
42
+ "data-disabled"?: "true";
43
+ }
44
+ /** 旋钮属性(纯视觉元素)。 */
45
+ export interface SwitchThumbProps {
46
+ "data-scope": "switch";
47
+ "data-part": "thumb";
48
+ "aria-hidden": "true";
49
+ }
50
+ /** 将公开输入归一化为唯一的跨框架状态。 */
51
+ export declare function resolveSwitchState(props?: QwSwitchProps): ResolvedSwitchState;
52
+ /** 将归一化结果转成 root 属性。 */
53
+ export declare function getSwitchRootProps(state: ResolvedSwitchState): SwitchRootProps;
54
+ /** 生成旋钮属性。 */
55
+ export declare function getSwitchThumbProps(): SwitchThumbProps;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qw-ui/core",
3
- "version": "0.3.0-next.11",
3
+ "version": "0.3.0-next.13",
4
4
  "description": "L2 · Headless Core — zag.js machine 薄包装,纯 TS / SSR-safe,零样式。",
5
5
  "license": "MIT",
6
6
  "author": "qw-ui contributors",
@@ -95,6 +95,14 @@
95
95
  "./input": {
96
96
  "types": "./dist/input/index.d.ts",
97
97
  "import": "./dist/input/index.js"
98
+ },
99
+ "./switch": {
100
+ "types": "./dist/switch/index.d.ts",
101
+ "import": "./dist/switch/index.js"
102
+ },
103
+ "./stepper": {
104
+ "types": "./dist/stepper/index.d.ts",
105
+ "import": "./dist/stepper/index.js"
98
106
  }
99
107
  },
100
108
  "sideEffects": false,
@@ -103,7 +111,7 @@
103
111
  "@zag-js/dialog": "^1.42.0",
104
112
  "@zag-js/tabs": "^1.42.0",
105
113
  "@zag-js/utils": "1.42.0",
106
- "@qw-ui/icons": "^0.3.0-next.11"
114
+ "@qw-ui/icons": "^0.3.0-next.13"
107
115
  },
108
116
  "devDependencies": {
109
117
  "@microsoft/api-extractor": "^7.58.9",
@@ -117,8 +125,8 @@
117
125
  "typescript": "^6.0.3",
118
126
  "unrun": "^0.3.1",
119
127
  "vitest": "^4.1.9",
120
- "@qw-ui/eslint-config": "0.0.1",
121
- "@qw-ui/tsconfig": "0.0.1"
128
+ "@qw-ui/tsconfig": "0.0.1",
129
+ "@qw-ui/eslint-config": "0.0.1"
122
130
  },
123
131
  "size-limit": [
124
132
  {