@@ -627,88 +627,6 @@ export interface RenderOptions {
627627 isConnected ?: boolean ;
628628}
629629
630- /**
631- * Renders a value, usually a lit-html TemplateResult, to the container.
632- *
633- * This example renders the text "Hello, Zoe!" inside a paragraph tag, appending
634- * it to the container `document.body`.
635- *
636- * ```js
637- * import {html, render} from 'lit';
638- *
639- * const name = "Zoe";
640- * render(html`<p>Hello, ${name}!</p>`, document.body);
641- * ```
642- *
643- * @param value Any [renderable
644- * value](https://lit.dev/docs/templates/expressions/#child-expressions),
645- * typically a {@linkcode TemplateResult} created by evaluating a template tag
646- * like {@linkcode html} or {@linkcode svg}.
647- * @param container A DOM container to render to. The first render will append
648- * the rendered value to the container, and subsequent renders will
649- * efficiently update the rendered value if the same result type was
650- * previously rendered there.
651- * @param options See {@linkcode RenderOptions} for options documentation.
652- * @see
653- * {@link https://lit.dev/docs/libraries/standalone-templates/#rendering-lit-html-templates| Rendering Lit HTML Templates }
654- */
655- export const render = (
656- value : unknown ,
657- container : HTMLElement | DocumentFragment ,
658- options ?: RenderOptions
659- ) : RootPart => {
660- if ( DEV_MODE && container == null ) {
661- // Give a clearer error message than
662- // Uncaught TypeError: Cannot read properties of null (reading
663- // '_$litPart$')
664- // which reads like an internal Lit error.
665- throw new TypeError ( `The container to render into may not be ${ container } ` ) ;
666- }
667- const renderId = DEV_MODE ? debugLogRenderId ++ : 0 ;
668- const partOwnerNode = options ?. renderBefore ?? container ;
669- // This property needs to remain unminified.
670- // eslint-disable-next-line @typescript-eslint/no-explicit-any
671- let part : ChildPart = ( partOwnerNode as any ) [ '_$litPart$' ] ;
672- debugLogEvent ?.( {
673- kind : 'begin render' ,
674- id : renderId ,
675- value,
676- container,
677- options,
678- part,
679- } ) ;
680- if ( part === undefined ) {
681- const endNode = options ?. renderBefore ?? null ;
682- // This property needs to remain unminified.
683- // eslint-disable-next-line @typescript-eslint/no-explicit-any
684- ( partOwnerNode as any ) [ '_$litPart$' ] = part = new ChildPart (
685- container . insertBefore ( createMarker ( ) , endNode ) ,
686- endNode ,
687- undefined ,
688- options ?? { }
689- ) ;
690- }
691- part . _$setValue ( value ) ;
692- debugLogEvent ?.( {
693- kind : 'end render' ,
694- id : renderId ,
695- value,
696- container,
697- options,
698- part,
699- } ) ;
700- return part as RootPart ;
701- } ;
702-
703- if ( ENABLE_EXTRA_SECURITY_HOOKS ) {
704- render . setSanitizer = setSanitizer ;
705- render . createSanitizer = createSanitizer ;
706- if ( DEV_MODE ) {
707- render . _testOnlyClearSanitizerFactoryDoNotCallOrElse =
708- _testOnlyClearSanitizerFactoryDoNotCallOrElse ;
709- }
710- }
711-
712630const walker = d . createTreeWalker (
713631 d ,
714632 129 /* NodeFilter.SHOW_{ELEMENT|COMMENT} */ ,
@@ -2186,3 +2104,85 @@ if (DEV_MODE && global.litHtmlVersions.length > 1) {
21862104 `Loading multiple versions is not recommended.`
21872105 ) ;
21882106}
2107+
2108+ /**
2109+ * Renders a value, usually a lit-html TemplateResult, to the container.
2110+ *
2111+ * This example renders the text "Hello, Zoe!" inside a paragraph tag, appending
2112+ * it to the container `document.body`.
2113+ *
2114+ * ```js
2115+ * import {html, render} from 'lit';
2116+ *
2117+ * const name = "Zoe";
2118+ * render(html`<p>Hello, ${name}!</p>`, document.body);
2119+ * ```
2120+ *
2121+ * @param value Any [renderable
2122+ * value](https://lit.dev/docs/templates/expressions/#child-expressions),
2123+ * typically a {@linkcode TemplateResult} created by evaluating a template tag
2124+ * like {@linkcode html} or {@linkcode svg}.
2125+ * @param container A DOM container to render to. The first render will append
2126+ * the rendered value to the container, and subsequent renders will
2127+ * efficiently update the rendered value if the same result type was
2128+ * previously rendered there.
2129+ * @param options See {@linkcode RenderOptions} for options documentation.
2130+ * @see
2131+ * {@link https://lit.dev/docs/libraries/standalone-templates/#rendering-lit-html-templates| Rendering Lit HTML Templates }
2132+ */
2133+ export const render = (
2134+ value : unknown ,
2135+ container : HTMLElement | DocumentFragment ,
2136+ options ?: RenderOptions
2137+ ) : RootPart => {
2138+ if ( DEV_MODE && container == null ) {
2139+ // Give a clearer error message than
2140+ // Uncaught TypeError: Cannot read properties of null (reading
2141+ // '_$litPart$')
2142+ // which reads like an internal Lit error.
2143+ throw new TypeError ( `The container to render into may not be ${ container } ` ) ;
2144+ }
2145+ const renderId = DEV_MODE ? debugLogRenderId ++ : 0 ;
2146+ const partOwnerNode = options ?. renderBefore ?? container ;
2147+ // This property needs to remain unminified.
2148+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2149+ let part : ChildPart = ( partOwnerNode as any ) [ '_$litPart$' ] ;
2150+ debugLogEvent ?.( {
2151+ kind : 'begin render' ,
2152+ id : renderId ,
2153+ value,
2154+ container,
2155+ options,
2156+ part,
2157+ } ) ;
2158+ if ( part === undefined ) {
2159+ const endNode = options ?. renderBefore ?? null ;
2160+ // This property needs to remain unminified.
2161+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2162+ ( partOwnerNode as any ) [ '_$litPart$' ] = part = new ChildPart (
2163+ container . insertBefore ( createMarker ( ) , endNode ) ,
2164+ endNode ,
2165+ undefined ,
2166+ options ?? { }
2167+ ) ;
2168+ }
2169+ part . _$setValue ( value ) ;
2170+ debugLogEvent ?.( {
2171+ kind : 'end render' ,
2172+ id : renderId ,
2173+ value,
2174+ container,
2175+ options,
2176+ part,
2177+ } ) ;
2178+ return part as RootPart ;
2179+ } ;
2180+
2181+ if ( ENABLE_EXTRA_SECURITY_HOOKS ) {
2182+ render . setSanitizer = setSanitizer ;
2183+ render . createSanitizer = createSanitizer ;
2184+ if ( DEV_MODE ) {
2185+ render . _testOnlyClearSanitizerFactoryDoNotCallOrElse =
2186+ _testOnlyClearSanitizerFactoryDoNotCallOrElse ;
2187+ }
2188+ }
0 commit comments