-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(): Remove storage + cssRules, gradientDefs, clipPathDefs globals #9030
Merged
Merged
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1cbc92e
getting out of hand pretty quickly
asturur 31e38e7
this is unused
asturur b11edca
this is the plan, now needs to work
asturur 8526c3c
this was broken
asturur 4176caf
Merge branch 'master' into remove-globals-styling
asturur b837fb0
broken 100%
asturur bb8a207
broken 50%
asturur 0d2cd24
missing type
asturur c1f4f7b
Merge branch 'master' into remove-globals-styling
asturur 6a5c59d
added changelog
asturur 447185d
Merge branch 'master' into remove-globals-styling
asturur File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
//@ts-nocheck | ||
import { DEFAULT_SVG_FONT_SIZE } from '../constants'; | ||
import { parseUnit } from '../util/misc/svgParsing'; | ||
import { cPath, fSize, svgValidParentsRegEx } from './constants'; | ||
|
@@ -8,6 +7,7 @@ import { normalizeValue } from './normalizeValue'; | |
import { parseFontDeclaration } from './parseFontDeclaration'; | ||
import { parseStyleAttribute } from './parseStyleAttribute'; | ||
import { setStrokeFillOpacity } from './setStrokeFillOpacity'; | ||
import type { CSSRules } from './typedefs'; | ||
|
||
/** | ||
* Returns an object of attributes' name/value, given element and an array of attribute names; | ||
|
@@ -17,59 +17,58 @@ import { setStrokeFillOpacity } from './setStrokeFillOpacity'; | |
* @return {Object} object containing parsed attributes' names/values | ||
*/ | ||
export function parseAttributes( | ||
element: SVGElement | HTMLElement, | ||
element: HTMLElement | null, | ||
attributes: string[], | ||
svgUid?: string | ||
cssRules?: CSSRules | ||
): Record<string, any> { | ||
if (!element) { | ||
return {}; | ||
} | ||
|
||
let value, | ||
parentAttributes = {}, | ||
parentAttributes: Record<string, string> = {}, | ||
fontSize, | ||
parentFontSize; | ||
parentFontSize = DEFAULT_SVG_FONT_SIZE; | ||
|
||
if (typeof svgUid === 'undefined') { | ||
svgUid = element.getAttribute('svgUid'); | ||
} | ||
// if there's a parent container (`g` or `a` or `symbol` node), parse its attributes recursively upwards | ||
if ( | ||
element.parentNode && | ||
svgValidParentsRegEx.test(element.parentNode.nodeName) | ||
) { | ||
parentAttributes = parseAttributes(element.parentNode, attributes, svgUid); | ||
parentAttributes = parseAttributes( | ||
element.parentElement, | ||
attributes, | ||
cssRules | ||
); | ||
if (parentAttributes.fontSize) { | ||
fontSize = parentFontSize = parseUnit(parentAttributes.fontSize); | ||
} | ||
} | ||
|
||
let ownAttributes = attributes.reduce(function (memo, attr) { | ||
value = element.getAttribute(attr); | ||
if (value) { | ||
// eslint-disable-line | ||
memo[attr] = value; | ||
} | ||
return memo; | ||
}, {}); | ||
// add values parsed from style, which take precedence over attributes | ||
// (see: http://www.w3.org/TR/SVG/styling.html#UsingPresentationAttributes) | ||
const cssAttrs = Object.assign( | ||
getGlobalStylesForElement(element, svgUid), | ||
parseStyleAttribute(element) | ||
); | ||
ownAttributes = Object.assign(ownAttributes, cssAttrs); | ||
if (cssAttrs[cPath]) { | ||
element.setAttribute(cPath, cssAttrs[cPath]); | ||
const ownAttributes: Record<string, string> = { | ||
...attributes.reduce<Record<string, string>>((memo, attr) => { | ||
value = element.getAttribute(attr); | ||
if (value) { | ||
memo[attr] = value; | ||
} | ||
return memo; | ||
}, {}), | ||
// add values parsed from style, which take precedence over attributes | ||
// (see: http://www.w3.org/TR/SVG/styling.html#UsingPresentationAttributes) | ||
...getGlobalStylesForElement(element, cssRules), | ||
...parseStyleAttribute(element), | ||
}; | ||
|
||
if (ownAttributes[cPath]) { | ||
element.setAttribute(cPath, ownAttributes[cPath]); | ||
} | ||
fontSize = parentFontSize = | ||
parentAttributes.fontSize || DEFAULT_SVG_FONT_SIZE; | ||
if (ownAttributes[fSize]) { | ||
// looks like the minimum should be 9px when dealing with ems. this is what looks like in browsers. | ||
ownAttributes[fSize] = fontSize = parseUnit( | ||
ownAttributes[fSize], | ||
parentFontSize | ||
); | ||
fontSize = parseUnit(ownAttributes[fSize], parentFontSize); | ||
ownAttributes[fSize] = `${fontSize}`; | ||
} | ||
|
||
const normalizedStyle = {}; | ||
const normalizedStyle: Record<string, string> = {}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i m not sure what happened here, i will rely on tests. |
||
for (const attr in ownAttributes) { | ||
const normalizedAttr = normalizeAttr(attr); | ||
const normalizedValue = normalizeValue( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks bad but i really just removed the var
rules
and chained 3 array methods of which we didn't need the return value