haori 0.4.11 → 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
@@ -31,11 +31,11 @@ const C = class C {
31
31
  C.devMode = !1;
32
32
  let L = C;
33
33
  const z = "embedded";
34
- function rt(R) {
35
- return R === "embedded" || R === "demo";
34
+ function rt(P) {
35
+ return P === "embedded" || P === "demo";
36
36
  }
37
- function it(R) {
38
- return R === null ? null : rt(R) ? R : z;
37
+ function it(P) {
38
+ return P === null ? null : rt(P) ? P : z;
39
39
  }
40
40
  const k = class k {
41
41
  /**
@@ -504,7 +504,7 @@ class A {
504
504
  n.appendChild(e), n.reset(), r.insertBefore(e, s);
505
505
  }
506
506
  }
507
- }), await P.evaluateAll(t);
507
+ }), await R.evaluateAll(t);
508
508
  }
509
509
  /**
510
510
  * data-each によって生成された複製(テンプレート以外)を削除します。
@@ -1404,7 +1404,7 @@ class x extends w {
1404
1404
  "month",
1405
1405
  "time",
1406
1406
  "week"
1407
- ], this.children = [], this.attributeMap = /* @__PURE__ */ new Map(), this.bindingData = null, this.bindingDataCache = null, this.visible = !0, this.display = null, this.template = null, this.listKey = null, this.value = null, this.skipMutationAttributes = !1, this.skipChangeValue = !1, this.syncValue(), t.getAttributeNames().forEach((e) => {
1407
+ ], this.children = [], this.attributeMap = /* @__PURE__ */ new Map(), this.bindingData = null, this.bindingDataCache = null, this.visible = !0, this.display = null, this.displayPriority = null, this.template = null, this.listKey = null, this.value = null, this.skipMutationAttributes = !1, this.skipChangeValue = !1, this.syncValue(), t.getAttributeNames().forEach((e) => {
1408
1408
  const r = t.getAttribute(e);
1409
1409
  if (r !== null && !this.attributeMap.has(e)) {
1410
1410
  const s = new U(e, r);
@@ -1470,13 +1470,13 @@ class x extends w {
1470
1470
  }), this.children.forEach((e) => {
1471
1471
  const r = e.clone();
1472
1472
  t.getTarget().appendChild(r.getTarget()), t.pushChild(r);
1473
- }), t.mounted = !1, t.bindingData = this.bindingData, t.clearBindingDataCache(), t.visible = !0, t.display = this.display, t.template = this.template, t.normalizeClonedVisibilityState(), t;
1473
+ }), t.mounted = !1, t.bindingData = this.bindingData, t.clearBindingDataCache(), t.visible = !0, t.display = this.display, t.displayPriority = this.displayPriority, t.template = this.template, t.normalizeClonedVisibilityState(), t;
1474
1474
  }
1475
1475
  /**
1476
1476
  * clone 時に runtime の hidden 状態だけを落とします。
1477
1477
  */
1478
1478
  normalizeClonedVisibilityState() {
1479
- (this.visible === !1 || this.getTarget().style.display === "none" || this.getTarget().hasAttribute(`${u.prefix}if-false`)) && (this.visible = !0, this.display = "", this.getTarget().style.display = "", this.getTarget().removeAttribute(`${u.prefix}if-false`)), this.children.forEach((t) => {
1479
+ (this.visible === !1 || this.getTarget().style.display === "none" || this.getTarget().hasAttribute(`${u.prefix}if-false`)) && (this.visible = !0, this.display = null, this.displayPriority = null, this.getTarget().style.removeProperty("display"), this.getTarget().removeAttribute(`${u.prefix}if-false`)), this.children.forEach((t) => {
1480
1480
  t instanceof x && t.normalizeClonedVisibilityState();
1481
1481
  });
1482
1482
  }
@@ -1941,7 +1941,11 @@ class x extends w {
1941
1941
  * @returns エレメントの非表示のPromise
1942
1942
  */
1943
1943
  hide() {
1944
- return this.visible = !1, this.display = this.getTarget().style.display, this.getTarget().style.display = "none", this.getTarget().setAttribute(`${u.prefix}if-false`, ""), Promise.resolve();
1944
+ if (!this.visible)
1945
+ return Promise.resolve();
1946
+ this.visible = !1;
1947
+ const t = this.getTarget();
1948
+ return this.display = t.style.getPropertyValue("display"), this.displayPriority = t.style.getPropertyPriority("display"), t.style.setProperty("display", "none", "important"), t.setAttribute(`${u.prefix}if-false`, ""), Promise.resolve();
1945
1949
  }
1946
1950
  /**
1947
1951
  * エレメントを表示します。
@@ -1949,7 +1953,14 @@ class x extends w {
1949
1953
  * @return エレメントの表示のPromise
1950
1954
  */
1951
1955
  show() {
1952
- return this.getTarget().style.display = this.display ?? "", this.getTarget().removeAttribute(`${u.prefix}if-false`), this.visible = !0, Promise.resolve();
1956
+ if (this.visible)
1957
+ return Promise.resolve();
1958
+ const t = this.getTarget();
1959
+ return this.display === null || this.display === "" ? t.style.removeProperty("display") : t.style.setProperty(
1960
+ "display",
1961
+ this.display,
1962
+ this.displayPriority ?? ""
1963
+ ), this.display = null, this.displayPriority = null, t.removeAttribute(`${u.prefix}if-false`), this.visible = !0, Promise.resolve();
1953
1964
  }
1954
1965
  /**
1955
1966
  * 指定した属性名を持つ最も近い親要素を返します。
@@ -2425,17 +2436,17 @@ function W() {
2425
2436
  ) ? t : X;
2426
2437
  }
2427
2438
  const lt = /* @__PURE__ */ new Set(["GET", "HEAD", "OPTIONS"]);
2428
- function ut(R) {
2429
- return lt.has(R.toUpperCase());
2439
+ function ut(P) {
2440
+ return lt.has(P.toUpperCase());
2430
2441
  }
2431
- function ct(R, t) {
2442
+ function ct(P, t) {
2432
2443
  for (const [e, r] of Object.entries(t))
2433
- r !== void 0 && (r === null ? R.append(e, "") : Array.isArray(r) ? r.forEach((s) => {
2434
- R.append(e, String(s));
2435
- }) : typeof r == "object" || typeof r == "function" ? R.append(e, JSON.stringify(r)) : R.append(e, String(r)));
2444
+ r !== void 0 && (r === null ? P.append(e, "") : Array.isArray(r) ? r.forEach((s) => {
2445
+ P.append(e, String(s));
2446
+ }) : typeof r == "object" || typeof r == "function" ? P.append(e, JSON.stringify(r)) : P.append(e, String(r)));
2436
2447
  }
2437
- function ht(R, t) {
2438
- const e = new URL(R, window.location.href), r = new URLSearchParams(e.search);
2448
+ function ht(P, t) {
2449
+ const e = new URL(P, window.location.href), r = new URLSearchParams(e.search);
2439
2450
  return ct(r, t), e.search = r.toString(), e.toString();
2440
2451
  }
2441
2452
  const c = class c {
@@ -2551,12 +2562,12 @@ const c = class c {
2551
2562
  if (typeof s != "string" || r === null)
2552
2563
  return null;
2553
2564
  const n = r.trim();
2554
- return c.SINGLE_PLACEHOLDER_REGEX.test(n) ? P.parseDataBind(s) : n.startsWith("{") || n.startsWith("[") ? P.parseDataBind(
2565
+ return c.SINGLE_PLACEHOLDER_REGEX.test(n) ? R.parseDataBind(s) : n.startsWith("{") || n.startsWith("[") ? R.parseDataBind(
2555
2566
  c.resolveDataJsonString(
2556
2567
  r,
2557
2568
  t.getBindingData()
2558
2569
  )
2559
- ) : P.parseDataBind(
2570
+ ) : R.parseDataBind(
2560
2571
  c.resolveDataParamString(r, t.getBindingData())
2561
2572
  );
2562
2573
  }
@@ -2632,7 +2643,7 @@ ${h}
2632
2643
  h
2633
2644
  );
2634
2645
  try {
2635
- i.headers = P.parseDataBind(d);
2646
+ i.headers = R.parseDataBind(d);
2636
2647
  } catch (b) {
2637
2648
  f.error("Haori", `Invalid fetch headers: ${b}`);
2638
2649
  }
@@ -2648,7 +2659,7 @@ ${h}
2648
2659
  h
2649
2660
  );
2650
2661
  try {
2651
- i.headers = P.parseDataBind(d);
2662
+ i.headers = R.parseDataBind(d);
2652
2663
  } catch (b) {
2653
2664
  f.error("Haori", `Invalid fetch headers: ${b}`);
2654
2665
  }
@@ -3008,7 +3019,7 @@ ${d}
3008
3019
  JSON.stringify(n)
3009
3020
  );
3010
3021
  const m = l.getBindingData();
3011
- Object.assign(m, n), await P.setBindingData(p, m);
3022
+ Object.assign(m, n), await R.setBindingData(p, m);
3012
3023
  }
3013
3024
  const a = i ? n : {}, o = new Response(JSON.stringify(a), {
3014
3025
  headers: { "Content-Type": "application/json" }
@@ -3248,7 +3259,7 @@ ${d}
3248
3259
  );
3249
3260
  } else
3250
3261
  i[a] = r;
3251
- s.push(P.setBindingData(n.getTarget(), i));
3262
+ s.push(R.setBindingData(n.getTarget(), i));
3252
3263
  });
3253
3264
  else {
3254
3265
  if (typeof r == "string")
@@ -3261,7 +3272,7 @@ ${d}
3261
3272
  r
3262
3273
  );
3263
3274
  s.push(
3264
- P.setBindingData(
3275
+ R.setBindingData(
3265
3276
  n.getTarget(),
3266
3277
  i
3267
3278
  )
@@ -3296,7 +3307,7 @@ ${d}
3296
3307
  ...s.getBindingData(),
3297
3308
  ...e
3298
3309
  };
3299
- return P.setBindingData(s.getTarget(), n);
3310
+ return R.setBindingData(s.getTarget(), n);
3300
3311
  });
3301
3312
  return Promise.all(r).then(() => {
3302
3313
  });
@@ -3361,7 +3372,7 @@ ${d}
3361
3372
  const e = [], r = t.clone();
3362
3373
  return e.push(
3363
3374
  t.getParent().insertAfter(r, t)
3364
- ), e.push(P.evaluateAll(r)), e.push(A.reset(r)), Promise.all(e).then(() => {
3375
+ ), e.push(R.evaluateAll(r)), e.push(A.reset(r)), Promise.all(e).then(() => {
3365
3376
  });
3366
3377
  }
3367
3378
  /**
@@ -4003,7 +4014,7 @@ g.ATTRIBUTE_ALIAS_SUFFIX = "attr-", g.PRIORITY_ATTRIBUTE_SUFFIXES = ["bind", "if
4003
4014
  "import",
4004
4015
  "url-param"
4005
4016
  ], g.ATTRIBUTE_PLACEHOLDER_REGEX = /\{\{\{[\s\S]+?\}\}\}|\{\{[\s\S]+?\}\}/;
4006
- let P = g;
4017
+ let R = g;
4007
4018
  const Y = class Y {
4008
4019
  /**
4009
4020
  * コンストラクタ。
@@ -4039,7 +4050,7 @@ const Y = class Y {
4039
4050
  * @param type イベントタイプ('click', 'change', 'load'など)
4040
4051
  */
4041
4052
  delegate(t, e) {
4042
- const r = this.getElementFromTarget(t.target);
4053
+ const r = this.getElementFromTarget(t.target, e);
4043
4054
  if (!r)
4044
4055
  return;
4045
4056
  const s = w.get(r);
@@ -4051,10 +4062,36 @@ const Y = class Y {
4051
4062
  * イベントのターゲットから HTMLElement を取得します。
4052
4063
  *
4053
4064
  * @param target イベントのターゲット
4065
+ * @param type イベントタイプ。click の場合のみ祖先委譲を行う
4054
4066
  * @returns HTMLElement または null
4055
4067
  */
4056
- getElementFromTarget(t) {
4057
- 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;
4058
4095
  }
4059
4096
  };
4060
4097
  Y.HISTORY_STATE_KEY = "__haoriHistoryState__";
@@ -4185,8 +4222,8 @@ const H = class H {
4185
4222
  return;
4186
4223
  H._initialized = !0;
4187
4224
  const t = await Promise.allSettled([
4188
- P.scan(document.head),
4189
- P.scan(document.body)
4225
+ R.scan(document.head),
4226
+ R.scan(document.body)
4190
4227
  ]), [e, r] = t;
4191
4228
  e.status !== "fulfilled" && f.error("[Haori]", "Failed to build head fragment:", e.reason), r.status !== "fulfilled" && f.error("[Haori]", "Failed to build body fragment:", r.reason), await F.wait(), document.body.setAttribute("data-haori-ready", ""), H.observe(document.head), H.observe(document.body), new Q().start(), $.syncTree(document.body);
4192
4229
  }
@@ -4208,12 +4245,12 @@ const H = class H {
4208
4245
  s.attributeName
4209
4246
  );
4210
4247
  const n = s.target;
4211
- if (s.attributeName && P.isAliasedAttributeReflection(
4248
+ if (s.attributeName && R.isAliasedAttributeReflection(
4212
4249
  n,
4213
4250
  s.attributeName
4214
4251
  ))
4215
4252
  break;
4216
- P.setAttribute(
4253
+ R.setAttribute(
4217
4254
  n,
4218
4255
  s.attributeName,
4219
4256
  n.getAttribute(s.attributeName),
@@ -4228,9 +4265,9 @@ const H = class H {
4228
4265
  Array.from(s.removedNodes).map((n) => n.nodeName),
4229
4266
  Array.from(s.addedNodes).map((n) => n.nodeName)
4230
4267
  ), Array.from(s.removedNodes).forEach((n) => {
4231
- $.cleanupTree(n), P.removeNode(n);
4268
+ $.cleanupTree(n), R.removeNode(n);
4232
4269
  }), Array.from(s.addedNodes).forEach((n) => {
4233
- n.parentElement instanceof HTMLElement && (P.addNode(n.parentElement, n), $.syncTree(n));
4270
+ n.parentElement instanceof HTMLElement && (R.addNode(n.parentElement, n), $.syncTree(n));
4234
4271
  });
4235
4272
  break;
4236
4273
  }
@@ -4240,7 +4277,7 @@ const H = class H {
4240
4277
  "Character data changed:",
4241
4278
  s.target,
4242
4279
  s.target.textContent
4243
- ), s.target instanceof Text || s.target instanceof Comment ? P.changeText(s.target, s.target.textContent) : f.warn(
4280
+ ), s.target instanceof Text || s.target instanceof Comment ? R.changeText(s.target, s.target.textContent) : f.warn(
4244
4281
  "[Haori]",
4245
4282
  "Unsupported character data type:",
4246
4283
  s.target
@@ -4265,9 +4302,9 @@ const H = class H {
4265
4302
  H._initialized = !1;
4266
4303
  let q = H;
4267
4304
  document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", q.init) : q.init();
4268
- const pt = "0.4.11";
4305
+ const pt = "0.4.13";
4269
4306
  export {
4270
- P as Core,
4307
+ R as Core,
4271
4308
  u as Env,
4272
4309
  A as Form,
4273
4310
  w as Fragment,