aboutsummaryrefslogtreecommitdiff
path: root/src/app/components
diff options
context:
space:
mode:
Diffstat (limited to 'src/app/components')
-rw-r--r--src/app/components/gallery/index.css34
-rw-r--r--src/app/components/gallery/index.html13
-rw-r--r--src/app/components/gallery/root.zig86
-rw-r--r--src/app/components/icons/index.css4
-rw-r--r--src/app/components/icons/menu.svg3
-rw-r--r--src/app/components/icons/root.zig17
-rw-r--r--src/app/components/icons/settings.svg4
-rw-r--r--src/app/components/icons/upload.svg4
-rw-r--r--src/app/components/image/index.css26
-rw-r--r--src/app/components/image/index.html3
-rw-r--r--src/app/components/image/root.zig32
-rw-r--r--src/app/components/navbutton/index.css63
-rw-r--r--src/app/components/navbutton/index.html12
-rw-r--r--src/app/components/navbutton/root.zig58
-rw-r--r--src/app/components/root.zig13
15 files changed, 372 insertions, 0 deletions
diff --git a/src/app/components/gallery/index.css b/src/app/components/gallery/index.css
new file mode 100644
index 0000000..35cab60
--- /dev/null
+++ b/src/app/components/gallery/index.css
@@ -0,0 +1,34 @@
+:host {
+ background: black;
+ --gallery-splits: 5;
+ display: flex;
+ flex-wrap: wrap;
+ overflow: auto;
+}
+
+#control {
+ position: absolute;
+ bottom: 10px;
+ right: 70px;
+ width: 100px;
+ height: 50px;
+ background: var(--primary);
+ border-radius: 50px;
+ display: grid;
+ grid-template-columns: 1fr 1fr;
+ cursor: pointer;
+ user-select: none;
+
+ div {
+ user-select: none;
+ color: var(--color);
+ width: 50px;
+ height: 50px;
+ text-align: center;
+ align-content: center;
+ }
+}
+
+app-image {
+ width: calc(100% / var(--gallery-splits));
+}
diff --git a/src/app/components/gallery/index.html b/src/app/components/gallery/index.html
new file mode 100644
index 0000000..efa58a3
--- /dev/null
+++ b/src/app/components/gallery/index.html
@@ -0,0 +1,13 @@
+<div id="control">
+ <div onclick="@zoomIn">
+ <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-plus" viewBox="0 0 16 16">
+ <path d="M8 4a.5.5 0 0 1 .5.5v3h3a.5.5 0 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3A.5.5 0 0 1 8 4">
+ </path>
+ </svg>
+ </div>
+ <div onclick="@zoomOut">
+ <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-dash" viewBox="0 0 16 16">
+ <path d="M4 8a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7A.5.5 0 0 1 4 8"></path>
+ </svg>
+ </div>
+</div>
diff --git a/src/app/components/gallery/root.zig b/src/app/components/gallery/root.zig
new file mode 100644
index 0000000..1eef707
--- /dev/null
+++ b/src/app/components/gallery/root.zig
@@ -0,0 +1,86 @@
+const std = @import("std");
+const gpa = std.heap.wasm_allocator;
+
+const zilch = @import("zilch");
+const Object = zilch.Object;
+const components = @import("../root.zig");
+const Image = components.Image;
+
+const app = @import("root").app;
+
+pub const component: zilch.Component = .build(.{
+ .name = "gallery",
+ .html = .parse(@embedFile("index.html")),
+ .css = @embedFile("index.css"),
+ .link = @This(),
+});
+
+const Self = @This();
+
+element: *Object,
+body: *Object,
+pool: std.heap.MemoryPool(Image),
+images: std.ArrayList(*Image),
+style: *zilch.Object,
+splits: usize,
+
+pub fn init(self: *Self, element: *Object) !void {
+ var env: zilch.Env = .default;
+ defer env.deinit();
+
+ self.element = element;
+ self.style = blk: {
+ var style = self.element.get(&env, "style");
+ break :blk try style.await(&env, *zilch.Object);
+ };
+ self.pool = .empty;
+ self.images = .empty;
+ self.splits = 5;
+
+ const number_of_boxes: u32 = 1000;
+
+ {
+ var elements: []zilch.Env.Future(*Object) = try gpa.alloc(zilch.Env.Future(*Object), number_of_boxes);
+ defer gpa.free(elements);
+ for (0..number_of_boxes) |index| {
+ const image = try self.pool.create(gpa);
+ elements[index] = Image.component.new(image, &env);
+ try self.images.append(gpa, image);
+ }
+
+ for (elements[0..], self.images.items) |*el, image| {
+ try image.init(try el.await(&env));
+ var future = image.setUrl(&env, "image/1");
+ future.ignore(&env);
+ }
+ }
+
+ var body = self.element.get(&env, "shadowRoot");
+
+ for (self.images.items) |image| {
+ var append_call = Object.call(body, &env, "append", .{image.element});
+ append_call.ignore(&env);
+ }
+
+ self.body = try body.await(&env, *Object);
+}
+
+pub fn zoomIn(self: *Self) !void {
+ var env: zilch.Env = .default;
+ defer env.deinit();
+
+ self.splits = @max(1, self.splits - 1);
+
+ var future = self.style.call(&env, "setProperty", .{ "--gallery-splits", self.splits });
+ future.ignore(&env);
+}
+
+pub fn zoomOut(self: *Self) !void {
+ var env: zilch.Env = .default;
+ defer env.deinit();
+
+ self.splits = @min(10, self.splits + 1);
+
+ var future = self.style.call(&env, "setProperty", .{ "--gallery-splits", self.splits });
+ future.ignore(&env);
+}
diff --git a/src/app/components/icons/index.css b/src/app/components/icons/index.css
new file mode 100644
index 0000000..81badfd
--- /dev/null
+++ b/src/app/components/icons/index.css
@@ -0,0 +1,4 @@
+:host {
+ width: 16px;
+ height: 16px;
+}
diff --git a/src/app/components/icons/menu.svg b/src/app/components/icons/menu.svg
new file mode 100644
index 0000000..df05f82
--- /dev/null
+++ b/src/app/components/icons/menu.svg
@@ -0,0 +1,3 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-three-dots-vertical" viewBox="0 0 16 16">
+ <path d="M9.5 13a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0m0-5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0m0-5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0"></path>
+</svg>
diff --git a/src/app/components/icons/root.zig b/src/app/components/icons/root.zig
new file mode 100644
index 0000000..0328472
--- /dev/null
+++ b/src/app/components/icons/root.zig
@@ -0,0 +1,17 @@
+const zilch = @import("zilch");
+
+pub const icons: []const zilch.Component = &.{
+ icon("menu"),
+ icon("upload"),
+ icon("settings"),
+};
+
+pub fn icon(name: []const u8) zilch.Component {
+ return .build(.{
+ .namespace = "icon",
+ .name = name,
+ .html = .parse(@embedFile(name ++ ".svg")),
+ .css = @embedFile("index.css"),
+ .link = struct {},
+ });
+}
diff --git a/src/app/components/icons/settings.svg b/src/app/components/icons/settings.svg
new file mode 100644
index 0000000..783f55f
--- /dev/null
+++ b/src/app/components/icons/settings.svg
@@ -0,0 +1,4 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-gear" viewBox="0 0 16 16">
+ <path d="M8 4.754a3.246 3.246 0 1 0 0 6.492 3.246 3.246 0 0 0 0-6.492M5.754 8a2.246 2.246 0 1 1 4.492 0 2.246 2.246 0 0 1-4.492 0"></path>
+ <path d="M9.796 1.343c-.527-1.79-3.065-1.79-3.592 0l-.094.319a.873.873 0 0 1-1.255.52l-.292-.16c-1.64-.892-3.433.902-2.54 2.541l.159.292a.873.873 0 0 1-.52 1.255l-.319.094c-1.79.527-1.79 3.065 0 3.592l.319.094a.873.873 0 0 1 .52 1.255l-.16.292c-.892 1.64.901 3.434 2.541 2.54l.292-.159a.873.873 0 0 1 1.255.52l.094.319c.527 1.79 3.065 1.79 3.592 0l.094-.319a.873.873 0 0 1 1.255-.52l.292.16c1.64.893 3.434-.902 2.54-2.541l-.159-.292a.873.873 0 0 1 .52-1.255l.319-.094c1.79-.527 1.79-3.065 0-3.592l-.319-.094a.873.873 0 0 1-.52-1.255l.16-.292c.893-1.64-.902-3.433-2.541-2.54l-.292.159a.873.873 0 0 1-1.255-.52zm-2.633.283c.246-.835 1.428-.835 1.674 0l.094.319a1.873 1.873 0 0 0 2.693 1.115l.291-.16c.764-.415 1.6.42 1.184 1.185l-.159.292a1.873 1.873 0 0 0 1.116 2.692l.318.094c.835.246.835 1.428 0 1.674l-.319.094a1.873 1.873 0 0 0-1.115 2.693l.16.291c.415.764-.42 1.6-1.185 1.184l-.291-.159a1.873 1.873 0 0 0-2.693 1.116l-.094.318c-.246.835-1.428.835-1.674 0l-.094-.319a1.873 1.873 0 0 0-2.692-1.115l-.292.16c-.764.415-1.6-.42-1.184-1.185l.159-.291A1.873 1.873 0 0 0 1.945 8.93l-.319-.094c-.835-.246-.835-1.428 0-1.674l.319-.094A1.873 1.873 0 0 0 3.06 4.377l-.16-.292c-.415-.764.42-1.6 1.185-1.184l.292.159a1.873 1.873 0 0 0 2.692-1.115z"></path>
+</svg>
diff --git a/src/app/components/icons/upload.svg b/src/app/components/icons/upload.svg
new file mode 100644
index 0000000..5187f80
--- /dev/null
+++ b/src/app/components/icons/upload.svg
@@ -0,0 +1,4 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-cloud-arrow-up" viewBox="0 0 16 16">
+ <path fill-rule="evenodd" d="M7.646 5.146a.5.5 0 0 1 .708 0l2 2a.5.5 0 0 1-.708.708L8.5 6.707V10.5a.5.5 0 0 1-1 0V6.707L6.354 7.854a.5.5 0 1 1-.708-.708z"></path>
+ <path d="M4.406 3.342A5.53 5.53 0 0 1 8 2c2.69 0 4.923 2 5.166 4.579C14.758 6.804 16 8.137 16 9.773 16 11.569 14.502 13 12.687 13H3.781C1.708 13 0 11.366 0 9.318c0-1.763 1.266-3.223 2.942-3.593.143-.863.698-1.723 1.464-2.383m.653.757c-.757.653-1.153 1.44-1.153 2.056v.448l-.445.049C2.064 6.805 1 7.952 1 9.318 1 10.785 2.23 12 3.781 12h8.906C13.98 12 15 10.988 15 9.773c0-1.216-1.02-2.228-2.313-2.228h-.5v-.5C12.188 4.825 10.328 3 8 3a4.53 4.53 0 0 0-2.941 1.1z"></path>
+</svg>
diff --git a/src/app/components/image/index.css b/src/app/components/image/index.css
new file mode 100644
index 0000000..d9a9ff5
--- /dev/null
+++ b/src/app/components/image/index.css
@@ -0,0 +1,26 @@
+.image {
+ width: 100%;
+ padding-bottom: 100%;
+ height: 0;
+ background: var(--image);
+ background-size: cover;
+ background-position: center;
+}
+
+img {
+ content: var(--image);
+ width: 100%;
+ display: none;
+ visibility: hidden;
+}
+
+@container style(--gallery-splits: 1) {
+ .image {
+ padding-bottom: 0px;
+ height: unset;
+ }
+
+ img {
+ display: unset;
+ }
+}
diff --git a/src/app/components/image/index.html b/src/app/components/image/index.html
new file mode 100644
index 0000000..2b135dc
--- /dev/null
+++ b/src/app/components/image/index.html
@@ -0,0 +1,3 @@
+<div class="image">
+ <img>
+</div>
diff --git a/src/app/components/image/root.zig b/src/app/components/image/root.zig
new file mode 100644
index 0000000..1d46d30
--- /dev/null
+++ b/src/app/components/image/root.zig
@@ -0,0 +1,32 @@
+const std = @import("std");
+const zilch = @import("zilch");
+
+pub const component: zilch.Component = .build(.{
+ .name = "image",
+ .html = .parse(@embedFile("index.html")),
+ .css = @embedFile("index.css"),
+ .link = @This(),
+});
+
+const Self = @This();
+
+element: *zilch.Object,
+style: *zilch.Object,
+
+pub fn init(self: *Self, element: *zilch.Object) !void {
+ var env: zilch.Env = .default;
+ defer env.deinit();
+
+ self.element = element;
+ self.style = blk: {
+ var style = self.element.get(&env, "style");
+ break :blk try style.await(&env, *zilch.Object);
+ };
+}
+
+pub fn setUrl(self: *Self, env: *zilch.Env, url: []const u8) zilch.Env.Future(void) {
+ var buffer: [1024]u8 = undefined;
+ var writer: std.Io.Writer = .fixed(&buffer);
+ writer.print("url({s})", .{url}) catch unreachable;
+ return .fromAny(self.style.call(env, "setProperty", .{"--image", writer.buffered()}));
+}
diff --git a/src/app/components/navbutton/index.css b/src/app/components/navbutton/index.css
new file mode 100644
index 0000000..6909464
--- /dev/null
+++ b/src/app/components/navbutton/index.css
@@ -0,0 +1,63 @@
+:host {
+ position: absolute;
+ bottom: 10px;
+ right: 10px;
+ --items-count: 2;
+}
+
+#button {
+ position: relative;
+ width: 50px;
+ height: 50px;
+ background: var(--secondary);
+ border-radius: 50px;
+ cursor: pointer;
+ color: var(--color);
+ transition: 0.2s ease height;
+ display: grid;
+ justify-content: center;
+ align-content: end;
+ overflow: hidden;
+}
+
+#button.open {
+ height: calc(50px * (var(--items-count) + 1));
+}
+
+#menu {
+ width: 50px;
+ height: 50px;
+ background: red;
+ border-radius: 50px;
+ display: grid;
+ background: var(--primary);
+}
+
+.icon {
+ margin: auto;
+ width: fit-content;
+ height: fit-content;
+ padding-top: 4px;
+}
+
+.items {
+ height: calc(50px * var(--items-count));
+ display: grid;
+ grid-template-rows: repeat(var(--items-count), auto);
+}
+
+.item {
+ margin: auto;
+ width: 40px;
+ height: 40px;
+ border-radius: 40px;
+ display: grid;
+}
+
+.item * {
+ margin: auto;
+}
+
+.item:hover {
+ background: #5f5e9c;
+}
diff --git a/src/app/components/navbutton/index.html b/src/app/components/navbutton/index.html
new file mode 100644
index 0000000..f2c9ff8
--- /dev/null
+++ b/src/app/components/navbutton/index.html
@@ -0,0 +1,12 @@
+<div id="button" onclick="@open">
+ <div class="items">
+ <div class="item"><icon-upload></icon-upload></div>
+ <div class="item"><icon-settings></icon-settings></div>
+ </div>
+
+ <div id="menu">
+ <div class="icon">
+ <icon-menu></icon-menu>
+ </div>
+ </div>
+</div>
diff --git a/src/app/components/navbutton/root.zig b/src/app/components/navbutton/root.zig
new file mode 100644
index 0000000..a512d1d
--- /dev/null
+++ b/src/app/components/navbutton/root.zig
@@ -0,0 +1,58 @@
+const std = @import("std");
+const app = @import("root").app;
+const zilch = @import("zilch");
+const Object = zilch.Object;
+const Promise = zilch.Promise;
+
+const Self = @This();
+
+pub const component: zilch.Component = .build(.{
+ .name = "navbutton",
+ .html = .parse(@embedFile("index.html")),
+ .css = @embedFile("index.css"),
+ .link = @This(),
+});
+
+element: *zilch.Object,
+shadow_root: *zilch.Object,
+button: struct {
+ classList: *zilch.Object,
+},
+
+pub fn init(self: *Self, element: *Object) !void {
+ var env: zilch.Env = .default;
+ defer env.deinit();
+
+ self.element = element;
+
+ var shadow_root = self.element.get(&env, "shadowRoot");
+
+ var class_list = cls: {
+ var button = Object.call(shadow_root, &env, "getElementById", .{"button"});
+ defer button.ignore(&env);
+ defer _ = Object.free(button, &env);
+
+ break :cls Object.get(button, &env, "classList");
+ };
+
+ self.button.classList = try class_list.await(&env, *Object);
+
+ self.shadow_root = try shadow_root.await(&env, *Object);
+}
+
+pub fn deinit(self: *Self) !void {
+ var env: zilch.Env = .default;
+ defer env.deinit();
+
+ _ = self.element.free(&env);
+ _ = self.shadow_root.free(&env);
+ _ = self.button.classList.free(&env);
+}
+
+pub fn open(self: *Self) !void {
+ var env: zilch.Env = .default;
+ defer env.deinit();
+
+ var toggle_call = self.button.classList.call(&env, "toggle", .{"open"});
+ toggle_call.ignore(&env);
+}
diff --git a/src/app/components/root.zig b/src/app/components/root.zig
new file mode 100644
index 0000000..999a052
--- /dev/null
+++ b/src/app/components/root.zig
@@ -0,0 +1,13 @@
+const zilch = @import("zilch");
+
+const icons = @import("icons/root.zig").icons;
+
+pub const NavButton = @import("navbutton/root.zig");
+pub const Image = @import("image/root.zig");
+pub const Gallery = @import("gallery/root.zig");
+
+pub const components = &[_]zilch.Component{
+ NavButton.component,
+ Image.component,
+ Gallery.component,
+} ++ icons;