@remotion/paths 4.0.484 → 4.0.486

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ export type CenterPathTarget = {
2
+ x: number;
3
+ y: number;
4
+ };
5
+ export declare const centerPath: (d: string, target?: CenterPathTarget) => string;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.centerPath = void 0;
4
+ const get_bounding_box_1 = require("./get-bounding-box");
5
+ const translate_path_1 = require("./translate-path");
6
+ /*
7
+ * @description Translates an SVG path so that the center of the bounding box is at the specified point. Defaults to 0, 0.
8
+ * @see [Documentation](https://www.remotion.dev/docs/paths/center-path)
9
+ */
10
+ const centerPath = (d, target = { x: 0, y: 0 }) => {
11
+ const box = (0, get_bounding_box_1.getBoundingBox)(d);
12
+ const dx = target.x - (box.x1 + box.x2) / 2;
13
+ const dy = target.y - (box.y1 + box.y2) / 2;
14
+ return (0, translate_path_1.translatePath)(d, dx, dy);
15
+ };
16
+ exports.centerPath = centerPath;
@@ -2137,6 +2137,104 @@ var getBoundingBox = (d) => {
2137
2137
  const unarced = removeATSHVQInstructions(normalizeInstructions(parsed));
2138
2138
  return getBoundingBoxFromInstructions(unarced);
2139
2139
  };
2140
+
2141
+ // src/translate-path.ts
2142
+ var translateSegments = (segments, x, y) => {
2143
+ return segments.map((segment) => {
2144
+ if (segment.type === "a" || segment.type === "c" || segment.type === "v" || segment.type === "s" || segment.type === "h" || segment.type === "l" || segment.type === "m" || segment.type === "q" || segment.type === "t") {
2145
+ return segment;
2146
+ }
2147
+ if (segment.type === "V") {
2148
+ return {
2149
+ type: "V",
2150
+ y: segment.y + y
2151
+ };
2152
+ }
2153
+ if (segment.type === "H") {
2154
+ return {
2155
+ type: "H",
2156
+ x: segment.x + x
2157
+ };
2158
+ }
2159
+ if (segment.type === "A") {
2160
+ return {
2161
+ type: "A",
2162
+ rx: segment.rx,
2163
+ ry: segment.ry,
2164
+ largeArcFlag: segment.largeArcFlag,
2165
+ sweepFlag: segment.sweepFlag,
2166
+ xAxisRotation: segment.xAxisRotation,
2167
+ x: segment.x + x,
2168
+ y: segment.y + y
2169
+ };
2170
+ }
2171
+ if (segment.type === "Z") {
2172
+ return segment;
2173
+ }
2174
+ if (segment.type === "C") {
2175
+ return {
2176
+ type: "C",
2177
+ cp1x: segment.cp1x + x,
2178
+ cp1y: segment.cp1y + y,
2179
+ cp2x: segment.cp2x + x,
2180
+ cp2y: segment.cp2y + y,
2181
+ x: segment.x + x,
2182
+ y: segment.y + y
2183
+ };
2184
+ }
2185
+ if (segment.type === "Q") {
2186
+ return {
2187
+ type: "Q",
2188
+ cpx: segment.cpx + x,
2189
+ cpy: segment.cpy + y,
2190
+ x: segment.x + x,
2191
+ y: segment.y + y
2192
+ };
2193
+ }
2194
+ if (segment.type === "S") {
2195
+ return {
2196
+ type: "S",
2197
+ cpx: segment.cpx + x,
2198
+ cpy: segment.cpy + y,
2199
+ x: segment.x + x,
2200
+ y: segment.y + y
2201
+ };
2202
+ }
2203
+ if (segment.type === "T") {
2204
+ return {
2205
+ type: "T",
2206
+ x: segment.x + x,
2207
+ y: segment.y + y
2208
+ };
2209
+ }
2210
+ if (segment.type === "L") {
2211
+ return {
2212
+ type: "L",
2213
+ x: segment.x + x,
2214
+ y: segment.y + y
2215
+ };
2216
+ }
2217
+ if (segment.type === "M") {
2218
+ return {
2219
+ type: "M",
2220
+ x: segment.x + x,
2221
+ y: segment.y + y
2222
+ };
2223
+ }
2224
+ throw new Error(`Unknown segment type: ${segment.type}`);
2225
+ });
2226
+ };
2227
+ var translatePath = (path, x, y) => {
2228
+ return serializeInstructions(translateSegments(parsePath(path), x, y));
2229
+ };
2230
+
2231
+ // src/center-path.ts
2232
+ var centerPath = (d, target = { x: 0, y: 0 }) => {
2233
+ const box = getBoundingBox(d);
2234
+ const dx = target.x - (box.x1 + box.x2) / 2;
2235
+ const dy = target.y - (box.y1 + box.y2) / 2;
2236
+ return translatePath(d, dx, dy);
2237
+ };
2140
2238
  // src/helpers/arc.ts
2141
2239
  var mod = (x, m) => {
2142
2240
  return (x % m + m) % m;
@@ -3179,96 +3277,6 @@ var interpolatePath = (value, firstPath, secondPath) => {
3179
3277
  const commandInterpolator = interpolateInstructions(aCommands, bCommands);
3180
3278
  return serializeInstructions(commandInterpolator(value));
3181
3279
  };
3182
- // src/translate-path.ts
3183
- var translateSegments = (segments, x, y) => {
3184
- return segments.map((segment) => {
3185
- if (segment.type === "a" || segment.type === "c" || segment.type === "v" || segment.type === "s" || segment.type === "h" || segment.type === "l" || segment.type === "m" || segment.type === "q" || segment.type === "t") {
3186
- return segment;
3187
- }
3188
- if (segment.type === "V") {
3189
- return {
3190
- type: "V",
3191
- y: segment.y + y
3192
- };
3193
- }
3194
- if (segment.type === "H") {
3195
- return {
3196
- type: "H",
3197
- x: segment.x + x
3198
- };
3199
- }
3200
- if (segment.type === "A") {
3201
- return {
3202
- type: "A",
3203
- rx: segment.rx,
3204
- ry: segment.ry,
3205
- largeArcFlag: segment.largeArcFlag,
3206
- sweepFlag: segment.sweepFlag,
3207
- xAxisRotation: segment.xAxisRotation,
3208
- x: segment.x + x,
3209
- y: segment.y + y
3210
- };
3211
- }
3212
- if (segment.type === "Z") {
3213
- return segment;
3214
- }
3215
- if (segment.type === "C") {
3216
- return {
3217
- type: "C",
3218
- cp1x: segment.cp1x + x,
3219
- cp1y: segment.cp1y + y,
3220
- cp2x: segment.cp2x + x,
3221
- cp2y: segment.cp2y + y,
3222
- x: segment.x + x,
3223
- y: segment.y + y
3224
- };
3225
- }
3226
- if (segment.type === "Q") {
3227
- return {
3228
- type: "Q",
3229
- cpx: segment.cpx + x,
3230
- cpy: segment.cpy + y,
3231
- x: segment.x + x,
3232
- y: segment.y + y
3233
- };
3234
- }
3235
- if (segment.type === "S") {
3236
- return {
3237
- type: "S",
3238
- cpx: segment.cpx + x,
3239
- cpy: segment.cpy + y,
3240
- x: segment.x + x,
3241
- y: segment.y + y
3242
- };
3243
- }
3244
- if (segment.type === "T") {
3245
- return {
3246
- type: "T",
3247
- x: segment.x + x,
3248
- y: segment.y + y
3249
- };
3250
- }
3251
- if (segment.type === "L") {
3252
- return {
3253
- type: "L",
3254
- x: segment.x + x,
3255
- y: segment.y + y
3256
- };
3257
- }
3258
- if (segment.type === "M") {
3259
- return {
3260
- type: "M",
3261
- x: segment.x + x,
3262
- y: segment.y + y
3263
- };
3264
- }
3265
- throw new Error(`Unknown segment type: ${segment.type}`);
3266
- });
3267
- };
3268
- var translatePath = (path, x, y) => {
3269
- return serializeInstructions(translateSegments(parsePath(path), x, y));
3270
- };
3271
-
3272
3280
  // src/reset-path.ts
3273
3281
  var resetPath = (d) => {
3274
3282
  const box = getBoundingBox(d);
@@ -3739,5 +3747,6 @@ export {
3739
3747
  extendViewBox,
3740
3748
  evolvePath,
3741
3749
  cutPath,
3750
+ centerPath,
3742
3751
  PathInternals
3743
3752
  };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export { centerPath, type CenterPathTarget } from './center-path';
1
2
  export { cutPath } from './cut-path';
2
3
  export { evolvePath } from './evolve-path';
3
4
  export { extendViewBox } from './extend-viewbox';
package/dist/index.js CHANGED
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PathInternals = exports.warpPath = exports.translatePath = exports.serializeInstructions = exports.scalePath = exports.reversePath = exports.resetPath = exports.reduceInstructions = exports.parsePath = exports.normalizePath = exports.interpolatePath = exports.getTangentAtLength = exports.getSubpaths = exports.getPointAtLength = exports.getLength = exports.getInstructionIndexAtLength = exports.getBoundingBox = exports.extendViewBox = exports.evolvePath = exports.cutPath = void 0;
3
+ exports.PathInternals = exports.warpPath = exports.translatePath = exports.serializeInstructions = exports.scalePath = exports.reversePath = exports.resetPath = exports.reduceInstructions = exports.parsePath = exports.normalizePath = exports.interpolatePath = exports.getTangentAtLength = exports.getSubpaths = exports.getPointAtLength = exports.getLength = exports.getInstructionIndexAtLength = exports.getBoundingBox = exports.extendViewBox = exports.evolvePath = exports.cutPath = exports.centerPath = void 0;
4
4
  const cut_path_1 = require("./cut-path");
5
5
  const debug_path_1 = require("./debug-path");
6
6
  const get_bounding_box_1 = require("./get-bounding-box");
7
+ const center_path_1 = require("./center-path");
8
+ Object.defineProperty(exports, "centerPath", { enumerable: true, get: function () { return center_path_1.centerPath; } });
7
9
  const cut_path_2 = require("./cut-path");
8
10
  Object.defineProperty(exports, "cutPath", { enumerable: true, get: function () { return cut_path_2.cutPath; } });
9
11
  const evolve_path_1 = require("./evolve-path");
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "url": "https://github.com/remotion-dev/remotion/tree/main/packages/paths"
4
4
  },
5
5
  "name": "@remotion/paths",
6
- "version": "4.0.484",
6
+ "version": "4.0.486",
7
7
  "description": "Utilities for working with SVG paths",
8
8
  "main": "dist/index.js",
9
9
  "types": "dist/index.d.ts",
@@ -26,7 +26,7 @@
26
26
  "utilities"
27
27
  ],
28
28
  "devDependencies": {
29
- "@remotion/eslint-config-internal": "4.0.484",
29
+ "@remotion/eslint-config-internal": "4.0.486",
30
30
  "eslint": "9.19.0",
31
31
  "@typescript/native-preview": "7.0.0-dev.20260217.1"
32
32
  },