aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2024-07-17 08:57:48 +0200
committerGitHub <noreply@github.com>2024-07-17 08:57:48 +0200
commit85f89126c127a318e90ef79e49af655795b3d122 (patch)
tree3bd133457efe2becc09ff04de7f721c94c8ece9a
parentec9d2fc952a683aaa9f0c523fbba0786babdf629 (diff)
parent1f5f978accc559f54aed0868e1a7a575a14a6d74 (diff)
downloadsvg.js-master.tar.gz
svg.js-master.zip
Merge pull request #1321 from hxdyj/patch-1HEADmaster
fix: shape.css() typescript tip
-rw-r--r--svg.js.d.ts19
1 files changed, 16 insertions, 3 deletions
diff --git a/svg.js.d.ts b/svg.js.d.ts
index 5fd0513..b3f17e9 100644
--- a/svg.js.d.ts
+++ b/svg.js.d.ts
@@ -4,14 +4,27 @@
// trick to keep reference to Array build-in type
declare class BuiltInArray<T> extends Array<T> {}
+// camelCase to kebab-case
+declare type CamelToKebab<S extends string> = S extends `${infer T}${infer U}`
+ ? U extends Uncapitalize<U>
+ ? `${Lowercase<T>}${CamelToKebab<U>}`
+ : `${Lowercase<T>}-${CamelToKebab<U>}`
+ : S;
+
+declare type ConvertKeysToKebab<T> = {
+ [K in keyof T as CamelToKebab<K & string>]: T[K];
+};
+
+declare type KebabCSSStyleDeclaration = ConvertKeysToKebab<CSSStyleDeclaration>
+
// trick to have nice attribute list for CSS
declare type CSSStyleName = Exclude<
- keyof CSSStyleDeclaration,
- 'parentRule' | 'length'
+ keyof KebabCSSStyleDeclaration,
+ 'parent-rule' | 'length'
>
// create our own style declaration that includes css vars
-interface CSSStyleDeclarationWithVars extends CSSStyleDeclaration {
+interface CSSStyleDeclarationWithVars extends KebabCSSStyleDeclaration {
[key: `--${string}`]: string
}