@cutting/svg 4.50.0 → 4.50.2

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.
@@ -1,6 +1,6 @@
1
- @cutting/svg:build: cache hit, replaying output d29261d18dcf8b0a
1
+ @cutting/svg:build: cache hit, replaying output 7771cdbf838b8a4e
2
2
  @cutting/svg:build:
3
- @cutting/svg:build: > @cutting/svg@4.50.0 build /home/runner/work/cuttingedge/cuttingedge/packages/svg
3
+ @cutting/svg:build: > @cutting/svg@4.50.2 build /home/runner/work/cuttingedge/cuttingedge/packages/svg
4
4
  @cutting/svg:build: > NODE_ENV=production devtools rollup
5
5
  @cutting/svg:build:
6
6
  @cutting/svg:build: DEBUG using tsconfig.dist.json
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @cutting/svg
2
2
 
3
+ ## 4.50.2
4
+
5
+ ### Patch Changes
6
+
7
+ - dbc72c3b: add tangent
8
+ - Updated dependencies [dbc72c3b]
9
+ - @cutting/util@4.55.1
10
+ - @cutting/use-get-parent-size@1.24.2
11
+ - @cutting/react-abortable-fetch@0.33.1
12
+
13
+ ## 4.50.1
14
+
15
+ ### Patch Changes
16
+
17
+ - @cutting/use-get-parent-size@1.24.1
18
+
3
19
  ## 4.50.0
4
20
 
5
21
  ### Minor Changes
@@ -1,10 +1,10 @@
1
1
  import type { ReactNode, Ref } from 'react';
2
- import type { PreserveAspectRatio } from '../../types/types';
2
+ import type { PreserveAspectRatio, SVGAttributes } from '../../types/types';
3
3
  export interface Point {
4
4
  x: number;
5
5
  y: number;
6
6
  }
7
- export interface ResponsiveSVGProps {
7
+ export declare type ResponsiveSVGProps = SVGAttributes<{
8
8
  width: number;
9
9
  height: number;
10
10
  origin?: Point;
@@ -13,6 +13,6 @@ export interface ResponsiveSVGProps {
13
13
  className?: string;
14
14
  hide?: boolean;
15
15
  children: ReactNode;
16
- }
17
- export declare function ResponsiveSVG({ height, width, children, origin, preserveAspectRatio, innerRef, className, }: ResponsiveSVGProps): JSX.Element;
16
+ }>;
17
+ export declare function ResponsiveSVG({ height, width, children, origin, preserveAspectRatio, innerRef, className, ...props }: ResponsiveSVGProps): JSX.Element;
18
18
  //# sourceMappingURL=ResponsiveSVG.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ResponsiveSVG.d.ts","sourceRoot":"","sources":["../../../../src/components/ResponsiveSVG/ResponsiveSVG.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAE7D,MAAM,WAAW,KAAK;IACpB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,KAAK,CAAC;IACf,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;IAC1C,QAAQ,CAAC,EAAE,GAAG,CAAC,aAAa,CAAC,CAAC;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,wBAAgB,aAAa,CAAC,EAC5B,MAAM,EACN,KAAK,EACL,QAAQ,EACR,MAAuB,EACvB,mBAAqC,EACrC,QAAQ,EACR,SAAS,GACV,EAAE,kBAAkB,GAAG,GAAG,CAAC,OAAO,CAyBlC"}
1
+ {"version":3,"file":"ResponsiveSVG.d.ts","sourceRoot":"","sources":["../../../../src/components/ResponsiveSVG/ResponsiveSVG.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,KAAK,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAE5E,MAAM,WAAW,KAAK;IACpB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAED,oBAAY,kBAAkB,GAAG,aAAa,CAAC;IAC7C,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,KAAK,CAAC;IACf,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;IAC1C,QAAQ,CAAC,EAAE,GAAG,CAAC,aAAa,CAAC,CAAC;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,QAAQ,EAAE,SAAS,CAAC;CACrB,CAAC,CAAC;AAEH,wBAAgB,aAAa,CAAC,EAC5B,MAAM,EACN,KAAK,EACL,QAAQ,EACR,MAAuB,EACvB,mBAAqC,EACrC,QAAQ,EACR,SAAS,EACT,GAAG,KAAK,EACT,EAAE,kBAAkB,GAAG,GAAG,CAAC,OAAO,CA0BlC"}
package/dist/esm/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{jsx as e}from"react/jsx-runtime";import{useEffect as r}from"react";import{useParentSize as t}from"@cutting/use-get-parent-size";import n from"classnames";function i({height:r,width:t,children:n,origin:i={x:0,y:0},preserveAspectRatio:s="xMaxYMid meet",innerRef:l,className:o}){const a=Math.ceil(t/(t/r));return e("div",{"data-testid":"cutting-svg-container",style:{position:"relative",overflow:"visible",height:"1px"},children:e("svg",{style:{overflow:"visible"},className:o,preserveAspectRatio:s,viewBox:`${i.x} ${i.y} ${t} ${a}`,ref:l,children:n})})}const s={display:"flex",flexDirection:"column",flexGrow:1,flexShrink:1,flexBasis:"0%",overflow:"hidden"};function l({parentRef:n,children:l,style:o=s,scale:a=1,align:c="none",options:{debounceDelay:f=50,...x}={},...h}){const{width:d,height:m}=t(n,{debounceDelay:f,...x});return r((()=>{if(n.current)for(const[e,r]of Object.entries(o))n.current.style[e]=r}),[n,o]),e(i,{width:d,height:m,...h,children:e("g",{transform:"center"===c?`translate(${d/2},${m/2-20}) scale(${a})`:`translate(0,0) scale(${a})`,children:l})})}function o({y:r=0,x:t=0,transform:i,className:s,children:l,innerRef:o,...a}){return e("g",{ref:o,className:n("visx-group",s),transform:i||`translate(${t}, ${r})`,...a,children:l})}function a({from:r={x:0,y:0},to:t={x:1,y:1},fill:i="transparent",className:s,innerRef:l,...o}){const a=r.x===t.x||r.y===t.y;return e("line",{ref:l,className:n("visx-line",s),x1:r.x,y1:r.y,x2:t.x,y2:t.y,fill:i,shapeRendering:a?"crispEdges":"auto",...o})}export{o as Group,a as Line,l as ParentsizeSVG,i as ResponsiveSVG};
1
+ import{jsx as e}from"react/jsx-runtime";import{useEffect as r}from"react";import{useParentSize as t}from"@cutting/use-get-parent-size";import n from"classnames";function i({height:r,width:t,children:n,origin:i={x:0,y:0},preserveAspectRatio:s="xMaxYMid meet",innerRef:l,className:o,...a}){const c=Math.ceil(t/(t/r));return e("div",{"data-testid":"cutting-svg-container",style:{position:"relative",overflow:"visible",height:"1px"},children:e("svg",{style:{overflow:"visible"},className:o,preserveAspectRatio:s,viewBox:`${i.x} ${i.y} ${t} ${c}`,ref:l,...a,children:n})})}const s={display:"flex",flexDirection:"column",flexGrow:1,flexShrink:1,flexBasis:"0%",overflow:"hidden"};function l({parentRef:n,children:l,style:o=s,scale:a=1,align:c="none",options:{debounceDelay:f=50,...x}={},...h}){const{width:d,height:m}=t(n,{debounceDelay:f,...x});return r((()=>{if(n.current)for(const[e,r]of Object.entries(o))n.current.style[e]=r}),[n,o]),e(i,{width:d,height:m,...h,children:e("g",{transform:"center"===c?`translate(${d/2},${m/2-20}) scale(${a})`:`translate(0,0) scale(${a})`,children:l})})}function o({y:r=0,x:t=0,transform:i,className:s,children:l,innerRef:o,...a}){return e("g",{ref:o,className:n("visx-group",s),transform:i||`translate(${t}, ${r})`,...a,children:l})}function a({from:r={x:0,y:0},to:t={x:1,y:1},fill:i="transparent",className:s,innerRef:l,...o}){const a=r.x===t.x||r.y===t.y;return e("line",{ref:l,className:n("visx-line",s),x1:r.x,y1:r.y,x2:t.x,y2:t.y,fill:i,shapeRendering:a?"crispEdges":"auto",...o})}export{o as Group,a as Line,l as ParentsizeSVG,i as ResponsiveSVG};
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/components/ResponsiveSVG/ResponsiveSVG.tsx","../../src/components/ParentsizeSVG/ParentsizeSVG.tsx","../../src/components/Group/Group.tsx","../../src/components/Line/Line.tsx"],"sourcesContent":["import type { ReactNode, Ref } from 'react';\nimport type { PreserveAspectRatio } from '../../types/types';\n\nexport interface Point {\n x: number;\n y: number;\n}\n\nexport interface ResponsiveSVGProps {\n width: number;\n height: number;\n origin?: Point;\n preserveAspectRatio?: PreserveAspectRatio;\n innerRef?: Ref<SVGSVGElement>;\n className?: string;\n hide?: boolean;\n children: ReactNode;\n}\n\nexport function ResponsiveSVG({\n height,\n width,\n children,\n origin = { x: 0, y: 0 },\n preserveAspectRatio = 'xMaxYMid meet',\n innerRef,\n className,\n}: ResponsiveSVGProps): JSX.Element {\n const aspect = width / height;\n\n const adjustedHeight = Math.ceil(width / aspect);\n\n return (\n <div\n data-testid=\"cutting-svg-container\"\n style={{\n position: 'relative',\n overflow: 'visible',\n height: '1px',\n }}\n >\n <svg\n style={{ overflow: 'visible' }}\n className={className}\n preserveAspectRatio={preserveAspectRatio}\n viewBox={`${origin.x} ${origin.y} ${width} ${adjustedHeight}`}\n ref={innerRef}\n >\n {children}\n </svg>\n </div>\n );\n}\n","import type { CSSProperties, PropsWithChildren, RefObject } from 'react';\nimport type { ResponsiveSVGProps } from '../ResponsiveSVG/ResponsiveSVG.js';\nimport type { UseParentSizeOptions } from '@cutting/use-get-parent-size';\nimport { useEffect } from 'react';\nimport { useParentSize } from '@cutting/use-get-parent-size';\nimport { ResponsiveSVG } from '../ResponsiveSVG/ResponsiveSVG';\n\ntype Align = 'none' | 'center';\n\nexport type ParentsizeSVGProps<E extends HTMLElement = HTMLElement> = {\n parentRef: RefObject<E>;\n style?: CSSProperties;\n align?: Align;\n scale?: number;\n options?: Partial<UseParentSizeOptions>;\n} & Partial<Omit<ResponsiveSVGProps, 'innerRef' | 'height' | 'height'>>;\n\nexport const DefaultStyle: CSSProperties = {\n display: 'flex',\n flexDirection: 'column',\n flexGrow: 1,\n flexShrink: 1,\n flexBasis: '0%',\n overflow: 'hidden',\n} as const;\n\nexport function ParentsizeSVG<E extends HTMLElement>({\n parentRef,\n children,\n style = DefaultStyle,\n scale = 1,\n align = 'none',\n options: { debounceDelay = 50, ...optionsRest } = {},\n ...rest\n}: PropsWithChildren<ParentsizeSVGProps<E>>): JSX.Element | null {\n const { width, height } = useParentSize(parentRef, { debounceDelay, ...optionsRest });\n\n useEffect(() => {\n if (!parentRef.current) {\n return;\n }\n\n for (const [key, value] of Object.entries(style)) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n parentRef.current.style[key as any] = value;\n }\n }, [parentRef, style]);\n\n const transform =\n align === 'center'\n ? `translate(${width / 2},${height / 2 - 20}) scale(${scale})`\n : `translate(0,0) scale(${scale})`;\n\n return (\n <ResponsiveSVG width={width} height={height} {...rest}>\n <g transform={transform}>{children}</g>\n </ResponsiveSVG>\n );\n}\n","import cx from 'classnames';\n\ntype GroupOnlyProps = {\n /** Top offset applied to `<g/>`. */\n y?: number;\n /** Left offset applied to `<g/>`. */\n x?: number;\n /** Override `x` and `y` to provide the entire `transform` string. */\n transform?: string;\n className?: string;\n children?: React.ReactNode;\n innerRef?: React.Ref<SVGGElement>;\n};\n\ntype GroupProps = GroupOnlyProps & Omit<React.SVGProps<SVGGElement>, keyof GroupOnlyProps>;\n\nexport function Group({\n y = 0,\n x = 0,\n transform,\n className,\n children,\n innerRef,\n ...restProps\n}: GroupProps): JSX.Element {\n return (\n <g\n ref={innerRef}\n className={cx('visx-group', className)}\n transform={transform || `translate(${x}, ${y})`}\n {...restProps}\n >\n {children}\n </g>\n );\n}\n","import cx from 'classnames';\nimport type { AddSVGProps, Point } from '../../types/types';\n\nexport type LineProps = {\n className?: string;\n innerRef?: React.Ref<SVGLineElement>;\n fill?: string;\n /** Starting x,y point of the line. */\n from?: Point;\n /** Ending x,y point of the line. */\n to?: Point;\n};\n\nexport function Line({\n from = { x: 0, y: 0 },\n to = { x: 1, y: 1 },\n fill = 'transparent',\n className,\n innerRef,\n ...restProps\n}: AddSVGProps<LineProps, SVGLineElement>): JSX.Element {\n const isRectilinear = from.x === to.x || from.y === to.y;\n\n return (\n <line\n ref={innerRef}\n className={cx('visx-line', className)}\n x1={from.x}\n y1={from.y}\n x2={to.x}\n y2={to.y}\n fill={fill}\n shapeRendering={isRectilinear ? 'crispEdges' : 'auto'}\n {...restProps}\n />\n );\n}\n"],"names":["ResponsiveSVG","height","width","children","origin","x","y","preserveAspectRatio","innerRef","className","adjustedHeight","Math","ceil","_jsx","style","position","overflow","viewBox","ref","DefaultStyle","display","flexDirection","flexGrow","flexShrink","flexBasis","ParentsizeSVG","parentRef","scale","align","options","debounceDelay","optionsRest","rest","useParentSize","useEffect","current","key","value","Object","entries","transform","Group","restProps","cx","Line","from","to","fill","isRectilinear","x1","y1","x2","y2","shapeRendering"],"mappings":"iKAmBgB,SAAAA,GAAcC,OAC5BA,EAAMC,MACNA,EAAKC,SACLA,EAAQC,OACRA,EAAS,CAAEC,EAAG,EAAGC,EAAG,GAAGC,oBACvBA,EAAsB,gBAAeC,SACrCA,EAAQC,UACRA,IAEA,MAEMC,EAAiBC,KAAKC,KAAKV,GAFlBA,EAAQD,IAIvB,OACEY,EAAA,MAAA,CAAA,cACc,wBACZC,MAAO,CACLC,SAAU,WACVC,SAAU,UACVf,OAAQ,OACTE,SAEDU,SACEC,MAAO,CAAEE,SAAU,WACnBP,UAAWA,EACXF,oBAAqBA,EACrBU,QAAS,GAAGb,EAAOC,KAAKD,EAAOE,KAAKJ,KAASQ,IAC7CQ,IAAKV,EAAQL,SAEZA,KAIT,CCnCO,MAAMgB,E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C,EACT6C,GAAIL,EAAKvC,EACT6C,GAAIL,EAAGzC,EACP+C,GAAIN,EAAGxC,EACPyC,KAAMA,EACNM,eAAgBL,EAAgB,aAAe,UAC3CN,GAGV"}
1
+ {"version":3,"file":"index.js","sources":["../../src/components/ResponsiveSVG/ResponsiveSVG.tsx","../../src/components/ParentsizeSVG/ParentsizeSVG.tsx","../../src/components/Group/Group.tsx","../../src/components/Line/Line.tsx"],"sourcesContent":["import type { ReactNode, Ref } from 'react';\nimport type { PreserveAspectRatio, SVGAttributes } from '../../types/types';\n\nexport interface Point {\n x: number;\n y: number;\n}\n\nexport type ResponsiveSVGProps = SVGAttributes<{\n width: number;\n height: number;\n origin?: Point;\n preserveAspectRatio?: PreserveAspectRatio;\n innerRef?: Ref<SVGSVGElement>;\n className?: string;\n hide?: boolean;\n children: ReactNode;\n}>;\n\nexport function ResponsiveSVG({\n height,\n width,\n children,\n origin = { x: 0, y: 0 },\n preserveAspectRatio = 'xMaxYMid meet',\n innerRef,\n className,\n ...props\n}: ResponsiveSVGProps): JSX.Element {\n const aspect = width / height;\n\n const adjustedHeight = Math.ceil(width / aspect);\n\n return (\n <div\n data-testid=\"cutting-svg-container\"\n style={{\n position: 'relative',\n overflow: 'visible',\n height: '1px',\n }}\n >\n <svg\n style={{ overflow: 'visible' }}\n className={className}\n preserveAspectRatio={preserveAspectRatio}\n viewBox={`${origin.x} ${origin.y} ${width} ${adjustedHeight}`}\n ref={innerRef}\n {...props}\n >\n {children}\n </svg>\n </div>\n );\n}\n","import type { CSSProperties, PropsWithChildren, RefObject } from 'react';\nimport type { ResponsiveSVGProps } from '../ResponsiveSVG/ResponsiveSVG.js';\nimport type { UseParentSizeOptions } from '@cutting/use-get-parent-size';\nimport { useEffect } from 'react';\nimport { useParentSize } from '@cutting/use-get-parent-size';\nimport { ResponsiveSVG } from '../ResponsiveSVG/ResponsiveSVG';\n\ntype Align = 'none' | 'center';\n\nexport type ParentsizeSVGProps<E extends HTMLElement = HTMLElement> = {\n parentRef: RefObject<E>;\n style?: CSSProperties;\n align?: Align;\n scale?: number;\n options?: Partial<UseParentSizeOptions>;\n} & Partial<Omit<ResponsiveSVGProps, 'innerRef' | 'height' | 'height'>>;\n\nexport const DefaultStyle: CSSProperties = {\n display: 'flex',\n flexDirection: 'column',\n flexGrow: 1,\n flexShrink: 1,\n flexBasis: '0%',\n overflow: 'hidden',\n} as const;\n\nexport function ParentsizeSVG<E extends HTMLElement>({\n parentRef,\n children,\n style = DefaultStyle,\n scale = 1,\n align = 'none',\n options: { debounceDelay = 50, ...optionsRest } = {},\n ...rest\n}: PropsWithChildren<ParentsizeSVGProps<E>>): JSX.Element | null {\n const { width, height } = useParentSize(parentRef, { debounceDelay, ...optionsRest });\n\n useEffect(() => {\n if (!parentRef.current) {\n return;\n }\n\n for (const [key, value] of Object.entries(style)) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n parentRef.current.style[key as any] = value;\n }\n }, [parentRef, style]);\n\n const transform =\n align === 'center'\n ? `translate(${width / 2},${height / 2 - 20}) scale(${scale})`\n : `translate(0,0) scale(${scale})`;\n\n return (\n <ResponsiveSVG width={width} height={height} {...rest}>\n <g transform={transform}>{children}</g>\n </ResponsiveSVG>\n );\n}\n","import cx from 'classnames';\n\ntype GroupOnlyProps = {\n /** Top offset applied to `<g/>`. */\n y?: number;\n /** Left offset applied to `<g/>`. */\n x?: number;\n /** Override `x` and `y` to provide the entire `transform` string. */\n transform?: string;\n className?: string;\n children?: React.ReactNode;\n innerRef?: React.Ref<SVGGElement>;\n};\n\ntype GroupProps = GroupOnlyProps & Omit<React.SVGProps<SVGGElement>, keyof GroupOnlyProps>;\n\nexport function Group({\n y = 0,\n x = 0,\n transform,\n className,\n children,\n innerRef,\n ...restProps\n}: GroupProps): JSX.Element {\n return (\n <g\n ref={innerRef}\n className={cx('visx-group', className)}\n transform={transform || `translate(${x}, ${y})`}\n {...restProps}\n >\n {children}\n </g>\n );\n}\n","import cx from 'classnames';\nimport type { AddSVGProps, Point } from '../../types/types';\n\nexport type LineProps = {\n className?: string;\n innerRef?: React.Ref<SVGLineElement>;\n fill?: string;\n /** Starting x,y point of the line. */\n from?: Point;\n /** Ending x,y point of the line. */\n to?: Point;\n};\n\nexport function Line({\n from = { x: 0, y: 0 },\n to = { x: 1, y: 1 },\n fill = 'transparent',\n className,\n innerRef,\n ...restProps\n}: AddSVGProps<LineProps, SVGLineElement>): JSX.Element {\n const isRectilinear = from.x === to.x || from.y === to.y;\n\n return (\n <line\n ref={innerRef}\n className={cx('visx-line', className)}\n x1={from.x}\n y1={from.y}\n x2={to.x}\n y2={to.y}\n fill={fill}\n shapeRendering={isRectilinear ? 'crispEdges' : 'auto'}\n {...restProps}\n />\n );\n}\n"],"names":["ResponsiveSVG","height","width","children","origin","x","y","preserveAspectRatio","innerRef","className","props","adjustedHeight","Math","ceil","_jsx","style","position","overflow","viewBox","ref","DefaultStyle","display","flexDirection","flexGrow","flexShrink","flexBasis","ParentsizeSVG","parentRef","scale","align","options","debounceDelay","optionsRest","rest","useParentSize","useEffect","current","key","value","Object","entries","transform","Group","restProps","cx","Line","from","to","fill","isRectilinear","x1","y1","x2","y2","shapeRendering"],"mappings":"iKAmBgB,SAAAA,GAAcC,OAC5BA,EAAMC,MACNA,EAAKC,SACLA,EAAQC,OACRA,EAAS,CAAEC,EAAG,EAAGC,EAAG,GAAGC,oBACvBA,EAAsB,gBAAeC,SACrCA,EAAQC,UACRA,KACGC,IAEH,MAEMC,EAAiBC,KAAKC,KAAKX,GAFlBA,EAAQD,IAIvB,OACEa,EAAA,MAAA,CAAA,cACc,wBACZC,MAAO,CACLC,SAAU,WACVC,SAAU,UACVhB,OAAQ,OACTE,SAEDW,SACEC,MAAO,CAAEE,SAAU,WACnBR,UAAWA,EACXF,oBAAqBA,EACrBW,QAAS,GAAGd,EAAOC,KAAKD,EAAOE,KAAKJ,KAASS,IAC7CQ,IAAKX,KACDE,EAAKP,SAERA,KAIT,CCrCO,MAAMiB,EAA8B,CACzCC,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GAAIL,EAAKxC,EACT8C,GAAIL,EAAG1C,EACPgD,GAAIN,EAAGzC,EACP0C,KAAMA,EACNM,eAAgBL,EAAgB,aAAe,UAC3CN,GAGV"}
@@ -1,3 +1,4 @@
1
+ import type { SVGAttributes as SvgAttributes } from 'react';
1
2
  export declare type PreserveAspectRatioAlignment = 'xMinYMin' | 'xMidYMin' | 'xMaxYMin' | 'xMinYMid' | 'xMidYMid' | 'xMaxYMid' | 'xMinYMax' | 'xMidYMax' | 'xMaxYMax';
2
3
  export declare type MeetOrSlice = 'meet' | 'slice';
3
4
  export declare type PreserveAspectRatio = `${PreserveAspectRatioAlignment} ${MeetOrSlice}`;
@@ -6,4 +7,5 @@ export interface Point {
6
7
  x: number;
7
8
  y: number;
8
9
  }
10
+ export declare type SVGAttributes<T> = T & Omit<SvgAttributes<SVGSVGElement>, 'origin' | 'viewBox' | 'preserveAspectRatio' | 'children '>;
9
11
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types/types.ts"],"names":[],"mappings":"AAAA,oBAAY,4BAA4B,GACpC,UAAU,GACV,UAAU,GACV,UAAU,GACV,UAAU,GACV,UAAU,GACV,UAAU,GACV,UAAU,GACV,UAAU,GACV,UAAU,CAAC;AAEf,oBAAY,WAAW,GAAG,MAAM,GAAG,OAAO,CAAC;AAE3C,oBAAY,mBAAmB,GAAG,GAAG,4BAA4B,IAAI,WAAW,EAAE,CAAC;AAEnF,oBAAY,WAAW,CAAC,KAAK,EAAE,OAAO,SAAS,UAAU,IAAI,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,KAAK,CAAC,CAAC;AAEhH,MAAM,WAAW,KAAK;IACpB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,IAAI,aAAa,EAAE,MAAM,OAAO,CAAC;AAE5D,oBAAY,4BAA4B,GACpC,UAAU,GACV,UAAU,GACV,UAAU,GACV,UAAU,GACV,UAAU,GACV,UAAU,GACV,UAAU,GACV,UAAU,GACV,UAAU,CAAC;AAEf,oBAAY,WAAW,GAAG,MAAM,GAAG,OAAO,CAAC;AAE3C,oBAAY,mBAAmB,GAAG,GAAG,4BAA4B,IAAI,WAAW,EAAE,CAAC;AAEnF,oBAAY,WAAW,CAAC,KAAK,EAAE,OAAO,SAAS,UAAU,IAAI,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,KAAK,CAAC,CAAC;AAEhH,MAAM,WAAW,KAAK;IACpB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAED,oBAAY,aAAa,CAAC,CAAC,IAAI,CAAC,GAC9B,IAAI,CAAC,aAAa,CAAC,aAAa,CAAC,EAAE,QAAQ,GAAG,SAAS,GAAG,qBAAqB,GAAG,WAAW,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cutting/svg",
3
- "version": "4.50.0",
3
+ "version": "4.50.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/dagda1/cuttingedge.git"
@@ -11,19 +11,20 @@
11
11
  "types": "dist/esm/index.d.ts",
12
12
  "license": "MIT",
13
13
  "dependencies": {
14
- "@cutting/react-abortable-fetch": "0.33.0",
15
- "@cutting/use-get-parent-size": "1.24.0",
16
- "@cutting/util": "4.55.0",
14
+ "@cutting/react-abortable-fetch": "0.33.1",
15
+ "@cutting/use-get-parent-size": "1.24.2",
16
+ "@cutting/util": "4.55.1",
17
17
  "classnames": "^2.3.2",
18
18
  "resize-observer-polyfill": "^1.5.1"
19
19
  },
20
20
  "devDependencies": {
21
- "@cutting/component-library": "5.31.0",
21
+ "@cutting/component-library": "5.32.0",
22
22
  "@cutting/devtools": "4.60.0",
23
23
  "@cutting/eslint-config": "4.42.0",
24
24
  "@cutting/tsconfig": "4.38.0",
25
25
  "@cutting/useful-types": "4.38.0",
26
26
  "@testing-library/react": "^13.4.0",
27
+ "@testing-library/user-event": "14.4.3",
27
28
  "@types/react": "18.0.21",
28
29
  "@types/react-dom": "18.0.6",
29
30
  "@vanilla-extract/css": "^1.9.1",
@@ -1,9 +1,9 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { render, screen } from '@testing-library/react';
1
+ import { describe, it, expect, vi } from 'vitest';
2
+ import { render, fireEvent } from '@testing-library/react';
3
3
  import { useParentSize } from '@cutting/use-get-parent-size';
4
4
  import { useRef } from 'react';
5
+ import type { ResponsiveSVGProps } from './ResponsiveSVG.js';
5
6
  import { ResponsiveSVG } from './ResponsiveSVG.js';
6
- import { vi } from 'vitest';
7
7
 
8
8
  import ResizeObserver from 'resize-observer-polyfill';
9
9
 
@@ -18,30 +18,69 @@ const resize = (width: number, height: number): void => {
18
18
  });
19
19
  };
20
20
 
21
- function TestEr(): JSX.Element {
21
+ type TestResponsiveSVGProps = Omit<ResponsiveSVGProps, 'width' | 'height' | 'children'>;
22
+
23
+ function TestEr(props: TestResponsiveSVGProps = {} as ResponsiveSVGProps): JSX.Element {
22
24
  const ref = useRef<HTMLDivElement>(null);
23
25
  const { width, height } = useParentSize(ref);
24
26
 
25
27
  return (
26
28
  <div ref={ref}>
27
- <ResponsiveSVG height={height} width={width}>
29
+ <ResponsiveSVG height={height} width={width} {...props}>
28
30
  <rect x="20%" y="20%" width="200px" height="200px" rx="20" />
29
31
  </ResponsiveSVG>
30
32
  </div>
31
33
  );
32
34
  }
33
35
 
34
- const wrap = () => render(<TestEr />);
36
+ const wrap = (props: TestResponsiveSVGProps = {} as ResponsiveSVGProps): ReturnType<typeof render> =>
37
+ render(<TestEr {...props} />);
38
+
39
+ class FakeMouseEvent extends MouseEvent {
40
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
41
+ constructor(type: string, values: any) {
42
+ const { pageX, pageY, offsetX, offsetY, x, y, ...mouseValues } = values;
43
+ super(type, mouseValues);
44
+
45
+ Object.assign(this, {
46
+ offsetX: offsetX || 0,
47
+ offsetY: offsetY || 0,
48
+ pageX: pageX || 0,
49
+ pageY: pageY || 0,
50
+ x: x || 0,
51
+ y: y || 0,
52
+ });
53
+ }
54
+ }
35
55
 
36
- describe.skip('useParentSize', () => {
37
- it('should set the svg viewBox attribute', () => {
38
- resize(200, 200);
39
- wrap();
56
+ describe('ResponsiveSVG', () => {
57
+ it('should pass intrinsic props straight through', () => {
58
+ const mouseMoveHandler = vi.fn();
40
59
 
41
- const svg = document.querySelector('svg') as SVGElement;
60
+ const { container } = wrap({ onMouseMove: mouseMoveHandler });
42
61
 
43
- expect(svg.getAttribute('viewBox')).toBe('0 0 200 200');
62
+ fireEvent.mouseMove(
63
+ container.querySelector('svg'),
64
+ new FakeMouseEvent('mousemove', {
65
+ bubbles: true,
66
+ pageX: 350,
67
+ pageY: 125,
68
+ }),
69
+ );
44
70
 
45
- screen.getByTestId('cutting-svg-container');
71
+ expect(mouseMoveHandler).toHaveBeenCalled();
46
72
  });
47
73
  });
74
+
75
+ // describe.skip('useParentSize', () => {
76
+ // it('should set the svg viewBox attribute', () => {
77
+ // resize(200, 200);
78
+ // wrap();
79
+
80
+ // const svg = document.querySelector('svg') as SVGElement;
81
+
82
+ // expect(svg.getAttribute('viewBox')).toBe('0 0 200 200');
83
+
84
+ // screen.getByTestId('cutting-svg-container');
85
+ // });
86
+ // });
@@ -1,12 +1,12 @@
1
1
  import type { ReactNode, Ref } from 'react';
2
- import type { PreserveAspectRatio } from '../../types/types';
2
+ import type { PreserveAspectRatio, SVGAttributes } from '../../types/types';
3
3
 
4
4
  export interface Point {
5
5
  x: number;
6
6
  y: number;
7
7
  }
8
8
 
9
- export interface ResponsiveSVGProps {
9
+ export type ResponsiveSVGProps = SVGAttributes<{
10
10
  width: number;
11
11
  height: number;
12
12
  origin?: Point;
@@ -15,7 +15,7 @@ export interface ResponsiveSVGProps {
15
15
  className?: string;
16
16
  hide?: boolean;
17
17
  children: ReactNode;
18
- }
18
+ }>;
19
19
 
20
20
  export function ResponsiveSVG({
21
21
  height,
@@ -25,6 +25,7 @@ export function ResponsiveSVG({
25
25
  preserveAspectRatio = 'xMaxYMid meet',
26
26
  innerRef,
27
27
  className,
28
+ ...props
28
29
  }: ResponsiveSVGProps): JSX.Element {
29
30
  const aspect = width / height;
30
31
 
@@ -45,6 +46,7 @@ export function ResponsiveSVG({
45
46
  preserveAspectRatio={preserveAspectRatio}
46
47
  viewBox={`${origin.x} ${origin.y} ${width} ${adjustedHeight}`}
47
48
  ref={innerRef}
49
+ {...props}
48
50
  >
49
51
  {children}
50
52
  </svg>
@@ -1,3 +1,5 @@
1
+ import type { SVGAttributes as SvgAttributes } from 'react';
2
+
1
3
  export type PreserveAspectRatioAlignment =
2
4
  | 'xMinYMin'
3
5
  | 'xMidYMin'
@@ -19,3 +21,6 @@ export interface Point {
19
21
  x: number;
20
22
  y: number;
21
23
  }
24
+
25
+ export type SVGAttributes<T> = T &
26
+ Omit<SvgAttributes<SVGSVGElement>, 'origin' | 'viewBox' | 'preserveAspectRatio' | 'children '>;