@bastiangx/opencode-unmoji 0.1.0

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 (44) hide show
  1. package/LICENSE +13 -0
  2. package/README.md +116 -0
  3. package/dist/core/config.d.ts +22 -0
  4. package/dist/core/config.d.ts.map +1 -0
  5. package/dist/core/config.js +82 -0
  6. package/dist/core/config.js.map +1 -0
  7. package/dist/core/emoji-data-generated.d.ts +6 -0
  8. package/dist/core/emoji-data-generated.d.ts.map +1 -0
  9. package/dist/core/emoji-data-generated.js +28363 -0
  10. package/dist/core/emoji-data-generated.js.map +1 -0
  11. package/dist/core/emoji-data.d.ts +8 -0
  12. package/dist/core/emoji-data.d.ts.map +1 -0
  13. package/dist/core/emoji-data.js +61 -0
  14. package/dist/core/emoji-data.js.map +1 -0
  15. package/dist/core/processor.d.ts +5 -0
  16. package/dist/core/processor.d.ts.map +1 -0
  17. package/dist/core/processor.js +60 -0
  18. package/dist/core/processor.js.map +1 -0
  19. package/dist/index.d.ts +3 -0
  20. package/dist/index.d.ts.map +1 -0
  21. package/dist/index.js +21 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/plugin.bundled.js +51559 -0
  24. package/dist/types/config.d.ts +36 -0
  25. package/dist/types/config.d.ts.map +1 -0
  26. package/dist/types/config.js +24 -0
  27. package/dist/types/config.js.map +1 -0
  28. package/dist/types/errors.d.ts +59 -0
  29. package/dist/types/errors.d.ts.map +1 -0
  30. package/dist/types/errors.js +6 -0
  31. package/dist/types/errors.js.map +1 -0
  32. package/dist/utils/code-detector.d.ts +17 -0
  33. package/dist/utils/code-detector.d.ts.map +1 -0
  34. package/dist/utils/code-detector.js +252 -0
  35. package/dist/utils/code-detector.js.map +1 -0
  36. package/dist/utils/debug.d.ts +18 -0
  37. package/dist/utils/debug.d.ts.map +1 -0
  38. package/dist/utils/debug.js +10 -0
  39. package/dist/utils/debug.js.map +1 -0
  40. package/dist/utils/grapheme.d.ts +20 -0
  41. package/dist/utils/grapheme.d.ts.map +1 -0
  42. package/dist/utils/grapheme.js +64 -0
  43. package/dist/utils/grapheme.js.map +1 -0
  44. package/package.json +59 -0
@@ -0,0 +1,8 @@
1
+ import { type Result } from "neverthrow";
2
+ import type { EmojiDataError } from "../types/errors.js";
3
+ export type ReplacementStyle = "github" | "slack" | "discord" | "cldr" | "iamcal" | "joypixels";
4
+ export declare function getEmojiSetSync(): Result<Set<string>, EmojiDataError>;
5
+ export declare function getEmojiMapSync(replacementStyle: ReplacementStyle): Result<Map<string, string>, EmojiDataError>;
6
+ export declare function getEmojiShortcode(emoji: string, map: Map<string, string>): string | null;
7
+ export declare function getReplacement(emoji: string, format: ":name:" | "[:name:]" | "{name}", map: Map<string, string>): string;
8
+ //# sourceMappingURL=emoji-data.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emoji-data.d.ts","sourceRoot":"","sources":["../../src/core/emoji-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAW,MAAM,YAAY,CAAC;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AASzD,MAAM,MAAM,gBAAgB,GACzB,QAAQ,GACR,OAAO,GACP,SAAS,GACT,MAAM,GACN,QAAQ,GACR,WAAW,CAAC;AAiBf,wBAAgB,eAAe,IAAI,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,cAAc,CAAC,CAQrE;AAED,wBAAgB,eAAe,CAC9B,gBAAgB,EAAE,gBAAgB,GAChC,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,cAAc,CAAC,CAoB7C;AAED,wBAAgB,iBAAiB,CAChC,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GACtB,MAAM,GAAG,IAAI,CAEf;AAaD,wBAAgB,cAAc,CAC7B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,QAAQ,GAAG,UAAU,GAAG,QAAQ,EACxC,GAAG,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GACtB,MAAM,CAIR"}
@@ -0,0 +1,61 @@
1
+ import { ok, err } from "neverthrow";
2
+ import { EMOJI_SET, EMOJI_MAP_CLDR, EMOJI_MAP_GITHUB, EMOJI_MAP_IAMCAL, EMOJI_MAP_JOYPIXELS, } from "./emoji-data-generated.js";
3
+ function _getShortcodePreset(style) {
4
+ if (style === "slack")
5
+ return "iamcal";
6
+ if (style === "discord")
7
+ return "joypixels";
8
+ return style;
9
+ }
10
+ const MAP_BY_PRESET = {
11
+ github: EMOJI_MAP_GITHUB,
12
+ cldr: EMOJI_MAP_CLDR,
13
+ iamcal: EMOJI_MAP_IAMCAL,
14
+ joypixels: EMOJI_MAP_JOYPIXELS,
15
+ };
16
+ export function getEmojiSetSync() {
17
+ if (EMOJI_SET.size === 0) {
18
+ return err({
19
+ domain: "emoji-data",
20
+ code: "EMPTY_DATASET",
21
+ });
22
+ }
23
+ return ok(EMOJI_SET);
24
+ }
25
+ export function getEmojiMapSync(replacementStyle) {
26
+ const preset = _getShortcodePreset(replacementStyle);
27
+ const map = MAP_BY_PRESET[preset];
28
+ if (!map) {
29
+ return err({
30
+ domain: "emoji-data",
31
+ code: "INVALID_DATA",
32
+ details: `Missing shortcode map for preset ${preset}`,
33
+ });
34
+ }
35
+ if (map.size === 0) {
36
+ return err({
37
+ domain: "emoji-data",
38
+ code: "EMPTY_DATASET",
39
+ });
40
+ }
41
+ return ok(map);
42
+ }
43
+ export function getEmojiShortcode(emoji, map) {
44
+ return map.get(emoji) ?? null;
45
+ }
46
+ function generateHexFallback(emoji) {
47
+ const codepoints = [];
48
+ for (const ch of emoji) {
49
+ const cp = ch.codePointAt(0);
50
+ if (cp !== undefined) {
51
+ codepoints.push(`u${cp.toString(16).padStart(4, "0")}`);
52
+ }
53
+ }
54
+ return `emoji_${codepoints.join("_")}`;
55
+ }
56
+ export function getReplacement(emoji, format, map) {
57
+ const shortcode = getEmojiShortcode(emoji, map);
58
+ const name = shortcode ?? generateHexFallback(emoji);
59
+ return format.replace("name", name);
60
+ }
61
+ //# sourceMappingURL=emoji-data.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emoji-data.js","sourceRoot":"","sources":["../../src/core/emoji-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,EAAE,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAElD,OAAO,EACN,SAAS,EACT,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,GACnB,MAAM,2BAA2B,CAAC;AAYnC,SAAS,mBAAmB,CAAC,KAAuB;IACnD,IAAI,KAAK,KAAK,OAAO;QAAE,OAAO,QAAQ,CAAC;IACvC,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,WAAW,CAAC;IAC5C,OAAO,KAAK,CAAC;AACd,CAAC;AAED,MAAM,aAAa,GAAiD;IACnE,MAAM,EAAE,gBAAgB;IACxB,IAAI,EAAE,cAAc;IACpB,MAAM,EAAE,gBAAgB;IACxB,SAAS,EAAE,mBAAmB;CACrB,CAAC;AAEX,MAAM,UAAU,eAAe;IAC9B,IAAI,SAAS,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO,GAAG,CAAC;YACV,MAAM,EAAE,YAAqB;YAC7B,IAAI,EAAE,eAAwB;SAC9B,CAAC,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,CAAC,SAAS,CAAC,CAAC;AACtB,CAAC;AAED,MAAM,UAAU,eAAe,CAC9B,gBAAkC;IAElC,MAAM,MAAM,GAAG,mBAAmB,CAAC,gBAAgB,CAAC,CAAC;IACrD,MAAM,GAAG,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;IAElC,IAAI,CAAC,GAAG,EAAE,CAAC;QACV,OAAO,GAAG,CAAC;YACV,MAAM,EAAE,YAAqB;YAC7B,IAAI,EAAE,cAAuB;YAC7B,OAAO,EAAE,oCAAoC,MAAM,EAAE;SACrD,CAAC,CAAC;IACJ,CAAC;IAED,IAAI,GAAG,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;QACpB,OAAO,GAAG,CAAC;YACV,MAAM,EAAE,YAAqB;YAC7B,IAAI,EAAE,eAAwB;SAC9B,CAAC,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,iBAAiB,CAChC,KAAa,EACb,GAAwB;IAExB,OAAO,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC;AAC/B,CAAC;AAED,SAAS,mBAAmB,CAAC,KAAa;IACzC,MAAM,UAAU,GAAa,EAAE,CAAC;IAChC,KAAK,MAAM,EAAE,IAAI,KAAK,EAAE,CAAC;QACxB,MAAM,EAAE,GAAG,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;QAC7B,IAAI,EAAE,KAAK,SAAS,EAAE,CAAC;YACtB,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;QACzD,CAAC;IACF,CAAC;IACD,OAAO,SAAS,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;AACxC,CAAC;AAED,MAAM,UAAU,cAAc,CAC7B,KAAa,EACb,MAAwC,EACxC,GAAwB;IAExB,MAAM,SAAS,GAAG,iBAAiB,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAChD,MAAM,IAAI,GAAG,SAAS,IAAI,mBAAmB,CAAC,KAAK,CAAC,CAAC;IACrD,OAAO,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AACrC,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { UnmojiConfig } from "../types/config.js";
2
+ import type { Result } from "neverthrow";
3
+ import type { ProcessingError } from "../types/errors.js";
4
+ export declare function processText(text: string, config: UnmojiConfig): Result<string, ProcessingError>;
5
+ //# sourceMappingURL=processor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"processor.d.ts","sourceRoot":"","sources":["../../src/core/processor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAe1D,wBAAgB,WAAW,CAC1B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,YAAY,GAClB,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAmEjC"}
@@ -0,0 +1,60 @@
1
+ import { ok, err } from "neverthrow";
2
+ import { detectCodeBlocks, detectQuotes, mergeRanges, isInPreservedRange, } from "../utils/code-detector.js";
3
+ import { graphemes, mightContainEmoji } from "../utils/grapheme.js";
4
+ import { getEmojiSetSync, getEmojiMapSync, getReplacement, } from "./emoji-data.js";
5
+ export function processText(text, config) {
6
+ if (!text || !mightContainEmoji(text)) {
7
+ return ok(text);
8
+ }
9
+ const emojiSetResult = getEmojiSetSync();
10
+ if (emojiSetResult.isErr()) {
11
+ return err({
12
+ domain: "processing",
13
+ code: "EMOJI_DATA_UNAVAILABLE",
14
+ cause: emojiSetResult.error,
15
+ });
16
+ }
17
+ const emojiSet = emojiSetResult.value;
18
+ let emojiMap = null;
19
+ if (config.mode === "replace") {
20
+ const style = config.replacementStyle || "github";
21
+ const emojiMapResult = getEmojiMapSync(style);
22
+ if (emojiMapResult.isErr()) {
23
+ return err({
24
+ domain: "processing",
25
+ code: "EMOJI_DATA_UNAVAILABLE",
26
+ cause: emojiMapResult.error,
27
+ });
28
+ }
29
+ emojiMap = emojiMapResult.value;
30
+ }
31
+ const codeRanges = detectCodeBlocks(text, {
32
+ preserveCodeBlocks: config.preserveCodeBlocks,
33
+ preserveInlineCode: config.preserveInlineCode,
34
+ });
35
+ const quoteRanges = detectQuotes(text, {
36
+ preserveBlockquotes: config.skipQuotes,
37
+ preserveInlineQuotes: config.skipQuotes,
38
+ });
39
+ const preservedRanges = mergeRanges([codeRanges, quoteRanges]);
40
+ const chunks = [];
41
+ let currentIndex = 0;
42
+ for (const grapheme of graphemes(text)) {
43
+ const graphemeLength = grapheme.length;
44
+ const inPreserved = isInPreservedRange(currentIndex, preservedRanges);
45
+ if (inPreserved || !emojiSet.has(grapheme)) {
46
+ chunks.push(grapheme);
47
+ }
48
+ else {
49
+ if (config.mode === "replace" && emojiMap) {
50
+ const format = config.replacementFormat;
51
+ const replacement = getReplacement(grapheme, format, emojiMap);
52
+ chunks.push(replacement);
53
+ }
54
+ }
55
+ // else: strip mode, skip emoji (push nothing)
56
+ currentIndex += graphemeLength;
57
+ }
58
+ return ok(chunks.join(""));
59
+ }
60
+ //# sourceMappingURL=processor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"processor.js","sourceRoot":"","sources":["../../src/core/processor.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EACN,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACX,kBAAkB,GAClB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,EACN,eAAe,EACf,eAAe,EACf,cAAc,GACd,MAAM,iBAAiB,CAAC;AAEzB,MAAM,UAAU,WAAW,CAC1B,IAAY,EACZ,MAAoB;IAEpB,IAAI,CAAC,IAAI,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,EAAE,CAAC;QACvC,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC;IACjB,CAAC;IAED,MAAM,cAAc,GAAG,eAAe,EAAE,CAAC;IAEzC,IAAI,cAAc,CAAC,KAAK,EAAE,EAAE,CAAC;QAC5B,OAAO,GAAG,CAAC;YACV,MAAM,EAA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eAAe,CAAC,CAAC;QAEtE,IAAI,WAAW,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC5C,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACvB,CAAC;aAAM,CAAC;YACP,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS,IAAI,QAAQ,EAAE,CAAC;gBAC3C,MAAM,MAAM,GAAG,MAAM,CAAC,iBAAiB,CAAC;gBACxC,MAAM,WAAW,GAAG,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;gBAC/D,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YAC1B,CAAC;QACF,CAAC;QACD,8CAA8C;QAE9C,YAAY,IAAI,cAAc,CAAC;IAChC,CAAC;IAED,OAAO,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;AAC5B,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from "@opencode-ai/plugin";
2
+ export declare const Unmoji: Plugin;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAS,MAAM,qBAAqB,CAAC;AAIzD,eAAO,MAAM,MAAM,EAAE,MAsBpB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,21 @@
1
+ import { loadConfig } from "./core/config.js";
2
+ import { processText } from "./core/processor.js";
3
+ export const Unmoji = async () => {
4
+ const configResult = loadConfig(process.cwd());
5
+ if (configResult.isErr()) {
6
+ return {};
7
+ }
8
+ const config = configResult.value;
9
+ if (!config.enabled) {
10
+ return {};
11
+ }
12
+ return {
13
+ "experimental.text.complete": async (_input, output) => {
14
+ const result = processText(output.text, config);
15
+ if (result.isOk()) {
16
+ output.text = result.value;
17
+ }
18
+ },
19
+ };
20
+ };
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElD,MAAM,CAAC,MAAM,MAAM,GAAW,KAAK,IAAI,EAAE;IACxC,MAAM,YAAY,GAAG,UAAU,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAE/C,IAAI,YAAY,CAAC,KAAK,EAAE,EAAE,CAAC;QAC1B,OAAO,EAAW,CAAC;IACpB,CAAC;IAED,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK,CAAC;IAElC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACrB,OAAO,EAAW,CAAC;IACpB,CAAC;IAED,OAAO;QACN,4BAA4B,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE;YACtD,MAAM,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YAEhD,IAAI,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;gBACnB,MAAM,CAAC,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC;YAC5B,CAAC;QACF,CAAC;KACQ,CAAC;AACZ,CAAC,CAAC"}