function init() {
  // Query the DOM for necessary elements
  let partAttribute = document.querySelector('part-attribute');
  const attachOpen = document.querySelector('#btn-attach-open');
  const attachClosed = document.querySelector('#btn-attach-closed');
  const addBlue = document.querySelector('#btn-add-blue');
  const resetDemo = document.querySelector('#btn-reset');

  /**
   * Event listener for the "Attach Open Shadow" button. Attaches a shadowRoot
   * to the <part-attribute> web component with { mode: 'open' } which allows
   * for modifications to the shadowRoot after attachment
   */
  attachOpen.addEventListener('click', () => {
    // Allow the user to click the edit and reset buttons
    addBlue.removeAttribute('disabled');
    resetDemo.removeAttribute('disabled');
    // Prevent the user from trying to attach another shadow DOM
    attachOpen.setAttribute('disabled', '');
    attachClosed.setAttribute('disabled', '');
    // Attach an open shadow to the web component
    partAttribute.attachOpenShadow();
  });

  /**
   * Event listener for the "Attach Closed Shadow" button. Attaches a shadowRoot
   * to the <part-attribute> web component with { mode: 'closed' } which prevents
   * modifications to the shadowRoot after attachment
   */
  attachClosed.addEventListener('click', () => {
    // Allow the user to click the edit and reset buttons
    addBlue.removeAttribute('disabled');
    resetDemo.removeAttribute('disabled');
    // Prevent the user from trying to attach another shadow DOM
    attachOpen.setAttribute('disabled', '');
    attachClosed.setAttribute('disabled', '');
    // Attach an closed shadow to the web component
    partAttribute.attachClosedShadow();
  });

  /**
   * Adds the "blue" class to the <part-attribute> element
   */
  addBlue.addEventListener('click', () => {
    partAttribute.classList.add('blue');
    addBlue.setAttribute('disabled', '');
    console.log('Class "blue" added to <part-attribute>');
  });

  /**
   * Since shadowRoots cannot be removed from elements once they have
   * been attached, the element itself must be deleted and replaced in
   * order to get a clean web component ready to attach another shadowRoot.
   * The on-screen console is also cleared of any messages
   */
  resetDemo.addEventListener('click', () => {
    // Remove & recreate the original <part-attribute> element
    partAttribute.remove();
    partAttribute = document.createElement('part-attribute');
    partAttribute.innerHTML = ' No Shadow Root ';
    const componentWrapper = document.querySelector('#component-wrapper');
    componentWrapper.insertAdjacentElement('afterbegin', partAttribute);
    // Allow the user to click the attach shadow buttons
    attachOpen.removeAttribute('disabled');
    attachClosed.removeAttribute('disabled');
    // Prevent the user from clicking the "edit" and "reset" buttons
    addBlue.setAttribute('disabled', '');
    resetDemo.setAttribute('disabled', '');
    // Clear the real and on-screen console
    document.querySelector('custom-console').clear();
    console.clear();
  });
}
/**
 * Init (initialize) function waits for the DOMContent to load before starting
 * to query elements and attach event listeners
 */
Init (initialize) function waits for the DOMContent to load before starting
to query elements and attach event listeners
Init ( initialize ) function waits for the DOMContent to load before starting to query elements and attach event listeners
function init() {
  let partAttribute = document.querySelector('part-attribute');
  const attachOpen = document.querySelector('#btn-attach-open');
  const attachClosed = document.querySelector('#btn-attach-closed');
  const addBlue = document.querySelector('#btn-add-blue');
  const resetDemo = document.querySelector('#btn-reset');
  attachOpen.addEventListener('click', () => {
    addBlue.removeAttribute('disabled');
    resetDemo.removeAttribute('disabled');
    attachOpen.setAttribute('disabled', '');
    attachClosed.setAttribute('disabled', '');
    partAttribute.attachOpenShadow();
  });
  attachClosed.addEventListener('click', () => {
    addBlue.removeAttribute('disabled');
    resetDemo.removeAttribute('disabled');
    attachOpen.setAttribute('disabled', '');
    attachClosed.setAttribute('disabled', '');
    partAttribute.attachClosedShadow();
  });
  addBlue.addEventListener('click', () => {
    partAttribute.classList.add('blue');
    addBlue.setAttribute('disabled', '');
    console.log('Class "blue" added to <part-attribute>');
  });
  resetDemo.addEventListener('click', () => {
    partAttribute.remove();
    partAttribute = document.createElement('part-attribute');
    partAttribute.innerHTML = ' No Shadow Root ';
    const componentWrapper = document.querySelector('#component-wrapper');
    componentWrapper.insertAdjacentElement('afterbegin', partAttribute);
    attachOpen.removeAttribute('disabled');
    attachClosed.removeAttribute('disabled');
    addBlue.setAttribute('disabled', '');
    resetDemo.setAttribute('disabled', '');
    document.querySelector('custom-console').clear();
    console.clear();
  });
}
function init ( ) { let partAttribute = document . querySelector ( 'part-attribute' ) ; const attachOpen = document . querySelector ( '#btn-attach-open' ) ; const attachClosed = document . querySelector ( '#btn-attach-closed' ) ; const addBlue = document . querySelector ( '#btn-add-blue' ) ; const resetDemo = document . querySelector ( '#btn-reset' ) ; attachOpen . addEventListener ( 'click' , ( ) => { addBlue . removeAttribute ( 'disabled' ) ; resetDemo . removeAttribute ( 'disabled' ) ; attachOpen . setAttribute ( 'disabled' , '' ) ; attachClosed . setAttribute ( 'disabled' , '' ) ; partAttribute . attachOpenShadow ( ) ; } ) ; attachClosed . addEventListener ( 'click' , ( ) => { addBlue . removeAttribute ( 'disabled' ) ; resetDemo . removeAttribute ( 'disabled' ) ; attachOpen . setAttribute ( 'disabled' , '' ) ; attachClosed . setAttribute ( 'disabled' , '' ) ; partAttribute . attachClosedShadow ( ) ; } ) ; addBlue . addEventListener ( 'click' , ( ) => { partAttribute . classList . add ( 'blue' ) ; addBlue . setAttribute ( 'disabled' , '' ) ; console . log ( 'Class "blue" added to <part-attribute>' ) ; } ) ; resetDemo . addEventListener ( 'click' , ( ) => { partAttribute . remove ( ) ; partAttribute = document . createElement ( 'part-attribute' ) ; partAttribute . innerHTML = ' No Shadow Root ' ; const componentWrapper = document . querySelector ( '#component-wrapper' ) ; componentWrapper . insertAdjacentElement ( 'afterbegin' , partAttribute ) ; attachOpen . removeAttribute ( 'disabled' ) ; attachClosed . removeAttribute ( 'disabled' ) ; addBlue . setAttribute ( 'disabled' , '' ) ; resetDemo . setAttribute ( 'disabled' , '' ) ; document . querySelector ( 'custom-console' ) . clear ( ) ; console . clear ( ) ; } ) ; }
Init (initialize) function waits for the DOMContent to load before starting
 to query elements and attach event listeners
Init ( initialize ) function waits for the DOMContent to load before starting to query elements and attach event listeners
// Query the DOM for necessary elements /**
   * Event listener for the "Attach Open Shadow" button. Attaches a shadowRoot
   * to the <part-attribute> web component with { mode: 'open' } which allows
   * for modifications to the shadowRoot after attachment
   */ // Allow the user to click the edit and reset buttons // Prevent the user from trying to attach another shadow DOM // Attach an open shadow to the web component /**
   * Event listener for the "Attach Closed Shadow" button. Attaches a shadowRoot
   * to the <part-attribute> web component with { mode: 'closed' } which prevents
   * modifications to the shadowRoot after attachment
   */ // Allow the user to click the edit and reset buttons // Prevent the user from trying to attach another shadow DOM // Attach an closed shadow to the web component /**
   * Adds the "blue" class to the <part-attribute> element
   */ /**
   * Since shadowRoots cannot be removed from elements once they have
   * been attached, the element itself must be deleted and replaced in
   * order to get a clean web component ready to attach another shadowRoot.
   * The on-screen console is also cleared of any messages
   */ // Remove & recreate the original <part-attribute> element // Allow the user to click the attach shadow buttons // Prevent the user from clicking the "edit" and "reset" buttons // Clear the real and on-screen console