Files
o2o-weather/frontend/public/embed/card.js
T
skkim c5129d14ed feat: 날씨 위젯에서 아침·낮·저녁·밤을 눌러 그 시간대 점수와 한마디 보기
- 서버가 카드 데이터에 시간대별 날씨 점수와 한마디(앱과 같은 65점 규칙: '오늘 낮은 ○○각!'/'…쉬어 가요')를 넣음
- 카드 4칸을 버튼으로: 누르면 점수·하늘·해와 달·한마디가 그 시간대로 바뀌고, 상세형 요약·상태 줄은 숨김(자리는 유지)
- 같은 칸을 다시 누르면 다시 그리지 않음, 누른 칸에 초점 유지, 휴대폰 터치 반짝임 없앰
- ASSET_VERSION 11
2026-11-26 13:43:31 +09:00

420 lines
24 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* 날씨각 카드 — 다른 사이트가 iframe 으로 붙이는 /embed/card 의 카드를 그린다 (모양은 card.css).
군산각(https://gunsan.webforai.kr/assets/weather.js, 2026-11-25 받은 것)의 카드 스크립트를 옮겨 왔다. 군산각의 이
카드는 날씨각 첫 화면 카드를 그대로 그린 위젯이라 점수·달 모양·하늘·4칸 줄이 날씨각과 같다. 원본과 다른 곳:
1. 날씨 값을 fetch 두 번(data-wx, data-wx-day)으로 받지 않고, 백엔드가 이 페이지에 넣어 둔 #wx-data JSON
({name, link, hero, picks, today})을 읽어 usable() 에 {hero}, today 로 넘긴다. 8초 제한·ask()·화면에 가까워지면 묻기는
뺐고, 바로 그린다. fetch 가 없는 브라우저는 카드 전체가 아니라 글꼴만 포기한다.
2. 문구(지금 날씨 점수, 아침·낮·저녁·밤·지금, 자세히 보기, 하늘 이름)는 data-wx-w 대신 이 파일의 WORDS 에 둔다.
외국어 갈래(wx-intl: 숫자만 보이는 줄, 접힌 줄)는 빼고 한국어 갈래만 남겼다. 날짜는 한국어 긴 꼴로만 쓴다.
3. 아이콘 경로 /assets/wx/ → /icons/ (날씨각 아이콘). 일출·일몰([data-sd-days]) 부분을 뺐다.
4. 원본의 빈 catch 두 곳(FontFace 만들기, document.fonts.add)을 뺐다. 글꼴 하나가 잘못되면 그 글꼴만 포기하고
(faces 의 catch), 글꼴을 붙이다 오류가 나도 카드는 그린다(finally).
5. 상세형(home) 날짜(.wx-dt)는 통째로 들어갈 때만 보인다. 원본은 좁으면 '1…' 처럼 말줄임으로 잘렸다. 카드를 그린 직후와
iframe 폭이 바뀔 때(resize) 글자 폭과 칸 폭을 비교해, 안 들어가면 상자에 is-nodt 를 붙여 숨긴다(card.css).
6. 그리기 전에는 원본의 빈 자리 표시 대신 서버 HTML 에 처음부터 든 토끼 로딩 화면(.wx-load)이 보이고, is-ready·
is-failed 가 붙으면 card.css 가 감춘다. 못 그렸을 때 링크 글자는 서버가 넣은 '날씨각에서 날씨 보기 ›'(원본은 '○○ 날씨
보기'와 새 창 그림)이고, 실패할 때 이 파일은 그 글자를 바꾸지 않는다. 이 파일이 아예 안 오면 card.css 가 8초 뒤 같은
링크를 보인다.
7. 아래 4칸은 버튼이다(원본은 보기만 하는 칸). 날씨각 앱 첫 화면처럼 칸을 누르면 그 시간대로 카드를 다시 그린다: 하늘
(data-t·data-sky, 구름·비·눈, 저녁·밤이면 오늘 밤 달)은 그 칸 그림과 같은 예보 칸, 점수는 hero.weather_slots, 한마디는
서버가 앱과 같은 규칙으로 만든 picks. 상세형 요약·상태 줄은 지금 값이라 자리만 두고 감춘다. '지금' 칸을 누르면 처음
모습이고, 점수나 picks 가 없는 칸도 지금 모습이다. 다시 그릴 때는 본문을 비우고 처음과 같이 만든다(글꼴은 처음 한 번만
받으므로 picks 의 한마디도 처음 글자 목록에 넣는다).
그대로 둔 것: 오늘(한국 날짜) 값이 아니면 그리지 않음, 날씨각 둥근 글꼴(Jua, Bagel Fat One)을 Google Fonts 에서
카드 글자만 받기(2.5초 넘으면 기본 글꼴), 화면 밖이면 움직임 멈춤(is-off), 그리다 실패하면 is-failed.
밖으로 나가는 요청은 이 글꼴뿐이다(쿠키·localStorage·통계 없음). 글은 textContent 로만 넣는다.
움직임 줄이기 설정이면 떨어지기·떠 있기·별똥별·반짝임·비 내리기·토끼 뛰기가 없다(card.css). */
(function () {
"use strict";
var doc = document, win = window;
var SVG = "http://www.w3.org/2000/svg";
function $all(sel, el) { return Array.prototype.slice.call((el || doc).querySelectorAll(sel)); }
// the visitor's date and time in Korea
function seoul() {
var o = {};
try {
new Intl.DateTimeFormat("en-CA", { timeZone: "Asia/Seoul", year: "numeric", month: "2-digit", day: "2-digit",
hour: "2-digit", minute: "2-digit", hourCycle: "h23" }).formatToParts(new Date()).forEach(function (p) { o[p.type] = p.value; });
// oxlint-disable-next-line no-unused-vars -- 바인딩 없는 catch 는 옛 브라우저에서 파일 전체가 문법 오류가 된다
} catch (e) { return null; }
if (!(o.year && o.month && o.day)) return null;
return { iso: o.year + "-" + o.month + "-" + o.day, mo: +o.month, h: (+o.hour || 0) % 24, mi: +o.minute || 0 };
}
var T = seoul(), day = T ? T.iso : "";
// ------------------------------------------------------------ weather
var boxes = $all(".wx");
if (!boxes.length) return;
// the card's words (군산각's data-wx-w on its Korean pages)
var WORDS = {
more: "자세히 보기",
score: "날씨 점수", // after the cell's name: '지금 날씨 점수', '아침 날씨 점수'
slots: { morning: "아침", day: "낮", sunset: "저녁", night: "밤", now: "지금" },
sky: { sun: "맑음", sun_cloud: "구름 조금", cloud: "흐림", rain: "비", snow: "눈", moon: "맑음" }
};
// 날씨각's own tables (its app: the hero card)
var COLS = ["morning", "day", "sunset", "night"];
var HOUR = { morning: 7, day: 13, sunset: 18, night: 22 };
var ICON = { clear: "sun", partly: "sun_cloud", cloudy: "cloud", rain: "rain", snow: "snow", sleet: "snow" };
var CLOUDS = { clear: 0, partly: 2, cloudy: 3, rain: 3, snow: 3, sleet: 3 };
var WANING = ["기우는 달", "하현달", "그믐달"];
var SUNSET = [17.7, 18.2, 18.6, 19.1, 19.5, 19.9, 19.9, 19.5, 18.9, 18.2, 17.6, 17.3]; // its sky by the clock
var ICONS = "/icons/";
function num(v) { return typeof v === "number" && isFinite(v); }
function deg(v) { return num(v) ? Math.round(v) + "°" : "–"; }
function el(tag, cls, text) {
var e = doc.createElement(tag);
if (cls) e.className = cls;
if (text != null) e.textContent = text;
return e;
}
function clockSky() {
if (!T) return "day";
var h = T.h + T.mi / 60, s = SUNSET[T.mo - 1] || 18.5;
return h >= 5 && h < 11 ? "morning" : h >= 11 && h < s + 1 ? (h < s - 2 ? "day" : "sunset") : "night";
}
// a slot's sky as 날씨각 reads it (rain_type: 2 rain · 3 sleet · 4 snow · 5 shower; sky: 2 partly · 3 cloudy)
function kind(s) {
if (!s) return "clear";
var r = s.rain_type, k = s.sky;
if (r === 2 || r === 5) return "rain";
if (r === 4) return "snow";
if (r === 3) return "sleet";
if (k === 3) return "cloudy";
if (k === 2) return "partly";
if (r == null && k == null) return { cloud: "cloudy", rain: "rain", snow: "snow" }[s.icon] || "clear";
return "clear";
}
// the slot for a cell: the last at or before its hour (one with a figure after it when that one has none)
function pick(slots, hour) {
var n = null;
slots.forEach(function (s) { if (s.hh <= hour) n = s; });
n = n || slots[0];
if (!num(n.temp_c)) n = slots.filter(function (s) { return s.hh > hour && num(s.temp_c); })[0] || n;
return n;
}
function nearest(slots) {
var t = Date.now(), have = slots.filter(function (s) { return num(s.temp_c); });
return have.reduce(function (a, s) { return Math.abs(s.ms - t) < Math.abs(a.ms - t) ? s : a; }, have[0]);
}
function usable(feed, today) {
var h = feed && feed.hero;
if (!h || typeof h !== "object" || !num(h.weather_score)) return null;
if (!today || typeof today !== "object") return null;
if (day && (String(h.now_at || "").slice(0, 10) !== day || today.day !== day)) return null;
var slots = (today.slots || []).filter(function (s) { return s && !isNaN(Date.parse(s.at)); }).map(function (s) {
var ms = Date.parse(s.at), k = new Date(ms + 324e5); // its hour in Korea
return { ms: ms, hh: k.getUTCHours() + k.getUTCMinutes() / 60, temp_c: s.temp_c, sky: s.sky, rain_type: s.rain_type, icon: s.icon };
});
if (!slots.some(function (s) { return num(s.temp_c); })) return null;
return { hero: h, slots: slots };
}
// 날씨각's moon (its app's own drawing: the disc, its seas and craters, the shade of its phase)
var SEAS = [[-.32, -.36, .3, .26], [.12, -.36, .17, .15], [.3, -.06, .2, .17], [-.56, .06, .26, .42], [.66, -.26, .1, .12],
[.52, .22, .13, .15], [-.14, .44, .18, .13], [-.46, .5, .1, .09]];
var CRATERS = [[.1, .72, .07], [.42, .52, .05], [-.66, -.5, .05], [.62, .52, .04], [-.2, .08, .04]];
var TONES = { night: { body: ["#fffcf2", "#f6ebcb", "#e0cc98"], shade: "#1a2050" },
dusk: { body: ["#fff8ee", "#ffe2cc", "#f2b9a2"], shade: "#4a2a63" } };
var uid = 0;
function node(tag, at, kids) {
var e = doc.createElementNS(SVG, tag);
Object.keys(at || {}).forEach(function (k) { e.setAttribute(k, at[k]); });
(kids || []).forEach(function (c) { if (c) e.appendChild(c); });
return e;
}
function shadePath(pct, r) {
var f = pct / 100;
return "M0," + (-r) + " A" + r + "," + r + " 0 0 0 0," + r + " A" + (r * Math.abs(1 - 2 * f)) + "," + r + " 0 0 " + (f < .5 ? 0 : 1) + " 0," + (-r);
}
function moon(pct, waxing, tone) {
var id = "wxm" + (++uid), a = TONES[tone], o = pct / 100, full = pct >= 99, nw = pct <= 1;
var stop = function (off, c, op) { return node("stop", op == null ? { offset: off, "stop-color": c } : { offset: off, "stop-color": c, "stop-opacity": op }); };
var defs = node("defs", {}, [
node("radialGradient", { id: id + "g" }, [stop("0.6", "#fff4cf", "0.55"), stop("0.8", "#ffe9a8", "0.16"), stop("1", "#ffe9a8", "0")]),
node("radialGradient", { id: id + "b", cx: "0.4", cy: "0.36", r: "0.72" }, [stop("0", a.body[0]), stop("0.6", a.body[1]), stop("1", a.body[2])]),
node("radialGradient", { id: id + "l" }, [stop("0.72", "#8a6f3c", "0"), stop("1", "#8a6f3c", "0.28")]),
node("clipPath", { id: id + "c" }, [node("circle", { r: "1" })]),
node("filter", { id: id + "f", x: "-0.2", y: "-0.2", width: "1.4", height: "1.4" }, [node("feGaussianBlur", { stdDeviation: "0.035" })])
]);
var seas = node("g", { filter: "url(#" + id + "f)", fill: "#c4b287", opacity: "0.55" },
SEAS.map(function (e) { return node("ellipse", { cx: e[0], cy: e[1], rx: e[2], ry: e[3] }); }));
var disc = node("g", { "clip-path": "url(#" + id + "c)" }, [node("circle", { r: "1", fill: "url(#" + id + "b)" }), seas]
.concat(CRATERS.map(function (e) { return node("circle", { cx: e[0], cy: e[1], r: e[2], fill: "#efe2bd", stroke: "#cdbb8c", "stroke-width": "0.018", opacity: "0.8" }); }))
.concat([node("circle", { r: "1", fill: "url(#" + id + "l)" }),
full ? null : node("path", waxing ? { d: shadePath(pct, 1.04), fill: a.shade, opacity: "0.94", filter: "url(#" + id + "f)" }
: { d: shadePath(pct, 1.04), fill: a.shade, opacity: "0.94", filter: "url(#" + id + "f)", transform: "scale(-1,1)" })]));
return node("svg", { viewBox: "-1.5 -1.5 3 3", class: "wx-mo", "aria-hidden": "true", focusable: "false" }, [defs,
nw ? null : node("circle", { r: "1.5", fill: "url(#" + id + "g)", opacity: String(full ? 1 : .12 + .8 * o) }), disc,
nw ? node("circle", { r: "1", fill: "none", stroke: "#fff", "stroke-opacity": "0.18", "stroke-width": "0.025" }) : null]);
}
// the night sky: 날씨각's 26 stars (kept between the head and the words: a star by a letter reads as part of it,
// one behind the see-through link as a dot after it) and 3 shooting stars; rain and snow
function sky(kindNow) {
var s = el("div", "wx-stars");
s.setAttribute("aria-hidden", "true");
for (var i = 0; i < 26; i++) {
var st = el("i", i % 3 ? "" : "wx-tw");
st.style.left = (i * 37 % 100) + "%";
st.style.top = (12 + (i * 53 % 60) * .55).toFixed(1) + "%";
st.style.opacity = String(.4 + i * 7 % 6 / 10);
st.style.setProperty("--dl", (i * 0.7 % 5).toFixed(1) + "s");
s.appendChild(st);
}
[["6%", "80%", "90px", "7s", "1.5s"], ["20%", "52%", "70px", "9s", "4s"], ["34%", "94%", "80px", "11s", "6.5s"]].forEach(function (x) {
var sh = el("span", "wx-shoot");
sh.style.top = x[0];
sh.style.left = x[1];
sh.style.setProperty("--len", x[2]);
sh.style.setProperty("--dur", x[3]);
sh.style.setProperty("--dl", x[4]);
s.appendChild(sh);
});
var out = [s];
var rain = kindNow === "rain" || kindNow === "sleet", snow = kindNow === "snow" || kindNow === "sleet";
if (rain || snow) {
var f = el("div", "wx-fx");
f.setAttribute("aria-hidden", "true");
var add = function (n, cls, step, a, b, c, d) {
for (var i = 0; i < n; i++) {
var x = el("i", cls);
x.style.left = (i * step % 100) + "%";
x.style.setProperty("--top", (i * a % 90) + "%");
x.style.setProperty("--dl", (i * b % 100 / c) + "s");
x.style.setProperty("--dur", d(i) + "s");
f.appendChild(x);
}
};
if (rain) add(22, "wx-drop", 41, 29, 37, 100, function (i) { return .55 + i * 13 % 5 / 10; });
if (snow) add(16, "wx-flake", 47, 31, 53, 25, function (i) { return 3.2 + i * 7 % 5 / 2; });
out.push(f);
}
return out;
}
// the date as 날씨각 writes it ('10월 31일 토요일')
function dateWords() {
try {
return new Intl.DateTimeFormat("ko", { timeZone: "Asia/Seoul", month: "long", day: "numeric", weekday: "long" }).format(new Date());
// oxlint-disable-next-line no-unused-vars -- 옛 브라우저용 catch 바인딩 (seoul() 참고)
} catch (e) { return ""; }
}
// the date shows only whole: hidden (is-nodt, card.css) when its letters are wider than its room, never cut ('1…')
function fitDate(box) {
var dt = box.querySelector("[data-wx-dt]");
if (!dt || !dt.textContent) return;
box.classList.remove("is-nodt");
var r = doc.createRange();
r.selectNodeContents(dt);
box.classList.toggle("is-nodt", r.getBoundingClientRect().width > dt.getBoundingClientRect().width + .01);
}
// ------------------------------------------------------------ 날씨각's round fonts, only the letters the card shows
var FONTS = "https://fonts.googleapis.com/css2?family=";
function faces(family, as, text) {
// the stylesheet's faces (one or more, each with its unicode-range), loaded before they join the page; none when
// the stylesheet or a face does not come
var url = FONTS + family + "&text=" + encodeURIComponent(text) + "&display=swap";
return win.fetch(url, { mode: "cors", credentials: "omit" }).then(function (r) { return r.ok ? r.text() : ""; }).then(function (css) {
var out = [];
(css.match(/@font-face\s*{[^}]*}/g) || []).forEach(function (blk) {
var src = /src:\s*url\((https:\/\/fonts\.gstatic\.com\/[^)\s]+)\)\s*format\(['"]?woff2['"]?\)/.exec(blk);
var ur = /unicode-range:\s*([^;]+);/.exec(blk);
if (!src) return;
out.push(new win.FontFace(as, "url(" + src[1] + ") format('woff2')", ur ? { unicodeRange: ur[1].trim() } : {}));
});
return Promise.all(out.map(function (f) { return f.load(); }));
}).catch(function () { return []; });
}
function fonts(round, digits, done) {
var over = false;
var end = function (list) {
if (over) return;
over = true;
clearTimeout(t);
// they join the page now, before the card is drawn in them — never afterwards (nothing changes its letters)
try {
(list || []).forEach(function (fs) { (fs || []).forEach(function (f) { doc.fonts.add(f); }); });
} finally {
done();
}
};
var t = setTimeout(function () { end(null); }, 2500);
if (!win.FontFace || !doc.fonts || !win.Promise || !win.fetch) return end(null);
Promise.all([faces("Jua", "WxJua", round), faces("Bagel+Fat+One", "WxBagel", digits)]).then(end);
}
function letters(s) {
var seen = {}, out = "";
s.replace(/\s+/g, "").split("").forEach(function (c) { if (!seen[c]) { seen[c] = 1; out += c; } });
return out;
}
// ------------------------------------------------------------ the card
// the cell shown other than now: one with its own score and words (picks, from the server); null shows now
function chosen(D, mode, k) {
var p = D.picks[k], ws = D.hero.weather_slots;
return k && k !== mode && p && typeof p.bubble === "string" && p.bubble.trim() && ws && num(ws[k]) ? k : null;
}
// k: the cell pressed (null at first: now)
function draw(box, D, k) {
var w = WORDS, side = box.classList.contains("wx-side"), h = D.hero, slots = D.slots;
var S = w.slots, SKY = w.sky;
var mode = HOUR[h.sky_mode] ? h.sky_mode : clockSky();
var now = nearest(slots), at = chosen(D, mode, k), cell = at || mode, pk = at ? D.picks[at] : null;
box.setAttribute("data-wx-at", at || "");
// the sky of the cell shown: the same forecast as its picture in the cells below
var skyNow = kind(at ? pick(slots, HOUR[at]) : now);
var body = box.querySelector("[data-wx-b]");
if (!body) return;
body.textContent = ""; // drawn again (a cell pressed): its stars, rain and snow made anew, never twice
box.setAttribute("data-t", cell);
box.setAttribute("data-sky", skyNow);
var dt = box.querySelector("[data-wx-dt]");
if (dt && !side) dt.textContent = dateWords();
sky(skyNow).forEach(function (x) { body.appendChild(x); });
// the sun, or the moon, with the score; 날씨각's clouds for the sky now
var stage = el("div", "wx-sky");
for (var i = 0; i < CLOUDS[skyNow]; i++) {
var c = el("span", "wx-cl wx-c" + (i + 1));
c.setAttribute("aria-hidden", "true");
c.appendChild(el("span", "wx-cb"));
stage.appendChild(c);
}
// tonight's moon from 저녁 on (the cell shown, now or pressed)
var mn = (cell === "sunset" || cell === "night") && h.moon_name && num(h.moon_pct)
? { pct: Math.max(0, Math.min(100, h.moon_pct)), waning: WANING.indexOf(h.moon_name) > -1 } : null;
var orb = el("div", "wx-orb" + (mn ? " wx-moon " + (mn.pct >= 50 ? "is-lit" : "is-dim") : ""));
if (mn) orb.appendChild(moon(mn.pct, !mn.waning, cell === "sunset" ? "dusk" : "night"));
var ob = el("div", "wx-ob");
ob.appendChild(orb);
stage.appendChild(ob);
body.appendChild(stage);
var score = el("p", "wx-sc");
score.appendChild(el("small", "", (at ? S[at] : S.now) + " " + w.score));
score.appendChild(el("b", "", String(Math.round(at ? h.weather_slots[at] : h.weather_score))));
orb.appendChild(score);
// the words: 날씨각's own (of the cell pressed: its picks). The summary and the status line tell of now: kept in their
// place but unseen when another cell is shown (the card does not move)
var say = el("div", "wx-say");
var bub = at ? pk.bubble : h.bubble;
if (typeof bub === "string" && bub.trim()) say.appendChild(el("p", "wx-bub", bub.trim()));
var sum = h.top1 && typeof h.top1.summary === "string" ? h.top1.summary.trim() : "";
if (!side && sum) say.appendChild(el("p", "wx-sum" + (at ? " is-hidden" : ""), sum));
var st = (Array.isArray(h.status) ? h.status : []).filter(function (x) { return x && typeof x.label === "string" && typeof x.value === "string"; });
if (!side && st.length) {
var p = el("p", "wx-st" + (at ? " is-hidden" : ""));
st.forEach(function (x, i) {
if (i) { var dot = el("span", "wx-dot", "·"); dot.setAttribute("aria-hidden", "true"); p.appendChild(dot); }
var one = el("span", "wx-si" + (x.tone === "warn" ? " is-warn" : ""));
one.appendChild(el("span", "wx-sl", x.label));
one.appendChild(doc.createTextNode(" "));
one.appendChild(el("b", "", x.value));
p.appendChild(one);
});
say.appendChild(p);
}
body.appendChild(say); // always, even empty: its room stays the same whichever cell is shown
// the four cells: 아침 · 낮 · 저녁 · 밤, the one it is now '지금'; a button each, the one shown pressed
var ol = el("ol", "wx-strip");
COLS.forEach(function (c) {
var isNow = c === mode, s = isNow ? now : pick(slots, HOUR[c]), sk = kind(s);
var ic = c === "night" && sk === "clear" ? "moon" : ICON[sk];
var name = isNow ? S.now : S[c], tc = isNow && num(h.temp_c) ? h.temp_c : s && s.temp_c;
var li = el("li");
var b = el("button", "wx-cell" + (c === cell ? " is-on" : ""));
b.type = "button";
b.setAttribute("data-wx-k", c);
b.setAttribute("aria-pressed", c === cell ? "true" : "false");
b.setAttribute("aria-label", num(tc) ? name + " " + Math.round(tc) + "도" : name);
b.appendChild(el("span", "wx-cn", name));
var img = el("img", "wx-ic");
img.src = ICONS + ic + ".webp";
img.alt = SKY[ic] || "";
img.width = img.height = side ? 18 : 22;
img.decoding = "async";
b.appendChild(img);
b.appendChild(el("b", "wx-tc", deg(tc)));
b.addEventListener("click", function () { again(box, D, c); });
li.appendChild(b);
ol.appendChild(li);
});
body.appendChild(ol);
// the link: only the 자세히 보기 button goes to 날씨각 (the rest of the card is not a link)
var go = box.querySelector("[data-wx-gl]");
if (go) {
var t = box.querySelector(".wx-t");
go.textContent = "";
go.appendChild(el("span", "vh", (t ? t.textContent : "") + " "));
go.appendChild(doc.createTextNode(w.more));
var arr = el("span", "wx-ar", "›");
arr.setAttribute("aria-hidden", "true");
go.appendChild(arr);
}
box.classList.add("is-ready");
if (!side) fitDate(box);
}
// the letters the card will show in 날씨각's round font (Jua) and in its score font (Bagel Fat One)
function roundText(D) {
var h = D.hero, S = WORDS.slots, s = "";
boxes.forEach(function (b) {
s += (b.querySelector(".wx-t") || {}).textContent || "";
s += WORDS.score + S.morning + S.day + S.sunset + S.night + S.now;
s += typeof h.bubble === "string" ? h.bubble : "";
COLS.forEach(function (k) { var p = D.picks[k]; s += p && typeof p.bubble === "string" ? p.bubble : ""; });
(Array.isArray(h.status) ? h.status : []).forEach(function (x) { s += (x && x.label || "") + (x && x.value || ""); });
});
return letters(s + "0123456789-–°·");
}
// the values the server put in the page (#wx-data); null when missing or broken
function given() {
var x = doc.getElementById("wx-data");
if (!x) return null;
// oxlint-disable-next-line no-unused-vars -- 옛 브라우저용 catch 바인딩 (seoul() 참고)
try { return JSON.parse(x.textContent); } catch (e) { return null; }
}
function fail() { boxes.forEach(function (b) { b.classList.add("is-failed"); }); }
// draw a card for cell k (null: now); one that cannot be drawn shows the link (is-failed)
function show(b, D, k) {
// oxlint-disable-next-line no-unused-vars -- 옛 브라우저용 catch 바인딩 (seoul() 참고)
try { draw(b, D, k); } catch (e) {
var x = b.querySelector("[data-wx-b]");
if (x) x.textContent = "";
b.classList.remove("is-ready");
b.classList.add("is-failed");
}
}
// a cell pressed: the card drawn again for it (is-again: the sun and clouds do not fall in again, card.css), the
// focus on that cell's new button (the cells are made anew), so the next Tab goes on to the cell after it
// a press that would show what is already shown (the same cell, or a cell without its own values) draws nothing
function again(box, D, k) {
var h = D.hero, mode = HOUR[h.sky_mode] ? h.sky_mode : clockSky();
if ((chosen(D, mode, k) || "") !== box.getAttribute("data-wx-at")) {
box.classList.add("is-again");
show(box, D, k);
}
var b = box.querySelector('[data-wx-k="' + k + '"]');
if (b) b.focus({ preventScroll: true });
}
function start() {
var g = given(), D = g && typeof g === "object" ? usable({ hero: g.hero }, g.today) : null;
if (!D) return fail();
D.picks = g.picks && typeof g.picks === "object" ? g.picks : {};
fonts(roundText(D), "0123456789", function () {
boxes.forEach(function (b) { show(b, D, null); });
});
}
start();
// the iframe's width changed (the host page resized): look again whether the date fits
win.addEventListener("resize", function () {
boxes.forEach(function (b) { if (b.classList.contains("is-ready") && !b.classList.contains("wx-side")) fitDate(b); });
});
// a card off the screen (the host page scrolled it away) rests: its motion paused
if (win.IntersectionObserver) {
var rest = new win.IntersectionObserver(function (seen) {
seen.forEach(function (e) { e.target.classList.toggle("is-off", !e.isIntersecting); });
});
boxes.forEach(function (b) { rest.observe(b); });
}
})();