@kirana-ui/vue 0.0.0-stage → 0.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 (88) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +130 -4
  3. package/src/accordion.d.ts +78 -0
  4. package/src/accordion.js +92 -0
  5. package/src/accordion.js.map +1 -0
  6. package/src/alert-dialog.d.ts +2 -0
  7. package/src/alert-dialog.js +1 -0
  8. package/src/avatar.d.ts +16 -0
  9. package/src/avatar.js +40 -0
  10. package/src/avatar.js.map +1 -0
  11. package/src/button.d.ts +23 -0
  12. package/src/button.js +22 -0
  13. package/src/button.js.map +1 -0
  14. package/src/checkbox.d.ts +51 -0
  15. package/src/checkbox.js +62 -0
  16. package/src/checkbox.js.map +1 -0
  17. package/src/collapsible.d.ts +39 -0
  18. package/src/collapsible.js +50 -0
  19. package/src/collapsible.js.map +1 -0
  20. package/src/dialog.d.ts +84 -0
  21. package/src/dialog.js +78 -0
  22. package/src/dialog.js.map +1 -0
  23. package/src/direction-context.d.ts +5 -0
  24. package/src/direction-context.js +9 -0
  25. package/src/direction-context.js.map +1 -0
  26. package/src/direction.d.ts +16 -0
  27. package/src/direction.js +25 -0
  28. package/src/direction.js.map +1 -0
  29. package/src/field-context.d.ts +6 -0
  30. package/src/field-context.js +17 -0
  31. package/src/field-context.js.map +1 -0
  32. package/src/field.d.ts +49 -0
  33. package/src/field.js +79 -0
  34. package/src/field.js.map +1 -0
  35. package/src/fieldset.d.ts +18 -0
  36. package/src/fieldset.js +35 -0
  37. package/src/fieldset.js.map +1 -0
  38. package/src/form.d.ts +22 -0
  39. package/src/form.js +29 -0
  40. package/src/form.js.map +1 -0
  41. package/src/hover-card.d.ts +38 -0
  42. package/src/hover-card.js +7 -0
  43. package/src/hover-card.js.map +1 -0
  44. package/src/hover-popup.d.ts +41 -0
  45. package/src/hover-popup.js +46 -0
  46. package/src/hover-popup.js.map +1 -0
  47. package/src/index.d.ts +23 -0
  48. package/src/index.js +23 -0
  49. package/src/meter.d.ts +34 -0
  50. package/src/meter.js +7 -0
  51. package/src/meter.js.map +1 -0
  52. package/src/popover.d.ts +39 -0
  53. package/src/popover.js +60 -0
  54. package/src/popover.js.map +1 -0
  55. package/src/progress.d.ts +34 -0
  56. package/src/progress.js +7 -0
  57. package/src/progress.js.map +1 -0
  58. package/src/radio-group.d.ts +76 -0
  59. package/src/radio-group.js +95 -0
  60. package/src/radio-group.js.map +1 -0
  61. package/src/runtime.d.ts +29 -0
  62. package/src/runtime.js +130 -0
  63. package/src/runtime.js.map +1 -0
  64. package/src/select.d.ts +119 -0
  65. package/src/select.js +127 -0
  66. package/src/select.js.map +1 -0
  67. package/src/separator.d.ts +10 -0
  68. package/src/separator.js +17 -0
  69. package/src/separator.js.map +1 -0
  70. package/src/slider.d.ts +79 -0
  71. package/src/slider.js +92 -0
  72. package/src/slider.js.map +1 -0
  73. package/src/switch.d.ts +40 -0
  74. package/src/switch.js +49 -0
  75. package/src/switch.js.map +1 -0
  76. package/src/tabs.d.ts +101 -0
  77. package/src/tabs.js +106 -0
  78. package/src/tabs.js.map +1 -0
  79. package/src/toggle.d.ts +26 -0
  80. package/src/toggle.js +31 -0
  81. package/src/toggle.js.map +1 -0
  82. package/src/tooltip.d.ts +38 -0
  83. package/src/tooltip.js +7 -0
  84. package/src/tooltip.js.map +1 -0
  85. package/src/value-bar.d.ts +38 -0
  86. package/src/value-bar.js +52 -0
  87. package/src/value-bar.js.map +1 -0
  88. package/README.md +0 -3
package/src/runtime.js ADDED
@@ -0,0 +1,130 @@
1
+ import { mergeProps, sameProps, signal } from "@kirana-ui/core";
2
+ import { Comment, Fragment, Teleport, cloneVNode, defineComponent, h, inject, onBeforeUnmount, onMounted, onScopeDispose, provide, queuePostFlushCb, shallowRef, watchEffect } from "vue";
3
+ // src/runtime.ts
4
+ /** A core signal as a Vue ref, read-only: tracked by whatever reads `.value`. */
5
+ function fromSignal(source) {
6
+ const ref = shallowRef(source.peek());
7
+ if (typeof window !== "undefined") onScopeDispose(source.subscribe(() => {
8
+ ref.value = source.peek();
9
+ }));
10
+ return ref;
11
+ }
12
+ /** A core signal that follows Vue state: the core hears a changed prop as it changes. */
13
+ function toSignal(read) {
14
+ const source = signal(read(), sameProps);
15
+ watchEffect(() => source.set(read()), { flush: "sync" });
16
+ return source;
17
+ }
18
+ /** A component's controller, made once, following its props. */
19
+ function controller(create, read) {
20
+ const made = create(toSignal(read));
21
+ let stop;
22
+ onMounted(() => {
23
+ stop = made.mount();
24
+ });
25
+ onBeforeUnmount(() => stop?.());
26
+ return made;
27
+ }
28
+ /** A controller its parts find: `provide` in the root, `use` in a part. */
29
+ function context(name) {
30
+ const key = Symbol(name);
31
+ return {
32
+ provide(made) {
33
+ provide(key, made);
34
+ return made;
35
+ },
36
+ use() {
37
+ const made = inject(key, void 0);
38
+ if (!made) throw new Error(`A ${name} part must be inside <${name}.Root>`);
39
+ return made;
40
+ }
41
+ };
42
+ }
43
+ function toVue(props) {
44
+ const out = {};
45
+ for (const key in props) {
46
+ const value = props[key];
47
+ if (typeof value === "function") {
48
+ const name = key.slice(2).toLowerCase();
49
+ const event = name === "focus" ? "focusin" : name === "blur" ? "focusout" : name;
50
+ out[`on${event[0].toUpperCase()}${event.slice(1)}`] = value;
51
+ } else out[key] = value;
52
+ }
53
+ return out;
54
+ }
55
+ function firstElement(nodes) {
56
+ for (const node of nodes ?? []) {
57
+ if (node.type === Comment) continue;
58
+ if (node.type === Fragment) return firstElement(node.children);
59
+ return node;
60
+ }
61
+ }
62
+ /**
63
+ * A part as a component: its element (`as`, the part's own tag by default), or with `as-child`
64
+ * the caller's own element in its slot, which takes the part's props. Either way the caller's
65
+ * attributes are merged under the part's, and the part's DOM work is attached to the element.
66
+ */
67
+ function partComponent(name, tag, resolve) {
68
+ return defineComponent({
69
+ name,
70
+ inheritAttrs: false,
71
+ props: {
72
+ as: {
73
+ type: String,
74
+ default: tag
75
+ },
76
+ asChild: Boolean
77
+ },
78
+ setup(props, { attrs, slots }) {
79
+ const part = resolve();
80
+ const own = fromSignal(part.props);
81
+ let element = null;
82
+ let detach;
83
+ let wanted = null;
84
+ const sync = () => {
85
+ if (wanted === element) return;
86
+ detach?.();
87
+ element = wanted;
88
+ detach = wanted ? part.attach(wanted) : void 0;
89
+ };
90
+ const attach = (target) => {
91
+ wanted = target instanceof HTMLElement ? target : target?.$el ?? null;
92
+ if (wanted) queuePostFlushCb(sync);
93
+ else sync();
94
+ };
95
+ return () => {
96
+ const merged = {
97
+ ...mergeProps(attrs, toVue(own.value)),
98
+ ref: attach
99
+ };
100
+ if (props.asChild) {
101
+ const child = firstElement(slots.default?.());
102
+ return child ? cloneVNode(child, merged, true) : null;
103
+ }
104
+ return h(props.as, merged, slots.default?.());
105
+ };
106
+ }
107
+ });
108
+ }
109
+ /** Its slot in a container at the end of the page, while `mounted`. */
110
+ function portalComponent(name, mounted) {
111
+ return defineComponent({
112
+ name,
113
+ setup(_props, { slots }) {
114
+ const shown = fromSignal(mounted());
115
+ const ready = shallowRef(false);
116
+ onMounted(() => {
117
+ ready.value = true;
118
+ });
119
+ return () => shown.value && ready.value ? h(Teleport, { to: "body" }, h("div", { "data-kirana-portal": "" }, slots.default?.())) : null;
120
+ }
121
+ });
122
+ }
123
+ /** A prop that is "not given" when absent, where Vue would make a boolean `false`. */
124
+ const optional = (type) => ({
125
+ type,
126
+ default: void 0
127
+ });
128
+ export { context, controller, fromSignal, optional, partComponent, portalComponent, toSignal };
129
+
130
+ //# sourceMappingURL=runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.js","names":[],"sources":["../../../../packages/vue/src/runtime.ts"],"sourcesContent":["import { mergeProps, sameProps, signal } from \"@kirana-ui/core\"\nimport type { Part, PartProps, ReadonlySignal } from \"@kirana-ui/core\"\nimport {\n Comment,\n Fragment,\n Teleport,\n cloneVNode,\n defineComponent,\n h,\n inject,\n onBeforeUnmount,\n onMounted,\n onScopeDispose,\n provide,\n queuePostFlushCb,\n shallowRef,\n watchEffect,\n} from \"vue\"\nimport type { Component, InjectionKey, ShallowRef, VNode } from \"vue\"\n\n/** A core signal as a Vue ref, read-only: tracked by whatever reads `.value`. */\nexport function fromSignal<T>(source: ReadonlySignal<T>): Readonly<ShallowRef<T>> {\n const ref = shallowRef(source.peek())\n // On a server nothing changes after the first read, and no scope is disposed to unsubscribe.\n if (typeof window !== \"undefined\") {\n onScopeDispose(\n source.subscribe(() => {\n ref.value = source.peek()\n })\n )\n }\n return ref\n}\n\n/** A core signal that follows Vue state: the core hears a changed prop as it changes. */\nexport function toSignal<T extends Record<string, unknown>>(read: () => T): ReadonlySignal<T> {\n const source = signal(read(), sameProps as (a: T, b: T) => boolean)\n watchEffect(() => source.set(read()), { flush: \"sync\" })\n return source\n}\n\n/** A component's controller, made once, following its props. */\nexport function controller<P extends Record<string, unknown>, C extends { mount(): () => void }>(\n create: (props: ReadonlySignal<P>) => C,\n read: () => P\n): C {\n const made = create(toSignal(read))\n let stop: (() => void) | undefined\n onMounted(() => {\n stop = made.mount()\n })\n onBeforeUnmount(() => stop?.())\n return made\n}\n\n/** A controller its parts find: `provide` in the root, `use` in a part. */\nexport function context<C>(name: string): { provide(controller: C): C; use(): C } {\n const key: InjectionKey<C> = Symbol(name)\n return {\n provide(made) {\n provide(key, made)\n return made\n },\n use() {\n const made = inject(key, undefined)\n if (!made) throw new Error(`A ${name} part must be inside <${name}.Root>`)\n return made\n },\n }\n}\n\nfunction toVue(props: PartProps): PartProps {\n const out: PartProps = {}\n for (const key in props) {\n const value = props[key]\n if (typeof value === \"function\") {\n // Vue names an event from the listener's key, so `onKeyDown` would listen for `key-down`:\n // it is `onKeydown`. Focus and blur are the bubbling ones, as in the core.\n const name = key.slice(2).toLowerCase()\n const event = name === \"focus\" ? \"focusin\" : name === \"blur\" ? \"focusout\" : name\n out[`on${event[0]!.toUpperCase()}${event.slice(1)}`] = value\n } else {\n out[key] = value\n }\n }\n return out\n}\n\nfunction firstElement(nodes: VNode[] | undefined): VNode | undefined {\n for (const node of nodes ?? []) {\n if (node.type === Comment) continue\n if (node.type === Fragment) return firstElement(node.children as VNode[])\n return node\n }\n return undefined\n}\n\n/**\n * A part as a component: its element (`as`, the part's own tag by default), or with `as-child`\n * the caller's own element in its slot, which takes the part's props. Either way the caller's\n * attributes are merged under the part's, and the part's DOM work is attached to the element.\n */\nexport function partComponent(name: string, tag: string, resolve: () => Part): Component {\n return defineComponent({\n name,\n inheritAttrs: false,\n props: { as: { type: String, default: tag }, asChild: Boolean },\n setup(props, { attrs, slots }) {\n const part = resolve()\n const own = fromSignal(part.props)\n let element: HTMLElement | null = null\n let detach: (() => void) | undefined\n\n // Vue calls a function ref as soon as the element exists, before the tree it is in reaches\n // the page: the part's DOM work (focus, measures, the starting style) waits for the flush\n // that follows the render, when it is there. An element that leaves detaches at once.\n let wanted: HTMLElement | null = null\n const sync = () => {\n if (wanted === element) return\n detach?.()\n element = wanted\n detach = wanted ? part.attach(wanted) : undefined\n }\n const attach = (target: unknown) => {\n wanted =\n target instanceof HTMLElement\n ? target\n : (((target as { $el?: unknown } | null)?.$el as HTMLElement | undefined) ?? null)\n if (wanted) queuePostFlushCb(sync)\n else sync()\n }\n\n return () => {\n const merged = { ...mergeProps(attrs, toVue(own.value)), ref: attach }\n if (props.asChild) {\n const child = firstElement(slots.default?.())\n return child ? cloneVNode(child, merged, true) : null\n }\n return h(props.as, merged, slots.default?.())\n }\n },\n })\n}\n\n/** Its slot in a container at the end of the page, while `mounted`. */\nexport function portalComponent(name: string, mounted: () => ReadonlySignal<boolean>): Component {\n return defineComponent({\n name,\n setup(_props, { slots }) {\n const shown = fromSignal(mounted())\n // Only in a browser, once the page is in it: a server draws no portal, so hydration must\n // find none either. One that opens later is drawn at once.\n const ready = shallowRef(false)\n onMounted(() => {\n ready.value = true\n })\n return () =>\n shown.value && ready.value\n ? h(Teleport, { to: \"body\" }, h(\"div\", { \"data-kirana-portal\": \"\" }, slots.default?.()))\n : null\n },\n })\n}\n\n/** A prop that is \"not given\" when absent, where Vue would make a boolean `false`. */\nexport const optional = <T>(type: T) => ({ type, default: undefined })\n"],"mappings":";;;;AAqBA,SAAgB,WAAc,QAAoD;CAChF,MAAM,MAAM,WAAW,OAAO,KAAK,CAAC;CAEpC,IAAI,OAAO,WAAW,aACpB,eACE,OAAO,gBAAgB;EACrB,IAAI,QAAQ,OAAO,KAAK;CAC1B,CAAC,CACH;CAEF,OAAO;AACT;;AAGA,SAAgB,SAA4C,MAAkC;CAC5F,MAAM,SAAS,OAAO,KAAK,GAAG,SAAoC;CAClE,kBAAkB,OAAO,IAAI,KAAK,CAAC,GAAG,EAAE,OAAO,OAAO,CAAC;CACvD,OAAO;AACT;;AAGA,SAAgB,WACd,QACA,MACG;CACH,MAAM,OAAO,OAAO,SAAS,IAAI,CAAC;CAClC,IAAI;CACJ,gBAAgB;EACd,OAAO,KAAK,MAAM;CACpB,CAAC;CACD,sBAAsB,OAAO,CAAC;CAC9B,OAAO;AACT;;AAGA,SAAgB,QAAW,MAAuD;CAChF,MAAM,MAAuB,OAAO,IAAI;CACxC,OAAO;EACL,QAAQ,MAAM;GACZ,QAAQ,KAAK,IAAI;GACjB,OAAO;EACT;EACA,MAAM;GACJ,MAAM,OAAO,OAAO,KAAK,KAAA,CAAS;GAClC,IAAI,CAAC,MAAM,MAAM,IAAI,MAAM,KAAK,KAAK,wBAAwB,KAAK,OAAO;GACzE,OAAO;EACT;CACF;AACF;AAEA,SAAS,MAAM,OAA6B;CAC1C,MAAM,MAAiB,CAAC;CACxB,KAAK,MAAM,OAAO,OAAO;EACvB,MAAM,QAAQ,MAAM;EACpB,IAAI,OAAO,UAAU,YAAY;GAG/B,MAAM,OAAO,IAAI,MAAM,CAAC,CAAC,CAAC,YAAY;GACtC,MAAM,QAAQ,SAAS,UAAU,YAAY,SAAS,SAAS,aAAa;GAC5E,IAAI,KAAK,MAAM,EAAE,CAAE,YAAY,IAAI,MAAM,MAAM,CAAC,OAAO;EACzD,OACE,IAAI,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gB;IACd,MAAM,QAAQ;GAChB,CAAC;GACD,aACE,MAAM,SAAS,MAAM,QACjB,EAAE,UAAU,EAAE,IAAI,OAAO,GAAG,EAAE,OAAO,EAAE,sBAAsB,GAAG,GAAG,MAAM,UAAU,CAAC,CAAC,IACrF;EACR;CACF,CAAC;AACH;;AAGA,MAAa,YAAe,UAAa;CAAE;CAAM,SAAS,KAAA;AAAU"}
@@ -0,0 +1,119 @@
1
+ import { PropType } from "vue";
2
+ export declare const Select: {
3
+ Root: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
4
+ value: {
5
+ type: PropType<unknown>;
6
+ default: unknown;
7
+ };
8
+ defaultValue: {
9
+ type: PropType<unknown>;
10
+ default: unknown;
11
+ };
12
+ open: {
13
+ type: BooleanConstructor;
14
+ default: undefined;
15
+ };
16
+ defaultOpen: BooleanConstructor;
17
+ disabled: BooleanConstructor;
18
+ required: BooleanConstructor;
19
+ name: StringConstructor;
20
+ items: PropType<readonly {
21
+ value: unknown;
22
+ label: string;
23
+ }[]>;
24
+ id: StringConstructor;
25
+ }>, () => (import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
26
+ [key: string]: any;
27
+ }>[] | import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
28
+ [key: string]: any;
29
+ }> | null | undefined)[], {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("openChange" | "update:open" | "update:value" | "valueChange")[], "openChange" | "update:open" | "update:value" | "valueChange", import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
30
+ value: {
31
+ type: PropType<unknown>;
32
+ default: unknown;
33
+ };
34
+ defaultValue: {
35
+ type: PropType<unknown>;
36
+ default: unknown;
37
+ };
38
+ open: {
39
+ type: BooleanConstructor;
40
+ default: undefined;
41
+ };
42
+ defaultOpen: BooleanConstructor;
43
+ disabled: BooleanConstructor;
44
+ required: BooleanConstructor;
45
+ name: StringConstructor;
46
+ items: PropType<readonly {
47
+ value: unknown;
48
+ label: string;
49
+ }[]>;
50
+ id: StringConstructor;
51
+ }>> & Readonly<{
52
+ onOpenChange?: ((...args: any[]) => any) | undefined;
53
+ "onUpdate:open"?: ((...args: any[]) => any) | undefined;
54
+ "onUpdate:value"?: ((...args: any[]) => any) | undefined;
55
+ onValueChange?: ((...args: any[]) => any) | undefined;
56
+ }>, {
57
+ value: unknown;
58
+ defaultValue: unknown;
59
+ open: boolean;
60
+ defaultOpen: boolean;
61
+ disabled: boolean;
62
+ required: boolean;
63
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
64
+ Trigger: import("vue").Component;
65
+ Value: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
66
+ placeholder: {
67
+ type: StringConstructor;
68
+ default: string;
69
+ };
70
+ }>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
71
+ [key: string]: any;
72
+ }>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
73
+ placeholder: {
74
+ type: StringConstructor;
75
+ default: string;
76
+ };
77
+ }>> & Readonly<{}>, {
78
+ placeholder: string;
79
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
80
+ Portal: import("vue").Component;
81
+ Positioner: import("vue").Component;
82
+ Popup: import("vue").Component;
83
+ Item: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
84
+ value: {
85
+ type: PropType<unknown>;
86
+ required: true;
87
+ };
88
+ disabled: {
89
+ type: BooleanConstructor;
90
+ default: undefined;
91
+ };
92
+ label: StringConstructor;
93
+ }>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
94
+ [key: string]: any;
95
+ }>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
96
+ value: {
97
+ type: PropType<unknown>;
98
+ required: true;
99
+ };
100
+ disabled: {
101
+ type: BooleanConstructor;
102
+ default: undefined;
103
+ };
104
+ label: StringConstructor;
105
+ }>> & Readonly<{}>, {
106
+ disabled: boolean;
107
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
108
+ ItemText: import("vue").Component;
109
+ ItemIndicator: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
110
+ keepMounted: BooleanConstructor;
111
+ }>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
112
+ [key: string]: any;
113
+ }> | null, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
114
+ keepMounted: BooleanConstructor;
115
+ }>> & Readonly<{}>, {
116
+ keepMounted: boolean;
117
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
118
+ };
119
+ //# sourceMappingURL=select.d.ts.map
package/src/select.js ADDED
@@ -0,0 +1,127 @@
1
+ import { positionerComponent } from "./popover.js";
2
+ import { useFieldAround } from "./field-context.js";
3
+ import { context, controller, fromSignal, optional, partComponent, portalComponent, toSignal } from "./runtime.js";
4
+ import { defined, within } from "@kirana-ui/core";
5
+ import { defineComponent, h, inject, provide, useId } from "vue";
6
+ import { createSelect } from "@kirana-ui/core/select";
7
+ // src/select.ts
8
+ const scope = context("Select");
9
+ const ITEM = Symbol("SelectItem");
10
+ const HiddenInput = partComponent("SelectHiddenInput", "input", () => scope.use().input);
11
+ /** `v-model:value`, `v-model:open`; `@value-change` and `@open-change` carry the details. */
12
+ const Root = defineComponent({
13
+ name: "SelectRoot",
14
+ props: {
15
+ value: {
16
+ type: null,
17
+ default: void 0
18
+ },
19
+ defaultValue: {
20
+ type: null,
21
+ default: null
22
+ },
23
+ open: optional(Boolean),
24
+ defaultOpen: Boolean,
25
+ disabled: Boolean,
26
+ required: Boolean,
27
+ name: String,
28
+ items: Array,
29
+ id: String
30
+ },
31
+ emits: [
32
+ "update:value",
33
+ "valueChange",
34
+ "update:open",
35
+ "openChange"
36
+ ],
37
+ setup(props, { slots, emit }) {
38
+ const generated = useId();
39
+ const field = useFieldAround();
40
+ const made = scope.provide(controller(within(createSelect, { field }), () => ({
41
+ id: props.id ?? generated,
42
+ value: props.value,
43
+ defaultValue: props.defaultValue,
44
+ open: props.open,
45
+ defaultOpen: props.defaultOpen,
46
+ disabled: props.disabled,
47
+ required: props.required,
48
+ name: props.name,
49
+ items: props.items,
50
+ onValueChange(value, details) {
51
+ emit("valueChange", value, details);
52
+ if (!details.canceled) emit("update:value", value);
53
+ },
54
+ onOpenChange(open, details) {
55
+ emit("openChange", open, details);
56
+ if (!details.canceled) emit("update:open", open);
57
+ }
58
+ })));
59
+ const named = fromSignal(made.named);
60
+ return () => [slots.default?.(), named.value ? h(HiddenInput) : null];
61
+ }
62
+ });
63
+ const ValueElement = partComponent("SelectValueElement", "span", () => scope.use().valuePart);
64
+ /** Shows the chosen value's label, or `placeholder` while nothing is chosen. */
65
+ const Value = defineComponent({
66
+ name: "SelectValue",
67
+ inheritAttrs: false,
68
+ props: { placeholder: {
69
+ type: String,
70
+ default: ""
71
+ } },
72
+ setup(props, { attrs, slots }) {
73
+ const label = fromSignal(scope.use().label);
74
+ return () => h(ValueElement, attrs, slots.default ?? (() => label.value ?? props.placeholder));
75
+ }
76
+ });
77
+ /** `label` is what typeahead matches and the trigger shows; the item's text when left out. */
78
+ const Item = defineComponent({
79
+ name: "SelectItem",
80
+ inheritAttrs: false,
81
+ props: {
82
+ value: {
83
+ type: null,
84
+ required: true
85
+ },
86
+ disabled: optional(Boolean),
87
+ label: String
88
+ },
89
+ setup(props, { attrs, slots }) {
90
+ const value = props.value;
91
+ const options = toSignal(() => ({
92
+ disabled: props.disabled,
93
+ label: props.label
94
+ }));
95
+ const part = scope.use().item(value, () => defined(options.get()));
96
+ provide(ITEM, value);
97
+ const Element = partComponent("SelectItemElement", "div", () => part);
98
+ return () => h(Element, attrs, slots);
99
+ }
100
+ });
101
+ const ItemText = partComponent("SelectItemText", "span", () => scope.use().itemText(inject(ITEM)));
102
+ const ItemIndicator = defineComponent({
103
+ name: "SelectItemIndicator",
104
+ inheritAttrs: false,
105
+ props: { keepMounted: Boolean },
106
+ setup(props, { attrs, slots }) {
107
+ const value = inject(ITEM);
108
+ const made = scope.use();
109
+ const selected = fromSignal(made.selected(value));
110
+ const Element = partComponent("SelectItemIndicatorElement", "span", () => made.itemIndicator(value));
111
+ return () => selected.value || props.keepMounted ? h(Element, attrs, slots) : null;
112
+ }
113
+ });
114
+ const Select = {
115
+ Root,
116
+ Trigger: partComponent("SelectTrigger", "button", () => scope.use().trigger),
117
+ Value,
118
+ Portal: portalComponent("SelectPortal", () => scope.use().mounted),
119
+ Positioner: positionerComponent("SelectPositioner", () => scope.use(), partComponent("SelectPositionerElement", "div", () => scope.use().positioner)),
120
+ Popup: partComponent("SelectPopup", "div", () => scope.use().popup),
121
+ Item,
122
+ ItemText,
123
+ ItemIndicator
124
+ };
125
+ export { Select };
126
+
127
+ //# sourceMappingURL=select.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"select.js","names":[],"sources":["../../../../packages/vue/src/select.ts"],"sourcesContent":["import { defined, within } from \"@kirana-ui/core\"\nimport type { ChangeDetails } from \"@kirana-ui/core\"\nimport { createSelect } from \"@kirana-ui/core/select\"\nimport type { Select as Controller } from \"@kirana-ui/core/select\"\nimport { defineComponent, h, inject, provide, useId } from \"vue\"\nimport type { InjectionKey, PropType } from \"vue\"\n\nimport { positionerComponent } from \"./popover.ts\"\nimport { useFieldAround } from \"./field-context.ts\"\nimport {\n context,\n controller,\n fromSignal,\n optional,\n partComponent,\n portalComponent,\n toSignal,\n} from \"./runtime.ts\"\n\nconst scope = context<Controller>(\"Select\")\nconst ITEM: InjectionKey<unknown> = Symbol(\"SelectItem\")\n\nconst HiddenInput = partComponent(\"SelectHiddenInput\", \"input\", () => scope.use().input)\n\n/** `v-model:value`, `v-model:open`; `@value-change` and `@open-change` carry the details. */\nconst Root = defineComponent({\n name: \"SelectRoot\",\n props: {\n value: { type: null as unknown as PropType<unknown>, default: undefined as unknown },\n defaultValue: { type: null as unknown as PropType<unknown>, default: null as unknown },\n open: optional(Boolean),\n defaultOpen: Boolean,\n disabled: Boolean,\n required: Boolean,\n name: String,\n items: Array as PropType<readonly { value: unknown; label: string }[]>,\n id: String,\n },\n emits: [\"update:value\", \"valueChange\", \"update:open\", \"openChange\"],\n setup(props, { slots, emit }) {\n const generated = useId()\n const field = useFieldAround()\n const made = scope.provide(\n controller(within(createSelect, { field }), () => ({\n id: props.id ?? generated,\n value: props.value,\n defaultValue: props.defaultValue,\n open: props.open,\n defaultOpen: props.defaultOpen,\n disabled: props.disabled,\n required: props.required,\n name: props.name,\n items: props.items,\n onValueChange(value: unknown, details: ChangeDetails) {\n emit(\"valueChange\", value, details)\n if (!details.canceled) emit(\"update:value\", value)\n },\n onOpenChange(open: boolean, details: ChangeDetails) {\n emit(\"openChange\", open, details)\n if (!details.canceled) emit(\"update:open\", open)\n },\n }))\n )\n const named = fromSignal(made.named)\n return () => [slots.default?.(), named.value ? h(HiddenInput) : null]\n },\n})\n\nconst ValueElement = partComponent(\"SelectValueElement\", \"span\", () => scope.use().valuePart)\n\n/** Shows the chosen value's label, or `placeholder` while nothing is chosen. */\nconst Value = defineComponent({\n name: \"SelectValue\",\n inheritAttrs: false,\n props: { placeholder: { type: String, default: \"\" } },\n setup(props, { attrs, slots }) {\n const label = fromSignal(scope.use().label)\n return () => h(ValueElement, attrs, slots.default ?? (() => label.value ?? props.placeholder))\n },\n})\n\n/** `label` is what typeahead matches and the trigger shows; the item's text when left out. */\nconst Item = defineComponent({\n name: \"SelectItem\",\n inheritAttrs: false,\n props: {\n value: { type: null as unknown as PropType<unknown>, required: true },\n disabled: optional(Boolean),\n label: String,\n },\n setup(props, { attrs, slots }) {\n // An item is its value for as long as it is in the page.\n const value = props.value\n const options = toSignal(() => ({ disabled: props.disabled, label: props.label }))\n const part = scope.use().item(value, () => defined(options.get()))\n provide(ITEM, value)\n const Element = partComponent(\"SelectItemElement\", \"div\", () => part)\n return () => h(Element, attrs, slots)\n },\n})\n\nconst ItemText = partComponent(\"SelectItemText\", \"span\", () => scope.use().itemText(inject(ITEM)))\n\nconst ItemIndicator = defineComponent({\n name: \"SelectItemIndicator\",\n inheritAttrs: false,\n props: { keepMounted: Boolean },\n setup(props, { attrs, slots }) {\n const value = inject(ITEM)\n const made = scope.use()\n const selected = fromSignal(made.selected(value))\n const Element = partComponent(\"SelectItemIndicatorElement\", \"span\", () =>\n made.itemIndicator(value)\n )\n return () => (selected.value || props.keepMounted ? h(Element, attrs, slots) : null)\n },\n})\n\nexport const Select = {\n Root,\n Trigger: partComponent(\"SelectTrigger\", \"button\", () => scope.use().trigger),\n Value,\n Portal: portalComponent(\"SelectPortal\", () => scope.use().mounted),\n Positioner: positionerComponent(\n \"SelectPositioner\",\n () => scope.use(),\n partComponent(\"SelectPositionerElement\", \"div\", () => scope.use().positioner)\n ),\n Popup: partComponent(\"SelectPopup\", \"div\", () => scope.use().popup),\n Item,\n ItemText,\n ItemIndicator,\n}\n"],"mappings":";;;;;;;AAmBA,MAAM,QAAQ,QAAoB,QAAQ;AAC1C,MAAM,OAA8B,OAAO,YAAY;AAEvD,MAAM,cAAc,cAAc,qBAAqB,eAAe,MAAM,IAAI,CAAC,CAAC,KAAK;;AAGvF,MAAM,OAAO,gBAAgB;CAC3B,MAAM;CACN,OAAO;EACL,OAAO;GAAE,MAAM;GAAsC,SAAS,KAAA;EAAqB;EACnF,cAAc;GAAE,MAAM;GAAsC,SAAS;EAAgB;EACrF,MAAM,SAAS,OAAO;EACtB,aAAa;EACb,UAAU;EACV,UAAU;EACV,MAAM;EACN,OAAO;EACP,IAAI;CACN;CACA,OAAO;EAAC;EAAgB;EAAe;EAAe;CAAY;CAClE,MAAM,OAAO,EAAE,OAAO,QAAQ;EAC5B,MAAM,YAAY,MAAM;EACxB,MAAM,QAAQ,eAAe;EAC7B,MAAM,OAAO,MAAM,Q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AAM,OAAO,MAAM,IAAI,CAAC,CAAC,KAAK,aAAa,QAAQ,QAAQ,IAAI,CAAC,CAAC;EACjE,QAAQ,MAAM,KAAK;EACnB,MAAM,UAAU,cAAc,qBAAqB,aAAa,IAAI;EACpE,aAAa,EAAE,SAAS,OAAO,KAAK;CACtC;AACF,CAAC;AAED,MAAM,WAAW,cAAc,kBAAkB,cAAc,MAAM,IAAI,CAAC,CAAC,SAAS,OAAO,IAAI,CAAC,CAAC;AAEjG,MAAM,gBAAgB,gBAAgB;CACpC,MAAM;CACN,cAAc;CACd,OAAO,EAAE,aAAa,QAAQ;CAC9B,MAAM,OAAO,EAAE,OAAO,SAAS;EAC7B,MAAM,QAAQ,OAAO,IAAI;EACzB,MAAM,OAAO,MAAM,IAAI;EACvB,MAAM,WAAW,WAAW,KAAK,SAAS,KAAK,CAAC;EAChD,MAAM,UAAU,cAAc,8BAA8B,cAC1D,KAAK,cAAc,KAAK,CAC1B;EACA,aAAc,SAAS,SAAS,MAAM,cAAc,EAAE,SAAS,OAAO,KAAK,IAAI;CACjF;AACF,CAAC;AAED,MAAa,SAAS;CACpB;CACA,SAAS,cAAc,iBAAiB,gBAAgB,MAAM,IAAI,CAAC,CAAC,OAAO;CAC3E;CACA,QAAQ,gBAAgB,sBAAsB,MAAM,IAAI,CAAC,CAAC,OAAO;CACjE,YAAY,oBACV,0BACM,MAAM,IAAI,GAChB,cAAc,2BAA2B,aAAa,MAAM,IAAI,CAAC,CAAC,UAAU,CAC9E;CACA,OAAO,cAAc,eAAe,aAAa,MAAM,IAAI,CAAC,CAAC,KAAK;CAClE;CACA;CACA;AACF"}
@@ -0,0 +1,10 @@
1
+ import { Orientation } from "@kirana-ui/core";
2
+ import { PropType } from "vue";
3
+ export declare const Separator: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
4
+ orientation: PropType<Orientation>;
5
+ }>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
6
+ [key: string]: any;
7
+ }>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
8
+ orientation: PropType<Orientation>;
9
+ }>> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
10
+ //# sourceMappingURL=separator.d.ts.map
@@ -0,0 +1,17 @@
1
+ import { controller, partComponent } from "./runtime.js";
2
+ import { defineComponent, h } from "vue";
3
+ import { createSeparator } from "@kirana-ui/core/separator";
4
+ // src/separator.ts
5
+ const Separator = defineComponent({
6
+ name: "Separator",
7
+ inheritAttrs: false,
8
+ props: { orientation: String },
9
+ setup(props, { attrs, slots }) {
10
+ const made = controller(createSeparator, () => ({ orientation: props.orientation }));
11
+ const Element = partComponent("SeparatorElement", "div", () => made.root);
12
+ return () => h(Element, attrs, slots);
13
+ }
14
+ });
15
+ export { Separator };
16
+
17
+ //# sourceMappingURL=separator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"separator.js","names":[],"sources":["../../../../packages/vue/src/separator.ts"],"sourcesContent":["import type { Orientation } from \"@kirana-ui/core\"\nimport { createSeparator } from \"@kirana-ui/core/separator\"\nimport { defineComponent, h } from \"vue\"\nimport type { PropType } from \"vue\"\n\nimport { controller, partComponent } from \"./runtime.ts\"\n\nexport const Separator = defineComponent({\n name: \"Separator\",\n inheritAttrs: false,\n props: { orientation: String as PropType<Orientation> },\n setup(props, { attrs, slots }) {\n const made = controller(createSeparator, () => ({ orientation: props.orientation }))\n const Element = partComponent(\"SeparatorElement\", \"div\", () => made.root)\n return () => h(Element, attrs, slots)\n },\n})\n"],"mappings":";;;;AAOA,MAAa,YAAY,gBAAgB;CACvC,MAAM;CACN,cAAc;CACd,OAAO,EAAE,aAAa,OAAgC;CACtD,MAAM,OAAO,EAAE,OAAO,SAAS;EAC7B,MAAM,OAAO,WAAW,wBAAwB,EAAE,aAAa,MAAM,YAAY,EAAE;EACnF,MAAM,UAAU,cAAc,oBAAoB,aAAa,KAAK,IAAI;EACxE,aAAa,EAAE,SAAS,OAAO,KAAK;CACtC;AACF,CAAC"}
@@ -0,0 +1,79 @@
1
+ import { PropType } from "vue";
2
+ import { SliderProps, SliderValue } from "@kirana-ui/core/slider";
3
+ export declare const Slider: {
4
+ Root: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
5
+ value: {
6
+ type: PropType<SliderValue>;
7
+ default: undefined;
8
+ };
9
+ defaultValue: {
10
+ type: PropType<SliderValue>;
11
+ default: undefined;
12
+ };
13
+ min: NumberConstructor;
14
+ max: NumberConstructor;
15
+ step: NumberConstructor;
16
+ largeStep: NumberConstructor;
17
+ minStepsBetweenValues: NumberConstructor;
18
+ orientation: PropType<"horizontal" | "vertical">;
19
+ disabled: BooleanConstructor;
20
+ name: StringConstructor;
21
+ format: PropType<Intl.NumberFormatOptions>;
22
+ locale: StringConstructor;
23
+ getAriaValueText: PropType<SliderProps["getAriaValueText"]>;
24
+ id: StringConstructor;
25
+ }>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
26
+ [key: string]: any;
27
+ }>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("update:value" | "valueChange" | "valueCommitted")[], "update:value" | "valueChange" | "valueCommitted", import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
28
+ value: {
29
+ type: PropType<SliderValue>;
30
+ default: undefined;
31
+ };
32
+ defaultValue: {
33
+ type: PropType<SliderValue>;
34
+ default: undefined;
35
+ };
36
+ min: NumberConstructor;
37
+ max: NumberConstructor;
38
+ step: NumberConstructor;
39
+ largeStep: NumberConstructor;
40
+ minStepsBetweenValues: NumberConstructor;
41
+ orientation: PropType<"horizontal" | "vertical">;
42
+ disabled: BooleanConstructor;
43
+ name: StringConstructor;
44
+ format: PropType<Intl.NumberFormatOptions>;
45
+ locale: StringConstructor;
46
+ getAriaValueText: PropType<SliderProps["getAriaValueText"]>;
47
+ id: StringConstructor;
48
+ }>> & Readonly<{
49
+ "onUpdate:value"?: ((...args: any[]) => any) | undefined;
50
+ onValueChange?: ((...args: any[]) => any) | undefined;
51
+ onValueCommitted?: ((...args: any[]) => any) | undefined;
52
+ }>, {
53
+ value: SliderValue;
54
+ defaultValue: SliderValue;
55
+ disabled: boolean;
56
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
57
+ Value: import("vue").DefineComponent<{}, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
58
+ [key: string]: any;
59
+ }>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
60
+ Control: import("vue").Component;
61
+ Track: import("vue").Component;
62
+ Indicator: import("vue").Component;
63
+ Thumb: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
64
+ index: {
65
+ type: NumberConstructor;
66
+ default: number;
67
+ };
68
+ }>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
69
+ [key: string]: any;
70
+ }>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
71
+ index: {
72
+ type: NumberConstructor;
73
+ default: number;
74
+ };
75
+ }>> & Readonly<{}>, {
76
+ index: number;
77
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
78
+ };
79
+ //# sourceMappingURL=slider.d.ts.map
package/src/slider.js ADDED
@@ -0,0 +1,92 @@
1
+ import { useDirectionAround } from "./direction-context.js";
2
+ import { useFieldAround } from "./field-context.js";
3
+ import { context, controller, fromSignal, optional, partComponent } from "./runtime.js";
4
+ import { within } from "@kirana-ui/core";
5
+ import { defineComponent, h, useId } from "vue";
6
+ import { createSlider } from "@kirana-ui/core/slider";
7
+ // src/slider.ts
8
+ const scope = context("Slider");
9
+ const RootElement = partComponent("SliderRootElement", "div", () => scope.use().root);
10
+ /** `v-model:value`, or `value` with `@value-change="(value, details) => …"`. */
11
+ const Root = defineComponent({
12
+ name: "SliderRoot",
13
+ inheritAttrs: false,
14
+ props: {
15
+ value: optional([Number, Array]),
16
+ defaultValue: optional([Number, Array]),
17
+ min: Number,
18
+ max: Number,
19
+ step: Number,
20
+ largeStep: Number,
21
+ minStepsBetweenValues: Number,
22
+ orientation: String,
23
+ disabled: Boolean,
24
+ name: String,
25
+ format: Object,
26
+ locale: String,
27
+ getAriaValueText: Function,
28
+ id: String
29
+ },
30
+ emits: [
31
+ "update:value",
32
+ "valueChange",
33
+ "valueCommitted"
34
+ ],
35
+ setup(props, { attrs, slots, emit }) {
36
+ const generated = useId();
37
+ const field = useFieldAround();
38
+ scope.provide(controller(within(createSlider, {
39
+ field,
40
+ direction: useDirectionAround()
41
+ }), () => ({
42
+ ...props,
43
+ id: props.id ?? generated,
44
+ onValueChange(value, details) {
45
+ emit("valueChange", value, details);
46
+ if (!details.canceled) emit("update:value", value);
47
+ },
48
+ onValueCommitted: (value, details) => emit("valueCommitted", value, details)
49
+ })));
50
+ return () => h(RootElement, attrs, slots);
51
+ }
52
+ });
53
+ /** `index` is which value of a range the thumb is, from 0. */
54
+ const Thumb = defineComponent({
55
+ name: "SliderThumb",
56
+ inheritAttrs: false,
57
+ props: { index: {
58
+ type: Number,
59
+ default: 0
60
+ } },
61
+ setup(props, { attrs, slots }) {
62
+ const slider = scope.use();
63
+ const index = props.index;
64
+ const Element = partComponent("SliderThumbElement", "div", () => slider.thumb(index));
65
+ const Input = partComponent("SliderThumbInput", "input", () => slider.thumbInput(index));
66
+ return () => h(Element, attrs, () => [slots.default?.(), h(Input)]);
67
+ }
68
+ });
69
+ const ValueElement = partComponent("SliderValueElement", "output", () => scope.use().value);
70
+ const Slider = {
71
+ Root,
72
+ Value: defineComponent({
73
+ name: "SliderValue",
74
+ inheritAttrs: false,
75
+ setup(_props, { attrs, slots }) {
76
+ const slider = scope.use();
77
+ const text = fromSignal(slider.text);
78
+ const values = fromSignal(slider.values);
79
+ return () => h(ValueElement, attrs, () => slots.default?.({
80
+ text: text.value,
81
+ values: values.value
82
+ }) ?? text.value);
83
+ }
84
+ }),
85
+ Control: partComponent("SliderControl", "div", () => scope.use().control),
86
+ Track: partComponent("SliderTrack", "div", () => scope.use().track),
87
+ Indicator: partComponent("SliderIndicator", "div", () => scope.use().indicator),
88
+ Thumb
89
+ };
90
+ export { Slider };
91
+
92
+ //# sourceMappingURL=slider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slider.js","names":[],"sources":["../../../../packages/vue/src/slider.ts"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type { ChangeDetails } from \"@kirana-ui/core\"\nimport { createSlider } from \"@kirana-ui/core/slider\"\nimport type { Slider as Controller, SliderProps, SliderValue } from \"@kirana-ui/core/slider\"\nimport { defineComponent, h, useId } from \"vue\"\nimport type { PropType } from \"vue\"\n\nimport { useDirectionAround } from \"./direction-context.ts\"\nimport { useFieldAround } from \"./field-context.ts\"\nimport { context, controller, fromSignal, optional, partComponent } from \"./runtime.ts\"\n\nconst scope = context<Controller>(\"Slider\")\n\nconst RootElement = partComponent(\"SliderRootElement\", \"div\", () => scope.use().root)\n\n/** `v-model:value`, or `value` with `@value-change=\"(value, details) => …\"`. */\nconst Root = defineComponent({\n name: \"SliderRoot\",\n inheritAttrs: false,\n props: {\n value: optional([Number, Array] as PropType<SliderValue>),\n defaultValue: optional([Number, Array] as PropType<SliderValue>),\n min: Number,\n max: Number,\n step: Number,\n largeStep: Number,\n minStepsBetweenValues: Number,\n orientation: String as PropType<\"horizontal\" | \"vertical\">,\n disabled: Boolean,\n name: String,\n format: Object as PropType<Intl.NumberFormatOptions>,\n locale: String,\n getAriaValueText: Function as PropType<SliderProps[\"getAriaValueText\"]>,\n id: String,\n },\n emits: [\"update:value\", \"valueChange\", \"valueCommitted\"],\n setup(props, { attrs, slots, emit }) {\n const generated = useId()\n const field = useFieldAround()\n scope.provide(\n controller(within(createSlider, { field, direction: useDirectionAround() }), () => ({\n ...props,\n id: props.id ?? generated,\n onValueChange(value: number | number[], details: ChangeDetails) {\n emit(\"valueChange\", value, details)\n if (!details.canceled) emit(\"update:value\", value)\n },\n onValueCommitted: (value: number | number[], details: ChangeDetails) =>\n emit(\"valueCommitted\", value, details),\n }))\n )\n return () => h(RootElement, attrs, slots)\n },\n})\n\n/** `index` is which value of a range the thumb is, from 0. */\nconst Thumb = defineComponent({\n name: \"SliderThumb\",\n inheritAttrs: false,\n props: { index: { type: Number, default: 0 } },\n setup(props, { attrs, slots }) {\n const slider = scope.use()\n // A thumb is its index for as long as it is in the page.\n const index = props.index\n const Element = partComponent(\"SliderThumbElement\", \"div\", () => slider.thumb(index))\n const Input = partComponent(\"SliderThumbInput\", \"input\", () => slider.thumbInput(index))\n return () => h(Element, attrs, () => [slots.default?.(), h(Input)])\n },\n})\n\nconst ValueElement = partComponent(\"SliderValueElement\", \"output\", () => scope.use().value)\n\n/** The written value, or what its slot makes of it (`v-slot=\"{ text, values }\"`). */\nconst Value = defineComponent({\n name: \"SliderValue\",\n inheritAttrs: false,\n setup(_props, { attrs, slots }) {\n const slider = scope.use()\n const text = fromSignal(slider.text)\n const values = fromSignal(slider.values)\n return () =>\n h(\n ValueElement,\n attrs,\n () => slots.default?.({ text: text.value, values: values.value }) ?? text.value\n )\n },\n})\n\nexport const Slider = {\n Root,\n Value,\n Control: partComponent(\"SliderControl\", \"div\", () => scope.use().control),\n Track: partComponent(\"SliderTrack\", \"div\", () => scope.use().track),\n Indicator: partComponent(\"SliderIndicator\", \"div\", () => scope.use().indicator),\n Thumb,\n}\n"],"mappings":";;;;;;;AAWA,MAAM,QAAQ,QAAoB,QAAQ;AAE1C,MAAM,cAAc,cAAc,qBAAqB,aAAa,MAAM,IAAI,CAAC,CAAC,IAAI;;AAGpF,MAAM,OAAO,gBAAgB;CAC3B,MAAM;CACN,cAAc;CACd,OAAO;EACL,OAAO,SAAS,CAAC,QAAQ,KAAK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