From b4c820b8235a730e3063fb723ba58d21cc2e3125 Mon Sep 17 00:00:00 2001 From: Aaron Date: Wed, 16 Oct 2024 21:37:20 +0800 Subject: [PATCH] refactor: remove enableAttributeDashCased support --- .../src/display-objects/DisplayObject.ts | 37 +------------------ packages/g-lite/src/dom/Element.ts | 9 +---- packages/g-lite/src/global-runtime.ts | 7 ---- packages/g-lite/src/utils/assert.ts | 28 -------------- packages/g-lite/src/utils/string.ts | 5 --- 5 files changed, 4 insertions(+), 82 deletions(-) delete mode 100644 packages/g-lite/src/utils/string.ts diff --git a/packages/g-lite/src/display-objects/DisplayObject.ts b/packages/g-lite/src/display-objects/DisplayObject.ts index 514117272..d7153f92b 100644 --- a/packages/g-lite/src/display-objects/DisplayObject.ts +++ b/packages/g-lite/src/display-objects/DisplayObject.ts @@ -19,7 +19,6 @@ import { Shape } from '../types'; import { createVec3, decompose, - formatAttributeName, fromRotationTranslationScale, getEuler, rad2deg, @@ -164,14 +163,6 @@ export class DisplayObject< this.getAnimations().forEach((animation) => { animation.cancel(); }); - - // FIXME - // this.renderable = null; - // this.cullable = null; - // this.transformable = null; - // this.rBushNode = null; - // this.geometry = null; - // this.sortable = null; } cloneNode( @@ -225,35 +216,14 @@ export class DisplayObject< } private initAttributes(attributes: StyleProps = {} as StyleProps) { - const renderable = this.renderable; - const options = { forceUpdateGeometry: true, - // usedAttributes: - // // only Group / Text should account for text relative props - // this.tagName === Shape.GROUP || this.tagName === Shape.TEXT - // ? INHERITABLE_STYLE_PROPS - // : INHERITABLE_BASE_STYLE_PROPS, }; - // account for FCP, process properties as less as possible - let formattedAttributes = attributes; - if (runtime.enableAttributeDashCased) { - // @ts-ignore - formattedAttributes = {}; - for (const name in attributes) { - const attributeName = formatAttributeName(name); - formattedAttributes[attributeName] = attributes[name]; - } - } - runtime.styleValueRegistry.processProperties( - this, - formattedAttributes, - options, - ); + runtime.styleValueRegistry.processProperties(this, attributes, options); // redraw at next frame - renderable.dirty = true; + this.renderable.dirty = true; } setAttribute( @@ -262,9 +232,6 @@ export class DisplayObject< force = false, memoize = true, ) { - if (runtime.enableAttributeDashCased) { - name = formatAttributeName(name as string) as Key; - } // ignore undefined value if (isUndefined(value)) { return; diff --git a/packages/g-lite/src/dom/Element.ts b/packages/g-lite/src/dom/Element.ts index b18b08819..9895201a6 100644 --- a/packages/g-lite/src/dom/Element.ts +++ b/packages/g-lite/src/dom/Element.ts @@ -10,7 +10,7 @@ import { Strategy } from '../components'; import { runtime } from '../global-runtime'; import type { AABB, Rectangle } from '../shapes'; import type { BaseStyleProps, ParsedBaseStyleProps } from '../types'; -import { formatAttributeName, isSymbol } from '../utils/assert'; +import { isSymbol } from '../utils/assert'; import { ERROR_MSG_APPEND_DESTROYED_ELEMENT, ERROR_MSG_METHOD_NOT_IMPLEMENTED, @@ -564,13 +564,8 @@ export class Element< return undefined; } - let value = this.attributes[name]; + const value = this.attributes[name]; if (value === undefined) { - if (runtime.enableAttributeDashCased) { - const attributeName = formatAttributeName(name as string); - value = this.attributes[attributeName]; - } - // if the given attribute does not exist, the value returned will either be null or "" return value; } else { diff --git a/packages/g-lite/src/global-runtime.ts b/packages/g-lite/src/global-runtime.ts index b3c22bef6..dfc8cd13c 100644 --- a/packages/g-lite/src/global-runtime.ts +++ b/packages/g-lite/src/global-runtime.ts @@ -72,12 +72,6 @@ export interface GlobalRuntime { */ enableStyleSyntax: boolean; - /** - * Enable using dash-cased attribute. - * @example - * circle.setAttribute('stroke-width', '2'); - */ - enableAttributeDashCased: boolean; enableSizeAttenuation: boolean; } @@ -178,5 +172,4 @@ runtime.styleValueRegistry = new DefaultStyleValueRegistry(runtime); runtime.layoutRegistry = null; runtime.globalThis = getGlobalThis(); runtime.enableStyleSyntax = true; -runtime.enableAttributeDashCased = false; runtime.enableSizeAttenuation = false; diff --git a/packages/g-lite/src/utils/assert.ts b/packages/g-lite/src/utils/assert.ts index 309817140..85e424a89 100644 --- a/packages/g-lite/src/utils/assert.ts +++ b/packages/g-lite/src/utils/assert.ts @@ -1,6 +1,3 @@ -import { memoize } from './memoize'; -import { camelCase } from './string'; - export function DCHECK(bool: boolean) { if (!bool) { throw new Error(); @@ -30,28 +27,3 @@ export function isSymbol(value: any): value is symbol { export const definedProps = (obj: Record) => Object.fromEntries(Object.entries(obj).filter(([, v]) => v !== undefined)); - -const FORMAT_ATTR_MAP = { - d: { - alias: 'path', - }, - strokeDasharray: { - alias: 'lineDash', - }, - strokeWidth: { - alias: 'lineWidth', - }, - textAnchor: { - alias: 'textAlign', - }, - src: { - alias: 'img', - }, -}; - -export const formatAttributeName = memoize((name: string) => { - let attributeName = camelCase(name); - const map = FORMAT_ATTR_MAP[attributeName]; - attributeName = map?.alias || attributeName; - return attributeName; -}); diff --git a/packages/g-lite/src/utils/string.ts b/packages/g-lite/src/utils/string.ts deleted file mode 100644 index 307c028a5..000000000 --- a/packages/g-lite/src/utils/string.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { memoize } from './memoize'; - -export const camelCase = memoize((str = '') => { - return str.replace(/-([a-z])/g, (g) => g[1].toUpperCase()); -});