website with slop placeholders

This commit is contained in:
udo
2026-04-22 13:31:51 +00:00
parent 14ebf10a22
commit 223cf4c6e1
336 changed files with 66009 additions and 116 deletions
@@ -0,0 +1,100 @@
#load "../../lib/app.uce"
COMPONENT(Request& context)
{
String title = first(context.call["title"].to_string(), "Sign in with OAuth");
String subtitle = first(context.call["subtitle"].to_string(), "Choose your preferred authentication method");
String callback_url = first(context.call["callback_url"].to_string(), starter_link("auth/callback", context));
DTree services = context.call["services"];
if(services.get_type_name() != "array" || services["google"]["name"].to_string() == "")
{
services["google"]["name"] = "Google";
services["google"]["color"] = "#4285f4";
services["google"]["icon"] = "fab fa-google";
services["google"]["scope"] = "openid email profile";
services["google"]["auth_url"] = "https://accounts.google.com/o/oauth2/v2/auth";
services["github"]["name"] = "GitHub";
services["github"]["color"] = "#333333";
services["github"]["icon"] = "fab fa-github";
services["github"]["scope"] = "user:email";
services["github"]["auth_url"] = "https://github.com/login/oauth/authorize";
services["discord"]["name"] = "Discord";
services["discord"]["color"] = "#5865f2";
services["discord"]["icon"] = "fab fa-discord";
services["discord"]["scope"] = "identify email";
services["discord"]["auth_url"] = "https://discord.com/api/oauth2/authorize";
services["twitch"]["name"] = "Twitch";
services["twitch"]["color"] = "#9146ff";
services["twitch"]["icon"] = "fab fa-twitch";
services["twitch"]["scope"] = "user:read:email";
services["twitch"]["auth_url"] = "https://id.twitch.tv/oauth2/authorize";
}
<>
<form class="card">
<div>
<h2><?= title ?></h2>
<label><?= subtitle ?></label>
</div>
<? services.each([&](DTree service, String service_key) {
String client_id = context.call[service_key + "_client_id"].to_string();
String handler_name = ascii_safe_name(service_key);
String service_name = service["name"].to_string();
String scope = service["scope"].to_string();
String auth_url = service["auth_url"].to_string();
String store_url = starter_link("auth/store-oauth-session", context);
?><div data-service="<?= service_key ?>">
<button type="button" class="btn" onclick='initiateOAuth_<?= handler_name ?>()'>
<i class="<?= service["icon"].to_string() ?>" style="color: <?= service["color"].to_string() ?>"></i>
Continue with <?= service_name ?>
</button>
<div class="loading" style="display: none;"><span>Connecting...</span></div>
<label>Secure authentication via <?= service_name ?></label>
<script>
window.initiateOAuth_<?= handler_name ?> = function () {
const wrapper = document.querySelector('[data-service="<?= service_key ?>"]');
if (!wrapper) return;
const button = wrapper.querySelector('.btn');
const loading = wrapper.querySelector('.loading');
if (button) button.style.display = 'none';
if (loading) loading.style.display = 'block';
const clientId = <?: json_encode(client_id) ?>;
if (!clientId || clientId.indexOf('YOUR_') === 0) {
alert('<?= service_name ?> OAuth is not configured yet.');
if (button) button.style.display = '';
if (loading) loading.style.display = 'none';
return;
}
const state = btoa(Math.random().toString(36).substring(2) + Math.random().toString(36).substring(2)).replace(/[^a-zA-Z0-9]/g, '');
const params = new URLSearchParams({
client_id: clientId,
redirect_uri: <?: json_encode(callback_url) ?>,
scope: <?: json_encode(scope) ?>,
response_type: 'code',
state: state
});
sessionStorage.setItem('oauth_state', state);
sessionStorage.setItem('oauth_service', <?: json_encode(service_key) ?>);
fetch(<?: json_encode(store_url) ?>, {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({oauth_service: <?: json_encode(service_key) ?>, oauth_state: state})
}).catch(console.error).finally(() => {
window.location.href = <?: json_encode(auth_url) ?> + '?' + params.toString();
});
};
</script>
</div><?
}); ?>
<div class="banner" id="oauth-status" style="display: none;"></div>
</form>
</>
}
@@ -0,0 +1,114 @@
#load "../../lib/app.uce"
COMPONENT(Request& context)
{
starter_boot(context);
<>
<div id="cookie-consent" style="
position: fixed;
bottom: 0;
left: 0;
right: 0;
background: var(--surface);
border-top: 1px solid var(--border);
box-shadow: var(--shadow-xl);
z-index: 9998;
padding: 1.5rem;
transform: translateY(100%);
transition: transform 0.3s ease;
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
" aria-live="polite">
<div style="
max-width: 1200px;
margin: 0 auto;
display: flex;
align-items: center;
justify-content: space-between;
gap: 1.5rem;
flex-wrap: wrap;
">
<div style="flex: 1; min-width: 300px;">
<div style="
display: flex;
align-items: center;
gap: 0.75rem;
margin-bottom: 0.5rem;
">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke='var(--primary)' stroke-width="2" style="flex-shrink: 0;">
<path d="M12 2C13.1 2 14 2.9 14 4C14 5.1 13.1 6 12 6C10.9 6 10 5.1 10 4C10 2.9 10.9 2 12 2M21 9V7L15 1L13 3L15 5H3V21A2 2 0 0 0 5 23H19A2 2 0 0 0 21 21V11L19 13V20H5V7H21M9 11V13H7V11H9M13 11V13H11V11H13M17 11V13H15V11H17M9 15V17H7V15H9M13 15V17H11V15H13M17 15V17H15V15H17Z"/>
</svg>
<h3 style="margin: 0; font-size: 1.1rem; font-weight: 600; color: var(--text-primary);">Cookie Notice</h3>
</div>
<p style="margin: 0; color: var(--text-secondary); font-size: 0.9rem; line-height: 1.5;">
We use cookies to enhance your browsing experience, serve personalized content, and analyze our traffic.
<a href="#" id="cookie-policy-link" style="color: var(--primary); text-decoration: none;">Learn more</a>
</p>
</div>
<div style="display: flex; gap: 0.75rem; flex-shrink: 0; align-items: center;">
<button id="cookie-reject" style="padding: 0.75rem 1.5rem; border: 1px solid var(--border); background: transparent; color: var(--text-secondary); border-radius: 0.5rem; cursor: pointer;">Reject All</button>
<button id="cookie-accept" style="padding: 0.75rem 1.5rem; border: 1px solid var(--primary); background: var(--primary); color: white; border-radius: 0.5rem; cursor: pointer;">Accept All</button>
</div>
</div>
</div>
<script>
(function() {
let cookieConsent = document.getElementById('cookie-consent');
let acceptButton = document.getElementById('cookie-accept');
let rejectButton = document.getElementById('cookie-reject');
let policyLink = document.getElementById('cookie-policy-link');
if (!cookieConsent) return;
let COOKIE_NAME = 'cookie_consent';
let COOKIE_EXPIRY_DAYS = 365;
function setCookie(name, value, days) {
let expires = new Date();
expires.setTime(expires.getTime() + (days * 24 * 60 * 60 * 1000));
document.cookie = name + '=' + value + ';expires=' + expires.toUTCString() + ';path=/;SameSite=Lax';
}
function getCookie(name) {
let nameEQ = name + '=';
let ca = document.cookie.split(';');
for (let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) === ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);
}
return null;
}
function hideBanner() {
cookieConsent.style.transform = 'translateY(100%)';
setTimeout(() => {
cookieConsent.style.display = 'none';
}, 300);
}
let existingConsent = getCookie(COOKIE_NAME);
if (!existingConsent) {
setTimeout(() => {
cookieConsent.style.transform = 'translateY(0)';
}, 1);
}
acceptButton.addEventListener('click', function() {
setCookie(COOKIE_NAME, 'accepted', COOKIE_EXPIRY_DAYS);
hideBanner();
});
rejectButton.addEventListener('click', function() {
setCookie(COOKIE_NAME, 'rejected', COOKIE_EXPIRY_DAYS);
hideBanner();
});
policyLink.addEventListener('click', function(e) {
e.preventDefault();
window.open('https://example.com/privacy-policy', '_blank');
});
}());
</script>
</>
}
@@ -0,0 +1,308 @@
#load "../../lib/app.uce"
String data_format_bytes(String raw, bool disk = false)
{
if(trim(raw) == "")
return("--");
StringList units;
units.push_back("B");
units.push_back("KB");
units.push_back("MB");
units.push_back("GB");
units.push_back("TB");
units.push_back("PB");
f64 value = atof(raw.c_str());
u32 unit_index = 0;
while((value >= 1024.0 || value <= -1024.0) && unit_index < units.size() - 1)
{
value /= 1024.0;
unit_index += 1;
}
u32 decimals = disk ? (unit_index >= 4 ? 2 : (unit_index >= 1 ? 1 : 0)) : (unit_index == 0 ? 0 : 1);
char buf[64];
snprintf(buf, sizeof(buf), ("%." + std::to_string(decimals) + "f").c_str(), value);
return(String(buf) + " " + units[unit_index]);
}
DTree data_format_value(DTree value, DTree row, DTree column)
{
DTree result;
String format = column["format"].to_string();
String raw = value.to_string();
String sort_value = raw;
String display_value = raw;
if(format == "number")
{
display_value = raw;
}
else if(format == "bytes")
{
display_value = data_format_bytes(raw, false);
}
else if(format == "disk-bytes")
{
display_value = data_format_bytes(raw, true);
}
else if(format == "percent")
{
display_value = raw + "%";
}
else if(format == "duration-ms")
{
f64 number = atof(raw.c_str());
if(number >= 1000.0)
{
char buf[64];
snprintf(buf, sizeof(buf), number >= 10000.0 ? "%.0f s" : "%.1f s", number / 1000.0);
display_value = buf;
}
else
{
char buf[64];
snprintf(buf, sizeof(buf), number >= 100.0 ? "%.0f ms" : "%.1f ms", number);
display_value = buf;
}
}
else if(format == "bool")
{
bool on = raw == "1" || to_lower(raw) == "true" || to_lower(raw) == "yes";
display_value = on ? "Yes" : "No";
sort_value = on ? "1" : "0";
}
result["display"] = display_value;
result["sort"] = sort_value;
return(result);
}
COMPONENT:SUMMARY_METRICS(Request& context)
{
String title = context.call["title"].to_string();
String subtitle = context.call["subtitle"].to_string();
<>
<div class="dashboard-panel">
<? if(title != "" || subtitle != "") { ?>
<div class="dashboard-panel-header">
<? if(title != "") { ?><h2><?= title ?></h2><? } ?>
<? if(subtitle != "") { ?><p><?= subtitle ?></p><? } ?>
</div>
<? } ?>
<div class="dashboard-stat-grid">
<? context.call["items"].each([&](DTree item, String key) {
String tone = first(item["tone"].to_string(), "info");
String href = item["href"].to_string();
String tag = href != "" ? "a" : "div";
?><<?= tag ?> class="dashboard-stat-card tone-<?= tone ?>"<?= href != "" ? " href=\"" + html_escape(href) + "\"" : "" ?>>
<div class="dashboard-stat-label"><?= first(item["label"].to_string(), "Metric") ?></div>
<div class="dashboard-stat-value"><?= first(item["value"].to_string(), "--") ?></div>
<? if(item["meta"].to_string() != "") { ?><div class="dashboard-stat-meta"><?= item["meta"].to_string() ?></div><? } ?>
</<?= tag ?>><?
}); ?>
</div>
</div>
</>
}
COMPONENT:TIMESERIES_CHART(Request& context)
{
starter_register_js("js/u-format.js", context);
starter_register_js("js/u-timeseries-chart.js", context);
String chart_id = first(context.call["id"].to_string(), "ts-chart-" + std::to_string((u64)time()));
String canvas_id = chart_id + "-canvas";
String title = context.call["title"].to_string();
String subtitle = context.call["subtitle"].to_string();
s32 height = std::max(180, (s32)int_val(first(context.call["height"].to_string(), "320")));
String x_axis_label = first(context.call["x_axis_label"].to_string(), "Time");
String y_axis_left_label = first(context.call["y_axis_left_label"].to_string(), "Value");
String y_axis_right_label = context.call["y_axis_right_label"].to_string();
String y_axis_left_format = first(context.call["y_axis_left_format"].to_string(), "number");
String y_axis_right_format = first(context.call["y_axis_right_format"].to_string(), "number");
<>
<div class="dashboard-panel">
<? if(title != "" || subtitle != "") { ?>
<div class="dashboard-panel-header">
<? if(title != "") { ?><h2><?= title ?></h2><? } ?>
<? if(subtitle != "") { ?><p><?= subtitle ?></p><? } ?>
</div>
<? } ?>
<canvas id="<?= canvas_id ?>" class="dashboard-chart-canvas" style="height: <?= std::to_string(height) ?>px"></canvas>
</div>
<script>
(function () {
if (typeof UTimeSeriesChart === 'undefined') return;
var chart = new UTimeSeriesChart(<?: json_encode(canvas_id) ?>, {
xAxisLabel: <?: json_encode(x_axis_label) ?>,
yAxisLeftLabel: <?: json_encode(y_axis_left_label) ?>,
yAxisRightLabel: <?: json_encode(y_axis_right_label) ?>,
yAxisLeftFormat: <?: json_encode(y_axis_left_format) ?>,
yAxisRightFormat: <?: json_encode(y_axis_right_format) ?>
});
chart.setData(<?: json_encode(context.call["series"]) ?>, <?: json_encode(context.call["x_labels"]) ?>);
window[<?: json_encode("chart_" + chart_id) ?>] = chart;
}());
</script>
</>
}
COMPONENT:SORTABLE_TABLE(Request& context)
{
starter_register_js("js/u-format.js", context);
starter_register_js("js/u-sortable-table.js", context);
String table_id = first(context.call["id"].to_string(), "sortable-table-" + std::to_string((u64)time()));
String title = context.call["title"].to_string();
String subtitle = context.call["subtitle"].to_string();
String empty_label = first(context.call["empty_label"].to_string(), "No data available");
DTree init_options;
init_options["storageKey"] = first(context.call["storage_key"].to_string(), "starter.sort." + table_id);
if(context.call["sort"]["column"].to_string() != "")
{
init_options["initialSort"]["column"] = context.call["sort"]["column"];
init_options["initialSort"]["direction"] = first(context.call["sort"]["direction"].to_string(), "asc");
}
<>
<div class="dashboard-panel">
<? if(title != "" || subtitle != "") { ?>
<div class="dashboard-panel-header">
<? if(title != "") { ?><h2><?= title ?></h2><? } ?>
<? if(subtitle != "") { ?><p><?= subtitle ?></p><? } ?>
</div>
<? } ?>
<div class="dashboard-table-wrap">
<table id="<?= table_id ?>" class="u-sortable-table">
<thead>
<tr>
<? context.call["columns"].each([&](DTree column, String key) {
String align = first(column["align"].to_string(), "left");
bool sortable = column["sortable"].to_string() == "" || column["sortable"].to_string() == "1";
?><th scope="col" class="align-<?= align ?>"<?= sortable ? "" : " data-sortable=\"false\"" ?>><?= first(column["label"].to_string(), column["key"].to_string(), "Column") ?></th><?
}); ?>
</tr>
</thead>
<tbody>
<? if(context.call["rows"].get_type_name() != "array" || context.call["rows"]["0"].get_type_name() != "array") { ?>
<tr data-empty-row="1"><td colspan="<?= context.call["columns"]._map.size() == 0 ? "1" : std::to_string(context.call["columns"]._map.size()) ?>" class="muted"><?= empty_label ?></td></tr>
<? } ?>
<? context.call["rows"].each([&](DTree row, String key) {
if(row.get_type_name() != "array")
return;
?><tr><?
context.call["columns"].each([&](DTree column, String ckey) {
String col_key = column["key"].to_string();
DTree formatted = data_format_value(row[col_key], row, column);
?><td class="align-<?= first(column["align"].to_string(), "left") ?>" data-sort-value="<?= formatted["sort"].to_string() ?>"><?= formatted["display"].to_string() ?></td><?
});
?></tr><?
}); ?>
</tbody>
</table>
</div>
</div>
<script>
(function () {
if (typeof USortableTable === 'undefined') return;
USortableTable.init(<?: json_encode(table_id) ?>, <?: json_encode(init_options) ?>);
}());
</script>
</>
}
COMPONENT:DATA_TABLE(Request& context)
{
String table_id = first(context.call["id"].to_string(), "data-grid-" + std::to_string((u64)time()));
starter_register_js("js/ag-grid/ag-grid-community.min.js", context);
starter_register_css("js/ag-grid/ag-grid.css", context);
starter_register_css("js/ag-grid/ag-theme-alpine.css", context);
DTree columns = context.call["columns"];
if(columns.get_type_name() != "array")
columns.set_array();
bool has_explicit_columns = columns.is_list() &&
columns._map.size() > 0 &&
columns._map.find("0") != columns._map.end() &&
columns["0"]["field"].to_string() != "";
if(!has_explicit_columns && context.call["items"]["0"].get_type_name() == "array")
{
context.call["items"]["0"].each([&](DTree value, String key) {
DTree col;
col["field"] = key;
col["headerName"] = key;
col["sortable"].set_bool(true);
col["filter"].set_bool(true);
col["resizable"].set_bool(true);
columns.push(col);
});
}
if(!columns.is_list())
{
DTree normalized_columns;
normalized_columns.set_array();
columns.each([&](DTree column, String key) {
if(column.get_type_name() == "array")
normalized_columns.push(column);
});
columns = normalized_columns;
}
DTree row_data = context.call["items"];
if(row_data.get_type_name() != "array")
row_data.set_array();
if(!row_data.is_list())
{
DTree normalized_rows;
normalized_rows.set_array();
row_data.each([&](DTree row, String key) {
if(row.get_type_name() == "array")
normalized_rows.push(row);
});
row_data = normalized_rows;
}
DTree grid_options;
grid_options["pagination"].set_bool(true);
grid_options["paginationPageSize"] = first(context.call["options"]["paginationPageSize"].to_string(), "20");
grid_options["paginationPageSizeSelector"].set_bool(false);
grid_options["suppressMenuHide"].set_bool(true);
grid_options["animateRows"].set_bool(true);
grid_options["columnDefs"] = columns;
grid_options["rowData"] = row_data;
<>
<div class="ag-grid-container" style="margin: 1rem 0;">
<div class="ag-grid-toolbar" style="display:flex;justify-content:space-between;align-items:center;margin-bottom:1rem;padding:0.75rem;background:var(--surface-elevated);border:1px solid var(--border);border-radius:0.5rem 0.5rem 0 0;border-bottom:none;">
<div style="display:flex;gap:1rem;align-items:center;flex:1;">
<span style="color: var(--text-secondary); font-size: 0.875rem; font-weight: 500;"><?= std::to_string(context.call["items"]._map.size()) ?> rows</span>
<input type="text" id="<?= table_id ?>-search" placeholder="Search all columns..." style="padding:0.5rem 0.75rem;border:1px solid var(--border);border-radius:0.375rem;background:var(--surface);color:var(--text-primary);font-size:0.875rem;width:250px;" />
</div>
<div style="display:flex;gap:0.5rem;">
<button id="<?= table_id ?>-export-csv" class="btn btn-outline">Export CSV</button>
<button id="<?= table_id ?>-clear-filters" class="btn btn-outline">Clear Filters</button>
</div>
</div>
<div id="<?= table_id ?>" class="ag-theme-alpine-dark" style="height: <?= first(context.call["height"].to_string(), "400px") ?>; width: 100%; border: 1px solid var(--border); border-radius: 0 0 0.5rem 0.5rem; overflow: hidden;"></div>
</div>
<script>
(function () {
if (typeof agGrid === 'undefined') return;
const gridOptions = <?: json_encode(grid_options) ?>;
const gridElement = document.getElementById(<?: json_encode(table_id) ?>);
if (!gridElement) return;
const gridApi = agGrid.createGrid(gridElement, gridOptions);
document.getElementById(<?: json_encode(table_id + "-search") ?>)?.addEventListener('input', function () {
gridApi.setQuickFilter(this.value);
});
document.getElementById(<?: json_encode(table_id + "-clear-filters") ?>)?.addEventListener('click', function () {
gridApi.setFilterModel(null);
gridApi.setQuickFilter('');
});
document.getElementById(<?: json_encode(table_id + "-export-csv") ?>)?.addEventListener('click', function () {
gridApi.exportDataAsCsv();
});
}());
</script>
</>
}
@@ -0,0 +1,604 @@
#load "../../lib/app.uce"
void marketing_default_features(DTree& features)
{
if(features.get_type_name() == "array" && features["0"]["title"].to_string() != "")
return;
DTree item;
item["icon"] = "⚡";
item["title"] = "Lightning Fast";
item["description"] = "Optimized for speed and performance with modern web technologies.";
features.push(item);
item.clear();
item["icon"] = "🎨";
item["title"] = "Beautiful Design";
item["description"] = "Carefully crafted components with attention to detail and user experience.";
features.push(item);
item.clear();
item["icon"] = "📱";
item["title"] = "Mobile First";
item["description"] = "Fully responsive design that works perfectly on all devices.";
features.push(item);
item.clear();
item["icon"] = "🔧";
item["title"] = "Easy to Use";
item["description"] = "Simple and intuitive component system for rapid development.";
features.push(item);
item.clear();
item["icon"] = "🛡️";
item["title"] = "Secure";
item["description"] = "Built with security best practices and server-side rendering first.";
features.push(item);
item.clear();
item["icon"] = "🚀";
item["title"] = "Scalable";
item["description"] = "Architecture designed to grow with your application needs.";
features.push(item);
}
COMPONENT:HERO_SECTION(Request& context)
{
String title = first(context.call["title"].to_string(), "Welcome to the Present");
String subtitle = first(context.call["subtitle"].to_string(), "Experience no-quite-modern web development with our cutting-edge framework");
String cta_text = first(context.call["cta_text"].to_string(), "Get Started");
String cta_link = first(context.call["cta_link"].to_string(), "#");
<>
<div class="hero-section">
<div class="hero-content">
<h1 class="hero-title"><?= title ?></h1>
<p class="hero-subtitle"><?= subtitle ?></p>
<div class="hero-actions">
<a href="<?= cta_link ?>" class="btn btn-large hero-cta"><?= cta_text ?></a>
<a href="#features" class="btn btn-outline btn-large">Learn More</a>
</div>
</div>
<div class="hero-visual">
<div class="floating-card">
<div class="card-header"></div>
<div class="card-content">
<div class="line"></div>
<div class="line short"></div>
<div class="line"></div>
</div>
</div>
<div class="floating-elements">
<div class="element element-1"></div>
<div class="element element-2"></div>
<div class="element element-3"></div>
</div>
</div>
</div>
<style>
.hero-section {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 4rem;
align-items: center;
min-height: 70vh;
padding: 4rem 2rem;
background: var(--bg-gradient);
color: var(--text-primary);
border-radius: var(--radius-xl);
margin-bottom: 4rem;
position: relative;
overflow: hidden;
}
.hero-section::before {
content: '';
position: absolute;
inset: 0;
background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox=\"0 0 100 100\"><defs><pattern id=\"grain\" width=\"100\" height=\"100\" patternUnits=\"userSpaceOnUse\"><circle cx=\"25\" cy=\"25\" r=\"1\" fill=\"white\" opacity=\"0.1\"/><circle cx=\"75\" cy=\"75\" r=\"1\" fill=\"white\" opacity=\"0.1\"/><circle cx=\"50\" cy=\"10\" r=\"0.5\" fill=\"white\" opacity=\"0.1\"/><circle cx=\"10\" cy=\"90\" r=\"0.5\" fill=\"white\" opacity=\"0.1\"/></pattern></defs><rect width=\"100%\" height=\"100%\" fill=\"url(%23grain)\"/></svg>');
}
.hero-content { position: relative; z-index: 2; }
.hero-title {
font-size: 3.5rem;
font-weight: 800;
margin-bottom: 1.5rem;
line-height: 1.1;
background: none;
color: var(--text-primary);
}
.hero-subtitle {
font-size: 1.25rem;
margin-bottom: 2rem;
opacity: 0.9;
line-height: 1.6;
}
.hero-actions {
display: flex;
gap: 1rem;
flex-wrap: wrap;
}
.hero-cta {
background: var(--surface);
color: var(--primary);
border: none;
}
.hero-visual {
position: relative;
display: flex;
justify-content: center;
align-items: center;
height: 400px;
}
.floating-card {
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 16px;
padding: 2rem;
width: 280px;
animation: float 6s ease-in-out infinite;
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
}
.card-header {
height: 60px;
background: linear-gradient(90deg, rgba(255,255,255,0.3), rgba(255,255,255,0.1));
border-radius: 8px;
margin-bottom: 1rem;
}
.card-content .line {
height: 12px;
background: rgba(255, 255, 255, 0.2);
border-radius: 6px;
margin-bottom: 8px;
}
.card-content .line.short { width: 60%; }
.floating-elements { position: absolute; width: 100%; height: 100%; }
.element {
position: absolute;
border-radius: 50%;
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(5px);
}
.element-1 { width: 60px; height: 60px; top: 20%; left: 10%; animation: float 4s ease-in-out infinite; }
.element-2 { width: 40px; height: 40px; top: 60%; right: 15%; animation: float 5s ease-in-out infinite reverse; }
.element-3 { width: 80px; height: 80px; bottom: 20%; left: 20%; animation: float 7s ease-in-out infinite; }
@keyframes float {
0%, 100% { transform: translateY(0px) rotate(0deg); }
50% { transform: translateY(-20px) rotate(10deg); }
}
@media (max-width: 768px) {
.hero-section { grid-template-columns: 1fr; text-align: center; padding: 3rem 1rem; gap: 2rem; }
.hero-title { font-size: 2.5rem; }
.hero-subtitle { font-size: 1.1rem; }
.hero-visual { height: 300px; }
.floating-card { width: 240px; padding: 1.5rem; }
}
</style>
<script>
$.ready(() => {
const heroTitle = document.querySelector('.hero-title');
if (!heroTitle || heroTitle.dataset.typed === '1') return;
heroTitle.dataset.typed = '1';
const text = heroTitle.textContent;
heroTitle.textContent = '';
let i = 0;
const typeWriter = () => {
heroTitle.textContent += text.charAt(i);
i += 1;
if (i < text.length) setTimeout(typeWriter, 24);
};
typeWriter();
});
</script>
</>
}
COMPONENT:FEATURES_GRID(Request& context)
{
DTree features = context.call["features"];
marketing_default_features(features);
<>
<div class="features-section" id="features">
<div class="features-header">
<h2>Why Choose Our Framework?</h2>
<p>Discover the powerful features that make development a breeze</p>
</div>
<div class="features-grid">
<? features.each([&](DTree feature, String key) {
?><div class="feature-card">
<div class="feature-icon"><?: feature["icon"].to_string() ?></div>
<h3 class="feature-title"><?= feature["title"].to_string() ?></h3>
<p class="feature-description"><?= feature["description"].to_string() ?></p>
<div class="feature-overlay"></div>
</div><?
}); ?>
</div>
</div>
<style>
.features-section { padding: 4rem 0; background: var(--bg-color); }
.features-header { text-align: center; margin-bottom: 4rem; }
.features-header h2 {
font-size: 2.5rem;
margin-bottom: 1rem;
background: linear-gradient(135deg, var(--primary), var(--secondary));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
.features-header p { font-size: 1.25rem; color: var(--text-secondary); max-width: 600px; margin: 0 auto; }
.features-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 2rem;
max-width: 1200px;
margin: 0 auto;
padding: 0 1rem;
}
.feature-card {
background: var(--surface);
padding: 2.5rem 2rem;
border-radius: var(--radius-xl);
text-align: center;
position: relative;
overflow: hidden;
border: 1px solid var(--border);
transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.feature-card:hover { transform: translateY(-8px) scale(1.02); box-shadow: var(--shadow-xl); border-color: var(--primary); }
.feature-card::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
height: 4px;
background: linear-gradient(90deg, var(--primary), var(--secondary));
transform: scaleX(0);
transition: transform 0.3s ease;
}
.feature-card:hover::before { transform: scaleX(1); }
.feature-icon {
font-size: 3rem;
margin-bottom: 1.5rem;
display: inline-block;
padding: 1rem;
background: linear-gradient(135deg, var(--primary), var(--secondary));
border-radius: 50%;
color: white;
box-shadow: var(--shadow-lg);
}
.feature-title { font-size: 1.5rem; font-weight: 600; margin-bottom: 1rem; color: var(--text-primary); }
.feature-description { color: var(--text-secondary); line-height: 1.6; }
.feature-overlay {
position: absolute;
inset: 0;
background: linear-gradient(135deg, var(--primary), var(--secondary));
opacity: 0;
transition: opacity 0.3s ease;
}
.feature-card:hover .feature-overlay { opacity: 0.05; }
@media (max-width: 768px) {
.features-grid { grid-template-columns: 1fr; gap: 1.5rem; padding: 0 0.5rem; }
.features-header h2 { font-size: 2rem; }
.feature-card { padding: 2rem 1.5rem; }
}
</style>
</>
}
COMPONENT:STATS_SECTION(Request& context)
{
DTree stats = context.call["stats"];
if(stats.get_type_name() != "array" || stats["0"]["label"].to_string() == "")
{
DTree item;
item["number"] = "99.9%"; item["label"] = "Uptime"; stats.push(item); item.clear();
item["number"] = "500ms"; item["label"] = "Average Response"; stats.push(item); item.clear();
item["number"] = "50K+"; item["label"] = "Active Users"; stats.push(item); item.clear();
item["number"] = "24/7"; item["label"] = "Support"; stats.push(item);
}
<>
<div class="stats-section">
<div class="stats-container">
<div class="stats-header">
<h2>Trusted by Developers Worldwide</h2>
<p>Join thousands of developers who have chosen our framework</p>
</div>
<div class="stats-grid">
<? stats.each([&](DTree stat, String key) {
?><div class="stat-item">
<div class="stat-number"><?= stat["number"].to_string() ?></div>
<div class="stat-label"><?= stat["label"].to_string() ?></div>
<div class="stat-bar"><div class="stat-fill"></div></div>
</div><?
}); ?>
</div>
</div>
</div>
<style>
.stats-section {
background: linear-gradient(135deg, var(--surface) 0%, var(--surface-elevated) 100%);
color: var(--text-primary);
padding: 4rem 0;
position: relative;
overflow: hidden;
border-top: 1px solid var(--border);
border-bottom: 1px solid var(--border);
}
.stats-container { max-width: 1200px; margin: 0 auto; padding: 0 1rem; position: relative; z-index: 2; }
.stats-header { text-align: center; margin-bottom: 4rem; }
.stats-header h2 { font-size: 2.5rem; margin-bottom: 1rem; font-weight: 700; }
.stats-header p { font-size: 1.25rem; opacity: 0.8; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 3rem; }
.stat-item {
text-align: center;
padding: 2rem;
background: var(--glass-bg);
backdrop-filter: blur(10px);
border: 1px solid var(--glass-border);
border-radius: var(--radius-xl);
}
.stat-number {
font-size: 3rem;
font-weight: 800;
margin-bottom: 0.5rem;
background: linear-gradient(135deg, var(--primary), var(--accent));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
.stat-label { font-size: 1.1rem; color: var(--text-secondary); margin-bottom: 1rem; font-weight: 500; }
.stat-bar { height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; }
.stat-fill { height: 100%; background: linear-gradient(90deg, var(--primary), var(--accent)); width: 100%; }
@media (max-width: 768px) {
.stats-grid { grid-template-columns: repeat(2, 1fr); gap: 1.5rem; }
.stats-header h2 { font-size: 2rem; }
}
@media (max-width: 480px) {
.stats-grid { grid-template-columns: 1fr; }
}
</style>
</>
}
COMPONENT:BRANDS_SHOWCASE(Request& context)
{
DTree logos = context.call["logos"];
if(logos.get_type_name() != "array" || logos["0"]["name"].to_string() == "")
{
DTree item;
for(s32 i = 1; i <= 6; i++)
{
item["name"] = "Brand " + std::to_string(i);
item["url"] = "img/cat0" + std::to_string(i) + ".jpg";
logos.push(item);
item.clear();
}
}
String title = first(context.call["title"].to_string(), "Trusted by Leading Companies");
<>
<div class="brands-section">
<div class="brands-container">
<h3 class="brands-title"><?= title ?></h3>
<div class="brands-grid">
<? logos.each([&](DTree logo, String key) {
?><div class="brand-item">
<img src="<?= logo["url"].to_string() ?>" alt="<?= logo["name"].to_string() ?>" />
</div><?
}); ?>
</div>
</div>
</div>
<style>
.brands-section { padding: 3rem 0; background: var(--surface); border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.brands-container { max-width: 1200px; margin: 0 auto; padding: 0 1rem; text-align: center; }
.brands-title { font-size: 1.125rem; color: var(--text-secondary); margin-bottom: 2rem; font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; }
.brands-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 2rem; align-items: center; }
.brand-item { display: flex; align-items: center; justify-content: center; padding: 1rem; border-radius: var(--radius); transition: all 0.3s ease; }
.brand-item:hover { transform: scale(1.05); background: var(--surface-hover); }
.brand-item img { max-width: 100%; height: auto; opacity: 0.6; transition: opacity 0.3s ease; filter: grayscale(100%); }
.brand-item:hover img { opacity: 1; filter: grayscale(0%); }
@media (max-width: 768px) {
.brands-grid { grid-template-columns: repeat(2, 1fr); gap: 1rem; }
.brands-section { padding: 2rem 0; }
}
</style>
</>
}
COMPONENT:TESTIMONIALS(Request& context)
{
DTree testimonials = context.call["testimonials"];
if(testimonials.get_type_name() != "array" || testimonials["0"]["name"].to_string() == "")
{
DTree item;
item["name"] = "Sarah Johnson"; item["role"] = "Senior Developer at TechCorp"; item["avatar"] = "img/cat01.jpg"; item["content"] = "This framework has revolutionized our development process."; item["rating"] = "5"; testimonials.push(item); item.clear();
item["name"] = "Michael Chen"; item["role"] = "CTO at StartupX"; item["avatar"] = "img/cat02.jpg"; item["content"] = "We switched from our legacy system and saw immediate improvements."; item["rating"] = "5"; testimonials.push(item); item.clear();
item["name"] = "Emily Rodriguez"; item["role"] = "Full Stack Developer"; item["avatar"] = "img/cat03.jpg"; item["content"] = "The documentation is excellent and the learning curve is gentle."; item["rating"] = "5"; testimonials.push(item);
}
<>
<div class="testimonials-section">
<div class="testimonials-container">
<div class="testimonials-header">
<h2>What Developers Say</h2>
<p>Don't just take our word for it - hear from the community</p>
</div>
<div class="testimonials-grid">
<? testimonials.each([&](DTree testimonial, String key) {
?><div class="testimonial-card">
<div class="testimonial-content">
<div class="quote-icon">"</div>
<p><?= testimonial["content"].to_string() ?></p>
<div class="stars"><? for(s32 i = 0; i < int_val(first(testimonial["rating"].to_string(), "5")); i++) { ?><span class="star">★</span><? } ?></div>
</div>
<div class="testimonial-author">
<img src="<?= testimonial["avatar"].to_string() ?>" alt="<?= testimonial["name"].to_string() ?>" class="avatar">
<div class="author-info">
<div class="author-name"><?= testimonial["name"].to_string() ?></div>
<div class="author-role"><?= testimonial["role"].to_string() ?></div>
</div>
</div>
</div><?
}); ?>
</div>
</div>
</div>
<style>
.testimonials-section { padding: 4rem 0; background: var(--bg-color); }
.testimonials-container { max-width: 1200px; margin: 0 auto; padding: 0 1rem; }
.testimonials-header { text-align: center; margin-bottom: 4rem; }
.testimonials-header h2 { font-size: 2.5rem; margin-bottom: 1rem; background: linear-gradient(135deg, var(--primary), var(--secondary)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
.testimonials-header p { font-size: 1.25rem; color: var(--text-secondary); }
.testimonials-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(350px, 1fr)); gap: 2rem; }
.testimonial-card { background: var(--surface); border-radius: var(--radius-xl); padding: 2.5rem 2rem; border: 1px solid var(--border); box-shadow: var(--shadow-md); }
.quote-icon { font-size: 4rem; color: var(--primary); opacity: 0.3; line-height: 1; margin-bottom: 1rem; font-family: serif; }
.testimonial-content p { font-size: 1.1rem; line-height: 1.7; color: var(--text-primary); margin-bottom: 1.5rem; }
.stars { display: flex; gap: 0.25rem; }
.star { color: #fbbf24; font-size: 1.25rem; }
.testimonial-author { display: flex; align-items: center; gap: 1rem; }
.avatar { width: 60px; height: 60px; border-radius: 50%; object-fit: cover; border: 3px solid var(--border); }
.author-name { font-weight: 600; color: var(--text-primary); margin-bottom: 0.25rem; }
.author-role { color: var(--text-secondary); font-size: 0.9rem; }
@media (max-width: 768px) {
.testimonials-grid { grid-template-columns: 1fr; gap: 1.5rem; }
.testimonial-card { padding: 2rem 1.5rem; }
.testimonials-header h2 { font-size: 2rem; }
}
</style>
</>
}
COMPONENT:PRICING_TABLE(Request& context)
{
DTree plans = context.call["plans"];
if(plans.get_type_name() != "array" || plans["0"]["name"].to_string() == "")
{
DTree plan;
DTree feature;
plan["name"] = "Starter"; plan["price"] = "Free"; plan["period"] = ""; plan["description"] = "Perfect for small projects and learning"; plan["cta"] = "Start Free"; feature = "Up to 3 projects"; plan["features"].push(feature); feature = "Community support"; plan["features"].push(feature); feature = "Basic components"; plan["features"].push(feature); plans.push(plan); plan.clear();
plan["name"] = "Pro"; plan["price"] = "$24"; plan["period"] = "/mo"; plan["description"] = "For serious products and teams"; plan["cta"] = "Choose Pro"; plan["popular"].set_bool(true); feature = "Unlimited projects"; plan["features"].push(feature); feature = "Priority support"; plan["features"].push(feature); feature = "Advanced components"; plan["features"].push(feature); plans.push(plan); plan.clear();
plan["name"] = "Enterprise"; plan["price"] = "$99"; plan["period"] = "/mo"; plan["description"] = "For larger teams and custom deployments"; plan["cta"] = "Contact Sales"; feature = "Custom integrations"; plan["features"].push(feature); feature = "Dedicated support"; plan["features"].push(feature); feature = "Architecture help"; plan["features"].push(feature); plans.push(plan);
}
<>
<div class="pricing-section">
<div class="pricing-container">
<div class="pricing-header">
<h2>Simple Pricing</h2>
<p>Choose the plan that fits your product stage.</p>
</div>
<div class="pricing-grid">
<? plans.each([&](DTree plan, String key) {
bool popular = plan["popular"].to_string() != "";
?><div class="pricing-card<?= popular ? " popular" : "" ?>">
<? if(popular) { ?><div class="popular-badge">Most Popular</div><? } ?>
<div class="plan-header">
<div class="plan-name"><?= plan["name"].to_string() ?></div>
<div class="plan-price">
<span class="price"><?= plan["price"].to_string() ?></span>
<span class="period"><?= plan["period"].to_string() ?></span>
</div>
<p class="plan-description"><?= plan["description"].to_string() ?></p>
</div>
<ul class="plan-features">
<? plan["features"].each([&](DTree feature, String feature_key) { ?><li><?= feature.to_string() ?></li><? }); ?>
</ul>
<div class="plan-footer">
<button class="btn <?= popular ? "btn-primary" : "btn-outline" ?> btn-large plan-cta"><?= first(plan["cta"].to_string(), "Choose Plan") ?></button>
</div>
</div><?
}); ?>
</div>
<div class="pricing-footer">
<p>All plans include a 30-day money-back guarantee. No setup fees.</p>
</div>
</div>
</div>
<style>
.pricing-section { padding: 5rem 0; background: var(--bg-color); }
.pricing-container { max-width: 1200px; margin: 0 auto; padding: 0 1rem; }
.pricing-header { text-align: center; margin-bottom: 4rem; }
.pricing-header h2 { font-size: 2.5rem; margin-bottom: 1rem; background: linear-gradient(135deg, var(--primary), var(--secondary)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
.pricing-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 2rem; margin-bottom: 3rem; }
.pricing-card { background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius-xl); padding: 2.5rem 2rem; position: relative; }
.pricing-card.popular { border-color: var(--primary); box-shadow: var(--shadow-lg); transform: scale(1.05); }
.popular-badge { position: absolute; top: -1rem; left: 50%; transform: translateX(-50%); background: linear-gradient(135deg, var(--primary), var(--secondary)); color: white; padding: 0.5rem 1.5rem; border-radius: 50px; font-size: 0.875rem; font-weight: 600; }
.plan-header { text-align: center; margin-bottom: 2rem; padding-bottom: 2rem; border-bottom: 1px solid var(--border); }
.plan-name { font-size: 1.5rem; font-weight: 600; margin-bottom: 1rem; color: var(--text-primary); }
.price { font-size: 3rem; font-weight: 800; color: var(--primary); }
.period { font-size: 1.125rem; color: var(--text-secondary); margin-left: 0.25rem; }
.plan-description { color: var(--text-secondary); line-height: 1.6; }
.plan-features { list-style: none; padding: 0; margin: 0 0 2rem; display: grid; gap: 0.75rem; }
.plan-features li { color: var(--text-primary); }
.plan-footer { text-align: center; }
.pricing-footer { text-align: center; color: var(--text-secondary); }
@media (max-width: 768px) {
.pricing-grid { grid-template-columns: 1fr; }
.pricing-card.popular { transform: none; }
}
</style>
</>
}
COMPONENT:CTA_SECTION(Request& context)
{
String title = first(context.call["title"].to_string(), "Ready to Get Started?");
String subtitle = first(context.call["subtitle"].to_string(), "Join thousands of developers building amazing applications with our framework.");
String cta_text = first(context.call["cta_text"].to_string(), "Start Building Now");
String cta_link = first(context.call["cta_link"].to_string(), "#");
String secondary_text = first(context.call["secondary_text"].to_string(), "View Documentation");
String secondary_link = first(context.call["secondary_link"].to_string(), "#");
<>
<div class="cta-section">
<div class="cta-container">
<div class="cta-content">
<h2 class="cta-title"><?= title ?></h2>
<p class="cta-subtitle"><?= subtitle ?></p>
<div class="cta-actions">
<a href="<?= cta_link ?>" class="btn btn-large cta-primary"><?= cta_text ?></a>
<a href="<?= secondary_link ?>" class="btn btn-outline btn-large cta-secondary"><?= secondary_text ?></a>
</div>
</div>
<div class="cta-visual">
<div class="floating-shapes">
<div class="shape shape-1"></div>
<div class="shape shape-2"></div>
<div class="shape shape-3"></div>
<div class="shape shape-4"></div>
</div>
</div>
</div>
</div>
<style>
.cta-section { background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%); color: white; padding: 5rem 0; position: relative; overflow: hidden; }
.cta-container { max-width: 1200px; margin: 0 auto; padding: 0 1rem; display: grid; grid-template-columns: 2fr 1fr; gap: 4rem; align-items: center; position: relative; z-index: 2; }
.cta-title { font-size: 3rem; font-weight: 800; margin-bottom: 1.5rem; line-height: 1.1; }
.cta-subtitle { font-size: 1.25rem; margin-bottom: 2.5rem; opacity: 0.9; line-height: 1.6; }
.cta-actions { display: flex; gap: 1.5rem; flex-wrap: wrap; }
.cta-primary { background: white; color: var(--primary); border: 2px solid white; }
.cta-secondary { border-color: rgba(255, 255, 255, 0.5); color: white; }
.cta-visual { position: relative; height: 300px; display: flex; align-items: center; justify-content: center; }
.floating-shapes { position: relative; width: 200px; height: 200px; }
.shape { position: absolute; background: rgba(255, 255, 255, 0.1); backdrop-filter: blur(5px); border: 1px solid rgba(255, 255, 255, 0.2); }
.shape-1 { width: 80px; height: 80px; border-radius: 20px; top: 0; left: 0; }
.shape-2 { width: 60px; height: 60px; border-radius: 50%; top: 20px; right: 0; }
.shape-3 { width: 100px; height: 40px; border-radius: 20px; bottom: 40px; left: 20px; }
.shape-4 { width: 50px; height: 50px; border-radius: 10px; bottom: 0; right: 30px; transform: rotate(45deg); }
@media (max-width: 968px) {
.cta-container { grid-template-columns: 1fr; text-align: center; gap: 2rem; }
.cta-title { font-size: 2.5rem; }
}
@media (max-width: 768px) {
.cta-section { padding: 3rem 0; }
.cta-title { font-size: 2rem; }
.cta-subtitle { font-size: 1.1rem; }
.cta-actions { justify-content: center; }
}
</style>
</>
}
@@ -0,0 +1,153 @@
#load "../../lib/app.uce"
COMPONENT(Request& context)
{
starter_boot(context);
String current_theme = context.cfg.get_by_path("theme/key").to_string();
String current_label = first(context.cfg.get_by_path("theme/label").to_string(), current_theme);
String route_path = context.var["starter"]["route"]["l_path"].to_string();
<>
<div id="theme-switcher" style="position: fixed; right: 1.5rem; bottom: 1.5rem; z-index: 9999; font-family: inherit;">
<style>
#theme-switcher .theme-launcher {
min-width: 56px;
height: 56px;
padding: 0 1rem;
border-radius: 999px;
background: var(--surface, #fff);
border: 1px solid var(--border, rgba(0,0,0,0.15));
box-shadow: var(--shadow-lg, 0 14px 32px rgba(0,0,0,0.18));
cursor: pointer;
transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease, background 0.2s ease;
display: inline-flex;
align-items: center;
justify-content: center;
gap: 0.65rem;
color: var(--text-primary, #111827);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
font: inherit;
font-size: 0.9rem;
font-weight: 700;
}
#theme-switcher .theme-launcher:hover {
transform: translateY(-2px);
box-shadow: var(--shadow-xl, 0 22px 42px rgba(0,0,0,0.22));
border-color: var(--primary, #2563eb);
background: var(--surface-elevated, var(--surface, #fff));
}
#theme-switcher .theme-launcher-label {
display: none;
white-space: nowrap;
}
#theme-switcher .theme-menu {
position: absolute;
right: 0;
bottom: 68px;
width: min(280px, calc(100vw - 2rem));
padding: 0.6rem;
border-radius: 14px;
border: 1px solid var(--border, rgba(0,0,0,0.15));
background: color-mix(in srgb, var(--surface, #fff) 92%, transparent 8%);
box-shadow: var(--shadow-xl, 0 22px 42px rgba(0,0,0,0.22));
}
#theme-switcher .theme-menu[hidden] {
display: none;
}
#theme-switcher .theme-menu-title {
margin: 0 0 0.45rem;
padding: 0.1rem 0.25rem 0.35rem;
color: var(--text-secondary, #6b7280);
font-size: 0.74rem;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
}
#theme-switcher .theme-menu-list {
display: grid;
gap: 0.35rem;
}
#theme-switcher .theme-option {
display: flex;
align-items: center;
justify-content: space-between;
gap: 0.75rem;
padding: 0.7rem 0.8rem;
border-radius: 10px;
border: 1px solid transparent;
color: var(--text-primary, #111827);
text-decoration: none;
font-size: 0.9rem;
font-weight: 600;
}
#theme-switcher .theme-option:hover {
background: color-mix(in srgb, var(--primary, #2563eb) 10%, transparent 90%);
border-color: color-mix(in srgb, var(--primary, #2563eb) 22%, transparent 78%);
text-decoration: none;
}
#theme-switcher .theme-option.is-active {
background: color-mix(in srgb, var(--primary, #2563eb) 16%, transparent 84%);
border-color: color-mix(in srgb, var(--primary, #2563eb) 28%, transparent 72%);
}
#theme-switcher .theme-option small {
color: var(--text-secondary, #6b7280);
font-size: 0.76rem;
font-weight: 600;
}
@media (min-width: 860px) {
#theme-switcher .theme-launcher-label {
display: inline;
}
}
</style>
<button id="theme-toggle" class="theme-launcher" aria-haspopup="true" aria-expanded="false" aria-label="Switch theme" title="Switch Theme" type="button">
<i class="fas fa-palette" aria-hidden="true"></i>
<span class="theme-launcher-label"><?= current_label ?></span>
</button>
<div id="theme-menu" class="theme-menu" hidden>
<div class="theme-menu-title">Available Themes</div>
<div class="theme-menu-list">
<? context.cfg.get_by_path("theme/options").each([&](DTree theme_info, String theme_key) {
StringMap params;
params["theme"] = theme_key;
String href = starter_link(route_path == "index" ? "" : route_path, params, context);
?><a class="theme-option<?= theme_key == current_theme ? " is-active" : "" ?>" href="<?= href ?>">
<span><?= theme_info["label"].to_string() ?></span>
<? if(theme_key == current_theme) { ?><small>Active</small><? } ?>
</a><?
}); ?>
</div>
</div>
</div>
<script>
(function() {
const themeToggle = document.getElementById('theme-toggle');
const themeMenu = document.getElementById('theme-menu');
if (!themeToggle || !themeMenu) return;
themeToggle.addEventListener('click', function() {
const isOpen = !themeMenu.hasAttribute('hidden');
themeMenu.toggleAttribute('hidden', isOpen);
themeToggle.setAttribute('aria-expanded', isOpen ? 'false' : 'true');
});
document.addEventListener('click', function(event) {
if (!themeMenu.hasAttribute('hidden') && !document.getElementById('theme-switcher').contains(event.target)) {
themeMenu.setAttribute('hidden', 'hidden');
themeToggle.setAttribute('aria-expanded', 'false');
}
});
document.addEventListener('keydown', function(event) {
if (event.key === 'Escape' && !themeMenu.hasAttribute('hidden')) {
themeMenu.setAttribute('hidden', 'hidden');
themeToggle.setAttribute('aria-expanded', 'false');
}
});
}());
</script>
</>
}
@@ -0,0 +1,91 @@
#load "helpers.uce"
COMPONENT(Request& context)
{
starter_register_js("components/gauges/common.js", context);
starter_register_css("themes/common/css/gauges.css", context);
String gauge_id = first(context.call["id"].to_string(), "arcgauge-" + std::to_string((u64)time()));
String title = context.call["title"].to_string();
String subtitle = context.call["subtitle"].to_string();
String style = context.call["style"].to_string();
DTree scale = context.call["scale"];
<>
<div class="arcgauge-set" id="<?= gauge_attr_id(gauge_id) ?>" style="<?= style ?>">
<? if(title != "") { ?>
<div class="arcgauge-set-header">
<h3><?= title ?></h3>
<? if(subtitle != "") { ?><p><?= subtitle ?></p><? } ?>
</div>
<? } ?>
<div class="arcgauge-grid">
<? context.call["items"].each([&](DTree item, String item_id_raw) {
DTree merged = scale;
item.each([&](DTree value, String key) { merged[key] = value; });
String item_id = gauge_attr_id(item_id_raw);
f64 value = float_val(first(merged["value"].to_string(), "0"));
f64 max_value = float_val(first(merged["max"].to_string(), "100"));
s32 precision = (s32)int_val(first(merged["precision"].to_string(), "1"));
f64 pct = max_value > 0.0 ? gauge_clamp_value((value / max_value) * 100.0, 0.0, 100.0) : 0.0;
f64 arc_length = round((pct / 100.0) * 157.08 * 10.0) / 10.0;
String resolved_color = "";
if(merged["color"].get_type_name() == "array")
resolved_color = gauge_range_color(merged["color"], value);
else
resolved_color = merged["color"].to_string();
if(resolved_color == "")
{
if(pct >= 85.0)
resolved_color = "var(--error, #ef4444)";
else if(pct >= 60.0)
resolved_color = "var(--warning, #f59e0b)";
else
resolved_color = "var(--success, #10b981)";
}
String display_value = gauge_format_number(value, precision) + merged["unit"].to_string();
String watermark_prefix = merged["watermark_prefix"].to_string();
?><section class="arcgauge-card">
<div class="arcgauge-label"><?= first(merged["label"].to_string(), item_id_raw) ?></div>
<svg class="arcgauge-svg" viewBox="0 0 120 68" aria-hidden="true">
<path class="arcgauge-track" d="M 10 60 A 50 50 0 0 1 110 60" fill="none" stroke-width="5" stroke-linecap="round"/>
<path id="<?= gauge_attr_id(gauge_id) ?>-<?= item_id ?>-arc" class="arcgauge-arc-dyn" d="M 10 60 A 50 50 0 0 1 110 60" fill="none" stroke="<?= resolved_color ?>" stroke-width="5" stroke-linecap="round" stroke-dasharray="<?= std::to_string(arc_length) ?> 157.08"/>
<? if(watermark_prefix != "") { ?>
<line id="<?= gauge_attr_id(watermark_prefix) ?>WmLo" class="arcgauge-watermark arcgauge-watermark-lo" x1="0" y1="0" x2="0" y2="0" opacity="0"/>
<line id="<?= gauge_attr_id(watermark_prefix) ?>WmHi" class="arcgauge-watermark arcgauge-watermark-hi" x1="0" y1="0" x2="0" y2="0" opacity="0"/>
<? } ?>
<text id="<?= gauge_attr_id(gauge_id) ?>-<?= item_id ?>-text" class="arcgauge-value" x="60" y="47" text-anchor="middle"><?= display_value ?></text>
<text class="arcgauge-caption" x="60" y="62" text-anchor="middle"><?= first(merged["caption"].to_string(), "") ?></text>
</svg>
<div class="arcgauge-meta" id="<?= gauge_attr_id(gauge_id) ?>-<?= item_id ?>-meta"><?= first(merged["meta"].to_string(), "--") ?></div>
</section><?
}); ?>
</div>
</div>
<? if(context.call["listen"].to_string() != "") { ?>
<script>
window.ArcgaugeComponents = window.ArcgaugeComponents || {
start_listen : function(prop) {
$.events.on('value-broadcast', function(data) {
if(!prop.items || !prop.items[data.name]) return;
const item = Object.assign({}, prop.scale || {}, prop.items[data.name]);
GaugeComponents.updateArcGauge({
arcId: prop.id + '-' + data.name + '-arc',
textId: prop.id + '-' + data.name + '-text',
metaId: prop.id + '-' + data.name + '-meta',
value: Number(data.value),
max: Number(item.max || 100),
suffix: item.unit || '',
precision: item.precision,
watermarkPrefix: item.watermark_prefix || data.name,
color: item.color,
meta: data.meta != null ? data.meta : null
});
});
}
};
ArcgaugeComponents.start_listen(<?: json_encode(context.call, '\'') ?>);
</script>
<? } ?>
</>
}
+95
View File
@@ -0,0 +1,95 @@
.horizontal .progressbar-item {
display: flex;
min-width: 100%;
padding: 5px;
}
.progressbar-container.vertical {
display: flex;
}
.vertical .progressbar-item {
display: flex;
flex-direction: column;
justify-content: flex-end;
padding: 5px;
text-align: center;
}
.progressbar-label {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
font-weight: bold;
}
.horizontal .progressbar-label, .horizontal .progressbar-value {
flex: 0 0 auto;
margin-right: 10px;
}
.horizontal .progressbar-label {
min-width: 50px;
}
.vertical .progressbar-label {
text-align: center;
}
.horizontal .progressbar-value {
min-width: 50px;
text-align: right;
}
.progressbar-background {
flex: 1;
background: var(--bg-color);
padding: 4px;
display: flex;
}
.vertical .progressbar-background {
flex-direction: column;
justify-content: flex-end;
}
.progressbar-bar {
transition: all 0.3s ease;
}
.progressbar-marker {
position: absolute;
z-index: 10;
opacity: 0.5;
background: var(--text-color, #333);
}
.progressbar-marker:hover {
opacity: 1;
}
.horizontal .progressbar-marker {
border-width: 0 2px 0 2px;
height: 100%;
top: 0;
min-width: 4px;
}
.vertical .progressbar-marker {
border-width: 2px 0 2px 0;
width: 100%;
left: 0;
min-height: 4px;
}
.progressbar-background {
position: relative;
}
.needlegauge-svg .needle {
transition: all 0.3s ease;
}
.needlegauge-item {
display: inline-block;
}
+121
View File
@@ -0,0 +1,121 @@
// common code for gauges components
window.GaugeComponents = window.GaugeComponents || {};
Object.assign(window.GaugeComponents, { // as a namespace
// utility functions
clampValue: function(value, min, max) {
return Math.min(max, Math.max(min, value));
},
pickEntryFromRange: function(ranges, value) {
if (!Array.isArray(ranges)) return null;
for (const entry of ranges) {
if (value >= entry.from && value <= entry.to) return entry;
}
return null;
},
/**
* Creates an SVG element with namespace
*/
createSVGElement: function(tagName, attributes = {}) {
const element = document.createElementNS('http://www.w3.org/2000/svg', tagName);
Object.entries(attributes).forEach(([key, value]) => {
element.setAttribute(key, value);
});
return element;
},
/**
* Gets CSS custom property value from computed styles
*/
getCSSVar: function(varName) {
return getComputedStyle(document.documentElement).getPropertyValue(varName).trim();
},
resolveColor: function(colorSpec, value, pct) {
if (Array.isArray(colorSpec)) {
const match = this.pickEntryFromRange(colorSpec, value);
if (match && match.color) return match.color;
}
if (typeof colorSpec === 'string' && colorSpec !== '') return colorSpec;
if (pct < 60) return this.getCSSVar('--success') || '#10b981';
if (pct < 85) return this.getCSSVar('--warning') || '#f59e0b';
return this.getCSSVar('--error') || '#ef4444';
},
formatValue: function(value, precision, suffix) {
const numericValue = Number(value);
const normalizedPrecision = Number.isFinite(precision) ? precision : 1;
if (!Number.isFinite(numericValue)) return '--';
return numericValue.toFixed(normalizedPrecision) + (suffix || '');
},
gaugeArcPoint: function(pct, radius = 50) {
const angle = Math.PI - (pct / 100) * Math.PI;
return {
x: 60 + radius * Math.cos(angle),
y: 60 - radius * Math.sin(angle),
};
},
updateWatermark: function(prefix, pct) {
const now = Date.now();
this._watermarks = this._watermarks || {};
let watermark = this._watermarks[prefix];
const resetWindow = 10 * 60 * 1000;
if (!watermark || (now - watermark.resetTs) > resetWindow) {
watermark = { lo: pct, hi: pct, resetTs: now };
this._watermarks[prefix] = watermark;
} else {
if (pct < watermark.lo) watermark.lo = pct;
if (pct > watermark.hi) watermark.hi = pct;
}
return watermark;
},
renderWatermarkTick: function(lineId, pct) {
const line = document.getElementById(lineId);
if (!line) return;
if (pct == null) {
line.setAttribute('opacity', '0');
return;
}
const outer = this.gaugeArcPoint(pct, 53);
const inner = this.gaugeArcPoint(pct, 43);
line.setAttribute('x1', outer.x.toFixed(1));
line.setAttribute('y1', outer.y.toFixed(1));
line.setAttribute('x2', inner.x.toFixed(1));
line.setAttribute('y2', inner.y.toFixed(1));
line.setAttribute('opacity', '0.7');
},
updateArcGauge: function(options) {
const value = Number(options.value);
const max = Number(options.max || 100);
const normalizedValue = Number.isFinite(value) ? value : 0;
const pct = this.clampValue(max === 0 ? 0 : (normalizedValue / max) * 100, 0, 100);
const arcLength = (pct / 100) * 157.08;
const arc = document.getElementById(options.arcId);
const text = document.getElementById(options.textId);
const meta = options.metaId ? document.getElementById(options.metaId) : null;
if (arc) {
arc.setAttribute('stroke-dasharray', arcLength.toFixed(1) + ' 157.08');
arc.setAttribute('stroke', this.resolveColor(options.color, normalizedValue, pct));
}
if (text) {
text.textContent = this.formatValue(normalizedValue, options.precision, options.suffix);
}
if (meta && options.meta != null) {
meta.textContent = options.meta;
}
if (options.watermarkPrefix) {
const watermark = this.updateWatermark(options.watermarkPrefix, pct);
this.renderWatermarkTick(options.watermarkPrefix + 'WmLo', watermark.lo);
this.renderWatermarkTick(options.watermarkPrefix + 'WmHi', watermark.hi);
}
}
});
@@ -0,0 +1,71 @@
#load "../../lib/app.uce"
#include <math.h>
f64 gauge_clamp_value(f64 value, f64 min_value, f64 max_value)
{
return(std::max(min_value, std::min(max_value, value)));
}
f64 gauge_pi()
{
return(3.14159265358979323846);
}
String gauge_string_attr(String value)
{
return(html_escape(value));
}
String gauge_attr_id(String value)
{
return(ascii_safe_name(value));
}
String gauge_range_color(DTree ranges, f64 value)
{
String matched = "";
ranges.each([&](DTree range, String key) {
f64 from_value = float_val(first(range["from"].to_string(), "-999999999"));
f64 to_value = float_val(first(range["to"].to_string(), "999999999"));
if(value >= from_value && value <= to_value && matched == "")
matched = range["color"].to_string();
});
return(matched);
}
String gauge_arc_path(f64 cx, f64 cy, f64 radius, f64 start_angle, f64 end_angle)
{
f64 start_x = cx + cos(start_angle) * radius;
f64 start_y = cy + sin(start_angle) * radius;
f64 end_x = cx + cos(end_angle) * radius;
f64 end_y = cy + sin(end_angle) * radius;
s32 large_arc = fabs(end_angle - start_angle) > gauge_pi() ? 1 : 0;
s32 sweep = end_angle >= start_angle ? 1 : 0;
return(
"M " + std::to_string(start_x) + " " + std::to_string(start_y) +
" A " + std::to_string(radius) + " " + std::to_string(radius) +
" 0 " + std::to_string(large_arc) + " " + std::to_string(sweep) +
" " + std::to_string(end_x) + " " + std::to_string(end_y)
);
}
String gauge_circle_segment_svg(f64 cx, f64 cy, f64 radius, f64 start_angle, f64 end_angle, String stroke, f64 stroke_width, String fill, String style)
{
String path_d = gauge_arc_path(cx, cy, radius, start_angle, end_angle);
return(
"<path d=\"" + gauge_string_attr(path_d) +
"\" fill=\"" + gauge_string_attr(fill) +
"\" stroke=\"" + gauge_string_attr(stroke) +
"\" stroke-width=\"" + gauge_string_attr(std::to_string(stroke_width)) +
"\" stroke-linecap=\"round\"" +
(style != "" ? " style=\"" + gauge_string_attr(style) + "\"" : "") +
"/>"
);
}
String gauge_format_number(f64 value, s32 precision)
{
char buf[64];
snprintf(buf, sizeof(buf), ("%." + std::to_string(std::max(0, precision)) + "f").c_str(), value);
return(String(buf));
}
@@ -0,0 +1,144 @@
#load "helpers.uce"
COMPONENT(Request& context)
{
starter_register_js("components/gauges/common.js", context);
starter_register_css("themes/common/css/gauges.css", context);
String gauge_id = first(context.call["id"].to_string(), "needlegauge-" + std::to_string((u64)time()));
String style = context.call["style"].to_string();
String title = context.call["title"].to_string();
String subtitle = context.call["subtitle"].to_string();
f64 size = float_val(first(context.call["size"].to_string(), "200"));
DTree scale = context.call["scale"];
f64 scale_angle_start = float_val(first(scale["angle_start"].to_string(), std::to_string(-gauge_pi())));
f64 scale_angle_end = float_val(first(scale["angle_end"].to_string(), "0"));
f64 img_height = float_val(first(context.call["img_height"].to_string(), std::to_string(size * std::max(cos(scale_angle_start), cos(scale_angle_end)))));
<>
<section class="gauge-set needlegauge-set" id="<?= gauge_attr_id(gauge_id) ?>" style="<?= style ?>">
<? if(title != "") { ?>
<div class="gauge-set-header">
<h3><?= title ?></h3>
<? if(subtitle != "") { ?><p><?= subtitle ?></p><? } ?>
</div>
<? } ?>
<div class="needlegauge-grid">
<? context.call["items"].each([&](DTree item, String item_id_raw) {
DTree merged = scale;
item.each([&](DTree value, String key) { merged[key] = value; });
String item_id = gauge_attr_id(item_id_raw);
String label = first(merged["label"].to_string(), item_id_raw);
String tooltip = merged["tooltip"].to_string();
String unit = merged["unit"].to_string();
f64 min_value = float_val(first(merged["min"].to_string(), "0"));
f64 max_value = float_val(first(merged["max"].to_string(), "100"));
f64 value = float_val(first(merged["value"].to_string(), "0"));
f64 vrange = max_value - min_value;
if(vrange == 0)
vrange = 1;
f64 angle_start = float_val(first(merged["angle_start"].to_string(), std::to_string(-gauge_pi())));
f64 angle_end = float_val(first(merged["angle_end"].to_string(), "0"));
f64 pct_value = gauge_clamp_value((value - min_value) / vrange, 0.0, 1.0);
f64 needle_angle = -gauge_pi() + angle_start + (pct_value * (angle_end - angle_start));
String needle_color = first(merged["color"].to_string(), "#888888");
if(merged["color"].get_type_name() == "array")
needle_color = first(gauge_range_color(merged["color"], value), "#888888");
String tick_color = first(merged["tick-color"].to_string(), "#888888");
f64 tick_interval = float_val(first(merged["ticks-every"].to_string(), std::to_string(vrange / 20.0)));
if(tick_interval == 0)
tick_interval = std::max(1.0, vrange / 20.0);
f64 label_interval = float_val(first(merged["value-labels-every"].to_string(), std::to_string(vrange / 4.0)));
if(label_interval == 0)
label_interval = std::max(1.0, vrange / 4.0);
String ticks_html = "";
for(f64 v = min_value; v <= max_value + 0.0001; v += tick_interval)
{
f64 angle = angle_start + ((v - min_value) / vrange) * (angle_end - angle_start);
f64 x1 = size / 2.0 + cos(angle) * size * 0.38;
f64 y1 = size / 2.0 + sin(angle) * size * 0.38;
f64 x2 = size / 2.0 + cos(angle) * size * 0.41;
f64 y2 = size / 2.0 + sin(angle) * size * 0.41;
ticks_html += "<line x1=\"" + gauge_string_attr(std::to_string(x1)) + "\" y1=\"" + gauge_string_attr(std::to_string(y1)) +
"\" x2=\"" + gauge_string_attr(std::to_string(x2)) + "\" y2=\"" + gauge_string_attr(std::to_string(y2)) +
"\" stroke=\"" + gauge_string_attr(tick_color) + "\" stroke-width=\"1\"/>";
}
for(f64 v = min_value; v <= max_value + 0.0001; v += label_interval)
{
f64 angle = angle_start + ((v - min_value) / vrange) * (angle_end - angle_start);
f64 x1 = size / 2.0 + cos(angle) * size * 0.35;
f64 y1 = size / 2.0 + sin(angle) * size * 0.35;
f64 x2 = size / 2.0 + cos(angle) * size * 0.41;
f64 y2 = size / 2.0 + sin(angle) * size * 0.41;
ticks_html += "<line x1=\"" + gauge_string_attr(std::to_string(x1)) + "\" y1=\"" + gauge_string_attr(std::to_string(y1)) +
"\" x2=\"" + gauge_string_attr(std::to_string(x2)) + "\" y2=\"" + gauge_string_attr(std::to_string(y2)) +
"\" stroke=\"" + gauge_string_attr(tick_color) + "\" stroke-width=\"3\"/>";
f64 lx = size / 2.0 + cos(angle) * size * 0.45;
f64 ly = size / 2.0 + sin(angle) * size * 0.45;
String label_value = std::to_string((s64)round(v));
ticks_html += "<text x=\"" + gauge_string_attr(std::to_string(lx)) + "\" y=\"" + gauge_string_attr(std::to_string(ly)) +
"\" text-anchor=\"middle\" dominant-baseline=\"central\" font-size=\"10\" fill=\"" + gauge_string_attr(tick_color) + "\">" +
html_escape(label_value) + "</text>";
}
String segments_html = "";
if(merged["color"].get_type_name() == "array")
{
merged["color"].each([&](DTree range, String key) {
f64 range_from = std::max(float_val(first(range["from"].to_string(), std::to_string(min_value))), min_value);
f64 range_to = std::min(float_val(first(range["to"].to_string(), std::to_string(max_value))), max_value);
f64 angle_from = angle_start + ((range_from - min_value) / vrange) * (angle_end - angle_start);
f64 angle_to = angle_start + ((range_to - min_value) / vrange) * (angle_end - angle_start);
segments_html += gauge_circle_segment_svg(size / 2.0, size / 2.0, size * 0.4, angle_from, angle_to, first(range["color"].to_string(), "rgba(120,120,120,0.5)"), 8.0, "rgba(0,0,0,0)", "opacity:0.25");
});
}
else
{
segments_html = gauge_circle_segment_svg(size / 2.0, size / 2.0, size * 0.4, angle_start, angle_end, tick_color, 8.0, "rgba(0,0,0,0)", "opacity:0.25");
}
?><section class="gauge-card needlegauge-card">
<div class="gauge-metric-label needlegauge-label-head"><?= label ?></div>
<div class="needlegauge-visual">
<svg id="<?= gauge_attr_id(gauge_id) ?>-<?= item_id ?>-svg" width="<?= std::to_string((s32)round(size)) ?>" height="<?= std::to_string((s32)round(img_height)) ?>" class="needlegauge-svg"
viewBox="0 0 <?= std::to_string((s32)round(size)) ?> <?= std::to_string((s32)round(img_height)) ?>">
<?: segments_html ?>
<g class="ticks"><?: ticks_html ?></g>
<line id="<?= gauge_attr_id(gauge_id) ?>-<?= item_id ?>-needle" class="needle"
x1="<?= std::to_string(size * 0.55) ?>" y1="<?= std::to_string(size * 0.5) ?>" x2="<?= std::to_string(size * 0.1) ?>" y2="<?= std::to_string(size * 0.5) ?>"
stroke="<?= needle_color ?>" stroke-width="3" stroke-linecap="round"
style="transform-origin: <?= std::to_string(size / 2.0) ?>px <?= std::to_string(size / 2.0) ?>px; transform: rotate(<?= std::to_string(needle_angle) ?>rad); transition: transform 0.3s ease;"/>
<circle cx="<?= std::to_string(size / 2.0) ?>" cy="<?= std::to_string(size / 2.0) ?>" r="6" fill="<?= needle_color ?>"/>
</svg>
</div>
<div class="needlegauge-info">
<div class="gauge-metric-value needlegauge-value" id="<?= gauge_attr_id(gauge_id) ?>-<?= item_id ?>-value" title="<?= tooltip ?>"><?= merged["value"].to_string() + unit ?></div>
<? if(tooltip != "") { ?><div class="gauge-metric-meta needlegauge-meta"><?= tooltip ?></div><? } ?>
</div>
</section><?
}); ?>
</div>
</section>
<? if(context.call["listen"].to_string() != "") { ?>
<script>
window.NeedlegaugeComponents = window.NeedlegaugeComponents || {
start_listen : function(prop) {
$.events.on('value-broadcast', function(data) {
if(!prop.items || !prop.items[data.name]) return;
let item = Object.assign({}, prop.scale || {}, prop.items[data.name]);
let valueEl = document.getElementById(prop.id + '-' + data.name + '-value');
let needle = document.getElementById(prop.id + '-' + data.name + '-needle');
if(valueEl) valueEl.textContent = data.value + (item.unit || '');
let min = Number(item.min || 0);
let max = Number(item.max || 100);
let pctValue = GaugeComponents.clampValue((Number(data.value) - min) / ((max - min) || 1), 0, 1);
let angleStart = Number(item.angle_start != null ? item.angle_start : -Math.PI);
let angleEnd = Number(item.angle_end != null ? item.angle_end : 0);
let angle = -Math.PI + angleStart + (pctValue * (angleEnd - angleStart));
if(needle) needle.style.transform = 'rotate(' + angle + 'rad)';
});
}
};
NeedlegaugeComponents.start_listen(<?: json_encode(context.call, '\'') ?>);
</script>
<? } ?>
</>
}
@@ -0,0 +1,168 @@
#load "helpers.uce"
COMPONENT(Request& context)
{
starter_register_js("components/gauges/common.js", context);
starter_register_css("themes/common/css/gauges.css", context);
String gauge_id = first(context.call["id"].to_string(), "progressbar-" + std::to_string((u64)time()));
String style = context.call["style"].to_string();
String item_style = context.call["item-style"].to_string();
String label_style = context.call["label-style"].to_string();
String value_style = context.call["value-style"].to_string();
String bar_style = context.call["bar-style"].to_string();
String title = context.call["title"].to_string();
String subtitle = context.call["subtitle"].to_string();
String layout = first(context.call["layout"].to_string(), "horizontal");
String bar_color_default = context.call["bar-color"].to_string();
DTree scale = context.call["scale"];
DTree markers = context.call["markers"];
StringList default_palette;
default_palette.push_back("var(--success, #10b981)");
default_palette.push_back("var(--primary, #60a5fa)");
default_palette.push_back("var(--accent, #22d3ee)");
default_palette.push_back("var(--warning, #f59e0b)");
u32 auto_color_counter = 0;
<>
<section class="gauge-set progressbar-set progressbar-set-<?= gauge_attr_id(layout) ?>" id="<?= gauge_attr_id(gauge_id) ?>" style="<?= style ?>">
<? if(title != "") { ?>
<div class="gauge-set-header">
<h3><?= title ?></h3>
<? if(subtitle != "") { ?><p><?= subtitle ?></p><? } ?>
</div>
<? } ?>
<? if(layout == "horizontal") { ?>
<div class="progressbar-grid progressbar-grid-horizontal">
<? context.call["items"].each([&](DTree bar, String bar_id) {
DTree merged = scale;
bar.each([&](DTree item, String key) { merged[key] = item; });
String item_id = gauge_attr_id(bar_id);
String merged_item_style = item_style;
if(merged["style"].to_string() != "")
merged_item_style += (merged_item_style != "" ? ";" : "") + merged["style"].to_string();
String tooltip = merged["tooltip"].to_string();
String before_html = merged["before"].to_string();
String after_html = merged["after"].to_string();
String unit = merged["unit"].to_string();
String label = first(merged["label"].to_string(), bar_id);
f64 min_value = float_val(first(merged["min"].to_string(), "0"));
f64 max_value = float_val(first(merged["max"].to_string(), "100"));
f64 value = float_val(first(merged["value"].to_string(), "0"));
f64 vrange = max_value - min_value;
if(vrange == 0)
vrange = 1;
f64 pct_value = gauge_clamp_value(((value - min_value) / vrange) * 100.0, 0.0, 100.0);
String resolved_color = merged["color"].to_string();
if(merged["color"].get_type_name() == "array")
resolved_color = gauge_range_color(merged["color"], value);
if(resolved_color == "")
resolved_color = first(bar_color_default, default_palette[auto_color_counter++ % default_palette.size()]);
String opacity = first(merged["opacity"].to_string(), "0.75");
?><section class="gauge-card progressbar-card progressbar-card-horizontal" id="<?= gauge_attr_id(gauge_id) ?>-<?= item_id ?>"
title="<?= tooltip ?>"
style="<?= merged_item_style ?>">
<?: before_html ?>
<div class="progressbar-card-head">
<div class="gauge-metric-label progressbar-label" style="<?= label_style ?>"><?= label ?></div>
<div class="gauge-metric-value progressbar-value" style="<?= value_style ?>" id="<?= gauge_attr_id(gauge_id) ?>-<?= item_id ?>-value"><?= merged["value"].to_string() + unit ?></div>
</div>
<div class="progressbar-background progressbar-background-horizontal">
<div class="progressbar-bar" id="<?= gauge_attr_id(gauge_id) ?>-<?= item_id ?>-bar"
style="background-color: <?= resolved_color ?>; <?= bar_style ?> opacity: <?= opacity ?>; width: <?= std::to_string(pct_value) ?>%;"></div>
<? markers.each([&](DTree marker, String marker_id) {
f64 marker_value = float_val(first(marker["value"].to_string(), "0"));
f64 marker_pct = gauge_clamp_value(((marker_value - min_value) / vrange) * 100.0, 0.0, 100.0);
String marker_color = first(marker["color"].to_string(), "var(--primary-light)");
?><div class="progressbar-marker"
title="<?= marker["label"].to_string() ?>"
style="left: <?= std::to_string(marker_pct) ?>%; background: <?= marker_color ?>;"></div><?
}); ?>
</div>
<? if(tooltip != "") { ?><div class="gauge-metric-meta progressbar-meta"><?= tooltip ?></div><? } ?>
<?: after_html ?>
</section><?
}); ?>
</div>
<? } else { ?>
<div class="progressbar-grid progressbar-grid-vertical" style="--progressbar-height: <?= first(context.call["height"].to_string(), "240") ?>px;">
<? context.call["items"].each([&](DTree bar, String bar_id) {
DTree merged = scale;
bar.each([&](DTree item, String key) { merged[key] = item; });
String item_id = gauge_attr_id(bar_id);
String merged_item_style = item_style;
if(merged["style"].to_string() != "")
merged_item_style += (merged_item_style != "" ? ";" : "") + merged["style"].to_string();
String tooltip = merged["tooltip"].to_string();
String before_html = merged["before"].to_string();
String after_html = merged["after"].to_string();
String unit = merged["unit"].to_string();
String label = first(merged["label"].to_string(), bar_id);
f64 min_value = float_val(first(merged["min"].to_string(), "0"));
f64 max_value = float_val(first(merged["max"].to_string(), "100"));
f64 value = float_val(first(merged["value"].to_string(), "0"));
f64 vrange = max_value - min_value;
if(vrange == 0)
vrange = 1;
f64 pct_value = gauge_clamp_value(((value - min_value) / vrange) * 100.0, 0.0, 100.0);
String resolved_color = merged["color"].to_string();
if(merged["color"].get_type_name() == "array")
resolved_color = gauge_range_color(merged["color"], value);
if(resolved_color == "")
resolved_color = first(bar_color_default, default_palette[auto_color_counter++ % default_palette.size()]);
String opacity = first(merged["opacity"].to_string(), "0.75");
?><section class="gauge-card progressbar-card progressbar-card-vertical" id="<?= gauge_attr_id(gauge_id) ?>-<?= item_id ?>"
title="<?= tooltip ?>"
style="<?= merged_item_style ?>">
<?: before_html ?>
<div class="gauge-metric-label progressbar-label" style="<?= label_style ?>"><?= label ?></div>
<div class="progressbar-background progressbar-background-vertical">
<div class="progressbar-bar" id="<?= gauge_attr_id(gauge_id) ?>-<?= item_id ?>-bar"
style="background-color: <?= resolved_color ?>; <?= bar_style ?> opacity: <?= opacity ?>; height: <?= std::to_string(pct_value) ?>%;"></div>
<? markers.each([&](DTree marker, String marker_id) {
f64 marker_value = float_val(first(marker["value"].to_string(), "0"));
f64 marker_pct = gauge_clamp_value(((marker_value - min_value) / vrange) * 100.0, 0.0, 100.0);
String marker_color = first(marker["color"].to_string(), "var(--primary-light)");
?><div class="progressbar-marker"
title="<?= marker["label"].to_string() ?>"
style="bottom: <?= std::to_string(marker_pct) ?>%; background: <?= marker_color ?>;"></div><?
}); ?>
</div>
<div class="gauge-metric-value progressbar-value" style="<?= value_style ?>" id="<?= gauge_attr_id(gauge_id) ?>-<?= item_id ?>-value"><?= merged["value"].to_string() + unit ?></div>
<? if(tooltip != "") { ?><div class="gauge-metric-meta progressbar-meta"><?= tooltip ?></div><? } ?>
<?: after_html ?>
</section><?
}); ?>
</div>
<? } ?>
</section>
<? if(context.call["listen"].to_string() != "") { ?>
<script>
window.ProgressbarComponents = window.ProgressbarComponents || {
start_listen : function(prop) {
$.events.on('value-broadcast', function(data) {
if(!prop.items || !prop.items[data.name]) return;
let bar = Object.assign({}, prop.scale || {}, prop.items[data.name]);
let target = document.getElementById(prop.id + '-' + data.name + '-bar');
let valueTarget = document.getElementById(prop.id + '-' + data.name + '-value');
if(valueTarget) valueTarget.textContent = data.value + (bar.unit || '');
let vrange = Number(bar.max || 100) - Number(bar.min || 0);
let pctValue = GaugeComponents.clampValue((Number(data.value) - Number(bar.min || 0)) / (vrange || 1) * 100, 0, 100);
if(Array.isArray(bar.color)) {
let colorMatch = GaugeComponents.pickEntryFromRange(bar.color, Number(data.value));
if(colorMatch && colorMatch.color && target)
target.style.background = colorMatch.color;
}
if(target) {
if(prop.layout === 'horizontal') target.style.width = pctValue + '%';
else target.style.height = pctValue + '%';
}
});
}
};
ProgressbarComponents.start_listen(<?: json_encode(context.call, '\'') ?>);
</script>
<? } ?>
</>
}
@@ -0,0 +1,32 @@
#load "../../lib/app.uce"
COMPONENT(Request& context)
{
starter_boot(context);
StarterUser users(context);
DTree user = users.current();
bool signed_in = user["email"].to_string() != "";
String theme_key = context.cfg.get_by_path("theme/key").to_string();
String wrapper_class = first(context.call["wrapper_class"].to_string(), theme_key == "localfirst" ? "admin-account-card" : "nav-account nav-menu");
String links_class = first(context.call["links_wrapper_class"].to_string(), theme_key == "localfirst" ? "admin-account-links" : "");
String name_class = first(context.call["name_class"].to_string(), theme_key == "localfirst" ? "admin-account-name" : "account-name");
<>
<div class="<?= wrapper_class ?>">
<? if(signed_in) { ?>
<span class="<?= name_class ?>"><?= first(user["username"].to_string(), user["email"].to_string(), "Account") ?></span>
<? if(links_class != "") { ?><div class="<?= links_class ?>"><? } ?>
<a href="<?= starter_link("account/profile", context) ?>">Profile</a>
<a href="<?= starter_link("account/logout", context) ?>">Logout</a>
<? if(links_class != "") { ?></div><? } ?>
<? } else { ?>
<? if(links_class != "") { ?><div class="<?= links_class ?>"><? } ?>
<a href="<?= starter_link("account/login", context) ?>">Login</a>
<? if(context.cfg.get_by_path("users/enable_signup").to_string() != "") { ?>
<a href="<?= starter_link("account/register", context) ?>">Register</a>
<? } ?>
<? if(links_class != "") { ?></div><? } ?>
<? } ?>
</div>
</>
}
@@ -0,0 +1,22 @@
#load "../../lib/app.uce"
COMPONENT(Request& context)
{
starter_boot(context);
bool embed_mode = starter_page_embed_mode(context);
if(embed_mode)
return;
String text = first(context.cfg.get_by_path("theme/footer_text").to_string(), context.cfg.get_by_path("site/name").to_string());
String inner_class = first(context.call["inner_class"].to_string(), context.cfg.get_by_path("theme/key").to_string() == "portal-light" ? "footer-inner" : "");
<>
<footer>
<? if(inner_class != "") { ?>
<div class="<?= inner_class ?>"><p><?= text ?></p></div>
<? } else { ?>
<div><p><?= text ?></p></div>
<? } ?>
</footer>
</>
}
@@ -0,0 +1,18 @@
#load "../../lib/app.uce"
COMPONENT(Request& context)
{
starter_boot(context);
if(starter_page_embed_mode(context))
return;
String cookie_value = context.call["cookie_consent"].to_string();
bool cookie_consent = !(cookie_value == "0" || cookie_value == "false" || cookie_value == "FALSE" || cookie_value == "no" || cookie_value == "NO");
<>
<?: component("../example/theme-switcher", context) ?>
<? if(cookie_consent) { ?>
<?: component("../basic/cookie-consent", context) ?>
<? } ?>
</>
}
@@ -0,0 +1,22 @@
#load "../../lib/app.uce"
COMPONENT(Request& context)
{
starter_boot(context);
String title = first(context.var["starter"]["page_title"].to_string(), context.cfg.get_by_path("site/default_page_title").to_string());
String description = first(context.cfg.get_by_path("theme/meta_description").to_string(), "UCE starter example");
String theme_color = first(context.cfg.get_by_path("theme/theme_color").to_string(), "#0f172a");
String icon = starter_asset_url(context.cfg.get_by_path("theme/path").to_string() + "icon.png", context);
<>
<meta charset="utf-8">
<title><?= title + " | " + context.cfg.get_by_path("site/name").to_string() ?></title>
<meta name="description" content="<?= description ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="<?= theme_color ?>">
<link rel="apple-touch-icon" href="<?= icon ?>" />
<link rel="icon" type="image/png" sizes="32x32" href="<?= icon ?>" />
<? starter_render_registered_css(context); ?>
<? starter_render_registered_js(context); ?>
</>
}
@@ -0,0 +1,20 @@
#load "../../lib/app.uce"
COMPONENT(Request& context)
{
starter_boot(context);
if(context.call["main_html"].to_string() != "")
context.var["starter"]["fragments"]["main"] = context.call["main_html"];
if(context.call["json"].get_type_name() == "array")
context.var["starter"]["json"] = context.call["json"];
if(context.call["page_type"].to_string() != "")
context.var["starter"]["page_type"] = context.call["page_type"];
if(context.call["embed_mode"].to_string() != "")
context.var["starter"]["embed_mode"] = context.call["embed_mode"];
starter_render_page(context);
}
COMPONENT:HEAD(Request& context)
{
print(component("head", context.call, context));
}
@@ -0,0 +1,31 @@
#load "../../lib/app.uce"
COMPONENT(Request& context)
{
starter_boot(context);
String nav_class = context.call["nav_class"].to_string();
if(nav_class == "" && (context.cfg.get_by_path("theme/key").to_string() == "portal-dark" || context.cfg.get_by_path("theme/key").to_string() == "dark" || context.cfg.get_by_path("theme/key").to_string() == "retro-gaming"))
nav_class = "nav-shell";
DTree account_props;
if(context.call["account_wrapper_class"].to_string() != "")
account_props["wrapper_class"] = context.call["account_wrapper_class"];
if(context.call["links_wrapper_class"].to_string() != "")
account_props["links_wrapper_class"] = context.call["links_wrapper_class"];
if(context.call["name_class"].to_string() != "")
account_props["name_class"] = context.call["name_class"];
<>
<nav<?: nav_class != "" ? " class=\"" + html_escape(nav_class) + "\"" : "" ?>>
<div class="nav-menu">
<a href="<?= starter_link("", context) ?>"><?= context.cfg.get_by_path("site/name").to_string() ?></a>
<? context.cfg.get_by_path("menu").each([&](DTree menu_item, String menu_key) {
if(menu_item["hidden"].to_string() == "1")
return;
?><a href="<?= starter_menu_href(menu_key, menu_item, context) ?>"><?= menu_item["title"].to_string() ?></a><?
}); ?>
</div>
<?: component("account_links", account_props, context) ?>
</nav>
</>
}
@@ -0,0 +1,122 @@
#load "../../lib/app.uce"
COMPONENT:APP_FRAME(Request& context)
{
starter_register_css("themes/common/css/workspace.css", context);
starter_register_js("js/u-workspace-shell.js", context);
String id = context.call["id"].to_string();
String overlay_id = context.call["overlay_id"].to_string();
String class_name = context.call["class"].to_string();
<>
<div<?: id != "" ? " id=\"" + html_escape(id) + "\"" : "" ?> class="ws-app<?= class_name != "" ? " " + html_escape(class_name) : "" ?>">
<?: context.call["sidebar_html"].to_string() ?>
<div<?: overlay_id != "" ? " id=\"" + html_escape(overlay_id) + "\"" : "" ?> class="ws-sidebar-overlay"></div>
<main class="ws-main"><?: context.call["main_html"].to_string() ?></main>
</div>
</>
}
COMPONENT:EMPTY_STATE(Request& context)
{
<>
<div class="ws-empty-state<?= context.call["class"].to_string() != "" ? " " + html_escape(context.call["class"].to_string()) : "" ?>">
<div class="ws-empty-icon"><i class="<?= first(context.call["icon_class"].to_string(), "fas fa-layer-group") ?>"></i></div>
<h2><?= context.call["title"].to_string() ?></h2>
<p><?= context.call["text"].to_string() ?></p>
<?: context.call["action_html"].to_string() ?>
</div>
</>
}
COMPONENT:LIST_STATE(Request& context)
{
<>
<div class="ws-list-state<?= context.call["class"].to_string() != "" ? " " + html_escape(context.call["class"].to_string()) : "" ?>"><? if(context.call["icon_class"].to_string() != "") { ?><i class="<?= context.call["icon_class"].to_string() ?>"></i><? } ?><span><?= context.call["text"].to_string() ?></span></div>
</>
}
COMPONENT:MOBILE_BAR(Request& context)
{
<>
<div class="ws-mobile-bar<?= context.call["class"].to_string() != "" ? " " + html_escape(context.call["class"].to_string()) : "" ?>">
<button<?: context.call["button_id"].to_string() != "" ? " id=\"" + html_escape(context.call["button_id"].to_string()) + "\"" : "" ?> class="ws-mobile-toggle" title="Toggle sidebar" type="button">
<i class="<?= first(context.call["icon_class"].to_string(), "fas fa-bars") ?>"></i>
</button>
<span class="ws-mobile-title"><?= context.call["title"].to_string() ?></span>
</div>
</>
}
COMPONENT:PANEL_HEADER(Request& context)
{
<>
<div class="ws-panel-header<?= context.call["class"].to_string() != "" ? " " + html_escape(context.call["class"].to_string()) : "" ?>">
<div class="ws-panel-title-group">
<h2><?= context.call["title"].to_string() ?></h2>
<? if(context.call["subtitle"].to_string() != "") { ?><p class="ws-subtitle"><?= context.call["subtitle"].to_string() ?></p><? } ?>
</div>
<? if(context.call["actions_html"].to_string() != "") { ?><div class="ws-header-actions"><?: context.call["actions_html"].to_string() ?></div><? } ?>
</div>
</>
}
COMPONENT:PANEL(Request& context)
{
<>
<section<?: context.call["id"].to_string() != "" ? " id=\"" + html_escape(context.call["id"].to_string()) + "\"" : "" ?> class="ws-panel<?= context.call["class"].to_string() != "" ? " " + html_escape(context.call["class"].to_string()) : "" ?>">
<?: context.call["header_html"].to_string() ?>
<?: context.call["body_html"].to_string() ?>
</section>
</>
}
COMPONENT:SECTION_HEAD(Request& context)
{
<>
<div class="ws-section-head<?= context.call["class"].to_string() != "" ? " " + html_escape(context.call["class"].to_string()) : "" ?>">
<h3><?= context.call["title"].to_string() ?></h3>
<? if(context.call["actions_html"].to_string() != "") { ?><div class="ws-header-actions"><?: context.call["actions_html"].to_string() ?></div><? } ?>
</div>
</>
}
COMPONENT:SECTION(Request& context)
{
<>
<section<?: context.call["id"].to_string() != "" ? " id=\"" + html_escape(context.call["id"].to_string()) + "\"" : "" ?> class="ws-section<?= context.call["class"].to_string() != "" ? " " + html_escape(context.call["class"].to_string()) : "" ?>">
<?: context.call["header_html"].to_string() ?>
<?: context.call["body_html"].to_string() ?>
</section>
</>
}
COMPONENT:SIDEBAR_SHELL(Request& context)
{
<>
<aside<?: context.call["id"].to_string() != "" ? " id=\"" + html_escape(context.call["id"].to_string()) + "\"" : "" ?> class="ws-sidebar<?= context.call["class"].to_string() != "" ? " " + html_escape(context.call["class"].to_string()) : "" ?>">
<?: context.call["top_html"].to_string() ?>
<?: context.call["body_html"].to_string() ?>
</aside>
</>
}
COMPONENT:SIDEBAR_TOOLBAR(Request& context)
{
<>
<div class="ws-sidebar-top<?= context.call["class"].to_string() != "" ? " " + html_escape(context.call["class"].to_string()) : "" ?>">
<?: context.call["action_html"].to_string() ?>
<div class="ws-search-wrap">
<i class="fas fa-search ws-search-icon"></i>
<input type="search"<?: context.call["search_input_id"].to_string() != "" ? " id=\"" + html_escape(context.call["search_input_id"].to_string()) + "\"" : "" ?> name="<?= first(context.call["search_input_name"].to_string(), "search") ?>" class="ws-search-input" placeholder="<?= first(context.call["search_placeholder"].to_string(), "Search...") ?>" autocomplete="off">
</div>
</div>
</>
}
COMPONENT:STATUS_PILL(Request& context)
{
String variant = to_lower(first(context.call["variant"].to_string(), "neutral"));
<>
<span class="ws-status-pill ws-status-pill-<?= variant ?><?= context.call["class"].to_string() != "" ? " " + html_escape(context.call["class"].to_string()) : "" ?>"><?= first(context.call["label"].to_string(), context.call["text"].to_string()) ?></span>
</>
}