@remotion/rough-notation 4.0.497 → 4.0.499

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.
@@ -7,13 +7,13 @@ import {
7
7
 
8
8
  // src/create-annotation.tsx
9
9
  import {
10
- createContext,
11
10
  createRef,
12
11
  useEffect as useEffect2,
12
+ useLayoutEffect,
13
13
  useMemo as useMemo2,
14
14
  useState as useState2
15
15
  } from "react";
16
- import { continueRender, delayRender } from "remotion";
16
+ import { continueRender, delayRender, useCurrentFrame } from "remotion";
17
17
 
18
18
  // src/element-size.ts
19
19
  import { useCallback, useEffect, useMemo, useState } from "react";
@@ -2405,34 +2405,22 @@ var renderAnnotation = ({
2405
2405
  };
2406
2406
 
2407
2407
  // src/rough.ts
2408
- var svgRect = ({
2409
- svg,
2410
- element,
2411
- scale
2412
- }) => {
2413
- const rect1 = svg.getBoundingClientRect();
2414
- const rect2 = element.getBoundingClientRect();
2415
- const inverseScale = 1 / scale;
2408
+ var getLocalRect = (element) => {
2416
2409
  return {
2417
- x: (rect2.x - rect1.x) * inverseScale,
2418
- y: (rect2.y - rect1.y) * inverseScale,
2419
- w: rect2.width * inverseScale,
2420
- h: rect2.height * inverseScale
2410
+ x: element.offsetLeft,
2411
+ y: element.offsetTop,
2412
+ w: element.offsetWidth,
2413
+ h: element.offsetHeight
2421
2414
  };
2422
2415
  };
2423
2416
  var render = ({
2424
- svg,
2425
2417
  seed,
2426
2418
  element,
2427
2419
  config,
2428
- scale,
2429
2420
  progress,
2430
2421
  options
2431
2422
  }) => {
2432
- if (scale === 0) {
2433
- return [];
2434
- }
2435
- const rect = svgRect({ svg, element, scale });
2423
+ const rect = getLocalRect(element);
2436
2424
  if (rect.w === 0 || rect.h === 0) {
2437
2425
  return [];
2438
2426
  }
@@ -2551,40 +2539,12 @@ var resolveAnnotationConfig = (config) => {
2551
2539
  };
2552
2540
 
2553
2541
  // src/create-annotation.tsx
2554
- import { jsx as jsx2, jsxs } from "react/jsx-runtime";
2555
- var AnnotationContext = createContext({
2556
- setSvgChildren: () => {
2557
- return;
2558
- },
2559
- svgChildren: []
2560
- });
2561
- var MEASURER_SIZE = 100;
2562
- var measurerSize = {
2563
- height: MEASURER_SIZE,
2564
- width: MEASURER_SIZE,
2565
- position: "fixed",
2566
- opacity: 0,
2567
- top: -1e4
2568
- };
2542
+ import { jsx as jsx2 } from "react/jsx-runtime";
2569
2543
  var createAnnotation = () => {
2570
2544
  const ref = createRef();
2571
2545
  const svgRef = createRef();
2572
- const measurer = createRef();
2573
2546
  const Container = (props) => {
2574
- const [svgChildren, setSvgChildren] = useState2([]);
2575
- const value = useMemo2(() => {
2576
- return { setSvgChildren, svgChildren };
2577
- }, [svgChildren]);
2578
- return /* @__PURE__ */ jsxs(AnnotationContext.Provider, {
2579
- value,
2580
- children: [
2581
- props.children,
2582
- /* @__PURE__ */ jsx2("div", {
2583
- ref: measurer,
2584
- style: measurerSize
2585
- })
2586
- ]
2587
- });
2547
+ return props.children;
2588
2548
  };
2589
2549
  const Tracker = ({ children, style }) => {
2590
2550
  return /* @__PURE__ */ jsx2("span", {
@@ -2611,9 +2571,11 @@ var createAnnotation = () => {
2611
2571
  progress,
2612
2572
  ...config
2613
2573
  }) => {
2574
+ const frame = useCurrentFrame();
2575
+ const parsedKey = JSON.stringify(resolveAnnotationConfig(config));
2614
2576
  const parsed = useMemo2(() => {
2615
- return resolveAnnotationConfig(config);
2616
- }, [config]);
2577
+ return JSON.parse(parsedKey);
2578
+ }, [parsedKey]);
2617
2579
  const roughJsOptions = useMemo2(() => {
2618
2580
  return resolveRoughOptions({
2619
2581
  roughness,
@@ -2643,16 +2605,20 @@ var createAnnotation = () => {
2643
2605
  }
2644
2606
  continueRender(initial);
2645
2607
  }, [initial, size]);
2646
- const scale = measurer.current ? measurer.current.getBoundingClientRect().width / MEASURER_SIZE : null;
2647
- const svgChildren = ref.current && scale ? render({
2648
- config: parsed,
2649
- svg: svgRef.current,
2650
- element: ref.current,
2651
- seed: seed ?? 1,
2652
- scale,
2653
- progress,
2654
- options: roughJsOptions
2655
- }) : [];
2608
+ const [svgChildren, setSvgChildren] = useState2([]);
2609
+ useLayoutEffect(() => {
2610
+ if (!ref.current || !svgRef.current) {
2611
+ setSvgChildren([]);
2612
+ return;
2613
+ }
2614
+ setSvgChildren(render({
2615
+ config: parsed,
2616
+ element: ref.current,
2617
+ seed: seed ?? 1,
2618
+ progress,
2619
+ options: roughJsOptions
2620
+ }));
2621
+ }, [frame, parsed, progress, roughJsOptions, seed, size]);
2656
2622
  return /* @__PURE__ */ jsx2("svg", {
2657
2623
  ref: svgRef,
2658
2624
  style: {
@@ -2670,7 +2636,7 @@ var createAnnotation = () => {
2670
2636
  };
2671
2637
 
2672
2638
  // src/Annotation.tsx
2673
- import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
2639
+ import { jsx as jsx3, jsxs } from "react/jsx-runtime";
2674
2640
  var colorSchema = {
2675
2641
  color: {
2676
2642
  type: "color",
@@ -2975,8 +2941,8 @@ var makeAnnotationComponent = ({
2975
2941
  outlineRef,
2976
2942
  children: /* @__PURE__ */ jsx3("span", {
2977
2943
  ref: outlineRef,
2978
- style: { display: "inline-block" },
2979
- children: /* @__PURE__ */ jsxs2(annotation.Container, {
2944
+ style: { display: "inline-block", position: "relative" },
2945
+ children: /* @__PURE__ */ jsxs(annotation.Container, {
2980
2946
  children: [
2981
2947
  layer === "behind" ? annotationElement : null,
2982
2948
  /* @__PURE__ */ jsx3(annotation.Tracker, {
package/dist/rough.d.ts CHANGED
@@ -1,11 +1,10 @@
1
1
  import type React from 'react';
2
- import type { ResolvedAnnotationConfig, RoughAnnotationOptions } from './types';
3
- export declare const render: ({ svg, seed, element, config, scale, progress, options, }: {
4
- readonly svg: SVGSVGElement;
2
+ import type { Rect, ResolvedAnnotationConfig, RoughAnnotationOptions } from './types';
3
+ export declare const getLocalRect: (element: HTMLElement) => Rect;
4
+ export declare const render: ({ seed, element, config, progress, options, }: {
5
5
  readonly seed: number;
6
6
  readonly element: HTMLElement;
7
7
  readonly config: ResolvedAnnotationConfig;
8
- readonly scale: number;
9
8
  readonly progress: number;
10
9
  readonly options: RoughAnnotationOptions;
11
10
  }) => React.ReactElement<unknown, string | React.JSXElementConstructor<any>>[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remotion/rough-notation",
3
- "version": "4.0.497",
3
+ "version": "4.0.499",
4
4
  "description": "Rough annotation primitives for Remotion",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -26,8 +26,8 @@
26
26
  "url": "https://github.com/remotion-dev/remotion/issues"
27
27
  },
28
28
  "dependencies": {
29
- "@remotion/paths": "4.0.497",
30
- "remotion": "4.0.497",
29
+ "@remotion/paths": "4.0.499",
30
+ "remotion": "4.0.499",
31
31
  "roughjs": "4.6.6"
32
32
  },
33
33
  "peerDependencies": {
@@ -45,7 +45,7 @@
45
45
  "devDependencies": {
46
46
  "react": "19.2.3",
47
47
  "react-dom": "19.2.3",
48
- "@remotion/eslint-config-internal": "4.0.497",
48
+ "@remotion/eslint-config-internal": "4.0.499",
49
49
  "eslint": "9.19.0",
50
50
  "@typescript/native-preview": "7.0.0-dev.20260217.1"
51
51
  },