@htmlplus/element 3.4.6 → 3.4.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client.d.ts CHANGED
@@ -225,16 +225,19 @@ declare function Watch(keys?: string | string[], immediate?: boolean): (target:
225
225
  */
226
226
  declare const classes: (input: unknown, smart?: boolean) => string;
227
227
 
228
+ interface HTMLPlusElements {
229
+ }
230
+ type BreakpointConfig = {
231
+ type: 'container' | 'media';
232
+ min?: number;
233
+ max?: number;
234
+ };
228
235
  /**
229
236
  * TODO
230
237
  */
231
- interface Config {
238
+ type Config<Namespace extends string, Breakpoints extends string> = {
232
239
  breakpoints?: {
233
- [key: string]: {
234
- type: 'container' | 'media';
235
- min?: number;
236
- max?: number;
237
- };
240
+ [key in Breakpoints]: BreakpointConfig;
238
241
  };
239
242
  event?: {
240
243
  resolver?: (parameters: unknown) => CustomEvent | undefined;
@@ -243,26 +246,24 @@ interface Config {
243
246
  [key: string]: unknown;
244
247
  };
245
248
  elements?: {
246
- [key: string]: {
249
+ [K in keyof HTMLPlusElements as K extends `${Namespace}-${string}` ? K : never]?: {
247
250
  properties?: {
248
- [key: string]: {
249
- default?: unknown;
251
+ [Prop in keyof HTMLPlusElements[K]['properties']]?: {
252
+ default?: HTMLPlusElements[K]['properties'][Prop];
250
253
  };
251
254
  };
252
255
  variants?: {
253
- [key: string]: {
254
- properties: {
255
- [key: string]: unknown;
256
- };
256
+ [M in HTMLPlusElements[K]['properties']['variant']]?: {
257
+ properties?: Partial<HTMLPlusElements[K]['properties']>;
257
258
  };
258
259
  };
259
260
  };
260
261
  };
261
- }
262
+ };
262
263
  /**
263
264
  * TODO
264
265
  */
265
- interface ConfigOptions {
266
+ type ConfigOptions = {
266
267
  /**
267
268
  * TODO
268
269
  */
@@ -271,23 +272,23 @@ interface ConfigOptions {
271
272
  * TODO
272
273
  */
273
274
  override?: boolean;
274
- }
275
+ };
275
276
  /**
276
277
  * TODO
277
278
  */
278
- declare const getConfig: (namespace: string) => Config;
279
+ declare const getConfig: <N extends string, B extends string>(namespace: N) => Config<N, B>;
279
280
  /**
280
281
  * TODO
281
282
  */
282
- declare const getConfigCreator: (namespace: string) => () => Config;
283
+ declare const getConfigCreator: <N extends string, B extends string>(namespace: N) => () => Config<N, B>;
283
284
  /**
284
285
  * TODO
285
286
  */
286
- declare const setConfig: (namespace: string, config: Config, options?: ConfigOptions) => void;
287
+ declare const setConfig: <N extends string, B extends string>(namespace: N, config: Config<N, B>, options?: ConfigOptions) => void;
287
288
  /**
288
289
  * TODO
289
290
  */
290
- declare const setConfigCreator: (namespace: string) => (config: Config, options?: ConfigOptions) => void;
291
+ declare const setConfigCreator: <N extends string, B extends string>(namespace: N) => (config: Config<N, B>, options?: ConfigOptions) => void;
291
292
 
292
293
  type Direction = 'ltr' | 'rtl';
293
294
  /**
@@ -382,4 +383,4 @@ type OverridableValue<Base, Overrides = unknown> = {
382
383
  } ? never : Unlisted<Base>);
383
384
 
384
385
  export { Bind, Consumer, Debounce, Direction$1 as Direction, Element$1 as Element, Event, Host, IsRTL, Listen, Method, Overrides, Property, Provider, Query, QueryAll, Slots$1 as Slots, State, Style, Variant, Watch, _internal_a_, _internal_h_, _internal_s_, classes, direction, dispatch, getConfig, getConfigCreator, host, isCSSColor, isCSSUnit, isRTL, off, on, query, queryAll, setConfig, setConfigCreator, slots, toUnit };
385
- export type { Config, ConfigOptions, EventEmitter, EventOptions, ListenOptions, OverridableValue, OverridesConfig, PropertyOptions };
386
+ export type { Config, ConfigOptions, EventEmitter, EventOptions, HTMLPlusElements, ListenOptions, OverridableValue, OverridesConfig, PropertyOptions };
package/dist/client.js CHANGED
@@ -268,7 +268,9 @@ const isCSSColor = (input) => {
268
268
  };
269
269
 
270
270
  const isCSSUnit = (input) => {
271
- return /^\d+(\.\d+)?(px|pt|cm|mm|in|em|rem|%|vw|vh)$/.test(input);
271
+ const option = new Option();
272
+ option.style.width = input;
273
+ return option.style.width !== '';
272
274
  };
273
275
 
274
276
  /**
@@ -1514,7 +1516,10 @@ const proxy = (constructor) => {
1514
1516
  const properties = getConfig(namespace).elements?.[tag]?.properties;
1515
1517
  if (!properties)
1516
1518
  return;
1517
- const defaults = Object.fromEntries(Object.entries(properties).map(([key, value]) => [key, value?.default]));
1519
+ const defaults = Object.fromEntries(Object.entries(properties).map(([key, value]) => [
1520
+ key,
1521
+ value?.default
1522
+ ]));
1518
1523
  Object.assign(this, defaults);
1519
1524
  })();
1520
1525
  // TODO
@@ -3,9 +3,9 @@ import { parse as parse$1 } from '@babel/parser';
3
3
  import fs from 'fs-extra';
4
4
  import { glob } from 'glob';
5
5
  import template from '@babel/template';
6
- import { pascalCase, kebabCase, camelCase, capitalCase } from 'change-case';
6
+ import { pascalCase, kebabCase, capitalCase } from 'change-case';
7
7
  import path, { join, resolve, dirname } from 'node:path';
8
- import { COMMENT_AUTO_ADDED, DECORATOR_PROPERTY, STATIC_TAG, DECORATOR_PROPERTY_TYPE, INTERNAL_STYLES_IMPORTED, INTERNAL_STYLES_LOCAL, INTERNAL_PATH, INTERNAL_HTML_IMPORTED, INTERNAL_HTML_LOCAL, ELEMENT_HOST_NAME, TYPE_OBJECT, TYPE_NULL, TYPE_ARRAY, TYPE_STRING, TYPE_ENUM, TYPE_NUMBER, TYPE_DATE, TYPE_BOOLEAN, INTERNAL_ATTRIBUTES_IMPORTED, INTERNAL_ATTRIBUTES_LOCAL, DECORATOR_CSS_VARIABLE, DECORATOR_EVENT, DECORATOR_METHOD, DECORATOR_STATE, STATIC_STYLE, STYLE_IMPORTED, PACKAGE_NAME, DECORATOR_ELEMENT, KEY } from './constants.js';
8
+ import { COMMENT_AUTO_ADDED, DECORATOR_PROPERTY, STATIC_TAG, DECORATOR_PROPERTY_TYPE, PACKAGE_NAME, INTERNAL_STYLES_IMPORTED, INTERNAL_STYLES_LOCAL, INTERNAL_PATH, INTERNAL_HTML_IMPORTED, INTERNAL_HTML_LOCAL, ELEMENT_HOST_NAME, TYPE_OBJECT, TYPE_NULL, TYPE_ARRAY, TYPE_STRING, TYPE_ENUM, TYPE_NUMBER, TYPE_DATE, TYPE_BOOLEAN, INTERNAL_ATTRIBUTES_IMPORTED, INTERNAL_ATTRIBUTES_LOCAL, DECORATOR_CSS_VARIABLE, DECORATOR_EVENT, DECORATOR_METHOD, DECORATOR_STATE, STATIC_STYLE, STYLE_IMPORTED, DECORATOR_ELEMENT, KEY } from './constants.js';
9
9
  import core from '@babel/traverse';
10
10
  import core$1 from '@babel/generator';
11
11
  import ora from 'ora';
@@ -667,7 +667,7 @@ const customElement = (userOptions) => {
667
667
  // biome-ignore lint: TODO
668
668
  event.typeAnnotation?.['typeAnnotation']?.typeParameters));
669
669
  const functionType = t.tsFunctionType(undefined, [parameter], t.tsTypeAnnotation(t.tsVoidKeyword()));
670
- const signature = t.tSPropertySignature(t.identifier(camelCase(`on-${key.name}`)), t.tsTypeAnnotation(functionType));
670
+ const signature = t.tSPropertySignature(t.identifier(key.name), t.tsTypeAnnotation(functionType));
671
671
  signature.optional = true;
672
672
  signature.leadingComments = t.cloneNode(event, true).leadingComments;
673
673
  return signature;
@@ -700,50 +700,170 @@ const customElement = (userOptions) => {
700
700
  return signature;
701
701
  })
702
702
  .filter((property) => !!property);
703
+ const attributeMapper = (context.classProperties ?? [])
704
+ .filter((property) => t.isIdentifier(property.key))
705
+ .map((property) => {
706
+ return `'${property.key.name}': '${extractAttribute(property) || kebabCase(property.key.name)}'`;
707
+ })
708
+ .join(',\n');
709
+ const overridableKeys = (context.classProperties ?? [])
710
+ .filter((property) => {
711
+ if (!t.isIdentifier(property.key))
712
+ return false;
713
+ const isOverridableValue =
714
+ // biome-ignore lint: TODO
715
+ property.typeAnnotation?.typeAnnotation?.typeName?.name ===
716
+ 'OverridableValue';
717
+ return isOverridableValue;
718
+ })
719
+ .map((property) => `'${property.key.name}'`)
720
+ .join(' | ');
703
721
  const ast = template.default.ast(`
704
722
  // THE FOLLOWING TYPES HAVE BEEN ADDED AUTOMATICALLY
705
723
 
706
- type Filter<Base, Overrides> = {
707
- [K in keyof Base as K extends keyof Overrides
708
- ? Overrides[K] extends never
709
- ? never
710
- : K
711
- : K]: Base[K];
724
+ type Filter<
725
+ Base,
726
+ Disables,
727
+ Mapper extends Record<PropertyKey, PropertyKey> | undefined = undefined
728
+ > = {
729
+ [K in keyof Base as
730
+ Mapper extends Record<PropertyKey, PropertyKey>
731
+ ? {
732
+ [P in keyof Mapper as Mapper[P]]: P
733
+ }[K] extends infer PropKey
734
+ ? PropKey extends keyof Disables
735
+ ? [Disables[PropKey]] extends [false]
736
+ ? never
737
+ : K
738
+ : K
739
+ : K
740
+ : K extends keyof Disables
741
+ ? [Disables[K]] extends [false]
742
+ ? never
743
+ : K
744
+ : K
745
+ ]: Base[K];
746
+ };
747
+
748
+ type Override<
749
+ Base,
750
+ Overrides,
751
+ AllowedKeys,
752
+ Mapper extends Record<PropertyKey, PropertyKey> | undefined = undefined
753
+ > = {
754
+ [K in keyof Base]:
755
+ Mapper extends Record<PropertyKey, PropertyKey>
756
+ ? {
757
+ [P in keyof Mapper as Mapper[P]]: P
758
+ }[K] extends infer PropKey
759
+ ? PropKey extends AllowedKeys
760
+ ? PropKey extends keyof Overrides
761
+ ? Overrides[PropKey]
762
+ : Base[K]
763
+ : Base[K]
764
+ : Base[K]
765
+ : K extends AllowedKeys
766
+ ? K extends keyof Overrides
767
+ ? Overrides[K]
768
+ : Base[K]
769
+ : Base[K];
712
770
  };
713
771
 
714
- export interface ${context.className}AttributesBase {
772
+ export type ${context.className}AttributesMapper = {
773
+ ${attributeMapper}
774
+ };
775
+
776
+ export type ${context.className}OverridableKeys = ${overridableKeys || 'never'};
777
+
778
+ export interface ${context.className}Disables {}
779
+
780
+ export interface ${context.className}Overrides {}
781
+
782
+ export type ${context.className}Attributes = Filter<
783
+ ${context.className}AttributesOverridden,
784
+ ${context.className}Disables,
785
+ ${context.className}AttributesMapper
786
+ >;
787
+
788
+ export type ${context.className}AttributesOverridden = Override<
789
+ ${context.className}AttributesBase,
790
+ ${context.className}Overrides,
791
+ ${context.className}OverridableKeys,
792
+ ${context.className}AttributesMapper
793
+ >;
794
+
795
+ export type ${context.className}AttributesBase = {
715
796
  ${attributes.map(print).join('')}
716
797
  }
717
798
 
718
- export interface ${context.className}AttributesDisables { }
719
-
720
- export type ${context.className}Attributes = Filter<${context.className}AttributesBase, ${context.className}AttributesDisables>;
799
+ export type ${context.className}Events = Filter<
800
+ ${context.className}EventsBase,
801
+ ${context.className}Disables
802
+ >;
721
803
 
722
- export interface ${context.className}EventsBase {
804
+ export type ${context.className}EventsBase = {
723
805
  ${events.map(print).join('')}
724
806
  }
725
807
 
726
- export interface ${context.className}EventsDisables { }
808
+ export type ${context.className}EventsJSX = Filter<
809
+ ${context.className}EventsBaseJSX,
810
+ ${context.className}Disables,
811
+ {
812
+ ${events.map((event) => `${print(event.key)}: 'on${pascalCase(print(event.key))}';`).join('')}
813
+ }
814
+ >;
815
+
816
+ export type ${context.className}EventsBaseJSX = {
817
+ ${events
818
+ .map((event) => ({
819
+ ...event,
820
+ key: t.identifier(`on${pascalCase(print(event.key))}`)
821
+ }))
822
+ .map(print)
823
+ .join('')}
824
+ };
727
825
 
728
- export type ${context.className}Events = Filter<${context.className}EventsBase, ${context.className}EventsDisables>;
826
+ export type ${context.className}Methods = Filter<
827
+ ${context.className}MethodsBase,
828
+ ${context.className}Disables
829
+ >;
729
830
 
730
- export interface ${context.className}MethodsBase {
831
+ export type ${context.className}MethodsBase = {
731
832
  ${methods.map(print).join('')}
732
833
  }
733
834
 
734
- export interface ${context.className}MethodsDisables { }
835
+ export type ${context.className}Properties = Filter<
836
+ ${context.className}PropertiesOverridden,
837
+ ${context.className}Disables
838
+ >;
735
839
 
736
- export type ${context.className}Methods = Filter<${context.className}MethodsBase, ${context.className}MethodsDisables>;
840
+ export type ${context.className}PropertiesOverridden = Override<
841
+ ${context.className}PropertiesBase,
842
+ ${context.className}Overrides,
843
+ ${context.className}OverridableKeys
844
+ >;
737
845
 
738
- export interface ${context.className}PropertiesBase {
846
+ export type ${context.className}PropertiesBase = {
739
847
  ${properties.map(print).join('')}
740
848
  }
741
849
 
742
- export interface ${context.className}PropertiesDisables { }
850
+ declare module '${PACKAGE_NAME}' {
851
+ interface HTMLPlusElements {
852
+ '${context.elementTagName}': {
853
+ properties: ${context.className}PropertiesOverridden;
854
+ }
855
+ }
856
+ }
743
857
 
744
- export type ${context.className}Properties = Filter<${context.className}PropertiesBase, ${context.className}PropertiesDisables>;
858
+ export type ${context.className}Element = globalThis.${context.elementInterfaceName};
745
859
 
746
- export interface ${context.className}JSX extends ${context.className}Events, ${context.className}Properties { }
860
+ export type ${context.className}JSX = ${context.className}Attributes & ${context.className}EventsJSX;
861
+
862
+ export namespace JSX {
863
+ interface IntrinsicElements {
864
+ "${context.elementTagName}": ${context.className}JSX;
865
+ }
866
+ }
747
867
 
748
868
  declare global {
749
869
  interface ${context.elementInterfaceName} extends HTMLElement, ${context.className}Methods, ${context.className}Properties { }
@@ -757,34 +877,14 @@ const customElement = (userOptions) => {
757
877
  "${context.elementTagName}": ${context.elementInterfaceName};
758
878
  }
759
879
  }
760
-
761
- export namespace JSX {
762
- interface IntrinsicElements {
763
- "${context.elementTagName}": ${context.className}Attributes & ${context.className}Events;
764
- }
765
- }
766
880
 
767
881
  declare module "react" {
768
882
  namespace JSX {
769
883
  interface IntrinsicElements {
770
- "${context.elementTagName}": ${context.className}Attributes & ${context.className}Events & Omit<DetailedHTMLProps<HTMLAttributes<${context.elementInterfaceName}>, ${context.elementInterfaceName}>, keyof (${context.className}Attributes & ${context.className}Events)>;
884
+ "${context.elementTagName}": ${context.className}JSX & Omit<DetailedHTMLProps<HTMLAttributes<${context.elementInterfaceName}>, ${context.elementInterfaceName}>, keyof ${context.className}JSX>;
771
885
  }
772
886
  }
773
887
  }
774
-
775
- ${['@builder.io/qwik', 'inferno', 'preact', 'solid-js']
776
- .map((key) => `
777
- declare module "${key}" {
778
- namespace JSX {
779
- interface IntrinsicElements {
780
- "${context.elementTagName}": ${context.className}Attributes & ${context.className}Events & Omit<HTMLAttributes<${context.elementInterfaceName}>, keyof (${context.className}Attributes & ${context.className}Events)>;
781
- }
782
- }
783
- }
784
- `)
785
- .join('\n')}
786
-
787
- export type ${context.className}Element = globalThis.${context.elementInterfaceName}
788
888
  `, {
789
889
  plugins: ['typescript'],
790
890
  preserveComments: true
@@ -817,37 +917,6 @@ const customElement = (userOptions) => {
817
917
  path.skip();
818
918
  }
819
919
  });
820
- // TODO
821
- visitor(ast, {
822
- TSTypeReference(path) {
823
- if (!t.isIdentifier(path.node.typeName))
824
- return;
825
- if (path.node.typeName.name !== 'OverridableValue')
826
- return;
827
- const property = path.findParent((p) => p.isTSPropertySignature());
828
- if (!property)
829
- return;
830
- if (!t.isTSPropertySignature(property.node))
831
- return;
832
- // biome-ignore lint: TODO
833
- const name = property.node.key.name || property.node.key.extra.rawValue;
834
- if (!name)
835
- return;
836
- if (!path.node.typeParameters?.params)
837
- return;
838
- if (path.node.typeParameters.params.length > 1)
839
- return;
840
- const interfaceName = pascalCase(`${context.className}-${name}-Overrides`);
841
- path.node.typeParameters.params[1] = t.identifier(interfaceName);
842
- path.skip();
843
- const has = ast.program.body.some((child) => t.isExportNamedDeclaration(child) &&
844
- t.isInterfaceDeclaration(child.declaration) &&
845
- child.declaration.id.name === interfaceName);
846
- if (has)
847
- return;
848
- ast.program.body.push(t.exportNamedDeclaration(t.interfaceDeclaration(t.identifier(interfaceName), undefined, undefined, t.objectTypeAnnotation([]))));
849
- }
850
- });
851
920
  }
852
921
  context.script = print(ast);
853
922
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@htmlplus/element",
3
- "version": "3.4.6",
3
+ "version": "3.4.7",
4
4
  "description": "A powerful library for building scalable, reusable, fast, tastable and lightweight design system for any web technologies. Powered by Web Component.",
5
5
  "keywords": [
6
6
  "components",