Skip to content

Commit

Permalink
formalize type definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
thescientist13 committed Feb 20, 2025
1 parent ec5713e commit d2c1ecf
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
"type": "git",
"url": "https://github.com/ProjectEvergreen/wcc.git"
},
"main": "src/wcc.js",
"type": "module",
"main": "src/wcc.js",
"exports": {
".": "./src/wcc.js",
"./types": "./src/index.d.ts"
},
"author": "Owen Buckley <[email protected]>",
"keywords": [
"Web Components",
Expand Down
18 changes: 18 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export type Metadata = object[{
[key: string]: {
instanceName: string;
moduleURL: URL;
isEntry: boolean
}
}]

// async function renderToString(elementURL, wrappingEntryTag = true, props = {}) {
export type renderToString = (elementURL: URL, wrappingEntryTag?: boolean, props?: any) => Promise<{
html: string;
metadata: Metadata
}>

export type renderFromHTML = (html: string, elementURLs: URL[]) => Promise<{
html: string;
metadata: Metadata
}>
15 changes: 2 additions & 13 deletions src/wcc.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,7 @@ async function initializeCustomElement(elementURL, tagName, node = {}, definitio
}
}

/**
* @param {URL} elementURL - The entry point custom element definition
* @param {boolean} wrappingEntryTag - Whether to wrap (or not wrap) your entry point's HTML in a custom element tag
* @param {any} props - Constructor props
*
* @returns {Promise<{ html: string, metadata: any[] }>}- Fully rendered HTML contents and custom elements metadata
*/
/** @type {import('./index.d.ts').renderToString} */
async function renderToString(elementURL, wrappingEntryTag = true, props = {}) {
const definitions = [];
const elementTagName = wrappingEntryTag && await getTagName(elementURL);
Expand Down Expand Up @@ -219,12 +213,7 @@ async function renderToString(elementURL, wrappingEntryTag = true, props = {}) {
};
}

/**
* @param {string} html - The HTML contents to render from
* @param {URL[]} elements - Custom element definitions to pass to the renderer
*
* @returns {Promise<{ html: string, metadata: any[] }>} Fully rendered HTML contents and custom elements metadata
*/
/** @type {import('./index.d.ts').renderFromHTML} */
async function renderFromHTML(html, elements = []) {
const definitions = [];

Expand Down

0 comments on commit d2c1ecf

Please sign in to comment.