{
  "files": {
    "app_core.h": "#pragma once\n#include <ArduinoJson.h>\n#include <cstddef>\n#include <cstdint>\n#include <cstdlib>\n\n// Portable application state and decisions. The protected hardware adapter and\n// native preview both use this exact reducer; no GPIO, networking or Arduino.\nnamespace KibiApp {\ninline constexpr uint8_t kScreenCount=3;\nstruct Model {uint8_t screenIndex=0;bool moduleOpen=false;bool enabled=false;};\nenum class InputKind:uint8_t {Plus,Minus,Tap,Swipe};\nstruct Input {InputKind kind=InputKind::Tap;int x=-1,y=-1,dx=0,dy=0;uint32_t durationMs=200;};\nenum class Action:uint8_t {None,NextScreen,PreviousScreen,OpenModule,CloseModule,Toggle};\ninline const char* actionName(Action action) {\n switch(action){case Action::NextScreen:return \"nextScreen\";case Action::PreviousScreen:return \"previousScreen\";case Action::OpenModule:return \"openModule\";case Action::CloseModule:return \"closeModule\";case Action::Toggle:return \"toggle\";default:return \"none\";}\n}\n// Explicit public-state codec. Add module fields here when Model grows; Studio\n// and the native runner deliberately do not know this application's field names.\n// Never encode credentials, private configuration or hardware handles.\ninline void encodeState(const Model& model,JsonObject out){out[\"screenIndex\"]=model.screenIndex;out[\"moduleOpen\"]=model.moduleOpen;out[\"enabled\"]=model.enabled;}\ninline bool decodeState(Model& model,JsonObjectConst in){if(!in[\"screenIndex\"].is<int>()||in[\"screenIndex\"].as<int>()<0||in[\"screenIndex\"].as<int>()>=kScreenCount||!in[\"moduleOpen\"].is<bool>()||!in[\"enabled\"].is<bool>())return false;model.screenIndex=in[\"screenIndex\"].as<uint8_t>();model.moduleOpen=in[\"moduleOpen\"].as<bool>();model.enabled=in[\"enabled\"].as<bool>();return true;}\n// nowMs is elapsed monotonic milliseconds. Return true when a timer changes UI\n// state; the same portable tick runs in the hardware adapter and native preview.\ninline bool tick(Model&,uint32_t){return false;}\ninline void normalize(Model& model){if(model.screenIndex>=kScreenCount)model.screenIndex=0;if(model.screenIndex!=1)model.moduleOpen=false;}\nnamespace Layout {\nstruct Rect {int x,y,width,height;};\ninline constexpr Rect homeModules{24,190,192,44},moduleDemo{24,100,192,62},moduleBack{24,244,192,42},settingToggle{24,104,192,64};\ninline bool contains(Rect rect,int x,int y){return x>=rect.x&&y>=rect.y&&x<rect.x+rect.width&&y<rect.y+rect.height;}\n}\nenum class Target:int8_t {None=-1,HomeModules,ModuleDemo,ModuleBack,SettingToggle};\ninline Target hitTarget(const Model& model,int x,int y){\n if(x<0||x>=240||y<0||y>=296)return Target::None;\n if(model.moduleOpen)return Layout::contains(Layout::moduleBack,x,y)?Target::ModuleBack:Target::None;\n if(model.screenIndex==0&&Layout::contains(Layout::homeModules,x,y))return Target::HomeModules;\n if(model.screenIndex==1&&Layout::contains(Layout::moduleDemo,x,y))return Target::ModuleDemo;\n if(model.screenIndex==2&&Layout::contains(Layout::settingToggle,x,y))return Target::SettingToggle;\n return Target::None;\n}\ninline Action navigate(Model& model,bool next){model.screenIndex=uint8_t((model.screenIndex+(next?1:kScreenCount-1))%kScreenCount);model.moduleOpen=false;return next?Action::NextScreen:Action::PreviousScreen;}\ninline Action reduceInput(Model& model,const Input& input){\n normalize(model);\n if(input.kind==InputKind::Plus)return navigate(model,true);\n if(input.kind==InputKind::Minus)return navigate(model,false);\n if(input.durationMs>1200)return Action::None;\n if(input.kind==InputKind::Swipe){if(std::abs(input.dx)<28||std::abs(input.dx)<=std::abs(input.dy))return Action::None;return navigate(model,input.dx<0);}\n if(input.kind!=InputKind::Tap||std::abs(input.dx)>10||std::abs(input.dy)>10)return Action::None;\n const Target target=hitTarget(model,input.x,input.y);\n if(target==Target::None||target!=hitTarget(model,input.x-input.dx,input.y-input.dy))return Action::None;\n switch(target){\n case Target::HomeModules:model.screenIndex=1;return Action::NextScreen;\n case Target::ModuleDemo:model.moduleOpen=true;return Action::OpenModule;\n case Target::ModuleBack:model.moduleOpen=false;return Action::CloseModule;\n case Target::SettingToggle:model.enabled=!model.enabled;return Action::Toggle;\n default:return Action::None;\n }\n}\n} // namespace KibiApp\n",
    "app_feature.h": "#pragma once\n#include \"app_view.h\"\n\n// Editable application extension. Keep state/visual decisions portable so the\n// hardware adapter and native preview can call these same hooks. Add hardware\n// services through reviewed adapters; never embed credentials in this file.\nnamespace KibiApp::Feature {\ninline void begin(Model& model,View::Context&){normalize(model);}\ninline bool tick(Model&,View::Context&,uint32_t){return false;}\ninline void input(Model&,const Input&,Action){}\n} // namespace KibiApp::Feature\n",
    "app_view.h": "#pragma once\n#include \"app_core.h\"\n#include \"kibi_typography.h\"\n#include <algorithm>\n#include <cstdio>\n\n// Native RGB565, Source Sans 3 AA4. This renderer is compiled unchanged for the\n// actual display and for Studio; there is no browser reconstruction of the UI.\nnamespace KibiApp::View {\nusing namespace KibiTypography;\ninline constexpr int kWidth=240,kHeight=296;\ninline constexpr uint16_t rgb(unsigned r,unsigned g,unsigned b){return uint16_t(((r>>3)<<11)|((g>>2)<<5)|(b>>3));}\ninline constexpr uint16_t kBackground=rgb(15,15,15),kText=rgb(245,245,245),kMuted=rgb(163,163,163),kRule=rgb(58,58,58),kSurface=rgb(27,27,27);\nstruct Context {uint32_t nowMs=100;bool online=true,loading=false,stale=false;};\ninline void pixel(Framebuffer frame,int x,int y,uint16_t color){if(x>=0&&x<kWidth&&y>=0&&y<kHeight)frame.pixels[y*frame.stride+x]=color;}\ninline void box(Framebuffer frame,int x,int y,int width,int height,uint16_t color){for(int row=std::max(0,y);row<std::min(kHeight,y+height);++row)for(int col=std::max(0,x);col<std::min(kWidth,x+width);++col)pixel(frame,col,row,color);}\ninline void rounded(Framebuffer frame,int x,int y,int width,int height,int radius,uint16_t color){\n for(int row=0;row<height;++row)for(int col=0;col<width;++col){const int cx=col<radius?radius-1:col>=width-radius?width-radius:col,cy=row<radius?radius-1:row>=height-radius?height-radius:row;const int dx=col-cx,dy=row-cy;if(dx*dx+dy*dy<=radius*radius)pixel(frame,x+col,y+row,color);}\n}\ninline void text(Framebuffer frame,Font font,const char* value,int x,int inkTop,uint16_t color){const auto& face=getFace(font);const auto metrics=measure(face,value);draw(frame,face,value,x-std::min(0,metrics.ink.x),inkTop-metrics.ink.y,color,{0,0,kWidth,kHeight});}\ninline void center(Framebuffer frame,Font font,const char* value,int inkTop,uint16_t color){text(frame,font,value,(kWidth-width(getFace(font),value))/2,inkTop,color);}\ninline void rule(Framebuffer frame,int y){box(frame,24,y,192,1,kRule);}\ninline void arrow(Framebuffer frame,int x,int y,uint16_t color){for(int i=0;i<5;++i){box(frame,x+i,y+i,2,2,color);box(frame,x+i,y+8-i,2,2,color);}}\ninline void button(Framebuffer frame,Layout::Rect rect,const char* label){rounded(frame,rect.x,rect.y,rect.width,rect.height,11,kText);center(frame,Font::Body18,label,rect.y+14,kBackground);}\ninline void header(Framebuffer frame,const char* title,const char* index){text(frame,Font::Header20,title,32,30,kText);const int w=width(getFace(Font::Body18),index);text(frame,Font::Body18,index,208-w,33,kMuted);}\ninline void dots(Framebuffer frame,uint8_t screen){for(int i=0;i<3;++i)rounded(frame,105+i*13,276,5,5,2,i==screen?kText:kRule);}\ninline const char* scenarioLabel(const Context& context){if(context.loading)return \"Загрузка…\";if(!context.online)return \"Офлайн-режим\";if(context.stale)return \"Нет свежих данных\";return nullptr;}\ninline void footer(Framebuffer frame,const Context& context,const char* defaultText){center(frame,Font::Body18,scenarioLabel(context)?scenarioLabel(context):defaultText,247,kMuted);}\ninline void home(Framebuffer frame,const Context& context){\n header(frame,\"КИБИ\",\"01 / 03\");\n text(frame,Font::Header20,\"Твоя идея.\",24,74,kText);text(frame,Font::Header20,\"Твой Киби.\",24,101,kText);\n text(frame,Font::Body18,\"Готовая основа\",24,141,kMuted);text(frame,Font::Body18,\"для приложения\",24,164,kMuted);\n button(frame,Layout::homeModules,\"Открыть модули\");footer(frame,context,\"Свайп / + −\");\n}\ninline void modules(Framebuffer frame,const Context& context){\n header(frame,\"Модули\",\"02 / 03\");text(frame,Font::Body18,\"Заготовки для идей\",24,70,kMuted);\n rounded(frame,24,100,192,62,10,kSurface);text(frame,Font::Medium20,\"Интерфейс\",36,113,kText);text(frame,Font::Body18,\"Живой пример\",36,139,kMuted);arrow(frame,199,125,kText);\n rule(frame,180);text(frame,Font::Medium20,\"Новый модуль\",32,194,kMuted);text(frame,Font::Body18,\"Место для твоего кода\",32,221,kMuted);\n footer(frame,context,\"\");\n}\ninline void module(Framebuffer frame,const Context& context){\n header(frame,\"Интерфейс\",\"ДЕМО\");\n text(frame,Font::Body18,\"Пример модуля\",24,81,kMuted);text(frame,Font::Header20,\"Здесь появится\",24,120,kText);text(frame,Font::Header20,\"твоя логика.\",24,148,kText);\n text(frame,Font::Body18,\"Без внешних данных\",24,192,kMuted);text(frame,Font::Body18,\"и подключённых услуг\",24,215,kMuted);\n button(frame,Layout::moduleBack,\"Назад\");\n if(scenarioLabel(context)){box(frame,24,75,192,24,kBackground);center(frame,Font::Body18,scenarioLabel(context),81,kMuted);}\n}\ninline void settings(Framebuffer frame,const Model& model,const Context& context){\n header(frame,\"Настройки\",\"03 / 03\");text(frame,Font::Body18,\"Пример состояния\",24,73,kMuted);\n rule(frame,101);text(frame,Font::Body18,\"Функция\",32,121,kText);text(frame,Font::Body18,model.enabled?\"Включено\":\"Выключено\",32,151,kMuted);\n rounded(frame,164,116,44,25,12,model.enabled?kText:kRule);rounded(frame,model.enabled?186:168,120,17,17,8,model.enabled?kBackground:kText);rule(frame,181);\n text(frame,Font::Body18,\"Меняет только\",24,197,kMuted);text(frame,Font::Body18,\"состояние примера\",24,220,kMuted);footer(frame,context,\"Связь не требуется\");\n}\ninline void render(uint16_t* pixels,size_t count,const Model& model,const Context& context){\n if(!pixels||count<size_t(kWidth*kHeight))return;\n Framebuffer frame{pixels,count,kWidth,kHeight,kWidth};std::fill(pixels,pixels+kWidth*kHeight,kBackground);\n if(model.moduleOpen&&model.screenIndex==1)module(frame,context);else{if(model.screenIndex==1)modules(frame,context);else if(model.screenIndex==2)settings(frame,model,context);else home(frame,context);dots(frame,model.screenIndex);}\n}\n} // namespace KibiApp::View\n"
  },
  "format": "kibi-app",
  "modules": [],
  "name": "Нейтральная основа Киби",
  "requirements": {
    "api": false,
    "wifi": false
  },
  "schemaVersion": 1,
  "sdk": "kibi-browser-2026-11-21-r1",
  "variant": "basic"
}
