Skip to content

Roughjs rough style props #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/common-sites-hope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"slidev-addon-fancy-arrow": minor
---

Add roughness and seed props
4 changes: 4 additions & 0 deletions components/FancyArrow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const props = defineProps<{
arc?: number | string;
arrowHeadType?: "line" | "polygon";
arrowHeadSize?: number | string;
roughness?: number | string;
seed?: number | string;
}>();

const point1 = props.id1
Expand All @@ -37,6 +39,8 @@ const roughSvg = useRoughArrow({
centerPositionParam: Number(props.arc ?? 0),
arrowHeadType: props.arrowHeadType ?? "line",
arrowHeadSize: props.arrowHeadSize ? Number(props.arrowHeadSize) : null,
roughness: props.roughness ? Number(props.roughness) : undefined,
seed: props.seed ? Number(props.seed) : undefined,
});
</script>

Expand Down
11 changes: 8 additions & 3 deletions components/use-rough-arrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export function useRoughArrow(props: {
width: number;
arrowHeadType: "line" | "polygon";
arrowHeadSize: number | null;
roughness?: number;
seed?: number;
twoWay: boolean;
centerPositionParam: number;
}) {
Expand All @@ -56,17 +58,20 @@ export function useRoughArrow(props: {
width,
arrowHeadType,
arrowHeadSize,
roughness,
seed,
twoWay,
centerPositionParam,
} = props;

const options = {
stroke: color,
strokeWidth: width,
fill: color,
fillStyle: "solid",
};

// We don't support the `bowing` param because it's not so effective for arc.
...(roughness !== undefined && { roughness }),
...(seed !== undefined && { seed }),
} as const;
const svg = ref<SVGSVGElement>(
document.createElementNS("http://www.w3.org/2000/svg", "svg"),
);
Expand Down
8 changes: 8 additions & 0 deletions slides.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
---
mdc: true
---

# Fancy Arrow

## Slidev addon for drawing arrows with <span v-mark.red id="fancy-styles">fancy styles</span>,

<span v-click id="rough-js">powered by [Rough.js](https://roughjs.com).</span>

<FancyArrow v-after id1="rough-js" pos1="bottomright" id2="fancy-styles" pos2="bottomleft" color="red" width="2" arc="-0.3" seed="1" roughness="2" />

---

# Demo
Expand Down