rough-emoji-draw 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.en.md +147 -0
  2. package/README.md +2 -0
  3. package/package.json +13 -1
package/README.en.md ADDED
@@ -0,0 +1,147 @@
1
+ # Rough Emoji Draw
2
+
3
+ [中文 README](./README.md)
4
+
5
+ Rough Emoji Draw is a lightweight frontend library that renders Unicode flag emojis as hand-drawn Rough.js-style Canvas images. The core drawing logic is written in TypeScript and built with Rslib into ESM, CommonJS, and IIFE outputs. Rough.js is bundled with the library, so you can use it after install or by referencing the build artifacts—no extra CDN is required.
6
+
7
+ ## Features
8
+
9
+ - Draw Unicode flag emojis onto a given `canvas`.
10
+ - Hand-drawn templates for common flags such as China, Japan, the United States, Australia, Thailand, France, Italy, Spain, and Vatican City.
11
+ - A unified fallback pipeline via emoji rasterization and pixel sampling for flags without dedicated templates.
12
+ - Three integration paths: npm `import` / Node `require`, and browser `<script>` with the global `window.RoughEmoji`.
13
+ - TypeScript declaration files for API autocomplete in TS projects.
14
+ - An `index.html` batch QA page to visually inspect 240+ country/region flags.
15
+
16
+ ## Tech Stack
17
+
18
+ - TypeScript
19
+ - DOM Canvas
20
+ - Rough.js
21
+ - Rslib
22
+
23
+ ## Requirements
24
+
25
+ - Node.js 20 or later (use `.nvmrc`: `nvm use`)
26
+ - [pnpm](https://pnpm.io/) 9 or later (recommended via Corepack: `corepack enable`)
27
+
28
+ ## Quick Start
29
+
30
+ Install dependencies:
31
+
32
+ ```bash
33
+ pnpm install
34
+ ```
35
+
36
+ Run type checking:
37
+
38
+ ```bash
39
+ pnpm run typecheck
40
+ ```
41
+
42
+ Build artifacts:
43
+
44
+ ```bash
45
+ pnpm run build
46
+ ```
47
+
48
+ The build produces:
49
+
50
+ | File | Format | Purpose |
51
+ | --- | --- | --- |
52
+ | `dist/index.js` | ESM | `import` |
53
+ | `dist/index.cjs` | CJS | Node.js `require()` |
54
+ | `dist/index.d.ts` | Types | TypeScript entry |
55
+ | `dist/rough-emoji.js` | IIFE (minified) | Browser `<script>` tag |
56
+
57
+ Preview the QA page locally (do not open HTML via `file://`; browsers block local JS):
58
+
59
+ ```bash
60
+ pnpm run dev
61
+ ```
62
+
63
+ Then open [http://localhost:3000/](http://localhost:3000/) in your browser.
64
+
65
+ ## Usage
66
+
67
+ ### npm package (ESM)
68
+
69
+ ```ts
70
+ import { RoughEmoji } from "rough-emoji-draw";
71
+
72
+ const canvas = document.querySelector<HTMLCanvasElement>("#flag-canvas")!;
73
+ RoughEmoji.draw(canvas, "🇨🇳");
74
+ ```
75
+
76
+ ### npm package (CommonJS / Node)
77
+
78
+ ```js
79
+ const { RoughEmoji } = require("rough-emoji-draw");
80
+
81
+ console.log(typeof RoughEmoji.draw); // "function"
82
+ ```
83
+
84
+ > Drawing requires a Canvas and DOM environment. The API loads fine on Node, but `draw` must run in a browser, jsdom, `node-canvas`, or another Canvas-capable runtime.
85
+
86
+ ### Browser `<script>` tag
87
+
88
+ Load the IIFE bundle only; it automatically attaches `window.RoughEmoji`:
89
+
90
+ ```html
91
+ <script src="./dist/rough-emoji.js"></script>
92
+ <canvas id="flag-canvas" width="720" height="720"></canvas>
93
+ <script>
94
+ const canvas = document.querySelector("#flag-canvas");
95
+ window.RoughEmoji.draw(canvas, "🇨🇳");
96
+ </script>
97
+ ```
98
+
99
+ If the page includes the demo form DOM (`#rough-canvas`, `#emoji-form`, etc.), interaction and download handlers are wired up automatically.
100
+
101
+ ## API
102
+
103
+ ### `RoughEmoji.draw(canvasElement, value)`
104
+
105
+ Normalizes the input to a flag emoji and draws it on the given `HTMLCanvasElement`. Invalid input falls back to the China flag.
106
+
107
+ ### `RoughEmoji.isFlagEmoji(value)`
108
+
109
+ Returns whether the string is a flag emoji composed of two regional indicator symbols.
110
+
111
+ ### `RoughEmoji.resolveFlag(value)`
112
+
113
+ Converts arbitrary input into a drawable flag emoji. Only valid flag emojis are accepted; invalid values fall back to `🇨🇳`.
114
+
115
+ ### Type exports
116
+
117
+ ```ts
118
+ import type { RoughEmojiApi } from "rough-emoji-draw";
119
+ ```
120
+
121
+ You can also import `RoughOptions`, `Point`, `RoughCanvasLike`, and the demo page helper `RoughEmojiApp` as needed.
122
+
123
+ ## Project Structure
124
+
125
+ ```text
126
+ .
127
+ ├── src/
128
+ │ ├── index.ts # npm library entry; exports API and types
129
+ │ ├── browser.ts # browser IIFE entry; mounts window.RoughEmoji
130
+ │ ├── rough-emoji.ts # core drawing logic
131
+ │ ├── rough-emoji-app.ts # single-page demo DOM bindings
132
+ │ ├── flag-utils.ts # flag emoji parsing and validation
133
+ │ ├── render-context.ts # canvas context switching
134
+ │ ├── constant.ts # static constants and template map
135
+ │ └── types.ts # public type declarations
136
+ ├── index.html # batch visual QA page
137
+ ├── rslib.config.ts # Rslib multi-format build config
138
+ ├── tsconfig.json # TypeScript config
139
+ └── package.json # scripts, dependencies, and exports
140
+ ```
141
+
142
+ ## Development Notes
143
+
144
+ - Add new flags in `src/rough-emoji.ts` with dedicated draw functions and register them in the template dispatch table.
145
+ - Draw functions use a square canvas coordinate system; derive new coordinates from `size` or existing flag layout variables.
146
+ - After changing drawing behavior, run `pnpm run typecheck`, then `pnpm run build`, and inspect results in `index.html`.
147
+ - `dist/` is build output and is usually not maintained as source; run `pnpm run build` before publishing or local preview.
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Rough Emoji Draw
2
2
 
3
+ [English README](./README.en.md)
4
+
3
5
  Rough Emoji Draw 是一个把 Unicode 国旗 emoji 绘制成 Rough.js 手写风格 Canvas 图像的轻量前端库。项目使用 TypeScript 编写核心绘制逻辑,通过 Rslib 同时输出 ESM、CommonJS 与 IIFE 产物;Rough.js 会随库一并打包,安装或引用构建产物即可使用,无需额外引入 CDN。
4
6
 
5
7
  ## 功能特性
package/package.json CHANGED
@@ -1,7 +1,19 @@
1
1
  {
2
2
  "name": "rough-emoji-draw",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "将 Unicode 国旗 emoji 绘制成 Rough.js 手写风格 Canvas 图像的轻量前端库",
5
+ "author": {
6
+ "name": "SHUAXINDIARY",
7
+ "url": "https://github.com/SHUAXINDIARY"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/SHUAXINDIARY/national-flag-svg.git"
12
+ },
13
+ "homepage": "https://github.com/SHUAXINDIARY/national-flag-svg#readme",
14
+ "bugs": {
15
+ "url": "https://github.com/SHUAXINDIARY/national-flag-svg/issues"
16
+ },
5
17
  "type": "module",
6
18
  "main": "./dist/index.cjs",
7
19
  "module": "./dist/index.js",