Skip to content

Commit f7dd7dd

Browse files
committed
Rewrite project
1 parent 63b6bd4 commit f7dd7dd

11 files changed

+176
-111
lines changed

.editorconfig

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
root = true
22

33
[*]
4-
indent_style = space
5-
indent_size = 2
6-
end_of_line = lf
74
charset = utf-8
8-
trim_trailing_whitespace = true
5+
end_of_line = lf
6+
indent_size = 2
7+
indent_style = space
98
insert_final_newline = true
9+
trim_trailing_whitespace = true

.github/workflows/main.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
jobs:
2+
main:
3+
runs-on: ubuntu-latest
4+
steps:
5+
- uses: actions/checkout@v4
6+
- uses: actions/setup-node@v4
7+
with:
8+
node-version: node
9+
- run: npm install
10+
- run: npm test
11+
- uses: JamesIves/github-pages-deploy-action@releases/v4
12+
with:
13+
branch: gh-pages
14+
commit-message: .
15+
folder: dest
16+
git-config-email: [email protected]
17+
git-config-name: Titus Wormer
18+
single-commit: true
19+
name: main
20+
on:
21+
push:
22+
branches:
23+
- website

.gitignore

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
.DS_Store
2-
*.log
1+
dest/
32
node_modules/
3+
*.d.ts
4+
*.log
5+
*.map
6+
*.tsbuildinfo
7+
.DS_Store
48
yarn.lock
5-
dest/

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
ignore-scripts=true
12
package-lock=false

.prettierignore

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
dest/
2+
*.html
3+
*.md

.travis.yml

-12
This file was deleted.

package.json

+67-55
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,44 @@
11
{
2-
"name": "www-retext-emoji",
3-
"private": true,
4-
"license": "MIT",
5-
"repository": "retextjs/retext-emoji",
6-
"bugs": "https://github.com/retextjs/retext-emoji/issues",
72
"author": "Titus Wormer <[email protected]> (https://wooorm.com)",
8-
"contributors": [
9-
"Titus Wormer <[email protected]> (https://wooorm.com)"
10-
],
11-
"devDependencies": {
12-
"browserify": "^16.0.0",
13-
"cssnano": "^4.0.0",
14-
"postcss-cli": "^6.0.0",
15-
"postcss-preset-env": "^6.0.0",
16-
"prettier": "^1.0.0",
17-
"rehype-cli": "^8.0.0",
18-
"rehype-preset-minify": "^4.0.0",
19-
"rehype-prevent-favicon-request": "^2.0.0",
20-
"remark-cli": "^7.0.0",
21-
"remark-preset-wooorm": "^6.0.0",
22-
"retext-emoji": "^6.0.0",
23-
"retext-english": "^3.0.0",
24-
"retext-stringify": "^2.0.0",
25-
"stylelint": "^11.0.0",
26-
"stylelint-config-standard": "^19.0.0",
27-
"tinyify": "^2.0.0",
28-
"unified": "^8.0.0",
29-
"xo": "^0.25.0"
30-
},
31-
"scripts": {
32-
"format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix && stylelint src/index.css --fix",
33-
"build:js": "browserify src -p tinyify -o dest/index.js",
34-
"build:css": "postcss src/index.css -o dest/index.css",
35-
"build:html": "rehype -u preset-minify -u prevent-favicon-request src -o dest",
36-
"build": "npm run build:js && npm run build:css && npm run build:html",
37-
"test": "npm run format && npm run build"
38-
},
39-
"prettier": {
40-
"tabWidth": 2,
41-
"useTabs": false,
42-
"singleQuote": true,
43-
"bracketSpacing": false,
44-
"semi": false,
45-
"trailingComma": "none"
46-
},
47-
"xo": {
48-
"prettier": true,
49-
"esnext": false,
50-
"rules": {
51-
"unicorn/prefer-node-append": "off"
52-
}
53-
},
54-
"stylelint": {
55-
"extends": "stylelint-config-standard"
56-
},
573
"browserslist": [
584
"> 1%",
595
"last 2 versions",
606
"not ie <= 8"
617
],
8+
"bugs": "https://github.com/retextjs/retext-emoji/issues",
9+
"contributors": [
10+
"Titus Wormer <[email protected]> (https://wooorm.com)"
11+
],
12+
"devDependencies": {
13+
"@types/nlcst": "^2.0.0",
14+
"@types/react": "^18.0.0",
15+
"@types/react-dom": "^18.0.0",
16+
"cssnano": "^7.0.0",
17+
"devlop": "^1.1.0",
18+
"esbuild": "^0.24.0",
19+
"postcss-cli": "^11.0.0",
20+
"postcss-preset-env": "^10.0.0",
21+
"prettier": "^3.0.0",
22+
"react": "^18.0.0",
23+
"react-dom": "^18.0.0",
24+
"rehype-cli": "^12.0.0",
25+
"rehype-preset-minify": "^7.0.0",
26+
"rehype-prevent-favicon-request": "^4.0.0",
27+
"remark-cli": "^12.0.0",
28+
"remark-preset-wooorm": "^10.0.0",
29+
"retext-emoji": "^9.0.0",
30+
"retext-english": "^5.0.0",
31+
"retext-stringify": "^4.0.0",
32+
"stylelint": "^16.0.0",
33+
"stylelint-config-standard": "^36.0.0",
34+
"type-coverage": "^2.0.0",
35+
"typescript": "^5.0.0",
36+
"unified": "^11.0.0",
37+
"vfile": "^6.0.0",
38+
"xo": "^0.59.0"
39+
},
40+
"license": "MIT",
41+
"name": "www-retext-emoji",
6242
"postcss": {
6343
"plugins": {
6444
"postcss-preset-env": {},
@@ -67,9 +47,41 @@
6747
}
6848
}
6949
},
50+
"prettier": {
51+
"bracketSpacing": false,
52+
"semi": false,
53+
"singleQuote": true,
54+
"tabWidth": 2,
55+
"trailingComma": "none",
56+
"useTabs": false
57+
},
58+
"private": true,
7059
"remarkConfig": {
7160
"plugins": [
72-
"preset-wooorm"
61+
"remark-preset-wooorm"
7362
]
63+
},
64+
"repository": "retextjs/retext-emoji",
65+
"typeCoverage": {
66+
"atLeast": 100,
67+
"strict": true
68+
},
69+
"type": "module",
70+
"scripts": {
71+
"build": "tsc --build --clean && tsc --build && type-coverage",
72+
"format": "remark --frail --output --quiet -- . && prettier --log-level warn --write -- . && xo && stylelint src/index.css --fix",
73+
"generate:css": "postcss --output dest/index.css -- src/index.css",
74+
"generate:html": "rehype --frail --output dest/ --quiet --use rehype-preset-minify --use rehype-prevent-favicon-request -- src/",
75+
"generate:js:module": "esbuild src/index.js --bundle --conditions=browser,production --define:process.env.NODE_ENV=\\\"production\\\" --format=esm --log-level=warning --minify --outfile=dest/index.module.js --target=es2020",
76+
"generate:js:nomodule": "esbuild src/index.js --bundle --conditions=browser,production --define:process.env.NODE_ENV=\\\"production\\\" --log-level=warning --minify --outfile=dest/index.nomodule.js --target=es6",
77+
"generate:js": "npm run generate:js:module && npm run generate:js:nomodule",
78+
"generate": "npm run generate:css && npm run generate:html && npm run generate:js",
79+
"test": "npm run build && npm run format && npm run generate"
80+
},
81+
"stylelint": {
82+
"extends": "stylelint-config-standard"
83+
},
84+
"xo": {
85+
"prettier": true
7486
}
7587
}

src/index.css

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
:root {
2-
color-scheme: light dark;
3-
background-color: hsl(0, 0%, 90%);
4-
}
5-
61
* {
72
box-sizing: border-box;
83
}
@@ -18,23 +13,28 @@ body {
1813
padding: 0 calc(1em + 1ex);
1914
}
2015

16+
html {
17+
color-scheme: light dark;
18+
background-color: hsl(0deg 0% 90%);
19+
}
20+
2121
p {
22-
margin-top: calc(1em + 1ex);
2322
margin-bottom: calc(1em + 1ex);
23+
margin-top: calc(1em + 1ex);
2424
}
2525

26+
select,
2627
textarea {
27-
width: 100%;
28+
font-size: inherit;
2829
}
2930

30-
select,
3131
textarea {
32-
font-size: inherit;
32+
width: 100%;
3333
}
3434

3535
@media (prefers-color-scheme: dark) {
36-
:root {
37-
background-color: hsl(214, 13%, 10%);
38-
color: hsl(214, 13%, 90%);
36+
html {
37+
background-color: hsl(214deg 13% 10%);
38+
color: hsl(214deg 13% 90%);
3939
}
4040
}

src/index.html

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
<!doctype html>
22
<meta charset=utf8>
3-
<meta content=width=device-width,initial-scale=1 name=viewport>
3+
<meta content=initial-scale=1,width=device-width name=viewport>
44
<title>retext-emoji</title>
5-
<link rel=stylesheet href=index.css>
5+
<link href=index.css rel=stylesheet>
66
<h1>retext-emoji</h1>
77
<p>A quick demo of <a href=https://github.com/retextjs/retext-emoji>retext-emoji</a>. Please raise any issues on <a href=https://github.com/retextjs/retext-emoji/issues>GitHub</a>.
88
<p>See <a href=https://github.com/wooorm/gemoji/blob/master/support.md>wooorm/gemoji</a> and <a href=https://github.com/wooorm/emoticon/blob/master/support.md>wooorm/emoticon</a> for lists of supported emoji.</p>
99
<p>
1010
<label>
1111
Convert:
1212
<select name=convert>
13-
<option value=encode selected>encode
13+
<option selected value=encode>encode
1414
<option value=decode>decode
1515
</select>
1616
</label>
1717
<p>
18-
<textarea spellcheck=false rows=20 cols=80 autofocus>I’m going to bed. :zzz:
18+
<textarea autofocus cols=80 rows=20 spellcheck=false>I’m going to bed. :zzz:
1919
It’s raining 🐱s and 🐶s!
2020

2121
&lt;3 xoxo &lt;3
2222

2323
=-3</textarea>
2424
<p>
25-
<textarea rows=20 cols=80 readonly></textarea>
26-
<script src=index.js></script>
25+
<textarea cols=80 readonly rows=20></textarea>
26+
<script src=index.module.js type=module></script>
27+
<script nomodule src=index.nomodule.js></script>

src/index.js

+38-19
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,61 @@
1-
'use strict'
2-
31
/* eslint-env browser */
42

5-
var unified = require('unified')
6-
var english = require('retext-english')
7-
var stringify = require('retext-stringify')
8-
var emoji = require('retext-emoji')
3+
/**
4+
* @import {Root} from 'nlcst'
5+
* @import {Options} from 'retext-emoji'
6+
* @import {Processor} from 'unified'
7+
*/
98

10-
var $convert = document.getElementsByName('convert')[0]
11-
var $areas = document.querySelectorAll('textarea')
9+
import {ok as assert} from 'devlop'
10+
import retextEmoji from 'retext-emoji'
11+
import retextEnglish from 'retext-english'
12+
import retextStringify from 'retext-stringify'
13+
import {unified} from 'unified'
1214

13-
var $input = $areas[0]
14-
var $output = $areas[1]
15+
const $convert = document.getElementsByName('convert')[0]
16+
const $areas = document.querySelectorAll('textarea')
1517

16-
var processor
17-
var state = {options: {}}
18+
const $input = $areas[0]
19+
const $output = $areas[1]
1820

19-
$convert.addEventListener('change', onchange)
21+
/** @type {Processor<Root, Root, undefined, Root, string> | undefined} */
22+
let processor
23+
24+
/** @type {{options: Options}} */
25+
const state = {options: {}}
2026

27+
$convert.addEventListener('change', onchange)
2128
$input.addEventListener('input', oninput)
2229

2330
onchange({target: $convert})
2431

32+
/**
33+
* @param {{target: EventTarget | null}} event
34+
* @returns {undefined}
35+
*/
2536
function onchange(event) {
26-
var value = event.target.selectedOptions[0]
37+
// This is all just because TS doesn’t understand normal code.
38+
const target = /** @type {HTMLSelectElement} */ (event.target)
39+
40+
const selectedOption = target.selectedOptions[0]
2741

28-
if (value) {
29-
state.options[event.target.name] = value.value
42+
if (selectedOption) {
43+
assert(target.name === 'convert')
44+
assert(
45+
selectedOption.value === 'decode' || selectedOption.value === 'encode'
46+
)
47+
state.options[target.name] = selectedOption.value
3048
}
3149

3250
processor = unified()
33-
.use(english)
34-
.use(emoji, state.options)
35-
.use(stringify)
51+
.use(retextEnglish)
52+
.use(retextEmoji, state.options)
53+
.use(retextStringify)
3654

3755
oninput()
3856
}
3957

4058
function oninput() {
59+
assert(processor)
4160
$output.value = processor.processSync($input.value).toString()
4261
}

tsconfig.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"compilerOptions": {
3+
"checkJs": true,
4+
"customConditions": ["development"],
5+
"declarationMap": true,
6+
"declaration": true,
7+
"emitDeclarationOnly": true,
8+
"exactOptionalPropertyTypes": true,
9+
"lib": ["dom", "es2023"],
10+
"module": "node16",
11+
"strict": true,
12+
"target": "es2023"
13+
},
14+
"exclude": ["dest/", "node_modules/"],
15+
"include": ["**/*.js"]
16+
}

0 commit comments

Comments
 (0)