Chandra

 view release on metacpan or  search on metacpan

Chandra.xs  view on Meta::CPAN

/*
 * Chandra.xs - Root XS file
 *
 * Thin wrapper: includes shared header (which provides all static
 * C functions when WEBVIEW_IMPLEMENTATION is defined), then pulls
 * in per-module XS fragments via INCLUDE:.
 */

#define WEBVIEW_IMPLEMENTATION
#define CHANDRA_XS_IMPLEMENTATION
#define CHANDRA_WINDOW_IMPLEMENTATION
#include "include/chandra/chandra.h"
#include "include/chandra/chandra_error.h"
#include "include/chandra/chandra_bind.h"
#include "include/chandra/chandra_element.h"
#include "include/chandra/chandra_devtools.h"
#include "include/chandra/chandra_internal.h"
#include "include/chandra/chandra_socket_common.h"
#include "include/chandra/chandra_socket_token.h"
#include "include/chandra/chandra_socket_hub.h"
#include "include/chandra/chandra_socket_client.h"
#include "include/chandra/chandra_notify.h"
#include "include/chandra/chandra_store.h"
#include "include/chandra/chandra_log.h"
#include "include/chandra/chandra_assets.h"
#include "include/chandra/chandra_clipboard.h"
#include "include/chandra/chandra_contextmenu.h"
#include "include/chandra/chandra_window.h"
#include "include/chandra/chandra_splash.h"
#include "include/chandra/chandra_form.h"
#include "include/chandra/chandra_bridge_ext.h"
#include "include/chandra/chandra_canvas.h"

/* Window registry - maps native wid to Perl SV* objects */
static HV *_window_registry = NULL;
static IV _window_id_counter = 0;

static void _ensure_registry(pTHX) {
    if (!_window_registry) {
        _window_registry = newHV();
    }
}

static void _register_window(pTHX_ IV wid, SV *obj) {
    _ensure_registry(aTHX);
    hv_store(_window_registry, (char*)&wid, sizeof(wid), SvREFCNT_inc(obj), 0);
}

static void _unregister_window(pTHX_ IV wid) {
    _ensure_registry(aTHX);
    hv_delete(_window_registry, (char*)&wid, sizeof(wid), G_DISCARD);
}

static SV *_get_window(pTHX_ IV wid) {
    SV **svp;
    _ensure_registry(aTHX);
    svp = hv_fetch(_window_registry, (char*)&wid, sizeof(wid), 0);
    return svp ? *svp : NULL;
}

static IV _get_window_count(pTHX) {
    _ensure_registry(aTHX);
    return HvKEYS(_window_registry);
}

/* Macros to call the static functions with aTHX */
#define ENSURE_REGISTRY() _ensure_registry(aTHX)
#define REGISTER_WINDOW(wid, obj) _register_window(aTHX_ wid, obj)
#define UNREGISTER_WINDOW(wid) _unregister_window(aTHX_ wid)
#define GET_WINDOW(wid) _get_window(aTHX_ wid)
#define GET_WINDOW_COUNT() _get_window_count(aTHX)

/* Toast state */
static int _toast_id = 0;
static int _toast_injected = 0;

/* Modal state */
static int _modal_id = 0;
static int _modal_injected = 0;

static const char *CHANDRA_TOAST_JS =
"(function(){"
"if(window.__chandraToast)return;"
"var c=document.createElement('div');"
"c.id='__chandra_toast_container';"
"c.style.cssText='position:fixed;top:16px;right:16px;z-index:99999;display:flex;flex-direction:column;gap:8px;pointer-events:none;max-width:380px;';"

Chandra.xs  view on Meta::CPAN

"var ftr=document.createElement('div');"
"ftr.style.cssText='padding:12px 20px 16px;display:flex;gap:8px;justify-content:flex-end;border-top:1px solid var(--chandra-border,#e0e0e0);';"
"opts.buttons.forEach(function(b){"
"var btn=document.createElement('button');"
"btn.textContent=b.label;"
"var cls='chandra-btn';"
"if(b.cls)cls+=' chandra-btn-'+b.cls;"
"btn.className=cls;"
"btn.onclick=function(){"
"if(b.action==='close')close(id);"
"else if(b.handler){"
"var val=null;var inp=document.getElementById(id+'_input');if(inp)val=inp.value;"
"window.chandra.invoke(b.handler,[val]).then(function(){close(id);});"
"}"
"};"
"ftr.appendChild(btn);});"
"modal.appendChild(ftr);}"
"overlay.appendChild(modal);"
"document.body.appendChild(overlay);"
"activeModal=id;"
"requestAnimationFrame(function(){modal.style.opacity='1';modal.style.transform='scale(1)';});"
"var inp=document.getElementById(id+'_input');if(inp)setTimeout(function(){inp.focus();inp.select();},100);"
"}"
"function close(id){"
"var ov=document.getElementById(id+'_overlay');"
"if(!ov)return;"
"var m=document.getElementById(id);"
"if(m){m.style.opacity='0';m.style.transform='scale(0.95)';}"
"setTimeout(function(){if(ov.parentNode)ov.parentNode.removeChild(ov);},200);"
"activeModal=null;}"
"window.__chandraModal={create:create,close:close};"
"})();";

MODULE = Chandra    PACKAGE = Chandra

INCLUDE: xs/core.xs
INCLUDE: xs/tray.xs
INCLUDE: xs/error.xs
INCLUDE: xs/event.xs
INCLUDE: xs/bridge.xs
INCLUDE: xs/bridge_extension.xs
INCLUDE: xs/bind.xs
INCLUDE: xs/element.xs
INCLUDE: xs/dialog.xs
INCLUDE: xs/devtools.xs
INCLUDE: xs/hotreload.xs
INCLUDE: xs/notify.xs

INCLUDE: xs/protocol.xs

INCLUDE: xs/shortcut.xs

INCLUDE: xs/socket_connection.xs
INCLUDE: xs/socket_token.xs
INCLUDE: xs/socket_hub.xs
INCLUDE: xs/socket_client.xs

INCLUDE: xs/app.xs

INCLUDE: xs/assets.xs
INCLUDE: xs/clipboard.xs
INCLUDE: xs/dragdrop.xs
INCLUDE: xs/contextmenu.xs
INCLUDE: xs/store.xs
INCLUDE: xs/log.xs
INCLUDE: xs/window.xs
INCLUDE: xs/splash.xs
INCLUDE: xs/form.xs
INCLUDE: xs/canvas.xs
INCLUDE: xs/toast.xs
INCLUDE: xs/modal.xs



( run in 0.621 second using v1.01-cache-2.11-cpan-84e82930d8c )