MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / applyOne

Function applyOne

packages/sdk/src/engine/apply-patches.ts:144–290  ·  view source on GitHub ↗
(parsed: ParsedDocument, patch: JsonPatchOp, p: ParsedPath)

Source from the content-addressed store, hash-verified

142
143// fallow-ignore-next-line complexity
144function applyOne(parsed: ParsedDocument, patch: JsonPatchOp, p: ParsedPath): void {
145 switch (p.type) {
146 case "style": {
147 const el = p.id ? findById(parsed.document, p.id) : null;
148 if (!el || !p.prop) return;
149 if (patch.op === "remove") {
150 setElementStyles(el, { [p.prop]: null });
151 } else {
152 setElementStyles(el, { [p.prop]: String(patch.value) });
153 }
154 break;
155 }
156
157 case "text": {
158 const el = p.id ? findById(parsed.document, p.id) : null;
159 if (!el) return;
160 if (patch.op === "remove") {
161 setOwnText(el, "");
162 } else {
163 setOwnText(el, String(patch.value ?? ""));
164 }
165 break;
166 }
167
168 case "attribute": {
169 const el = p.id ? findById(parsed.document, p.id) : null;
170 if (!el || !p.prop) return;
171 if (patch.op === "remove") {
172 el.removeAttribute(p.prop);
173 } else {
174 el.setAttribute(p.prop, String(patch.value ?? ""));
175 }
176 break;
177 }
178
179 case "timing": {
180 const el = p.id ? findById(parsed.document, p.id) : null;
181 if (!el || !p.field) return;
182 if (p.field === "start") {
183 if (patch.op === "remove") el.removeAttribute("data-start");
184 else el.setAttribute("data-start", String(patch.value));
185 } else if (p.field === "duration") {
186 // Patch value is the data-duration value — set directly.
187 if (patch.op === "remove") el.removeAttribute("data-duration");
188 else el.setAttribute("data-duration", String(patch.value));
189 } else if (p.field === "end") {
190 // Patch value is the absolute data-end time — set directly, no re-derivation.
191 if (patch.op === "remove") el.removeAttribute("data-end");
192 else el.setAttribute("data-end", String(patch.value));
193 } else if (p.field === "trackIndex") {
194 if (patch.op === "remove") el.removeAttribute("data-track-index");
195 else el.setAttribute("data-track-index", String(patch.value));
196 }
197 break;
198 }
199
200 case "hold": {
201 const el = p.id ? findById(parsed.document, p.id) : null;

Callers 1

applyPatchesToDocumentFunction · 0.85

Calls 10

setElementStylesFunction · 0.85
setOwnTextFunction · 0.85
applyVariableDefaultFunction · 0.85
setGsapScriptFunction · 0.85
setStyleSheetFunction · 0.85
findRootFunction · 0.85
fromMethod · 0.80
findByIdFunction · 0.70
setAttributeMethod · 0.65
hasAttributeMethod · 0.65

Tested by

no test coverage detected