@cognitap/radiant 0.0.9 → 0.0.10

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.
@@ -1 +1 @@
1
- {"version":3,"file":"components.js","sourceRoot":"","sources":["../../../src/themes/components.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAEvC,+EAA+E;AAC/E,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,MAAM,EAAE;QACN,MAAM,EAAE,KAAK;QACb,aAAa,EAAE,KAAK;QACpB,WAAW,EAAE,KAAK;QAClB,kBAAkB,EAAE,KAAK;QACzB,MAAM,EAAE,KAAK;QACb,WAAW,EAAE,KAAK;QAClB,WAAW,EAAE,KAAK;QAClB,OAAO,EAAE,KAAK;QACd,YAAY,EAAE,KAAK;QACnB,YAAY,EAAE,KAAK;QACnB,QAAQ,EAAE,KAAK;QACf,aAAa,EAAE,KAAK;QACpB,aAAa,EAAE,KAAK;QACpB,UAAU,EAAE,QAAQ;QACpB,aAAa,EAAE,KAAK;QACpB,MAAM,EAAE,KAAK;QACb,aAAa,EAAE,KAAK;QACpB,SAAS,EAAE,SAAS;QACpB,KAAK,EAAE,SAAS;QAChB,IAAI,EAAE,KAAK;QACX,QAAQ,EAAE,KAAK;QACf,UAAU,EAAE,KAAK;QACjB,UAAU,EAAE,KAAK;QACjB,UAAU,EAAE,KAAK;QACjB,SAAS,EAAE,KAAK;QAChB,UAAU,EAAE,QAAQ;QACpB,UAAU,EAAE,KAAK;QACjB,WAAW,EAAE,KAAK;QAClB,WAAW,EAAE,KAAK;QAClB,WAAW,EAAE,KAAK;QAClB,WAAW,EAAE,KAAK;QAClB,kBAAkB,EAAE,KAAK;QACzB,UAAU,EAAE,KAAK;QACjB,UAAU,EAAE,KAAK;QACjB,aAAa,EAAE,KAAK;QACpB,WAAW,EAAE,KAAK;QAClB,UAAU,EAAE,KAAK;QACjB,WAAW,EAAE,KAAK;QA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C;IACH,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["import { kebabCase } from './tokens.js'\n\n/** Explicit component slots; omitted slots reset to CSS fallback semantics. */\nexport const componentRegistry = {\n button: {\n radius: 'css',\n radiusPressed: 'css',\n cornerShape: 'css',\n cornerShapePressed: 'css',\n height: 'css',\n heightSmall: 'css',\n heightLarge: 'css',\n padding: 'css',\n paddingSmall: 'css',\n paddingLarge: 'css',\n fontSize: 'css',\n fontSizeSmall: 'css',\n fontSizeLarge: 'css',\n fontWeight: 'weight',\n letterSpacing: 'css',\n shadow: 'css',\n shadowPressed: 'css',\n highlight: 'opacity',\n sheen: 'opacity',\n glow: 'css',\n backdrop: 'css',\n stateColor: 'css',\n hoverLayer: 'css',\n pressLayer: 'css',\n hoverLift: 'css',\n pressScale: 'number',\n pressShift: 'css',\n pressShiftX: 'css',\n borderWidth: 'css',\n borderColor: 'css',\n ghostShadow: 'css',\n ghostShadowPressed: 'css',\n focusColor: 'css',\n fontFamily: 'css',\n textTransform: 'css',\n borderStyle: 'css',\n focusWidth: 'css',\n focusOffset: 'css',\n focusStyle: 'css',\n pressDuration: 'css',\n pressEase: 'css',\n releaseDuration: 'css',\n releaseEase: 'css',\n colorDuration: 'css',\n disabledOpacity: 'opacity'\n },\n link: {\n color: 'css',\n hoverColor: 'css',\n underlineOffset: 'css',\n decorationThickness: 'css',\n decorationThicknessHover: 'css',\n colorDuration: 'css',\n focusColor: 'css',\n focusWidth: 'css',\n focusOffset: 'css',\n focusStyle: 'css'\n },\n field: {\n gap: 'css',\n labelColor: 'css',\n labelSize: 'css',\n labelWeight: 'weight',\n descriptionColor: 'css',\n descriptionSize: 'css',\n errorColor: 'css',\n errorSize: 'css',\n requiredColor: 'css',\n disabledOpacity: 'opacity'\n },\n input: {\n height: 'css',\n padding: 'css',\n fontFamily: 'css',\n fontSize: 'css',\n fontWeight: 'weight',\n color: 'css',\n background: 'css',\n borderWidth: 'css',\n borderStyle: 'css',\n borderColor: 'css',\n radius: 'css',\n cornerShape: 'css',\n shadow: 'css',\n placeholder: 'css',\n invalidBorder: 'css',\n disabledBackground: 'css',\n focusColor: 'css',\n focusWidth: 'css',\n focusOffset: 'css',\n focusStyle: 'css'\n },\n textarea: {\n minHeight: 'css',\n paddingBlock: 'css',\n padding: 'css',\n fontFamily: 'css',\n fontSize: 'css',\n fontWeight: 'weight',\n color: 'css',\n background: 'css',\n borderWidth: 'css',\n borderStyle: 'css',\n borderColor: 'css',\n radius: 'css',\n cornerShape: 'css',\n shadow: 'css',\n placeholder: 'css',\n invalidBorder: 'css',\n disabledBackground: 'css',\n focusColor: 'css',\n focusWidth: 'css',\n focusOffset: 'css',\n focusStyle: 'css'\n },\n select: {\n height: 'css',\n padding: 'css',\n fontFamily: 'css',\n fontSize: 'css',\n fontWeight: 'weight',\n color: 'css',\n background: 'css',\n borderWidth: 'css',\n borderStyle: 'css',\n borderColor: 'css',\n radius: 'css',\n cornerShape: 'css',\n shadow: 'css',\n focusColor: 'css',\n contentPadding: 'css',\n contentRadius: 'css',\n contentBackground: 'css',\n contentBackdropFilter: 'css',\n contentShadow: 'css',\n itemRadius: 'css',\n itemBackground: 'css',\n itemColor: 'css'\n },\n checkbox: {\n size: 'css',\n radius: 'css',\n cornerShape: 'css',\n borderWidth: 'css',\n borderStyle: 'css',\n borderColor: 'css',\n background: 'css',\n checkedBackground: 'css',\n checkedBorder: 'css',\n mark: 'css',\n invalidBorder: 'css',\n gap: 'css',\n labelColor: 'css',\n labelSize: 'css',\n disabledBorder: 'css',\n disabledBackground: 'css',\n focusColor: 'css',\n focusWidth: 'css',\n focusOffset: 'css',\n focusStyle: 'css'\n },\n radio: {\n size: 'css',\n radius: 'css',\n cornerShape: 'css',\n borderWidth: 'css',\n borderStyle: 'css',\n borderColor: 'css',\n background: 'css',\n checkedBackground: 'css',\n checkedBorder: 'css',\n mark: 'css',\n invalidBorder: 'css',\n labelGap: 'css',\n labelColor: 'css',\n labelSize: 'css',\n disabledBorder: 'css',\n disabledBackground: 'css',\n focusColor: 'css',\n focusWidth: 'css',\n focusOffset: 'css',\n focusStyle: 'css'\n },\n dialog: {\n width: 'css',\n padding: 'css',\n gap: 'css',\n radius: 'css',\n cornerShape: 'css',\n background: 'css',\n color: 'css',\n borderWidth: 'css',\n borderStyle: 'css',\n borderColor: 'css',\n shadow: 'css',\n backdrop: 'css',\n backdropFilter: 'css',\n titleSize: 'css',\n titleWeight: 'weight',\n descriptionColor: 'css',\n descriptionSize: 'css',\n focusColor: 'css',\n focusWidth: 'css',\n focusOffset: 'css',\n focusStyle: 'css'\n },\n collapsible: {\n radius: 'css',\n cornerShape: 'css',\n background: 'css',\n color: 'css',\n borderWidth: 'css',\n borderStyle: 'css',\n borderColor: 'css',\n padding: 'css',\n gap: 'css',\n contentColor: 'css',\n contentSize: 'css',\n duration: 'css',\n focusColor: 'css',\n focusWidth: 'css',\n focusOffset: 'css',\n focusStyle: 'css'\n },\n accordion: {\n gap: 'css'\n },\n card: {\n radius: 'css',\n cornerShape: 'css',\n background: 'css',\n color: 'css',\n borderWidth: 'css',\n borderStyle: 'css',\n borderColor: 'css',\n padding: 'css',\n gap: 'css',\n headerGap: 'css',\n footerGap: 'css',\n shadow: 'css',\n titleSize: 'css',\n titleWeight: 'weight',\n descriptionColor: 'css',\n descriptionSize: 'css'\n },\n radioGroup: { gap: 'css' }\n} as const\n\ntype ValueKind = 'css' | 'weight' | 'number' | 'opacity'\ntype KindValue<T> = T extends 'css' ? string : T extends 'weight' ? string | number : number\nexport type ThemeComponentOverrides = {\n readonly [F in keyof typeof componentRegistry]?: {\n readonly [K in keyof (typeof componentRegistry)[F]]?: KindValue<\n (typeof componentRegistry)[F][K]\n >\n }\n}\n\nexport const componentVariables = Object.freeze(\n Object.fromEntries(\n Object.entries(componentRegistry).map(([family, keys]) => [\n family,\n Object.freeze(\n Object.fromEntries(\n Object.keys(keys).map(key => [key, `--rad-${kebabCase(family)}-${kebabCase(key)}`])\n )\n )\n ])\n )\n) as Readonly<Record<keyof typeof componentRegistry, Readonly<Record<string, `--rad-${string}`>>>>\n\nexport function componentValueKind(family: string, key: string): ValueKind | undefined {\n if (!Object.hasOwn(componentRegistry, family)) return undefined\n const keys = componentRegistry[family as keyof typeof componentRegistry]\n return Object.hasOwn(keys, key) ? (keys as Record<string, ValueKind>)[key] : undefined\n}\n\nexport function flattenComponents(overrides: ThemeComponentOverrides = {}, reset = false) {\n const result: Record<`--rad-${string}`, string | number> = {}\n for (const [family, variables] of Object.entries(componentVariables)) {\n const values = overrides[family as keyof ThemeComponentOverrides] as\n | Record<string, string | number | undefined>\n | undefined\n for (const [key, variable] of Object.entries(variables)) {\n const value = values?.[key]\n if (value !== undefined) result[variable] = value\n else if (reset) result[variable] = 'initial'\n }\n }\n return result\n}\n"]}
1
+ {"version":3,"file":"components.js","sourceRoot":"","sources":["../../../src/themes/components.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAEvC,+EAA+E;AAC/E,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,MAAM,EAAE;QACN,MAAM,EAAE,KAAK;QACb,aAAa,EAAE,KAAK;QACpB,WAAW,EAAE,KAAK;QAClB,kBAAkB,EAAE,KAAK;QACzB,MAAM,EAAE,KAAK;QACb,WAAW,EAAE,KAAK;QAClB,WAAW,EAAE,KAAK;QAClB,OAAO,EAAE,KAAK;QACd,YAAY,EAAE,KAAK;QACnB,YAAY,EAAE,KAAK;QACnB,QAAQ,EAAE,KAAK;QACf,aAAa,EAAE,KAAK;QACpB,aAAa,EAAE,KAAK;QACpB,UAAU,EAAE,QAAQ;QACpB,aAAa,EAAE,KAAK;QACpB,MAAM,EAAE,KAAK;QACb,aAAa,EAAE,KAAK;QACpB,SAAS,EAAE,SAAS;QACpB,KAAK,EAAE,SAAS;QAChB,IAAI,EAAE,KAAK;QACX,QAAQ,EAAE,KAAK;QACf,UAAU,EAAE,KAAK;QACjB,UAAU,EAAE,KAAK;QACjB,U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ACH,CAC+F,CAAA;AAElG,MAAM,UAAU,kBAAkB,CAAC,MAAc,EAAE,GAAW;IAC5D,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,iBAAiB,EAAE,MAAM,CAAC;QAAE,OAAO,SAAS,CAAA;IAC/D,MAAM,IAAI,GAAG,iBAAiB,CAAC,MAAwC,CAAC,CAAA;IACxE,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,CAAE,IAAkC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;AACxF,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,YAAqC,EAAE,EAAE,KAAK,GAAG,KAAK;IACtF,MAAM,MAAM,GAA+C,EAAE,CAAA;IAC7D,KAAK,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,kBAAkB,CAAC,EAAE,CAAC;QACrE,MAAM,MAAM,GAAG,SAAS,CAAC,MAAuC,CAEnD,CAAA;QACb,KAAK,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;YACxD,MAAM,KAAK,GAAG,MAAM,EAAE,CAAC,GAAG,CAAC,CAAA;YAC3B,IAAI,KAAK,KAAK,SAAS;gBAAE,MAAM,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAA;iBAC5C,IAAI,KAAK;gBAAE,MAAM,CAAC,QAAQ,CAAC,GAAG,SAAS,CAAA;QAC9C,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["import { kebabCase } from './tokens.js'\n\n/** Explicit component slots; omitted slots reset to CSS fallback semantics. */\nexport const componentRegistry = {\n button: {\n radius: 'css',\n radiusPressed: 'css',\n cornerShape: 'css',\n cornerShapePressed: 'css',\n height: 'css',\n heightSmall: 'css',\n heightLarge: 'css',\n padding: 'css',\n paddingSmall: 'css',\n paddingLarge: 'css',\n fontSize: 'css',\n fontSizeSmall: 'css',\n fontSizeLarge: 'css',\n fontWeight: 'weight',\n letterSpacing: 'css',\n shadow: 'css',\n shadowPressed: 'css',\n highlight: 'opacity',\n sheen: 'opacity',\n glow: 'css',\n backdrop: 'css',\n stateColor: 'css',\n hoverLayer: 'css',\n pressLayer: 'css',\n hoverLift: 'css',\n pressScale: 'number',\n pressShift: 'css',\n pressShiftX: 'css',\n borderWidth: 'css',\n borderColor: 'css',\n ghostShadow: 'css',\n ghostShadowPressed: 'css',\n focusColor: 'css',\n fontFamily: 'css',\n textTransform: 'css',\n borderStyle: 'css',\n focusWidth: 'css',\n focusOffset: 'css',\n focusStyle: 'css',\n pressDuration: 'css',\n pressEase: 'css',\n releaseDuration: 'css',\n releaseEase: 'css',\n colorDuration: 'css',\n disabledOpacity: 'opacity'\n },\n link: {\n color: 'css',\n hoverColor: 'css',\n underlineOffset: 'css',\n decorationThickness: 'css',\n decorationThicknessHover: 'css',\n colorDuration: 'css',\n focusColor: 'css',\n focusWidth: 'css',\n focusOffset: 'css',\n focusStyle: 'css'\n },\n field: {\n gap: 'css',\n labelColor: 'css',\n labelSize: 'css',\n labelWeight: 'weight',\n descriptionColor: 'css',\n descriptionSize: 'css',\n errorColor: 'css',\n errorSize: 'css',\n requiredColor: 'css',\n disabledOpacity: 'opacity'\n },\n input: {\n height: 'css',\n padding: 'css',\n fontFamily: 'css',\n fontSize: 'css',\n fontWeight: 'weight',\n color: 'css',\n background: 'css',\n borderWidth: 'css',\n borderStyle: 'css',\n borderColor: 'css',\n radius: 'css',\n cornerShape: 'css',\n shadow: 'css',\n placeholder: 'css',\n invalidBorder: 'css',\n disabledBackground: 'css',\n focusColor: 'css',\n focusWidth: 'css',\n focusOffset: 'css',\n focusStyle: 'css'\n },\n textarea: {\n minHeight: 'css',\n paddingBlock: 'css',\n padding: 'css',\n fontFamily: 'css',\n fontSize: 'css',\n fontWeight: 'weight',\n color: 'css',\n background: 'css',\n borderWidth: 'css',\n borderStyle: 'css',\n borderColor: 'css',\n radius: 'css',\n cornerShape: 'css',\n shadow: 'css',\n placeholder: 'css',\n invalidBorder: 'css',\n disabledBackground: 'css',\n focusColor: 'css',\n focusWidth: 'css',\n focusOffset: 'css',\n focusStyle: 'css'\n },\n select: {\n height: 'css',\n padding: 'css',\n fontFamily: 'css',\n fontSize: 'css',\n fontWeight: 'weight',\n color: 'css',\n background: 'css',\n borderWidth: 'css',\n borderStyle: 'css',\n borderColor: 'css',\n radius: 'css',\n cornerShape: 'css',\n shadow: 'css',\n focusColor: 'css',\n contentPadding: 'css',\n contentRadius: 'css',\n contentBackground: 'css',\n contentBackdropFilter: 'css',\n contentShadow: 'css',\n itemRadius: 'css',\n itemBackground: 'css',\n itemColor: 'css'\n },\n checkbox: {\n size: 'css',\n radius: 'css',\n cornerShape: 'css',\n borderWidth: 'css',\n borderStyle: 'css',\n borderColor: 'css',\n background: 'css',\n checkedBackground: 'css',\n checkedBorder: 'css',\n mark: 'css',\n invalidBorder: 'css',\n gap: 'css',\n labelColor: 'css',\n labelSize: 'css',\n disabledBorder: 'css',\n disabledBackground: 'css',\n focusColor: 'css',\n focusWidth: 'css',\n focusOffset: 'css',\n focusStyle: 'css'\n },\n switch: {\n width: 'css',\n height: 'css',\n radius: 'css',\n cornerShape: 'css',\n borderWidth: 'css',\n borderStyle: 'css',\n borderColor: 'css',\n background: 'css',\n checkedBackground: 'css',\n checkedBorder: 'css',\n thumb: 'css',\n checkedThumb: 'css',\n thumbRadius: 'css',\n invalidBorder: 'css',\n gap: 'css',\n labelColor: 'css',\n labelSize: 'css',\n disabledBorder: 'css',\n disabledBackground: 'css',\n disabledThumb: 'css',\n focusColor: 'css',\n focusWidth: 'css',\n focusOffset: 'css',\n focusStyle: 'css'\n },\n radio: {\n size: 'css',\n radius: 'css',\n cornerShape: 'css',\n borderWidth: 'css',\n borderStyle: 'css',\n borderColor: 'css',\n background: 'css',\n checkedBackground: 'css',\n checkedBorder: 'css',\n mark: 'css',\n invalidBorder: 'css',\n labelGap: 'css',\n labelColor: 'css',\n labelSize: 'css',\n disabledBorder: 'css',\n disabledBackground: 'css',\n focusColor: 'css',\n focusWidth: 'css',\n focusOffset: 'css',\n focusStyle: 'css'\n },\n dialog: {\n width: 'css',\n padding: 'css',\n gap: 'css',\n radius: 'css',\n cornerShape: 'css',\n background: 'css',\n color: 'css',\n borderWidth: 'css',\n borderStyle: 'css',\n borderColor: 'css',\n shadow: 'css',\n backdrop: 'css',\n backdropFilter: 'css',\n titleSize: 'css',\n titleWeight: 'weight',\n descriptionColor: 'css',\n descriptionSize: 'css',\n focusColor: 'css',\n focusWidth: 'css',\n focusOffset: 'css',\n focusStyle: 'css'\n },\n collapsible: {\n radius: 'css',\n cornerShape: 'css',\n background: 'css',\n color: 'css',\n borderWidth: 'css',\n borderStyle: 'css',\n borderColor: 'css',\n padding: 'css',\n gap: 'css',\n contentColor: 'css',\n contentSize: 'css',\n duration: 'css',\n focusColor: 'css',\n focusWidth: 'css',\n focusOffset: 'css',\n focusStyle: 'css'\n },\n accordion: {\n gap: 'css'\n },\n card: {\n radius: 'css',\n cornerShape: 'css',\n background: 'css',\n color: 'css',\n borderWidth: 'css',\n borderStyle: 'css',\n borderColor: 'css',\n padding: 'css',\n gap: 'css',\n headerGap: 'css',\n footerGap: 'css',\n shadow: 'css',\n titleSize: 'css',\n titleWeight: 'weight',\n descriptionColor: 'css',\n descriptionSize: 'css'\n },\n radioGroup: { gap: 'css' }\n} as const\n\ntype ValueKind = 'css' | 'weight' | 'number' | 'opacity'\ntype KindValue<T> = T extends 'css' ? string : T extends 'weight' ? string | number : number\nexport type ThemeComponentOverrides = {\n readonly [F in keyof typeof componentRegistry]?: {\n readonly [K in keyof (typeof componentRegistry)[F]]?: KindValue<\n (typeof componentRegistry)[F][K]\n >\n }\n}\n\nexport const componentVariables = Object.freeze(\n Object.fromEntries(\n Object.entries(componentRegistry).map(([family, keys]) => [\n family,\n Object.freeze(\n Object.fromEntries(\n Object.keys(keys).map(key => [key, `--rad-${kebabCase(family)}-${kebabCase(key)}`])\n )\n )\n ])\n )\n) as Readonly<Record<keyof typeof componentRegistry, Readonly<Record<string, `--rad-${string}`>>>>\n\nexport function componentValueKind(family: string, key: string): ValueKind | undefined {\n if (!Object.hasOwn(componentRegistry, family)) return undefined\n const keys = componentRegistry[family as keyof typeof componentRegistry]\n return Object.hasOwn(keys, key) ? (keys as Record<string, ValueKind>)[key] : undefined\n}\n\nexport function flattenComponents(overrides: ThemeComponentOverrides = {}, reset = false) {\n const result: Record<`--rad-${string}`, string | number> = {}\n for (const [family, variables] of Object.entries(componentVariables)) {\n const values = overrides[family as keyof ThemeComponentOverrides] as\n | Record<string, string | number | undefined>\n | undefined\n for (const [key, variable] of Object.entries(variables)) {\n const value = values?.[key]\n if (value !== undefined) result[variable] = value\n else if (reset) result[variable] = 'initial'\n }\n }\n return result\n}\n"]}
@@ -1,10 +1,10 @@
1
1
  # Architecture
2
2
 
3
- How Radiant's twelve families fit together and why. Props are on the
3
+ How Radiant's thirteen families fit together and why. Props are on the
4
4
  [docs site](https://github.com/cognitap/radiant-docs); themes are in [theming](theming.md); springs are in
5
5
  [motion](motion.md).
6
6
 
7
- The families are Button, Link, Field, Input, Textarea, Select, Checkbox, RadioGroup (with Radio),
7
+ The families are Button, Link, Field, Input, Textarea, Select, Checkbox, Switch, RadioGroup (with Radio),
8
8
  Dialog, Collapsible, Accordion and Card. All ship in one package,
9
9
  `@cognitap/radiant`. Deep imports are unsupported.
10
10
 
@@ -59,7 +59,7 @@ Actions take three independent props:
59
59
  | `tone` | `accent`, `neutral`, `warning`, `danger` | `accent` |
60
60
  | `controlSize` | `small`, `medium`, `large` | `medium` |
61
61
 
62
- A variant picks the treatment and a tone picks the palette. Input, Textarea, Checkbox,
62
+ A variant picks the treatment and a tone picks the palette. Input, Textarea, Checkbox, Switch,
63
63
  Radio and RadioGroup share `controlSize` but have no variants. Native meanings
64
64
  win: `Input.size` stays a character count, and a checkbox `value` stays its
65
65
  submitted data. Radius is a theme decision, not a prop.
@@ -97,7 +97,7 @@ host, never a wrapper:
97
97
  | --------------------------------------------------------------- | --------------------------------------------------- |
98
98
  | Button / Link | `button` / `a`, including through `render` |
99
99
  | Field | `div` in control layout; `fieldset` in group layout |
100
- | Input / Checkbox / Radio | Native `input` |
100
+ | Input / Checkbox / Switch / Radio | Native `input` |
101
101
  | Textarea | Native `textarea` |
102
102
  | Select / SelectPortal | None; state / portal |
103
103
  | SelectTrigger / SelectContent / SelectViewport / SelectItem | Button's `button` / `div` / `div` / `div` |
@@ -111,7 +111,7 @@ host, never a wrapper:
111
111
  | CardTitle / CardDescription | Heading chosen by `level` / `p` |
112
112
 
113
113
  Internal parts take `className` and `style` through a `parts` map. Field has
114
- `label`, `description`, `error` and `required`. Checkbox and Radio have
114
+ `label`, `description`, `error` and `required`. Checkbox, Switch and Radio have
115
115
  `wrapper`, `label` and `indicator`, and RadioGroup adds `options`. These hooks
116
116
  cannot replace IDs, ARIA, handlers or refs. Caller classes merge after the
117
117
  defaults and caller `style` wins. Identity and presentation data attributes
@@ -125,7 +125,8 @@ Why: styling written for Button still reaches a DialogTrigger.
125
125
  Style real state: native `:disabled`, `:checked` and `open`, plus `aria-busy`
126
126
  for pending. Field and RadioGroup set `data-invalid`, `data-disabled` and
127
127
  `data-required`. Disclosures and DialogContent set `data-state="open|closed"`.
128
- Actions set `data-variant`, `data-tone` and `data-control-size`.
128
+ Actions set `data-variant`, `data-tone` and `data-control-size`. Switch uses
129
+ `data-dragging` during a provisional pointer gesture; `:checked` stays committed.
129
130
 
130
131
  ## State and forms
131
132
 
@@ -134,15 +135,15 @@ or `open` to control it, or `default*` to set an initial value. Passing both, or
134
135
  a mount, throws; remount with a new `key` instead. A controlled callback is a request, and the consumer
135
136
  may refuse it. No-op requests and prop syncs fire no callback.
136
137
 
137
- | Family | State | Callback | Empty |
138
- | -------------------------- | ---------------------------- | -------------------------------------------- | ------- |
139
- | Input, Textarea | `value` / `defaultValue` | Native `onChange`, `onBlur` | `''` |
140
- | Checkbox, standalone Radio | `checked` / `defaultChecked` | Native `onChange`, `onBlur` | `false` |
141
- | RadioGroup | `value` / `defaultValue` | `onValueChange(string)` or native `onChange` | `null` |
142
- | Select | `value` / `defaultValue` | `onValueChange(string \| null)` | `null` |
143
- | Dialog, Collapsible | `open` / `defaultOpen` | `onOpenChange(boolean)` | `false` |
144
- | Accordion single | `value` / `defaultValue` | `onValueChange(string \| null)` | `null` |
145
- | Accordion multiple | `value` / `defaultValue` | `onValueChange(string[])` | `[]` |
138
+ | Family | State | Callback | Empty |
139
+ | ---------------------------------- | ---------------------------- | -------------------------------------------- | ------- |
140
+ | Input, Textarea | `value` / `defaultValue` | Native `onChange`, `onBlur` | `''` |
141
+ | Checkbox, Switch, standalone Radio | `checked` / `defaultChecked` | Native `onChange`, `onBlur` | `false` |
142
+ | RadioGroup | `value` / `defaultValue` | `onValueChange(string)` or native `onChange` | `null` |
143
+ | Select | `value` / `defaultValue` | `onValueChange(string \| null)` | `null` |
144
+ | Dialog, Collapsible | `open` / `defaultOpen` | `onOpenChange(boolean)` | `false` |
145
+ | Accordion single | `value` / `defaultValue` | `onValueChange(string \| null)` | `null` |
146
+ | Accordion multiple | `value` / `defaultValue` | `onValueChange(string[])` | `[]` |
146
147
 
147
148
  RadioGroup owns its options' `name` and selection. Use one of `onValueChange`
148
149
  or `onChange` to write state, not both. `''` is a valid option value, and `null`
package/docs/theming.md CHANGED
@@ -90,7 +90,7 @@ example, `components.button.radius` changes Button only, while
90
90
  component never falls back to another component's override.
91
91
 
92
92
  Component keys are grouped by family under `components`: `button`, `link`,
93
- `field`, `input`, `textarea`, `select`, `checkbox`, `radio`, `radioGroup`, `dialog`, `collapsible`,
93
+ `field`, `input`, `textarea`, `select`, `checkbox`, `switch`, `radio`, `radioGroup`, `dialog`, `collapsible`,
94
94
  `accordion` and `card`. Every key is listed in
95
95
  [`src/themes/components.ts`](../src/themes/components.ts). Button-only fonts,
96
96
  uppercase, shadows, squash and pressed shape belong under `components.button`.
@@ -126,7 +126,7 @@ Some defaults to know:
126
126
  - Checkbox caps an inherited radius at a quarter of its size, so it stays a
127
127
  box. An explicit `components.checkbox.radius` still wins.
128
128
  - Radio stays circular under any control shape.
129
- - Input, Checkbox and Radio outlines mix border and foreground colors, so
129
+ - Input, Textarea, Checkbox, Switch and Radio outlines mix border and foreground colors, so
130
130
  controls have more contrast than passive dividers.
131
131
  - Disabled opacity applies once, not again on a disabled child.
132
132
 
@@ -226,14 +226,14 @@ Load real italic and bold faces; synthetic styles are turned off.
226
226
 
227
227
  Components use the UI roles:
228
228
 
229
- | Text | Role |
230
- | ------------------------------------------------------------------- | ------------------------- |
231
- | ThemeScope, Card, DialogContent, Field, disclosure body | `ui-body` |
232
- | CardTitle, DialogTitle | `ui-title` |
233
- | Field label, disclosure triggers, Button, Checkbox and Radio labels | `ui-label` |
234
- | Input, Textarea | `ui-body` |
235
- | Field help and error, CardDescription, DialogDescription | `ui-supporting` |
236
- | Inline Link | Inherits surrounding text |
229
+ | Text | Role |
230
+ | --------------------------------------------------------------------------- | ------------------------- |
231
+ | ThemeScope, Card, DialogContent, Field, disclosure body | `ui-body` |
232
+ | CardTitle, DialogTitle | `ui-title` |
233
+ | Field label, disclosure triggers, Button, Checkbox, Switch and Radio labels | `ui-label` |
234
+ | Input, Textarea | `ui-body` |
235
+ | Field help and error, CardDescription, DialogDescription | `ui-supporting` |
236
+ | Inline Link | Inherits surrounding text |
237
237
 
238
238
  Controls keep their own font size from `control.<size>.fontSize`, so changing
239
239
  the UI role size does not resize buttons or inputs.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cognitap/radiant",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "description": "React interaction components and presentation primitives",
5
5
  "homepage": "https://radiant-docs.pages.dev",
6
6
  "bugs": {
@@ -131,13 +131,11 @@
131
131
  "format:check": "oxfmt --check",
132
132
  "check:source": "pnpm theme:check && pnpm format:check && pnpm lint && pnpm typecheck && pnpm docs:check",
133
133
  "docs:check": "node scripts/check-docs.mjs",
134
- "check:ci": "pnpm check:source && pnpm test && pnpm build:storybook && pnpm test:browser:smoke",
135
- "check": "pnpm check:source && pnpm test && pnpm build:storybook && pnpm test:browser",
134
+ "check": "pnpm check:source && pnpm build && node --test tests/*.test.mjs && node scripts/pack-and-test.ts && pnpm build:storybook && pnpm test:browser --project=storybook-radiant-light --project=storybook-radiant-dark",
136
135
  "release:prepare": "node scripts/prepare-release.mjs",
137
136
  "theme:generate": "node scripts/generate-theme-css.mjs",
138
137
  "theme:check": "node scripts/generate-theme-css.mjs --check",
139
138
  "watch:theme": "node scripts/generate-theme-css.mjs --watch",
140
- "test:browser": "pnpm theme:generate && vitest run",
141
- "test:browser:smoke": "pnpm test:browser --project=storybook-radiant-light --project=storybook-radiant-dark --project=browser-platform"
139
+ "test:browser": "pnpm theme:generate && vitest run"
142
140
  }
143
141
  }
package/src/Switch.tsx ADDED
@@ -0,0 +1,174 @@
1
+ 'use client'
2
+
3
+ import { useCallback, useLayoutEffect, useRef, type ComponentProps, type ReactNode } from 'react'
4
+ import { cva } from 'class-variance-authority'
5
+ import { cn } from './cn.js'
6
+ import { useSwitchDrag } from './react/useSwitchDrag.js'
7
+ import { useComposedRefs } from './react/useComposedRefs.js'
8
+ import { useNativeOwner, type CheckedOwner } from './react/useNativeOwner.js'
9
+ import { controlBorderClass, controlMetrics } from './controlStyles.js'
10
+ import { useFieldControl } from './Field.js'
11
+ import type { ThemeStyle } from './themes/defineTheme.js'
12
+ import type { ControlSize, ControlParts } from './presentation.js'
13
+
14
+ const switchVariants = cva([
15
+ controlBorderClass,
16
+ 'peer col-start-1 row-start-1 m-0 box-border appearance-none touch-pan-y select-none cursor-default',
17
+ 'h-[var(--rad-switch-height,calc(var(--_rad-control-indicator-size)*1.25))]',
18
+ 'w-[var(--rad-switch-width,calc(var(--_rad-control-indicator-size)*2.25))]',
19
+ 'rounded-[var(--rad-switch-radius,var(--rad-control-radius,0.5rem))]',
20
+ '[corner-shape:var(--rad-switch-corner-shape,var(--rad-control-corner-shape,round))]',
21
+ '[border-width:var(--rad-switch-border-width,var(--rad-control-border-width,1px))]',
22
+ '[border-style:var(--rad-switch-border-style,var(--rad-control-border-style,solid))]',
23
+ '[border-color:var(--rad-switch-border-color,var(--_rad-control-border))]',
24
+ 'bg-[var(--rad-switch-background,var(--rad-color-surface,oklch(1_0_0)))]',
25
+ 'checked:bg-[var(--rad-switch-checked-background,var(--rad-color-accent,oklch(0.21_0.006_286)))]',
26
+ 'checked:[border-color:var(--rad-switch-checked-border,var(--rad-switch-checked-background,var(--rad-color-accent,oklch(0.21_0.006_286))))]',
27
+ 'data-invalid:[border-color:var(--rad-switch-invalid-border,var(--rad-color-invalid,oklch(0.56_0.19_25)))]',
28
+ 'focus-visible:outline-solid',
29
+ 'focus-visible:[outline-color:var(--rad-switch-focus-color,var(--rad-color-focus,oklch(0.55_0.13_255)))]',
30
+ 'focus-visible:[outline-width:var(--rad-switch-focus-width,var(--rad-focus-width,2px))]',
31
+ 'focus-visible:[outline-offset:var(--rad-switch-focus-offset,var(--rad-focus-offset,2px))]',
32
+ 'focus-visible:[outline-style:var(--rad-switch-focus-style,var(--rad-focus-style,solid))]',
33
+ 'disabled:cursor-not-allowed',
34
+ 'disabled:[border-color:var(--rad-switch-disabled-border,var(--rad-color-disabled-border,oklch(0.88_0.005_286)))]',
35
+ 'disabled:bg-[var(--rad-switch-disabled-background,var(--rad-color-disabled-background,oklch(0.96_0.005_286)))]',
36
+ 'forced-colors:border-[CanvasText] forced-colors:bg-[Canvas]',
37
+ 'forced-colors:checked:bg-[Highlight]',
38
+ 'forced-colors:disabled:border-[GrayText] forced-colors:disabled:bg-[Canvas]'
39
+ ])
40
+
41
+ const thumbClass =
42
+ 'block size-full shrink-0 forced-colors:[forced-color-adjust:none] rounded-[var(--rad-switch-thumb-radius,var(--rad-control-radius,0.5rem))] [corner-shape:var(--rad-switch-corner-shape,var(--rad-control-corner-shape,round))] bg-current'
43
+ const indicatorClass =
44
+ 'pointer-events-none absolute inset-[3px] flex justify-start peer-checked:justify-end [color:var(--rad-switch-thumb,var(--rad-color-muted-foreground,oklch(0.45_0.01_286)))] peer-checked:[color:var(--rad-switch-checked-thumb,var(--rad-color-accent-foreground,oklch(0.985_0_0)))] peer-disabled:[color:var(--rad-switch-disabled-thumb,var(--rad-color-muted-foreground,oklch(0.45_0.01_286)))] forced-colors:text-[CanvasText] forced-colors:peer-checked:text-[HighlightText] forced-colors:peer-disabled:text-[GrayText]'
45
+
46
+ const rowClass =
47
+ 'inline-flex min-h-6 min-w-0 max-w-full cursor-default items-center gap-[var(--rad-switch-gap,var(--rad-spacing-label-gap,0.5rem))] select-none has-disabled:cursor-not-allowed'
48
+ const labelClass =
49
+ 'min-w-0 break-words font-[family-name:var(--rad-typography-roles-ui-label-family,system-ui,sans-serif)] tracking-[var(--rad-typography-roles-ui-label-letter-spacing,-0.011em)] font-[number:var(--rad-typography-roles-ui-label-weight,400)] [color:var(--rad-switch-label-color,var(--rad-color-foreground,oklch(0.21_0.006_286)))] text-[length:var(--rad-switch-label-size,var(--_rad-control-font-size))] leading-[var(--rad-typography-roles-ui-label-line-height,1.4)]'
50
+
51
+ export type SwitchProps = Omit<
52
+ ComponentProps<'input'>,
53
+ 'type' | 'role' | 'aria-checked' | 'checked' | 'defaultChecked' | 'readOnly' | 'style'
54
+ > &
55
+ CheckedOwner & {
56
+ /** Stable setting name. Omit when Field supplies the label. */
57
+ label?: ReactNode
58
+ controlSize?: ControlSize
59
+ /** Native input styles. Parts style the wrapper, label and decorative thumb. */
60
+ style?: ThemeStyle
61
+ parts?: ControlParts
62
+ }
63
+
64
+ /** Native on/off setting. Read checked for state and value for submitted data. */
65
+ export function Switch({
66
+ className,
67
+ controlSize = 'medium',
68
+ parts,
69
+ label,
70
+ id,
71
+ disabled,
72
+ required,
73
+ checked,
74
+ defaultChecked,
75
+ ref,
76
+ 'aria-describedby': ariaDescribedBy,
77
+ 'aria-invalid': ariaInvalid,
78
+ 'aria-required': ariaRequired,
79
+ ...props
80
+ }: SwitchProps) {
81
+ const controlled = useNativeOwner('Switch', checked, defaultChecked)
82
+ const labelled = label != null && label !== false && label !== ''
83
+ const control = useFieldControl({
84
+ id,
85
+ disabled,
86
+ required,
87
+ 'aria-describedby': ariaDescribedBy,
88
+ 'aria-invalid': ariaInvalid,
89
+ 'aria-required': ariaRequired
90
+ })
91
+ const nodeRef = useRef<HTMLInputElement>(null)
92
+ const railRef = useRef<HTMLSpanElement>(null)
93
+ const handleRef = useRef<HTMLSpanElement>(null)
94
+ const drag = useSwitchDrag(nodeRef, railRef, handleRef)
95
+ const initialise = useCallback(
96
+ (node: HTMLInputElement | null) => {
97
+ nodeRef.current = node
98
+ if (node && controlled) node.defaultChecked = node.checked
99
+ },
100
+ [controlled]
101
+ )
102
+ const hostRef = useComposedRefs(initialise, ref)
103
+ useLayoutEffect(() => {
104
+ if (nodeRef.current && controlled) nodeRef.current.defaultChecked = !!checked
105
+ })
106
+ const controlNode = (
107
+ <span
108
+ className={cn('relative inline-grid w-fit shrink-0', !labelled && parts?.wrapper?.className)}
109
+ style={!labelled ? parts?.wrapper?.style : undefined}
110
+ data-slot={!labelled ? 'switch-wrapper' : undefined}
111
+ >
112
+ <input
113
+ {...props}
114
+ {...control}
115
+ onPointerDown={event => {
116
+ props.onPointerDown?.(event)
117
+ drag.start(event.nativeEvent)
118
+ }}
119
+ onKeyDown={event => {
120
+ props.onKeyDown?.(event)
121
+ if (drag.escape(event.nativeEvent)) {
122
+ event.preventDefault()
123
+ event.stopPropagation()
124
+ }
125
+ }}
126
+ checked={checked}
127
+ defaultChecked={defaultChecked}
128
+ ref={hostRef}
129
+ className={cn(switchVariants(), controlMetrics({ controlSize }), className)}
130
+ data-control-size={controlSize}
131
+ data-slot="switch"
132
+ data-dragging={undefined}
133
+ type="checkbox"
134
+ role="switch"
135
+ aria-checked={undefined}
136
+ />
137
+ <span
138
+ aria-hidden="true"
139
+ ref={railRef}
140
+ dir={props.dir}
141
+ style={{ direction: props.style?.direction }}
142
+ className={indicatorClass}
143
+ >
144
+ <span
145
+ ref={handleRef}
146
+ className="h-full w-auto shrink-0 aspect-square"
147
+ >
148
+ <span
149
+ className={cn(thumbClass, parts?.indicator?.className)}
150
+ style={parts?.indicator?.style}
151
+ data-slot="switch-indicator"
152
+ />
153
+ </span>
154
+ </span>
155
+ </span>
156
+ )
157
+ if (!labelled) return controlNode
158
+ return (
159
+ <label
160
+ className={cn(rowClass, parts?.wrapper?.className)}
161
+ style={parts?.wrapper?.style}
162
+ data-slot="switch-wrapper"
163
+ >
164
+ {controlNode}
165
+ <span
166
+ className={cn(labelClass, controlMetrics({ controlSize }), parts?.label?.className)}
167
+ style={parts?.label?.style}
168
+ data-slot="switch-label"
169
+ >
170
+ {label}
171
+ </span>
172
+ </label>
173
+ )
174
+ }
package/src/cn.ts CHANGED
@@ -23,9 +23,12 @@ export const cn: CnFunction = createCn({
23
23
  ...roleClasses('text', 'size'),
24
24
  ...roleClasses('text', 'fluid-size'),
25
25
  'text-(--rad-select-font-size)',
26
- 'text-(--rad-textarea-font-size)'
26
+ 'text-(--rad-textarea-font-size)',
27
+ 'text-(--rad-switch-label-size)'
27
28
  ],
28
- h: ['h-(--rad-select-height)'],
29
+ h: ['h-(--rad-select-height)', 'h-(--rad-switch-height)'],
30
+ w: ['w-(--rad-switch-width)'],
31
+ gap: ['gap-(--rad-switch-gap)'],
29
32
  'min-h': ['min-h-(--rad-textarea-min-height)'],
30
33
  py: ['py-(--rad-textarea-padding-block)'],
31
34
  px: ['px-(--rad-select-padding)', 'px-(--rad-textarea-padding)'],
@@ -33,13 +36,20 @@ export const cn: CnFunction = createCn({
33
36
  rounded: [
34
37
  'rounded-(--rad-select-radius)',
35
38
  'rounded-(--rad-textarea-radius)',
39
+ 'rounded-(--rad-switch-radius)',
40
+ 'rounded-(--rad-switch-thumb-radius)',
36
41
  'rounded-(--rad-select-content-radius)',
37
42
  'rounded-(--rad-select-item-radius)'
38
43
  ],
39
- 'border-w': ['border-(--rad-select-border-width)', 'border-(--rad-textarea-border-width)'],
44
+ 'border-w': [
45
+ 'border-(--rad-select-border-width)',
46
+ 'border-(--rad-textarea-border-width)',
47
+ 'border-(--rad-switch-border-width)'
48
+ ],
40
49
  'border-style': [
41
50
  'border-(--rad-select-border-style)',
42
- 'border-(--rad-textarea-border-style)'
51
+ 'border-(--rad-textarea-border-style)',
52
+ 'border-(--rad-switch-border-style)'
43
53
  ],
44
54
  shadow: [
45
55
  'shadow-(--rad-select-shadow)',
@@ -48,11 +58,18 @@ export const cn: CnFunction = createCn({
48
58
  ],
49
59
  'corner-shape': [
50
60
  '[corner-shape:var(--rad-select-corner-shape)]',
51
- '[corner-shape:var(--rad-textarea-corner-shape)]'
61
+ '[corner-shape:var(--rad-textarea-corner-shape)]',
62
+ '[corner-shape:var(--rad-switch-corner-shape)]'
63
+ ],
64
+ 'outline-w': ['outline-(--rad-textarea-focus-width)', 'outline-(--rad-switch-focus-width)'],
65
+ 'outline-offset': [
66
+ 'outline-offset-(--rad-textarea-focus-offset)',
67
+ 'outline-offset-(--rad-switch-focus-offset)'
68
+ ],
69
+ 'outline-style': [
70
+ 'outline-(--rad-textarea-focus-style)',
71
+ 'outline-(--rad-switch-focus-style)'
52
72
  ],
53
- 'outline-w': ['outline-(--rad-textarea-focus-width)'],
54
- 'outline-offset': ['outline-offset-(--rad-textarea-focus-offset)'],
55
- 'outline-style': ['outline-(--rad-textarea-focus-style)'],
56
73
  'backdrop-filter': ['[backdrop-filter:var(--rad-select-content-backdrop-filter)]'],
57
74
  leading: roleClasses('leading', 'line-height'),
58
75
  tracking: roleClasses('tracking', 'letter-spacing'),
package/src/index.ts CHANGED
@@ -34,6 +34,8 @@ export type {
34
34
  SelectItemTextProps,
35
35
  SelectGroupProps
36
36
  } from './Select.js'
37
+ export { Switch } from './Switch.js'
38
+ export type { SwitchProps } from './Switch.js'
37
39
  export { Checkbox } from './Checkbox.js'
38
40
  export type { CheckboxProps } from './Checkbox.js'
39
41
  export { Radio, RadioGroup } from './RadioGroup.js'
@@ -0,0 +1,188 @@
1
+ export interface SwitchDragBinding {
2
+ start(event: PointerEvent): void
3
+ escape(event: KeyboardEvent): boolean
4
+ reconcile(): void
5
+ dispose(): void
6
+ }
7
+
8
+ type Gesture = {
9
+ pointer: number
10
+ x: number
11
+ y: number
12
+ checked: boolean
13
+ direction: number
14
+ travel: number
15
+ cssTravel: number
16
+ progress: number
17
+ moved: boolean
18
+ transform: string
19
+ form: HTMLFormElement | null
20
+ cleanup(): void
21
+ }
22
+
23
+ /** Preview on a private thumb wrapper; commit through the input's native activation. */
24
+ export function bindSwitchDrag(
25
+ input: HTMLInputElement,
26
+ rail: HTMLElement,
27
+ handle: HTMLElement
28
+ ): SwitchDragBinding {
29
+ const document = input.ownerDocument
30
+ const view = document.defaultView!
31
+ let gesture: Gesture | null = null
32
+ let suppressClick = false
33
+ const blocked = () => input.matches(':disabled') || !input.isConnected
34
+ const metrics = () => ({
35
+ travel: Math.max(0, rail.getBoundingClientRect().width - handle.getBoundingClientRect().width),
36
+ cssTravel: Math.max(
37
+ 0,
38
+ parseFloat(view.getComputedStyle(rail).width) -
39
+ parseFloat(view.getComputedStyle(handle).width)
40
+ ),
41
+ direction: view.getComputedStyle(rail).direction === 'rtl' ? -1 : 1
42
+ })
43
+ function finish() {
44
+ const current = gesture
45
+ if (!current) return
46
+ gesture = null
47
+ suppressClick = current.moved
48
+ current.cleanup()
49
+ handle.style.transform = current.transform
50
+ input.removeAttribute('data-dragging')
51
+ if (input.hasPointerCapture(current.pointer)) input.releasePointerCapture(current.pointer)
52
+ return current
53
+ }
54
+ const cancel = () => {
55
+ finish()
56
+ }
57
+ function move(event: PointerEvent) {
58
+ const current = gesture
59
+ if (!current || current.pointer !== event.pointerId) return
60
+ if (event.defaultPrevented || blocked() || input.checked !== current.checked) {
61
+ cancel()
62
+ return
63
+ }
64
+ const dx = event.clientX - current.x
65
+ if (!current.moved && Math.abs(event.clientY - current.y) > Math.max(4, Math.abs(dx))) {
66
+ cancel()
67
+ return
68
+ }
69
+ if (!current.moved && Math.abs(dx) < 3) return
70
+ if (!current.moved) {
71
+ current.moved = true
72
+ input.focus({ preventScroll: true })
73
+ if (gesture !== current) return
74
+ input.setAttribute('data-dragging', '')
75
+ try {
76
+ input.setPointerCapture(current.pointer)
77
+ } catch {
78
+ /* Owner-document events retain outside release. */
79
+ }
80
+ }
81
+ if (gesture !== current) return
82
+ event.preventDefault()
83
+ current.progress = Math.max(
84
+ 0,
85
+ Math.min(1, Number(current.checked) + (dx * current.direction) / current.travel)
86
+ )
87
+ handle.style.transform = `translateX(${(current.progress - Number(current.checked)) * current.cssTravel * current.direction}px)`
88
+ }
89
+ function up(event: PointerEvent) {
90
+ const current = gesture
91
+ if (!current || current.pointer !== event.pointerId) return
92
+ if (event.defaultPrevented || blocked() || input.checked !== current.checked) {
93
+ cancel()
94
+ return
95
+ }
96
+ // A release can contain a final coordinate without a preceding move sample.
97
+ if (current.moved) move(event)
98
+ const ended = finish()
99
+ if (!ended?.moved) return
100
+ const next = ended.progress === 0.5 ? ended.checked : ended.progress > 0.5
101
+ if (next !== input.checked) input.click()
102
+ }
103
+ function pointerCancelled(event: PointerEvent) {
104
+ if (gesture?.pointer === event.pointerId) cancel()
105
+ }
106
+ function click(event: MouseEvent) {
107
+ // Native keyboard/programmatic activation has detail 0, including our commit.
108
+ if (!suppressClick || event.detail === 0) return
109
+ suppressClick = false
110
+ event.preventDefault()
111
+ event.stopPropagation()
112
+ }
113
+ input.addEventListener('click', click, true)
114
+ return {
115
+ start(event) {
116
+ if (
117
+ event.defaultPrevented ||
118
+ event.button !== 0 ||
119
+ event.isPrimary === false ||
120
+ gesture ||
121
+ blocked()
122
+ )
123
+ return
124
+ suppressClick = false
125
+ const measured = metrics()
126
+ if (!(measured.travel > 0 && measured.cssTravel > 0)) return
127
+ const observer = new view.MutationObserver(() => {
128
+ if (blocked()) cancel()
129
+ })
130
+ observer.observe(input, { attributes: true, attributeFilter: ['disabled'] })
131
+ for (let parent = input.parentElement; parent; parent = parent.parentElement)
132
+ if (parent.tagName === 'FIELDSET')
133
+ observer.observe(parent, { attributes: true, attributeFilter: ['disabled'] })
134
+ const form = input.form
135
+ gesture = {
136
+ pointer: event.pointerId,
137
+ x: event.clientX,
138
+ y: event.clientY,
139
+ checked: input.checked,
140
+ ...measured,
141
+ progress: Number(input.checked),
142
+ moved: false,
143
+ transform: handle.style.transform,
144
+ form,
145
+ cleanup() {
146
+ document.removeEventListener('pointermove', move)
147
+ document.removeEventListener('pointerup', up)
148
+ document.removeEventListener('pointercancel', pointerCancelled)
149
+ input.removeEventListener('lostpointercapture', pointerCancelled)
150
+ input.removeEventListener('blur', cancel)
151
+ form?.removeEventListener('reset', cancel)
152
+ view.removeEventListener('blur', cancel)
153
+ view.removeEventListener('resize', cancel)
154
+ observer.disconnect()
155
+ }
156
+ }
157
+ document.addEventListener('pointermove', move, { passive: false })
158
+ document.addEventListener('pointerup', up)
159
+ document.addEventListener('pointercancel', pointerCancelled)
160
+ input.addEventListener('lostpointercapture', pointerCancelled)
161
+ input.addEventListener('blur', cancel)
162
+ form?.addEventListener('reset', cancel)
163
+ view.addEventListener('blur', cancel)
164
+ view.addEventListener('resize', cancel)
165
+ },
166
+ escape(event) {
167
+ if (!gesture || event.defaultPrevented || event.key !== 'Escape') return false
168
+ cancel()
169
+ return true
170
+ },
171
+ reconcile() {
172
+ if (!gesture) return
173
+ const measured = metrics()
174
+ if (
175
+ blocked() ||
176
+ input.checked !== gesture.checked ||
177
+ input.form !== gesture.form ||
178
+ measured.direction !== gesture.direction ||
179
+ Math.abs(measured.travel - gesture.travel) > 0.5
180
+ )
181
+ cancel()
182
+ },
183
+ dispose() {
184
+ cancel()
185
+ input.removeEventListener('click', click, true)
186
+ }
187
+ }
188
+ }