millirec 0.1.1 → 0.2.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 (89) hide show
  1. package/CHANGELOG.md +101 -0
  2. package/README.md +286 -51
  3. package/dist/char-cnn/cnn-web.wasm +0 -0
  4. package/dist/char-cnn/core.d.ts +15 -1
  5. package/dist/char-cnn/core.js +214 -100
  6. package/dist/char-cnn/index.d.ts +1 -1
  7. package/dist/char-cnn/index.js +267 -137
  8. package/dist/char-cnn/millirec-char-cnn-core.min.js +1 -1
  9. package/dist/char-cnn/millirec-char-cnn.min.js +1 -1
  10. package/dist/char-cnn/options/accurate/tiny.head.bin +0 -0
  11. package/dist/char-cnn/options/accurate.js +6 -6
  12. package/dist/char-cnn/options/accurate.json +5 -5
  13. package/dist/char-cnn/options/all/all-base.head.bin +0 -0
  14. package/dist/char-cnn/options/all/all-base.q4.bin +0 -0
  15. package/dist/char-cnn/options/all/all-tiny.bin +0 -0
  16. package/dist/char-cnn/options/all/all-tiny.head.bin +0 -0
  17. package/dist/char-cnn/options/all-fast/all-base-p25.bin +0 -0
  18. package/dist/char-cnn/options/all-fast/all-base-p25.head.bin +0 -0
  19. package/dist/char-cnn/options/all-fast/all-tiny.bin +0 -0
  20. package/dist/char-cnn/options/all-fast/all-tiny.head.bin +0 -0
  21. package/dist/char-cnn/options/all-fast.js +17 -0
  22. package/dist/char-cnn/options/all-fast.json +15 -0
  23. package/dist/char-cnn/options/all-small/all-tiny-qat4.head.bin +0 -0
  24. package/dist/char-cnn/options/all-small/all-tiny-qat4.q4.bin +0 -0
  25. package/dist/char-cnn/options/all-small.js +11 -0
  26. package/dist/char-cnn/options/all-small.json +9 -0
  27. package/dist/char-cnn/options/all.js +17 -0
  28. package/dist/char-cnn/options/all.json +15 -0
  29. package/dist/char-cnn/options/digits/digits-base.head.bin +0 -0
  30. package/dist/char-cnn/options/digits/digits-base.q4.bin +0 -0
  31. package/dist/char-cnn/options/digits/digits-tiny.bin +0 -0
  32. package/dist/char-cnn/options/digits/digits-tiny.head.bin +0 -0
  33. package/dist/char-cnn/options/digits-fast/digits-base-p25.bin +0 -0
  34. package/dist/char-cnn/options/digits-fast/digits-base-p25.head.bin +0 -0
  35. package/dist/char-cnn/options/digits-fast/digits-tiny.bin +0 -0
  36. package/dist/char-cnn/options/digits-fast/digits-tiny.head.bin +0 -0
  37. package/dist/char-cnn/options/digits-fast.js +17 -0
  38. package/dist/char-cnn/options/digits-fast.json +15 -0
  39. package/dist/char-cnn/options/digits-small/digits-tiny-qat4.head.bin +0 -0
  40. package/dist/char-cnn/options/digits-small/digits-tiny-qat4.q4.bin +0 -0
  41. package/dist/char-cnn/options/digits-small.js +11 -0
  42. package/dist/char-cnn/options/digits-small.json +9 -0
  43. package/dist/char-cnn/options/digits.js +17 -0
  44. package/dist/char-cnn/options/digits.json +15 -0
  45. package/dist/char-cnn/options/fast/base-p25.head.bin +0 -0
  46. package/dist/char-cnn/options/fast/tiny.bin +0 -0
  47. package/dist/char-cnn/options/fast/tiny.head.bin +0 -0
  48. package/dist/char-cnn/options/fast.js +6 -6
  49. package/dist/char-cnn/options/fast.json +5 -5
  50. package/dist/char-cnn/options/lowercase/lowercase-base.head.bin +0 -0
  51. package/dist/char-cnn/options/lowercase/lowercase-base.q4.bin +0 -0
  52. package/dist/char-cnn/options/lowercase/lowercase-tiny.bin +0 -0
  53. package/dist/char-cnn/options/lowercase/lowercase-tiny.head.bin +0 -0
  54. package/dist/char-cnn/options/lowercase-fast/lowercase-base-p25.bin +0 -0
  55. package/dist/char-cnn/options/lowercase-fast/lowercase-base-p25.head.bin +0 -0
  56. package/dist/char-cnn/options/lowercase-fast/lowercase-tiny.bin +0 -0
  57. package/dist/char-cnn/options/lowercase-fast/lowercase-tiny.head.bin +0 -0
  58. package/dist/char-cnn/options/lowercase-fast.js +17 -0
  59. package/dist/char-cnn/options/lowercase-fast.json +15 -0
  60. package/dist/char-cnn/options/lowercase-small/lowercase-tiny-qat4.head.bin +0 -0
  61. package/dist/char-cnn/options/lowercase-small/lowercase-tiny-qat4.q4.bin +0 -0
  62. package/dist/char-cnn/options/lowercase-small.js +11 -0
  63. package/dist/char-cnn/options/lowercase-small.json +9 -0
  64. package/dist/char-cnn/options/lowercase.js +17 -0
  65. package/dist/char-cnn/options/lowercase.json +15 -0
  66. package/dist/char-cnn/options/small/tiny.head.bin +0 -0
  67. package/dist/char-cnn/options/small/tiny.q4.bin +0 -0
  68. package/dist/char-cnn/options/small.js +3 -3
  69. package/dist/char-cnn/options/small.json +2 -2
  70. package/dist/char-lite/core.d.ts +1 -0
  71. package/dist/char-lite/core.js +628 -0
  72. package/dist/char-lite/index.d.ts +28 -8
  73. package/dist/char-lite/index.js +459 -297
  74. package/dist/char-lite/millirec-char-lite.min.js +1 -1
  75. package/dist/char-lite/millirec.wasm +0 -0
  76. package/dist/char-lite/sets.json +25 -29
  77. package/dist/index.d.ts +35 -0
  78. package/dist/index.js +88 -0
  79. package/dist/overlap/millirec-overlap.min.js +7 -7
  80. package/dist/overlap/millirec.wasm +0 -0
  81. package/dist/pad/index.d.ts +8 -0
  82. package/dist/pad/index.js +482 -0
  83. package/package.json +30 -8
  84. package/dist/char-cnn/base-p25.head.bin +0 -0
  85. package/dist/char-cnn/tiny.head.bin +0 -0
  86. /package/dist/char-cnn/{base.head.bin → options/accurate/base.head.bin} +0 -0
  87. /package/dist/char-cnn/{base.q4.bin → options/accurate/base.q4.bin} +0 -0
  88. /package/dist/char-cnn/{tiny.bin → options/accurate/tiny.bin} +0 -0
  89. /package/dist/char-cnn/{base-p25.bin → options/fast/base-p25.bin} +0 -0
@@ -30,6 +30,8 @@ export interface CreateOptions {
30
30
  }
31
31
 
32
32
  export interface AttachOptions {
33
+ /** Passed to every recognize() the pad makes, e.g. { only: '0123456789' }. */
34
+ recognizeOptions?: { only?: string | string[] | Set<string> }
33
35
  /** Pad size in CSS px (default 240 x 240). */
34
36
  width?: number
35
37
  height?: number
@@ -77,23 +79,41 @@ export type SetName = (typeof SETS)[number]
77
79
  /** Fetch a shipped training set. */
78
80
  export declare function loadSet(name: SetName, opts?: { assetBase?: string }): Promise<Training>
79
81
 
80
- export declare class MillirecCharLite {
81
- static create(opts: CreateOptions): Promise<MillirecCharLite>
82
+ /** What recognize() can be restricted to: a string of one-character classes, or a list/Set of class names. */
83
+ export type Only = string | string[] | Set<string>
84
+
85
+ export declare class MillirecCharLiteCore {
86
+ static create(opts: CreateOptions): Promise<MillirecCharLiteCore>
82
87
  /** Strokes → one sample. Pass the set's pointsPerShape (shipped sets: 25). */
83
88
  static strokesToSample(strokes: Strokes | Stroke, pointsPerShape?: number): Sample | null
84
89
  /** A copy of `training` with your own drawings added per class (new classes allowed). */
85
90
  static withSamples(training: Training | Record<string, Sample[]>, extra: Record<string, Array<Strokes | Stroke | Sample>>, opts?: { replace?: boolean }): Training
86
- static createDrawCanvas(opts?: object): unknown
91
+ readonly engine: 'char-lite'
92
+ /** The training set's classes (teach() does not change them; it returns the taught names). */
93
+ readonly classes: string[]
87
94
  readonly charList: string[]
88
95
  readonly ready: Promise<void>
89
- /** null for an empty drawing, and after destroy(). */
90
- recognize(strokes: Strokes | Stroke): Promise<Reading[] | null>
96
+ /** null for an empty drawing, and after destroy(). `only` answers among those classes alone, scoring every template
97
+ * exactly — slower, and its runner-ups can differ from a plain recognize()'s (the first answer does not); plugins'
98
+ * rerank does not run. Fewer than three readings when fewer classes are possible. */
99
+ recognize(strokes: Strokes | Stroke, opts?: { only?: Only }): Promise<Reading[] | null>
91
100
  /** Raw per-template costs: costs[i] holds one cost per training sample of classes[i] (lower is closer). */
92
101
  rawScores(strokes: Strokes | Stroke): Promise<{ classes: string[]; costs: number[][] } | null>
102
+ /** Read symbols of your own from a few drawings each: recognize() then answers among the taught names only.
103
+ * `{ add: true }` keeps what was taught before. null when no drawing was usable. To ADD symbols to the
104
+ * training set instead, build it with withSamples(). */
105
+ teach(examples: Record<string, Array<Strokes | Stroke>>, opts?: { add?: boolean }): Promise<{ classes: string[]; n: number } | null>
106
+ /** Drop what teach() learned. */
107
+ forget(): void
93
108
  use(plugin: { rerank?: (out: unknown, ctx: unknown) => unknown }): this
94
- /** Mount a drawing pad in `el`; `el` then fires 'millirec:result' and 'millirec:clear'. */
95
- attach(el: HTMLElement, opts?: AttachOptions): Pad
96
- /** Stop the instance's Worker (each instance holds one, plus a wasm matcher). Pending and later
109
+ /** Stop the instance's Workers (one, plus one while something is taught). Pending and later
97
110
  * recognize()/rawScores() calls resolve null. */
98
111
  destroy(): void
99
112
  }
113
+
114
+ export declare class MillirecCharLite extends MillirecCharLiteCore {
115
+ static create(opts: CreateOptions): Promise<MillirecCharLite>
116
+ static createDrawCanvas(opts?: object): unknown
117
+ /** Mount a drawing pad in `el`; `el` then fires 'millirec:result' and 'millirec:clear'. */
118
+ attach(el: HTMLElement, opts?: AttachOptions): Pad
119
+ }