MCPcopy
hub / github.com/midrender/revideo / measureSize

Method measureSize

packages/2d/src/lib/code/CodeCursor.ts:92–136  ·  view source on GitHub ↗

* Measure the desired size of the code scope. * * @remarks * The result can be retrieved with getSize. * * @param scope - The code scope to measure.

(scope: CodeScope)

Source from the content-addressed store, hash-verified

90 * @param scope - The code scope to measure.
91 */
92 public measureSize(scope: CodeScope) {
93 const progress = unwrap(scope.progress);
94 for (const wrapped of scope.fragments) {
95 const possibleFragment = unwrap(wrapped);
96 if (isCodeScope(possibleFragment)) {
97 this.measureSize(possibleFragment);
98 continue;
99 }
100 if (Array.isArray(possibleFragment)) {
101 this.measureSize({
102 progress: scope.progress,
103 fragments: possibleFragment,
104 });
105 continue;
106 }
107
108 const fragment = parseCodeFragment(
109 possibleFragment,
110 this.context,
111 this.monoWidth,
112 );
113
114 const beforeMaxWidth = this.calculateMaxWidth(fragment.before);
115 const afterMaxWidth = this.calculateMaxWidth(fragment.after);
116
117 const maxWidth = map(beforeMaxWidth, afterMaxWidth, progress);
118 if (maxWidth > this.maxWidth) {
119 this.maxWidth = maxWidth;
120 }
121
122 const beforeEnd = this.calculateWidth(fragment.before);
123 const afterEnd = this.calculateWidth(fragment.after);
124 this.cursor.x = map(beforeEnd, afterEnd, progress);
125
126 if (this.cursor.y === 0) {
127 this.cursor.y = 1;
128 }
129
130 this.cursor.y += map(
131 fragment.before.newRows,
132 fragment.after.newRows,
133 progress,
134 );
135 }
136 }
137
138 /**
139 * Get the size measured by the cursor.

Callers 1

desiredSizeMethod · 0.80

Calls 6

calculateMaxWidthMethod · 0.95
calculateWidthMethod · 0.95
unwrapFunction · 0.90
isCodeScopeFunction · 0.90
parseCodeFragmentFunction · 0.90
mapFunction · 0.90

Tested by

no test coverage detected