aegis-framework 0.2.0 → 0.2.1

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.
@@ -604,300 +604,392 @@
604
604
  return invoke(action, payload);
605
605
  },
606
606
 
607
- // ==================== Utility Functions ====================
607
+ // ==================== DOM Utilities ====================
608
608
 
609
609
  /**
610
610
  * Version of Aegis
611
611
  */
612
- version: '0.1.4',
612
+ version: '0.2.0',
613
613
 
614
614
  /**
615
615
  * Check if running in Aegis environment
616
616
  */
617
617
  isAegis: function () {
618
618
  return !!(window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.aegis);
619
- }
620
- };
619
+ },
621
620
 
622
- // ==================== Aegis Utility API ($ helpers) ====================
621
+ // ==================== Element Selection ====================
623
622
 
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
- }
623
+ /**
624
+ * Get single element by selector
625
+ */
626
+ get: function (selector) {
627
+ if (typeof selector !== 'string') return selector;
628
+ if (selector.startsWith('#') && !selector.includes(' ') && !selector.includes('.')) {
629
+ return document.getElementById(selector.slice(1));
630
+ }
631
+ return document.querySelector(selector);
632
+ },
635
633
 
636
- /**
637
- * Select all elements
638
- * @param {string} selector - CSS selector
639
- * @returns {NodeList}
640
- */
641
- function $$(selector) {
642
- return document.querySelectorAll(selector);
643
- }
634
+ /**
635
+ * Get all elements by selector
636
+ */
637
+ getAll: function (selector) {
638
+ return document.querySelectorAll(selector);
639
+ },
644
640
 
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);
641
+ // ==================== Event Shortcuts ====================
642
+
643
+ /**
644
+ * Universal event listener
645
+ */
646
+ on: function (selector, events, handler, options = {}) {
647
+ const elements = typeof selector === 'string' ? Aegis.getAll(selector) : [selector];
648
+ const eventList = events.split(' ');
649
+ elements.forEach(el => {
650
+ eventList.forEach(event => {
651
+ el.addEventListener(event.trim(), handler, options);
652
+ });
654
653
  });
655
- });
656
- return elements;
657
- };
654
+ return elements;
655
+ },
658
656
 
659
- $.once = function (selector, events, handler) {
660
- return $.on(selector, events, handler, { once: true });
661
- };
657
+ /**
658
+ * One-time event listener
659
+ */
660
+ once: function (selector, events, handler) {
661
+ return Aegis.on(selector, events, handler, { once: true });
662
+ },
662
663
 
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);
664
+ /**
665
+ * Remove event listener
666
+ */
667
+ off: function (selector, events, handler) {
668
+ const elements = typeof selector === 'string' ? Aegis.getAll(selector) : [selector];
669
+ const eventList = events.split(' ');
670
+ elements.forEach(el => {
671
+ eventList.forEach(event => {
672
+ el.removeEventListener(event.trim(), handler);
673
+ });
669
674
  });
670
- });
671
- return elements;
672
- };
675
+ return elements;
676
+ },
673
677
 
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
- };
678
+ /**
679
+ * Click shortcut
680
+ */
681
+ click: function (selector, handler) {
682
+ return Aegis.on(selector, 'click', handler);
683
+ },
704
684
 
705
- $.addClass = function (selector, ...classes) {
706
- const el = typeof selector === 'string' ? $(selector) : selector;
707
- if (el) el.classList.add(...classes);
708
- return el;
709
- };
685
+ /**
686
+ * Submit shortcut
687
+ */
688
+ submit: function (selector, handler) {
689
+ return Aegis.on(selector, 'submit', handler);
690
+ },
710
691
 
711
- $.removeClass = function (selector, ...classes) {
712
- const el = typeof selector === 'string' ? $(selector) : selector;
713
- if (el) el.classList.remove(...classes);
714
- return el;
715
- };
692
+ /**
693
+ * Change shortcut
694
+ */
695
+ change: function (selector, handler) {
696
+ return Aegis.on(selector, 'change', handler);
697
+ },
716
698
 
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
- };
699
+ /**
700
+ * Input shortcut
701
+ */
702
+ input: function (selector, handler) {
703
+ return Aegis.on(selector, 'input', handler);
704
+ },
722
705
 
723
- $.hasClass = function (selector, className) {
724
- const el = typeof selector === 'string' ? $(selector) : selector;
725
- return el ? el.classList.contains(className) : false;
726
- };
706
+ /**
707
+ * Hover shortcut (mouseenter + mouseleave)
708
+ */
709
+ hover: function (selector, onEnter, onLeave) {
710
+ Aegis.on(selector, 'mouseenter', onEnter);
711
+ if (onLeave) Aegis.on(selector, 'mouseleave', onLeave);
712
+ },
727
713
 
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
- };
714
+ /**
715
+ * Key press shortcut
716
+ */
717
+ keypress: function (selector, handler) {
718
+ return Aegis.on(selector, 'keydown', handler);
719
+ },
733
720
 
734
- $.hide = function (selector) {
735
- const el = typeof selector === 'string' ? $(selector) : selector;
736
- if (el) el.style.display = 'none';
737
- return el;
738
- };
721
+ // ==================== Element Creation ====================
739
722
 
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
- };
723
+ /**
724
+ * Create element with options
725
+ */
726
+ create: function (tag, options = {}) {
727
+ const el = document.createElement(tag);
728
+ if (options.id) el.id = options.id;
729
+ if (options.class) el.className = options.class;
730
+ if (options.html) el.innerHTML = options.html;
731
+ if (options.text) el.textContent = options.text;
732
+ if (options.value !== undefined) el.value = options.value;
733
+ if (options.attrs) {
734
+ Object.entries(options.attrs).forEach(([key, value]) => {
735
+ el.setAttribute(key, value);
736
+ });
737
+ }
738
+ if (options.style) {
739
+ Object.assign(el.style, options.style);
740
+ }
741
+ if (options.data) {
742
+ Object.entries(options.data).forEach(([key, value]) => {
743
+ el.dataset[key] = value;
744
+ });
745
+ }
746
+ if (options.on) {
747
+ Object.entries(options.on).forEach(([event, handler]) => {
748
+ el.addEventListener(event, handler);
749
+ });
750
+ }
751
+ if (options.children) {
752
+ options.children.forEach(child => el.appendChild(child));
753
+ }
754
+ if (options.parent) {
755
+ const parent = Aegis.get(options.parent);
756
+ if (parent) parent.appendChild(el);
757
+ }
758
+ return el;
759
+ },
745
760
 
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
- };
761
+ // ==================== Class Manipulation ====================
751
762
 
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
- };
763
+ addClass: function (selector, ...classes) {
764
+ const el = Aegis.get(selector);
765
+ if (el) el.classList.add(...classes);
766
+ return el;
767
+ },
759
768
 
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
- };
769
+ removeClass: function (selector, ...classes) {
770
+ const el = Aegis.get(selector);
771
+ if (el) el.classList.remove(...classes);
772
+ return el;
773
+ },
767
774
 
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
+ toggleClass: function (selector, className, force) {
776
+ const el = Aegis.get(selector);
777
+ if (el) el.classList.toggle(className, force);
778
+ return el;
779
+ },
775
780
 
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
- };
781
+ hasClass: function (selector, className) {
782
+ const el = Aegis.get(selector);
783
+ return el ? el.classList.contains(className) : false;
784
+ },
783
785
 
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
- };
786
+ // ==================== Style Manipulation ====================
789
787
 
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
- };
788
+ css: function (selector, styles) {
789
+ const el = Aegis.get(selector);
790
+ if (el && styles) Object.assign(el.style, styles);
791
+ return el;
792
+ },
795
793
 
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
- };
794
+ hide: function (selector) {
795
+ const el = Aegis.get(selector);
796
+ if (el) el.style.display = 'none';
797
+ return el;
798
+ },
802
799
 
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
- };
800
+ show: function (selector, display = 'block') {
801
+ const el = Aegis.get(selector);
802
+ if (el) el.style.display = display;
803
+ return el;
804
+ },
809
805
 
810
- // JSON Utilities
811
- $.parseJSON = function (str, fallback = null) {
812
- try {
813
- return JSON.parse(str);
814
- } catch (e) {
815
- return fallback;
816
- }
817
- };
806
+ toggleDisplay: function (selector) {
807
+ const el = Aegis.get(selector);
808
+ if (el) el.style.display = el.style.display === 'none' ? '' : 'none';
809
+ return el;
810
+ },
818
811
 
819
- $.stringify = function (obj, pretty = false) {
820
- return JSON.stringify(obj, null, pretty ? 2 : 0);
821
- };
812
+ // ==================== Content Manipulation ====================
813
+
814
+ attr: function (selector, name, value) {
815
+ const el = Aegis.get(selector);
816
+ if (!el) return null;
817
+ if (value === undefined) return el.getAttribute(name);
818
+ el.setAttribute(name, value);
819
+ return el;
820
+ },
821
+
822
+ data: function (selector, key, value) {
823
+ const el = Aegis.get(selector);
824
+ if (!el) return null;
825
+ if (value === undefined) return el.dataset[key];
826
+ el.dataset[key] = value;
827
+ return el;
828
+ },
829
+
830
+ html: function (selector, content) {
831
+ const el = Aegis.get(selector);
832
+ if (!el) return null;
833
+ if (content === undefined) return el.innerHTML;
834
+ el.innerHTML = content;
835
+ return el;
836
+ },
837
+
838
+ text: function (selector, content) {
839
+ const el = Aegis.get(selector);
840
+ if (!el) return null;
841
+ if (content === undefined) return el.textContent;
842
+ el.textContent = content;
843
+ return el;
844
+ },
845
+
846
+ val: function (selector, value) {
847
+ const el = Aegis.get(selector);
848
+ if (!el) return null;
849
+ if (value === undefined) return el.value;
850
+ el.value = value;
851
+ return el;
852
+ },
853
+
854
+ // ==================== DOM Manipulation ====================
855
+
856
+ each: function (selector, callback) {
857
+ const elements = typeof selector === 'string' ? Aegis.getAll(selector) : selector;
858
+ elements.forEach((el, i) => callback(el, i));
859
+ return elements;
860
+ },
861
+
862
+ removeEl: function (selector) {
863
+ const el = Aegis.get(selector);
864
+ if (el && el.parentNode) el.parentNode.removeChild(el);
865
+ return el;
866
+ },
867
+
868
+ append: function (parent, child) {
869
+ const p = Aegis.get(parent);
870
+ const c = typeof child === 'string' ? Aegis.get(child) : child;
871
+ if (p && c) p.appendChild(c);
872
+ return p;
873
+ },
874
+
875
+ prepend: function (parent, child) {
876
+ const p = Aegis.get(parent);
877
+ const c = typeof child === 'string' ? Aegis.get(child) : child;
878
+ if (p && c) p.insertBefore(c, p.firstChild);
879
+ return p;
880
+ },
881
+
882
+ empty: function (selector) {
883
+ const el = Aegis.get(selector);
884
+ if (el) el.innerHTML = '';
885
+ return el;
886
+ },
887
+
888
+ // ==================== JSON Utilities ====================
822
889
 
823
- // LocalStorage Utilities
824
- $.storage = {
825
- get: function (key, fallback = null) {
890
+ parseJSON: function (str, fallback = null) {
826
891
  try {
827
- const value = localStorage.getItem(key);
828
- return value ? JSON.parse(value) : fallback;
892
+ return JSON.parse(str);
829
893
  } catch (e) {
830
894
  return fallback;
831
895
  }
832
896
  },
833
- set: function (key, value) {
834
- try {
835
- localStorage.setItem(key, JSON.stringify(value));
836
- return true;
837
- } catch (e) {
838
- return false;
839
- }
897
+
898
+ stringify: function (obj, pretty = false) {
899
+ return JSON.stringify(obj, null, pretty ? 2 : 0);
840
900
  },
841
- remove: function (key) {
842
- localStorage.removeItem(key);
901
+
902
+ // ==================== Storage Utilities ====================
903
+
904
+ storage: {
905
+ get: function (key, fallback = null) {
906
+ try {
907
+ const value = localStorage.getItem(key);
908
+ return value ? JSON.parse(value) : fallback;
909
+ } catch (e) {
910
+ return fallback;
911
+ }
912
+ },
913
+ set: function (key, value) {
914
+ try {
915
+ localStorage.setItem(key, JSON.stringify(value));
916
+ return true;
917
+ } catch (e) {
918
+ return false;
919
+ }
920
+ },
921
+ remove: function (key) {
922
+ localStorage.removeItem(key);
923
+ },
924
+ clear: function () {
925
+ localStorage.clear();
926
+ }
843
927
  },
844
- clear: function () {
845
- localStorage.clear();
846
- }
847
- };
848
928
 
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
- };
929
+ // ==================== Animation Utilities ====================
861
930
 
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
- };
931
+ fadeIn: function (selector, duration = 300) {
932
+ const el = Aegis.get(selector);
933
+ if (!el) return;
934
+ el.style.opacity = '0';
935
+ el.style.display = '';
936
+ el.style.transition = `opacity ${duration}ms ease`;
937
+ requestAnimationFrame(() => {
938
+ el.style.opacity = '1';
939
+ });
940
+ return el;
941
+ },
872
942
 
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
- };
943
+ fadeOut: function (selector, duration = 300) {
944
+ const el = Aegis.get(selector);
945
+ if (!el) return;
946
+ el.style.transition = `opacity ${duration}ms ease`;
947
+ el.style.opacity = '0';
948
+ setTimeout(() => {
949
+ el.style.display = 'none';
950
+ }, duration);
951
+ return el;
952
+ },
881
953
 
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
- };
954
+ // ==================== Utility Functions ====================
890
955
 
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);
956
+ ready: function (callback) {
957
+ if (document.readyState !== 'loading') {
958
+ callback();
959
+ } else {
960
+ document.addEventListener('DOMContentLoaded', callback);
899
961
  }
900
- };
962
+ },
963
+
964
+ debounce: function (func, wait) {
965
+ let timeout;
966
+ return function (...args) {
967
+ clearTimeout(timeout);
968
+ timeout = setTimeout(() => func.apply(this, args), wait);
969
+ };
970
+ },
971
+
972
+ throttle: function (func, limit) {
973
+ let inThrottle;
974
+ return function (...args) {
975
+ if (!inThrottle) {
976
+ func.apply(this, args);
977
+ inThrottle = true;
978
+ setTimeout(() => inThrottle = false, limit);
979
+ }
980
+ };
981
+ },
982
+
983
+ delay: function (ms) {
984
+ return new Promise(resolve => setTimeout(resolve, ms));
985
+ },
986
+
987
+ /**
988
+ * Generate unique ID
989
+ */
990
+ uid: function (prefix = 'aegis') {
991
+ return `${prefix}-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
992
+ }
901
993
  };
902
994
 
903
995
  // ==================== Expose to Window ====================
@@ -905,10 +997,6 @@
905
997
  // Make Aegis available globally
906
998
  window.Aegis = Aegis;
907
999
 
908
- // Expose $ and $$ globally (optional jQuery-like syntax)
909
- window.$ = window.$ || $;
910
- window.$$ = window.$$ || $$;
911
-
912
1000
  // Also expose as module if applicable
913
1001
  if (typeof module !== 'undefined' && module.exports) {
914
1002
  module.exports = Aegis;
@@ -917,3 +1005,4 @@
917
1005
  console.log('%c⚡ Aegis v' + Aegis.version + ' loaded', 'color: #00ff88; font-weight: bold;');
918
1006
 
919
1007
  })();
1008
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aegis-framework",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
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",