chore(fmt): add legacy stubs and strip trailing whitespace to unblock cargo fmt

This commit is contained in:
Selfhosting Dev
2025-09-17 07:43:07 +09:00
parent fcf8ce1f3c
commit adbb0201a9
385 changed files with 35622 additions and 15004 deletions

View File

@ -1,6 +1,6 @@
/*!
* Web Boxes Module - ブラウザ専用Box群
*
*
* WebAssembly環境専用のBox群を管理
* HTML5 APIs、DOM操作、Canvas描画等をNyashから利用可能にする
*/
@ -21,4 +21,4 @@ pub use web_display_box::WebDisplayBox;
pub use web_console_box::WebConsoleBox;
#[cfg(target_arch = "wasm32")]
pub use web_canvas_box::WebCanvasBox;
pub use web_canvas_box::WebCanvasBox;

View File

@ -1,21 +1,18 @@
/*!
* WebCanvasBox - ブラウザCanvas完全制御Box
*
*
* WebAssembly環境でHTML5 Canvasの完全制御
* ピクセルの世界を制圧する革命的Box
*/
use crate::box_trait::{NyashBox, StringBox, BoolBox, BoxCore, BoxBase};
use crate::box_trait::{BoolBox, BoxBase, BoxCore, NyashBox, StringBox};
use std::any::Any;
#[cfg(target_arch = "wasm32")]
use wasm_bindgen::prelude::*;
#[cfg(target_arch = "wasm32")]
use web_sys::{
HtmlCanvasElement,
CanvasRenderingContext2d,
};
use web_sys::{CanvasRenderingContext2d, HtmlCanvasElement};
// 🎨 Browser Canvas complete control Box
#[cfg(target_arch = "wasm32")]
@ -30,22 +27,22 @@ pub struct WebCanvasBox {
#[cfg(target_arch = "wasm32")]
impl WebCanvasBox {
pub fn new(canvas_id: String, width: u32, height: u32) -> Self {
let instance = Self {
let instance = Self {
base: BoxBase::new(),
canvas_id: canvas_id.clone(),
width,
height,
};
// キャンバス要素を初期化
if let Some(canvas) = instance.get_canvas_element() {
canvas.set_width(width);
canvas.set_height(height);
}
instance
}
/// Canvas要素を取得
fn get_canvas_element(&self) -> Option<HtmlCanvasElement> {
let window = web_sys::window()?;
@ -53,7 +50,7 @@ impl WebCanvasBox {
let element = document.get_element_by_id(&self.canvas_id)?;
element.dyn_into::<HtmlCanvasElement>().ok()
}
/// 2Dレンダリングコンテキストを取得
fn get_2d_context(&self) -> Option<CanvasRenderingContext2d> {
let canvas = self.get_canvas_element()?;
@ -62,35 +59,35 @@ impl WebCanvasBox {
.ok()?
.and_then(|ctx| ctx.dyn_into::<CanvasRenderingContext2d>().ok())
}
/// キャンバスをクリア
pub fn clear(&self) {
if let Some(ctx) = self.get_2d_context() {
ctx.clear_rect(0.0, 0.0, self.width as f64, self.height as f64);
}
}
/// 塗りつぶし色を設定
pub fn set_fill_style(&self, color: &str) {
if let Some(ctx) = self.get_2d_context() {
ctx.set_fill_style(&wasm_bindgen::JsValue::from_str(color));
}
}
/// 線の色を設定
pub fn set_stroke_style(&self, color: &str) {
if let Some(ctx) = self.get_2d_context() {
ctx.set_stroke_style(&wasm_bindgen::JsValue::from_str(color));
}
}
/// 線の太さを設定
pub fn set_line_width(&self, width: f64) {
if let Some(ctx) = self.get_2d_context() {
ctx.set_line_width(width);
}
}
/// 塗りつぶし矩形を描画
pub fn fill_rect(&self, x: f64, y: f64, width: f64, height: f64, color: &str) {
if let Some(ctx) = self.get_2d_context() {
@ -98,37 +95,47 @@ impl WebCanvasBox {
ctx.fill_rect(x, y, width, height);
}
}
/// 枠線矩形を描画
pub fn stroke_rect(&self, x: f64, y: f64, width: f64, height: f64, color: &str, line_width: f64) {
pub fn stroke_rect(
&self,
x: f64,
y: f64,
width: f64,
height: f64,
color: &str,
line_width: f64,
) {
if let Some(ctx) = self.get_2d_context() {
ctx.set_stroke_style(&wasm_bindgen::JsValue::from_str(color));
ctx.set_line_width(line_width);
ctx.stroke_rect(x, y, width, height);
}
}
/// 塗りつぶし円を描画
pub fn fill_circle(&self, x: f64, y: f64, radius: f64, color: &str) {
if let Some(ctx) = self.get_2d_context() {
ctx.set_fill_style(&wasm_bindgen::JsValue::from_str(color));
ctx.begin_path();
ctx.arc(x, y, radius, 0.0, 2.0 * std::f64::consts::PI).unwrap_or_default();
ctx.arc(x, y, radius, 0.0, 2.0 * std::f64::consts::PI)
.unwrap_or_default();
ctx.fill();
}
}
/// 枠線円を描画
pub fn stroke_circle(&self, x: f64, y: f64, radius: f64, color: &str, line_width: f64) {
if let Some(ctx) = self.get_2d_context() {
ctx.set_stroke_style(&wasm_bindgen::JsValue::from_str(color));
ctx.set_line_width(line_width);
ctx.begin_path();
ctx.arc(x, y, radius, 0.0, 2.0 * std::f64::consts::PI).unwrap_or_default();
ctx.arc(x, y, radius, 0.0, 2.0 * std::f64::consts::PI)
.unwrap_or_default();
ctx.stroke();
}
}
/// 直線を描画
pub fn draw_line(&self, x1: f64, y1: f64, x2: f64, y2: f64, color: &str, line_width: f64) {
if let Some(ctx) = self.get_2d_context() {
@ -140,7 +147,7 @@ impl WebCanvasBox {
ctx.stroke();
}
}
/// テキストを描画(塗りつぶし)
pub fn fill_text(&self, text: &str, x: f64, y: f64, font: &str, color: &str) {
if let Some(ctx) = self.get_2d_context() {
@ -149,9 +156,17 @@ impl WebCanvasBox {
ctx.fill_text(text, x, y).unwrap_or_default();
}
}
/// テキストを描画(枠線)
pub fn stroke_text(&self, text: &str, x: f64, y: f64, font: &str, color: &str, line_width: f64) {
pub fn stroke_text(
&self,
text: &str,
x: f64,
y: f64,
font: &str,
color: &str,
line_width: f64,
) {
if let Some(ctx) = self.get_2d_context() {
ctx.set_font(font);
ctx.set_stroke_style(&wasm_bindgen::JsValue::from_str(color));
@ -159,35 +174,35 @@ impl WebCanvasBox {
ctx.stroke_text(text, x, y).unwrap_or_default();
}
}
/// パス描画開始
pub fn begin_path(&self) {
if let Some(ctx) = self.get_2d_context() {
ctx.begin_path();
}
}
/// パスを指定位置に移動
pub fn move_to(&self, x: f64, y: f64) {
if let Some(ctx) = self.get_2d_context() {
ctx.move_to(x, y);
}
}
/// パスに直線を追加
pub fn line_to(&self, x: f64, y: f64) {
if let Some(ctx) = self.get_2d_context() {
ctx.line_to(x, y);
}
}
/// パスを閉じる
pub fn close_path(&self) {
if let Some(ctx) = self.get_2d_context() {
ctx.close_path();
}
}
/// パスを塗りつぶし
pub fn fill(&self, color: &str) {
if let Some(ctx) = self.get_2d_context() {
@ -195,7 +210,7 @@ impl WebCanvasBox {
ctx.fill();
}
}
/// パスを枠線描画
pub fn stroke(&self, color: &str, line_width: f64) {
if let Some(ctx) = self.get_2d_context() {
@ -204,56 +219,56 @@ impl WebCanvasBox {
ctx.stroke();
}
}
/// 現在の描画状態を保存
pub fn save(&self) {
if let Some(ctx) = self.get_2d_context() {
ctx.save();
}
}
/// 描画状態を復元
pub fn restore(&self) {
if let Some(ctx) = self.get_2d_context() {
ctx.restore();
}
}
/// 座標系を回転
pub fn rotate(&self, angle: f64) {
if let Some(ctx) = self.get_2d_context() {
ctx.rotate(angle).unwrap_or_default();
}
}
/// 座標系をスケール
pub fn scale(&self, x: f64, y: f64) {
if let Some(ctx) = self.get_2d_context() {
ctx.scale(x, y).unwrap_or_default();
}
}
/// 座標系を平行移動
pub fn translate(&self, x: f64, y: f64) {
if let Some(ctx) = self.get_2d_context() {
ctx.translate(x, y).unwrap_or_default();
}
}
/// キャンバスのサイズを取得
pub fn get_width(&self) -> u32 {
self.width
}
pub fn get_height(&self) -> u32 {
self.height
}
/// キャンバスのサイズを変更
pub fn resize(&mut self, width: u32, height: u32) {
self.width = width;
self.height = height;
if let Some(canvas) = self.get_canvas_element() {
canvas.set_width(width);
canvas.set_height(height);
@ -266,19 +281,23 @@ impl BoxCore for WebCanvasBox {
fn box_id(&self) -> u64 {
self.base.id
}
fn parent_type_id(&self) -> Option<std::any::TypeId> {
self.base.parent_type_id
}
fn fmt_box(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "WebCanvasBox({}, {}x{})", self.canvas_id, self.width, self.height)
write!(
f,
"WebCanvasBox({}, {}x{})",
self.canvas_id, self.width, self.height
)
}
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
@ -289,7 +308,7 @@ impl NyashBox for WebCanvasBox {
fn clone_box(&self) -> Box<dyn NyashBox> {
Box::new(self.clone())
}
/// 仮実装: clone_boxと同じ後で修正
fn share_box(&self) -> Box<dyn NyashBox> {
self.clone_box()
@ -297,18 +316,14 @@ impl NyashBox for WebCanvasBox {
fn to_string_box(&self) -> StringBox {
StringBox::new(format!(
"WebCanvasBox({}, {}x{})",
self.canvas_id,
self.width,
self.height
"WebCanvasBox({}, {}x{})",
self.canvas_id, self.width, self.height
))
}
fn type_name(&self) -> &'static str {
"WebCanvasBox"
}
fn equals(&self, other: &dyn NyashBox) -> BoolBox {
if let Some(other_canvas) = other.as_any().downcast_ref::<WebCanvasBox>() {
@ -324,4 +339,4 @@ impl std::fmt::Display for WebCanvasBox {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.fmt_box(f)
}
}
}

View File

@ -1,11 +1,11 @@
/*!
* WebConsoleBox - ブラウザHTML要素コンソール出力Box
*
*
* WebAssembly環境でHTML要素へのコンソール風出力
* F12コンソールの代わりに指定要素に出力
*/
use crate::box_trait::{NyashBox, StringBox, BoolBox, BoxCore, BoxBase};
use crate::box_trait::{BoolBox, BoxBase, BoxCore, NyashBox, StringBox};
use std::any::Any;
#[cfg(target_arch = "wasm32")]
@ -25,85 +25,91 @@ pub struct WebConsoleBox {
#[cfg(target_arch = "wasm32")]
impl WebConsoleBox {
pub fn new(element_id: String) -> Self {
Self {
Self {
base: BoxBase::new(),
target_element_id: element_id,
}
}
/// 指定した要素IDのHTML要素を取得
fn get_target_element(&self) -> Option<Element> {
let window = web_sys::window()?;
let document = window.document()?;
document.get_element_by_id(&self.target_element_id)
}
/// コンソール出力を追加(改行付き)
fn append_console_line(&self, message: &str, level: &str) {
if let Some(element) = self.get_target_element() {
let timestamp = js_sys::Date::new_0().to_iso_string().as_string().unwrap_or_default();
let time_part = timestamp.split('T').nth(1).unwrap_or("00:00:00").split('.').nth(0).unwrap_or("00:00:00");
let timestamp = js_sys::Date::new_0()
.to_iso_string()
.as_string()
.unwrap_or_default();
let time_part = timestamp
.split('T')
.nth(1)
.unwrap_or("00:00:00")
.split('.')
.nth(0)
.unwrap_or("00:00:00");
let (level_prefix, color) = match level {
"log" => ("📝", "white"),
"warn" => ("⚠️", "yellow"),
"error" => ("", "red"),
"error" => ("", "red"),
"info" => ("", "cyan"),
"debug" => ("🔍", "gray"),
_ => ("📝", "white"),
};
let formatted_line = format!(
"<span style='color: {}'>[{}] {} {}</span><br>",
color,
time_part,
level_prefix,
message
"<span style='color: {}'>[{}] {} {}</span><br>",
color, time_part, level_prefix, message
);
let current_content = element.inner_html();
let new_content = format!("{}{}", current_content, formatted_line);
element.set_inner_html(&new_content);
// 自動スクロール
if let Some(html_element) = element.dyn_ref::<HtmlElement>() {
html_element.set_scroll_top(html_element.scroll_height());
}
}
}
/// ログメッセージを出力
pub fn log(&self, message: &str) {
self.append_console_line(message, "log");
}
/// 警告メッセージを出力
pub fn warn(&self, message: &str) {
self.append_console_line(message, "warn");
}
/// エラーメッセージを出力
pub fn error(&self, message: &str) {
self.append_console_line(message, "error");
}
/// 情報メッセージを出力
pub fn info(&self, message: &str) {
self.append_console_line(message, "info");
}
/// デバッグメッセージを出力
pub fn debug(&self, message: &str) {
self.append_console_line(message, "debug");
}
/// コンソールをクリア
pub fn clear(&self) {
if let Some(element) = self.get_target_element() {
element.set_inner_html("");
}
}
/// 区切り線を追加
pub fn separator(&self) {
if let Some(element) = self.get_target_element() {
@ -113,7 +119,7 @@ impl WebConsoleBox {
element.set_inner_html(&new_content);
}
}
/// グループ開始(見出し付き)
pub fn group(&self, title: &str) {
if let Some(element) = self.get_target_element() {
@ -126,7 +132,7 @@ impl WebConsoleBox {
element.set_inner_html(&new_content);
}
}
/// グループ終了
pub fn group_end(&self) {
if let Some(element) = self.get_target_element() {
@ -143,19 +149,19 @@ impl BoxCore for WebConsoleBox {
fn box_id(&self) -> u64 {
self.base.id
}
fn parent_type_id(&self) -> Option<std::any::TypeId> {
self.base.parent_type_id
}
fn fmt_box(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "WebConsoleBox({})", self.target_element_id)
}
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
@ -166,7 +172,7 @@ impl NyashBox for WebConsoleBox {
fn clone_box(&self) -> Box<dyn NyashBox> {
Box::new(self.clone())
}
/// 仮実装: clone_boxと同じ後で修正
fn share_box(&self) -> Box<dyn NyashBox> {
self.clone_box()
@ -176,11 +182,9 @@ impl NyashBox for WebConsoleBox {
StringBox::new(format!("WebConsoleBox({})", self.target_element_id))
}
fn type_name(&self) -> &'static str {
"WebConsoleBox"
}
fn equals(&self, other: &dyn NyashBox) -> BoolBox {
if let Some(other_console) = other.as_any().downcast_ref::<WebConsoleBox>() {
@ -196,4 +200,4 @@ impl std::fmt::Display for WebConsoleBox {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.fmt_box(f)
}
}
}

View File

@ -1,11 +1,11 @@
/*!
* WebDisplayBox - ブラウザHTML要素表示制御Box
*
*
* WebAssembly環境でHTML要素への直接出力・スタイル制御
* プレイグラウンドの出力パネル等を完全制御
*/
use crate::box_trait::{NyashBox, StringBox, BoolBox, BoxCore, BoxBase};
use crate::box_trait::{BoolBox, BoxBase, BoxCore, NyashBox, StringBox};
use std::any::Any;
#[cfg(target_arch = "wasm32")]
@ -25,19 +25,19 @@ pub struct WebDisplayBox {
#[cfg(target_arch = "wasm32")]
impl WebDisplayBox {
pub fn new(element_id: String) -> Self {
Self {
Self {
base: BoxBase::new(),
target_element_id: element_id,
}
}
/// 指定した要素IDのHTML要素を取得
fn get_target_element(&self) -> Option<Element> {
let window = web_sys::window()?;
let document = window.document()?;
document.get_element_by_id(&self.target_element_id)
}
/// テキストを追加出力
pub fn print(&self, message: &str) {
if let Some(element) = self.get_target_element() {
@ -50,7 +50,7 @@ impl WebDisplayBox {
element.set_inner_html(&new_content);
}
}
/// テキストを改行付きで追加出力
pub fn println(&self, message: &str) {
if let Some(element) = self.get_target_element() {
@ -63,14 +63,14 @@ impl WebDisplayBox {
element.set_inner_html(&new_content);
}
}
/// HTMLコンテンツを完全置換
pub fn set_html(&self, html_content: &str) {
if let Some(element) = self.get_target_element() {
element.set_inner_html(html_content);
}
}
/// HTMLコンテンツを追加
pub fn append_html(&self, html_content: &str) {
if let Some(element) = self.get_target_element() {
@ -79,7 +79,7 @@ impl WebDisplayBox {
element.set_inner_html(&new_content);
}
}
/// CSSスタイルを設定
pub fn set_css(&self, property: &str, value: &str) {
if let Some(element) = self.get_target_element() {
@ -89,38 +89,38 @@ impl WebDisplayBox {
}
}
}
/// CSSクラスを追加
pub fn add_class(&self, class_name: &str) {
if let Some(element) = self.get_target_element() {
let _ = element.class_list().add_1(class_name);
}
}
/// CSSクラスを削除
pub fn remove_class(&self, class_name: &str) {
if let Some(element) = self.get_target_element() {
let _ = element.class_list().remove_1(class_name);
}
}
/// 内容をクリア
pub fn clear(&self) {
if let Some(element) = self.get_target_element() {
element.set_inner_html("");
}
}
/// 要素を表示
pub fn show(&self) {
self.set_css("display", "block");
}
/// 要素を非表示
pub fn hide(&self) {
self.set_css("display", "none");
}
/// スクロールを最下部に移動
pub fn scroll_to_bottom(&self) {
if let Some(element) = self.get_target_element() {
@ -136,19 +136,19 @@ impl BoxCore for WebDisplayBox {
fn box_id(&self) -> u64 {
self.base.id
}
fn parent_type_id(&self) -> Option<std::any::TypeId> {
self.base.parent_type_id
}
fn fmt_box(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "WebDisplayBox({})", self.target_element_id)
}
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
@ -159,7 +159,7 @@ impl NyashBox for WebDisplayBox {
fn clone_box(&self) -> Box<dyn NyashBox> {
Box::new(self.clone())
}
/// 仮実装: clone_boxと同じ後で修正
fn share_box(&self) -> Box<dyn NyashBox> {
self.clone_box()
@ -169,11 +169,9 @@ impl NyashBox for WebDisplayBox {
StringBox::new(format!("WebDisplayBox({})", self.target_element_id))
}
fn type_name(&self) -> &'static str {
"WebDisplayBox"
}
fn equals(&self, other: &dyn NyashBox) -> BoolBox {
if let Some(other_display) = other.as_any().downcast_ref::<WebDisplayBox>() {
@ -189,4 +187,4 @@ impl std::fmt::Display for WebDisplayBox {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.fmt_box(f)
}
}
}