text-input-guard 0.1.6 → 0.2.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.
@@ -288,6 +288,26 @@ class SwapState {
288
288
  * @property {any} [detail] - 追加情報(制限値など)
289
289
  */
290
290
 
291
+ /**
292
+ * バリデーションがどの評価タイミングから呼び出されたかを表す識別子
293
+ *
294
+ * - "input" : 入力中の評価(inputイベントなど)
295
+ * - "commit" : 確定時の評価(blurなど)
296
+ *
297
+ * @typedef {"input"|"commit"} ValidateSource
298
+ */
299
+
300
+ /**
301
+ * バリデーション結果を表すオブジェクト
302
+ * - 各ルールの評価が完了したタイミングでコールバックに渡される
303
+ *
304
+ * @typedef {Object} ValidateResult
305
+ * @property {Guard} guard - この結果を発生させた Guard インスタンス
306
+ * @property {ValidateSource} source - 評価が実行されたタイミング(input / commit)
307
+ * @property {TigError[]} errors - 発生したエラー一覧
308
+ * @property {boolean} isValid - エラーが存在しない場合は true
309
+ */
310
+
291
311
  /**
292
312
  * setValue で設定できる値型
293
313
  * - number は String に変換して設定する
@@ -378,8 +398,9 @@ class SwapState {
378
398
  * @typedef {Object} AttachOptions
379
399
  * @property {Rule[]} [rules] - 適用するルール配列(順番がフェーズ内実行順になる)
380
400
  * @property {boolean} [warn] - 非対応ルールなどを console.warn するか
381
- * @property {string} [invalidClass] - エラー時に付けるclass名
401
+ * @property {string} [invalidClass="is-invalid"] - エラー時に付けるclass名
382
402
  * @property {SeparateValueOptions} [separateValue] - 表示値と内部値の分離設定
403
+ * @property {(result: ValidateResult) => void} [onValidate] - 評価完了時の通知(input/commitごと)
383
404
  */
384
405
 
385
406
  /**
@@ -434,7 +455,7 @@ function warnLog(msg, warn) {
434
455
  function attach(element, options = {}) {
435
456
  const guard = new InputGuard(element, options);
436
457
  guard.init();
437
- return guard.toGuard();
458
+ return guard.getGuard();
438
459
  }
439
460
 
440
461
  /**
@@ -514,6 +535,12 @@ class InputGuard {
514
535
  */
515
536
  this.rules = Array.isArray(options.rules) ? options.rules : [];
516
537
 
538
+ /**
539
+ * attach時に登録されたバリデーション結果コールバック
540
+ * @type {(result: ValidateResult) => void | undefined}
541
+ */
542
+ this.onValidate = options.onValidate;
543
+
517
544
  /**
518
545
  * 実際に送信を担う要素(swap時は hidden(raw) 側)
519
546
  * swapしない場合は originalElement と同一
@@ -549,6 +576,12 @@ class InputGuard {
549
576
  */
550
577
  this.errors = [];
551
578
 
579
+ /**
580
+ * attach の返却値
581
+ * @type {Guard|null}
582
+ */
583
+ this._guard = null;
584
+
552
585
  // --------------------------------------------------
553
586
  // pipeline(フェーズごとのルール配列)
554
587
  // --------------------------------------------------
@@ -1018,6 +1051,31 @@ class InputGuard {
1018
1051
  this.errors = [];
1019
1052
  }
1020
1053
 
1054
+ /**
1055
+ * バリデーション結果をコールバックへ通知する
1056
+ *
1057
+ * - attach() の options.onValidate が指定されている場合のみ呼び出す
1058
+ * - evaluateInput / evaluateCommit の評価完了時に実行される
1059
+ * - エラーが存在しない場合でも呼び出される
1060
+ *
1061
+ * @param {ValidateSource} source - 評価が実行されたタイミング("input" | "commit")
1062
+ * @returns {void}
1063
+ */
1064
+ notifyValidate(source) {
1065
+ if (!this.onValidate) {
1066
+ return;
1067
+ }
1068
+
1069
+ const errors = this.getErrors();
1070
+
1071
+ this.onValidate({
1072
+ guard: this.getGuard(),
1073
+ source,
1074
+ errors,
1075
+ isValid: errors.length === 0
1076
+ });
1077
+ }
1078
+
1021
1079
  /**
1022
1080
  * normalize.char フェーズを実行する(文字の正規化)
1023
1081
  * @param {string} value
@@ -1387,6 +1445,9 @@ class InputGuard {
1387
1445
  // 受理値は常にrawとして保存(revert先・getRawValueの一貫性)
1388
1446
  this.lastAcceptedValue = raw;
1389
1447
  this.lastAcceptedSelection = this.readSelection(display);
1448
+
1449
+ // コールバック関数処理
1450
+ this.notifyValidate("input");
1390
1451
  }
1391
1452
 
1392
1453
  /**
@@ -1451,6 +1512,9 @@ class InputGuard {
1451
1512
  // 8) 受理値は raw を保持(revertやgetRawValueが安定する)
1452
1513
  this.lastAcceptedValue = raw;
1453
1514
  this.lastAcceptedSelection = this.readSelection(display);
1515
+
1516
+ // コールバック関数処理
1517
+ this.notifyValidate("commit");
1454
1518
  }
1455
1519
 
1456
1520
  /**
@@ -1526,8 +1590,13 @@ class InputGuard {
1526
1590
  * - InputGuard 自体を公開せず、最小の操作だけを渡す
1527
1591
  * @returns {Guard}
1528
1592
  */
1529
- toGuard() {
1530
- return {
1593
+ getGuard() {
1594
+ if (this._guard) {
1595
+ return this._guard;
1596
+ }
1597
+
1598
+ // ここで “this” を閉じ込めた関数群を一度だけ作る
1599
+ this._guard = {
1531
1600
  detach: () => this.detach(),
1532
1601
  isValid: () => this.isValid(),
1533
1602
  getErrors: () => this.getErrors(),
@@ -1539,6 +1608,8 @@ class InputGuard {
1539
1608
  commit: () => this.evaluateCommit(),
1540
1609
  setValue: (value, mode) => this.setValue(value, mode)
1541
1610
  };
1611
+
1612
+ return this._guard;
1542
1613
  }
1543
1614
  }
1544
1615
 
@@ -2168,8 +2239,8 @@ numeric.fromDataset = function fromDataset(dataset, _el) {
2168
2239
  * @property {boolean} [countLeadingZeros=true] - 整数部の先頭ゼロを桁数に含める
2169
2240
  * @property {"none"|"truncateLeft"|"truncateRight"|"clamp"} [fixIntOnBlur="none"] - blur時の整数部補正
2170
2241
  * @property {"none"|"truncate"|"round"} [fixFracOnBlur="none"] - blur時の小数部補正
2171
- * @property {"none"|"block"} [overflowInputInt="none"] - 入力中:整数部が最大桁を超える入力をブロックする
2172
- * @property {"none"|"block"} [overflowInputFrac="none"] - 入力中:小数部が最大桁を超える入力をブロックする
2242
+ * @property {"block"|"error"} [modeInt="block"] - 整数部が最大桁を超える入力の挙動
2243
+ * @property {"block"|"error"} [modeFrac="block"] - 小数部が最大桁を超える入力の挙動
2173
2244
  * @property {boolean} [forceFracOnBlur=false] - blur時に小数部を必ず表示(frac桁まで0埋め)
2174
2245
  */
2175
2246
 
@@ -2311,8 +2382,8 @@ function digits(options = {}) {
2311
2382
  countLeadingZeros: options.countLeadingZeros ?? true,
2312
2383
  fixIntOnBlur: options.fixIntOnBlur ?? "none",
2313
2384
  fixFracOnBlur: options.fixFracOnBlur ?? "none",
2314
- overflowInputInt: options.overflowInputInt ?? "none",
2315
- overflowInputFrac: options.overflowInputFrac ?? "none",
2385
+ modeInt: options.modeInt ?? "block",
2386
+ modeFrac: options.modeFrac ?? "block",
2316
2387
  forceFracOnBlur: options.forceFracOnBlur ?? false
2317
2388
  };
2318
2389
 
@@ -2339,7 +2410,7 @@ function digits(options = {}) {
2339
2410
  const intDigits = countIntDigits(intPart, opt.countLeadingZeros);
2340
2411
  if (intDigits > opt.int) {
2341
2412
  // 入力ブロック(int)
2342
- if (opt.overflowInputInt === "block") {
2413
+ if (opt.modeInt === "block") {
2343
2414
  ctx.requestRevert({
2344
2415
  reason: "digits.int_overflow",
2345
2416
  detail: { limit: opt.int, actual: intDigits }
@@ -2362,7 +2433,7 @@ function digits(options = {}) {
2362
2433
  const fracDigits = (fracPart ?? "").length;
2363
2434
  if (fracDigits > opt.frac) {
2364
2435
  // 入力ブロック(frac)
2365
- if (opt.overflowInputFrac === "block") {
2436
+ if (opt.modeFrac === "block") {
2366
2437
  ctx.requestRevert({
2367
2438
  reason: "digits.frac_overflow",
2368
2439
  detail: { limit: opt.frac, actual: fracDigits }
@@ -2479,8 +2550,8 @@ function digits(options = {}) {
2479
2550
  * - data-tig-rules-digits-count-leading-zeros -> dataset.tigRulesDigitsCountLeadingZeros
2480
2551
  * - data-tig-rules-digits-fix-int-on-blur -> dataset.tigRulesDigitsFixIntOnBlur
2481
2552
  * - data-tig-rules-digits-fix-frac-on-blur -> dataset.tigRulesDigitsFixFracOnBlur
2482
- * - data-tig-rules-digits-overflow-input-int -> dataset.tigRulesDigitsOverflowInputInt
2483
- * - data-tig-rules-digits-overflow-input-frac -> dataset.tigRulesDigitsOverflowInputFrac
2553
+ * - data-tig-rules-digits-mode-int -> dataset.tigRulesDigitsModeInt
2554
+ * - data-tig-rules-digits-mode-frac -> dataset.tigRulesDigitsModeFrac
2484
2555
  * - data-tig-rules-digits-force-frac-on-blur -> dataset.tigRulesDigitsForceFracOnBlur
2485
2556
  *
2486
2557
  * @param {DOMStringMap} dataset
@@ -2533,15 +2604,15 @@ digits.fromDataset = function fromDataset(dataset, _el) {
2533
2604
  options.fixFracOnBlur = fixFrac;
2534
2605
  }
2535
2606
 
2536
- // overflowInputInt / overflowInputFrac
2537
- const ovInt = parseDatasetEnum(dataset.tigRulesDigitsOverflowInputInt, ["none", "block"]);
2538
- if (ovInt != null) {
2539
- options.overflowInputInt = ovInt;
2607
+ // modeInt / modeFrac
2608
+ const modeInt = parseDatasetEnum(dataset.tigRulesDigitsModeInt, ["block", "error"]);
2609
+ if (modeInt != null) {
2610
+ options.modeInt = modeInt;
2540
2611
  }
2541
2612
 
2542
- const ovFrac = parseDatasetEnum(dataset.tigRulesDigitsOverflowInputFrac, ["none", "block"]);
2543
- if (ovFrac != null) {
2544
- options.overflowInputFrac = ovFrac;
2613
+ const modeFrac = parseDatasetEnum(dataset.tigRulesDigitsModeFrac, ["block", "error"]);
2614
+ if (modeFrac != null) {
2615
+ options.modeFrac = modeFrac;
2545
2616
  }
2546
2617
 
2547
2618
  // forceFracOnBlur
@@ -2630,6 +2701,104 @@ comma.fromDataset = function fromDataset(dataset, _el) {
2630
2701
  return comma();
2631
2702
  };
2632
2703
 
2704
+ /**
2705
+ * The script is part of TextInputGuard.
2706
+ *
2707
+ * AUTHOR:
2708
+ * natade-jp (https://github.com/natade-jp)
2709
+ *
2710
+ * LICENSE:
2711
+ * The MIT license https://opensource.org/licenses/MIT
2712
+ */
2713
+
2714
+ /**
2715
+ * IMEオフ入力相当の文字変換テーブル
2716
+ * @type {Record<string, string>}
2717
+ */
2718
+ /* eslint-disable quote-props */
2719
+ const IME_OFF_MAP = {
2720
+ "\u3000": "\u0020", // 全角スペース → space
2721
+ "\u3001": "\u002C", // 、 → ,
2722
+ "\u3002": "\u002E", // 。 → .
2723
+ "\u300C": "\u005B", // 「 → [
2724
+ "\u300D": "\u005D", // 」 → ]
2725
+ "\u301C": "\u007E", // 〜 → ~
2726
+ "\u30FC": "\u002D", // ー → -
2727
+ "\uFFE5": "\u005C" // ¥ → \
2728
+ };
2729
+ /* eslint-enable quote-props */
2730
+
2731
+ /**
2732
+ * ASCII入力欄に日本語IMEで入った文字をASCIIへ矯正する
2733
+ * @param {string} text - 変換したいテキスト
2734
+ * @returns {string} 変換後のテキスト
2735
+ */
2736
+ const toImeOff = function (text) {
2737
+ return Array.from(String(text), (ch) => {
2738
+ // 個別マップ
2739
+ if (ch in IME_OFF_MAP) {
2740
+ return IME_OFF_MAP[ch];
2741
+ }
2742
+
2743
+ const code = ch.charCodeAt(0);
2744
+
2745
+ // 全角ASCII
2746
+ if (code >= 0xFF01 && code <= 0xFF5E) {
2747
+ return String.fromCharCode(code - 0xFEE0);
2748
+ }
2749
+
2750
+ // シングルクォート系
2751
+ if (code >= 0x2018 && code <= 0x201B) {
2752
+ return "'";
2753
+ }
2754
+
2755
+ // ダブルクォート系
2756
+ if (code >= 0x201C && code <= 0x201F) {
2757
+ return '"';
2758
+ }
2759
+
2760
+ return ch;
2761
+ }).join("");
2762
+ };
2763
+
2764
+ /**
2765
+ * ASCII入力欄に日本語IMEで入った文字をASCIIへ矯正する
2766
+ *
2767
+ * 注意:
2768
+ * - これは「半角化」ではなく「IMEオフ入力相当への寄せ」
2769
+ * - ascii() とは責務が異なる
2770
+ *
2771
+ * @returns {Rule}
2772
+ */
2773
+ function imeOff() {
2774
+ return {
2775
+ name: "imeOff",
2776
+ targets: ["input", "textarea"],
2777
+
2778
+ normalizeChar(value, ctx) {
2779
+ return toImeOff(value);
2780
+ }
2781
+ };
2782
+ }
2783
+
2784
+ /**
2785
+ * dataset から imeOff ルールを生成する
2786
+ *
2787
+ * 対応する data 属性
2788
+ * - data-tig-rules-ime-off
2789
+ *
2790
+ * @param {DOMStringMap} dataset
2791
+ * @param {HTMLInputElement|HTMLTextAreaElement} _el
2792
+ * @returns {Rule|null}
2793
+ */
2794
+ imeOff.fromDataset = function fromDataset(dataset, _el) {
2795
+ if (dataset.tigRulesImeOff == null) {
2796
+ return null;
2797
+ }
2798
+
2799
+ return imeOff();
2800
+ };
2801
+
2633
2802
  /**
2634
2803
  * The script is part of Mojix for TextInputGuard.
2635
2804
  *
@@ -5771,13 +5940,10 @@ function kana(options = {}) {
5771
5940
  }
5772
5941
  s = Mojix.toKatakana(s);
5773
5942
  if (opt.target === "katakana-full") {
5774
- s = Mojix.toFullWidthSpace(s);
5775
5943
  s = Mojix.toFullWidthKana(s);
5776
5944
  } else if (opt.target === "katakana-half") {
5777
- s = Mojix.toHalfWidthSpace(s);
5778
5945
  s = Mojix.toHalfWidthKana(s);
5779
5946
  } else {
5780
- s = Mojix.toFullWidthSpace(s);
5781
5947
  s = Mojix.toFullWidthKana(s);
5782
5948
  s = Mojix.toHiragana(s);
5783
5949
  }
@@ -5854,7 +6020,7 @@ kana.fromDataset = function fromDataset(dataset, _el) {
5854
6020
  function ascii(options = {}) {
5855
6021
  /** @type {AsciiRuleOptions} */
5856
6022
  const opt = {
5857
- case: options.case ?? null
6023
+ case: options.case ?? "none"
5858
6024
  };
5859
6025
 
5860
6026
  return {
@@ -5867,6 +6033,10 @@ function ascii(options = {}) {
5867
6033
  // まず半角へ正規化
5868
6034
  s = Mojix.toHalfWidthAsciiCode(s);
5869
6035
 
6036
+ // toHalfWidthAsciiCode で対応できていない文字も実施
6037
+ s = s.replace(/\uFFE5/g, "\u005C"); //¥
6038
+ s = s.replace(/[\u2010-\u2015\u2212\u30FC\uFF0D\uFF70]/g, "\u002D"); //ハイフンに似ている記号
6039
+
5870
6040
  // 英字の大文字/小文字統一
5871
6041
  if (opt.case === "upper") {
5872
6042
  s = s.toUpperCase();
@@ -5921,6 +6091,23 @@ ascii.fromDataset = function fromDataset(dataset, _el) {
5921
6091
  */
5922
6092
 
5923
6093
 
6094
+ /**
6095
+ * filter ルールのオプション
6096
+ * - category は和集合で扱う(複数指定OK)
6097
+ * - allow は追加許可(和集合)
6098
+ * - deny は除外(差集合)
6099
+ *
6100
+ * allowed = (category の和集合 ∪ allow) − deny
6101
+ *
6102
+ * @typedef {Object} FilterRuleOptions
6103
+ * @property {"block"|"error"} [mode="block"] - 不要文字を入力中した場合の挙動
6104
+ * @property {FilterCategory[]} [category] - カテゴリ(配列)
6105
+ * @property {RegExp|string} [allow] - 追加で許可する正規表現(1文字にマッチさせる想定)
6106
+ * @property {string} [allowFlags] - allow が文字列のときの flags("iu" など。g/y は無視)
6107
+ * @property {RegExp|string} [deny] - 除外する正規表現(1文字にマッチさせる想定)
6108
+ * @property {string} [denyFlags] - deny が文字列のときの flags("iu" など。g/y は無視)
6109
+ */
6110
+
5924
6111
  /**
5925
6112
  * filter ルールのカテゴリ名
5926
6113
  *
@@ -5959,28 +6146,6 @@ const FILTER_CATEGORIES = [
5959
6146
  "single-codepoint-only"
5960
6147
  ];
5961
6148
 
5962
- /**
5963
- * filter ルールの動作モード
5964
- * @typedef {"drop"|"error"} FilterMode
5965
- */
5966
-
5967
- /**
5968
- * filter ルールのオプション
5969
- * - category は和集合で扱う(複数指定OK)
5970
- * - allow は追加許可(和集合)
5971
- * - deny は除外(差集合)
5972
- *
5973
- * allowed = (category の和集合 ∪ allow) − deny
5974
- *
5975
- * @typedef {Object} FilterRuleOptions
5976
- * @property {FilterMode} [mode="drop"] - drop: 不要文字を削除 / error: 削除せずエラーを積む
5977
- * @property {FilterCategory[]} [category] - カテゴリ(配列)
5978
- * @property {RegExp|string} [allow] - 追加で許可する正規表現(1文字にマッチさせる想定)
5979
- * @property {string} [allowFlags] - allow が文字列のときの flags("iu" など。g/y は無視)
5980
- * @property {RegExp|string} [deny] - 除外する正規表現(1文字にマッチさせる想定)
5981
- * @property {string} [denyFlags] - deny が文字列のときの flags("iu" など。g/y は無視)
5982
- */
5983
-
5984
6149
  /**
5985
6150
  * /g や /y は lastIndex の罠があるので除去して使う
5986
6151
  * @param {string} flags
@@ -6182,16 +6347,13 @@ const scanByAllowed = function (value, isAllowed, maxInvalidChars = 20) {
6182
6347
 
6183
6348
  /**
6184
6349
  * filter ルールを生成する
6185
- * - mode="drop": 不要文字を落とすだけ
6186
- * - mode="error": 文字は落とさず validate でエラーを積む
6187
- *
6188
6350
  * @param {FilterRuleOptions} [options]
6189
6351
  * @returns {Rule}
6190
6352
  */
6191
6353
  function filter(options = {}) {
6192
6354
  /** @type {FilterRuleOptions} */
6193
6355
  const opt = {
6194
- mode: options.mode ?? "drop",
6356
+ mode: options.mode ?? "block",
6195
6357
  category: options.category ?? [],
6196
6358
  allow: options.allow,
6197
6359
  allowFlags: options.allowFlags,
@@ -6276,7 +6438,7 @@ function filter(options = {}) {
6276
6438
  *
6277
6439
  * 対応する data 属性(dataset 名)
6278
6440
  * - data-tig-rules-filter -> dataset.tigRulesFilter
6279
- * - data-tig-rules-filter-mode -> dataset.tigRulesFilterMode ("drop"|"error")
6441
+ * - data-tig-rules-filter-mode -> dataset.tigRulesFilterMode
6280
6442
  * - data-tig-rules-filter-category -> dataset.tigRulesFilterCategory ("a,b,c")
6281
6443
  * - data-tig-rules-filter-allow -> dataset.tigRulesFilterAllow
6282
6444
  * - data-tig-rules-filter-allow-flags -> dataset.tigRulesFilterAllowFlags
@@ -6295,7 +6457,7 @@ filter.fromDataset = function fromDataset(dataset, _el) {
6295
6457
  /** @type {FilterRuleOptions} */
6296
6458
  const options = {};
6297
6459
 
6298
- const mode = parseDatasetEnum(dataset.tigRulesFilterMode, ["drop", "error"]);
6460
+ const mode = parseDatasetEnum(dataset.tigRulesFilterMode, ["block", "error"]);
6299
6461
  if (mode != null) {
6300
6462
  options.mode = mode;
6301
6463
  }
@@ -6351,11 +6513,8 @@ filter.fromDataset = function fromDataset(dataset, _el) {
6351
6513
  * length ルールのオプション
6352
6514
  * @typedef {Object} LengthRuleOptions
6353
6515
  * @property {number} [max] - 最大長(グラフェム数)。未指定なら制限なし
6354
- * @property {"block"|"error"} [overflowInput="block"] - 入力中に最大長を超えたときの挙動
6516
+ * @property {"block"|"error"} [mode="block"] - 入力中に最大長を超えたときの挙動
6355
6517
  * @property {"grapheme"|"utf-16"|"utf-32"} [unit="grapheme"] - 長さの単位
6356
- *
6357
- * block : 最大長を超える部分を切る
6358
- * error : エラーを積むだけ(値は変更しない)
6359
6518
  */
6360
6519
 
6361
6520
  /**
@@ -6476,7 +6635,7 @@ function length(options = {}) {
6476
6635
  /** @type {LengthRuleOptions} */
6477
6636
  const opt = {
6478
6637
  max: typeof options.max === "number" ? options.max : undefined,
6479
- overflowInput: options.overflowInput ?? "block",
6638
+ mode: options.mode ?? "block",
6480
6639
  unit: options.unit ?? "grapheme"
6481
6640
  };
6482
6641
 
@@ -6486,7 +6645,7 @@ function length(options = {}) {
6486
6645
 
6487
6646
  normalizeChar(value, ctx) {
6488
6647
  // block 以外は何もしない
6489
- if (opt.overflowInput !== "block") {
6648
+ if (opt.mode !== "block") {
6490
6649
  return value;
6491
6650
  }
6492
6651
  // max 未指定なら制限なし
@@ -6500,8 +6659,8 @@ function length(options = {}) {
6500
6659
 
6501
6660
  validate(value, ctx) {
6502
6661
  // error 以外は何もしない
6503
- if (opt.overflowInput !== "error") {
6504
- return value;
6662
+ if (opt.mode !== "error") {
6663
+ return;
6505
6664
  }
6506
6665
  // max 未指定なら制限なし
6507
6666
  if (typeof opt.max !== "number") {
@@ -6514,7 +6673,7 @@ function length(options = {}) {
6514
6673
  code: "length.max_overflow",
6515
6674
  rule: "length",
6516
6675
  phase: "validate",
6517
- detail: { max: opt.max, actual: len }
6676
+ detail: { limit: opt.max, actual: len }
6518
6677
  });
6519
6678
  }
6520
6679
  }
@@ -6529,7 +6688,7 @@ function length(options = {}) {
6529
6688
  * 対応する data 属性(dataset 名)
6530
6689
  * - data-tig-rules-length -> dataset.tigRulesLength
6531
6690
  * - data-tig-rules-length-max -> dataset.tigRulesLengthMax
6532
- * - data-tig-rules-length-overflow-input -> dataset.tigRulesLengthOverflowInput
6691
+ * - data-tig-rules-length-mode -> dataset.tigRulesLengthMode
6533
6692
  * - data-tig-rules-length-unit -> dataset.tigRulesLengthUnit
6534
6693
  *
6535
6694
  * @param {DOMStringMap} dataset
@@ -6550,12 +6709,9 @@ length.fromDataset = function fromDataset(dataset, _el) {
6550
6709
  options.max = max;
6551
6710
  }
6552
6711
 
6553
- const overflowInput = parseDatasetEnum(
6554
- dataset.tigRulesLengthOverflowInput,
6555
- ["block", "error"]
6556
- );
6557
- if (overflowInput != null) {
6558
- options.overflowInput = overflowInput;
6712
+ const mode = parseDatasetEnum(dataset.tigRulesLengthMode, ["block", "error"]);
6713
+ if (mode != null) {
6714
+ options.mode = mode;
6559
6715
  }
6560
6716
 
6561
6717
  const unit = parseDatasetEnum(
@@ -6584,10 +6740,7 @@ length.fromDataset = function fromDataset(dataset, _el) {
6584
6740
  * width ルールのオプション
6585
6741
  * @typedef {Object} WidthRuleOptions
6586
6742
  * @property {number} [max] - 最大長(全角は2, 半角は1)
6587
- * @property {"block"|"error"} [overflowInput="block"] - 入力中に最大長を超えたときの挙動
6588
- *
6589
- * block : 最大長を超える部分を切る
6590
- * error : エラーを積むだけ(値は変更しない)
6743
+ * @property {"block"|"error"} [mode="block"] - 入力中に最大長を超えたときの挙動
6591
6744
  */
6592
6745
 
6593
6746
  /**
@@ -6599,7 +6752,7 @@ function width(options = {}) {
6599
6752
  /** @type {WidthRuleOptions} */
6600
6753
  const opt = {
6601
6754
  max: typeof options.max === "number" ? options.max : undefined,
6602
- overflowInput: options.overflowInput ?? "block"
6755
+ mode: options.mode ?? "block"
6603
6756
  };
6604
6757
 
6605
6758
  return {
@@ -6608,7 +6761,7 @@ function width(options = {}) {
6608
6761
 
6609
6762
  normalizeChar(value, ctx) {
6610
6763
  // block 以外は何もしない
6611
- if (opt.overflowInput !== "block") {
6764
+ if (opt.mode !== "block") {
6612
6765
  return value;
6613
6766
  }
6614
6767
  // max 未指定なら制限なし
@@ -6632,8 +6785,8 @@ function width(options = {}) {
6632
6785
 
6633
6786
  validate(value, ctx) {
6634
6787
  // error 以外は何もしない
6635
- if (opt.overflowInput !== "error") {
6636
- return value;
6788
+ if (opt.mode !== "error") {
6789
+ return;
6637
6790
  }
6638
6791
  // max 未指定なら制限なし
6639
6792
  if (typeof opt.max !== "number") {
@@ -6653,10 +6806,10 @@ function width(options = {}) {
6653
6806
  const len = Mojix.getWidth(value);
6654
6807
  if (len > opt.max) {
6655
6808
  ctx.pushError({
6656
- code: "length.max_overflow",
6657
- rule: "length",
6809
+ code: "width.max_overflow",
6810
+ rule: "width",
6658
6811
  phase: "validate",
6659
- detail: { max: opt.max, actual: len }
6812
+ detail: { limit: opt.max, actual: len }
6660
6813
  });
6661
6814
  }
6662
6815
  }
@@ -6671,7 +6824,7 @@ function width(options = {}) {
6671
6824
  * 対応する data 属性(dataset 名)
6672
6825
  * - data-tig-rules-length -> dataset.tigRulesWidth
6673
6826
  * - data-tig-rules-length-max -> dataset.tigRulesWidthMax
6674
- * - data-tig-rules-length-overflow-input -> dataset.tigRulesWidthOverflowInput
6827
+ * - data-tig-rules-length-mode -> dataset.tigRulesWidthMode
6675
6828
  *
6676
6829
  * @param {DOMStringMap} dataset
6677
6830
  * @param {HTMLInputElement|HTMLTextAreaElement} _el
@@ -6691,12 +6844,9 @@ width.fromDataset = function fromDataset(dataset, _el) {
6691
6844
  options.max = max;
6692
6845
  }
6693
6846
 
6694
- const overflowInput = parseDatasetEnum(
6695
- dataset.tigRulesWidthOverflowInput,
6696
- ["block", "error"]
6697
- );
6698
- if (overflowInput != null) {
6699
- options.overflowInput = overflowInput;
6847
+ const mode = parseDatasetEnum(dataset.tigRulesWidthMode, ["block", "error"]);
6848
+ if (mode != null) {
6849
+ options.mode = mode;
6700
6850
  }
6701
6851
 
6702
6852
  return width(options);
@@ -6717,11 +6867,8 @@ width.fromDataset = function fromDataset(dataset, _el) {
6717
6867
  * bytes ルールのオプション
6718
6868
  * @typedef {Object} BytesRuleOptions
6719
6869
  * @property {number} [max] - 最大長(グラフェム数)。未指定なら制限なし
6720
- * @property {"block"|"error"} [overflowInput="block"] - 入力中に最大長を超えたときの挙動
6870
+ * @property {"block"|"error"} [mode="block"] - 入力中に最大長を超えたときの挙動
6721
6871
  * @property {"utf-8"|"utf-16"|"utf-32"|"sjis"|"cp932"} [unit="utf-8"] - サイズの単位(sjis系を使用する場合はfilterも必須)
6722
- *
6723
- * block : 最大長を超える部分を切る
6724
- * error : エラーを積むだけ(値は変更しない)
6725
6872
  */
6726
6873
 
6727
6874
  /**
@@ -6846,7 +6993,7 @@ function bytes(options = {}) {
6846
6993
  /** @type {BytesRuleOptions} */
6847
6994
  const opt = {
6848
6995
  max: typeof options.max === "number" ? options.max : undefined,
6849
- overflowInput: options.overflowInput ?? "block",
6996
+ mode: options.mode ?? "block",
6850
6997
  unit: options.unit ?? "utf-8"
6851
6998
  };
6852
6999
 
@@ -6856,7 +7003,7 @@ function bytes(options = {}) {
6856
7003
 
6857
7004
  normalizeChar(value, ctx) {
6858
7005
  // block 以外は何もしない
6859
- if (opt.overflowInput !== "block") {
7006
+ if (opt.mode !== "block") {
6860
7007
  return value;
6861
7008
  }
6862
7009
  // max 未指定なら制限なし
@@ -6870,8 +7017,8 @@ function bytes(options = {}) {
6870
7017
 
6871
7018
  validate(value, ctx) {
6872
7019
  // error 以外は何もしない
6873
- if (opt.overflowInput !== "error") {
6874
- return value;
7020
+ if (opt.mode !== "error") {
7021
+ return;
6875
7022
  }
6876
7023
  // max 未指定なら制限なし
6877
7024
  if (typeof opt.max !== "number") {
@@ -6899,7 +7046,7 @@ function bytes(options = {}) {
6899
7046
  * 対応する data 属性(dataset 名)
6900
7047
  * - data-tig-rules-bytes -> dataset.tigRulesBytes
6901
7048
  * - data-tig-rules-bytes-max -> dataset.tigRulesBytesMax
6902
- * - data-tig-rules-bytes-overflow-input -> dataset.tigRulesBytesOverflowInput
7049
+ * - data-tig-rules-bytes-mode -> dataset.tigRulesBytesMode
6903
7050
  * - data-tig-rules-bytes-unit -> dataset.tigRulesBytesUnit
6904
7051
  *
6905
7052
  * @param {DOMStringMap} dataset
@@ -6920,12 +7067,9 @@ bytes.fromDataset = function fromDataset(dataset, _el) {
6920
7067
  options.max = max;
6921
7068
  }
6922
7069
 
6923
- const overflowInput = parseDatasetEnum(
6924
- dataset.tigRulesBytesOverflowInput,
6925
- ["block", "error"]
6926
- );
6927
- if (overflowInput != null) {
6928
- options.overflowInput = overflowInput;
7070
+ const mode = parseDatasetEnum(dataset.tigRulesBytesMode, ["block", "error"]);
7071
+ if (mode != null) {
7072
+ options.mode = mode;
6929
7073
  }
6930
7074
 
6931
7075
  const unit = parseDatasetEnum(
@@ -7194,6 +7338,7 @@ const auto = new InputGuardAutoAttach(attach, [
7194
7338
  { name: "numeric", fromDataset: numeric.fromDataset },
7195
7339
  { name: "digits", fromDataset: digits.fromDataset },
7196
7340
  { name: "comma", fromDataset: comma.fromDataset },
7341
+ { name: "imeOff", fromDataset: imeOff.fromDataset },
7197
7342
  { name: "kana", fromDataset: kana.fromDataset },
7198
7343
  { name: "ascii", fromDataset: ascii.fromDataset },
7199
7344
  { name: "filter", fromDataset: filter.fromDataset },
@@ -7218,6 +7363,7 @@ const rules = {
7218
7363
  numeric,
7219
7364
  digits,
7220
7365
  comma,
7366
+ imeOff,
7221
7367
  kana,
7222
7368
  ascii,
7223
7369
  filter,
@@ -7231,11 +7377,11 @@ const rules = {
7231
7377
 
7232
7378
  /**
7233
7379
  * バージョン(ビルド時に置換したいならここを差し替える)
7234
- * 例: rollup replace で ""0.1.6"" を package.json の version に置換
7380
+ * 例: rollup replace で ""0.2.1"" を package.json の version に置換
7235
7381
  */
7236
7382
  // @ts-ignore
7237
7383
  // eslint-disable-next-line no-undef
7238
- const version = "0.1.6" ;
7384
+ const version = "0.2.1" ;
7239
7385
 
7240
7386
  exports.ascii = ascii;
7241
7387
  exports.attach = attach;
@@ -7245,6 +7391,7 @@ exports.bytes = bytes;
7245
7391
  exports.comma = comma;
7246
7392
  exports.digits = digits;
7247
7393
  exports.filter = filter;
7394
+ exports.imeOff = imeOff;
7248
7395
  exports.kana = kana;
7249
7396
  exports.length = length;
7250
7397
  exports.numeric = numeric;