1 line
25 KiB
Plaintext
1 line
25 KiB
Plaintext
|
{"version":3,"file":"experimental-hydrate.js","sources":["../../src/experimental-hydrate.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2019 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */\n\nimport type {TemplateResult} from './lit-html.js';\n\nimport {noChange, RenderOptions, _$LH} from './lit-html.js';\nimport {AttributePartInfo, PartType} from './directive.js';\nimport {\n isPrimitive,\n isSingleExpression,\n isTemplateResult,\n isCompiledTemplateResult,\n} from './directive-helpers.js';\n\n// In the Node build, this import will be injected by Rollup:\n// import {Buffer} from 'buffer';\n\nconst NODE_MODE = false;\n\nconst {\n _TemplateInstance: TemplateInstance,\n _isIterable: isIterable,\n _resolveDirective: resolveDirective,\n _ChildPart: ChildPart,\n _ElementPart: ElementPart,\n} = _$LH;\n\ntype ChildPart = InstanceType<typeof ChildPart>;\ntype TemplateInstance = InstanceType<typeof TemplateInstance>;\n\n/**\n * Information needed to rehydrate a single TemplateResult.\n */\ntype ChildPartState =\n | {\n type: 'leaf';\n /** The ChildPart that the result is rendered to */\n part: ChildPart;\n }\n | {\n type: 'iterable';\n /** The ChildPart that the result is rendered to */\n part: ChildPart;\n value: Iterable<unknown>;\n iterator: Iterator<unknown>;\n done: boolean;\n }\n | {\n type: 'template-instance';\n /** The ChildPart that the result is rendered to */\n part: ChildPart;\n\n result: TemplateResult;\n\n /** The TemplateInstance created from the TemplateResult */\n instance: TemplateInstance;\n\n /**\n * The index of the next Template part to be hydrated. This is mutable and\n * updated as the tree walk discovers new part markers at the right level in\n * the template instance tree. Note there is only one Template part per\n * attribute with (one or more) bindings.\n */\n templatePartIndex: number;\n\n /**\n * The index of the next TemplateInstance part to be hydrated. This is used\n * to retrieve the value from the TemplateResult and initialize the\n * TemplateInstance parts' values for dirty-checking on first render.\n */\n instancePartIndex: number;\n };\n\n/**\n * hydrate() operates on a container with server-side rendered content and\n * restores the client side data structures needed for lit-html updates such as\n * TemplateInstances and Parts. After calling `hydrate`, lit-html will behave as\n * if it initially rendered the DOM, and any subsequent updates will update\n * efficiently, the same as if lit-html had rendered the DOM on the client.\n *\n * hydrate() must be called on DOM that adheres the to lit-ssr structure for\n * parts. ChildParts must be represented with both a start and end comment\n * marker, and ChildParts that contain a TemplateInstance must have the template\n * digest written into the comment data.\n *\n * Since render() encloses its output in a ChildPart, there must always be a root\n * ChildPart.\n *\n * Example (using for # ... for annotations in HTML)\n *\n * Given this input:\n *\n * html`<div class=${x}>${y}</div>`\n *\n * The SSR DOM is:\n *\n * <!--lit-part AEmR7W+R0Ak=--> # Start marker for the root ChildPart created\n * # by render(). Includes the digest of the\n * # template\n * <div class=\"TEST_X\">\n * <!--lit-node 0--> # Indicates there are attribute bindings here\n * # The number is the depth-first index of the parent\n * # node in the template.\n * <!--lit-part--> # Start marker for the ${x} expression\n * TEST_Y\n * <!--/lit-part--> # End marker for the ${x} expression\n * </div>\n *\n * <!--/lit-part--> # End marker for the root ChildPart\n *\n * @param rootValue\n * @param container\n * @param userOptions\n *\n * @deprecated This has been moved to `@lit-labs/ssr-client` and will be removed\n * in a future release.\n */\nexport const hyd
|