Skip to content

Commit be60b04

Browse files
committed
feat(new tool): CSS <> XPath converter
Convert CSS Selectors from/to XPath expressions
1 parent 318fb6e commit be60b04

File tree

8 files changed

+120
-8
lines changed

8 files changed

+120
-8
lines changed

components.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ declare module '@vue/runtime-core' {
5858
CrontabGenerator: typeof import('./src/tools/crontab-generator/crontab-generator.vue')['default']
5959
CSelect: typeof import('./src/ui/c-select/c-select.vue')['default']
6060
'CSelect.demo': typeof import('./src/ui/c-select/c-select.demo.vue')['default']
61+
CssXpathConverter: typeof import('./src/tools/css-xpath-converter/css-xpath-converter.vue')['default']
6162
CTable: typeof import('./src/ui/c-table/c-table.vue')['default']
6263
'CTable.demo': typeof import('./src/ui/c-table/c-table.demo.vue')['default']
6364
CTextCopyable: typeof import('./src/ui/c-text-copyable/c-text-copyable.vue')['default']
@@ -132,6 +133,7 @@ declare module '@vue/runtime-core' {
132133
NCode: typeof import('naive-ui')['NCode']
133134
NCollapseTransition: typeof import('naive-ui')['NCollapseTransition']
134135
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
136+
NDivider: typeof import('naive-ui')['NDivider']
135137
NEllipsis: typeof import('naive-ui')['NEllipsis']
136138
NForm: typeof import('naive-ui')['NForm']
137139
NFormItem: typeof import('naive-ui')['NFormItem']

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"cron-validator": "^1.3.1",
5656
"cronstrue": "^2.26.0",
5757
"crypto-js": "^4.1.1",
58+
"csstoxpath": "^2.0.0",
5859
"date-fns": "^2.29.3",
5960
"dompurify": "^3.0.6",
6061
"email-normalizer": "^1.0.0",
@@ -94,6 +95,7 @@
9495
"vue-tsc": "^1.8.1",
9596
"xml-formatter": "^3.3.2",
9697
"xml-js": "^1.6.11",
98+
"xpath-to-css": "^1.2.0",
9799
"yaml": "^2.2.1"
98100
},
99101
"devDependencies": {

pnpm-lock.yaml

Lines changed: 25 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<script setup lang="ts">
2+
import xPathToCss from 'xpath-to-css';
3+
import cssToXpath from 'csstoxpath';
4+
import TextareaCopyable from '@/components/TextareaCopyable.vue';
5+
6+
const cssInput = ref('');
7+
const xpathOutput = computed(
8+
() => {
9+
try {
10+
return cssToXpath(cssInput.value);
11+
}
12+
catch (e: any) {
13+
return e.toString();
14+
}
15+
},
16+
);
17+
18+
const xpathInput = ref('');
19+
const cssOutput = computed(
20+
() => {
21+
try {
22+
return xPathToCss(xpathInput.value);
23+
}
24+
catch (e: any) {
25+
return e.toString();
26+
}
27+
},
28+
);
29+
</script>
30+
31+
<template>
32+
<div max-w-600>
33+
<c-card title="CSS to XPath">
34+
<c-input-text
35+
v-model:value="cssInput"
36+
placeholder="Put your CSS selector here..."
37+
label="CSS selector to convert"
38+
raw-text
39+
mb-5
40+
/>
41+
42+
<n-divider />
43+
44+
<TextareaCopyable
45+
label="XPath expression"
46+
:value="xpathOutput"
47+
readonly
48+
mb-5
49+
/>
50+
</c-card>
51+
52+
<c-card title="XPath to CSS" mt-5>
53+
<c-input-text
54+
v-model:value="xpathInput"
55+
placeholder="Put your XPath expression here..."
56+
label="XPath expression to convert"
57+
raw-text
58+
mb-5
59+
/>
60+
61+
<n-divider />
62+
63+
<TextareaCopyable
64+
label="CSS Selector"
65+
:value="cssOutput"
66+
readonly
67+
mb-5
68+
/>
69+
</c-card>
70+
</div>
71+
</template>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
declare module "csstoxpath" {
2+
export default function cssToXPath(xpath: string): string;
3+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Braces } from '@vicons/tabler';
2+
import { defineTool } from '../tool';
3+
4+
export const tool = defineTool({
5+
name: 'CSS XPath Converter',
6+
path: '/css-xpath-converter',
7+
description: 'Convert CSS selector to/from XPath expression',
8+
keywords: ['css', 'xpath', 'converter'],
9+
component: () => import('./css-xpath-converter.vue'),
10+
icon: Braces,
11+
createdAt: new Date('2024-08-15'),
12+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
declare module "xpath-to-css" {
2+
export default function xpathToCSS(xpath: string): string;
3+
}

src/tools/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { tool as base64FileConverter } from './base64-file-converter';
22
import { tool as base64StringConverter } from './base64-string-converter';
33
import { tool as basicAuthGenerator } from './basic-auth-generator';
44
import { tool as emailNormalizer } from './email-normalizer';
5+
import { tool as cssXpathConverter } from './css-xpath-converter';
56

67
import { tool as asciiTextDrawer } from './ascii-text-drawer';
78

@@ -154,6 +155,7 @@ export const toolsByCategory: ToolCategory[] = [
154155
xmlFormatter,
155156
yamlViewer,
156157
emailNormalizer,
158+
cssXpathConverter,
157159
],
158160
},
159161
{

0 commit comments

Comments
 (0)