Skip to content

Commit 52e6b0f

Browse files
authored
Merge pull request #579 from OskarLinde/feat/add-svg-helper
feature: expose page-local root SVG element as global in rule scripts
2 parents 56f6a96 + 9031487 commit 52e6b0f

File tree

3 files changed

+4
-0
lines changed

3 files changed

+4
-0
lines changed

docs/_docs/03-usage.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ Service data can be dynamically constructed using JavaScript code. Below is the
253253
| `hass` | Home Assistant [hass](https://home-assistant.io/developers/development_hass_object/) object |
254254
| `element` | current SVG element |
255255
| `elements` | current SVG elements |
256+
| `svg` | Root `<svg>` element for the current floorplan page (use for scoped `querySelector(...)`) |
256257

257258
| Functions | Description |
258259
| ------------------------ | ------------------------------------------------------------------------------------------- |

src/components/floorplan/floorplan-element.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1715,6 +1715,7 @@ export class FloorplanElement extends LitElement {
17151715
this.svgElements,
17161716
this.functions,
17171717
svgElementInfo,
1718+
this.svg,
17181719
ruleInfo
17191720
);
17201721
} catch (err) {

src/components/floorplan/lib/eval-helper.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export class EvalHelper {
4545
svgElements?: { [elementId: string]: SVGGraphicsElement },
4646
functions?: unknown,
4747
svgElementInfo?: FloorplanSvgElementInfo,
48+
svg?: SVGGraphicsElement,
4849
ruleInfo?: FloorplanRuleInfo
4950
): unknown {
5051
this.expression = expression.trim();
@@ -97,6 +98,7 @@ export class EvalHelper {
9798
this.interpreter.import('hass', hass);
9899
this.interpreter.import('element', svgElement);
99100
this.interpreter.import('elements', svgElements);
101+
this.interpreter.import('svg', svg); // Provide direct access to the root <svg> element for rule scripts
100102

101103
// Let the user call "action" function (to call our service call-handler)
102104
this.interpreter.import('action',

0 commit comments

Comments
 (0)