Author: LakeFox
Email: [email protected]
Date: Tue, 21 May 2024 21:15:29 -0600
docs/utils/index.html
added dynamic FPS
Commits
ae78990ed5b06e02833bd8e578a3af1df49adc00 ae742fdbda42322f4fa1d30761f516bf1ad45a70 1ae1fe418977632fafe3e61c5f02e87f0cad6c87 099527773e9bc03b40b9ce5d8a492ebbcdebcf32 b6acff3a27a7c66e35ab7ea5ffe48f1a69efaf11 07144afe32b8dd752fc4d80efd81529e2df9e4e5 ca735fa2c136dd5f35a5ccf2ffe2133b906c7f94 e2ea9c897ee1e89f89cd5c043632326348191b3a 10f4ce166028ee8ff926170d4d9e17d54e63a4a4 4bd704181610864a1fc4ebe65f20220ea1f1c00b 1c468e139a0f87655e4222b8512c38bec429d067 d8d6cadd2741b05c7a121ccb6753c5a48b8ad1b4 4c0529a8475408ee41d4e4dbd9c969db14594d37 ed8180f077d294d1e2f347f6c30d2977e8670b42 9113424c26a247352fe7b111fff39d1562f6c342 f783d5cacccf047368f8f20fc687bf5ad8f6f66a 66084134570c2a3d87e1336a2ab2ca50341b93b2 031df3b2fd4851345dd6f4c443057141d5b9e65b baf5d8cc1ccf27d14e4e58edcc4c170bba6445df e9c8f7961cf8b188938535b318b50397a76268ba 29572e238d6ba3f401717032bd12a2f409bf1ea9 d6025b04ef9516745adae85a478cbf9f98433597 476d6415583067674f395660961e33b9b40c3e66 906dd99de66ad7df92011a52fb19e0319224741e 4c44132d28d06548d2c90c2f8ca72dd3047fa52d 79e4c754771ba514b29a36e96a7570f266de3c41 36aaa13c4ea4d1235c64febfe9a8fd797037bbb2 6d4b83918686647193953a59c166baf7455b4996 c6a1e4a5102e9a3b5045957c22a0a73ac1a7ca4c db934f090648cdcd96e2f5f12a9bad762c60bfcd 7af8fc3f425ca3814ce1088fbd8a7f82513a1bb2 1c650539c11b715b14ee9013ad7d7faa8f733a7a 717ed8747f4df855c63e13ff95dcab720b8713cd 1c786f0d0efe1a47c285564824c9503881bef393 af527f354d956456e2e71a7f81f1470e74888e69 94ded12a3e3953459ccfbec2f225cecb43b47c73 c0081dc2f877de951fd8b0cd37136568a7ebb586 cbc825d6b458d50debc5913c6b5ed442138d7462 0a3baa3c4708754c79d023ad0addb4cbfb2844c2 a07b34e07b359327e413ccb7ea2dcdf1a91504de 4bf00213a866402775b162fb6f4b7b0bc37a8af7 1b690fa946047f4b897b417d8bc3b02c54cfdb2d 83b05e82a5f28bbe288565ae8a65943ba681cb4a 37d58d4f9de6af12611dada7ba5ae42d51ef05c6 8bbfc0ded0504595111765963d396a4574773e05 81049efedf0b3b521fb2949d8eb03d5ba681b0a5 6dcb369a2fa2bb69f94598fb4224a1349a80db6c c3e4d0cb62570c56ef5bc530f57eeea613f083fc 82d0fbb470daae4091bf30fb57707d66bd193992 166ec9ab6f4a3af0fe522a7dbe166951d2b39b31 992895a8842900d9a0803e7099611d650aba257d 4904b0b2812f9f0f45a59f2efacae89dabe9fe7c 36beac951788f5fb7ab2eeb3381300b07993bfe8 541818a92a5be6442879cd9b3420e1ef27f6e663 43ac3a1bbe6e727869a26ab8697c035eb60577fa d2afd27150a869ff41b8e100e82f20af54146105 0374f24d4685954662fa9db05939a8cbcd492b1c ed04d15b29d4df0329e8a4725c1a371a5cb0a20e 39fc4123096b04a4584b48d6efbb1acd5acacbf9 18315df2eb529bab6c5c79607ecb94626b170ae6 c519a195b90ad689d60d85365252e433b7488eaf d0d2839012c26032488bfe657797b4b590f926c7 8e0cb82ccac15fbc3e08bb53b148563e62437a44 d4413acd4dbad43507018f24e0456a9bc432d156 0dc05886b3ae0c59667f03a245e0728ab094f130 c9a3652d779d9700d9a9d797fd0c58d349a58de1 76425d002c70c3d853c117389a3b407efc53c7c2 fb409ef93b05cd4268e83c7201da73b6b29d482a da1cce88d00f7f7c373df1ce66b18e26e3a2d6e9 fa74cd48bb8959855c9d6b874f874671611611f7 610079be424f3a72ad02aa62e1c89607481750e0 60fda643c807730c3774beaa10a0910a31a4278a 6d2bcdcad816fd2b31c612fe45d3fd5a2fb14f98 b2d960e7d263bee55badbca47dc5d4d4f2d61084 f2ba1e3a96dd571d142c5a37c462743a21148e5f 25cbd33758fdb18f79aa1cf6500d1c1c024ee516 cde2d71846d1f69e5f386d354006465d61a4d19c cf708c22c45491dbdbbdbbb4450b08969f2e33bc 7bda495fbc9ea2c3aa87ac73a5cf4881eecf1482 9499d6967b394b70a22d9be34f47ee1b7a3fc55e 3aa3e67cd8ab769bc2c12b46fc77b11be2b1a0dd abed4927dc46e3e952fd21472f7ae4150ee16044 73953118e02b4c2d8159279624810dddd75e9100 031e4b18d91d825b56ef1e9eda5f1638bcd26629 fa3e1c57efa140ea58f56c6abf1f5f12f9bf2c7d a9b1b82a40fa6c462a9919b2832a89eb6bb47784 a8bf5e2504bdbe257686d48c2bfcaf061abfc95d e2830e4a6650ca8a1c53116a6d86f2975951dbbf 4a48b4c6905999527a7fc8d32e53d8c347c9ac74 9cfdb8c7ddce3a1b34a6590d8872f820601c2c53 128fad8298e89eadafa5feea43ca94f5115b9090 95d4595418fa814d47707441f2dc98d07eac12d6 5e35f7131d999b406eaeafc689374e3426845e6d 3402992fd25a64838e7acecfba3fad645c6c2511 8fcabdf5a34e7d80de988c10426c27adb0622087 1884dd57148595841cfb324f5b812d8640964978 6008cc8c3444f86d729ae5a81ae26919da1bb516 03d40c0d7e8feda38add1d89e3805df74997d915 810685c4aac0a651beaecd0488443a3b293b315d a666abc115c6693b355d5a8ef9cdfc3d77a088ca bcd3619f96c4157ee5b6450bc2bd1f23f27c9d81 9c428f6ab674582e022ea469ef2ac1e3f7ccb933 6e99df4296470d349da01f2e29698dbb34692a0f ed739dfaeb1ca5da10b2c75236faee40bacaf851 006a9351f3320662bff0b96d5d27daa1ba4e52e4 d6b38763cf83ad275aed0450151a97098f48859a 4ea031466d93057705a52caf2dfa21929b215730 a1bead3d96a11f4badedbd5a6eb984473c1cd309 7aa36472009f43cad843b465f67d2927f3428fdf 5f875adcd63ebd9ac9dfaef3ea16e6a6d3735503 4c0cc347e5e52d8ed99e84d42b309c4541d9280c c3de867fbbc27aaefba7aa88f97b5b1406c7c58e 00754639948b6612016ed5c434e97f44e7c65ed6 ffe16b1e768209b1c2021301a142b7fcd9a35a4b 800e568c600187f7228b228874ad20fb57f35166 d36b349e0eea73e99253b64fae3afeb5c4c276ca a7d8eff776e4e28a85e7835ee7ff6d50775748e7 bd0bd280c89d5d742e0ef13673c854436657466f 42da0bb422cdca21c8491af40ca9631206d8e964 e81415f70bedf456983b18692b4ae04355f15283 09c0a9a40ca6d8a8b6eaa6f06ce3f8c2440f7ee1 26eaa5b9c8cc2a84f9de04e17e01f201c122989e 649f49d0618e3c8cb940c4d259a536dfcc66020f 27ec987a8e8a9bc645f6cd38d9f8d5d52e7dbedb eb566ec8284ba205d27699a9bf465e26158b5098 4bdf14d6decad2ef14a77c108227273dd700e9a3 5598cb31dc238e16f58da2f793a1e2f7f5768dba 0bfe812e3d1f25756efcf92162961f5d55c3a5d8 9f96c81ba868d6269f3698c64ca8a83e74b0510f d5f01925db8323eeabbc43ec1b72a685da00dd6b f09195ec50a24c35947cb52feca1978ac5599871 0a10380275edaffc88632ef444a15b15c47ec17e 3f08ca6c77812c1d39f2949d2bab7416c77cc4ca af784841593347b2fd440fb78872fe9ac0fe1c09 9aa492880457b6fc20968f5d036cb6fe912e8964 c622cc4a0d279b98570b0af11fc67278e3355556 4d5dead4c4d3b3e34198e59e6ee0f6b3ca7c64b1 2191ceb040dd58a0794250e9e6c795a509b9fad5 775c1d3bc761967ff2f0a83e345c951117a5e9aa ace03eee6a19e6a12ad12c25e310ac3d223d2d48 f10dbc643cb334dc70657a086a38aadb59b59e29 ea63ec4d6f32b8a652d495d9c66d777313271e4a 038178b09b92d678107449519b75a977a08f45e9 f9cdbbb9ebfc1db9261b430427aa719be56a53c1 0a200674c645cf59ae69f25a25440db0b89c0c30 2e7189bb5db8a803c0ade25613a50bfcc264746a e6ca3edcf724fb8f2457423d9261ab73faf1f5da 6ff2d4a7c2fbc14ea856eb891f019c7978905834 72fac5e32be9bbf531dc8e324f2b865eb265ec4f 351cd2077d369fc0a9b9ec8675ede29288d41f35 061dd2a2659df35d1edd4ba74d67e6e72b531bf7 3c32ab918568bf4f59b0a8b393020de888dc2c3e 08fa11670d73b4f71226541761e09a99fc8a17c9 9d94e556f3eb471fd312af194ca7c4b82b67da6c db70db80c56513ebad6b95b66273e623198c5f44 e666311a274481b4af90702c916004ccbf9b6d8a 9780e12fa7acfb3a5be7d4171068c8c100858c53 baee9c1074cbf844b7c4a3c837ebb17f7861d075 0aae4ce623c90bfd7ea6c4f20967bf50001dc22f c8b42e81407d55a6444986deb435fa8144822c49 9e9967bb87524a82ae9411ca974d3b081ec52c53 3eac611da268444f07e1f718ffd18c7f47bc2a4c fbb2b3a689be07c57cde471e651ba06d7ecf7316 28d61bf3fae304b22ce0380c93a6f997e8c77e32 992c464588845b09ff2b4a61b5de719b9cdaf356 716fff934be2016bc00b2fcf17e19bc0ecfdeeb0 69a2005824c09fa33828ec5ffa24b9df8cd5bcc0 4fa6810e9e944c7d0c4ff06bed6a534e33869034 8dbbcec096317e9016c2f3478be4d458dbb34ad8 2c7c01be15245ae8997185fee247c00106cc81db 5af9b8d40ec97f5741d9a69161ef4aa10c879724 c9851e1b750de6c324c749b4bff5725d79e2b610 0a9f5a297bb97486fc23bb3a0bb39cb8b5b8cc27 aa4bda96b90fab60bf383c255d60b9580b5b6a31 cd8a892d7f6ca71c5d591d4282d98083462d77fe 98cc1a202fd2dbf27e87378c1588edc5eb1c3d60 d3068f5500a98d2a2b71d4c01d5296477224b743 1b28153bff1449200899115d4a1d9f612fac716c d992717d5df7bf68a5907446f9b31c78b5a01f51 497033c40c559bceb5c7980c8d48bd1d935188e3 d967a66b91fd990264e5a4b134385d80e5980c57 a397e9dda8244b6977adb9daeb5ab5ddff6e6140 60b804dc01593469962dae00a1e4004f0a8d7c53 a7b240cf9199d727e494b97ad2d9b65440a9ef1c 2458e3538eef44deb6f3d6a4831aef19414fd0ed c19139b782f5124ea86fc1610fe13ea85f77a279 c67f095bcad89fc6e6b635792a96ed0ed295e1a8 9ecebc8512dbb2a0ed61df1901eafd3832893bf8 95a551f86f299d7f8b424c26da3ff77400368fed ae5c8d61d8c75ed4b01dac60edd37859bc8f9d8f e54f11cae13b053a44afe10cdb47b65f535caca9 9b4fcfd0bee437354defe7e0f431857ff21c0edb ee5c2a995e1b9affef5a8e12f23cff8b0813d2ab 034c3e1601aaa0cba81118030a849485eea2b7ea 0cce165ede3a66867a863d5cb86afff5db406587 375b4fd6eca2d9d63959f9c755de6f8c5d89d302 8bec92a21036bedb734571d443f7b1a14daaa6eb 14d0b11516cd8bbdea84a3fa6cf53cff9619d902 c1e77a9311a8679328d0dc1337dd940682296927 6ab614d3e218d4c5cb3f69001a71350d3d7c65ec 77f6db23a5b65257959cc55e03eff09ee8f25cfc 64b7a40bb5620ec0522d9609fc961cff9cafe68a 62dca0c033d444aa579970c4c871b802c2a82d60 21f5480d3441d7c918a817368172bc14d714a3e8 3fc038d8db20f298b843a7eeeb31f25abf5a2788 492236c84ca4cfc3d8aea9d32d75b6a65a2fe52a 759a12b81483024d52d7b2055f66d675c05ea372 50580213060d8392a2da78eec0b8f08adddeba62 6374e3bb760d470dacdadfc14ef7cb824d9e194c 964b76fe981ab840a2cbc8a807789abae92ae660 b30861536f72d0ffc97c8780b62759fb764ed40b 5edb09e6ea1ba70cdac64a2196481b1f038301c2 34eeb6773589a95ecf66484b999cf443e57632d0 4ee9c48fa4b6f983c03acf77e8d04720fe43e1a6 88ebb8d8af483c96640f7df804e87fca20284c4d ce9fadbe2bd8bac62b475a387a8577f8a806fd52 9e7eb5f80cde5398270e1c4c85258118e22fe8ef a19227e38c38ceb21695ac14ea7754002980cf55 4277bc56f4490533734b1ed78fb5a9c8575f7afb 424479529f31e00ff3263795d42218a026fa528a 91c0289a560e3f3860d7b39549010adf917b8d1b 62a80750f59f92786acc48b18c3365d021bc5590 c0de5849434d88dd115eac9e5bc8eafcd0a0fa76 f869b8a4d7f88ac88437c9f3cfb4416784990e98 ee80bb3fe9cdd54af1ce4aba7f5e2fd136a2499c 8563a689d5957e4fd3ff9fecfbf97def28de4bff de8179675f9250b28678671addf56e33e5829e79 43b815a08101d267bc5d937d0b003a419bb2abd9 9e4164f6b3f847f371351a324905def648ea1747 1f26e1cc07a0de2edb516769b74e99b965b6d75d c36c0e51aad0f40f3f61406e786ba198ab6d90f9 c727bae4cb644789b0a975ec665c8b02652d4651 a61b91abb5ba8128c1438cc59b2f054c71f28d2a 2e1cecf0bba482b9976f3d8f274611195b0cf2f8 707ef18dccda6b917e1b421291e47e658555b3d2 b456956bfd85041b5b70b50d5fb2eaf3c9de64f2 f39d14d001e3dd0e73c4f8200f4132b47ebb40d3 9f0bcb8f5d1922199afb7bc8f8bb57bb10d0fe12 e877036f029a0198d9da39775443c8ac2132309b 2391f2f3881dbdabf96ca33c931e9cd5f42cedc9 82189594b7e20243f5ece31c6f7b804d6b83b0d7 5abd3260994cc77992f5c6437bdcdf45c32d9867 2519053ee4c5b2ce1c2851fee0d47d612d27aa1f 05584371da7da40cdab309ea2809c51c02069384 b61c8342cee8a0942ce276c2d2de773347ab4dcd c7b80824ade46956377b955838b73325d6fbe4d9 9866874e4701f30f1a293a7fd2e5d242bbf82c4f 2308aecbde415948894a55e53201c5abb7184039 e8b44094228f41fa5996788b977d07072fcf87a6 2facd93337f682bd8aa1222805c46720a53edc99 2d9288cec441356241f7d59d120de06ee7b97fdd
Diff
diff --git a/docs/utils/index.html b/docs/utils/index.html
index d083b6c..b558c5a 100644
--- a/docs/utils/index.html
+++ b/docs/utils/index.html
@@ -53,63 +53,63 @@
-  7	"reflect"
-  8	"regexp"
-  9	"strconv"
- 10	"strings"
- 11
- 12	"golang.org/x/net/html"
- 13)
- 14
- 15func GetXY(n *element.Node, state *map[string]element.State) (float32, float32) {
- 16	s := *state
- 17	// self := s[n.Properties.Id]
- 18
- 19	offsetX := float32(0)
- 20	offsetY := float32(0)
- 21
- 22	if n.Parent != nil {
- 23		parent := s[n.Parent.Properties.Id]
- 24		// x, y := GetXY(n.Parent, state)
- 25		offsetX += parent.Border.Width + parent.Padding.Left
- 26		offsetY += parent.Border.Width + parent.Padding.Top
- 27	}
- 28
- 29	return offsetX, offsetY
- 30}
- 31
- 32type WidthHeight struct {
- 33	Width  float32
- 34	Height float32
- 35}
- 36
- 37func GetWH(n element.Node, state *map[string]element.State) WidthHeight {
- 38	s := *state
- 39	self := s[n.Properties.Id]
- 40	parent := element.State{}
- 41
- 42	if n.Style == nil {
- 43		n.Style = map[string]string{}
- 44	}
- 45
- 46	fs := self.EM
- 47
- 48	var pwh WidthHeight
- 49	if n.Parent != nil {
- 50		parent = s[n.Parent.Properties.Id]
- 51		pwh = GetWH(*n.Parent, state)
- 52	} else {
- 53		pwh = WidthHeight{}
- 54		if n.Style["width"] != "" {
- 55			str := strings.TrimSuffix(n.Style["width"], "px")
- 56			// Convert the string to float32
- 57			f, _ := strconv.ParseFloat(str, 32)
- 58			pwh.Width = float32(f)
- 59		}
- 60
- 61		if n.Style["height"] != "" {
- 62			str := strings.TrimSuffix(n.Style["height"], "px")
- 63			// Convert the string to float32
- 64			f, _ := strconv.ParseFloat(str, 32)
- 65			pwh.Height = float32(f)
- 66		}
- 67	}
- 68
- 69	wStyle := n.Style["width"]
+  7	"math"
+  8	"reflect"
+  9	"regexp"
+ 10	"strconv"
+ 11	"strings"
+ 12
+ 13	"golang.org/x/net/html"
+ 14)
+ 15
+ 16// MapToInlineCSS converts a map[string]string to a string formatted like inline CSS style
+ 17func MapToInline(m map[string]string) string {
+ 18	var cssStrings []string
+ 19	for key, value := range m {
+ 20		cssStrings = append(cssStrings, fmt.Sprintf("%s: %s;", key, value))
+ 21	}
+ 22	return strings.Join(cssStrings, " ")
+ 23}
+ 24
+ 25// InlineCSSToMap converts a string formatted like inline CSS style to a map[string]string
+ 26func InlineToMap(cssString string) map[string]string {
+ 27	cssMap := make(map[string]string)
+ 28	declarations := strings.Split(cssString, ";")
+ 29	for _, declaration := range declarations {
+ 30		parts := strings.Split(strings.TrimSpace(declaration), ":")
+ 31		if len(parts) == 2 {
+ 32			key := strings.TrimSpace(parts[0])
+ 33			value := strings.TrimSpace(parts[1])
+ 34			cssMap[key] = value
+ 35		}
+ 36	}
+ 37	return cssMap
+ 38}
+ 39
+ 40func GetXY(n *element.Node, state *map[string]element.State) (float32, float32) {
+ 41	s := *state
+ 42	// self := s[n.Properties.Id]
+ 43
+ 44	offsetX := float32(0)
+ 45	offsetY := float32(0)
+ 46
+ 47	if n.Parent != nil {
+ 48		parent := s[n.Parent.Properties.Id]
+ 49		// x, y := GetXY(n.Parent, state)
+ 50		offsetX += parent.Border.Width + parent.Padding.Left
+ 51		offsetY += parent.Border.Width + parent.Padding.Top
+ 52	}
+ 53
+ 54	return offsetX, offsetY
+ 55}
+ 56
+ 57type WidthHeight struct {
+ 58	Width  float32
+ 59	Height float32
+ 60}
+ 61
+ 62func GetWH(n element.Node, state *map[string]element.State) WidthHeight {
+ 63	s := *state
+ 64	self := s[n.Properties.Id]
+ 65	parent := element.State{}
+ 66
+ 67	if n.Style == nil {
+ 68		n.Style = map[string]string{}
+ 69	}
@@ -117,25 +117,25 @@
- 71	if wStyle == "" && n.Style["display"] != "inline" {
- 72		wStyle = "100%"
- 73	}
- 74
- 75	width, _ := ConvertToPixels(wStyle, fs, pwh.Width)
- 76	height, _ := ConvertToPixels(n.Style["height"], fs, pwh.Height)
- 77
- 78	if n.Style["min-width"] != "" {
- 79		minWidth, _ := ConvertToPixels(n.Style["min-width"], fs, pwh.Width)
- 80		width = Max(width, minWidth)
- 81	}
- 82
- 83	if n.Style["max-width"] != "" {
- 84		maxWidth, _ := ConvertToPixels(n.Style["max-width"], fs, pwh.Width)
- 85		width = Min(width, maxWidth)
- 86	}
- 87	if n.Style["min-height"] != "" {
- 88		minHeight, _ := ConvertToPixels(n.Style["min-height"], fs, pwh.Height)
- 89		height = Max(height, minHeight)
- 90	}
- 91
- 92	if n.Style["max-height"] != "" {
- 93		maxHeight, _ := ConvertToPixels(n.Style["max-height"], fs, pwh.Height)
- 94		height = Min(height, maxHeight)
- 95	}
+ 71	fs := self.EM
+ 72
+ 73	var pwh WidthHeight
+ 74	if n.Parent != nil {
+ 75		parent = s[n.Parent.Properties.Id]
+ 76		pwh = GetWH(*n.Parent, state)
+ 77	} else {
+ 78		pwh = WidthHeight{}
+ 79		if n.Style["width"] != "" {
+ 80			str := strings.TrimSuffix(n.Style["width"], "px")
+ 81			// Convert the string to float32
+ 82			f, _ := strconv.ParseFloat(str, 32)
+ 83			pwh.Width = float32(f)
+ 84		}
+ 85
+ 86		if n.Style["height"] != "" {
+ 87			str := strings.TrimSuffix(n.Style["height"], "px")
+ 88			// Convert the string to float32
+ 89			f, _ := strconv.ParseFloat(str, 32)
+ 90			pwh.Height = float32(f)
+ 91		}
+ 92	}
+ 93
+ 94	width, _ := ConvertToPixels(n.Style["width"], fs, pwh.Width)
+ 95	height, _ := ConvertToPixels(n.Style["height"], fs, pwh.Height)
@@ -143,3 +143,3 @@
- 97	wh := WidthHeight{
- 98		Width:  width,
- 99		Height: height,
+ 97	if n.Style["min-width"] != "" {
+ 98		minWidth, _ := ConvertToPixels(n.Style["min-width"], fs, pwh.Width)
+ 99		width = Max(width, minWidth)
@@ -148,12 +148,12 @@
-102	if n.Parent != nil {
-103		wh.Width += self.Padding.Left + self.Padding.Right
-104		wh.Height += self.Padding.Top + self.Padding.Bottom
-105		// fmt.Println(n.Properties.Id, wh, p)
-106	}
-107
-108	if wStyle == "100%" {
-109		wh.Width = wh.Width - ((self.Margin.Right + self.Margin.Left + (self.Border.Width * 2)) + (parent.Padding.Left + parent.Padding.Right) + (self.Padding.Left + self.Padding.Right))
-110	}
-111
-112	if n.Style["height"] == "100%" {
-113		wh.Height -= (self.Margin.Top + self.Margin.Bottom) + (parent.Padding.Top + parent.Padding.Bottom)
+102	if n.Style["max-width"] != "" {
+103		maxWidth, _ := ConvertToPixels(n.Style["max-width"], fs, pwh.Width)
+104		width = Min(width, maxWidth)
+105	}
+106	if n.Style["min-height"] != "" {
+107		minHeight, _ := ConvertToPixels(n.Style["min-height"], fs, pwh.Height)
+108		height = Max(height, minHeight)
+109	}
+110
+111	if n.Style["max-height"] != "" {
+112		maxHeight, _ := ConvertToPixels(n.Style["max-height"], fs, pwh.Height)
+113		height = Min(height, maxHeight)
@@ -162,41 +162,41 @@
-116	return wh
-117}
-118
-119func GetMP(n element.Node, wh WidthHeight, state *map[string]element.State, t string) element.MarginPadding {
-120	s := *state
-121	self := s[n.Properties.Id]
-122	fs := self.EM
-123	m := element.MarginPadding{}
-124
-125	if n.Style[t] != "" {
-126		left, right, top, bottom := convertMarginToIndividualProperties(n.Style[t])
-127		if n.Style[t+"-left"] == "" {
-128			n.Style[t+"-left"] = left
-129		}
-130		if n.Style[t+"-right"] == "" {
-131			n.Style[t+"-right"] = right
-132		}
-133		if n.Style[t+"-top"] == "" {
-134			n.Style[t+"-top"] = top
-135		}
-136		if n.Style[t+"-bottom"] == "" {
-137			n.Style[t+"-bottom"] = bottom
-138		}
-139	}
-140	if n.Style[t+"-left"] != "" || n.Style[t+"-right"] != "" {
-141		l, _ := ConvertToPixels(n.Style[t+"-left"], fs, wh.Width)
-142		r, _ := ConvertToPixels(n.Style[t+"-right"], fs, wh.Width)
-143		m.Left = l
-144		m.Right = r
-145	}
-146	if n.Style[t+"-top"] != "" || n.Style[t+"-bottom"] != "" {
-147		top, _ := ConvertToPixels(n.Style[t+"-top"], fs, wh.Height)
-148		b, _ := ConvertToPixels(n.Style[t+"-bottom"], fs, wh.Height)
-149		m.Top = top
-150		m.Bottom = b
-151	}
-152	if t == "margin" {
-153		if n.Style["margin"] == "auto" && n.Style["margin-left"] == "" && n.Style["margin-right"] == "" {
-154			pwh := GetWH(*n.Parent, state)
-155			m.Left = Max((pwh.Width-wh.Width)/2, 0)
-156			m.Right = m.Left
+116	wh := WidthHeight{
+117		Width:  width,
+118		Height: height,
+119	}
+120
+121	if n.Parent != nil {
+122		wh.Width += self.Padding.Left + self.Padding.Right
+123		wh.Height += self.Padding.Top + self.Padding.Bottom
+124		// fmt.Println(n.Properties.Id, wh, p)
+125	}
+126
+127	if n.Style["width"] == "100%" {
+128		wh.Width = wh.Width - ((self.Margin.Right + self.Margin.Left + (self.Border.Width * 2)) + (parent.Padding.Left + parent.Padding.Right) + (self.Padding.Left + self.Padding.Right))
+129	}
+130
+131	if n.Style["height"] == "100%" {
+132		wh.Height -= (self.Margin.Top + self.Margin.Bottom) + (parent.Padding.Top + parent.Padding.Bottom)
+133	}
+134
+135	return wh
+136}
+137
+138func GetMP(n element.Node, wh WidthHeight, state *map[string]element.State, t string) element.MarginPadding {
+139	s := *state
+140	self := s[n.Properties.Id]
+141	fs := self.EM
+142	m := element.MarginPadding{}
+143
+144	if n.Style[t] != "" {
+145		left, right, top, bottom := convertMarginToIndividualProperties(n.Style[t])
+146		if n.Style[t+"-left"] == "" {
+147			n.Style[t+"-left"] = left
+148		}
+149		if n.Style[t+"-right"] == "" {
+150			n.Style[t+"-right"] = right
+151		}
+152		if n.Style[t+"-top"] == "" {
+153			n.Style[t+"-top"] = top
+154		}
+155		if n.Style[t+"-bottom"] == "" {
+156			n.Style[t+"-bottom"] = bottom
@@ -205,82 +205,82 @@
-159
-160	return m
-161}
-162
-163func convertMarginToIndividualProperties(margin string) (string, string, string, string) {
-164	// Remove extra whitespace
-165	margin = strings.TrimSpace(margin)
-166
-167	if margin == "" {
-168		return "0px", "0px", "0px", "0px"
-169	}
-170
-171	// Regular expression to match values with optional units
-172	re := regexp.MustCompile(`(-?\d+(\.\d+)?)(\w*|\%)?`)
-173
-174	// Extract numerical values from the margin property
-175	matches := re.FindAllStringSubmatch(margin, -1)
-176
-177	// Initialize variables for individual margins
-178	var left, right, top, bottom string
-179
-180	switch len(matches) {
-181	case 1:
-182		// If only one value is provided, apply it to all margins
-183		left = matches[0][0]
-184		right = matches[0][0]
-185		top = matches[0][0]
-186		bottom = matches[0][0]
-187	case 2:
-188		// If two values are provided, apply the first to top and bottom, and the second to left and right
-189		top = matches[0][0]
-190		bottom = matches[0][0]
-191		left = matches[1][0]
-192		right = matches[1][0]
-193	case 3:
-194		// If three values are provided, apply the first to top, the second to left and right, and the third to bottom
-195		top = matches[0][0]
-196		left = matches[1][0]
-197		right = matches[1][0]
-198		bottom = matches[2][0]
-199	case 4:
-200		// If four values are provided, apply them to top, right, bottom, and left, respectively
-201		top = matches[0][0]
-202		right = matches[1][0]
-203		bottom = matches[2][0]
-204		left = matches[3][0]
-205	}
-206
-207	return left, right, top, bottom
-208}
-209
-210// ConvertToPixels converts a CSS measurement to pixels.
-211func ConvertToPixels(value string, em, max float32) (float32, error) {
-212	unitFactors := map[string]float32{
-213		"px": 1,
-214		"em": em,
-215		"pt": 1.33,
-216		"pc": 16.89,
-217		"%":  max / 100,
-218		"vw": max / 100,
-219		"vh": max / 100,
-220		"cm": 37.79527559,
-221		"in": 96,
-222	}
-223
-224	if strings.HasPrefix(value, "calc(") {
-225		// Handle calculation expression
-226		calcResult, err := evaluateCalcExpression(value[5:len(value)-1], em, max)
-227		if err != nil {
-228			return 0, err
-229		}
-230		return calcResult, nil
-231	} else {
-232		// Extract numeric value and unit
-233		for k, v := range unitFactors {
-234			if strings.HasSuffix(value, k) {
-235				cutStr, _ := strings.CutSuffix(value, k)
-236				numericValue, _ := strconv.ParseFloat(cutStr, 64)
-237				return float32(numericValue) * v, nil
-238			}
-239		}
-240		return 0, fmt.Errorf("unable to parse value")
+159	if n.Style[t+"-left"] != "" || n.Style[t+"-right"] != "" {
+160		l, _ := ConvertToPixels(n.Style[t+"-left"], fs, wh.Width)
+161		r, _ := ConvertToPixels(n.Style[t+"-right"], fs, wh.Width)
+162		m.Left = l
+163		m.Right = r
+164	}
+165	if n.Style[t+"-top"] != "" || n.Style[t+"-bottom"] != "" {
+166		top, _ := ConvertToPixels(n.Style[t+"-top"], fs, wh.Height)
+167		b, _ := ConvertToPixels(n.Style[t+"-bottom"], fs, wh.Height)
+168		m.Top = top
+169		m.Bottom = b
+170	}
+171	if t == "margin" {
+172		if n.Style["margin"] == "auto" && n.Style["margin-left"] == "" && n.Style["margin-right"] == "" {
+173			pwh := GetWH(*n.Parent, state)
+174			m.Left = Max((pwh.Width-wh.Width)/2, 0)
+175			m.Right = m.Left
+176		}
+177	}
+178
+179	return m
+180}
+181
+182func convertMarginToIndividualProperties(margin string) (string, string, string, string) {
+183	// Remove extra whitespace
+184	margin = strings.TrimSpace(margin)
+185
+186	if margin == "" {
+187		return "0px", "0px", "0px", "0px"
+188	}
+189
+190	// Regular expression to match values with optional units
+191	re := regexp.MustCompile(`(-?\d+(\.\d+)?)(\w*|\%)?`)
+192
+193	// Extract numerical values from the margin property
+194	matches := re.FindAllStringSubmatch(margin, -1)
+195
+196	// Initialize variables for individual margins
+197	var left, right, top, bottom string
+198
+199	switch len(matches) {
+200	case 1:
+201		// If only one value is provided, apply it to all margins
+202		left = matches[0][0]
+203		right = matches[0][0]
+204		top = matches[0][0]
+205		bottom = matches[0][0]
+206	case 2:
+207		// If two values are provided, apply the first to top and bottom, and the second to left and right
+208		top = matches[0][0]
+209		bottom = matches[0][0]
+210		left = matches[1][0]
+211		right = matches[1][0]
+212	case 3:
+213		// If three values are provided, apply the first to top, the second to left and right, and the third to bottom
+214		top = matches[0][0]
+215		left = matches[1][0]
+216		right = matches[1][0]
+217		bottom = matches[2][0]
+218	case 4:
+219		// If four values are provided, apply them to top, right, bottom, and left, respectively
+220		top = matches[0][0]
+221		right = matches[1][0]
+222		bottom = matches[2][0]
+223		left = matches[3][0]
+224	}
+225
+226	return left, right, top, bottom
+227}
+228
+229// ConvertToPixels converts a CSS measurement to pixels.
+230func ConvertToPixels(value string, em, max float32) (float32, error) {
+231	unitFactors := map[string]float32{
+232		"px": 1,
+233		"em": em,
+234		"pt": 1.33,
+235		"pc": 16.89,
+236		"%":  max / 100,
+237		"vw": max / 100,
+238		"vh": max / 100,
+239		"cm": 37.79527559,
+240		"in": 96,
@@ -289,37 +289,37 @@
-243}
-244
-245// evaluateCalcExpression recursively evaluates 'calc()' expressions
-246func evaluateCalcExpression(expression string, em, max float32) (float32, error) {
-247	terms := strings.FieldsFunc(expression, func(c rune) bool {
-248		return c == '+' || c == '-' || c == '*' || c == '/'
-249	})
-250
-251	operators := strings.FieldsFunc(expression, func(c rune) bool {
-252		return c != '+' && c != '-' && c != '*' && c != '/'
-253	})
-254
-255	var result float32
-256
-257	for i, term := range terms {
-258		value, err := ConvertToPixels(strings.TrimSpace(term), em, max)
-259		if err != nil {
-260			return 0, err
-261		}
-262
-263		if i > 0 {
-264			switch operators[i-1] {
-265			case "+":
-266				result += value
-267			case "-":
-268				result -= value
-269			case "*":
-270				result *= value
-271			case "/":
-272				if value != 0 {
-273					result /= value
-274				} else {
-275					return 0, fmt.Errorf("division by zero in 'calc()' expression")
-276				}
-277			}
-278		} else {
-279			result = value
+243	if strings.HasPrefix(value, "calc(") {
+244		// Handle calculation expression
+245		calcResult, err := evaluateCalcExpression(value[5:len(value)-1], em, max)
+246		if err != nil {
+247			return 0, err
+248		}
+249		return calcResult, nil
+250	} else {
+251		// Extract numeric value and unit
+252		for k, v := range unitFactors {
+253			if strings.HasSuffix(value, k) {
+254				cutStr, _ := strings.CutSuffix(value, k)
+255				numericValue, _ := strconv.ParseFloat(cutStr, 64)
+256				return float32(numericValue) * v, nil
+257			}
+258		}
+259		return 0, fmt.Errorf("unable to parse value")
+260	}
+261
+262}
+263
+264// evaluateCalcExpression recursively evaluates 'calc()' expressions
+265func evaluateCalcExpression(expression string, em, max float32) (float32, error) {
+266	terms := strings.FieldsFunc(expression, func(c rune) bool {
+267		return c == '+' || c == '-' || c == '*' || c == '/'
+268	})
+269
+270	operators := strings.FieldsFunc(expression, func(c rune) bool {
+271		return c != '+' && c != '-' && c != '*' && c != '/'
+272	})
+273
+274	var result float32
+275
+276	for i, term := range terms {
+277		value, err := ConvertToPixels(strings.TrimSpace(term), em, max)
+278		if err != nil {
+279			return 0, err
@@ -327,35 +327,35 @@
-281	}
-282
-283	return result, nil
-284}
-285
-286func Merge(m1, m2 map[string]string) map[string]string {
-287	// Create a new map and copy m1 into it
-288	result := make(map[string]string)
-289	for k, v := range m1 {
-290		result[k] = v
-291	}
-292
-293	// Merge m2 into the new map
-294	for k, v := range m2 {
-295		result[k] = v
-296	}
-297
-298	return result
-299}
-300
-301func Max(a, b float32) float32 {
-302	if a > b {
-303		return a
-304	} else {
-305		return b
-306	}
-307}
-308
-309func Min(a, b float32) float32 {
-310	if a < b {
-311		return a
-312	} else {
-313		return b
-314	}
-315}
+281
+282		if i > 0 {
+283			switch operators[i-1] {
+284			case "+":
+285				result += value
+286			case "-":
+287				result -= value
+288			case "*":
+289				result *= value
+290			case "/":
+291				if value != 0 {
+292					result /= value
+293				} else {
+294					return 0, fmt.Errorf("division by zero in 'calc()' expression")
+295				}
+296			}
+297		} else {
+298			result = value
+299		}
+300	}
+301
+302	return result, nil
+303}
+304
+305func GetTextBounds(text string, fontSize, width, height float32) (float32, float32) {
+306	w := float32(len(text) * int(fontSize))
+307	h := fontSize
+308	if width > 0 && height > 0 {
+309		if w > width {
+310			height = Max(height, float32(math.Ceil(float64(w/width)))*h)
+311		}
+312		return width, height
+313	} else {
+314		return w, h
+315	}
@@ -363,7 +363,7 @@
-317// getStructField uses reflection to get the value of a struct field by name
-318func GetStructField(data interface{}, fieldName string) (interface{}, error) {
-319	val := reflect.ValueOf(data)
-320
-321	// Make sure we have a pointer to a struct
-322	if val.Kind() != reflect.Ptr || val.Elem().Kind() != reflect.Struct {
-323		return nil, fmt.Errorf("expected a pointer to a struct")
+317}
+318
+319func Merge(m1, m2 map[string]string) map[string]string {
+320	// Create a new map and copy m1 into it
+321	result := make(map[string]string)
+322	for k, v := range m1 {
+323		result[k] = v
@@ -372,7 +372,7 @@
-326	// Get the struct field by name
-327	field := val.Elem().FieldByName(fieldName)
-328
-329	// Check if the field exists
-330	if !field.IsValid() {
-331		return nil, fmt.Errorf("field not found: %s", fieldName)
-332	}
+326	// Merge m2 into the new map
+327	for k, v := range m2 {
+328		result[k] = v
+329	}
+330
+331	return result
+332}
@@ -380,13 +380,13 @@
-334	return field.Interface(), nil
-335}
-336
-337func SetStructFieldValue(data interface{}, fieldName string, newValue interface{}) error {
-338	val := reflect.ValueOf(data)
-339
-340	// Make sure we have a pointer to a struct
-341	if val.Kind() != reflect.Ptr || val.Elem().Kind() != reflect.Struct {
-342		return fmt.Errorf("expected a pointer to a struct")
-343	}
-344
-345	// Get the struct field by name
-346	field := val.Elem().FieldByName(fieldName)
+334func ExMerge(m1, m2 map[string]string) map[string]string {
+335	// Create a new map and copy m1 into it
+336	result := make(map[string]string)
+337	for k, v := range m1 {
+338		result[k] = v
+339	}
+340
+341	// Merge m2 into the new map only if the key is not already present
+342	for k, v := range m2 {
+343		if result[k] == "" {
+344			result[k] = v
+345		}
+346	}
@@ -394,8 +394,8 @@
-348	// Check if the field exists
-349	if !field.IsValid() {
-350		return fmt.Errorf("field not found: %s", fieldName)
-351	}
-352
-353	// Check if the new value type is assignable to the field type
-354	if !reflect.ValueOf(newValue).Type().AssignableTo(field.Type()) {
-355		return fmt.Errorf("incompatible types for field %s", fieldName)
+348	return result
+349}
+350
+351func Max(a, b float32) float32 {
+352	if a > b {
+353		return a
+354	} else {
+355		return b
@@ -403,41 +403,41 @@
-357
-358	// Set the new value
-359	field.Set(reflect.ValueOf(newValue))
-360
-361	return nil
-362}
-363
-364// func Check(e error) {
-365// 	if e != nil {
-366// 		panic(e)
-367// 	}
-368// }
-369
-370func GetInnerText(n *html.Node) string {
-371	var result strings.Builder
-372
-373	var getText func(*html.Node)
-374	getText = func(n *html.Node) {
-375		// Skip processing if the node is a head tag
-376		if n.Type == html.ElementNode && n.Data == "head" {
-377			return
-378		}
-379
-380		// If it's a text node, append its content
-381		if n.Type == html.TextNode {
-382			result.WriteString(n.Data)
-383		}
-384
-385		// Traverse child nodes recursively
-386		for c := n.FirstChild; c != nil; c = c.NextSibling {
-387			getText(c)
-388		}
-389	}
-390
-391	getText(n)
-392
-393	return result.String()
-394}
-395
-396func GetPositionOffsetNode(n *element.Node) *element.Node {
-397	pos := n.Style["position"]
+357}
+358
+359func Min(a, b float32) float32 {
+360	if a < b {
+361		return a
+362	} else {
+363		return b
+364	}
+365}
+366
+367func FindRelative(n *element.Node, styleMap map[string]map[string]string) (float32, float32) {
+368	pos := styleMap[n.Properties.Id]["position"]
+369
+370	if pos == "relative" {
+371		x, _ := strconv.ParseFloat(styleMap[n.Properties.Id]["x"], 32)
+372		y, _ := strconv.ParseFloat(styleMap[n.Properties.Id]["y"], 32)
+373		return float32(x), float32(y)
+374	} else {
+375		if n.Parent != nil {
+376			x, y := FindRelative(n.Parent, styleMap)
+377			return x, y
+378		} else {
+379			return 0, 0
+380		}
+381	}
+382}
+383
+384func ParseFloat(str string, def float32) float32 {
+385	var a float32
+386	if str == "" {
+387		a = 0
+388	} else {
+389		v, _ := strconv.ParseFloat(str, 32)
+390		a = float32(v)
+391	}
+392	return a
+393}
+394
+395// getStructField uses reflection to get the value of a struct field by name
+396func GetStructField(data interface{}, fieldName string) (interface{}, error) {
+397	val := reflect.ValueOf(data)
@@ -445,26 +445,26 @@
-399	if pos == "relative" {
-400		return n
-401	} else {
-402		if n.Parent.TagName != "ROOT" {
-403			if n.Parent.Style != nil {
-404				return GetPositionOffsetNode(n.Parent)
-405			} else {
-406				return nil
-407			}
-408		} else {
-409			return n.Parent
-410		}
-411	}
-412}
-413
-414func IsParent(n element.Node, name string) bool {
-415	if n.Parent.TagName != "ROOT" {
-416		if n.Parent.TagName == name {
-417			return true
-418		} else {
-419			return IsParent(*n.Parent, name)
-420		}
-421	} else {
-422		return false
-423	}
-424}
+399	// Make sure we have a pointer to a struct
+400	if val.Kind() != reflect.Ptr || val.Elem().Kind() != reflect.Struct {
+401		return nil, fmt.Errorf("expected a pointer to a struct")
+402	}
+403
+404	// Get the struct field by name
+405	field := val.Elem().FieldByName(fieldName)
+406
+407	// Check if the field exists
+408	if !field.IsValid() {
+409		return nil, fmt.Errorf("field not found: %s", fieldName)
+410	}
+411
+412	return field.Interface(), nil
+413}
+414
+415func SetStructFieldValue(data interface{}, fieldName string, newValue interface{}) error {
+416	val := reflect.ValueOf(data)
+417
+418	// Make sure we have a pointer to a struct
+419	if val.Kind() != reflect.Ptr || val.Elem().Kind() != reflect.Struct {
+420		return fmt.Errorf("expected a pointer to a struct")
+421	}
+422
+423	// Get the struct field by name
+424	field := val.Elem().FieldByName(fieldName)
@@ -472,12 +472,12 @@
-426func ChildrenHaveText(n *element.Node) bool {
-427	for _, child := range n.Children {
-428		if len(strings.TrimSpace(child.InnerText)) != 0 {
-429			return true
-430		}
-431		// Recursively check if any child nodes have text
-432		if ChildrenHaveText(&child) {
-433			return true
-434		}
-435	}
-436	return false
-437}
+426	// Check if the field exists
+427	if !field.IsValid() {
+428		return fmt.Errorf("field not found: %s", fieldName)
+429	}
+430
+431	// Check if the new value type is assignable to the field type
+432	if !reflect.ValueOf(newValue).Type().AssignableTo(field.Type()) {
+433		return fmt.Errorf("incompatible types for field %s", fieldName)
+434	}
+435
+436	// Set the new value
+437	field.Set(reflect.ValueOf(newValue))
@@ -485,11 +485,11 @@
-439func NodeToHTML(node element.Node) (string, string) {
-440	// if node.TagName == "notaspan" {
-441	// 	return node.InnerText + " ", ""
-442	// }
-443
-444	var buffer bytes.Buffer
-445	buffer.WriteString("<" + node.TagName)
-446
-447	if node.Properties.Editable {
-448		buffer.WriteString(" contentEditable=\"true\"")
-449	}
+439	return nil
+440}
+441
+442func Check(e error) {
+443	if e != nil {
+444		panic(e)
+445	}
+446}
+447
+448func GetInnerText(n *html.Node) string {
+449	var result strings.Builder
@@ -497,19 +497,19 @@
-451	// Add ID if present
-452	if node.Id != "" {
-453		buffer.WriteString(" id=\"" + node.Id + "\"")
-454	}
-455
-456	// Add ID if present
-457	if node.Title != "" {
-458		buffer.WriteString(" title=\"" + node.Title + "\"")
-459	}
-460
-461	// Add ID if present
-462	if node.Src != "" {
-463		buffer.WriteString(" src=\"" + node.Src + "\"")
-464	}
-465
-466	// Add ID if present
-467	if node.Href != "" {
-468		buffer.WriteString(" href=\"" + node.Href + "\"")
-469	}
+451	var getText func(*html.Node)
+452	getText = func(n *html.Node) {
+453		// Skip processing if the node is a head tag
+454		if n.Type == html.ElementNode && n.Data == "head" {
+455			return
+456		}
+457
+458		// If it's a text node, append its content
+459		if n.Type == html.TextNode {
+460			result.WriteString(n.Data)
+461		}
+462
+463		// Traverse child nodes recursively
+464		for c := n.FirstChild; c != nil; c = c.NextSibling {
+465			getText(c)
+466		}
+467	}
+468
+469	getText(n)
@@ -517,27 +517,27 @@
-471	// Add class list if present
-472	if len(node.ClassList.Classes) > 0 || node.ClassList.Value != "" {
-473		classes := ""
-474		for _, v := range node.ClassList.Classes {
-475			if string(v[0]) != ":" {
-476				classes += v + " "
-477			}
-478		}
-479		classes = strings.TrimSpace(classes)
-480		if len(classes) > 0 {
-481			buffer.WriteString(" class=\"" + classes + "\"")
-482		}
-483	}
-484
-485	// Add style if present
-486	if len(node.Style) > 0 {
-487
-488		style := ""
-489		for key, value := range node.Style {
-490			if key != "inlineText" {
-491				style += key + ":" + value + ";"
-492			}
-493		}
-494		style = strings.TrimSpace(style)
-495
-496		if len(style) > 0 {
-497			buffer.WriteString(" style=\"" + style + "\"")
+471	return result.String()
+472}
+473
+474func GetPositionOffsetNode(n *element.Node) *element.Node {
+475	pos := n.Style["position"]
+476
+477	if pos == "relative" {
+478		return n
+479	} else {
+480		if n.Parent.TagName != "ROOT" {
+481			if n.Parent.Style != nil {
+482				return GetPositionOffsetNode(n.Parent)
+483			} else {
+484				return nil
+485			}
+486		} else {
+487			return n.Parent
+488		}
+489	}
+490}
+491
+492func IsParent(n element.Node, name string) bool {
+493	if n.Parent.TagName != "ROOT" {
+494		if n.Parent.TagName == name {
+495			return true
+496		} else {
+497			return IsParent(*n.Parent, name)
@@ -545,14 +545,14 @@
-499	}
-500
-501	// Add other attributes if present
-502	for key, value := range node.Attribute {
-503		if strings.TrimSpace(value) != "" {
-504			buffer.WriteString(" " + key + "=\"" + value + "\"")
-505		}
-506	}
-507
-508	buffer.WriteString(">")
-509
-510	// Add inner text if present
-511	if node.InnerText != "" && !ChildrenHaveText(&node) {
-512		buffer.WriteString(node.InnerText)
+499	} else {
+500		return false
+501	}
+502}
+503
+504func ChildrenHaveText(n *element.Node) bool {
+505	for _, child := range n.Children {
+506		if len(strings.TrimSpace(child.InnerText)) != 0 {
+507			return true
+508		}
+509		// Recursively check if any child nodes have text
+510		if ChildrenHaveText(&child) {
+511			return true
+512		}
@@ -560 +560 @@
-514	return buffer.String(), "</" + node.TagName + ">"
+514	return false
@@ -563,10 +563,10 @@
-517func OuterHTML(node element.Node) string {
-518	var buffer bytes.Buffer
-519
-520	tag, closing := NodeToHTML(node)
-521
-522	buffer.WriteString(tag)
-523
-524	// Recursively add children
-525	for _, child := range node.Children {
-526		buffer.WriteString(OuterHTML(child))
+517func NodeToHTML(node element.Node) (string, string) {
+518	// if node.TagName == "notaspan" {
+519	// 	return node.InnerText + " ", ""
+520	// }
+521
+522	var buffer bytes.Buffer
+523	buffer.WriteString("<" + node.TagName)
+524
+525	if node.Properties.Editable {
+526		buffer.WriteString(" contentEditable=\"true\"")
@@ -575,4 +575,4 @@
-529	buffer.WriteString(closing)
-530
-531	return buffer.String()
-532}
+529	// Add ID if present
+530	if node.Id != "" {
+531		buffer.WriteString(" id=\"" + node.Id + "\"")
+532	}
@@ -580,8 +580,86 @@
-534func InnerHTML(node element.Node) string {
-535	var buffer bytes.Buffer
-536	// Recursively add children
-537	for _, child := range node.Children {
-538		buffer.WriteString(OuterHTML(child))
-539	}
-540	return buffer.String()
-541}
+534	// Add ID if present
+535	if node.Title != "" {
+536		buffer.WriteString(" title=\"" + node.Title + "\"")
+537	}
+538
+539	// Add ID if present
+540	if node.Src != "" {
+541		buffer.WriteString(" src=\"" + node.Src + "\"")
+542	}
+543
+544	// Add ID if present
+545	if node.Href != "" {
+546		buffer.WriteString(" href=\"" + node.Href + "\"")
+547	}
+548
+549	// Add class list if present
+550	if len(node.ClassList.Classes) > 0 || node.ClassList.Value != "" {
+551		classes := ""
+552		for _, v := range node.ClassList.Classes {
+553			if string(v[0]) != ":" {
+554				classes += v + " "
+555			}
+556		}
+557		classes = strings.TrimSpace(classes)
+558		if len(classes) > 0 {
+559			buffer.WriteString(" class=\"" + classes + "\"")
+560		}
+561	}
+562
+563	// Add style if present
+564	if len(node.Style) > 0 {
+565
+566		style := ""
+567		for key, value := range node.Style {
+568			if key != "inlineText" {
+569				style += key + ":" + value + ";"
+570			}
+571		}
+572		style = strings.TrimSpace(style)
+573
+574		if len(style) > 0 {
+575			buffer.WriteString(" style=\"" + style + "\"")
+576		}
+577	}
+578
+579	// Add other attributes if present
+580	for key, value := range node.Attribute {
+581		if strings.TrimSpace(value) != "" {
+582			buffer.WriteString(" " + key + "=\"" + value + "\"")
+583		}
+584	}
+585
+586	buffer.WriteString(">")
+587
+588	// Add inner text if present
+589	if node.InnerText != "" && !ChildrenHaveText(&node) {
+590		buffer.WriteString(node.InnerText)
+591	}
+592	return buffer.String(), "</" + node.TagName + ">"
+593}
+594
+595func OuterHTML(node element.Node) string {
+596	var buffer bytes.Buffer
+597
+598	tag, closing := NodeToHTML(node)
+599
+600	buffer.WriteString(tag)
+601
+602	// Recursively add children
+603	for _, child := range node.Children {
+604		buffer.WriteString(OuterHTML(child))
+605	}
+606
+607	buffer.WriteString(closing)
+608
+609	return buffer.String()
+610}
+611
+612func InnerHTML(node element.Node) string {
+613	var buffer bytes.Buffer
+614	// Recursively add children
+615	for _, child := range node.Children {
+616		buffer.WriteString(OuterHTML(child))
+617	}
+618	return buffer.String()
+619}


    
        
        
        
        
        GRIM UI 
        
        
        
        
    
    
        
        

Utils

dsa

# MapToInline?(go)

# InlineToMap?(go)

# GetWH?(go)

# GetMP?(go)

# convertMarginToIndividualProperties?(go)

# ConvertToPixels?(go)

# evaluateCalcExpression?(go)

# GetTextBounds?(go)

# Merge?(go)

# ExMerge?(go)

# Max?(go)

# Min?(go)

# FindRelative?(go)

# ParseFloat?(go)

# GetStructField?(go)

# SetStructFieldValue?(go)

# Check?(go)

# GetInnerText?(go)

# GetPositionOffsetNode?(go)

# IsParent?(go)

  1package utils
  2
  3import (
  4	"bytes"
  5	"fmt"
  6	"gui/element"
  7	"reflect"
  8	"regexp"
  9	"strconv"
 10	"strings"
 11
 12	"golang.org/x/net/html"
 13)
 14
 15func GetXY(n *element.Node, state *map[string]element.State) (float32, float32) {
 16	s := *state
 17	// self := s[n.Properties.Id]
 18
 19	offsetX := float32(0)
 20	offsetY := float32(0)
 21
 22	if n.Parent != nil {
 23		parent := s[n.Parent.Properties.Id]
 24		// x, y := GetXY(n.Parent, state)
 25		offsetX += parent.Border.Width + parent.Padding.Left
 26		offsetY += parent.Border.Width + parent.Padding.Top
 27	}
 28
 29	return offsetX, offsetY
 30}
 31
 32type WidthHeight struct {
 33	Width  float32
 34	Height float32
 35}
 36
 37func GetWH(n element.Node, state *map[string]element.State) WidthHeight {
 38	s := *state
 39	self := s[n.Properties.Id]
 40	parent := element.State{}
 41
 42	if n.Style == nil {
 43		n.Style = map[string]string{}
 44	}
 45
 46	fs := self.EM
 47
 48	var pwh WidthHeight
 49	if n.Parent != nil {
 50		parent = s[n.Parent.Properties.Id]
 51		pwh = GetWH(*n.Parent, state)
 52	} else {
 53		pwh = WidthHeight{}
 54		if n.Style["width"] != "" {
 55			str := strings.TrimSuffix(n.Style["width"], "px")
 56			// Convert the string to float32
 57			f, _ := strconv.ParseFloat(str, 32)
 58			pwh.Width = float32(f)
 59		}
 60
 61		if n.Style["height"] != "" {
 62			str := strings.TrimSuffix(n.Style["height"], "px")
 63			// Convert the string to float32
 64			f, _ := strconv.ParseFloat(str, 32)
 65			pwh.Height = float32(f)
 66		}
 67	}
 68
 69	wStyle := n.Style["width"]
 70
 71	if wStyle == "" && n.Style["display"] != "inline" {
 72		wStyle = "100%"
 73	}
 74
 75	width, _ := ConvertToPixels(wStyle, fs, pwh.Width)
 76	height, _ := ConvertToPixels(n.Style["height"], fs, pwh.Height)
 77
 78	if n.Style["min-width"] != "" {
 79		minWidth, _ := ConvertToPixels(n.Style["min-width"], fs, pwh.Width)
 80		width = Max(width, minWidth)
 81	}
 82
 83	if n.Style["max-width"] != "" {
 84		maxWidth, _ := ConvertToPixels(n.Style["max-width"], fs, pwh.Width)
 85		width = Min(width, maxWidth)
 86	}
 87	if n.Style["min-height"] != "" {
 88		minHeight, _ := ConvertToPixels(n.Style["min-height"], fs, pwh.Height)
 89		height = Max(height, minHeight)
 90	}
 91
 92	if n.Style["max-height"] != "" {
 93		maxHeight, _ := ConvertToPixels(n.Style["max-height"], fs, pwh.Height)
 94		height = Min(height, maxHeight)
 95	}
 96
 97	wh := WidthHeight{
 98		Width:  width,
 99		Height: height,
100	}
101
102	if n.Parent != nil {
103		wh.Width += self.Padding.Left + self.Padding.Right
104		wh.Height += self.Padding.Top + self.Padding.Bottom
105		// fmt.Println(n.Properties.Id, wh, p)
106	}
107
108	if wStyle == "100%" {
109		wh.Width = wh.Width - ((self.Margin.Right + self.Margin.Left + (self.Border.Width * 2)) + (parent.Padding.Left + parent.Padding.Right) + (self.Padding.Left + self.Padding.Right))
110	}
111
112	if n.Style["height"] == "100%" {
113		wh.Height -= (self.Margin.Top + self.Margin.Bottom) + (parent.Padding.Top + parent.Padding.Bottom)
114	}
115
116	return wh
117}
118
119func GetMP(n element.Node, wh WidthHeight, state *map[string]element.State, t string) element.MarginPadding {
120	s := *state
121	self := s[n.Properties.Id]
122	fs := self.EM
123	m := element.MarginPadding{}
124
125	if n.Style[t] != "" {
126		left, right, top, bottom := convertMarginToIndividualProperties(n.Style[t])
127		if n.Style[t+"-left"] == "" {
128			n.Style[t+"-left"] = left
129		}
130		if n.Style[t+"-right"] == "" {
131			n.Style[t+"-right"] = right
132		}
133		if n.Style[t+"-top"] == "" {
134			n.Style[t+"-top"] = top
135		}
136		if n.Style[t+"-bottom"] == "" {
137			n.Style[t+"-bottom"] = bottom
138		}
139	}
140	if n.Style[t+"-left"] != "" || n.Style[t+"-right"] != "" {
141		l, _ := ConvertToPixels(n.Style[t+"-left"], fs, wh.Width)
142		r, _ := ConvertToPixels(n.Style[t+"-right"], fs, wh.Width)
143		m.Left = l
144		m.Right = r
145	}
146	if n.Style[t+"-top"] != "" || n.Style[t+"-bottom"] != "" {
147		top, _ := ConvertToPixels(n.Style[t+"-top"], fs, wh.Height)
148		b, _ := ConvertToPixels(n.Style[t+"-bottom"], fs, wh.Height)
149		m.Top = top
150		m.Bottom = b
151	}
152	if t == "margin" {
153		if n.Style["margin"] == "auto" && n.Style["margin-left"] == "" && n.Style["margin-right"] == "" {
154			pwh := GetWH(*n.Parent, state)
155			m.Left = Max((pwh.Width-wh.Width)/2, 0)
156			m.Right = m.Left
157		}
158	}
159
160	return m
161}
162
163func convertMarginToIndividualProperties(margin string) (string, string, string, string) {
164	// Remove extra whitespace
165	margin = strings.TrimSpace(margin)
166
167	if margin == "" {
168		return "0px", "0px", "0px", "0px"
169	}
170
171	// Regular expression to match values with optional units
172	re := regexp.MustCompile(`(-?\d+(\.\d+)?)(\w*|\%)?`)
173
174	// Extract numerical values from the margin property
175	matches := re.FindAllStringSubmatch(margin, -1)
176
177	// Initialize variables for individual margins
178	var left, right, top, bottom string
179
180	switch len(matches) {
181	case 1:
182		// If only one value is provided, apply it to all margins
183		left = matches[0][0]
184		right = matches[0][0]
185		top = matches[0][0]
186		bottom = matches[0][0]
187	case 2:
188		// If two values are provided, apply the first to top and bottom, and the second to left and right
189		top = matches[0][0]
190		bottom = matches[0][0]
191		left = matches[1][0]
192		right = matches[1][0]
193	case 3:
194		// If three values are provided, apply the first to top, the second to left and right, and the third to bottom
195		top = matches[0][0]
196		left = matches[1][0]
197		right = matches[1][0]
198		bottom = matches[2][0]
199	case 4:
200		// If four values are provided, apply them to top, right, bottom, and left, respectively
201		top = matches[0][0]
202		right = matches[1][0]
203		bottom = matches[2][0]
204		left = matches[3][0]
205	}
206
207	return left, right, top, bottom
208}
209
210// ConvertToPixels converts a CSS measurement to pixels.
211func ConvertToPixels(value string, em, max float32) (float32, error) {
212	unitFactors := map[string]float32{
213		"px": 1,
214		"em": em,
215		"pt": 1.33,
216		"pc": 16.89,
217		"%":  max / 100,
218		"vw": max / 100,
219		"vh": max / 100,
220		"cm": 37.79527559,
221		"in": 96,
222	}
223
224	if strings.HasPrefix(value, "calc(") {
225		// Handle calculation expression
226		calcResult, err := evaluateCalcExpression(value[5:len(value)-1], em, max)
227		if err != nil {
228			return 0, err
229		}
230		return calcResult, nil
231	} else {
232		// Extract numeric value and unit
233		for k, v := range unitFactors {
234			if strings.HasSuffix(value, k) {
235				cutStr, _ := strings.CutSuffix(value, k)
236				numericValue, _ := strconv.ParseFloat(cutStr, 64)
237				return float32(numericValue) * v, nil
238			}
239		}
240		return 0, fmt.Errorf("unable to parse value")
241	}
242
243}
244
245// evaluateCalcExpression recursively evaluates 'calc()' expressions
246func evaluateCalcExpression(expression string, em, max float32) (float32, error) {
247	terms := strings.FieldsFunc(expression, func(c rune) bool {
248		return c == '+' || c == '-' || c == '*' || c == '/'
249	})
250
251	operators := strings.FieldsFunc(expression, func(c rune) bool {
252		return c != '+' && c != '-' && c != '*' && c != '/'
253	})
254
255	var result float32
256
257	for i, term := range terms {
258		value, err := ConvertToPixels(strings.TrimSpace(term), em, max)
259		if err != nil {
260			return 0, err
261		}
262
263		if i > 0 {
264			switch operators[i-1] {
265			case "+":
266				result += value
267			case "-":
268				result -= value
269			case "*":
270				result *= value
271			case "/":
272				if value != 0 {
273					result /= value
274				} else {
275					return 0, fmt.Errorf("division by zero in 'calc()' expression")
276				}
277			}
278		} else {
279			result = value
280		}
281	}
282
283	return result, nil
284}
285
286func Merge(m1, m2 map[string]string) map[string]string {
287	// Create a new map and copy m1 into it
288	result := make(map[string]string)
289	for k, v := range m1 {
290		result[k] = v
291	}
292
293	// Merge m2 into the new map
294	for k, v := range m2 {
295		result[k] = v
296	}
297
298	return result
299}
300
301func Max(a, b float32) float32 {
302	if a > b {
303		return a
304	} else {
305		return b
306	}
307}
308
309func Min(a, b float32) float32 {
310	if a < b {
311		return a
312	} else {
313		return b
314	}
315}
316
317// getStructField uses reflection to get the value of a struct field by name
318func GetStructField(data interface{}, fieldName string) (interface{}, error) {
319	val := reflect.ValueOf(data)
320
321	// Make sure we have a pointer to a struct
322	if val.Kind() != reflect.Ptr || val.Elem().Kind() != reflect.Struct {
323		return nil, fmt.Errorf("expected a pointer to a struct")
324	}
325
326	// Get the struct field by name
327	field := val.Elem().FieldByName(fieldName)
328
329	// Check if the field exists
330	if !field.IsValid() {
331		return nil, fmt.Errorf("field not found: %s", fieldName)
332	}
333
334	return field.Interface(), nil
335}
336
337func SetStructFieldValue(data interface{}, fieldName string, newValue interface{}) error {
338	val := reflect.ValueOf(data)
339
340	// Make sure we have a pointer to a struct
341	if val.Kind() != reflect.Ptr || val.Elem().Kind() != reflect.Struct {
342		return fmt.Errorf("expected a pointer to a struct")
343	}
344
345	// Get the struct field by name
346	field := val.Elem().FieldByName(fieldName)
347
348	// Check if the field exists
349	if !field.IsValid() {
350		return fmt.Errorf("field not found: %s", fieldName)
351	}
352
353	// Check if the new value type is assignable to the field type
354	if !reflect.ValueOf(newValue).Type().AssignableTo(field.Type()) {
355		return fmt.Errorf("incompatible types for field %s", fieldName)
356	}
357
358	// Set the new value
359	field.Set(reflect.ValueOf(newValue))
360
361	return nil
362}
363
364// func Check(e error) {
365// 	if e != nil {
366// 		panic(e)
367// 	}
368// }
369
370func GetInnerText(n *html.Node) string {
371	var result strings.Builder
372
373	var getText func(*html.Node)
374	getText = func(n *html.Node) {
375		// Skip processing if the node is a head tag
376		if n.Type == html.ElementNode && n.Data == "head" {
377			return
378		}
379
380		// If it's a text node, append its content
381		if n.Type == html.TextNode {
382			result.WriteString(n.Data)
383		}
384
385		// Traverse child nodes recursively
386		for c := n.FirstChild; c != nil; c = c.NextSibling {
387			getText(c)
388		}
389	}
390
391	getText(n)
392
393	return result.String()
394}
395
396func GetPositionOffsetNode(n *element.Node) *element.Node {
397	pos := n.Style["position"]
398
399	if pos == "relative" {
400		return n
401	} else {
402		if n.Parent.TagName != "ROOT" {
403			if n.Parent.Style != nil {
404				return GetPositionOffsetNode(n.Parent)
405			} else {
406				return nil
407			}
408		} else {
409			return n.Parent
410		}
411	}
412}
413
414func IsParent(n element.Node, name string) bool {
415	if n.Parent.TagName != "ROOT" {
416		if n.Parent.TagName == name {
417			return true
418		} else {
419			return IsParent(*n.Parent, name)
420		}
421	} else {
422		return false
423	}
424}
425
426func ChildrenHaveText(n *element.Node) bool {
427	for _, child := range n.Children {
428		if len(strings.TrimSpace(child.InnerText)) != 0 {
429			return true
430		}
431		// Recursively check if any child nodes have text
432		if ChildrenHaveText(&child) {
433			return true
434		}
435	}
436	return false
437}
438
439func NodeToHTML(node element.Node) (string, string) {
440	// if node.TagName == "notaspan" {
441	// 	return node.InnerText + " ", ""
442	// }
443
444	var buffer bytes.Buffer
445	buffer.WriteString("<" + node.TagName)
446
447	if node.Properties.Editable {
448		buffer.WriteString(" contentEditable=\"true\"")
449	}
450
451	// Add ID if present
452	if node.Id != "" {
453		buffer.WriteString(" id=\"" + node.Id + "\"")
454	}
455
456	// Add ID if present
457	if node.Title != "" {
458		buffer.WriteString(" title=\"" + node.Title + "\"")
459	}
460
461	// Add ID if present
462	if node.Src != "" {
463		buffer.WriteString(" src=\"" + node.Src + "\"")
464	}
465
466	// Add ID if present
467	if node.Href != "" {
468		buffer.WriteString(" href=\"" + node.Href + "\"")
469	}
470
471	// Add class list if present
472	if len(node.ClassList.Classes) > 0 || node.ClassList.Value != "" {
473		classes := ""
474		for _, v := range node.ClassList.Classes {
475			if string(v[0]) != ":" {
476				classes += v + " "
477			}
478		}
479		classes = strings.TrimSpace(classes)
480		if len(classes) > 0 {
481			buffer.WriteString(" class=\"" + classes + "\"")
482		}
483	}
484
485	// Add style if present
486	if len(node.Style) > 0 {
487
488		style := ""
489		for key, value := range node.Style {
490			if key != "inlineText" {
491				style += key + ":" + value + ";"
492			}
493		}
494		style = strings.TrimSpace(style)
495
496		if len(style) > 0 {
497			buffer.WriteString(" style=\"" + style + "\"")
498		}
499	}
500
501	// Add other attributes if present
502	for key, value := range node.Attribute {
503		if strings.TrimSpace(value) != "" {
504			buffer.WriteString(" " + key + "=\"" + value + "\"")
505		}
506	}
507
508	buffer.WriteString(">")
509
510	// Add inner text if present
511	if node.InnerText != "" && !ChildrenHaveText(&node) {
512		buffer.WriteString(node.InnerText)
513	}
514	return buffer.String(), "</" + node.TagName + ">"
515}
516
517func OuterHTML(node element.Node) string {
518	var buffer bytes.Buffer
519
520	tag, closing := NodeToHTML(node)
521
522	buffer.WriteString(tag)
523
524	// Recursively add children
525	for _, child := range node.Children {
526		buffer.WriteString(OuterHTML(child))
527	}
528
529	buffer.WriteString(closing)
530
531	return buffer.String()
532}
533
534func InnerHTML(node element.Node) string {
535	var buffer bytes.Buffer
536	// Recursively add children
537	for _, child := range node.Children {
538		buffer.WriteString(OuterHTML(child))
539	}
540	return buffer.String()
541}