Skip to content

Commit

Permalink
refactor to lightMode config
Browse files Browse the repository at this point in the history
  • Loading branch information
thescientist13 committed May 11, 2022
1 parent 667209b commit fdb3ad4
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 11 deletions.
4 changes: 3 additions & 1 deletion build.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ async function init() {
const distRoot = './dist';
const pagesRoot = './docs/pages';
const pages = await fs.readdir(new URL(pagesRoot, import.meta.url));
const { html } = await renderToString(new URL('./docs/index.js', import.meta.url), false);
const { html } = await renderToString(new URL('./docs/index.js', import.meta.url), {
lightMode: true
});

// await fs.rm(distRoot, { recursive: true, force: true });
// await fs.mkdir('./dist', { recursive: true });
Expand Down
9 changes: 2 additions & 7 deletions src/wcc.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,14 @@ async function initializeCustomElement(elementURL, tagName, attrs = []) {

async function renderToString(elementURL, options = {}) {
definitions = [];
const { includeShadowRoots = true, unwrapTopLevelShadowRoot = false } = options;
const { lightMode = false } = options;
const includeShadowRoots = !lightMode;

const elementInstance = await initializeCustomElement(elementURL);
// invert includeShadowRoots at the top level to double `<template>` tag wrapping top level content
// this is useful in conjunction with a WC used as a page, where we only want its content, not necessarily its template
const elementHtml = elementInstance.getInnerHTML({ includeShadowRoots });
const elementTree = parseFragment(elementHtml);
const finalTree = await renderComponentRoots(elementTree, includeShadowRoots);

// elementInstance.shadowRoot.innerHTML = serialize(finalTree);

console.debug(serialize(finalTree));

return {
html: serialize(finalTree),
metadata: definitions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
* Config
* {
* includeShadowRoots: false
* lightMode: true
* }
*/

Expand All @@ -26,12 +26,12 @@ import { renderToString } from '../../../src/wcc.js';
const expect = chai.expect;

describe('Run WCC For ', function() {
const LABEL = 'Nested Custom Element w/ no rendered Shadow Roots';
const LABEL = 'Nested Custom Element w/ no using Light Mode configuration';
let dom;

before(async function() {
const { html } = await renderToString(new URL('./src/pages/index.js', import.meta.url), {
includeShadowRoots: false
lightMode: true
});

dom = new JSDOM(html);
Expand Down

0 comments on commit fdb3ad4

Please sign in to comment.