Skip to content

Commit

Permalink
fix: vivid init when environment doesn't allow to re-assign readonly …
Browse files Browse the repository at this point in the history
…args (#71)
  • Loading branch information
dvelluto authored Jul 11, 2024
1 parent 3028a34 commit 43cbf46
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/initialization/initVivid.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ const appendStyleElement = (document = window.document) => (styleDescriptor) =>
* @throws {Error} error - if the provided target argument is `null` or not a Node of type `Document` / `DocumentFragment` / `HTMLElement`
*/
export const initVivid = (target, callback, options = {}) => {
if (target instanceof HTMLElement) {
target.classList.add('vivid-scope') // vivid 2.x
target.setAttribute(`${vividDataAttributePrefix}-v2`, vividVersion.v2)
let targetElement = target
if (targetElement instanceof HTMLElement) {
targetElement.classList.add('vivid-scope') // vivid 2.x
targetElement.setAttribute(`${vividDataAttributePrefix}-v2`, vividVersion.v2)

target.classList.add('vvd-root') // vivid 3.x
target.setAttribute(`${vividDataAttributePrefix}-v3`, vividVersion.v3)
target = undefined
targetElement.classList.add('vvd-root') // vivid 3.x
targetElement.setAttribute(`${vividDataAttributePrefix}-v3`, vividVersion.v3)
targetElement = undefined
}
if (!options.theme) {
options.theme = 'light'
Expand All @@ -54,6 +55,6 @@ export const initVivid = (target, callback, options = {}) => {
}
return Promise.all([
init(),
context.mount(target)
context.mount(targetElement)
]).then(callback)
}

0 comments on commit 43cbf46

Please sign in to comment.