{
  "version": 3,
  "sources": ["../../src/document/models/CanvasTree/utils/tokenMap.ts"],
  "sourcesContent": ["import { localPackageFallbackIdentifier } from \"@framerjs/framer-runtime/crossorigin\"\nimport { assert } from \"@framerjs/shared\"\nimport type { CanvasTree } from \"../index.ts\"\nimport type { CanvasNode } from \"../nodes/CanvasNode.ts\"\nimport { ColorStyleTokenListNode } from \"../nodes/ColorStyleTokenListNode.ts\"\nimport type { ColorStyleTokenNode } from \"../nodes/ColorStyleTokenNode.ts\"\nimport type { CombinedVariableProviderValueMap } from \"../traits/VariableProvider.ts\"\nimport { EagerVariableProviderMap } from \"../traits/utils/EagerVariableProviderMap.ts\"\nimport { findValueForTokenCSSVariable, removeTokensFromNode } from \"./tokens.ts\"\n\n/**\n * @deprecated There's no such thing as package anymore\n * Returns a nested map of ColorStyleTokenNodes indexed by id. Then grouped\n * by PackageId.\n */\nexport function getColorStyleTokensByPackageIdMap(tree: CanvasTree): {\n\t[pkgId: string]: { [tokenId: string]: ColorStyleTokenNode }\n} {\n\tconst result: { [pkgId: string]: { [tokenId: string]: ColorStyleTokenNode } } = {}\n\n\t// Collect local tokens.\n\tfor (const token of ColorStyleTokenListNode.getTokenNodes(tree)) {\n\t\tif (!result[localPackageFallbackIdentifier]) {\n\t\t\tresult[localPackageFallbackIdentifier] = {}\n\t\t}\n\t\tconst existingTokens = result[localPackageFallbackIdentifier]\n\t\tassert(existingTokens, \"Tokens entry must exist\")\n\t\texistingTokens[token.id] = token\n\t}\n\n\treturn result\n}\n\n/** Returns a map of TokenId to ColorStyleTokenNode. Includes soft-deleted tokens. */\nexport function getColorStyleTokenMap(tree: CanvasTree): { [id: string]: ColorStyleTokenNode } {\n\tconst result: { [id: string]: ColorStyleTokenNode } = {}\n\tfor (const token of ColorStyleTokenListNode.getAllTokenNodes(tree)) {\n\t\tresult[token.id] = token\n\t}\n\treturn result\n}\n\n/**\n * Creates a clone of the node provided and walks the children replacing any\n * variables within the nodes with values. Then returns the cloned node.\n */\nexport function removeAllTokensFromNodeTree<T extends CanvasNode>(node: T, tree: CanvasTree, isDarkMode: boolean): T {\n\tconst clone = node.cloneWithIds()\n\n\t// Replace all token references with the value\n\tconst tokens = Object.values(getColorStyleTokenMap(tree))\n\tfor (const n of clone.walk()) Object.assign(n, removeTokensFromNode(n, tokens, isDarkMode))\n\n\treturn clone\n}\n\n/**\n * Replace color tokens with their current value in a combined variable value map. It alters the value map in place.\n */\nexport function removeTokensFromValueMap(\n\ttree: CanvasTree,\n\tcombinedValueMap: CombinedVariableProviderValueMap | undefined,\n\tisDarkMode: boolean,\n) {\n\tif (!combinedValueMap) return\n\n\tconst tokens = Object.values(getColorStyleTokenMap(tree))\n\tconst map: { [tokenId: string]: string } = {}\n\tfor (const t of tokens) {\n\t\tconst value = t.colorForMode(isDarkMode)\n\t\tif (!value) return\n\t\tmap[t.id] = value\n\t}\n\n\tfor (const [providerId, valueMap] of combinedValueMap) {\n\t\tconst newValueMap = new EagerVariableProviderMap<unknown>()\n\n\t\tfor (const [variableId, value] of valueMap) {\n\t\t\tconst replacement = findValueForTokenCSSVariable(value, map)\n\t\t\tif (replacement) {\n\t\t\t\tnewValueMap.set(variableId, replacement)\n\t\t\t} else {\n\t\t\t\tnewValueMap.set(variableId, value)\n\t\t\t}\n\t\t}\n\n\t\tcombinedValueMap.set(providerId, newValueMap)\n\t}\n}\n"],
  "mappings": ";;;;;;;;;;;;;;;;AAeO,SAAS,kCAAkC,MAEhD;AACD,QAAM,SAA0E,CAAC;AAGjF,aAAW,SAAS,wBAAwB,cAAc,IAAI,GAAG;AAChE,QAAI,CAAC,OAAO,8BAA8B,GAAG;AAC5C,aAAO,8BAA8B,IAAI,CAAC;AAAA,IAC3C;AACA,UAAM,iBAAiB,OAAO,8BAA8B;AAC5D,WAAO,gBAAgB,yBAAyB;AAChD,mBAAe,MAAM,EAAE,IAAI;AAAA,EAC5B;AAEA,SAAO;AACR;AAGO,SAAS,sBAAsB,MAAyD;AAC9F,QAAM,SAAgD,CAAC;A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