mirror of
https://github.com/jonasrafa/kunkun-ext-fancy-text.git
synced 2025-04-03 17:56:44 +00:00
initial commit
This commit is contained in:
commit
3a078bd9ff
177
.gitignore
vendored
Normal file
177
.gitignore
vendored
Normal file
@ -0,0 +1,177 @@
|
||||
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore
|
||||
|
||||
# Logs
|
||||
|
||||
logs
|
||||
_.log
|
||||
npm-debug.log_
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
.pnpm-debug.log*
|
||||
|
||||
# Caches
|
||||
|
||||
.cache
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
|
||||
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
|
||||
|
||||
# Runtime data
|
||||
|
||||
pids
|
||||
_.pid
|
||||
_.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
|
||||
coverage
|
||||
*.lcov
|
||||
|
||||
# nyc test coverage
|
||||
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# Snowpack dependency directory (https://snowpack.dev/)
|
||||
|
||||
web_modules/
|
||||
|
||||
# TypeScript cache
|
||||
|
||||
*.tsbuildinfo
|
||||
|
||||
# Optional npm cache directory
|
||||
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
|
||||
.eslintcache
|
||||
|
||||
# Optional stylelint cache
|
||||
|
||||
.stylelintcache
|
||||
|
||||
# Microbundle cache
|
||||
|
||||
.rpt2_cache/
|
||||
.rts2_cache_cjs/
|
||||
.rts2_cache_es/
|
||||
.rts2_cache_umd/
|
||||
|
||||
# Optional REPL history
|
||||
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variable files
|
||||
|
||||
.env
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
.env.local
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
|
||||
.parcel-cache
|
||||
|
||||
# Next.js build output
|
||||
|
||||
.next
|
||||
out
|
||||
|
||||
# Nuxt.js build / generate output
|
||||
|
||||
.nuxt
|
||||
dist
|
||||
|
||||
# Gatsby files
|
||||
|
||||
# Comment in the public line in if your project uses Gatsby and not Next.js
|
||||
|
||||
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||
|
||||
# public
|
||||
|
||||
# vuepress build output
|
||||
|
||||
.vuepress/dist
|
||||
|
||||
# vuepress v2.x temp and cache directory
|
||||
|
||||
.temp
|
||||
|
||||
# Docusaurus cache and generated files
|
||||
|
||||
.docusaurus
|
||||
|
||||
# Serverless directories
|
||||
|
||||
.serverless/
|
||||
|
||||
# FuseBox cache
|
||||
|
||||
.fusebox/
|
||||
|
||||
# DynamoDB Local files
|
||||
|
||||
.dynamodb/
|
||||
|
||||
# TernJS port file
|
||||
|
||||
.tern-port
|
||||
|
||||
# Stores VSCode versions used for testing VSCode extensions
|
||||
|
||||
.vscode-test
|
||||
|
||||
# yarn v2
|
||||
|
||||
.yarn/cache
|
||||
.yarn/unplugged
|
||||
.yarn/build-state.yml
|
||||
.yarn/install-state.gz
|
||||
.pnp.*
|
||||
|
||||
# IntelliJ based IDEs
|
||||
.idea
|
||||
|
||||
# Finder (MacOS) folder config
|
||||
.DS_Store
|
||||
extensions_support/
|
||||
|
22
CHANGELOG.md
Normal file
22
CHANGELOG.md
Normal file
@ -0,0 +1,22 @@
|
||||
# template-ext-worker
|
||||
|
||||
## 0.0.5
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies
|
||||
- @kksh/api@0.0.53
|
||||
|
||||
## 0.0.4
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies
|
||||
- @kksh/api@0.0.48
|
||||
|
||||
## 0.0.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies
|
||||
- @kksh/api@0.0.47
|
19
README.md
Normal file
19
README.md
Normal file
@ -0,0 +1,19 @@
|
||||
# Fancy Fonts
|
||||
|
||||
Turn your normal text into fancy text!
|
||||
|
||||
Some examples:
|
||||
|
||||
> 𝚂𝚝𝚊𝚢 𝚒𝚗 𝚝𝚑𝚎 𝚏𝚕𝚘𝚠
|
||||
|
||||
> 𝕾𝖙𝖆𝖞 𝖎𝖓 𝖙𝖍𝖊 𝖋𝖑𝖔𝖜
|
||||
|
||||
> S̶t̶̶a̶y̶ i̶n̶ t̶h̶e̶ f̶l̶o̶w̶
|
||||
|
||||
> 𝒮𝓉𝒶𝓎 𝒾𝓃 𝓉𝒽ℯ 𝒻𝓁ℴ𝓌
|
||||
|
||||
This extension converts your text by using pseudofonts made with unicode characters.
|
||||
|
||||
_Note:_ Some of these fonts might not be recognizable by screen-readers. So please use them with care.
|
||||
|
||||
Credits to [Raycast Store: Fancy Text](https://www.raycast.com/peduarte/fancy-text).
|
30
build.ts
Normal file
30
build.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import { watch } from "fs"
|
||||
import { join } from "path"
|
||||
import { refreshTemplateWorkerExtension } from "@kksh/api/dev"
|
||||
import { $ } from "bun"
|
||||
|
||||
const entrypoints = ["./src/index.ts"]
|
||||
|
||||
async function build() {
|
||||
try {
|
||||
for (const entrypoint of entrypoints) {
|
||||
await $`bun build --minify --target=browser --outdir=./dist ${entrypoint}`
|
||||
}
|
||||
if (Bun.argv.includes("dev")) {
|
||||
await refreshTemplateWorkerExtension()
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
const srcDir = join(import.meta.dir, "src")
|
||||
|
||||
await build()
|
||||
|
||||
if (Bun.argv.includes("dev")) {
|
||||
console.log(`Watching ${srcDir} for changes...`)
|
||||
watch(srcDir, { recursive: true }, async (event, filename) => {
|
||||
await build()
|
||||
})
|
||||
}
|
47
package.json
Normal file
47
package.json
Normal file
@ -0,0 +1,47 @@
|
||||
{
|
||||
"$schema": "https://schema.kunkun.sh",
|
||||
"name": "kunkun-ext-fancy-text",
|
||||
"version": "0.0.5",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
"kunkun": {
|
||||
"name": "Fancy Text",
|
||||
"shortDescription": "Convert your normal text to fancy text",
|
||||
"longDescription": "Convert your normal text to fancy text",
|
||||
"identifier": "fancy-text",
|
||||
"permissions": [
|
||||
"clipboard:write-text"
|
||||
],
|
||||
"demoImages": [],
|
||||
"icon": {
|
||||
"type": "iconify",
|
||||
"value": "la:pen-fancy"
|
||||
},
|
||||
"customUiCmds": [],
|
||||
"templateUiCmds": [
|
||||
{
|
||||
"name": "Fancy Text",
|
||||
"main": "dist/index.js",
|
||||
"cmds": []
|
||||
}
|
||||
]
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "bun build.ts dev",
|
||||
"build": "bun build.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@kksh/api": "0.0.53",
|
||||
"i18next": "^23.15.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/bun": "latest"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": "^5.0.0"
|
||||
},
|
||||
"files": [
|
||||
"./dist",
|
||||
".gitignore"
|
||||
]
|
||||
}
|
2231
pnpm-lock.yaml
generated
Normal file
2231
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
1058
src/fonts.json
Normal file
1058
src/fonts.json
Normal file
File diff suppressed because it is too large
Load Diff
5
src/i18n/en.ts
Normal file
5
src/i18n/en.ts
Normal file
@ -0,0 +1,5 @@
|
||||
const en = {
|
||||
welcome: "Welcome to Kunkun"
|
||||
}
|
||||
export default en
|
||||
export type Translation = typeof en
|
20
src/i18n/index.ts
Normal file
20
src/i18n/index.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import i18next from "i18next"
|
||||
import en, { type Translation } from "./en"
|
||||
import zh from "./zh"
|
||||
|
||||
export function setupI18n(language: "en" | "zh" = "en") {
|
||||
i18next.init({
|
||||
resources: {
|
||||
en: {
|
||||
translation: en
|
||||
},
|
||||
zh: {
|
||||
translation: zh
|
||||
}
|
||||
},
|
||||
lng: language, // default language
|
||||
fallbackLng: "en"
|
||||
})
|
||||
}
|
||||
|
||||
export const t = (key: keyof Translation, options?: any) => i18next.t(key, options)
|
5
src/i18n/zh.ts
Normal file
5
src/i18n/zh.ts
Normal file
@ -0,0 +1,5 @@
|
||||
import type { Translation } from "./en"
|
||||
|
||||
export default {
|
||||
welcome: "欢迎来到Kunkun"
|
||||
} satisfies Translation
|
86
src/index.ts
Normal file
86
src/index.ts
Normal file
@ -0,0 +1,86 @@
|
||||
import {
|
||||
clipboard,
|
||||
expose,
|
||||
List,
|
||||
toast,
|
||||
ui,
|
||||
WorkerExtension,
|
||||
} from "@kksh/api/ui/worker";
|
||||
import fonts from "./fonts.json";
|
||||
import { PseudoFont } from "./pseudo-font";
|
||||
|
||||
const Actions = {
|
||||
copyToClipboard: "Copy to Clipboard",
|
||||
};
|
||||
|
||||
class ExtensionTemplate extends WorkerExtension {
|
||||
private term: string = "Lorem Ipsum";
|
||||
private fontsFiltered: PseudoFont[] = [];
|
||||
|
||||
async load() {
|
||||
const pseudoFonts = fonts.map((font) => {
|
||||
const pseudoFont = new PseudoFont(
|
||||
font.fontName,
|
||||
font.fontLower || "abcdefghijklmnopqrstuvwxyz",
|
||||
font.fontUpper || "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
||||
font.fontDigits || "0123456789"
|
||||
);
|
||||
if (font.experimentalFont) {
|
||||
pseudoFont.experimental = true;
|
||||
}
|
||||
return pseudoFont;
|
||||
});
|
||||
|
||||
this.fontsFiltered = pseudoFonts
|
||||
.filter((font) => !font.experimental)
|
||||
.sort((a, b) => a.fontName.localeCompare(b.fontName));
|
||||
|
||||
return ui.setSearchBarPlaceholder("Type your text here...").then(() => {
|
||||
return ui.render(
|
||||
new List.List({
|
||||
filter: "none",
|
||||
items: this.renderList(this.term),
|
||||
})
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
renderList(searchTerm: string = ""): List.Item[] {
|
||||
if (searchTerm) {
|
||||
this.term = searchTerm;
|
||||
}
|
||||
return this.fontsFiltered.map((font) => {
|
||||
return new List.Item({
|
||||
title: font.convert(this.term),
|
||||
value: font.fontName,
|
||||
accessories: [
|
||||
new List.ItemAccessory({
|
||||
text: font.fontName,
|
||||
}),
|
||||
],
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async onSearchTermChange(term: string): Promise<void> {
|
||||
return ui.render(
|
||||
new List.List({
|
||||
defaultAction: Actions.copyToClipboard,
|
||||
filter: "none",
|
||||
items: this.renderList(term),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
onListItemSelected(value: string): Promise<void> {
|
||||
const font = this.fontsFiltered.find((font) => font.fontName === value);
|
||||
if (font) {
|
||||
console.log(value);
|
||||
clipboard.writeText(font.convert(this.term));
|
||||
toast.success("Copied to clipboard");
|
||||
}
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
|
||||
expose(new ExtensionTemplate());
|
39
src/pseudo-font.ts
Normal file
39
src/pseudo-font.ts
Normal file
@ -0,0 +1,39 @@
|
||||
// Helper class for font conversion
|
||||
export class PseudoFont {
|
||||
fontName: string;
|
||||
fontLower: string[];
|
||||
fontUpper: string[];
|
||||
fontDigits: string[];
|
||||
experimental: boolean;
|
||||
private referenceLower = "abcdefghijklmnopqrstuvwxyz";
|
||||
private referenceUpper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
private referenceDigits = "0123456789";
|
||||
|
||||
constructor(
|
||||
fontName: string,
|
||||
fontLower: string | string[],
|
||||
fontUpper: string | string[],
|
||||
fontDigits: string | string[]
|
||||
) {
|
||||
this.fontName = fontName;
|
||||
this.fontLower = Array.isArray(fontLower) ? fontLower : [...fontLower];
|
||||
this.fontUpper = Array.isArray(fontUpper) ? fontUpper : [...fontUpper];
|
||||
this.fontDigits = Array.isArray(fontDigits) ? fontDigits : [...fontDigits];
|
||||
this.experimental = false;
|
||||
}
|
||||
|
||||
convert(rawText: string): string {
|
||||
return [...rawText]
|
||||
.map((char) => {
|
||||
if (this.referenceLower.includes(char)) {
|
||||
return this.fontLower[this.referenceLower.indexOf(char)];
|
||||
} else if (this.referenceUpper.includes(char)) {
|
||||
return this.fontUpper[this.referenceUpper.indexOf(char)];
|
||||
} else if (this.referenceDigits.includes(char)) {
|
||||
return this.fontDigits[this.referenceDigits.indexOf(char)];
|
||||
}
|
||||
return char;
|
||||
})
|
||||
.join("");
|
||||
}
|
||||
}
|
27
tsconfig.json
Normal file
27
tsconfig.json
Normal file
@ -0,0 +1,27 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
// Enable latest features
|
||||
"lib": [
|
||||
"ESNext",
|
||||
"DOM"
|
||||
],
|
||||
"target": "ESNext",
|
||||
"module": "ESNext",
|
||||
"moduleDetection": "force",
|
||||
"jsx": "react-jsx",
|
||||
"allowJs": true,
|
||||
// Bundler mode
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": false,
|
||||
"verbatimModuleSyntax": true,
|
||||
"noEmit": true,
|
||||
// Best practices
|
||||
"strict": true,
|
||||
"skipLibCheck": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
// Some stricter flags (disabled by default)
|
||||
"noUnusedLocals": false,
|
||||
"noUnusedParameters": false,
|
||||
"noPropertyAccessFromIndexSignature": false
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user