{"id":19351523,"url":"https://github.com/lessfish/alfred-tailwindpx2twvalue","last_synced_at":"2025-02-24T10:27:18.101Z","repository":{"id":90624586,"uuid":"603610921","full_name":"lessfish/alfred-TailwindPx2TwValue","owner":"lessfish","description":"An Alfred workflow to make px to value of className in tailwind","archived":false,"fork":false,"pushed_at":"2023-02-19T03:19:17.000Z","size":343,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-09T02:33:23.510Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lessfish.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-19T03:14:58.000Z","updated_at":"2023-02-19T05:26:48.000Z","dependencies_parsed_at":"2023-07-16T02:00:56.809Z","dependency_job_id":null,"html_url":"https://github.com/lessfish/alfred-TailwindPx2TwValue","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lessfish%2Falfred-TailwindPx2TwValue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lessfish%2Falfred-TailwindPx2TwValue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lessfish%2Falfred-TailwindPx2TwValue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lessfish%2Falfred-TailwindPx2TwValue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lessfish","download_url":"https://codeload.github.com/lessfish/alfred-TailwindPx2TwValue/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240460467,"owners_count":19804894,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T04:36:32.274Z","updated_at":"2025-02-24T10:27:18.064Z","avatar_url":"https://github.com/lessfish.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TailwindPx2TwValue\n\n\u003cimg src=\"screenshot.png\" width=\"694\"\u003e\n\n## 使用\n\n在 Alfred 中，输入 `ta` 关键字，回车或者空格后，输入像素值，自动帮你查找在 tailwind 中对应的数值，然后再次回车，会复制到剪切板中\n\n如果该像素值没有对应的类名数值，结果列表中会优先展示最接近的数值，如果两个数值一样接近，会优先展示大于输入数值的。比如 `ta 9`，会依次展示 10px 和 8px 所对应的（这里我个人是觉得如果一定要使用的话，ue 上的间隙应该是往大了加会比较好）\n\n## 使用 issue\n\n* 因为仅个人使用，懒得导出了，可以直接 clone 到具体存放 workflow 的文件夹中进行使用\n* 运行脚本需要修改成自己的 node 所在位置（`/usr/local/opt/node@14/bin/node index.js \"$1\" ` 这里需要替换）\n\n## 开发背景\n\n最近在用 tailwind，确实能减轻不少工作量，但是一些类名经常需要去翻文档\n\n比如用 [Margin](https://tailwindcss.com/docs/margin) 属性，想展示 `margin-top: 16px` 这个样式，我们可以粗暴的用 `mt-[16px]`，但是用 `mt-4` 显然更加简便（不过前提是得基于 html 设置的 font-size 为默认的 16px，其实底层用的是 rem。然后 tailwind 中 1 就表示 4px，所以 16px 是 4）。但是这两者之间的映射关系经常又需要翻文档\n\n该 Alfred Workflow 就是为了简化这个查询而生，找到像素和类名之间的 [映射文档](https://tailwindcss.com/docs/customizing-spacing#default-spacing-scale)\n\n我们在 dom 中选中该文档中 tbody 标签的内容，然后在 devtools 中用以下脚本将映射关系提取：\n\n```js\n// https://tailwindcss.com/docs/customizing-spacing#default-spacing-scale\n// 首先选中 \u003ctbody\u003e 标签\n\nconst ans = []\nconst trs = $0.getElementsByTagName('tr')\n\nfor (const tr of trs) {\n  const tds = tr.getElementsByTagName('td')\n  ans.push({\n    name: tds[0].innerText,\n    size: tds[1].innerText,\n    pixels: tds[2].innerText,\n  })\n}\n\nconsole.log(ans);\n\n// 复制 ans 到 data.json 文件中\n```\n\n提取的映射关系在 [data.json](data.json) 文件中\n\n其他的就是简单的 Alfred Workflow 的开发了","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flessfish%2Falfred-tailwindpx2twvalue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flessfish%2Falfred-tailwindpx2twvalue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flessfish%2Falfred-tailwindpx2twvalue/lists"}