| 302 | } |
| 303 | |
| 304 | export class ShadowRootTree { |
| 305 | element: string |
| 306 | shadowRoot?: string |
| 307 | mode?: ShadowRootMode |
| 308 | children = new Set<ShadowRootTree>() |
| 309 | |
| 310 | constructor (element: string, shadowRoot?: string, mode?: ShadowRootMode) { |
| 311 | this.element = element |
| 312 | this.shadowRoot = shadowRoot |
| 313 | this.mode = mode |
| 314 | } |
| 315 | |
| 316 | /** |
| 317 | * Attach new shadow element to tree |
| 318 | */ |
| 319 | addShadowElement (tree: ShadowRootTree): void |
| 320 | /** |
| 321 | * Attach new shadow element to tree of sub tree |
| 322 | * @param scope {string} shadow element id of tree to attach new element to |
| 323 | * @param element {string} element id |
| 324 | * @param shadowRoot {string} shadow root id |
| 325 | */ |
| 326 | addShadowElement (scope: string, tree: ShadowRootTree): void |
| 327 | addShadowElement (...args: (ShadowRootTree | string | undefined)[]) { |
| 328 | const [scope, treeArg] = args |
| 329 | if (!scope && !treeArg) { |
| 330 | throw new Error('Method "addShadowElement" expects at least 2 arguments') |
| 331 | } |
| 332 | |
| 333 | if (scope instanceof ShadowRootTree) { |
| 334 | for (const child of this.children) { |
| 335 | if (child.element === scope.element) { |
| 336 | return |
| 337 | } |
| 338 | } |
| 339 | this.children.add(scope) |
| 340 | return |
| 341 | } |
| 342 | |
| 343 | /** |
| 344 | * if we have a scope, check if it matches any ShadowRootTree based |
| 345 | * by element or shadow root id |
| 346 | */ |
| 347 | if (typeof scope === 'string' && treeArg instanceof ShadowRootTree) { |
| 348 | const tree = this.find(scope) || this.findByShadowId(scope) |
| 349 | if (!tree) { |
| 350 | return |
| 351 | } |
| 352 | |
| 353 | tree.addShadowElement(treeArg) |
| 354 | return |
| 355 | } |
| 356 | |
| 357 | throw new Error('Invalid arguments for "addShadowElement" method') |
| 358 | } |
| 359 | |
| 360 | find (element: string): ShadowRootTree | undefined { |
| 361 | if (this.element === element) { |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…