haori 0.4.12 → 0.4.13

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.
package/dist/haori.es.js CHANGED
@@ -4050,7 +4050,7 @@ const Y = class Y {
4050
4050
  * @param type イベントタイプ('click', 'change', 'load'など)
4051
4051
  */
4052
4052
  delegate(t, e) {
4053
- const r = this.getElementFromTarget(t.target);
4053
+ const r = this.getElementFromTarget(t.target, e);
4054
4054
  if (!r)
4055
4055
  return;
4056
4056
  const s = w.get(r);
@@ -4062,10 +4062,36 @@ const Y = class Y {
4062
4062
  * イベントのターゲットから HTMLElement を取得します。
4063
4063
  *
4064
4064
  * @param target イベントのターゲット
4065
+ * @param type イベントタイプ。click の場合のみ祖先委譲を行う
4065
4066
  * @returns HTMLElement または null
4066
4067
  */
4067
- getElementFromTarget(t) {
4068
- return t ? t instanceof HTMLElement ? t : t instanceof Node ? t.parentElement : null : null;
4068
+ getElementFromTarget(t, e) {
4069
+ if (!t)
4070
+ return null;
4071
+ if (t instanceof HTMLElement)
4072
+ return e === "click" ? this.findClickableElement(t) : t;
4073
+ if (t instanceof Node) {
4074
+ const r = t.parentElement;
4075
+ return r ? e === "click" ? this.findClickableElement(r) : r : null;
4076
+ }
4077
+ return null;
4078
+ }
4079
+ /**
4080
+ * data-click-* 属性を持つ最も近い祖先要素を返します。
4081
+ *
4082
+ * @param element 探索開始要素
4083
+ * @returns 処理対象要素。見つからない場合は null
4084
+ */
4085
+ findClickableElement(t) {
4086
+ let e = t;
4087
+ for (; e; ) {
4088
+ if (e.getAttributeNames().some(
4089
+ (r) => r.startsWith("data-click-")
4090
+ ))
4091
+ return e;
4092
+ e = e.parentElement;
4093
+ }
4094
+ return null;
4069
4095
  }
4070
4096
  };
4071
4097
  Y.HISTORY_STATE_KEY = "__haoriHistoryState__";
@@ -4276,7 +4302,7 @@ const H = class H {
4276
4302
  H._initialized = !1;
4277
4303
  let q = H;
4278
4304
  document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", q.init) : q.init();
4279
- const pt = "0.4.12";
4305
+ const pt = "0.4.13";
4280
4306
  export {
4281
4307
  R as Core,
4282
4308
  u as Env,