@@ -28,14 +28,15 @@ const INVALID_ATTR_NAME_CHAR_REGEX =
2828 * @param {Payload } to_copy
2929 * @returns {Payload }
3030 */
31- export function copy_payload ( { out, css, head } ) {
31+ export function copy_payload ( { out, css, head, uid } ) {
3232 return {
3333 out,
3434 css : new Set ( css ) ,
3535 head : {
3636 title : head . title ,
3737 out : head . out
38- }
38+ } ,
39+ uid
3940 } ;
4041}
4142
@@ -48,6 +49,7 @@ export function copy_payload({ out, css, head }) {
4849export function assign_payload ( p1 , p2 ) {
4950 p1 . out = p2 . out ;
5051 p1 . head = p2 . head ;
52+ p1 . uid = p2 . uid ;
5153}
5254
5355/**
@@ -83,17 +85,27 @@ export function element(payload, tag, attributes_fn = noop, children_fn = noop)
8385 */
8486export let on_destroy = [ ] ;
8587
88+ function create_uid_generator ( ) {
89+ let uid = 100 ;
90+ return ( ) => 's' + uid ++ ;
91+ }
92+
8693/**
8794 * Only available on the server and when compiling with the `server` option.
8895 * Takes a component and returns an object with `body` and `head` properties on it, which you can use to populate the HTML when server-rendering your app.
8996 * @template {Record<string, any>} Props
9097 * @param {import('svelte').Component<Props> | ComponentType<SvelteComponent<Props>> } component
91- * @param {{ props?: Omit<Props, '$$slots' | '$$events'>; context?: Map<any, any> } } [options]
98+ * @param {{ props?: Omit<Props, '$$slots' | '$$events'>; context?: Map<any, any>, uid?: () => string } } [options]
9299 * @returns {RenderOutput }
93100 */
94101export function render ( component , options = { } ) {
95102 /** @type {Payload } */
96- const payload = { out : '' , css : new Set ( ) , head : { title : '' , out : '' } } ;
103+ const payload = {
104+ out : '' ,
105+ css : new Set ( ) ,
106+ head : { title : '' , out : '' } ,
107+ uid : options . uid ?? create_uid_generator ( )
108+ } ;
97109
98110 const prev_on_destroy = on_destroy ;
99111 on_destroy = [ ] ;
@@ -526,6 +538,17 @@ export function once(get_value) {
526538 } ;
527539}
528540
541+ /**
542+ * Create an unique ID
543+ * @param {Payload } payload
544+ * @returns {string }
545+ */
546+ export function create_uid ( payload ) {
547+ const UID = payload . uid ( ) ;
548+ payload . out += '<!--#' + UID + '-->' ;
549+ return UID ;
550+ }
551+
529552export { attr , clsx } ;
530553
531554export { html } from './blocks/html.js' ;
0 commit comments