Author: LakeFox
Email: [email protected]
Date: Sat, 18 May 2024 15:57:20 -0600
docs/cstyle/index.html
transformers and text are working
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/cstyle/index.html b/docs/cstyle/index.html
index cf20576..480af84 100644
--- a/docs/cstyle/index.html
+++ b/docs/cstyle/index.html
@@ -68 +68 @@ The utils.ChildrenHaveText function is called here instead of checking if the no
- 27	Handler  func(element.Node, *CSS) element.Node
+ 27	Handler  func(element.Node) element.Node
@@ -81,10 +81,10 @@ The utils.ChildrenHaveText function is called here instead of checking if the no
- 40	for _, v := range c.Transformers {
- 41		if v.Selector(&n) {
- 42			n = v.Handler(n, c)
- 43		}
- 44	}
- 45	for i := 0; i < len(n.Children); i++ {
- 46		v := n.Children[i]
- 47		tc := c.Transform(v)
- 48		n = *tc.Parent
- 49		n.Children[i] = tc
+ 40	fmt.Println("########")
+ 41	fmt.Println(n.TagName)
+ 42	// for i := 0; i < len(n.Children); i++ {
+ 43	// 	v := n.Children[i]
+ 44	// 	fmt.Println(v.TagName)
+ 45	// }
+ 46	for i := 0; i < len(n.Children); i++ {
+ 47		v := n.Children[i]
+ 48		fmt.Println(v.TagName)
+ 49		n.Children[i] = c.Transform(v)
@@ -92,15 +92,15 @@ The utils.ChildrenHaveText function is called here instead of checking if the no
- 51
- 52	return n
- 53}
- 54
- 55func (c *CSS) StyleSheet(path string) {
- 56	// Parse the CSS file
- 57	dat, err := os.ReadFile(path)
- 58	utils.Check(err)
- 59	styles := parser.ParseCSS(string(dat))
- 60
- 61	c.StyleSheets = append(c.StyleSheets, styles)
- 62}
- 63
- 64func (c *CSS) StyleTag(css string) {
- 65	styles := parser.ParseCSS(css)
+ 51	for _, v := range c.Transformers {
+ 52		if v.Selector(&n) {
+ 53			n = v.Handler(n)
+ 54		}
+ 55	}
+ 56
+ 57	return n
+ 58}
+ 59
+ 60func (c *CSS) StyleSheet(path string) {
+ 61	// Parse the CSS file
+ 62	dat, err := os.ReadFile(path)
+ 63	utils.Check(err)
+ 64	styles := parser.ParseCSS(string(dat))
+ 65
@@ -110,51 +110,51 @@ The utils.ChildrenHaveText function is called here instead of checking if the no
- 69var inheritedProps = []string{
- 70	"color",
- 71	"cursor",
- 72	"font",
- 73	"font-family",
- 74	"font-size",
- 75	"font-style",
- 76	"font-weight",
- 77	"letter-spacing",
- 78	"line-height",
- 79	// "text-align",
- 80	"text-indent",
- 81	"text-justify",
- 82	"text-shadow",
- 83	"text-transform",
- 84	"text-decoration",
- 85	"visibility",
- 86	"word-spacing",
- 87	"display",
- 88}
- 89
- 90func (c *CSS) GetStyles(n element.Node) map[string]string {
- 91	styles := map[string]string{}
- 92
- 93	if n.Parent != nil {
- 94		ps := c.GetStyles(*n.Parent)
- 95		for _, v := range inheritedProps {
- 96			if ps[v] != "" {
- 97				styles[v] = ps[v]
- 98			}
- 99		}
-100	}
-101	for k, v := range n.Style {
-102		styles[k] = v
-103	}
-104	hovered := false
-105	if slices.Contains(n.ClassList.Classes, ":hover") {
-106		hovered = true
-107	}
-108
-109	for _, styleSheet := range c.StyleSheets {
-110		for selector := range styleSheet {
-111			// fmt.Println(selector, n.Properties.Id)
-112			key := selector
-113			if strings.Contains(selector, ":hover") && hovered {
-114				selector = strings.Replace(selector, ":hover", "", -1)
-115			}
-116			if element.TestSelector(selector, &n) {
-117				for k, v := range styleSheet[key] {
-118					styles[k] = v
-119				}
+ 69func (c *CSS) StyleTag(css string) {
+ 70	styles := parser.ParseCSS(css)
+ 71	c.StyleSheets = append(c.StyleSheets, styles)
+ 72}
+ 73
+ 74var inheritedProps = []string{
+ 75	"color",
+ 76	"cursor",
+ 77	"font",
+ 78	"font-family",
+ 79	"font-size",
+ 80	"font-style",
+ 81	"font-weight",
+ 82	"letter-spacing",
+ 83	"line-height",
+ 84	// "text-align",
+ 85	"text-indent",
+ 86	"text-justify",
+ 87	"text-shadow",
+ 88	"text-transform",
+ 89	"text-decoration",
+ 90	"visibility",
+ 91	"word-spacing",
+ 92	"display",
+ 93}
+ 94
+ 95func (c *CSS) GetStyles(n element.Node) map[string]string {
+ 96	styles := map[string]string{}
+ 97
+ 98	if n.Parent != nil {
+ 99		ps := c.GetStyles(*n.Parent)
+100		for _, v := range inheritedProps {
+101			if ps[v] != "" {
+102				styles[v] = ps[v]
+103			}
+104		}
+105	}
+106	for k, v := range n.Style {
+107		styles[k] = v
+108	}
+109	hovered := false
+110	if slices.Contains(n.ClassList.Classes, ":hover") {
+111		hovered = true
+112	}
+113
+114	for _, styleSheet := range c.StyleSheets {
+115		for selector := range styleSheet {
+116			// fmt.Println(selector, n.Properties.Id)
+117			key := selector
+118			if strings.Contains(selector, ":hover") && hovered {
+119				selector = strings.Replace(selector, ":hover", "", -1)
@@ -162,54 +162,54 @@ The utils.ChildrenHaveText function is called here instead of checking if the no
-121
-122		}
-123	}
-124
-125	// This is different than node.Style
-126	// temp1 = <span style=​"color:​#a6e22e">​CSS​</span>​
-127	// temp1.style == CSSStyleDeclaration {0: 'color', accentColor: '', additiveSymbols: '', alignContent: '', alignItems: '', alignSelf: '', …}
-128	// temp1.getAttribute("style") == 'color:#a6e22e'
-129	inline := parser.ParseStyleAttribute(n.GetAttribute("style") + ";")
-130	styles = utils.Merge(styles, inline)
-131	// add hover and focus css events
-132
-133	if n.Parent != nil {
-134		if styles["z-index"] == "" && n.Parent.Style["z-index"] != "" {
-135			z, _ := strconv.Atoi(n.Parent.Style["z-index"])
-136			z += 1
-137			styles["z-index"] = strconv.Itoa(z)
-138		}
-139	}
-140
-141	return styles
-142}
-143
-144func (c *CSS) AddPlugin(plugin Plugin) {
-145	c.Plugins = append(c.Plugins, plugin)
-146}
-147
-148func (c *CSS) AddTransformer(transformer Transformer) {
-149	c.Transformers = append(c.Transformers, transformer)
-150}
-151
-152func CheckNode(n *element.Node, state *map[string]element.State) {
-153	s := *state
-154	self := s[n.Properties.Id]
-155
-156	fmt.Println(n.TagName, n.Properties.Id)
-157	fmt.Printf("ID: %v\n", n.Id)
-158	fmt.Printf("EM: %v\n", self.EM)
-159	fmt.Printf("Parent: %v\n", n.Parent.TagName)
-160	fmt.Printf("Classes: %v\n", n.ClassList.Classes)
-161	fmt.Printf("Text: %v\n", n.InnerText)
-162	fmt.Printf("X: %v, Y: %v, Z: %v\n", self.X, self.Y, self.Z)
-163	fmt.Printf("Width: %v, Height: %v\n", self.Width, self.Height)
-164	fmt.Printf("Styles: %v\n", n.Style)
-165	fmt.Printf("Background: %v\n", self.Background)
-166	fmt.Printf("Border: %v\n\n\n", self.Border)
-167}
-168
-169func (c *CSS) ComputeNodeStyle(n *element.Node, state *map[string]element.State) *element.Node {
-170
-171	// Head is not renderable
-172	if utils.IsParent(*n, "head") {
-173		return n
-174	}
+121			if element.TestSelector(selector, &n) {
+122				for k, v := range styleSheet[key] {
+123					styles[k] = v
+124				}
+125			}
+126
+127		}
+128	}
+129
+130	// This is different than node.Style
+131	// temp1 = <span style=​"color:​#a6e22e">​CSS​</span>​
+132	// temp1.style == CSSStyleDeclaration {0: 'color', accentColor: '', additiveSymbols: '', alignContent: '', alignItems: '', alignSelf: '', …}
+133	// temp1.getAttribute("style") == 'color:#a6e22e'
+134	inline := parser.ParseStyleAttribute(n.GetAttribute("style") + ";")
+135	styles = utils.Merge(styles, inline)
+136	// add hover and focus css events
+137
+138	if n.Parent != nil {
+139		if styles["z-index"] == "" && n.Parent.Style["z-index"] != "" {
+140			z, _ := strconv.Atoi(n.Parent.Style["z-index"])
+141			z += 1
+142			styles["z-index"] = strconv.Itoa(z)
+143		}
+144	}
+145
+146	return styles
+147}
+148
+149func (c *CSS) AddPlugin(plugin Plugin) {
+150	c.Plugins = append(c.Plugins, plugin)
+151}
+152
+153func (c *CSS) AddTransformer(transformer Transformer) {
+154	c.Transformers = append(c.Transformers, transformer)
+155}
+156
+157func CheckNode(n *element.Node, state *map[string]element.State) {
+158	s := *state
+159	self := s[n.Properties.Id]
+160
+161	fmt.Println(n.TagName, n.Properties.Id)
+162	fmt.Printf("ID: %v\n", n.Id)
+163	fmt.Printf("EM: %v\n", self.EM)
+164	fmt.Printf("Parent: %v\n", n.Parent.TagName)
+165	fmt.Printf("Classes: %v\n", n.ClassList.Classes)
+166	fmt.Printf("Text: %v\n", n.InnerText)
+167	fmt.Printf("X: %v, Y: %v, Z: %v\n", self.X, self.Y, self.Z)
+168	fmt.Printf("Width: %v, Height: %v\n", self.Width, self.Height)
+169	fmt.Printf("Styles: %v\n", self.Style)
+170	fmt.Printf("Background: %v\n", self.Background)
+171	fmt.Printf("Border: %v\n\n\n", self.Border)
+172}
+173
+174func (c *CSS) ComputeNodeStyle(n *element.Node, state *map[string]element.State) *element.Node {
@@ -217,11 +217,11 @@ The utils.ChildrenHaveText function is called here instead of checking if the no
-176	plugins := c.Plugins
-177
-178	s := *state
-179	self := s[n.Properties.Id]
-180	parent := s[n.Parent.Properties.Id]
-181
-182	self.Background = color.Parse(n.Style, "background")
-183	self.Border, _ = CompleteBorder(n.Style, self, parent)
-184
-185	fs, _ := utils.ConvertToPixels(n.Style["font-size"], parent.EM, parent.Width)
-186	self.EM = fs
+176	// Head is not renderable
+177	if utils.IsParent(*n, "head") {
+178		return n
+179	}
+180
+181	plugins := c.Plugins
+182
+183	s := *state
+184	self := s[n.Properties.Id]
+185	parent := s[n.Parent.Properties.Id]
+186	self.Style = c.GetStyles(*n)
@@ -229,16 +229,16 @@ The utils.ChildrenHaveText function is called here instead of checking if the no
-188	if n.Style["display"] == "none" {
-189		self.X = 0
-190		self.Y = 0
-191		self.Width = 0
-192		self.Height = 0
-193		return n
-194	}
-195
-196	if n.Style["width"] == "" && n.Style["display"] == "block" {
-197		n.Style["width"] = "100%"
-198	}
-199
-200	// Set Z index value to be sorted in window
-201	if n.Style["z-index"] != "" {
-202		z, _ := strconv.Atoi(n.Style["z-index"])
-203		self.Z = float32(z)
+188	self.Background = color.Parse(self.Style, "background")
+189	self.Border, _ = CompleteBorder(self.Style, self, parent)
+190
+191	fs, _ := utils.ConvertToPixels(self.Style["font-size"], parent.EM, parent.Width)
+192	self.EM = fs
+193
+194	if self.Style["display"] == "none" {
+195		self.X = 0
+196		self.Y = 0
+197		self.Width = 0
+198		self.Height = 0
+199		return n
+200	}
+201
+202	if self.Style["width"] == "" && self.Style["display"] == "block" {
+203		self.Style["width"] = "100%"
@@ -247,5 +247,5 @@ The utils.ChildrenHaveText function is called here instead of checking if the no
-206	if parent.Z > 0 {
-207		self.Z = parent.Z + 1
-208	}
-209
-210	(*state)[n.Properties.Id] = self
+206	// Set Z index value to be sorted in window
+207	if self.Style["z-index"] != "" {
+208		z, _ := strconv.Atoi(self.Style["z-index"])
+209		self.Z = float32(z)
+210	}
@@ -253,3 +253,3 @@ The utils.ChildrenHaveText function is called here instead of checking if the no
-212	wh := utils.GetWH(*n, state)
-213	width := wh.Width
-214	height := wh.Height
+212	if parent.Z > 0 {
+213		self.Z = parent.Z + 1
+214	}
@@ -257,5 +257,5 @@ The utils.ChildrenHaveText function is called here instead of checking if the no
-216	x, y := parent.X, parent.Y
-217	// !NOTE: Would like to consolidate all XY function into this function like WH
-218	offsetX, offsetY := utils.GetXY(n, state)
-219	x += offsetX
-220	y += offsetY
+216	(*state)[n.Properties.Id] = self
+217
+218	wh := utils.GetWH(*n, state)
+219	width := wh.Width
+220	height := wh.Height
@@ -263,7 +263,7 @@ The utils.ChildrenHaveText function is called here instead of checking if the no
-222	var top, left, right, bottom bool = false, false, false, false
-223
-224	m := utils.GetMP(*n, wh, state, "margin")
-225	p := utils.GetMP(*n, wh, state, "padding")
-226
-227	self.Margin = m
-228	self.Padding = p
+222	x, y := parent.X, parent.Y
+223	// !NOTE: Would like to consolidate all XY function into this function like WH
+224	offsetX, offsetY := utils.GetXY(n, state)
+225	x += offsetX
+226	y += offsetY
+227
+228	var top, left, right, bottom bool = false, false, false, false
@@ -271,109 +271,109 @@ The utils.ChildrenHaveText function is called here instead of checking if the no
-230	if n.Style["position"] == "absolute" {
-231		bas := utils.GetPositionOffsetNode(n)
-232		base := s[bas.Properties.Id]
-233		if n.Style["top"] != "" {
-234			v, _ := utils.ConvertToPixels(n.Style["top"], self.EM, parent.Width)
-235			y = v + base.Y
-236			top = true
-237		}
-238		if n.Style["left"] != "" {
-239			v, _ := utils.ConvertToPixels(n.Style["left"], self.EM, parent.Width)
-240			x = v + base.X
-241			left = true
-242		}
-243		if n.Style["right"] != "" {
-244			v, _ := utils.ConvertToPixels(n.Style["right"], self.EM, parent.Width)
-245			x = (base.Width - width) - v
-246			right = true
-247		}
-248		if n.Style["bottom"] != "" {
-249			v, _ := utils.ConvertToPixels(n.Style["bottom"], self.EM, parent.Width)
-250			y = (base.Height - height) - v
-251			bottom = true
-252		}
-253
-254	} else {
-255		for i, v := range n.Parent.Children {
-256			if v.Style["position"] != "absolute" {
-257				if v.Properties.Id == n.Properties.Id {
-258					if i-1 > 0 {
-259						sib := n.Parent.Children[i-1]
-260						sibling := s[sib.Properties.Id]
-261						if sib.Style["position"] != "absolute" {
-262							if n.Style["display"] == "inline" {
-263								if sib.Style["display"] == "inline" {
-264									y = sibling.Y
-265								} else {
-266									y = sibling.Y + sibling.Height
-267								}
-268							} else {
-269								y = sibling.Y + sibling.Height + (sibling.Border.Width * 2) + sibling.Margin.Bottom
-270							}
-271						}
-272
-273					}
-274					break
-275				} else if n.Style["display"] != "inline" {
-276					vState := s[v.Properties.Id]
-277					y += vState.Margin.Top + vState.Margin.Bottom + vState.Padding.Top + vState.Padding.Bottom + vState.Height + (self.Border.Width)
-278				}
-279			}
-280		}
-281	}
-282
-283	// Display modes need to be calculated here
-284
-285	relPos := !top && !left && !right && !bottom
-286
-287	if left || relPos {
-288		x += m.Left
-289	}
-290	if top || relPos {
-291		y += m.Top
-292	}
-293	if right {
-294		x -= m.Right
-295	}
-296	if bottom {
-297		y -= m.Bottom
-298	}
-299
-300	self.X = x
-301	self.Y = y
-302	self.Width = width
-303	self.Height = height
-304	(*state)[n.Properties.Id] = self
-305
-306	if !utils.ChildrenHaveText(n) && len(n.InnerText) > 0 {
-307		// Confirm text exists
-308		if len(strings.TrimSpace(n.InnerText)) > 0 {
-309			n.InnerText = strings.TrimSpace(n.InnerText)
-310			self = genTextNode(n, state)
-311		}
-312	}
-313
-314	(*state)[n.Properties.Id] = self
-315	(*state)[n.Parent.Properties.Id] = parent
-316
-317	// Call children here
-318
-319	var childYOffset float32
-320	for i := 0; i < len(n.Children); i++ {
-321		v := n.Children[i]
-322		v.Parent = n
-323		// This is were the tainting comes from
-324		n.Children[i] = *c.ComputeNodeStyle(&v, state)
-325
-326		cState := (*state)[n.Children[i].Properties.Id]
-327		if n.Style["height"] == "" {
-328			if v.Style["position"] != "absolute" && cState.Y+cState.Height > childYOffset {
-329				childYOffset = cState.Y + cState.Height
-330				self.Height = (cState.Y - self.Border.Width) - (self.Y) + cState.Height
-331				self.Height += cState.Margin.Top
-332				self.Height += cState.Margin.Bottom
-333				self.Height += cState.Padding.Top
-334				self.Height += cState.Padding.Bottom
-335			}
-336		}
-337		if cState.Width > self.Width {
-338			self.Width = cState.Width
+230	m := utils.GetMP(*n, wh, state, "margin")
+231	p := utils.GetMP(*n, wh, state, "padding")
+232
+233	self.Margin = m
+234	self.Padding = p
+235
+236	if self.Style["position"] == "absolute" {
+237		bas := utils.GetPositionOffsetNode(n, state)
+238		base := s[bas.Properties.Id]
+239		if self.Style["top"] != "" {
+240			v, _ := utils.ConvertToPixels(self.Style["top"], self.EM, parent.Width)
+241			y = v + base.Y
+242			top = true
+243		}
+244		if self.Style["left"] != "" {
+245			v, _ := utils.ConvertToPixels(self.Style["left"], self.EM, parent.Width)
+246			x = v + base.X
+247			left = true
+248		}
+249		if self.Style["right"] != "" {
+250			v, _ := utils.ConvertToPixels(self.Style["right"], self.EM, parent.Width)
+251			x = (base.Width - width) - v
+252			right = true
+253		}
+254		if self.Style["bottom"] != "" {
+255			v, _ := utils.ConvertToPixels(self.Style["bottom"], self.EM, parent.Width)
+256			y = (base.Height - height) - v
+257			bottom = true
+258		}
+259
+260	} else {
+261		for i, v := range n.Parent.Children {
+262			vState := s[v.Properties.Id]
+263			if vState.Style["position"] != "absolute" {
+264				if v.Properties.Id == n.Properties.Id {
+265					if i-1 > 0 {
+266						sib := n.Parent.Children[i-1]
+267						sibling := s[sib.Properties.Id]
+268						if sibling.Style["position"] != "absolute" {
+269							if self.Style["display"] == "inline" {
+270								if sibling.Style["display"] == "inline" {
+271									y = sibling.Y
+272								} else {
+273									y = sibling.Y + sibling.Height
+274								}
+275							} else {
+276								y = sibling.Y + sibling.Height + (sibling.Border.Width * 2) + sibling.Margin.Bottom
+277							}
+278						}
+279
+280					}
+281					break
+282				} else if self.Style["display"] != "inline" {
+283					vState := s[v.Properties.Id]
+284					y += vState.Margin.Top + vState.Margin.Bottom + vState.Padding.Top + vState.Padding.Bottom + vState.Height + (self.Border.Width)
+285				}
+286			}
+287		}
+288	}
+289
+290	// Display modes need to be calculated here
+291
+292	relPos := !top && !left && !right && !bottom
+293
+294	if left || relPos {
+295		x += m.Left
+296	}
+297	if top || relPos {
+298		y += m.Top
+299	}
+300	if right {
+301		x -= m.Right
+302	}
+303	if bottom {
+304		y -= m.Bottom
+305	}
+306
+307	self.X = x
+308	self.Y = y
+309	self.Width = width
+310	self.Height = height
+311	(*state)[n.Properties.Id] = self
+312
+313	if !utils.ChildrenHaveText(n) && len(n.InnerText) > 0 {
+314		// Confirm text exists
+315		// words := strings.Split(strings.TrimSpace(n.InnerText), " ")
+316		// if len(words) != 1 {
+317		// 	if self.Style["display"] == "inline" {
+318		// 		n.InnerText = words[0]
+319		// 		// for i := 1; i < len(words); i++ {
+320		// 		// el := *n
+321		// 		// el.InnerText = strings.Join(words[1:], " ")
+322		// 		// n.Parent.InsertAfter(el, *n)
+323		// 		// fmt.Println("injetc", el.Properties.Id)
+324		// 		// }
+325
+326		// 	} else {
+327		// 		// el := n.CreateElement("notaspan")
+328		// 		// el.InnerText = n.InnerText
+329		// 		// n.AppendChild(el)
+330		// 		// self.Style["font-size"] = parent.Style["font-size"]
+331		// 		// self.EM = parent.EM
+332		// 		// n.InnerText = ""
+333		// 	}
+334		// 	(*state)[n.Properties.Id] = self
+335		// }
+336		if len(strings.TrimSpace(n.InnerText)) > 0 {
+337			n.InnerText = strings.TrimSpace(n.InnerText)
+338			self = genTextNode(n, state)
@@ -383,29 +383,29 @@ The utils.ChildrenHaveText function is called here instead of checking if the no
-342	self.Height += self.Padding.Bottom
-343
-344	(*state)[n.Properties.Id] = self
-345
-346	// Sorting the array by the Level field
-347	sort.Slice(plugins, func(i, j int) bool {
-348		return plugins[i].Level < plugins[j].Level
-349	})
-350
-351	for _, v := range plugins {
-352		matches := true
-353		for name, value := range v.Styles {
-354			if n.Style[name] != value && !(value == "*") && n.Style[name] != "" {
-355				matches = false
-356			}
-357		}
-358		if matches {
-359			v.Handler(n, state)
-360		}
-361	}
-362
-363	// CheckNode(n, state)
-364
-365	return n
-366}
-367
-368func CompleteBorder(cssProperties map[string]string, self, parent element.State) (element.Border, error) {
-369	// Split the shorthand into components
-370	borderComponents := strings.Fields(cssProperties["border"])
+342	(*state)[n.Properties.Id] = self
+343	(*state)[n.Parent.Properties.Id] = parent
+344
+345	// Call children here
+346
+347	var childYOffset float32
+348	for i := 0; i < len(n.Children); i++ {
+349		v := n.Children[i]
+350		v.Parent = n
+351		// This is were the tainting comes from
+352		n.Children[i] = *c.ComputeNodeStyle(&v, state)
+353
+354		cState := (*state)[n.Children[i].Properties.Id]
+355		if self.Style["height"] == "" {
+356			if cState.Style["position"] != "absolute" && cState.Y+cState.Height > childYOffset {
+357				childYOffset = cState.Y + cState.Height
+358				self.Height = (cState.Y - self.Border.Width) - (self.Y) + cState.Height
+359				self.Height += cState.Margin.Top
+360				self.Height += cState.Margin.Bottom
+361				self.Height += cState.Padding.Top
+362				self.Height += cState.Padding.Bottom
+363			}
+364		}
+365		if cState.Width > self.Width {
+366			self.Width = cState.Width
+367		}
+368	}
+369
+370	self.Height += self.Padding.Bottom
@@ -413,18 +413,18 @@ The utils.ChildrenHaveText function is called here instead of checking if the no
-372	// Ensure there are at least 1 component (width or style or color)
-373	if len(borderComponents) >= 1 {
-374		width := "0px" // Default width
-375		style := "solid"
-376		borderColor := "#000000" // Default color
-377
-378		// Extract style and color if available
-379		if len(borderComponents) >= 1 {
-380			width = borderComponents[0]
-381		}
-382
-383		// Extract style and color if available
-384		if len(borderComponents) >= 2 {
-385			style = borderComponents[1]
-386		}
-387		if len(borderComponents) >= 3 {
-388			borderColor = borderComponents[2]
-389		}
+372	(*state)[n.Properties.Id] = self
+373
+374	// Sorting the array by the Level field
+375	sort.Slice(plugins, func(i, j int) bool {
+376		return plugins[i].Level < plugins[j].Level
+377	})
+378
+379	for _, v := range plugins {
+380		matches := true
+381		for name, value := range v.Styles {
+382			if self.Style[name] != value && !(value == "*") && self.Style[name] != "" {
+383				matches = false
+384			}
+385		}
+386		if matches {
+387			v.Handler(n, state)
+388		}
+389	}
@@ -432,23 +432,23 @@ The utils.ChildrenHaveText function is called here instead of checking if the no
-391		parsedColor, _ := color.Color(borderColor)
-392
-393		w, _ := utils.ConvertToPixels(width, self.EM, parent.Width)
-394
-395		return element.Border{
-396			Width:  w,
-397			Style:  style,
-398			Color:  parsedColor,
-399			Radius: cssProperties["border-radius"],
-400		}, nil
-401	}
-402
-403	return element.Border{}, fmt.Errorf("invalid border shorthand format")
-404}
-405
-406func genTextNode(n *element.Node, state *map[string]element.State) element.State {
-407	s := *state
-408	self := s[n.Properties.Id]
-409	parent := s[n.Parent.Properties.Id]
-410
-411	text := element.Text{}
-412
-413	bold, italic := false, false
+391	// n.InnerHTML = utils.InnerHTML(*n)
+392	// tag, closing := utils.NodeToHTML(*n)
+393	// n.OuterHTML = tag + n.InnerHTML + closing
+394
+395	// CheckNode(n, state)
+396
+397	return n
+398}
+399
+400func CompleteBorder(cssProperties map[string]string, self, parent element.State) (element.Border, error) {
+401	// Split the shorthand into components
+402	borderComponents := strings.Fields(cssProperties["border"])
+403
+404	// Ensure there are at least 1 component (width or style or color)
+405	if len(borderComponents) >= 1 {
+406		width := "0px" // Default width
+407		style := "solid"
+408		borderColor := "#000000" // Default color
+409
+410		// Extract style and color if available
+411		if len(borderComponents) >= 1 {
+412			width = borderComponents[0]
+413		}
@@ -456,7 +456,7 @@ The utils.ChildrenHaveText function is called here instead of checking if the no
-415	if n.Style["font-weight"] == "bold" {
-416		bold = true
-417	}
-418
-419	if n.Style["font-style"] == "italic" {
-420		italic = true
-421	}
+415		// Extract style and color if available
+416		if len(borderComponents) >= 2 {
+417			style = borderComponents[1]
+418		}
+419		if len(borderComponents) >= 3 {
+420			borderColor = borderComponents[2]
+421		}
@@ -464,10 +464,10 @@ The utils.ChildrenHaveText function is called here instead of checking if the no
-423	if text.Font == nil {
-424		f, _ := font.LoadFont(n.Style["font-family"], int(self.EM), bold, italic)
-425		text.Font = f
-426	}
-427
-428	letterSpacing, _ := utils.ConvertToPixels(n.Style["letter-spacing"], self.EM, parent.Width)
-429	wordSpacing, _ := utils.ConvertToPixels(n.Style["word-spacing"], self.EM, parent.Width)
-430	lineHeight, _ := utils.ConvertToPixels(n.Style["line-height"], self.EM, parent.Width)
-431	if lineHeight == 0 {
-432		lineHeight = self.EM + 3
+423		parsedColor, _ := color.Color(borderColor)
+424
+425		w, _ := utils.ConvertToPixels(width, self.EM, parent.Width)
+426
+427		return element.Border{
+428			Width:  w,
+429			Style:  style,
+430			Color:  parsedColor,
+431			Radius: cssProperties["border-radius"],
+432		}, nil
@@ -476,24 +476,24 @@ The utils.ChildrenHaveText function is called here instead of checking if the no
-435	text.LineHeight = int(lineHeight)
-436	text.WordSpacing = int(wordSpacing)
-437	text.LetterSpacing = int(letterSpacing)
-438	wb := " "
-439
-440	if n.Style["word-wrap"] == "break-word" {
-441		wb = ""
-442	}
-443
-444	if n.Style["text-wrap"] == "wrap" || n.Style["text-wrap"] == "balance" {
-445		wb = ""
-446	}
-447
-448	var dt float32
-449
-450	if n.Style["text-decoration-thickness"] == "auto" || n.Style["text-decoration-thickness"] == "" {
-451		dt = self.EM / 7
-452	} else {
-453		dt, _ = utils.ConvertToPixels(n.Style["text-decoration-thickness"], self.EM, parent.Width)
-454	}
-455
-456	col := color.Parse(n.Style, "font")
-457
-458	self.Color = col
+435	return element.Border{}, fmt.Errorf("invalid border shorthand format")
+436}
+437
+438func genTextNode(n *element.Node, state *map[string]element.State) element.State {
+439	s := *state
+440	self := s[n.Properties.Id]
+441	parent := s[n.Parent.Properties.Id]
+442
+443	text := element.Text{}
+444
+445	bold, italic := false, false
+446
+447	if self.Style["font-weight"] == "bold" {
+448		bold = true
+449	}
+450
+451	if self.Style["font-style"] == "italic" {
+452		italic = true
+453	}
+454
+455	if text.Font == nil {
+456		f, _ := font.LoadFont(self.Style["font-family"], int(self.EM), bold, italic)
+457		text.Font = f
+458	}
@@ -501,21 +501,21 @@ The utils.ChildrenHaveText function is called here instead of checking if the no
-460	text.Color = col
-461	text.DecorationColor = color.Parse(n.Style, "decoration")
-462	text.Align = n.Style["text-align"]
-463	text.WordBreak = wb
-464	text.WordSpacing = int(wordSpacing)
-465	text.LetterSpacing = int(letterSpacing)
-466	text.WhiteSpace = n.Style["white-space"]
-467	text.DecorationThickness = int(dt)
-468	text.Overlined = n.Style["text-decoration"] == "overline"
-469	text.Underlined = n.Style["text-decoration"] == "underline"
-470	text.LineThrough = n.Style["text-decoration"] == "linethrough"
-471	text.EM = int(self.EM)
-472	text.Width = int(parent.Width)
-473	text.Text = n.InnerText
-474
-475	if n.Style["word-spacing"] == "" {
-476		text.WordSpacing = font.MeasureSpace(&text)
-477	}
-478
-479	img, width := font.Render(&text)
-480	self.Texture = img
+460	letterSpacing, _ := utils.ConvertToPixels(self.Style["letter-spacing"], self.EM, parent.Width)
+461	wordSpacing, _ := utils.ConvertToPixels(self.Style["word-spacing"], self.EM, parent.Width)
+462	lineHeight, _ := utils.ConvertToPixels(self.Style["line-height"], self.EM, parent.Width)
+463	if lineHeight == 0 {
+464		lineHeight = self.EM + 3
+465	}
+466
+467	text.LineHeight = int(lineHeight)
+468	text.WordSpacing = int(wordSpacing)
+469	text.LetterSpacing = int(letterSpacing)
+470	wb := " "
+471
+472	if self.Style["word-wrap"] == "break-word" {
+473		wb = ""
+474	}
+475
+476	if self.Style["text-wrap"] == "wrap" || self.Style["text-wrap"] == "balance" {
+477		wb = ""
+478	}
+479
+480	var dt float32
@@ -523,7 +523,7 @@ The utils.ChildrenHaveText function is called here instead of checking if the no
-482	if n.Style["height"] == "" {
-483		self.Height = float32(text.LineHeight)
-484	}
-485
-486	if n.Style["width"] == "" {
-487		self.Width = float32(width)
-488	}
+482	if self.Style["text-decoration-thickness"] == "auto" || self.Style["text-decoration-thickness"] == "" {
+483		dt = self.EM / 7
+484	} else {
+485		dt, _ = utils.ConvertToPixels(self.Style["text-decoration-thickness"], self.EM, parent.Width)
+486	}
+487
+488	col := color.Parse(self.Style, "font")
@@ -531,2 +531,34 @@ The utils.ChildrenHaveText function is called here instead of checking if the no
-490	return self
-491}
+490	self.Color = col
+491
+492	text.Color = col
+493	text.DecorationColor = color.Parse(self.Style, "decoration")
+494	text.Align = self.Style["text-align"]
+495	text.WordBreak = wb
+496	text.WordSpacing = int(wordSpacing)
+497	text.LetterSpacing = int(letterSpacing)
+498	text.WhiteSpace = self.Style["white-space"]
+499	text.DecorationThickness = int(dt)
+500	text.Overlined = self.Style["text-decoration"] == "overline"
+501	text.Underlined = self.Style["text-decoration"] == "underline"
+502	text.LineThrough = self.Style["text-decoration"] == "linethrough"
+503	text.EM = int(self.EM)
+504	text.Width = int(parent.Width)
+505	text.Text = n.InnerText
+506
+507	if self.Style["word-spacing"] == "" {
+508		text.WordSpacing = font.MeasureSpace(&text)
+509	}
+510
+511	img, width := font.Render(&text)
+512	self.Texture = img
+513
+514	if self.Style["height"] == "" {
+515		self.Height = float32(text.LineHeight)
+516	}
+517
+518	if self.Style["width"] == "" {
+519		self.Width = float32(width)
+520	}
+521
+522	return self
+523}


    
        
        
        
        
        GRIM UI 
        
        
        
        
    
    
        
        

CStyle

CStyle is a single pass style computer.

# StyleSheet?(go)

# StyleTag?(go)

# GetStyles?(go)

# AddPlugin?(go)

See /cstyle/plugins/

# ComputeNodeStyle?(go)

if !utils.ChildrenHaveText(n) The utils.ChildrenHaveText function is called here instead of checking if the node directly has text is because in the case below

1<em><b>Text</b></em>

The em element does not have text but it has a element with text insid, but the element will still need to be rendered as text.

# parseBorderShorthand?(go)

# CompleteBorder?(go)

# genTextNode?(go)

  1package cstyle
  2
  3import (
  4	"fmt"
  5	"gui/color"
  6	"gui/element"
  7	"gui/font"
  8	"gui/parser"
  9	"gui/utils"
 10	"os"
 11	"slices"
 12	"sort"
 13	"strconv"
 14	"strings"
 15)
 16
 17// !TODO: Make a fine selector to target tags and if it has children or not etc
 18// + could copy the transformers but idk
 19type Plugin struct {
 20	Styles  map[string]string
 21	Level   int
 22	Handler func(*element.Node, *map[string]element.State)
 23}
 24
 25type Transformer struct {
 26	Selector func(*element.Node) bool
 27	Handler  func(element.Node, *CSS) element.Node
 28}
 29
 30type CSS struct {
 31	Width        float32
 32	Height       float32
 33	StyleSheets  []map[string]map[string]string
 34	Plugins      []Plugin
 35	Transformers []Transformer
 36	Document     *element.Node
 37}
 38
 39func (c *CSS) Transform(n element.Node) element.Node {
 40	for _, v := range c.Transformers {
 41		if v.Selector(&n) {
 42			n = v.Handler(n, c)
 43		}
 44	}
 45	for i := 0; i < len(n.Children); i++ {
 46		v := n.Children[i]
 47		tc := c.Transform(v)
 48		n = *tc.Parent
 49		n.Children[i] = tc
 50	}
 51
 52	return n
 53}
 54
 55func (c *CSS) StyleSheet(path string) {
 56	// Parse the CSS file
 57	dat, err := os.ReadFile(path)
 58	utils.Check(err)
 59	styles := parser.ParseCSS(string(dat))
 60
 61	c.StyleSheets = append(c.StyleSheets, styles)
 62}
 63
 64func (c *CSS) StyleTag(css string) {
 65	styles := parser.ParseCSS(css)
 66	c.StyleSheets = append(c.StyleSheets, styles)
 67}
 68
 69var inheritedProps = []string{
 70	"color",
 71	"cursor",
 72	"font",
 73	"font-family",
 74	"font-size",
 75	"font-style",
 76	"font-weight",
 77	"letter-spacing",
 78	"line-height",
 79	// "text-align",
 80	"text-indent",
 81	"text-justify",
 82	"text-shadow",
 83	"text-transform",
 84	"text-decoration",
 85	"visibility",
 86	"word-spacing",
 87	"display",
 88}
 89
 90func (c *CSS) GetStyles(n element.Node) map[string]string {
 91	styles := map[string]string{}
 92
 93	if n.Parent != nil {
 94		ps := c.GetStyles(*n.Parent)
 95		for _, v := range inheritedProps {
 96			if ps[v] != "" {
 97				styles[v] = ps[v]
 98			}
 99		}
100	}
101	for k, v := range n.Style {
102		styles[k] = v
103	}
104	hovered := false
105	if slices.Contains(n.ClassList.Classes, ":hover") {
106		hovered = true
107	}
108
109	for _, styleSheet := range c.StyleSheets {
110		for selector := range styleSheet {
111			// fmt.Println(selector, n.Properties.Id)
112			key := selector
113			if strings.Contains(selector, ":hover") && hovered {
114				selector = strings.Replace(selector, ":hover", "", -1)
115			}
116			if element.TestSelector(selector, &n) {
117				for k, v := range styleSheet[key] {
118					styles[k] = v
119				}
120			}
121
122		}
123	}
124
125	// This is different than node.Style
126	// temp1 = <span style=​"color:​#a6e22e">​CSS​</span>​
127	// temp1.style == CSSStyleDeclaration {0: 'color', accentColor: '', additiveSymbols: '', alignContent: '', alignItems: '', alignSelf: '', …}
128	// temp1.getAttribute("style") == 'color:#a6e22e'
129	inline := parser.ParseStyleAttribute(n.GetAttribute("style") + ";")
130	styles = utils.Merge(styles, inline)
131	// add hover and focus css events
132
133	if n.Parent != nil {
134		if styles["z-index"] == "" && n.Parent.Style["z-index"] != "" {
135			z, _ := strconv.Atoi(n.Parent.Style["z-index"])
136			z += 1
137			styles["z-index"] = strconv.Itoa(z)
138		}
139	}
140
141	return styles
142}
143
144func (c *CSS) AddPlugin(plugin Plugin) {
145	c.Plugins = append(c.Plugins, plugin)
146}
147
148func (c *CSS) AddTransformer(transformer Transformer) {
149	c.Transformers = append(c.Transformers, transformer)
150}
151
152func CheckNode(n *element.Node, state *map[string]element.State) {
153	s := *state
154	self := s[n.Properties.Id]
155
156	fmt.Println(n.TagName, n.Properties.Id)
157	fmt.Printf("ID: %v\n", n.Id)
158	fmt.Printf("EM: %v\n", self.EM)
159	fmt.Printf("Parent: %v\n", n.Parent.TagName)
160	fmt.Printf("Classes: %v\n", n.ClassList.Classes)
161	fmt.Printf("Text: %v\n", n.InnerText)
162	fmt.Printf("X: %v, Y: %v, Z: %v\n", self.X, self.Y, self.Z)
163	fmt.Printf("Width: %v, Height: %v\n", self.Width, self.Height)
164	fmt.Printf("Styles: %v\n", n.Style)
165	fmt.Printf("Background: %v\n", self.Background)
166	fmt.Printf("Border: %v\n\n\n", self.Border)
167}
168
169func (c *CSS) ComputeNodeStyle(n *element.Node, state *map[string]element.State) *element.Node {
170
171	// Head is not renderable
172	if utils.IsParent(*n, "head") {
173		return n
174	}
175
176	plugins := c.Plugins
177
178	s := *state
179	self := s[n.Properties.Id]
180	parent := s[n.Parent.Properties.Id]
181
182	self.Background = color.Parse(n.Style, "background")
183	self.Border, _ = CompleteBorder(n.Style, self, parent)
184
185	fs, _ := utils.ConvertToPixels(n.Style["font-size"], parent.EM, parent.Width)
186	self.EM = fs
187
188	if n.Style["display"] == "none" {
189		self.X = 0
190		self.Y = 0
191		self.Width = 0
192		self.Height = 0
193		return n
194	}
195
196	if n.Style["width"] == "" && n.Style["display"] == "block" {
197		n.Style["width"] = "100%"
198	}
199
200	// Set Z index value to be sorted in window
201	if n.Style["z-index"] != "" {
202		z, _ := strconv.Atoi(n.Style["z-index"])
203		self.Z = float32(z)
204	}
205
206	if parent.Z > 0 {
207		self.Z = parent.Z + 1
208	}
209
210	(*state)[n.Properties.Id] = self
211
212	wh := utils.GetWH(*n, state)
213	width := wh.Width
214	height := wh.Height
215
216	x, y := parent.X, parent.Y
217	// !NOTE: Would like to consolidate all XY function into this function like WH
218	offsetX, offsetY := utils.GetXY(n, state)
219	x += offsetX
220	y += offsetY
221
222	var top, left, right, bottom bool = false, false, false, false
223
224	m := utils.GetMP(*n, wh, state, "margin")
225	p := utils.GetMP(*n, wh, state, "padding")
226
227	self.Margin = m
228	self.Padding = p
229
230	if n.Style["position"] == "absolute" {
231		bas := utils.GetPositionOffsetNode(n)
232		base := s[bas.Properties.Id]
233		if n.Style["top"] != "" {
234			v, _ := utils.ConvertToPixels(n.Style["top"], self.EM, parent.Width)
235			y = v + base.Y
236			top = true
237		}
238		if n.Style["left"] != "" {
239			v, _ := utils.ConvertToPixels(n.Style["left"], self.EM, parent.Width)
240			x = v + base.X
241			left = true
242		}
243		if n.Style["right"] != "" {
244			v, _ := utils.ConvertToPixels(n.Style["right"], self.EM, parent.Width)
245			x = (base.Width - width) - v
246			right = true
247		}
248		if n.Style["bottom"] != "" {
249			v, _ := utils.ConvertToPixels(n.Style["bottom"], self.EM, parent.Width)
250			y = (base.Height - height) - v
251			bottom = true
252		}
253
254	} else {
255		for i, v := range n.Parent.Children {
256			if v.Style["position"] != "absolute" {
257				if v.Properties.Id == n.Properties.Id {
258					if i-1 > 0 {
259						sib := n.Parent.Children[i-1]
260						sibling := s[sib.Properties.Id]
261						if sib.Style["position"] != "absolute" {
262							if n.Style["display"] == "inline" {
263								if sib.Style["display"] == "inline" {
264									y = sibling.Y
265								} else {
266									y = sibling.Y + sibling.Height
267								}
268							} else {
269								y = sibling.Y + sibling.Height + (sibling.Border.Width * 2) + sibling.Margin.Bottom
270							}
271						}
272
273					}
274					break
275				} else if n.Style["display"] != "inline" {
276					vState := s[v.Properties.Id]
277					y += vState.Margin.Top + vState.Margin.Bottom + vState.Padding.Top + vState.Padding.Bottom + vState.Height + (self.Border.Width)
278				}
279			}
280		}
281	}
282
283	// Display modes need to be calculated here
284
285	relPos := !top && !left && !right && !bottom
286
287	if left || relPos {
288		x += m.Left
289	}
290	if top || relPos {
291		y += m.Top
292	}
293	if right {
294		x -= m.Right
295	}
296	if bottom {
297		y -= m.Bottom
298	}
299
300	self.X = x
301	self.Y = y
302	self.Width = width
303	self.Height = height
304	(*state)[n.Properties.Id] = self
305
306	if !utils.ChildrenHaveText(n) && len(n.InnerText) > 0 {
307		// Confirm text exists
308		if len(strings.TrimSpace(n.InnerText)) > 0 {
309			n.InnerText = strings.TrimSpace(n.InnerText)
310			self = genTextNode(n, state)
311		}
312	}
313
314	(*state)[n.Properties.Id] = self
315	(*state)[n.Parent.Properties.Id] = parent
316
317	// Call children here
318
319	var childYOffset float32
320	for i := 0; i < len(n.Children); i++ {
321		v := n.Children[i]
322		v.Parent = n
323		// This is were the tainting comes from
324		n.Children[i] = *c.ComputeNodeStyle(&v, state)
325
326		cState := (*state)[n.Children[i].Properties.Id]
327		if n.Style["height"] == "" {
328			if v.Style["position"] != "absolute" && cState.Y+cState.Height > childYOffset {
329				childYOffset = cState.Y + cState.Height
330				self.Height = (cState.Y - self.Border.Width) - (self.Y) + cState.Height
331				self.Height += cState.Margin.Top
332				self.Height += cState.Margin.Bottom
333				self.Height += cState.Padding.Top
334				self.Height += cState.Padding.Bottom
335			}
336		}
337		if cState.Width > self.Width {
338			self.Width = cState.Width
339		}
340	}
341
342	self.Height += self.Padding.Bottom
343
344	(*state)[n.Properties.Id] = self
345
346	// Sorting the array by the Level field
347	sort.Slice(plugins, func(i, j int) bool {
348		return plugins[i].Level < plugins[j].Level
349	})
350
351	for _, v := range plugins {
352		matches := true
353		for name, value := range v.Styles {
354			if n.Style[name] != value && !(value == "*") && n.Style[name] != "" {
355				matches = false
356			}
357		}
358		if matches {
359			v.Handler(n, state)
360		}
361	}
362
363	// CheckNode(n, state)
364
365	return n
366}
367
368func CompleteBorder(cssProperties map[string]string, self, parent element.State) (element.Border, error) {
369	// Split the shorthand into components
370	borderComponents := strings.Fields(cssProperties["border"])
371
372	// Ensure there are at least 1 component (width or style or color)
373	if len(borderComponents) >= 1 {
374		width := "0px" // Default width
375		style := "solid"
376		borderColor := "#000000" // Default color
377
378		// Extract style and color if available
379		if len(borderComponents) >= 1 {
380			width = borderComponents[0]
381		}
382
383		// Extract style and color if available
384		if len(borderComponents) >= 2 {
385			style = borderComponents[1]
386		}
387		if len(borderComponents) >= 3 {
388			borderColor = borderComponents[2]
389		}
390
391		parsedColor, _ := color.Color(borderColor)
392
393		w, _ := utils.ConvertToPixels(width, self.EM, parent.Width)
394
395		return element.Border{
396			Width:  w,
397			Style:  style,
398			Color:  parsedColor,
399			Radius: cssProperties["border-radius"],
400		}, nil
401	}
402
403	return element.Border{}, fmt.Errorf("invalid border shorthand format")
404}
405
406func genTextNode(n *element.Node, state *map[string]element.State) element.State {
407	s := *state
408	self := s[n.Properties.Id]
409	parent := s[n.Parent.Properties.Id]
410
411	text := element.Text{}
412
413	bold, italic := false, false
414
415	if n.Style["font-weight"] == "bold" {
416		bold = true
417	}
418
419	if n.Style["font-style"] == "italic" {
420		italic = true
421	}
422
423	if text.Font == nil {
424		f, _ := font.LoadFont(n.Style["font-family"], int(self.EM), bold, italic)
425		text.Font = f
426	}
427
428	letterSpacing, _ := utils.ConvertToPixels(n.Style["letter-spacing"], self.EM, parent.Width)
429	wordSpacing, _ := utils.ConvertToPixels(n.Style["word-spacing"], self.EM, parent.Width)
430	lineHeight, _ := utils.ConvertToPixels(n.Style["line-height"], self.EM, parent.Width)
431	if lineHeight == 0 {
432		lineHeight = self.EM + 3
433	}
434
435	text.LineHeight = int(lineHeight)
436	text.WordSpacing = int(wordSpacing)
437	text.LetterSpacing = int(letterSpacing)
438	wb := " "
439
440	if n.Style["word-wrap"] == "break-word" {
441		wb = ""
442	}
443
444	if n.Style["text-wrap"] == "wrap" || n.Style["text-wrap"] == "balance" {
445		wb = ""
446	}
447
448	var dt float32
449
450	if n.Style["text-decoration-thickness"] == "auto" || n.Style["text-decoration-thickness"] == "" {
451		dt = self.EM / 7
452	} else {
453		dt, _ = utils.ConvertToPixels(n.Style["text-decoration-thickness"], self.EM, parent.Width)
454	}
455
456	col := color.Parse(n.Style, "font")
457
458	self.Color = col
459
460	text.Color = col
461	text.DecorationColor = color.Parse(n.Style, "decoration")
462	text.Align = n.Style["text-align"]
463	text.WordBreak = wb
464	text.WordSpacing = int(wordSpacing)
465	text.LetterSpacing = int(letterSpacing)
466	text.WhiteSpace = n.Style["white-space"]
467	text.DecorationThickness = int(dt)
468	text.Overlined = n.Style["text-decoration"] == "overline"
469	text.Underlined = n.Style["text-decoration"] == "underline"
470	text.LineThrough = n.Style["text-decoration"] == "linethrough"
471	text.EM = int(self.EM)
472	text.Width = int(parent.Width)
473	text.Text = n.InnerText
474
475	if n.Style["word-spacing"] == "" {
476		text.WordSpacing = font.MeasureSpace(&text)
477	}
478
479	img, width := font.Render(&text)
480	self.Texture = img
481
482	if n.Style["height"] == "" {
483		self.Height = float32(text.LineHeight)
484	}
485
486	if n.Style["width"] == "" {
487		self.Width = float32(width)
488	}
489
490	return self
491}