-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(new tool): CSS <> XPath converter
Convert CSS Selectors from/to XPath expressions
- Loading branch information
Showing
3 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<script setup lang="ts"> | ||
import xPathToCss from 'xpath-to-css'; | ||
import cssToXpath from 'csstoxpath'; | ||
import TextareaCopyable from '@/components/TextareaCopyable.vue'; | ||
const cssInput = ref(''); | ||
const xpathOutput = computed( | ||
() => { | ||
try { | ||
return cssToXpath(cssInput.value); | ||
} | ||
catch (e: any) { | ||
return e.toString(); | ||
} | ||
}, | ||
); | ||
const xpathInput = ref(''); | ||
const cssOutput = computed( | ||
() => { | ||
try { | ||
return xPathToCss(xpathInput.value); | ||
} | ||
catch (e: any) { | ||
return e.toString(); | ||
} | ||
}, | ||
); | ||
</script> | ||
|
||
<template> | ||
<div max-w-600> | ||
<c-card title="CSS to XPath"> | ||
<c-input-text | ||
v-model:value="cssInput" | ||
placeholder="Put your CSS selector here..." | ||
label="CSS selector to convert" | ||
raw-text | ||
mb-5 | ||
/> | ||
|
||
<n-divider /> | ||
|
||
<TextareaCopyable | ||
label="XPath expression" | ||
:value="xpathOutput" | ||
readonly | ||
mb-5 | ||
/> | ||
</c-card> | ||
|
||
<c-card title="XPath to CSS" mt-5> | ||
<c-input-text | ||
v-model:value="xpathInput" | ||
placeholder="Put your XPath expression here..." | ||
label="XPath expression to convert" | ||
raw-text | ||
mb-5 | ||
/> | ||
|
||
<n-divider /> | ||
|
||
<TextareaCopyable | ||
label="CSS Selector" | ||
:value="cssOutput" | ||
readonly | ||
mb-5 | ||
/> | ||
</c-card> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Braces } from '@vicons/tabler'; | ||
import { defineTool } from '../tool'; | ||
|
||
export const tool = defineTool({ | ||
name: 'Css XPath Converter', | ||
path: '/css-xpath-converter', | ||
description: 'Convert CSS selector to/from XPath expression', | ||
keywords: ['css', 'xpath', 'converter'], | ||
component: () => import('./css-xpath-converter.vue'), | ||
icon: Braces, | ||
createdAt: new Date('2024-08-15'), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters