Files
NapCatQQ/.pnpm-store/v3/files/53/4ce57941f99bbcbe32402c7e8649bf66a620f6aee0444c280b97921aa002e6b7e6b2d2651c483d8a0b931ce109c7360fefe6e390ff2fb3c1e92df86355acd6
T
TanTan e311ca3275
Build NapCat Artifacts / Type Check & Test (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

45 lines
1.1 KiB
Plaintext

import Attributor from './attributor.js';
function camelize(name: string): string {
const parts = name.split('-');
const rest = parts
.slice(1)
.map((part: string) => part[0].toUpperCase() + part.slice(1))
.join('');
return parts[0] + rest;
}
class StyleAttributor extends Attributor {
public static keys(node: HTMLElement): string[] {
return (node.getAttribute('style') || '').split(';').map((value) => {
const arr = value.split(':');
return arr[0].trim();
});
}
public add(node: HTMLElement, value: any): boolean {
if (!this.canAdd(node, value)) {
return false;
}
// @ts-expect-error Fix me later
node.style[camelize(this.keyName)] = value;
return true;
}
public remove(node: HTMLElement): void {
// @ts-expect-error Fix me later
node.style[camelize(this.keyName)] = '';
if (!node.getAttribute('style')) {
node.removeAttribute('style');
}
}
public value(node: HTMLElement): any {
// @ts-expect-error Fix me later
const value = node.style[camelize(this.keyName)];
return this.canAdd(node, value) ? value : '';
}
}
export default StyleAttributor;