(path: string)
| 94 | * Returns null for paths that don't correspond to override-set entries. |
| 95 | */ |
| 96 | export function pathToKey(path: string): string | null { |
| 97 | // /elements/{id}/inlineStyles/{prop} → "{id}.style.{prop}" |
| 98 | // id segment may contain ~1 (RFC 6902-escaped "/") for scoped ids |
| 99 | const styleMatch = /^\/elements\/([^/]+)\/inlineStyles\/(.+)$/.exec(path); |
| 100 | if (styleMatch) return `${decodePathSegment(styleMatch[1]!)}.style.${styleMatch[2]}`; |
| 101 | |
| 102 | // /elements/{id}/text → "{id}.text" |
| 103 | const textMatch = /^\/elements\/([^/]+)\/text$/.exec(path); |
| 104 | if (textMatch) return `${decodePathSegment(textMatch[1]!)}.text`; |
| 105 | |
| 106 | // /elements/{id}/attributes/{name} → "{id}.attr.{name}" |
| 107 | const attrMatch = /^\/elements\/([^/]+)\/attributes\/(.+)$/.exec(path); |
| 108 | if (attrMatch) return `${decodePathSegment(attrMatch[1]!)}.attr.${attrMatch[2]}`; |
| 109 | |
| 110 | // /elements/{id}/timing/{field} → "{id}.timing.{field}" |
| 111 | // Note: field "end" maps to the computed data-end attribute value. |
| 112 | const timingMatch = /^\/elements\/([^/]+)\/timing\/(.+)$/.exec(path); |
| 113 | if (timingMatch) return `${decodePathSegment(timingMatch[1]!)}.timing.${timingMatch[2]}`; |
| 114 | |
| 115 | // /elements/{id}/hold/{field} → "{id}.hold.{field}" |
| 116 | const holdMatch = /^\/elements\/([^/]+)\/hold\/(.+)$/.exec(path); |
| 117 | if (holdMatch) return `${decodePathSegment(holdMatch[1]!)}.hold.${holdMatch[2]}`; |
| 118 | |
| 119 | // /elements/{id} (whole element) → "{id}" |
| 120 | const elemMatch = /^\/elements\/([^/]+)$/.exec(path); |
| 121 | if (elemMatch) return decodePathSegment(elemMatch[1]!); |
| 122 | |
| 123 | // /variables/{id} → "var.{id}" |
| 124 | const varMatch = /^\/variables\/(.+)$/.exec(path); |
| 125 | if (varMatch) return `var.${varMatch[1]}`; |
| 126 | |
| 127 | // /metadata/{field} → "meta.{field}" |
| 128 | const metaMatch = /^\/metadata\/(.+)$/.exec(path); |
| 129 | if (metaMatch) return `meta.${metaMatch[1]}`; |
| 130 | |
| 131 | // /script/gsap → "script.gsap" |
| 132 | if (path === "/script/gsap") return "script.gsap"; |
| 133 | |
| 134 | // /style/css → "style.css" |
| 135 | if (path === "/style/css") return "style.css"; |
| 136 | |
| 137 | return null; |
| 138 | } |
| 139 | |
| 140 | /** |
| 141 | * Inverse of pathToKey — maps an override-set key back to its RFC 6902 path. |
no test coverage detected