···11+{"version":3,"sources":["/components/input/s3/common.js","https://jsr.io/@bradenmacdonald/s3-lite-client/0.9.5/mod.ts","https://jsr.io/@bradenmacdonald/s3-lite-client/0.9.5/client.ts","https://jsr.io/@bradenmacdonald/s3-lite-client/0.9.5/transform-chunk-sizes.ts","https://jsr.io/@bradenmacdonald/s3-lite-client/0.9.5/errors.ts","https://jsr.io/@bradenmacdonald/s3-lite-client/0.9.5/xml-parser.ts","https://jsr.io/@bradenmacdonald/s3-lite-client/0.9.5/helpers.ts","https://jsr.io/@bradenmacdonald/s3-lite-client/0.9.5/object-uploader.ts","https://jsr.io/@bradenmacdonald/s3-lite-client/0.9.5/signing.ts"],"sourcesContent":["import { S3Client } from \"@bradenmacdonald/s3-lite-client\";\nimport * as IDB from \"idb-keyval\";\nimport * as URI from \"uri-js\";\nimport QS from \"query-string\";\n\nimport { ENCODINGS, IDB_BUCKETS, SCHEME } from \"./constants.js\";\n\n/**\n * @import { Track } from \"@definitions/types.d.ts\";\n * @import { Bucket } from \"./types.d.ts\";\n */\n\n////////////////////////////////////////////\n// 🛠️\n////////////////////////////////////////////\n\n/**\n * @param {Track[]} tracks\n */\nexport function bucketsFromTracks(tracks) {\n /** @type {Record<string, Bucket>} */\n const acc = {};\n\n tracks.forEach((track) => {\n const parsed = parseURI(track.uri);\n if (!parsed) return;\n\n const id = bucketId(parsed.bucket);\n if (acc[id]) return;\n\n acc[id] = parsed.bucket;\n });\n\n return acc;\n}\n\n/**\n * @param {Bucket} bucket\n */\nexport function bucketId(bucket) {\n return `${bucket.accessKey}:${bucket.secretKey}@${bucket.host}`;\n}\n\n/**\n * @param {Bucket} bucket\n * @param {string} [path]\n */\nexport function buildURI(bucket, path) {\n return URI.serialize({\n scheme: SCHEME,\n userinfo: `${bucket.accessKey}:${bucket.secretKey}`,\n host: bucket.host.replace(/^https?:\\/\\//, \"\"),\n path: path,\n query: QS.stringify({\n bucketName: bucket.bucketName,\n bucketPath: bucket.path,\n region: bucket.region,\n }),\n });\n}\n\n/**\n * @param {Bucket} bucket\n */\nexport async function consultBucket(bucket) {\n const client = createClient(bucket);\n return await client.bucketExists(bucket.bucketName);\n}\n\n/**\n * @param {Bucket} bucket\n */\nexport function createClient(bucket) {\n return new S3Client({\n bucket: bucket.bucketName,\n endPoint: `http${\n bucket.host.startsWith(\"localhost\") ? \"\" : \"s\"\n }://${bucket.host}`,\n region: bucket.region,\n pathStyle: false,\n accessKey: bucket.accessKey,\n secretKey: bucket.secretKey,\n });\n}\n\n/**\n * @param {string} a\n */\nexport function encodeAwsUriComponent(a) {\n return encodeURIComponent(a).replace(\n /(\\+|!|\"|#|\\$|&|'|\\(|\\)|\\*|\\+|,|:|;|=|\\?|@)/gim,\n (match) => /** @type {any} */ (ENCODINGS)[match] ?? match,\n );\n}\n\n/**\n * @param {Track[]} tracks\n */\nexport function groupTracksByBucket(tracks) {\n /** @type {Record<string, { bucket: Bucket; tracks: Track[] }>} */\n const acc = {};\n\n tracks.forEach((track) => {\n const parsed = parseURI(track.uri);\n if (!parsed) return acc;\n\n const id = bucketId(parsed.bucket);\n\n if (acc[id]) {\n acc[id].tracks.push(track);\n } else {\n acc[id] = { bucket: parsed.bucket, tracks: [track] };\n }\n });\n\n return acc;\n}\n\n/**\n * @returns {Promise<Record<string, Bucket>>}\n */\nexport async function loadBuckets() {\n const i = await IDB.get(IDB_BUCKETS);\n return i ? i : {};\n}\n\n/**\n * @param {string} uriString\n * @returns {{ bucket: Bucket; path: string } | undefined}\n */\nexport function parseURI(uriString) {\n const uri = URI.parse(uriString);\n if (uri.scheme !== SCHEME) return undefined;\n if (!uri.host) return undefined;\n\n const [accessKey, secretKey] = uri.userinfo?.split(\":\") ?? [];\n if (!accessKey || !secretKey) return undefined;\n\n const qs = QS.parse(uri.query || \"\");\n\n const bucket = {\n accessKey,\n bucketName: typeof qs.bucketName === \"string\" ? qs.bucketName : \"\",\n host: uri.host,\n path: qs.bucketPath === \"string\" ? qs.bucketPath : \"/\",\n region: typeof qs.region === \"string\" ? qs.region : \"\",\n secretKey,\n };\n\n const path =\n (bucket.path.replace(/\\/$/, \"\") + URI.unescapeComponent(uri.path || \"\"))\n .replace(\n /^\\//,\n \"\",\n );\n\n return { bucket, path };\n}\n\n/**\n * @param {Record<string, Bucket>} items\n */\nexport async function saveBuckets(items) {\n await IDB.set(IDB_BUCKETS, items);\n}\n","/**\n * @module\n * A lightweight client for connecting to S3-compatible object storage services.\n */\n\nexport {\n Client as S3Client,\n type ClientOptions as S3ClientOptions,\n type CommonPrefix as S3CommonPrefix,\n type CopiedObjectInfo as S3CopiedObjectInfo,\n type ObjectMetadata as S3ObjectMetadata,\n type ObjectStatus as S3ObjectStatus,\n type PolicyCondition as S3PolicyCondition,\n type PresignedPostResult as S3PresignedPostResult,\n type ResponseOverrideParams as S3ResponseOverrideParams,\n type S3Object,\n type UploadedObjectInfo as S3UploadedObjectInfo,\n} from \"./client.ts\";\nexport * as S3Errors from \"./errors.ts\";\n","import { TransformChunkSizes } from \"./transform-chunk-sizes.ts\";\nimport * as errors from \"./errors.ts\";\nimport {\n isValidBucketName,\n isValidObjectName,\n isValidPort,\n makeDateLong,\n sanitizeETag,\n sha256digestHex,\n type Uint8Array_,\n} from \"./helpers.ts\";\nimport { ObjectUploader } from \"./object-uploader.ts\";\nimport { presignPostV4, presignV4, signV4 } from \"./signing.ts\";\nimport { parse as parseXML } from \"./xml-parser.ts\";\n\nexport interface ClientOptions {\n /**\n * The full URL of the S3 endpoint. Can also be just the hostname (deprecated).\n * Examples: \"https://s3.eu-west-1.amazonaws.com\", \"http://localhost:9000\"\n */\n endPoint: string;\n accessKey?: string;\n secretKey?: string;\n /** If using temporary credentials, a session token is required. Otherwise you don't need this. */\n sessionToken?: string;\n /** Default bucket name, if not specified on individual requests */\n bucket?: string;\n /** Region to use, e.g. \"us-east-1\" */\n region: string;\n /** Use path-style requests, e.g. https://endpoint/bucket/object-key instead of https://bucket/object-key (default: true) */\n pathStyle?: boolean | undefined;\n /**\n * Whether to use HTTPS. Defaults to true unless http:// is explicitly specified in endPoint.\n * @deprecated Pass in a complete URL to `endPoint` instead, including 'https://' or 'http://'\n */\n useSSL?: boolean | undefined;\n /**\n * Port to use. Will be extracted from URL if provided, otherwise defaults to 80/443 based on protocol.\n * @deprecated Pass in a complete URL to `endPoint` instead, including a port number if needed.\n */\n port?: number | undefined;\n /**\n * Path prefix. Usually not required, but some API servers like Supabase S3 need this.\n * e.g. If docs say \"S3 Storage URL: http://127.0.0.1:54321/storage/v1/s3\" then pathPrefix is \"/storage/v1/s3\"\n *\n * @deprecated Pass in a complete URL to `endPoint` instead.\n */\n pathPrefix?: string;\n}\n\n/**\n * Standard Metadata (headers) that can be set when interacting with an object.\n * See https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutObject.html\n */\nconst metadataKeys = [\n \"Content-Type\",\n \"Cache-Control\",\n \"Content-Disposition\",\n \"Content-Encoding\",\n \"Content-Language\",\n \"Expires\",\n \"x-amz-checksum-sha256\",\n \"x-amz-grant-full-control\",\n \"x-amz-grant-read\",\n \"x-amz-grant-read-acp\",\n \"x-amz-grant-write-acp\",\n \"x-amz-server-side-encryption\",\n \"x-amz-storage-class\",\n \"x-amz-website-redirect-location\",\n \"x-amz-server-side-encryption-customer-algorithm\",\n \"x-amz-server-side-encryption-customer-key\",\n \"x-amz-server-side-encryption-customer-key-MD5\",\n \"x-amz-server-side-encryption-aws-kms-key-id\",\n \"x-amz-server-side-encryption-context\",\n \"x-amz-server-side-encryption-bucket-key-enabled\",\n \"x-amz-request-payer\",\n \"x-amz-tagging\",\n \"x-amz-object-lock-mode\",\n \"x-amz-object-lock-retain-until-date\",\n \"x-amz-object-lock-legal-hold\",\n \"x-amz-expected-bucket-owner\",\n] as const;\n\n/**\n * Metadata (standard and custom) that can be set when uploading an object.\n *\n * Custom keys should be like \"x-amz-meta-...\"\n */\nexport type ObjectMetadata =\n & {\n \"x-amz-acl\"?:\n | \"private\"\n | \"public-read\"\n | \"public-read-write\"\n | \"authenticated-read\"\n | \"aws-exec-read\"\n | \"bucket-owner-read\"\n | \"bucket-owner-full-control\";\n }\n & { [K in typeof metadataKeys[number]]?: string }\n & { [customMetadata: `x-amz-meta-${string}`]: string };\n\n/** Response Header Overrides\n * These parameters can be used with an authenticated or presigned get object request, to\n * override certain headers that will be sent with the response. These cannot be used with\n * anonymous requests (although some servers like MinIO do seem to allow it).\n * See https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObject.html\n */\nexport interface ResponseOverrideParams {\n \"response-content-type\"?: string;\n \"response-content-language\"?: string;\n \"response-expires\"?: string;\n \"response-cache-control\"?: string;\n \"response-content-disposition\"?: string;\n \"response-content-encoding\"?: string;\n}\n\nexport interface UploadedObjectInfo {\n etag: string;\n versionId: string | null;\n}\n\nexport interface CopiedObjectInfo extends UploadedObjectInfo {\n lastModified: Date;\n copySourceVersionId: string | null;\n}\n\n/** Details about an object as returned by a \"list objects\" operation */\nexport interface S3Object {\n type: \"Object\";\n key: string;\n lastModified: Date;\n etag: string;\n size: number;\n}\n/**\n * When listing objects and returning a delimited result (e.g. grouped by folders),\n * this represents a group of keys with a common prefix.\n * See https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-prefixes.html\n */\nexport interface CommonPrefix {\n type: \"CommonPrefix\";\n prefix: string;\n}\n\n/**\n * Additional properties provided by `statObject` compared to `listObjects`.\n */\nexport interface ObjectStatus extends S3Object {\n versionId: string | null;\n metadata: ObjectMetadata;\n}\n\n/** The minimum allowed part size for multi-part uploads. https://docs.aws.amazon.com/AmazonS3/latest/userguide/qfacts.html */\nconst minimumPartSize = 5 * 1024 * 1024;\n/** The maximum allowed part size for multi-part uploads. https://docs.aws.amazon.com/AmazonS3/latest/userguide/qfacts.html */\nconst maximumPartSize = 5 * 1024 * 1024 * 1024;\n/** The maximum allowed object size for multi-part uploads. https://docs.aws.amazon.com/AmazonS3/latest/userguide/qfacts.html */\nconst maxObjectSize = 5 * 1024 * 1024 * 1024 * 1024;\n\n/**\n * Interface for presigned POST policy conditions\n */\nexport type PolicyCondition = Record<string, unknown> | string[];\n\n/**\n * Interface for the result of a presigned POST request\n */\nexport interface PresignedPostResult {\n /**\n * The URL to POST the form to\n */\n url: string;\n /**\n * The fields to include in the form\n */\n fields: Record<string, string>;\n}\n\n/**\n * Client for connecting to S3-compatible object storage services.\n */\nexport class Client {\n readonly host: string;\n readonly port: number;\n readonly protocol: \"https:\" | \"http:\";\n readonly accessKey?: string;\n readonly #secretKey: string;\n readonly sessionToken?: string;\n readonly defaultBucket: string | undefined;\n readonly region: string;\n readonly userAgent = \"s3-lite-client\";\n /** Use path-style requests, e.g. https://endpoint/bucket/object-key instead of https://bucket/object-key */\n readonly pathStyle: boolean;\n readonly pathPrefix?: string;\n\n constructor({ endPoint, useSSL, port, pathPrefix, ...params }: Readonly<ClientOptions>) {\n // Check if endpoint is a URL (starts with http:// or https://)\n if (/^https?:\\/\\//i.test(endPoint)) {\n if (useSSL !== undefined || port !== undefined || pathPrefix !== undefined) {\n throw new errors.InvalidArgumentError(`useSSL/port/pathPrefix cannot be specified if endPoint is a URL.`);\n }\n try {\n const url = new URL(endPoint);\n endPoint = url.hostname; // Now this is just the hostname\n useSSL = url.protocol === \"https:\";\n port = url.port ? parseInt(url.port, 10) : (useSSL ? 443 : 80);\n if (url.pathname && url.pathname !== \"/\") {\n pathPrefix = url.pathname.endsWith(\"/\") ? url.pathname.slice(0, -1) : url.pathname;\n }\n } catch {\n throw new errors.InvalidEndpointError(`Invalid endPoint URL: ${endPoint}`);\n }\n }\n\n // Now validate the extracted hostname\n if (typeof endPoint !== \"string\" || endPoint.length === 0) {\n throw new errors.InvalidEndpointError(`Invalid endPoint: ${endPoint}`);\n }\n\n // Default values if not specified.\n if (useSSL === undefined) {\n useSSL = true;\n }\n\n // Validate port\n if (port !== undefined && !isValidPort(port)) {\n throw new errors.InvalidArgumentError(`Invalid port: ${port}`);\n }\n\n // Validate credentials\n if (params.accessKey && !params.secretKey) {\n throw new errors.InvalidArgumentError(`If specifying access key, secret key must also be provided.`);\n }\n if (params.accessKey && params.accessKey.startsWith(\"ASIA\") && !params.sessionToken) {\n throw new errors.InvalidArgumentError(`If specifying temporary access key, session token must also be provided.`);\n }\n\n const defaultPort = useSSL ? 443 : 80;\n this.port = port ?? defaultPort;\n this.host = endPoint.toLowerCase() + (this.port !== defaultPort ? `:${this.port}` : \"\");\n this.protocol = useSSL ? \"https:\" : \"http:\";\n this.accessKey = params.accessKey;\n this.#secretKey = params.secretKey ?? \"\";\n this.sessionToken = params.sessionToken;\n this.pathStyle = params.pathStyle ?? true; // Default path style is true\n this.pathPrefix = pathPrefix ?? \"\";\n this.defaultBucket = params.bucket;\n this.region = params.region;\n\n if (this.pathPrefix) {\n if (!this.pathStyle) {\n throw new errors.InvalidArgumentError(`pathPrefix is incompatible with pathStyle=false`);\n }\n if (!this.pathPrefix.startsWith(\"/\")) {\n throw new errors.InvalidArgumentError(`pathPrefix should start with /`);\n }\n if (this.pathPrefix.endsWith(\"/\")) {\n throw new errors.InvalidArgumentError(`pathPrefix should not end with /`);\n }\n }\n }\n\n /** Internal helper method to figure out which bucket name to use for a request */\n protected getBucketName(options: undefined | { bucketName?: string }): string {\n const bucketName = options?.bucketName ?? this.defaultBucket;\n if (bucketName === undefined || !isValidBucketName(bucketName)) {\n throw new errors.InvalidBucketNameError(bucketName ?? \"\");\n }\n return bucketName;\n }\n\n /**\n * Common code used for both \"normal\" requests and presigned URL requests\n */\n private buildRequestOptions(options: {\n objectName: string;\n bucketName?: string;\n headers?: Headers;\n query?: string | Record<string, string>;\n }): {\n headers: Headers;\n host: string;\n path: string;\n encodedPath: string;\n } {\n const bucketName = this.getBucketName(options);\n const host = this.pathStyle ? this.host : `${bucketName}.${this.host}`;\n const headers = options.headers ?? new Headers();\n headers.set(\"host\", host);\n const queryAsString = typeof options.query === \"object\"\n ? new URLSearchParams(options.query).toString().replace(\"+\", \"%20\") // Signing requires spaces become %20, never +\n : (options.query);\n\n const basePath = this.pathStyle\n ? `${this.pathPrefix}/${bucketName}/${options.objectName}`\n : `/${options.objectName}`;\n const querySuffix = queryAsString ? `?${queryAsString}` : \"\";\n const path = basePath + querySuffix;\n // For signing, we have to use the path as-is, but for making the request we have to be sure to\n // escape the '+' and '%' characters, or we'll get signing errors, at least with some S3 servers.\n const encodedPath = basePath.split(\"/\").map((part) => encodeURIComponent(part)).join(\"/\") + querySuffix;\n return { headers, host, path, encodedPath };\n }\n\n /**\n * Make a single request to S3\n */\n public async makeRequest({ method, payload, ...options }: {\n method: \"POST\" | \"GET\" | \"PUT\" | \"DELETE\" | string;\n headers?: Headers;\n query?: string | Record<string, string>;\n objectName: string;\n bucketName?: string;\n /** The status code we expect the server to return */\n statusCode?: number;\n /** The request body */\n payload?: Uint8Array_ | string;\n /**\n * returnBody: We have to read the request body to avoid leaking resources.\n * So by default this method will read and ignore the body. If you actually\n * need it, set returnBody: true and this function won't touch it so that\n * the caller can read it.\n */\n returnBody?: boolean;\n }): Promise<Response> {\n const date = new Date();\n const { headers, host, path, encodedPath } = this.buildRequestOptions(options);\n const statusCode = options.statusCode ?? 200;\n\n if (\n method === \"POST\" || method === \"PUT\" || method === \"DELETE\"\n ) {\n if (payload === undefined) {\n payload = new Uint8Array();\n } else if (typeof payload === \"string\") {\n payload = new TextEncoder().encode(payload);\n }\n headers.set(\"Content-Length\", String(payload.length));\n } else if (payload) {\n throw new Error(`Unexpected payload on ${method} request.`);\n }\n const sha256sum = await sha256digestHex(payload ?? new Uint8Array());\n headers.set(\"x-amz-date\", makeDateLong(date));\n headers.set(\"x-amz-content-sha256\", sha256sum);\n if (this.accessKey) {\n if (this.sessionToken) {\n headers.set(\"x-amz-security-token\", this.sessionToken);\n }\n headers.set(\n \"authorization\",\n await signV4({\n headers,\n method,\n path,\n accessKey: this.accessKey,\n secretKey: this.#secretKey,\n region: this.region,\n date,\n }),\n );\n }\n\n const fullUrl = `${this.protocol}//${host}${encodedPath}`;\n\n const response = await fetch(fullUrl, {\n method,\n headers,\n body: payload,\n });\n\n if (response.status !== statusCode) {\n if (response.status >= 400) {\n const error = await errors.parseServerError(response);\n throw error;\n } else if (response.status === 301) {\n // Unfortunately we are not allowed to access the Location header to know what the new location is.\n throw new errors.ServerError(\n response.status,\n \"UnexpectedRedirect\",\n `The server unexpectedly returned a redirect response. With AWS S3, this usually means you need to use a ` +\n `region-specific endpoint like \"s3.us-west-2.amazonaws.com\" instead of \"s3.amazonaws.com\"`,\n );\n }\n throw new errors.ServerError(\n response.status,\n \"UnexpectedStatusCode\",\n `Unexpected response code from the server (expected ${statusCode}, got ${response.status} ${response.statusText}).`,\n );\n }\n if (!options.returnBody) {\n // Just read the body and ignore its contents, to avoid leaking resources.\n await response.body?.getReader().read();\n }\n return response;\n }\n\n /**\n * Delete a single object.\n *\n * You can also pass a versionId to delete a specific version of an object.\n */\n async deleteObject(\n objectName: string,\n options: { bucketName?: string; versionId?: string; governanceBypass?: boolean } = {},\n ) {\n const bucketName = this.getBucketName(options);\n if (!isValidObjectName(objectName)) {\n throw new errors.InvalidObjectNameError(objectName);\n }\n\n const query: Record<string, string> = options.versionId ? { versionId: options.versionId } : {};\n const headers = new Headers();\n if (options.governanceBypass) {\n headers.set(\"X-Amz-Bypass-Governance-Retention\", \"true\");\n }\n\n await this.makeRequest({\n method: \"DELETE\",\n bucketName,\n objectName,\n headers,\n query,\n statusCode: 204,\n });\n }\n\n /**\n * Check if an object with the specified key exists.\n */\n public async exists(\n objectName: string,\n options?: { bucketName?: string; versionId?: string; headers?: Record<string, string> },\n ): Promise<boolean> {\n try {\n await this.statObject(objectName, options);\n return true;\n } catch (err: unknown) {\n if (err instanceof errors.ServerError && err.statusCode === 404) {\n return false;\n }\n throw err;\n }\n }\n\n /**\n * Get an object.\n *\n * Returns a standard HTTP Response object, which has many ways of consuming the response including\n * `.text()`, `.json()`, `.body` (ReadableStream), `.arrayBuffer()`, and `.blob()`.\n */\n public getObject(\n objectName: string,\n options?: {\n metadata?: ObjectMetadata;\n bucketName?: string;\n versionId?: string;\n responseParams?: ResponseOverrideParams;\n },\n ): Promise<Response> {\n return this.getPartialObject(objectName, { ...options, offset: 0, length: 0 });\n }\n\n /**\n * Stream a partial object, starting from the specified offset in bytes, up to the specified length in bytes.\n * A length of zero will return the rest of the object from the specified offset.\n * Pass a version UUID as \"versionId\" to download a specific version.\n *\n * Returns a standard HTTP Response object.\n */\n public async getPartialObject(\n objectName: string,\n { offset, length, ...options }: {\n offset: number;\n length: number;\n metadata?: ObjectMetadata;\n bucketName?: string;\n versionId?: string;\n responseParams?: ResponseOverrideParams;\n },\n ): Promise<Response> {\n const bucketName = this.getBucketName(options);\n if (!isValidObjectName(objectName)) {\n throw new errors.InvalidObjectNameError(objectName);\n }\n\n const headers = new Headers(Object.entries(options.metadata ?? {}));\n let statusCode = 200; // Expected status code\n if (offset || length) {\n let range = \"\";\n if (offset) {\n range = `bytes=${+offset}-`;\n } else {\n range = \"bytes=0-\";\n offset = 0;\n }\n if (length) {\n range += `${(+length + offset) - 1}`;\n }\n headers.set(\"Range\", range);\n statusCode = 206; // HTTP 206 \"Partial Content\"\n }\n\n // Create query string options\n const query: Record<string, string> = {\n ...options.responseParams,\n ...(options.versionId ? { versionId: options.versionId } : {}),\n };\n return await this.makeRequest({\n method: \"GET\",\n bucketName,\n objectName,\n headers,\n query,\n statusCode,\n returnBody: true,\n });\n }\n\n /**\n * Low-level method to generate a pre-signed URL.\n * @param method The HTTP method to use for the request\n * @param objectName The object name, e.g. \"path/to/file.txt\"\n * @param options Detailed options, such as expiry time for the pre-signed URL. Use expirySeconds to specify the expiry time; default is seven days.\n */\n getPresignedUrl(\n method: \"GET\" | \"PUT\" | \"HEAD\" | \"DELETE\",\n objectName: string,\n options: { bucketName?: string; parameters?: Record<string, string>; expirySeconds?: number; requestDate?: Date } =\n {},\n ): Promise<string> {\n if (!this.accessKey) {\n throw new errors.AccessKeyRequiredError();\n }\n if (!isValidObjectName(objectName)) {\n throw new errors.InvalidObjectNameError(objectName);\n }\n const { headers, path } = this.buildRequestOptions({\n objectName,\n bucketName: options.bucketName,\n query: options.parameters,\n });\n const requestDate = options.requestDate ?? new Date();\n const expirySeconds = options.expirySeconds ?? 24 * 60 * 60 * 7; // default expiration is 7 days in seconds.\n\n return presignV4({\n protocol: this.protocol,\n headers,\n method,\n path,\n accessKey: this.accessKey,\n secretKey: this.#secretKey,\n sessionToken: this.sessionToken,\n region: this.region,\n date: requestDate,\n expirySeconds,\n });\n }\n\n /**\n * Generate a pre-signed GET request URL.\n *\n * Use options.expirySeconds to override the expiration time (default is 7 days)\n */\n presignedGetObject(\n objectName: string,\n options: {\n bucketName?: string;\n versionId?: string;\n responseParams?: ResponseOverrideParams;\n expirySeconds?: number;\n requestDate?: Date;\n } = {},\n ): Promise<string> {\n const { versionId, responseParams, ...otherOptions } = options;\n const parameters: Record<string, string> = {\n ...responseParams,\n ...(versionId ? { versionId } : {}),\n };\n return this.getPresignedUrl(\"GET\", objectName, { parameters, ...otherOptions });\n }\n\n /**\n * List objects in the bucket, optionally filtered by the given key prefix.\n *\n * This returns a flat list; use listObjectsGrouped() for more advanced behavior.\n */\n public async *listObjects(\n options: {\n prefix?: string;\n bucketName?: string;\n /** Don't return more than this many results in total. Default: unlimited. */\n maxResults?: number;\n /**\n * How many keys to retrieve per HTTP request (default: 1000)\n * This is a maximum; sometimes fewer keys will be returned.\n * This will not affect the shape of the result, just its efficiency.\n */\n pageSize?: number;\n } = {},\n ): AsyncGenerator<S3Object, void, undefined> {\n for await (const result of this.listObjectsGrouped({ ...options, delimiter: \"\" })) {\n // Since we didn't specify a delimiter, listObjectsGrouped() should only return\n // actual object keys, not any CommonPrefix groupings.\n if (result.type === \"Object\") {\n yield result;\n } else {\n throw new Error(`Unexpected result from listObjectsGrouped(): ${result}`);\n }\n }\n }\n\n /**\n * List objects in the bucket, grouped based on the specified \"delimiter\".\n *\n * See https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-prefixes.html\n */\n public async *listObjectsGrouped(\n options: {\n delimiter: string;\n prefix?: string;\n bucketName?: string;\n /** Don't return more than this many results in total. Default: unlimited. */\n maxResults?: number;\n /**\n * How many keys to retrieve per HTTP request (default: 1000)\n * This is a maximum; sometimes fewer keys will be returned.\n * This will not affect the shape of the result, just its efficiency.\n */\n pageSize?: number;\n },\n ): AsyncGenerator<S3Object | CommonPrefix, void, undefined> {\n const bucketName = this.getBucketName(options);\n let continuationToken = \"\";\n const pageSize = options.pageSize ?? 1_000;\n if (pageSize < 1 || pageSize > 1_000) {\n throw new errors.InvalidArgumentError(\"pageSize must be between 1 and 1,000.\");\n }\n let resultCount = 0; // Count the total number of results\n\n while (true) {\n // How many results to fetch in the next request:\n const maxKeys = options.maxResults ? Math.min(pageSize, options.maxResults - resultCount) : pageSize;\n if (maxKeys === 0) {\n return;\n }\n // Fetch the next page of results:\n const pageResponse = await this.makeRequest({\n method: \"GET\",\n bucketName,\n objectName: \"\",\n query: {\n \"list-type\": \"2\",\n prefix: options.prefix ?? \"\",\n delimiter: options.delimiter,\n \"max-keys\": String(maxKeys),\n ...(continuationToken ? { \"continuation-token\": continuationToken } : {}),\n },\n returnBody: true,\n });\n const responseText = await pageResponse.text();\n // Parse the response XML.\n // See https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html#API_ListObjectsV2_ResponseSyntax\n const root = parseXML(responseText).root;\n if (!root || root.name !== \"ListBucketResult\") {\n throw new Error(`Unexpected response: ${responseText}`);\n }\n // If a delimiter was specified, first return any common prefixes from this page of results:\n const prefixElements = root.children\n .filter((c) => c.name === \"CommonPrefixes\")\n .flatMap((c) => c.children);\n const toYield: Array<S3Object | CommonPrefix> = [];\n for (const prefixElement of prefixElements) {\n toYield.push({\n type: \"CommonPrefix\",\n prefix: prefixElement.content ?? \"\",\n });\n resultCount++;\n }\n // Now return all regular object keys found in the result:\n for (const objectElement of root.children.filter((c) => c.name === \"Contents\")) {\n toYield.push({\n type: \"Object\",\n key: objectElement.children.find((c) => c.name === \"Key\")?.content ?? \"\",\n etag: sanitizeETag(objectElement.children.find((c) => c.name === \"ETag\")?.content ?? \"\"),\n size: parseInt(objectElement.children.find((c) => c.name === \"Size\")?.content ?? \"\", 10),\n lastModified: new Date(objectElement.children.find((c) => c.name === \"LastModified\")?.content ?? \"invalid\"),\n });\n resultCount++;\n }\n // Now, interlace the commonprefixes and regular objects, so that the overall result stays sorted\n // in alphabetical order, instead of mixed by common prefixes first then other entries later.\n // This way guarantees consistent behavior regardless of page size.\n toYield.sort((a, b) => {\n const aStr = a.type === \"Object\" ? a.key : a.prefix;\n const bStr = b.type === \"Object\" ? b.key : b.prefix;\n return aStr > bStr ? 1 : aStr < bStr ? -1 : 0;\n });\n for (const entry of toYield) {\n yield entry;\n }\n const isTruncated = root.children.find((c) => c.name === \"IsTruncated\")?.content === \"true\";\n if (isTruncated) {\n // There are more results.\n const nextContinuationToken = root.children.find((c) => c.name === \"NextContinuationToken\")?.content;\n if (!nextContinuationToken) {\n throw new Error(\"Unexpectedly missing continuation token, but server said there are more results.\");\n }\n continuationToken = nextContinuationToken;\n } else {\n // That's it, no more results.\n return;\n }\n }\n }\n\n /**\n * Upload an object\n */\n async putObject(\n objectName: string,\n streamOrData: ReadableStream<Uint8Array> | Uint8Array | string,\n options?: {\n metadata?: ObjectMetadata;\n size?: number;\n bucketName?: string;\n /**\n * For large uploads, split them into parts of this size.\n * Default: 64MB if object size is known, 500MB if total object size is unknown.\n * This is a minimum; larger part sizes may be required for large uploads or if the total size is unknown.\n */\n partSize?: number;\n },\n ): Promise<UploadedObjectInfo> {\n const bucketName = this.getBucketName(options);\n if (!isValidObjectName(objectName)) {\n throw new errors.InvalidObjectNameError(objectName);\n }\n\n // Prepare a readable stream for the upload:\n let size: number | undefined;\n let stream: ReadableStream<Uint8Array>;\n if (typeof streamOrData === \"string\") {\n // Convert to binary using UTF-8\n const binaryData = new TextEncoder().encode(streamOrData);\n if (typeof ReadableStream.from !== \"undefined\") {\n stream = ReadableStream.from([binaryData]);\n } else {\n // ReadableStream.from is not yet supported by some runtimes :/\n // https://github.com/oven-sh/bun/issues/3700\n // https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/from_static#browser_compatibility\n // deno-fmt-ignore\n stream = new ReadableStream({ start(c) { c.enqueue(binaryData); c.close(); } });\n }\n size = binaryData.length;\n } else if (streamOrData instanceof Uint8Array) {\n if (typeof ReadableStream.from !== \"undefined\") {\n stream = ReadableStream.from([streamOrData]);\n } else {\n // deno-fmt-ignore\n stream = new ReadableStream({ start(c) { c.enqueue(streamOrData); c.close(); } });\n }\n size = streamOrData.byteLength;\n } else if (streamOrData instanceof ReadableStream) {\n stream = streamOrData;\n } else {\n throw new errors.InvalidArgumentError(\n `Invalid stream/data type provided.`,\n );\n }\n\n // Validate the size parameter\n if (options?.size !== undefined) {\n if (size !== undefined && options?.size !== size) {\n throw new errors.InvalidArgumentError(\n `size was specified (${options.size}) but doesn't match auto-detected size (${size}).`,\n );\n }\n if (typeof options.size !== \"number\" || options.size < 0 || isNaN(options.size)) {\n throw new errors.InvalidArgumentError(\n `invalid size specified: ${options.size}`,\n );\n } else {\n size = options.size;\n }\n }\n\n // Determine the part size, if we may need to do a multi-part upload.\n const partSize = options?.partSize ?? this.calculatePartSize(size);\n if (partSize < minimumPartSize) {\n throw new errors.InvalidArgumentError(`Part size should be greater than 5MB`);\n } else if (partSize > maximumPartSize) {\n throw new errors.InvalidArgumentError(`Part size should be less than 6MB`);\n }\n\n // s3 requires that all non-end chunks be at least `this.partSize`,\n // so we chunk the stream until we hit either that size or the end before\n // we flush it to s3.\n const chunker = new TransformChunkSizes(partSize);\n\n // This is a Writable stream that can be written to in order to upload\n // to the specified bucket and object automatically.\n const uploader = new ObjectUploader({\n client: this,\n bucketName,\n objectName,\n partSize,\n metadata: options?.metadata ?? {},\n });\n // stream => chunker => uploader\n await stream.pipeThrough(chunker).pipeTo(uploader);\n return uploader.getResult();\n }\n\n /**\n * Calculate part size given the object size. Part size will be at least this.partSize.\n *\n * Per https://docs.aws.amazon.com/AmazonS3/latest/userguide/qfacts.html we have to\n * stick to the following rules:\n * - part size between 5MB (this.maximumPartSize) and 5GB (this.maxObjectSize)\n * (the final part can be smaller than 5MB however)\n * - maximum of 10,000 parts per upload\n * - maximum object size of 5TB\n */\n protected calculatePartSize(size: number | undefined): number {\n if (size === undefined) {\n // If we don't know the total size (e.g. we're streaming data), assume it's\n // the largest allowed object size, so we can guarantee the upload works\n // regardless of the total size.\n size = maxObjectSize;\n }\n if (size > maxObjectSize) {\n throw new TypeError(`size should not be more than ${maxObjectSize}`);\n }\n let partSize = 64 * 1024 * 1024; // Start with 64MB\n while (true) {\n // If partSize is big enough to accomodate the object size, then use it.\n if ((partSize * 10_000) > size) {\n return partSize;\n }\n // Try part sizes as 64MB, 80MB, 96MB etc.\n partSize += 16 * 1024 * 1024;\n }\n }\n\n /**\n * Get detailed information about an object.\n */\n public async statObject(\n objectName: string,\n options?: {\n bucketName?: string;\n versionId?: string;\n /**\n * Additional headers to include in the request\n */\n headers?: Record<string, string>;\n },\n ): Promise<ObjectStatus> {\n const bucketName = this.getBucketName(options);\n if (!isValidObjectName(objectName)) {\n throw new errors.InvalidObjectNameError(objectName);\n }\n const query: Record<string, string> = {};\n if (options?.versionId) {\n query.versionId = options.versionId;\n }\n\n const response = await this.makeRequest({\n method: \"HEAD\",\n bucketName,\n objectName,\n query,\n // Add custom headers if provided\n headers: new Headers(options?.headers),\n });\n\n const metadata: ObjectMetadata = {};\n for (const header of metadataKeys) {\n if (response.headers.has(header)) {\n metadata[header] = response.headers.get(header) as string;\n }\n }\n // Also add in custom metadata\n response.headers.forEach((_value, key) => {\n if (key.startsWith(\"x-amz-meta-\")) {\n metadata[key as `x-amz-meta-${string}`] = response.headers.get(key) as string;\n }\n });\n\n return {\n type: \"Object\",\n key: objectName,\n size: parseInt(response.headers.get(\"content-length\") ?? \"\", 10),\n metadata,\n lastModified: new Date(response.headers.get(\"Last-Modified\") ?? \"error: missing last modified\"),\n versionId: response.headers.get(\"x-amz-version-id\") || null,\n etag: sanitizeETag(response.headers.get(\"ETag\") ?? \"\"),\n };\n }\n\n /**\n * Copy an object into this bucket\n */\n public async copyObject(\n source: { sourceBucketName?: string; sourceKey: string; sourceVersionId?: string },\n objectName: string,\n options?: {\n bucketName?: string;\n /** Metadata for the new object. If not specified, metadata will be copied from the source. */\n metadata?: ObjectMetadata;\n },\n ): Promise<CopiedObjectInfo> {\n const bucketName = this.getBucketName(options);\n const sourceBucketName = source.sourceBucketName ?? bucketName;\n if (!isValidObjectName(objectName)) {\n throw new errors.InvalidObjectNameError(objectName);\n }\n\n // The \"x-amz-copy-source\" header is like \"bucket/objectkey\" with an optional version ID.\n // e.g. \"awsexamplebucket/reports/january.pdf?versionId=QUpfdndhfd8438MNFDN93jdnJFkdmqnh893\"\n let xAmzCopySource = `${sourceBucketName}/${\n source.sourceKey.split(\"/\").map((part) => encodeURIComponent(part)).join(\"/\")\n }`;\n if (source.sourceVersionId) xAmzCopySource += `?versionId=${source.sourceVersionId}`;\n\n const headers = new Headers(options?.metadata);\n if (options?.metadata !== undefined) {\n headers.set(\"x-amz-metadata-directive\", \"REPLACE\");\n }\n headers.set(\"x-amz-copy-source\", xAmzCopySource);\n\n const response = await this.makeRequest({ method: \"PUT\", bucketName, objectName, headers, returnBody: true });\n\n const responseText = await response.text();\n // Parse the response XML.\n // See https://docs.aws.amazon.com/AmazonS3/latest/API/API_CopyObject.html#API_CopyObject_ResponseSyntax\n const root = parseXML(responseText).root;\n if (!root || root.name !== \"CopyObjectResult\") {\n throw new Error(`Unexpected response: ${responseText}`);\n }\n const etagString = root.children.find((c) => c.name === \"ETag\")?.content ?? \"\";\n const lastModifiedString = root.children.find((c) => c.name === \"LastModified\")?.content;\n if (lastModifiedString === undefined) {\n throw new Error(\"Unable to find <LastModified>...</LastModified> from the server.\");\n }\n\n return {\n copySourceVersionId: response.headers.get(\"x-amz-copy-source-version-id\") || null,\n etag: sanitizeETag(etagString),\n lastModified: new Date(lastModifiedString),\n versionId: response.headers.get(\"x-amz-version-id\") || null,\n };\n }\n\n /** Check if a bucket exists */\n public async bucketExists(bucketName: string): Promise<boolean> {\n try {\n const objects = this.listObjects({ bucketName });\n // We don't need to fully list the objects, just check if we can start listing\n await objects.next();\n return true;\n } catch (err: unknown) {\n if (err instanceof errors.ServerError && err.statusCode === 404) {\n return false;\n }\n throw err;\n }\n }\n\n /** Create a new bucket */\n public async makeBucket(bucketName: string): Promise<void> {\n await this.makeRequest({\n method: \"PUT\",\n bucketName: this.getBucketName({ bucketName }),\n objectName: \"\",\n statusCode: 200,\n });\n }\n\n /** Delete a bucket (must be empty) */\n public async removeBucket(bucketName: string): Promise<void> {\n await this.makeRequest({\n method: \"DELETE\",\n bucketName: this.getBucketName({ bucketName }),\n objectName: \"\",\n statusCode: 204,\n });\n }\n\n /**\n * Creates a presigned POST policy that can be used to allow browser/client uploads directly to S3.\n * This is equivalent to AWS SDK's createPresignedPost functionality.\n *\n * @param objectName - Object name for which the presigned URL is generated\n * @param options - Additional options\n * @returns An object with url and fields that can be used to construct a form for direct uploads\n */\n presignedPostObject(\n objectName: string,\n options: {\n /**\n * Bucket name to use for this operation. If not specified, the default bucket name will be used.\n */\n bucketName?: string;\n /**\n * Expiry time in seconds for the presigned URL. Default is 1 hour (3600 seconds).\n */\n expirySeconds?: number;\n /**\n * Date when the presigned URL becomes valid. Default is now.\n */\n requestDate?: Date;\n /**\n * Additional policy conditions to apply.\n * See: https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-HTTPPOSTConstructPolicy.html\n */\n conditions?: PolicyCondition[];\n /**\n * Additional form fields to include in the policy and the result.\n */\n fields?: Record<string, string>;\n } = {},\n ): Promise<PresignedPostResult> {\n if (!isValidObjectName(objectName)) {\n throw new errors.InvalidObjectNameError(objectName);\n }\n\n const bucketName = this.getBucketName(options);\n if (!bucketName) {\n throw new Error(\n \"Bucket name is required for presignedPost, but none was provided either to this method nor to the client constructor\",\n );\n }\n\n // Build request options\n const requestDate = options.requestDate || new Date();\n const expirySeconds = options.expirySeconds ?? 3600; // Default 1 hour\n\n return presignPostV4({\n protocol: this.protocol,\n host: this.host,\n bucket: bucketName,\n objectKey: objectName,\n accessKey: this.accessKey || \"\",\n secretKey: this.#secretKey || \"\",\n region: this.region,\n date: requestDate,\n expirySeconds,\n conditions: options.conditions,\n fields: options.fields,\n });\n }\n}\n","/**\n * This stream transform will buffer the data it receives until it has enough to form\n * a chunk of the specified size, then pass on the data in chunks of the specified size.\n */\nexport class TransformChunkSizes extends TransformStream<Uint8Array, Uint8Array> {\n constructor(private readonly outChunkSize: number) {\n // We'll keep one internal buffer of size outChunkSize,\n // plus a current \"offset\" telling us how many bytes are in it.\n let buffer = new Uint8Array(outChunkSize);\n let offset = 0;\n\n super({\n transform(chunk, controller) {\n let pos = 0;\n while (pos < chunk.length) {\n // How many bytes remain to fill the buffer?\n const needed = outChunkSize - offset;\n // How many bytes we can copy from the incoming chunk this iteration\n const toCopy = Math.min(needed, chunk.length - pos);\n\n // Copy from chunk into our internal buffer\n buffer.set(chunk.subarray(pos, pos + toCopy), offset);\n pos += toCopy;\n offset += toCopy;\n\n // If we've filled a chunk, push it to the output, then reset\n if (offset === outChunkSize) {\n controller.enqueue(buffer);\n // We must not reuse that buffer, because it's still being read by the controller.\n buffer = new Uint8Array(outChunkSize);\n offset = 0;\n }\n }\n },\n flush(controller) {\n // If anything remains in the buffer at the end, enqueue it.\n if (offset > 0) {\n controller.enqueue(buffer.subarray(0, offset));\n }\n },\n });\n }\n}\n","/**\n * @module\n * All the errors which can be thrown by this S3 client.\n * Every error is a subclass of S3Error.\n */\n\nimport { parse as parseXML } from \"./xml-parser.ts\";\n\n/**\n * Base class for all errors raised by this S3 client.\n */\nexport class S3Error extends Error {}\n\n// Preserve API compatibility with the old name:\n/** @deprecated Use `S3Error` instead. */\nexport const DenoS3LiteClientError = S3Error;\n\n/**\n * An argument or configuration parameter was invalid.\n */\nexport class InvalidArgumentError extends S3Error {}\n\n/**\n * InvalidEndpointError is generated when an invalid end point value is\n * provided which does not follow domain standards.\n */\nexport class InvalidEndpointError extends S3Error {}\n\n/**\n * InvalidBucketNameError is generated when an invalid bucket name is\n * provided which does not follow AWS S3 specifications.\n * http://docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html\n */\nexport class InvalidBucketNameError extends S3Error {\n constructor(public readonly bucketName: string) {\n super(`Invalid bucket name: ${bucketName}`);\n }\n}\n\n/**\n * InvalidObjectNameError is generated when an invalid object name is\n * provided which does not follow AWS S3 specifications.\n * http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html\n */\nexport class InvalidObjectNameError extends S3Error {\n constructor(public readonly objectName: string) {\n super(`Invalid object name: ${objectName}`);\n }\n}\n\n/** The request cannot be made without an access key to authenticate it */\nexport class AccessKeyRequiredError extends S3Error {\n constructor() {\n super(\"accessKey is required\");\n }\n}\n\n/** The request cannot be made without a secret key to authenticate it */\nexport class SecretKeyRequiredError extends S3Error {\n constructor() {\n super(\"secretKey is required\");\n }\n}\n\n/** The expiration time for the request is invalid */\nexport class InvalidExpiryError extends S3Error {\n constructor() {\n super(\"expirySeconds cannot be less than 1 second or more than 7 days\");\n }\n}\n\n/** Any error thrown by the server */\nexport class ServerError extends S3Error {\n readonly key: string | undefined;\n readonly bucketName: string | undefined;\n readonly resource: string | undefined;\n readonly region: string | undefined;\n\n constructor(\n public readonly statusCode: number,\n public readonly code: string,\n message: string,\n otherData: { key?: string; bucketName?: string; resource?: string; region?: string } = {},\n ) {\n super(message);\n this.key = otherData.key;\n this.bucketName = otherData.bucketName;\n this.resource = otherData.resource;\n this.region = otherData.region;\n }\n}\n\n/** Helper function to parse an error returned by the S3 server. */\nexport async function parseServerError(response: Response): Promise<ServerError> {\n try {\n const xmlParsed = parseXML(await response.text());\n const errorRoot = xmlParsed.root;\n if (errorRoot?.name !== \"Error\") {\n throw new Error(\"Invalid root, expected <Error>\");\n }\n const code = errorRoot.children.find((c) => c.name === \"Code\")?.content ?? \"UnknownErrorCode\";\n const message = errorRoot.children.find((c) => c.name === \"Message\")?.content ??\n \"The error message could not be determined.\";\n const key = errorRoot.children.find((c) => c.name === \"Key\")?.content;\n const bucketName = errorRoot.children.find((c) => c.name === \"BucketName\")?.content;\n const resource = errorRoot.children.find((c) => c.name === \"Resource\")?.content; // e.g. the object key\n const region = errorRoot.children.find((c) => c.name === \"Region\")?.content;\n return new ServerError(response.status, code, message, { key, bucketName, resource, region });\n } catch {\n return new ServerError(\n response.status,\n \"UnrecognizedError\",\n `Error: Unexpected response code ${response.status} ${response.statusText}. Unable to parse response as XML.`,\n );\n }\n}\n","/**\n * Basic XML parser for Deno\n * https://github.com/nekobato/deno-xml-parser\n * By Hayato Koriyama, MIT licensed\n * Based on https://github.com/segmentio/xml-parser (MIT licensed)\n * \"Simple non-compliant XML parser because we just need to parse some basic responses\"\n */\n\ninterface Document {\n declaration: {\n attributes: Record<string, string>;\n };\n root: Xml | undefined;\n}\n\ninterface Xml {\n name: string;\n attributes: Record<string, string>;\n content?: string;\n children: Xml[];\n}\n\n/**\n * Parse the given string of `xml`.\n */\nexport function parse(xml: string): Document {\n xml = xml.trim();\n\n // strip comments\n xml = xml.replace(/<!--[\\s\\S]*?-->/g, \"\");\n\n return document();\n\n /**\n * XML document.\n */\n function document(): Document {\n return {\n declaration: declaration(),\n root: tag(),\n };\n }\n\n /**\n * Declaration.\n */\n function declaration() {\n const m = match(/^<\\?xml\\s*/);\n if (!m) return;\n\n // tag.\n // deno-lint-ignore no-explicit-any\n const node: any = {\n attributes: {},\n };\n\n // attributes\n while (!(eos() || is(\"?>\"))) {\n const attr = attribute();\n if (!attr) return node;\n node.attributes[attr.name] = attr.value;\n }\n\n match(/\\?>\\s*/);\n\n return node;\n }\n\n /**\n * Tag.\n */\n function tag() {\n const m = match(/^<([\\w-:.]+)\\s*/);\n if (!m) return;\n\n // name\n const node: Xml = {\n name: m[1],\n attributes: {},\n children: [],\n };\n\n // attributes\n while (!(eos() || is(\">\") || is(\"?>\") || is(\"/>\"))) {\n const attr = attribute();\n if (!attr) return node;\n node.attributes[attr.name] = attr.value;\n }\n\n // self closing tag\n if (match(/^\\s*\\/>\\s*/)) {\n return node;\n }\n\n match(/\\??>\\s*/);\n\n // content\n node.content = content();\n\n // children\n let child;\n while ((child = tag())) {\n node.children.push(child);\n }\n\n // closing\n match(/^<\\/[\\w-:.]+>\\s*/);\n\n return node;\n }\n\n /**\n * Text content.\n */\n function content() {\n const m = match(/^([^<]*)/);\n if (m) return entities(m[1]);\n return \"\";\n }\n\n /**\n * Attribute.\n */\n function attribute() {\n const m = match(/([\\w:-]+)\\s*=\\s*(\"[^\"]*\"|'[^']*'|\\w+)\\s*/);\n if (!m) return;\n return { name: m[1], value: entities(strip(m[2])) };\n }\n\n /**\n * Strip quotes from `val`.\n */\n function strip(val: string) {\n return val.replace(/^['\"]|['\"]$/g, \"\");\n }\n\n /** Basic handling of entities: & < > */\n function entities(val: string) {\n return val.replaceAll(\"<\", \"<\").replaceAll(\">\", \">\").replaceAll(\"&\", \"&\");\n }\n\n /**\n * Match `re` and advance the string.\n */\n function match(re: RegExp) {\n const m = xml.match(re);\n if (!m) return;\n xml = xml.slice(m[0].length);\n return m;\n }\n\n /**\n * End-of-source.\n */\n function eos() {\n return xml.length === 0;\n }\n\n /**\n * Check for `prefix`.\n */\n function is(prefix: string) {\n return xml.startsWith(prefix);\n }\n}\n","/**\n * For TypeScript 5.7+ we have to write `Uint8Array<ArrayBuffer>` instead of\n * `Uint8Array` or we'll get type errors in various places where arrays based\n * on SharedArrayBuffer are not allowed. This type alias will work both pre-\n * and post- TypeScript 5.7. Yes this is annoying.\n */\nexport type Uint8Array_ = ReturnType<Uint8Array[\"slice\"]>;\n\nexport function isValidPort(port: number) {\n // verify if port is a number.\n if (typeof port !== \"number\" || isNaN(port)) {\n return false;\n }\n // Verify if port is in range.\n return port >= 1 && port <= 65535;\n}\n\n/**\n * Validate a bucket name.\n *\n * This is pretty minimal, general validation. We let the remote\n * S3 server do detailed validation.\n *\n * https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html\n */\nexport function isValidBucketName(bucket: string): boolean {\n if (typeof bucket !== \"string\") {\n return false;\n }\n // Generally the bucket name length limit is 63, but\n // \"Before March 1, 2018, buckets created in the US East (N. Virginia)\n // Region could have names that were up to 255 characters long\"\n if (bucket.length > 255) {\n return false;\n }\n // \"Bucket names must not contain two adjacent periods.\"\n if (bucket.includes(\"..\")) {\n return false;\n }\n // \"Bucket names must begin and end with a letter or number.\"\n // \"Bucket names can consist only of lowercase letters, numbers,\n // periods (.), and hyphens (-).\"\n // -> Most S3 servers require lowercase bucket names but some allow\n // uppercase (Backblaze, AWS us-east buckets created before 2018)\n return Boolean(bucket.match(/^[a-zA-Z0-9][a-zA-Z0-9.-]+[a-zA-Z0-9]$/));\n}\n\n/**\n * check if objectName is a valid object name\n * http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html\n */\nexport function isValidObjectName(objectName: string) {\n if (!isValidPrefix(objectName)) return false;\n if (objectName.length === 0) return false;\n return true;\n}\n\n// check if prefix is valid\nexport function isValidPrefix(prefix: string) {\n if (typeof prefix !== \"string\") return false;\n if (prefix.length > 1024) return false;\n return true;\n}\n\n/**\n * Convert some binary data to a hex string\n */\nexport function bin2hex(binary: Uint8Array) {\n return Array.from(binary).map((b) => b.toString(16).padStart(2, \"0\")).join(\n \"\",\n );\n}\n\nexport function sanitizeETag(etag = \"\") {\n const replaceChars: Record<string, string> = {\n '\"': \"\",\n \""\": \"\",\n \""\": \"\",\n \""\": \"\",\n \""\": \"\",\n };\n return etag.replace(\n /^(\"|"|")|(\"|"|")$/g,\n (m) => replaceChars[m],\n );\n}\n\nexport function getVersionId(headers: Headers): string | null {\n return headers.get(\"x-amz-version-id\") ?? null;\n}\n\n/** Create a Date string with format: 'YYYYMMDDTHHmmss' + Z */\nexport function makeDateLong(date: Date) {\n // Gives format like: '2017-08-07T16:28:59.889Z'\n const dateStr = date.toISOString();\n\n return dateStr.slice(0, 4) +\n dateStr.slice(5, 7) +\n dateStr.slice(8, 13) +\n dateStr.slice(14, 16) +\n dateStr.slice(17, 19) + \"Z\";\n}\n\n/** Create a Date string with format: 'YYYYMMDD' */\nexport function makeDateShort(date: Date) {\n return makeDateLong(date).slice(0, 8);\n}\n\nexport function getScope(region: string, date: Date) {\n return `${makeDateShort(date)}/${region}/s3/aws4_request`;\n}\n\nexport async function sha256digestHex(data: Uint8Array_ | string) {\n if (!(data instanceof Uint8Array)) {\n data = new TextEncoder().encode(data);\n }\n return bin2hex(new Uint8Array(await crypto.subtle.digest(\"SHA-256\", data)));\n}\n","import type { Client, ObjectMetadata, UploadedObjectInfo } from \"./client.ts\";\nimport { getVersionId, sanitizeETag, type Uint8Array_ } from \"./helpers.ts\";\nimport { parse as parseXML } from \"./xml-parser.ts\";\n\n// Metadata headers that must be included in each part of a multi-part upload\nconst multipartTagAlongMetadataKeys = [\n \"x-amz-server-side-encryption-customer-algorithm\",\n \"x-amz-server-side-encryption-customer-key\",\n \"x-amz-server-side-encryption-customer-key-MD5\",\n];\n\n/**\n * Stream a file to S3\n *\n * We assume that TransformChunkSizes has been used first, so that this stream\n * will always receive chunks of exactly size \"partSize\", except for the final\n * chunk.\n *\n * Note that the total size of the upload doesn't have to be known in advance,\n * as long as TransformChunkSizes was used first. Then this ObjectUploader\n * will decide based on the size of the first chunk whether it is doing a\n * single-request upload or a multi-part upload.\n */\nexport class ObjectUploader extends WritableStream<Uint8Array_> {\n public readonly getResult: () => UploadedObjectInfo;\n\n constructor({ client, bucketName, objectName, partSize, metadata }: {\n client: Client;\n bucketName: string;\n objectName: string;\n partSize: number;\n metadata: Record<string, string>;\n }) {\n let result: UploadedObjectInfo;\n let nextPartNumber = 1;\n let uploadId: string;\n const etags: { part: number; etag: string }[] = [];\n /** If an error occurs during multi-part uploads, we temporarily store it here. */\n let multiUploadError: Error | undefined;\n /** If doing multi-part upload, this holds a promise for each part so we can upload them in parallel */\n const partsPromises: Promise<Response | void>[] = [];\n\n super({\n start() {}, // required\n async write(chunk, _controller) {\n const method = \"PUT\";\n const partNumber = nextPartNumber++;\n\n try {\n // We are going to upload this file in a single part, because it's small enough\n if (partNumber == 1 && chunk.length < partSize) {\n // PUT the chunk in a single request — use an empty query.\n const response = await client.makeRequest({\n method,\n headers: new Headers({\n // Set user metadata as this is not a multipart upload\n ...metadata,\n \"Content-Length\": String(chunk.length),\n }),\n bucketName,\n objectName,\n payload: chunk,\n });\n result = {\n etag: sanitizeETag(response.headers.get(\"etag\") ?? undefined),\n versionId: getVersionId(response.headers),\n };\n return;\n }\n\n /// If we get here, this is a streaming upload in multiple parts.\n if (partNumber === 1) {\n uploadId = (await initiateNewMultipartUpload({\n client,\n bucketName,\n objectName,\n metadata,\n })).uploadId;\n }\n // Upload the next part\n const partHeaders: Record<string, string> = {\n \"Content-Length\": String(chunk.length),\n };\n for (const key of multipartTagAlongMetadataKeys) {\n const value = metadata[key];\n if (value) {\n partHeaders[key] = value;\n }\n }\n const partPromise = client.makeRequest({\n method,\n query: { partNumber: partNumber.toString(), uploadId },\n headers: new Headers(partHeaders),\n bucketName: bucketName,\n objectName: objectName,\n payload: chunk,\n }).then((response) => {\n // In order to aggregate the parts together, we need to collect the etags.\n let etag = response.headers.get(\"etag\") ?? \"\";\n if (etag) {\n etag = etag.replace(/^\"/, \"\").replace(/\"$/, \"\");\n }\n etags.push({ part: partNumber, etag });\n return response;\n });\n // We can't `await partPromise` now, because that will cause the uploads to\n // happen in series instead of parallel. But we don't want to let the promise\n // throw an exception when we haven't awaited it, because that can cause the\n // process to crash. So use .catch() to watch for errors and store them in\n // `multiUploadError` if they occur.\n partsPromises.push(partPromise.catch((err) => {\n // An error occurred when uploading this one part:\n if (!multiUploadError) {\n multiUploadError = err;\n }\n }));\n } catch (err) {\n // Throwing an error will make future writes to this sink fail.\n throw err;\n }\n },\n async close() {\n if (result) {\n // This was already completed, in a single upload. Nothing more to do.\n } else if (uploadId) {\n // Wait for all parts to finish uploading (or fail)\n await Promise.all(partsPromises);\n if (multiUploadError) {\n // One or more parts failed to upload:\n throw multiUploadError;\n }\n // Sort the etags (required)\n etags.sort((a, b) => a.part > b.part ? 1 : -1);\n // Complete the multi-part upload\n result = await completeMultipartUpload({ client, bucketName, objectName, uploadId, etags });\n } else {\n throw new Error(\"Stream was closed without uploading any data.\");\n }\n },\n });\n this.getResult = () => {\n if (result === undefined) {\n throw new Error(\"Result is not ready. await the stream first.\");\n }\n return result;\n };\n }\n}\n\n/** Initiate a new multipart upload request. */\nasync function initiateNewMultipartUpload(\n options: {\n client: Client;\n bucketName: string;\n objectName: string;\n metadata?: ObjectMetadata;\n },\n): Promise<{ uploadId: string }> {\n const method = \"POST\";\n const headers = new Headers(options.metadata);\n const query = \"uploads\";\n const response = await options.client.makeRequest({\n method,\n bucketName: options.bucketName,\n objectName: options.objectName,\n query,\n headers,\n returnBody: true,\n });\n // Response is like:\n // <InitiateMultipartUploadResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">\n // <Bucket>dev-bucket</Bucket>\n // <Key>test-32m.dat</Key>\n // <UploadId>422f976b-35e0-4a55-aca7-bf2d46277f93</UploadId>\n // </InitiateMultipartUploadResult>\n const responseText = await response.text();\n const root = parseXML(responseText).root;\n if (!root || root.name !== \"InitiateMultipartUploadResult\") {\n throw new Error(`Unexpected response: ${responseText}`);\n }\n const uploadId = root.children.find((c) => c.name === \"UploadId\")?.content;\n if (!uploadId) {\n throw new Error(`Unable to get UploadId from response: ${responseText}`);\n }\n return { uploadId };\n}\n\nasync function completeMultipartUpload(\n { client, bucketName, objectName, uploadId, etags }: {\n client: Client;\n bucketName: string;\n objectName: string;\n uploadId: string;\n etags: { part: number; etag: string }[];\n },\n): Promise<UploadedObjectInfo> {\n const payload = `\n <CompleteMultipartUpload xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">\n ${etags.map((et) => ` <Part><PartNumber>${et.part}</PartNumber><ETag>${et.etag}</ETag></Part>`).join(\"\\n\")}\n </CompleteMultipartUpload>\n `;\n const response = await client.makeRequest({\n method: \"POST\",\n bucketName,\n objectName,\n query: `uploadId=${encodeURIComponent(uploadId)}`,\n payload: new TextEncoder().encode(payload),\n returnBody: true,\n });\n const responseText = await response.text();\n // Example response:\n // <?xml version=\"1.0\" encoding=\"UTF-8\"?>\n // <CompleteMultipartUploadResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">\n // <Location>http://localhost:9000/dev-bucket/test-32m.dat</Location>\n // <Bucket>dev-bucket</Bucket>\n // <Key>test-32m.dat</Key>\n // <ETag>"4581589392ae60eafdb031f441858c7a-7"</ETag>\n // </CompleteMultipartUploadResult>\n const root = parseXML(responseText).root;\n if (!root || root.name !== \"CompleteMultipartUploadResult\") {\n throw new Error(`Unexpected response: ${responseText}`);\n }\n const etagRaw = root.children.find((c) => c.name === \"ETag\")?.content;\n if (!etagRaw) throw new Error(`Unable to get ETag from response: ${responseText}`);\n const versionId = getVersionId(response.headers);\n return {\n etag: sanitizeETag(etagRaw),\n versionId,\n };\n}\n","import * as errors from \"./errors.ts\";\nimport { bin2hex, getScope, makeDateLong, makeDateShort, sha256digestHex, type Uint8Array_ } from \"./helpers.ts\";\n\nconst signV4Algorithm = \"AWS4-HMAC-SHA256\";\n\n/**\n * Generate the Authorization header required to authenticate an S3/AWS request.\n */\nexport async function signV4(request: {\n headers: Headers;\n method: string;\n path: string;\n accessKey: string;\n secretKey: string;\n region: string;\n date: Date;\n}): Promise<string> {\n if (!request.accessKey) {\n throw new errors.AccessKeyRequiredError();\n }\n if (!request.secretKey) {\n throw new errors.SecretKeyRequiredError();\n }\n\n const sha256sum = request.headers.get(\"x-amz-content-sha256\");\n if (sha256sum === null) {\n throw new Error(\n \"Internal S3 client error - expected x-amz-content-sha256 header, but it's missing.\",\n );\n }\n\n const signedHeaders = getHeadersToSign(request.headers);\n const canonicalRequest = getCanonicalRequest(\n request.method,\n request.path,\n request.headers,\n signedHeaders,\n sha256sum,\n );\n const stringToSign = await getStringToSign(\n canonicalRequest,\n request.date,\n request.region,\n );\n const signingKey = await getSigningKey(\n request.date,\n request.region,\n request.secretKey,\n );\n const credential = getCredential(\n request.accessKey,\n request.region,\n request.date,\n );\n const signature = bin2hex(await sha256hmac(signingKey, stringToSign))\n .toLowerCase();\n\n return `${signV4Algorithm} Credential=${credential}, SignedHeaders=${\n signedHeaders.join(\";\").toLowerCase()\n }, Signature=${signature}`;\n}\n\n/**\n * Generate a pre-signed URL\n */\nexport async function presignV4(request: {\n protocol: \"http:\" | \"https:\";\n headers: Headers;\n method: string;\n path: string;\n accessKey: string;\n secretKey: string;\n sessionToken?: string;\n region: string;\n date: Date;\n expirySeconds: number;\n}): Promise<string> {\n if (!request.accessKey) {\n throw new errors.AccessKeyRequiredError();\n }\n if (!request.secretKey) {\n throw new errors.SecretKeyRequiredError();\n }\n if (request.expirySeconds < 1 || request.expirySeconds > 604800) {\n throw new errors.InvalidExpiryError();\n }\n if (!request.headers.has(\"Host\")) {\n throw new Error(\"Internal error: host header missing\");\n }\n\n // Information about the future request that we're going to sign:\n const resource = request.path.split(\"?\")[0];\n const queryString = request.path.split(\"?\")[1];\n const iso8601Date = makeDateLong(request.date);\n const signedHeaders = getHeadersToSign(request.headers);\n const credential = getCredential(request.accessKey, request.region, request.date);\n const hashedPayload = \"UNSIGNED-PAYLOAD\";\n\n // Build the query string for our new signed URL:\n const newQuery = new URLSearchParams(queryString);\n newQuery.set(\"X-Amz-Algorithm\", signV4Algorithm);\n newQuery.set(\"X-Amz-Credential\", credential);\n newQuery.set(\"X-Amz-Date\", iso8601Date);\n newQuery.set(\"X-Amz-Expires\", request.expirySeconds.toString());\n newQuery.set(\"X-Amz-SignedHeaders\", signedHeaders.join(\";\").toLowerCase());\n if (request.sessionToken) {\n newQuery.set(\"X-Amz-Security-Token\", request.sessionToken);\n }\n const newQueryString = newQuery.toString().replace(\"+\", \"%20\"); // Signing requires spaces become %20, never +\n const signingPath = resource + \"?\" + newQueryString;\n const encodedPath = resource.split(\"/\").map((part) => encodeURIComponent(part)).join(\"/\");\n\n const canonicalRequest = getCanonicalRequest(\n request.method,\n signingPath,\n request.headers,\n signedHeaders,\n hashedPayload,\n );\n const stringToSign = await getStringToSign(canonicalRequest, request.date, request.region);\n const signingKey = await getSigningKey(request.date, request.region, request.secretKey);\n const signature = bin2hex(await sha256hmac(signingKey, stringToSign)).toLowerCase();\n // deno-fmt-ignore\n const presignedUrl = `${request.protocol}//${request.headers.get(\"Host\")}${encodedPath}?${newQueryString}&X-Amz-Signature=${signature}`;\n return presignedUrl;\n}\n\n/**\n * Given the set of HTTP headers that we'll be sending with an S3/AWS request, determine which\n * headers will be signed, and in what order.\n */\nfunction getHeadersToSign(headers: Headers): string[] {\n // Excerpts from @lsegal - https://github.com/aws/aws-sdk-js/issues/659#issuecomment-120477258\n //\n // User-Agent:\n //\n // This is ignored from signing because signing this causes problems with generating pre-signed URLs\n // (that are executed by other agents) or when customers pass requests through proxies, which may\n // modify the user-agent.\n //\n // Content-Length:\n //\n // This is ignored from signing because generating a pre-signed URL should not provide a content-length\n // constraint, specifically when vending a S3 pre-signed PUT URL. The corollary to this is that when\n // sending regular requests (non-pre-signed), the signature contains a checksum of the body, which\n // implicitly validates the payload length (since changing the number of bytes would change the checksum)\n // and therefore this header is not valuable in the signature.\n //\n // Content-Type:\n //\n // Signing this header causes quite a number of problems in browser environments, where browsers\n // like to modify and normalize the content-type header in different ways. There is more information\n // on this in https://github.com/aws/aws-sdk-js/issues/244. Avoiding this field simplifies logic\n // and reduces the possibility of future bugs\n //\n // Authorization:\n //\n // Is skipped for obvious reasons\n\n const ignoredHeaders = [\n \"authorization\",\n \"content-length\",\n \"content-type\",\n \"user-agent\",\n ];\n const headersToSign = [];\n for (const key of headers.keys()) {\n if (ignoredHeaders.includes(key.toLowerCase())) {\n continue; // Ignore this header\n }\n headersToSign.push(key);\n }\n headersToSign.sort();\n return headersToSign;\n}\n\nconst CODES = {\n A: \"A\".charCodeAt(0),\n Z: \"Z\".charCodeAt(0),\n a: \"a\".charCodeAt(0),\n z: \"z\".charCodeAt(0),\n \"0\": \"0\".charCodeAt(0),\n \"9\": \"9\".charCodeAt(0),\n \"/\": \"/\".charCodeAt(0),\n};\nconst ALLOWED_BYTES = \"-._~\".split(\"\").map((s) => s.charCodeAt(0));\n\n/**\n * Canonical URI encoding for signing, per AWS documentation:\n * 1. URI encode every byte except the unreserved characters:\n * 'A'-'Z', 'a'-'z', '0'-'9', '-', '.', '_', and '~'.\n * 2. The space character must be encoded as \"%20\" (and not as \"+\").\n * 3. Each URI encoded byte is formed by a '%' and the\n * two-digit uppercase hexadecimal value of the byte. e.g. \"%1A\".\n * 4. Encode the forward slash character, '/', everywhere except\n * in the object key name. For example, if the object key name\n * is photos/Jan/sample.jpg, the forward slash in the key name\n * is not encoded.\n *\n * See https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-header-based-auth.html\n *\n * @param string the string to encode.\n */\nfunction awsUriEncode(string: string, allowSlashes = false) {\n const bytes: Uint8Array = new TextEncoder().encode(string);\n let encoded = \"\";\n for (const byte of bytes) {\n if (\n (byte >= CODES.A && byte <= CODES.Z) ||\n (byte >= CODES.a && byte <= CODES.z) ||\n (byte >= CODES[\"0\"] && byte <= CODES[\"9\"]) ||\n (ALLOWED_BYTES.includes(byte)) ||\n (byte == CODES[\"/\"] && allowSlashes)\n ) {\n encoded += String.fromCharCode(byte);\n } else {\n encoded += \"%\" + byte.toString(16).padStart(2, \"0\").toUpperCase();\n }\n }\n return encoded;\n}\n\n/**\n * getCanonicalRequest generate a canonical request of style.\n *\n * canonicalRequest =\n * <HTTPMethod>\\n\n * <CanonicalURI>\\n\n * <CanonicalQueryString>\\n\n * <CanonicalHeaders>\\n\n * <SignedHeaders>\\n\n * <HashedPayload>\n */\nfunction getCanonicalRequest(\n method: string,\n path: string,\n headers: Headers,\n headersToSign: string[],\n payloadHash: string,\n): string {\n const headersArray = headersToSign.reduce<string[]>((acc, headerKey) => {\n // Trim spaces from the value (required by V4 spec)\n const val = `${headers.get(headerKey)}`.replace(/ +/g, \" \");\n acc.push(`${headerKey.toLowerCase()}:${val}`);\n return acc;\n }, []);\n\n const requestResource = path.split(\"?\")[0];\n let requestQuery = path.split(\"?\")[1];\n if (requestQuery) {\n requestQuery = requestQuery\n .split(\"&\")\n .map((element) => {\n const [key, val] = element.split(\"=\", 2);\n // The input is assumed to be encoded, so we need to decode it first.\n return awsUriEncode(decodeURIComponent(key)) + \"=\" + awsUriEncode(decodeURIComponent(val || \"\"));\n })\n .sort() // sort after encoding\n .join(\"&\");\n } else {\n requestQuery = \"\";\n }\n\n // construct the canonical string from these parts:\n return [\n method.toUpperCase(),\n awsUriEncode(requestResource, true),\n requestQuery,\n headersArray.join(\"\\n\") + \"\\n\",\n headersToSign.join(\";\").toLowerCase(),\n payloadHash,\n ].join(\"\\n\");\n}\n\n// returns the string that needs to be signed\nasync function getStringToSign(\n canonicalRequest: string,\n requestDate: Date,\n region: string,\n): Promise<string> {\n const hash = await sha256digestHex(canonicalRequest);\n const scope = getScope(region, requestDate);\n return [\n signV4Algorithm,\n makeDateLong(requestDate),\n scope,\n hash,\n ].join(\"\\n\");\n}\n\n/** returns the key used for calculating signature */\nasync function getSigningKey(\n date: Date,\n region: string,\n secretKey: string,\n): Promise<Uint8Array_> {\n const dateLine = makeDateShort(date);\n const hmac1 = await sha256hmac(\"AWS4\" + secretKey, dateLine);\n const hmac2 = await sha256hmac(hmac1, region);\n const hmac3 = await sha256hmac(hmac2, \"s3\");\n return await sha256hmac(hmac3, \"aws4_request\");\n}\n\n/** generate a credential string */\nfunction getCredential(accessKey: string, region: string, requestDate: Date) {\n return `${accessKey}/${getScope(region, requestDate)}`;\n}\n\n/**\n * Given a secret key and some data, generate a HMAC of the data using SHA-256.\n */\nasync function sha256hmac(\n secretKey: Uint8Array_ | string,\n data: Uint8Array_ | string,\n): Promise<Uint8Array_> {\n const enc = new TextEncoder();\n const keyObject = await crypto.subtle.importKey(\n \"raw\", // raw format of the key - should be Uint8Array\n secretKey instanceof Uint8Array ? secretKey : enc.encode(secretKey),\n { name: \"HMAC\", hash: { name: \"SHA-256\" } }, // algorithm\n false, // export = false\n [\"sign\", \"verify\"], // what this key can do\n );\n const signature = await crypto.subtle.sign(\n \"HMAC\",\n keyObject,\n data instanceof Uint8Array ? data : enc.encode(data),\n );\n return new Uint8Array(signature);\n}\n\n/**\n * Type for S3 Post Policy conditions\n * S3 allows conditions to have different shapes\n */\ntype PolicyCondition = Record<string, unknown> | string[];\n\n/**\n * Generate a presigned POST policy that can be used to allow direct uploads to S3.\n * This is equivalent to AWS SDK's presignedPost functionality.\n */\nexport async function presignPostV4(request: {\n host: string;\n protocol: \"http:\" | \"https:\";\n bucket: string;\n objectKey: string;\n accessKey: string;\n secretKey: string;\n region: string;\n date: Date;\n expirySeconds: number;\n conditions?: PolicyCondition[];\n fields?: Record<string, string>;\n}): Promise<{\n url: string;\n fields: Record<string, string>;\n}> {\n if (!request.accessKey) {\n throw new errors.AccessKeyRequiredError();\n }\n if (!request.secretKey) {\n throw new errors.SecretKeyRequiredError();\n }\n if (request.expirySeconds < 1 || request.expirySeconds > 604800) {\n throw new errors.InvalidExpiryError();\n }\n\n const expiration = new Date(request.date);\n expiration.setSeconds(expiration.getSeconds() + request.expirySeconds);\n const credential = getCredential(request.accessKey, request.region, request.date);\n const iso8601Date = makeDateLong(request.date);\n\n // Default required policy fields\n const fields: Record<string, string> = {\n \"X-Amz-Algorithm\": signV4Algorithm,\n \"X-Amz-Credential\": credential,\n \"X-Amz-Date\": iso8601Date,\n \"key\": request.objectKey,\n ...request.fields,\n };\n\n // Build policy document\n const conditions: PolicyCondition[] = [\n { bucket: request.bucket },\n { key: request.objectKey },\n { \"X-Amz-Algorithm\": signV4Algorithm },\n { \"X-Amz-Credential\": credential },\n { \"X-Amz-Date\": iso8601Date },\n ];\n\n // Add any additional conditions provided by the user\n if (request.conditions) {\n conditions.push(...request.conditions);\n }\n\n // Add additional fields as conditions\n for (const [key, value] of Object.entries(request.fields || {})) {\n // Skip fields that we've already added to conditions\n if ([\"key\", \"X-Amz-Algorithm\", \"X-Amz-Credential\", \"X-Amz-Date\"].includes(key)) continue;\n conditions.push({ [key]: value });\n }\n\n const policy = {\n expiration: expiration.toISOString(),\n conditions,\n };\n\n // Convert policy to base64\n const policyBytes = new TextEncoder().encode(JSON.stringify(policy));\n const base64Policy = btoa(String.fromCharCode(...policyBytes));\n fields[\"policy\"] = base64Policy;\n\n // Calculate signature\n const stringToSign = base64Policy;\n const signingKey = await getSigningKey(request.date, request.region, request.secretKey);\n const signature = bin2hex(await sha256hmac(signingKey, stringToSign)).toLowerCase();\n fields[\"X-Amz-Signature\"] = signature;\n\n // Construct the URL\n const url = `${request.protocol}//${request.host}/${request.bucket}`;\n\n return { url, fields };\n}\n\n// Export for testing purposes only\nexport const _internalMethods = {\n awsUriEncode,\n getHeadersToSign,\n getCanonicalRequest,\n getStringToSign,\n getSigningKey,\n getCredential,\n sha256hmac,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;;ACAA;;;;ACAA;;;;ACAA;;AAIO,IAAM,sBAAN,cAAkC,gBAAA;EAJzC,OAIyC;;;;EACvC,YAA6B,cAAsB;AAGjD,QAAI,SAAS,IAAI,WAAW,YAAA;AAC5B,QAAI,SAAS;AAEb,UAAM;MACJ,UAAU,OAAO,YAAU;AACzB,YAAI,MAAM;AACV,eAAO,MAAM,MAAM,QAAQ;AAEzB,gBAAM,SAAS,eAAe;AAE9B,gBAAM,SAAS,KAAK,IAAI,QAAQ,MAAM,SAAS,GAAA;AAG/C,iBAAO,IAAI,MAAM,SAAS,KAAK,MAAM,MAAA,GAAS,MAAA;AAC9C,iBAAO;AACP,oBAAU;AAGV,cAAI,WAAW,cAAc;AAC3B,uBAAW,QAAQ,MAAA;AAEnB,qBAAS,IAAI,WAAW,YAAA;AACxB,qBAAS;UACX;QACF;MACF;MACA,MAAM,YAAU;AAEd,YAAI,SAAS,GAAG;AACd,qBAAW,QAAQ,OAAO,SAAS,GAAG,MAAA,CAAA;QACxC;MACF;IACF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S;AAC/B,MAAI,IAAI,WAAW,OAAQ,QAAO;AAClC,MAAI,CAAC,IAAI,KAAM,QAAO;AAEtB,QAAM,CAAC,WAAW,SAAS,IAAI,IAAI,UAAU,MAAM,GAAG,KAAK,CAAC;AAC5D,MAAI,CAAC,aAAa,CAAC,UAAW,QAAO;AAErC,QAAM,KAAK,qBAAG,MAAM,IAAI,SAAS,EAAE;AAEnC,QAAM,SAAS;AAAA,IACb;AAAA,IACA,YAAY,OAAO,GAAG,eAAe,WAAW,GAAG,aAAa;AAAA,IAChE,MAAM,IAAI;AAAA,IACV,MAAM,GAAG,eAAe,WAAW,GAAG,aAAa;AAAA,IACnD,QAAQ,OAAO,GAAG,WAAW,WAAW,GAAG,SAAS;AAAA,IACpD;AAAA,EACF;AAEA,QAAM,QACH,OAAO,KAAK,QAAQ,OAAO,EAAE,IAAQ,sBAAkB,IAAI,QAAQ,EAAE,GACnE;AAAA,IACC;AAAA,IACA;AAAA,EACF;AAEJ,SAAO,EAAE,QAAQ,KAAK;AACxB;AA3BgB;AAgChB,eAAsB,YAAY,OAAO;AACvC,QAAU,IAAI,aAAa,KAAK;AAClC;AAFsB;","names":[],"sourceRoot":"file:///var/home/toko/Code/tokono.ma/diffuse-artifacts/diffuse","file":"/chunk-AISBWLUT.js.map"}
···11+{"version":3,"sources":["/common/element.js","/node_modules/.deno/lit-html@3.3.2/node_modules/lit-html/src/lit-html.ts"],"sourcesContent":["import QS from \"query-string\";\nimport { decodeMessage, encodeMessage, RPCChannel } from \"@kunkun/kkrpc\";\nimport { html, render } from \"lit-html\";\n\nimport { effect, signal } from \"@common/signal.js\";\nimport { rpc, workerLink, workerProxy, workerTunnel } from \"./worker.js\";\nimport { BrowserPostMessageIo } from \"./worker/rpc.js\";\n\n/**\n * @import {BroadcastingStatus, WorkerOpts} from \"./element.d.ts\"\n * @import {ProxiedActions, Tunnel} from \"./worker.d.ts\";\n * @import {Signal} from \"./signal.d.ts\"\n */\n\nexport { html, nothing } from \"lit-html\";\nexport const DEFAULT_GROUP = \"default\";\n\n/**\n * Base for custom elements, provides some utility functionality\n * around rendering and managing signals.\n */\nexport class DiffuseElement extends HTMLElement {\n $connected = signal(false);\n\n #connected = Promise.withResolvers();\n #disposables = /** @type {Array<() => void>} */ ([]);\n\n /** */\n constructor() {\n super();\n\n this.uuid = crypto.randomUUID();\n this.worker = this.worker.bind(this);\n this.workerLink = this.workerLink.bind(this);\n }\n\n /**\n * @param {string} _name\n * @param {string} oldValue\n * @param {string} newValue\n */\n attributeChangedCallback(_name, oldValue, newValue) {\n if (oldValue !== newValue) this.#render();\n }\n\n /**\n * Effect helper that automatically is disposes\n * when this element is removed from the DOM.\n *\n * @param {() => void} fn\n */\n effect(fn) {\n const unregister = effect(fn);\n this.#disposables.push(unregister);\n return unregister;\n }\n\n /** */\n forceRender() {\n return this.#render();\n }\n\n /** */\n get group() {\n return this.getAttribute(\"group\") ?? DEFAULT_GROUP;\n }\n\n /** */\n get label() {\n return this.getAttribute(\"label\") ?? this.id ?? this.localName;\n }\n\n /** */\n get nameWithGroup() {\n return `${this.constructor.prototype.constructor.NAME}/${this.group}`;\n }\n\n /** */\n root() {\n return (this.shadowRoot ?? this);\n }\n\n /** */\n get selector() {\n return this.id.length ? `#${this.id}` : this.localName;\n }\n\n /** */\n whenConnected() {\n return this.#connected.promise;\n }\n\n /** */\n whenDefined() {\n return customElements.whenDefined(this.localName);\n }\n\n /**\n * Avoid replacing the whole subtree,\n * morph the existing DOM into the new given tree.\n */\n #render() {\n if (!(\"render\" in this && typeof this.render === \"function\")) return;\n\n const tmp = this.render({\n html: html,\n state: \"state\" in this ? this.state : undefined,\n });\n\n render(tmp, this.root());\n }\n\n // LIFECYCLE\n\n connectedCallback() {\n this.$connected.value = true;\n this.#connected.resolve(null);\n\n if (!(\"render\" in this && typeof this.render === \"function\")) return;\n\n this.effect(() => {\n if (!(\"render\" in this && typeof this.render === \"function\")) return;\n this.#render();\n });\n }\n\n disconnectedCallback() {\n this.$connected.value = false;\n this.#teardown();\n }\n\n #teardown() {\n this.#disposables.forEach((fn) => fn());\n }\n\n // WORKERS\n\n /** @type {undefined | Worker | SharedWorker} */\n #worker;\n\n createWorker() {\n const NAME = this.constructor.prototype.constructor.NAME;\n const WORKER_URL = this.constructor.prototype.constructor.WORKER_URL;\n\n if (!NAME) throw new Error(\"Missing `NAME` static property\");\n if (!WORKER_URL) throw new Error(\"Missing `WORKER_URL` static property\");\n\n // Query\n const query = QS.stringify(\n \"workerQuery\" in this && typeof this.workerQuery === \"function\"\n ? this.workerQuery()\n : {},\n );\n\n // Setup worker\n const name = this.nameWithGroup;\n const url = import.meta.resolve(\"./\" + WORKER_URL) + `?${query}`;\n\n let worker;\n\n if (this.hasAttribute(\"group\")) {\n worker = new SharedWorker(url, { name, type: \"module\" });\n } else {\n worker = new Worker(url, { name, type: \"module\" });\n }\n\n return worker;\n }\n\n /** */\n dependencies() {\n return Object.fromEntries(\n Array.from(this.children).flatMap((element) => {\n if (\"nameWithGroup\" in element === false) {\n return [];\n }\n\n const d = /** @type {DiffuseElement} */ (element);\n return [[d.localName, d]];\n }),\n );\n }\n\n worker() {\n this.#worker ??= this.createWorker();\n return this.#worker;\n }\n\n workerLink() {\n const worker = this.worker();\n return workerLink(worker);\n }\n\n /**\n * @template {Record<string, (...args: any[]) => any>} Actions\n * @param {WorkerOpts} [opts]\n * @returns {ProxiedActions<Actions>}\n */\n workerProxy(opts) {\n return workerProxy(\n () => this.workerTunnel(opts).port,\n );\n }\n\n /**\n * @param {WorkerOpts} [opts]\n */\n workerTunnel({ forceNew } = {}) {\n // Creates a MessagePort that is connected to the worker.\n // All the dependencies are added automatically.\n const worker = forceNew === true ||\n (typeof forceNew === \"object\" && forceNew.self === true)\n ? this.createWorker()\n : this.worker();\n const deps = this.dependencies();\n\n let toWorker;\n\n if (Object.keys(deps).length) {\n toWorker =\n /**\n * @param {any} msg\n */\n async (msg) => {\n /** @type {Array<[string, Tunnel]>} */\n const ports = Object.entries(deps).map(\n /** @param {[string, DiffuseElement]} _ */\n ([k, v]) => {\n const n = typeof forceNew === \"object\"\n ? forceNew.dependencies?.[k] ?? false\n : false;\n return [k, v.workerTunnel({ forceNew: n })];\n },\n );\n\n const decoded = await decodeMessage(msg);\n const data = {\n data: Array.isArray(decoded.args) ? decoded.args[0] : decoded.args,\n ports: Object.fromEntries(ports.map(([k, v]) => {\n return [k, v.port];\n })),\n };\n\n const encoded = encodeMessage(\n {\n ...decoded,\n args: Array.isArray(decoded.args)\n ? [data, ...decoded.args.slice(1)]\n : decoded.args,\n },\n {},\n true,\n ports.map(([_k, v]) => v.port),\n );\n\n this.#disposables.push(() => {\n ports.forEach(([_k, v]) => v.disconnect());\n });\n\n return {\n data: encoded,\n transfer: ports.map(([_k, v]) => v.port),\n };\n };\n }\n\n const tunnel = workerTunnel(worker, { toWorker });\n return tunnel;\n }\n}\n\n/**\n * Broadcastable version of the base class.\n *\n * Share the state of an element across multiple tabs\n * of the same origin and have one instance be the leader.\n */\nexport class BroadcastableDiffuseElement extends DiffuseElement {\n broadcasted = false;\n\n /** @type {{ assumeLeadership?: boolean }} */\n #broadcastingOptions = {};\n\n #broadcastingStatus;\n broadcastingStatus;\n\n /** @type {PromiseWithResolvers<void>} */\n #lock = Promise.withResolvers();\n\n /** @type {PromiseWithResolvers<BroadcastingStatus>} */\n #status = Promise.withResolvers();\n\n constructor() {\n super();\n\n this.broadcast = this.broadcast.bind(this);\n\n /** @type {Signal<Promise<BroadcastingStatus>>} */\n this.#broadcastingStatus = signal(this.#status.promise, { eager: true });\n this.broadcastingStatus = this.#broadcastingStatus.get;\n }\n\n /**\n * @template {Record<string, { strategy: \"leaderOnly\" | \"replicate\", fn: (...args: any[]) => any }>} ActionsWithStrategy\n * @template {{ [K in keyof ActionsWithStrategy]: ActionsWithStrategy[K][\"fn\"] }} Actions\n * @param {string} channelName\n * @param {ActionsWithStrategy} actionsWithStrategy\n * @param {{ assumeLeadership?: boolean }} [options]\n */\n broadcast(channelName, actionsWithStrategy, options) {\n if (this.broadcasted) return;\n if (options) this.#broadcastingOptions = options;\n\n const channel = new BroadcastChannel(channelName);\n const msg = new MessageChannel();\n\n /**\n * @typedef {{ [K in keyof ActionsWithStrategy]: ActionsWithStrategy[K][\"fn\"] }} A\n */\n\n this.broadcasted = true;\n this.channelName = channelName;\n\n const _rpc = rpc(\n msg.port2,\n Object.fromEntries(\n Object.entries(actionsWithStrategy).map(([k, v]) => {\n return [k, v.fn.bind(this)];\n }),\n ),\n );\n\n channel.addEventListener(\n \"message\",\n async (event) => {\n if (event.data?.includes('\"method\":\"leader:')) {\n const status = await this.#status.promise;\n if (status.leader) {\n const json = event.data.replace('\"method\":\"leader:', '\"method\":\"');\n msg.port1.postMessage(json);\n }\n } else {\n msg.port1.postMessage(event.data);\n }\n },\n );\n\n msg.port1.addEventListener(\n \"message\",\n (event) => channel.postMessage(event.data),\n );\n\n msg.port1.start();\n msg.port2.start();\n\n async function anyoneWaiting() {\n const state = await navigator.locks.query();\n return !!state.pending?.length;\n }\n\n const io = new BrowserPostMessageIo(() => msg.port2);\n\n /** @type {undefined | RPCChannel<{}, ProxiedActions<Actions>>} */\n const proxyChannel = new RPCChannel(io, { enableTransfer: true });\n\n /** @type {ProxiedActions<Actions>} */\n const proxy = proxyChannel.getAPI();\n\n /** @type {any} */\n const actions = {};\n\n Object.entries(actionsWithStrategy).forEach(\n ([action, { fn, strategy }]) => {\n const ogFn = fn.bind(this);\n let wrapFn = ogFn;\n\n switch (strategy) {\n case \"leaderOnly\":\n /** @param {Parameters<Actions[action]>} args */\n wrapFn = async (...args) => {\n const status = await this.#status.promise;\n return status.leader\n ? ogFn(...args)\n : proxyChannel.callMethod(`leader:${action}`, args);\n };\n break;\n\n case \"replicate\":\n /** @param {Parameters<Actions[action]>} args */\n wrapFn = async (...args) => {\n anyoneWaiting().then((bool) => {\n if (bool) proxy[action](...args);\n });\n return ogFn(...args);\n };\n break;\n }\n\n actions[action] = wrapFn;\n },\n );\n\n return /** @type {ProxiedActions<Actions>} */ (actions);\n }\n\n async isLeader() {\n if (this.broadcasted) {\n const status = await this.broadcastingStatus();\n return status.leader;\n } else {\n return true;\n }\n }\n\n // LIFECYCLE\n\n /**\n * @override\n */\n connectedCallback() {\n super.connectedCallback();\n\n if (!this.broadcasted) return;\n\n // Grab a lock if it isn't acquired yet and if needed,\n // and hold it until `this.lock.promise` resolves.\n const assumeLeadership = this.#broadcastingOptions?.assumeLeadership;\n\n if (assumeLeadership === undefined || assumeLeadership === true) {\n navigator.locks.request(\n `${this.channelName}/lock`,\n assumeLeadership === true ? { steal: true } : { ifAvailable: true },\n (lock) => {\n this.#status.resolve(\n lock ? { leader: true, initialLeader: true } : { leader: false },\n );\n if (lock) return this.#lock.promise;\n },\n );\n } else {\n this.#status.resolve(\n { leader: false },\n );\n }\n\n // When the lock status is initially determined, log its status.\n // Additionally, wait for lock if needed.\n this.#status.promise.then((status) => {\n if (status.leader) {\n console.log(`🧙 Elected leader for: ${this.channelName}`);\n } else {\n console.log(`🔮 Watching leader: ${this.channelName}`);\n }\n\n // Wait for leadership\n if (status.leader === false) {\n navigator.locks.request(\n `${this.channelName}/lock`,\n () => {\n this.#status = Promise.withResolvers();\n this.#status.resolve({ leader: true, initialLeader: false });\n\n this.#broadcastingStatus.value = this.#status.promise;\n\n return this.#lock.promise;\n },\n );\n }\n });\n }\n\n /**\n * @override\n */\n disconnectedCallback() {\n super.disconnectedCallback();\n this.#lock.resolve();\n }\n}\n\n/**\n * Component DOM selector.\n *\n * Basically `document.querySelector` but returns the element\n * with the correct type based on the element module given.\n *\n * ```\n * import * as QueryEngine from \"@components/engine/query/element.js\"\n *\n * const instance = component(QueryEngine)\n * ```\n *\n * @template {abstract new (...args: any[]) => any} C\n * @param {{ CLASS: C; NAME: string }} elementModule\n * @param {string} [id] Optional id to select\n */\nexport function component(elementModule, id) {\n const el = document.querySelector(\n id ? `${elementModule.NAME}#${id}` : elementModule.NAME,\n );\n if (!el) {\n throw new Error(`Element for selector '${elementModule.NAME}' not found.`);\n }\n return /** @type {InstanceType<C>} */ (el);\n}\n\n/**\n * @template {HTMLElement} T\n * @param {DiffuseElement} parent\n * @param {string} attribute\n * @returns {T}\n */\nexport function query(parent, attribute) {\n const selector = parent.getAttribute(attribute);\n\n if (!selector) {\n throw new Error(`Missing required '${attribute}' attribute`);\n }\n\n /** @type {T | null} */\n const element = document.querySelector(selector);\n if (!element) throw new Error(`Missing required '${selector}' element`);\n return element;\n}\n\n/**\n * @template {HTMLElement} T\n * @param {DiffuseElement} parent\n * @param {string} attribute\n */\nexport function queryOptional(parent, attribute) {\n const selector = parent.getAttribute(attribute);\n\n if (!selector) {\n return null;\n }\n\n /** @type {T | null} */\n const elementOrNull = document.querySelector(selector);\n return elementOrNull;\n}\n\n/**\n * @param {Record<string, Worker | SharedWorker>} workers\n */\nexport function terminateWorkers(workers) {\n Object.values(workers).forEach((worker) => {\n if (worker instanceof Worker) worker.terminate();\n });\n}\n\n/**\n * @template {Record<string, DiffuseElement>} T\n * @param {T} elements\n */\nexport async function whenElementsDefined(elements) {\n await Promise.all(\n Object.values(elements).map((element) =>\n customElements.whenDefined(element.localName)\n ),\n );\n}\n","/**\n * @license\n * Copyright 2017 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */\n\n// IMPORTANT: these imports must be type-only\nimport type {Directive, DirectiveResult, PartInfo} from './directive.js';\nimport type {TrustedHTML, TrustedTypesWindow} from 'trusted-types/lib/index.js';\n\nconst DEV_MODE = true;\nconst ENABLE_EXTRA_SECURITY_HOOKS = true;\nconst ENABLE_SHADYDOM_NOPATCH = true;\nconst NODE_MODE = false;\n\n// Allows minifiers to rename references to globalThis\nconst global = globalThis;\n\n/**\n * Contains types that are part of the unstable debug API.\n *\n * Everything in this API is not stable and may change or be removed in the future,\n * even on patch releases.\n */\n// eslint-disable-next-line @typescript-eslint/no-namespace\nexport namespace LitUnstable {\n /**\n * When Lit is running in dev mode and `window.emitLitDebugLogEvents` is true,\n * we will emit 'lit-debug' events to window, with live details about the update and render\n * lifecycle. These can be useful for writing debug tooling and visualizations.\n *\n * Please be aware that running with window.emitLitDebugLogEvents has performance overhead,\n * making certain operations that are normally very cheap (like a no-op render) much slower,\n * because we must copy data and dispatch events.\n */\n // eslint-disable-next-line @typescript-eslint/no-namespace\n export namespace DebugLog {\n export type Entry =\n | TemplatePrep\n | TemplateInstantiated\n | TemplateInstantiatedAndUpdated\n | TemplateUpdating\n | BeginRender\n | EndRender\n | CommitPartEntry\n | SetPartValue;\n export interface TemplatePrep {\n kind: 'template prep';\n template: Template;\n strings: TemplateStringsArray;\n clonableTemplate: HTMLTemplateElement;\n parts: TemplatePart[];\n }\n export interface BeginRender {\n kind: 'begin render';\n id: number;\n value: unknown;\n container: RenderRootNode;\n options: RenderOptions | undefined;\n part: ChildPart | undefined;\n }\n export interface EndRender {\n kind: 'end render';\n id: number;\n value: unknown;\n container: RenderRootNode;\n options: RenderOptions | undefined;\n part: ChildPart;\n }\n export interface TemplateInstantiated {\n kind: 'template instantiated';\n template: Template | CompiledTemplate;\n instance: TemplateInstance;\n options: RenderOptions | undefined;\n fragment: Node;\n parts: Array<Part | undefined>;\n values: unknown[];\n }\n export interface TemplateInstantiatedAndUpdated {\n kind: 'template instantiated and updated';\n template: Template | CompiledTemplate;\n instance: TemplateInstance;\n options: RenderOptions | undefined;\n fragment: Node;\n parts: Array<Part | undefined>;\n values: unknown[];\n }\n export interface TemplateUpdating {\n kind: 'template updating';\n template: Template | CompiledTemplate;\n instance: TemplateInstance;\n options: RenderOptions | undefined;\n parts: Array<Part | undefined>;\n values: unknown[];\n }\n export interface SetPartValue {\n kind: 'set part';\n part: Part;\n value: unknown;\n valueIndex: number;\n values: unknown[];\n templateInstance: TemplateInstance;\n }\n\n export type CommitPartEntry =\n | CommitNothingToChildEntry\n | CommitText\n | CommitNode\n | CommitAttribute\n | CommitProperty\n | CommitBooleanAttribute\n | CommitEventListener\n | CommitToElementBinding;\n\n export interface CommitNothingToChildEntry {\n kind: 'commit nothing to child';\n start: ChildNode;\n end: ChildNode | null;\n parent: Disconnectable | undefined;\n options: RenderOptions | undefined;\n }\n\n export interface CommitText {\n kind: 'commit text';\n node: Text;\n value: unknown;\n options: RenderOptions | undefined;\n }\n\n export interface CommitNode {\n kind: 'commit node';\n start: Node;\n parent: Disconnectable | undefined;\n value: Node;\n options: RenderOptions | undefined;\n }\n\n export interface CommitAttribute {\n kind: 'commit attribute';\n element: Element;\n name: string;\n value: unknown;\n options: RenderOptions | undefined;\n }\n\n export interface CommitProperty {\n kind: 'commit property';\n element: Element;\n name: string;\n value: unknown;\n options: RenderOptions | undefined;\n }\n\n export interface CommitBooleanAttribute {\n kind: 'commit boolean attribute';\n element: Element;\n name: string;\n value: boolean;\n options: RenderOptions | undefined;\n }\n\n export interface CommitEventListener {\n kind: 'commit event listener';\n element: Element;\n name: string;\n value: unknown;\n oldListener: unknown;\n options: RenderOptions | undefined;\n // True if we're removing the old event listener (e.g. because settings changed, or value is nothing)\n removeListener: boolean;\n // True if we're adding a new event listener (e.g. because first render, or settings changed)\n addListener: boolean;\n }\n\n export interface CommitToElementBinding {\n kind: 'commit to element binding';\n element: Element;\n value: unknown;\n options: RenderOptions | undefined;\n }\n }\n}\n\ninterface DebugLoggingWindow {\n // Even in dev mode, we generally don't want to emit these events, as that's\n // another level of cost, so only emit them when DEV_MODE is true _and_ when\n // window.emitLitDebugEvents is true.\n emitLitDebugLogEvents?: boolean;\n}\n\n/**\n * Useful for visualizing and logging insights into what the Lit template system is doing.\n *\n * Compiled out of prod mode builds.\n */\nconst debugLogEvent = DEV_MODE\n ? (event: LitUnstable.DebugLog.Entry) => {\n const shouldEmit = (global as unknown as DebugLoggingWindow)\n .emitLitDebugLogEvents;\n if (!shouldEmit) {\n return;\n }\n global.dispatchEvent(\n new CustomEvent<LitUnstable.DebugLog.Entry>('lit-debug', {\n detail: event,\n })\n );\n }\n : undefined;\n// Used for connecting beginRender and endRender events when there are nested\n// renders when errors are thrown preventing an endRender event from being\n// called.\nlet debugLogRenderId = 0;\n\nlet issueWarning: (code: string, warning: string) => void;\n\nif (DEV_MODE) {\n global.litIssuedWarnings ??= new Set();\n\n /**\n * Issue a warning if we haven't already, based either on `code` or `warning`.\n * Warnings are disabled automatically only by `warning`; disabling via `code`\n * can be done by users.\n */\n issueWarning = (code: string, warning: string) => {\n warning += code\n ? ` See https://lit.dev/msg/${code} for more information.`\n : '';\n if (\n !global.litIssuedWarnings!.has(warning) &&\n !global.litIssuedWarnings!.has(code)\n ) {\n console.warn(warning);\n global.litIssuedWarnings!.add(warning);\n }\n };\n\n queueMicrotask(() => {\n issueWarning(\n 'dev-mode',\n `Lit is in dev mode. Not recommended for production!`\n );\n });\n}\n\nconst wrap =\n ENABLE_SHADYDOM_NOPATCH &&\n global.ShadyDOM?.inUse &&\n global.ShadyDOM?.noPatch === true\n ? (global.ShadyDOM!.wrap as <T extends Node>(node: T) => T)\n : <T extends Node>(node: T) => node;\n\nconst trustedTypes = (global as unknown as TrustedTypesWindow).trustedTypes;\n\n/**\n * Our TrustedTypePolicy for HTML which is declared using the html template\n * tag function.\n *\n * That HTML is a developer-authored constant, and is parsed with innerHTML\n * before any untrusted expressions have been mixed in. Therefor it is\n * considered safe by construction.\n */\nconst policy = trustedTypes\n ? trustedTypes.createPolicy('lit-html', {\n createHTML: (s) => s,\n })\n : undefined;\n\n/**\n * Used to sanitize any value before it is written into the DOM. This can be\n * used to implement a security policy of allowed and disallowed values in\n * order to prevent XSS attacks.\n *\n * One way of using this callback would be to check attributes and properties\n * against a list of high risk fields, and require that values written to such\n * fields be instances of a class which is safe by construction. Closure's Safe\n * HTML Types is one implementation of this technique (\n * https://github.com/google/safe-html-types/blob/master/doc/safehtml-types.md).\n * The TrustedTypes polyfill in API-only mode could also be used as a basis\n * for this technique (https://github.com/WICG/trusted-types).\n *\n * @param node The HTML node (usually either a #text node or an Element) that\n * is being written to. Note that this is just an exemplar node, the write\n * may take place against another instance of the same class of node.\n * @param name The name of an attribute or property (for example, 'href').\n * @param type Indicates whether the write that's about to be performed will\n * be to a property or a node.\n * @return A function that will sanitize this class of writes.\n */\nexport type SanitizerFactory = (\n node: Node,\n name: string,\n type: 'property' | 'attribute'\n) => ValueSanitizer;\n\n/**\n * A function which can sanitize values that will be written to a specific kind\n * of DOM sink.\n *\n * See SanitizerFactory.\n *\n * @param value The value to sanitize. Will be the actual value passed into\n * the lit-html template literal, so this could be of any type.\n * @return The value to write to the DOM. Usually the same as the input value,\n * unless sanitization is needed.\n */\nexport type ValueSanitizer = (value: unknown) => unknown;\n\nconst identityFunction: ValueSanitizer = (value: unknown) => value;\nconst noopSanitizer: SanitizerFactory = (\n _node: Node,\n _name: string,\n _type: 'property' | 'attribute'\n) => identityFunction;\n\n/** Sets the global sanitizer factory. */\nconst setSanitizer = (newSanitizer: SanitizerFactory) => {\n if (!ENABLE_EXTRA_SECURITY_HOOKS) {\n return;\n }\n if (sanitizerFactoryInternal !== noopSanitizer) {\n throw new Error(\n `Attempted to overwrite existing lit-html security policy.` +\n ` setSanitizeDOMValueFactory should be called at most once.`\n );\n }\n sanitizerFactoryInternal = newSanitizer;\n};\n\n/**\n * Only used in internal tests, not a part of the public API.\n */\nconst _testOnlyClearSanitizerFactoryDoNotCallOrElse = () => {\n sanitizerFactoryInternal = noopSanitizer;\n};\n\nconst createSanitizer: SanitizerFactory = (node, name, type) => {\n return sanitizerFactoryInternal(node, name, type);\n};\n\n// Added to an attribute name to mark the attribute as bound so we can find\n// it easily.\nconst boundAttributeSuffix = '$lit$';\n\n// This marker is used in many syntactic positions in HTML, so it must be\n// a valid element name and attribute name. We don't support dynamic names (yet)\n// but this at least ensures that the parse tree is closer to the template\n// intention.\nconst marker = `lit$${Math.random().toFixed(9).slice(2)}$`;\n\n// String used to tell if a comment is a marker comment\nconst markerMatch = '?' + marker;\n\n// Text used to insert a comment marker node. We use processing instruction\n// syntax because it's slightly smaller, but parses as a comment node.\nconst nodeMarker = `<${markerMatch}>`;\n\nconst d =\n NODE_MODE && global.document === undefined\n ? ({\n createTreeWalker() {\n return {};\n },\n } as unknown as Document)\n : document;\n\n// Creates a dynamic marker. We never have to search for these in the DOM.\nconst createMarker = () => d.createComment('');\n\n// https://tc39.github.io/ecma262/#sec-typeof-operator\ntype Primitive = null | undefined | boolean | number | string | symbol | bigint;\nconst isPrimitive = (value: unknown): value is Primitive =>\n value === null || (typeof value != 'object' && typeof value != 'function');\nconst isArray = Array.isArray;\nconst isIterable = (value: unknown): value is Iterable<unknown> =>\n isArray(value) ||\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n typeof (value as any)?.[Symbol.iterator] === 'function';\n\nconst SPACE_CHAR = `[ \\t\\n\\f\\r]`;\nconst ATTR_VALUE_CHAR = `[^ \\t\\n\\f\\r\"'\\`<>=]`;\nconst NAME_CHAR = `[^\\\\s\"'>=/]`;\n\n// These regexes represent the five parsing states that we care about in the\n// Template's HTML scanner. They match the *end* of the state they're named\n// after.\n// Depending on the match, we transition to a new state. If there's no match,\n// we stay in the same state.\n// Note that the regexes are stateful. We utilize lastIndex and sync it\n// across the multiple regexes used. In addition to the five regexes below\n// we also dynamically create a regex to find the matching end tags for raw\n// text elements.\n\n/**\n * End of text is: `<` followed by:\n * (comment start) or (tag) or (dynamic tag binding)\n */\nconst textEndRegex = /<(?:(!--|\\/[^a-zA-Z])|(\\/?[a-zA-Z][^>\\s]*)|(\\/?$))/g;\nconst COMMENT_START = 1;\nconst TAG_NAME = 2;\nconst DYNAMIC_TAG_NAME = 3;\n\nconst commentEndRegex = /-->/g;\n/**\n * Comments not started with <!--, like </{, can be ended by a single `>`\n */\nconst comment2EndRegex = />/g;\n\n/**\n * The tagEnd regex matches the end of the \"inside an opening\" tag syntax\n * position. It either matches a `>`, an attribute-like sequence, or the end\n * of the string after a space (attribute-name position ending).\n *\n * See attributes in the HTML spec:\n * https://www.w3.org/TR/html5/syntax.html#elements-attributes\n *\n * \" \\t\\n\\f\\r\" are HTML space characters:\n * https://infra.spec.whatwg.org/#ascii-whitespace\n *\n * So an attribute is:\n * * The name: any character except a whitespace character, (\"), ('), \">\",\n * \"=\", or \"/\". Note: this is different from the HTML spec which also excludes control characters.\n * * Followed by zero or more space characters\n * * Followed by \"=\"\n * * Followed by zero or more space characters\n * * Followed by:\n * * Any character except space, ('), (\"), \"<\", \">\", \"=\", (`), or\n * * (\") then any non-(\"), or\n * * (') then any non-(')\n */\nconst tagEndRegex = new RegExp(\n `>|${SPACE_CHAR}(?:(${NAME_CHAR}+)(${SPACE_CHAR}*=${SPACE_CHAR}*(?:${ATTR_VALUE_CHAR}|(\"|')|))|$)`,\n 'g'\n);\nconst ENTIRE_MATCH = 0;\nconst ATTRIBUTE_NAME = 1;\nconst SPACES_AND_EQUALS = 2;\nconst QUOTE_CHAR = 3;\n\nconst singleQuoteAttrEndRegex = /'/g;\nconst doubleQuoteAttrEndRegex = /\"/g;\n/**\n * Matches the raw text elements.\n *\n * Comments are not parsed within raw text elements, so we need to search their\n * text content for marker strings.\n */\nconst rawTextElement = /^(?:script|style|textarea|title)$/i;\n\n/** TemplateResult types */\nconst HTML_RESULT = 1;\nconst SVG_RESULT = 2;\nconst MATHML_RESULT = 3;\n\ntype ResultType = typeof HTML_RESULT | typeof SVG_RESULT | typeof MATHML_RESULT;\n\n// TemplatePart types\n// IMPORTANT: these must match the values in PartType\nconst ATTRIBUTE_PART = 1;\nconst CHILD_PART = 2;\nconst PROPERTY_PART = 3;\nconst BOOLEAN_ATTRIBUTE_PART = 4;\nconst EVENT_PART = 5;\nconst ELEMENT_PART = 6;\nconst COMMENT_PART = 7;\n\n/**\n * The return type of the template tag functions, {@linkcode html} and\n * {@linkcode svg} when it hasn't been compiled by @lit-labs/compiler.\n *\n * A `TemplateResult` object holds all the information about a template\n * expression required to render it: the template strings, expression values,\n * and type of template (html or svg).\n *\n * `TemplateResult` objects do not create any DOM on their own. To create or\n * update DOM you need to render the `TemplateResult`. See\n * [Rendering](https://lit.dev/docs/components/rendering) for more information.\n *\n */\nexport type UncompiledTemplateResult<T extends ResultType = ResultType> = {\n // This property needs to remain unminified.\n ['_$litType$']: T;\n strings: TemplateStringsArray;\n values: unknown[];\n};\n\n/**\n * This is a template result that may be either uncompiled or compiled.\n *\n * In the future, TemplateResult will be this type. If you want to explicitly\n * note that a template result is potentially compiled, you can reference this\n * type and it will continue to behave the same through the next major version\n * of Lit. This can be useful for code that wants to prepare for the next\n * major version of Lit.\n */\nexport type MaybeCompiledTemplateResult<T extends ResultType = ResultType> =\n | UncompiledTemplateResult<T>\n | CompiledTemplateResult;\n\n/**\n * The return type of the template tag functions, {@linkcode html} and\n * {@linkcode svg}.\n *\n * A `TemplateResult` object holds all the information about a template\n * expression required to render it: the template strings, expression values,\n * and type of template (html or svg).\n *\n * `TemplateResult` objects do not create any DOM on their own. To create or\n * update DOM you need to render the `TemplateResult`. See\n * [Rendering](https://lit.dev/docs/components/rendering) for more information.\n *\n * In Lit 4, this type will be an alias of\n * MaybeCompiledTemplateResult, so that code will get type errors if it assumes\n * that Lit templates are not compiled. When deliberately working with only\n * one, use either {@linkcode CompiledTemplateResult} or\n * {@linkcode UncompiledTemplateResult} explicitly.\n */\nexport type TemplateResult<T extends ResultType = ResultType> =\n UncompiledTemplateResult<T>;\n\nexport type HTMLTemplateResult = TemplateResult<typeof HTML_RESULT>;\n\nexport type SVGTemplateResult = TemplateResult<typeof SVG_RESULT>;\n\nexport type MathMLTemplateResult = TemplateResult<typeof MATHML_RESULT>;\n\n/**\n * A TemplateResult that has been compiled by @lit-labs/compiler, skipping the\n * prepare step.\n */\nexport interface CompiledTemplateResult {\n // This is a factory in order to make template initialization lazy\n // and allow ShadyRenderOptions scope to be passed in.\n // This property needs to remain unminified.\n ['_$litType$']: CompiledTemplate;\n values: unknown[];\n}\n\nexport interface CompiledTemplate extends Omit<Template, 'el'> {\n // el is overridden to be optional. We initialize it on first render\n el?: HTMLTemplateElement;\n\n // The prepared HTML string to create a template element from.\n // The type is a TemplateStringsArray to guarantee that the value came from\n // source code, preventing a JSON injection attack.\n h: TemplateStringsArray;\n}\n\n/**\n * Generates a template literal tag function that returns a TemplateResult with\n * the given result type.\n */\nconst tag =\n <T extends ResultType>(type: T) =>\n (strings: TemplateStringsArray, ...values: unknown[]): TemplateResult<T> => {\n // Warn against templates octal escape sequences\n // We do this here rather than in render so that the warning is closer to the\n // template definition.\n if (DEV_MODE && strings.some((s) => s === undefined)) {\n console.warn(\n 'Some template strings are undefined.\\n' +\n 'This is probably caused by illegal octal escape sequences.'\n );\n }\n if (DEV_MODE) {\n // Import static-html.js results in a circular dependency which g3 doesn't\n // handle. Instead we know that static values must have the field\n // `_$litStatic$`.\n if (\n values.some((val) => (val as {_$litStatic$: unknown})?.['_$litStatic$'])\n ) {\n issueWarning(\n '',\n `Static values 'literal' or 'unsafeStatic' cannot be used as values to non-static templates.\\n` +\n `Please use the static 'html' tag function. See https://lit.dev/docs/templates/expressions/#static-expressions`\n );\n }\n }\n return {\n // This property needs to remain unminified.\n ['_$litType$']: type,\n strings,\n values,\n };\n };\n\n/**\n * Interprets a template literal as an HTML template that can efficiently\n * render to and update a container.\n *\n * ```ts\n * const header = (title: string) => html`<h1>${title}</h1>`;\n * ```\n *\n * The `html` tag returns a description of the DOM to render as a value. It is\n * lazy, meaning no work is done until the template is rendered. When rendering,\n * if a template comes from the same expression as a previously rendered result,\n * it's efficiently updated instead of replaced.\n */\nexport const html = tag(HTML_RESULT);\n\n/**\n * Interprets a template literal as an SVG fragment that can efficiently render\n * to and update a container.\n *\n * ```ts\n * const rect = svg`<rect width=\"10\" height=\"10\"></rect>`;\n *\n * const myImage = html`\n * <svg viewBox=\"0 0 10 10\" xmlns=\"http://www.w3.org/2000/svg\">\n * ${rect}\n * </svg>`;\n * ```\n *\n * The `svg` *tag function* should only be used for SVG fragments, or elements\n * that would be contained **inside** an `<svg>` HTML element. A common error is\n * placing an `<svg>` *element* in a template tagged with the `svg` tag\n * function. The `<svg>` element is an HTML element and should be used within a\n * template tagged with the {@linkcode html} tag function.\n *\n * In LitElement usage, it's invalid to return an SVG fragment from the\n * `render()` method, as the SVG fragment will be contained within the element's\n * shadow root and thus not be properly contained within an `<svg>` HTML\n * element.\n */\nexport const svg = tag(SVG_RESULT);\n\n/**\n * Interprets a template literal as MathML fragment that can efficiently render\n * to and update a container.\n *\n * ```ts\n * const num = mathml`<mn>1</mn>`;\n *\n * const eq = html`\n * <math>\n * ${num}\n * </math>`;\n * ```\n *\n * The `mathml` *tag function* should only be used for MathML fragments, or\n * elements that would be contained **inside** a `<math>` HTML element. A common\n * error is placing a `<math>` *element* in a template tagged with the `mathml`\n * tag function. The `<math>` element is an HTML element and should be used\n * within a template tagged with the {@linkcode html} tag function.\n *\n * In LitElement usage, it's invalid to return an MathML fragment from the\n * `render()` method, as the MathML fragment will be contained within the\n * element's shadow root and thus not be properly contained within a `<math>`\n * HTML element.\n */\nexport const mathml = tag(MATHML_RESULT);\n\n/**\n * A sentinel value that signals that a value was handled by a directive and\n * should not be written to the DOM.\n */\nexport const noChange = Symbol.for('lit-noChange');\n\n/**\n * A sentinel value that signals a ChildPart to fully clear its content.\n *\n * ```ts\n * const button = html`${\n * user.isAdmin\n * ? html`<button>DELETE</button>`\n * : nothing\n * }`;\n * ```\n *\n * Prefer using `nothing` over other falsy values as it provides a consistent\n * behavior between various expression binding contexts.\n *\n * In child expressions, `undefined`, `null`, `''`, and `nothing` all behave the\n * same and render no nodes. In attribute expressions, `nothing` _removes_ the\n * attribute, while `undefined` and `null` will render an empty string. In\n * property expressions `nothing` becomes `undefined`.\n */\nexport const nothing = Symbol.for('lit-nothing');\n\n/**\n * The cache of prepared templates, keyed by the tagged TemplateStringsArray\n * and _not_ accounting for the specific template tag used. This means that\n * template tags cannot be dynamic - they must statically be one of html, svg,\n * or attr. This restriction simplifies the cache lookup, which is on the hot\n * path for rendering.\n */\nconst templateCache = new WeakMap<TemplateStringsArray, Template>();\n\n/**\n * Object specifying options for controlling lit-html rendering. Note that\n * while `render` may be called multiple times on the same `container` (and\n * `renderBefore` reference node) to efficiently update the rendered content,\n * only the options passed in during the first render are respected during\n * the lifetime of renders to that unique `container` + `renderBefore`\n * combination.\n */\nexport interface RenderOptions {\n /**\n * An object to use as the `this` value for event listeners. It's often\n * useful to set this to the host component rendering a template.\n */\n host?: object;\n /**\n * A DOM node before which to render content in the container.\n */\n renderBefore?: ChildNode | null;\n /**\n * Node used for cloning the template (`importNode` will be called on this\n * node). This controls the `ownerDocument` of the rendered DOM, along with\n * any inherited context. Defaults to the global `document`.\n */\n creationScope?: {importNode(node: Node, deep?: boolean): Node};\n /**\n * The initial connected state for the top-level part being rendered. If no\n * `isConnected` option is set, `AsyncDirective`s will be connected by\n * default. Set to `false` if the initial render occurs in a disconnected tree\n * and `AsyncDirective`s should see `isConnected === false` for their initial\n * render. The `part.setConnected()` method must be used subsequent to initial\n * render to change the connected state of the part.\n */\n isConnected?: boolean;\n}\n\n/**\n * The root DOM node for rendering.\n */\nexport type RenderRootNode = HTMLElement | SVGElement | DocumentFragment;\n\nconst walker = d.createTreeWalker(\n d,\n 129 /* NodeFilter.SHOW_{ELEMENT|COMMENT} */\n);\n\nlet sanitizerFactoryInternal: SanitizerFactory = noopSanitizer;\n\n//\n// Classes only below here, const variable declarations only above here...\n//\n// Keeping variable declarations and classes together improves minification.\n// Interfaces and type aliases can be interleaved freely.\n//\n\n// Type for classes that have a `_directive` or `_directives[]` field, used by\n// `resolveDirective`\nexport interface DirectiveParent {\n _$parent?: DirectiveParent;\n _$isConnected: boolean;\n __directive?: Directive;\n __directives?: Array<Directive | undefined>;\n}\n\nfunction trustFromTemplateString(\n tsa: TemplateStringsArray,\n stringFromTSA: string\n): TrustedHTML {\n // A security check to prevent spoofing of Lit template results.\n // In the future, we may be able to replace this with Array.isTemplateObject,\n // though we might need to make that check inside of the html and svg\n // functions, because precompiled templates don't come in as\n // TemplateStringArray objects.\n if (!isArray(tsa) || !tsa.hasOwnProperty('raw')) {\n let message = 'invalid template strings array';\n if (DEV_MODE) {\n message = `\n Internal Error: expected template strings to be an array\n with a 'raw' field. Faking a template strings array by\n calling html or svg like an ordinary function is effectively\n the same as calling unsafeHtml and can lead to major security\n issues, e.g. opening your code up to XSS attacks.\n If you're using the html or svg tagged template functions normally\n and still seeing this error, please file a bug at\n https://github.com/lit/lit/issues/new?template=bug_report.md\n and include information about your build tooling, if any.\n `\n .trim()\n .replace(/\\n */g, '\\n');\n }\n throw new Error(message);\n }\n return policy !== undefined\n ? policy.createHTML(stringFromTSA)\n : (stringFromTSA as unknown as TrustedHTML);\n}\n\n/**\n * Returns an HTML string for the given TemplateStringsArray and result type\n * (HTML or SVG), along with the case-sensitive bound attribute names in\n * template order. The HTML contains comment markers denoting the `ChildPart`s\n * and suffixes on bound attributes denoting the `AttributeParts`.\n *\n * @param strings template strings array\n * @param type HTML or SVG\n * @return Array containing `[html, attrNames]` (array returned for terseness,\n * to avoid object fields since this code is shared with non-minified SSR\n * code)\n */\nconst getTemplateHtml = (\n strings: TemplateStringsArray,\n type: ResultType\n): [TrustedHTML, Array<string>] => {\n // Insert makers into the template HTML to represent the position of\n // bindings. The following code scans the template strings to determine the\n // syntactic position of the bindings. They can be in text position, where\n // we insert an HTML comment, attribute value position, where we insert a\n // sentinel string and re-write the attribute name, or inside a tag where\n // we insert the sentinel string.\n const l = strings.length - 1;\n // Stores the case-sensitive bound attribute names in the order of their\n // parts. ElementParts are also reflected in this array as undefined\n // rather than a string, to disambiguate from attribute bindings.\n const attrNames: Array<string> = [];\n let html =\n type === SVG_RESULT ? '<svg>' : type === MATHML_RESULT ? '<math>' : '';\n\n // When we're inside a raw text tag (not it's text content), the regex\n // will still be tagRegex so we can find attributes, but will switch to\n // this regex when the tag ends.\n let rawTextEndRegex: RegExp | undefined;\n\n // The current parsing state, represented as a reference to one of the\n // regexes\n let regex = textEndRegex;\n\n for (let i = 0; i < l; i++) {\n const s = strings[i];\n // The index of the end of the last attribute name. When this is\n // positive at end of a string, it means we're in an attribute value\n // position and need to rewrite the attribute name.\n // We also use a special value of -2 to indicate that we encountered\n // the end of a string in attribute name position.\n let attrNameEndIndex = -1;\n let attrName: string | undefined;\n let lastIndex = 0;\n let match!: RegExpExecArray | null;\n\n // The conditions in this loop handle the current parse state, and the\n // assignments to the `regex` variable are the state transitions.\n while (lastIndex < s.length) {\n // Make sure we start searching from where we previously left off\n regex.lastIndex = lastIndex;\n match = regex.exec(s);\n if (match === null) {\n break;\n }\n lastIndex = regex.lastIndex;\n if (regex === textEndRegex) {\n if (match[COMMENT_START] === '!--') {\n regex = commentEndRegex;\n } else if (match[COMMENT_START] !== undefined) {\n // We started a weird comment, like </{\n regex = comment2EndRegex;\n } else if (match[TAG_NAME] !== undefined) {\n if (rawTextElement.test(match[TAG_NAME])) {\n // Record if we encounter a raw-text element. We'll switch to\n // this regex at the end of the tag.\n rawTextEndRegex = new RegExp(`</${match[TAG_NAME]}`, 'g');\n }\n regex = tagEndRegex;\n } else if (match[DYNAMIC_TAG_NAME] !== undefined) {\n if (DEV_MODE) {\n throw new Error(\n 'Bindings in tag names are not supported. Please use static templates instead. ' +\n 'See https://lit.dev/docs/templates/expressions/#static-expressions'\n );\n }\n regex = tagEndRegex;\n }\n } else if (regex === tagEndRegex) {\n if (match[ENTIRE_MATCH] === '>') {\n // End of a tag. If we had started a raw-text element, use that\n // regex\n regex = rawTextEndRegex ?? textEndRegex;\n // We may be ending an unquoted attribute value, so make sure we\n // clear any pending attrNameEndIndex\n attrNameEndIndex = -1;\n } else if (match[ATTRIBUTE_NAME] === undefined) {\n // Attribute name position\n attrNameEndIndex = -2;\n } else {\n attrNameEndIndex = regex.lastIndex - match[SPACES_AND_EQUALS].length;\n attrName = match[ATTRIBUTE_NAME];\n regex =\n match[QUOTE_CHAR] === undefined\n ? tagEndRegex\n : match[QUOTE_CHAR] === '\"'\n ? doubleQuoteAttrEndRegex\n : singleQuoteAttrEndRegex;\n }\n } else if (\n regex === doubleQuoteAttrEndRegex ||\n regex === singleQuoteAttrEndRegex\n ) {\n regex = tagEndRegex;\n } else if (regex === commentEndRegex || regex === comment2EndRegex) {\n regex = textEndRegex;\n } else {\n // Not one of the five state regexes, so it must be the dynamically\n // created raw text regex and we're at the close of that element.\n regex = tagEndRegex;\n rawTextEndRegex = undefined;\n }\n }\n\n if (DEV_MODE) {\n // If we have a attrNameEndIndex, which indicates that we should\n // rewrite the attribute name, assert that we're in a valid attribute\n // position - either in a tag, or a quoted attribute value.\n console.assert(\n attrNameEndIndex === -1 ||\n regex === tagEndRegex ||\n regex === singleQuoteAttrEndRegex ||\n regex === doubleQuoteAttrEndRegex,\n 'unexpected parse state B'\n );\n }\n\n // We have four cases:\n // 1. We're in text position, and not in a raw text element\n // (regex === textEndRegex): insert a comment marker.\n // 2. We have a non-negative attrNameEndIndex which means we need to\n // rewrite the attribute name to add a bound attribute suffix.\n // 3. We're at the non-first binding in a multi-binding attribute, use a\n // plain marker.\n // 4. We're somewhere else inside the tag. If we're in attribute name\n // position (attrNameEndIndex === -2), add a sequential suffix to\n // generate a unique attribute name.\n\n // Detect a binding next to self-closing tag end and insert a space to\n // separate the marker from the tag end:\n const end =\n regex === tagEndRegex && strings[i + 1].startsWith('/>') ? ' ' : '';\n html +=\n regex === textEndRegex\n ? s + nodeMarker\n : attrNameEndIndex >= 0\n ? (attrNames.push(attrName!),\n s.slice(0, attrNameEndIndex) +\n boundAttributeSuffix +\n s.slice(attrNameEndIndex)) +\n marker +\n end\n : s + marker + (attrNameEndIndex === -2 ? i : end);\n }\n\n const htmlResult: string | TrustedHTML =\n html +\n (strings[l] || '<?>') +\n (type === SVG_RESULT ? '</svg>' : type === MATHML_RESULT ? '</math>' : '');\n\n // Returned as an array for terseness\n return [trustFromTemplateString(strings, htmlResult), attrNames];\n};\n\n/** @internal */\nexport type {Template};\nclass Template {\n /** @internal */\n el!: HTMLTemplateElement;\n\n parts: Array<TemplatePart> = [];\n\n constructor(\n // This property needs to remain unminified.\n {strings, ['_$litType$']: type}: UncompiledTemplateResult,\n options?: RenderOptions\n ) {\n let node: Node | null;\n let nodeIndex = 0;\n let attrNameIndex = 0;\n const partCount = strings.length - 1;\n const parts = this.parts;\n\n // Create template element\n const [html, attrNames] = getTemplateHtml(strings, type);\n this.el = Template.createElement(html, options);\n walker.currentNode = this.el.content;\n\n // Re-parent SVG or MathML nodes into template root\n if (type === SVG_RESULT || type === MATHML_RESULT) {\n const wrapper = this.el.content.firstChild!;\n wrapper.replaceWith(...wrapper.childNodes);\n }\n\n // Walk the template to find binding markers and create TemplateParts\n while ((node = walker.nextNode()) !== null && parts.length < partCount) {\n if (node.nodeType === 1) {\n if (DEV_MODE) {\n const tag = (node as Element).localName;\n // Warn if `textarea` includes an expression and throw if `template`\n // does since these are not supported. We do this by checking\n // innerHTML for anything that looks like a marker. This catches\n // cases like bindings in textarea there markers turn into text nodes.\n if (\n /^(?:textarea|template)$/i!.test(tag) &&\n (node as Element).innerHTML.includes(marker)\n ) {\n const m =\n `Expressions are not supported inside \\`${tag}\\` ` +\n `elements. See https://lit.dev/msg/expression-in-${tag} for more ` +\n `information.`;\n if (tag === 'template') {\n throw new Error(m);\n } else issueWarning('', m);\n }\n }\n // TODO (justinfagnani): for attempted dynamic tag names, we don't\n // increment the bindingIndex, and it'll be off by 1 in the element\n // and off by two after it.\n if ((node as Element).hasAttributes()) {\n for (const name of (node as Element).getAttributeNames()) {\n if (name.endsWith(boundAttributeSuffix)) {\n const realName = attrNames[attrNameIndex++];\n const value = (node as Element).getAttribute(name)!;\n const statics = value.split(marker);\n const m = /([.?@])?(.*)/.exec(realName)!;\n parts.push({\n type: ATTRIBUTE_PART,\n index: nodeIndex,\n name: m[2],\n strings: statics,\n ctor:\n m[1] === '.'\n ? PropertyPart\n : m[1] === '?'\n ? BooleanAttributePart\n : m[1] === '@'\n ? EventPart\n : AttributePart,\n });\n (node as Element).removeAttribute(name);\n } else if (name.startsWith(marker)) {\n parts.push({\n type: ELEMENT_PART,\n index: nodeIndex,\n });\n (node as Element).removeAttribute(name);\n }\n }\n }\n // TODO (justinfagnani): benchmark the regex against testing for each\n // of the 3 raw text element names.\n if (rawTextElement.test((node as Element).tagName)) {\n // For raw text elements we need to split the text content on\n // markers, create a Text node for each segment, and create\n // a TemplatePart for each marker.\n const strings = (node as Element).textContent!.split(marker);\n const lastIndex = strings.length - 1;\n if (lastIndex > 0) {\n (node as Element).textContent = trustedTypes\n ? (trustedTypes.emptyScript as unknown as '')\n : '';\n // Generate a new text node for each literal section\n // These nodes are also used as the markers for child parts\n for (let i = 0; i < lastIndex; i++) {\n (node as Element).append(strings[i], createMarker());\n // Walk past the marker node we just added\n walker.nextNode();\n parts.push({type: CHILD_PART, index: ++nodeIndex});\n }\n // Note because this marker is added after the walker's current\n // node, it will be walked to in the outer loop (and ignored), so\n // we don't need to adjust nodeIndex here\n (node as Element).append(strings[lastIndex], createMarker());\n }\n }\n } else if (node.nodeType === 8) {\n const data = (node as Comment).data;\n if (data === markerMatch) {\n parts.push({type: CHILD_PART, index: nodeIndex});\n } else {\n let i = -1;\n while ((i = (node as Comment).data.indexOf(marker, i + 1)) !== -1) {\n // Comment node has a binding marker inside, make an inactive part\n // The binding won't work, but subsequent bindings will\n parts.push({type: COMMENT_PART, index: nodeIndex});\n // Move to the end of the match\n i += marker.length - 1;\n }\n }\n }\n nodeIndex++;\n }\n\n if (DEV_MODE) {\n // If there was a duplicate attribute on a tag, then when the tag is\n // parsed into an element the attribute gets de-duplicated. We can detect\n // this mismatch if we haven't precisely consumed every attribute name\n // when preparing the template. This works because `attrNames` is built\n // from the template string and `attrNameIndex` comes from processing the\n // resulting DOM.\n if (attrNames.length !== attrNameIndex) {\n throw new Error(\n `Detected duplicate attribute bindings. This occurs if your template ` +\n `has duplicate attributes on an element tag. For example ` +\n `\"<input ?disabled=\\${true} ?disabled=\\${false}>\" contains a ` +\n `duplicate \"disabled\" attribute. The error was detected in ` +\n `the following template: \\n` +\n '`' +\n strings.join('${...}') +\n '`'\n );\n }\n }\n\n // We could set walker.currentNode to another node here to prevent a memory\n // leak, but every time we prepare a template, we immediately render it\n // and re-use the walker in new TemplateInstance._clone().\n debugLogEvent &&\n debugLogEvent({\n kind: 'template prep',\n template: this,\n clonableTemplate: this.el,\n parts: this.parts,\n strings,\n });\n }\n\n // Overridden via `litHtmlPolyfillSupport` to provide platform support.\n /** @nocollapse */\n static createElement(html: TrustedHTML, _options?: RenderOptions) {\n const el = d.createElement('template');\n el.innerHTML = html as unknown as string;\n return el;\n }\n}\n\nexport interface Disconnectable {\n _$parent?: Disconnectable;\n _$disconnectableChildren?: Set<Disconnectable>;\n // Rather than hold connection state on instances, Disconnectables recursively\n // fetch the connection state from the RootPart they are connected in via\n // getters up the Disconnectable tree via _$parent references. This pushes the\n // cost of tracking the isConnected state to `AsyncDirectives`, and avoids\n // needing to pass all Disconnectables (parts, template instances, and\n // directives) their connection state each time it changes, which would be\n // costly for trees that have no AsyncDirectives.\n _$isConnected: boolean;\n}\n\nfunction resolveDirective(\n part: ChildPart | AttributePart | ElementPart,\n value: unknown,\n parent: DirectiveParent = part,\n attributeIndex?: number\n): unknown {\n // Bail early if the value is explicitly noChange. Note, this means any\n // nested directive is still attached and is not run.\n if (value === noChange) {\n return value;\n }\n let currentDirective =\n attributeIndex !== undefined\n ? (parent as AttributePart).__directives?.[attributeIndex]\n : (parent as ChildPart | ElementPart | Directive).__directive;\n const nextDirectiveConstructor = isPrimitive(value)\n ? undefined\n : // This property needs to remain unminified.\n (value as DirectiveResult)['_$litDirective$'];\n if (currentDirective?.constructor !== nextDirectiveConstructor) {\n // This property needs to remain unminified.\n currentDirective?.['_$notifyDirectiveConnectionChanged']?.(false);\n if (nextDirectiveConstructor === undefined) {\n currentDirective = undefined;\n } else {\n currentDirective = new nextDirectiveConstructor(part as PartInfo);\n currentDirective._$initialize(part, parent, attributeIndex);\n }\n if (attributeIndex !== undefined) {\n ((parent as AttributePart).__directives ??= [])[attributeIndex] =\n currentDirective;\n } else {\n (parent as ChildPart | Directive).__directive = currentDirective;\n }\n }\n if (currentDirective !== undefined) {\n value = resolveDirective(\n part,\n currentDirective._$resolve(part, (value as DirectiveResult).values),\n currentDirective,\n attributeIndex\n );\n }\n return value;\n}\n\nexport type {TemplateInstance};\n/**\n * An updateable instance of a Template. Holds references to the Parts used to\n * update the template instance.\n */\nclass TemplateInstance implements Disconnectable {\n _$template: Template;\n _$parts: Array<Part | undefined> = [];\n\n /** @internal */\n _$parent: ChildPart;\n /** @internal */\n _$disconnectableChildren?: Set<Disconnectable> = undefined;\n\n constructor(template: Template, parent: ChildPart) {\n this._$template = template;\n this._$parent = parent;\n }\n\n // Called by ChildPart parentNode getter\n get parentNode() {\n return this._$parent.parentNode;\n }\n\n // See comment in Disconnectable interface for why this is a getter\n get _$isConnected() {\n return this._$parent._$isConnected;\n }\n\n // This method is separate from the constructor because we need to return a\n // DocumentFragment and we don't want to hold onto it with an instance field.\n _clone(options: RenderOptions | undefined) {\n const {\n el: {content},\n parts: parts,\n } = this._$template;\n const fragment = (options?.creationScope ?? d).importNode(content, true);\n walker.currentNode = fragment;\n\n let node = walker.nextNode()!;\n let nodeIndex = 0;\n let partIndex = 0;\n let templatePart = parts[0];\n\n while (templatePart !== undefined) {\n if (nodeIndex === templatePart.index) {\n let part: Part | undefined;\n if (templatePart.type === CHILD_PART) {\n part = new ChildPart(\n node as HTMLElement,\n node.nextSibling,\n this,\n options\n );\n } else if (templatePart.type === ATTRIBUTE_PART) {\n part = new templatePart.ctor(\n node as HTMLElement,\n templatePart.name,\n templatePart.strings,\n this,\n options\n );\n } else if (templatePart.type === ELEMENT_PART) {\n part = new ElementPart(node as HTMLElement, this, options);\n }\n this._$parts.push(part);\n templatePart = parts[++partIndex];\n }\n if (nodeIndex !== templatePart?.index) {\n node = walker.nextNode()!;\n nodeIndex++;\n }\n }\n // We need to set the currentNode away from the cloned tree so that we\n // don't hold onto the tree even if the tree is detached and should be\n // freed.\n walker.currentNode = d;\n return fragment;\n }\n\n _update(values: Array<unknown>) {\n let i = 0;\n for (const part of this._$parts) {\n if (part !== undefined) {\n debugLogEvent &&\n debugLogEvent({\n kind: 'set part',\n part,\n value: values[i],\n valueIndex: i,\n values,\n templateInstance: this,\n });\n if ((part as AttributePart).strings !== undefined) {\n (part as AttributePart)._$setValue(values, part as AttributePart, i);\n // The number of values the part consumes is part.strings.length - 1\n // since values are in between template spans. We increment i by 1\n // later in the loop, so increment it by part.strings.length - 2 here\n i += (part as AttributePart).strings!.length - 2;\n } else {\n part._$setValue(values[i]);\n }\n }\n i++;\n }\n }\n}\n\n/*\n * Parts\n */\ntype AttributeTemplatePart = {\n readonly type: typeof ATTRIBUTE_PART;\n readonly index: number;\n readonly name: string;\n readonly ctor: typeof AttributePart;\n readonly strings: ReadonlyArray<string>;\n};\ntype ChildTemplatePart = {\n readonly type: typeof CHILD_PART;\n readonly index: number;\n};\ntype ElementTemplatePart = {\n readonly type: typeof ELEMENT_PART;\n readonly index: number;\n};\ntype CommentTemplatePart = {\n readonly type: typeof COMMENT_PART;\n readonly index: number;\n};\n\n/**\n * A TemplatePart represents a dynamic part in a template, before the template\n * is instantiated. When a template is instantiated Parts are created from\n * TemplateParts.\n */\ntype TemplatePart =\n | ChildTemplatePart\n | AttributeTemplatePart\n | ElementTemplatePart\n | CommentTemplatePart;\n\nexport type Part =\n | ChildPart\n | AttributePart\n | PropertyPart\n | BooleanAttributePart\n | ElementPart\n | EventPart;\n\nexport type {ChildPart};\nclass ChildPart implements Disconnectable {\n readonly type = CHILD_PART;\n readonly options: RenderOptions | undefined;\n _$committedValue: unknown = nothing;\n /** @internal */\n __directive?: Directive;\n /** @internal */\n _$startNode: ChildNode;\n /** @internal */\n _$endNode: ChildNode | null;\n private _textSanitizer: ValueSanitizer | undefined;\n /** @internal */\n _$parent: Disconnectable | undefined;\n /**\n * Connection state for RootParts only (i.e. ChildPart without _$parent\n * returned from top-level `render`). This field is unused otherwise. The\n * intention would be clearer if we made `RootPart` a subclass of `ChildPart`\n * with this field (and a different _$isConnected getter), but the subclass\n * caused a perf regression, possibly due to making call sites polymorphic.\n * @internal\n */\n __isConnected: boolean;\n\n // See comment in Disconnectable interface for why this is a getter\n get _$isConnected() {\n // ChildParts that are not at the root should always be created with a\n // parent; only RootChildNode's won't, so they return the local isConnected\n // state\n return this._$parent?._$isConnected ?? this.__isConnected;\n }\n\n // The following fields will be patched onto ChildParts when required by\n // AsyncDirective\n /** @internal */\n _$disconnectableChildren?: Set<Disconnectable> = undefined;\n /** @internal */\n _$notifyConnectionChanged?(\n isConnected: boolean,\n removeFromParent?: boolean,\n from?: number\n ): void;\n /** @internal */\n _$reparentDisconnectables?(parent: Disconnectable): void;\n\n constructor(\n startNode: ChildNode,\n endNode: ChildNode | null,\n parent: TemplateInstance | ChildPart | undefined,\n options: RenderOptions | undefined\n ) {\n this._$startNode = startNode;\n this._$endNode = endNode;\n this._$parent = parent;\n this.options = options;\n // Note __isConnected is only ever accessed on RootParts (i.e. when there is\n // no _$parent); the value on a non-root-part is \"don't care\", but checking\n // for parent would be more code\n this.__isConnected = options?.isConnected ?? true;\n if (ENABLE_EXTRA_SECURITY_HOOKS) {\n // Explicitly initialize for consistent class shape.\n this._textSanitizer = undefined;\n }\n }\n\n /**\n * The parent node into which the part renders its content.\n *\n * A ChildPart's content consists of a range of adjacent child nodes of\n * `.parentNode`, possibly bordered by 'marker nodes' (`.startNode` and\n * `.endNode`).\n *\n * - If both `.startNode` and `.endNode` are non-null, then the part's content\n * consists of all siblings between `.startNode` and `.endNode`, exclusively.\n *\n * - If `.startNode` is non-null but `.endNode` is null, then the part's\n * content consists of all siblings following `.startNode`, up to and\n * including the last child of `.parentNode`. If `.endNode` is non-null, then\n * `.startNode` will always be non-null.\n *\n * - If both `.endNode` and `.startNode` are null, then the part's content\n * consists of all child nodes of `.parentNode`.\n */\n get parentNode(): Node {\n let parentNode: Node = wrap(this._$startNode).parentNode!;\n const parent = this._$parent;\n if (\n parent !== undefined &&\n parentNode?.nodeType === 11 /* Node.DOCUMENT_FRAGMENT */\n ) {\n // If the parentNode is a DocumentFragment, it may be because the DOM is\n // still in the cloned fragment during initial render; if so, get the real\n // parentNode the part will be committed into by asking the parent.\n parentNode = (parent as ChildPart | TemplateInstance).parentNode;\n }\n return parentNode;\n }\n\n /**\n * The part's leading marker node, if any. See `.parentNode` for more\n * information.\n */\n get startNode(): Node | null {\n return this._$startNode;\n }\n\n /**\n * The part's trailing marker node, if any. See `.parentNode` for more\n * information.\n */\n get endNode(): Node | null {\n return this._$endNode;\n }\n\n _$setValue(value: unknown, directiveParent: DirectiveParent = this): void {\n if (DEV_MODE && this.parentNode === null) {\n throw new Error(\n `This \\`ChildPart\\` has no \\`parentNode\\` and therefore cannot accept a value. This likely means the element containing the part was manipulated in an unsupported way outside of Lit's control such that the part's marker nodes were ejected from DOM. For example, setting the element's \\`innerHTML\\` or \\`textContent\\` can do this.`\n );\n }\n value = resolveDirective(this, value, directiveParent);\n if (isPrimitive(value)) {\n // Non-rendering child values. It's important that these do not render\n // empty text nodes to avoid issues with preventing default <slot>\n // fallback content.\n if (value === nothing || value == null || value === '') {\n if (this._$committedValue !== nothing) {\n debugLogEvent &&\n debugLogEvent({\n kind: 'commit nothing to child',\n start: this._$startNode,\n end: this._$endNode,\n parent: this._$parent,\n options: this.options,\n });\n this._$clear();\n }\n this._$committedValue = nothing;\n } else if (value !== this._$committedValue && value !== noChange) {\n this._commitText(value);\n }\n // This property needs to remain unminified.\n } else if ((value as TemplateResult)['_$litType$'] !== undefined) {\n this._commitTemplateResult(value as TemplateResult);\n } else if ((value as Node).nodeType !== undefined) {\n if (DEV_MODE && this.options?.host === value) {\n this._commitText(\n `[probable mistake: rendered a template's host in itself ` +\n `(commonly caused by writing \\${this} in a template]`\n );\n console.warn(\n `Attempted to render the template host`,\n value,\n `inside itself. This is almost always a mistake, and in dev mode `,\n `we render some warning text. In production however, we'll `,\n `render it, which will usually result in an error, and sometimes `,\n `in the element disappearing from the DOM.`\n );\n return;\n }\n this._commitNode(value as Node);\n } else if (isIterable(value)) {\n this._commitIterable(value);\n } else {\n // Fallback, will render the string representation\n this._commitText(value);\n }\n }\n\n private _insert<T extends Node>(node: T) {\n return wrap(wrap(this._$startNode).parentNode!).insertBefore(\n node,\n this._$endNode\n );\n }\n\n private _commitNode(value: Node): void {\n if (this._$committedValue !== value) {\n this._$clear();\n if (\n ENABLE_EXTRA_SECURITY_HOOKS &&\n sanitizerFactoryInternal !== noopSanitizer\n ) {\n const parentNodeName = this._$startNode.parentNode?.nodeName;\n if (parentNodeName === 'STYLE' || parentNodeName === 'SCRIPT') {\n let message = 'Forbidden';\n if (DEV_MODE) {\n if (parentNodeName === 'STYLE') {\n message =\n `Lit does not support binding inside style nodes. ` +\n `This is a security risk, as style injection attacks can ` +\n `exfiltrate data and spoof UIs. ` +\n `Consider instead using css\\`...\\` literals ` +\n `to compose styles, and do dynamic styling with ` +\n `css custom properties, ::parts, <slot>s, ` +\n `and by mutating the DOM rather than stylesheets.`;\n } else {\n message =\n `Lit does not support binding inside script nodes. ` +\n `This is a security risk, as it could allow arbitrary ` +\n `code execution.`;\n }\n }\n throw new Error(message);\n }\n }\n debugLogEvent &&\n debugLogEvent({\n kind: 'commit node',\n start: this._$startNode,\n parent: this._$parent,\n value: value,\n options: this.options,\n });\n this._$committedValue = this._insert(value);\n }\n }\n\n private _commitText(value: unknown): void {\n // If the committed value is a primitive it means we called _commitText on\n // the previous render, and we know that this._$startNode.nextSibling is a\n // Text node. We can now just replace the text content (.data) of the node.\n if (\n this._$committedValue !== nothing &&\n isPrimitive(this._$committedValue)\n ) {\n const node = wrap(this._$startNode).nextSibling as Text;\n if (ENABLE_EXTRA_SECURITY_HOOKS) {\n if (this._textSanitizer === undefined) {\n this._textSanitizer = createSanitizer(node, 'data', 'property');\n }\n value = this._textSanitizer(value);\n }\n debugLogEvent &&\n debugLogEvent({\n kind: 'commit text',\n node,\n value,\n options: this.options,\n });\n (node as Text).data = value as string;\n } else {\n if (ENABLE_EXTRA_SECURITY_HOOKS) {\n const textNode = d.createTextNode('');\n this._commitNode(textNode);\n // When setting text content, for security purposes it matters a lot\n // what the parent is. For example, <style> and <script> need to be\n // handled with care, while <span> does not. So first we need to put a\n // text node into the document, then we can sanitize its content.\n if (this._textSanitizer === undefined) {\n this._textSanitizer = createSanitizer(textNode, 'data', 'property');\n }\n value = this._textSanitizer(value);\n debugLogEvent &&\n debugLogEvent({\n kind: 'commit text',\n node: textNode,\n value,\n options: this.options,\n });\n textNode.data = value as string;\n } else {\n this._commitNode(d.createTextNode(value as string));\n debugLogEvent &&\n debugLogEvent({\n kind: 'commit text',\n node: wrap(this._$startNode).nextSibling as Text,\n value,\n options: this.options,\n });\n }\n }\n this._$committedValue = value;\n }\n\n private _commitTemplateResult(\n result: TemplateResult | CompiledTemplateResult\n ): void {\n // This property needs to remain unminified.\n const {values, ['_$litType$']: type} = result;\n // If $litType$ is a number, result is a plain TemplateResult and we get\n // the template from the template cache. If not, result is a\n // CompiledTemplateResult and _$litType$ is a CompiledTemplate and we need\n // to create the <template> element the first time we see it.\n const template: Template | CompiledTemplate =\n typeof type === 'number'\n ? this._$getTemplate(result as UncompiledTemplateResult)\n : (type.el === undefined &&\n (type.el = Template.createElement(\n trustFromTemplateString(type.h, type.h[0]),\n this.options\n )),\n type);\n\n if ((this._$committedValue as TemplateInstance)?._$template === template) {\n debugLogEvent &&\n debugLogEvent({\n kind: 'template updating',\n template,\n instance: this._$committedValue as TemplateInstance,\n parts: (this._$committedValue as TemplateInstance)._$parts,\n options: this.options,\n values,\n });\n (this._$committedValue as TemplateInstance)._update(values);\n } else {\n const instance = new TemplateInstance(template as Template, this);\n const fragment = instance._clone(this.options);\n debugLogEvent &&\n debugLogEvent({\n kind: 'template instantiated',\n template,\n instance,\n parts: instance._$parts,\n options: this.options,\n fragment,\n values,\n });\n instance._update(values);\n debugLogEvent &&\n debugLogEvent({\n kind: 'template instantiated and updated',\n template,\n instance,\n parts: instance._$parts,\n options: this.options,\n fragment,\n values,\n });\n this._commitNode(fragment);\n this._$committedValue = instance;\n }\n }\n\n // Overridden via `litHtmlPolyfillSupport` to provide platform support.\n /** @internal */\n _$getTemplate(result: UncompiledTemplateResult) {\n let template = templateCache.get(result.strings);\n if (template === undefined) {\n templateCache.set(result.strings, (template = new Template(result)));\n }\n return template;\n }\n\n private _commitIterable(value: Iterable<unknown>): void {\n // For an Iterable, we create a new InstancePart per item, then set its\n // value to the item. This is a little bit of overhead for every item in\n // an Iterable, but it lets us recurse easily and efficiently update Arrays\n // of TemplateResults that will be commonly returned from expressions like:\n // array.map((i) => html`${i}`), by reusing existing TemplateInstances.\n\n // If value is an array, then the previous render was of an\n // iterable and value will contain the ChildParts from the previous\n // render. If value is not an array, clear this part and make a new\n // array for ChildParts.\n if (!isArray(this._$committedValue)) {\n this._$committedValue = [];\n this._$clear();\n }\n\n // Lets us keep track of how many items we stamped so we can clear leftover\n // items from a previous render\n const itemParts = this._$committedValue as ChildPart[];\n let partIndex = 0;\n let itemPart: ChildPart | undefined;\n\n for (const item of value) {\n if (partIndex === itemParts.length) {\n // If no existing part, create a new one\n // TODO (justinfagnani): test perf impact of always creating two parts\n // instead of sharing parts between nodes\n // https://github.com/lit/lit/issues/1266\n itemParts.push(\n (itemPart = new ChildPart(\n this._insert(createMarker()),\n this._insert(createMarker()),\n this,\n this.options\n ))\n );\n } else {\n // Reuse an existing part\n itemPart = itemParts[partIndex];\n }\n itemPart._$setValue(item);\n partIndex++;\n }\n\n if (partIndex < itemParts.length) {\n // itemParts always have end nodes\n this._$clear(\n itemPart && wrap(itemPart._$endNode!).nextSibling,\n partIndex\n );\n // Truncate the parts array so _value reflects the current state\n itemParts.length = partIndex;\n }\n }\n\n /**\n * Removes the nodes contained within this Part from the DOM.\n *\n * @param start Start node to clear from, for clearing a subset of the part's\n * DOM (used when truncating iterables)\n * @param from When `start` is specified, the index within the iterable from\n * which ChildParts are being removed, used for disconnecting directives\n * in those Parts.\n *\n * @internal\n */\n _$clear(\n start: ChildNode | null = wrap(this._$startNode).nextSibling,\n from?: number\n ) {\n this._$notifyConnectionChanged?.(false, true, from);\n while (start !== this._$endNode) {\n // The non-null assertion is safe because if _$startNode.nextSibling is\n // null, then _$endNode is also null, and we would not have entered this\n // loop.\n const n = wrap(start!).nextSibling;\n wrap(start!).remove();\n start = n;\n }\n }\n\n /**\n * Implementation of RootPart's `isConnected`. Note that this method\n * should only be called on `RootPart`s (the `ChildPart` returned from a\n * top-level `render()` call). It has no effect on non-root ChildParts.\n * @param isConnected Whether to set\n * @internal\n */\n setConnected(isConnected: boolean) {\n if (this._$parent === undefined) {\n this.__isConnected = isConnected;\n this._$notifyConnectionChanged?.(isConnected);\n } else if (DEV_MODE) {\n throw new Error(\n 'part.setConnected() may only be called on a ' +\n 'RootPart returned from render().'\n );\n }\n }\n}\n\n/**\n * A top-level `ChildPart` returned from `render` that manages the connected\n * state of `AsyncDirective`s created throughout the tree below it.\n */\nexport interface RootPart extends ChildPart {\n /**\n * Sets the connection state for `AsyncDirective`s contained within this root\n * ChildPart.\n *\n * lit-html does not automatically monitor the connectedness of DOM rendered;\n * as such, it is the responsibility of the caller to `render` to ensure that\n * `part.setConnected(false)` is called before the part object is potentially\n * discarded, to ensure that `AsyncDirective`s have a chance to dispose of\n * any resources being held. If a `RootPart` that was previously\n * disconnected is subsequently re-connected (and its `AsyncDirective`s should\n * re-connect), `setConnected(true)` should be called.\n *\n * @param isConnected Whether directives within this tree should be connected\n * or not\n */\n setConnected(isConnected: boolean): void;\n}\n\nexport type {AttributePart};\nclass AttributePart implements Disconnectable {\n readonly type:\n | typeof ATTRIBUTE_PART\n | typeof PROPERTY_PART\n | typeof BOOLEAN_ATTRIBUTE_PART\n | typeof EVENT_PART = ATTRIBUTE_PART;\n readonly element: HTMLElement;\n readonly name: string;\n readonly options: RenderOptions | undefined;\n\n /**\n * If this attribute part represents an interpolation, this contains the\n * static strings of the interpolation. For single-value, complete bindings,\n * this is undefined.\n */\n readonly strings?: ReadonlyArray<string>;\n /** @internal */\n _$committedValue: unknown | Array<unknown> = nothing;\n /** @internal */\n __directives?: Array<Directive | undefined>;\n /** @internal */\n _$parent: Disconnectable;\n /** @internal */\n _$disconnectableChildren?: Set<Disconnectable> = undefined;\n\n protected _sanitizer: ValueSanitizer | undefined;\n\n get tagName() {\n return this.element.tagName;\n }\n\n // See comment in Disconnectable interface for why this is a getter\n get _$isConnected() {\n return this._$parent._$isConnected;\n }\n\n constructor(\n element: HTMLElement,\n name: string,\n strings: ReadonlyArray<string>,\n parent: Disconnectable,\n options: RenderOptions | undefined\n ) {\n this.element = element;\n this.name = name;\n this._$parent = parent;\n this.options = options;\n if (strings.length > 2 || strings[0] !== '' || strings[1] !== '') {\n this._$committedValue = new Array(strings.length - 1).fill(new String());\n this.strings = strings;\n } else {\n this._$committedValue = nothing;\n }\n if (ENABLE_EXTRA_SECURITY_HOOKS) {\n this._sanitizer = undefined;\n }\n }\n\n /**\n * Sets the value of this part by resolving the value from possibly multiple\n * values and static strings and committing it to the DOM.\n * If this part is single-valued, `this._strings` will be undefined, and the\n * method will be called with a single value argument. If this part is\n * multi-value, `this._strings` will be defined, and the method is called\n * with the value array of the part's owning TemplateInstance, and an offset\n * into the value array from which the values should be read.\n * This method is overloaded this way to eliminate short-lived array slices\n * of the template instance values, and allow a fast-path for single-valued\n * parts.\n *\n * @param value The part value, or an array of values for multi-valued parts\n * @param valueIndex the index to start reading values from. `undefined` for\n * single-valued parts\n * @param noCommit causes the part to not commit its value to the DOM. Used\n * in hydration to prime attribute parts with their first-rendered value,\n * but not set the attribute, and in SSR to no-op the DOM operation and\n * capture the value for serialization.\n *\n * @internal\n */\n _$setValue(\n value: unknown | Array<unknown>,\n directiveParent: DirectiveParent = this,\n valueIndex?: number,\n noCommit?: boolean\n ) {\n const strings = this.strings;\n\n // Whether any of the values has changed, for dirty-checking\n let change = false;\n\n if (strings === undefined) {\n // Single-value binding case\n value = resolveDirective(this, value, directiveParent, 0);\n change =\n !isPrimitive(value) ||\n (value !== this._$committedValue && value !== noChange);\n if (change) {\n this._$committedValue = value;\n }\n } else {\n // Interpolation case\n const values = value as Array<unknown>;\n value = strings[0];\n\n let i, v;\n for (i = 0; i < strings.length - 1; i++) {\n v = resolveDirective(this, values[valueIndex! + i], directiveParent, i);\n\n if (v === noChange) {\n // If the user-provided value is `noChange`, use the previous value\n v = (this._$committedValue as Array<unknown>)[i];\n }\n change ||=\n !isPrimitive(v) || v !== (this._$committedValue as Array<unknown>)[i];\n if (v === nothing) {\n value = nothing;\n } else if (value !== nothing) {\n value += (v ?? '') + strings[i + 1];\n }\n // We always record each value, even if one is `nothing`, for future\n // change detection.\n (this._$committedValue as Array<unknown>)[i] = v;\n }\n }\n if (change && !noCommit) {\n this._commitValue(value);\n }\n }\n\n /** @internal */\n _commitValue(value: unknown) {\n if (value === nothing) {\n (wrap(this.element) as Element).removeAttribute(this.name);\n } else {\n if (ENABLE_EXTRA_SECURITY_HOOKS) {\n if (this._sanitizer === undefined) {\n this._sanitizer = sanitizerFactoryInternal(\n this.element,\n this.name,\n 'attribute'\n );\n }\n value = this._sanitizer(value ?? '');\n }\n debugLogEvent &&\n debugLogEvent({\n kind: 'commit attribute',\n element: this.element,\n name: this.name,\n value,\n options: this.options,\n });\n (wrap(this.element) as Element).setAttribute(\n this.name,\n (value ?? '') as string\n );\n }\n }\n}\n\nexport type {PropertyPart};\nclass PropertyPart extends AttributePart {\n override readonly type = PROPERTY_PART;\n\n /** @internal */\n override _commitValue(value: unknown) {\n if (ENABLE_EXTRA_SECURITY_HOOKS) {\n if (this._sanitizer === undefined) {\n this._sanitizer = sanitizerFactoryInternal(\n this.element,\n this.name,\n 'property'\n );\n }\n value = this._sanitizer(value);\n }\n debugLogEvent &&\n debugLogEvent({\n kind: 'commit property',\n element: this.element,\n name: this.name,\n value,\n options: this.options,\n });\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (this.element as any)[this.name] = value === nothing ? undefined : value;\n }\n}\n\nexport type {BooleanAttributePart};\nclass BooleanAttributePart extends AttributePart {\n override readonly type = BOOLEAN_ATTRIBUTE_PART;\n\n /** @internal */\n override _commitValue(value: unknown) {\n debugLogEvent &&\n debugLogEvent({\n kind: 'commit boolean attribute',\n element: this.element,\n name: this.name,\n value: !!(value && value !== nothing),\n options: this.options,\n });\n (wrap(this.element) as Element).toggleAttribute(\n this.name,\n !!value && value !== nothing\n );\n }\n}\n\ntype EventListenerWithOptions = EventListenerOrEventListenerObject &\n Partial<AddEventListenerOptions>;\n\n/**\n * An AttributePart that manages an event listener via add/removeEventListener.\n *\n * This part works by adding itself as the event listener on an element, then\n * delegating to the value passed to it. This reduces the number of calls to\n * add/removeEventListener if the listener changes frequently, such as when an\n * inline function is used as a listener.\n *\n * Because event options are passed when adding listeners, we must take case\n * to add and remove the part as a listener when the event options change.\n */\nexport type {EventPart};\nclass EventPart extends AttributePart {\n override readonly type = EVENT_PART;\n\n constructor(\n element: HTMLElement,\n name: string,\n strings: ReadonlyArray<string>,\n parent: Disconnectable,\n options: RenderOptions | undefined\n ) {\n super(element, name, strings, parent, options);\n\n if (DEV_MODE && this.strings !== undefined) {\n throw new Error(\n `A \\`<${element.localName}>\\` has a \\`@${name}=...\\` listener with ` +\n 'invalid content. Event listeners in templates must have exactly ' +\n 'one expression and no surrounding text.'\n );\n }\n }\n\n // EventPart does not use the base _$setValue/_resolveValue implementation\n // since the dirty checking is more complex\n /** @internal */\n override _$setValue(\n newListener: unknown,\n directiveParent: DirectiveParent = this\n ) {\n newListener =\n resolveDirective(this, newListener, directiveParent, 0) ?? nothing;\n if (newListener === noChange) {\n return;\n }\n const oldListener = this._$committedValue;\n\n // If the new value is nothing or any options change we have to remove the\n // part as a listener.\n const shouldRemoveListener =\n (newListener === nothing && oldListener !== nothing) ||\n (newListener as EventListenerWithOptions).capture !==\n (oldListener as EventListenerWithOptions).capture ||\n (newListener as EventListenerWithOptions).once !==\n (oldListener as EventListenerWithOptions).once ||\n (newListener as EventListenerWithOptions).passive !==\n (oldListener as EventListenerWithOptions).passive;\n\n // If the new value is not nothing and we removed the listener, we have\n // to add the part as a listener.\n const shouldAddListener =\n newListener !== nothing &&\n (oldListener === nothing || shouldRemoveListener);\n\n debugLogEvent &&\n debugLogEvent({\n kind: 'commit event listener',\n element: this.element,\n name: this.name,\n value: newListener,\n options: this.options,\n removeListener: shouldRemoveListener,\n addListener: shouldAddListener,\n oldListener,\n });\n if (shouldRemoveListener) {\n this.element.removeEventListener(\n this.name,\n this,\n oldListener as EventListenerWithOptions\n );\n }\n if (shouldAddListener) {\n this.element.addEventListener(\n this.name,\n this,\n newListener as EventListenerWithOptions\n );\n }\n this._$committedValue = newListener;\n }\n\n handleEvent(event: Event) {\n if (typeof this._$committedValue === 'function') {\n this._$committedValue.call(this.options?.host ?? this.element, event);\n } else {\n (this._$committedValue as EventListenerObject).handleEvent(event);\n }\n }\n}\n\nexport type {ElementPart};\nclass ElementPart implements Disconnectable {\n readonly type = ELEMENT_PART;\n\n /** @internal */\n __directive?: Directive;\n\n // This is to ensure that every Part has a _$committedValue\n _$committedValue: undefined;\n\n /** @internal */\n _$parent!: Disconnectable;\n\n /** @internal */\n _$disconnectableChildren?: Set<Disconnectable> = undefined;\n\n options: RenderOptions | undefined;\n\n constructor(\n public element: Element,\n parent: Disconnectable,\n options: RenderOptions | undefined\n ) {\n this._$parent = parent;\n this.options = options;\n }\n\n // See comment in Disconnectable interface for why this is a getter\n get _$isConnected() {\n return this._$parent._$isConnected;\n }\n\n _$setValue(value: unknown): void {\n debugLogEvent &&\n debugLogEvent({\n kind: 'commit to element binding',\n element: this.element,\n value,\n options: this.options,\n });\n resolveDirective(this, value);\n }\n}\n\n/**\n * END USERS SHOULD NOT RELY ON THIS OBJECT.\n *\n * Private exports for use by other Lit packages, not intended for use by\n * external users.\n *\n * We currently do not make a mangled rollup build of the lit-ssr code. In order\n * to keep a number of (otherwise private) top-level exports mangled in the\n * client side code, we export a _$LH object containing those members (or\n * helper methods for accessing private fields of those members), and then\n * re-export them for use in lit-ssr. This keeps lit-ssr agnostic to whether the\n * client-side code is being used in `dev` mode or `prod` mode.\n *\n * This has a unique name, to disambiguate it from private exports in\n * lit-element, which re-exports all of lit-html.\n *\n * @private\n */\nexport const _$LH = {\n // Used in lit-ssr\n _boundAttributeSuffix: boundAttributeSuffix,\n _marker: marker,\n _markerMatch: markerMatch,\n _HTML_RESULT: HTML_RESULT,\n _getTemplateHtml: getTemplateHtml,\n // Used in tests and private-ssr-support\n _TemplateInstance: TemplateInstance,\n _isIterable: isIterable,\n _resolveDirective: resolveDirective,\n _ChildPart: ChildPart,\n _AttributePart: AttributePart,\n _BooleanAttributePart: BooleanAttributePart,\n _EventPart: EventPart,\n _PropertyPart: PropertyPart,\n _ElementPart: ElementPart,\n};\n\n// Apply polyfills if available\nconst polyfillSupport = DEV_MODE\n ? global.litHtmlPolyfillSupportDevMode\n : global.litHtmlPolyfillSupport;\npolyfillSupport?.(Template, ChildPart);\n\n// IMPORTANT: do not change the property name or the assignment expression.\n// This line will be used in regexes to search for lit-html usage.\n(global.litHtmlVersions ??= []).push('3.3.2');\nif (DEV_MODE && global.litHtmlVersions.length > 1) {\n queueMicrotask(() => {\n issueWarning!(\n 'multiple-versions',\n `Multiple versions of Lit loaded. ` +\n `Loading multiple versions is not recommended.`\n );\n });\n}\n\n/**\n * Renders a value, usually a lit-html TemplateResult, to the container.\n *\n * This example renders the text \"Hello, Zoe!\" inside a paragraph tag, appending\n * it to the container `document.body`.\n *\n * ```js\n * import {html, render} from 'lit';\n *\n * const name = \"Zoe\";\n * render(html`<p>Hello, ${name}!</p>`, document.body);\n * ```\n *\n * @param value Any [renderable\n * value](https://lit.dev/docs/templates/expressions/#child-expressions),\n * typically a {@linkcode TemplateResult} created by evaluating a template tag\n * like {@linkcode html} or {@linkcode svg}.\n * @param container A DOM container to render to. The first render will append\n * the rendered value to the container, and subsequent renders will\n * efficiently update the rendered value if the same result type was\n * previously rendered there.\n * @param options See {@linkcode RenderOptions} for options documentation.\n * @see\n * {@link https://lit.dev/docs/libraries/standalone-templates/#rendering-lit-html-templates| Rendering Lit HTML Templates}\n */\nexport const render = (\n value: unknown,\n container: RenderRootNode,\n options?: RenderOptions\n): RootPart => {\n if (DEV_MODE && container == null) {\n // Give a clearer error message than\n // Uncaught TypeError: Cannot read properties of null (reading\n // '_$litPart$')\n // which reads like an internal Lit error.\n throw new TypeError(`The container to render into may not be ${container}`);\n }\n const renderId = DEV_MODE ? debugLogRenderId++ : 0;\n const partOwnerNode = options?.renderBefore ?? container;\n // This property needs to remain unminified.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let part: ChildPart = (partOwnerNode as any)['_$litPart$'];\n debugLogEvent &&\n debugLogEvent({\n kind: 'begin render',\n id: renderId,\n value,\n container,\n options,\n part,\n });\n if (part === undefined) {\n const endNode = options?.renderBefore ?? null;\n // This property needs to remain unminified.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (partOwnerNode as any)['_$litPart$'] = part = new ChildPart(\n container.insertBefore(createMarker(), endNode),\n endNode,\n undefined,\n options ?? {}\n );\n }\n part._$setValue(value);\n debugLogEvent &&\n debugLogEvent({\n kind: 'end render',\n id: renderId,\n value,\n container,\n options,\n part,\n });\n return part as RootPart;\n};\n\nif (ENABLE_EXTRA_SECURITY_HOOKS) {\n render.setSanitizer = setSanitizer;\n render.createSanitizer = createSanitizer;\n if (DEV_MODE) {\n render._testOnlyClearSanitizerFactoryDoNotCallOrElse =\n _testOnlyClearSanitizerFactoryDoNotCallOrElse;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;A;;;;ACgBA,IAAMA,IAASC;AAAf,IAqOMC,IAKiBC,wBAAAA,OAAYA,IAAZA;AA1OvB,IA4OMC,IAAgBJ,EAAyCI;AA5O/D,IAsPMC,IAASD,IACXA,EAAaE,aAAa,YAAY,EACpCC,YAAaC,wBAAAA,OAAMA,IAANA,cAAMA,CAAAA,IAAAA;AAxPzB,IAsUMC,IAAuB;AAtU7B,IA4UMC,IAAS,OAAOC,KAAKC,OAAAA,EAASC,QAAQ,CAAA,EAAGC,MAAM,CAAA,CAAA;AA5UrD,IA+UMC,IAAc,MAAML;A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AAO,aAAa,SAAS;AAE9C,MAAI,CAAC,UAAU;AACb,UAAM,IAAI,MAAM,qBAAqB,SAAS,aAAa;AAAA,EAC7D;AAGA,QAAM,UAAU,SAAS,cAAc,QAAQ;AAC/C,MAAI,CAAC,QAAS,OAAM,IAAI,MAAM,qBAAqB,QAAQ,WAAW;AACtE,SAAO;AACT;AAXgB;AAkBT,SAAS,cAAc,QAAQ,WAAW;AAC/C,QAAM,WAAW,OAAO,aAAa,SAAS;AAE9C,MAAI,CAAC,UAAU;AACb,WAAO;AAAA,EACT;AAGA,QAAM,gBAAgB,SAAS,cAAc,QAAQ;AACrD,SAAO;AACT;AAVgB;AAeT,SAAS,iBAAiB,SAAS;AACxC,SAAO,OAAO,OAAO,EAAE,QAAQ,CAAC,WAAW;AACzC,QAAI,kBAAkB,OAAQ,QAAO,UAAU;AAAA,EACjD,CAAC;AACH;AAJgB;AAUhB,eAAsB,oBAAoB,UAAU;AAClD,QAAM,QAAQ;AAAA,IACZ,OAAO,OAAO,QAAQ,EAAE;AAAA,MAAI,CAAC,YAC3B,eAAe,YAAY,QAAQ,SAAS;AAAA,IAC9C;AAAA,EACF;AACF;AANsB;","names":["global","globalThis","wrap","node","trustedTypes","policy","createPolicy","createHTML","s","boundAttributeSuffix","marker","Math","random","toFixed","slice","markerMatch","nodeMarker","d","document","createTreeWalker","createMarker","createComment","isPrimitive","value","isArray","Array","isIterable","Symbol","iterator","SPACE_CHAR","textEndRegex","commentEndRegex","comment2EndRegex","tagEndRegex","RegExp","singleQuoteAttrEndRegex","doubleQuoteAttrEndRegex","rawTextElement","tag","type","strings","values","_$litType$","html","svg","mathml","noChange","for","nothing","templateCache","WeakMap","walker","trustFromTemplateString","tsa","stringFromTSA","hasOwnProperty","Error","getTemplateHtml","l","length","attrNames","rawTextEndRegex","regex","i","attrName","match","attrNameEndIndex","lastIndex","exec","test","end","startsWith","push","Template","constructor","options","this","parts","nodeIndex","attrNameIndex","partCount","el","createElement","currentNode","content","wrapper","firstChild","replaceWith","childNodes","nextNode","nodeType","hasAttributes","name","getAttributeNames","endsWith","realName","statics","getAttribute","split","m","index","ctor","PropertyPart","BooleanAttributePart","EventPart","AttributePart","removeAttribute","tagName","textContent","emptyScript","append","data","indexOf","_options","innerHTML","resolveDirective","part","parent","attributeIndex","currentDirective","__directives","__directive","nextDirectiveConstructor","_$initialize","_$resolve","TemplateInstance","template","_$parts","_$disconnectableChildren","_$template","_$parent","parentNode","_$isConnected","fragment","creationScope","importNode","partIndex","templatePart","ChildPart","nextSibling","ElementPart","_$setValue","__isConnected","startNode","endNode","_$committedValue","_$startNode","_$endNode","isConnected","directiveParent","_$clear","_commitText","_commitTemplateResult","_commitNode","_commitIterable","insertBefore","_insert","createTextNode","result","_$getTemplate","h","_update","instance","_clone","get","set","itemParts","itemPart","item","start","from","_$notifyConnectionChanged","n","remove","element","fill","String","valueIndex","noCommit","change","v","_commitValue","setAttribute","toggleAttribute","super","newListener","oldListener","shouldRemoveListener","capture","once","passive","shouldAddListener","removeEventListener","addEventListener","event","call","host","handleEvent","_$LH","_boundAttributeSuffix","_marker","_markerMatch","_HTML_RESULT","_getTemplateHtml","_TemplateInstance","_isIterable","_resolveDirective","_ChildPart","_AttributePart","_BooleanAttributePart","_EventPart","_PropertyPart","_ElementPart","polyfillSupport","litHtmlPolyfillSupport","litHtmlVersions","render","container","partOwnerNode","renderBefore","query","d","k","v","n"],"sourceRoot":"file:///var/home/toko/Code/tokono.ma/diffuse-artifacts/diffuse","file":"/chunk-H46AZIKM.js.map"}
···11+{"version":3,"sources":["/node_modules/.deno/idb-keyval@6.2.2/node_modules/idb-keyval/dist/index.js"],"sourcesContent":["function promisifyRequest(request) {\n return new Promise((resolve, reject) => {\n // @ts-ignore - file size hacks\n request.oncomplete = request.onsuccess = () => resolve(request.result);\n // @ts-ignore - file size hacks\n request.onabort = request.onerror = () => reject(request.error);\n });\n}\nfunction createStore(dbName, storeName) {\n let dbp;\n const getDB = () => {\n if (dbp)\n return dbp;\n const request = indexedDB.open(dbName);\n request.onupgradeneeded = () => request.result.createObjectStore(storeName);\n dbp = promisifyRequest(request);\n dbp.then((db) => {\n // It seems like Safari sometimes likes to just close the connection.\n // It's supposed to fire this event when that happens. Let's hope it does!\n db.onclose = () => (dbp = undefined);\n }, () => { });\n return dbp;\n };\n return (txMode, callback) => getDB().then((db) => callback(db.transaction(storeName, txMode).objectStore(storeName)));\n}\nlet defaultGetStoreFunc;\nfunction defaultGetStore() {\n if (!defaultGetStoreFunc) {\n defaultGetStoreFunc = createStore('keyval-store', 'keyval');\n }\n return defaultGetStoreFunc;\n}\n/**\n * Get a value by its key.\n *\n * @param key\n * @param customStore Method to get a custom store. Use with caution (see the docs).\n */\nfunction get(key, customStore = defaultGetStore()) {\n return customStore('readonly', (store) => promisifyRequest(store.get(key)));\n}\n/**\n * Set a value with a key.\n *\n * @param key\n * @param value\n * @param customStore Method to get a custom store. Use with caution (see the docs).\n */\nfunction set(key, value, customStore = defaultGetStore()) {\n return customStore('readwrite', (store) => {\n store.put(value, key);\n return promisifyRequest(store.transaction);\n });\n}\n/**\n * Set multiple values at once. This is faster than calling set() multiple times.\n * It's also atomic – if one of the pairs can't be added, none will be added.\n *\n * @param entries Array of entries, where each entry is an array of `[key, value]`.\n * @param customStore Method to get a custom store. Use with caution (see the docs).\n */\nfunction setMany(entries, customStore = defaultGetStore()) {\n return customStore('readwrite', (store) => {\n entries.forEach((entry) => store.put(entry[1], entry[0]));\n return promisifyRequest(store.transaction);\n });\n}\n/**\n * Get multiple values by their keys\n *\n * @param keys\n * @param customStore Method to get a custom store. Use with caution (see the docs).\n */\nfunction getMany(keys, customStore = defaultGetStore()) {\n return customStore('readonly', (store) => Promise.all(keys.map((key) => promisifyRequest(store.get(key)))));\n}\n/**\n * Update a value. This lets you see the old value and update it as an atomic operation.\n *\n * @param key\n * @param updater A callback that takes the old value and returns a new value.\n * @param customStore Method to get a custom store. Use with caution (see the docs).\n */\nfunction update(key, updater, customStore = defaultGetStore()) {\n return customStore('readwrite', (store) => \n // Need to create the promise manually.\n // If I try to chain promises, the transaction closes in browsers\n // that use a promise polyfill (IE10/11).\n new Promise((resolve, reject) => {\n store.get(key).onsuccess = function () {\n try {\n store.put(updater(this.result), key);\n resolve(promisifyRequest(store.transaction));\n }\n catch (err) {\n reject(err);\n }\n };\n }));\n}\n/**\n * Delete a particular key from the store.\n *\n * @param key\n * @param customStore Method to get a custom store. Use with caution (see the docs).\n */\nfunction del(key, customStore = defaultGetStore()) {\n return customStore('readwrite', (store) => {\n store.delete(key);\n return promisifyRequest(store.transaction);\n });\n}\n/**\n * Delete multiple keys at once.\n *\n * @param keys List of keys to delete.\n * @param customStore Method to get a custom store. Use with caution (see the docs).\n */\nfunction delMany(keys, customStore = defaultGetStore()) {\n return customStore('readwrite', (store) => {\n keys.forEach((key) => store.delete(key));\n return promisifyRequest(store.transaction);\n });\n}\n/**\n * Clear all values in the store.\n *\n * @param customStore Method to get a custom store. Use with caution (see the docs).\n */\nfunction clear(customStore = defaultGetStore()) {\n return customStore('readwrite', (store) => {\n store.clear();\n return promisifyRequest(store.transaction);\n });\n}\nfunction eachCursor(store, callback) {\n store.openCursor().onsuccess = function () {\n if (!this.result)\n return;\n callback(this.result);\n this.result.continue();\n };\n return promisifyRequest(store.transaction);\n}\n/**\n * Get all keys in the store.\n *\n * @param customStore Method to get a custom store. Use with caution (see the docs).\n */\nfunction keys(customStore = defaultGetStore()) {\n return customStore('readonly', (store) => {\n // Fast path for modern browsers\n if (store.getAllKeys) {\n return promisifyRequest(store.getAllKeys());\n }\n const items = [];\n return eachCursor(store, (cursor) => items.push(cursor.key)).then(() => items);\n });\n}\n/**\n * Get all values in the store.\n *\n * @param customStore Method to get a custom store. Use with caution (see the docs).\n */\nfunction values(customStore = defaultGetStore()) {\n return customStore('readonly', (store) => {\n // Fast path for modern browsers\n if (store.getAll) {\n return promisifyRequest(store.getAll());\n }\n const items = [];\n return eachCursor(store, (cursor) => items.push(cursor.value)).then(() => items);\n });\n}\n/**\n * Get all entries in the store. Each entry is an array of `[key, value]`.\n *\n * @param customStore Method to get a custom store. Use with caution (see the docs).\n */\nfunction entries(customStore = defaultGetStore()) {\n return customStore('readonly', (store) => {\n // Fast path for modern browsers\n // (although, hopefully we'll get a simpler path some day)\n if (store.getAll && store.getAllKeys) {\n return Promise.all([\n promisifyRequest(store.getAllKeys()),\n promisifyRequest(store.getAll()),\n ]).then(([keys, values]) => keys.map((key, i) => [key, values[i]]));\n }\n const items = [];\n return customStore('readonly', (store) => eachCursor(store, (cursor) => items.push([cursor.key, cursor.value])).then(() => items));\n });\n}\n\nexport { clear, createStore, del, delMany, entries, get, getMany, keys, promisifyRequest, set, setMany, update, values };\n"],"mappings":";;;;;;;AAAA;AAAA;AAAA,SAAS,iBAAiB,SAAS;AAC/B,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AAEpC,YAAQ,aAAa,QAAQ,YAAY,MAAM,QAAQ,QAAQ,MAAM;AAErE,YAAQ,UAAU,QAAQ,UAAU,MAAM,OAAO,QAAQ,KAAK;AAAA,EAClE,CAAC;AACL;AAPS;AAQT,SAAS,YAAY,QAAQ,WAAW;AACpC,MAAI;AACJ,QAAM,QAAQ,6BAAM;AAChB,QAAI;AACA,aAAO;AACX,UAAM,UAAU,UAAU,KAAK,MAAM;AACrC,YAAQ,kBAAkB,MAAM,QAAQ,OAAO,kBAAkB,SAAS;AAC1E,UAAM,iBAAiB,OAAO;AAC9B,QAAI,KAAK,CAAC,OAAO;AAGb,SAAG,UAAU,MAAO,MAAM;AAAA,IAC9B,GAAG,MAAM;AAAA,IAAE,CAAC;AACZ,WAAO;AAAA,EACX,GAZc;AAad,SAAO,CAAC,QAAQ,aAAa,MAAM,EAAE,KAAK,CAAC,OAAO,SAAS,GAAG,YAAY,WAAW,MAAM,EAAE,YAAY,SAAS,CAAC,CAAC;AACxH;AAhBS;AAiBT,IAAI;AACJ,SAAS,kBAAkB;AACvB,MAAI,CAAC,qBAAqB;AACtB,0BAAsB,YAAY,gBAAgB,QAAQ;AAAA,EAC9D;AACA,SAAO;AACX;AALS;AAYT,SAAS,IAAI,KAAK,cAAc,gBAAgB,GAAG;AAC/C,SAAO,YAAY,YAAY,CAAC,UAAU,iBAAiB,MAAM,IAAI,GAAG,CAAC,CAAC;AAC9E;AAFS;AAUT,SAAS,IAAI,KAAK,OAAO,cAAc,gBAAgB,GAAG;AACtD,SAAO,YAAY,aAAa,CAAC,UAAU;AACvC,UAAM,IAAI,OAAO,GAAG;AACpB,WAAO,iBAAiB,MAAM,WAAW;AAAA,EAC7C,CAAC;AACL;AALS;AA0DT,SAAS,IAAI,KAAK,cAAc,gBAAgB,GAAG;AAC/C,SAAO,YAAY,aAAa,CAAC,UAAU;AACvC,UAAM,OAAO,GAAG;AAChB,WAAO,iBAAiB,MAAM,WAAW;AAAA,EAC7C,CAAC;AACL;AALS;","names":[],"sourceRoot":"file:///var/home/toko/Code/tokono.ma/diffuse-artifacts/diffuse","file":"/chunk-JBHW662S.js.map"}
···11+{"version":3,"sources":["/node_modules/.deno/lit-html@3.3.2/node_modules/lit-html/src/directive.ts","/node_modules/.deno/lit-html@3.3.2/node_modules/lit-html/src/directive-helpers.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2017 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */\n\nimport {Disconnectable, Part} from './lit-html.js';\n\nexport {\n AttributePart,\n BooleanAttributePart,\n ChildPart,\n ElementPart,\n EventPart,\n Part,\n PropertyPart,\n} from './lit-html.js';\n\nexport interface DirectiveClass {\n new (part: PartInfo): Directive;\n}\n\n/**\n * This utility type extracts the signature of a directive class's render()\n * method so we can use it for the type of the generated directive function.\n */\nexport type DirectiveParameters<C extends Directive> = Parameters<C['render']>;\n\n/**\n * A generated directive function doesn't evaluate the directive, but just\n * returns a DirectiveResult object that captures the arguments.\n */\nexport interface DirectiveResult<C extends DirectiveClass = DirectiveClass> {\n /**\n * This property needs to remain unminified.\n * @internal\n */\n ['_$litDirective$']: C;\n /** @internal */\n values: DirectiveParameters<InstanceType<C>>;\n}\n\nexport const PartType = {\n ATTRIBUTE: 1,\n CHILD: 2,\n PROPERTY: 3,\n BOOLEAN_ATTRIBUTE: 4,\n EVENT: 5,\n ELEMENT: 6,\n} as const;\n\nexport type PartType = (typeof PartType)[keyof typeof PartType];\n\nexport interface ChildPartInfo {\n readonly type: typeof PartType.CHILD;\n}\n\nexport interface AttributePartInfo {\n readonly type:\n | typeof PartType.ATTRIBUTE\n | typeof PartType.PROPERTY\n | typeof PartType.BOOLEAN_ATTRIBUTE\n | typeof PartType.EVENT;\n readonly strings?: ReadonlyArray<string>;\n readonly name: string;\n readonly tagName: string;\n}\n\nexport interface ElementPartInfo {\n readonly type: typeof PartType.ELEMENT;\n}\n\n/**\n * Information about the part a directive is bound to.\n *\n * This is useful for checking that a directive is attached to a valid part,\n * such as with directive that can only be used on attribute bindings.\n */\nexport type PartInfo = ChildPartInfo | AttributePartInfo | ElementPartInfo;\n\n/**\n * Creates a user-facing directive function from a Directive class. This\n * function has the same parameters as the directive's render() method.\n */\nexport const directive =\n <C extends DirectiveClass>(c: C) =>\n (...values: DirectiveParameters<InstanceType<C>>): DirectiveResult<C> => ({\n // This property needs to remain unminified.\n ['_$litDirective$']: c,\n values,\n });\n\n/**\n * Base class for creating custom directives. Users should extend this class,\n * implement `render` and/or `update`, and then pass their subclass to\n * `directive`.\n */\nexport abstract class Directive implements Disconnectable {\n //@internal\n __part!: Part;\n //@internal\n __attributeIndex: number | undefined;\n //@internal\n __directive?: Directive;\n\n //@internal\n _$parent!: Disconnectable;\n\n // These will only exist on the AsyncDirective subclass\n //@internal\n _$disconnectableChildren?: Set<Disconnectable>;\n // This property needs to remain unminified.\n //@internal\n ['_$notifyDirectiveConnectionChanged']?(isConnected: boolean): void;\n\n constructor(_partInfo: PartInfo) {}\n\n // See comment in Disconnectable interface for why this is a getter\n get _$isConnected() {\n return this._$parent._$isConnected;\n }\n\n /** @internal */\n _$initialize(\n part: Part,\n parent: Disconnectable,\n attributeIndex: number | undefined\n ) {\n this.__part = part;\n this._$parent = parent;\n this.__attributeIndex = attributeIndex;\n }\n /** @internal */\n _$resolve(part: Part, props: Array<unknown>): unknown {\n return this.update(part, props);\n }\n\n abstract render(...props: Array<unknown>): unknown;\n\n update(_part: Part, props: Array<unknown>): unknown {\n return this.render(...props);\n }\n}\n","/**\n * @license\n * Copyright 2020 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */\n\nimport {\n _$LH,\n Part,\n DirectiveParent,\n CompiledTemplateResult,\n MaybeCompiledTemplateResult,\n UncompiledTemplateResult,\n} from './lit-html.js';\nimport {\n DirectiveResult,\n DirectiveClass,\n PartInfo,\n AttributePartInfo,\n} from './directive.js';\ntype Primitive = null | undefined | boolean | number | string | symbol | bigint;\n\nconst {_ChildPart: ChildPart} = _$LH;\n\ntype ChildPart = InstanceType<typeof ChildPart>;\n\nconst ENABLE_SHADYDOM_NOPATCH = true;\n\nconst wrap =\n ENABLE_SHADYDOM_NOPATCH &&\n window.ShadyDOM?.inUse &&\n window.ShadyDOM?.noPatch === true\n ? window.ShadyDOM!.wrap\n : (node: Node) => node;\n\n/**\n * Tests if a value is a primitive value.\n *\n * See https://tc39.github.io/ecma262/#sec-typeof-operator\n */\nexport const isPrimitive = (value: unknown): value is Primitive =>\n value === null || (typeof value != 'object' && typeof value != 'function');\n\nexport const TemplateResultType = {\n HTML: 1,\n SVG: 2,\n MATHML: 3,\n} as const;\n\nexport type TemplateResultType =\n (typeof TemplateResultType)[keyof typeof TemplateResultType];\n\ntype IsTemplateResult = {\n (val: unknown): val is MaybeCompiledTemplateResult;\n <T extends TemplateResultType>(\n val: unknown,\n type: T\n ): val is UncompiledTemplateResult<T>;\n};\n\n/**\n * Tests if a value is a TemplateResult or a CompiledTemplateResult.\n */\nexport const isTemplateResult: IsTemplateResult = (\n value: unknown,\n type?: TemplateResultType\n): value is UncompiledTemplateResult =>\n type === undefined\n ? // This property needs to remain unminified.\n (value as UncompiledTemplateResult)?.['_$litType$'] !== undefined\n : (value as UncompiledTemplateResult)?.['_$litType$'] === type;\n\n/**\n * Tests if a value is a CompiledTemplateResult.\n */\nexport const isCompiledTemplateResult = (\n value: unknown\n): value is CompiledTemplateResult => {\n return (value as CompiledTemplateResult)?.['_$litType$']?.h != null;\n};\n\n/**\n * Tests if a value is a DirectiveResult.\n */\nexport const isDirectiveResult = (value: unknown): value is DirectiveResult =>\n // This property needs to remain unminified.\n (value as DirectiveResult)?.['_$litDirective$'] !== undefined;\n\n/**\n * Retrieves the Directive class for a DirectiveResult\n */\nexport const getDirectiveClass = (value: unknown): DirectiveClass | undefined =>\n // This property needs to remain unminified.\n (value as DirectiveResult)?.['_$litDirective$'];\n\n/**\n * Tests whether a part has only a single-expression with no strings to\n * interpolate between.\n *\n * Only AttributePart and PropertyPart can have multiple expressions.\n * Multi-expression parts have a `strings` property and single-expression\n * parts do not.\n */\nexport const isSingleExpression = (part: PartInfo) =>\n (part as AttributePartInfo).strings === undefined;\n\nconst createMarker = () => document.createComment('');\n\n/**\n * Inserts a ChildPart into the given container ChildPart's DOM, either at the\n * end of the container ChildPart, or before the optional `refPart`.\n *\n * This does not add the part to the containerPart's committed value. That must\n * be done by callers.\n *\n * @param containerPart Part within which to add the new ChildPart\n * @param refPart Part before which to add the new ChildPart; when omitted the\n * part added to the end of the `containerPart`\n * @param part Part to insert, or undefined to create a new part\n */\nexport const insertPart = (\n containerPart: ChildPart,\n refPart?: ChildPart,\n part?: ChildPart\n): ChildPart => {\n const container = wrap(containerPart._$startNode).parentNode!;\n\n const refNode =\n refPart === undefined ? containerPart._$endNode : refPart._$startNode;\n\n if (part === undefined) {\n const startNode = wrap(container).insertBefore(createMarker(), refNode);\n const endNode = wrap(container).insertBefore(createMarker(), refNode);\n part = new ChildPart(\n startNode,\n endNode,\n containerPart,\n containerPart.options\n );\n } else {\n const endNode = wrap(part._$endNode!).nextSibling;\n const oldParent = part._$parent;\n const parentChanged = oldParent !== containerPart;\n if (parentChanged) {\n part._$reparentDisconnectables?.(containerPart);\n // Note that although `_$reparentDisconnectables` updates the part's\n // `_$parent` reference after unlinking from its current parent, that\n // method only exists if Disconnectables are present, so we need to\n // unconditionally set it here\n part._$parent = containerPart;\n // Since the _$isConnected getter is somewhat costly, only\n // read it once we know the subtree has directives that need\n // to be notified\n let newConnectionState;\n if (\n part._$notifyConnectionChanged !== undefined &&\n (newConnectionState = containerPart._$isConnected) !==\n oldParent!._$isConnected\n ) {\n part._$notifyConnectionChanged(newConnectionState);\n }\n }\n if (endNode !== refNode || parentChanged) {\n let start: Node | null = part._$startNode;\n while (start !== endNode) {\n const n: Node | null = wrap(start!).nextSibling;\n wrap(container).insertBefore(start!, refNode);\n start = n;\n }\n }\n }\n\n return part;\n};\n\n/**\n * Sets the value of a Part.\n *\n * Note that this should only be used to set/update the value of user-created\n * parts (i.e. those created using `insertPart`); it should not be used\n * by directives to set the value of the directive's container part. Directives\n * should return a value from `update`/`render` to update their part state.\n *\n * For directives that require setting their part value asynchronously, they\n * should extend `AsyncDirective` and call `this.setValue()`.\n *\n * @param part Part to set\n * @param value Value to set\n * @param index For `AttributePart`s, the index to set\n * @param directiveParent Used internally; should not be set by user\n */\nexport const setChildPartValue = <T extends ChildPart>(\n part: T,\n value: unknown,\n directiveParent: DirectiveParent = part\n): T => {\n part._$setValue(value, directiveParent);\n return part;\n};\n\n// A sentinel value that can never appear as a part value except when set by\n// live(). Used to force a dirty-check to fail and cause a re-render.\nconst RESET_VALUE = {};\n\n/**\n * Sets the committed value of a ChildPart directly without triggering the\n * commit stage of the part.\n *\n * This is useful in cases where a directive needs to update the part such\n * that the next update detects a value change or not. When value is omitted,\n * the next update will be guaranteed to be detected as a change.\n *\n * @param part\n * @param value\n */\nexport const setCommittedValue = (part: Part, value: unknown = RESET_VALUE) =>\n (part._$committedValue = value);\n\n/**\n * Returns the committed value of a ChildPart.\n *\n * The committed value is used for change detection and efficient updates of\n * the part. It can differ from the value set by the template or directive in\n * cases where the template value is transformed before being committed.\n *\n * - `TemplateResult`s are committed as a `TemplateInstance`\n * - Iterables are committed as `Array<ChildPart>`\n * - All other types are committed as the template value or value returned or\n * set by a directive.\n *\n * @param part\n */\nexport const getCommittedValue = (part: ChildPart) => part._$committedValue;\n\n/**\n * Removes a ChildPart from the DOM, including any of its content and markers.\n *\n * Note: The only difference between this and clearPart() is that this also\n * removes the part's start node. This means that the ChildPart must own its\n * start node, ie it must be a marker node specifically for this part and not an\n * anchor from surrounding content.\n *\n * @param part The Part to remove\n */\nexport const removePart = (part: ChildPart) => {\n part._$clear();\n part._$startNode.remove();\n};\n\nexport const clearPart = (part: ChildPart) => {\n part._$clear();\n};\n"],"mappings":";;;;;;;;;;;;AA0CO,IA0CMA,IACgBC,wBAAAA,OAC3B,IAAIC,QAA4C,EAE9CC,iBAAqBF,IACrBC,QAAAA,GAAAA,IAJyBD;AAIzBC,IAQkBE,IARlBF,MAQkBE;SAAAA;;;EAkBpB,YAAYC,IAAAA;EAAsB;EAGlC,IAAA,OAAIC;AACF,WAAOC,KAAKC,KAASF;EACvB;EAGA,KACEG,IACAC,IACAC,IAAAA;AAEAJ,SAAKK,OAASH,IACdF,KAAKC,OAAWE,IAChBH,KAAKM,OAAmBF;EAC1B;EAEA,KAAUF,IAAYK,IAAAA;AACpB,WAAOP,KAAKQ,OAAON,IAAMK,EAAAA;EAC3B;EAIA,OAAOE,IAAaF,IAAAA;AAClB,WAAOP,KAAKU,OAAAA,GAAUH,EAAAA;EACxB;AAAA;A;;;;ACvHF,IAAA,EAAOI,GAAYC,EAAAA,IAAaC;AAAhC,IAMMC,KAKCC,8BAAeA,GAAfA;AAXP,IAyCaC,IAAqC,wBAChDC,GACAC,OAAAA,WAEAA,KAAAA,WAEKD,GAAiD,aACjDA,GAAiD,eAAMC,IAPZ;AAzClD,IAqDaC,IACXF,8BAE+D,QAAvDA,GAA+C,YAAGG,GAF1DH;AAtDF,IAoFMI,IAAe,6BAAMC,SAASC,cAAc,EAAA,GAA7B;AApFrB,IAkGaC,IAAa,wBACxBC,GACAC,GACAC,OAAAA;AAEA,QAAMC,KAAiBH,EAAcI,KAAaC,YAE5CC,KAAAA,WACJL,IAAwBD,EAAcO,OAAYN,EAAQG;AAE5D,MAAA,WAAIF,IAAoB;AACtB,UAAMM,KAAiBL,GAAWM,aAAab,EAAAA,GAAgBU,EAAAA,GACzDI,KAAeP,GAAWM,aAAab,EAAAA,GAAgBU,EAAAA;AAC7DJ,IAAAA,KAAO,IAAIS,EACTH,IACAE,IACAV,GACAA,EAAcY,OAAAA;EAElB,OAAO;AACL,UAAMF,KAAeR,GAAKK,KAAYM,aAChCC,KAAYZ,GAAKa,MACjBC,IAAgBF,OAAcd;AACpC,QAAIgB,GAAe;AAUjB,UAAIC;AATJf,MAAAA,GAAKgB,OAA4BlB,CAAAA,GAKjCE,GAAKa,OAAWf,GAAAA,WAMdE,GAAKiB,SACJF,KAAqBjB,EAAcoB,UAClCN,GAAWM,QAEblB,GAAKiB,KAA0BF,EAAAA;IAEnC;AACA,QAAIP,OAAYJ,MAAWU,GAAe;AACxC,UAAIK,KAAqBnB,GAAKE;AAC9B,aAAOiB,OAAUX,MAAS;AACxB,cAAMY,KAAiBC,GAAKF,EAAAA,EAAQR;AACpCU,QAAAA,GAAKpB,EAAAA,EAAWM,aAAaY,IAAQf,EAAAA,GACrCe,KAAQC;MACV;IACF;EACF;AAEA,SAAOpB;AAAAA,GApDiB;AAlG1B,IAoLMsB,IAAc,CAAA;AApLpB,IAiMaC,IAAoB,wBAACC,GAAYC,KAAiBH,MAC5DE,EAAKE,OAAmBD,IADM;AAjMjC,IAkNaE,IAAqBH,8BAAoBA,EAAKE,MAAzBF;AAlNlC,IAmOaI,IAAaC,8BAAAA;AACxBA,IAAKC,KAAAA;AAAAA,GADmBD;","names":["directive","c","values","_$litDirective$","Directive","_partInfo","_$isConnected","this","_$parent","part","parent","attributeIndex","__part","__attributeIndex","props","update","_part","render","_ChildPart","ChildPart","_$LH","wrap","node","isTemplateResult","value","type","isCompiledTemplateResult","h","createMarker","document","createComment","insertPart","containerPart","refPart","part","container","_$startNode","parentNode","refNode","_$endNode","startNode","insertBefore","endNode","ChildPart","options","nextSibling","oldParent","_$parent","parentChanged","newConnectionState","_$reparentDisconnectables","_$notifyConnectionChanged","_$isConnected","start","n","wrap","RESET_VALUE","setCommittedValue","part","value","_$committedValue","getCommittedValue","clearPart","part","_$clear"],"sourceRoot":"file:///var/home/toko/Code/tokono.ma/diffuse-artifacts/diffuse","file":"/chunk-NT5H3ES3.js.map"}