Skip to content

Commit

Permalink
major: initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
LumaKernel committed Jan 28, 2024
0 parents commit 0e42a6c
Show file tree
Hide file tree
Showing 84 changed files with 14,310 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
/examples/
/dist/
35 changes: 35 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* eslint-env node */
module.exports = {
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended-type-checked",
],
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint"],
parserOptions: {
project: true,
tsconfigRootDir: __dirname,
},
root: true,
rules: {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/require-await": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{ argsIgnorePattern: "^_", varsIgnorePattern: "^_" },
],
},
overrides: [
{
files: ["*.cjs"],
env: {
node: true,
},
},
],
};
31 changes: 31 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
on:
push:
branches:
- main
- release
pull_request:
jobs:
ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- run: npm ci
- run: npm run lint
- run: npm run test
- run: npm run typecheck
- run: |
npm run examples
echo "[test] checking examples output"
git diff --exit-code -- ./examples/
- run: npm run build
- run: npx -q --no-install semantic-release
env:
GITHUB_TOKEN: ${{ github.token }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
/dist/
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
/examples/
/dist/
*.json
209 changes: 209 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
# luma-unified

> [!WARNING]
> このパッケージが提供するプラグインは私のユースケースに特化したものなので,直接使うのは推奨しません.
> The plugins provided by this package are specific to my use case, so I do not recommend using them directly!
## ライセンス

MITとCC0でライセンスされています

## rehype-add-slug

各ヘディングに対し,slug化したそのテキストを属性として渡し,それより上位のヘディングのslugも属性に付与するプラグイン

```ts
import rehypeAddSlug from "@luma-dev/my-unified/rehype-add-slug";
```

例: 以下の入力に対し,

```md
# hello world

## 1. getting started

## 2. install

## 3. uninstall

# description

## 1. something

## 2. other
```

以下のように変換される

```js
<h1 slug="hello_world">hello world</h1>
<h2 lastH1Slug="hello_world" slug="1.getting_started">1. getting started</h1>
<h2 lastH1Slug="hello_world" slug="2.install">2. install</h1>
...
```

## rehype-replace-text

句点読点を統一する.「,」「.」を「、」「。」に置き換えるプラグイン.

```ts
import rehypeReplaceText from "@luma-dev/my-unified/rehype-replace-text";
```

例: 以下の入力に対し,

```md
こんにちは,ねこだよ.
```

以下のように変換される

```md
こんにちは、ねこだよ。
```

## remark-term

用語を参照する記法を追加します.mdx前提です.

```ts
import remarkTerm from "@luma-dev/my-unified/remark-term";
```

例: 以下の入力に対し,

```mdx
[@逆元]を考える.

{/* 以下のようにすると途中で定義を変えられる */}

<DefMapImp 逆元="群の逆元" />

[@逆元]を考える.

{/* 通常のリンクでは先頭の@をエスケープする必要がある */}
[\@これもリンク](https://example.com)だよ.
```

以下のように変換される

```mdx
<LumaTerm
rawTermRef="逆元"
termRef="逆元"
gotBy="raw"
indexInPage={0}
totalInPage={1}
/>
を考える.

<LumaTerm
rawTermRef="逆元"
termRef="群の逆元"
gotBy="imp"
indexInPage={0}
totalInPage={1}
/>
を考える.
```

`indexInPage``termRef` が何個目に出るか, `totalInPage``termRef` が全体で何個あるか,をページ内で集計したもの.

`DefMapImp` (implicit) の他に `DefMapExp` (explicit) でも書き換えられる.
それらの振る舞いの違いは利用側に委ねられている.
[remark-frontmatter](https://github.com/remarkjs/remark-frontmatter)を入れた状態でfrontmatterのYAMLで `DefMapExp``DefMapImp` を使うと同様に初期化できる

```mdx
---
DefMapExp:
DefMapImp:
逆元: 行列の逆元
---
```

## rehype-katex

- 下記に対する検出をして共通の定義を差し込むなどを行う
- `<Katex>`, `<KatexDef>` で囲まれたテキスト
- `katex`, `katex-def` という言語で設定したコードブロック -`katex-save` という言語で設定したコードブロックを `<Save>` に変換する

```ts
import rehypeKatex from "@luma-dev/my-unified/rehype-katex";
```

## rehype-wrap

`<LumaMdxLayout>` で囲ってメタ情報を属性として入れるプラグイン.

```ts
import rehypeKatex from "@luma-dev/my-unified/rehype-wrap";
```

例: 以下の入力に対し,

```mdx
---
foo: bar
---

hello
```

以下のように変換される

```mdx
<LumaMdxLayout meta={{ foo: 'bar' }} file={...} toc={...}>
hello
</LumaMdxLayout>
```

- `file` はmdxファイル自体の情報
- `toc` はヘッダをまとめた情報
- `[{ tag: 'h1', level: 1, titleComponent: ..., titleText: '...', slug: '...', children: [...] }, ...]` という形式になる

## remark-save

`<Save $name>` で囲ってページローカル保存(コンパイル時), `[$name]` で呼び出しができるプラグイン.

```ts
import remarkSave from "@luma-dev/my-unified/remark-save";
```

例: 以下の入力に対し,

```mdx
<Save $who>world</Save>
hello [$who]
```

以下のように変換される

```mdx
hello world
```

## rehype-meta

`<_luma_internal_meta>` というタグのコンポーネントと一緒にメタデータを入れておくプラグイン.
rehype-wrapでメタデータを入れるために必要.

```ts
import rehypeSave from "@luma-dev/my-unified/rehype-meta";
```

## rehype-clean-internal

`<_luma_internal_*>` などを消すプラグイン.

```ts
import rehypeCleanInternal from "@luma-dev/my-unified/rehype-clean-internal";
```

## rehype-counter

`[#name]` という記法で,その名前ごとに登場回数をカウントして `<LumaCounter index={0} total={3} />` のように置き換える. `<C $name anyAttr="something" />` のように書くことでそれ以降のその名前のカウンタに属性を一律で付与できる.

```ts
import rehypeCounter from "@luma-dev/my-unified/rehype-counter";
```
3 changes: 3 additions & 0 deletions examples/es/input/ctx-delete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(() => {
delete globalThis[a];
})();
1 change: 1 addition & 0 deletions examples/es/input/ctx-push.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
void (globalThis[a] += "a");
1 change: 1 addition & 0 deletions examples/es/input/ctx-reset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
void (globalThis[a] = "");
1 change: 1 addition & 0 deletions examples/es/input/ctx-value.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
globalThis[a];
1 change: 1 addition & 0 deletions examples/es/input/json-parse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
JSON.parse("a");
1 change: 1 addition & 0 deletions examples/es/input/make-symbol.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const a = Symbol();
1 change: 1 addition & 0 deletions examples/es/input/var.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a;
68 changes: 68 additions & 0 deletions examples/es/output/ctx-delete.js.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"type": "Program",
"start": 0,
"end": 39,
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 38,
"expression": {
"type": "CallExpression",
"start": 0,
"end": 37,
"callee": {
"type": "ArrowFunctionExpression",
"start": 1,
"end": 34,
"id": null,
"expression": false,
"generator": false,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
"start": 7,
"end": 34,
"body": [
{
"type": "ExpressionStatement",
"start": 11,
"end": 32,
"expression": {
"type": "UnaryExpression",
"start": 11,
"end": 31,
"operator": "delete",
"prefix": true,
"argument": {
"type": "MemberExpression",
"start": 18,
"end": 31,
"object": {
"type": "Identifier",
"start": 18,
"end": 28,
"name": "globalThis"
},
"property": {
"type": "Identifier",
"start": 29,
"end": 30,
"name": "a"
},
"computed": true,
"optional": false
}
}
}
]
}
},
"arguments": [],
"optional": false
}
}
],
"sourceType": "module"
}
Loading

0 comments on commit 0e42a6c

Please sign in to comment.