aegis-framework 0.1.4 → 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,18 +604,391 @@
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.0',
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
+
621
+ // ==================== Element Selection ====================
622
+
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
+ },
633
+
634
+ /**
635
+ * Get all elements by selector
636
+ */
637
+ getAll: function (selector) {
638
+ return document.querySelectorAll(selector);
639
+ },
640
+
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
+ });
653
+ });
654
+ return elements;
655
+ },
656
+
657
+ /**
658
+ * One-time event listener
659
+ */
660
+ once: function (selector, events, handler) {
661
+ return Aegis.on(selector, events, handler, { once: true });
662
+ },
663
+
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
+ });
674
+ });
675
+ return elements;
676
+ },
677
+
678
+ /**
679
+ * Click shortcut
680
+ */
681
+ click: function (selector, handler) {
682
+ return Aegis.on(selector, 'click', handler);
683
+ },
684
+
685
+ /**
686
+ * Submit shortcut
687
+ */
688
+ submit: function (selector, handler) {
689
+ return Aegis.on(selector, 'submit', handler);
690
+ },
691
+
692
+ /**
693
+ * Change shortcut
694
+ */
695
+ change: function (selector, handler) {
696
+ return Aegis.on(selector, 'change', handler);
697
+ },
698
+
699
+ /**
700
+ * Input shortcut
701
+ */
702
+ input: function (selector, handler) {
703
+ return Aegis.on(selector, 'input', handler);
704
+ },
705
+
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
+ },
713
+
714
+ /**
715
+ * Key press shortcut
716
+ */
717
+ keypress: function (selector, handler) {
718
+ return Aegis.on(selector, 'keydown', handler);
719
+ },
720
+
721
+ // ==================== Element Creation ====================
722
+
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
+ },
760
+
761
+ // ==================== Class Manipulation ====================
762
+
763
+ addClass: function (selector, ...classes) {
764
+ const el = Aegis.get(selector);
765
+ if (el) el.classList.add(...classes);
766
+ return el;
767
+ },
768
+
769
+ removeClass: function (selector, ...classes) {
770
+ const el = Aegis.get(selector);
771
+ if (el) el.classList.remove(...classes);
772
+ return el;
773
+ },
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
+ },
780
+
781
+ hasClass: function (selector, className) {
782
+ const el = Aegis.get(selector);
783
+ return el ? el.classList.contains(className) : false;
784
+ },
785
+
786
+ // ==================== Style Manipulation ====================
787
+
788
+ css: function (selector, styles) {
789
+ const el = Aegis.get(selector);
790
+ if (el && styles) Object.assign(el.style, styles);
791
+ return el;
792
+ },
793
+
794
+ hide: function (selector) {
795
+ const el = Aegis.get(selector);
796
+ if (el) el.style.display = 'none';
797
+ return el;
798
+ },
799
+
800
+ show: function (selector, display = 'block') {
801
+ const el = Aegis.get(selector);
802
+ if (el) el.style.display = display;
803
+ return el;
804
+ },
805
+
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
+ },
811
+
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 ====================
889
+
890
+ parseJSON: function (str, fallback = null) {
891
+ try {
892
+ return JSON.parse(str);
893
+ } catch (e) {
894
+ return fallback;
895
+ }
896
+ },
897
+
898
+ stringify: function (obj, pretty = false) {
899
+ return JSON.stringify(obj, null, pretty ? 2 : 0);
900
+ },
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
+ }
927
+ },
928
+
929
+ // ==================== Animation Utilities ====================
930
+
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
+ },
942
+
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
+ },
953
+
954
+ // ==================== Utility Functions ====================
955
+
956
+ ready: function (callback) {
957
+ if (document.readyState !== 'loading') {
958
+ callback();
959
+ } else {
960
+ document.addEventListener('DOMContentLoaded', callback);
961
+ }
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)}`;
619
992
  }
620
993
  };
621
994
 
@@ -632,3 +1005,4 @@
632
1005
  console.log('%c⚡ Aegis v' + Aegis.version + ' loaded', 'color: #00ff88; font-weight: bold;');
633
1006
 
634
1007
  })();
1008
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aegis-framework",
3
- "version": "0.1.4",
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",