Skip to content

Commit

Permalink
refactor: remove enableAttributeDashCased support
Browse files Browse the repository at this point in the history
  • Loading branch information
Aarebecca committed Oct 16, 2024
1 parent 30068e3 commit af9d607
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 83 deletions.
37 changes: 2 additions & 35 deletions packages/g-lite/src/display-objects/DisplayObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { Shape } from '../types';
import {
createVec3,
decompose,
formatAttributeName,
fromRotationTranslationScale,
getEuler,
rad2deg,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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<Key extends keyof StyleProps>(
Expand All @@ -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;
Expand Down
9 changes: 2 additions & 7 deletions packages/g-lite/src/dom/Element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 0 additions & 7 deletions packages/g-lite/src/global-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,6 @@ export interface GlobalRuntime {
*/
enableStyleSyntax: boolean;

/**
* Enable using dash-cased attribute.
* @example
* circle.setAttribute('stroke-width', '2');
*/
enableAttributeDashCased: boolean;
enableSizeAttenuation: boolean;
}

Expand Down Expand Up @@ -178,5 +172,4 @@ runtime.styleValueRegistry = new DefaultStyleValueRegistry(runtime);
runtime.layoutRegistry = null;
runtime.globalThis = getGlobalThis();
runtime.enableStyleSyntax = true;
runtime.enableAttributeDashCased = false;
runtime.enableSizeAttenuation = false;
28 changes: 0 additions & 28 deletions packages/g-lite/src/utils/assert.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { memoize } from './memoize';
import { camelCase } from './string';

export function DCHECK(bool: boolean) {
if (!bool) {
throw new Error();
Expand Down Expand Up @@ -30,28 +27,3 @@ export function isSymbol(value: any): value is symbol {

export const definedProps = (obj: Record<string, unknown>) =>
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;
});
1 change: 0 additions & 1 deletion packages/g-lite/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export * from './memoize';
export * from './path';
export * from './pointer-events';
export * from './raf';
export * from './string';
export * from './tapable';
export * from './text';
export * from './transform-mat4';
5 changes: 0 additions & 5 deletions packages/g-lite/src/utils/string.ts

This file was deleted.

0 comments on commit af9d607

Please sign in to comment.