diff --git a/Crafter.Web.cppm b/Crafter.CppDOM.cppm similarity index 55% rename from Crafter.Web.cppm rename to Crafter.CppDOM.cppm index 1c30dc6..b264112 100644 --- a/Crafter.Web.cppm +++ b/Crafter.CppDOM.cppm @@ -22,9 +22,7 @@ module; #include #include #include -export module Crafter.Web; -export import :HtmlElement; -export import :Canvas; +export module Crafter.CppDOM; extern "C" { void __cxa_allocate_exception() { @@ -38,13 +36,13 @@ extern "C" { -export namespace Crafter::Web::Bindings { +export namespace Crafter::CppDOM::Bindings { __attribute__((import_module("env"), import_name("setInnerHTML"))) void SetInnerHTML(const char* id, std::size_t idLenght, const char* html, std::size_t htmlLenght); - __attribute__((import_module("env"), import_name("strokeRect"))) void StrokeRect(std::uint64_t id, std::uint32_t x, std::uint32_t y, std::uint32_t width, std::uint32_t height, const char* color, std::size_t colorLenght); - __attribute__((import_module("env"), import_name("putImageData"))) void PutImageData(std::uint64_t id, Crafter::Web::Pixel* buffer, std::uint32_t width, std::uint32_t height); - __attribute__((import_module("env"), import_name("fetch"))) void Fetch(void* obj, const char* url, std::size_t urlCallback, char* buffer, void (*listener)(void* obj, std::uint32_t, char*)); - __attribute__((import_module("env"), import_name("setTimeout"))) void SetTimeout(void* obj, std::uint32_t time, void (*listener)(void* obj)); - __attribute__((import_module("env"), import_name("draw"))) void Draw(std::uint64_t id, std::uint32_t x, std::uint32_t y, const char* text, std::uint32_t textLenght); + // __attribute__((import_module("env"), import_name("strokeRect"))) void StrokeRect(std::uint64_t id, std::uint32_t x, std::uint32_t y, std::uint32_t width, std::uint32_t height, const char* color, std::size_t colorLenght); + // __attribute__((import_module("env"), import_name("putImageData"))) void PutImageData(std::uint64_t id, Crafter::Web::Pixel* buffer, std::uint32_t width, std::uint32_t height); + // __attribute__((import_module("env"), import_name("fetch"))) void Fetch(void* obj, const char* url, std::size_t urlCallback, char* buffer, void (*listener)(void* obj, std::uint32_t, char*)); + // __attribute__((import_module("env"), import_name("setTimeout"))) void SetTimeout(void* obj, std::uint32_t time, void (*listener)(void* obj)); + // __attribute__((import_module("env"), import_name("draw"))) void Draw(std::uint64_t id, std::uint32_t x, std::uint32_t y, const char* text, std::uint32_t textLenght); //__attribute__((import_module("env"), import_name("addEventListener"))) void AddEventListener(std::string id, std::string eventId, void (*listener)(void)); } diff --git a/Crafter.Web.js b/Crafter.CppDOM.js similarity index 100% rename from Crafter.Web.js rename to Crafter.CppDOM.js diff --git a/Crafter.Web-Canvas.cpp b/Crafter.Web-Canvas.cpp deleted file mode 100644 index 4985b8b..0000000 --- a/Crafter.Web-Canvas.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* -Crafter.Web -Copyright (C) 2024 Catcrafts -Catcrafts.net - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Lesser General Public -License as published by the Free Software Foundation; either -version 3.0 of the License, or (at your option) any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public -License along with this library; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -module; -#include -#include -#include -#include -#include -#include -module Crafter.Web; -using namespace Crafter::Web; - -Canvas::Canvas(std::uint32_t width, std::uint32_t height, std::string value, std::unordered_map style, std::vector children , std::unordered_map attributes) : HtmlElement("canvas", value, style, children, attributes), width(width), height(height) { - this->attributes.insert({"width",std::to_string(width)}); - this->attributes.insert({"height",std::to_string(height)}); -} - -void Canvas::DrawRect(std::uint32_t x, std::uint32_t y, std::uint32_t width, std::uint32_t height, std::string color) { - Crafter::Web::Bindings::StrokeRect(id, x, y, width, height, color.c_str(), color.size()); -} - -void Canvas::SetBuffer(Pixel* buffer) { - Crafter::Web::Bindings::PutImageData(id, buffer, width, height); -} diff --git a/Crafter.Web-Canvas.cppm b/Crafter.Web-Canvas.cppm deleted file mode 100644 index 71773e2..0000000 --- a/Crafter.Web-Canvas.cppm +++ /dev/null @@ -1,47 +0,0 @@ -/* -Crafter.Web -Copyright (C) 2024 Catcrafts -Catcrafts.net - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Lesser General Public -License as published by the Free Software Foundation; either -version 3.0 of the License, or (at your option) any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public -License along with this library; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -module; -#include -#include -#include -#include -export module Crafter.Web:Canvas; -import :HtmlElement; - -export namespace Crafter::Web { - - struct Pixel { - std::uint8_t r; - std::uint8_t g; - std::uint8_t b; - std::uint8_t a; - }; - - class Canvas : public Crafter::Web::HtmlElement { - public: - std::uint32_t width; - std::uint32_t height; - Canvas(std::uint32_t width, std::uint32_t height, std::string value = "", std::unordered_map style = {}, std::vector children = {}, std::unordered_map attributes = {}); - void DrawRect(std::uint32_t x, std::uint32_t y, std::uint32_t width, std::uint32_t height, std::string color); - void SetBuffer(Pixel* buffer); - }; -} - diff --git a/Crafter.Web-HtmlElement.cpp b/Crafter.Web-HtmlElement.cpp deleted file mode 100644 index a2ba2e9..0000000 --- a/Crafter.Web-HtmlElement.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* -Crafter.Web -Copyright (C) 2024 Catcrafts -Catcrafts.net - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Lesser General Public -License as published by the Free Software Foundation; either -version 3.0 of the License, or (at your option) any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public -License along with this library; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -module; -#include -#include -#include -#include -#include -#include -module Crafter.Web; -using namespace Crafter::Web; - -HtmlElement::HtmlElement(std::string tag, std::string value, std::unordered_map style, std::vector children, std::unordered_map attributes) : id(idCounter++), tag(tag), children(children), style(style), value(value), attributes(attributes) { - -} - - -std::string HtmlElement::Render() const { - std::string childrenRendered; - for(HtmlElement* child : children){ - childrenRendered+=child->Render(); - } - std::string styleRender; - for(const auto& [key, value] : style){ - styleRender+=std::format("{}:{};",key,value); - } - std::string attributesRender; - for(const auto& [key, value] : attributes){ - attributesRender+=std::format("{}=\"{}\"",key,value); - } - return std::format("<{} id=\"{}\" style=\"{}\" {}>{}{}",tag, id, styleRender, attributesRender, value, childrenRendered, tag); -} - -void HtmlElement::RenderAsRoot() const { - const std::string render = Render(); - const char id[] = "body"; - Crafter::Web::Bindings::SetInnerHTML(id, sizeof(id)-1, render.c_str(), render.size()-1); -} diff --git a/Crafter.Web-HtmlElement.cppm b/Crafter.Web-HtmlElement.cppm deleted file mode 100644 index 62c16c1..0000000 --- a/Crafter.Web-HtmlElement.cppm +++ /dev/null @@ -1,42 +0,0 @@ -/* -Crafter.Web -Copyright (C) 2024 Catcrafts -Catcrafts.net - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Lesser General Public -License as published by the Free Software Foundation; either -version 3.0 of the License, or (at your option) any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public -License along with this library; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -module; -#include -#include -#include -#include -export module Crafter.Web:HtmlElement; - -export namespace Crafter::Web { - class HtmlElement { - public: - inline static std::uint64_t idCounter = 0; - std::uint64_t id; - std::string tag; - std::string value; - std::unordered_map style; - std::vector children; - std::unordered_map attributes; - HtmlElement(std::string tag, std::string value = "", std::unordered_map style = {}, std::vector children = {}, std::unordered_map attributes = {}); - std::string Render() const; - void RenderAsRoot() const; - }; -} diff --git a/project.json b/project.json index 84afc9a..91c6946 100644 --- a/project.json +++ b/project.json @@ -4,9 +4,9 @@ { "name": "base", "standard": "c++26", - "source_files": ["Crafter.Web-HtmlElement", "Crafter.Web-Canvas"], - "module_files": ["Crafter.Web-Canvas", "Crafter.Web-HtmlElement", "Crafter.Web"], - "additional_files": ["Crafter.Web.js"], + "source_files": [], + "module_files": ["Crafter.CppDOM"], + "additional_files": ["Crafter.CppDOM.js"], "build_dir": "./build", "output_dir": "./bin", "type":"library", diff --git a/sample/main.cpp b/sample/main.cpp deleted file mode 100644 index c1ea598..0000000 --- a/sample/main.cpp +++ /dev/null @@ -1,17 +0,0 @@ -import Crafter.Web; -using namespace Crafter::Web; - -int main() { - HtmlElement root("div", "", {}, { - HtmlElement("h1", "HELLO FROM C++"), - HtmlElement("h1", "blue text", {{"color","blue"}}), - HtmlElement("h1", "", {{"display","flex"}, {"justify-content","space-between"}}, { - HtmlElement("div", "c++"), - HtmlElement("div", "webdev"), - HtmlElement("div", "is"), - HtmlElement("div", "awesome") - }), - HtmlElement("img", "", {}, {}, {{"src","https://upload.wikimedia.org/wikipedia/commons/thumb/1/18/ISO_C%2B%2B_Logo.svg/1822px-ISO_C%2B%2B_Logo.svg.png"},{"width","200"}}), - }); - root.RenderAsRoot(); -} diff --git a/sample/project.json b/sample/project.json deleted file mode 100644 index 5dcb9c7..0000000 --- a/sample/project.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "name": "sample-project", - "configurations": [ - { - "name": "debug", - "standard": "c++26", - "source_files": ["main"], - "module_files": [], - "build_dir": "./build", - "output_dir": "./bin", - "optimization_level": "0", - "target": "wasm32-unknown-wasi", - "type": "executable", - "dependencies": [ - { - "path":"../project.json", - "configuration":"debug" - } - ] - } - ] -}