@santi020k/lumen-elements 1.6.0 → 1.7.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.
@@ -0,0 +1,26 @@
1
+ export type LumenCustomElementRegistry = Pick<CustomElementRegistry, 'define' | 'get'>;
2
+ export interface LumenElementConfig {
3
+ attributeClassAliases?: Record<string, string>;
4
+ attributeClasses?: Record<string, Record<string, string>>;
5
+ baseClassName: string;
6
+ defaults?: Record<string, string>;
7
+ observedAttributes?: readonly string[];
8
+ role?: string;
9
+ tagName: string;
10
+ }
11
+ export type LumenElementConstructor = CustomElementConstructor & {
12
+ config: LumenElementConfig;
13
+ };
14
+ export declare class LumenElement extends HTMLElement {
15
+ static config: LumenElementConfig;
16
+ static get observedAttributes(): readonly string[];
17
+ connectedCallback(): void;
18
+ disconnectedCallback(): void;
19
+ attributeChangedCallback(_name?: string, _previousValue?: string | null, _value?: string | null): void;
20
+ protected get config(): LumenElementConfig;
21
+ private applyDefaults;
22
+ private applyClassNames;
23
+ }
24
+ export declare const createLumenElementClass: (config: LumenElementConfig) => LumenElementConstructor;
25
+ export declare const defineLumenElement: (config: LumenElementConfig, element: CustomElementConstructor, registry?: LumenCustomElementRegistry) => void;
26
+ //# sourceMappingURL=element-base.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"element-base.d.ts","sourceRoot":"","sources":["../src/element-base.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,0BAA0B,GAAG,IAAI,CAC3C,qBAAqB,EACrB,QAAQ,GAAG,KAAK,CACjB,CAAA;AAED,MAAM,WAAW,kBAAkB;IACjC,qBAAqB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC9C,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;IACzD,aAAa,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACjC,kBAAkB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;IACtC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,MAAM,uBAAuB,GAAG,wBAAwB,GAAG;IAC/D,MAAM,EAAE,kBAAkB,CAAA;CAC3B,CAAA;AA2BD,qBAAa,YAAa,SAAQ,WAAW;IAC3C,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAA;IAEjC,MAAM,KAAK,kBAAkB,sBAI5B;IAED,iBAAiB;IAMjB,oBAAoB;IAIpB,wBAAwB,CACtB,KAAK,CAAC,EAAE,MAAM,EACd,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,EAC9B,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI;IAKxB,SAAS,KAAK,MAAM,uBAEnB;IAED,OAAO,CAAC,aAAa;IAYrB,OAAO,CAAC,eAAe;CA4BxB;AAED,eAAO,MAAM,uBAAuB,GAClC,QAAQ,kBAAkB,KACzB,uBAEF,CAAA;AAED,eAAO,MAAM,kBAAkB,GAC7B,QAAQ,kBAAkB,EAC1B,SAAS,wBAAwB,EACjC,WAAW,0BAA0B,KACpC,IAQF,CAAA"}
@@ -0,0 +1,66 @@
1
+ import { composeClassName } from '@santi020k/lumen-core';
2
+ const appliedClassNames = new WeakMap();
3
+ const mergeClassNames = (...classNames) => composeClassName(...classNames)
4
+ .split(/\s+/)
5
+ .filter(Boolean);
6
+ const resolveAttributeClassName = (element, config, attributeName, classMap) => {
7
+ const canonicalAttribute = config.attributeClassAliases?.[attributeName];
8
+ if (canonicalAttribute && element.hasAttribute(canonicalAttribute))
9
+ return undefined;
10
+ const attributeValue = element.hasAttribute(attributeName) ?
11
+ element.getAttribute(attributeName) || 'true' :
12
+ config.defaults?.[attributeName];
13
+ return attributeValue ? classMap[attributeValue] : undefined;
14
+ };
15
+ export class LumenElement extends HTMLElement {
16
+ static config;
17
+ static get observedAttributes() {
18
+ return this.config.observedAttributes ?? Object.keys(this.config.attributeClasses ?? {});
19
+ }
20
+ connectedCallback() {
21
+ this.applyDefaults();
22
+ this.applyClassNames();
23
+ }
24
+ disconnectedCallback() {
25
+ }
26
+ attributeChangedCallback(_name, _previousValue, _value) {
27
+ this.applyClassNames();
28
+ }
29
+ get config() {
30
+ return this.constructor.config;
31
+ }
32
+ applyDefaults() {
33
+ for (const [name, value] of Object.entries(this.config.defaults ?? {})) {
34
+ if (!this.hasAttribute(name)) {
35
+ this.setAttribute(name, value);
36
+ }
37
+ }
38
+ if (this.config.role && !this.hasAttribute('role')) {
39
+ this.setAttribute('role', this.config.role);
40
+ }
41
+ }
42
+ applyClassNames() {
43
+ const previousClassNames = appliedClassNames.get(this) ?? [];
44
+ for (const className of previousClassNames) {
45
+ this.classList.remove(className);
46
+ }
47
+ const classNames = mergeClassNames(this.config.baseClassName);
48
+ for (const [attributeName, classMap] of Object.entries(this.config.attributeClasses ?? {})) {
49
+ const className = resolveAttributeClassName(this, this.config, attributeName, classMap);
50
+ if (className) {
51
+ classNames.push(...mergeClassNames(className));
52
+ }
53
+ }
54
+ this.classList.add(...classNames);
55
+ appliedClassNames.set(this, classNames);
56
+ }
57
+ }
58
+ export const createLumenElementClass = (config) => class extends LumenElement {
59
+ static config = config;
60
+ };
61
+ export const defineLumenElement = (config, element, registry) => {
62
+ const targetRegistry = registry ?? (typeof customElements === 'undefined' ? undefined : customElements);
63
+ if (targetRegistry && !targetRegistry.get(config.tagName)) {
64
+ targetRegistry.define(config.tagName, element);
65
+ }
66
+ };
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './define.js';
2
+ export type { LumenTabsChangeDetail, LumenTabsChangeEvent } from '@santi020k/lumen-core';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,YAAY,EACV,qBAAqB,EACrB,oBAAoB,EACrB,MAAM,uBAAuB,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@santi020k/lumen-elements",
3
- "version": "1.6.0",
3
+ "version": "1.7.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -9,6 +9,7 @@
9
9
  "sideEffects": [
10
10
  "./layers.css",
11
11
  "./styles.css",
12
+ "./styles/critical.css",
12
13
  "./dist/define.js"
13
14
  ],
14
15
  "main": "./dist/index.js",
@@ -23,20 +24,46 @@
23
24
  "types": "./dist/define.d.ts",
24
25
  "import": "./dist/define.js"
25
26
  },
27
+ "./components/badge": {
28
+ "types": "./dist/components/badge.d.ts",
29
+ "import": "./dist/components/badge.js"
30
+ },
31
+ "./components/button": {
32
+ "types": "./dist/components/button.d.ts",
33
+ "import": "./dist/components/button.js"
34
+ },
35
+ "./components/card": {
36
+ "types": "./dist/components/card.d.ts",
37
+ "import": "./dist/components/card.js"
38
+ },
39
+ "./components/combobox": {
40
+ "types": "./dist/components/combobox.d.ts",
41
+ "import": "./dist/components/combobox.js"
42
+ },
43
+ "./components/foundations": {
44
+ "types": "./dist/components/foundations.d.ts",
45
+ "import": "./dist/components/foundations.js"
46
+ },
26
47
  "./styles.css": "./styles.css",
48
+ "./styles/critical.css": "./styles/critical.css",
27
49
  "./layers.css": "./layers.css",
28
50
  "./package.json": "./package.json"
29
51
  },
30
52
  "files": [
53
+ "bin",
31
54
  "dist",
32
55
  "layers.css",
33
56
  "styles.css",
57
+ "styles",
34
58
  "README.md",
35
59
  "LICENSE"
36
60
  ],
61
+ "bin": {
62
+ "lumen": "./bin/lumen.mjs"
63
+ },
37
64
  "dependencies": {
38
- "@santi020k/lumen": "^1.6.0",
39
- "@santi020k/lumen-core": "^1.4.0"
65
+ "@santi020k/lumen": "^1.7.0",
66
+ "@santi020k/lumen-core": "^1.7.0"
40
67
  },
41
68
  "devDependencies": {
42
69
  "@vitest/coverage-v8": "^4.1.11",
@@ -80,6 +107,7 @@
80
107
  "test:coverage": "vitest run --config ../../vitest.config.ts --project elements --coverage",
81
108
  "lint": "eslint . --no-warn-ignored --max-warnings=0",
82
109
  "lint:fix": "eslint . --fix --no-warn-ignored --max-warnings=0",
110
+ "measure:registration": "pnpm run build && node scripts/measure-registration.mjs",
83
111
  "clean": "rm -rf dist coverage"
84
112
  }
85
113
  }