mirror of
https://github.com/google/blockly.git
synced 2026-01-07 09:00:11 +01:00
fix: Create CSS vars for SVG patterns. (#8671)
This commit is contained in:
15
core/grid.ts
15
core/grid.ts
@@ -210,6 +210,9 @@ export class Grid {
|
||||
* @param rnd A random ID to append to the pattern's ID.
|
||||
* @param gridOptions The object containing grid configuration.
|
||||
* @param defs The root SVG element for this workspace's defs.
|
||||
* @param injectionDiv The div containing the parent workspace and all related
|
||||
* workspaces and block containers. CSS variables representing SVG patterns
|
||||
* will be scoped to this container.
|
||||
* @returns The SVG element for the grid pattern.
|
||||
* @internal
|
||||
*/
|
||||
@@ -217,6 +220,7 @@ export class Grid {
|
||||
rnd: string,
|
||||
gridOptions: GridOptions,
|
||||
defs: SVGElement,
|
||||
injectionDiv?: HTMLElement,
|
||||
): SVGElement {
|
||||
/*
|
||||
<pattern id="blocklyGridPattern837493" patternUnits="userSpaceOnUse">
|
||||
@@ -247,6 +251,17 @@ export class Grid {
|
||||
// Edge 16 doesn't handle empty patterns
|
||||
dom.createSvgElement(Svg.LINE, {}, gridPattern);
|
||||
}
|
||||
|
||||
if (injectionDiv) {
|
||||
// Add CSS variables scoped to the injection div referencing the created
|
||||
// patterns so that CSS can apply the patterns to any element in the
|
||||
// injection div.
|
||||
injectionDiv.style.setProperty(
|
||||
'--blocklyGridPattern',
|
||||
`url(#${gridPattern.id})`,
|
||||
);
|
||||
}
|
||||
|
||||
return gridPattern;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user