import sublime
import sublime_plugin
import re
import time
import os
SETTINGS = {}
lastCompletion = {"needFix": False, "value": None, "region": None}
def plugin_loaded():
init_settings()
def init_settings():
get_settings()
sublime.load_settings('cssrem.sublime-settings').add_on_change('get_settings', get_settings)
def get_settings():
settings = sublime.load_settings('cssrem.sublime-settings')
SETTINGS['px_to_rem'] = settings.get('px_to_rem', 40)
SETTINGS['max_rem_fraction_length'] = settings.get('max_rem_fraction_length', 6)
SETTINGS['available_file_types'] = settings.get('available_file_types', ['.css', '.less', '.sass'])
def get_setting(view, key):
return view.settings().get(key, SETTINGS[key]);
class CssRemCommand(sublime_plugin.EventListener):
def on_text_command(self, view, name, args):
if name == 'commit_completion':
view.run_command('replace_rem')
return None
def on_query_completions(self, view, prefix, locations):
# print('cssrem start {0}, {1}'.format(prefix, locations))
# only works on specific file types
fileName, fileExtension = os.path.splitext(view.file_name())
if not fileExtension.lower() in get_setting(view, 'available_file_types'):
return []
# reset completion match
lastCompletion["needFix"] = False
location = locations[0]
snippets = []
# get rem match
match = re.compile("([\d.]+)p(x)?").match(prefix)
if match:
lineLocation = view.line(location)
line = view.substr(sublime.Region(lineLocation.a, location))
value = match.group(1)
# fix: values like `0.5px`
segmentStart = line.rfind(" ", 0, location)
if segmentStart == -1:
segmentStart = 0
segmentStr = line[segmentStart:location]
segment = re.compile("([\d.])+" + value).search(segmentStr)
if segment:
value = segment.group(0)
start = lineLocation.a + segmentStart + 0 + segment.start(0)
lastCompletion["needFix"] = True
else:
start = location
remValue = round(float(value) / get_setting(view, 'px_to_rem'), get_setting(view, 'max_rem_fraction_length'))
# save them for replace fix
lastCompletion["value"] = str(remValue) + 'rem'
lastCompletion["region"] = sublime.Region(start, location)
# set completion snippet
snippets += [(value + 'px ->rem(' + str(get_setting(view, 'px_to_rem')) + ')', str(remValue) + 'rem')]
# print("cssrem: {0}".format(snippets))
return snippets
class ReplaceRemCommand(sublime_plugin.TextCommand):
def run(self, edit):
needFix = lastCompletion["needFix"]
if needFix == True:
value = lastCompletion["value"]
region = lastCompletion["region"]
# print('replace: {0}, {1}'.format(value, region))
self.view.replace(edit, region, value)
self.view.end_edit(edit)
没有合适的资源?快使用搜索试试~ 我知道了~
课件和资料 前端.rar
共994个文件
html:344个
jpg:308个
png:124个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 59 浏览量
2023-02-25
09:14:10
上传
评论
收藏 49.24MB RAR 举报
温馨提示
免责声明:资料部分来源于合法的互联网渠道收集和整理,部分自己学习积累成果,供大家学习参考与交流。收取的费用仅用于收集和整理资料耗费时间的酬劳。 本人尊重原创作者或出版方,资料版权归原作者或出版方所有,本人不对所涉及的版权问题或内容负法律责任。如有侵权,请举报或通知本人删除。
资源推荐
资源详情
资源评论
收起资源包目录
课件和资料 前端.rar (994个子文件)
jQuery_handbook.chm 401KB
jQuery_handbook.chm 401KB
jQuery_handbook.chw 36KB
jQuery_handbook.chw 36KB
bootstrap.min.css 111KB
bootstrap.min.css 111KB
bootstrap.min.css 111KB
style.css 38KB
website.css 30KB
main.css 22KB
swiper.min.css 17KB
swiper.min.css 17KB
swiper.min.css 17KB
swiper.min.css 17KB
swiper.min.css 17KB
website.css 8KB
main.css 8KB
main.css 4KB
main.css 4KB
main.css 4KB
main.css 4KB
main.css 3KB
main.css 3KB
index.css 3KB
ebook.css 3KB
test.css 2KB
test.css 2KB
main.css 2KB
main.css 2KB
reset.css 669B
reset.css 669B
reset.css 664B
search.css 599B
reset.css 507B
reset.css 445B
reset.css 432B
reset.css 432B
reset.css 432B
reset.css 432B
reset.css 432B
1.css 233B
2.css 230B
main.css 147B
main.css 91B
fontawesome-webfont.eot 71KB
glyphicons-halflings-regular.eot 20KB
glyphicons-halflings-regular.eot 20KB
glyphicons-halflings-regular.eot 20KB
cssrem.gif 334KB
cssrem.gif 334KB
003-02.gif 79KB
003-02.gif 79KB
003-02.gif 79KB
003-02.gif 79KB
003-02.gif 79KB
bike_loading.gif 79KB
004-02.gif 20KB
004-02.gif 20KB
004-02.gif 20KB
004-02.gif 20KB
004-02.gif 20KB
004-02.gif 20KB
003-01.gif 2KB
003-01.gif 2KB
003-01.gif 2KB
003-01.gif 2KB
003-01.gif 2KB
dot.gif 1KB
dot.gif 1KB
.gitignore 53B
.gitignore 53B
section04.html 63KB
section02.html 62KB
section01.html 58KB
section05.html 58KB
section01.html 57KB
section01.html 56KB
section03.html 54KB
section01.html 54KB
section02.html 54KB
section03.html 54KB
section04.html 53KB
section01.html 53KB
section02.html 53KB
section003.html 52KB
section05.html 52KB
section09.html 52KB
section05.html 52KB
section06.html 51KB
section02.html 51KB
section08.html 51KB
section02.html 51KB
section02.html 51KB
section05.html 51KB
section01.html 51KB
section04.html 51KB
section00.html 51KB
section07.html 51KB
section05.html 51KB
section04.html 51KB
共 994 条
- 1
- 2
- 3
- 4
- 5
- 6
- 10
资源评论
金枝玉叶9
- 粉丝: 140
- 资源: 7639
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功