@ckui/core 0.0.0-stage → 0.1.0-next.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Christoph Kugler
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,134 @@
1
- # Temporary Holding Version
1
+ # @ckui/core
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Accessible, themeable Angular components that work equally well on phone and desktop.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @ckui/core@next @angular/cdk
9
+ ```
10
+
11
+ 0.1 is in prerelease (`next`). Pin an exact version (`npm install --save-exact @ckui/core@next`),
12
+ because prereleases can change between builds.
13
+
14
+ Peer dependencies: `@angular/common`, `@angular/core`, `@angular/forms` and `@angular/cdk`, all
15
+ `^22.2.0`.
16
+
17
+ ## Styles
18
+
19
+ Import the stylesheet once, for example in `angular.json`:
20
+
21
+ ```json
22
+ "styles": ["node_modules/@ckui/core/styles/styles.css"]
23
+ ```
24
+
25
+ or in your global CSS: `@import '@ckui/core/styles.css';`
26
+
27
+ It only declares `--ck-*` custom properties and `.ck-*` classes, all inside `@layer ckui`, and
28
+ styles no element. Add the class `ck-root` to `<html>` to apply the font, text colour, background
29
+ and `color-scheme` (on `<body>`, `color-scheme` would not reach the viewport and scrollbars).
30
+
31
+ The light theme is the default and the dark theme follows `prefers-color-scheme`. Force a theme for
32
+ the whole page or any subtree with `data-ck-theme="light"` or `data-ck-theme="dark"`. Themes nest.
33
+ A nested theme switches only the tokens and `color-scheme`; to repaint the section, give it
34
+ `ck-root` as well (or your own `color` and `background` from the tokens).
35
+
36
+ A whole app look (colours, radii, font, focus ring) is one block of tokens in your own stylesheet, outside any layer, so it beats the library without `!important`. A theme with low-contrast lines must keep control and field boundaries at 3:1 itself (WCAG 1.4.11). The docs site has a copyable near-black example under Theming, Custom theme. Controls also read `--ck-color-control` and `--ck-color-control-border` (the secondary button) and `--ck-font-variant-numeric` (tabular numerals by default).
37
+
38
+ ## Configuration
39
+
40
+ ```ts
41
+ import { provideCkui } from '@ckui/core';
42
+
43
+ bootstrapApplication(App, {
44
+ providers: [
45
+ provideCkui({
46
+ size: 'md', // 'sm' | 'md' | 'lg' | 'xl', default 'md'
47
+ sheetBreakpoint: 640, // px; coarse pointer below this width uses sheets
48
+ labels: { close: 'Schließen' }, // or a Signal / () => Signal<Partial<CkLabels>>
49
+ }),
50
+ ],
51
+ });
52
+ ```
53
+
54
+ Built-in strings are a signal that resolves to the English defaults plus your overrides. Blank
55
+ values fall back to the default. To override them for one part of the app, provide `CK_LABELS`
56
+ yourself, as a `Signal<CkLabels>`, on that subtree's injector.
57
+
58
+ ## Button
59
+
60
+ ```ts
61
+ import { CkButton } from '@ckui/core/button';
62
+ ```
63
+
64
+ ```html
65
+ <button ckButton variant="primary">Save</button>
66
+ <button ckButton variant="ghost" [loading]="saving()">Send</button>
67
+ <button ckButton iconOnly aria-label="Close"><svg>...</svg></button>
68
+ <a ckButton routerLink="/settings">Settings</a>
69
+ ```
70
+
71
+ `ckButton` styles a native `<button>` or `<a>`; there is no `<ck-button>` element, so `type`, `form`,
72
+ `aria-*` and `routerLink` stay on the real element. Inputs: `variant` (`'primary' | 'secondary' |
73
+ 'ghost' | 'danger'`, default `secondary`), `size` (default from `provideCkui`), `iconOnly`,
74
+ `loading` and `disabled`. A button without a `type` gets `type="button"`. A loading button stays
75
+ focusable, ignores clicks and announces the `loading` label once; a disabled link gets
76
+ `aria-disabled` and leaves the tab order. An icon-only button needs an accessible name (development
77
+ builds warn). Component token: `--ck-button-radius`.
78
+
79
+ Global element styles: your own unlayered rules such as `a { color: … }` or
80
+ `a:hover { text-decoration: … }` beat the layered button, by design. Scope them with
81
+ `a:not(.ck-button)`, or put resets in a layer declared before ckui: `@layer reset, ckui;`.
82
+
83
+ ## Field and input
84
+
85
+ ```ts
86
+ import { CK_FIELD_IMPORTS } from '@ckui/core/field';
87
+ ```
88
+
89
+ ```html
90
+ <ck-field>
91
+ <label>Email</label>
92
+ <span ckPrefix>@</span>
93
+ <input ckInput type="email" autocomplete="email" formControlName="email" />
94
+ <button ckButton ckSuffix variant="ghost" iconOnly size="sm" aria-label="Clear">...</button>
95
+ <ck-hint>We only use it to send the receipt.</ck-hint>
96
+ <ck-error>Enter a valid email.</ck-error>
97
+ </ck-field>
98
+ ```
99
+
100
+ `ck-field` wraps one native `<input>` or `<textarea>` marked with `ckInput` and draws the box, a
101
+ floating `<label>`, a hint, an error and prefix and suffix content. It works with Reactive Forms,
102
+ `ngModel` and Signal Forms (`[formField]`); there is no value accessor, the control stays native, so
103
+ `type`, `inputmode`, `enterkeyhint`, `autocomplete` and every other attribute stay on it. Inputs of
104
+ `ck-field`: `size` (default from `provideCkui`), `labelFloat` (`'auto' | 'always'`) and `invalid`
105
+ (`undefined` follows the control, `true` or `false` forces the state). Inputs of `textarea[ckInput]`:
106
+ `autosize`, `minRows` and `maxRows`. `ckInput` without a field draws its own box and takes a `size`.
107
+
108
+ The field links `<label for>` and the control `id`, merges the hint and error ids into
109
+ `aria-describedby` (your own tokens stay), sets `aria-invalid` while errors show and `aria-required`
110
+ for a required control, and puts the errors in one polite live region. A `<ck-error>` stays hidden
111
+ until the control is invalid and touched, or its form was submitted. The label floats while the
112
+ control is focused, has a value, a placeholder or an autofilled value, is a native date or time
113
+ control, or the field has a prefix. Under a coarse pointer the control is 44px high and its text is
114
+ at least 16px. Component tokens: `--ck-field-radius`, `--ck-field-bg`, `--ck-field-border-color`.
115
+
116
+ Linting: angular-eslint's `label-has-associated-control` flags `<ck-field><label>…</label><input ckInput>`
117
+ because the link is made at runtime. Either write `for` and `id` yourself (the field keeps both) or turn
118
+ the rule off for templates that use `ck-field`.
119
+
120
+ Global element styles: your own unlayered rules such as `input { font: … }` beat the layered field,
121
+ by design. Put resets in a layer declared before ckui: `@layer reset, ckui;`.
122
+
123
+ ## Status
124
+
125
+ Pre-release. Version 0.1 is in progress and the API is not stable yet.
126
+
127
+ ## Links
128
+
129
+ - Documentation: https://christophk93.github.io/ckui/
130
+ - Source and issues: https://github.com/ChristophK93/ckui
131
+
132
+ ## Licence
133
+
134
+ MIT
@@ -0,0 +1,233 @@
1
+ import { isPlatformBrowser } from "@angular/common";
2
+ import * as i0 from "@angular/core";
3
+ import { ChangeDetectionStrategy, Component, DestroyRef, ElementRef, PLATFORM_ID, Renderer2, ViewEncapsulation, afterNextRender, booleanAttribute, computed, effect, inject, input, untracked } from "@angular/core";
4
+ import { CK_CONFIG, CK_LABELS } from "@ckui/core";
5
+ import { CkAnnouncer } from "@ckui/core/internal";
6
+ var CkButton = class CkButton {
7
+ variant = input("secondary", ...ngDevMode ? [{ debugName: "variant" }] : /* istanbul ignore next */ []);
8
+ size = input(void 0, ...ngDevMode ? [{ debugName: "size" }] : /* istanbul ignore next */ []);
9
+ iconOnly = input(false, {
10
+ ...ngDevMode ? { debugName: "iconOnly" } : /* istanbul ignore next */ {},
11
+ transform: booleanAttribute
12
+ });
13
+ loading = input(false, {
14
+ ...ngDevMode ? { debugName: "loading" } : /* istanbul ignore next */ {},
15
+ transform: booleanAttribute
16
+ });
17
+ disabled = input(false, {
18
+ ...ngDevMode ? { debugName: "disabled" } : /* istanbul ignore next */ {},
19
+ transform: booleanAttribute
20
+ });
21
+ element = inject(ElementRef).nativeElement;
22
+ renderer = inject(Renderer2);
23
+ config = inject(CK_CONFIG);
24
+ labels = inject(CK_LABELS);
25
+ announcer = inject(CkAnnouncer);
26
+ isBrowser = isPlatformBrowser(inject(PLATFORM_ID));
27
+ isNativeButton = this.element.tagName === "BUTTON";
28
+ modifierClasses = computed(() => `ck-button--${this.variant()} ck-button--${this.size() ?? this.config.size}`, ...ngDevMode ? [{ debugName: "modifierClasses" }] : /* istanbul ignore next */ []);
29
+ overridden = /* @__PURE__ */ new Map();
30
+ previousLoading;
31
+ constructor() {
32
+ const destroyRef = inject(DestroyRef);
33
+ if (this.isNativeButton && !this.element.hasAttribute("type")) this.renderer.setAttribute(this.element, "type", "button");
34
+ const blockClick = (event) => {
35
+ if (this.loading() || this.disabled()) {
36
+ event.preventDefault();
37
+ event.stopImmediatePropagation();
38
+ }
39
+ };
40
+ for (const type of ["click", "auxclick"]) {
41
+ this.element.addEventListener(type, blockClick, { capture: true });
42
+ destroyRef.onDestroy(() => this.element.removeEventListener(type, blockClick, { capture: true }));
43
+ }
44
+ effect(() => {
45
+ const disabled = this.disabled();
46
+ const loading = this.loading();
47
+ const blockedLink = !this.isNativeButton && disabled;
48
+ this.override("disabled", this.isNativeButton && disabled ? "" : null);
49
+ this.override("aria-disabled", loading || blockedLink ? "true" : null);
50
+ this.override("tabindex", blockedLink ? "-1" : null);
51
+ });
52
+ effect(() => {
53
+ const loading = this.loading();
54
+ const started = this.previousLoading === false && loading;
55
+ this.previousLoading = loading;
56
+ if (started && this.isBrowser) {
57
+ const message = untracked(() => this.labels().loading);
58
+ this.announcer.announce(message);
59
+ }
60
+ });
61
+ if (typeof ngDevMode !== "undefined" && ngDevMode) {
62
+ let destroyed = false;
63
+ destroyRef.onDestroy(() => destroyed = true);
64
+ afterNextRender(() => {
65
+ if (!destroyed && this.iconOnly() && !this.hasAccessibleName()) console.warn("[ckui] ckButton with iconOnly has no accessible name. Add an aria-label, aria-labelledby or title.", this.element);
66
+ });
67
+ }
68
+ }
69
+ override(name, value) {
70
+ if (value !== null) {
71
+ if (!this.overridden.has(name)) this.overridden.set(name, this.element.getAttribute(name));
72
+ this.renderer.setAttribute(this.element, name, value);
73
+ } else if (this.overridden.has(name)) {
74
+ const previous = this.overridden.get(name) ?? null;
75
+ this.overridden.delete(name);
76
+ if (previous === null) this.renderer.removeAttribute(this.element, name);
77
+ else this.renderer.setAttribute(this.element, name, previous);
78
+ }
79
+ }
80
+ hasAccessibleName() {
81
+ const element = this.element;
82
+ const attribute = (name) => (element.getAttribute(name) ?? "").trim() !== "";
83
+ if (attribute("aria-label") || attribute("title") || visibleText(element) !== "") return true;
84
+ return (element.getAttribute("aria-labelledby") ?? "").split(/\s+/).some((id) => id !== "" && (element.ownerDocument.getElementById(id)?.textContent ?? "").trim() !== "");
85
+ }
86
+ static ɵfac = i0.ɵɵngDeclareFactory({
87
+ minVersion: "12.0.0",
88
+ version: "22.2.4",
89
+ ngImport: i0,
90
+ type: CkButton,
91
+ deps: [],
92
+ target: i0.ɵɵFactoryTarget.Component
93
+ });
94
+ static ɵcmp = i0.ɵɵngDeclareComponent({
95
+ minVersion: "17.1.0",
96
+ version: "22.2.4",
97
+ type: CkButton,
98
+ isStandalone: true,
99
+ selector: "button[ckButton], a[ckButton]",
100
+ inputs: {
101
+ variant: {
102
+ classPropertyName: "variant",
103
+ publicName: "variant",
104
+ isSignal: true,
105
+ isRequired: false,
106
+ transformFunction: null
107
+ },
108
+ size: {
109
+ classPropertyName: "size",
110
+ publicName: "size",
111
+ isSignal: true,
112
+ isRequired: false,
113
+ transformFunction: null
114
+ },
115
+ iconOnly: {
116
+ classPropertyName: "iconOnly",
117
+ publicName: "iconOnly",
118
+ isSignal: true,
119
+ isRequired: false,
120
+ transformFunction: null
121
+ },
122
+ loading: {
123
+ classPropertyName: "loading",
124
+ publicName: "loading",
125
+ isSignal: true,
126
+ isRequired: false,
127
+ transformFunction: null
128
+ },
129
+ disabled: {
130
+ classPropertyName: "disabled",
131
+ publicName: "disabled",
132
+ isSignal: true,
133
+ isRequired: false,
134
+ transformFunction: null
135
+ }
136
+ },
137
+ host: {
138
+ properties: {
139
+ "class": "modifierClasses()",
140
+ "class.ck-button--icon-only": "iconOnly()",
141
+ "class.ck-button--loading": "loading()",
142
+ "class.ck-button--disabled": "disabled()"
143
+ },
144
+ classAttribute: "ck-button"
145
+ },
146
+ ngImport: i0,
147
+ template: `
148
+ <span class="ck-button__content"><ng-content /></span>
149
+ <span class="ck-button__spinner" aria-hidden="true"></span>
150
+ `,
151
+ isInline: true,
152
+ styles: ["@layer ckui{.ck-button{position:relative;display:inline-flex;align-items:center;justify-content:center;box-sizing:border-box;max-inline-size:100%;margin:0;border:1px solid transparent;border-radius:var(--ck-button-radius, var(--ck-control-radius));color-scheme:var(--ck-color-scheme);font-family:inherit;font-variant-numeric:var(--ck-font-variant-numeric);font-weight:var(--ck-font-weight-medium);line-height:var(--ck-line-height-tight);text-align:center;text-decoration:none;overflow-wrap:break-word;cursor:pointer;touch-action:manipulation;transition:background-color var(--ck-duration-fast) var(--ck-ease-standard)}.ck-button--sm{min-block-size:var(--ck-control-height-sm);padding-block:var(--ck-space-1);padding-inline:var(--ck-control-padding-inline-sm);font-size:var(--ck-control-font-size-sm)}.ck-button--md{min-block-size:var(--ck-control-height-md);padding-block:var(--ck-space-1);padding-inline:var(--ck-control-padding-inline-md);font-size:var(--ck-control-font-size-md)}.ck-button--lg{min-block-size:var(--ck-control-height-lg);padding-block:var(--ck-space-1);padding-inline:var(--ck-control-padding-inline-lg);font-size:var(--ck-control-font-size-lg)}.ck-button--xl{min-block-size:var(--ck-control-height-xl);padding-block:var(--ck-space-1);padding-inline:var(--ck-control-padding-inline-xl);font-size:var(--ck-control-font-size-xl)}.ck-button--icon-only{padding-inline:0}.ck-button--icon-only.ck-button--sm{inline-size:var(--ck-control-height-sm)}.ck-button--icon-only.ck-button--md{inline-size:var(--ck-control-height-md)}.ck-button--icon-only.ck-button--lg{inline-size:var(--ck-control-height-lg)}.ck-button--icon-only.ck-button--xl{inline-size:var(--ck-control-height-xl)}.ck-button__content{display:inline-flex;align-items:center;justify-content:center;gap:var(--ck-space-2);min-inline-size:0}.ck-button__content>svg,.ck-button__content>*>svg{flex:none;inline-size:1em;block-size:1em;color:currentColor}.ck-button--primary{background:var(--ck-color-primary);color:var(--ck-color-on-primary)}.ck-button--danger{background:var(--ck-color-danger);color:var(--ck-color-on-danger)}.ck-button--secondary{border-color:var(--ck-color-control-border);background:var(--ck-color-control);color:var(--ck-color-fg)}.ck-button--ghost{background:transparent;color:var(--ck-color-primary-fg)}@media(hover:hover){.ck-button--primary:hover{background:var(--ck-color-primary-hover)}.ck-button--danger:hover{background:var(--ck-color-danger-hover)}.ck-button--secondary:hover{background-image:linear-gradient(var(--ck-color-surface-hover),var(--ck-color-surface-hover))}.ck-button--ghost:hover{background:var(--ck-color-surface-hover)}}.ck-button--primary:active{background:var(--ck-color-primary-active)}.ck-button--danger:active{background:var(--ck-color-danger-active)}.ck-button--secondary:active{background-image:linear-gradient(var(--ck-color-surface-active),var(--ck-color-surface-active))}.ck-button--ghost:active{background:var(--ck-color-surface-active)}.ck-button:focus-visible{outline:var(--ck-focus-ring);outline-offset:var(--ck-focus-ring-offset)}.ck-button--loading{cursor:progress}.ck-button--loading .ck-button__content{opacity:0}.ck-button__spinner{display:none;position:absolute;inset-block-start:50%;inset-inline-start:50%;box-sizing:border-box;inline-size:1.25em;block-size:1.25em;margin-block-start:-.625em;margin-inline-start:-.625em;border:.15em solid color-mix(in oklch,currentColor 30%,transparent);border-block-start-color:currentColor;border-radius:var(--ck-radius-full);animation:ck-button-spin calc(var(--ck-duration-slow) * 3) linear infinite}.ck-button--loading .ck-button__spinner{display:block}:is(.ck-button--disabled,.ck-button:disabled),:is(.ck-button--disabled,.ck-button:disabled):hover,:is(.ck-button--disabled,.ck-button:disabled):active{border-color:transparent;background:var(--ck-color-surface-hover);color:var(--ck-color-fg-disabled);cursor:not-allowed}.ck-button--ghost:is(.ck-button--disabled,:disabled),.ck-button--ghost:is(.ck-button--disabled,:disabled):hover,.ck-button--ghost:is(.ck-button--disabled,:disabled):active{background:transparent}@keyframes ck-button-spin{to{transform:rotate(360deg)}}@media(prefers-reduced-motion:reduce){.ck-button__spinner{animation:none}}@media(forced-colors:active){.ck-button{border-color:ButtonText}:is(.ck-button--disabled,.ck-button:disabled),:is(.ck-button--disabled,.ck-button:disabled):hover,:is(.ck-button--disabled,.ck-button:disabled):active{border-color:GrayText;color:GrayText}.ck-button__spinner{border-color:ButtonText;border-block-start-color:Highlight}}}\n"],
153
+ changeDetection: i0.ChangeDetectionStrategy.OnPush,
154
+ encapsulation: i0.ViewEncapsulation.None
155
+ });
156
+ };
157
+ i0.ɵɵngDeclareClassMetadata({
158
+ minVersion: "12.0.0",
159
+ version: "22.2.4",
160
+ ngImport: i0,
161
+ type: CkButton,
162
+ decorators: [{
163
+ type: Component,
164
+ args: [{
165
+ selector: "button[ckButton], a[ckButton]",
166
+ changeDetection: ChangeDetectionStrategy.OnPush,
167
+ encapsulation: ViewEncapsulation.None,
168
+ host: {
169
+ class: "ck-button",
170
+ "[class]": "modifierClasses()",
171
+ "[class.ck-button--icon-only]": "iconOnly()",
172
+ "[class.ck-button--loading]": "loading()",
173
+ "[class.ck-button--disabled]": "disabled()"
174
+ },
175
+ template: `
176
+ <span class="ck-button__content"><ng-content /></span>
177
+ <span class="ck-button__spinner" aria-hidden="true"></span>
178
+ `,
179
+ styles: ["@layer ckui{.ck-button{position:relative;display:inline-flex;align-items:center;justify-content:center;box-sizing:border-box;max-inline-size:100%;margin:0;border:1px solid transparent;border-radius:var(--ck-button-radius, var(--ck-control-radius));color-scheme:var(--ck-color-scheme);font-family:inherit;font-variant-numeric:var(--ck-font-variant-numeric);font-weight:var(--ck-font-weight-medium);line-height:var(--ck-line-height-tight);text-align:center;text-decoration:none;overflow-wrap:break-word;cursor:pointer;touch-action:manipulation;transition:background-color var(--ck-duration-fast) var(--ck-ease-standard)}.ck-button--sm{min-block-size:var(--ck-control-height-sm);padding-block:var(--ck-space-1);padding-inline:var(--ck-control-padding-inline-sm);font-size:var(--ck-control-font-size-sm)}.ck-button--md{min-block-size:var(--ck-control-height-md);padding-block:var(--ck-space-1);padding-inline:var(--ck-control-padding-inline-md);font-size:var(--ck-control-font-size-md)}.ck-button--lg{min-block-size:var(--ck-control-height-lg);padding-block:var(--ck-space-1);padding-inline:var(--ck-control-padding-inline-lg);font-size:var(--ck-control-font-size-lg)}.ck-button--xl{min-block-size:var(--ck-control-height-xl);padding-block:var(--ck-space-1);padding-inline:var(--ck-control-padding-inline-xl);font-size:var(--ck-control-font-size-xl)}.ck-button--icon-only{padding-inline:0}.ck-button--icon-only.ck-button--sm{inline-size:var(--ck-control-height-sm)}.ck-button--icon-only.ck-button--md{inline-size:var(--ck-control-height-md)}.ck-button--icon-only.ck-button--lg{inline-size:var(--ck-control-height-lg)}.ck-button--icon-only.ck-button--xl{inline-size:var(--ck-control-height-xl)}.ck-button__content{display:inline-flex;align-items:center;justify-content:center;gap:var(--ck-space-2);min-inline-size:0}.ck-button__content>svg,.ck-button__content>*>svg{flex:none;inline-size:1em;block-size:1em;color:currentColor}.ck-button--primary{background:var(--ck-color-primary);color:var(--ck-color-on-primary)}.ck-button--danger{background:var(--ck-color-danger);color:var(--ck-color-on-danger)}.ck-button--secondary{border-color:var(--ck-color-control-border);background:var(--ck-color-control);color:var(--ck-color-fg)}.ck-button--ghost{background:transparent;color:var(--ck-color-primary-fg)}@media(hover:hover){.ck-button--primary:hover{background:var(--ck-color-primary-hover)}.ck-button--danger:hover{background:var(--ck-color-danger-hover)}.ck-button--secondary:hover{background-image:linear-gradient(var(--ck-color-surface-hover),var(--ck-color-surface-hover))}.ck-button--ghost:hover{background:var(--ck-color-surface-hover)}}.ck-button--primary:active{background:var(--ck-color-primary-active)}.ck-button--danger:active{background:var(--ck-color-danger-active)}.ck-button--secondary:active{background-image:linear-gradient(var(--ck-color-surface-active),var(--ck-color-surface-active))}.ck-button--ghost:active{background:var(--ck-color-surface-active)}.ck-button:focus-visible{outline:var(--ck-focus-ring);outline-offset:var(--ck-focus-ring-offset)}.ck-button--loading{cursor:progress}.ck-button--loading .ck-button__content{opacity:0}.ck-button__spinner{display:none;position:absolute;inset-block-start:50%;inset-inline-start:50%;box-sizing:border-box;inline-size:1.25em;block-size:1.25em;margin-block-start:-.625em;margin-inline-start:-.625em;border:.15em solid color-mix(in oklch,currentColor 30%,transparent);border-block-start-color:currentColor;border-radius:var(--ck-radius-full);animation:ck-button-spin calc(var(--ck-duration-slow) * 3) linear infinite}.ck-button--loading .ck-button__spinner{display:block}:is(.ck-button--disabled,.ck-button:disabled),:is(.ck-button--disabled,.ck-button:disabled):hover,:is(.ck-button--disabled,.ck-button:disabled):active{border-color:transparent;background:var(--ck-color-surface-hover);color:var(--ck-color-fg-disabled);cursor:not-allowed}.ck-button--ghost:is(.ck-button--disabled,:disabled),.ck-button--ghost:is(.ck-button--disabled,:disabled):hover,.ck-button--ghost:is(.ck-button--disabled,:disabled):active{background:transparent}@keyframes ck-button-spin{to{transform:rotate(360deg)}}@media(prefers-reduced-motion:reduce){.ck-button__spinner{animation:none}}@media(forced-colors:active){.ck-button{border-color:ButtonText}:is(.ck-button--disabled,.ck-button:disabled),:is(.ck-button--disabled,.ck-button:disabled):hover,:is(.ck-button--disabled,.ck-button:disabled):active{border-color:GrayText;color:GrayText}.ck-button__spinner{border-color:ButtonText;border-block-start-color:Highlight}}}\n"]
180
+ }]
181
+ }],
182
+ ctorParameters: () => [],
183
+ propDecorators: {
184
+ variant: [{
185
+ type: i0.Input,
186
+ args: [{
187
+ isSignal: true,
188
+ alias: "variant",
189
+ required: false
190
+ }]
191
+ }],
192
+ size: [{
193
+ type: i0.Input,
194
+ args: [{
195
+ isSignal: true,
196
+ alias: "size",
197
+ required: false
198
+ }]
199
+ }],
200
+ iconOnly: [{
201
+ type: i0.Input,
202
+ args: [{
203
+ isSignal: true,
204
+ alias: "iconOnly",
205
+ required: false
206
+ }]
207
+ }],
208
+ loading: [{
209
+ type: i0.Input,
210
+ args: [{
211
+ isSignal: true,
212
+ alias: "loading",
213
+ required: false
214
+ }]
215
+ }],
216
+ disabled: [{
217
+ type: i0.Input,
218
+ args: [{
219
+ isSignal: true,
220
+ alias: "disabled",
221
+ required: false
222
+ }]
223
+ }]
224
+ }
225
+ });
226
+ function visibleText(node) {
227
+ if (node.nodeType === Node.TEXT_NODE) return (node.textContent ?? "").trim();
228
+ if (node instanceof Element && (node.getAttribute("aria-hidden") === "true" || node.hasAttribute("hidden"))) return "";
229
+ return Array.from(node.childNodes, visibleText).join("");
230
+ }
231
+ export { CkButton };
232
+
233
+ //# sourceMappingURL=ckui-core-button.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ckui-core-button.mjs","names":[],"sources":["../../../../projects/core/button/button.ts"],"sourcesContent":["import { isPlatformBrowser } from '@angular/common';\nimport {\n ChangeDetectionStrategy,\n Component,\n DestroyRef,\n ElementRef,\n PLATFORM_ID,\n Renderer2,\n ViewEncapsulation,\n afterNextRender,\n booleanAttribute,\n computed,\n effect,\n inject,\n input,\n untracked,\n} from '@angular/core';\nimport { CK_CONFIG, CK_LABELS, CkSize } from '@ckui/core';\nimport { CkAnnouncer } from '@ckui/core/internal';\n\ndeclare const ngDevMode: unknown;\n\nexport type CkButtonVariant = 'primary' | 'secondary' | 'ghost' | 'danger';\n\n/**\n * Styles a native `<button>` or `<a>` as a button. The element keeps every native attribute\n * (`type`, `form`, `aria-*`, `routerLink`); there is no `<ck-button>` element.\n */\n@Component({\n selector: 'button[ckButton], a[ckButton]',\n changeDetection: ChangeDetectionStrategy.OnPush,\n encapsulation: ViewEncapsulation.None,\n host: {\n class: 'ck-button',\n '[class]': 'modifierClasses()',\n '[class.ck-button--icon-only]': 'iconOnly()',\n '[class.ck-button--loading]': 'loading()',\n '[class.ck-button--disabled]': 'disabled()',\n },\n template: `\n <span class=\"ck-button__content\"><ng-content /></span>\n <span class=\"ck-button__spinner\" aria-hidden=\"true\"></span>\n `,\n styleUrl: './button.css',\n})\nexport class CkButton {\n readonly variant = input<CkButtonVariant>('secondary');\n /** `undefined` uses the size from `provideCkui`. */\n readonly size = input<CkSize | undefined>(undefined);\n readonly iconOnly = input(false, { transform: booleanAttribute });\n readonly loading = input(false, { transform: booleanAttribute });\n readonly disabled = input(false, { transform: booleanAttribute });\n\n private readonly element = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;\n private readonly renderer = inject(Renderer2);\n private readonly config = inject(CK_CONFIG);\n private readonly labels = inject(CK_LABELS);\n private readonly announcer = inject(CkAnnouncer);\n private readonly isBrowser = isPlatformBrowser(inject(PLATFORM_ID));\n private readonly isNativeButton = this.element.tagName === 'BUTTON';\n\n protected readonly modifierClasses = computed(\n () => `ck-button--${this.variant()} ck-button--${this.size() ?? this.config.size}`,\n );\n\n /** The consumer's own value of every attribute this component currently overrides. */\n private readonly overridden = new Map<string, string | null>();\n private previousLoading: boolean | undefined;\n\n constructor() {\n const destroyRef = inject(DestroyRef);\n\n // A later `[type]` binding or a static type wins; only a missing type gets the default.\n if (this.isNativeButton && !this.element.hasAttribute('type')) {\n this.renderer.setAttribute(this.element, 'type', 'button');\n }\n\n // Capture phase on the host runs before routerLink and consumer (click) listeners.\n const blockClick = (event: Event): void => {\n if (this.loading() || this.disabled()) {\n event.preventDefault();\n event.stopImmediatePropagation();\n }\n };\n for (const type of ['click', 'auxclick']) {\n this.element.addEventListener(type, blockClick, { capture: true });\n destroyRef.onDestroy(() =>\n this.element.removeEventListener(type, blockClick, { capture: true }),\n );\n }\n\n effect(() => {\n const disabled = this.disabled();\n const loading = this.loading();\n const blockedLink = !this.isNativeButton && disabled;\n this.override('disabled', this.isNativeButton && disabled ? '' : null);\n this.override('aria-disabled', loading || blockedLink ? 'true' : null);\n this.override('tabindex', blockedLink ? '-1' : null);\n });\n\n effect(() => {\n const loading = this.loading();\n const started = this.previousLoading === false && loading;\n this.previousLoading = loading;\n if (started && this.isBrowser) {\n const message = untracked(() => this.labels().loading);\n void this.announcer.announce(message);\n }\n });\n\n if (typeof ngDevMode !== 'undefined' && ngDevMode) {\n let destroyed = false;\n destroyRef.onDestroy(() => (destroyed = true));\n afterNextRender(() => {\n if (!destroyed && this.iconOnly() && !this.hasAccessibleName()) {\n console.warn(\n '[ckui] ckButton with iconOnly has no accessible name. Add an aria-label, aria-labelledby or title.',\n this.element,\n );\n }\n });\n }\n }\n\n /** Sets the attribute, or gives the consumer's own value back when `value` is null. */\n private override(name: string, value: string | null): void {\n if (value !== null) {\n if (!this.overridden.has(name)) {\n this.overridden.set(name, this.element.getAttribute(name));\n }\n this.renderer.setAttribute(this.element, name, value);\n } else if (this.overridden.has(name)) {\n const previous = this.overridden.get(name) ?? null;\n this.overridden.delete(name);\n if (previous === null) {\n this.renderer.removeAttribute(this.element, name);\n } else {\n this.renderer.setAttribute(this.element, name, previous);\n }\n }\n }\n\n private hasAccessibleName(): boolean {\n const element = this.element;\n const attribute = (name: string): boolean => (element.getAttribute(name) ?? '').trim() !== '';\n if (attribute('aria-label') || attribute('title') || visibleText(element) !== '') {\n return true;\n }\n return (element.getAttribute('aria-labelledby') ?? '')\n .split(/\\s+/)\n .some(\n (id) =>\n id !== '' && (element.ownerDocument.getElementById(id)?.textContent ?? '').trim() !== '',\n );\n }\n}\n\n/** Text that is neither in an `aria-hidden` nor in a `hidden` subtree. */\nfunction visibleText(node: Node): string {\n if (node.nodeType === Node.TEXT_NODE) {\n return (node.textContent ?? '').trim();\n }\n if (\n node instanceof Element &&\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