/*! * Sauna Session Planner — planning logic * (c) 2026 DIVELUX Inc. MIT License. https://diveluxsaunahat.com * * Pure functions, no DOM. Works in the browser (window.SaunaPlanner) and in * Node (require('./planner.js')). * * WHERE THE NUMBERS COME FROM * These are conservative, commonly repeated sauna conventions, not research * findings and not medical advice: * * 1. Time per round. General guidance is to keep a single stay in a hot sauna * to no more than 15–20 minutes (e.g. Harvard Health Publishing, "Sauna * Health Benefits: Are saunas healthy or harmful?"). Beginners are usually * told to start at 5–10 minutes. So: new 5–10, regular 8–15, seasoned up to * 20, and never more than 20 in a hot room. * 2. Hotter room, shorter round. Inside each experience band the round gets * shorter as the temperature moves from the low end to the high end of the * normal range for that kind of sauna (x1.15 at the low end, x0.75 at the * high end). * 3. Humidity. Löyly (water on the stones), banya steam and steam rooms feel * hotter than dry air at the same reading, so their bands sit a little * lower than the dry Finnish band. * 4. Infrared cabins run much cooler (roughly 110–150 °F), so sessions are * longer and usually a single stay; capped here at 35 minutes. * 5. Breaks. The usual convention is to cool down for at least as long as you * were in the heat. Here: break = round length, but never under 10 minutes * and capped at 20. The session always ends with a cool-down. * 6. Rounds. The classic session is 2–3 rounds. New: at most 2. Regular: 3. * Seasoned: 4. * 7. Water. One glass (8 fl oz / ~240 ml) before, one in each break, and two * to four glasses afterwards depending on total time in the heat (the * "two to four glasses after" figure is the Harvard Health guidance above). * 8. Heat ladder. A straight-line temperature gradient from floor to ceiling, * anchored at the thermometer. It is an illustration of stratification, * not a measurement of any real room. */ (function (root, factory) { if (typeof module === 'object' && module.exports) module.exports = factory(); else root.SaunaPlanner = factory(); })(typeof self !== 'undefined' ? self : this, function () { 'use strict'; var GLASS_OZ = 8; var GLASS_ML = 240; var MIN_TOTAL = 15; var MAX_TOTAL = 180; var COOL_DOWN = 10; // final cool-down, minutes var COOL_DOWN_MIN = 5; // shortest final cool-down when time is tight var REST_MIN = 10; var REST_MAX = 20; /* * Per sauna type: * c / f slider range and default in each unit (kept as round numbers) * rounds [min, base, max] minutes per round, by experience level * maxRounds by experience level * gradient °C per meter of height, for the heat ladder illustration * benches whether "which bench" advice makes sense */ var TYPES = { dry: { label: 'Finnish, dry', hint: 'Hot, dry air. Little or no water on the stones.', c: { min: 60, max: 100, def: 80 }, f: { min: 140, max: 210, def: 175 }, rounds: { 'new': [5, 8, 10], regular: [8, 12, 15], seasoned: [10, 16, 20] }, maxRounds: { 'new': 2, regular: 3, seasoned: 4 }, gradient: 14, benches: true }, loyly: { label: 'Finnish, with löyly', hint: 'Water on the stones. Each ladle makes the same air feel hotter.', c: { min: 65, max: 100, def: 80 }, f: { min: 150, max: 210, def: 180 }, rounds: { 'new': [5, 7, 10], regular: [8, 11, 15], seasoned: [10, 14, 18] }, maxRounds: { 'new': 2, regular: 3, seasoned: 4 }, gradient: 12, benches: true }, banya: { label: 'Russian banya', hint: 'Lower temperature, heavy steam. Feels hotter than the reading.', c: { min: 55, max: 90, def: 70 }, f: { min: 130, max: 195, def: 160 }, rounds: { 'new': [5, 6, 8], regular: [6, 10, 12], seasoned: [8, 12, 15] }, maxRounds: { 'new': 2, regular: 3, seasoned: 4 }, gradient: 10, benches: true }, steam: { label: 'Steam room / hammam', hint: 'Warm, fully saturated air. Sweat cannot evaporate, so go easy.', c: { min: 38, max: 50, def: 43 }, f: { min: 100, max: 120, def: 110 }, rounds: { 'new': [5, 8, 10], regular: [8, 12, 15], seasoned: [10, 15, 20] }, maxRounds: { 'new': 2, regular: 3, seasoned: 3 }, gradient: 5, benches: true }, infrared: { label: 'Infrared', hint: 'Panels warm you directly. Cooler air, longer single stay.', c: { min: 40, max: 65, def: 55 }, f: { min: 105, max: 150, def: 130 }, rounds: { 'new': [10, 15, 20], regular: [15, 25, 30], seasoned: [20, 30, 35] }, maxRounds: { 'new': 1, regular: 1, seasoned: 2 }, gradient: 3, benches: false } }; var LEVELS = { 'new': { label: 'New', hint: 'First sessions, or back after a long break' }, regular: { label: 'Regular', hint: 'A few times a month' }, seasoned: { label: 'Seasoned', hint: 'Weekly or more, for years' } }; /* Heights for the heat ladder (meters). Thermometer assumed at head height on the upper bench, which is where most are mounted. */ var LADDER_LEVELS = [ { key: 'ceiling', label: 'Ceiling', m: 2.1 }, { key: 'upper', label: 'Head, upper bench', m: 1.7, thermometer: true }, { key: 'lower', label: 'Head, lower bench', m: 1.25 }, { key: 'feet', label: 'Feet on the lower bench', m: 0.45 }, { key: 'floor', label: 'Floor', m: 0 } ]; var THERMOMETER_M = 1.7; var ROOM_C = 22; // the ladder never drops below ordinary room temperature function c2f(c) { return c * 9 / 5 + 32; } function f2c(f) { return (f - 32) * 5 / 9; } function clamp(v, lo, hi) { return Math.min(hi, Math.max(lo, v)); } function num(v, fallback) { var n = typeof v === 'number' ? v : parseFloat(v); return isFinite(n) ? n : fallback; } /* Turn any input into a complete, valid set of options. */ function normalize(input) { input = input || {}; var type = Object.prototype.hasOwnProperty.call(TYPES, input.type) ? input.type : 'dry'; var level = Object.prototype.hasOwnProperty.call(LEVELS, input.level) ? input.level : 'new'; var unit = String(input.unit || 'f').toLowerCase() === 'c' ? 'c' : 'f'; var range = TYPES[type][unit]; var temp = Math.round(clamp(num(input.temp, range.def), range.min, range.max)); var total = Math.round(clamp(num(input.total, 60), MIN_TOTAL, MAX_TOTAL)); return { type: type, level: level, unit: unit, temp: temp, total: total }; } /* 0 at the cool end of the normal range for this sauna type, 1 at the hot end. */ function heatPosition(o) { var t = TYPES[o.type]; var c = o.unit === 'c' ? o.temp : f2c(o.temp); return clamp((c - t.c.min) / (t.c.max - t.c.min), 0, 1); } function roundMinutes(o) { var band = TYPES[o.type].rounds[o.level]; // [min, base, max] var factor = 1.15 - 0.40 * heatPosition(o); return clamp(Math.round(band[1] * factor), band[0], band[2]); } function water(rounds, heatMin) { var before = 1; var between = Math.max(0, rounds - 1); var after = heatMin <= 20 ? 2 : heatMin <= 40 ? 3 : 4; var glasses = before + between + after; return { before: before, between: between, after: after, glasses: glasses, oz: glasses * GLASS_OZ, ml: glasses * GLASS_ML, liters: Math.round(glasses * GLASS_ML / 100) / 10 }; } function plan(input) { var o = normalize(input); var t = TYPES[o.type]; var roundMin = roundMinutes(o); var restMin = clamp(roundMin, REST_MIN, REST_MAX); var coolMin = COOL_DOWN; var maxRounds = t.maxRounds[o.level]; var rounds = 0; var trimmed = false; // Most rounds that fit, final cool-down included. for (var n = maxRounds; n >= 1; n--) { if (n * roundMin + (n - 1) * restMin + coolMin <= o.total) { rounds = n; break; } } // Not even one round fits: shorten the cool-down first, then the round. if (!rounds) { rounds = 1; coolMin = COOL_DOWN_MIN; if (roundMin + coolMin > o.total) { roundMin = o.total - coolMin; trimmed = true; } } var heatMin = rounds * roundMin; var usedMin = heatMin + (rounds - 1) * restMin + coolMin; var segments = []; var at = 0; for (var i = 1; i <= rounds; i++) { segments.push({ kind: 'heat', index: i, min: roundMin, start: at, label: 'Round ' + i }); at += roundMin; if (i < rounds) { segments.push({ kind: 'rest', index: i, min: restMin, start: at, label: 'Cool-down' }); at += restMin; } } segments.push({ kind: 'cool', index: rounds, min: coolMin, start: at, label: 'Final cool-down' }); var bench = null; if (t.benches) { bench = o.level === 'new' ? 'lower' : o.level === 'regular' ? 'either' : 'upper'; } var notes = []; var pos = heatPosition(o); if (pos >= 0.85) { notes.push('This is the hot end of the usual range for this kind of sauna, so the rounds are shorter.'); } if (o.type === 'loyly' || o.type === 'banya') { notes.push('Steam makes the same reading feel hotter. After a big ladle, move down a bench or step out early.'); } if (o.type === 'steam') { notes.push('In saturated air sweat cannot evaporate and cool you. Leave early if it feels like work.'); } if (o.type === 'infrared' && rounds === 1) { notes.push('Infrared sessions are usually one continuous stay. Step out for a minute whenever you want to.'); } if (trimmed) { notes.push('The round was shortened to fit your time and still leave a cool-down.'); } if (rounds < maxRounds && !trimmed) { notes.push('With more time you could add another round. Do not make these ones longer instead.'); } return { input: o, rounds: rounds, roundMin: roundMin, restMin: rounds > 1 ? restMin : 0, coolMin: coolMin, heatMin: heatMin, usedMin: usedMin, spareMin: o.total - usedMin, trimmed: trimmed, bench: bench, water: water(rounds, heatMin), segments: segments, notes: notes }; } /* Straight-line stratification anchored at the thermometer. Illustration only. */ function ladder(input) { var o = normalize(input); var t = TYPES[o.type]; var atThermometer = o.unit === 'c' ? o.temp : f2c(o.temp); return LADDER_LEVELS.map(function (lv) { var c = Math.max(ROOM_C, atThermometer + (lv.m - THERMOMETER_M) * t.gradient); if (lv.thermometer) c = atThermometer; return { key: lv.key, label: lv.label, meters: lv.m, feet: Math.round(lv.m * 3.28084 * 2) / 2, thermometer: !!lv.thermometer, c: Math.round(c), f: Math.round(c2f(c)) }; }); } /* URL parameters for "share this plan". */ function toQuery(input) { var o = normalize(input); return 'sauna=' + o.type + '&temp=' + o.temp + '&unit=' + o.unit + '&level=' + o.level + '&time=' + o.total; } function fromQuery(search) { var out = {}; String(search || '').replace(/^[?#]/, '').split('&').forEach(function (pair) { var i = pair.indexOf('='); if (i < 1) return; var k = pair.slice(0, i); var v; try { v = decodeURIComponent(pair.slice(i + 1)); } catch (e) { return; } if (k === 'sauna') out.type = v; else if (k === 'temp') out.temp = v; else if (k === 'unit') out.unit = v; else if (k === 'level') out.level = v; else if (k === 'time') out.total = v; }); return out; } /* Convert a temperature when the unit toggle flips; snaps into the range. */ function convertTemp(type, temp, toUnit) { var t = TYPES[type] || TYPES.dry; var range = t[toUnit === 'c' ? 'c' : 'f']; var v = toUnit === 'c' ? f2c(temp) : c2f(temp); if (toUnit !== 'c') v = Math.round(v / 5) * 5; // °F slider moves in fives return Math.round(clamp(v, range.min, range.max)); } return { TYPES: TYPES, LEVELS: LEVELS, MIN_TOTAL: MIN_TOTAL, MAX_TOTAL: MAX_TOTAL, GLASS_OZ: GLASS_OZ, GLASS_ML: GLASS_ML, c2f: c2f, f2c: f2c, normalize: normalize, plan: plan, ladder: ladder, toQuery: toQuery, fromQuery: fromQuery, convertTemp: convertTemp }; });