Datasets:
Upload 6 files
Browse files- scripts/1_get_evalutation.py +220 -0
- scripts/2_compute_alisa_scores.py +93 -0
- scripts/js/codeSim.js +627 -0
- scripts/js/computeQuality.js +183 -0
- scripts/js/one-color-all.js +2 -0
- scripts/js/vue.global.js +0 -0
scripts/1_get_evalutation.py
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# %%
|
| 2 |
+
import os
|
| 3 |
+
import sys
|
| 4 |
+
import json
|
| 5 |
+
import time
|
| 6 |
+
import asyncio
|
| 7 |
+
import logging
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
from tqdm.asyncio import tqdm
|
| 10 |
+
from argparse import ArgumentParser
|
| 11 |
+
from playwright.async_api import async_playwright
|
| 12 |
+
|
| 13 |
+
cmd_args = True
|
| 14 |
+
parser = ArgumentParser()
|
| 15 |
+
parser.add_argument('--test_dir', default='./test_webpages', help='the directory of test webpages.')
|
| 16 |
+
parser.add_argument('--inference_dir', default='./inference', help='the directory of model output webpages.')
|
| 17 |
+
parser.add_argument('--save_dir', default='./save_results', help='the directory for saving result info jsonl file.')
|
| 18 |
+
parser.add_argument('--model_name', default="Qwen2.5-VL-32B-Instruct", help='using the vlms for your inference')
|
| 19 |
+
parser.add_argument('--num_workers', default=50, help='num workers for computing')
|
| 20 |
+
parser.add_argument('--log_dir', default='./', help='num workers for computing')
|
| 21 |
+
if not cmd_args:
|
| 22 |
+
args = parser.parse_args([]) # You can directly set above parameters in the default.
|
| 23 |
+
else:
|
| 24 |
+
args = parser.parse_args()
|
| 25 |
+
|
| 26 |
+
MODEL_NAME = os.path.basename(args.model_name)
|
| 27 |
+
LOG_PATH = os.path.join(args.log_dir, f'get_evaluation_{MODEL_NAME}.log')
|
| 28 |
+
INFERENCE_DIR = args.inference_dir
|
| 29 |
+
ORI_DIR = args.test_dir
|
| 30 |
+
SAVE_PATH = os.path.join(args.save_dir, {MODEL_NAME}.jsonl)
|
| 31 |
+
|
| 32 |
+
# 启动时预加载一次
|
| 33 |
+
with open("./scripts/js/vue.global.js", "r", encoding="utf-8") as f:
|
| 34 |
+
vue_code = f.read()
|
| 35 |
+
with open("./scripts/js/one-color-all.js", "r", encoding="utf-8") as f:
|
| 36 |
+
one_color_code = f.read()
|
| 37 |
+
with open("./scripts/js/codeSim.js", "r", encoding="utf-8") as f:
|
| 38 |
+
codesim_code = f.read()
|
| 39 |
+
|
| 40 |
+
# Worker数量
|
| 41 |
+
NUM_WORKERS = args.num_workers
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def setup_logger(is_console_handler=True):
|
| 45 |
+
logger = logging.getLogger('web_scraping')
|
| 46 |
+
logger.setLevel(logging.INFO)
|
| 47 |
+
|
| 48 |
+
file_handler = logging.FileHandler(LOG_PATH)
|
| 49 |
+
file_handler.setLevel(logging.INFO)
|
| 50 |
+
|
| 51 |
+
if is_console_handler:
|
| 52 |
+
console_handler = logging.StreamHandler(sys.stdout)
|
| 53 |
+
console_handler.setLevel(logging.INFO)
|
| 54 |
+
|
| 55 |
+
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s',
|
| 56 |
+
datefmt='%Y-%m-%d %H:%M:%S')
|
| 57 |
+
file_handler.setFormatter(formatter)
|
| 58 |
+
if is_console_handler:
|
| 59 |
+
console_handler.setFormatter(formatter)
|
| 60 |
+
|
| 61 |
+
logger.addHandler(file_handler)
|
| 62 |
+
if is_console_handler:
|
| 63 |
+
logger.addHandler(console_handler)
|
| 64 |
+
|
| 65 |
+
return logger
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
cache = []
|
| 69 |
+
file_lock = asyncio.Lock()
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
async def save_result(name, layoutSim, styleSim, force=False):
|
| 73 |
+
if force:
|
| 74 |
+
async with file_lock:
|
| 75 |
+
with open(SAVE_PATH, 'a') as f:
|
| 76 |
+
for c in cache:
|
| 77 |
+
f.write(json.dumps(c) + '\n')
|
| 78 |
+
cache.clear()
|
| 79 |
+
return 0
|
| 80 |
+
save_item = {
|
| 81 |
+
'name': name,
|
| 82 |
+
'groupLayoutScore': layoutSim['groupLayoutScore'],
|
| 83 |
+
'overallScore': layoutSim['overallScore'],
|
| 84 |
+
'relativeLayoutScore': layoutSim['relativeLayoutScore'],
|
| 85 |
+
'relativeStyleScore': styleSim['relativeStyleScore']
|
| 86 |
+
}
|
| 87 |
+
cache.append(save_item)
|
| 88 |
+
if len(cache) >= NUM_WORKERS:
|
| 89 |
+
async with file_lock:
|
| 90 |
+
with open(SAVE_PATH, 'a') as f:
|
| 91 |
+
for c in cache:
|
| 92 |
+
f.write(json.dumps(c) + '\n')
|
| 93 |
+
cache.clear()
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
async def worker(name, queue, browser, logger, pbar):
|
| 97 |
+
while not queue.empty():
|
| 98 |
+
html_item = await queue.get()
|
| 99 |
+
name = os.path.splitext(html_item)[0]
|
| 100 |
+
source_html_path = os.path.join(INFERENCE_DIR, f"{name}.html")
|
| 101 |
+
target_html_path = os.path.join(ORI_DIR, name, "index.html")
|
| 102 |
+
if not os.path.exists(source_html_path):
|
| 103 |
+
logger.error(f"❌ File not Exsits: {source_html_path}")
|
| 104 |
+
queue.task_done()
|
| 105 |
+
pbar.update(1)
|
| 106 |
+
continue
|
| 107 |
+
if not os.path.exists(target_html_path):
|
| 108 |
+
logger.error(f"❌ File not Exsits: {target_html_path}")
|
| 109 |
+
queue.task_done()
|
| 110 |
+
pbar.update(1)
|
| 111 |
+
continue
|
| 112 |
+
logger.info(
|
| 113 |
+
f"⭐ push {source_html_path}")
|
| 114 |
+
file_url = Path(source_html_path).as_uri()
|
| 115 |
+
|
| 116 |
+
start_time = time.perf_counter()
|
| 117 |
+
page = await browser.new_page(viewport={'width': 1920, 'height': 1080})
|
| 118 |
+
try:
|
| 119 |
+
try:
|
| 120 |
+
await page.goto(
|
| 121 |
+
file_url,
|
| 122 |
+
timeout=10000,
|
| 123 |
+
wait_until='domcontentloaded'
|
| 124 |
+
)
|
| 125 |
+
except Exception as e:
|
| 126 |
+
logger.error(f"⚠ Loading: {file_url}, Error: {e}")
|
| 127 |
+
await page.add_script_tag(content=vue_code)
|
| 128 |
+
await page.add_script_tag(content=one_color_code)
|
| 129 |
+
await page.add_script_tag(content=codesim_code)
|
| 130 |
+
sources = await page.evaluate("() => getElements()")
|
| 131 |
+
elapsed = time.perf_counter() - start_time
|
| 132 |
+
logger.info(
|
| 133 |
+
f"✅ Source computed complete {source_html_path}, element count: {len(sources)} time: {elapsed:.2f}")
|
| 134 |
+
except Exception as e:
|
| 135 |
+
logger.error(f"❌ Source computed failed: {source_html_path}, Error: {e}")
|
| 136 |
+
finally:
|
| 137 |
+
await page.close()
|
| 138 |
+
|
| 139 |
+
file_url = Path(target_html_path).as_uri()
|
| 140 |
+
sec_start_time = time.perf_counter()
|
| 141 |
+
page = await browser.new_page(viewport={'width': 1920, 'height': 1080})
|
| 142 |
+
# Listen console
|
| 143 |
+
# page.on("console", lambda msg: print(f"Console: {msg.type} - {msg.text}"))
|
| 144 |
+
try:
|
| 145 |
+
try:
|
| 146 |
+
await page.goto(
|
| 147 |
+
file_url,
|
| 148 |
+
timeout=3000,
|
| 149 |
+
wait_until='domcontentloaded'
|
| 150 |
+
)
|
| 151 |
+
except Exception as e:
|
| 152 |
+
logger.error(f"⚠ Loading: {file_url}, Error: {e}")
|
| 153 |
+
await page.add_script_tag(content=vue_code)
|
| 154 |
+
await page.add_script_tag(content=one_color_code)
|
| 155 |
+
await page.add_script_tag(content=codesim_code)
|
| 156 |
+
await page.evaluate("() => targetEls.value = getElements(false)")
|
| 157 |
+
layoutSim = await page.evaluate("(sources) => getLayoutSim(sources)", sources)
|
| 158 |
+
styleSim = await page.evaluate("(sources) => getStyleSim(sources)", sources)
|
| 159 |
+
await save_result(name, layoutSim, styleSim)
|
| 160 |
+
elapsed_total = time.perf_counter() - start_time
|
| 161 |
+
elapsed = time.perf_counter() - sec_start_time
|
| 162 |
+
logger.info(
|
| 163 |
+
f"✅ Target computed complete {target_html_path}, layoutSim: {layoutSim['overallScore']}, styleSim: {styleSim['relativeStyleScore']}, element_count: {len(sources)} time: {elapsed:.2f} total_time: {elapsed_total:.2f}")
|
| 164 |
+
except Exception as e:
|
| 165 |
+
logger.error(f"❌ Target computed failed: {target_html_path}, Error: {e}")
|
| 166 |
+
finally:
|
| 167 |
+
await page.close()
|
| 168 |
+
queue.task_done()
|
| 169 |
+
pbar.update(1)
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
async def main():
|
| 173 |
+
# Construct Task Queue
|
| 174 |
+
logger = setup_logger(False)
|
| 175 |
+
source_list = os.listdir(INFERENCE_DIR)
|
| 176 |
+
|
| 177 |
+
len_total = len(source_list)
|
| 178 |
+
print('Total: ', len_total)
|
| 179 |
+
exists_meta = []
|
| 180 |
+
if os.path.exists(SAVE_PATH):
|
| 181 |
+
with open(SAVE_PATH) as f:
|
| 182 |
+
exists_data = f.readlines()
|
| 183 |
+
exists_data = [json.loads(item) for item in exists_data]
|
| 184 |
+
for meta_info in exists_data:
|
| 185 |
+
name = meta_info.get("name", 'none')
|
| 186 |
+
exists_meta.append(name + '.html')
|
| 187 |
+
|
| 188 |
+
exists_meta = set(exists_meta)
|
| 189 |
+
source_list = [h for h in source_list if h not in exists_meta]
|
| 190 |
+
print(
|
| 191 |
+
f"Found: {len(exists_meta)} Matched: {len_total - len(source_list)} Remain: {len(source_list)}")
|
| 192 |
+
|
| 193 |
+
# random.shuffle(source_list)
|
| 194 |
+
queue = asyncio.Queue()
|
| 195 |
+
for html_item in source_list:
|
| 196 |
+
await queue.put(html_item)
|
| 197 |
+
|
| 198 |
+
async with async_playwright() as p:
|
| 199 |
+
browser_list = []
|
| 200 |
+
for i in range(NUM_WORKERS):
|
| 201 |
+
browser = await p.chromium.launch(headless=True, args=['--no-sandbox', '--disable-setuid-sandbox'])
|
| 202 |
+
browser_list.append(browser)
|
| 203 |
+
print('Browser Started')
|
| 204 |
+
with tqdm(total=len(source_list), desc="Progress") as pbar:
|
| 205 |
+
tasks = []
|
| 206 |
+
for i in range(NUM_WORKERS):
|
| 207 |
+
browser = browser_list[i % len(browser_list)]
|
| 208 |
+
tasks.append(asyncio.create_task(
|
| 209 |
+
worker(f"worker-{i}", queue, browser, logger, pbar)))
|
| 210 |
+
await queue.join()
|
| 211 |
+
for t in tasks:
|
| 212 |
+
t.cancel()
|
| 213 |
+
for browser in browser_list:
|
| 214 |
+
await browser.close()
|
| 215 |
+
save_result(None, None, None, True)
|
| 216 |
+
|
| 217 |
+
if __name__ == "__main__":
|
| 218 |
+
asyncio.run(main())
|
| 219 |
+
|
| 220 |
+
# await main()
|
scripts/2_compute_alisa_scores.py
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# %%
|
| 2 |
+
import os
|
| 3 |
+
import json
|
| 4 |
+
import numpy as np
|
| 5 |
+
from tqdm import tqdm
|
| 6 |
+
from copy import deepcopy
|
| 7 |
+
from argparse import ArgumentParser
|
| 8 |
+
|
| 9 |
+
cmd_args = True
|
| 10 |
+
parser = ArgumentParser()
|
| 11 |
+
parser.add_argument('--test_dir', default='./test_webpages', help='the directory of test webpages.')
|
| 12 |
+
parser.add_argument('--save_dir', default='./save_results', help='the directory for saving result info jsonl file.')
|
| 13 |
+
parser.add_argument('--model_name', default="Qwen2.5-VL-32B-Instruct", help='using the vlms for your inference')
|
| 14 |
+
|
| 15 |
+
if not cmd_args:
|
| 16 |
+
args = parser.parse_args([]) # You can directly set above parameters in the default.
|
| 17 |
+
else:
|
| 18 |
+
args = parser.parse_args()
|
| 19 |
+
|
| 20 |
+
MODEL_NAME = args.model_name
|
| 21 |
+
|
| 22 |
+
save_path = os.path.join(args.save_dir, f'{MODEL_NAME}.jsonl')
|
| 23 |
+
data_info = args.test_dir
|
| 24 |
+
|
| 25 |
+
with open(data_info) as f:
|
| 26 |
+
data_info_list = f.readlines()
|
| 27 |
+
data_info_list = [json.loads(item) for item in data_info_list]
|
| 28 |
+
data_info_dict = {
|
| 29 |
+
item['name']: item for item in data_info_list
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
result_sample = {
|
| 33 |
+
'groupLayoutScore': [],
|
| 34 |
+
'overallScore': [],
|
| 35 |
+
'relativeLayoutScore': [],
|
| 36 |
+
'relativeStyleScore': []
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
ranges_count = [0, 50, 100, 150, 200, 400]
|
| 40 |
+
# ranges_count = [0, 200, 400]
|
| 41 |
+
|
| 42 |
+
ranges = {
|
| 43 |
+
key: {
|
| 44 |
+
'data': deepcopy(result_sample),
|
| 45 |
+
'industries': {}
|
| 46 |
+
} for key in ranges_count
|
| 47 |
+
}
|
| 48 |
+
industries = {}
|
| 49 |
+
|
| 50 |
+
with open(save_path) as f:
|
| 51 |
+
ori_data = f.readlines()
|
| 52 |
+
|
| 53 |
+
result = deepcopy(result_sample)
|
| 54 |
+
|
| 55 |
+
ori_data = [json.loads(item) for item in ori_data]
|
| 56 |
+
for item in tqdm(ori_data):
|
| 57 |
+
if item['name'] not in data_info_dict:
|
| 58 |
+
continue
|
| 59 |
+
data_info = data_info_dict[item['name']]
|
| 60 |
+
element_count = data_info.get('element_count', 0)
|
| 61 |
+
for key in result:
|
| 62 |
+
if str(item[key]) == 'nan' or item[key] < 0:
|
| 63 |
+
continue
|
| 64 |
+
result[key].append(item[key])
|
| 65 |
+
|
| 66 |
+
append_key = None
|
| 67 |
+
for range_key in ranges:
|
| 68 |
+
if element_count > range_key:
|
| 69 |
+
append_key = range_key
|
| 70 |
+
ranges[append_key]['data'][key].append(item[key])
|
| 71 |
+
industry = data_info['industry']
|
| 72 |
+
if industry not in ranges[append_key]['industries']:
|
| 73 |
+
ranges[append_key]['industries'][industry] = deepcopy(result_sample)
|
| 74 |
+
ranges[append_key]['industries'][industry][key].append(item[key])
|
| 75 |
+
if industry not in industries:
|
| 76 |
+
industries[industry] = deepcopy(result_sample)
|
| 77 |
+
industries[industry][key].append(item[key])
|
| 78 |
+
|
| 79 |
+
for key in result:
|
| 80 |
+
print(key, np.mean(result[key]))
|
| 81 |
+
|
| 82 |
+
for key in ranges:
|
| 83 |
+
range_item = ranges[key]
|
| 84 |
+
data = range_item['data']
|
| 85 |
+
for metric_key in data:
|
| 86 |
+
print(f'{key} {metric_key} {np.mean(data[metric_key]):.2f}')
|
| 87 |
+
print('---')
|
| 88 |
+
|
| 89 |
+
for industry_key in industries:
|
| 90 |
+
idu_item = industries[industry_key]
|
| 91 |
+
for metric_key in idu_item:
|
| 92 |
+
print(f'{industry_key} {metric_key} {np.mean(idu_item[metric_key]):.2f}')
|
| 93 |
+
print('---')
|
scripts/js/codeSim.js
ADDED
|
@@ -0,0 +1,627 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const onecolor = one.color
|
| 2 |
+
const styleCheckList = Vue.ref({
|
| 3 |
+
isPosition: false,
|
| 4 |
+
isColor: true,
|
| 5 |
+
isFontSize: true,
|
| 6 |
+
isFontStyle: false,
|
| 7 |
+
isFontWeight: false,
|
| 8 |
+
isBackgroundColor: true,
|
| 9 |
+
isBorderRadius: true,
|
| 10 |
+
isBorderWidth: true,
|
| 11 |
+
isOpacity: false,
|
| 12 |
+
ignoreUnvisible: true
|
| 13 |
+
})
|
| 14 |
+
const maxElsLimit = Vue.ref(1500)
|
| 15 |
+
|
| 16 |
+
const sourceEls = Vue.ref([])
|
| 17 |
+
const targetEls = Vue.ref([])
|
| 18 |
+
const targetHaveAssEls = Vue.ref([])
|
| 19 |
+
const targetNoAssEls = Vue.ref([])
|
| 20 |
+
|
| 21 |
+
const getElements = (toPlaywright = true) => {
|
| 22 |
+
let toList = [];
|
| 23 |
+
const ref = document.body;
|
| 24 |
+
const parentWidth = ref.offsetWidth
|
| 25 |
+
const parentHeight = document.documentElement.clientHeight
|
| 26 |
+
const parentScrollHeight = ref.scrollHeight
|
| 27 |
+
let elements = [];
|
| 28 |
+
elements = document.querySelectorAll('body *')
|
| 29 |
+
toList.splice(0, toList.length);
|
| 30 |
+
for (let el of elements) {
|
| 31 |
+
if (['script'].includes(el.tagName.toLowerCase())) continue
|
| 32 |
+
if (isUnvisible(el)) continue
|
| 33 |
+
toList.push(el)
|
| 34 |
+
}
|
| 35 |
+
if (toList.length > maxElsLimit.value) {
|
| 36 |
+
toList = toList.slice(0, maxElsLimit.value)
|
| 37 |
+
}
|
| 38 |
+
toList.forEach((el) => {
|
| 39 |
+
let clientRect = el.getBoundingClientRect()
|
| 40 |
+
let pos = {
|
| 41 |
+
left: clientRect.left + scrollX,
|
| 42 |
+
right: clientRect.right + scrollX,
|
| 43 |
+
top: clientRect.top + scrollY,
|
| 44 |
+
bottom: clientRect.bottom + scrollY,
|
| 45 |
+
width: clientRect.width,
|
| 46 |
+
height: clientRect.height
|
| 47 |
+
}
|
| 48 |
+
const isFixedOrSticky = ['fixed', 'sticky'].includes(
|
| 49 |
+
getComputedStyle(el).position
|
| 50 |
+
)
|
| 51 |
+
if (isFixedOrSticky) {
|
| 52 |
+
pos.left = clientRect.left
|
| 53 |
+
pos.right = clientRect.right
|
| 54 |
+
pos.top = clientRect.top
|
| 55 |
+
pos.bottom = clientRect.bottom
|
| 56 |
+
}
|
| 57 |
+
let biasX = []
|
| 58 |
+
let biasY = []
|
| 59 |
+
if (pos.left < parentWidth / 2) biasX = ['left']
|
| 60 |
+
else biasX = ['right']
|
| 61 |
+
if (pos.left < parentWidth / 2 && pos.right > parentWidth / 2) biasX.push('mid')
|
| 62 |
+
|
| 63 |
+
if (pos.top < parentHeight / 2) biasY = ['top']
|
| 64 |
+
else if (pos.top > parentScrollHeight - parentHeight / 2) biasY = ['bottom']
|
| 65 |
+
else biasY = ['scroll']
|
| 66 |
+
if (pos.top < parentHeight / 2 && pos.bottom > parentHeight / 2 && isFixedOrSticky)
|
| 67 |
+
biasY.push('mid')
|
| 68 |
+
|
| 69 |
+
el.alisaInfo = {
|
| 70 |
+
elInfo: {
|
| 71 |
+
pos: pos,
|
| 72 |
+
biasX,
|
| 73 |
+
biasY
|
| 74 |
+
},
|
| 75 |
+
parentInfo: {
|
| 76 |
+
width: parentWidth,
|
| 77 |
+
height: parentHeight,
|
| 78 |
+
scrollHeight: parentScrollHeight
|
| 79 |
+
},
|
| 80 |
+
styles: getComputedStyle(el),
|
| 81 |
+
groupLeft: [],
|
| 82 |
+
groupRight: [],
|
| 83 |
+
groupTop: [],
|
| 84 |
+
groupBottom: [],
|
| 85 |
+
groupAxisWidth: [],
|
| 86 |
+
groupAxisHeight: [],
|
| 87 |
+
groupAll: [],
|
| 88 |
+
raceList: [],
|
| 89 |
+
assElement: null,
|
| 90 |
+
assLayoutSimScore: 0,
|
| 91 |
+
assStyleSimScore: 0
|
| 92 |
+
}
|
| 93 |
+
})
|
| 94 |
+
|
| 95 |
+
toList.forEach((el) => {
|
| 96 |
+
getSameGroup(el, toList, 'left')
|
| 97 |
+
getSameGroup(el, toList, 'right')
|
| 98 |
+
getSameGroup(el, toList, 'top')
|
| 99 |
+
getSameGroup(el, toList, 'bottom')
|
| 100 |
+
getSameGroup(el, toList, 'axisWidth')
|
| 101 |
+
getSameGroup(el, toList, 'axisHeight')
|
| 102 |
+
})
|
| 103 |
+
toList.forEach((el) => {
|
| 104 |
+
getSameRace(el, toList)
|
| 105 |
+
})
|
| 106 |
+
|
| 107 |
+
if (!toPlaywright) return toList;
|
| 108 |
+
|
| 109 |
+
let formatList = [];
|
| 110 |
+
toList.forEach((el, idx) => {
|
| 111 |
+
el._idx = idx;
|
| 112 |
+
let formatItem = {
|
| 113 |
+
idx: idx,
|
| 114 |
+
isAlisaObj: true,
|
| 115 |
+
tagName: el.tagName,
|
| 116 |
+
innerText: el.innerText ? el.innerText : false,
|
| 117 |
+
alisaInfo: {
|
| 118 |
+
...el.alisaInfo
|
| 119 |
+
}
|
| 120 |
+
}
|
| 121 |
+
formatList.push(formatItem)
|
| 122 |
+
})
|
| 123 |
+
|
| 124 |
+
formatList.forEach((el) => {
|
| 125 |
+
let decodeKeys = [
|
| 126 |
+
'groupLeft',
|
| 127 |
+
'groupRight',
|
| 128 |
+
'groupTop',
|
| 129 |
+
'groupBottom',
|
| 130 |
+
'groupAxisWidth',
|
| 131 |
+
'groupAxisHeight',
|
| 132 |
+
'groupAll',
|
| 133 |
+
'raceList'
|
| 134 |
+
]
|
| 135 |
+
for (let key of decodeKeys) {
|
| 136 |
+
let dl = []
|
| 137 |
+
for (let keyItem of el.alisaInfo[key]) {
|
| 138 |
+
dl.push(keyItem._idx)
|
| 139 |
+
}
|
| 140 |
+
el.alisaInfo[key] = dl;
|
| 141 |
+
}
|
| 142 |
+
})
|
| 143 |
+
|
| 144 |
+
return formatList;
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
const isUnvisible = (el) => {
|
| 148 |
+
const style = getComputedStyle(el);
|
| 149 |
+
const rect = el.getBoundingClientRect();
|
| 150 |
+
const hidden =
|
| 151 |
+
style.display === 'none' ||
|
| 152 |
+
style.visibility === 'hidden' ||
|
| 153 |
+
style.opacity === '0' || rect.width === 0 ||
|
| 154 |
+
rect.height === 0;
|
| 155 |
+
return hidden;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
const getSameGroup = (el, elList, direction, offset = 5) => {
|
| 159 |
+
let idx = elList.indexOf(el)
|
| 160 |
+
if (idx < 0) return
|
| 161 |
+
const Direction = direction.slice(0, 1).toUpperCase() + direction.slice(1)
|
| 162 |
+
const isSamePos = (direction, pos1, pos2, offset) => {
|
| 163 |
+
if (['left', 'top', 'right', 'bottom'].includes(direction))
|
| 164 |
+
if (Math.abs(pos1[direction] - pos2[direction]) <= offset) return true
|
| 165 |
+
if (direction == 'axisWidth')
|
| 166 |
+
if (Math.abs(pos1.width / 2 + pos1.left - pos2.width / 2 - pos2.left) <= offset)
|
| 167 |
+
return true
|
| 168 |
+
if (direction == 'axisHeight')
|
| 169 |
+
if (Math.abs(pos1.height / 2 + pos1.top - pos2.height / 2 - pos2.top) <= offset)
|
| 170 |
+
return true
|
| 171 |
+
return false
|
| 172 |
+
}
|
| 173 |
+
elList.forEach((element, i) => {
|
| 174 |
+
if (idx == i) return
|
| 175 |
+
if (
|
| 176 |
+
isSamePos(
|
| 177 |
+
direction,
|
| 178 |
+
el.alisaInfo.elInfo.pos,
|
| 179 |
+
element.alisaInfo.elInfo.pos,
|
| 180 |
+
offset
|
| 181 |
+
)
|
| 182 |
+
) {
|
| 183 |
+
el.alisaInfo[`group${Direction}`].push(element)
|
| 184 |
+
let itemIndex = el.alisaInfo.groupAll.indexOf(element)
|
| 185 |
+
if (itemIndex < 0) el.alisaInfo.groupAll.push(element)
|
| 186 |
+
}
|
| 187 |
+
})
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
const getSameRace = (el, elList) => {
|
| 191 |
+
let idx = elList.indexOf(el)
|
| 192 |
+
if (idx < 0) return
|
| 193 |
+
const isSameRace = (el1, el2) => {
|
| 194 |
+
const groupAll = el1.alisaInfo.groupAll
|
| 195 |
+
if (groupAll.indexOf(el2) < 0) return false
|
| 196 |
+
if (el1.tagName != el2.tagName) return false
|
| 197 |
+
return el1.className == el2.className
|
| 198 |
+
}
|
| 199 |
+
elList.forEach((element, i) => {
|
| 200 |
+
if (idx == i) return
|
| 201 |
+
if (isSameRace(el, element)) {
|
| 202 |
+
el.alisaInfo.raceList.push(element)
|
| 203 |
+
}
|
| 204 |
+
})
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
const getAllAssociated = (sources, offset = 5, callback = null) => {
|
| 208 |
+
let encodeKeys = [
|
| 209 |
+
'groupLeft',
|
| 210 |
+
'groupRight',
|
| 211 |
+
'groupTop',
|
| 212 |
+
'groupBottom',
|
| 213 |
+
'groupAxisWidth',
|
| 214 |
+
'groupAxisHeight',
|
| 215 |
+
'groupAll',
|
| 216 |
+
'raceList'
|
| 217 |
+
]
|
| 218 |
+
sources.forEach(el => {
|
| 219 |
+
for (let key of encodeKeys) {
|
| 220 |
+
let dl = []
|
| 221 |
+
for (let idx of el.alisaInfo[key]) {
|
| 222 |
+
dl.push(sources[idx])
|
| 223 |
+
}
|
| 224 |
+
el.alisaInfo[key] = dl;
|
| 225 |
+
}
|
| 226 |
+
});
|
| 227 |
+
sourceEls.value = sources;
|
| 228 |
+
targetHaveAssEls.value = [];
|
| 229 |
+
targetNoAssEls.value = [];
|
| 230 |
+
targetEls.value.forEach((el) => {
|
| 231 |
+
getElAssociated(el, sourceEls.value, offset, callback)
|
| 232 |
+
})
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
const getLayoutSim = (sources, offset = 5, callback = null) => {
|
| 236 |
+
getAllAssociated(sources, offset, callback);
|
| 237 |
+
let allTargetEls = targetEls.value
|
| 238 |
+
let viewedEls = []
|
| 239 |
+
let count = 0
|
| 240 |
+
allTargetEls.forEach((ei) => {
|
| 241 |
+
if (viewedEls.indexOf(ei) < 0) {
|
| 242 |
+
count += 1
|
| 243 |
+
viewedEls.push(ei)
|
| 244 |
+
ei.alisaInfo.raceList.forEach((ri) => {
|
| 245 |
+
viewedEls.push(ri)
|
| 246 |
+
})
|
| 247 |
+
}
|
| 248 |
+
})
|
| 249 |
+
let arraysEqual = (a, b) => {
|
| 250 |
+
if (!(Array.isArray(a) && Array.isArray(b))) return 'not equal'
|
| 251 |
+
let status = 'equal'
|
| 252 |
+
a.forEach((ai) => {
|
| 253 |
+
if (ai !== 'mid' && b.indexOf(ai) < 0) {
|
| 254 |
+
status = 'not equal'
|
| 255 |
+
return
|
| 256 |
+
}
|
| 257 |
+
if (ai === 'mid' && b.indexOf(ai) < 0) {
|
| 258 |
+
status = 'partial equal'
|
| 259 |
+
return
|
| 260 |
+
}
|
| 261 |
+
})
|
| 262 |
+
return status
|
| 263 |
+
}
|
| 264 |
+
let posDiff = (val1, val2, ref) => {
|
| 265 |
+
if (Math.abs(val1 - val2) / ref > 1) return 0
|
| 266 |
+
return 1 - Math.abs(val1 - val2) / ref
|
| 267 |
+
}
|
| 268 |
+
targetHaveAssEls.value.forEach((el) => {
|
| 269 |
+
let layoutWeight = 1 / (el.alisaInfo.raceList.length + 1) / count
|
| 270 |
+
let score = layoutWeight * 100
|
| 271 |
+
let assEl = el.alisaInfo.assElement
|
| 272 |
+
let halfWidth = el.alisaInfo.parentInfo.width / 2
|
| 273 |
+
let halfHeight = el.alisaInfo.parentInfo.height / 2
|
| 274 |
+
let biasXEqual = arraysEqual(
|
| 275 |
+
el.alisaInfo.elInfo.biasX,
|
| 276 |
+
assEl.alisaInfo.elInfo.biasX
|
| 277 |
+
)
|
| 278 |
+
let biasYEqual = arraysEqual(
|
| 279 |
+
el.alisaInfo.elInfo.biasY,
|
| 280 |
+
assEl.alisaInfo.elInfo.biasY
|
| 281 |
+
)
|
| 282 |
+
if (biasXEqual == 'not equal' || biasYEqual == 'not equal') score *= 0
|
| 283 |
+
if (biasXEqual == 'partial equal' || biasYEqual == 'partial equal') score *= 0.5
|
| 284 |
+
score =
|
| 285 |
+
score *
|
| 286 |
+
posDiff(
|
| 287 |
+
el.alisaInfo.elInfo.pos.left,
|
| 288 |
+
assEl.alisaInfo.elInfo.pos.left,
|
| 289 |
+
halfWidth
|
| 290 |
+
) *
|
| 291 |
+
posDiff(el.alisaInfo.elInfo.pos.top, assEl.alisaInfo.elInfo.pos.top, halfHeight)
|
| 292 |
+
el.alisaInfo.assLayoutSimScore = score
|
| 293 |
+
})
|
| 294 |
+
let relativeLayoutScore = 0
|
| 295 |
+
targetHaveAssEls.value.forEach((el) => {
|
| 296 |
+
relativeLayoutScore += el.alisaInfo.assLayoutSimScore
|
| 297 |
+
})
|
| 298 |
+
|
| 299 |
+
let misMatchedLength = 0
|
| 300 |
+
let matchedLength = 0
|
| 301 |
+
targetEls.value.forEach((targetEl) => {
|
| 302 |
+
let assEl = targetEl.alisaInfo.assElement
|
| 303 |
+
if (!assEl) return
|
| 304 |
+
let targetGroupAll = targetEl.alisaInfo.groupAll
|
| 305 |
+
let sourceGroupAll = assEl.alisaInfo.groupAll
|
| 306 |
+
targetGroupAll.forEach((gi) => {
|
| 307 |
+
if (!gi.alisaInfo.assElement) misMatchedLength += 1
|
| 308 |
+
else if (sourceGroupAll.indexOf(gi.alisaInfo.assElement) < 0)
|
| 309 |
+
misMatchedLength += 1
|
| 310 |
+
else matchedLength += 1
|
| 311 |
+
})
|
| 312 |
+
})
|
| 313 |
+
let groupLayoutScore = (matchedLength / (matchedLength + misMatchedLength)) * 100
|
| 314 |
+
|
| 315 |
+
if (misMatchedLength === 0 && matchedLength === 0) {
|
| 316 |
+
groupLayoutScore = 0
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
console.log(
|
| 320 |
+
relativeLayoutScore,
|
| 321 |
+
groupLayoutScore,
|
| 322 |
+
(relativeLayoutScore + groupLayoutScore) / 2
|
| 323 |
+
)
|
| 324 |
+
console.log(targetHaveAssEls.value)
|
| 325 |
+
console.log(targetNoAssEls.value)
|
| 326 |
+
|
| 327 |
+
return {
|
| 328 |
+
relativeLayoutScore,
|
| 329 |
+
groupLayoutScore,
|
| 330 |
+
targetHaveAssEls: targetHaveAssEls.value.length,
|
| 331 |
+
targetNoAssEls: targetNoAssEls.value.length,
|
| 332 |
+
overallScore: (relativeLayoutScore + groupLayoutScore) / 2
|
| 333 |
+
}
|
| 334 |
+
}
|
| 335 |
+
|
| 336 |
+
const getStyleSim = (sources, offset = 5, callback = null) => {
|
| 337 |
+
getAllAssociated(sources, offset, callback);
|
| 338 |
+
let allTargetEls = targetEls.value
|
| 339 |
+
let viewedEls = []
|
| 340 |
+
let count = 0
|
| 341 |
+
allTargetEls.forEach((ei) => {
|
| 342 |
+
if (viewedEls.indexOf(ei) < 0) {
|
| 343 |
+
count += 1
|
| 344 |
+
viewedEls.push(ei)
|
| 345 |
+
ei.alisaInfo.raceList.forEach((ri) => {
|
| 346 |
+
viewedEls.push(ri)
|
| 347 |
+
})
|
| 348 |
+
}
|
| 349 |
+
})
|
| 350 |
+
|
| 351 |
+
const DEFAULT_COLOR = 'rgba(0, 0, 0, 0)'
|
| 352 |
+
|
| 353 |
+
const getGradientColors = (gradientCSS) => {
|
| 354 |
+
const colorRegex = /rgba?\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*(,\s*\d?\.?\d+)?\s*\)/gi;
|
| 355 |
+
let colors = gradientCSS.match(colorRegex) || [];
|
| 356 |
+
if (colors.length === 0) return null;
|
| 357 |
+
// return avg. color if multiple colors found
|
| 358 |
+
const colorObjs = colors.map(color => onecolor(color));
|
| 359 |
+
let avgColor = { _red: 0, _green: 0, _blue: 0 };
|
| 360 |
+
for (let color of colorObjs) {
|
| 361 |
+
avgColor._red += color._red;
|
| 362 |
+
avgColor._green += color._green;
|
| 363 |
+
avgColor._blue += color._blue;
|
| 364 |
+
}
|
| 365 |
+
avgColor._red = Math.round(avgColor._red / colorObjs.length);
|
| 366 |
+
avgColor._green = Math.round(avgColor._green / colorObjs.length);
|
| 367 |
+
avgColor._blue = Math.round(avgColor._blue / colorObjs.length);
|
| 368 |
+
return avgColor;
|
| 369 |
+
}
|
| 370 |
+
|
| 371 |
+
const perceptualColorDistance = (c1, c2) => {
|
| 372 |
+
const rMean = (c1._red + c2._red) / 2;
|
| 373 |
+
const rDiff = c1._red - c2._red;
|
| 374 |
+
const gDiff = c1._green - c2._green;
|
| 375 |
+
const bDiff = c1._blue - c2._blue;
|
| 376 |
+
return Math.sqrt(
|
| 377 |
+
(2 + rMean / 256) * rDiff * rDiff +
|
| 378 |
+
4 * gDiff * gDiff +
|
| 379 |
+
(2 + (255 - rMean) / 256) * bDiff * bDiff
|
| 380 |
+
);
|
| 381 |
+
}
|
| 382 |
+
|
| 383 |
+
let computedStyles = (el) => {
|
| 384 |
+
return el.alisaInfo.styles;
|
| 385 |
+
}
|
| 386 |
+
|
| 387 |
+
let colorDiff = (tgt, src) => {
|
| 388 |
+
const color1 = onecolor(computedStyles(src).color || DEFAULT_COLOR)
|
| 389 |
+
const color2 = onecolor(computedStyles(tgt).color || DEFAULT_COLOR)
|
| 390 |
+
const colorDiff = perceptualColorDistance(color1, color2);
|
| 391 |
+
return 1 - colorDiff < 0 ? 0 : 1 - colorDiff;
|
| 392 |
+
}
|
| 393 |
+
|
| 394 |
+
let backgroundColorDiff = (tgt, src) => {
|
| 395 |
+
let imageColor1 = getGradientColors(computedStyles(src).backgroundImage)
|
| 396 |
+
let imageColor2 = getGradientColors(computedStyles(tgt).backgroundImage)
|
| 397 |
+
let colorDiff = 0;
|
| 398 |
+
if (imageColor1 || imageColor2) {
|
| 399 |
+
if (!imageColor1) imageColor1 = onecolor(DEFAULT_COLOR);
|
| 400 |
+
if (!imageColor2) imageColor2 = onecolor(DEFAULT_COLOR);
|
| 401 |
+
colorDiff = perceptualColorDistance(imageColor1, imageColor2);
|
| 402 |
+
}
|
| 403 |
+
else {
|
| 404 |
+
const color1 = onecolor(computedStyles(src).backgroundColor || DEFAULT_COLOR)
|
| 405 |
+
const color2 = onecolor(computedStyles(tgt).backgroundColor || DEFAULT_COLOR)
|
| 406 |
+
colorDiff = perceptualColorDistance(color1, color2);
|
| 407 |
+
}
|
| 408 |
+
return 1 - colorDiff < 0 ? 0 : 1 - colorDiff;
|
| 409 |
+
}
|
| 410 |
+
|
| 411 |
+
let fontSizeDiff = (tgt, src) => {
|
| 412 |
+
let size1 = computedStyles(src).fontSize;
|
| 413 |
+
let size2 = computedStyles(tgt).fontSize;
|
| 414 |
+
size1 = parseFloat(size1);
|
| 415 |
+
size2 = parseFloat(size2);
|
| 416 |
+
let sizeDiff = Math.abs(size1 - size2);
|
| 417 |
+
return 1 - sizeDiff / size2;
|
| 418 |
+
}
|
| 419 |
+
|
| 420 |
+
let fontWeightDiff = (tgt, src) => {
|
| 421 |
+
let fontWeight1 = computedStyles(src).fontWeight;
|
| 422 |
+
let fontWeight2 = computedStyles(tgt).fontWeight;
|
| 423 |
+
fontWeight1 = parseFloat(fontWeight1);
|
| 424 |
+
fontWeight2 = parseFloat(fontWeight2);
|
| 425 |
+
if (fontWeight1.toString() === 'NaN') fontWeight1 = 400;
|
| 426 |
+
if (fontWeight2.toString() === 'NaN') fontWeight2 = 400;
|
| 427 |
+
let sizeDiff = Math.abs(fontWeight1 - fontWeight2);
|
| 428 |
+
return 1 - sizeDiff / fontWeight2;
|
| 429 |
+
}
|
| 430 |
+
|
| 431 |
+
let positionDiff = (tgt, src) => {
|
| 432 |
+
let position1 = computedStyles(src).position;
|
| 433 |
+
let position2 = computedStyles(tgt).position;
|
| 434 |
+
return position1 == position2 ? 1 : 0;
|
| 435 |
+
}
|
| 436 |
+
|
| 437 |
+
let fontStyleDiff = (tgt, src) => {
|
| 438 |
+
let fontStyle1 = computedStyles(src).fontStyle;
|
| 439 |
+
let fontStyle2 = computedStyles(tgt).fontStyle;
|
| 440 |
+
return fontStyle1 == fontStyle2 ? 1 : 0;
|
| 441 |
+
}
|
| 442 |
+
|
| 443 |
+
let borderRadiusDiff = (tgt, src) => {
|
| 444 |
+
let topLeft1 = computedStyles(src).borderTopLeftRadius;
|
| 445 |
+
let topLeft2 = computedStyles(tgt).borderTopLeftRadius;
|
| 446 |
+
let topRight1 = computedStyles(src).borderTopRightRadius;
|
| 447 |
+
let topRight2 = computedStyles(tgt).borderTopRightRadius;
|
| 448 |
+
let bottomLeft1 = computedStyles(src).borderBottomLeftRadius;
|
| 449 |
+
let bottomLeft2 = computedStyles(tgt).borderBottomLeftRadius;
|
| 450 |
+
let bottomRight1 = computedStyles(src).borderBottomRightRadius;
|
| 451 |
+
let bottomRight2 = computedStyles(tgt).borderBottomRightRadius;
|
| 452 |
+
topLeft1 = parseFloat(topLeft1)
|
| 453 |
+
topLeft2 = parseFloat(topLeft2)
|
| 454 |
+
topRight1 = parseFloat(topRight1)
|
| 455 |
+
topRight2 = parseFloat(topRight2)
|
| 456 |
+
bottomLeft1 = parseFloat(bottomLeft1)
|
| 457 |
+
bottomLeft2 = parseFloat(bottomLeft2)
|
| 458 |
+
bottomRight1 = parseFloat(bottomRight1)
|
| 459 |
+
bottomRight2 = parseFloat(bottomRight2)
|
| 460 |
+
let topLeftDiff = Math.abs(topLeft1 - topLeft2);
|
| 461 |
+
let topRightDiff = Math.abs(topRight1 - topRight2);
|
| 462 |
+
let bottomLeftDiff = Math.abs(bottomLeft1 - bottomLeft2);
|
| 463 |
+
let bottomRightDiff = Math.abs(bottomRight1 - bottomRight2);
|
| 464 |
+
let targetRelative = tgt.alisaInfo.elInfo.pos.height;
|
| 465 |
+
targetRelative = targetRelative > tgt.alisaInfo.elInfo.pos.width ? tgt.alisaInfo.elInfo.pos.width / 2 : targetRelative / 2;
|
| 466 |
+
let avg = (topLeftDiff + topRightDiff + bottomLeftDiff + bottomRightDiff) / targetRelative;
|
| 467 |
+
avg = avg > 1 ? 1 : avg;
|
| 468 |
+
return 1 - avg;
|
| 469 |
+
}
|
| 470 |
+
|
| 471 |
+
let borderWidthDiff = (tgt, src) => {
|
| 472 |
+
let top1 = computedStyles(src).borderTopWidth;
|
| 473 |
+
let top2 = computedStyles(tgt).borderTopWidth;
|
| 474 |
+
let right1 = computedStyles(src).borderRightWidth;
|
| 475 |
+
let right2 = computedStyles(tgt).borderRightWidth;
|
| 476 |
+
let bottom1 = computedStyles(src).borderBottomWidth;
|
| 477 |
+
let bottom2 = computedStyles(tgt).borderBottomWidth;
|
| 478 |
+
let left1 = computedStyles(src).borderLeftWidth;
|
| 479 |
+
let left2 = computedStyles(tgt).borderLeftWidth;
|
| 480 |
+
top1 = parseFloat(top1)
|
| 481 |
+
top2 = parseFloat(top2)
|
| 482 |
+
right1 = parseFloat(right1)
|
| 483 |
+
right2 = parseFloat(right2)
|
| 484 |
+
bottom1 = parseFloat(bottom1)
|
| 485 |
+
bottom2 = parseFloat(bottom2)
|
| 486 |
+
left1 = parseFloat(left1)
|
| 487 |
+
left2 = parseFloat(left2)
|
| 488 |
+
let topDiff = Math.abs(top1 - top2);
|
| 489 |
+
let rightDiff = Math.abs(right1 - right2);
|
| 490 |
+
let bottomDiff = Math.abs(bottom1 - bottom2);
|
| 491 |
+
let leftDiff = Math.abs(left1 - left2);
|
| 492 |
+
let targetRelative = tgt.alisaInfo.elInfo.pos.height;
|
| 493 |
+
targetRelative = targetRelative > tgt.alisaInfo.elInfo.pos.width ? tgt.alisaInfo.elInfo.pos.width / 2 : targetRelative / 2;
|
| 494 |
+
let avg = (topDiff + rightDiff + bottomDiff + leftDiff) / targetRelative;
|
| 495 |
+
avg = avg > 1 ? 1 : avg;
|
| 496 |
+
return 1 - avg;
|
| 497 |
+
}
|
| 498 |
+
|
| 499 |
+
let opacityDiff = (tgt, src) => {
|
| 500 |
+
let opacity1 = computedStyles(src).opacity;
|
| 501 |
+
let opacity2 = computedStyles(tgt).opacity;
|
| 502 |
+
opacity1 = parseFloat(opacity1);
|
| 503 |
+
opacity2 = parseFloat(opacity2);
|
| 504 |
+
if (opacity1.toString() === 'NaN') opacity1 = 1;
|
| 505 |
+
if (opacity2.toString() === 'NaN') opacity2 = 1;
|
| 506 |
+
let sizeDiff = Math.abs(opacity1 - opacity2);
|
| 507 |
+
return 1 - sizeDiff / opacity2;
|
| 508 |
+
}
|
| 509 |
+
|
| 510 |
+
targetHaveAssEls.value.forEach((el) => {
|
| 511 |
+
let layoutWeight = 1 / (el.alisaInfo.raceList.length + 1) / count
|
| 512 |
+
let score = layoutWeight * 100
|
| 513 |
+
let unitScoreList = [];
|
| 514 |
+
let assEl = el.alisaInfo.assElement
|
| 515 |
+
if (styleCheckList.value.isPosition)
|
| 516 |
+
unitScoreList.push(positionDiff(el, assEl));
|
| 517 |
+
if (styleCheckList.value.isColor)
|
| 518 |
+
unitScoreList.push(colorDiff(el, assEl));
|
| 519 |
+
if (styleCheckList.value.isBackgroundColor)
|
| 520 |
+
unitScoreList.push(backgroundColorDiff(el, assEl));
|
| 521 |
+
if (styleCheckList.value.isFontSize)
|
| 522 |
+
unitScoreList.push(fontSizeDiff(el, assEl));
|
| 523 |
+
if (styleCheckList.value.isFontStyle)
|
| 524 |
+
unitScoreList.push(fontStyleDiff(el, assEl));
|
| 525 |
+
if (styleCheckList.value.isFontWeight)
|
| 526 |
+
unitScoreList.push(fontWeightDiff(el, assEl));
|
| 527 |
+
if (styleCheckList.value.isBorderRadius)
|
| 528 |
+
unitScoreList.push(borderRadiusDiff(el, assEl))
|
| 529 |
+
if (styleCheckList.value.isBorderWidth)
|
| 530 |
+
unitScoreList.push(borderWidthDiff(el, assEl))
|
| 531 |
+
if (styleCheckList.value.isOpacity)
|
| 532 |
+
unitScoreList.push(opacityDiff(el, assEl))
|
| 533 |
+
const sum = unitScoreList.reduce((acc, val) => acc + val, 0);
|
| 534 |
+
const avg = sum / unitScoreList.length;
|
| 535 |
+
el.alisaInfo.assStyleSimScore = score * avg;
|
| 536 |
+
})
|
| 537 |
+
|
| 538 |
+
let relativeStyleScore = 0
|
| 539 |
+
targetHaveAssEls.value.forEach((el) => {
|
| 540 |
+
relativeStyleScore += el.alisaInfo.assStyleSimScore
|
| 541 |
+
})
|
| 542 |
+
console.log(relativeStyleScore)
|
| 543 |
+
|
| 544 |
+
return {
|
| 545 |
+
relativeStyleScore
|
| 546 |
+
}
|
| 547 |
+
}
|
| 548 |
+
|
| 549 |
+
const getElAssociated = (targetEl, sourceElList, offset = 5, callBack = null) => {
|
| 550 |
+
let candidateList = [...sourceElList]
|
| 551 |
+
let sizeDiff = (source, target) => {
|
| 552 |
+
return (
|
| 553 |
+
Math.abs(
|
| 554 |
+
source.alisaInfo.elInfo.pos.width - target.alisaInfo.elInfo.pos.width
|
| 555 |
+
) +
|
| 556 |
+
Math.abs(
|
| 557 |
+
source.alisaInfo.elInfo.pos.height - target.alisaInfo.elInfo.pos.height
|
| 558 |
+
)
|
| 559 |
+
)
|
| 560 |
+
}
|
| 561 |
+
let posDiff = (source, target) => {
|
| 562 |
+
return Math.sqrt(
|
| 563 |
+
Math.pow(
|
| 564 |
+
target.alisaInfo.elInfo.pos.left - source.alisaInfo.elInfo.pos.left,
|
| 565 |
+
2
|
| 566 |
+
) +
|
| 567 |
+
Math.pow(
|
| 568 |
+
target.alisaInfo.elInfo.pos.top - source.alisaInfo.elInfo.pos.top,
|
| 569 |
+
2
|
| 570 |
+
)
|
| 571 |
+
)
|
| 572 |
+
}
|
| 573 |
+
candidateList.sort((a, b) => {
|
| 574 |
+
const aSizeDiff = sizeDiff(a, targetEl)
|
| 575 |
+
const bSizeDiff = sizeDiff(b, targetEl)
|
| 576 |
+
if (aSizeDiff == bSizeDiff) {
|
| 577 |
+
const aPosDiff = posDiff(a, targetEl)
|
| 578 |
+
const bPosDiff = posDiff(b, targetEl)
|
| 579 |
+
return aPosDiff - bPosDiff
|
| 580 |
+
}
|
| 581 |
+
return aSizeDiff - bSizeDiff
|
| 582 |
+
})
|
| 583 |
+
if (targetEl.innerText == '' || !targetEl.innerText) {
|
| 584 |
+
for (let item of candidateList) {
|
| 585 |
+
if (sizeDiff(item, targetEl) <= offset * 2) {
|
| 586 |
+
targetEl.alisaInfo.assElement = item
|
| 587 |
+
item.alisaInfo.assElement = targetEl
|
| 588 |
+
targetHaveAssEls.value.push(targetEl)
|
| 589 |
+
if (callBack)
|
| 590 |
+
callBack(targetEl, item)
|
| 591 |
+
return
|
| 592 |
+
}
|
| 593 |
+
}
|
| 594 |
+
} else {
|
| 595 |
+
for (let item of candidateList) {
|
| 596 |
+
if (LCSSim(item.innerText, targetEl.innerText) >= 0.8) {
|
| 597 |
+
targetEl.alisaInfo.assElement = item
|
| 598 |
+
item.alisaInfo.assElement = targetEl
|
| 599 |
+
targetHaveAssEls.value.push(targetEl)
|
| 600 |
+
if (callBack)
|
| 601 |
+
callBack(targetEl, item)
|
| 602 |
+
return
|
| 603 |
+
}
|
| 604 |
+
}
|
| 605 |
+
}
|
| 606 |
+
targetNoAssEls.value.push(targetEl)
|
| 607 |
+
}
|
| 608 |
+
|
| 609 |
+
const LCS = (a, b) => {
|
| 610 |
+
const dp = Array(a.length + 1).fill()
|
| 611 |
+
.map(() => Array(b.length + 1).fill(0))
|
| 612 |
+
for (let i = 1; i <= a.length; i++) {
|
| 613 |
+
for (let j = 1; j <= b.length; j++) {
|
| 614 |
+
dp[i][j] =
|
| 615 |
+
a[i - 1] === b[j - 1]
|
| 616 |
+
? dp[i - 1][j - 1] + 1
|
| 617 |
+
: Math.max(dp[i - 1][j], dp[i][j - 1])
|
| 618 |
+
}
|
| 619 |
+
}
|
| 620 |
+
return dp[a.length][b.length]
|
| 621 |
+
}
|
| 622 |
+
|
| 623 |
+
const LCSSim = (a, b) => {
|
| 624 |
+
if (!a || !b) return 0;
|
| 625 |
+
const lcsLength = LCS(a, b)
|
| 626 |
+
return lcsLength / Math.max(a.length, b.length)
|
| 627 |
+
}
|
scripts/js/computeQuality.js
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const getElements = () => {
|
| 2 |
+
let toList = [];
|
| 3 |
+
const ref = window;
|
| 4 |
+
const parentWidth = ref.offsetWidth
|
| 5 |
+
const parentHeight = ref.offsetHeight
|
| 6 |
+
const parentScrollHeight = ref.scrollHeight
|
| 7 |
+
let elements = [];
|
| 8 |
+
elements = document.querySelectorAll('body *')
|
| 9 |
+
toList.splice(0, toList.length);
|
| 10 |
+
for (let el of elements) {
|
| 11 |
+
if (['script'].includes(el.tagName.toLowerCase())) continue
|
| 12 |
+
if (isUnvisible(el)) continue
|
| 13 |
+
toList.push(el)
|
| 14 |
+
}
|
| 15 |
+
toList.forEach((el) => {
|
| 16 |
+
let clientRect = el.getBoundingClientRect()
|
| 17 |
+
let pos = {
|
| 18 |
+
left: clientRect.left + scrollX,
|
| 19 |
+
right: clientRect.right + scrollX,
|
| 20 |
+
top: clientRect.top + scrollY,
|
| 21 |
+
bottom: clientRect.bottom + scrollY,
|
| 22 |
+
width: clientRect.width,
|
| 23 |
+
height: clientRect.height
|
| 24 |
+
}
|
| 25 |
+
const isFixedOrSticky = ['fixed', 'sticky'].includes(
|
| 26 |
+
getComputedStyle(el).position
|
| 27 |
+
)
|
| 28 |
+
if (isFixedOrSticky) {
|
| 29 |
+
pos.left = clientRect.left
|
| 30 |
+
pos.right = clientRect.right
|
| 31 |
+
pos.top = clientRect.top
|
| 32 |
+
pos.bottom = clientRect.bottom
|
| 33 |
+
}
|
| 34 |
+
let biasX = []
|
| 35 |
+
let biasY = []
|
| 36 |
+
if (pos.left < parentWidth / 2) biasX = ['left']
|
| 37 |
+
else biasX = ['right']
|
| 38 |
+
if (pos.left < parentWidth / 2 && pos.right > parentWidth / 2) biasX.push('mid')
|
| 39 |
+
|
| 40 |
+
if (pos.top < parentHeight / 2) biasY = ['top']
|
| 41 |
+
else if (pos.top > parentScrollHeight - parentHeight / 2) biasY = ['bottom']
|
| 42 |
+
else biasY = ['scroll']
|
| 43 |
+
if (pos.top < parentHeight / 2 && pos.bottom > parentHeight / 2 && isFixedOrSticky)
|
| 44 |
+
biasY.push('mid')
|
| 45 |
+
|
| 46 |
+
el.alisaInfo = {
|
| 47 |
+
elInfo: {
|
| 48 |
+
pos: pos,
|
| 49 |
+
biasX,
|
| 50 |
+
biasY
|
| 51 |
+
},
|
| 52 |
+
parentInfo: {
|
| 53 |
+
width: parentWidth,
|
| 54 |
+
height: parentHeight,
|
| 55 |
+
scrollHeight: parentScrollHeight
|
| 56 |
+
},
|
| 57 |
+
groupLeft: [],
|
| 58 |
+
groupRight: [],
|
| 59 |
+
groupTop: [],
|
| 60 |
+
groupBottom: [],
|
| 61 |
+
groupAxisWidth: [],
|
| 62 |
+
groupAxisHeight: [],
|
| 63 |
+
groupAll: [],
|
| 64 |
+
raceList: [],
|
| 65 |
+
assElement: null,
|
| 66 |
+
assLayoutSimScore: 0,
|
| 67 |
+
assStyleSimScore: 0
|
| 68 |
+
}
|
| 69 |
+
})
|
| 70 |
+
|
| 71 |
+
toList.forEach((el) => {
|
| 72 |
+
getSameGroup(el, toList, 'left')
|
| 73 |
+
getSameGroup(el, toList, 'right')
|
| 74 |
+
getSameGroup(el, toList, 'top')
|
| 75 |
+
getSameGroup(el, toList, 'bottom')
|
| 76 |
+
getSameGroup(el, toList, 'axisWidth')
|
| 77 |
+
getSameGroup(el, toList, 'axisHeight')
|
| 78 |
+
})
|
| 79 |
+
toList.forEach((el) => {
|
| 80 |
+
getSameRace(el, toList)
|
| 81 |
+
})
|
| 82 |
+
|
| 83 |
+
return toList;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
const isUnvisible = (el) => {
|
| 87 |
+
const style = getComputedStyle(el);
|
| 88 |
+
const rect = el.getBoundingClientRect();
|
| 89 |
+
const hidden =
|
| 90 |
+
style.display === 'none' ||
|
| 91 |
+
style.visibility === 'hidden' ||
|
| 92 |
+
style.opacity === '0' || rect.width === 0 ||
|
| 93 |
+
rect.height === 0;
|
| 94 |
+
return hidden;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
const getSameGroup = (el, elList, direction, offset = 5) => {
|
| 98 |
+
let idx = elList.indexOf(el)
|
| 99 |
+
if (idx < 0) return
|
| 100 |
+
const Direction = direction.slice(0, 1).toUpperCase() + direction.slice(1)
|
| 101 |
+
const isSamePos = (direction, pos1, pos2, offset) => {
|
| 102 |
+
if (['left', 'top', 'right', 'bottom'].includes(direction))
|
| 103 |
+
if (Math.abs(pos1[direction] - pos2[direction]) <= offset) return true
|
| 104 |
+
if (direction == 'axisWidth')
|
| 105 |
+
if (Math.abs(pos1.width / 2 + pos1.left - pos2.width / 2 - pos2.left) <= offset)
|
| 106 |
+
return true
|
| 107 |
+
if (direction == 'axisHeight')
|
| 108 |
+
if (Math.abs(pos1.height / 2 + pos1.top - pos2.height / 2 - pos2.top) <= offset)
|
| 109 |
+
return true
|
| 110 |
+
return false
|
| 111 |
+
}
|
| 112 |
+
elList.forEach((element, i) => {
|
| 113 |
+
if (idx == i) return
|
| 114 |
+
if (
|
| 115 |
+
isSamePos(
|
| 116 |
+
direction,
|
| 117 |
+
el.alisaInfo.elInfo.pos,
|
| 118 |
+
element.alisaInfo.elInfo.pos,
|
| 119 |
+
offset
|
| 120 |
+
)
|
| 121 |
+
) {
|
| 122 |
+
el.alisaInfo[`group${Direction}`].push(element)
|
| 123 |
+
let itemIndex = el.alisaInfo.groupAll.indexOf(element)
|
| 124 |
+
if (itemIndex < 0) el.alisaInfo.groupAll.push(element)
|
| 125 |
+
}
|
| 126 |
+
})
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
const getSameRace = (el, elList) => {
|
| 130 |
+
let idx = elList.indexOf(el)
|
| 131 |
+
if (idx < 0) return
|
| 132 |
+
const isSameRace = (el1, el2) => {
|
| 133 |
+
const groupAll = el1.alisaInfo.groupAll
|
| 134 |
+
if (groupAll.indexOf(el2) < 0) return false
|
| 135 |
+
if (el1.tagName != el2.tagName) return false
|
| 136 |
+
return el1.className == el2.className
|
| 137 |
+
}
|
| 138 |
+
elList.forEach((element, i) => {
|
| 139 |
+
if (idx == i) return
|
| 140 |
+
if (isSameRace(el, element)) {
|
| 141 |
+
el.alisaInfo.raceList.push(element)
|
| 142 |
+
}
|
| 143 |
+
})
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
const computedRawElementRatio = (offset = 5) => {
|
| 147 |
+
const toList = getElements();
|
| 148 |
+
try {
|
| 149 |
+
let docMargin = parseFloat(
|
| 150 |
+
getComputedStyle(document.body).marginLeft
|
| 151 |
+
)
|
| 152 |
+
let count = 0
|
| 153 |
+
toList.forEach((el) => {
|
| 154 |
+
if (Math.abs(docMargin - el.alisaInfo.elInfo.pos.left) < offset) {
|
| 155 |
+
if (getComputedStyle(el).position === 'static') {
|
| 156 |
+
count++
|
| 157 |
+
}
|
| 158 |
+
}
|
| 159 |
+
})
|
| 160 |
+
console.log(count / toList.length)
|
| 161 |
+
return count / toList.length
|
| 162 |
+
} catch (e) {
|
| 163 |
+
console.error('Error in getting iframe document margin', e)
|
| 164 |
+
return -1
|
| 165 |
+
}
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
const computedElementNum = () => {
|
| 169 |
+
const toList = getElements();
|
| 170 |
+
let allTargetEls = toList
|
| 171 |
+
let viewedEls = []
|
| 172 |
+
let count = 0
|
| 173 |
+
allTargetEls.forEach((ei) => {
|
| 174 |
+
if (viewedEls.indexOf(ei) < 0) {
|
| 175 |
+
count += 1
|
| 176 |
+
viewedEls.push(ei)
|
| 177 |
+
ei.alisaInfo.raceList.forEach((ri) => {
|
| 178 |
+
viewedEls.push(ri)
|
| 179 |
+
})
|
| 180 |
+
}
|
| 181 |
+
})
|
| 182 |
+
return count
|
| 183 |
+
}
|
scripts/js/one-color-all.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):((e=e||self).one=e.one||{},e.one.color=t())}(this,(function(){"use strict";var e=[],t=function(e){return void 0===e},a=/\s*(\.\d+|\d+(?:\.\d+)?)(%|deg)?\s*/,r=/\s*(\.\d+|100|\d?\d(?:\.\d+)?)%\s*/,n=new RegExp("^(rgb|hsl|hsv)a?\\("+a.source+"[, ]"+a.source+"[, ]"+a.source+"(?:[,/]"+a.source+")?\\)$","i");function i(e,t,a){return"%"===e?100:"deg"===e||a&&0===t?360:e?void 0:255}function o(e){if(Array.isArray(e)){if("string"==typeof e[0]&&"function"==typeof o[e[0]])return new o[e[0]](e.slice(1,e.length));if(4===e.length)return new o.RGB(e[0]/255,e[1]/255,e[2]/255,e[3]/255)}else if("string"==typeof e){var a=e.toLowerCase();o.namedColors[a]&&(e="#"+o.namedColors[a]),"transparent"===a&&(e="rgba(0,0,0,0)");var s=e.match(n);if(s){var f=s[1].toUpperCase(),u="H"===f[0];if(t(o[f]))throw new Error("color."+f+" is not installed.");let e=t(s[8])?1:void 0;return void 0===e&&(e="%"===s[9]?parseFloat(s[8])/100:parseFloat(s[8])),new o[f](parseFloat(s[2])/i(s[3],0,u),parseFloat(s[4])/i(s[5],1,u),parseFloat(s[6])/i(s[7],2,u),e)}e.length<6&&(e=e.replace(/^#?([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])?$/i,"$1$1$2$2$3$3$4$4"));var l=e.match(/^#?([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])?$/i);if(l)return new o.RGB(parseInt(l[1],16)/255,parseInt(l[2],16)/255,parseInt(l[3],16)/255,l[4]?parseInt(l[4],16)/255:1);if(o.CMYK){var h=e.match(new RegExp("^cmyk\\("+r.source+","+r.source+","+r.source+","+r.source+"\\)$","i"));if(h)return new o.CMYK(parseFloat(h[1])/100,parseFloat(h[2])/100,parseFloat(h[3])/100,parseFloat(h[4])/100)}}else if("object"==typeof e&&e.isColor)return e;return!1}o.namedColors={},o.installColorSpace=function(a,r,n){o[a]=function(e){var t=Array.isArray(e)?e:arguments;r.forEach((function(e,n){var i=t[n];if("alpha"===e)this._alpha=isNaN(i)||i>1?1:i<0?0:i;else{if(isNaN(i))throw new Error("["+a+"]: Invalid color: ("+r.join(",")+")");"hue"===e?this._hue=i<0?i-Math.floor(i):i%1:this["_"+e]=i<0?0:i>1?1:i}}),this)},o[a].propertyNames=r;var i=o[a].prototype;for(var s in["valueOf","hex","hexa","css","cssa"].forEach((function(e){i[e]=i[e]||("RGB"===a?i.hex:function(){return this.rgb()[e]()})})),i.isColor=!0,i.equals=function(e,n){t(n)&&(n=1e-10),e=e[a.toLowerCase()]();for(var i=0;i<r.length;i+=1)if(Math.abs(this["_"+r[i]]-e["_"+r[i]])>n)return!1;return!0},i.toJSON=function(){return[a].concat(r.map((function(e){return this["_"+e]}),this))},n)if(Object.prototype.hasOwnProperty.call(n,s)){var f=s.match(/^from(.*)$/);f?o[f[1].toUpperCase()].prototype[a.toLowerCase()]=n[s]:i[s]=n[s]}function u(e,t){var a={};for(var r in a[t.toLowerCase()]=function(){return this.rgb()[t.toLowerCase()]()},o[t].propertyNames.forEach((function(e){var r="black"===e?"k":e.charAt(0);a[e]=a[r]=function(a,r){return this[t.toLowerCase()]()[e](a,r)}})),a)Object.prototype.hasOwnProperty.call(a,r)&&void 0===o[e].prototype[r]&&(o[e].prototype[r]=a[r])}return i[a.toLowerCase()]=function(){return this},i.toString=function(){return"["+a+" "+r.map((function(e){return this["_"+e]}),this).join(", ")+"]"},r.forEach((function(e){var t="black"===e?"k":e.charAt(0);i[e]=i[t]=function(t,a){return void 0===t?this["_"+e]:a?new this.constructor(r.map((function(a){return this["_"+a]+(e===a?t:0)}),this)):new this.constructor(r.map((function(a){return e===a?t:this["_"+a]}),this))}})),e.forEach((function(e){u(a,e),u(e,a)})),e.push(a),o},o.pluginList=[],o.use=function(e){return-1===o.pluginList.indexOf(e)&&(this.pluginList.push(e),e(o)),o},o.installMethod=function(t,a){return e.forEach((function(e){o[e].prototype[t]=a})),this},o.installColorSpace("RGB",["red","green","blue","alpha"],{hex:function(){var e=(65536*Math.round(255*this._red)+256*Math.round(255*this._green)+Math.round(255*this._blue)).toString(16);return"#"+"00000".substr(0,6-e.length)+e},hexa:function(){var e=Math.round(255*this._alpha).toString(16);return this.hex()+"00".substr(0,2-e.length)+e},css:function(){return"rgb("+Math.round(255*this._red)+","+Math.round(255*this._green)+","+Math.round(255*this._blue)+")"},cssa:function(){return"rgba("+Math.round(255*this._red)+","+Math.round(255*this._green)+","+Math.round(255*this._blue)+","+this._alpha+")"}});var s=function(e){e.installColorSpace("XYZ",["x","y","z","alpha"],{fromRgb:function(){var t=function(e){return e>.04045?Math.pow((e+.055)/1.055,2.4):e/12.92},a=t(this._red),r=t(this._green),n=t(this._blue);return new e.XYZ(.4124564*a+.3575761*r+.1804375*n,.2126729*a+.7151522*r+.072175*n,.0193339*a+.119192*r+.9503041*n,this._alpha)},rgb:function(){var t=this._x,a=this._y,r=this._z,n=function(e){return e>.0031308?1.055*Math.pow(e,1/2.4)-.055:12.92*e};return new e.RGB(n(3.2404542*t+-1.5371385*a+-.4985314*r),n(-.969266*t+1.8760108*a+.041556*r),n(.0556434*t+-.2040259*a+1.0572252*r),this._alpha)},lab:function(){var t=function(e){return e>.008856?Math.pow(e,1/3):7.787037*e+4/29},a=t(this._x/95.047),r=t(this._y/100),n=t(this._z/108.883);return new e.LAB(116*r-16,500*(a-r),200*(r-n),this._alpha)}})},f=function(e){e.installColorSpace("HSV",["hue","saturation","value","alpha"],{rgb:function(){var t,a,r,n=this._hue,i=this._saturation,o=this._value,s=Math.min(5,Math.floor(6*n)),f=6*n-s,u=o*(1-i),l=o*(1-f*i),h=o*(1-(1-f)*i);switch(s){case 0:t=o,a=h,r=u;break;case 1:t=l,a=o,r=u;break;case 2:t=u,a=o,r=h;break;case 3:t=u,a=l,r=o;break;case 4:t=h,a=u,r=o;break;case 5:t=o,a=u,r=l}return new e.RGB(t,a,r,this._alpha)},hsl:function(){var t,a=(2-this._saturation)*this._value,r=this._saturation*this._value,n=a<=1?a:2-a;return t=n<1e-9?0:r/n,new e.HSL(this._hue,t,a/2,this._alpha)},fromRgb:function(){var t,a=this._red,r=this._green,n=this._blue,i=Math.max(a,r,n),o=i-Math.min(a,r,n),s=0===i?0:o/i,f=i;if(0===o)t=0;else switch(i){case a:t=(r-n)/o/6+(r<n?1:0);break;case r:t=(n-a)/o/6+1/3;break;case n:t=(a-r)/o/6+2/3}return new e.HSV(t,s,f,this._alpha)}})},u=function(e){e.use(f),e.installColorSpace("HSL",["hue","saturation","lightness","alpha"],{hsv:function(){var t,a=2*this._lightness,r=this._saturation*(a<=1?a:2-a);return t=a+r<1e-9?0:2*r/(a+r),new e.HSV(this._hue,t,(a+r)/2,this._alpha)},rgb:function(){return this.hsv().rgb()},fromRgb:function(){return this.hsv().hsl()}})},l=function(e){function t(e){return e<=.03928?e/12.92:Math.pow((e+.055)/1.055,2.4)}e.installMethod("luminance",(function(){var e=this.rgb();return.2126*t(e._red)+.7152*t(e._green)+.0722*t(e._blue)}))},h=function(e){e.installMethod("isDark",(function(){var e=this.rgb();return(255*e._red*299+255*e._green*587+255*e._blue*114)/1e3<128}))};return o.use(s).use((function(e){e.use(s),e.installColorSpace("LAB",["l","a","b","alpha"],{fromRgb:function(){return this.xyz().lab()},rgb:function(){return this.xyz().rgb()},xyz:function(){var t=function(e){var t=Math.pow(e,3);return t>.008856?t:(e-16/116)/7.87},a=(this._l+16)/116,r=this._a/500+a,n=a-this._b/200;return new e.XYZ(95.047*t(r),100*t(a),108.883*t(n),this._alpha)}})})).use(f).use(u).use((function(e){e.installColorSpace("CMYK",["cyan","magenta","yellow","black","alpha"],{rgb:function(){return new e.RGB(1-this._cyan*(1-this._black)-this._black,1-this._magenta*(1-this._black)-this._black,1-this._yellow*(1-this._black)-this._black,this._alpha)},fromRgb:function(){var t=this._red,a=this._green,r=this._blue,n=1-t,i=1-a,o=1-r,s=1;return t||a||r?(n=(n-(s=Math.min(n,Math.min(i,o))))/(1-s),i=(i-s)/(1-s),o=(o-s)/(1-s)):s=1,new e.CMYK(n,i,o,s,this._alpha)}})})).use((function(e){e.namedColors={aliceblue:"f0f8ff",antiquewhite:"faebd7",aqua:"0ff",aquamarine:"7fffd4",azure:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"000",blanchedalmond:"ffebcd",blue:"00f",blueviolet:"8a2be2",brown:"a52a2a",burlywood:"deb887",cadetblue:"5f9ea0",chartreuse:"7fff00",chocolate:"d2691e",coral:"ff7f50",cornflowerblue:"6495ed",cornsilk:"fff8dc",crimson:"dc143c",cyan:"0ff",darkblue:"00008b",darkcyan:"008b8b",darkgoldenrod:"b8860b",darkgray:"a9a9a9",darkgrey:"a9a9a9",darkgreen:"006400",darkkhaki:"bdb76b",darkmagenta:"8b008b",darkolivegreen:"556b2f",darkorange:"ff8c00",darkorchid:"9932cc",darkred:"8b0000",darksalmon:"e9967a",darkseagreen:"8fbc8f",darkslateblue:"483d8b",darkslategray:"2f4f4f",darkslategrey:"2f4f4f",darkturquoise:"00ced1",darkviolet:"9400d3",deeppink:"ff1493",deepskyblue:"00bfff",dimgray:"696969",dimgrey:"696969",dodgerblue:"1e90ff",firebrick:"b22222",floralwhite:"fffaf0",forestgreen:"228b22",fuchsia:"f0f",gainsboro:"dcdcdc",ghostwhite:"f8f8ff",gold:"ffd700",goldenrod:"daa520",gray:"808080",grey:"808080",green:"008000",greenyellow:"adff2f",honeydew:"f0fff0",hotpink:"ff69b4",indianred:"cd5c5c",indigo:"4b0082",ivory:"fffff0",khaki:"f0e68c",lavender:"e6e6fa",lavenderblush:"fff0f5",lawngreen:"7cfc00",lemonchiffon:"fffacd",lightblue:"add8e6",lightcoral:"f08080",lightcyan:"e0ffff",lightgoldenrodyellow:"fafad2",lightgray:"d3d3d3",lightgrey:"d3d3d3",lightgreen:"90ee90",lightpink:"ffb6c1",lightsalmon:"ffa07a",lightseagreen:"20b2aa",lightskyblue:"87cefa",lightslategray:"789",lightslategrey:"789",lightsteelblue:"b0c4de",lightyellow:"ffffe0",lime:"0f0",limegreen:"32cd32",linen:"faf0e6",magenta:"f0f",maroon:"800000",mediumaquamarine:"66cdaa",mediumblue:"0000cd",mediumorchid:"ba55d3",mediumpurple:"9370d8",mediumseagreen:"3cb371",mediumslateblue:"7b68ee",mediumspringgreen:"00fa9a",mediumturquoise:"48d1cc",mediumvioletred:"c71585",midnightblue:"191970",mintcream:"f5fffa",mistyrose:"ffe4e1",moccasin:"ffe4b5",navajowhite:"ffdead",navy:"000080",oldlace:"fdf5e6",olive:"808000",olivedrab:"6b8e23",orange:"ffa500",orangered:"ff4500",orchid:"da70d6",palegoldenrod:"eee8aa",palegreen:"98fb98",paleturquoise:"afeeee",palevioletred:"d87093",papayawhip:"ffefd5",peachpuff:"ffdab9",peru:"cd853f",pink:"ffc0cb",plum:"dda0dd",powderblue:"b0e0e6",purple:"800080",rebeccapurple:"639",red:"f00",rosybrown:"bc8f8f",royalblue:"4169e1",saddlebrown:"8b4513",salmon:"fa8072",sandybrown:"f4a460",seagreen:"2e8b57",seashell:"fff5ee",sienna:"a0522d",silver:"c0c0c0",skyblue:"87ceeb",slateblue:"6a5acd",slategray:"708090",slategrey:"708090",snow:"fffafa",springgreen:"00ff7f",steelblue:"4682b4",tan:"d2b48c",teal:"008080",thistle:"d8bfd8",tomato:"ff6347",turquoise:"40e0d0",violet:"ee82ee",wheat:"f5deb3",white:"fff",whitesmoke:"f5f5f5",yellow:"ff0",yellowgreen:"9acd32"}})).use((function(e){e.installMethod("clearer",(function(e){return this.alpha(isNaN(e)?-.1:-e,!0)}))})).use((function(e){e.use(l),e.installMethod("contrast",(function(e){var t=this.luminance(),a=e.luminance();return t>a?(t+.05)/(a+.05):(a+.05)/(t+.05)}))})).use((function(e){e.use(u),e.installMethod("darken",(function(e){return this.lightness(isNaN(e)?-.1:-e,!0)}))})).use((function(e){e.use(u),e.installMethod("desaturate",(function(e){return this.saturation(isNaN(e)?-.1:-e,!0)}))})).use((function(e){function t(){var t=this.rgb(),a=.3*t._red+.59*t._green+.11*t._blue;return new e.RGB(a,a,a,t._alpha)}e.installMethod("greyscale",t).installMethod("grayscale",t)})).use(h).use((function(e){e.use(h),e.installMethod("isLight",(function(){return!this.isDark()}))})).use((function(e){e.use(u),e.installMethod("lighten",(function(e){return this.lightness(isNaN(e)?.1:e,!0)}))})).use(l).use((function(e){e.installMethod("mix",(function(t,a){t=e(t).rgb();var r=2*(a=1-(isNaN(a)?.5:a))-1,n=this._alpha-t._alpha,i=((r*n==-1?r:(r+n)/(1+r*n))+1)/2,o=1-i,s=this.rgb();return new e.RGB(s._red*i+t._red*o,s._green*i+t._green*o,s._blue*i+t._blue*o,s._alpha*a+t._alpha*(1-a))}))})).use((function(e){e.installMethod("negate",(function(){var t=this.rgb();return new e.RGB(1-t._red,1-t._green,1-t._blue,this._alpha)}))})).use((function(e){e.installMethod("opaquer",(function(e){return this.alpha(isNaN(e)?.1:e,!0)}))})).use((function(e){e.use(u),e.installMethod("rotate",(function(e){return this.hue((e||0)/360,!0)}))})).use((function(e){e.use(u),e.installMethod("saturate",(function(e){return this.saturation(isNaN(e)?.1:e,!0)}))})).use((function(e){e.installMethod("toAlpha",(function(e){var t=this.rgb(),a=e(e).rgb(),r=new e.RGB(0,0,0,t._alpha),n=["_red","_green","_blue"];return n.forEach((function(e){t[e]<1e-10?r[e]=t[e]:t[e]>a[e]?r[e]=(t[e]-a[e])/(1-a[e]):t[e]>a[e]?r[e]=(a[e]-t[e])/a[e]:r[e]=0})),r._red>r._green?r._red>r._blue?t._alpha=r._red:t._alpha=r._blue:r._green>r._blue?t._alpha=r._green:t._alpha=r._blue,t._alpha<1e-10||(n.forEach((function(e){t[e]=(t[e]-a[e])/t._alpha+a[e]})),t._alpha*=r._alpha),t}))}))}));
|
| 2 |
+
//# sourceMappingURL=one-color-all.js.map
|
scripts/js/vue.global.js
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|