aegis-framework 0.1.4 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -609,7 +609,7 @@
609
609
  /**
610
610
  * Version of Aegis
611
611
  */
612
- version: '0.1.0',
612
+ version: '0.1.4',
613
613
 
614
614
  /**
615
615
  * Check if running in Aegis environment
@@ -619,11 +619,296 @@
619
619
  }
620
620
  };
621
621
 
622
+ // ==================== Aegis Utility API ($ helpers) ====================
623
+
624
+ /**
625
+ * Select single element (like jQuery $)
626
+ * @param {string} selector - CSS selector
627
+ * @returns {Element|null}
628
+ */
629
+ function $(selector) {
630
+ if (selector.startsWith('#') && !selector.includes(' ') && !selector.includes('.')) {
631
+ return document.getElementById(selector.slice(1));
632
+ }
633
+ return document.querySelector(selector);
634
+ }
635
+
636
+ /**
637
+ * Select all elements
638
+ * @param {string} selector - CSS selector
639
+ * @returns {NodeList}
640
+ */
641
+ function $$(selector) {
642
+ return document.querySelectorAll(selector);
643
+ }
644
+
645
+ /**
646
+ * Utility methods attached to $
647
+ */
648
+ $.on = function (selector, events, handler, options = {}) {
649
+ const elements = typeof selector === 'string' ? $$(selector) : [selector];
650
+ const eventList = events.split(' ');
651
+ elements.forEach(el => {
652
+ eventList.forEach(event => {
653
+ el.addEventListener(event.trim(), handler, options);
654
+ });
655
+ });
656
+ return elements;
657
+ };
658
+
659
+ $.once = function (selector, events, handler) {
660
+ return $.on(selector, events, handler, { once: true });
661
+ };
662
+
663
+ $.off = function (selector, events, handler) {
664
+ const elements = typeof selector === 'string' ? $$(selector) : [selector];
665
+ const eventList = events.split(' ');
666
+ elements.forEach(el => {
667
+ eventList.forEach(event => {
668
+ el.removeEventListener(event.trim(), handler);
669
+ });
670
+ });
671
+ return elements;
672
+ };
673
+
674
+ $.create = function (tag, options = {}) {
675
+ const el = document.createElement(tag);
676
+ if (options.id) el.id = options.id;
677
+ if (options.class) el.className = options.class;
678
+ if (options.html) el.innerHTML = options.html;
679
+ if (options.text) el.textContent = options.text;
680
+ if (options.attrs) {
681
+ Object.entries(options.attrs).forEach(([key, value]) => {
682
+ el.setAttribute(key, value);
683
+ });
684
+ }
685
+ if (options.style) {
686
+ Object.assign(el.style, options.style);
687
+ }
688
+ if (options.data) {
689
+ Object.entries(options.data).forEach(([key, value]) => {
690
+ el.dataset[key] = value;
691
+ });
692
+ }
693
+ if (options.on) {
694
+ Object.entries(options.on).forEach(([event, handler]) => {
695
+ el.addEventListener(event, handler);
696
+ });
697
+ }
698
+ if (options.parent) {
699
+ const parent = typeof options.parent === 'string' ? $(options.parent) : options.parent;
700
+ if (parent) parent.appendChild(el);
701
+ }
702
+ return el;
703
+ };
704
+
705
+ $.addClass = function (selector, ...classes) {
706
+ const el = typeof selector === 'string' ? $(selector) : selector;
707
+ if (el) el.classList.add(...classes);
708
+ return el;
709
+ };
710
+
711
+ $.removeClass = function (selector, ...classes) {
712
+ const el = typeof selector === 'string' ? $(selector) : selector;
713
+ if (el) el.classList.remove(...classes);
714
+ return el;
715
+ };
716
+
717
+ $.toggleClass = function (selector, className, force) {
718
+ const el = typeof selector === 'string' ? $(selector) : selector;
719
+ if (el) el.classList.toggle(className, force);
720
+ return el;
721
+ };
722
+
723
+ $.hasClass = function (selector, className) {
724
+ const el = typeof selector === 'string' ? $(selector) : selector;
725
+ return el ? el.classList.contains(className) : false;
726
+ };
727
+
728
+ $.css = function (selector, styles) {
729
+ const el = typeof selector === 'string' ? $(selector) : selector;
730
+ if (el && styles) Object.assign(el.style, styles);
731
+ return el;
732
+ };
733
+
734
+ $.hide = function (selector) {
735
+ const el = typeof selector === 'string' ? $(selector) : selector;
736
+ if (el) el.style.display = 'none';
737
+ return el;
738
+ };
739
+
740
+ $.show = function (selector, display = 'block') {
741
+ const el = typeof selector === 'string' ? $(selector) : selector;
742
+ if (el) el.style.display = display;
743
+ return el;
744
+ };
745
+
746
+ $.toggle = function (selector) {
747
+ const el = typeof selector === 'string' ? $(selector) : selector;
748
+ if (el) el.style.display = el.style.display === 'none' ? '' : 'none';
749
+ return el;
750
+ };
751
+
752
+ $.attr = function (selector, name, value) {
753
+ const el = typeof selector === 'string' ? $(selector) : selector;
754
+ if (!el) return null;
755
+ if (value === undefined) return el.getAttribute(name);
756
+ el.setAttribute(name, value);
757
+ return el;
758
+ };
759
+
760
+ $.data = function (selector, key, value) {
761
+ const el = typeof selector === 'string' ? $(selector) : selector;
762
+ if (!el) return null;
763
+ if (value === undefined) return el.dataset[key];
764
+ el.dataset[key] = value;
765
+ return el;
766
+ };
767
+
768
+ $.html = function (selector, content) {
769
+ const el = typeof selector === 'string' ? $(selector) : selector;
770
+ if (!el) return null;
771
+ if (content === undefined) return el.innerHTML;
772
+ el.innerHTML = content;
773
+ return el;
774
+ };
775
+
776
+ $.text = function (selector, content) {
777
+ const el = typeof selector === 'string' ? $(selector) : selector;
778
+ if (!el) return null;
779
+ if (content === undefined) return el.textContent;
780
+ el.textContent = content;
781
+ return el;
782
+ };
783
+
784
+ $.each = function (selector, callback) {
785
+ const elements = typeof selector === 'string' ? $$(selector) : selector;
786
+ elements.forEach((el, i) => callback(el, i));
787
+ return elements;
788
+ };
789
+
790
+ $.remove = function (selector) {
791
+ const el = typeof selector === 'string' ? $(selector) : selector;
792
+ if (el && el.parentNode) el.parentNode.removeChild(el);
793
+ return el;
794
+ };
795
+
796
+ $.append = function (parent, child) {
797
+ const p = typeof parent === 'string' ? $(parent) : parent;
798
+ const c = typeof child === 'string' ? $(child) : child;
799
+ if (p && c) p.appendChild(c);
800
+ return p;
801
+ };
802
+
803
+ $.prepend = function (parent, child) {
804
+ const p = typeof parent === 'string' ? $(parent) : parent;
805
+ const c = typeof child === 'string' ? $(child) : child;
806
+ if (p && c) p.insertBefore(c, p.firstChild);
807
+ return p;
808
+ };
809
+
810
+ // JSON Utilities
811
+ $.parseJSON = function (str, fallback = null) {
812
+ try {
813
+ return JSON.parse(str);
814
+ } catch (e) {
815
+ return fallback;
816
+ }
817
+ };
818
+
819
+ $.stringify = function (obj, pretty = false) {
820
+ return JSON.stringify(obj, null, pretty ? 2 : 0);
821
+ };
822
+
823
+ // LocalStorage Utilities
824
+ $.storage = {
825
+ get: function (key, fallback = null) {
826
+ try {
827
+ const value = localStorage.getItem(key);
828
+ return value ? JSON.parse(value) : fallback;
829
+ } catch (e) {
830
+ return fallback;
831
+ }
832
+ },
833
+ set: function (key, value) {
834
+ try {
835
+ localStorage.setItem(key, JSON.stringify(value));
836
+ return true;
837
+ } catch (e) {
838
+ return false;
839
+ }
840
+ },
841
+ remove: function (key) {
842
+ localStorage.removeItem(key);
843
+ },
844
+ clear: function () {
845
+ localStorage.clear();
846
+ }
847
+ };
848
+
849
+ // Animation helpers
850
+ $.fadeIn = function (selector, duration = 300) {
851
+ const el = typeof selector === 'string' ? $(selector) : selector;
852
+ if (!el) return;
853
+ el.style.opacity = '0';
854
+ el.style.display = '';
855
+ el.style.transition = `opacity ${duration}ms ease`;
856
+ requestAnimationFrame(() => {
857
+ el.style.opacity = '1';
858
+ });
859
+ return el;
860
+ };
861
+
862
+ $.fadeOut = function (selector, duration = 300) {
863
+ const el = typeof selector === 'string' ? $(selector) : selector;
864
+ if (!el) return;
865
+ el.style.transition = `opacity ${duration}ms ease`;
866
+ el.style.opacity = '0';
867
+ setTimeout(() => {
868
+ el.style.display = 'none';
869
+ }, duration);
870
+ return el;
871
+ };
872
+
873
+ // Ready handler (like jQuery $(document).ready)
874
+ $.ready = function (callback) {
875
+ if (document.readyState !== 'loading') {
876
+ callback();
877
+ } else {
878
+ document.addEventListener('DOMContentLoaded', callback);
879
+ }
880
+ };
881
+
882
+ // Debounce utility
883
+ $.debounce = function (func, wait) {
884
+ let timeout;
885
+ return function (...args) {
886
+ clearTimeout(timeout);
887
+ timeout = setTimeout(() => func.apply(this, args), wait);
888
+ };
889
+ };
890
+
891
+ // Throttle utility
892
+ $.throttle = function (func, limit) {
893
+ let inThrottle;
894
+ return function (...args) {
895
+ if (!inThrottle) {
896
+ func.apply(this, args);
897
+ inThrottle = true;
898
+ setTimeout(() => inThrottle = false, limit);
899
+ }
900
+ };
901
+ };
902
+
622
903
  // ==================== Expose to Window ====================
623
904
 
624
905
  // Make Aegis available globally
625
906
  window.Aegis = Aegis;
626
907
 
908
+ // Expose $ and $$ globally (optional jQuery-like syntax)
909
+ window.$ = window.$ || $;
910
+ window.$$ = window.$$ || $$;
911
+
627
912
  // Also expose as module if applicable
628
913
  if (typeof module !== 'undefined' && module.exports) {
629
914
  module.exports = Aegis;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aegis-framework",
3
- "version": "0.1.4",
3
+ "version": "0.2.0",
4
4
  "description": "Lightweight AppImage framework using WebKit2GTK and Python - An alternative to Electron that creates ~200KB apps instead of 150MB!",
5
5
  "keywords": [
6
6
  "appimage",